Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
b637d39
Initial commit
gamblor21 Oct 25, 2020
12d770b
Added __probe_for_device
gamblor21 Oct 25, 2020
8a37983
Added doc and translations
gamblor21 Oct 26, 2020
9ec2245
Clean up
gamblor21 Oct 27, 2020
2374b0d
Fixed whitespace issues
gamblor21 Oct 27, 2020
90b9ec6
Initial Sleep Support
microdev1 Sep 18, 2020
3a30887
Update soft reboot message
microdev1 Sep 18, 2020
e310b87
Get io wake working
microdev1 Sep 19, 2020
05a3f20
Add function to get time elapsed during sleep
microdev1 Sep 22, 2020
21ba61a
Add function to disable alarm
microdev1 Sep 22, 2020
e5ff55b
Renamed alarm modules
microdev1 Sep 23, 2020
4d8ffdc
restructure alarm modules
microdev1 Sep 24, 2020
da44972
Fix build error
microdev1 Sep 24, 2020
59df1a1
Add alarm_touch module
microdev1 Sep 24, 2020
e359389
Add description of alarm modules
microdev1 Sep 24, 2020
930cf14
Add check for invalid io, function to disable all alarms
microdev1 Sep 26, 2020
0e444f0
Implement sleep on code.py exit
microdev1 Sep 30, 2020
354536c
Update translation
microdev1 Oct 7, 2020
1196d4b
move to new module
tannewt Oct 14, 2020
85dadf3
More API changes
tannewt Oct 15, 2020
9a4efed
Start tweaking the workflow to sleep
tannewt Oct 28, 2020
e7da852
Fixing review comments
gamblor21 Oct 29, 2020
78477a3
Initial SPI commit
gamblor21 Oct 31, 2020
5ea09fe
Fixed stubs
gamblor21 Oct 31, 2020
76c1153
Fixed stubs
gamblor21 Nov 1, 2020
7dd5380
Fixed stubs again
gamblor21 Nov 1, 2020
8bbbb28
Fixes from testing SPI
gamblor21 Nov 2, 2020
197539b
Moved I2CDevice and SPI to match python library
gamblor21 Nov 3, 2020
4c93db3
Renamed to adafruit_bus_device
gamblor21 Nov 4, 2020
03b110b
Add abort check in I2C lock
gamblor21 Nov 11, 2020
f61c4e6
Removing from smaller builds
gamblor21 Nov 11, 2020
23ed3ef
Removing frozen libs
gamblor21 Nov 11, 2020
bb77f1d
wip: initial code changes, starting from @tannewt's sleepio branch
dhalbert Nov 16, 2020
ffff02c
Merge remote-tracking branch 'adafruit/main' into sleep
dhalbert Nov 16, 2020
682054a
WIP: redo API; not compiled yet
dhalbert Nov 19, 2020
5bb3c32
merge from main
dhalbert Nov 19, 2020
649c930
wip
dhalbert Nov 19, 2020
cd436ba
Merge remote-tracking branch 'adafruit/main' into sleep
dhalbert Nov 19, 2020
39e1f52
wip; not compiling yet
dhalbert Nov 19, 2020
e4c6699
compiles
dhalbert Nov 21, 2020
75559f3
wip: ResetReason to microcontroller.cpu
dhalbert Nov 22, 2020
a0f1ec3
wip
dhalbert Nov 23, 2020
25591a3
Merge branch 'esp32s2-common-hal-mcu-delay-us' into sleep
dhalbert Nov 23, 2020
3abee9b
compiles; maybe ready to test, or almost
dhalbert Nov 23, 2020
7a45afc
working, but need to avoid deep sleeping too fast before USB ready
dhalbert Nov 24, 2020
f868cc5
some API renaming and bug fixes; fix docs
dhalbert Nov 25, 2020
9dbea36
changed alarm.time API
dhalbert Nov 25, 2020
ef0830b
merge from upstream + wip
dhalbert Nov 25, 2020
104a089
deep sleep working; deep sleep delay when connected
dhalbert Nov 27, 2020
e308a9e
working! PinAlarm not implemented yet.
dhalbert Nov 27, 2020
596e0e4
merge from upstream
dhalbert Nov 27, 2020
f96475c
update Requests; rolled back by accident
dhalbert Nov 27, 2020
65e2fe4
fix stub problems; touch up doc
dhalbert Nov 28, 2020
2830cc9
make translate
dhalbert Nov 28, 2020
28d9e91
Disable complex arithmetic on SAMD21 builds to make space
dhalbert Nov 28, 2020
4ac4faa
Use nina-fw root certs
tannewt Dec 1, 2020
9276244
Two minor socket changes
tannewt Dec 1, 2020
9a9e972
Ignore certificates readme in doc build
tannewt Dec 1, 2020
a95285a
Translated using Weblate (Polish)
szajakubiak Dec 1, 2020
f6cba4c
Translated using Weblate (Polish)
tawez Dec 1, 2020
44e0d98
Translated using Weblate (Polish)
szajakubiak Dec 1, 2020
2b9ca4d
Translated using Weblate (Polish)
tawez Dec 1, 2020
2373857
Merge branch 'main' into bus_device
gamblor21 Dec 1, 2020
d3bbb99
Fixing stubs
gamblor21 Dec 1, 2020
8b7c23c
address review comments
dhalbert Dec 2, 2020
fe1c2fa
Removed bus device from simmel build
gamblor21 Dec 2, 2020
72fa7d8
fix doc errors
dhalbert Dec 2, 2020
73e22f9
Block all tasks (not interrupts) during flash erase
tannewt Dec 2, 2020
cb863e4
Added to partial builds where frozen removed
gamblor21 Dec 2, 2020
1c00deb
Translated using Weblate (Polish)
tawez Dec 1, 2020
9e6b2b1
Translated using Weblate (Czech)
vkuthan Dec 1, 2020
d7ba641
Merge pull request #3767 from dhalbert/sleep
tannewt Dec 2, 2020
8f6baa2
Merge branch 'origin/main' into Weblate.
weblate Dec 2, 2020
7655102
Update translation files
weblate Dec 2, 2020
31acfed
Merge pull request #3780 from tannewt/block_while_erasing
dhalbert Dec 2, 2020
51fd678
Merge branch 'origin/main' into Weblate.
weblate Dec 2, 2020
9b3186b
Merge pull request #3776 from tannewt/backup_socket_timeout
dhalbert Dec 2, 2020
c7749a5
Merge branch 'origin/main' into Weblate.
weblate Dec 2, 2020
348392f
Merge pull request #3775 from tannewt/nina_certs
dhalbert Dec 2, 2020
a483cd1
Merge branch 'origin/main' into Weblate.
weblate Dec 2, 2020
1130b80
Merge pull request #3612 from gamblor21/bus_device
tannewt Dec 2, 2020
079bf7a
Merge branch 'origin/main' into Weblate.
weblate Dec 2, 2020
03d0ec8
Update translation files
weblate Dec 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
compiles
  • Loading branch information
