Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 16 additions & 4 deletions src/codal_app/microbithal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "MicroBitDevice.h"
#include "neopixel.h"

#define HAL_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

NRF52Pin *const pin_obj[] = {
&uBit.io.P0,
&uBit.io.P1,
Expand Down Expand Up @@ -104,12 +106,22 @@ int microbit_hal_temperature(void) {
return uBit.thermometer.getTemperature();
}

void microbit_hal_power_wake_on_button(int button) {
button_obj[button]->wakeOnActive(true);
void microbit_hal_power_clear_wake_sources(void) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added void to the argument list here.

for (size_t i = 0; i < HAL_ARRAY_SIZE(pin_obj); ++i) {
microbit_hal_power_wake_on_pin(i, false);
}
for (size_t i = 0; i < HAL_ARRAY_SIZE(button_obj); ++i) {
microbit_hal_power_wake_on_button(i, false);
}
// TODO: Clear the run_every wake up source when implemented
}

void microbit_hal_power_wake_on_button(int button, bool wake_on_active) {
button_obj[button]->wakeOnActive(wake_on_active);
}

void microbit_hal_power_wake_on_pin(int pin) {
pin_obj[pin]->wakeOnActive(true);
void microbit_hal_power_wake_on_pin(int pin, bool wake_on_active) {
pin_obj[pin]->wakeOnActive(wake_on_active);
}

void microbit_hal_power_off(void) {
Expand Down
5 changes: 3 additions & 2 deletions src/codal_app/microbithal.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ void microbit_hal_reset(void);
void microbit_hal_panic(int);
int microbit_hal_temperature(void);

void microbit_hal_power_wake_on_button(int button);
void microbit_hal_power_wake_on_pin(int pin);
void microbit_hal_power_clear_wake_sources(void);
void microbit_hal_power_wake_on_button(int button, bool wake_on_active);
void microbit_hal_power_wake_on_pin(int pin, bool wake_on_active);
void microbit_hal_power_off(void);
void microbit_hal_power_deep_sleep(bool wake_on_ms, uint32_t ms);

Expand Down
8 changes: 5 additions & 3 deletions src/codal_port/modpower.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ STATIC mp_obj_t power_deep_sleep(size_t n_args, const mp_obj_t *pos_args, mp_map
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);

microbit_hal_power_clear_wake_sources();

if (args[ARG_pins].u_obj != mp_const_none) {
mp_obj_t *items;
size_t len = get_array(&args[ARG_pins].u_obj, &items);
for (size_t i = 0; i < len; ++i) {
microbit_hal_power_wake_on_pin(microbit_obj_get_pin_name(items[i]));
microbit_hal_power_wake_on_pin(microbit_obj_get_pin_name(items[i]), true);
}
}

Expand All @@ -75,9 +77,9 @@ STATIC mp_obj_t power_deep_sleep(size_t n_args, const mp_obj_t *pos_args, mp_map
size_t len = get_array(&args[ARG_buttons].u_obj, &items);
for (size_t i = 0; i < len; ++i) {
if (items[i] == MP_OBJ_FROM_PTR(&microbit_button_a_obj)) {
microbit_hal_power_wake_on_button(0);
microbit_hal_power_wake_on_button(0, true);
} else if (items[i] == MP_OBJ_FROM_PTR(&microbit_button_b_obj)) {
microbit_hal_power_wake_on_button(1);
microbit_hal_power_wake_on_button(1, true);
} else {
mp_raise_ValueError(MP_ERROR_TEXT("expecting a button"));
}
Expand Down