extmod/modmachine: Factor ports' machine module dict to common code.
This is a code factoring to have the dict for the machine module in one location, and all the ports use that same dict. The machine.soft_reset() function implementation is also factored because it's the same for all ports that did already implement it. Eventually more functions/bindings can be factored. All ports remain functionally the same, except: - cc3200 port: gains soft_reset, mem8, mem16, mem32, Signal; loses POWER_ON (which was a legacy constant, replaced long ago by PWRON_RESET) - nrf port: gains Signal - qemu-arm port: gains soft_reset - unix port: gains soft_reset - zephyr port: gains soft_reset, mem8, mem16, mem32 Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -41,7 +41,6 @@ set(MICROPY_SOURCE_PORT
|
||||
machine_spi.c
|
||||
machine_pin.c
|
||||
modbluetooth_zephyr.c
|
||||
modmachine.c
|
||||
modsocket.c
|
||||
modzephyr.c
|
||||
modzsensor.c
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013-2015 Damien P. George
|
||||
* Copyright (c) 2013-2023 Damien P. George
|
||||
* Copyright (c) 2016 Paul Sokolovsky
|
||||
* Copyright (c) 2016 Linaro Limited
|
||||
*
|
||||
@@ -26,16 +26,25 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
// This file is never compiled standalone, it's included directly from
|
||||
// extmod/modmachine.c via MICROPY_PY_MACHINE_INCLUDEFILE.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <zephyr/sys/reboot.h>
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
#include "extmod/modmachine.h"
|
||||
#include "modmachine.h"
|
||||
|
||||
#if MICROPY_PY_MACHINE
|
||||
#ifdef CONFIG_REBOOT
|
||||
#define MICROPY_PY_MACHINE_RESET_ENTRY { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) },
|
||||
#else
|
||||
#define MICROPY_PY_MACHINE_RESET_ENTRY
|
||||
#endif
|
||||
|
||||
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
||||
MICROPY_PY_MACHINE_RESET_ENTRY \
|
||||
{ MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_idle), MP_ROM_PTR(&machine_idle_obj) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) }, \
|
||||
|
||||
STATIC mp_obj_t machine_reset(void) {
|
||||
sys_reboot(SYS_REBOOT_COLD);
|
||||
@@ -55,38 +64,3 @@ STATIC mp_obj_t machine_idle(void) {
|
||||
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) },
|
||||
#ifdef CONFIG_REBOOT
|
||||
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) },
|
||||
#endif
|
||||
{ MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_idle), MP_ROM_PTR(&machine_idle_obj) },
|
||||
|
||||
#if MICROPY_PY_MACHINE_I2C
|
||||
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&machine_i2c_type) },
|
||||
#endif
|
||||
#if MICROPY_PY_MACHINE_SPI
|
||||
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&machine_spi_type) },
|
||||
#endif
|
||||
#if MICROPY_PY_MACHINE_UART
|
||||
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&machine_uart_type) },
|
||||
#endif
|
||||
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_Signal), MP_ROM_PTR(&machine_signal_type) },
|
||||
|
||||
// reset causes
|
||||
/*{ MP_ROM_QSTR(MP_QSTR_PWRON_RESET), MP_ROM_INT(REASON_DEFAULT_RST) },*/
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table);
|
||||
|
||||
const mp_obj_module_t mp_module_machine = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t *)&machine_module_globals,
|
||||
};
|
||||
|
||||
MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine);
|
||||
|
||||
#endif // MICROPY_PY_MACHINE
|
||||
|
||||
@@ -64,6 +64,7 @@
|
||||
#define MICROPY_PY_IO (0)
|
||||
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
|
||||
#define MICROPY_PY_MACHINE (1)
|
||||
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/zephyr/modmachine.c"
|
||||
#define MICROPY_PY_MACHINE_I2C (1)
|
||||
#define MICROPY_PY_MACHINE_SPI (1)
|
||||
#define MICROPY_PY_MACHINE_SPI_MSB (SPI_TRANSFER_MSB)
|
||||
|
||||
Reference in New Issue
Block a user