Get io wake working
This commit is contained in:
parent
3a30887b44
commit
e310b871c8
2
main.c
2
main.c
@ -509,7 +509,7 @@ int __attribute__((used)) main(void) {
|
||||
}
|
||||
if (exit_code == PYEXEC_FORCED_EXIT) {
|
||||
if (!first_run) {
|
||||
serial_write_compressed(translate("\n\n ----- soft reboot -----\n"));
|
||||
serial_write_compressed(translate("\n\n------ soft reboot ------\n"));
|
||||
}
|
||||
first_run = false;
|
||||
skip_repl = run_code_py(safe_mode);
|
||||
|
27
ports/esp32s2/common-hal/io_alarm/__init__.c
Normal file
27
ports/esp32s2/common-hal/io_alarm/__init__.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include "shared-bindings/io_alarm/__init__.h"
|
||||
|
||||
#include "esp_sleep.h"
|
||||
#include "driver/rtc_io.h"
|
||||
|
||||
void common_hal_io_alarm_pin_state (uint8_t gpio, uint8_t level, bool pull) {
|
||||
if (!rtc_gpio_is_valid_gpio(gpio)) {
|
||||
mp_raise_ValueError(translate("io must be rtc io"));
|
||||
return;
|
||||
}
|
||||
|
||||
switch(esp_sleep_enable_ext0_wakeup(gpio, level)) {
|
||||
case ESP_ERR_INVALID_ARG:
|
||||
mp_raise_ValueError(translate("trigger level must be 0 or 1"));
|
||||
return;
|
||||
case ESP_ERR_INVALID_STATE:
|
||||
mp_raise_RuntimeError(translate("wakeup conflict"));
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (pull) {
|
||||
(level) ? rtc_gpio_pulldown_en(gpio) : rtc_gpio_pullup_en(gpio);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "esp_sleep.h"
|
||||
|
||||
#include "shared-bindings/timealarm/__init__.h"
|
||||
#include "shared-bindings/time_alarm/__init__.h"
|
||||
|
||||
void common_hal_timealarm_duration (uint32_t ms) {
|
||||
void common_hal_time_alarm_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,7 +22,8 @@ CIRCUITPY_FREQUENCYIO = 0
|
||||
CIRCUITPY_I2CPERIPHERAL = 0
|
||||
CIRCUITPY_ROTARYIO = 0
|
||||
CIRCUITPY_NVM = 0
|
||||
CIRCUITPY_TIMEALARM = 1
|
||||
CIRCUITPY_TIME_ALARM = 1
|
||||
CIRCUITPY_IO_ALARM = 1
|
||||
# We don't have enough endpoints to include MIDI.
|
||||
CIRCUITPY_USB_MIDI = 0
|
||||
CIRCUITPY_WIFI = 1
|
||||
|
@ -259,8 +259,11 @@ endif
|
||||
ifeq ($(CIRCUITPY_TIME),1)
|
||||
SRC_PATTERNS += time/%
|
||||
endif
|
||||
ifeq ($(CIRCUITPY_TIMEALARM),1)
|
||||
SRC_PATTERNS += timealarm/%
|
||||
ifeq ($(CIRCUITPY_TIME_ALARM),1)
|
||||
SRC_PATTERNS += time_alarm/%
|
||||
endif
|
||||
ifeq ($(CIRCUITPY_IO_ALARM),1)
|
||||
SRC_PATTERNS += io_alarm/%
|
||||
endif
|
||||
ifeq ($(CIRCUITPY_TOUCHIO),1)
|
||||
SRC_PATTERNS += touchio/%
|
||||
@ -363,7 +366,8 @@ SRC_COMMON_HAL_ALL = \
|
||||
ssl/SSLContext.c \
|
||||
supervisor/Runtime.c \
|
||||
supervisor/__init__.c \
|
||||
timealarm/__init__.c \
|
||||
time_alarm/__init__.c \
|
||||
io_alarm/__init__.c \
|
||||
watchdog/WatchDogMode.c \
|
||||
watchdog/WatchDogTimer.c \
|
||||
watchdog/__init__.c \
|
||||
|
@ -663,11 +663,18 @@ 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 },
|
||||
#if CIRCUITPY_TIME_ALARM
|
||||
extern const struct _mp_obj_module_t time_alarm_module;
|
||||
#define TIME_ALARM_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_time_alarm), (mp_obj_t)&time_alarm_module },
|
||||
#else
|
||||
#define TIMEALARM_MODULE
|
||||
#define TIME_ALARM_MODULE
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_IO_ALARM
|
||||
extern const struct _mp_obj_module_t io_alarm_module;
|
||||
#define IO_ALARM_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_io_alarm), (mp_obj_t)&io_alarm_module },
|
||||
#else
|
||||
#define IO_ALARM_MODULE
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_TOUCHIO
|
||||
@ -828,7 +835,8 @@ extern const struct _mp_obj_module_t wifi_module;
|
||||
STRUCT_MODULE \
|
||||
SUPERVISOR_MODULE \
|
||||
TOUCHIO_MODULE \
|
||||
TIMEALARM_MODULE \
|
||||
TIME_ALARM_MODULE \
|
||||
IO_ALARM_MODULE \
|
||||
UHEAP_MODULE \
|
||||
USB_HID_MODULE \
|
||||
USB_MIDI_MODULE \
|
||||
|
@ -234,8 +234,11 @@ CFLAGS += -DCIRCUITPY_TERMINALIO=$(CIRCUITPY_TERMINALIO)
|
||||
CIRCUITPY_TIME ?= 1
|
||||
CFLAGS += -DCIRCUITPY_TIME=$(CIRCUITPY_TIME)
|
||||
|
||||
CIRCUITPY_TIMEALARM ?= 0
|
||||
CFLAGS += -DCIRCUITPY_TIMEALARM=$(CIRCUITPY_TIMEALARM)
|
||||
CIRCUITPY_TIME_ALARM ?= 0
|
||||
CFLAGS += -DCIRCUITPY_TIME_ALARM=$(CIRCUITPY_TIME_ALARM)
|
||||
|
||||
CIRCUITPY_IO_ALARM ?= 0
|
||||
CFLAGS += -DCIRCUITPY_IO_ALARM=$(CIRCUITPY_IO_ALARM)
|
||||
|
||||
# touchio might be native or generic. See circuitpy_defns.mk.
|
||||
CIRCUITPY_TOUCHIO_USE_NATIVE ?= 0
|
||||
|
34
shared-bindings/io_alarm/__init__.c
Normal file
34
shared-bindings/io_alarm/__init__.c
Normal file
@ -0,0 +1,34 @@
|
||||
#include "py/obj.h"
|
||||
|
||||
#include "shared-bindings/io_alarm/__init__.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
|
||||
//| Set Timer Wakeup
|
||||
//|
|
||||
STATIC mp_obj_t io_alarm_pin_state(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_level, ARG_pull };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_level, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
|
||||
{ MP_QSTR_pull, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_bool = false} },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
mcu_pin_obj_t *pin = validate_obj_is_pin(pos_args[0]);
|
||||
common_hal_io_alarm_pin_state(pin->number, args[ARG_level].u_int, args[ARG_pull].u_bool);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(io_alarm_pin_state_obj, 1, io_alarm_pin_state);
|
||||
|
||||
STATIC const mp_rom_map_elem_t io_alarm_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_io_alarm) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_PinState), MP_ROM_PTR(&io_alarm_pin_state_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(io_alarm_module_globals, io_alarm_module_globals_table);
|
||||
|
||||
const mp_obj_module_t io_alarm_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&io_alarm_module_globals,
|
||||
};
|
8
shared-bindings/io_alarm/__init__.h
Normal file
8
shared-bindings/io_alarm/__init__.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_IO_ALARM___INIT___H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_IO_ALARM___INIT___H
|
||||
|
||||
#include "py/runtime.h"
|
||||
|
||||
extern void common_hal_io_alarm_pin_state(uint8_t gpio, uint8_t level, bool pull);
|
||||
|
||||
#endif //MICROPY_INCLUDED_SHARED_BINDINGS_IO_ALARM___INIT___H
|
31
shared-bindings/time_alarm/__init__.c
Normal file
31
shared-bindings/time_alarm/__init__.c
Normal file
@ -0,0 +1,31 @@
|
||||
#include "py/obj.h"
|
||||
#include "shared-bindings/time_alarm/__init__.h"
|
||||
|
||||
//| Set Timer Wakeup
|
||||
//|
|
||||
STATIC mp_obj_t time_alarm_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_time_alarm_duration(msecs);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_alarm_duration_obj, time_alarm_duration);
|
||||
|
||||
STATIC const mp_rom_map_elem_t time_alarm_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_time_alarm) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_Duration), MP_ROM_PTR(&time_alarm_duration_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(time_alarm_module_globals, time_alarm_module_globals_table);
|
||||
|
||||
const mp_obj_module_t time_alarm_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&time_alarm_module_globals,
|
||||
};
|
8
shared-bindings/time_alarm/__init__.h
Normal file
8
shared-bindings/time_alarm/__init__.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_TIME_ALARM___INIT___H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_TIME_ALARM___INIT___H
|
||||
|
||||
#include "py/runtime.h"
|
||||
|
||||
extern void common_hal_time_alarm_duration(uint32_t);
|
||||
|
||||
#endif //MICROPY_INCLUDED_SHARED_BINDINGS_TIME_ALARM___INIT___H
|
@ -1,31 +0,0 @@
|
||||
#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,
|
||||
};
|
@ -1,8 +0,0 @@
|
||||
#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