Initial Sleep Support
This commit is contained in:
parent
557a58b244
commit
90b9ec6f2c
@ -41,6 +41,8 @@
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
||||
#include "esp_sleep.h"
|
||||
|
||||
void common_hal_mcu_delay_us(uint32_t delay) {
|
||||
|
||||
}
|
||||
@ -77,6 +79,10 @@ void common_hal_mcu_reset(void) {
|
||||
while(1);
|
||||
}
|
||||
|
||||
void common_hal_mcu_sleep(void) {
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
// The singleton microcontroller.Processor object, bound to microcontroller.cpu
|
||||
// It currently only has properties, and no state.
|
||||
const mcu_processor_obj_t common_hal_mcu_processor_obj = {
|
||||
|
10
ports/esp32s2/common-hal/timealarm/__init__.c
Normal file
10
ports/esp32s2/common-hal/timealarm/__init__.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include "esp_sleep.h"
|
||||
|
||||
#include "shared-bindings/timealarm/__init__.h"
|
||||
|
||||
void common_hal_timealarm_duration (uint32_t ms) {
|
||||
if (esp_sleep_enable_timer_wakeup((ms) * 1000) == ESP_ERR_INVALID_ARG) {
|
||||
mp_raise_ValueError(translate("time out of range"));
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ CIRCUITPY_FREQUENCYIO = 0
|
||||
CIRCUITPY_I2CPERIPHERAL = 0
|
||||
CIRCUITPY_ROTARYIO = 0
|
||||
CIRCUITPY_NVM = 0
|
||||
CIRCUITPY_TIMEALARM = 1
|
||||
# We don't have enough endpoints to include MIDI.
|
||||
CIRCUITPY_USB_MIDI = 0
|
||||
CIRCUITPY_WIFI = 1
|
||||
|
@ -259,6 +259,9 @@ endif
|
||||
ifeq ($(CIRCUITPY_TIME),1)
|
||||
SRC_PATTERNS += time/%
|
||||
endif
|
||||
ifeq ($(CIRCUITPY_TIMEALARM),1)
|
||||
SRC_PATTERNS += timealarm/%
|
||||
endif
|
||||
ifeq ($(CIRCUITPY_TOUCHIO),1)
|
||||
SRC_PATTERNS += touchio/%
|
||||
endif
|
||||
@ -360,6 +363,7 @@ SRC_COMMON_HAL_ALL = \
|
||||
ssl/SSLContext.c \
|
||||
supervisor/Runtime.c \
|
||||
supervisor/__init__.c \
|
||||
timealarm/__init__.c \
|
||||
watchdog/WatchDogMode.c \
|
||||
watchdog/WatchDogTimer.c \
|
||||
watchdog/__init__.c \
|
||||
|
@ -663,6 +663,13 @@ extern const struct _mp_obj_module_t time_module;
|
||||
#define TIME_MODULE_ALT_NAME
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_TIMEALARM
|
||||
extern const struct _mp_obj_module_t timealarm_module;
|
||||
#define TIMEALARM_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_timealarm), (mp_obj_t)&timealarm_module },
|
||||
#else
|
||||
#define TIMEALARM_MODULE
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_TOUCHIO
|
||||
extern const struct _mp_obj_module_t touchio_module;
|
||||
#define TOUCHIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_touchio), (mp_obj_t)&touchio_module },
|
||||
@ -821,6 +828,7 @@ extern const struct _mp_obj_module_t wifi_module;
|
||||
STRUCT_MODULE \
|
||||
SUPERVISOR_MODULE \
|
||||
TOUCHIO_MODULE \
|
||||
TIMEALARM_MODULE \
|
||||
UHEAP_MODULE \
|
||||
USB_HID_MODULE \
|
||||
USB_MIDI_MODULE \
|
||||
|
@ -234,6 +234,9 @@ CFLAGS += -DCIRCUITPY_TERMINALIO=$(CIRCUITPY_TERMINALIO)
|
||||
CIRCUITPY_TIME ?= 1
|
||||
CFLAGS += -DCIRCUITPY_TIME=$(CIRCUITPY_TIME)
|
||||
|
||||
CIRCUITPY_TIMEALARM ?= 0
|
||||
CFLAGS += -DCIRCUITPY_TIMEALARM=$(CIRCUITPY_TIMEALARM)
|
||||
|
||||
# touchio might be native or generic. See circuitpy_defns.mk.
|
||||
CIRCUITPY_TOUCHIO_USE_NATIVE ?= 0
|
||||
CFLAGS += -DCIRCUITPY_TOUCHIO_USE_NATIVE=$(CIRCUITPY_TOUCHIO_USE_NATIVE)
|
||||
|
@ -136,6 +136,22 @@ STATIC mp_obj_t mcu_reset(void) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mcu_reset_obj, mcu_reset);
|
||||
|
||||
//| def sleep() -> None:
|
||||
//| """Microcontroller will go into deep sleep.
|
||||
//| cpy will restart when wakeup func. is triggered`.
|
||||
//|
|
||||
//| .. warning:: This may result in file system corruption when connected to a
|
||||
//| host computer. Be very careful when calling this! Make sure the device
|
||||
//| "Safely removed" on Windows or "ejected" on Mac OSX and Linux."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t mcu_sleep(void) {
|
||||
common_hal_mcu_sleep();
|
||||
// We won't actually get here because mcu is going into sleep.
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mcu_sleep_obj, mcu_sleep);
|
||||
|
||||
//| nvm: Optional[ByteArray]
|
||||
//| """Available non-volatile memory.
|
||||
//| This object is the sole instance of `nvm.ByteArray` when available or ``None`` otherwise.
|
||||
@ -171,6 +187,7 @@ STATIC const mp_rom_map_elem_t mcu_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_enable_interrupts), MP_ROM_PTR(&mcu_enable_interrupts_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_on_next_reset), MP_ROM_PTR(&mcu_on_next_reset_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&mcu_reset_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mcu_sleep_obj) },
|
||||
#if CIRCUITPY_INTERNAL_NVM_SIZE > 0
|
||||
{ MP_ROM_QSTR(MP_QSTR_nvm), MP_ROM_PTR(&common_hal_mcu_nvm_obj) },
|
||||
#else
|
||||
|
@ -43,6 +43,8 @@ extern void common_hal_mcu_enable_interrupts(void);
|
||||
extern void common_hal_mcu_on_next_reset(mcu_runmode_t runmode);
|
||||
extern void common_hal_mcu_reset(void);
|
||||
|
||||
extern void common_hal_mcu_sleep(void);
|
||||
|
||||
extern const mp_obj_dict_t mcu_pin_globals;
|
||||
|
||||
extern const mcu_processor_obj_t common_hal_mcu_processor_obj;
|
||||
|
31
shared-bindings/timealarm/__init__.c
Normal file
31
shared-bindings/timealarm/__init__.c
Normal file
@ -0,0 +1,31 @@
|
||||
#include "py/obj.h"
|
||||
#include "shared-bindings/timealarm/__init__.h"
|
||||
|
||||
//| Set Timer Wakeup
|
||||
//|
|
||||
STATIC mp_obj_t timealarm_duration(mp_obj_t seconds_o) {
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
mp_float_t seconds = mp_obj_get_float(seconds_o);
|
||||
mp_float_t msecs = 1000.0f * seconds + 0.5f;
|
||||
#else
|
||||
mp_int_t seconds = mp_obj_get_int(seconds_o);
|
||||
mp_int_t msecs = 1000 * seconds;
|
||||
#endif
|
||||
if (seconds < 0) {
|
||||
mp_raise_ValueError(translate("sleep length must be non-negative"));
|
||||
}
|
||||
common_hal_timealarm_duration(msecs);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(timealarm_duration_obj, timealarm_duration);
|
||||
|
||||
STATIC const mp_rom_map_elem_t timealarm_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_timealarm) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_duration), MP_ROM_PTR(&timealarm_duration_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(timealarm_module_globals, timealarm_module_globals_table);
|
||||
|
||||
const mp_obj_module_t timealarm_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&timealarm_module_globals,
|
||||
};
|
8
shared-bindings/timealarm/__init__.h
Normal file
8
shared-bindings/timealarm/__init__.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ulp___INIT___H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_ulp___INIT___H
|
||||
|
||||
#include "py/runtime.h"
|
||||
|
||||
extern void common_hal_timealarm_duration(uint32_t);
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user