This is an automated email from the ASF dual-hosted git repository. jerzy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push: new 8f27a533a tinyusb/msc_fat_view: Add API to eject/insert medium 8f27a533a is described below commit 8f27a533a7e3bc9174f41ee39fd37f3a99d05c34 Author: Jerzy Kasenberg <jerzy.kasenb...@codecoup.pl> AuthorDate: Fri Mar 22 15:43:28 2024 +0100 tinyusb/msc_fat_view: Add API to eject/insert medium msc_fat_view adds some predefined entries to root directory. If application decides to add more entries after USB starts and host system already read and cached some data media eject/insert sequence can inform system that old directory structure and FAT is not valid. msc_fat_view_add_dir_entry() function will do it automatically but it is also possible to report no medium with msc_fat_view_media_eject() function msc_fat_view_media_insert() will inform host system that media is present. syscfg value MSC_FAT_VIEW_AUTO_INSERT when set to 1 will report media as present during system init. --- .../include/msc_fat_view/msc_fat_view.h | 19 ++++++++++++++ hw/usb/tinyusb/msc_fat_view/src/msc_fat_view.c | 29 +++++++++++++++++++--- hw/usb/tinyusb/msc_fat_view/syscfg.yml | 6 +++++ 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/hw/usb/tinyusb/msc_fat_view/include/msc_fat_view/msc_fat_view.h b/hw/usb/tinyusb/msc_fat_view/include/msc_fat_view/msc_fat_view.h index 61814487a..9b7f23cf3 100644 --- a/hw/usb/tinyusb/msc_fat_view/include/msc_fat_view/msc_fat_view.h +++ b/hw/usb/tinyusb/msc_fat_view/include/msc_fat_view/msc_fat_view.h @@ -48,8 +48,27 @@ typedef struct file_entry { /** * Add file handler to root folder. * + * If medium was inserted this function will first eject media + * to make system aware that disk content has changed and reload + * is needed. + * * @param file - File entry that will popup in root folder. */ void msc_fat_view_add_dir_entry(const file_entry_t *file); +/** + * Eject media + * + * This function can be called before new root dir entries are added + * in application. + * Several entries can be added without generating too many disk ejected + * notification in host system. + */ +void msc_fat_view_media_eject(void); + +/** + * Insert media after all root entries are added. + */ +void msc_fat_view_media_insert(void); + #endif /* __MSC_FAT_VIEW_H__ */ diff --git a/hw/usb/tinyusb/msc_fat_view/src/msc_fat_view.c b/hw/usb/tinyusb/msc_fat_view/src/msc_fat_view.c index 31a519a2f..6fcedbcf6 100644 --- a/hw/usb/tinyusb/msc_fat_view/src/msc_fat_view.c +++ b/hw/usb/tinyusb/msc_fat_view/src/msc_fat_view.c @@ -219,12 +219,14 @@ static uint8_t root_dir_entry_count; static scsi_cmd_type_t last_scsi_command; -static enum { +typedef enum { MEDIUM_NOT_PRESENT, REPORT_MEDIUM_CHANGE, MEDIUM_RELOAD, MEDIUM_PRESENT, -} medium_state; +} medium_state_t; + +static medium_state_t medium_state; struct unallocated_write { uint32_t first_sector; @@ -915,10 +917,17 @@ void msc_fat_view_add_dir_entry(const file_entry_t *file) { int entry_ix = root_dir_entry_count++; + medium_state_t state = medium_state; + if (state != MEDIUM_NOT_PRESENT) { + medium_state = MEDIUM_NOT_PRESENT; + } root_dir[entry_ix].file = file; root_dir[entry_ix].dir_slots = fat_dir_entry_slots(file->name); MSC_FAT_VIEW_LOG_DEBUG("Added root entry %s\n", file->name); + if (state != MEDIUM_NOT_PRESENT) { + medium_state = MEDIUM_RELOAD; + } } void @@ -1822,9 +1831,23 @@ tud_msc_scsi_cb(uint8_t lun, uint8_t const scsi_cmd[16], void *buffer, uint16_t } void -msc_fat_view_pkg_init(void) +msc_fat_view_media_eject(void) +{ + medium_state = MEDIUM_NOT_PRESENT; +} + +void +msc_fat_view_media_insert(void) { medium_state = MEDIUM_RELOAD; +} + +void +msc_fat_view_pkg_init(void) +{ + if (MYNEWT_VAL(MSC_FAT_VIEW_AUTO_INSERT)) { + msc_fat_view_media_insert(); + } init_disk_data(); } diff --git a/hw/usb/tinyusb/msc_fat_view/syscfg.yml b/hw/usb/tinyusb/msc_fat_view/syscfg.yml index de6d17751..34f0cb665 100644 --- a/hw/usb/tinyusb/msc_fat_view/syscfg.yml +++ b/hw/usb/tinyusb/msc_fat_view/syscfg.yml @@ -103,6 +103,12 @@ syscfg.defs: Normally this if folder (not file) generated by Windows. If this file is present Windows will not create folder saving time for writes. value: 0 + MSC_FAT_VIEW_AUTO_INSERT: + description: > + If set to 1, media is reported as present during system init. + If set to 0, msc_fat_view_insert_media() function needs to be called after + all root entries are added. + value: 1 MSC_FAT_VIEW_LOG_MOD: description: 'Numeric module ID to use for MSC FAT view log messages.'