Skip to content

Commit 649c930

Browse files
committed
wip
1 parent 5bb3c32 commit 649c930

File tree

17 files changed

+234
-48
lines changed

17 files changed

+234
-48
lines changed

main.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363

6464
#include "boards/board.h"
6565

66+
#if CIRCUITPY_ALARM
67+
#include "shared-bindings/alarm/__init__.h"
68+
#endif
69+
6670
#if CIRCUITPY_DISPLAYIO
6771
#include "shared-module/displayio/__init__.h"
6872
#endif
@@ -88,10 +92,6 @@
8892
#include "common-hal/canio/CAN.h"
8993
#endif
9094

91-
#if CIRCUITPY_SLEEP
92-
#include "shared-bindings/sleep/__init__.h"
93-
#endif
94-
9595
void do_str(const char *src, mp_parse_input_kind_t input_kind) {
9696
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
9797
if (lex == NULL) {
@@ -320,7 +320,7 @@ bool run_code_py(safe_mode_t safe_mode) {
320320
#endif
321321
rgb_status_animation_t animation;
322322
bool ok = result->return_code != PYEXEC_EXCEPTION;
323-
#if CIRCUITPY_SLEEP
323+
#if CIRCUITPY_ALARM
324324
// If USB isn't enumerated then deep sleep.
325325
if (ok && !supervisor_workflow_active() && supervisor_ticks_ms64() > CIRCUITPY_USB_ENUMERATION_DELAY * 1024) {
326326
common_hal_sleep_deep_sleep();
@@ -361,7 +361,7 @@ bool run_code_py(safe_mode_t safe_mode) {
361361
#endif
362362
bool animation_done = tick_rgb_status_animation(&animation);
363363
if (animation_done && supervisor_workflow_active()) {
364-
#if CIRCUITPY_SLEEP
364+
#if CIRCUITPY_ALARM
365365
int64_t remaining_enumeration_wait = CIRCUITPY_USB_ENUMERATION_DELAY * 1024 - supervisor_ticks_ms64();
366366
// If USB isn't enumerated then deep sleep after our waiting period.
367367
if (ok && remaining_enumeration_wait < 0) {
@@ -423,9 +423,13 @@ void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
423423
if (!skip_boot_output) {
424424
// Wait 1.5 seconds before opening CIRCUITPY_BOOT_OUTPUT_FILE for write,
425425
// in case power is momentary or will fail shortly due to, say a low, battery.
426-
if (common_hal_sleep_get_reset_reason() == RESET_REASON_POWER_VALID) {
426+
#if CIRCUITPY_ALARM
427+
if (common_hal_sleep_get_reset_reason() == RESET_REASON_POWER_ON) {
428+
#endif
427429
mp_hal_delay_ms(1500);
430+
#if CIRCUITPY_ALARM
428431
}
432+
#endif
429433

430434
// USB isn't up, so we can write the file.
431435
filesystem_set_internal_writable_by_usb(false);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 @microDev1 (GitHub)
7+
* Copyright (c) 2020 Dan Halbert for Adafruit Industries
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#include "esp_sleep.h"
29+
30+
#include "shared-bindings/alarm/time/DurationAlarm.h"
31+
32+
void common_hal_alarm_pin_pin_pin_alarm_construct(alarm_pin_pin_alarm_obj_t *self, mcu_pin_obj_t *pin, bool level, bool edge, bool pull) {
33+
self->pin = pin;
34+
self->level = level;
35+
self->edge = edge;
36+
self->pull = pull;
37+
38+
mcu_pin_obj_t *common_hal_alarm_pin_pin_alarm_get_pin(alarm_pin_pin_alarm_obj_t *self) {
39+
return self->pin;
40+
}
41+
42+
bool common_hal_alarm_pin_pin_alarm_get_level(alarm_pin_pin_alarm_obj_t *self) {
43+
return self->level;
44+
}
45+
46+
bool common_hal_alarm_pin_pin_alarm_get_edge(alarm_pin_pin_alarm_obj_t *self) {
47+
return self->edge;
48+
}
49+
50+
bool common_hal_alarm_pin_pin_alarm_get_pull(alarm_pin_pin_alarm_obj_t *self) {
51+
return self->pull;
52+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Dan Halbert for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
28+
#include "py/obj.h"
29+
30+
typedef struct {
31+
mp_obj_base_t base;
32+
mcu_pin_obj_t *pin;
33+
bool level;
34+
bool edge;
35+
bool pull;
36+
} alarm_pin_pin_alarm_obj_t;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 @microDev1 (GitHub)
7+
* Copyright (c) 2020 Dan Halbert for Adafruit Industries
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#include "esp_sleep.h"
29+
30+
#include "shared-bindings/alarm/time/DurationAlarm.h"
31+
32+
void common_hal_alarm_time_duration_alarm_construct(alarm_time_duration_alarm_obj_t *self, mp_float_t duration) {
33+
self->duration = duration;
34+
}
35+
36+
mp_float_t common_hal_alarm_time_duration_alarm_get_duration(alarm_time_duration_alarm_obj_t *self) {
37+
return self->duration;
38+
}
39+
void common_hal_alarm_time_duration_alarm_enable(alarm_time_duration_alarm_obj_t *self)
40+
if (esp_sleep_enable_timer_wakeup((uint64_t) (self->duration * 1000000)) == ESP_ERR_INVALID_ARG) {
41+
mp_raise_ValueError(translate("duration out of range"));
42+
}
43+
}
44+
45+
void common_hal_alarm_time_duration_alarm_disable (alarm_time_duration_alarm_obj_t *self) {
46+
(void) self;
47+
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER);
48+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 @microDev1 (GitHub)
7+
* Copyright (c) 2020 Dan Halbert for Adafruit Industries
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
29+
#include "py/obj.h"
30+
31+
typedef struct {
32+
mp_obj_base_t base;
33+
mp_float_t duration; // seconds
34+
} alarm_time_duration_alarm_obj_t;

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

Lines changed: 0 additions & 13 deletions
This file was deleted.

py/circuitpy_defns.mk

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,8 @@ SRC_COMMON_HAL_ALL = \
302302
_pew/PewPew.c \
303303
_pew/__init__.c \
304304
alarm/__init__.c \
305-
alarm/pin/__init__.c \
306-
alarm/time/__init__.c \
307-
alarm/touch/__init__.c \
305+
alarm/pin/PinAlarm.c \
306+
alarm/time/DurationAlarm.c \
308307
analogio/AnalogIn.c \
309308
analogio/AnalogOut.c \
310309
analogio/__init__.c \

py/circuitpy_mpconfig.mk

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ CFLAGS += -DCIRCUITPY_AESIO=$(CIRCUITPY_AESIO)
4242
# TODO: CIRCUITPY_ALARM will gradually be added to
4343
# as many ports as possible
4444
# so make this 1 or CIRCUITPY_FULL_BUILD eventually
45-
CIRCUITPY_SLEEPIO ?= 0
46-
CFLAGS += -DCIRCUITPY_SLEEPIO=$(CIRCUITPY_SLEEPIO)
47-
4845
CIRCUITPY_ALARM ?= 0
4946
CFLAGS += -DCIRCUITPY_ALARM=$(CIRCUITPY_ALARM)
5047

shared-bindings/alarm/ResetReason.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,39 @@
2828

2929
#include "shared-bindings/alarm/ResetReason.h"
3030

31-
MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, POWER_VALID, RESET_REASON_POWER_VALID);
31+
MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, POWER_VALID, RESET_REASON_POWER_ON);
3232
MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, SOFTWARE, RESET_REASON_SOFTWARE);
3333
MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, DEEP_SLEEP_ALARM, RESET_REASON_DEEP_SLEEP_ALARM);
3434
MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, EXTERNAL, RESET_REASON_EXTERNAL);
3535

3636
//| class ResetReason:
3737
//| """The reason the chip was last reset"""
3838
//|
39-
//| POWER_VALID: object
40-
//| """The chip was reset and started once power levels were valid."""
39+
//| POWER_ON: object
40+
//| """The chip was started from power off."""
41+
//|
42+
//| BROWNOUT: object
43+
//| """The chip was reset due to voltage brownout."""
4144
//|
4245
//| SOFTWARE: object
4346
//| """The chip was reset from software."""
4447
//|
4548
//| DEEP_SLEEP_ALARM: object
46-
//| """The chip was reset for deep sleep and started by an alarm."""
49+
//| """The chip was reset for deep sleep and restarted by an alarm."""
50+
//|
51+
//| RESET_PIN: object
52+
//| """The chip was reset by a signal on its reset pin. The pin might be connected to a reset buton."""
4753
//|
48-
//| EXTERNAL: object
49-
//| """The chip was reset by an external input such as a button."""
54+
//| WATCHDOG: object
55+
//| """The chip was reset by its watchdog timer."""
5056
//|
5157
MAKE_ENUM_MAP(alarm_reset_reason) {
52-
MAKE_ENUM_MAP_ENTRY(reset_reason, POWER_VALID),
58+
MAKE_ENUM_MAP_ENTRY(reset_reason, POWER_ON),
59+
MAKE_ENUM_MAP_ENTRY(reset_reason, BROWNOUT),
5360
MAKE_ENUM_MAP_ENTRY(reset_reason, SOFTWARE),
5461
MAKE_ENUM_MAP_ENTRY(reset_reason, DEEP_SLEEP_ALARM),
55-
MAKE_ENUM_MAP_ENTRY(reset_reason, EXTERNAL),
62+
MAKE_ENUM_MAP_ENTRY(reset_reason, RESET_PIN),
63+
MAKE_ENUM_MAP_ENTRY(reset_reason, WATCHDOG),
5664
};
5765
STATIC MP_DEFINE_CONST_DICT(alarm_reset_reason_locals_dict, alarm_reset_reason_locals_table);
5866

0 commit comments

Comments
 (0)