From a393a6e0c578231123220e73adc32b8ee58db64b Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Sun, 3 Feb 2019 13:41:20 -0800 Subject: [PATCH 1/3] Add fast seek support to file objects --- extmod/vfs_fat_file.c | 17 +++++++++++++++++ lib/oofatfs/ffconf.h | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c index 75fa2fbd49..4c38a35e54 100644 --- a/extmod/vfs_fat_file.c +++ b/extmod/vfs_fat_file.c @@ -197,6 +197,23 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar m_del_obj(pyb_file_obj_t, o); mp_raise_OSError(fresult_to_errno_table[res]); } + // If we're reading, turn on fast seek. + if (mode == FA_READ) { + // one call to determine how much space we need. + DWORD temp_table[2]; + temp_table[0] = 2; + o->fp.cltbl = temp_table; + f_lseek(&o->fp, CREATE_LINKMAP); + DWORD size = (temp_table[0] + 1) * 2; + o->fp.cltbl = m_malloc_maybe(size, false); + if (o->fp.cltbl != NULL) { + o->fp.cltbl[0] = size; + res = f_lseek(&o->fp, CREATE_LINKMAP); + if (res != FR_OK) { + o->fp.cltbl = NULL; + } + } + } // for 'a' mode, we must begin at the end of the file if ((mode & FA_OPEN_ALWAYS) != 0) { diff --git a/lib/oofatfs/ffconf.h b/lib/oofatfs/ffconf.h index 315101f0e4..214311b4c2 100644 --- a/lib/oofatfs/ffconf.h +++ b/lib/oofatfs/ffconf.h @@ -74,7 +74,7 @@ /* This option switches f_mkfs() function. (0:Disable or 1:Enable) */ -#define _USE_FASTSEEK 0 +#define _USE_FASTSEEK 1 /* This option switches fast seek function. (0:Disable or 1:Enable) */ From 90e596470336aa45a44dcbdf2ab9dfd254b9ab79 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Sun, 3 Feb 2019 13:42:03 -0800 Subject: [PATCH 2/3] Set auto brightness on by default for boards with displays built in. --- ports/atmel-samd/boards/hallowing_m0_express/board.c | 1 + ports/atmel-samd/boards/pyportal/board.c | 1 + 2 files changed, 2 insertions(+) diff --git a/ports/atmel-samd/boards/hallowing_m0_express/board.c b/ports/atmel-samd/boards/hallowing_m0_express/board.c index ab166d39be..23b1194138 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/board.c @@ -94,6 +94,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA00); + common_hal_displayio_display_set_auto_brightness(display, true); } bool board_requests_safe_mode(void) { diff --git a/ports/atmel-samd/boards/pyportal/board.c b/ports/atmel-samd/boards/pyportal/board.c index 3ef079e537..9b05063baf 100644 --- a/ports/atmel-samd/boards/pyportal/board.c +++ b/ports/atmel-samd/boards/pyportal/board.c @@ -91,6 +91,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PB31); + common_hal_displayio_display_set_auto_brightness(display, true); } bool board_requests_safe_mode(void) { From b249243a9f8d6ed246b0b873fe606066a6d712ed Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 4 Feb 2019 13:39:51 -0800 Subject: [PATCH 3/3] Fix allocation size --- extmod/vfs_fat_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c index 4c38a35e54..1b2bb27f83 100644 --- a/extmod/vfs_fat_file.c +++ b/extmod/vfs_fat_file.c @@ -205,7 +205,7 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar o->fp.cltbl = temp_table; f_lseek(&o->fp, CREATE_LINKMAP); DWORD size = (temp_table[0] + 1) * 2; - o->fp.cltbl = m_malloc_maybe(size, false); + o->fp.cltbl = m_malloc_maybe(size * sizeof(DWORD), false); if (o->fp.cltbl != NULL) { o->fp.cltbl[0] = size; res = f_lseek(&o->fp, CREATE_LINKMAP);