From 5a21c30ab24b3caa1928fc35eedee94acd7d5598 Mon Sep 17 00:00:00 2001 From: Isaac Benitez Date: Sun, 18 Sep 2022 18:43:27 -0700 Subject: [PATCH 1/4] Added utime() to the os librady --- extmod/vfs_fat.c | 22 ++++++++++++++++++++++ shared-bindings/os/__init__.c | 12 ++++++++++++ shared-bindings/os/__init__.h | 1 + shared-module/os/__init__.c | 7 +++++++ 4 files changed, 42 insertions(+) diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index d19a53a9efc33..6d5bfbe205a32 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -415,6 +415,27 @@ STATIC mp_obj_t vfs_fat_umount(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_umount_obj, vfs_fat_umount); +STATIC mp_obj_t vfs_fat_utime(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t time_in) { + mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in); + const char *path = mp_obj_str_get_str(path_in); + const int time = mp_obj_get_int(time_in); + + timeutils_struct_time_t tm; + timeutils_seconds_since_epoch_to_struct_time(time, &tm); + + FILINFO fno; + fno.fdate = (WORD)(((tm.tm_year - 1980) * 512U) | tm.tm_mon * 32U | tm.tm_mday); + fno.ftime = (WORD)(tm.tm_hour * 2048U | tm.tm_min * 32U | tm.tm_sec / 2U); + + FRESULT res = f_utime(&self->fatfs, path, &fno); + if (res != FR_OK) { + mp_raise_OSError_fresult(res); + } + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_3(fat_vfs_utime_obj, vfs_fat_utime); + #if MICROPY_FATFS_USE_LABEL STATIC mp_obj_t vfs_fat_getlabel(mp_obj_t self_in) { fs_user_mount_t *self = MP_OBJ_TO_PTR(self_in); @@ -466,6 +487,7 @@ STATIC const mp_rom_map_elem_t fat_vfs_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&fat_vfs_statvfs_obj) }, { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&vfs_fat_mount_obj) }, { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&fat_vfs_umount_obj) }, + { MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&fat_vfs_utime_obj) }, #if MICROPY_FATFS_USE_LABEL { MP_ROM_QSTR(MP_QSTR_label), MP_ROM_PTR(&fat_vfs_label_obj) }, #endif diff --git a/shared-bindings/os/__init__.c b/shared-bindings/os/__init__.c index 407fa025587aa..54e33b3835ce7 100644 --- a/shared-bindings/os/__init__.c +++ b/shared-bindings/os/__init__.c @@ -247,6 +247,17 @@ STATIC mp_obj_t os_urandom(mp_obj_t size_in) { } MP_DEFINE_CONST_FUN_OBJ_1(os_urandom_obj, os_urandom); +//| def utime(path: str, time: int) -> None: +//| """Change the timestamp of a file.""" +//| ... +//| +STATIC mp_obj_t os_utime(mp_obj_t path_in, mp_obj_t time_in) { + const char *path = mp_obj_str_get_str(path_in); + common_hal_os_utime(path, time_in); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(os_utime_obj, os_utime); + STATIC const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_os) }, @@ -263,6 +274,7 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&os_stat_obj) }, { MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&os_statvfs_obj) }, { MP_ROM_QSTR(MP_QSTR_unlink), MP_ROM_PTR(&os_remove_obj) }, // unlink aliases to remove + { MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&os_utime_obj) }, { MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&os_sync_obj) }, diff --git a/shared-bindings/os/__init__.h b/shared-bindings/os/__init__.h index 5a27f309b41bf..749d74baa2338 100644 --- a/shared-bindings/os/__init__.h +++ b/shared-bindings/os/__init__.h @@ -45,6 +45,7 @@ void common_hal_os_rename(const char *old_path, const char *new_path); void common_hal_os_rmdir(const char *path); mp_obj_t common_hal_os_stat(const char *path); mp_obj_t common_hal_os_statvfs(const char *path); +void common_hal_os_utime(const char *path, mp_obj_t time); // Returns true if data was correctly sourced from a true random number generator. bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length); diff --git a/shared-module/os/__init__.c b/shared-module/os/__init__.c index 35933ebaf6fa5..e7d49c1a6bfd0 100644 --- a/shared-module/os/__init__.c +++ b/shared-module/os/__init__.c @@ -226,3 +226,10 @@ mp_obj_t common_hal_os_statvfs(const char *path) { } return mp_vfs_proxy_call(vfs, MP_QSTR_statvfs, 1, &path_out); } + +void common_hal_os_utime(const char *path, mp_obj_t time) { + mp_obj_t args[2]; + mp_vfs_mount_t *vfs = lookup_path(path, &args[0]); + args[1] = time; + mp_vfs_proxy_call(vfs, MP_QSTR_utime, 2, args); +} From 71d649613fe1915428cfa10200ea89a4501c3ae5 Mon Sep 17 00:00:00 2001 From: Isaac Benitez Date: Thu, 22 Sep 2022 00:56:44 -0700 Subject: [PATCH 2/4] Updated utime() to take a 2-tuple instead of a plain int --- extmod/vfs_fat.c | 13 +++++++++---- shared-bindings/os/__init__.c | 6 +++--- shared-bindings/os/__init__.h | 2 +- shared-module/os/__init__.c | 4 ++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index 6d5bfbe205a32..3a1bdb29c5773 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -415,18 +415,23 @@ STATIC mp_obj_t vfs_fat_umount(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_umount_obj, vfs_fat_umount); -STATIC mp_obj_t vfs_fat_utime(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t time_in) { +STATIC mp_obj_t vfs_fat_utime(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t times_in) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in); const char *path = mp_obj_str_get_str(path_in); - const int time = mp_obj_get_int(time_in); + if (!mp_obj_is_tuple_compatible(times_in)) { + mp_raise_type_arg(&mp_type_TypeError, times_in); + } + mp_obj_t *times; + mp_obj_get_array_fixed_n(times_in, 2, ×); + const int atime = mp_obj_get_int(times[0]); + const int mtime = mp_obj_get_int(times[1]); timeutils_struct_time_t tm; - timeutils_seconds_since_epoch_to_struct_time(time, &tm); + timeutils_seconds_since_epoch_to_struct_time(atime, &tm); FILINFO fno; fno.fdate = (WORD)(((tm.tm_year - 1980) * 512U) | tm.tm_mon * 32U | tm.tm_mday); fno.ftime = (WORD)(tm.tm_hour * 2048U | tm.tm_min * 32U | tm.tm_sec / 2U); - FRESULT res = f_utime(&self->fatfs, path, &fno); if (res != FR_OK) { mp_raise_OSError_fresult(res); diff --git a/shared-bindings/os/__init__.c b/shared-bindings/os/__init__.c index 54e33b3835ce7..684b0d17359ef 100644 --- a/shared-bindings/os/__init__.c +++ b/shared-bindings/os/__init__.c @@ -247,13 +247,13 @@ STATIC mp_obj_t os_urandom(mp_obj_t size_in) { } MP_DEFINE_CONST_FUN_OBJ_1(os_urandom_obj, os_urandom); -//| def utime(path: str, time: int) -> None: +//| def utime(path: str, times: Tuple[int, int]) -> None: //| """Change the timestamp of a file.""" //| ... //| -STATIC mp_obj_t os_utime(mp_obj_t path_in, mp_obj_t time_in) { +STATIC mp_obj_t os_utime(mp_obj_t path_in, mp_obj_t times_in) { const char *path = mp_obj_str_get_str(path_in); - common_hal_os_utime(path, time_in); + common_hal_os_utime(path, times_in); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(os_utime_obj, os_utime); diff --git a/shared-bindings/os/__init__.h b/shared-bindings/os/__init__.h index 749d74baa2338..00d8c28a50815 100644 --- a/shared-bindings/os/__init__.h +++ b/shared-bindings/os/__init__.h @@ -45,7 +45,7 @@ void common_hal_os_rename(const char *old_path, const char *new_path); void common_hal_os_rmdir(const char *path); mp_obj_t common_hal_os_stat(const char *path); mp_obj_t common_hal_os_statvfs(const char *path); -void common_hal_os_utime(const char *path, mp_obj_t time); +void common_hal_os_utime(const char *path, mp_obj_t times); // Returns true if data was correctly sourced from a true random number generator. bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length); diff --git a/shared-module/os/__init__.c b/shared-module/os/__init__.c index e7d49c1a6bfd0..200fcb2f611a1 100644 --- a/shared-module/os/__init__.c +++ b/shared-module/os/__init__.c @@ -227,9 +227,9 @@ mp_obj_t common_hal_os_statvfs(const char *path) { return mp_vfs_proxy_call(vfs, MP_QSTR_statvfs, 1, &path_out); } -void common_hal_os_utime(const char *path, mp_obj_t time) { +void common_hal_os_utime(const char *path, mp_obj_t times) { mp_obj_t args[2]; mp_vfs_mount_t *vfs = lookup_path(path, &args[0]); - args[1] = time; + args[1] = times; mp_vfs_proxy_call(vfs, MP_QSTR_utime, 2, args); } From 72a045e427db6cfdab1cd9f508aa00a9846fb38c Mon Sep 17 00:00:00 2001 From: Isaac Benitez Date: Thu, 22 Sep 2022 09:06:02 -0700 Subject: [PATCH 3/4] Fixed unused variable warning --- extmod/vfs_fat.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index 3a1bdb29c5773..b4f6c22506ee0 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -422,12 +422,15 @@ STATIC mp_obj_t vfs_fat_utime(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t times_ mp_raise_type_arg(&mp_type_TypeError, times_in); } - mp_obj_t *times; - mp_obj_get_array_fixed_n(times_in, 2, ×); - const int atime = mp_obj_get_int(times[0]); - const int mtime = mp_obj_get_int(times[1]); + mp_obj_t *otimes; + mp_obj_get_array_fixed_n(times_in, 2, &otimes); + + // Validate that both elements of the tuple are int and discard the second one + int time[2]; + time[0] = mp_obj_get_int(otimes[0]); + time[1] = mp_obj_get_int(otimes[1]); timeutils_struct_time_t tm; - timeutils_seconds_since_epoch_to_struct_time(atime, &tm); + timeutils_seconds_since_epoch_to_struct_time(time[0], &tm); FILINFO fno; fno.fdate = (WORD)(((tm.tm_year - 1980) * 512U) | tm.tm_mon * 32U | tm.tm_mday); From b097c0736ac36c4277cd7cebca586dd8fc725dee Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 7 Oct 2022 22:35:53 -0400 Subject: [PATCH 4/4] shrink some small builds --- ports/atmel-samd/boards/arduino_mkr1300/mpconfigboard.mk | 2 ++ ports/atmel-samd/boards/arduino_nano_33_iot/mpconfigboard.mk | 2 ++ ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk | 2 ++ ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.mk | 5 +++-- ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk | 2 ++ .../boards/sparkfun_redboard_turbo/mpconfigboard.mk | 2 ++ 6 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ports/atmel-samd/boards/arduino_mkr1300/mpconfigboard.mk b/ports/atmel-samd/boards/arduino_mkr1300/mpconfigboard.mk index 261e30d7e55e0..5d02fe3824dd2 100644 --- a/ports/atmel-samd/boards/arduino_mkr1300/mpconfigboard.mk +++ b/ports/atmel-samd/boards/arduino_mkr1300/mpconfigboard.mk @@ -11,3 +11,5 @@ CIRCUITPY_BUILD_EXTENSIONS = bin,uf2 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 + +CIRCUITPY_RAINBOWIO = 0 diff --git a/ports/atmel-samd/boards/arduino_nano_33_iot/mpconfigboard.mk b/ports/atmel-samd/boards/arduino_nano_33_iot/mpconfigboard.mk index f289aad065ca2..7ef2af6ddb218 100644 --- a/ports/atmel-samd/boards/arduino_nano_33_iot/mpconfigboard.mk +++ b/ports/atmel-samd/boards/arduino_nano_33_iot/mpconfigboard.mk @@ -11,3 +11,5 @@ CIRCUITPY_BUILD_EXTENSIONS = bin,uf2 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 + +CIRCUITPY_RAINBOWIO = 0 diff --git a/ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk b/ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk index cf64b05bcfb36..0c2df96c5dad5 100644 --- a/ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk +++ b/ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk @@ -11,3 +11,5 @@ CIRCUITPY_BUILD_EXTENSIONS = bin,uf2 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 + +CIRCUITPY_RAINBOWIO = 0 diff --git a/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.mk index a1891f972eec7..aa9055a5e39aa 100644 --- a/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.mk @@ -15,12 +15,13 @@ CIRCUITPY_FULL_BUILD = 0 # A number of modules are removed for RFM69 to make room for frozen libraries. # Many I/O functions are not available. CIRCUITPY_ANALOGIO = 1 +CIRCUITPY_BUSDEVICE = 1 +CIRCUITPY_RAINBOWIO = 0 CIRCUITPY_ROTARYIO = 0 CIRCUITPY_RTC = 0 +CIRCUITPY_TOUCHIO = 0 CIRCUITPY_USB_MIDI = 0 CIRCUITPY_USB_HID = 0 -CIRCUITPY_TOUCHIO = 0 -CIRCUITPY_BUSDEVICE = 1 # Include these Python libraries in firmware. FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_RFM69 diff --git a/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk b/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk index bcf3e132d317f..32be4805d7418 100644 --- a/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk @@ -20,11 +20,13 @@ CIRCUITPY_BITBANG_APA102 = 0 CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_I2CTARGET = 0 CIRCUITPY_NEOPIXEL_WRITE = 0 +CIRCUITPY_ONEWIREIO = 0 CIRCUITPY_PARALLELDISPLAY = 0 CIRCUITPY_PIXELBUF = 0 CIRCUITPY_PS2IO = 0 CIRCUITPY_PULSEIO = 0 CIRCUITPY_PWMIO = 0 +CIRCUITPY_RAINBOWIO = 0 CIRCUITPY_ROTARYIO = 0 CIRCUITPY_RTC = 0 CIRCUITPY_SAMD = 0 diff --git a/ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.mk b/ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.mk index 70ece9b9fcce3..ef23e56022435 100755 --- a/ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.mk +++ b/ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.mk @@ -9,3 +9,5 @@ CHIP_FAMILY = samd21 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "W25Q32FV" LONGINT_IMPL = MPZ + +CIRCUITPY_RAINBOWIO = 0 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy