Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
nRF: Handle SPEAKER_ENABLE_PIN
.. the existing code, which was never activated by the preprocessor,
wasn't quite right.
  • Loading branch information
jepler committed Nov 1, 2019
commit fe47eba97fffb6a689592158bf6f97959c2ec798
24 changes: 16 additions & 8 deletions ports/nrf/common-hal/microcontroller/Pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/

#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/digitalio/DigitalInOut.h"

#include "nrf_gpio.h"
#include "py/mphal.h"
Expand All @@ -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];
Expand All @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down