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:
dkato
Date:
Fri Oct 16 04:28:07 2015 +0000
Revision:
0:ee40da884cfc
Child:
6:df19c3e787ca
first commit

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