Skip to content

Commit e3638ff

Browse files
authored
Merge pull request #2262 from jepler/cpb-speaker-disable
cpb: Disable the onboard speaker until request
2 parents cd3fcc8 + 2bdccf0 commit e3638ff

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

ports/nrf/boards/circuitplayground_bluefruit/mpconfigboard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,5 @@
6969

7070
#define DEFAULT_UART_BUS_RX (&pin_P0_30)
7171
#define DEFAULT_UART_BUS_TX (&pin_P0_14)
72+
73+
#define SPEAKER_ENABLE_PIN (&pin_P1_04)

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
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;
4748
STATIC uint32_t claimed_pins[GPIO_COUNT];
4849
STATIC 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+
5064
void 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

Comments
 (0)