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"
3436#ifdef MICROPY_HW_NEOPIXEL
3537bool 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.
7069void 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
8286void 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) {
9498void 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
99109bool pin_number_is_free (uint8_t pin_port , uint8_t pin_number ) {
100110 return !(claimed_pins [pin_port ] & 1 <<pin_number );
101111}
102112
103113bool 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