Renamed alarm modules

This commit is contained in:
microDev 2020-09-23 12:54:07 +05:30 committed by Scott Shawcroft
parent 21ba61afbb
commit e5ff55b15c
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA
16 changed files with 170 additions and 170 deletions

View File

@ -1,9 +1,9 @@
#include "shared-bindings/io_alarm/__init__.h"
#include "shared-bindings/alarm_io/__init__.h"
#include "esp_sleep.h"
#include "driver/rtc_io.h"
mp_obj_t common_hal_io_alarm_pin_state (io_alarm_obj_t *self_in) {
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"));
}
@ -22,6 +22,6 @@ mp_obj_t common_hal_io_alarm_pin_state (io_alarm_obj_t *self_in) {
return self_in;
}
void common_hal_io_alarm_disable (void) {
void common_hal_alarm_io_disable (void) {
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_EXT0 | ESP_SLEEP_WAKEUP_EXT1);
}

View File

@ -1,13 +1,13 @@
#include "esp_sleep.h"
#include "shared-bindings/time_alarm/__init__.h"
#include "shared-bindings/alarm_time/__init__.h"
void common_hal_time_alarm_duration (uint32_t ms) {
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_time_alarm_disable (void) {
void common_hal_alarm_time_disable (void) {
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER);
}

View File

@ -99,13 +99,13 @@ mp_obj_t common_hal_mcu_get_wake_alarm(void) {
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_TIMER: ;
//Wake up from timer.
time_alarm_obj_t *timer = m_new_obj(time_alarm_obj_t);
timer->base.type = &time_alarm_type;
alarm_time_obj_t *timer = m_new_obj(alarm_time_obj_t);
timer->base.type = &alarm_time_type;
return timer;
case ESP_SLEEP_WAKEUP_EXT0: ;
//Wake up from GPIO
io_alarm_obj_t *ext0 = m_new_obj(io_alarm_obj_t);
ext0->base.type = &io_alarm_type;
alarm_io_obj_t *ext0 = m_new_obj(alarm_io_obj_t);
ext0->base.type = &alarm_io_type;
return ext0;
case ESP_SLEEP_WAKEUP_EXT1:
//Wake up from GPIO, returns -> esp_sleep_get_ext1_wakeup_status()

View File

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

View File

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

View File

@ -663,18 +663,18 @@ extern const struct _mp_obj_module_t time_module;
#define TIME_MODULE_ALT_NAME
#endif
#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 },
#if CIRCUITPY_ALARM_TIME
extern const struct _mp_obj_module_t alarm_time_module;
#define ALARM_TIME_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_alarm_time), (mp_obj_t)&alarm_time_module },
#else
#define TIME_ALARM_MODULE
#define ALARM_TIME_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 },
#if CIRCUITPY_ALARM_IO
extern const struct _mp_obj_module_t alarm_io_module;
#define ALARM_IO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_alarm_io), (mp_obj_t)&alarm_io_module },
#else
#define IO_ALARM_MODULE
#define ALARM_IO_MODULE
#endif
#if CIRCUITPY_TOUCHIO
@ -835,8 +835,8 @@ extern const struct _mp_obj_module_t wifi_module;
STRUCT_MODULE \
SUPERVISOR_MODULE \
TOUCHIO_MODULE \
TIME_ALARM_MODULE \
IO_ALARM_MODULE \
ALARM_TIME_MODULE \
ALARM_IO_MODULE \
UHEAP_MODULE \
USB_HID_MODULE \
USB_MIDI_MODULE \

View File

@ -234,11 +234,11 @@ CFLAGS += -DCIRCUITPY_TERMINALIO=$(CIRCUITPY_TERMINALIO)
CIRCUITPY_TIME ?= 1
CFLAGS += -DCIRCUITPY_TIME=$(CIRCUITPY_TIME)
CIRCUITPY_TIME_ALARM ?= 0
CFLAGS += -DCIRCUITPY_TIME_ALARM=$(CIRCUITPY_TIME_ALARM)
CIRCUITPY_ALARM_TIME ?= 0
CFLAGS += -DCIRCUITPY_ALARM_TIME=$(CIRCUITPY_ALARM_TIME)
CIRCUITPY_IO_ALARM ?= 0
CFLAGS += -DCIRCUITPY_IO_ALARM=$(CIRCUITPY_IO_ALARM)
CIRCUITPY_ALARM_IO ?= 0
CFLAGS += -DCIRCUITPY_ALARM_IO=$(CIRCUITPY_ALARM_IO)
# touchio might be native or generic. See circuitpy_defns.mk.
CIRCUITPY_TOUCHIO_USE_NATIVE ?= 0

View File

@ -0,0 +1,54 @@
#include "py/obj.h"
#include "shared-bindings/alarm_io/__init__.h"
#include "shared-bindings/microcontroller/Pin.h"
//| Set Pin Wakeup
//|
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);
mcu_pin_obj_t *pin = validate_obj_is_pin(pos_args[0]);
alarm_io_obj_t *self = m_new_obj(alarm_io_obj_t);
self->base.type = &alarm_io_type;
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);
//| Disable Pin Wakeup
//|
STATIC mp_obj_t alarm_io_disable(void) {
common_hal_alarm_io_disable();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(alarm_io_disable_obj, alarm_io_disable);
STATIC const mp_rom_map_elem_t alarm_io_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_alarm_io) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_PinState), MP_ROM_PTR(&alarm_io_pin_state_obj) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_Disable), MP_ROM_PTR(&alarm_io_disable_obj) },
};
STATIC MP_DEFINE_CONST_DICT(alarm_io_module_globals, alarm_io_module_globals_table);
const mp_obj_module_t alarm_io_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&alarm_io_module_globals,
};
const mp_obj_type_t alarm_io_type = {
{ &mp_type_type },
.name = MP_QSTR_ioAlarm,
};

