diff options
| author | Scott Shawcroft <scott.shawcroft@gmail.com> | 2017-06-27 15:17:30 -0700 |
|---|---|---|
| committer | Scott Shawcroft <scott.shawcroft@gmail.com> | 2017-06-27 15:17:30 -0700 |
| commit | 778e975936b9e892c4f1b85ce73462a0ce6d36d2 (patch) | |
| tree | 9e365392d9150c3c724bb1f14fa07025270dbe21 /esp8266 | |
| parent | e87a61ffb4ad089b7eb5eb4512cb57c085fd9136 (diff) | |
Split uos module into os and storage.
os is a subset of CPython's os. storage contains additional
file system mounting functionality based on UNIX's mount
management.
Fixes #140
Diffstat (limited to 'esp8266')
| -rw-r--r-- | esp8266/Makefile | 5 | ||||
| -rw-r--r-- | esp8266/common-hal/os/__init__.c (renamed from esp8266/moduos.c) | 58 | ||||
| -rw-r--r-- | esp8266/mpconfigport.h | 8 |
3 files changed, 9 insertions, 62 deletions
diff --git a/esp8266/Makefile b/esp8266/Makefile index c1ec3ca93..54c826351 100644 --- a/esp8266/Makefile +++ b/esp8266/Makefile @@ -93,8 +93,6 @@ SRC_C = \ machine_hspi.c \ modesp.c \ modnetwork.c \ - modutime.c \ - moduos.c \ modonewire.c \ ets_alt_task.c \ fatfs_port.c \ @@ -119,6 +117,7 @@ SRC_COMMON_HAL = \ busio/SPI.c \ busio/UART.c \ neopixel_write/__init__.c \ + os/__init__.c \ time/__init__.c \ board/__init__.c @@ -139,6 +138,8 @@ SRC_SHARED_MODULE = \ bitbangio/SPI.c \ busio/I2C.c \ busio/OneWire.c \ + os/__init__.c \ + storage/__init__.c \ SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \ $(addprefix shared-module/, $(SRC_SHARED_MODULE)) diff --git a/esp8266/moduos.c b/esp8266/common-hal/os/__init__.c index 807d2e18a..df241ecae 100644 --- a/esp8266/moduos.c +++ b/esp8266/common-hal/os/__init__.c @@ -4,6 +4,7 @@ * The MIT License (MIT) * * Copyright (c) 2015 Josef Gajdusek + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,11 +29,7 @@ #include "py/objtuple.h" #include "py/objstr.h" -#include "extmod/misc.h" -#include "extmod/vfs.h" -#include "extmod/vfs_fat.h" #include "genhdr/mpversion.h" -#include "esp_mphal.h" #include "user_interface.h" STATIC const qstr os_uname_info_fields[] = { @@ -57,60 +54,9 @@ STATIC mp_obj_tuple_t os_uname_info_obj = { } }; -STATIC mp_obj_t os_uname(void) { +mp_obj_t common_hal_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), false); return (mp_obj_t)&os_uname_info_obj; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname); - -STATIC mp_obj_t os_urandom(mp_obj_t num) { - mp_int_t n = mp_obj_get_int(num); - vstr_t vstr; - vstr_init_len(&vstr, n); - for (int i = 0; i < n; i++) { - vstr.buf[i] = *WDEV_HWRNG; - } - 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_obj_t os_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(&mp_uos_dupterm_obj) }, - { MP_ROM_QSTR(MP_QSTR_dupterm_notify), MP_ROM_PTR(&os_dupterm_notify_obj) }, - #endif - #if MICROPY_VFS_FAT - { MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) }, - { 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) }, - #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, -}; diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h index fec1eb0f0..066788832 100644 --- a/esp8266/mpconfigport.h +++ b/esp8266/mpconfigport.h @@ -156,7 +156,8 @@ void *esp_native_code_commit(void*, size_t); 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 os_module; +extern const struct _mp_obj_module_t storage_module; extern const struct _mp_obj_module_t mp_module_lwip; extern const struct _mp_obj_module_t mp_module_machine; extern const struct _mp_obj_module_t onewire_module; @@ -174,8 +175,7 @@ extern const struct _mp_obj_module_t time_module; { MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&mp_module_lwip }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_usocket), (mp_obj_t)&mp_module_lwip }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_network), (mp_obj_t)&network_module }, \ - { MP_OBJ_NEW_QSTR(MP_QSTR_utime), (mp_obj_t)&utime_module }, \ - { MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&uos_module }, \ + { MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&os_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&mp_module_machine }, \ { MP_OBJ_NEW_QSTR(MP_QSTR__onewire), (mp_obj_t)&onewire_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_microcontroller), (mp_obj_t)µcontroller_module }, \ @@ -185,10 +185,10 @@ extern const struct _mp_obj_module_t time_module; { MP_OBJ_NEW_QSTR(MP_QSTR_pulseio), (mp_obj_t)&pulseio_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_busio), (mp_obj_t)&busio_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_bitbangio), (mp_obj_t)&bitbangio_module }, \ + { MP_OBJ_NEW_QSTR(MP_QSTR_storage), (mp_obj_t)&storage_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module }, \ #define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \ - { MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&uos_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_json), (mp_obj_t)&mp_module_ujson }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_errno), (mp_obj_t)&mp_module_uerrno }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_select), (mp_obj_t)&mp_module_uselect }, \ |
