diff --git a/applications/nrf5340_audio/src/modules/sd_card.c b/applications/nrf5340_audio/src/modules/sd_card.c index 6989ccdd3cd..32e19d016a5 100644 --- a/applications/nrf5340_audio/src/modules/sd_card.c +++ b/applications/nrf5340_audio/src/modules/sd_card.c @@ -19,13 +19,15 @@ LOG_MODULE_REGISTER(sd_card, CONFIG_MODULE_SD_CARD_LOG_LEVEL); #define SD_ROOT_PATH "/SD:/" -#define PATH_MAX_LEN 260 /* Maximum length for path support by Windows file system*/ +/* Maximum length for path support by Windows file system */ +#define PATH_MAX_LEN 260 #define K_SEM_OPER_TIMEOUT_MS 500 +K_SEM_DEFINE(m_sem_sd_oper_ongoing, 1, 1); + static const char *sd_root_path = "/SD:"; static FATFS fat_fs; static bool sd_init_success; -K_SEM_DEFINE(m_sem_sd_oper_ongoing, 1, 1); static struct fs_mount_t mnt_pt = { .type = FS_FATFS, @@ -51,6 +53,7 @@ int sd_card_list_files(char const *const path, char *buf, size_t *buf_size) k_sem_give(&m_sem_sd_oper_ongoing); return -ENODEV; } + fs_dir_t_init(&dirp); if (path == NULL) { @@ -87,6 +90,7 @@ int sd_card_list_files(char const *const path, char *buf, size_t *buf_size) if (entry.name[0] == 0) { break; } + if (buf != NULL) { size_t remaining_buf_size = *buf_size - used_buf_size; ssize_t len = snprintk( @@ -101,6 +105,7 @@ int sd_card_list_files(char const *const path, char *buf, size_t *buf_size) used_buf_size += len; } + LOG_INF("[%s] %s", entry.type == FS_DIR_ENTRY_DIR ? "DIR " : "FILE", entry.name); } diff --git a/applications/nrf5340_audio/src/modules/sd_card.h b/applications/nrf5340_audio/src/modules/sd_card.h index 8ecabd740e8..a51bd37fcee 100644 --- a/applications/nrf5340_audio/src/modules/sd_card.h +++ b/applications/nrf5340_audio/src/modules/sd_card.h @@ -10,7 +10,8 @@ #include #include -/**@brief Print out the contents under SD card root path and write the content to buffer. +/** + * @brief Print out the contents under SD card root path and write the content to buffer. * * @param[in] path Path of the folder which is going to be listed. * If assigned path is null, then listing the contents under @@ -29,7 +30,8 @@ */ int sd_card_list_files(char const *const path, char *buf, size_t *buf_size); -/**@brief Write data from buffer into the file. +/** + * @brief Write data from buffer into the file. * * @note If the file already exists, data will be appended to the end of the file. * @@ -47,7 +49,8 @@ int sd_card_list_files(char const *const path, char *buf, size_t *buf_size); */ int sd_card_open_write_close(char const *const filename, char const *const data, size_t *size); -/**@brief Read data from file into the buffer. +/** + * @brief Read data from file into the buffer. * * @param[in] filename Name of the target file for reading, the default location is * the root directoy of SD card, accept absolute path under @@ -65,7 +68,8 @@ int sd_card_open_write_close(char const *const filename, char const *const data, */ int sd_card_open_read_close(char const *const filename, char *const buf, size_t *size); -/**@brief Open file on SD card. +/** + * @brief Open file on SD card. * * @param[in] filename Name of file to open. Default * location is the root directoy of SD card. @@ -81,7 +85,8 @@ int sd_card_open_read_close(char const *const filename, char *const buf, size_t */ int sd_card_open(char const *const filename, struct fs_file_t *f_seg_read_entry); -/**@brief Read segment on the open file on the SD card. +/** + * @brief Read segment on the open file on the SD card. * * @param[out] buf Pointer to the buffer to write the read data into. * @param[in, out] size Number of bytes to be read from file. @@ -100,7 +105,8 @@ int sd_card_open(char const *const filename, struct fs_file_t *f_seg_read_entry) */ int sd_card_read(char *buf, size_t *size, struct fs_file_t *f_seg_read_entry); -/**@brief Close the file opened by the sd_card_segment_read_open function. +/** + * @brief Close the file opened by the sd_card_segment_read_open function. * * @param[in, out] f_seg_read_entry Pointer to a file object. After call to this * function, the pointer is reset and can be used for @@ -114,7 +120,8 @@ int sd_card_read(char *buf, size_t *size, struct fs_file_t *f_seg_read_entry); */ int sd_card_close(struct fs_file_t *f_seg_read_entry); -/**@brief Initialize the SD card interface and print out SD card details. +/** + * @brief Initialize the SD card interface and print out SD card details. * * @retval 0 on success. * @retval -ENODEV SD init failed. SD card likely not inserted.