dhalbert committed Nov 21, 2020
commit e4c66990e27779f43f4901d431b6c61f8da85f51
38 changes: 22 additions & 16 deletions ports/esp32s2/common-hal/alarm/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,50 +26,56 @@
*/

#include "shared-bindings/alarm/__init__.h"
#include "shared-bindings/alarm_io/__init__.h"
#include "shared-bindings/alarm_time/__init__.h"
#include "shared-bindings/alarm/pin/PinAlarm.h"
#include "shared-bindings/alarm/time/DurationAlarm.h"

#include "esp_sleep.h"

void common_hal_alarm_disable_all(void) {
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
}

mp_obj_t common_hal_alarm_get_reset_reason(void) {
alarm_reset_reason_t common_hal_alarm_get_reset_reason(void) {
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_TIMER:
return RESET_REASON_DEEP_SLEEP_ALARM;

case ESP_SLEEP_WAKEUP_EXT0:
return RESET_REASON_DEEP_SLEEP_ALARM;

case ESP_SLEEP_WAKEUP_TOUCHPAD:
//TODO: implement TouchIO
case ESP_SLEEP_WAKEUP_UNDEFINED:
default:
return mp_const_none;
break;
return RESET_REASON_INVALID;
}
}


mp_obj_t common_hal_alarm_get_wake_alarm(void) {
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_TIMER: ;
//Wake up from timer.
alarm_time_obj_t *timer = m_new_obj(alarm_time_obj_t);
timer->base.type = &alarm_time_type;
case ESP_SLEEP_WAKEUP_TIMER: {
// Wake up from timer.
alarm_time_duration_alarm_obj_t *timer = m_new_obj(alarm_time_duration_alarm_obj_t);
timer->base.type = &alarm_time_duration_alarm_type;
return timer;
case ESP_SLEEP_WAKEUP_EXT0: ;
//Wake up from GPIO
alarm_io_obj_t *ext0 = m_new_obj(alarm_io_obj_t);
ext0->base.type = &alarm_io_type;
}

case ESP_SLEEP_WAKEUP_EXT0: {
// Wake up from GPIO
alarm_pin_pin_alarm_obj_t *ext0 = m_new_obj(alarm_pin_pin_alarm_obj_t);
ext0->base.type = &alarm_pin_pin_alarm_type;
return ext0;
}

case ESP_SLEEP_WAKEUP_TOUCHPAD:
//TODO: implement TouchIO
//Wake up from touch on pad, esp_sleep_get_touchpad_wakeup_status()
// TODO: implement TouchIO
// Wake up from touch on pad, esp_sleep_get_touchpad_wakeup_status()
break;

case ESP_SLEEP_WAKEUP_UNDEFINED:
default:
//Not a deep sleep reset
// Not a deep sleep reset.
break;
}
return mp_const_none;
Expand Down
8 changes: 5 additions & 3 deletions ports/esp32s2/common-hal/alarm/pin/PinAlarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@

