forked from aroyer-qc/MP3-STM32F746G-DISCO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
explorer.c
167 lines (151 loc) · 3.97 KB
/
explorer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/**
******************************************************************************
* @file explorer.c
* @author MCD Application Team
* @brief This file provides USB Key drive configuration
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private typedef -----------------------------------------------------------*/
FATFS USBH_FatFs;
char USBKey_Path[4] = "0:/";
FILELIST_FileTypeDef FileList;
uint16_t NumObs = 0;
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/**
* @brief Initializes the USB KEY Storage.
* @param None
* @retval Status
*/
uint8_t AUDIO_StorageInit(void)
{
/* Link the USB Key disk I/O driver */
if((f_mount(&USBH_FatFs, (TCHAR const*)USBKey_Path, 0) != FR_OK))
{
/* FatFs Initialization Error */
LCD_ErrLog("Cannot Initialize FatFs! \n");
return 1;
}
else
{
LCD_DbgLog ("INFO : FatFs Initialized! \n");
return 0;
}
}
/**
* @brief Copies disk content in the explorer list.
* @param None
* @retval Operation result
*/
FRESULT AUDIO_StorageParse(void)
{
FRESULT res = FR_OK;
FILINFO fno;
DIR dir;
char *fn;
#if _USE_LFN
static char lfn[_MAX_LFN];
fno.lfname = lfn;
fno.lfsize = sizeof(lfn);
#endif
res = f_opendir(&dir, USBKey_Path);
FileList.ptr = 0;
if(res == FR_OK)
{
while(USBH_MSC_IsReady(&hUSBHost))
{
res = f_readdir(&dir, &fno);
if(res != FR_OK || fno.fname[0] == 0)
{
break;
}
if(fno.fname[0] == '.')
{
continue;
}
#if _USE_LFN
fn = *fno.lfname ? fno.lfname : fno.fname;
#else
fn = fno.fname;
#endif
if(FileList.ptr < 240)
{
if((fno.fattrib & AM_DIR) == 0)
{
if((strstr(fn, "wav")) || (strstr(fn, "WAV")) || (strstr(fn, "mp3")) || (strstr(fn, "MP3")))
{
strncpy((char *)FileList.file[FileList.ptr].name, (char *)fn, FILEMGR_FILE_NAME_SIZE);
FileList.file[FileList.ptr].type = FILETYPE_FILE;
FileList.ptr++;
}
}
}
}
}
NumObs = FileList.ptr;
f_closedir(&dir);
return res;
}
/**
* @brief Shows audio file (*.wav) on the root
* @param None
* @retval None
*/
uint8_t AUDIO_ShowAudioFiles(void)
{
uint8_t i = 0;
uint8_t line_idx = 0;
if(AUDIO_StorageInit() == FR_OK)
{
if(AUDIO_StorageParse() == FR_OK)
{
if(FileList.ptr > 0)
{
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
LCD_UsrLog("audio file(s) [ROOT]:\n\n");
for(i = 0; i < FileList.ptr; i++)
{
line_idx++;
LCD_DbgLog(" |__");
LCD_DbgLog((char *)FileList.file[i].name);
LCD_DbgLog("\n");
}
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
LCD_UsrLog("\nEnd of files list.\n");
return 0;
}
return 1;
}
return 2;
}
else
{
return 3;
}
}
/**
* @brief Gets Fil Object Number.
* @param None
* @retval None
*/
uint16_t AUDIO_GetFilObjectNumber(void)
{
return NumObs;
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/