extmod/modmachine: Provide common bindings for 6 bare-metal functions.
Minor changes for consistency are: - nrf gains: unique_id(), freq() [they do nothing] - samd: deepsleep() now resets after calling lightsleep() - esp32: lightsleep()/deepsleep() no longer take kw arg "sleep", instead it's positional to match others. also, passing 0 here will now do a 0ms sleep instead of acting like nothing was passed. reset_cause() no longer takes any args (before it would just ignore them) - mimxrt: freq() with an argument and lightsleep() both raise NotImplementedError Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -85,13 +85,9 @@
|
||||
|
||||
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
||||
{ MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&machine_info_obj) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&machine_lightsleep_obj) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_lightsleep), MP_ROM_PTR(&machine_lightsleep_obj) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&machine_deepsleep_obj) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&pin_type) }, \
|
||||
\
|
||||
MICROPY_PY_MACHINE_RTCOUNTER_ENTRY \
|
||||
@@ -178,14 +174,16 @@ STATIC mp_obj_t machine_info(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj, 0, 1, machine_info);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj, 0, 1, machine_info);
|
||||
|
||||
STATIC mp_obj_t mp_machine_unique_id(void) {
|
||||
return mp_const_empty_bytes;
|
||||
}
|
||||
|
||||
// Resets the board in a manner similar to pushing the external RESET button.
|
||||
STATIC mp_obj_t machine_reset(void) {
|
||||
NORETURN STATIC void mp_machine_reset(void) {
|
||||
NVIC_SystemReset();
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
|
||||
|
||||
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
|
||||
MICROPY_BOARD_ENTER_BOOTLOADER(n_args, args);
|
||||
@@ -197,22 +195,25 @@ STATIC void mp_machine_idle(void) {
|
||||
MICROPY_EVENT_POLL_HOOK;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t machine_lightsleep(void) {
|
||||
STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||
__WFE();
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_lightsleep_obj, machine_lightsleep);
|
||||
|
||||
STATIC mp_obj_t machine_deepsleep(void) {
|
||||
__WFI();
|
||||
return mp_const_none;
|
||||
NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||
mp_machine_reset();
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_deepsleep_obj, machine_deepsleep);
|
||||
|
||||
STATIC mp_obj_t machine_reset_cause(void) {
|
||||
return MP_OBJ_NEW_SMALL_INT(reset_cause);
|
||||
STATIC mp_int_t mp_machine_reset_cause(void) {
|
||||
return reset_cause;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_machine_get_freq(void) {
|
||||
mp_raise_NotImplementedError(NULL);
|
||||
}
|
||||
|
||||
STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
|
||||
mp_raise_NotImplementedError(NULL);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause);
|
||||
|
||||
STATIC mp_obj_t machine_enable_irq(void) {
|
||||
#ifndef BLUETOOTH_SD
|
||||
|
||||
@@ -32,9 +32,4 @@
|
||||
|
||||
void machine_init(void);
|
||||
|
||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_0(machine_reset_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_0(machine_lightsleep_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_0(machine_deepsleep_obj);
|
||||
|
||||
#endif // __MICROPY_INCLUDED_NRF5_MODMACHINE_H__
|
||||
|
||||
@@ -160,6 +160,7 @@
|
||||
#define MICROPY_PY_TIME (1)
|
||||
#define MICROPY_PY_MACHINE (1)
|
||||
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/nrf/modules/machine/modmachine.c"
|
||||
#define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1)
|
||||
#define MICROPY_PY_MACHINE_PULSE (0)
|
||||
#define MICROPY_PY_MACHINE_SOFTI2C (MICROPY_PY_MACHINE_I2C)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user