Skip to content

Commit 6499d18

Browse files
committed
Remove board_deep_sleep_hook, which should be done in board_deinit.
1 parent 623bf65 commit 6499d18

File tree

4 files changed

+20
-47
lines changed

4 files changed

+20
-47
lines changed

ports/atmel-samd/boards/seeeduino_wio_terminal/board.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include "shared-module/displayio/__init__.h"
3333
#include "shared-module/displayio/mipi_constants.h"
3434
#include "shared-bindings/digitalio/DigitalInOut.h"
35-
#include "common-hal/alarm/__init__.h"
3635

3736
displayio_fourwire_obj_t board_display_obj;
3837
digitalio_digitalinout_obj_t CTR_5V;
@@ -52,7 +51,7 @@ uint8_t display_init_sequence[] = {
5251
0xc1, 0x01, 0x10, // Power control SAP[2:0];BT[3:0]
5352
0xc5, 0x02, 0x3e, 0x28, // VCM control
5453
0xc7, 0x01, 0x86, // VCM control2
55-
0x36, 0x01, 0x38, // Memory Access Control
54+
0x36, 0x01, 0xe8, // Memory Access Control
5655
0x37, 0x01, 0x00, // Vertical scroll zero
5756
0x3a, 0x01, 0x55, // COLMOD: Pixel Format Set
5857
0xb1, 0x02, 0x00, 0x18, // Frame Rate Control (In Normal Mode/Full Colors)
@@ -89,7 +88,7 @@ void board_init(void) {
8988
240, // Height
9089
0, // column start
9190
0, // row start
92-
180, // rotation
91+
0, // rotation
9392
16, // Color depth
9493
false, // Grayscale
9594
false, // pixels in a byte share a row. Only valid for depths < 8
@@ -130,6 +129,8 @@ void board_init(void) {
130129
common_hal_digitalio_digitalinout_never_reset(&CTR_3V3);
131130
common_hal_digitalio_digitalinout_never_reset(&USB_HOST_ENABLE);
132131

132+
// reset pin after fake deep sleep
133+
reset_pin_number(pin_PA18.number);
133134
}
134135

135136
bool board_requests_safe_mode(void) {
@@ -144,10 +145,8 @@ void board_deinit(void) {
144145
common_hal_digitalio_digitalinout_deinit(&CTR_5V);
145146
common_hal_digitalio_digitalinout_deinit(&CTR_3V3);
146147
common_hal_digitalio_digitalinout_deinit(&USB_HOST_ENABLE);
147-
}
148148

149-
void board_deep_sleep_hook(void) {
150-
// Pins are reset before entering deep sleep in cleanup_after_vm()
151-
// This hook turn RTL_PWR off
149+
// Turn off RTL8720DN before the deep sleep.
150+
// Pin state is kept during BACKUP sleep.
152151
gpio_set_pin_direction(pin_PA18.number, GPIO_DIRECTION_OUT);
153152
}

ports/atmel-samd/common-hal/alarm/__init__.c

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,10 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj
101101
PM->SLEEPCFG.reg = PM_SLEEPCFG_SLEEPMODE_STANDBY;
102102
while (PM->SLEEPCFG.bit.SLEEPMODE != PM_SLEEPCFG_SLEEPMODE_STANDBY_Val) {
103103
}
104-
// Even though RAMCFG_OFF, SYSRAM seems to be retained. Probably
105-
// because RTC keeps sleepwalking. Anyway, STDBYCFG should be
106-
// left intact as 0 to retain SYSRAM.
107-
#if 0
108-
PM->STDBYCFG.reg = PM_STDBYCFG_RAMCFG_OFF;
109-
#endif
104+
// STDBYCFG is left to be 0 to retain SYSRAM. Note that, even if
105+
// RAMCFG_OFF is set here, SYSRAM seems to be retained, probably
106+
// because RTC and/or USB keeps sleepwalking.
107+
110108
while (!mp_hal_is_interrupted()) {
111109
RUN_BACKGROUND_TASKS;
112110
// Detect if interrupt was alarm or ctrl-C interrupt.
@@ -153,11 +151,6 @@ void NORETURN common_hal_alarm_enter_deep_sleep(void) {
153151
alarm_time_timealarm_prepare_for_deep_sleep();
154152
// port_disable_tick(); // TODO: Required for SAMD?
155153

156-
// Set pin state before the deep sleep, to turn off devices and reduce power.
157-
// In case of Wio Terminal, set PA18 to 0 to turn off RTL8720DN.
158-
// Pin state is kept during BACKUP sleep.
159-
board_deep_sleep_hook();
160-
161154
// cache alarm flag and etc since RTC about to be reset
162155
uint32_t _flag = SAMD_ALARM_FLAG; // RTC->MODE0.BKUP[0].reg
163156
uint32_t _target = RTC->MODE0.COMP[1].reg;
@@ -193,13 +186,7 @@ void NORETURN common_hal_alarm_enter_deep_sleep(void) {
193186
// Enable interrupts
194187
common_hal_mcu_enable_interrupts();
195188

196-
// Set-up Deep Sleep Mode & RAM retention
197-
// Left BRAMCFG untouched as 0
198-
#if 0
199-
PM->BKUPCFG.reg = PM_BKUPCFG_BRAMCFG(0x2); // No RAM retention 0x2 partial:0x1
200-
while (PM->BKUPCFG.bit.BRAMCFG != 0x2) { // Wait for synchronization
201-
}
202-
#endif
189+
// Set-up Deep Sleep Mode with backup RAM retention
203190
PM->SLEEPCFG.reg = PM_SLEEPCFG_SLEEPMODE_BACKUP;
204191
while (PM->SLEEPCFG.bit.SLEEPMODE != PM_SLEEPCFG_SLEEPMODE_BACKUP_Val) {
205192
}
@@ -216,24 +203,10 @@ void NORETURN common_hal_alarm_enter_deep_sleep(void) {
216203
}
217204
}
218205

219-
// In case of fake deep sleep, event loop is mostly managed in main.c.
220-
// Default common_hal_alarm_pretending_deep_sleep is defined in shared-bindings.
221-
// Note that "pretending" does not work on REPL; it only works for main.py (or code.py, ...).
222-
//
223-
// In case of fake sleep, if pin state is modified in the hook, the pin is left dirty...
224-
#if 0
225-
void common_hal_alarm_pretending_deep_sleep(void) {
226-
// RTC is already be furnished by common_hal_alarm_set_deep_sleep_alarms.
227-
// fake_sleep = true;
228-
229-
board_deep_sleep_hook();
230-
port_idle_until_interrupt();
231-
}
232-
#endif
206+
// Default common_hal_alarm_pretending_deep_sleep is defined in
207+
// shared-bindings, which is used here. Note that "pretending" does
208+
// not work on REPL; it only works for main.py (or code.py, ...).
233209

234210
void common_hal_alarm_gc_collect(void) {
235211
gc_collect_ptr(shared_alarm_get_wake_alarm());
236212
}
237-
238-
MP_WEAK void board_deep_sleep_hook(void) {
239-
}

ports/atmel-samd/common-hal/alarm/__init__.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,4 @@ extern void alarm_set_wakeup_reason(samd_sleep_source_t reason);
5757
void alarm_get_wakeup_cause(void);
5858
extern void alarm_reset(void);
5959

60-
extern void board_deep_sleep_hook(void);
6160
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ALARM__INIT__H

ports/atmel-samd/common-hal/alarm/pin/PinAlarm.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,14 @@ void alarm_pin_pinalarm_reset(void) {
171171
static void pinalarm_set_alarms_light(size_t n_alarms, const mp_obj_t *alarms) {
172172
int err = PINALARM_NOERR;
173173
size_t i;
174+
const mcu_pin_obj_t *pin;
174175

175176
for (i = 0; i < n_alarms; i++) {
176177
if (!mp_obj_is_type(alarms[i], &alarm_pin_pinalarm_type)) {
177178
continue;
178179
}
179180
alarm_pin_pinalarm_obj_t *alarm = MP_OBJ_TO_PTR(alarms[i]);
180-
const mcu_pin_obj_t *pin = alarm->pin;
181+
pin = alarm->pin;
181182

182183
if (!pin_number_is_free(pin->number)) {
183184
err = PINALARM_ERR_NOT_FREE;
@@ -229,14 +230,15 @@ static void pinalarm_set_alarms_light(size_t n_alarms, const mp_obj_t *alarms) {
229230

230231
switch (err) {
231232
case PINALARM_ERR_NOT_FREE:
232-
mp_raise_RuntimeError(translate("Pin is not free"));
233-
;
233+
assert_pin_free(pin);
234+
// raise ValueError here
235+
MP_FALLTHROUGH
234236
case PINALARM_ERR_NOEXTINT:
235237
mp_raise_RuntimeError(translate("No hardware support on pin"));
236238
case PINALARM_ERR_NOCHANNEL:
237239
mp_raise_RuntimeError(translate("A hardware interrupt channel is already in use"));
238240
default:
239-
mp_raise_RuntimeError(translate("Unknown error"));
241+
mp_raise_RuntimeError(translate("Unknown reason."));
240242
}
241243
}
242244

0 commit comments

Comments
 (0)