The "GR-PEACH_Audio_Playback_7InchLCD_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:   GR-PEACH_video R_BSP TLV320_RBSP USBHost_custom

Fork of GR-PEACH_Audio_Playback_Sample by Renesas

Note

For a sample program of without LCD Board, please refer to GR-PEACH_Audio_Playback_Sample.

Introduction

The "GR-PEACH_Audio_Playback_7InchLCD_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/1050186/lcd_figure1_1.png

1.2 Pin Definitions

Table 1.1 shows the pins used in this sample code.

/media/uploads/1050186/lcd_table1_1.png

2. Sample Code Operating Environment

In order to operate this sample code, GR-PEACH, Audio Camera Shield and 7.1 inch LCD Shield must be needed. For details on Audio Camera Shield and 7.1 inch LCD Shield, please refer to the following links, respectively:

In this section, it is described that how board is configured and to control audio playback via command line and touch screen.

2.1 Operating Environment

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

/media/uploads/1050186/lcd_figure2_1.png

Figure 2.2 and 2.3 show how to configure GR-PEACH, Audio Camera Shield and 7.1 inch LCD shield when using USB0 and USB1, respectively.

/media/uploads/1050186/lcd_figure2_2.png /media/uploads/1050186/lcd_figure2_3.png

Table 2.1 lists the overview of Graphical User Interface (GUI) of this sample code.

/media/uploads/1050186/lcd_table2_1.png

2.2 List of User Operations

Table 2.2 shows the relationship among Audio Playback, Command Line and Onboard Switch.

/media/uploads/1050186/lcd_table2_2.png

3. Function Outline

Table 3.1, 3.2 and 3.3 shows the overview of functions implemented in this sample code.

/media/uploads/1050186/lcd_table3_1.png /media/uploads/1050186/lcd_table3_2.png /media/uploads/1050186/lcd_table3_3.png /media/uploads/1050186/lcd_figure3_1.png

3.1 Playback Control

This sample program supports the operation "play", "pause", "stop", "play next song" and "play previous song".

3.2 Trick Play Control

In order to enable/disable Repeat Mode, user need to type "repeat" on command line or click the corresponding icon shown in Table 2.2. By derault, Repeat Mode is enabled. When Repeat Mode is enabled, the first song is played back after the playback of the last song is finished. Otherwise, the playback is shopped when finishing to play back the last song.

3.3 How to see Song Information

The information of the song being played back can be seen by typing playinfo on command line. Table 3.4 lists the items user can see on the terminal.

/media/uploads/dkato/audioplayback_table3_4.png

3.4 How to analyze the folder structure in USB stick

In this sample code, the folder structure in USB stick is analyzed in the breadth-first order. Table 3.5 shows how the files in USB stick are numbered.

/media/uploads/dkato/audioplayback_table3_5.png

4.Others

4.1 Serial Communication Setting

With respect to the default serial communication related setting on mbed, please refer to the follwing link:
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication
Please set up the terminal software you would like to use on your PC in consideration of the above. For example, 9600 should be specified for the baud rate on the terminal in order to control this sample via command line.

4.2 Necessary modification when using GCC ARM Embedded

If you would like to use GCC ARM Embedded, you must revise the following linker script incorporated in mbed OS 5 package as follows:

  • Linker Script to be modified
    $(PROJECT_ROOT)/mbed-os/targets/TARGET_RENESAS/TARGET_RZ_A1H/device/TOOLCHAIN_GCC_ARM/RZA1H.ld

    Please note that $(PROJECT_ROOT) in the above denotes the root directory of this sample code

  • Before Modification

RZA1H.ld

/* Linker script for mbed RZ_A1H */

/* Linker script to configure memory regions. */
MEMORY
{
  ROM   (rx)  : ORIGIN = 0x00000000, LENGTH = 0x02000000
  BOOT_LOADER (rx) : ORIGIN = 0x18000000, LENGTH = 0x00004000 
  SFLASH (rx) : ORIGIN = 0x18004000, LENGTH = 0x07FFC000 
  L_TTB (rw)  : ORIGIN = 0x20000000, LENGTH = 0x00004000 
  RAM (rwx) : ORIGIN = 0x20020000, LENGTH = 0x00700000
  RAM_NC (rwx) : ORIGIN = 0x20900000, LENGTH = 0x00100000
}
(snip)
  • After Modification

RZA1H.ld

/* Linker script for mbed RZ_A1H */

/* Linker script to configure memory regions. */
MEMORY
{
  ROM   (rx)  : ORIGIN = 0x00000000, LENGTH = 0x02000000
  BOOT_LOADER (rx) : ORIGIN = 0x18000000, LENGTH = 0x00004000 
  SFLASH (rx) : ORIGIN = 0x18004000, LENGTH = 0x07FFC000 
  L_TTB (rw)  : ORIGIN = 0x20000000, LENGTH = 0x00004000 
  RAM (rwx) : ORIGIN = 0x20020000, LENGTH = 0x00180000
  RAM_NC (rwx) : ORIGIN = 0x20200000, LENGTH = 0x00680000
}
(snip)
Committer:
Osamu Nakamura
Date:
Tue Apr 11 12:42:10 2017 +0900
Revision:
6:a957aaa284f0
Parent:
5:25de5b925302
Update R-BSP from rev. cbb9d60c8748 to fb9eda52224e so that this program can be compiled with IAR toolchain.

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