124 lines
3.1 KiB
C
124 lines
3.1 KiB
C
#include "board.h"
|
|
#include "clock_config.h"
|
|
#include "peripherals.h"
|
|
#include "pin_mux.h"
|
|
|
|
/* FS */
|
|
/* clang-format off */
|
|
#include "ff.h"
|
|
#include "diskio.h"
|
|
#include "fsl_debug_console.h"
|
|
#include "fsl_sd.h"
|
|
#include "fsl_sd_disk.h"
|
|
#include "sdmmc_config.h"
|
|
/* clang-format on */
|
|
|
|
#include "FreeRTOS.h"
|
|
#include "task.h"
|
|
|
|
#include "app_flac_callbacks.h"
|
|
|
|
#define FLAC_FILE_NAME "2:/re_tryment.flac"
|
|
|
|
static FATFS s_fs;
|
|
static const TCHAR s_drive_num[] = {SDDISK + '0', ':', '/'};
|
|
|
|
static status_t sdcardWaitCardInsert(void);
|
|
static void vTaskPlayer(void *pvParameters);
|
|
|
|
int main(void) {
|
|
BOARD_InitBootPins();
|
|
BOARD_InitBootClocks();
|
|
BOARD_InitBootPeripherals();
|
|
|
|
BOARD_InitDebugConsole();
|
|
|
|
PRINTF("Hello world!!\r\n");
|
|
|
|
xTaskCreate(vTaskPlayer, "PLAYER", 4096, NULL, 4, NULL);
|
|
|
|
vTaskStartScheduler();
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void vTaskPlayer(void *pvParameters) {
|
|
if (sdcardWaitCardInsert() != kStatus_Success) {
|
|
PRINTF("Card detect failed...\r\n");
|
|
goto dead_loop;
|
|
}
|
|
|
|
PRINTF("SD inserted...\r\n");
|
|
|
|
if (f_mount(&s_fs, s_drive_num, 1U) != FR_OK) { /* Mount immediately */
|
|
PRINTF("Failed to mount filesystem...\r\n");
|
|
goto dead_loop;
|
|
}
|
|
|
|
PRINTF("FS mounted...\r\n");
|
|
|
|
app_flac_client_t client;
|
|
if (app_flac_init(&client, FLAC_FILE_NAME) < 0) {
|
|
PRINTF("Open FLAC file failed...\r\n");
|
|
goto dead_loop;
|
|
}
|
|
|
|
PRINTF("File opened...\r\n");
|
|
|
|
FLAC__StreamDecoder *decoder = FLAC__stream_decoder_new();
|
|
if (decoder == NULL) {
|
|
PRINTF("Error allocating decoder...\r\n");
|
|
}
|
|
|
|
FLAC__stream_decoder_set_md5_checking(decoder, true);
|
|
|
|
FLAC__StreamDecoderInitStatus status =
|
|
FLAC__stream_decoder_init_stream(decoder, app_flac_read, app_flac_seek, app_flac_tell, app_flac_length,
|
|
app_flac_eof, app_flac_write, app_flac_meta, app_flac_error, &client);
|
|
|
|
if (status != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
|
|
PRINTF("Stream decoder init failed: %d...\r\n", status);
|
|
goto dead_loop;
|
|
}
|
|
|
|
FLAC__bool ret = FLAC__stream_decoder_process_until_end_of_stream(decoder);
|
|
if (ret) {
|
|
PRINTF("Processed OK!\r\n");
|
|
} else {
|
|
PRINTF("Processed error: %s...\r\n", FLAC__StreamDecoderStateString[FLAC__stream_decoder_get_state(decoder)]);
|
|
}
|
|
|
|
FLAC__stream_decoder_delete(decoder);
|
|
|
|
f_close(&client.fd);
|
|
|
|
dead_loop:
|
|
for (;;) {
|
|
vTaskSuspend(NULL);
|
|
}
|
|
}
|
|
|
|
static status_t sdcardWaitCardInsert(void) {
|
|
BOARD_SD_Config(&g_sd, NULL, BOARD_SDMMC_SD_HOST_IRQ_PRIORITY, NULL);
|
|
|
|
/* SD host init function */
|
|
if (SD_HostInit(&g_sd) != kStatus_Success) {
|
|
PRINTF("\r\nSD host init fail\r\n");
|
|
return kStatus_Fail;
|
|
}
|
|
|
|
/* wait card insert */
|
|
if (SD_PollingCardInsert(&g_sd, kSD_Inserted) == kStatus_Success) {
|
|
PRINTF("\r\nCard inserted.\r\n");
|
|
/* power off card */
|
|
SD_SetCardPower(&g_sd, false);
|
|
/* power on the card */
|
|
SD_SetCardPower(&g_sd, true);
|
|
} else {
|
|
PRINTF("\r\nCard detect fail.\r\n");
|
|
return kStatus_Fail;
|
|
}
|
|
|
|
return kStatus_Success;
|
|
}
|