diff options
| author | Damien George <damien@micropython.org> | 2023-11-23 16:36:52 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2023-11-30 16:11:11 +1100 |
| commit | 30a63a204dc6ad02c996d5c40c34b67c85c650e4 (patch) | |
| tree | 464f08a0b2cd65e773daaf93101fdeeee25cfb81 /extmod/modmachine.c | |
| parent | 7d39db2503cab67f03216161b0e829939f80fff7 (diff) | |
extmod/modmachine: Provide common Python bindings for machine.idle().
And use it in all ports. The ports are unchanged, except esp8266 which now
just returns None from this function instead of the time elapsed (to match
other ports), and qemu-arm which gains this function.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'extmod/modmachine.c')
| -rw-r--r-- | extmod/modmachine.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/extmod/modmachine.c b/extmod/modmachine.c index e0bef3a73..311d5dc03 100644 --- a/extmod/modmachine.c +++ b/extmod/modmachine.c @@ -35,6 +35,10 @@ #include "drivers/dht/dht.h" #endif +// The port must provide implementations of these low-level machine functions. + +STATIC void mp_machine_idle(void); + // The port can provide additional machine-module implementation in this file. #ifdef MICROPY_PY_MACHINE_INCLUDEFILE #include MICROPY_PY_MACHINE_INCLUDEFILE @@ -46,6 +50,12 @@ STATIC mp_obj_t machine_soft_reset(void) { } STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_soft_reset_obj, machine_soft_reset); +STATIC mp_obj_t machine_idle(void) { + mp_machine_idle(); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle); + STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) }, @@ -57,6 +67,9 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { // Reset related functions. { MP_ROM_QSTR(MP_QSTR_soft_reset), MP_ROM_PTR(&machine_soft_reset_obj) }, + // Power related functions. + { MP_ROM_QSTR(MP_QSTR_idle), MP_ROM_PTR(&machine_idle_obj) }, + // Functions for bit protocols. #if MICROPY_PY_MACHINE_BITSTREAM { MP_ROM_QSTR(MP_QSTR_bitstream), MP_ROM_PTR(&machine_bitstream_obj) }, |
