26
26
*/
27
27
28
28
#include "shared-bindings/microcontroller/Pin.h"
29
+ #include "shared-bindings/digitalio/DigitalInOut.h"
30
+ #include "supervisor/shared/rgb_led_status.h"
29
31
30
32
#include "py/mphal.h"
31
33
#include "stm32f4/pins.h"
34
36
#ifdef MICROPY_HW_NEOPIXEL
35
37
bool neopixel_in_use ;
36
38
#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
44
39
45
40
#if MCU_PACKAGE == 144
46
41
#define GPIO_PORT_COUNT 7
@@ -64,20 +59,29 @@ void reset_all_pins(void) {
64
59
for (uint8_t i = 0 ; i < GPIO_PORT_COUNT ; i ++ ) {
65
60
HAL_GPIO_DeInit (ports [i ], ~never_reset_pins [i ]);
66
61
}
62
+
63
+ #ifdef MICROPY_HW_NEOPIXEL
64
+ neopixel_in_use = false;
65
+ #endif
67
66
}
68
67
69
68
// Mark pin as free and return it to a quiescent state.
70
69
void reset_pin_number (uint8_t pin_port , uint8_t pin_number ) {
71
70
if (pin_port == 0x0F ) {
72
71
return ;
73
72
}
74
-
75
- // Clear claimed bit.
73
+ // Clear claimed bit & reset
76
74
claimed_pins [pin_port ] &= ~(1 <<pin_number );
77
- // Reset the pin
78
75
HAL_GPIO_DeInit (ports [pin_port ], 1 <<pin_number );
79
- }
80
76
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
+ }
81
85
82
86
void never_reset_pin_number (uint8_t pin_port , uint8_t pin_number ) {
83
87
never_reset_pins [pin_port ] |= 1 <<pin_number ;
@@ -94,13 +98,25 @@ void common_hal_reset_pin(const mcu_pin_obj_t* pin) {
94
98
void claim_pin (const mcu_pin_obj_t * pin ) {
95
99
// Set bit in claimed_pins bitmask.
96
100
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
97
107
}
98
108
99
109
bool pin_number_is_free (uint8_t pin_port , uint8_t pin_number ) {
100
110
return !(claimed_pins [pin_port ] & 1 <<pin_number );
101
111
}
102
112
103
113
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
+
104
120
return pin_number_is_free (pin -> port , pin -> number );
105
121
}
106
122
0 commit comments