The "GR-PEACH_Audio_Playback_Sample" is a sample code that can provides high-resolution audio playback of FLAC format files. It also allows the user to audio-playback control functions such as play, pause, and stop by manipulating key switches.

Dependencies:   R_BSP TLV320_RBSP USBHost_custom

Note

For a sample program of with LCD Board,
please refer to GR-PEACH_Audio_Playback_7InchLCD_Sample.

Introduction

The "GR-PEACH_Audio_Playback_Sample" is a sample code that can provides high-resolution audio playback of FLAC format files. It also allows the user to audio-playback control functions such as play, pause, and stop by manipulating key switches.

1. Overview of the Sample Code

1.1 Software Block Diagram

Figure 1.1 shows the software block diagram.

/media/uploads/dkato/audioplayback_figure1_1x.png

1.2 Pin Definitions

Table 1.1 shows the pins that this sample code are to use.

/media/uploads/dkato/audioplayback_table1_1.png

2. Sample Code Operating Environment

This sample code runs in GR-PEACH + the Audio/Camera shield for the GR-PEACH environment. This section explains the functions of the ports that are used by this sample code.

2.1 Operating Environment

Figure 2.1 shows the configuration of the operating environment for running this sample code.

/media/uploads/dkato/audioplayback_figure2_1.png /media/uploads/1050186/figure2_2.png /media/uploads/dkato/audioplayback_figure2_3.png

2.2 List of User Operations

A list of user operations on the command line, TFT touch keys, and switch key that the user can perform for this sample code is shown in. Table 2.1.

/media/uploads/dkato/audioplayback_table2_1x.png

3. Function Outline

The functions of this sample code are summarized in Table 3.1 to Table 3.3.

/media/uploads/dkato/audioplayback_table3_1.png /media/uploads/dkato/audioplayback_table3_2.png /media/uploads/dkato/audioplayback_table3_3.png /media/uploads/dkato/audioplayback_figure3_1.png

3.1 Playback Control

The playback control that the sample code supports include play, pause, stop, skip to next, and skip to previous.

3.2 Trick Play Control

Manipulating "Repeat" alternates between "Repeat mode On" and "Repeat mode Off". The default mode is "Repeat mode On". When the repeat mode is on, the playback of the first song starts after the playback of the last song is finished. When the repeat mode is off, the sample code enters the stopped state after the playback of the last song is finished.

3.3 Acquisition of the Song Information

The information of the song being played is obtained by operating the "Play info" during the playback of the song. Table 3.4 lists the items of information that can be obtained by the "Play info" operation.

/media/uploads/dkato/audioplayback_table3_4.png

3.4 How the Folder Structure is Analyzed

The sample coded analyzes the folder structure in the breadth-first search order. The order in which files are numbered is illustrated in Table 3.5. The sample code does not sort the files by file or folder name.

/media/uploads/dkato/audioplayback_table3_5.png

4.Others

The default setting of serial communication (baud rate etc.) in mbed is shown the following link.
Please refer to the link and change the settings of your PC terminal software.
The default value of baud rate in mbed is 9600, and this application uses baud rate 9600.
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication

