25
25
*/
26
26
27
27
#include "shared-bindings/microcontroller/Pin.h"
28
+ #include "shared-bindings/digitalio/DigitalInOut.h"
28
29
29
30
#include "nrf_gpio.h"
30
31
#include "py/mphal.h"
@@ -47,6 +48,19 @@ bool speaker_enable_in_use;
47
48
STATIC uint32_t claimed_pins [GPIO_COUNT ];
48
49
STATIC uint32_t never_reset_pins [GPIO_COUNT ];
49
50
51
+ STATIC void reset_speaker_enable_pin (void ) {
52
+ #ifdef SPEAKER_ENABLE_PIN
53
+ speaker_enable_in_use = false;
54
+ nrf_gpio_cfg (SPEAKER_ENABLE_PIN -> number ,
55
+ NRF_GPIO_PIN_DIR_OUTPUT ,
56
+ NRF_GPIO_PIN_INPUT_DISCONNECT ,
57
+ NRF_GPIO_PIN_NOPULL ,
58
+ NRF_GPIO_PIN_H0H1 ,
59
+ NRF_GPIO_PIN_NOSENSE );
60
+ nrf_gpio_pin_write (SPEAKER_ENABLE_PIN -> number , false);
61
+ #endif
62
+ }
63
+
50
64
void reset_all_pins (void ) {
51
65
for (size_t i = 0 ; i < GPIO_COUNT ; i ++ ) {
52
66
claimed_pins [i ] = never_reset_pins [i ];
@@ -68,10 +82,7 @@ void reset_all_pins(void) {
68
82
#endif
69
83
70
84
// After configuring SWD because it may be shared.
71
- #ifdef SPEAKER_ENABLE_PIN
72
- speaker_enable_in_use = false;
73
- // TODO set pin to out and turn off.
74
- #endif
85
+ reset_speaker_enable_pin ();
75
86
}
76
87
77
88
// Mark pin as free and return it to a quiescent state.
@@ -104,10 +115,7 @@ void reset_pin_number(uint8_t pin_number) {
104
115
105
116
#ifdef SPEAKER_ENABLE_PIN
106
117
if (pin_number == SPEAKER_ENABLE_PIN -> number ) {
107
- speaker_enable_in_use = false;
108
- common_hal_digitalio_digitalinout_switch_to_output (SPEAKER_ENABLE_PIN , true, DRIVE_MODE_PUSH_PULL );
109
- nrf_gpio_pin_dir_set (pin_number , NRF_GPIO_PIN_DIR_OUTPUT );
110
- nrf_gpio_pin_write (pin_number , false);
118
+ reset_speaker_enable_pin ();
111
119
}
112
120
#endif
113
121
}
0 commit comments