Skip to content

Commit a4438da

Browse files
committed
ports/zephyr: Add machine lightsleep
1 parent b4cf82b commit a4438da

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

ports/zephyr/modmachine.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
#include <stdio.h>
3333
#include <zephyr/sys/reboot.h>
34+
#include <zephyr/pm/pm.h>
35+
#include <zephyr/pm/device.h>
3436

3537
#include "modmachine.h"
3638

@@ -61,3 +63,30 @@ MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause);
6163
static void mp_machine_idle(void) {
6264
k_yield();
6365
}
66+
67+
static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
68+
mp_int_t milliseconds = mp_obj_get_int(args[0]);
69+
// Get the UART device
70+
const struct device *uart0 = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
71+
// Set UART device to low power state
72+
pm_device_action_run(uart0, PM_DEVICE_ACTION_SUSPEND);
73+
k_sleep(K_MSEC(milliseconds));
74+
// Set UART device back to active state
75+
pm_device_action_run(uart0, PM_DEVICE_ACTION_RESUME);
76+
}
77+
78+
static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
79+
mp_raise_ValueError(MP_ERROR_TEXT("not implemented"));
80+
}
81+
82+
static mp_obj_t mp_machine_get_freq(void) {
83+
mp_raise_ValueError(MP_ERROR_TEXT("not implemented"));
84+
}
85+
86+
static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
87+
mp_raise_ValueError(MP_ERROR_TEXT("not implemented"));
88+
}
89+
90+
static mp_obj_t mp_machine_unique_id(void) {
91+
mp_raise_ValueError(MP_ERROR_TEXT("not implemented"));
92+
}

ports/zephyr/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
6262
#define MICROPY_PY_MACHINE (1)
6363
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/zephyr/modmachine.c"
64+
#define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1)
6465
#define MICROPY_PY_MACHINE_I2C (1)
6566
#define MICROPY_PY_MACHINE_SPI (1)
6667
#define MICROPY_PY_MACHINE_SPI_MSB (SPI_TRANSFER_MSB)

ports/zephyr/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ CONFIG_FPU=y
1616
CONFIG_MAIN_STACK_SIZE=4736
1717
CONFIG_POLL=y
1818

19+
CONFIG_PM=y
20+
CONFIG_PM_DEVICE=y
1921
CONFIG_DEVICE_DT_METADATA=y
2022

2123
# Enable sensor subsystem (doesn't add code if not used).

0 commit comments

Comments
 (0)