summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2020-11-19 17:47:12 -0500
committerDan Halbert <halbert@halwitz.org>2020-11-19 17:47:12 -0500
commit39e1f52e28c620db65d59f16a29d5476c4868901 (patch)
tree7d6995457ce336464a41b96ebbfce603d3ba313c /shared-bindings
parentcd436bad1ae9b8b448219979fe98e29ddbb2e953 (diff)
wip; not compiling yet
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/alarm/__init__.c17
-rw-r--r--shared-bindings/alarm/__init__.h4
-rw-r--r--shared-bindings/canio/BusState.c70
-rw-r--r--shared-bindings/canio/BusState.h33
-rw-r--r--shared-bindings/canio/__init__.c60
-rw-r--r--shared-bindings/canio/__init__.h6
6 files changed, 72 insertions, 118 deletions
diff --git a/shared-bindings/alarm/__init__.c b/shared-bindings/alarm/__init__.c
index 20535e156..ecbf7fe04 100644
--- a/shared-bindings/alarm/__init__.c
+++ b/shared-bindings/alarm/__init__.c
@@ -34,11 +34,9 @@
#include "py/obj.h"
#include "py/runtime.h"
-#include "shared-bindings/alarm/pin/__init__.h"
-#include "shared-bindings/alarm/time/__init__.h"
-
STATIC mp_obj_t alarm_sleep_until_alarm(size_t n_args, const mp_obj_t *args) {
// TODO
+ return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(alarm_sleep_until_alarm_obj, 1, MP_OBJ_FUN_ARGS_MAX, alarm_sleep_until_alarm);
@@ -51,6 +49,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(alarm_sleep_until_alarm_obj, 1, MP_OBJ_FUN_A
//|
STATIC mp_obj_t alarm_restart_on_alarm(size_t n_args, const mp_obj_t *args) {
// TODO
+ return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(alarm_restart_on_alarm_obj, 1, MP_OBJ_FUN_ARGS_MAX, alarm_restart_on_alarm);
@@ -102,7 +101,6 @@ mp_map_elem_t alarm_module_globals_table[] = {
};
STATIC MP_DEFINE_MUTABLE_DICT(alarm_module_globals, alarm_module_globals_table);
-// These are called from common_hal code to set the current wake alarm.
void common_hal_alarm_set_wake_alarm(mp_obj_t alarm) {
// Equivalent of:
// alarm.wake_alarm = alarm
@@ -113,7 +111,16 @@ void common_hal_alarm_set_wake_alarm(mp_obj_t alarm) {
}
}
-// These are called from common hal code to set the current wake alarm.
+alarm_reset_reason_t common_hal_alarm_get_reset_reason(void) {
+ mp_map_elem_t *elem =
+ mp_map_lookup(&alarm_module_globals_table, MP_ROM_QSTR(MP_QSTR_reset_reason), MP_MAP_LOOKUP);
+ if (elem) {
+ return elem->value;
+ } else {
+ return mp_const_none;
+ }
+}
+
void common_hal_alarm_set_reset_reason(mp_obj_t reset_reason) {
// Equivalent of:
// alarm.reset_reason = reset_reason
diff --git a/shared-bindings/alarm/__init__.h b/shared-bindings/alarm/__init__.h
index ce9cc79f4..a0ee76e53 100644
--- a/shared-bindings/alarm/__init__.h
+++ b/shared-bindings/alarm/__init__.h
@@ -29,7 +29,11 @@
#include "py/obj.h"
+#include "shared-bindings/alarm/ResetReason.h"
+
extern void common_hal_alarm_set_wake_alarm(mp_obj_t alarm);
+
+extern alarm_reset_reason_t common_hal_alarm_get_reset_reason(void);
extern void common_hal_alarm_set_reset_reason(mp_obj_t reset_reason);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM___INIT___H
diff --git a/shared-bindings/canio/BusState.c b/shared-bindings/canio/BusState.c
deleted file mode 100644
index e0501b8d8..000000000
--- a/shared-bindings/canio/BusState.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * This file is part of the MicroPython project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Jeff Epler 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/canio/BusState.h"
-
-MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, ERROR_ACTIVE, BUS_STATE_ERROR_ACTIVE);
-MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, ERROR_PASSIVE, BUS_STATE_ERROR_PASSIVE);
-MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, ERROR_WARNING, BUS_STATE_ERROR_WARNING);
-MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, BUS_OFF, BUS_STATE_OFF);
-
-//| class BusState:
-//| """The state of the CAN bus"""
-//|
-//| ERROR_ACTIVE: object
-//| """The bus is in the normal (active) state"""
-//|
-//| ERROR_WARNING: object
-//| """The bus is in the normal (active) state, but a moderate number of errors have occurred recently.
-//|
-//| NOTE: Not all implementations may use ERROR_WARNING. Do not rely on seeing ERROR_WARNING before ERROR_PASSIVE."""
-//|
-//| ERROR_PASSIVE: object
-//| """The bus is in the passive state due to the number of errors that have occurred recently.
-//|
-//| This device will acknowledge packets it receives, but cannot transmit messages.
-//| If additional errors occur, this device may progress to BUS_OFF.
-//| If it successfully acknowledges other packets on the bus, it can return to ERROR_WARNING or ERROR_ACTIVE and transmit packets.
-//| """
-//|
-//| BUS_OFF: object
-//| """The bus has turned off due to the number of errors that have
-//| occurred recently. It must be restarted before it will send or receive
-//| packets. This device will neither send or acknowledge packets on the bus."""
-//|
-MAKE_ENUM_MAP(canio_bus_state) {
- MAKE_ENUM_MAP_ENTRY(bus_state, ERROR_ACTIVE),
- MAKE_ENUM_MAP_ENTRY(bus_state, ERROR_PASSIVE),
- MAKE_ENUM_MAP_ENTRY(bus_state, ERROR_WARNING),
- MAKE_ENUM_MAP_ENTRY(bus_state, BUS_OFF),
-};
-STATIC MP_DEFINE_CONST_DICT(canio_bus_state_locals_dict, canio_bus_state_locals_table);
-
-MAKE_PRINTER(canio, canio_bus_state);
-
-MAKE_ENUM_TYPE(canio, BusState, canio_bus_state);
diff --git a/shared-bindings/canio/BusState.h b/shared-bindings/canio/BusState.h
deleted file mode 100644
index e24eba92c..000000000
--- a/shared-bindings/canio/BusState.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * This file is part of the MicroPython project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Jeff Epler 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 {
- BUS_STATE_ERROR_ACTIVE, BUS_STATE_ERROR_PASSIVE, BUS_STATE_ERROR_WARNING, BUS_STATE_OFF
-} canio_bus_state_t;
-
-extern const mp_obj_type_t canio_bus_state_type;
diff --git a/shared-bindings/canio/__init__.c b/shared-bindings/canio/__init__.c
index 451a68c9e..f29d3ab8a 100644
--- a/shared-bindings/canio/__init__.c
+++ b/shared-bindings/canio/__init__.c
@@ -24,16 +24,6 @@
* THE SOFTWARE.
*/
-#include "py/obj.h"
-
-#include "shared-bindings/canio/__init__.h"
-
-#include "shared-bindings/canio/BusState.h"
-#include "shared-bindings/canio/CAN.h"
-#include "shared-bindings/canio/Match.h"
-#include "shared-bindings/canio/Message.h"
-#include "shared-bindings/canio/Listener.h"
-
//| """CAN bus access
//|
//| The `canio` module contains low level classes to support the CAN bus
@@ -67,6 +57,56 @@
//| """
//|
+#include "py/obj.h"
+#include "py/enum.h"
+
+#include "shared-bindings/canio/__init__.h"
+#include "shared-bindings/canio/CAN.h"
+#include "shared-bindings/canio/Match.h"
+#include "shared-bindings/canio/Message.h"
+#include "shared-bindings/canio/Listener.h"
+
+MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, ERROR_ACTIVE, BUS_STATE_ERROR_ACTIVE);
+MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, ERROR_PASSIVE, BUS_STATE_ERROR_PASSIVE);
+MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, ERROR_WARNING, BUS_STATE_ERROR_WARNING);
+MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, BUS_OFF, BUS_STATE_OFF);
+
+//| class BusState:
+//| """The state of the CAN bus"""
+//|
+//| ERROR_ACTIVE: object
+//| """The bus is in the normal (active) state"""
+//|
+//| ERROR_WARNING: object
+//| """The bus is in the normal (active) state, but a moderate number of errors have occurred recently.
+//|
+//| NOTE: Not all implementations may use ERROR_WARNING. Do not rely on seeing ERROR_WARNING before ERROR_PASSIVE."""
+//|
+//| ERROR_PASSIVE: object
+//| """The bus is in the passive state due to the number of errors that have occurred recently.
+//|
+//| This device will acknowledge packets it receives, but cannot transmit messages.
+//| If additional errors occur, this device may progress to BUS_OFF.
+//| If it successfully acknowledges other packets on the bus, it can return to ERROR_WARNING or ERROR_ACTIVE and transmit packets.
+//| """
+//|
+//| BUS_OFF: object
+//| """The bus has turned off due to the number of errors that have
+//| occurred recently. It must be restarted before it will send or receive
+//| packets. This device will neither send or acknowledge packets on the bus."""
+//|
+MAKE_ENUM_MAP(canio_bus_state) {
+ MAKE_ENUM_MAP_ENTRY(bus_state, ERROR_ACTIVE),
+ MAKE_ENUM_MAP_ENTRY(bus_state, ERROR_PASSIVE),
+ MAKE_ENUM_MAP_ENTRY(bus_state, ERROR_WARNING),
+ MAKE_ENUM_MAP_ENTRY(bus_state, BUS_OFF),
+};
+STATIC MP_DEFINE_CONST_DICT(canio_bus_state_locals_dict, canio_bus_state_locals_table);
+
+MAKE_PRINTER(canio, canio_bus_state);
+
+MAKE_ENUM_TYPE(canio, BusState, canio_bus_state);
+
STATIC const mp_rom_map_elem_t canio_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_BusState), MP_ROM_PTR(&canio_bus_state_type) },
{ MP_ROM_QSTR(MP_QSTR_CAN), MP_ROM_PTR(&canio_can_type) },
diff --git a/shared-bindings/canio/__init__.h b/shared-bindings/canio/__init__.h
index 20b6638cd..e24eba92c 100644
--- a/shared-bindings/canio/__init__.h
+++ b/shared-bindings/canio/__init__.h
@@ -25,3 +25,9 @@
*/
#pragma once
+
+typedef enum {
+ BUS_STATE_ERROR_ACTIVE, BUS_STATE_ERROR_PASSIVE, BUS_STATE_ERROR_WARNING, BUS_STATE_OFF
+} canio_bus_state_t;
+
+extern const mp_obj_type_t canio_bus_state_type;