some cleanups.

This commit is contained in:
jun2sak 2021-02-21 09:57:14 +09:00
parent d659c2ce34
commit 36c59250dd
2 changed files with 107 additions and 102 deletions

View File

@ -51,7 +51,8 @@
#include "nrfx.h"
#include "nrfx_gpiote.h"
#if 0
// XXX
#define DEBUG_LED_PIN (NRF_GPIO_PIN_MAP(1, 11)) // P1_11 = LED
void _debug_led_init(void) {
nrf_gpio_cfg_output(DEBUG_LED_PIN);
@ -59,7 +60,7 @@ void _debug_led_init(void) {
void _debug_led_set(int v) {
nrf_gpio_pin_write(DEBUG_LED_PIN, v);
}
#endif
// Singleton instance of SleepMemory.
const alarm_sleep_memory_obj_t alarm_sleep_memory_obj = {
@ -84,10 +85,10 @@ STATIC nrf_sleep_source_t _get_wakeup_cause(void) {
return NRF_SLEEP_WAKEUP_TIMER;
}
#if 0
// XXX not implemented yet
if (alarm_touch_touchalarm_woke_us_up()) {
return ESP_SLEEP_WAKEUP_TOUCHPAD;
}
return esp_sleep_get_wakeup_cause();
#endif
if (reset_reason_saved & NRF_POWER_RESETREAS_RESETPIN_MASK) {
return NRF_SLEEP_WAKEUP_RESETPIN;
@ -154,6 +155,7 @@ STATIC void _setup_sleep_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t
alarm_pin_pinalarm_set_alarms(deep_sleep, n_alarms, alarms);
alarm_time_timealarm_set_alarms(deep_sleep, n_alarms, alarms);
#if 0
// XXX not implemented yet
alarm_touch_touchalarm_set_alarm(deep_sleep, n_alarms, alarms);
#endif
}
@ -213,7 +215,7 @@ void common_hal_alarm_set_deep_sleep_alarms(size_t n_alarms, const mp_obj_t *ala
void NORETURN alarm_enter_deep_sleep(void) {
alarm_pin_pinalarm_prepare_for_deep_sleep();
//alarm_touch_touchalarm_prepare_for_deep_sleep();
//alarm_touch_touchalarm_prepare_for_deep_sleep(); // XXX
uint8_t sd_enabled;
sd_softdevice_is_enabled(&sd_enabled);

View File

@ -136,7 +136,15 @@ void alarm_pin_pinalarm_reset(void) {
pull_pins = 0;
}
void _setup2(void) {
static void setup_pin1_for_lightsleep(void) {
if ( nrfx_gpiote_is_init() ) {
nrfx_gpiote_uninit();
}
nrfx_gpiote_init(NRFX_GPIOTE_CONFIG_IRQ_PRIORITY);
_pinhandler_gpiote_count = 0;
_pinhandler_ev_pin = MYGPIOTE_EV_PIN_UNDEF;
nrfx_gpiote_in_config_t cfg = {
.sense = NRF_GPIOTE_POLARITY_TOGGLE,
.pull = NRF_GPIO_PIN_PULLUP,
@ -155,7 +163,8 @@ void _setup2(void) {
}
if (((high_alarms & mask) != 0) && ((low_alarms & mask) == 0)) {
cfg.sense = NRF_GPIOTE_POLARITY_LOTOHI;
cfg.pull = ((pull_pins & mask) != 0) ? NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_NOPULL;
cfg.pull = ((pull_pins & mask) != 0) ?
NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_NOPULL;
#ifdef MY_DEBUGUART
pull = -1; sense = 1;
#endif
@ -163,7 +172,8 @@ void _setup2(void) {
else
if (((high_alarms & mask) == 0) && ((low_alarms & mask) != 0)) {
cfg.sense = NRF_GPIOTE_POLARITY_HITOLO;
cfg.pull = ((pull_pins & mask) != 0) ? NRF_GPIO_PIN_PULLUP : NRF_GPIO_PIN_NOPULL;
cfg.pull = ((pull_pins & mask) != 0) ?
NRF_GPIO_PIN_PULLUP : NRF_GPIO_PIN_NOPULL;
#ifdef MY_DEBUGUART
pull = 1; sense = -1;
#endif
@ -175,7 +185,8 @@ void _setup2(void) {
sense = 9;
#endif
}
nrfx_gpiote_in_init((nrfx_gpiote_pin_t)i, &cfg, pinalarm_gpiote_handler);
nrfx_gpiote_in_init((nrfx_gpiote_pin_t)i, &cfg,
pinalarm_gpiote_handler);
nrfx_gpiote_in_event_enable((nrfx_gpiote_pin_t)i, true);
#ifdef MY_DEBUGUART
dbg_printf("pin=%d, sense=%d, pull=%d\r\n", i, sense, pull);
@ -183,18 +194,7 @@ void _setup2(void) {
}
}
void _setup_pin1_for_lightsleep(void) {
if ( nrfx_gpiote_is_init() ) {
nrfx_gpiote_uninit();
}
nrfx_gpiote_init(NRFX_GPIOTE_CONFIG_IRQ_PRIORITY);
_pinhandler_gpiote_count = 0;
_pinhandler_ev_pin = MYGPIOTE_EV_PIN_UNDEF;
_setup2();
}
void _setup_pin1_for_deepsleep(void) {
static void setup_pin1_for_deepsleep(void) {
for(size_t i = 0; i < 64; ++i) {
uint64_t mask = 1ull << i;
int pull = 0;
@ -205,7 +205,8 @@ void _setup_pin1_for_deepsleep(void) {
continue;
}
if (((high_alarms & mask) != 0) && ((low_alarms & mask) == 0)) {
pull = ((pull_pins & mask) != 0) ? NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_NOPULL;
pull = ((pull_pins & mask) != 0) ?
NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_NOPULL;
nrf_gpio_cfg_input((uint32_t)i, (nrf_gpio_pin_pull_t)pull);
nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_HIGH);
#ifdef MY_DEBUGUART
@ -214,7 +215,8 @@ void _setup_pin1_for_deepsleep(void) {
}
else
if (((high_alarms & mask) == 0) && ((low_alarms & mask) != 0)) {
pull = ((pull_pins & mask) != 0) ? NRF_GPIO_PIN_PULLUP : NRF_GPIO_PIN_NOPULL;
pull = ((pull_pins & mask) != 0) ?
NRF_GPIO_PIN_PULLUP : NRF_GPIO_PIN_NOPULL;
nrf_gpio_cfg_input((uint32_t)i, (nrf_gpio_pin_pull_t)pull);
nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_LOW);
#ifdef MY_DEBUGUART
@ -262,10 +264,11 @@ void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ob
}
if (pin_number != -1) {
if (!deep_sleep) {
_setup_pin1_for_lightsleep();
setup_pin1_for_lightsleep();
}
else {
//_setup_pin1_for_deepsleep(pin_number);
// we don't setup gpio HW here but do them in
// alarm_pin_pinalarm_prepare_for_deep_sleep() below
}
}
else {
@ -274,5 +277,5 @@ void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ob
}
void alarm_pin_pinalarm_prepare_for_deep_sleep(void) {
_setup_pin1_for_deepsleep();
setup_pin1_for_deepsleep();
}