From ef4d057a19f3a53008fe2025530e0a43090c1bcd Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Sun, 9 Feb 2020 19:45:47 +0000 Subject: [PATCH] nrf: uos: Add support for LFS1 and LFS2 --- ports/nrf/modules/uos/moduos.c | 13 +++++++++++-- ports/nrf/mphalport.h | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ports/nrf/modules/uos/moduos.c b/ports/nrf/modules/uos/moduos.c index 98a5661f4..cd1327a68 100644 --- a/ports/nrf/modules/uos/moduos.c +++ b/ports/nrf/modules/uos/moduos.c @@ -36,6 +36,7 @@ #include "modules/uos/microbitfs.h" #include "extmod/vfs.h" #include "extmod/vfs_fat.h" +#include "extmod/vfs_lfs.h" #include "genhdr/mpversion.h" #include "uart.h" @@ -81,7 +82,7 @@ STATIC mp_obj_t os_uname(void) { } STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname); -#if MICROPY_VFS +#if MICROPY_VFS_VFAT /// \function sync() /// Sync all filesystems. STATIC mp_obj_t os_sync(void) { @@ -151,7 +152,6 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&mp_vfs_statvfs_obj) }, { MP_ROM_QSTR(MP_QSTR_unlink), MP_ROM_PTR(&mp_vfs_remove_obj) }, // unlink aliases to remove - { MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&mod_os_sync_obj) }, #elif MICROPY_MBFS { MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&uos_mbfs_listdir_obj) }, @@ -174,7 +174,16 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { #if MICROPY_VFS { 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) }, + { MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&mod_os_sync_obj) }, +#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 }; diff --git a/ports/nrf/mphalport.h b/ports/nrf/mphalport.h index 15b37b7ef..0dfbfac84 100644 --- a/ports/nrf/mphalport.h +++ b/ports/nrf/mphalport.h @@ -46,6 +46,12 @@ extern const unsigned char mp_hal_status_to_errno_table[4]; NORETURN void mp_hal_raise(HAL_StatusTypeDef status); void mp_hal_set_interrupt_char(int c); // -1 to disable +/* This is a nasty hack to get MICROPY_VFS_LFS2 to work on a device + * without an real RTC (all nRF devices have a fixed rate "RTC" but + * it doesn't know the actual time of day). + */ +#define mp_hal_time_ns() (0) + int mp_hal_stdin_rx_chr(void); void mp_hal_stdout_tx_str(const char *str);