Skip to content

Commit a479732

Browse files
committed
add microcontroller toggles for status LED
1 parent 51078cc commit a479732

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535
#define AUTORESET_DELAY_MS 500
3636
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000)
3737

38-
#define MICROPY_HW_NEOPIXEL &pin_PC00
38+
#define MICROPY_HW_NEOPIXEL (&pin_PC00)
3939

4040
// On-board flash
41-
#define SPI_FLASH_MOSI_PIN &pin_PB05
42-
#define SPI_FLASH_MISO_PIN &pin_PB04
43-
#define SPI_FLASH_SCK_PIN &pin_PB03
44-
#define SPI_FLASH_CS_PIN &pin_PA15
41+
#define SPI_FLASH_MOSI_PIN (&pin_PB05)
42+
#define SPI_FLASH_MISO_PIN (&pin_PB04)
43+
#define SPI_FLASH_SCK_PIN (&pin_PB03)
44+
#define SPI_FLASH_CS_PIN (&pin_PA15)
4545

4646
#define DEFAULT_I2C_BUS_SCL (&pin_PB06)
4747
#define DEFAULT_I2C_BUS_SDA (&pin_PB07)

ports/stm32f4/common-hal/microcontroller/Pin.c

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
*/
2727

2828
#include "shared-bindings/microcontroller/Pin.h"
29+
#include "shared-bindings/digitalio/DigitalInOut.h"
30+
#include "supervisor/shared/rgb_led_status.h"
2931

3032
#include "py/mphal.h"
3133
#include "stm32f4/pins.h"
@@ -34,13 +36,6 @@
3436
#ifdef MICROPY_HW_NEOPIXEL
3537
bool neopixel_in_use;
3638
#endif
37-
#ifdef MICROPY_HW_APA102_MOSI
38-
bool apa102_sck_in_use;
39-
bool apa102_mosi_in_use;
40-
#endif
41-
#ifdef SPEAKER_ENABLE_PIN
42-
bool speaker_enable_in_use;
43-
#endif
4439

4540
#if MCU_PACKAGE == 144
4641
#define GPIO_PORT_COUNT 7
@@ -64,20 +59,29 @@ void reset_all_pins(void) {
6459
for (uint8_t i = 0; i < GPIO_PORT_COUNT; i++) {
6560
HAL_GPIO_DeInit(ports[i], ~never_reset_pins[i]);
6661
}
62+
63+
#ifdef MICROPY_HW_NEOPIXEL
64+
neopixel_in_use = false;
65+
#endif
6766
}
6867

6968
// Mark pin as free and return it to a quiescent state.
7069
void reset_pin_number(uint8_t pin_port, uint8_t pin_number) {
7170
if (pin_port == 0x0F) {
7271
return;
7372
}
74-
75-
// Clear claimed bit.
73+
// Clear claimed bit & reset
7674
claimed_pins[pin_port] &= ~(1<<pin_number);
77-
// Reset the pin
7875
HAL_GPIO_DeInit(ports[pin_port], 1<<pin_number);
79-
}
8076

77+
#ifdef MICROPY_HW_NEOPIXEL
78+
if (pin_port == MICROPY_HW_NEOPIXEL->port && pin_number == MICROPY_HW_NEOPIXEL->number) {
79+
neopixel_in_use = false;
80+
rgb_led_status_init();
81+
return;
82+
}
83+
#endif
84+
}
8185

8286
void never_reset_pin_number(uint8_t pin_port, uint8_t pin_number) {
8387
never_reset_pins[pin_port] |= 1<<pin_number;
@@ -94,13 +98,25 @@ void common_hal_reset_pin(const mcu_pin_obj_t* pin) {
9498
void claim_pin(const mcu_pin_obj_t* pin) {
9599
// Set bit in claimed_pins bitmask.
96100
claimed_pins[pin->port] |= 1<<pin->number;
101+
102+
#ifdef MICROPY_HW_NEOPIXEL
103+
if (pin == MICROPY_HW_NEOPIXEL) {
104+
neopixel_in_use = true;
105+
}
106+
#endif
97107
}
98108

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

103113
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) {
114+
#ifdef MICROPY_HW_NEOPIXEL
115+
if (pin == MICROPY_HW_NEOPIXEL) {
116+
return !neopixel_in_use;
117+
}
118+
#endif
119+
104120
return pin_number_is_free(pin->port, pin->number);
105121
}
106122

0 commit comments

Comments
 (0)