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:
@@ -63,13 +63,7 @@
|
||||
|
||||
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
||||
{ MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&machine_info_obj) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_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_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, \
|
||||
\
|
||||
@@ -183,19 +177,16 @@ STATIC mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) {
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj, 0, 1, machine_info);
|
||||
|
||||
// Returns a string of 16 bytes (128 bits), which is the unique ID for the MCU.
|
||||
STATIC mp_obj_t machine_unique_id(void) {
|
||||
STATIC mp_obj_t mp_machine_unique_id(void) {
|
||||
uint8_t id[16];
|
||||
get_unique_id((uint8_t *)&id);
|
||||
return mp_obj_new_bytes(id, 16);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id);
|
||||
|
||||
// Resets the pyboard in a manner similar to pushing the external RESET button.
|
||||
STATIC mp_obj_t machine_reset(void) {
|
||||
NORETURN STATIC void mp_machine_reset(void) {
|
||||
powerctrl_mcu_reset();
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
|
||||
|
||||
// Activate the bootloader without BOOT* pins.
|
||||
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
|
||||
@@ -218,17 +209,13 @@ NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
|
||||
// get or set the MCU frequencies
|
||||
STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_args == 0) {
|
||||
// get
|
||||
return mp_obj_new_int(SystemCoreClock);
|
||||
} else {
|
||||
// set
|
||||
mp_raise_NotImplementedError(MP_ERROR_TEXT("machine.freq set not supported yet"));
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC mp_obj_t mp_machine_get_freq(void) {
|
||||
return mp_obj_new_int(SystemCoreClock);
|
||||
}
|
||||
|
||||
STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
|
||||
mp_raise_NotImplementedError(MP_ERROR_TEXT("machine.freq set not supported yet"));
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 4, machine_freq);
|
||||
|
||||
// idle()
|
||||
// This executies a wfi machine instruction which reduces power consumption
|
||||
@@ -237,27 +224,22 @@ STATIC void mp_machine_idle(void) {
|
||||
__WFI();
|
||||
}
|
||||
|
||||
STATIC mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||
STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_args != 0) {
|
||||
mp_obj_t args2[2] = {MP_OBJ_NULL, args[0]};
|
||||
machine_rtc_wakeup(2, args2);
|
||||
}
|
||||
powerctrl_enter_stop_mode();
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lightsleep_obj, 0, 1, machine_lightsleep);
|
||||
|
||||
STATIC mp_obj_t machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||
NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_args != 0) {
|
||||
mp_obj_t args2[2] = {MP_OBJ_NULL, args[0]};
|
||||
machine_rtc_wakeup(2, args2);
|
||||
}
|
||||
powerctrl_enter_standby_mode();
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_deepsleep_obj, 0, 1, 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_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause);
|
||||
|
||||
@@ -33,25 +33,13 @@ extern const mp_obj_type_t machine_touchpad_type;
|
||||
extern const mp_obj_type_t machine_dac_type;
|
||||
extern const mp_obj_type_t machine_sdcard_type;
|
||||
|
||||
|
||||
void machine_init(void);
|
||||
void machine_deinit(void);
|
||||
void machine_pin_init(void);
|
||||
void machine_pin_deinit(void);
|
||||
void machine_i2s_init0(void);
|
||||
|
||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_0(machine_unique_id_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_0(machine_reset_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj);
|
||||
|
||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lightsleep_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_deepsleep_obj);
|
||||
|
||||
MP_DECLARE_CONST_FUN_OBJ_0(machine_disable_irq_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_enable_irq_obj);
|
||||
|
||||
MP_DECLARE_CONST_FUN_OBJ_0(pyb_irq_stats_obj);
|
||||
|
||||
#endif // MICROPY_INCLUDED_RENESAS_RA_MODMACHINE_H
|
||||
|
||||
@@ -131,6 +131,7 @@
|
||||
#ifndef MICROPY_PY_MACHINE
|
||||
#define MICROPY_PY_MACHINE (1)
|
||||
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/renesas-ra/modmachine.c"
|
||||
#define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1)
|
||||
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
|
||||
#define MICROPY_PY_MACHINE_ADC (1)
|
||||
#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/renesas-ra/machine_adc.c"
|
||||
|
||||
@@ -245,7 +245,7 @@ void powerctrl_enter_stop_mode(void) {
|
||||
enable_irq(irq_state);
|
||||
}
|
||||
|
||||
void powerctrl_enter_standby_mode(void) {
|
||||
NORETURN void powerctrl_enter_standby_mode(void) {
|
||||
rtc_init_finalise();
|
||||
|
||||
#if defined(MICROPY_BOARD_ENTER_STANDBY)
|
||||
@@ -301,4 +301,6 @@ void powerctrl_enter_standby_mode(void) {
|
||||
// enter standby mode
|
||||
|
||||
// we never return; MCU is reset on exit from standby
|
||||
|
||||
powerctrl_mcu_reset();
|
||||
}
|
||||
|
||||
@@ -37,6 +37,6 @@ NORETURN void powerctrl_enter_bootloader(uint32_t r0, uint32_t bl_addr);
|
||||
void powerctrl_check_enter_bootloader(void);
|
||||
|
||||
void powerctrl_enter_stop_mode(void);
|
||||
void powerctrl_enter_standby_mode(void);
|
||||
NORETURN void powerctrl_enter_standby_mode(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_RA_POWERCTRL_H
|
||||
|
||||
Reference in New Issue
Block a user