Skip to content

Commit e5ff55b

Browse files
microdev1tannewt
authored andcommitted
Renamed alarm modules
1 parent 21ba61a commit e5ff55b

File tree

16 files changed

+170
-170
lines changed

16 files changed

+170
-170
lines changed

ports/esp32s2/common-hal/io_alarm/__init__.c renamed to ports/esp32s2/common-hal/alarm_io/__init__.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include "shared-bindings/io_alarm/__init__.h"
1+
#include "shared-bindings/alarm_io/__init__.h"
22

33
#include "esp_sleep.h"
44
#include "driver/rtc_io.h"
55

6-
mp_obj_t common_hal_io_alarm_pin_state (io_alarm_obj_t *self_in) {
6+
mp_obj_t common_hal_alarm_io_pin_state (alarm_io_obj_t *self_in) {
77
if (!rtc_gpio_is_valid_gpio(self_in->gpio)) {
88
mp_raise_ValueError(translate("io must be rtc io"));
99
}
@@ -22,6 +22,6 @@ mp_obj_t common_hal_io_alarm_pin_state (io_alarm_obj_t *self_in) {
2222
return self_in;
2323
}
2424

25-
void common_hal_io_alarm_disable (void) {
25+
void common_hal_alarm_io_disable (void) {
2626
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_EXT0 | ESP_SLEEP_WAKEUP_EXT1);
2727
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include "esp_sleep.h"
22

3-
#include "shared-bindings/time_alarm/__init__.h"
3+
#include "shared-bindings/alarm_time/__init__.h"
44

5-
void common_hal_time_alarm_duration (uint32_t ms) {
5+
void common_hal_alarm_time_duration (uint32_t ms) {
66
if (esp_sleep_enable_timer_wakeup((ms) * 1000) == ESP_ERR_INVALID_ARG) {
77
mp_raise_ValueError(translate("time out of range"));
88
}
99
}
1010

11-
void common_hal_time_alarm_disable (void) {
11+
void common_hal_alarm_time_disable (void) {
1212
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER);
1313
}

ports/esp32s2/common-hal/microcontroller/__init__.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ mp_obj_t common_hal_mcu_get_wake_alarm(void) {
9999
switch (esp_sleep_get_wakeup_cause()) {
100100
case ESP_SLEEP_WAKEUP_TIMER: ;
101101
//Wake up from timer.
102-
time_alarm_obj_t *timer = m_new_obj(time_alarm_obj_t);
103-
timer->base.type = &time_alarm_type;
102+
alarm_time_obj_t *timer = m_new_obj(alarm_time_obj_t);
103+
timer->base.type = &alarm_time_type;
104104
return timer;
105105
case ESP_SLEEP_WAKEUP_EXT0: ;
106106
//Wake up from GPIO
107-
io_alarm_obj_t *ext0 = m_new_obj(io_alarm_obj_t);
108-
ext0->base.type = &io_alarm_type;
107+
alarm_io_obj_t *ext0 = m_new_obj(alarm_io_obj_t);
108+
ext0->base.type = &alarm_io_type;
109109
return ext0;
110110
case ESP_SLEEP_WAKEUP_EXT1:
111111
//Wake up from GPIO, returns -> esp_sleep_get_ext1_wakeup_status()

ports/esp32s2/mpconfigport.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ CIRCUITPY_FREQUENCYIO = 0
2222
CIRCUITPY_I2CPERIPHERAL = 0
2323
CIRCUITPY_ROTARYIO = 0
2424
CIRCUITPY_NVM = 0
25-
CIRCUITPY_TIME_ALARM = 1
26-
CIRCUITPY_IO_ALARM = 1
25+
CIRCUITPY_ALARM_TIME = 1
26+
CIRCUITPY_ALARM_IO = 1
2727
# We don't have enough endpoints to include MIDI.
2828
CIRCUITPY_USB_MIDI = 0
2929
CIRCUITPY_WIFI = 1

py/circuitpy_defns.mk

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,11 @@ endif
259259
ifeq ($(CIRCUITPY_TIME),1)
260260
SRC_PATTERNS += time/%
261261
endif
262-
ifeq ($(CIRCUITPY_TIME_ALARM),1)
263-
SRC_PATTERNS += time_alarm/%
262+
ifeq ($(CIRCUITPY_ALARM_TIME),1)
263+
SRC_PATTERNS += alarm_time/%
264264
endif
265-
ifeq ($(CIRCUITPY_IO_ALARM),1)
266-
SRC_PATTERNS += io_alarm/%
265+
ifeq ($(CIRCUITPY_ALARM_IO),1)
266+
SRC_PATTERNS += alarm_io/%
267267
endif
268268
ifeq ($(CIRCUITPY_TOUCHIO),1)
269269
SRC_PATTERNS += touchio/%
@@ -366,8 +366,8 @@ SRC_COMMON_HAL_ALL = \
366366
ssl/SSLContext.c \
367367
supervisor/Runtime.c \
368368
supervisor/__init__.c \
369-
time_alarm/__init__.c \
370-
io_alarm/__init__.c \
369+
alarm_time/__init__.c \
370+
alarm_io/__init__.c \
371371
watchdog/WatchDogMode.c \
372372
watchdog/WatchDogTimer.c \
373373
watchdog/__init__.c \

py/circuitpy_mpconfig.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -663,18 +663,18 @@ extern const struct _mp_obj_module_t time_module;
663663
#define TIME_MODULE_ALT_NAME
664664
#endif
665665

666-
#if CIRCUITPY_TIME_ALARM
667-
extern const struct _mp_obj_module_t time_alarm_module;
668-
#define TIME_ALARM_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_time_alarm), (mp_obj_t)&time_alarm_module },
666+
#if CIRCUITPY_ALARM_TIME
667+
extern const struct _mp_obj_module_t alarm_time_module;
668+
#define ALARM_TIME_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_alarm_time), (mp_obj_t)&alarm_time_module },
669669
#else
670-
#define TIME_ALARM_MODULE
670+
#define ALARM_TIME_MODULE
671671
#endif
672672

673-
#if CIRCUITPY_IO_ALARM
674-
extern const struct _mp_obj_module_t io_alarm_module;
675-
#define IO_ALARM_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_io_alarm), (mp_obj_t)&io_alarm_module },
673+
#if CIRCUITPY_ALARM_IO
674+
extern const struct _mp_obj_module_t alarm_io_module;
675+
#define ALARM_IO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_alarm_io), (mp_obj_t)&alarm_io_module },
676676
#else
677-
#define IO_ALARM_MODULE
677+
#define ALARM_IO_MODULE
678678
#endif
679679

680680
#if CIRCUITPY_TOUCHIO
@@ -835,8 +835,8 @@ extern const struct _mp_obj_module_t wifi_module;
835835
STRUCT_MODULE \
836836
SUPERVISOR_MODULE \
837837
TOUCHIO_MODULE \
838-
TIME_ALARM_MODULE \
839-
IO_ALARM_MODULE \
838+
ALARM_TIME_MODULE \
839+
ALARM_IO_MODULE \
840840
UHEAP_MODULE \
841841
USB_HID_MODULE \
842842
USB_MIDI_MODULE \

py/circuitpy_mpconfig.mk

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,11 @@ CFLAGS += -DCIRCUITPY_TERMINALIO=$(CIRCUITPY_TERMINALIO)
234234
CIRCUITPY_TIME ?= 1
235235
CFLAGS += -DCIRCUITPY_TIME=$(CIRCUITPY_TIME)
236236

237-
CIRCUITPY_TIME_ALARM ?= 0
238-
CFLAGS += -DCIRCUITPY_TIME_ALARM=$(CIRCUITPY_TIME_ALARM)
237+
CIRCUITPY_ALARM_TIME ?= 0
238+
CFLAGS += -DCIRCUITPY_ALARM_TIME=$(CIRCUITPY_ALARM_TIME)
239239

240-
CIRCUITPY_IO_ALARM ?= 0
241-
CFLAGS += -DCIRCUITPY_IO_ALARM=$(CIRCUITPY_IO_ALARM)
240+
CIRCUITPY_ALARM_IO ?= 0
241+
CFLAGS += -DCIRCUITPY_ALARM_IO=$(CIRCUITPY_ALARM_IO)
242242

243243
# touchio might be native or generic. See circuitpy_defns.mk.
244244
CIRCUITPY_TOUCHIO_USE_NATIVE ?= 0

shared-bindings/alarm_io/__init__.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include "py/obj.h"
2+
3+
#include "shared-bindings/alarm_io/__init__.h"
4+
#include "shared-bindings/microcontroller/Pin.h"
5+
6+
//| Set Pin Wakeup
7+
//|
8+
STATIC mp_obj_t alarm_io_pin_state(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
9+
enum { ARG_level, ARG_pull };
10+
static const mp_arg_t allowed_args[] = {
11+
{ MP_QSTR_level, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
12+
{ MP_QSTR_pull, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_bool = false} },
13+
};
14+
15+
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
16+
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
17+
18+
mcu_pin_obj_t *pin = validate_obj_is_pin(pos_args[0]);
19+
alarm_io_obj_t *self = m_new_obj(alarm_io_obj_t);
20+
21+
self->base.type = &alarm_io_type;
22+
self->gpio = pin->number;
23+
self->level = args[ARG_level].u_int;
24+
self->pull = args[ARG_pull].u_bool;
25+
26+
return common_hal_alarm_io_pin_state(self);
27+
}
28+
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(alarm_io_pin_state_obj, 1, alarm_io_pin_state);
29+
30+
31+
//| Disable Pin Wakeup
32+
//|
33+
STATIC mp_obj_t alarm_io_disable(void) {
34+
common_hal_alarm_io_disable();
35+
return mp_const_none;
36+
}
37+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(alarm_io_disable_obj, alarm_io_disable);
38+
39+
STATIC const mp_rom_map_elem_t alarm_io_module_globals_table[] = {
40+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_alarm_io) },
41+
{ MP_OBJ_NEW_QSTR(MP_QSTR_PinState), MP_ROM_PTR(&alarm_io_pin_state_obj) },
42+
{ MP_OBJ_NEW_QSTR(MP_QSTR_Disable), MP_ROM_PTR(&alarm_io_disable_obj) },
43+
};
44+
STATIC MP_DEFINE_CONST_DICT(alarm_io_module_globals, alarm_io_module_globals_table);
45+
46+
const mp_obj_module_t alarm_io_module = {
47+
.base = { &mp_type_module },
48+
.globals = (mp_obj_dict_t*)&alarm_io_module_globals,
49+
};
50+
51+
const mp_obj_type_t alarm_io_type = {
52+
{ &mp_type_type },
53+
.name = MP_QSTR_ioAlarm,
54+
};

shared-bindings/alarm_io/__init__.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_IO___INIT___H
2+
#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_IO___INIT___H
3+
4+
#include "py/runtime.h"
5+
6+
typedef struct {
7+
mp_obj_base_t base;
8+
uint8_t gpio, level;
9+
bool pull;
10+
} alarm_io_obj_t;
11+
12+
extern const mp_obj_type_t alarm_io_type;
13+
14+
extern mp_obj_t common_hal_alarm_io_pin_state (alarm_io_obj_t *self_in);
15+
extern void common_hal_alarm_io_disable (void);
16+
17+
#endif //MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_IO___INIT___H

shared-bindings/alarm_time/__init__.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "py/obj.h"
2+
#include "shared-bindings/alarm_time/__init__.h"
3+
4+
//| Set Timer Wakeup
5+
//|
6+
STATIC mp_obj_t alarm_time_duration(mp_obj_t seconds_o) {
7+
#if MICROPY_PY_BUILTINS_FLOAT
8+
mp_float_t seconds = mp_obj_get_float(seconds_o);
9+
mp_float_t msecs = 1000.0f * seconds + 0.5f;
10+
#else
11+
mp_int_t seconds = mp_obj_get_int(seconds_o);
12+
mp_int_t msecs = 1000 * seconds;
13+
#endif
14+
15+
if (seconds < 0) {
16+
mp_raise_ValueError(translate("sleep length must be non-negative"));
17+
}
18+
common_hal_alarm_time_duration(msecs);
19+
20+
alarm_time_obj_t *self = m_new_obj(alarm_time_obj_t);
21+
self->base.type = &alarm_time_type;
22+
23+
return self;
24+
}
25+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(alarm_time_duration_obj, alarm_time_duration);
26+
27+
//| Disable Timer Wakeup
28+
//|
29+
STATIC mp_obj_t alarm_time_disable(void) {
30+
common_hal_alarm_time_disable();
31+
return mp_const_none;
32+
}
33+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(alarm_time_disable_obj, alarm_time_disable);
34+
35+
STATIC const mp_rom_map_elem_t alarm_time_module_globals_table[] = {
36+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_alarm_time) },
37+
{ MP_OBJ_NEW_QSTR(MP_QSTR_Duration), MP_ROM_PTR(&alarm_time_duration_obj) },
38+
{ MP_OBJ_NEW_QSTR(MP_QSTR_Disable), MP_ROM_PTR(&alarm_time_disable_obj) },
39+
};
40+
STATIC MP_DEFINE_CONST_DICT(alarm_time_module_globals, alarm_time_module_globals_table);
41+
42+
const mp_obj_module_t alarm_time_module = {
43+
.base = { &mp_type_module },
44+
.globals = (mp_obj_dict_t*)&alarm_time_module_globals,
45+
};
46+
47+
const mp_obj_type_t alarm_time_type = {
48+
{ &mp_type_type },
49+
.name = MP_QSTR_timeAlarm,
50+
};

0 commit comments

Comments
 (0)