Skip to content

Commit 2ca649a

Browse files
committed
codal_app/microbithal: Add power management functions.
Signed-off-by: Damien George <[email protected]>
1 parent 3b56528 commit 2ca649a

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/codal_app/microbithal.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,26 @@ int microbit_hal_temperature(void) {
104104
return uBit.thermometer.getTemperature();
105105
}
106106

107+
void microbit_hal_power_wake_on_button(int button) {
108+
button_obj[button]->wakeOnActive(true);
109+
}
110+
111+
void microbit_hal_power_wake_on_pin(int pin) {
112+
pin_obj[pin]->wakeOnActive(true);
113+
}
114+
115+
void microbit_hal_power_off(void) {
116+
uBit.power.off();
117+
}
118+
119+
void microbit_hal_power_deep_sleep(bool wake_on_ms, uint32_t ms) {
120+
if (wake_on_ms) {
121+
uBit.power.deepSleep(ms);
122+
} else {
123+
uBit.power.deepSleep();
124+
}
125+
}
126+
107127
void microbit_hal_pin_set_pull(int pin, int pull) {
108128
pin_obj[pin]->setPull(pin_pull_mode_mapping[pull]);
109129
pin_pull_state[pin] = pull;

src/codal_app/microbithal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ void microbit_hal_reset(void);
103103
void microbit_hal_panic(int);
104104
int microbit_hal_temperature(void);
105105

106+
void microbit_hal_power_wake_on_button(int button);
107+
void microbit_hal_power_wake_on_pin(int pin);
108+
void microbit_hal_power_off(void);
109+
void microbit_hal_power_deep_sleep(bool wake_on_ms, uint32_t ms);
110+
106111
void microbit_hal_pin_set_pull(int pin, int pull);
107112
int microbit_hal_pin_get_pull(int pin);
108113
int microbit_hal_pin_set_analog_period_us(int pin, int period);

0 commit comments

Comments
 (0)