summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2020-10-27 17:55:03 -0700
committerScott Shawcroft <scott@tannewt.org>2020-10-27 17:55:03 -0700
commit9a4efed8cbaca3aa48c6cc0ce0a4e267eef7a8e1 (patch)
treea4503697ca0d3fab4e15ee6add1171165ac32146 /shared-bindings
parent85dadf3a561c21e284d5daf42b1b3e367ce7ebc6 (diff)
Start tweaking the workflow to sleep
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/alarm_touch/__init__.c28
-rw-r--r--shared-bindings/alarm_touch/__init__.h14
-rw-r--r--shared-bindings/sleepio/ResetReason.c61
-rw-r--r--shared-bindings/sleepio/ResetReason.h36
-rw-r--r--shared-bindings/sleepio/__init__.c27
-rw-r--r--shared-bindings/sleepio/__init__.h5
6 files changed, 110 insertions, 61 deletions
diff --git a/shared-bindings/alarm_touch/__init__.c b/shared-bindings/alarm_touch/__init__.c
deleted file mode 100644
index 5f5a156d8..000000000
--- a/shared-bindings/alarm_touch/__init__.c
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "py/obj.h"
-#include "shared-bindings/alarm_touch/__init__.h"
-
-//| """alarm_touch module
-//|
-//| The `alarm_touch` module implements deep sleep."""
-
-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,
-};
diff --git a/shared-bindings/alarm_touch/__init__.h b/shared-bindings/alarm_touch/__init__.h
deleted file mode 100644
index 600587d24..000000000
--- a/shared-bindings/alarm_touch/__init__.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#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
diff --git a/shared-bindings/sleepio/ResetReason.c b/shared-bindings/sleepio/ResetReason.c
new file mode 100644
index 000000000..095f4bed0
--- /dev/null
+++ b/shared-bindings/sleepio/ResetReason.c
@@ -0,0 +1,61 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "py/enum.h"
+
+#include "shared-bindings/sleepio/ResetReason.h"
+
+MAKE_ENUM_VALUE(sleepio_reset_reason_type, reset_reason, POWER_VALID, RESET_REASON_POWER_VALID);
+MAKE_ENUM_VALUE(sleepio_reset_reason_type, reset_reason, SOFTWARE, RESET_REASON_SOFTWARE);
+MAKE_ENUM_VALUE(sleepio_reset_reason_type, reset_reason, DEEP_SLEEP_ALARM, RESET_REASON_DEEP_SLEEP_ALARM);
+MAKE_ENUM_VALUE(sleepio_reset_reason_type, reset_reason, EXTERNAL, RESET_REASON_EXTERNAL);
+
+//| class ResetReason:
+//| """The reason the chip was last reset"""
+//|
+//| POWER_VALID: object
+//| """The chip was reset and started once power levels were valid."""
+//|
+//| SOFTWARE: object
+//| """The chip was reset from software."""
+//|
+//| DEEP_SLEEP_ALARM: object
+//| """The chip was reset for deep sleep and started by an alarm."""
+//|
+//| EXTERNAL: object
+//| """The chip was reset by an external input such as a button."""
+//|
+MAKE_ENUM_MAP(sleepio_reset_reason) {
+ MAKE_ENUM_MAP_ENTRY(reset_reason, POWER_VALID),
+ MAKE_ENUM_MAP_ENTRY(reset_reason, SOFTWARE),
+ MAKE_ENUM_MAP_ENTRY(reset_reason, DEEP_SLEEP_ALARM),
+ MAKE_ENUM_MAP_ENTRY(reset_reason, EXTERNAL),
+};
+STATIC MP_DEFINE_CONST_DICT(sleepio_reset_reason_locals_dict, sleepio_reset_reason_locals_table);
+
+MAKE_PRINTER(sleepio, sleepio_reset_reason);
+
+MAKE_ENUM_TYPE(sleepio, ResetReason, sleepio_reset_reason);
diff --git a/shared-bindings/sleepio/ResetReason.h b/shared-bindings/sleepio/ResetReason.h
new file mode 100644
index 000000000..50b8d002a
--- /dev/null
+++ b/shared-bindings/sleepio/ResetReason.h
@@ -0,0 +1,36 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#pragma once
+
+typedef enum {
+ RESET_REASON_POWER_APPLIED,
+ RESET_REASON_SOFTWARE,
+ RESET_REASON_DEEP_SLEEP_ALARM,
+ RESET_REASON_BUTTON,
+} sleepio_reset_reason_t;
+
+extern const mp_obj_type_t sleepio_reset_reason_type;
diff --git a/shared-bindings/sleepio/__init__.c b/shared-bindings/sleepio/__init__.c
index 2d5db18f0..9793c1b50 100644
--- a/shared-bindings/sleepio/__init__.c
+++ b/shared-bindings/sleepio/__init__.c
@@ -47,6 +47,10 @@
//| """The most recent alarm to wake us up from a sleep (light or deep.)"""
//|
+//| reset_reason: ResetReason
+//| """The reason the chip started up from reset state. This can may be power up or due to an alarm."""
+//|
+
//| def sleep_until_alarm(alarm: Alarm, ...) -> Alarm:
//| """Performs a light sleep until woken by one of the alarms. The alarm that woke us up is
//| returned."""
@@ -54,14 +58,6 @@
//|
STATIC mp_obj_t sleepio_sleep_until_alarm(size_t n_args, const mp_obj_t *args) {
- // mp_int_t size = MP_OBJ_SMALL_INT_VALUE(struct_calcsize(args[0]));
- // vstr_t vstr;
- // vstr_init_len(&vstr, size);
- // byte *p = (byte*)vstr.buf;
- // memset(p, 0, size);
- // byte *end_p = &p[size];
- // shared_modules_struct_pack_into(args[0], p, end_p, n_args - 1, &args[1]);
- // return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(sleepio_sleep_until_alarm_obj, 1, MP_OBJ_FUN_ARGS_MAX, sleepio_sleep_until_alarm);
@@ -71,14 +67,6 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(sleepio_sleep_until_alarm_obj, 1, MP_OBJ_FUN
//| ...
//|
STATIC mp_obj_t sleepio_set_alarms(size_t n_args, const mp_obj_t *args) {
- // mp_int_t size = MP_OBJ_SMALL_INT_VALUE(struct_calcsize(args[0]));
- // vstr_t vstr;
- // vstr_init_len(&vstr, size);
- // byte *p = (byte*)vstr.buf;
- // memset(p, 0, size);
- // byte *end_p = &p[size];
- // shared_modules_struct_pack_into(args[0], p, end_p, n_args - 1, &args[1]);
- // return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(sleepio_set_alarms_obj, 1, MP_OBJ_FUN_ARGS_MAX, sleepio_set_alarms);
@@ -87,16 +75,23 @@ mp_map_elem_t sleepio_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sleepio) },
{ MP_ROM_QSTR(MP_QSTR_wake_alarm), mp_const_none },
+ { MP_ROM_QSTR(MP_QSTR_reset_reason), mp_const_none },
{ MP_ROM_QSTR(MP_QSTR_sleep_until_alarm), sleepio_sleep_until_alarm_obj },
{ MP_ROM_QSTR(MP_QSTR_set_alarms), sleepio_set_alarms_obj },
};
STATIC MP_DEFINE_CONST_DICT(sleepio_module_globals, sleepio_module_globals_table);
+// These are called from common hal code to set the current wake alarm.
void common_hal_sleepio_set_wake_alarm(mp_obj_t alarm) {
// sleepio_module_globals_table[1].value = alarm;
}
+// These are called from common hal code to set the current wake alarm.
+void common_hal_sleepio_set_reset_reason(mp_obj_t reset_reason) {
+ // sleepio_module_globals_table[1].value = alarm;
+}
+
const mp_obj_module_t sleepio_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&sleepio_module_globals,
diff --git a/shared-bindings/sleepio/__init__.h b/shared-bindings/sleepio/__init__.h
index ccd3bf4a0..6ea538055 100644
--- a/shared-bindings/sleepio/__init__.h
+++ b/shared-bindings/sleepio/__init__.h
@@ -3,8 +3,7 @@
#include "py/obj.h"
-// This is implemented by shared-bindings so that implementations can set the
-// newest alarm source.
-extern void common_hal_sleepio_set_wake_alarm(mp_obj_t alarm);
+extern mp_obj_t common_hal_sleepio_get_wake_alarm(void);
+extern sleepio_reset_reason_t common_hal_sleepio_get_reset_reason(void);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_SLEEPIO___INIT___H