esp8266/moduos: Convert module to use extmod version.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
11b77263ef
commit
ade2720e55
|
@ -55,6 +55,13 @@
|
|||
#endif
|
||||
|
||||
#if MICROPY_PY_UOS_UNAME
|
||||
|
||||
#if MICROPY_PY_UOS_UNAME_RELEASE_DYNAMIC
|
||||
#define CONST_RELEASE
|
||||
#else
|
||||
#define CONST_RELEASE const
|
||||
#endif
|
||||
|
||||
STATIC const qstr mp_uos_uname_info_fields[] = {
|
||||
MP_QSTR_sysname,
|
||||
MP_QSTR_nodename,
|
||||
|
@ -64,7 +71,7 @@ STATIC const qstr mp_uos_uname_info_fields[] = {
|
|||
};
|
||||
STATIC const MP_DEFINE_STR_OBJ(mp_uos_uname_info_sysname_obj, MICROPY_PY_SYS_PLATFORM);
|
||||
STATIC const MP_DEFINE_STR_OBJ(mp_uos_uname_info_nodename_obj, MICROPY_PY_SYS_PLATFORM);
|
||||
STATIC const MP_DEFINE_STR_OBJ(mp_uos_uname_info_release_obj, MICROPY_VERSION_STRING);
|
||||
STATIC CONST_RELEASE MP_DEFINE_STR_OBJ(mp_uos_uname_info_release_obj, MICROPY_VERSION_STRING);
|
||||
STATIC const MP_DEFINE_STR_OBJ(mp_uos_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE MICROPY_BUILD_TYPE_PAREN);
|
||||
STATIC const MP_DEFINE_STR_OBJ(mp_uos_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME);
|
||||
|
||||
|
@ -80,9 +87,15 @@ STATIC MP_DEFINE_ATTRTUPLE(
|
|||
);
|
||||
|
||||
STATIC mp_obj_t mp_uos_uname(void) {
|
||||
#if MICROPY_PY_UOS_UNAME_RELEASE_DYNAMIC
|
||||
const char *release = mp_uos_uname_release();
|
||||
mp_uos_uname_info_release_obj.len = strlen(release);
|
||||
mp_uos_uname_info_release_obj.data = (const byte *)release;
|
||||
#endif
|
||||
return MP_OBJ_FROM_PTR(&mp_uos_uname_info_obj);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_uos_uname_obj, mp_uos_uname);
|
||||
|
||||
#endif
|
||||
|
||||
STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
|
||||
|
|
|
@ -102,7 +102,6 @@ SRC_C = \
|
|||
modesp.c \
|
||||
modnetwork.c \
|
||||
modutime.c \
|
||||
moduos.c \
|
||||
ets_alt_task.c \
|
||||
fatfs_port.c \
|
||||
posix_helpers.c \
|
||||
|
|
|
@ -69,8 +69,7 @@ STATIC void mp_reset(void) {
|
|||
args[1] = MP_OBJ_NEW_SMALL_INT(115200);
|
||||
args[0] = pyb_uart_type.make_new(&pyb_uart_type, 2, 0, args);
|
||||
args[1] = MP_OBJ_NEW_SMALL_INT(1);
|
||||
extern mp_obj_t os_dupterm(size_t n_args, const mp_obj_t *args);
|
||||
os_dupterm(2, args);
|
||||
mp_uos_dupterm_obj.fun.var(2, args);
|
||||
}
|
||||
|
||||
#if MICROPY_MODULE_FROZEN
|
||||
|
|
|
@ -37,37 +37,11 @@
|
|||
#include "esp_mphal.h"
|
||||
#include "user_interface.h"
|
||||
|
||||
STATIC const qstr os_uname_info_fields[] = {
|
||||
MP_QSTR_sysname, MP_QSTR_nodename,
|
||||
MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine
|
||||
};
|
||||
STATIC const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_PY_SYS_PLATFORM);
|
||||
STATIC const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_PY_SYS_PLATFORM);
|
||||
STATIC const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE);
|
||||
STATIC const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME);
|
||||
|
||||
STATIC mp_obj_tuple_t os_uname_info_obj = {
|
||||
.base = {&mp_type_attrtuple},
|
||||
.len = 5,
|
||||
.items = {
|
||||
(mp_obj_t)&os_uname_info_sysname_obj,
|
||||
(mp_obj_t)&os_uname_info_nodename_obj,
|
||||
NULL,
|
||||
(mp_obj_t)&os_uname_info_version_obj,
|
||||
(mp_obj_t)&os_uname_info_machine_obj,
|
||||
(void *)os_uname_info_fields,
|
||||
}
|
||||
};
|
||||
|
||||
STATIC mp_obj_t os_uname(void) {
|
||||
// We must populate the "release" field each time in case it was GC'd since the last call.
|
||||
const char *ver = system_get_sdk_version();
|
||||
os_uname_info_obj.items[2] = mp_obj_new_str(ver, strlen(ver));
|
||||
return (mp_obj_t)&os_uname_info_obj;
|
||||
STATIC const char *mp_uos_uname_release(void) {
|
||||
return system_get_sdk_version();
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname);
|
||||
|
||||
STATIC mp_obj_t os_urandom(mp_obj_t num) {
|
||||
STATIC mp_obj_t mp_uos_urandom(mp_obj_t num) {
|
||||
mp_int_t n = mp_obj_get_int(num);
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, n);
|
||||
|
@ -76,64 +50,20 @@ STATIC mp_obj_t os_urandom(mp_obj_t num) {
|
|||
}
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_urandom_obj, os_urandom);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_uos_urandom_obj, mp_uos_urandom);
|
||||
|
||||
// We wrap the mp_uos_dupterm function to detect if a UART is attached or not
|
||||
mp_obj_t os_dupterm(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_t prev_obj = mp_uos_dupterm_obj.fun.var(n_args, args);
|
||||
if (mp_obj_get_type(args[0]) == &pyb_uart_type) {
|
||||
void mp_uos_dupterm_stream_detached_attached(mp_obj_t stream_detached, mp_obj_t stream_attached) {
|
||||
if (mp_obj_get_type(stream_attached) == &pyb_uart_type) {
|
||||
++uart_attached_to_dupterm;
|
||||
}
|
||||
if (mp_obj_get_type(prev_obj) == &pyb_uart_type) {
|
||||
if (mp_obj_get_type(stream_detached) == &pyb_uart_type) {
|
||||
--uart_attached_to_dupterm;
|
||||
}
|
||||
return prev_obj;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(os_dupterm_obj, 1, 2, os_dupterm);
|
||||
|
||||
STATIC mp_obj_t os_dupterm_notify(mp_obj_t obj_in) {
|
||||
STATIC mp_obj_t mp_uos_dupterm_notify(mp_obj_t obj_in) {
|
||||
(void)obj_in;
|
||||
mp_hal_signal_dupterm_input();
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_dupterm_notify_obj, os_dupterm_notify);
|
||||
|
||||
STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uos) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_uname), MP_ROM_PTR(&os_uname_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_urandom), MP_ROM_PTR(&os_urandom_obj) },
|
||||
#if MICROPY_PY_OS_DUPTERM
|
||||
{ MP_ROM_QSTR(MP_QSTR_dupterm), MP_ROM_PTR(&os_dupterm_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_dupterm_notify), MP_ROM_PTR(&os_dupterm_notify_obj) },
|
||||
#endif
|
||||
#if MICROPY_VFS
|
||||
{ MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&mp_vfs_ilistdir_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&mp_vfs_listdir_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&mp_vfs_mkdir_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_rmdir), MP_ROM_PTR(&mp_vfs_rmdir_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_chdir), MP_ROM_PTR(&mp_vfs_chdir_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_getcwd), MP_ROM_PTR(&mp_vfs_getcwd_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&mp_vfs_remove_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&mp_vfs_rename_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&mp_vfs_stat_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&mp_vfs_statvfs_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&mp_vfs_umount_obj) },
|
||||
#if MICROPY_VFS_FAT
|
||||
{ MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) },
|
||||
#endif
|
||||
#if MICROPY_VFS_LFS1
|
||||
{ MP_ROM_QSTR(MP_QSTR_VfsLfs1), MP_ROM_PTR(&mp_type_vfs_lfs1) },
|
||||
#endif
|
||||
#if MICROPY_VFS_LFS2
|
||||
{ MP_ROM_QSTR(MP_QSTR_VfsLfs2), MP_ROM_PTR(&mp_type_vfs_lfs2) },
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table);
|
||||
|
||||
const mp_obj_module_t uos_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t *)&os_module_globals,
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_uos_dupterm_notify_obj, mp_uos_dupterm_notify);
|
||||
|
|
|
@ -95,7 +95,14 @@
|
|||
#define MICROPY_PY_WEBREPL_DELAY (20)
|
||||
#define MICROPY_PY_WEBREPL_STATIC_FILEBUF (1)
|
||||
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
|
||||
#define MICROPY_PY_UOS (1)
|
||||
#define MICROPY_PY_UOS_INCLUDEFILE "ports/esp8266/moduos.c"
|
||||
#define MICROPY_PY_OS_DUPTERM (2)
|
||||
#define MICROPY_PY_UOS_DUPTERM_NOTIFY (1)
|
||||
#define MICROPY_PY_UOS_DUPTERM_STREAM_DETACHED_ATTACHED (1)
|
||||
#define MICROPY_PY_UOS_UNAME (1)
|
||||
#define MICROPY_PY_UOS_UNAME_RELEASE_DYNAMIC (1)
|
||||
#define MICROPY_PY_UOS_URANDOM (1)
|
||||
#define MICROPY_CPYTHON_COMPAT (1)
|
||||
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
|
||||
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
|
||||
|
@ -172,7 +179,6 @@ extern const struct _mp_print_t mp_debug_print;
|
|||
extern const struct _mp_obj_module_t esp_module;
|
||||
extern const struct _mp_obj_module_t network_module;
|
||||
extern const struct _mp_obj_module_t utime_module;
|
||||
extern const struct _mp_obj_module_t uos_module;
|
||||
extern const struct _mp_obj_module_t mp_module_lwip;
|
||||
extern const struct _mp_obj_module_t mp_module_onewire;
|
||||
|
||||
|
@ -181,7 +187,6 @@ extern const struct _mp_obj_module_t mp_module_onewire;
|
|||
{ MP_ROM_QSTR(MP_QSTR_usocket), MP_ROM_PTR(&mp_module_lwip) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_network), MP_ROM_PTR(&network_module) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&utime_module) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&uos_module) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR__onewire), MP_ROM_PTR(&mp_module_onewire) }, \
|
||||
|
||||
#define MP_STATE_PORT MP_STATE_VM
|
||||
|
|
Loading…
Reference in New Issue