Get io wake working

This commit is contained in:
microDev 2020-09-19 17:48:36 +05:30 committed by Scott Shawcroft
parent 3a30887b44
commit e310b871c8
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA
13 changed files with 138 additions and 53 deletions

2
main.c
View File

@ -509,7 +509,7 @@ int __attribute__((used)) main(void) {
} }
if (exit_code == PYEXEC_FORCED_EXIT) { if (exit_code == PYEXEC_FORCED_EXIT) {
if (!first_run) { if (!first_run) {
serial_write_compressed(translate("\n\n ----- soft reboot -----\n")); serial_write_compressed(translate("\n\n------ soft reboot ------\n"));
} }
first_run = false; first_run = false;
skip_repl = run_code_py(safe_mode); skip_repl = run_code_py(safe_mode);

View 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);
}
}

View File

@ -1,8 +1,8 @@
#include "esp_sleep.h" #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) { if (esp_sleep_enable_timer_wakeup((ms) * 1000) == ESP_ERR_INVALID_ARG) {
mp_raise_ValueError(translate("time out of range")); mp_raise_ValueError(translate("time out of range"));
} }

View File

@ -22,7 +22,8 @@ CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_ROTARYIO = 0 CIRCUITPY_ROTARYIO = 0
CIRCUITPY_NVM = 0 CIRCUITPY_NVM = 0
CIRCUITPY_TIMEALARM = 1 CIRCUITPY_TIME_ALARM = 1
CIRCUITPY_IO_ALARM = 1
# We don't have enough endpoints to include MIDI. # We don't have enough endpoints to include MIDI.
CIRCUITPY_USB_MIDI = 0 CIRCUITPY_USB_MIDI = 0
CIRCUITPY_WIFI = 1 CIRCUITPY_WIFI = 1

View File

@ -259,8 +259,11 @@ endif
ifeq ($(CIRCUITPY_TIME),1) ifeq ($(CIRCUITPY_TIME),1)
SRC_PATTERNS += time/% SRC_PATTERNS += time/%
endif endif
ifeq ($(CIRCUITPY_TIMEALARM),1) ifeq ($(CIRCUITPY_TIME_ALARM),1)
SRC_PATTERNS += timealarm/% SRC_PATTERNS += time_alarm/%
endif
ifeq ($(CIRCUITPY_IO_ALARM),1)
SRC_PATTERNS += io_alarm/%
endif endif
ifeq ($(CIRCUITPY_TOUCHIO),1) ifeq ($(CIRCUITPY_TOUCHIO),1)
SRC_PATTERNS += touchio/% SRC_PATTERNS += touchio/%
@ -363,7 +366,8 @@ SRC_COMMON_HAL_ALL = \
ssl/SSLContext.c \ ssl/SSLContext.c \
supervisor/Runtime.c \ supervisor/Runtime.c \
supervisor/__init__.c \ supervisor/__init__.c \
timealarm/__init__.c \ time_alarm/__init__.c \
io_alarm/__init__.c \
watchdog/WatchDogMode.c \ watchdog/WatchDogMode.c \
watchdog/WatchDogTimer.c \ watchdog/WatchDogTimer.c \
watchdog/__init__.c \ watchdog/__init__.c \

View File

@ -663,11 +663,18 @@ extern const struct _mp_obj_module_t time_module;
#define TIME_MODULE_ALT_NAME #define TIME_MODULE_ALT_NAME
#endif #endif
#if CIRCUITPY_TIMEALARM #if CIRCUITPY_TIME_ALARM
extern const struct _mp_obj_module_t timealarm_module; extern const struct _mp_obj_module_t time_alarm_module;
#define TIMEALARM_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_timealarm), (mp_obj_t)&timealarm_module }, #define TIME_ALARM_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_time_alarm), (mp_obj_t)&time_alarm_module },
#else #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 #endif
#if CIRCUITPY_TOUCHIO #if CIRCUITPY_TOUCHIO
@ -828,7 +835,8 @@ extern const struct _mp_obj_module_t wifi_module;
STRUCT_MODULE \ STRUCT_MODULE \
SUPERVISOR_MODULE \ SUPERVISOR_MODULE \
TOUCHIO_MODULE \ TOUCHIO_MODULE \
TIMEALARM_MODULE \ TIME_ALARM_MODULE \
IO_ALARM_MODULE \
UHEAP_MODULE \ UHEAP_MODULE \
USB_HID_MODULE \ USB_HID_MODULE \
USB_MIDI_MODULE \ USB_MIDI_MODULE \

View File

@ -234,8 +234,11 @@ CFLAGS += -DCIRCUITPY_TERMINALIO=$(CIRCUITPY_TERMINALIO)
CIRCUITPY_TIME ?= 1 CIRCUITPY_TIME ?= 1
CFLAGS += -DCIRCUITPY_TIME=$(CIRCUITPY_TIME) CFLAGS += -DCIRCUITPY_TIME=$(CIRCUITPY_TIME)
CIRCUITPY_TIMEALARM ?= 0 CIRCUITPY_TIME_ALARM ?= 0
CFLAGS += -DCIRCUITPY_TIMEALARM=$(CIRCUITPY_TIMEALARM) 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. # touchio might be native or generic. See circuitpy_defns.mk.
CIRCUITPY_TOUCHIO_USE_NATIVE ?= 0 CIRCUITPY_TOUCHIO_USE_NATIVE ?= 0

View 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,
};

View 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

View 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,
};

View 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

View File

@ -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,
};

View File

@ -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