summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorDavePutz <dwputz@gmail.com>2021-01-04 15:47:06 -0600
committerGitHub <noreply@github.com>2021-01-04 15:47:06 -0600
commit76e9f495c744153f10f40992a04256bf8770184b (patch)
tree548142ea70d26eb69fd5d3560b2800f297f8098b /shared-bindings
parent9c14593d623181e7b1eb5f5358869977befc1d74 (diff)
parentf6f1ef7dc26f9e253f09d48a8ec822a2f5e805fb (diff)
Merge pull request #37 from adafruit/main
update from adafruit main
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/_pixelbuf/PixelBuf.c2
-rw-r--r--shared-bindings/alarm/__init__.c42
-rw-r--r--shared-bindings/alarm/__init__.h7
-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/wifi/Network.c17
-rw-r--r--shared-bindings/wifi/Network.h1
-rw-r--r--shared-bindings/wifi/Radio.c2
12 files changed, 247 insertions, 67 deletions
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/alarm/__init__.c b/shared-bindings/alarm/__init__.c
index 700fe020e..7023c70e5 100644
--- a/shared-bindings/alarm/__init__.c
+++ b/shared-bindings/alarm/__init__.c
@@ -32,6 +32,7 @@
#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"
@@ -71,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"));
@@ -159,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);
@@ -172,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);
@@ -182,6 +184,18 @@ 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) },
@@ -195,25 +209,33 @@ STATIC mp_map_elem_t alarm_module_globals_table[] = {
{ 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_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);
-STATIC void alarm_set_wake_alarm(mp_obj_t alarm) {
- // Equivalent of:
- // alarm.wake_alarm = 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) {
- elem->value = alarm;
+ return elem->value;
+ } else {
+ return NULL;
}
}
// Initialize .wake_alarm value.
-void alarm_save_wakeup_alarm(void) {
- alarm_set_wake_alarm(common_hal_alarm_get_wake_alarm());
+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 = common_hal_alarm_get_wake_alarm();
+ }
}
const mp_obj_module_t alarm_module = {
diff --git a/shared-bindings/alarm/__init__.h b/shared-bindings/alarm/__init__.h
index 8c4b6cad9..154f91e26 100644
--- a/shared-bindings/alarm/__init__.h
+++ b/shared-bindings/alarm/__init__.h
@@ -43,13 +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.
-void alarm_save_wakeup_alarm(void);
+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/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);