#include "esp_sleep.h"

#include "shared-bindings/alarm/time/DurationAlarm.h"
#include "shared-bindings/alarm/pin/PinAlarm.h"
#include "shared-bindings/microcontroller/Pin.h"

void common_hal_alarm_pin_pin_pin_alarm_construct(alarm_pin_pin_alarm_obj_t *self, mcu_pin_obj_t *pin, bool level, bool edge, bool pull) {
void common_hal_alarm_pin_pin_alarm_construct(alarm_pin_pin_alarm_obj_t *self, const mcu_pin_obj_t *pin, bool level, bool edge, bool pull) {
self->pin = pin;
self->level = level;
self->edge = edge;
self->pull = pull;
}

mcu_pin_obj_t *common_hal_alarm_pin_pin_alarm_get_pin(alarm_pin_pin_alarm_obj_t *self) {
const mcu_pin_obj_t *common_hal_alarm_pin_pin_alarm_get_pin(alarm_pin_pin_alarm_obj_t *self) {
return self->pin;
}

Expand Down
2 changes: 1 addition & 1 deletion ports/esp32s2/common-hal/alarm/pin/PinAlarm.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

typedef struct {
mp_obj_base_t base;
mcu_pin_obj_t *pin;
const mcu_pin_obj_t *pin;
bool level;
bool edge;
bool pull;
Expand Down
5 changes: 4 additions & 1 deletion ports/esp32s2/common-hal/alarm/time/DurationAlarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#include "esp_sleep.h"

#include "py/runtime.h"

#include "shared-bindings/alarm/time/DurationAlarm.h"

void common_hal_alarm_time_duration_alarm_construct(alarm_time_duration_alarm_obj_t *self, mp_float_t duration) {
Expand All @@ -36,7 +38,8 @@ void common_hal_alarm_time_duration_alarm_construct(alarm_time_duration_alarm_ob
mp_float_t common_hal_alarm_time_duration_alarm_get_duration(alarm_time_duration_alarm_obj_t *self) {
return self->duration;
}
void common_hal_alarm_time_duration_alarm_enable(alarm_time_duration_alarm_obj_t *self)

void common_hal_alarm_time_duration_alarm_enable(alarm_time_duration_alarm_obj_t *self) {
if (esp_sleep_enable_timer_wakeup((uint64_t) (self->duration * 1000000)) == ESP_ERR_INVALID_ARG) {
mp_raise_ValueError(translate("duration out of range"));
}
Expand Down
11 changes: 5 additions & 6 deletions py/circuitpy_defns.mk
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,6 @@ SRC_COMMON_HAL_ALL = \
rtc/__init__.c \
sdioio/SDCard.c \
sdioio/__init__.c \
sleepio/__init__.c \
sleepio/ResetReason.c \
socketpool/__init__.c \
socketpool/SocketPool.c \
socketpool/Socket.c \
Expand Down Expand Up @@ -395,9 +393,10 @@ $(filter $(SRC_PATTERNS), \
_bleio/Address.c \
_bleio/Attribute.c \
_bleio/ScanEntry.c \
canio/Match.c \
_eve/__init__.c \
alarm/ResetReason.c \
camera/ImageFormat.c \
canio/Match.c \
digitalio/Direction.c \
digitalio/DriveMode.c \
digitalio/Pull.c \
Expand All @@ -414,9 +413,6 @@ SRC_SHARED_MODULE_ALL = \
_bleio/Attribute.c \
_bleio/ScanEntry.c \
_bleio/ScanResults.c \
canio/Match.c \
canio/Message.c \
canio/RemoteTransmissionRequest.c \
_eve/__init__.c \
_pixelbuf/PixelBuf.c \
_pixelbuf/__init__.c \
Expand All @@ -441,6 +437,9 @@ SRC_SHARED_MODULE_ALL = \
bitbangio/__init__.c \
board/__init__.c \
busio/OneWire.c \
canio/Match.c \
canio/Message.c \
canio/RemoteTransmissionRequest.c \
displayio/Bitmap.c \
displayio/ColorConverter.c \
displayio/Display.c \
Expand Down
4 changes: 2 additions & 2 deletions py/enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ typedef struct {
} cp_enum_obj_t;

#define MAKE_ENUM_VALUE(type, prefix, name, value) \
STATIC const cp_enum_obj_t prefix ## _ ## name ## _obj = { \
const cp_enum_obj_t prefix ## _ ## name ## _obj = { \
{ &type }, value, MP_QSTR_ ## name, \
}

#define MAKE_ENUM_MAP(name) \
STATIC const mp_rom_map_elem_t name ## _locals_table[] =
const mp_rom_map_elem_t name ## _locals_table[] =

#define MAKE_ENUM_MAP_ENTRY(prefix, name) \
{ MP_ROM_QSTR(MP_QSTR_ ## name), MP_ROM_PTR(&prefix ## _ ## name ## _obj) }
Expand Down
4 changes: 3 additions & 1 deletion py/genlast.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def preprocess(command, output_dir, fn):
print(e, file=sys.stderr)

def maybe_preprocess(command, output_dir, fn):
if subprocess.call(["grep", "-lqE", "(MP_QSTR|translate)", fn]) == 0:
# Preprocess the source file if it contains "MP_QSTR", "translate",
# or if it uses enum.h (which generates "MP_QSTR" strings.
if subprocess.call(["grep", "-lqE", r"(MP_QSTR|translate|enum\.h)", fn]) == 0:
preprocess(command, output_dir, fn)

if __name__ == '__main__':
Expand Down
12 changes: 10 additions & 2 deletions shared-bindings/alarm/ResetReason.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,25 @@
* THE SOFTWARE.
*/

#include "py/obj.h"
#include "py/enum.h"

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

MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, POWER_VALID, RESET_REASON_POWER_ON);
MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, INVALID, RESET_REASON_INVALID);
MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, POWER_ON, RESET_REASON_POWER_ON);
MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, BROWNOUT, RESET_REASON_BROWNOUT);
MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, SOFTWARE, RESET_REASON_SOFTWARE);
MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, DEEP_SLEEP_ALARM, RESET_REASON_DEEP_SLEEP_ALARM);
MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, EXTERNAL, RESET_REASON_EXTERNAL);
MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, RESET_PIN, RESET_REASON_RESET_PIN);
MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, WATCHDOG, RESET_REASON_WATCHDOG);

