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:
parent
48b5a7b060
commit
e1ec6af654
|
@ -43,6 +43,16 @@ STATIC void mp_machine_idle(void);
|
||||||
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args);
|
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MICROPY_PY_MACHINE_BARE_METAL_FUNCS
|
||||||
|
STATIC mp_obj_t mp_machine_unique_id(void);
|
||||||
|
NORETURN STATIC void mp_machine_reset(void);
|
||||||
|
STATIC mp_int_t mp_machine_reset_cause(void);
|
||||||
|
STATIC mp_obj_t mp_machine_get_freq(void);
|
||||||
|
STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args);
|
||||||
|
STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args);
|
||||||
|
NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args);
|
||||||
|
#endif
|
||||||
|
|
||||||
// The port can provide additional machine-module implementation in this file.
|
// The port can provide additional machine-module implementation in this file.
|
||||||
#ifdef MICROPY_PY_MACHINE_INCLUDEFILE
|
#ifdef MICROPY_PY_MACHINE_INCLUDEFILE
|
||||||
#include MICROPY_PY_MACHINE_INCLUDEFILE
|
#include MICROPY_PY_MACHINE_INCLUDEFILE
|
||||||
|
@ -67,6 +77,46 @@ STATIC mp_obj_t machine_idle(void) {
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle);
|
||||||
|
|
||||||
|
#if MICROPY_PY_MACHINE_BARE_METAL_FUNCS
|
||||||
|
|
||||||
|
STATIC mp_obj_t machine_unique_id(void) {
|
||||||
|
return mp_machine_unique_id();
|
||||||
|
}
|
||||||
|
MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id);
|
||||||
|
|
||||||
|
NORETURN STATIC mp_obj_t machine_reset(void) {
|
||||||
|
mp_machine_reset();
|
||||||
|
}
|
||||||
|
MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
|
||||||
|
|
||||||
|
STATIC mp_obj_t machine_reset_cause(void) {
|
||||||
|
return MP_OBJ_NEW_SMALL_INT(mp_machine_reset_cause());
|
||||||
|
}
|
||||||
|
MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause);
|
||||||
|
|
||||||
|
STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
|
||||||
|
if (n_args == 0) {
|
||||||
|
return mp_machine_get_freq();
|
||||||
|
} else {
|
||||||
|
mp_machine_set_freq(n_args, args);
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 1, machine_freq);
|
||||||
|
|
||||||
|
STATIC mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||||
|
mp_machine_lightsleep(n_args, args);
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lightsleep_obj, 0, 1, machine_lightsleep);
|
||||||
|
|
||||||
|
NORETURN STATIC mp_obj_t machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||||
|
mp_machine_deepsleep(n_args, args);
|
||||||
|
}
|
||||||
|
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_deepsleep_obj, 0, 1, machine_deepsleep);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
|
STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
|
||||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) },
|
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) },
|
||||||
|
|
||||||
|
@ -75,14 +125,28 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
|
||||||
{ MP_ROM_QSTR(MP_QSTR_mem16), MP_ROM_PTR(&machine_mem16_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_mem16), MP_ROM_PTR(&machine_mem16_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_mem32), MP_ROM_PTR(&machine_mem32_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_mem32), MP_ROM_PTR(&machine_mem32_obj) },
|
||||||
|
|
||||||
|
// Miscellaneous functions.
|
||||||
|
#if MICROPY_PY_MACHINE_BARE_METAL_FUNCS
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) },
|
||||||
|
#endif
|
||||||
|
|
||||||
// Reset related functions.
|
// Reset related functions.
|
||||||
{ MP_ROM_QSTR(MP_QSTR_soft_reset), MP_ROM_PTR(&machine_soft_reset_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_soft_reset), MP_ROM_PTR(&machine_soft_reset_obj) },
|
||||||
#if MICROPY_PY_MACHINE_BOOTLOADER
|
#if MICROPY_PY_MACHINE_BOOTLOADER
|
||||||
{ MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&machine_bootloader_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&machine_bootloader_obj) },
|
||||||
#endif
|
#endif
|
||||||
|
#if MICROPY_PY_MACHINE_BARE_METAL_FUNCS
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) },
|
||||||
|
#endif
|
||||||
|
|
||||||
// Power related functions.
|
// Power related functions.
|
||||||
{ MP_ROM_QSTR(MP_QSTR_idle), MP_ROM_PTR(&machine_idle_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_idle), MP_ROM_PTR(&machine_idle_obj) },
|
||||||
|
#if MICROPY_PY_MACHINE_BARE_METAL_FUNCS
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_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) },
|
||||||
|
#endif
|
||||||
|
|
||||||
// Functions for bit protocols.
|
// Functions for bit protocols.
|
||||||
#if MICROPY_PY_MACHINE_BITSTREAM
|
#if MICROPY_PY_MACHINE_BITSTREAM
|
||||||
|
|
|
@ -241,6 +241,12 @@ NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args);
|
||||||
void machine_bitstream_high_low(mp_hal_pin_obj_t pin, uint32_t *timing_ns, const uint8_t *buf, size_t len);
|
void machine_bitstream_high_low(mp_hal_pin_obj_t pin, uint32_t *timing_ns, const uint8_t *buf, size_t len);
|
||||||
mp_uint_t machine_time_pulse_us(mp_hal_pin_obj_t pin, int pulse_level, mp_uint_t timeout_us);
|
mp_uint_t machine_time_pulse_us(mp_hal_pin_obj_t pin, int pulse_level, mp_uint_t timeout_us);
|
||||||
|
|
||||||
|
MP_DECLARE_CONST_FUN_OBJ_0(machine_unique_id_obj);
|
||||||
|
MP_DECLARE_CONST_FUN_OBJ_0(machine_reset_obj);
|
||||||
|
MP_DECLARE_CONST_FUN_OBJ_0(machine_reset_cause_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_VAR_BETWEEN(machine_bootloader_obj);
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj);
|
||||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bitstream_obj);
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bitstream_obj);
|
||||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_time_pulse_us_obj);
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_time_pulse_us_obj);
|
||||||
|
|
|
@ -56,16 +56,10 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, \
|
|
||||||
MICROPY_PY_MACHINE_INFO_ENTRY \
|
MICROPY_PY_MACHINE_INFO_ENTRY \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_obj) }, \
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) }, \
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_main), MP_ROM_PTR(&machine_main_obj) }, \
|
{ MP_ROM_QSTR(MP_QSTR_main), MP_ROM_PTR(&machine_main_obj) }, \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_rng), MP_ROM_PTR(&machine_rng_get_obj) }, \
|
{ MP_ROM_QSTR(MP_QSTR_rng), MP_ROM_PTR(&machine_rng_get_obj) }, \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&machine_lightsleep_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_wake_reason), MP_ROM_PTR(&machine_wake_reason_obj) }, \
|
{ MP_ROM_QSTR(MP_QSTR_wake_reason), MP_ROM_PTR(&machine_wake_reason_obj) }, \
|
||||||
\
|
\
|
||||||
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) }, \
|
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) }, \
|
||||||
|
@ -99,24 +93,20 @@ extern OsiTaskHandle svTaskHandle;
|
||||||
extern OsiTaskHandle xSimpleLinkSpawnTaskHndl;
|
extern OsiTaskHandle xSimpleLinkSpawnTaskHndl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/// \module machine - functions related to the SoC
|
|
||||||
///
|
|
||||||
|
|
||||||
MP_DECLARE_CONST_FUN_OBJ_0(machine_disable_irq_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_VAR_BETWEEN(machine_enable_irq_obj);
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
// MicroPython bindings;
|
// MicroPython bindings;
|
||||||
|
|
||||||
STATIC mp_obj_t machine_reset(void) {
|
NORETURN STATIC void mp_machine_reset(void) {
|
||||||
// disable wlan
|
// disable wlan
|
||||||
wlan_stop(SL_STOP_TIMEOUT_LONG);
|
wlan_stop(SL_STOP_TIMEOUT_LONG);
|
||||||
// reset the cpu and it's peripherals
|
// reset the cpu and it's peripherals
|
||||||
MAP_PRCMMCUReset(true);
|
MAP_PRCMMCUReset(true);
|
||||||
return mp_const_none;
|
for (;;) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
STATIC mp_obj_t machine_info(uint n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t machine_info(uint n_args, const mp_obj_t *args) {
|
||||||
|
@ -145,17 +135,19 @@ STATIC mp_obj_t machine_info(uint n_args, const mp_obj_t *args) {
|
||||||
STATIC 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);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
STATIC mp_obj_t machine_freq(void) {
|
STATIC mp_obj_t mp_machine_get_freq(void) {
|
||||||
return mp_obj_new_int(HAL_FCPU_HZ);
|
return mp_obj_new_int(HAL_FCPU_HZ);
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_freq_obj, machine_freq);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_unique_id(void) {
|
STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
|
||||||
|
mp_raise_NotImplementedError(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC mp_obj_t mp_machine_unique_id(void) {
|
||||||
uint8_t mac[SL_BSSID_LENGTH];
|
uint8_t mac[SL_BSSID_LENGTH];
|
||||||
wlan_get_mac (mac);
|
wlan_get_mac (mac);
|
||||||
return mp_obj_new_bytes(mac, SL_BSSID_LENGTH);
|
return mp_obj_new_bytes(mac, SL_BSSID_LENGTH);
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_main(mp_obj_t main) {
|
STATIC mp_obj_t machine_main(mp_obj_t main) {
|
||||||
if (mp_obj_is_str(main)) {
|
if (mp_obj_is_str(main)) {
|
||||||
|
@ -171,22 +163,19 @@ STATIC void mp_machine_idle(void) {
|
||||||
__WFI();
|
__WFI();
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC mp_obj_t machine_lightsleep(void) {
|
STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||||
pyb_sleep_sleep();
|
pyb_sleep_sleep();
|
||||||
return mp_const_none;
|
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_lightsleep_obj, machine_lightsleep);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_deepsleep (void) {
|
NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||||
pyb_sleep_deepsleep();
|
pyb_sleep_deepsleep();
|
||||||
return mp_const_none;
|
for (;;) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_deepsleep_obj, machine_deepsleep);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_reset_cause (void) {
|
STATIC mp_int_t mp_machine_reset_cause(void) {
|
||||||
return mp_obj_new_int(pyb_sleep_get_reset_cause());
|
return pyb_sleep_get_reset_cause();
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_wake_reason (void) {
|
STATIC mp_obj_t machine_wake_reason (void) {
|
||||||
return mp_obj_new_int(pyb_sleep_get_wake_reason());
|
return mp_obj_new_int(pyb_sleep_get_wake_reason());
|
||||||
|
|
|
@ -122,6 +122,7 @@
|
||||||
#define MICROPY_PY_TIME_INCLUDEFILE "ports/cc3200/mods/modtime.c"
|
#define MICROPY_PY_TIME_INCLUDEFILE "ports/cc3200/mods/modtime.c"
|
||||||
#define MICROPY_PY_MACHINE (1)
|
#define MICROPY_PY_MACHINE (1)
|
||||||
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/cc3200/mods/modmachine.c"
|
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/cc3200/mods/modmachine.c"
|
||||||
|
#define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1)
|
||||||
#define MICROPY_PY_MACHINE_WDT (1)
|
#define MICROPY_PY_MACHINE_WDT (1)
|
||||||
#define MICROPY_PY_MACHINE_WDT_INCLUDEFILE "ports/cc3200/mods/machine_wdt.c"
|
#define MICROPY_PY_MACHINE_WDT_INCLUDEFILE "ports/cc3200/mods/machine_wdt.c"
|
||||||
|
|
||||||
|
|
|
@ -52,12 +52,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_obj) }, \
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, \
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) }, \
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&machine_lightsleep_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_disable_irq), MP_ROM_PTR(&machine_disable_irq_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) }, \
|
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, \
|
||||||
|
@ -73,7 +68,6 @@
|
||||||
{ MP_ROM_QSTR(MP_QSTR_DEEPSLEEP), MP_ROM_INT(MACHINE_WAKE_DEEPSLEEP) }, \
|
{ MP_ROM_QSTR(MP_QSTR_DEEPSLEEP), MP_ROM_INT(MACHINE_WAKE_DEEPSLEEP) }, \
|
||||||
\
|
\
|
||||||
/* Reset reasons */ \
|
/* Reset reasons */ \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) }, \
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_HARD_RESET), MP_ROM_INT(MP_HARD_RESET) }, \
|
{ MP_ROM_QSTR(MP_QSTR_HARD_RESET), MP_ROM_INT(MP_HARD_RESET) }, \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_PWRON_RESET), MP_ROM_INT(MP_PWRON_RESET) }, \
|
{ MP_ROM_QSTR(MP_QSTR_PWRON_RESET), MP_ROM_INT(MP_PWRON_RESET) }, \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_WDT_RESET), MP_ROM_INT(MP_WDT_RESET) }, \
|
{ MP_ROM_QSTR(MP_QSTR_WDT_RESET), MP_ROM_INT(MP_WDT_RESET) }, \
|
||||||
|
@ -103,65 +97,51 @@ STATIC bool is_soft_reset = 0;
|
||||||
int esp_clk_cpu_freq(void);
|
int esp_clk_cpu_freq(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t mp_machine_get_freq(void) {
|
||||||
if (n_args == 0) {
|
return mp_obj_new_int(esp_rom_get_cpu_ticks_per_us() * 1000000);
|
||||||
// get
|
}
|
||||||
return mp_obj_new_int(esp_rom_get_cpu_ticks_per_us() * 1000000);
|
|
||||||
} else {
|
STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
|
||||||
// set
|
mp_int_t freq = mp_obj_get_int(args[0]) / 1000000;
|
||||||
mp_int_t freq = mp_obj_get_int(args[0]) / 1000000;
|
if (freq != 20 && freq != 40 && freq != 80 && freq != 160
|
||||||
if (freq != 20 && freq != 40 && freq != 80 && freq != 160
|
#if !CONFIG_IDF_TARGET_ESP32C3
|
||||||
#if !CONFIG_IDF_TARGET_ESP32C3
|
&& freq != 240
|
||||||
&& freq != 240
|
|
||||||
#endif
|
|
||||||
) {
|
|
||||||
#if CONFIG_IDF_TARGET_ESP32C3
|
|
||||||
mp_raise_ValueError(MP_ERROR_TEXT("frequency must be 20MHz, 40MHz, 80Mhz or 160MHz"));
|
|
||||||
#else
|
|
||||||
mp_raise_ValueError(MP_ERROR_TEXT("frequency must be 20MHz, 40MHz, 80Mhz, 160MHz or 240MHz"));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#if CONFIG_IDF_TARGET_ESP32
|
|
||||||
esp_pm_config_esp32_t pm;
|
|
||||||
#elif CONFIG_IDF_TARGET_ESP32C3
|
|
||||||
esp_pm_config_esp32c3_t pm;
|
|
||||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
|
||||||
esp_pm_config_esp32s2_t pm;
|
|
||||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
|
||||||
esp_pm_config_esp32s3_t pm;
|
|
||||||
#endif
|
#endif
|
||||||
pm.max_freq_mhz = freq;
|
) {
|
||||||
pm.min_freq_mhz = freq;
|
#if CONFIG_IDF_TARGET_ESP32C3
|
||||||
pm.light_sleep_enable = false;
|
mp_raise_ValueError(MP_ERROR_TEXT("frequency must be 20MHz, 40MHz, 80Mhz or 160MHz"));
|
||||||
esp_err_t ret = esp_pm_configure(&pm);
|
#else
|
||||||
if (ret != ESP_OK) {
|
mp_raise_ValueError(MP_ERROR_TEXT("frequency must be 20MHz, 40MHz, 80Mhz, 160MHz or 240MHz"));
|
||||||
mp_raise_ValueError(NULL);
|
#endif
|
||||||
}
|
}
|
||||||
while (esp_rom_get_cpu_ticks_per_us() != freq) {
|
#if CONFIG_IDF_TARGET_ESP32
|
||||||
vTaskDelay(1);
|
esp_pm_config_esp32_t pm;
|
||||||
}
|
#elif CONFIG_IDF_TARGET_ESP32C3
|
||||||
return mp_const_none;
|
esp_pm_config_esp32c3_t pm;
|
||||||
|
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||||
|
esp_pm_config_esp32s2_t pm;
|
||||||
|
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||||
|
esp_pm_config_esp32s3_t pm;
|
||||||
|
#endif
|
||||||
|
pm.max_freq_mhz = freq;
|
||||||
|
pm.min_freq_mhz = freq;
|
||||||
|
pm.light_sleep_enable = false;
|
||||||
|
esp_err_t ret = esp_pm_configure(&pm);
|
||||||
|
if (ret != ESP_OK) {
|
||||||
|
mp_raise_ValueError(NULL);
|
||||||
|
}
|
||||||
|
while (esp_rom_get_cpu_ticks_per_us() != freq) {
|
||||||
|
vTaskDelay(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 1, machine_freq);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_sleep_helper(wake_type_t wake_type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
|
||||||
|
|
||||||
enum {ARG_sleep_ms};
|
|
||||||
const mp_arg_t allowed_args[] = {
|
|
||||||
{ MP_QSTR_sleep_ms, MP_ARG_INT, { .u_int = 0 } },
|
|
||||||
};
|
|
||||||
|
|
||||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
|
||||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
|
||||||
|
|
||||||
|
|
||||||
mp_int_t expiry = args[ARG_sleep_ms].u_int;
|
|
||||||
|
|
||||||
|
STATIC void machine_sleep_helper(wake_type_t wake_type, size_t n_args, const mp_obj_t *args) {
|
||||||
// First, disable any previously set wake-up source
|
// First, disable any previously set wake-up source
|
||||||
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
|
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
|
||||||
|
|
||||||
if (expiry != 0) {
|
// Set the expiry time of the sleep, if given.
|
||||||
|
if (n_args != 0) {
|
||||||
|
mp_int_t expiry = mp_obj_get_int(args[0]);
|
||||||
esp_sleep_enable_timer_wakeup(((uint64_t)expiry) * 1000);
|
esp_sleep_enable_timer_wakeup(((uint64_t)expiry) * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,53 +179,45 @@ STATIC mp_obj_t machine_sleep_helper(wake_type_t wake_type, size_t n_args, const
|
||||||
esp_deep_sleep_start();
|
esp_deep_sleep_start();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return mp_const_none;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||||
return machine_sleep_helper(MACHINE_WAKE_SLEEP, n_args, pos_args, kw_args);
|
machine_sleep_helper(MACHINE_WAKE_SLEEP, n_args, args);
|
||||||
};
|
};
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_lightsleep_obj, 0, machine_lightsleep);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_deepsleep(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||||
return machine_sleep_helper(MACHINE_WAKE_DEEPSLEEP, n_args, pos_args, kw_args);
|
machine_sleep_helper(MACHINE_WAKE_DEEPSLEEP, n_args, args);
|
||||||
|
mp_machine_reset();
|
||||||
};
|
};
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_deepsleep_obj, 0, machine_deepsleep);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_reset_cause(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
STATIC mp_int_t mp_machine_reset_cause(void) {
|
||||||
if (is_soft_reset) {
|
if (is_soft_reset) {
|
||||||
return MP_OBJ_NEW_SMALL_INT(MP_SOFT_RESET);
|
return MP_SOFT_RESET;
|
||||||
}
|
}
|
||||||
switch (esp_reset_reason()) {
|
switch (esp_reset_reason()) {
|
||||||
case ESP_RST_POWERON:
|
case ESP_RST_POWERON:
|
||||||
case ESP_RST_BROWNOUT:
|
case ESP_RST_BROWNOUT:
|
||||||
return MP_OBJ_NEW_SMALL_INT(MP_PWRON_RESET);
|
return MP_PWRON_RESET;
|
||||||
break;
|
|
||||||
|
|
||||||
case ESP_RST_INT_WDT:
|
case ESP_RST_INT_WDT:
|
||||||
case ESP_RST_TASK_WDT:
|
case ESP_RST_TASK_WDT:
|
||||||
case ESP_RST_WDT:
|
case ESP_RST_WDT:
|
||||||
return MP_OBJ_NEW_SMALL_INT(MP_WDT_RESET);
|
return MP_WDT_RESET;
|
||||||
break;
|
|
||||||
|
|
||||||
case ESP_RST_DEEPSLEEP:
|
case ESP_RST_DEEPSLEEP:
|
||||||
return MP_OBJ_NEW_SMALL_INT(MP_DEEPSLEEP_RESET);
|
return MP_DEEPSLEEP_RESET;
|
||||||
break;
|
|
||||||
|
|
||||||
case ESP_RST_SW:
|
case ESP_RST_SW:
|
||||||
case ESP_RST_PANIC:
|
case ESP_RST_PANIC:
|
||||||
case ESP_RST_EXT: // Comment in ESP-IDF: "For ESP32, ESP_RST_EXT is never returned"
|
case ESP_RST_EXT: // Comment in ESP-IDF: "For ESP32, ESP_RST_EXT is never returned"
|
||||||
return MP_OBJ_NEW_SMALL_INT(MP_HARD_RESET);
|
return MP_HARD_RESET;
|
||||||
break;
|
|
||||||
|
|
||||||
case ESP_RST_SDIO:
|
case ESP_RST_SDIO:
|
||||||
case ESP_RST_UNKNOWN:
|
case ESP_RST_UNKNOWN:
|
||||||
default:
|
default:
|
||||||
return MP_OBJ_NEW_SMALL_INT(0);
|
return 0;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_reset_cause_obj, 0, machine_reset_cause);
|
|
||||||
|
|
||||||
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
|
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
|
||||||
MICROPY_BOARD_ENTER_BOOTLOADER(n_args, args);
|
MICROPY_BOARD_ENTER_BOOTLOADER(n_args, args);
|
||||||
|
@ -267,18 +239,15 @@ STATIC mp_obj_t machine_wake_reason(size_t n_args, const mp_obj_t *pos_args, mp_
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_wake_reason_obj, 0, machine_wake_reason);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_wake_reason_obj, 0, machine_wake_reason);
|
||||||
|
|
||||||
STATIC mp_obj_t machine_reset(void) {
|
NORETURN STATIC void mp_machine_reset(void) {
|
||||||
esp_restart();
|
esp_restart();
|
||||||
return mp_const_none;
|
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_unique_id(void) {
|
STATIC mp_obj_t mp_machine_unique_id(void) {
|
||||||
uint8_t chipid[6];
|
uint8_t chipid[6];
|
||||||
esp_efuse_mac_get_default(chipid);
|
esp_efuse_mac_get_default(chipid);
|
||||||
return mp_obj_new_bytes(chipid, 6);
|
return mp_obj_new_bytes(chipid, 6);
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id);
|
|
||||||
|
|
||||||
STATIC void mp_machine_idle(void) {
|
STATIC void mp_machine_idle(void) {
|
||||||
MP_THREAD_GIL_EXIT();
|
MP_THREAD_GIL_EXIT();
|
||||||
|
|
|
@ -97,6 +97,7 @@
|
||||||
#define MICROPY_PY_OS_URANDOM (1)
|
#define MICROPY_PY_OS_URANDOM (1)
|
||||||
#define MICROPY_PY_MACHINE (1)
|
#define MICROPY_PY_MACHINE (1)
|
||||||
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/esp32/modmachine.c"
|
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/esp32/modmachine.c"
|
||||||
|
#define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1)
|
||||||
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
|
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
|
||||||
#define MICROPY_PY_MACHINE_ADC (1)
|
#define MICROPY_PY_MACHINE_ADC (1)
|
||||||
#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/esp32/machine_adc.c"
|
#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/esp32/machine_adc.c"
|
||||||
|
|
|
@ -41,13 +41,7 @@
|
||||||
#define MACHINE_WAKE_DEEPSLEEP (0x04)
|
#define MACHINE_WAKE_DEEPSLEEP (0x04)
|
||||||
|
|
||||||
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_obj) }, \
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, \
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) }, \
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) }, \
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&machine_lightsleep_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_disable_irq), MP_ROM_PTR(&machine_disable_irq_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) }, \
|
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, \
|
||||||
|
@ -68,45 +62,42 @@
|
||||||
{ MP_ROM_QSTR(MP_QSTR_WDT_RESET), MP_ROM_INT(REASON_WDT_RST) }, \
|
{ MP_ROM_QSTR(MP_QSTR_WDT_RESET), MP_ROM_INT(REASON_WDT_RST) }, \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_SOFT_RESET), MP_ROM_INT(REASON_SOFT_RESTART) }, \
|
{ MP_ROM_QSTR(MP_QSTR_SOFT_RESET), MP_ROM_INT(REASON_SOFT_RESTART) }, \
|
||||||
|
|
||||||
STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t mp_machine_get_freq(void) {
|
||||||
if (n_args == 0) {
|
return mp_obj_new_int(system_get_cpu_freq() * 1000000);
|
||||||
// get
|
}
|
||||||
return mp_obj_new_int(system_get_cpu_freq() * 1000000);
|
|
||||||
} else {
|
STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
|
||||||
// set
|
mp_int_t freq = mp_obj_get_int(args[0]) / 1000000;
|
||||||
mp_int_t freq = mp_obj_get_int(args[0]) / 1000000;
|
if (freq != 80 && freq != 160) {
|
||||||
if (freq != 80 && freq != 160) {
|
mp_raise_ValueError(MP_ERROR_TEXT("frequency can only be either 80Mhz or 160MHz"));
|
||||||
mp_raise_ValueError(MP_ERROR_TEXT("frequency can only be either 80Mhz or 160MHz"));
|
}
|
||||||
}
|
system_update_cpu_freq(freq);
|
||||||
system_update_cpu_freq(freq);
|
}
|
||||||
return mp_const_none;
|
|
||||||
|
NORETURN STATIC void mp_machine_reset(void) {
|
||||||
|
system_restart();
|
||||||
|
|
||||||
|
// we must not return
|
||||||
|
for (;;) {
|
||||||
|
ets_loop_iter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 1, machine_freq);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_reset(void) {
|
STATIC mp_int_t mp_machine_reset_cause(void) {
|
||||||
system_restart();
|
return system_get_rst_info()->reason;
|
||||||
return mp_const_none;
|
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_reset_cause(void) {
|
STATIC mp_obj_t mp_machine_unique_id(void) {
|
||||||
return MP_OBJ_NEW_SMALL_INT(system_get_rst_info()->reason);
|
|
||||||
}
|
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_unique_id(void) {
|
|
||||||
uint32_t id = system_get_chip_id();
|
uint32_t id = system_get_chip_id();
|
||||||
return mp_obj_new_bytes((byte *)&id, sizeof(id));
|
return mp_obj_new_bytes((byte *)&id, sizeof(id));
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id);
|
|
||||||
|
|
||||||
STATIC void mp_machine_idle(void) {
|
STATIC void mp_machine_idle(void) {
|
||||||
asm ("waiti 0");
|
asm ("waiti 0");
|
||||||
ets_event_poll(); // handle any events after possibly a long wait (eg feed WDT)
|
ets_event_poll(); // handle any events after possibly a long wait (eg feed WDT)
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
uint32_t max_us = 0xffffffff;
|
uint32_t max_us = 0xffffffff;
|
||||||
if (n_args == 1) {
|
if (n_args == 1) {
|
||||||
mp_int_t max_ms = mp_obj_get_int(args[0]);
|
mp_int_t max_ms = mp_obj_get_int(args[0]);
|
||||||
|
@ -124,11 +115,9 @@ STATIC mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||||
asm ("waiti 0");
|
asm ("waiti 0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mp_const_none;
|
|
||||||
}
|
}
|
||||||
STATIC 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) {
|
||||||
// default to sleep forever
|
// default to sleep forever
|
||||||
uint32_t sleep_us = 0;
|
uint32_t sleep_us = 0;
|
||||||
|
|
||||||
|
@ -171,10 +160,7 @@ STATIC mp_obj_t machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||||
// we must not return
|
// we must not return
|
||||||
ets_loop_iter();
|
ets_loop_iter();
|
||||||
}
|
}
|
||||||
|
|
||||||
return mp_const_none;
|
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_deepsleep_obj, 0, 1, machine_deepsleep);
|
|
||||||
|
|
||||||
// These values are from the datasheet
|
// These values are from the datasheet
|
||||||
#define ESP_TIMER_US_MIN (100)
|
#define ESP_TIMER_US_MIN (100)
|
||||||
|
|
|
@ -65,6 +65,7 @@
|
||||||
#define MICROPY_PY_LWIP_SOCK_RAW (1)
|
#define MICROPY_PY_LWIP_SOCK_RAW (1)
|
||||||
#define MICROPY_PY_MACHINE (1)
|
#define MICROPY_PY_MACHINE (1)
|
||||||
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/esp8266/modmachine.c"
|
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/esp8266/modmachine.c"
|
||||||
|
#define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1)
|
||||||
#define MICROPY_PY_MACHINE_ADC (1)
|
#define MICROPY_PY_MACHINE_ADC (1)
|
||||||
#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/esp8266/machine_adc.c"
|
#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/esp8266/machine_adc.c"
|
||||||
#define MICROPY_PY_MACHINE_ADC_READ (1)
|
#define MICROPY_PY_MACHINE_ADC_READ (1)
|
||||||
|
|
|
@ -57,18 +57,12 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
||||||
{ 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_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) }, \
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_obj) }, \
|
|
||||||
MICROPY_PY_MACHINE_LED_ENTRY \
|
MICROPY_PY_MACHINE_LED_ENTRY \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) }, \
|
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) }, \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&machine_timer_type) }, \
|
{ MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&machine_timer_type) }, \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_RTC), MP_ROM_PTR(&machine_rtc_type) }, \
|
{ MP_ROM_QSTR(MP_QSTR_RTC), MP_ROM_PTR(&machine_rtc_type) }, \
|
||||||
MICROPY_PY_MACHINE_SDCARD_ENTRY \
|
MICROPY_PY_MACHINE_SDCARD_ENTRY \
|
||||||
\
|
\
|
||||||
{ MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&machine_deepsleep_obj) }, \
|
|
||||||
\
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_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) }, \
|
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, \
|
||||||
\
|
\
|
||||||
|
@ -85,27 +79,27 @@ typedef enum {
|
||||||
MP_SOFT_RESET
|
MP_SOFT_RESET
|
||||||
} reset_reason_t;
|
} reset_reason_t;
|
||||||
|
|
||||||
STATIC mp_obj_t machine_unique_id(void) {
|
STATIC mp_obj_t mp_machine_unique_id(void) {
|
||||||
unsigned char id[8];
|
unsigned char id[8];
|
||||||
mp_hal_get_unique_id(id);
|
mp_hal_get_unique_id(id);
|
||||||
return mp_obj_new_bytes(id, sizeof(id));
|
return mp_obj_new_bytes(id, sizeof(id));
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_reset(void) {
|
NORETURN STATIC void mp_machine_reset(void) {
|
||||||
WDOG_TriggerSystemSoftwareReset(WDOG1);
|
WDOG_TriggerSystemSoftwareReset(WDOG1);
|
||||||
return mp_const_none;
|
while (true) {
|
||||||
|
;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_reset_cause(void) {
|
STATIC mp_int_t mp_machine_reset_cause(void) {
|
||||||
#ifdef MIMXRT117x_SERIES
|
#ifdef MIMXRT117x_SERIES
|
||||||
uint32_t user_reset_flag = kSRC_M7CoreIppUserResetFlag;
|
uint32_t user_reset_flag = kSRC_M7CoreIppUserResetFlag;
|
||||||
#else
|
#else
|
||||||
uint32_t user_reset_flag = kSRC_IppUserResetFlag;
|
uint32_t user_reset_flag = kSRC_IppUserResetFlag;
|
||||||
#endif
|
#endif
|
||||||
if (SRC->SRSR & user_reset_flag) {
|
if (SRC->SRSR & user_reset_flag) {
|
||||||
return MP_OBJ_NEW_SMALL_INT(MP_DEEPSLEEP_RESET);
|
return MP_DEEPSLEEP_RESET;
|
||||||
}
|
}
|
||||||
uint16_t reset_cause =
|
uint16_t reset_cause =
|
||||||
WDOG_GetStatusFlags(WDOG1) & (kWDOG_PowerOnResetFlag | kWDOG_TimeoutResetFlag | kWDOG_SoftwareResetFlag);
|
WDOG_GetStatusFlags(WDOG1) & (kWDOG_PowerOnResetFlag | kWDOG_TimeoutResetFlag | kWDOG_SoftwareResetFlag);
|
||||||
|
@ -116,20 +110,26 @@ STATIC mp_obj_t machine_reset_cause(void) {
|
||||||
} else {
|
} else {
|
||||||
reset_cause = MP_SOFT_RESET;
|
reset_cause = MP_SOFT_RESET;
|
||||||
}
|
}
|
||||||
return MP_OBJ_NEW_SMALL_INT(reset_cause);
|
return reset_cause;
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_freq(void) {
|
STATIC mp_obj_t mp_machine_get_freq(void) {
|
||||||
return MP_OBJ_NEW_SMALL_INT(mp_hal_get_cpu_freq());
|
return MP_OBJ_NEW_SMALL_INT(mp_hal_get_cpu_freq());
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_freq_obj, machine_freq);
|
|
||||||
|
STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
|
||||||
|
mp_raise_NotImplementedError(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
STATIC void mp_machine_idle(void) {
|
STATIC void mp_machine_idle(void) {
|
||||||
MICROPY_EVENT_POLL_HOOK;
|
MICROPY_EVENT_POLL_HOOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC mp_obj_t machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||||
|
mp_raise_NotImplementedError(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||||
if (n_args != 0) {
|
if (n_args != 0) {
|
||||||
mp_int_t seconds = mp_obj_get_int(args[0]) / 1000;
|
mp_int_t seconds = mp_obj_get_int(args[0]) / 1000;
|
||||||
if (seconds > 0) {
|
if (seconds > 0) {
|
||||||
|
@ -155,10 +155,7 @@ STATIC mp_obj_t machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||||
while (true) {
|
while (true) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mp_const_none;
|
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_deepsleep_obj, 0, 1, machine_deepsleep);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_disable_irq(void) {
|
STATIC mp_obj_t machine_disable_irq(void) {
|
||||||
uint32_t state = MICROPY_BEGIN_ATOMIC_SECTION();
|
uint32_t state = MICROPY_BEGIN_ATOMIC_SECTION();
|
||||||
|
|
|
@ -79,6 +79,7 @@ uint32_t trng_random_u32(void);
|
||||||
#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (trng_random_u32())
|
#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (trng_random_u32())
|
||||||
#define MICROPY_PY_MACHINE (1)
|
#define MICROPY_PY_MACHINE (1)
|
||||||
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/mimxrt/modmachine.c"
|
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/mimxrt/modmachine.c"
|
||||||
|
#define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1)
|
||||||
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
|
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
|
||||||
#define MICROPY_PY_MACHINE_ADC (1)
|
#define MICROPY_PY_MACHINE_ADC (1)
|
||||||
#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/mimxrt/machine_adc.c"
|
#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/mimxrt/machine_adc.c"
|
||||||
|
|
|
@ -85,13 +85,9 @@
|
||||||
|
|
||||||
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&machine_info_obj) }, \
|
{ 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_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_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_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) }, \
|
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&pin_type) }, \
|
||||||
\
|
\
|
||||||
MICROPY_PY_MACHINE_RTCOUNTER_ENTRY \
|
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;
|
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.
|
// 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();
|
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) {
|
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
|
||||||
MICROPY_BOARD_ENTER_BOOTLOADER(n_args, args);
|
MICROPY_BOARD_ENTER_BOOTLOADER(n_args, args);
|
||||||
|
@ -197,22 +195,25 @@ STATIC void mp_machine_idle(void) {
|
||||||
MICROPY_EVENT_POLL_HOOK;
|
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();
|
__WFE();
|
||||||
return mp_const_none;
|
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_lightsleep_obj, machine_lightsleep);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_deepsleep(void) {
|
NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||||
__WFI();
|
mp_machine_reset();
|
||||||
return mp_const_none;
|
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_deepsleep_obj, machine_deepsleep);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_reset_cause(void) {
|
STATIC mp_int_t mp_machine_reset_cause(void) {
|
||||||
return MP_OBJ_NEW_SMALL_INT(reset_cause);
|
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) {
|
STATIC mp_obj_t machine_enable_irq(void) {
|
||||||
#ifndef BLUETOOTH_SD
|
#ifndef BLUETOOTH_SD
|
||||||
|
|
|
@ -32,9 +32,4 @@
|
||||||
|
|
||||||
void machine_init(void);
|
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__
|
#endif // __MICROPY_INCLUDED_NRF5_MODMACHINE_H__
|
||||||
|
|
|
@ -160,6 +160,7 @@
|
||||||
#define MICROPY_PY_TIME (1)
|
#define MICROPY_PY_TIME (1)
|
||||||
#define MICROPY_PY_MACHINE (1)
|
#define MICROPY_PY_MACHINE (1)
|
||||||
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/nrf/modules/machine/modmachine.c"
|
#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_PULSE (0)
|
||||||
#define MICROPY_PY_MACHINE_SOFTI2C (MICROPY_PY_MACHINE_I2C)
|
#define MICROPY_PY_MACHINE_SOFTI2C (MICROPY_PY_MACHINE_I2C)
|
||||||
|
|
||||||
|
|
|
@ -63,13 +63,7 @@
|
||||||
|
|
||||||
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&machine_info_obj) }, \
|
{ 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_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_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) }, \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_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);
|
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.
|
// 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];
|
uint8_t id[16];
|
||||||
get_unique_id((uint8_t *)&id);
|
get_unique_id((uint8_t *)&id);
|
||||||
return mp_obj_new_bytes(id, 16);
|
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.
|
// 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();
|
powerctrl_mcu_reset();
|
||||||
return mp_const_none;
|
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
|
|
||||||
|
|
||||||
// Activate the bootloader without BOOT* pins.
|
// Activate the bootloader without BOOT* pins.
|
||||||
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
|
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
|
// get or set the MCU frequencies
|
||||||
STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t mp_machine_get_freq(void) {
|
||||||
if (n_args == 0) {
|
return mp_obj_new_int(SystemCoreClock);
|
||||||
// get
|
}
|
||||||
return mp_obj_new_int(SystemCoreClock);
|
|
||||||
} else {
|
STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
|
||||||
// set
|
mp_raise_NotImplementedError(MP_ERROR_TEXT("machine.freq set not supported yet"));
|
||||||
mp_raise_NotImplementedError(MP_ERROR_TEXT("machine.freq set not supported yet"));
|
|
||||||
return mp_const_none;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 4, machine_freq);
|
|
||||||
|
|
||||||
// idle()
|
// idle()
|
||||||
// This executies a wfi machine instruction which reduces power consumption
|
// This executies a wfi machine instruction which reduces power consumption
|
||||||
|
@ -237,27 +224,22 @@ STATIC void mp_machine_idle(void) {
|
||||||
__WFI();
|
__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) {
|
if (n_args != 0) {
|
||||||
mp_obj_t args2[2] = {MP_OBJ_NULL, args[0]};
|
mp_obj_t args2[2] = {MP_OBJ_NULL, args[0]};
|
||||||
machine_rtc_wakeup(2, args2);
|
machine_rtc_wakeup(2, args2);
|
||||||
}
|
}
|
||||||
powerctrl_enter_stop_mode();
|
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) {
|
if (n_args != 0) {
|
||||||
mp_obj_t args2[2] = {MP_OBJ_NULL, args[0]};
|
mp_obj_t args2[2] = {MP_OBJ_NULL, args[0]};
|
||||||
machine_rtc_wakeup(2, args2);
|
machine_rtc_wakeup(2, args2);
|
||||||
}
|
}
|
||||||
powerctrl_enter_standby_mode();
|
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) {
|
STATIC mp_int_t mp_machine_reset_cause(void) {
|
||||||
return MP_OBJ_NEW_SMALL_INT(reset_cause);
|
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_dac_type;
|
||||||
extern const mp_obj_type_t machine_sdcard_type;
|
extern const mp_obj_type_t machine_sdcard_type;
|
||||||
|
|
||||||
|
|
||||||
void machine_init(void);
|
void machine_init(void);
|
||||||
void machine_deinit(void);
|
void machine_deinit(void);
|
||||||
void machine_pin_init(void);
|
void machine_pin_init(void);
|
||||||
void machine_pin_deinit(void);
|
void machine_pin_deinit(void);
|
||||||
void machine_i2s_init0(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_0(machine_disable_irq_obj);
|
||||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_enable_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
|
#endif // MICROPY_INCLUDED_RENESAS_RA_MODMACHINE_H
|
||||||
|
|
|
@ -131,6 +131,7 @@
|
||||||
#ifndef MICROPY_PY_MACHINE
|
#ifndef MICROPY_PY_MACHINE
|
||||||
#define MICROPY_PY_MACHINE (1)
|
#define MICROPY_PY_MACHINE (1)
|
||||||
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/renesas-ra/modmachine.c"
|
#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_BOOTLOADER (1)
|
||||||
#define MICROPY_PY_MACHINE_ADC (1)
|
#define MICROPY_PY_MACHINE_ADC (1)
|
||||||
#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/renesas-ra/machine_adc.c"
|
#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);
|
enable_irq(irq_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void powerctrl_enter_standby_mode(void) {
|
NORETURN void powerctrl_enter_standby_mode(void) {
|
||||||
rtc_init_finalise();
|
rtc_init_finalise();
|
||||||
|
|
||||||
#if defined(MICROPY_BOARD_ENTER_STANDBY)
|
#if defined(MICROPY_BOARD_ENTER_STANDBY)
|
||||||
|
@ -301,4 +301,6 @@ void powerctrl_enter_standby_mode(void) {
|
||||||
// enter standby mode
|
// enter standby mode
|
||||||
|
|
||||||
// we never return; MCU is reset on exit from standby
|
// 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_check_enter_bootloader(void);
|
||||||
|
|
||||||
void powerctrl_enter_stop_mode(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
|
#endif // MICROPY_INCLUDED_RA_POWERCTRL_H
|
||||||
|
|
|
@ -48,14 +48,6 @@
|
||||||
#define RP2_RESET_WDT (3)
|
#define RP2_RESET_WDT (3)
|
||||||
|
|
||||||
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
||||||
{ 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_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) }, \
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_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_disable_irq), MP_ROM_PTR(&machine_disable_irq_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) }, \
|
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, \
|
||||||
\
|
\
|
||||||
|
@ -66,32 +58,28 @@
|
||||||
{ MP_ROM_QSTR(MP_QSTR_PWRON_RESET), MP_ROM_INT(RP2_RESET_PWRON) }, \
|
{ MP_ROM_QSTR(MP_QSTR_PWRON_RESET), MP_ROM_INT(RP2_RESET_PWRON) }, \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_WDT_RESET), MP_ROM_INT(RP2_RESET_WDT) }, \
|
{ MP_ROM_QSTR(MP_QSTR_WDT_RESET), MP_ROM_INT(RP2_RESET_WDT) }, \
|
||||||
|
|
||||||
STATIC mp_obj_t machine_unique_id(void) {
|
STATIC mp_obj_t mp_machine_unique_id(void) {
|
||||||
pico_unique_board_id_t id;
|
pico_unique_board_id_t id;
|
||||||
pico_get_unique_board_id(&id);
|
pico_get_unique_board_id(&id);
|
||||||
return mp_obj_new_bytes(id.id, sizeof(id.id));
|
return mp_obj_new_bytes(id.id, sizeof(id.id));
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_reset(void) {
|
NORETURN STATIC void mp_machine_reset(void) {
|
||||||
watchdog_reboot(0, SRAM_END, 0);
|
watchdog_reboot(0, SRAM_END, 0);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
__wfi();
|
__wfi();
|
||||||
}
|
}
|
||||||
return mp_const_none;
|
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_reset_cause(void) {
|
STATIC mp_int_t mp_machine_reset_cause(void) {
|
||||||
int reset_cause;
|
int reset_cause;
|
||||||
if (watchdog_caused_reboot()) {
|
if (watchdog_caused_reboot()) {
|
||||||
reset_cause = RP2_RESET_WDT;
|
reset_cause = RP2_RESET_WDT;
|
||||||
} else {
|
} else {
|
||||||
reset_cause = RP2_RESET_PWRON;
|
reset_cause = RP2_RESET_PWRON;
|
||||||
}
|
}
|
||||||
return MP_OBJ_NEW_SMALL_INT(reset_cause);
|
return reset_cause;
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause);
|
|
||||||
|
|
||||||
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
|
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
|
||||||
MICROPY_BOARD_ENTER_BOOTLOADER(n_args, args);
|
MICROPY_BOARD_ENTER_BOOTLOADER(n_args, args);
|
||||||
|
@ -101,28 +89,26 @@ NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t mp_machine_get_freq(void) {
|
||||||
if (n_args == 0) {
|
return MP_OBJ_NEW_SMALL_INT(mp_hal_get_cpu_freq());
|
||||||
return MP_OBJ_NEW_SMALL_INT(mp_hal_get_cpu_freq());
|
}
|
||||||
} else {
|
|
||||||
mp_int_t freq = mp_obj_get_int(args[0]);
|
STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
|
||||||
if (!set_sys_clock_khz(freq / 1000, false)) {
|
mp_int_t freq = mp_obj_get_int(args[0]);
|
||||||
mp_raise_ValueError(MP_ERROR_TEXT("cannot change frequency"));
|
if (!set_sys_clock_khz(freq / 1000, false)) {
|
||||||
}
|
mp_raise_ValueError(MP_ERROR_TEXT("cannot change frequency"));
|
||||||
#if MICROPY_HW_ENABLE_UART_REPL
|
}
|
||||||
setup_default_uart();
|
#if MICROPY_HW_ENABLE_UART_REPL
|
||||||
mp_uart_init();
|
setup_default_uart();
|
||||||
#endif
|
mp_uart_init();
|
||||||
return mp_const_none;
|
#endif
|
||||||
}
|
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 1, machine_freq);
|
|
||||||
|
|
||||||
STATIC void mp_machine_idle(void) {
|
STATIC void mp_machine_idle(void) {
|
||||||
__wfe();
|
__wfe();
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
mp_int_t delay_ms = 0;
|
mp_int_t delay_ms = 0;
|
||||||
bool use_timer_alarm = false;
|
bool use_timer_alarm = false;
|
||||||
|
|
||||||
|
@ -131,7 +117,7 @@ STATIC mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||||
if (delay_ms <= 1) {
|
if (delay_ms <= 1) {
|
||||||
// Sleep is too small, just use standard delay.
|
// Sleep is too small, just use standard delay.
|
||||||
mp_hal_delay_ms(delay_ms);
|
mp_hal_delay_ms(delay_ms);
|
||||||
return mp_const_none;
|
return;
|
||||||
}
|
}
|
||||||
use_timer_alarm = delay_ms < (1ULL << 32) / 1000;
|
use_timer_alarm = delay_ms < (1ULL << 32) / 1000;
|
||||||
if (use_timer_alarm) {
|
if (use_timer_alarm) {
|
||||||
|
@ -148,7 +134,7 @@ STATIC mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||||
#if MICROPY_PY_NETWORK_CYW43
|
#if MICROPY_PY_NETWORK_CYW43
|
||||||
if (cyw43_has_pending && cyw43_poll != NULL) {
|
if (cyw43_has_pending && cyw43_poll != NULL) {
|
||||||
restore_interrupts(my_interrupts);
|
restore_interrupts(my_interrupts);
|
||||||
return mp_const_none;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// Disable USB and ADC clocks.
|
// Disable USB and ADC clocks.
|
||||||
|
@ -204,16 +190,12 @@ STATIC mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||||
// Bring back all clocks.
|
// Bring back all clocks.
|
||||||
clocks_init();
|
clocks_init();
|
||||||
restore_interrupts(my_interrupts);
|
restore_interrupts(my_interrupts);
|
||||||
|
|
||||||
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) {
|
||||||
machine_lightsleep(n_args, args);
|
mp_machine_lightsleep(n_args, args);
|
||||||
return machine_reset();
|
mp_machine_reset();
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_deepsleep_obj, 0, 1, machine_deepsleep);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_disable_irq(void) {
|
STATIC mp_obj_t machine_disable_irq(void) {
|
||||||
uint32_t state = MICROPY_BEGIN_ATOMIC_SECTION();
|
uint32_t state = MICROPY_BEGIN_ATOMIC_SECTION();
|
||||||
|
|
|
@ -112,6 +112,7 @@
|
||||||
#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (rosc_random_u32())
|
#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (rosc_random_u32())
|
||||||
#define MICROPY_PY_MACHINE (1)
|
#define MICROPY_PY_MACHINE (1)
|
||||||
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/rp2/modmachine.c"
|
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/rp2/modmachine.c"
|
||||||
|
#define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1)
|
||||||
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
|
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
|
||||||
#define MICROPY_PY_MACHINE_ADC (1)
|
#define MICROPY_PY_MACHINE_ADC (1)
|
||||||
#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/rp2/machine_adc.c"
|
#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/rp2/machine_adc.c"
|
||||||
|
|
|
@ -55,19 +55,12 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
||||||
{ 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_unique_id), MP_ROM_PTR(&machine_unique_id_obj) }, \
|
|
||||||
\
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) }, \
|
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) }, \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&machine_timer_type) }, \
|
{ MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&machine_timer_type) }, \
|
||||||
MICROPY_PY_MACHINE_RTC_ENTRY \
|
MICROPY_PY_MACHINE_RTC_ENTRY \
|
||||||
\
|
\
|
||||||
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_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) }, \
|
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) }, \
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_lightsleep), MP_ROM_PTR(&machine_lightsleep_obj) }, \
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&machine_lightsleep_obj) }, \
|
|
||||||
\
|
\
|
||||||
/* Class constants. */ \
|
/* Class constants. */ \
|
||||||
/* Use numerical constants instead of the symbolic names, */ \
|
/* Use numerical constants instead of the symbolic names, */ \
|
||||||
|
@ -81,15 +74,13 @@
|
||||||
extern bool EIC_occured;
|
extern bool EIC_occured;
|
||||||
extern uint32_t _dbl_tap_addr;
|
extern uint32_t _dbl_tap_addr;
|
||||||
|
|
||||||
STATIC mp_obj_t machine_reset(void) {
|
NORETURN STATIC void mp_machine_reset(void) {
|
||||||
*DBL_TAP_ADDR = DBL_TAP_MAGIC_RESET;
|
*DBL_TAP_ADDR = DBL_TAP_MAGIC_RESET;
|
||||||
#ifdef DBL_TAP_ADDR_ALT
|
#ifdef DBL_TAP_ADDR_ALT
|
||||||
*DBL_TAP_ADDR_ALT = DBL_TAP_MAGIC_RESET;
|
*DBL_TAP_ADDR_ALT = DBL_TAP_MAGIC_RESET;
|
||||||
#endif
|
#endif
|
||||||
NVIC_SystemReset();
|
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) {
|
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
|
||||||
*DBL_TAP_ADDR = DBL_TAP_MAGIC_LOADER;
|
*DBL_TAP_ADDR = DBL_TAP_MAGIC_LOADER;
|
||||||
|
@ -99,25 +90,22 @@ NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t mp_machine_get_freq(void) {
|
||||||
if (n_args == 0) {
|
return MP_OBJ_NEW_SMALL_INT(get_cpu_freq());
|
||||||
return MP_OBJ_NEW_SMALL_INT(get_cpu_freq());
|
}
|
||||||
} else {
|
|
||||||
uint32_t freq = mp_obj_get_int(args[0]);
|
STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
|
||||||
if (freq >= 1000000 && freq <= MAX_CPU_FREQ) {
|
uint32_t freq = mp_obj_get_int(args[0]);
|
||||||
set_cpu_freq(freq);
|
if (freq >= 1000000 && freq <= MAX_CPU_FREQ) {
|
||||||
}
|
set_cpu_freq(freq);
|
||||||
return mp_const_none;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 1, machine_freq);
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_unique_id(void) {
|
STATIC mp_obj_t mp_machine_unique_id(void) {
|
||||||
samd_unique_id_t id;
|
samd_unique_id_t id;
|
||||||
samd_get_unique_id(&id);
|
samd_get_unique_id(&id);
|
||||||
return mp_obj_new_bytes((byte *)&id.bytes, sizeof(id.bytes));
|
return mp_obj_new_bytes((byte *)&id.bytes, sizeof(id.bytes));
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id);
|
|
||||||
|
|
||||||
STATIC void mp_machine_idle(void) {
|
STATIC void mp_machine_idle(void) {
|
||||||
MICROPY_EVENT_POLL_HOOK;
|
MICROPY_EVENT_POLL_HOOK;
|
||||||
|
@ -136,18 +124,17 @@ STATIC mp_obj_t machine_enable_irq(mp_obj_t state_in) {
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_1(machine_enable_irq_obj, machine_enable_irq);
|
MP_DEFINE_CONST_FUN_OBJ_1(machine_enable_irq_obj, machine_enable_irq);
|
||||||
|
|
||||||
STATIC mp_obj_t machine_reset_cause(void) {
|
STATIC mp_int_t mp_machine_reset_cause(void) {
|
||||||
#if defined(MCU_SAMD21)
|
#if defined(MCU_SAMD21)
|
||||||
return MP_OBJ_NEW_SMALL_INT(PM->RCAUSE.reg);
|
return PM->RCAUSE.reg;
|
||||||
#elif defined(MCU_SAMD51)
|
#elif defined(MCU_SAMD51)
|
||||||
return MP_OBJ_NEW_SMALL_INT(RSTC->RCAUSE.reg);
|
return RSTC->RCAUSE.reg;
|
||||||
#else
|
#else
|
||||||
return MP_OBJ_NEW_SMALL_INT(0);
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause);
|
|
||||||
|
|
||||||
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) {
|
||||||
int32_t duration = -1;
|
int32_t duration = -1;
|
||||||
uint32_t freq = get_cpu_freq();
|
uint32_t freq = get_cpu_freq();
|
||||||
if (n_args > 0) {
|
if (n_args > 0) {
|
||||||
|
@ -197,6 +184,9 @@ STATIC mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||||
#endif
|
#endif
|
||||||
// Speed up again
|
// Speed up again
|
||||||
set_cpu_freq(freq);
|
set_cpu_freq(freq);
|
||||||
return mp_const_none;
|
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lightsleep_obj, 0, 1, machine_lightsleep);
|
|
||||||
|
NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||||
|
mp_machine_lightsleep(n_args, args);
|
||||||
|
mp_machine_reset();
|
||||||
|
}
|
||||||
|
|
|
@ -94,6 +94,7 @@
|
||||||
#define MICROPY_PY_TIME_INCLUDEFILE "ports/samd/modtime.c"
|
#define MICROPY_PY_TIME_INCLUDEFILE "ports/samd/modtime.c"
|
||||||
#define MICROPY_PY_MACHINE (1)
|
#define MICROPY_PY_MACHINE (1)
|
||||||
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/samd/modmachine.c"
|
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/samd/modmachine.c"
|
||||||
|
#define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1)
|
||||||
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
|
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
|
||||||
#define MICROPY_PY_OS (1)
|
#define MICROPY_PY_OS (1)
|
||||||
#define MICROPY_PY_OS_INCLUDEFILE "ports/samd/modos.c"
|
#define MICROPY_PY_OS_INCLUDEFILE "ports/samd/modos.c"
|
||||||
|
|
|
@ -97,14 +97,8 @@
|
||||||
|
|
||||||
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&machine_info_obj) }, \
|
{ 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) }, \
|
|
||||||
MICROPY_PY_MACHINE_RNG_ENTRY \
|
MICROPY_PY_MACHINE_RNG_ENTRY \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&machine_lightsleep_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_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) }, \
|
||||||
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, \
|
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, \
|
||||||
|
@ -283,18 +277,15 @@ 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);
|
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj, 0, 1, machine_info);
|
||||||
|
|
||||||
// Returns a string of 12 bytes (96 bits), which is the unique ID for the MCU.
|
// Returns a string of 12 bytes (96 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) {
|
||||||
byte *id = (byte *)MP_HAL_UNIQUE_ID_ADDRESS;
|
byte *id = (byte *)MP_HAL_UNIQUE_ID_ADDRESS;
|
||||||
return mp_obj_new_bytes(id, 12);
|
return mp_obj_new_bytes(id, 12);
|
||||||
}
|
}
|
||||||
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.
|
// 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();
|
powerctrl_mcu_reset();
|
||||||
return mp_const_none;
|
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
|
|
||||||
|
|
||||||
// Activate the bootloader without BOOT* pins.
|
// Activate the bootloader without BOOT* pins.
|
||||||
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
|
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
|
||||||
|
@ -323,57 +314,53 @@ NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// get or set the MCU frequencies
|
// get or set the MCU frequencies
|
||||||
STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t mp_machine_get_freq(void) {
|
||||||
if (n_args == 0) {
|
mp_obj_t tuple[] = {
|
||||||
// get
|
mp_obj_new_int(HAL_RCC_GetSysClockFreq()),
|
||||||
mp_obj_t tuple[] = {
|
mp_obj_new_int(HAL_RCC_GetHCLKFreq()),
|
||||||
mp_obj_new_int(HAL_RCC_GetSysClockFreq()),
|
mp_obj_new_int(HAL_RCC_GetPCLK1Freq()),
|
||||||
mp_obj_new_int(HAL_RCC_GetHCLKFreq()),
|
#if !defined(STM32F0) && !defined(STM32G0)
|
||||||
mp_obj_new_int(HAL_RCC_GetPCLK1Freq()),
|
mp_obj_new_int(HAL_RCC_GetPCLK2Freq()),
|
||||||
#if !defined(STM32F0) && !defined(STM32G0)
|
|
||||||
mp_obj_new_int(HAL_RCC_GetPCLK2Freq()),
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
return mp_obj_new_tuple(MP_ARRAY_SIZE(tuple), tuple);
|
|
||||||
} else {
|
|
||||||
// set
|
|
||||||
#if defined(STM32F0) || defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32G0)
|
|
||||||
mp_raise_NotImplementedError(MP_ERROR_TEXT("machine.freq set not supported yet"));
|
|
||||||
#else
|
|
||||||
mp_int_t sysclk = mp_obj_get_int(args[0]);
|
|
||||||
mp_int_t ahb = sysclk;
|
|
||||||
#if defined(STM32H7)
|
|
||||||
if (ahb > 200000000) {
|
|
||||||
ahb /= 2;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(STM32WB)
|
};
|
||||||
mp_int_t apb1 = ahb;
|
return mp_obj_new_tuple(MP_ARRAY_SIZE(tuple), tuple);
|
||||||
mp_int_t apb2 = ahb;
|
}
|
||||||
#else
|
|
||||||
mp_int_t apb1 = ahb / 4;
|
STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
|
||||||
mp_int_t apb2 = ahb / 2;
|
#if defined(STM32F0) || defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32G0)
|
||||||
#endif
|
mp_raise_NotImplementedError(MP_ERROR_TEXT("machine.freq set not supported yet"));
|
||||||
if (n_args > 1) {
|
#else
|
||||||
ahb = mp_obj_get_int(args[1]);
|
mp_int_t sysclk = mp_obj_get_int(args[0]);
|
||||||
if (n_args > 2) {
|
mp_int_t ahb = sysclk;
|
||||||
apb1 = mp_obj_get_int(args[2]);
|
#if defined(STM32H7)
|
||||||
if (n_args > 3) {
|
if (ahb > 200000000) {
|
||||||
apb2 = mp_obj_get_int(args[3]);
|
ahb /= 2;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(STM32WB)
|
||||||
|
mp_int_t apb1 = ahb;
|
||||||
|
mp_int_t apb2 = ahb;
|
||||||
|
#else
|
||||||
|
mp_int_t apb1 = ahb / 4;
|
||||||
|
mp_int_t apb2 = ahb / 2;
|
||||||
|
#endif
|
||||||
|
if (n_args > 1) {
|
||||||
|
ahb = mp_obj_get_int(args[1]);
|
||||||
|
if (n_args > 2) {
|
||||||
|
apb1 = mp_obj_get_int(args[2]);
|
||||||
|
if (n_args > 3) {
|
||||||
|
apb2 = mp_obj_get_int(args[3]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int ret = powerctrl_set_sysclk(sysclk, ahb, apb1, apb2);
|
|
||||||
if (ret == -MP_EINVAL) {
|
|
||||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid freq"));
|
|
||||||
} else if (ret < 0) {
|
|
||||||
MICROPY_BOARD_FATAL_ERROR("can't change freq");
|
|
||||||
}
|
|
||||||
return mp_const_none;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
int ret = powerctrl_set_sysclk(sysclk, ahb, apb1, apb2);
|
||||||
|
if (ret == -MP_EINVAL) {
|
||||||
|
mp_raise_ValueError(MP_ERROR_TEXT("invalid freq"));
|
||||||
|
} else if (ret < 0) {
|
||||||
|
MICROPY_BOARD_FATAL_ERROR("can't change freq");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 4, machine_freq);
|
|
||||||
|
|
||||||
// idle()
|
// idle()
|
||||||
// This executies a wfi machine instruction which reduces power consumption
|
// This executies a wfi machine instruction which reduces power consumption
|
||||||
|
@ -382,27 +369,22 @@ STATIC void mp_machine_idle(void) {
|
||||||
__WFI();
|
__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) {
|
if (n_args != 0) {
|
||||||
mp_obj_t args2[2] = {MP_OBJ_NULL, args[0]};
|
mp_obj_t args2[2] = {MP_OBJ_NULL, args[0]};
|
||||||
pyb_rtc_wakeup(2, args2);
|
pyb_rtc_wakeup(2, args2);
|
||||||
}
|
}
|
||||||
powerctrl_enter_stop_mode();
|
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) {
|
STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||||
if (n_args != 0) {
|
if (n_args != 0) {
|
||||||
mp_obj_t args2[2] = {MP_OBJ_NULL, args[0]};
|
mp_obj_t args2[2] = {MP_OBJ_NULL, args[0]};
|
||||||
pyb_rtc_wakeup(2, args2);
|
pyb_rtc_wakeup(2, args2);
|
||||||
}
|
}
|
||||||
powerctrl_enter_standby_mode();
|
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) {
|
STATIC mp_int_t mp_machine_reset_cause(void) {
|
||||||
return MP_OBJ_NEW_SMALL_INT(reset_cause);
|
return reset_cause;
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause);
|
|
||||||
|
|
|
@ -33,13 +33,6 @@ void machine_deinit(void);
|
||||||
void machine_i2s_init0();
|
void machine_i2s_init0();
|
||||||
|
|
||||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj);
|
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_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_reset_cause_obj);
|
|
||||||
|
|
||||||
MP_DECLARE_CONST_FUN_OBJ_0(machine_disable_irq_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_VAR_BETWEEN(machine_enable_irq_obj);
|
||||||
|
|
|
@ -111,6 +111,7 @@
|
||||||
#ifndef MICROPY_PY_MACHINE
|
#ifndef MICROPY_PY_MACHINE
|
||||||
#define MICROPY_PY_MACHINE (1)
|
#define MICROPY_PY_MACHINE (1)
|
||||||
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/stm32/modmachine.c"
|
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/stm32/modmachine.c"
|
||||||
|
#define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1)
|
||||||
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
|
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
|
||||||
#define MICROPY_PY_MACHINE_ADC (1)
|
#define MICROPY_PY_MACHINE_ADC (1)
|
||||||
#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/stm32/machine_adc.c"
|
#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/stm32/machine_adc.c"
|
||||||
|
|
|
@ -993,7 +993,7 @@ void powerctrl_enter_stop_mode(void) {
|
||||||
enable_irq(irq_state);
|
enable_irq(irq_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void powerctrl_enter_standby_mode(void) {
|
NORETURN void powerctrl_enter_standby_mode(void) {
|
||||||
rtc_init_finalise();
|
rtc_init_finalise();
|
||||||
|
|
||||||
#if defined(MICROPY_BOARD_ENTER_STANDBY)
|
#if defined(MICROPY_BOARD_ENTER_STANDBY)
|
||||||
|
@ -1114,5 +1114,7 @@ void powerctrl_enter_standby_mode(void) {
|
||||||
|
|
||||||
// enter standby mode
|
// enter standby mode
|
||||||
HAL_PWR_EnterSTANDBYMode();
|
HAL_PWR_EnterSTANDBYMode();
|
||||||
// we never return; MCU is reset on exit from standby
|
|
||||||
|
// MCU is reset on exit from standby, but just in case it's not, do an explicit reset.
|
||||||
|
powerctrl_mcu_reset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,6 @@ void powerctrl_config_systick(void);
|
||||||
int powerctrl_rcc_clock_config_pll(RCC_ClkInitTypeDef *rcc_init, uint32_t sysclk_mhz, bool need_pllsai);
|
int powerctrl_rcc_clock_config_pll(RCC_ClkInitTypeDef *rcc_init, uint32_t sysclk_mhz, bool need_pllsai);
|
||||||
int powerctrl_set_sysclk(uint32_t sysclk, uint32_t ahb, uint32_t apb1, uint32_t apb2);
|
int powerctrl_set_sysclk(uint32_t sysclk, uint32_t ahb, uint32_t apb1, uint32_t apb2);
|
||||||
void powerctrl_enter_stop_mode(void);
|
void powerctrl_enter_stop_mode(void);
|
||||||
void powerctrl_enter_standby_mode(void);
|
NORETURN void powerctrl_enter_standby_mode(void);
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_STM32_POWERCTRL_H
|
#endif // MICROPY_INCLUDED_STM32_POWERCTRL_H
|
||||||
|
|
|
@ -50,13 +50,13 @@ STATIC mp_obj_t machine_reset(void) {
|
||||||
// Won't get here, Zephyr has infiniloop on its side
|
// Won't get here, Zephyr has infiniloop on its side
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
|
MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
|
||||||
|
|
||||||
STATIC mp_obj_t machine_reset_cause(void) {
|
STATIC mp_obj_t machine_reset_cause(void) {
|
||||||
printf("Warning: %s is not implemented\n", __func__);
|
printf("Warning: %s is not implemented\n", __func__);
|
||||||
return MP_OBJ_NEW_SMALL_INT(42);
|
return MP_OBJ_NEW_SMALL_INT(42);
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause);
|
MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause);
|
||||||
|
|
||||||
STATIC void mp_machine_idle(void) {
|
STATIC void mp_machine_idle(void) {
|
||||||
k_yield();
|
k_yield();
|
||||||
|
|
|
@ -3,8 +3,6 @@
|
||||||
|
|
||||||
#include "py/obj.h"
|
#include "py/obj.h"
|
||||||
|
|
||||||
MP_DECLARE_CONST_FUN_OBJ_0(machine_info_obj);
|
|
||||||
|
|
||||||
typedef struct _machine_pin_obj_t {
|
typedef struct _machine_pin_obj_t {
|
||||||
mp_obj_base_t base;
|
mp_obj_base_t base;
|
||||||
const struct device *port;
|
const struct device *port;
|
||||||
|
|
Loading…
Reference in New Issue