Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add microcontroller toggles for status LED
  • Loading branch information
hierophect committed Nov 18, 2019
commit a4797327cd4ea9fd53e00bf2ecfc82c30e413cec
10 changes: 5 additions & 5 deletions ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
#define AUTORESET_DELAY_MS 500
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000)

#define MICROPY_HW_NEOPIXEL &pin_PC00
#define MICROPY_HW_NEOPIXEL (&pin_PC00)

// On-board flash
#define SPI_FLASH_MOSI_PIN &pin_PB05
#define SPI_FLASH_MISO_PIN &pin_PB04
#define SPI_FLASH_SCK_PIN &pin_PB03
#define SPI_FLASH_CS_PIN &pin_PA15
#define SPI_FLASH_MOSI_PIN (&pin_PB05)
#define SPI_FLASH_MISO_PIN (&pin_PB04)
#define SPI_FLASH_SCK_PIN (&pin_PB03)
#define SPI_FLASH_CS_PIN (&pin_PA15)

#define DEFAULT_I2C_BUS_SCL (&pin_PB06)
#define DEFAULT_I2C_BUS_SDA (&pin_PB07)
Expand Down
38 changes: 27 additions & 11 deletions ports/stm32f4/common-hal/microcontroller/Pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*/

#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/digitalio/DigitalInOut.h"
#include "supervisor/shared/rgb_led_status.h"

#include "py/mphal.h"
#include "stm32f4/pins.h"
Expand All @@ -34,13 +36,6 @@
#ifdef MICROPY_HW_NEOPIXEL
bool neopixel_in_use;
#endif
#ifdef MICROPY_HW_APA102_MOSI
bool apa102_sck_in_use;
bool apa102_mosi_in_use;
#endif
#ifdef SPEAKER_ENABLE_PIN
bool speaker_enable_in_use;
#endif

#if MCU_PACKAGE == 144
#define GPIO_PORT_COUNT 7
Expand All @@ -64,20 +59,29 @@ void reset_all_pins(void) {
for (uint8_t i = 0; i < GPIO_PORT_COUNT; i++) {
HAL_GPIO_DeInit(ports[i], ~never_reset_pins[i]);
}

#ifdef MICROPY_HW_NEOPIXEL
neopixel_in_use = false;
#endif
}

// Mark pin as free and return it to a quiescent state.
void reset_pin_number(uint8_t pin_port, uint8_t pin_number) {
if (pin_port == 0x0F) {
return;
}

// Clear claimed bit.
// Clear claimed bit & reset
claimed_pins[pin_port] &= ~(1<<pin_number);
// Reset the pin
HAL_GPIO_DeInit(ports[pin_port], 1<<pin_number);
}

#ifdef MICROPY_HW_NEOPIXEL
if (pin_port == MICROPY_HW_NEOPIXEL->port && pin_number == MICROPY_HW_NEOPIXEL->number) {
neopixel_in_use = false;
rgb_led_status_init();
return;
}
#endif
}

void never_reset_pin_number(uint8_t pin_port, uint8_t pin_number) {
never_reset_pins[pin_port] |= 1<<pin_number;
Expand All @@ -94,13 +98,25 @@ void common_hal_reset_pin(const mcu_pin_obj_t* pin) {
void claim_pin(const mcu_pin_obj_t* pin) {
// Set bit in claimed_pins bitmask.
claimed_pins[pin->port] |= 1<<pin->number;

#ifdef MICROPY_HW_NEOPIXEL
if (pin == MICROPY_HW_NEOPIXEL) {
neopixel_in_use = true;
}
#endif
}

bool pin_number_is_free(uint8_t pin_port, uint8_t pin_number) {
return !(claimed_pins[pin_port] & 1<<pin_number);
}

bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) {
#ifdef MICROPY_HW_NEOPIXEL
if (pin == MICROPY_HW_NEOPIXEL) {
return !neopixel_in_use;
}
#endif

return pin_number_is_free(pin->port, pin->number);
}

Expand Down