//| class ResetReason:
//| """The reason the chip was last reset"""
//|
//| INVALID: object
//| """Invalid reason: indicates an internal error."""
//|
//| POWER_ON: object
//| """The chip was started from power off."""
//|
Expand All @@ -55,6 +62,7 @@ MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, EXTERNAL, RESET_REASON_EX
//| """The chip was reset by its watchdog timer."""
//|
MAKE_ENUM_MAP(alarm_reset_reason) {
MAKE_ENUM_MAP_ENTRY(reset_reason, INVALID),
MAKE_ENUM_MAP_ENTRY(reset_reason, POWER_ON),
MAKE_ENUM_MAP_ENTRY(reset_reason, BROWNOUT),
MAKE_ENUM_MAP_ENTRY(reset_reason, SOFTWARE),
Expand Down
8 changes: 6 additions & 2 deletions shared-bindings/alarm/ResetReason.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM__RESET_REASON__H
#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM__RESET_REASON__H

#include "py/obj.h"
#include "py/enum.h"

typedef enum {
RESET_REASON_INVALID,
RESET_REASON_POWER_ON,
RESET_REASON_BROWNOUT,
RESET_REASON_SOFTWARE,
Expand All @@ -36,8 +40,8 @@ typedef enum {
RESET_REASON_WATCHDOG,
} alarm_reset_reason_t;

extern const mp_obj_type_t alarm_reset_reason_type;
extern const cp_enum_obj_t reset_reason_INVALID_obj;

extern alarm_reset_reason_t common_hal_alarm_get_reset_reason(void);
extern const mp_obj_type_t alarm_reset_reason_type;

#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM__RESET_REASON__H
45 changes: 20 additions & 25 deletions shared-bindings/alarm/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
#include "py/obj.h"
#include "py/runtime.h"

#include "shared-bindings/alarm/__init__.h"
#include "shared-bindings/alarm/ResetReason.h"
#include "shared-bindings/alarm/pin/PinAlarm.h"
#include "shared-bindings/alarm/time/DurationAlarm.h"

STATIC mp_obj_t alarm_sleep_until_alarm(size_t n_args, const mp_obj_t *args) {
// TODO
return mp_const_none;
Expand All @@ -56,47 +61,47 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(alarm_restart_on_alarm_obj, 1, MP_OBJ_FUN_AR
//| """The `alarm.pin` module contains alarm attributes and classes related to pins
//| """
//|
mp_map_elem_t alarm_pin_globals_table[] = {
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_ROM_PTR(&alarm_pin_pin_alarm_type) },
{ MP_ROM_QSTR(MP_QSTR_PinAlarm), MP_OBJ_FROM_PTR(&alarm_pin_pin_alarm_type) },
};

STATIC MP_DEFINE_CONST_DICT(alarm_pin_globals, alarm_pin_globals_table);

const mp_obj_module_t alarm_pin_module = {
STATIC const mp_obj_module_t alarm_pin_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&alarm_pinn_globals,
.globals = (mp_obj_dict_t*)&alarm_pin_globals,
};

//| """The `alarm.time` module contains alarm attributes and classes related to time-keeping.
//| """
//|
mp_map_elem_t alarm_time_globals_table[] = {
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_DurationAlarm), MP_ROM_PTR(&alarm_time_duration_alarm_type) },
{ MP_ROM_QSTR(MP_QSTR_DurationAlarm), MP_OBJ_FROM_PTR(&alarm_time_duration_alarm_type) },
};

STATIC MP_DEFINE_CONST_DICT(alarm_time_globals, alarm_time_globals_table);

const mp_obj_module_t alarm_time_module = {
STATIC const mp_obj_module_t alarm_time_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&alarm_time_globals,
};

mp_map_elem_t alarm_module_globals_table[] = {
STATIC mp_map_elem_t alarm_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_alarm) },