Committer:
Osamu Nakamura
Date:
Fri Mar 31 14:00:23 2017 +0900
Revision:
6:df19c3e787ca
Parent:
0:ee40da884cfc
Introduced mbedOS 5 instead of mbedOS 2 (classic)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:ee40da884cfc 1 /*******************************************************************************
dkato 0:ee40da884cfc 2 * DISCLAIMER
dkato 0:ee40da884cfc 3 * This software is supplied by Renesas Electronics Corporation and is only
dkato 0:ee40da884cfc 4 * intended for use with Renesas products. No other uses are authorized. This
dkato 0:ee40da884cfc 5 * software is owned by Renesas Electronics Corporation and is protected under
dkato 0:ee40da884cfc 6 * all applicable laws, including copyright laws.
dkato 0:ee40da884cfc 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
dkato 0:ee40da884cfc 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
dkato 0:ee40da884cfc 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
dkato 0:ee40da884cfc 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
dkato 0:ee40da884cfc 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
dkato 0:ee40da884cfc 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
dkato 0:ee40da884cfc 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
dkato 0:ee40da884cfc 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
dkato 0:ee40da884cfc 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
dkato 0:ee40da884cfc 16 * Renesas reserves the right, without notice, to make changes to this software
dkato 0:ee40da884cfc 17 * and to discontinue the availability of this software. By using this software,
dkato 0:ee40da884cfc 18 * you agree to the additional terms and conditions found by accessing the
dkato 0:ee40da884cfc 19 * following link:
dkato 0:ee40da884cfc 20 * http://www.renesas.com/disclaimer*
dkato 0:ee40da884cfc 21 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
dkato 0:ee40da884cfc 22 *******************************************************************************/
dkato 0:ee40da884cfc 23
dkato 0:ee40da884cfc 24 #include "mbed.h"
Osamu Nakamura 6:df19c3e787ca 25 #include "FATFileSystem.h"
dkato 0:ee40da884cfc 26 #include "USBHostMSD.h"
dkato 0:ee40da884cfc 27 #include "sys_scan_folder.h"
dkato 0:ee40da884cfc 28
dkato 0:ee40da884cfc 29 /*--- Macro definition of folder structure scan. ---*/
dkato 0:ee40da884cfc 30 /* The character string to identify root directory. */
dkato 0:ee40da884cfc 31 #define STR_ROOT_FOR_F_OPENDIR "" /* to use f_opendir() */
dkato 0:ee40da884cfc 32 #define STR_ROOT_FOR_FOPEN "/" SYS_USB_MOUNT_NAME /* to use fopen() */
dkato 0:ee40da884cfc 33
dkato 0:ee40da884cfc 34 /* The file extension of FLAC. */
dkato 0:ee40da884cfc 35 #define FILE_EXT_FLAC ".flac"
dkato 0:ee40da884cfc 36 #define FILE_EXT_FLA ".fla"
dkato 0:ee40da884cfc 37
dkato 0:ee40da884cfc 38 #define CHR_FULL_STOP '.' /* 0x2E: FULL STOP */
dkato 0:ee40da884cfc 39 #define CHR_SOLIDUS '/' /* 0x2F: SOLIDUS */
dkato 0:ee40da884cfc 40 #define FOLD_ID_NOT_EXIST (0xFFFFFFFFu)
dkato 0:ee40da884cfc 41 #define OPEN_MODE_READ_ONLY "r"
dkato 0:ee40da884cfc 42
dkato 0:ee40da884cfc 43 /* File path maximum size including the usb mount name size */
dkato 0:ee40da884cfc 44 #define USB_MOUNT_NAME_SIZE (sizeof(STR_ROOT_FOR_FOPEN "/"))
dkato 0:ee40da884cfc 45 #define FILE_PATH_MAX_LEN (60u)
dkato 0:ee40da884cfc 46 #define FILE_PATH_MAX_SIZE (USB_MOUNT_NAME_SIZE + FILE_PATH_MAX_LEN)
dkato 0:ee40da884cfc 47
dkato 0:ee40da884cfc 48 static const char_t *get_full_path(fid_scan_folder_t * const p_info,
dkato 0:ee40da884cfc 49 const item_t * const p_item);
dkato 0:ee40da884cfc 50 static bool open_dir(fid_scan_folder_t * const p_info,
dkato 0:ee40da884cfc 51 const item_t * const p_item, FATFS_DIR * const p_fdir);
dkato 0:ee40da884cfc 52 static bool read_dir(fid_scan_folder_t * const p_info, FATFS_DIR * const p_fdir,
dkato 0:ee40da884cfc 53 const char_t ** const p_name, bool * const p_flag_dir);
dkato 0:ee40da884cfc 54 static bool regist_item(item_t * const p_item,
dkato 0:ee40da884cfc 55 const char_t * const p_name, const uint32_t parent);
dkato 0:ee40da884cfc 56 static bool check_extension(const char_t * const p_name);
dkato 0:ee40da884cfc 57
dkato 0:ee40da884cfc 58 static bool check_folder_depth(const fid_scan_folder_t * const p_info,
dkato 0:ee40da884cfc 59 const uint32_t folder_id);
dkato 0:ee40da884cfc 60
dkato 0:ee40da884cfc 61 void fid_init(fid_scan_folder_t * const p_info)
dkato 0:ee40da884cfc 62 {
dkato 0:ee40da884cfc 63 if (p_info != NULL) {
dkato 0:ee40da884cfc 64 p_info->total_folder = 0u;
dkato 0:ee40da884cfc 65 p_info->total_track = 0u;
dkato 0:ee40da884cfc 66 }
dkato 0:ee40da884cfc 67 }
dkato 0:ee40da884cfc 68
dkato 0:ee40da884cfc 69 bool fid_scan_folder_struct(fid_scan_folder_t * const p_info)
dkato 0:ee40da884cfc 70 {
dkato 0:ee40da884cfc 71 bool ret = false;
dkato 0:ee40da884cfc 72 bool result;
dkato 0:ee40da884cfc 73 bool chk;
dkato 0:ee40da884cfc 74 uint32_t i;
dkato 0:ee40da884cfc 75 item_t *p_item;
dkato 0:ee40da884cfc 76 FATFS_DIR fdir;
dkato 0:ee40da884cfc 77 const char_t *p_name;
dkato 0:ee40da884cfc 78 bool flg_dir;
dkato 0:ee40da884cfc 79 bool chk_dep;
dkato 0:ee40da884cfc 80
dkato 0:ee40da884cfc 81 if (p_info != NULL) {
dkato 0:ee40da884cfc 82 /* Initializes the scan data. */
dkato 0:ee40da884cfc 83 p_info->total_track = 0u;
dkato 0:ee40da884cfc 84 p_info->total_folder = 0u;
dkato 0:ee40da884cfc 85
dkato 0:ee40da884cfc 86 /* Registers the identifier of the root directory to use f_opendir(). */
dkato 0:ee40da884cfc 87 (void) regist_item(&p_info->folder_list[0], STR_ROOT_FOR_F_OPENDIR, FOLD_ID_NOT_EXIST);
dkato 0:ee40da884cfc 88 p_info->total_folder++;
dkato 0:ee40da884cfc 89
dkato 0:ee40da884cfc 90 /* Checks the item in all registered directory. */
dkato 0:ee40da884cfc 91 for (i = 0; i < p_info->total_folder; i++) {
dkato 0:ee40da884cfc 92 chk_dep = check_folder_depth(p_info, i);
dkato 0:ee40da884cfc 93 result = open_dir(p_info, &p_info->folder_list[i], &fdir);
dkato 0:ee40da884cfc 94 while (result == true) {
dkato 0:ee40da884cfc 95 result = read_dir(p_info, &fdir, &p_name, &flg_dir);
dkato 0:ee40da884cfc 96 if (result == true) {
dkato 0:ee40da884cfc 97 /* Checks the attribute of this item. */
dkato 0:ee40da884cfc 98 if (flg_dir == true) {
dkato 0:ee40da884cfc 99 /* This item is directory. */
dkato 0:ee40da884cfc 100 if ((chk_dep == true) && (p_info->total_folder < SYS_MAX_FOLDER_NUM)) {
dkato 0:ee40da884cfc 101 p_item = &p_info->folder_list[p_info->total_folder];
dkato 0:ee40da884cfc 102 chk = regist_item(p_item, p_name, i);
dkato 0:ee40da884cfc 103 if (chk == true) {
dkato 0:ee40da884cfc 104 /* Register of directory item was success. */
dkato 0:ee40da884cfc 105 p_info->total_folder++;
dkato 0:ee40da884cfc 106 }
dkato 0:ee40da884cfc 107 }
dkato 0:ee40da884cfc 108 } else {
dkato 0:ee40da884cfc 109 /* This item is file. */
dkato 0:ee40da884cfc 110 chk = check_extension(p_name);
dkato 0:ee40da884cfc 111 if ((chk == true) && (p_info->total_track < SYS_MAX_TRACK_NUM)) {
dkato 0:ee40da884cfc 112 /* This item is FLAC file. */
dkato 0:ee40da884cfc 113 p_item = &p_info->track_list[p_info->total_track];
dkato 0:ee40da884cfc 114 chk = regist_item(p_item, p_name, i);
dkato 0:ee40da884cfc 115 if (chk == true) {
dkato 0:ee40da884cfc 116 /* Register of file item was success. */
dkato 0:ee40da884cfc 117 p_info->total_track++;
dkato 0:ee40da884cfc 118 }
dkato 0:ee40da884cfc 119 }
dkato 0:ee40da884cfc 120 }
dkato 0:ee40da884cfc 121 }
dkato 0:ee40da884cfc 122 }
dkato 0:ee40da884cfc 123 }
dkato 0:ee40da884cfc 124 /* Changes the identifier of the root directory to use fopen(). */
dkato 0:ee40da884cfc 125 (void) regist_item(&p_info->folder_list[0], STR_ROOT_FOR_FOPEN, FOLD_ID_NOT_EXIST);
dkato 0:ee40da884cfc 126
dkato 0:ee40da884cfc 127 if (p_info->total_track > 0u) {
dkato 0:ee40da884cfc 128 ret = true;
dkato 0:ee40da884cfc 129 }
dkato 0:ee40da884cfc 130 }
dkato 0:ee40da884cfc 131
dkato 0:ee40da884cfc 132 return ret;
dkato 0:ee40da884cfc 133 }
dkato 0:ee40da884cfc 134
dkato 0:ee40da884cfc 135 FILE *fid_open_track(fid_scan_folder_t * const p_info, const uint32_t track_id)
dkato 0:ee40da884cfc 136 {
dkato 0:ee40da884cfc 137 FILE *fp = NULL;
dkato 0:ee40da884cfc 138 const char_t *p_path;
dkato 0:ee40da884cfc 139 size_t path_len;
dkato 0:ee40da884cfc 140
dkato 0:ee40da884cfc 141 if (p_info != NULL) {
dkato 0:ee40da884cfc 142 if (track_id < p_info->total_track) {
dkato 0:ee40da884cfc 143 p_path = get_full_path(p_info, &p_info->track_list[track_id]);
dkato 0:ee40da884cfc 144 if (p_path != NULL) {
dkato 0:ee40da884cfc 145 path_len = strlen(p_path);
dkato 0:ee40da884cfc 146 /* File path maximum length is limited by the specification of "fopen". */
dkato 0:ee40da884cfc 147 if (path_len < FILE_PATH_MAX_SIZE) {
dkato 0:ee40da884cfc 148 fp = fopen(p_path, OPEN_MODE_READ_ONLY);
dkato 0:ee40da884cfc 149 }
dkato 0:ee40da884cfc 150 }
dkato 0:ee40da884cfc 151 }
dkato 0:ee40da884cfc 152 }
dkato 0:ee40da884cfc 153 return fp;
dkato 0:ee40da884cfc 154 }
dkato 0:ee40da884cfc 155
dkato 0:ee40da884cfc 156 void fid_close_track(FILE * const fp)
dkato 0:ee40da884cfc 157 {
dkato 0:ee40da884cfc 158 if (fp != NULL) {
dkato 0:ee40da884cfc 159 (void) fclose(fp);
dkato 0:ee40da884cfc 160 }
dkato 0:ee40da884cfc 161 }
dkato 0:ee40da884cfc 162
dkato 0:ee40da884cfc 163 const char_t *fid_get_track_name(const fid_scan_folder_t * const p_info,
dkato 0:ee40da884cfc 164 const uint32_t track_id)
dkato 0:ee40da884cfc 165 {
dkato 0:ee40da884cfc 166 const char_t *p_name = NULL;
dkato 0:ee40da884cfc 167
dkato 0:ee40da884cfc 168 if (p_info != NULL) {
dkato 0:ee40da884cfc 169 if (track_id < p_info->total_track) {
dkato 0:ee40da884cfc 170 p_name = &p_info->track_list[track_id].name[0];
dkato 0:ee40da884cfc 171 }
dkato 0:ee40da884cfc 172 }
dkato 0:ee40da884cfc 173 return p_name;
dkato 0:ee40da884cfc 174 }
dkato 0:ee40da884cfc 175
dkato 0:ee40da884cfc 176 uint32_t fid_get_total_track(const fid_scan_folder_t * const p_info)
dkato 0:ee40da884cfc 177 {
dkato 0:ee40da884cfc 178 uint32_t ret = 0u;
dkato 0:ee40da884cfc 179
dkato 0:ee40da884cfc 180 if (p_info != NULL) {
dkato 0:ee40da884cfc 181 ret = p_info->total_track;
dkato 0:ee40da884cfc 182 }
dkato 0:ee40da884cfc 183 return ret;
dkato 0:ee40da884cfc 184 }
dkato 0:ee40da884cfc 185
dkato 0:ee40da884cfc 186 /** Gets the full path
dkato 0:ee40da884cfc 187 *
dkato 0:ee40da884cfc 188 * @param p_info Pointer to the control data of folder scan module.
dkato 0:ee40da884cfc 189 * @param p_item Pointer to the item structure of the folder / track.
dkato 0:ee40da884cfc 190 *
dkato 0:ee40da884cfc 191 * @returns
dkato 0:ee40da884cfc 192 * Pointer to the full path.
dkato 0:ee40da884cfc 193 */
dkato 0:ee40da884cfc 194 static const char_t *get_full_path(fid_scan_folder_t * const p_info,
dkato 0:ee40da884cfc 195 const item_t * const p_item)
dkato 0:ee40da884cfc 196 {
dkato 0:ee40da884cfc 197 const char_t *p_path = NULL;
dkato 0:ee40da884cfc 198 const item_t *p;
dkato 0:ee40da884cfc 199 const item_t *item_list[SYS_MAX_FOLDER_DEPTH];
dkato 0:ee40da884cfc 200 uint32_t i;
dkato 0:ee40da884cfc 201 uint32_t item_cnt;
dkato 0:ee40da884cfc 202 uint32_t buf_cnt;
dkato 0:ee40da884cfc 203 uint32_t len;
dkato 0:ee40da884cfc 204 bool err;
dkato 0:ee40da884cfc 205
dkato 0:ee40da884cfc 206 if ((p_info != NULL) && (p_item != NULL)) {
dkato 0:ee40da884cfc 207 for (i = 0; i < SYS_MAX_FOLDER_DEPTH; i++) {
dkato 0:ee40da884cfc 208 item_list[i] = NULL;
dkato 0:ee40da884cfc 209 }
dkato 0:ee40da884cfc 210 p_info->work_buf[0] = '\0';
dkato 0:ee40da884cfc 211
dkato 0:ee40da884cfc 212 /* Stores the item name until the root folder. */
dkato 0:ee40da884cfc 213 p = p_item;
dkato 0:ee40da884cfc 214 item_cnt = 0;
dkato 0:ee40da884cfc 215 while ((item_cnt < SYS_MAX_FOLDER_DEPTH) &&
dkato 0:ee40da884cfc 216 (p->parent_number < p_info->total_folder)) {
dkato 0:ee40da884cfc 217 item_list[item_cnt] = p;
dkato 0:ee40da884cfc 218 item_cnt++;
dkato 0:ee40da884cfc 219 p = &p_info->folder_list[p->parent_number];
dkato 0:ee40da884cfc 220 }
dkato 0:ee40da884cfc 221 if (p->parent_number == FOLD_ID_NOT_EXIST) {
dkato 0:ee40da884cfc 222 buf_cnt = strlen(p->name);
dkato 0:ee40da884cfc 223 (void) strncpy(&p_info->work_buf[0], p->name, sizeof(p_info->work_buf));
dkato 0:ee40da884cfc 224 err = false;
dkato 0:ee40da884cfc 225 while ((item_cnt > 0u) && (err != true)) {
dkato 0:ee40da884cfc 226 item_cnt--;
dkato 0:ee40da884cfc 227 p = item_list[item_cnt];
dkato 0:ee40da884cfc 228 /* Concatenates SOLIDUS character to the "work_buf" variable. */
dkato 0:ee40da884cfc 229 if ((buf_cnt + 1u) < sizeof(p_info->work_buf)) {
dkato 0:ee40da884cfc 230 p_info->work_buf[buf_cnt] = CHR_SOLIDUS;
dkato 0:ee40da884cfc 231 buf_cnt++;
dkato 0:ee40da884cfc 232 } else {
dkato 0:ee40da884cfc 233 err = true;
dkato 0:ee40da884cfc 234 }
dkato 0:ee40da884cfc 235 /* Concatenates the item name to the "work_buf" variable. */
dkato 0:ee40da884cfc 236 if (p != NULL) {
dkato 0:ee40da884cfc 237 len = strlen(p->name);
dkato 0:ee40da884cfc 238 if ((buf_cnt + len) < sizeof(p_info->work_buf)) {
dkato 0:ee40da884cfc 239 (void) strncpy(&p_info->work_buf[buf_cnt], p->name, len);
dkato 0:ee40da884cfc 240 buf_cnt += len;
dkato 0:ee40da884cfc 241 } else {
dkato 0:ee40da884cfc 242 err = true;
dkato 0:ee40da884cfc 243 }
dkato 0:ee40da884cfc 244 }
dkato 0:ee40da884cfc 245 }
dkato 0:ee40da884cfc 246 if (err != true) {
dkato 0:ee40da884cfc 247 p_info->work_buf[buf_cnt] = '\0';
dkato 0:ee40da884cfc 248 p_path = &p_info->work_buf[0];
dkato 0:ee40da884cfc 249 }
dkato 0:ee40da884cfc 250 }
dkato 0:ee40da884cfc 251 }
dkato 0:ee40da884cfc 252 return p_path;
dkato 0:ee40da884cfc 253 }
dkato 0:ee40da884cfc 254
dkato 0:ee40da884cfc 255 /** Opens the directory
dkato 0:ee40da884cfc 256 *
dkato 0:ee40da884cfc 257 * @param p_info Pointer to the control data of folder scan module.
dkato 0:ee40da884cfc 258 * @param p_item Pointer to the item structure of the folder / track.
dkato 0:ee40da884cfc 259 * @param p_fdir Pointer to the structure to store the directory object.
dkato 0:ee40da884cfc 260 *
dkato 0:ee40da884cfc 261 * @returns
dkato 0:ee40da884cfc 262 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 263 */
dkato 0:ee40da884cfc 264 static bool open_dir(fid_scan_folder_t * const p_info,
dkato 0:ee40da884cfc 265 const item_t * const p_item, FATFS_DIR * const p_fdir)
dkato 0:ee40da884cfc 266 {
dkato 0:ee40da884cfc 267 bool ret = false;
dkato 0:ee40da884cfc 268 const char_t *p_path;
dkato 0:ee40da884cfc 269 FRESULT ferr;
dkato 0:ee40da884cfc 270
dkato 0:ee40da884cfc 271 if ((p_info != NULL) && (p_item != NULL) && (p_fdir != NULL)) {
dkato 0:ee40da884cfc 272 p_path = get_full_path(p_info, p_item);
dkato 0:ee40da884cfc 273 if (p_path != NULL) {
dkato 0:ee40da884cfc 274 ferr = f_opendir(p_fdir, p_path);
dkato 0:ee40da884cfc 275 if (ferr == FR_OK) {
dkato 0:ee40da884cfc 276 ret = true;
dkato 0:ee40da884cfc 277 }
dkato 0:ee40da884cfc 278 }
dkato 0:ee40da884cfc 279 }
dkato 0:ee40da884cfc 280 return ret;
dkato 0:ee40da884cfc 281 }
dkato 0:ee40da884cfc 282
dkato 0:ee40da884cfc 283 /** Reads the directory
dkato 0:ee40da884cfc 284 *
dkato 0:ee40da884cfc 285 * @param p_info Pointer to the control data of folder scan module.
dkato 0:ee40da884cfc 286 * @param p_fdir Pointer to the structure of the directory object.
dkato 0:ee40da884cfc 287 * @param p_flag_dir Pointer to the variable to store the directory flag.
dkato 0:ee40da884cfc 288 *
dkato 0:ee40da884cfc 289 * @returns
dkato 0:ee40da884cfc 290 * Pointer to the name.
dkato 0:ee40da884cfc 291 */
dkato 0:ee40da884cfc 292 static bool read_dir(fid_scan_folder_t * const p_info, FATFS_DIR * const p_fdir,
dkato 0:ee40da884cfc 293 const char_t ** const p_name, bool * const p_flag_dir)
dkato 0:ee40da884cfc 294 {
dkato 0:ee40da884cfc 295 bool ret = false;
dkato 0:ee40da884cfc 296 FRESULT ferr;
dkato 0:ee40da884cfc 297 FILINFO finfo;
dkato 0:ee40da884cfc 298
dkato 0:ee40da884cfc 299 if ((p_info != NULL) && (p_fdir != NULL) &&
dkato 0:ee40da884cfc 300 (p_name != NULL) && (p_flag_dir != NULL)) {
dkato 0:ee40da884cfc 301 /* Sets the buffer to store the long file name. */
dkato 0:ee40da884cfc 302 finfo.lfname = &p_info->work_buf[0];
dkato 0:ee40da884cfc 303 finfo.lfsize = sizeof(p_info->work_buf);
dkato 0:ee40da884cfc 304 ferr = f_readdir(p_fdir, &finfo);
dkato 0:ee40da884cfc 305 if ((ferr == FR_OK) && ((int32_t)finfo.fname[0] != '\0')) {
dkato 0:ee40da884cfc 306 if (finfo.lfname != NULL) {
dkato 0:ee40da884cfc 307 if ((int32_t)finfo.lfname[0] == '\0') {
dkato 0:ee40da884cfc 308 /* Long file name does not exist. */
dkato 0:ee40da884cfc 309 (void) strncpy(finfo.lfname, finfo.fname, finfo.lfsize);
dkato 0:ee40da884cfc 310 }
dkato 0:ee40da884cfc 311 /* Adds the NULL terminal character. */
dkato 0:ee40da884cfc 312 /* This is fail-safe processing. */
dkato 0:ee40da884cfc 313 finfo.lfname[finfo.lfsize - 1u] = '\0';
dkato 0:ee40da884cfc 314
dkato 0:ee40da884cfc 315 ret = true;
dkato 0:ee40da884cfc 316 *p_name = finfo.lfname;
dkato 0:ee40da884cfc 317 if ((finfo.fattrib & AM_DIR) != 0) {
dkato 0:ee40da884cfc 318 /* This item is directory. */
dkato 0:ee40da884cfc 319 *p_flag_dir = true;
dkato 0:ee40da884cfc 320 } else {
dkato 0:ee40da884cfc 321 /* This item is file. */
dkato 0:ee40da884cfc 322 *p_flag_dir = false;
dkato 0:ee40da884cfc 323 }
dkato 0:ee40da884cfc 324 }
dkato 0:ee40da884cfc 325 }
dkato 0:ee40da884cfc 326 }
dkato 0:ee40da884cfc 327 return ret;
dkato 0:ee40da884cfc 328 }
dkato 0:ee40da884cfc 329
dkato 0:ee40da884cfc 330 /** Registers the item of the folder / track
dkato 0:ee40da884cfc 331 *
dkato 0:ee40da884cfc 332 * @param p_item Pointer to the structure to store the item of the folder / track.
dkato 0:ee40da884cfc 333 * @param p_name Pointer to the name of the item.
dkato 0:ee40da884cfc 334 * @param parent Number of the parent folder of the item.
dkato 0:ee40da884cfc 335 *
dkato 0:ee40da884cfc 336 * @returns
dkato 0:ee40da884cfc 337 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 338 */
dkato 0:ee40da884cfc 339 static bool regist_item(item_t * const p_item,
dkato 0:ee40da884cfc 340 const char_t * const p_name, const uint32_t parent)
dkato 0:ee40da884cfc 341 {
dkato 0:ee40da884cfc 342 bool ret = false;
dkato 0:ee40da884cfc 343 uint32_t len;
dkato 0:ee40da884cfc 344
dkato 0:ee40da884cfc 345 if ((p_item != NULL) && (p_name != NULL)) {
dkato 0:ee40da884cfc 346 len = strlen(p_name);
dkato 0:ee40da884cfc 347 if ((len + 1u) < sizeof(p_item->name)) {
dkato 0:ee40da884cfc 348 (void) strncpy(p_item->name, p_name, sizeof(p_item->name));
dkato 0:ee40da884cfc 349 p_item->name[sizeof(p_item->name) - 1u] = '\0';
dkato 0:ee40da884cfc 350 p_item->parent_number = parent;
dkato 0:ee40da884cfc 351 ret = true;
dkato 0:ee40da884cfc 352 }
dkato 0:ee40da884cfc 353 }
dkato 0:ee40da884cfc 354 return ret;
dkato 0:ee40da884cfc 355 }
dkato 0:ee40da884cfc 356
dkato 0:ee40da884cfc 357 /** Checks the extension of the track name
dkato 0:ee40da884cfc 358 *
dkato 0:ee40da884cfc 359 * @param p_name Pointer to the name of the track.
dkato 0:ee40da884cfc 360 *
dkato 0:ee40da884cfc 361 * @returns
dkato 0:ee40da884cfc 362 * Results of the checking. true is FLAC file. false is other file.
dkato 0:ee40da884cfc 363 */
dkato 0:ee40da884cfc 364 static bool check_extension(const char_t * const p_name)
dkato 0:ee40da884cfc 365 {
dkato 0:ee40da884cfc 366 bool ret = false;
dkato 0:ee40da884cfc 367 const char_t *p;
dkato 0:ee40da884cfc 368
dkato 0:ee40da884cfc 369 if (p_name != NULL) {
dkato 0:ee40da884cfc 370 p = strrchr(p_name, CHR_FULL_STOP);
dkato 0:ee40da884cfc 371 if (p != NULL) {
dkato 0:ee40da884cfc 372 if (strncasecmp(p, FILE_EXT_FLAC, sizeof(FILE_EXT_FLAC)) == 0) {
dkato 0:ee40da884cfc 373 ret = true;
dkato 0:ee40da884cfc 374 } else if (strncasecmp(p, FILE_EXT_FLA, sizeof(FILE_EXT_FLA)) == 0) {
dkato 0:ee40da884cfc 375 ret = true;
dkato 0:ee40da884cfc 376 } else {
dkato 0:ee40da884cfc 377 /* DO NOTHING */
dkato 0:ee40da884cfc 378 }
dkato 0:ee40da884cfc 379 }
dkato 0:ee40da884cfc 380 }
dkato 0:ee40da884cfc 381 return ret;
dkato 0:ee40da884cfc 382 }
dkato 0:ee40da884cfc 383
dkato 0:ee40da884cfc 384 /** Checks the folder depth in the scan range
dkato 0:ee40da884cfc 385 *
dkato 0:ee40da884cfc 386 * @param p_info Pointer to the control data of folder scan module.
dkato 0:ee40da884cfc 387 * @param folder_id Folder ID [0 - (total folder - 1)]
dkato 0:ee40da884cfc 388 *
dkato 0:ee40da884cfc 389 * @returns
dkato 0:ee40da884cfc 390 * Results of the checking. true is the scan range. false is out of a scan range.
dkato 0:ee40da884cfc 391 */
dkato 0:ee40da884cfc 392 static bool check_folder_depth(const fid_scan_folder_t * const p_info,
dkato 0:ee40da884cfc 393 const uint32_t folder_id)
dkato 0:ee40da884cfc 394 {
dkato 0:ee40da884cfc 395 bool ret = false;
dkato 0:ee40da884cfc 396 uint32_t depth;
dkato 0:ee40da884cfc 397 uint32_t parent_id;
dkato 0:ee40da884cfc 398
dkato 0:ee40da884cfc 399 if (p_info != NULL) {
dkato 0:ee40da884cfc 400 /* Counts the folder depth. */
dkato 0:ee40da884cfc 401 parent_id = folder_id;
dkato 0:ee40da884cfc 402 depth = 0u;
dkato 0:ee40da884cfc 403 while ((depth < SYS_MAX_FOLDER_DEPTH) &&
dkato 0:ee40da884cfc 404 (parent_id < p_info->total_folder)) {
dkato 0:ee40da884cfc 405 depth++;
dkato 0:ee40da884cfc 406 parent_id = p_info->folder_list[parent_id].parent_number;
dkato 0:ee40da884cfc 407 }
dkato 0:ee40da884cfc 408 if (parent_id == FOLD_ID_NOT_EXIST) {
dkato 0:ee40da884cfc 409 /* Found the root folder. */
dkato 0:ee40da884cfc 410 if (depth < SYS_MAX_FOLDER_DEPTH) {
dkato 0:ee40da884cfc 411 ret = true;
dkato 0:ee40da884cfc 412 }
dkato 0:ee40da884cfc 413 }
dkato 0:ee40da884cfc 414 }
dkato 0:ee40da884cfc 415 return ret;
dkato 0:ee40da884cfc 416 }