Merge pull request #2262 from jepler/cpb-speaker-disable

cpb: Disable the onboard speaker until request
This commit is contained in:
Dan Halbert 2019-11-03 18:34:29 -05:00 committed by GitHub
commit e3638ffaad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 8 deletions

View File

@ -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)

View File

@ -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
}