2525 */
2626
2727#include "shared-bindings/microcontroller/Pin.h"
28+ #include "shared-bindings/digitalio/DigitalInOut.h"
2829
2930#include "nrf_gpio.h"
3031#include "py/mphal.h"
@@ -47,6 +48,19 @@ bool speaker_enable_in_use;
4748STATIC uint32_t claimed_pins [GPIO_COUNT ];
4849STATIC uint32_t never_reset_pins [GPIO_COUNT ];
4950
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+
5064void reset_all_pins (void ) {
5165 for (size_t i = 0 ; i < GPIO_COUNT ; i ++ ) {
5266 claimed_pins [i ] = never_reset_pins [i ];
@@ -68,10 +82,7 @@ void reset_all_pins(void) {
6882 #endif
6983
7084 // 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 ();
7586}
7687
7788// Mark pin as free and return it to a quiescent state.
@@ -104,10 +115,7 @@ void reset_pin_number(uint8_t pin_number) {
104115
105116 #ifdef SPEAKER_ENABLE_PIN
106117 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 ();
111119 }
112120 #endif
113121}
0 commit comments