Add alarm_touch module

This commit is contained in:
microDev 2020-09-25 00:28:50 +05:30 committed by Scott Shawcroft
parent da449723df
commit 59df1a11ad
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA
15 changed files with 83 additions and 31 deletions

View File

@ -36,17 +36,17 @@ mp_obj_t common_hal_alarm_get_wake_alarm(void) {
case ESP_SLEEP_WAKEUP_TIMER: ;
//Wake up from timer.
alarm_time_obj_t *timer = m_new_obj(alarm_time_obj_t);
timer->base.type = &alarm_time_type;
timer->base.type = &alarm_time_type;
return timer;
case ESP_SLEEP_WAKEUP_EXT0: ;
//Wake up from GPIO
alarm_io_obj_t *ext0 = m_new_obj(alarm_io_obj_t);
ext0->base.type = &alarm_io_type;
return ext0;
case ESP_SLEEP_WAKEUP_TOUCHPAD:
ext0->base.type = &alarm_io_type;
return ext0;
case ESP_SLEEP_WAKEUP_TOUCHPAD:
//TODO: implement TouchIO
//Wake up from touch on pad, esp_sleep_get_touchpad_wakeup_status()
break;
break;
case ESP_SLEEP_WAKEUP_UNDEFINED:
default:
//Not a deep sleep reset

View File

@ -5,22 +5,22 @@
mp_obj_t common_hal_alarm_io_pin_state (alarm_io_obj_t *self_in) {
if (!rtc_gpio_is_valid_gpio(self_in->gpio)) {
mp_raise_ValueError(translate("io must be rtc io"));
}
mp_raise_ValueError(translate("io must be rtc io"));
}
switch(esp_sleep_enable_ext0_wakeup(self_in->gpio, self_in->level)) {
case ESP_ERR_INVALID_ARG:
mp_raise_ValueError(translate("trigger level must be 0 or 1"));
case ESP_ERR_INVALID_STATE:
mp_raise_RuntimeError(translate("wakeup conflict"));
default:
break;
default:
break;
}
if (self_in->pull) { (self_in->level) ? rtc_gpio_pulldown_en(self_in->gpio) : rtc_gpio_pullup_en(self_in->gpio); }
return self_in;
}
return self_in;
}
void common_hal_alarm_io_disable (void) {
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_EXT0 | ESP_SLEEP_WAKEUP_EXT1);

View File

@ -5,8 +5,8 @@
void common_hal_alarm_time_duration (uint32_t ms) {
if (esp_sleep_enable_timer_wakeup((ms) * 1000) == ESP_ERR_INVALID_ARG) {
mp_raise_ValueError(translate("time out of range"));
}
}
}
}
void common_hal_alarm_time_disable (void) {
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER);

View File

@ -0,0 +1,7 @@
#include "esp_sleep.h"
#include "shared-bindings/alarm_touch/__init__.h"
void common_hal_alarm_touch_disable (void) {
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TOUCHPAD);
}

View File

@ -80,7 +80,7 @@ void common_hal_mcu_reset(void) {
}
void common_hal_mcu_sleep(void) {
esp_deep_sleep_start();
esp_deep_sleep_start();
}
// The singleton microcontroller.Processor object, bound to microcontroller.cpu

View File

@ -17,6 +17,7 @@ CIRCUITPY_FULL_BUILD = 1
CIRCUITPY_ALARM = 1
CIRCUITPY_ALARM_IO = 1
CIRCUITPY_ALARM_TIME = 1
CIRCUITPY_ALARM_TOUCH = 1
CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_AUDIOIO = 0
CIRCUITPY_CANIO = 1

View File

@ -86,7 +86,7 @@ safe_mode_t port_init(void) {
if (heap == NULL) {
return NO_HEAP;
}
return NO_SAFE_MODE;
}

View File

@ -108,6 +108,9 @@ endif
ifeq ($(CIRCUITPY_ALARM_TIME),1)
SRC_PATTERNS += alarm_time/%
endif
ifeq ($(CIRCUITPY_ALARM_TIME),1)
SRC_PATTERNS += alarm_touch/%
endif
ifeq ($(CIRCUITPY_ANALOGIO),1)
SRC_PATTERNS += analogio/%
endif
@ -310,6 +313,7 @@ SRC_COMMON_HAL_ALL = \
alarm/__init__.c \
alarm_io/__init__.c \
alarm_time/__init__.c \
alarm_touch/__init__.c \
analogio/AnalogIn.c \
analogio/AnalogOut.c \
analogio/__init__.c \

