aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Halbert <halbert@adafruit.com>2019-11-03 18:34:29 -0500
committerGitHub <noreply@github.com>2019-11-03 18:34:29 -0500
commite3638ffaad1a77687082770c1da935b9b3ddcc01 (patch)
tree69d3b0b8591bdbfc8f3c74893b3b1c4afa87d4c9
parentcd3fcc87abd730e12ae63e1d4e84419ebb3fedd7 (diff)
parent2bdccf03a722fc1bdb0434e96361d3d8acd0ca09 (diff)
Merge pull request #2262 from jepler/cpb-speaker-disable5.0.0-alpha.5
cpb: Disable the onboard speaker until request
-rw-r--r--ports/nrf/boards/circuitplayground_bluefruit/mpconfigboard.h2
-rw-r--r--ports/nrf/common-hal/microcontroller/Pin.c24
2 files changed, 18 insertions, 8 deletions
diff --git a/ports/nrf/boards/circuitplayground_bluefruit/mpconfigboard.h b/ports/nrf/boards/circuitplayground_bluefruit/mpconfigboard.h
index 66e06417a..4e37eae0a 100644
--- a/ports/nrf/boards/circuitplayground_bluefruit/mpconfigboard.h
+++ b/ports/nrf/boards/circuitplayground_bluefruit/mpconfigboard.h
@@ -69,3 +69,5 @@
#define DEFAULT_UART_BUS_RX (&pin_P0_30)
#define DEFAULT_UART_BUS_TX (&pin_P0_14)
+
+#define SPEAKER_ENABLE_PIN (&pin_P1_04)
diff --git a/ports/nrf/common-hal/microcontroller/Pin.c b/ports/nrf/common-hal/microcontroller/Pin.c
index b2f065a08..ce55317e5 100644
--- a/ports/nrf/common-hal/microcontroller/Pin.c
+++ b/ports/nrf/common-hal/microcontroller/Pin.c
@@ -25,6 +25,7 @@
*/
#include "shared-bindings/microcontroller/Pin.h"
+#include "shared-bindings/digitalio/DigitalInOut.h"
#include "nrf_gpio.h"
#include "py/mphal.h"
@@ -47,6 +48,19 @@ bool speaker_enable_in_use;
STATIC uint32_t claimed_pins[GPIO_COUNT];
STATIC uint32_t never_reset_pins[GPIO_COUNT];
+STATIC void reset_speaker_enable_pin(void) {
+#ifdef SPEAKER_ENABLE_PIN
+ speaker_enable_in_use = false;
+ nrf_gpio_cfg(SPEAKER_ENABLE_PIN->number,
+ NRF_GPIO_PIN_DIR_OUTPUT,
+ NRF_GPIO_PIN_INPUT_DISCONNECT,
+ NRF_GPIO_PIN_NOPULL,
+ NRF_GPIO_PIN_H0H1,
+ NRF_GPIO_PIN_NOSENSE);
+ nrf_gpio_pin_write(SPEAKER_ENABLE_PIN->number, false);
+#endif
+}
+
void reset_all_pins(void) {
for (size_t i = 0; i < GPIO_COUNT; i++) {
claimed_pins[i] = never_reset_pins[i];
@@ -68,10 +82,7 @@ void reset_all_pins(void) {
#endif
// After configuring SWD because it may be shared.
- #ifdef SPEAKER_ENABLE_PIN
- speaker_enable_in_use = false;
- // TODO set pin to out and turn off.
- #endif
+ reset_speaker_enable_pin();
}
// Mark pin as free and return it to a quiescent state.
@@ -104,10 +115,7 @@ void reset_pin_number(uint8_t pin_number) {
#ifdef SPEAKER_ENABLE_PIN
if (pin_number == SPEAKER_ENABLE_PIN->number) {
- speaker_enable_in_use = false;
- common_hal_digitalio_digitalinout_switch_to_output(SPEAKER_ENABLE_PIN, true, DRIVE_MODE_PUSH_PULL);
- nrf_gpio_pin_dir_set(pin_number, NRF_GPIO_PIN_DIR_OUTPUT);
- nrf_gpio_pin_write(pin_number, false);
+ reset_speaker_enable_pin();
}
#endif
}