summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authoriot49 <49917707+iot49@users.noreply.github.com>2021-01-05 11:19:11 -0800
committerGitHub <noreply@github.com>2021-01-05 11:19:11 -0800
commit1a82555803ab66bdb608508fccbcc9acc9bac657 (patch)
tree21447176919a7fea924667ca6e9a1f3a802e6f45 /shared-bindings
parent90a299bb1e6c80971b576dc51dd50bca6220b6f7 (diff)
parentf6f1ef7dc26f9e253f09d48a8ec822a2f5e805fb (diff)
Merge branch 'main' into msgpack
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/_bleio/Adapter.c13
-rw-r--r--shared-bindings/_bleio/Characteristic.c4
-rw-r--r--shared-bindings/_bleio/Descriptor.c4
-rw-r--r--shared-bindings/_pixelbuf/PixelBuf.c2
-rw-r--r--shared-bindings/adafruit_bus_device/I2CDevice.c8
-rw-r--r--shared-bindings/adafruit_bus_device/I2CDevice.h2
-rw-r--r--shared-bindings/alarm/SleepMemory.c159
-rw-r--r--shared-bindings/alarm/SleepMemory.h40
-rw-r--r--shared-bindings/alarm/__init__.c49
-rw-r--r--shared-bindings/alarm/__init__.h10
-rw-r--r--shared-bindings/alarm/pin/PinAlarm.c50
-rw-r--r--shared-bindings/alarm/pin/PinAlarm.h18
-rw-r--r--shared-bindings/alarm/time/TimeAlarm.c32
-rw-r--r--shared-bindings/alarm/time/TimeAlarm.h12
-rw-r--r--shared-bindings/alarm/touch/TouchAlarm.c91
-rw-r--r--shared-bindings/alarm/touch/TouchAlarm.h40
-rw-r--r--shared-bindings/camera/ImageFormat.c1
-rw-r--r--shared-bindings/camera/ImageFormat.h2
-rw-r--r--shared-bindings/dualbank/__init__.c115
-rw-r--r--shared-bindings/dualbank/__init__.h35
-rw-r--r--shared-bindings/wifi/Network.c17
-rw-r--r--shared-bindings/wifi/Network.h1
-rw-r--r--shared-bindings/wifi/Radio.c2
23 files changed, 629 insertions, 78 deletions
diff --git a/shared-bindings/_bleio/Adapter.c b/shared-bindings/_bleio/Adapter.c
index 682177093..7d7076aab 100644
--- a/shared-bindings/_bleio/Adapter.c
+++ b/shared-bindings/_bleio/Adapter.c
@@ -33,8 +33,8 @@
#include "shared-bindings/_bleio/Address.h"
#include "shared-bindings/_bleio/Adapter.h"
-#define ADV_INTERVAL_MIN (0.0020f)
-#define ADV_INTERVAL_MIN_STRING "0.0020"
+#define ADV_INTERVAL_MIN (0.02001f)
+#define ADV_INTERVAL_MIN_STRING "0.02001"
#define ADV_INTERVAL_MAX (10.24f)
#define ADV_INTERVAL_MAX_STRING "10.24"
// 20ms is recommended by Apple
@@ -307,7 +307,7 @@ STATIC mp_obj_t bleio_adapter_start_scan(size_t n_args, const mp_obj_t *pos_args
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);
- mp_float_t timeout = 0;
+ mp_float_t timeout = 0.0f;
if (args[ARG_timeout].u_obj != mp_const_none) {
timeout = mp_obj_get_float(args[ARG_timeout].u_obj);
}
@@ -325,6 +325,13 @@ STATIC mp_obj_t bleio_adapter_start_scan(size_t n_args, const mp_obj_t *pos_args
mp_raise_ValueError_varg(translate("interval must be in range %s-%s"), INTERVAL_MIN_STRING, INTERVAL_MAX_STRING);
}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wfloat-equal"
+ if (timeout != 0.0f && timeout < interval) {
+ mp_raise_ValueError(translate("non-zero timeout must be >= interval"));
+ }
+#pragma GCC diagnostic pop
+
const mp_float_t window = mp_obj_float_get(args[ARG_window].u_obj);
if (window > interval) {
mp_raise_ValueError(translate("window must be <= interval"));
diff --git a/shared-bindings/_bleio/Characteristic.c b/shared-bindings/_bleio/Characteristic.c
index 5e384a44c..a0751b7e3 100644
--- a/shared-bindings/_bleio/Characteristic.c
+++ b/shared-bindings/_bleio/Characteristic.c
@@ -110,8 +110,8 @@ STATIC mp_obj_t bleio_characteristic_add_to_service(size_t n_args, const mp_obj_
common_hal_bleio_attribute_security_mode_check_valid(write_perm);
const mp_int_t max_length_int = args[ARG_max_length].u_int;
- if (max_length_int <= 0) {
- mp_raise_ValueError(translate("max_length must be > 0"));
+ if (max_length_int < 0) {
+ mp_raise_ValueError(translate("max_length must be >= 0"));
}
const size_t max_length = (size_t) max_length_int;
const bool fixed_length = args[ARG_fixed_length].u_bool;
diff --git a/shared-bindings/_bleio/Descriptor.c b/shared-bindings/_bleio/Descriptor.c
index c313007c6..60f0acf44 100644
--- a/shared-bindings/_bleio/Descriptor.c
+++ b/shared-bindings/_bleio/Descriptor.c
@@ -101,8 +101,8 @@ STATIC mp_obj_t bleio_descriptor_add_to_characteristic(size_t n_args, const mp_o
common_hal_bleio_attribute_security_mode_check_valid(write_perm);
const mp_int_t max_length_int = args[ARG_max_length].u_int;
- if (max_length_int <= 0) {
- mp_raise_ValueError(translate("max_length must be > 0"));
+ if (max_length_int < 0) {
+ mp_raise_ValueError(translate("max_length must be >= 0"));
}
const size_t max_length = (size_t) max_length_int;
const bool fixed_length = args[ARG_fixed_length].u_bool;
diff --git a/shared-bindings/_pixelbuf/PixelBuf.c b/shared-bindings/_pixelbuf/PixelBuf.c
index 88e8aa801..a4b5b5b1b 100644
--- a/shared-bindings/_pixelbuf/PixelBuf.c
+++ b/shared-bindings/_pixelbuf/PixelBuf.c
@@ -185,7 +185,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(pixelbuf_pixelbuf_get_brightness_obj, pixelbuf_pixelbu
STATIC mp_obj_t pixelbuf_pixelbuf_obj_set_brightness(mp_obj_t self_in, mp_obj_t value) {
- mp_float_t brightness = mp_obj_float_get(value);
+ mp_float_t brightness = mp_obj_get_float(value);
if (brightness > 1) {
brightness = 1;
} else if (brightness < 0) {
diff --git a/shared-bindings/adafruit_bus_device/I2CDevice.c b/shared-bindings/adafruit_bus_device/I2CDevice.c
index 4c9086162..a4c04e198 100644
--- a/shared-bindings/adafruit_bus_device/I2CDevice.c
+++ b/shared-bindings/adafruit_bus_device/I2CDevice.c
@@ -163,7 +163,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_readinto_obj, 2,
//| """
//| ...
//|
-STATIC void write(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, int32_t start, mp_int_t end) {
+STATIC void write(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, int32_t start, mp_int_t end, bool transmit_stop_bit) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_READ);
@@ -173,7 +173,7 @@ STATIC void write(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, in
mp_raise_ValueError(translate("Buffer must be at least length 1"));
}
- uint8_t status = common_hal_adafruit_bus_device_i2cdevice_write(MP_OBJ_TO_PTR(self), ((uint8_t*)bufinfo.buf) + start, length);
+ uint8_t status = common_hal_adafruit_bus_device_i2cdevice_write(MP_OBJ_TO_PTR(self), ((uint8_t*)bufinfo.buf) + start, length, transmit_stop_bit);
if (status != 0) {
mp_raise_OSError(status);
}
@@ -191,7 +191,7 @@ STATIC mp_obj_t adafruit_bus_device_i2cdevice_write(size_t n_args, const mp_obj_
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);
- write(self, args[ARG_buffer].u_obj, args[ARG_start].u_int, args[ARG_end].u_int);
+ write(self, args[ARG_buffer].u_obj, args[ARG_start].u_int, args[ARG_end].u_int, true);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_write_obj, 2, adafruit_bus_device_i2cdevice_write);
@@ -233,7 +233,7 @@ STATIC mp_obj_t adafruit_bus_device_i2cdevice_write_then_readinto(size_t n_args,
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);
- write(self, args[ARG_out_buffer].u_obj, args[ARG_out_start].u_int, args[ARG_out_end].u_int);
+ write(self, args[ARG_out_buffer].u_obj, args[ARG_out_start].u_int, args[ARG_out_end].u_int, false);
readinto(self, args[ARG_in_buffer].u_obj, args[ARG_in_start].u_int, args[ARG_in_end].u_int);
diff --git a/shared-bindings/adafruit_bus_device/I2CDevice.h b/shared-bindings/adafruit_bus_device/I2CDevice.h
index 7b2182ff0..cf7b1321a 100644
--- a/shared-bindings/adafruit_bus_device/I2CDevice.h
+++ b/shared-bindings/adafruit_bus_device/I2CDevice.h
@@ -45,7 +45,7 @@ extern const mp_obj_type_t adafruit_bus_device_i2cdevice_type;
// Initializes the hardware peripheral.
extern void common_hal_adafruit_bus_device_i2cdevice_construct(adafruit_bus_device_i2cdevice_obj_t *self, busio_i2c_obj_t *i2c, uint8_t device_address);
extern uint8_t common_hal_adafruit_bus_device_i2cdevice_readinto(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, size_t length);
-extern uint8_t common_hal_adafruit_bus_device_i2cdevice_write(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, size_t length);
+extern uint8_t common_hal_adafruit_bus_device_i2cdevice_write(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, size_t length, bool transmit_stop_bit);
extern void common_hal_adafruit_bus_device_i2cdevice_lock(adafruit_bus_device_i2cdevice_obj_t *self);
extern void common_hal_adafruit_bus_device_i2cdevice_unlock(adafruit_bus_device_i2cdevice_obj_t *self);
extern void common_hal_adafruit_bus_device_i2cdevice_probe_for_device(adafruit_bus_device_i2cdevice_obj_t *self);
diff --git a/shared-bindings/alarm/SleepMemory.c b/shared-bindings/alarm/SleepMemory.c
new file mode 100644
index 000000000..bec0b7665
--- /dev/null
+++ b/shared-bindings/alarm/SleepMemory.c
@@ -0,0 +1,159 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
+ * Copyright (c) 2020 Dan Halbert 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/binary.h"
+#include "py/objproperty.h"
+#include "py/runtime.h"
+#include "py/runtime0.h"
+
+#include "shared-bindings/alarm/SleepMemory.h"
+#include "supervisor/shared/translate.h"
+
+//| class SleepMemory:
+//| """Store raw bytes in RAM that persists during deep sleep.
+//| The class acts as a ``bytearray``.
+//| If power is lost, the memory contents are lost.
+//|
+//| Note that this class can't be imported and used directly. The sole
+//| instance of :class:`SleepMemory` is available at
+//| :attr:`alarm.sleep_memory`.
+//|
+//| Usage::
+//|
+//| import alarm
+//| alarm.sleep_memory[0] = True
+//| alarm.sleep_memory[1] = 12
+//| """
+
+//| def __init__(self) -> None:
+//| """Not used. Access the sole instance through `alarm.sleep_memory`."""
+//| ...
+//|
+
+STATIC const mp_rom_map_elem_t alarm_sleep_memory_locals_dict_table[] = {
+};
+
+STATIC MP_DEFINE_CONST_DICT(alarm_sleep_memory_locals_dict, alarm_sleep_memory_locals_dict_table);
+
+//| @overload
+//| def __getitem__(self, index: slice) -> bytearray: ...
+//| @overload
+//| def __getitem__(self, index: int) -> int:
+//| """Returns the value at the given index."""
+//| ...
+//|
+//| @overload
+//| def __setitem__(self, index: slice, value: ReadableBuffer) -> None: ...
+//| @overload
+//| def __setitem__(self, index: int, value: int) -> None:
+//| """Set the value at the given index."""
+//| ...
+//|
+STATIC mp_obj_t alarm_sleep_memory_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) {
+ if (value == MP_OBJ_NULL) {
+ // delete item
+ // slice deletion
+ return MP_OBJ_NULL; // op not supported
+ } else {
+ alarm_sleep_memory_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ if (0) {
+#if MICROPY_PY_BUILTINS_SLICE
+ } else if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) {
+ mp_bound_slice_t slice;
+ if (!mp_seq_get_fast_slice_indexes(common_hal_alarm_sleep_memory_get_length(self), index_in, &slice)) {
+ mp_raise_NotImplementedError(translate("only slices with step=1 (aka None) are supported"));
+ }
+ if (value != MP_OBJ_SENTINEL) {
+ #if MICROPY_PY_ARRAY_SLICE_ASSIGN
+ // Assign
+ size_t src_len = slice.stop - slice.start;
+ uint8_t* src_items;
+ if (MP_OBJ_IS_TYPE(value, &mp_type_array) ||
+ MP_OBJ_IS_TYPE(value, &mp_type_bytearray) ||
+ MP_OBJ_IS_TYPE(value, &mp_type_memoryview) ||
+ MP_OBJ_IS_TYPE(value, &mp_type_bytes)) {
+ mp_buffer_info_t bufinfo;
+ mp_get_buffer_raise(value, &bufinfo, MP_BUFFER_READ);
+ if (bufinfo.len != src_len) {
+ mp_raise_ValueError(translate("Slice and value different lengths."));
+ }
+ src_len = bufinfo.len;
+ src_items = bufinfo.buf;
+ if (1 != mp_binary_get_size('@', bufinfo.typecode, NULL)) {
+ mp_raise_ValueError(translate("Array values should be single bytes."));
+ }
+ } else {
+ mp_raise_NotImplementedError(translate("array/bytes required on right side"));
+ }
+
+ if (!common_hal_alarm_sleep_memory_set_bytes(self, slice.start, src_items, src_len)) {
+ mp_raise_RuntimeError(translate("Unable to write to sleep_memory."));
+ }
+ return mp_const_none;
+ #else
+ return MP_OBJ_NULL; // op not supported
+ #endif
+ } else {
+ // Read slice.
+ size_t len = slice.stop - slice.start;
+ uint8_t *items = m_new(uint8_t, len);
+ common_hal_alarm_sleep_memory_get_bytes(self, slice.start, items, len);
+ return mp_obj_new_bytearray_by_ref(len, items);
+ }
+#endif
+ } else {
+ // Single index rather than slice.
+ size_t index = mp_get_index(self->base.type, common_hal_alarm_sleep_memory_get_length(self),
+ index_in, false);
+ if (value == MP_OBJ_SENTINEL) {
+ // load
+ uint8_t value_out;
+ common_hal_alarm_sleep_memory_get_bytes(self, index, &value_out, 1);
+ return MP_OBJ_NEW_SMALL_INT(value_out);
+ } else {
+ // store
+ mp_int_t byte_value = mp_obj_get_int(value);
+ if (byte_value > 0xff || byte_value < 0) {
+ mp_raise_ValueError(translate("Bytes must be between 0 and 255."));
+ }
+ uint8_t short_value = byte_value;
+ if (!common_hal_alarm_sleep_memory_set_bytes(self, index, &short_value, 1)) {
+ mp_raise_RuntimeError(translate("Unable to write to sleep_memory."));
+ }
+ return mp_const_none;
+ }
+ }
+ }
+}
+
+const mp_obj_type_t alarm_sleep_memory_type = {
+ { &mp_type_type },
+ .name = MP_QSTR_SleepMemory,
+ .subscr = alarm_sleep_memory_subscr,
+ .print = NULL,
+ .locals_dict = (mp_obj_t)&alarm_sleep_memory_locals_dict,
+};
diff --git a/shared-bindings/alarm/SleepMemory.h b/shared-bindings/alarm/SleepMemory.h
new file mode 100644
index 000000000..e7a56521b
--- /dev/null
+++ b/shared-bindings/alarm/SleepMemory.h
@@ -0,0 +1,40 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
+ * 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.
+ */
+
+#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_SLEEPMEMORY_H
+#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_SLEEPMEMORY_H
+
+#include "common-hal/alarm/SleepMemory.h"
+
+extern const mp_obj_type_t alarm_sleep_memory_type;
+
+uint32_t common_hal_alarm_sleep_memory_get_length(alarm_sleep_memory_obj_t *self);
+
+bool common_hal_alarm_sleep_memory_set_bytes(alarm_sleep_memory_obj_t *self, uint32_t start_index, const uint8_t* values, uint32_t len);
+void common_hal_alarm_sleep_memory_get_bytes(alarm_sleep_memory_obj_t *self, uint32_t start_index, uint8_t* values, uint32_t len);
+
+#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_SLEEPMEMORY_H
diff --git a/shared-bindings/alarm/__init__.c b/shared-bindings/alarm/__init__.c
index 5420b8404..7023c70e5 100644
--- a/shared-bindings/alarm/__init__.c
+++ b/shared-bindings/alarm/__init__.c
@@ -29,8 +29,10 @@
#include "py/runtime.h"
#include "shared-bindings/alarm/__init__.h"
+#include "shared-bindings/alarm/SleepMemory.h"
#include "shared-bindings/alarm/pin/PinAlarm.h"
#include "shared-bindings/alarm/time/TimeAlarm.h"
+#include "shared-bindings/alarm/touch/TouchAlarm.h"
#include "shared-bindings/supervisor/Runtime.h"
#include "shared-bindings/time/__init__.h"
#include "supervisor/shared/autoreload.h"
@@ -57,7 +59,11 @@
//| maintaining the connection takes priority and power consumption may not be reduced.
//| """
+//| sleep_memory: SleepMemory
+//| """Memory that persists during deep sleep.
+//| This object is the sole instance of `alarm.SleepMemory`."""
//|
+
//| wake_alarm: Alarm
//| """The most recently triggered alarm. If CircuitPython was sleeping, the alarm the woke it from sleep."""
//|
@@ -66,8 +72,9 @@
void validate_objs_are_alarms(size_t n_args, const mp_obj_t *objs) {
for (size_t i = 0; i < n_args; i++) {
- if (MP_OBJ_IS_TYPE(objs[i], &alarm_pin_pin_alarm_type) ||
- MP_OBJ_IS_TYPE(objs[i], &alarm_time_time_alarm_type)) {
+ if (MP_OBJ_IS_TYPE(objs[i], &alarm_pin_pinalarm_type) ||
+ MP_OBJ_IS_TYPE(objs[i], &alarm_time_timealarm_type) ||
+ MP_OBJ_IS_TYPE(objs[i], &alarm_touch_touchalarm_type)) {
continue;
}
mp_raise_TypeError_varg(translate("Expected an alarm"));
@@ -154,7 +161,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(alarm_exit_and_deep_sleep_until_alarms_obj,
STATIC const mp_map_elem_t alarm_pin_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pin) },
- { MP_ROM_QSTR(MP_QSTR_PinAlarm), MP_OBJ_FROM_PTR(&alarm_pin_pin_alarm_type) },
+ { MP_ROM_QSTR(MP_QSTR_PinAlarm), MP_OBJ_FROM_PTR(&alarm_pin_pinalarm_type) },
};
STATIC MP_DEFINE_CONST_DICT(alarm_pin_globals, alarm_pin_globals_table);
@@ -167,7 +174,7 @@ STATIC const mp_obj_module_t alarm_pin_module = {
STATIC const mp_map_elem_t alarm_time_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_time) },
- { MP_ROM_QSTR(MP_QSTR_TimeAlarm), MP_OBJ_FROM_PTR(&alarm_time_time_alarm_type) },
+ { MP_ROM_QSTR(MP_QSTR_TimeAlarm), MP_OBJ_FROM_PTR(&alarm_time_timealarm_type) },
};
STATIC MP_DEFINE_CONST_DICT(alarm_time_globals, alarm_time_globals_table);
@@ -177,6 +184,19 @@ STATIC const mp_obj_module_t alarm_time_module = {
.globals = (mp_obj_dict_t*)&alarm_time_globals,
};
+STATIC const mp_map_elem_t alarm_touch_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_touch) },
+ { MP_ROM_QSTR(MP_QSTR_TouchAlarm), MP_OBJ_FROM_PTR(&alarm_touch_touchalarm_type) },
+};
+
+STATIC MP_DEFINE_CONST_DICT(alarm_touch_globals, alarm_touch_globals_table);
+
+STATIC const mp_obj_module_t alarm_touch_module = {
+ .base = { &mp_type_module },
+ .globals = (mp_obj_dict_t*)&alarm_touch_globals,
+};
+
+// The module table is mutable because .wake_alarm is a mutable attribute.
STATIC mp_map_elem_t alarm_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_alarm) },
@@ -188,18 +208,33 @@ STATIC mp_map_elem_t alarm_module_globals_table[] = {
MP_OBJ_FROM_PTR(&alarm_exit_and_deep_sleep_until_alarms_obj) },
{ MP_ROM_QSTR(MP_QSTR_pin), MP_OBJ_FROM_PTR(&alarm_pin_module) },
- { MP_ROM_QSTR(MP_QSTR_time), MP_OBJ_FROM_PTR(&alarm_time_module) }
+ { MP_ROM_QSTR(MP_QSTR_time), MP_OBJ_FROM_PTR(&alarm_time_module) },
+ { MP_ROM_QSTR(MP_QSTR_touch), MP_OBJ_FROM_PTR(&alarm_touch_module) },
+ { MP_ROM_QSTR(MP_QSTR_SleepMemory), MP_OBJ_FROM_PTR(&alarm_sleep_memory_type) },
+ { MP_ROM_QSTR(MP_QSTR_sleep_memory), MP_OBJ_FROM_PTR(&alarm_sleep_memory_obj) },
};
STATIC MP_DEFINE_MUTABLE_DICT(alarm_module_globals, alarm_module_globals_table);
-void common_hal_alarm_set_wake_alarm(mp_obj_t alarm) {
+// Fetch value from module dict.
+mp_obj_t alarm_get_wake_alarm(void) {
+ mp_map_elem_t *elem =
+ mp_map_lookup(&alarm_module_globals.map, MP_ROM_QSTR(MP_QSTR_wake_alarm), MP_MAP_LOOKUP);
+ if (elem) {
+ return elem->value;
+ } else {
+ return NULL;
+ }
+}
+
+// Initialize .wake_alarm value.
+void alarm_save_wake_alarm(void) {
// Equivalent of:
// alarm.wake_alarm = alarm
mp_map_elem_t *elem =
mp_map_lookup(&alarm_module_globals.map, MP_ROM_QSTR(MP_QSTR_wake_alarm), MP_MAP_LOOKUP);
if (elem) {
- elem->value = alarm;
+ elem->value = common_hal_alarm_get_wake_alarm();
}
}
diff --git a/shared-bindings/alarm/__init__.h b/shared-bindings/alarm/__init__.h
index 5a8c613d9..154f91e26 100644
--- a/shared-bindings/alarm/__init__.h
+++ b/shared-bindings/alarm/__init__.h
@@ -43,10 +43,18 @@ extern void common_hal_alarm_set_deep_sleep_alarms(size_t n_alarms, const mp_obj
// Deep sleep is entered outside of the VM so we omit the `common_hal_` prefix.
extern NORETURN void alarm_enter_deep_sleep(void);
+// Fetches value from module dict.
+extern mp_obj_t alarm_get_wake_alarm(void);
+
+extern void common_hal_alarm_gc_collect(void);
+extern mp_obj_t common_hal_alarm_get_wake_alarm(void);
+
// Used by wake-up code.
-extern void common_hal_alarm_set_wake_alarm(mp_obj_t alarm);
+void alarm_save_wake_alarm(void);
+
// True if an alarm is alerting. This is most useful for pretend deep sleep.
extern bool alarm_woken_from_sleep(void);
+
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM___INIT___H
diff --git a/shared-bindings/alarm/pin/PinAlarm.c b/shared-bindings/alarm/pin/PinAlarm.c
index 7a5617142..89de016bc 100644
--- a/shared-bindings/alarm/pin/PinAlarm.c
+++ b/shared-bindings/alarm/pin/PinAlarm.c
@@ -60,9 +60,9 @@
//| """
//| ...
//|
-STATIC mp_obj_t alarm_pin_pin_alarm_make_new(const mp_obj_type_t *type, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
- alarm_pin_pin_alarm_obj_t *self = m_new_obj(alarm_pin_pin_alarm_obj_t);
- self->base.type = &alarm_pin_pin_alarm_type;
+STATIC mp_obj_t alarm_pin_pinalarm_make_new(const mp_obj_type_t *type, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+ alarm_pin_pinalarm_obj_t *self = m_new_obj(alarm_pin_pinalarm_obj_t);
+ self->base.type = &alarm_pin_pinalarm_type;
enum { ARG_pin, ARG_value, ARG_edge, ARG_pull };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ },
@@ -75,7 +75,7 @@ STATIC mp_obj_t alarm_pin_pin_alarm_make_new(const mp_obj_type_t *type, mp_uint_
mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[ARG_pin].u_obj);
- common_hal_alarm_pin_pin_alarm_construct(self,
+ common_hal_alarm_pin_pinalarm_construct(self,
pin,
args[ARG_value].u_bool,
args[ARG_edge].u_bool,
@@ -87,15 +87,19 @@ STATIC mp_obj_t alarm_pin_pin_alarm_make_new(const mp_obj_type_t *type, mp_uint_
//| pin: microcontroller.Pin
//| """The trigger pin."""
//|
-STATIC mp_obj_t alarm_pin_pin_alarm_obj_get_pin(mp_obj_t self_in) {
- alarm_pin_pin_alarm_obj_t *self = MP_OBJ_TO_PTR(self_in);
- return common_hal_alarm_pin_pin_alarm_get_pin(self);
+STATIC mp_obj_t alarm_pin_pinalarm_obj_get_pin(mp_obj_t self_in) {
+ alarm_pin_pinalarm_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ mcu_pin_obj_t* pin = common_hal_alarm_pin_pinalarm_get_pin(self);
+ if (pin == NULL) {
+ return mp_const_none;
+ }
+ return MP_OBJ_FROM_PTR(pin);
}
-MP_DEFINE_CONST_FUN_OBJ_1(alarm_pin_pin_alarm_get_pin_obj, alarm_pin_pin_alarm_obj_get_pin);
+MP_DEFINE_CONST_FUN_OBJ_1(alarm_pin_pinalarm_get_pin_obj, alarm_pin_pinalarm_obj_get_pin);
-const mp_obj_property_t alarm_pin_pin_alarm_pin_obj = {
+const mp_obj_property_t alarm_pin_pinalarm_pin_obj = {
.base.type = &mp_type_property,
- .proxy = {(mp_obj_t)&alarm_pin_pin_alarm_get_pin_obj,
+ .proxy = {(mp_obj_t)&alarm_pin_pinalarm_get_pin_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj},
};
@@ -103,29 +107,29 @@ const mp_obj_property_t alarm_pin_pin_alarm_pin_obj = {
//| value: bool
//| """The value on which to trigger."""
//|
-STATIC mp_obj_t alarm_pin_pin_alarm_obj_get_value(mp_obj_t self_in) {
- alarm_pin_pin_alarm_obj_t *self = MP_OBJ_TO_PTR(self_in);
- return mp_obj_new_bool(common_hal_alarm_pin_pin_alarm_get_value(self));
+STATIC mp_obj_t alarm_pin_pinalarm_obj_get_value(mp_obj_t self_in) {
+ alarm_pin_pinalarm_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ return mp_obj_new_bool(common_hal_alarm_pin_pinalarm_get_value(self));
}
-MP_DEFINE_CONST_FUN_OBJ_1(alarm_pin_pin_alarm_get_value_obj, alarm_pin_pin_alarm_obj_get_value);
+MP_DEFINE_CONST_FUN_OBJ_1(alarm_pin_pinalarm_get_value_obj, alarm_pin_pinalarm_obj_get_value);
-const mp_obj_property_t alarm_pin_pin_alarm_value_obj = {
+const mp_obj_property_t alarm_pin_pinalarm_value_obj = {
.base.type = &mp_type_property,
- .proxy = {(mp_obj_t)&alarm_pin_pin_alarm_get_value_obj,
+ .proxy = {(mp_obj_t)&alarm_pin_pinalarm_get_value_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj},
};
-STATIC const mp_rom_map_elem_t alarm_pin_pin_alarm_locals_dict_table[] = {
- { MP_ROM_QSTR(MP_QSTR_pin), MP_ROM_PTR(&alarm_pin_pin_alarm_pin_obj) },
- { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&alarm_pin_pin_alarm_value_obj) },
+STATIC const mp_rom_map_elem_t alarm_pin_pinalarm_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_pin), MP_ROM_PTR(&alarm_pin_pinalarm_pin_obj) },
+ { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&alarm_pin_pinalarm_value_obj) },
};
-STATIC MP_DEFINE_CONST_DICT(alarm_pin_pin_alarm_locals_dict, alarm_pin_pin_alarm_locals_dict_table);
+STATIC MP_DEFINE_CONST_DICT(alarm_pin_pinalarm_locals_dict, alarm_pin_pinalarm_locals_dict_table);
-const mp_obj_type_t alarm_pin_pin_alarm_type = {
+const mp_obj_type_t alarm_pin_pinalarm_type = {
{ &mp_type_type },
.name = MP_QSTR_PinAlarm,
- .make_new = alarm_pin_pin_alarm_make_new,
- .locals_dict = (mp_obj_t)&alarm_pin_pin_alarm_locals_dict,
+ .make_new = alarm_pin_pinalarm_make_new,
+ .locals_dict = (mp_obj_t)&alarm_pin_pinalarm_locals_dict,
};
diff --git a/shared-bindings/alarm/pin/PinAlarm.h b/shared-bindings/alarm/pin/PinAlarm.h
index 49ba71089..48865009c 100644
--- a/shared-bindings/alarm/pin/PinAlarm.h
+++ b/shared-bindings/alarm/pin/PinAlarm.h
@@ -24,20 +24,20 @@
* THE SOFTWARE.
*/
-#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_PIN_PIN_ALARM_H
-#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_PIN_PIN_ALARM_H
+#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_PIN_PINALARM_H
+#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_PIN_PINALARM_H
#include "py/obj.h"
#include "py/objtuple.h"
#include "common-hal/microcontroller/Pin.h"
#include "common-hal/alarm/pin/PinAlarm.h"
-extern const mp_obj_type_t alarm_pin_pin_alarm_type;
+extern const mp_obj_type_t alarm_pin_pinalarm_type;
-void common_hal_alarm_pin_pin_alarm_construct(alarm_pin_pin_alarm_obj_t *self, mcu_pin_obj_t *pin, bool value, bool edge, bool pull);
-extern mcu_pin_obj_t *common_hal_alarm_pin_pin_alarm_get_pin(alarm_pin_pin_alarm_obj_t *self);
-extern bool common_hal_alarm_pin_pin_alarm_get_value(alarm_pin_pin_alarm_obj_t *self);
-extern bool common_hal_alarm_pin_pin_alarm_get_edge(alarm_pin_pin_alarm_obj_t *self);
-extern bool common_hal_alarm_pin_pin_alarm_get_pull(alarm_pin_pin_alarm_obj_t *self);
+void common_hal_alarm_pin_pinalarm_construct(alarm_pin_pinalarm_obj_t *self, mcu_pin_obj_t *pin, bool value, bool edge, bool pull);
+extern mcu_pin_obj_t *common_hal_alarm_pin_pinalarm_get_pin(alarm_pin_pinalarm_obj_t *self);
+extern bool common_hal_alarm_pin_pinalarm_get_value(alarm_pin_pinalarm_obj_t *self);
+extern bool common_hal_alarm_pin_pinalarm_get_edge(alarm_pin_pinalarm_obj_t *self);
+extern bool common_hal_alarm_pin_pinalarm_get_pull(alarm_pin_pinalarm_obj_t *self);
-#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_PIN_PIN_ALARM_H
+#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_PIN_PINALARM_H
diff --git a/shared-bindings/alarm/time/TimeAlarm.c b/shared-bindings/alarm/time/TimeAlarm.c
index 1c4d976ad..1c9b8d37c 100644
--- a/shared-bindings/alarm/time/TimeAlarm.c
+++ b/shared-bindings/alarm/time/TimeAlarm.c
@@ -56,10 +56,10 @@ mp_obj_t MP_WEAK rtc_get_time_source_time(void) {
//| """
//| ...
//|
-STATIC mp_obj_t alarm_time_time_alarm_make_new(const mp_obj_type_t *type,
+STATIC mp_obj_t alarm_time_timealarm_make_new(const mp_obj_type_t *type,
mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
- alarm_time_time_alarm_obj_t *self = m_new_obj(alarm_time_time_alarm_obj_t);
- self->base.type = &alarm_time_time_alarm_type;
+ alarm_time_timealarm_obj_t *self = m_new_obj(alarm_time_timealarm_obj_t);
+ self->base.type = &alarm_time_timealarm_type;
enum { ARG_monotonic_time, ARG_epoch_time };
static const mp_arg_t allowed_args[] = {
@@ -105,7 +105,7 @@ STATIC mp_obj_t alarm_time_time_alarm_make_new(const mp_obj_type_t *type,
mp_raise_ValueError(translate("Time is in the past."));
}
- common_hal_alarm_time_time_alarm_construct(self, monotonic_time);
+ common_hal_alarm_time_timealarm_construct(self, monotonic_time);
return MP_OBJ_FROM_PTR(self);
}
@@ -116,28 +116,28 @@ STATIC mp_obj_t alarm_time_time_alarm_make_new(const mp_obj_type_t *type,
//| by this property only as a `time.monotonic()` time.
//| """
//|
-STATIC mp_obj_t alarm_time_time_alarm_obj_get_monotonic_time(mp_obj_t self_in) {
- alarm_time_time_alarm_obj_t *self = MP_OBJ_TO_PTR(self_in);
- return mp_obj_new_float(common_hal_alarm_time_time_alarm_get_monotonic_time(self));
+STATIC mp_obj_t alarm_time_timealarm_obj_get_monotonic_time(mp_obj_t self_in) {
+ alarm_time_timealarm_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ return mp_obj_new_float(common_hal_alarm_time_timealarm_get_monotonic_time(self));
}
-MP_DEFINE_CONST_FUN_OBJ_1(alarm_time_time_alarm_get_monotonic_time_obj, alarm_time_time_alarm_obj_get_monotonic_time);
+MP_DEFINE_CONST_FUN_OBJ_1(alarm_time_timealarm_get_monotonic_time_obj, alarm_time_timealarm_obj_get_monotonic_time);
-const mp_obj_property_t alarm_time_time_alarm_monotonic_time_obj = {
+const mp_obj_property_t alarm_time_timealarm_monotonic_time_obj = {
.base.type = &mp_type_property,
- .proxy = {(mp_obj_t)&alarm_time_time_alarm_get_monotonic_time_obj,
+ .proxy = {(mp_obj_t)&alarm_time_timealarm_get_monotonic_time_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj},
};
-STATIC const mp_rom_map_elem_t alarm_time_time_alarm_locals_dict_table[] = {
- { MP_ROM_QSTR(MP_QSTR_monotonic_time), MP_ROM_PTR(&alarm_time_time_alarm_monotonic_time_obj) },
+STATIC const mp_rom_map_elem_t alarm_time_timealarm_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_monotonic_time), MP_ROM_PTR(&alarm_time_timealarm_monotonic_time_obj) },
};
-STATIC MP_DEFINE_CONST_DICT(alarm_time_time_alarm_locals_dict, alarm_time_time_alarm_locals_dict_table);
+STATIC MP_DEFINE_CONST_DICT(alarm_time_timealarm_locals_dict, alarm_time_timealarm_locals_dict_table);
-const mp_obj_type_t alarm_time_time_alarm_type = {
+const mp_obj_type_t alarm_time_timealarm_type = {
{ &mp_type_type },
.name = MP_QSTR_TimeAlarm,
- .make_new = alarm_time_time_alarm_make_new,
- .locals_dict = (mp_obj_t)&alarm_time_time_alarm_locals_dict,
+ .make_new = alarm_time_timealarm_make_new,
+ .locals_dict = (mp_obj_t)&alarm_time_timealarm_locals_dict,
};
diff --git a/shared-bindings/alarm/time/TimeAlarm.h b/shared-bindings/alarm/time/TimeAlarm.h
index ceb3291c9..0a4b9caf4 100644
--- a/shared-bindings/alarm/time/TimeAlarm.h
+++ b/shared-bindings/alarm/time/TimeAlarm.h
@@ -24,16 +24,16 @@
* THE SOFTWARE.
*/
-#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME_MONOTONIC_TIME_ALARM_H
-#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME_MONOTINIC_TIME_ALARM_H
+#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME_TIMEALARM_H
+#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME_TIMEALARM_H
#include "py/obj.h"
#include "common-hal/alarm/time/TimeAlarm.h"
-extern const mp_obj_type_t alarm_time_time_alarm_type;
+extern const mp_obj_type_t alarm_time_timealarm_type;
-extern void common_hal_alarm_time_time_alarm_construct(alarm_time_time_alarm_obj_t *self, mp_float_t monotonic_time);
-extern mp_float_t common_hal_alarm_time_time_alarm_get_monotonic_time(alarm_time_time_alarm_obj_t *self);
+extern void common_hal_alarm_time_timealarm_construct(alarm_time_timealarm_obj_t *self, mp_float_t monotonic_time);
+extern mp_float_t common_hal_alarm_time_timealarm_get_monotonic_time(alarm_time_timealarm_obj_t *self);
-#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME_MONOTONIC_TIME_ALARM_H
+#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME_TIMEALARM_H
diff --git a/shared-bindings/alarm/touch/TouchAlarm.c b/shared-bindings/alarm/touch/TouchAlarm.c
new file mode 100644
index 000000000..4259b71bd
--- /dev/null
+++ b/shared-bindings/alarm/touch/TouchAlarm.c
@@ -0,0 +1,91 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 microDev
+ *
+ * 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 "shared-bindings/alarm/touch/TouchAlarm.h"
+#include "shared-bindings/board/__init__.h"
+
+#include "py/objproperty.h"
+
+//| class TouchAlarm:
+//| """Trigger an alarm when touch is detected."""
+//|
+//| def __init__(self, *pin: microcontroller.Pin) -> None:
+//| """Create an alarm that will be triggered when the given pin is touched.
+//| The alarm is not active until it is passed to an `alarm`-enabling function, such as
+//| `alarm.light_sleep_until_alarms()` or `alarm.exit_and_deep_sleep_until_alarms()`.
+//|
+//| :param microcontroller.Pin pin: The pin to monitor. On some ports, the choice of pin
+//| may be limited due to hardware restrictions, particularly for deep-sleep alarms.
+//| """
+//| ...
+//|
+STATIC mp_obj_t alarm_touch_touchalarm_make_new(const mp_obj_type_t *type,
+ mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+ alarm_touch_touchalarm_obj_t *self = m_new_obj(alarm_touch_touchalarm_obj_t);
+ self->base.type = &alarm_touch_touchalarm_type;
+
+ enum { ARG_pin };
+ static const mp_arg_t allowed_args[] = {
+ { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ },
+ };
+
+ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
+ mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
+
+ const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[ARG_pin].u_obj);
+
+ common_hal_alarm_touch_touchalarm_construct(self, pin);
+
+ return MP_OBJ_FROM_PTR(self);
+}
+
+//| pin: microcontroller.Pin
+//| """The trigger pin."""
+//|
+STATIC mp_obj_t alarm_touch_touchalarm_obj_get_pin(mp_obj_t self_in) {
+ alarm_touch_touchalarm_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ return MP_OBJ_FROM_PTR(self->pin);
+}
+MP_DEFINE_CONST_FUN_OBJ_1(alarm_touch_touchalarm_get_pin_obj, alarm_touch_touchalarm_obj_get_pin);
+
+const mp_obj_property_t alarm_touch_touchalarm_pin_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&alarm_touch_touchalarm_get_pin_obj,
+ (mp_obj_t)&mp_const_none_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
+
+STATIC const mp_rom_map_elem_t alarm_touch_touchalarm_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_pin), MP_ROM_PTR(&alarm_touch_touchalarm_pin_obj) },
+};
+STATIC MP_DEFINE_CONST_DICT(alarm_touch_touchalarm_locals_dict, alarm_touch_touchalarm_locals_dict_table);
+
+const mp_obj_type_t alarm_touch_touchalarm_type = {
+ { &mp_type_type },
+ .name = MP_QSTR_TouchAlarm,
+ .make_new = alarm_touch_touchalarm_make_new,
+ .locals_dict = (mp_obj_t)&alarm_touch_touchalarm_locals_dict,
+};
diff --git a/shared-bindings/alarm/touch/TouchAlarm.h b/shared-bindings/alarm/touch/TouchAlarm.h
new file mode 100644
index 000000000..1b70d4dae
--- /dev/null
+++ b/shared-bindings/alarm/touch/TouchAlarm.h
@@ -0,0 +1,40 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 microDev
+ *
+ * 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.
+ */
+
+#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TOUCH_TOUCHALARM_H
+#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TOUCH_TOUCHALARM_H
+
+#include "py/obj.h"
+#include "py/runtime.h"
+
+#include "common-hal/microcontroller/Pin.h"
+#include "common-hal/alarm/touch/TouchAlarm.h"
+
+extern const mp_obj_type_t alarm_touch_touchalarm_type;
+
+extern void common_hal_alarm_touch_touchalarm_construct(alarm_touch_touchalarm_obj_t *self, const mcu_pin_obj_t *pin);
+
+#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TOUCH_TOUCHALARM_H
diff --git a/shared-bindings/camera/ImageFormat.c b/shared-bindings/camera/ImageFormat.c
index d4bdddc56..9f2f9617f 100644
--- a/shared-bindings/camera/ImageFormat.c
+++ b/shared-bindings/camera/ImageFormat.c
@@ -38,7 +38,6 @@
//| RGB565: ImageFormat
//| """RGB565 format."""
//|
-const mp_obj_type_t camera_imageformat_type;
const camera_imageformat_obj_t camera_imageformat_jpg_obj = {
{ &camera_imageformat_type },
diff --git a/shared-bindings/camera/ImageFormat.h b/shared-bindings/camera/ImageFormat.h
index 8abc88438..32a36354f 100644
--- a/shared-bindings/camera/ImageFormat.h
+++ b/shared-bindings/camera/ImageFormat.h
@@ -35,7 +35,7 @@ typedef enum {
IMAGEFORMAT_RGB565,
} camera_imageformat_t;
-const mp_obj_type_t camera_imageformat_type;
+extern const mp_obj_type_t camera_imageformat_type;
camera_imageformat_t camera_imageformat_obj_to_type(mp_obj_t obj);
mp_obj_t camera_imageformat_type_to_obj(camera_imageformat_t mode);
diff --git a/shared-bindings/dualbank/__init__.c b/shared-bindings/dualbank/__init__.c
new file mode 100644
index 000000000..8021ab18b
--- /dev/null
+++ b/shared-bindings/dualbank/__init__.c
@@ -0,0 +1,115 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 microDev
+ *
+ * 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 "shared-bindings/dualbank/__init__.h"
+
+//| """DUALBANK Module
+//|
+//| The `dualbank` module adds ability to update and switch
+//| between the two app partitions.
+//|
+//| There are two identical partitions, these contain different
+//| firmware versions.
+//| Having two partitions enables rollback functionality.
+//|
+//| The two partitions are defined as boot partition and
+//| next-update partition. Calling `dualbank.flash()` writes
+//| the next-update partition.
+//|
+//| After the next-update partition is written a validation
+//| check is performed and on a successful validation this
+//| partition is set as the boot partition. On next reset,
+//| firmware will be loaded from this partition.
+//|
+//| Here is the sequence of commands to follow:
+//|
+//| .. code-block:: python
+//|
+//| import dualbank
+//|
+//| dualbank.flash(buffer, offset)
+//| dualbank.switch()
+//| """
+//| ...
+//|
+
+//| def flash(*buffer: ReadableBuffer, offset: int=0) -> None:
+//| """Writes one of two app partitions at the given offset.
+//|
+//| This can be called multiple times when flashing the firmware
+//| in small chunks.
+//| """
+//| ...
+//|
+STATIC mp_obj_t dualbank_flash(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+ enum { ARG_buffer, ARG_offset };
+ static const mp_arg_t allowed_args[] = {
+ { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED },
+ { MP_QSTR_offset, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
+ };
+
+ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
+ mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
+
+ if (args[ARG_offset].u_int < 0) {
+ mp_raise_ValueError(translate("offset must be >= 0"));
+ }
+
+ mp_buffer_info_t bufinfo;
+ mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_READ);
+
+ common_hal_dualbank_flash(bufinfo.buf, bufinfo.len, args[ARG_offset].u_int);
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_KW(dualbank_flash_obj, 0, dualbank_flash);
+
+//| def switch() -> None:
+//| """Switches the boot partition.
+//|
+//| On next reset, firmware will be loaded from the partition
+//| just switched over to.
+//| """
+//| ...
+//|
+STATIC mp_obj_t dualbank_switch(void) {
+ common_hal_dualbank_switch();
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_0(dualbank_switch_obj, dualbank_switch);
+
+STATIC const mp_rom_map_elem_t dualbank_module_globals_table[] = {
+ // module name
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_dualbank) },
+ // module functions
+ { MP_ROM_QSTR(MP_QSTR_flash), MP_ROM_PTR(&dualbank_flash_obj) },
+ { MP_ROM_QSTR(MP_QSTR_switch), MP_ROM_PTR(&dualbank_switch_obj) },
+};
+STATIC MP_DEFINE_CONST_DICT(dualbank_module_globals, dualbank_module_globals_table);
+
+const mp_obj_module_t dualbank_module = {
+ .base = { &mp_type_module },
+ .globals = (mp_obj_dict_t*)&dualbank_module_globals,
+};
diff --git a/shared-bindings/dualbank/__init__.h b/shared-bindings/dualbank/__init__.h
new file mode 100644
index 000000000..7edbc6d68
--- /dev/null
+++ b/shared-bindings/dualbank/__init__.h
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 microDev
+ *
+ * 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.
+ */
+
+#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DUALBANK___INIT___H
+#define MICROPY_INCLUDED_SHARED_BINDINGS_DUALBANK___INIT___H
+
+#include "py/runtime.h"
+
+extern void common_hal_dualbank_switch(void);
+extern void common_hal_dualbank_flash(const void *buf, const size_t len, const size_t offset);
+
+#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DUALBANK___INIT___H
diff --git a/shared-bindings/wifi/Network.c b/shared-bindings/wifi/Network.c
index bf970a9c0..009712ad1 100644
--- a/shared-bindings/wifi/Network.c
+++ b/shared-bindings/wifi/Network.c
@@ -108,12 +108,29 @@ const mp_obj_property_t wifi_network_channel_obj = {
(mp_obj_t)&mp_const_none_obj },
};
+//| country: str
+//| """String id of the country code"""
+//|
+STATIC mp_obj_t wifi_network_get_country(mp_obj_t self) {
+ return common_hal_wifi_network_get_country(self);
+
+}
+MP_DEFINE_CONST_FUN_OBJ_1(wifi_network_get_country_obj, wifi_network_get_country);
+
+const mp_obj_property_t wifi_network_country_obj = {
+ .base.type = &mp_type_property,
+ .proxy = { (mp_obj_t)&wifi_network_get_country_obj,
+ (mp_obj_t)&mp_const_none_obj,
+ (mp_obj_t)&mp_const_none_obj },
+};
+
STATIC const mp_rom_map_elem_t wifi_network_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_ssid), MP_ROM_PTR(&wifi_network_ssid_obj) },
{ MP_ROM_QSTR(MP_QSTR_bssid), MP_ROM_PTR(&wifi_network_bssid_obj) },
{ MP_ROM_QSTR(MP_QSTR_rssi), MP_ROM_PTR(&wifi_network_rssi_obj) },
{ MP_ROM_QSTR(MP_QSTR_channel), MP_ROM_PTR(&wifi_network_channel_obj) },
+ { MP_ROM_QSTR(MP_QSTR_country), MP_ROM_PTR(&wifi_network_country_obj) },
};
STATIC MP_DEFINE_CONST_DICT(wifi_network_locals_dict, wifi_network_locals_dict_table);
diff --git a/shared-bindings/wifi/Network.h b/shared-bindings/wifi/Network.h
index c9bbc685e..e672e3108 100644
--- a/shared-bindings/wifi/Network.h
+++ b/shared-bindings/wifi/Network.h
@@ -39,5 +39,6 @@ extern mp_obj_t common_hal_wifi_network_get_ssid(wifi_network_obj_t *self);
extern mp_obj_t common_hal_wifi_network_get_bssid(wifi_network_obj_t *self);
extern mp_obj_t common_hal_wifi_network_get_rssi(wifi_network_obj_t *self);
extern mp_obj_t common_hal_wifi_network_get_channel(wifi_network_obj_t *self);
+extern mp_obj_t common_hal_wifi_network_get_country(wifi_network_obj_t *self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_NETWORK_H
diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c
index edbd9fd2f..723572a32 100644
--- a/shared-bindings/wifi/Radio.c
+++ b/shared-bindings/wifi/Radio.c
@@ -295,7 +295,7 @@ const mp_obj_property_t wifi_radio_ipv4_dns_obj = {
};
//| ap_info: Optional[Network]
-//| """Network object containing BSSID, SSID, channel, and RSSI when connected to an access point. None otherwise."""
+//| """Network object containing BSSID, SSID, channel, country and RSSI when connected to an access point. None otherwise."""
//|
STATIC mp_obj_t wifi_radio_get_ap_info(mp_obj_t self) {
return common_hal_wifi_radio_get_ap_info(self);