// wake_alarm and reset_reason are mutable attributes.
{ 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_reset_reason), MP_OBJ_FROM_PTR(&reset_reason_INVALID_obj) },

{ MP_ROM_QSTR(MP_QSTR_sleep_until_alarm), MP_ROM_PTR(&alarm_sleep_until_alarm_obj) },
{ MP_ROM_QSTR(MP_QSTR_restart_on_alarm), MP_ROM_PTR(&alarm_restart_on_alarm_obj) },
{ MP_ROM_QSTR(MP_QSTR_sleep_until_alarm), MP_OBJ_FROM_PTR(&alarm_sleep_until_alarm_obj) },
{ MP_ROM_QSTR(MP_QSTR_restart_on_alarm), MP_OBJ_FROM_PTR(&alarm_restart_on_alarm_obj) },

{ MP_ROM_QSTR(MP_QSTR_pin), MP_ROM_PTR(&alarm_pin_module) },
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&alarm_time_module) }
{ 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) }

};
STATIC MP_DEFINE_MUTABLE_DICT(alarm_module_globals, alarm_module_globals_table);
Expand All @@ -105,27 +110,17 @@ void common_hal_alarm_set_wake_alarm(mp_obj_t alarm) {
// Equivalent of:
// alarm.wake_alarm = alarm
mp_map_elem_t *elem =
mp_map_lookup(&alarm_module_globals_table, MP_ROM_QSTR(MP_QSTR_wake_alarm), MP_MAP_LOOKUP);
mp_map_lookup(&alarm_module_globals.map, MP_ROM_QSTR(MP_QSTR_wake_alarm), MP_MAP_LOOKUP);
if (elem) {
elem->value = 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
mp_map_elem_t *elem =
mp_map_lookup(&alarm_module_globals_table, MP_ROM_QSTR(MP_QSTR_reset_reason), MP_MAP_LOOKUP);
mp_map_lookup(&alarm_module_globals.map, MP_ROM_QSTR(MP_QSTR_reset_reason), MP_MAP_LOOKUP);
if (elem) {
elem->value = reset_reason;
}
Expand Down
11 changes: 6 additions & 5 deletions shared-bindings/alarm/pin/PinAlarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "shared-bindings/board/__init__.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/alarm/pin/PinAlarm.h"

#include "py/nlr.h"
#include "py/obj.h"
Expand Down Expand Up @@ -58,8 +59,7 @@
//| """
//| ...
//|
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 *args, mp_map_t *kw_args) {
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;
enum { ARG_pin, ARG_level, ARG_edge, ARG_pull };
Expand All @@ -74,7 +74,7 @@ STATIC mp_obj_t alarm_pin_pin_alarm_make_new(const mp_obj_type_t *type,

const mcu_pin_obj_t* pin = validate_obj_is_free_pin(args[ARG_pin].u_obj);

common_hal_alarm_pin_pin_pin_alarm_construct(
common_hal_alarm_pin_pin_alarm_construct(
self, pin, args[ARG_level].u_bool, args[ARG_edge].u_bool, args[ARG_pull].u_bool);

return MP_OBJ_FROM_PTR(self);
Expand Down Expand Up @@ -110,11 +110,12 @@ STATIC mp_obj_t alarm_pin_pin_alarm_binary_op(mp_binary_op_t op, mp_obj_t lhs_in
STATIC const mp_rom_map_elem_t alarm_pin_pin_alarm_locals_dict_table[] = {
};

STATIC MP_DEFINE_CONST_DICT(alarm_pin_pin_alarm_locals, alarm_pin_pin_alarm_locals_dict);
STATIC MP_DEFINE_CONST_DICT(alarm_pin_pin_alarm_locals_dict, alarm_pin_pin_alarm_locals_dict_table);

const mp_obj_type_t alarm_pin_pin_alarm_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,
.binary_op = alarm_pin_pin_alarm_binary_op,
.locals_dict = (mp_obj_t)&alarm_pin_pin_alarm_locals_dict,
};
Loading