View File

@ -0,0 +1,17 @@
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_IO___INIT___H
#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_IO___INIT___H
#include "py/runtime.h"
typedef struct {
mp_obj_base_t base;
uint8_t gpio, level;
bool pull;
} alarm_io_obj_t;
extern const mp_obj_type_t alarm_io_type;
extern mp_obj_t common_hal_alarm_io_pin_state (alarm_io_obj_t *self_in);
extern void common_hal_alarm_io_disable (void);
#endif //MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_IO___INIT___H

View File

@ -0,0 +1,50 @@
#include "py/obj.h"
#include "shared-bindings/alarm_time/__init__.h"
//| Set Timer Wakeup
//|
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;
#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_alarm_time_duration(msecs);
alarm_time_obj_t *self = m_new_obj(alarm_time_obj_t);
self->base.type = &alarm_time_type;
return self;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(alarm_time_duration_obj, alarm_time_duration);
//| Disable Timer Wakeup
//|
STATIC mp_obj_t alarm_time_disable(void) {
common_hal_alarm_time_disable();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(alarm_time_disable_obj, alarm_time_disable);
STATIC const mp_rom_map_elem_t alarm_time_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_alarm_time) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_Duration), MP_ROM_PTR(&alarm_time_duration_obj) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_Disable), MP_ROM_PTR(&alarm_time_disable_obj) },
};
STATIC MP_DEFINE_CONST_DICT(alarm_time_module_globals, alarm_time_module_globals_table);
const mp_obj_module_t alarm_time_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&alarm_time_module_globals,
};
const mp_obj_type_t alarm_time_type = {
{ &mp_type_type },
.name = MP_QSTR_timeAlarm,
};

View File

@ -0,0 +1,15 @@
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME___INIT___H
#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME___INIT___H
#include "py/runtime.h"
typedef struct {
mp_obj_base_t base;
} alarm_time_obj_t;
extern const mp_obj_type_t alarm_time_type;
extern void common_hal_alarm_time_duration(uint32_t);
extern void common_hal_alarm_time_disable (void);
#endif //MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME___INIT___H

View File

@ -1,54 +0,0 @@
#include "py/obj.h"
#include "shared-bindings/io_alarm/__init__.h"
#include "shared-bindings/microcontroller/Pin.h"
//| Set Pin 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]);
io_alarm_obj_t *self = m_new_obj(io_alarm_obj_t);
self->base.type = &io_alarm_type;
self->gpio = pin->number;
self->level = args[ARG_level].u_int;
self->pull = args[ARG_pull].u_bool;
return common_hal_io_alarm_pin_state(self);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(io_alarm_pin_state_obj, 1, io_alarm_pin_state);
//| Disable Pin Wakeup
//|
STATIC mp_obj_t io_alarm_disable(void) {
common_hal_io_alarm_disable();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(io_alarm_disable_obj, io_alarm_disable);
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) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_Disable), MP_ROM_PTR(&io_alarm_disable_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,
};
const mp_obj_type_t io_alarm_type = {
{ &mp_type_type },
.name = MP_QSTR_ioAlarm,
};

View File

@ -1,17 +0,0 @@
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_IO_ALARM___INIT___H
#define MICROPY_INCLUDED_SHARED_BINDINGS_IO_ALARM___INIT___H
#include "py/runtime.h"
typedef struct {
mp_obj_base_t base;
uint8_t gpio, level;
bool pull;
} io_alarm_obj_t;
extern const mp_obj_type_t io_alarm_type;
extern mp_obj_t common_hal_io_alarm_pin_state (io_alarm_obj_t *self_in);
extern void common_hal_io_alarm_disable (void);
#endif //MICROPY_INCLUDED_SHARED_BINDINGS_IO_ALARM___INIT___H

View File

@ -35,8 +35,8 @@
#include "shared-bindings/microcontroller/RunMode.h"
#include "shared-bindings/io_alarm/__init__.h"
#include "shared-bindings/time_alarm/__init__.h"
#include "shared-bindings/alarm_io/__init__.h"
#include "shared-bindings/alarm_time/__init__.h"
extern void common_hal_mcu_delay_us(uint32_t);

View File

@ -1,50 +0,0 @@
#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);
time_alarm_obj_t *self = m_new_obj(time_alarm_obj_t);
self->base.type = &time_alarm_type;
return self;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_alarm_duration_obj, time_alarm_duration);
//| Disable Timer Wakeup
//|
STATIC mp_obj_t time_alarm_disable(void) {
common_hal_time_alarm_disable();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_alarm_disable_obj, time_alarm_disable);
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) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_Disable), MP_ROM_PTR(&time_alarm_disable_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,
};
const mp_obj_type_t time_alarm_type = {
{ &mp_type_type },
.name = MP_QSTR_timeAlarm,
};

View File

@ -1,15 +0,0 @@
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_TIME_ALARM___INIT___H
#define MICROPY_INCLUDED_SHARED_BINDINGS_TIME_ALARM___INIT___H
#include "py/runtime.h"
typedef struct {
mp_obj_base_t base;
} time_alarm_obj_t;
extern const mp_obj_type_t time_alarm_type;
extern void common_hal_time_alarm_duration(uint32_t);
extern void common_hal_time_alarm_disable (void);
#endif //MICROPY_INCLUDED_SHARED_BINDINGS_TIME_ALARM___INIT___H