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:
1050186
Date:
Mon Jan 25 02:41:36 2016 +0000
Revision:
4:2672de88a46b
Parent:
0:ee40da884cfc
Child:
5:25de5b925302
Audio Playback sample program that use the LCD board

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