Remove board_deep_sleep_hook, which should be done in board_deinit.

This commit is contained in:
Tsutomu IKEGAMI 2022-02-21 19:21:42 +09:00
parent 623bf659a5
commit 6499d18bb8
4 changed files with 20 additions and 47 deletions

View File

@ -32,7 +32,6 @@
#include "shared-module/displayio/__init__.h"
#include "shared-module/displayio/mipi_constants.h"
#include "shared-bindings/digitalio/DigitalInOut.h"
#include "common-hal/alarm/__init__.h"
displayio_fourwire_obj_t board_display_obj;
digitalio_digitalinout_obj_t CTR_5V;
@ -52,7 +51,7 @@ uint8_t display_init_sequence[] = {
0xc1, 0x01, 0x10, // Power control SAP[2:0];BT[3:0]
0xc5, 0x02, 0x3e, 0x28, // VCM control
0xc7, 0x01, 0x86, // VCM control2
0x36, 0x01, 0x38, // Memory Access Control
0x36, 0x01, 0xe8, // Memory Access Control
0x37, 0x01, 0x00, // Vertical scroll zero
0x3a, 0x01, 0x55, // COLMOD: Pixel Format Set
0xb1, 0x02, 0x00, 0x18, // Frame Rate Control (In Normal Mode/Full Colors)
@ -89,7 +88,7 @@ void board_init(void) {
240, // Height
0, // column start
0, // row start
180, // rotation
0, // rotation
16, // Color depth
false, // Grayscale
false, // pixels in a byte share a row. Only valid for depths < 8
@ -130,6 +129,8 @@ void board_init(void) {
common_hal_digitalio_digitalinout_never_reset(&CTR_3V3);
common_hal_digitalio_digitalinout_never_reset(&USB_HOST_ENABLE);
// reset pin after fake deep sleep
reset_pin_number(pin_PA18.number);
}
bool board_requests_safe_mode(void) {
@ -144,10 +145,8 @@ void board_deinit(void) {
common_hal_digitalio_digitalinout_deinit(&CTR_5V);
common_hal_digitalio_digitalinout_deinit(&CTR_3V3);
common_hal_digitalio_digitalinout_deinit(&USB_HOST_ENABLE);
}
void board_deep_sleep_hook(void) {
// Pins are reset before entering deep sleep in cleanup_after_vm()
// This hook turn RTL_PWR off
// Turn off RTL8720DN before the deep sleep.
// Pin state is kept during BACKUP sleep.
gpio_set_pin_direction(pin_PA18.number, GPIO_DIRECTION_OUT);
}

View File

@ -101,12 +101,10 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj
PM->SLEEPCFG.reg = PM_SLEEPCFG_SLEEPMODE_STANDBY;
while (PM->SLEEPCFG.bit.SLEEPMODE != PM_SLEEPCFG_SLEEPMODE_STANDBY_Val) {
}
// Even though RAMCFG_OFF, SYSRAM seems to be retained. Probably
// because RTC keeps sleepwalking. Anyway, STDBYCFG should be
// left intact as 0 to retain SYSRAM.
#if 0
PM->STDBYCFG.reg = PM_STDBYCFG_RAMCFG_OFF;
#endif
// STDBYCFG is left to be 0 to retain SYSRAM. Note that, even if
// RAMCFG_OFF is set here, SYSRAM seems to be retained, probably
// because RTC and/or USB keeps sleepwalking.
while (!mp_hal_is_interrupted()) {
RUN_BACKGROUND_TASKS;
// Detect if interrupt was alarm or ctrl-C interrupt.
@ -153,11 +151,6 @@ void NORETURN common_hal_alarm_enter_deep_sleep(void) {
alarm_time_timealarm_prepare_for_deep_sleep();
// port_disable_tick(); // TODO: Required for SAMD?
// Set pin state before the deep sleep, to turn off devices and reduce power.
// In case of Wio Terminal, set PA18 to 0 to turn off RTL8720DN.
// Pin state is kept during BACKUP sleep.
board_deep_sleep_hook();
// cache alarm flag and etc since RTC about to be reset
uint32_t _flag = SAMD_ALARM_FLAG; // RTC->MODE0.BKUP[0].reg
uint32_t _target = RTC->MODE0.COMP[1].reg;
@ -193,13 +186,7 @@ void NORETURN common_hal_alarm_enter_deep_sleep(void) {
// Enable interrupts
common_hal_mcu_enable_interrupts();
// Set-up Deep Sleep Mode & RAM retention
// Left BRAMCFG untouched as 0
#if 0
PM->BKUPCFG.reg = PM_BKUPCFG_BRAMCFG(0x2); // No RAM retention 0x2 partial:0x1
while (PM->BKUPCFG.bit.BRAMCFG != 0x2) { // Wait for synchronization
}
#endif
// Set-up Deep Sleep Mode with backup RAM retention
PM->SLEEPCFG.reg = PM_SLEEPCFG_SLEEPMODE_BACKUP;
while (PM->SLEEPCFG.bit.SLEEPMODE != PM_SLEEPCFG_SLEEPMODE_BACKUP_Val) {
}
@ -216,24 +203,10 @@ void NORETURN common_hal_alarm_enter_deep_sleep(void) {
}
}
// In case of fake deep sleep, event loop is mostly managed in main.c.
// Default common_hal_alarm_pretending_deep_sleep is defined in shared-bindings.
// Note that "pretending" does not work on REPL; it only works for main.py (or code.py, ...).
//
// In case of fake sleep, if pin state is modified in the hook, the pin is left dirty...
#if 0
void common_hal_alarm_pretending_deep_sleep(void) {
// RTC is already be furnished by common_hal_alarm_set_deep_sleep_alarms.
// fake_sleep = true;
board_deep_sleep_hook();
port_idle_until_interrupt();
}
#endif
// Default common_hal_alarm_pretending_deep_sleep is defined in
// shared-bindings, which is used here. Note that "pretending" does
// not work on REPL; it only works for main.py (or code.py, ...).
void common_hal_alarm_gc_collect(void) {
gc_collect_ptr(shared_alarm_get_wake_alarm());
}
MP_WEAK void board_deep_sleep_hook(void) {
}

View File

@ -57,5 +57,4 @@ extern void alarm_set_wakeup_reason(samd_sleep_source_t reason);
void alarm_get_wakeup_cause(void);
extern void alarm_reset(void);
extern void board_deep_sleep_hook(void);
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ALARM__INIT__H

View File

@ -171,13 +171,14 @@ void alarm_pin_pinalarm_reset(void) {
static void pinalarm_set_alarms_light(size_t n_alarms, const mp_obj_t *alarms) {
int err = PINALARM_NOERR;
size_t i;
const mcu_pin_obj_t *pin;
for (i = 0; i < n_alarms; i++) {
if (!mp_obj_is_type(alarms[i], &alarm_pin_pinalarm_type)) {
continue;
}
alarm_pin_pinalarm_obj_t *alarm = MP_OBJ_TO_PTR(alarms[i]);
const mcu_pin_obj_t *pin = alarm->pin;
pin = alarm->pin;
if (!pin_number_is_free(pin->number)) {
err = PINALARM_ERR_NOT_FREE;
@ -229,14 +230,15 @@ static void pinalarm_set_alarms_light(size_t n_alarms, const mp_obj_t *alarms) {
switch (err) {
case PINALARM_ERR_NOT_FREE:
mp_raise_RuntimeError(translate("Pin is not free"));
;
assert_pin_free(pin);
// raise ValueError here
MP_FALLTHROUGH
case PINALARM_ERR_NOEXTINT:
mp_raise_RuntimeError(translate("No hardware support on pin"));
case PINALARM_ERR_NOCHANNEL:
mp_raise_RuntimeError(translate("A hardware interrupt channel is already in use"));
default:
mp_raise_RuntimeError(translate("Unknown error"));
mp_raise_RuntimeError(translate("Unknown reason."));
}
}