View File

@ -261,6 +261,13 @@ extern const struct _mp_obj_module_t alarm_time_module;
#define ALARM_TIME_MODULE
#endif
#if CIRCUITPY_ALARM_TOUCH
extern const struct _mp_obj_module_t alarm_touch_module;
#define ALARM_TOUCH_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_alarm_touch), (mp_obj_t)&alarm_touch_module },
#else
#define ALARM_TOUCH_MODULE
#endif
#if CIRCUITPY_ANALOGIO
#define ANALOGIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_analogio), (mp_obj_t)&analogio_module },
extern const struct _mp_obj_module_t analogio_module;
@ -787,6 +794,7 @@ extern const struct _mp_obj_module_t wifi_module;
ALARM_MODULE \
ALARM_IO_MODULE \
ALARM_TIME_MODULE \
ALARM_TOUCH_MODULE \
ANALOGIO_MODULE \
AUDIOBUSIO_MODULE \
AUDIOCORE_MODULE \

View File

@ -48,6 +48,9 @@ CFLAGS += -DCIRCUITPY_ALARM_IO=$(CIRCUITPY_ALARM_IO)
CIRCUITPY_ALARM_TIME ?= 0
CFLAGS += -DCIRCUITPY_ALARM_TIME=$(CIRCUITPY_ALARM_TIME)
CIRCUITPY_ALARM_TOUCH ?= 0
CFLAGS += -DCIRCUITPY_ALARM_TOUCH=$(CIRCUITPY_ALARM_TOUCH)
CIRCUITPY_ANALOGIO ?= 1
CFLAGS += -DCIRCUITPY_ANALOGIO=$(CIRCUITPY_ANALOGIO)

View File

@ -3,15 +3,15 @@
#include "shared-bindings/alarm_io/__init__.h"
#include "shared-bindings/microcontroller/Pin.h"
STATIC mp_obj_t alarm_io_pin_state(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
STATIC mp_obj_t alarm_io_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);
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]);
alarm_io_obj_t *self = m_new_obj(alarm_io_obj_t);
@ -20,12 +20,12 @@ STATIC mp_obj_t alarm_io_pin_state(size_t n_args, const mp_obj_t *pos_args, mp_m
self->gpio = pin->number;
self->level = args[ARG_level].u_int;
self->pull = args[ARG_pull].u_bool;
return common_hal_alarm_io_pin_state(self);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(alarm_io_pin_state_obj, 1, alarm_io_pin_state);
STATIC mp_obj_t alarm_io_disable(void) {
STATIC mp_obj_t alarm_io_disable(void) {
common_hal_alarm_io_disable();
return mp_const_none;
}

View File

@ -1,7 +1,7 @@
#include "py/obj.h"
#include "shared-bindings/alarm_time/__init__.h"
STATIC mp_obj_t alarm_time_duration(mp_obj_t seconds_o) {
STATIC mp_obj_t alarm_time_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;
@ -22,7 +22,7 @@ STATIC mp_obj_t alarm_time_duration(mp_obj_t seconds_o) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(alarm_time_duration_obj, alarm_time_duration);
STATIC mp_obj_t alarm_time_disable(void) {
STATIC mp_obj_t alarm_time_disable(void) {
common_hal_alarm_time_disable();
return mp_const_none;
}

View File

@ -0,0 +1,24 @@
#include "py/obj.h"
#include "shared-bindings/alarm_touch/__init__.h"
STATIC mp_obj_t alarm_touch_disable(void) {
common_hal_alarm_touch_disable();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(alarm_touch_disable_obj, alarm_touch_disable);
STATIC const mp_rom_map_elem_t alarm_touch_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_alarm_touch) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_Disable), MP_ROM_PTR(&alarm_touch_disable_obj) },
};
STATIC MP_DEFINE_CONST_DICT(alarm_touch_module_globals, alarm_touch_module_globals_table);
const mp_obj_module_t alarm_touch_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&alarm_touch_module_globals,
};
const mp_obj_type_t alarm_touch_type = {
{ &mp_type_type },
.name = MP_QSTR_touchAlarm,
};

View File

@ -0,0 +1,14 @@
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TOUCH___INIT___H
#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TOUCH___INIT___H
#include "py/runtime.h"
typedef struct {
mp_obj_base_t base;
} alarm_touch_obj_t;
extern const mp_obj_type_t alarm_touch_type;
extern void common_hal_alarm_touch_disable (void);
#endif //MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TOUCH___INIT___H

View File

@ -135,15 +135,6 @@ 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.