Skip to content

Commit 2b5561f

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

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

ports/zephyr/modmachine.c

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

3232
#include <stdio.h>
3333
#include <zephyr/sys/reboot.h>
34+
#include <zephyr/pm/pm.h>
35+
#include <zephyr/pm/device.h>
36+
#include <zephyr/sys_clock.h>
37+
#include <zephyr/drivers/hwinfo.h>
3438

3539
#include "modmachine.h"
3640

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

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)