mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-08 14:43:04 +08:00
split player code to player_background and player_ui; add play list code; add wm8978 driver for codec v2 board; add sdcard waiting check.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@187 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
1 parent
6a0d160604
commit
367b13bcbe
17 files changed
+1772
-1222
No files matched your search
@@ -42,6 +42,10 @@
|
||||
// <i>Default: 1
|
||||
#define STM32_CONSOLE_USART 1
|
||||
|
||||
// <o> Codec Version <1=>Version 1 <2=>Version 2
|
||||
// <i>Default: 1
|
||||
#define CODEC_VERSION 1
|
||||
|
||||
void rt_hw_board_led_on(int n);
|
||||
void rt_hw_board_led_off(int n);
|
||||
void rt_hw_board_init(void);
|
||||
|
||||
@@ -224,9 +224,9 @@ static void _filelist_view_constructor(struct filelist_view *view)
|
||||
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(view)) = RTGUI_ALIGN_CENTER_VERTICAL;
|
||||
|
||||
file_image = rtgui_image_create_from_mem("xpm",
|
||||
(rt_uint8_t*)file_xpm, sizeof(file_xpm));
|
||||
(rt_uint8_t*)file_xpm, sizeof(file_xpm), RT_TRUE);
|
||||
folder_image = rtgui_image_create_from_mem("xpm",
|
||||
(rt_uint8_t*)folder_xpm, sizeof(folder_xpm));
|
||||
(rt_uint8_t*)folder_xpm, sizeof(folder_xpm), RT_TRUE);
|
||||
}
|
||||
|
||||
rtgui_type_t *filelist_view_type_get(void)
|
||||
|
||||
@@ -36,7 +36,7 @@ static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_ev
|
||||
|
||||
rtt_image = RT_NULL;
|
||||
}
|
||||
|
||||
|
||||
if (network_image != RT_NULL)
|
||||
{
|
||||
rect.x1 = rect.x2 - (network_image->w + 2);
|
||||
@@ -61,7 +61,7 @@ static void info_entry(void* parameter)
|
||||
rtgui_thread_register(rt_thread_self(), mq);
|
||||
|
||||
network_image = rtgui_image_create_from_mem("xpm",
|
||||
(rt_uint8_t*)network_xpm, sizeof(network_xpm));
|
||||
(rt_uint8_t*)network_xpm, sizeof(network_xpm), RT_TRUE);
|
||||
workbench = rtgui_workbench_create("info", "workbench");
|
||||
if (workbench == RT_NULL) return;
|
||||
|
||||
|
||||
+123
-21
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,101 @@
|
||||
#include "play_list.h"
|
||||
#include "player_ui.h"
|
||||
#include <string.h>
|
||||
|
||||
static struct play_item **play_list = RT_NULL;
|
||||
static rt_uint16_t play_list_size = 0;
|
||||
static rt_int16_t play_list_current = 0;
|
||||
|
||||
void play_list_clear()
|
||||
{
|
||||
rt_uint32_t index;
|
||||
|
||||
for (index = 0; index < play_list_size; index ++)
|
||||
{
|
||||
rt_free(play_list[index]->fn);
|
||||
rt_free(play_list[index]);
|
||||
|
||||
play_list[index] = RT_NULL;
|
||||
}
|
||||
|
||||
rt_free(play_list);
|
||||
play_list = RT_NULL;
|
||||
play_list_size = 0;
|
||||
}
|
||||
|
||||
char* play_list_start()
|
||||
{
|
||||
play_list_current = 0;
|
||||
return play_list[play_list_current]->fn;
|
||||
}
|
||||
|
||||
rt_bool_t play_list_is_end()
|
||||
{
|
||||
if ((play_list_current == play_list_size - 1) ||
|
||||
play_list_size == 0)
|
||||
return RT_TRUE;
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
rt_uint32_t play_list_items(void)
|
||||
{
|
||||
return play_list_size;
|
||||
}
|
||||
|
||||
struct play_item* play_list_item(rt_uint32_t n)
|
||||
{
|
||||
if (n > play_list_size) return RT_NULL;
|
||||
return play_list[n];
|
||||
}
|
||||
|
||||
void play_list_append(char* fn)
|
||||
{
|
||||
play_list_size ++;
|
||||
if (play_list == RT_NULL)
|
||||
play_list = (struct play_item**) rt_malloc (play_list_size * sizeof(struct play_item*));
|
||||
else
|
||||
play_list = (struct play_item**) rt_realloc(play_list, play_list_size * sizeof(struct play_item*));
|
||||
|
||||
play_list[play_list_size - 1] = (struct play_item*)rt_malloc(sizeof(struct play_item));
|
||||
if (strstr(fn, ".mp3") != RT_NULL ||
|
||||
strstr(fn, ".MP3") != RT_NULL)
|
||||
{
|
||||
struct tag_info info;
|
||||
|
||||
memset(&info, 0, sizeof(info));
|
||||
mp3_get_info(fn, &info);
|
||||
if (info.title[0] == '\0')
|
||||
rt_snprintf(play_list[play_list_size - 1]->title, sizeof(play_list[play_list_size - 1]->title),
|
||||
"<δ֪ÃûÒôÀÖ>");
|
||||
else
|
||||
strcpy(play_list[play_list_size - 1]->title, info.title);
|
||||
|
||||
play_list[play_list_size - 1]->fn = rt_strdup(fn);
|
||||
play_list[play_list_size - 1]->duration = info.duration;
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_snprintf(play_list[play_list_size - 1]->title, sizeof(play_list[play_list_size - 1]->title),
|
||||
"<δ֪ÃûÒôÀÖ>");
|
||||
play_list[play_list_size - 1]->fn = rt_strdup(fn);
|
||||
play_list[play_list_size - 1]->duration = 0;
|
||||
}
|
||||
}
|
||||
|
||||
char* play_list_next()
|
||||
{
|
||||
if (play_list_current < play_list_size - 1) play_list_current ++;
|
||||
return play_list[play_list_current]->fn;
|
||||
}
|
||||
|
||||
char* play_list_prev()
|
||||
{
|
||||
if (play_list_current > 0) play_list_current --;
|
||||
return play_list[play_list_current]->fn;
|
||||
}
|
||||
|
||||
char* play_list_current_item()
|
||||
{
|
||||
return play_list[play_list_current]->fn;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef __PLAY_LIST_H__
|
||||
#define __PLAY_LIST_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
struct play_item
|
||||
{
|
||||
char title[40];
|
||||
char *fn;
|
||||
rt_uint32_t duration;
|
||||
};
|
||||
|
||||
void play_list_clear(void);
|
||||
|
||||
char* play_list_start(void);
|
||||
rt_bool_t play_list_is_end(void);
|
||||
rt_uint32_t play_list_items(void);
|
||||
struct play_item* play_list_item(rt_uint32_t n);
|
||||
|
||||
void play_list_append(char* fn);
|
||||
char* play_list_next(void);
|
||||
char* play_list_prev(void);
|
||||
char* play_list_current_item(void);
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,83 @@
|
||||
#include "player_bg.h"
|
||||
#include "player_ui.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static rt_mq_t player_thread_mq;
|
||||
rt_bool_t is_playing = RT_FALSE;
|
||||
|
||||
rt_bool_t player_is_playing()
|
||||
{
|
||||
return is_playing;
|
||||
}
|
||||
|
||||
void player_play_file(const char* fn)
|
||||
{
|
||||
struct player_request request;
|
||||
request.type = PLAYER_REQUEST_PLAY_SINGLE_FILE;
|
||||
strncpy(request.fn, fn, sizeof(request.fn));
|
||||
|
||||
/* send to message queue */
|
||||
rt_mq_send(player_thread_mq, (void*)&request, sizeof(struct player_request));
|
||||
}
|
||||
|
||||
void player_stop()
|
||||
{
|
||||
is_playing = RT_FALSE;
|
||||
}
|
||||
|
||||
void player_thread(void* parameter)
|
||||
{
|
||||
rt_err_t result;
|
||||
struct player_request request;
|
||||
|
||||
while(1)
|
||||
{
|
||||
/* get request from message queue */
|
||||
result = rt_mq_recv(player_thread_mq, (void*)&request,
|
||||
sizeof(struct player_request), RT_WAITING_FOREVER);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
switch (request.type)
|
||||
{
|
||||
case PLAYER_REQUEST_PLAY_SINGLE_FILE:
|
||||
if ((strstr(request.fn, ".mp3") != RT_NULL) ||
|
||||
(strstr(request.fn, ".MP3") != RT_NULL))
|
||||
{
|
||||
is_playing = RT_TRUE;
|
||||
player_notify_play();
|
||||
|
||||
/* get music tag information */
|
||||
mp3(request.fn);
|
||||
|
||||
player_notify_stop();
|
||||
is_playing = RT_FALSE;
|
||||
}
|
||||
else if ((strstr(request.fn, ".wav") != RT_NULL) ||
|
||||
(strstr(request.fn, ".WAV") != RT_NULL))
|
||||
{
|
||||
is_playing = RT_TRUE;
|
||||
wav(request.fn);
|
||||
is_playing = RT_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void player_init()
|
||||
{
|
||||
rt_thread_t tid;
|
||||
|
||||
/* create player thread */
|
||||
player_thread_mq = rt_mq_create("player", sizeof(struct player_request),
|
||||
8, RT_IPC_FLAG_FIFO);
|
||||
RT_ASSERT(player_thread_mq != RT_NULL);
|
||||
|
||||
tid = rt_thread_create("ply_bg", player_thread, RT_NULL,
|
||||
2048, 20, 5);
|
||||
if (tid != RT_NULL) rt_thread_startup(tid);
|
||||
|
||||
player_ui_init();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef __PLAYER_BG_H__
|
||||
#define __PLAYER_BG_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
enum PLAYER_REQUEST_TYPE
|
||||
{
|
||||
PLAYER_REQUEST_PLAY_SINGLE_FILE,
|
||||
PLAYER_REQUEST_PLAY_LIST,
|
||||
PLAYER_REQUEST_STOP,
|
||||
PLAYER_REQUEST_NEXT,
|
||||
PLAYER_REQUEST_PREV,
|
||||
};
|
||||
|
||||
struct player_request
|
||||
{
|
||||
enum PLAYER_REQUEST_TYPE type;
|
||||
|
||||
char fn[64];
|
||||
};
|
||||
|
||||
rt_bool_t player_is_playing(void);
|
||||
void player_stop(void);
|
||||
|
||||
void player_play_list(const char** list);
|
||||
void player_play_file(const char* fn);
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,47 @@
|
||||
#ifndef __PLAYER_H__
|
||||
#define __PLAYER_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
/* music tag information structure */
|
||||
struct tag_info
|
||||
{
|
||||
char title [40]; /* music title */
|
||||
char artist[40]; /* music artist */
|
||||
|
||||
rt_uint32_t duration; /* music total duration (second) */
|
||||
rt_uint32_t position; /* music current position (second) */
|
||||
|
||||
rt_uint32_t bit_rate; /* bit rate */
|
||||
rt_uint32_t sampling; /* sampling */
|
||||
rt_uint32_t data_start; /* start position of data */
|
||||
};
|
||||
|
||||
enum PLAYER_CMD
|
||||
{
|
||||
PLAYER_CMD_START,
|
||||
PLAYER_CMD_STOP
|
||||
};
|
||||
|
||||
enum PLAYER_MODE
|
||||
{
|
||||
PLAYER_STOP,
|
||||
PLAYER_PLAY_FILE,
|
||||
PLAYER_PLAY_RADIO,
|
||||
};
|
||||
|
||||
enum PLAYER_STEP
|
||||
{
|
||||
PLAYER_STEP_STOP,
|
||||
PLAYER_STEP_PREV,
|
||||
PLAYER_STEP_NEXT,
|
||||
};
|
||||
|
||||
void player_ui_init(void);
|
||||
|
||||
void player_notify_play(void);
|
||||
void player_notify_stop(void);
|
||||
|
||||
void player_set_position(rt_uint32_t position);
|
||||
|
||||
#endif
|
||||
+193
-189
File diff suppressed because it is too large.
Load diff
@@ -24,7 +24,6 @@ File 1,1,<.\stm32f10x_it.c><stm32f10x_it.c>
|
||||
File 1,1,<.\usart.c><usart.c>
|
||||
File 1,1,<.\sdcard.c><sdcard.c>
|
||||
File 1,1,<.\rtc.c><rtc.c>
|
||||
File 1,1,<.\wm8753.c><wm8753.c>
|
||||
File 1,1,<.\dm9000.c><dm9000.c>
|
||||
File 1,1,<.\fsmc_nand.c><fsmc_nand.c>
|
||||
File 1,1,<.\fsmc_sram.c><fsmc_sram.c>
|
||||
@@ -36,10 +35,14 @@ File 1,1,<.\wav.c><wav.c>
|
||||
File 1,1,<.\netbuffer.c><netbuffer.c>
|
||||
File 1,1,<.\key.c><key.c>
|
||||
File 1,1,<.\info.c><info.c>
|
||||
File 1,1,<.\player.c><player.c>
|
||||
File 1,1,<.\filelist.c><filelist.c>
|
||||
File 1,1,<.\device_info.c><device_info.c>
|
||||
File 1,1,<.\listview.c><listview.c>
|
||||
File 1,1,<.\wm8753.c><wm8753.c>
|
||||
File 1,1,<.\player_ui.c><player_ui.c>
|
||||
File 1,1,<.\player_bg.c><player_bg.c>
|
||||
File 1,1,<.\wm8978.c><wm8978.c>
|
||||
File 1,1,<.\play_list.c><play_list.c>
|
||||
File 2,1,<..\..\src\clock.c><clock.c>
|
||||
File 2,1,<..\..\src\idle.c><idle.c>
|
||||
File 2,1,<..\..\src\ipc.c><ipc.c>
|
||||
|
||||
+30
-10
@@ -21,7 +21,9 @@
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "sdcard.h"
|
||||
#include <stm32f10x_dma.h>
|
||||
#include <stm32f10x_sdio.h>
|
||||
#include <stm32f10x_sdio.h>
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
/** @addtogroup STM32F10x_StdPeriph_Examples
|
||||
* @{
|
||||
@@ -955,12 +957,30 @@ SD_Error SD_ReadBlock(uint32_t addr, uint32_t *readbuff, uint16_t BlockSize)
|
||||
}
|
||||
}
|
||||
else if (DeviceMode == SD_DMA_MODE)
|
||||
{
|
||||
{
|
||||
int cnt = 0;
|
||||
SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
|
||||
SDIO_DMACmd(ENABLE);
|
||||
DMA_RxConfiguration(readbuff, BlockSize);
|
||||
while (DMA_GetFlagStatus(DMA2_FLAG_TC4) == RESET)
|
||||
{}
|
||||
{
|
||||
cnt ++;
|
||||
if (cnt > 10 * 50000)
|
||||
{
|
||||
rt_kprintf("DMA flag 0x%08x\n", DMA_GetFlagStatus(DMA2_FLAG_TC4));
|
||||
/* Clear all DPSM configuration */
|
||||
SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
|
||||
SDIO_DataInitStructure.SDIO_DataLength = 0;
|
||||
SDIO_DataInitStructure.SDIO_DataBlockSize = SDIO_DataBlockSize_1b;
|
||||
SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToCard;
|
||||
SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
|
||||
SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Disable;
|
||||
SDIO_DataConfig(&SDIO_DataInitStructure);
|
||||
SDIO_DMACmd(DISABLE);
|
||||
errorstatus = SD_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return(errorstatus);
|
||||
}
|
||||
@@ -2941,7 +2961,7 @@ static void DMA_RxConfiguration(uint32_t *BufferDST, uint32_t BufferSize)
|
||||
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
|
||||
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
|
||||
DMA_Init(DMA2_Channel4, &DMA_InitStructure);
|
||||
|
||||
|
||||
/* DMA2 Channel4 enable */
|
||||
DMA_Cmd(DMA2_Channel4, ENABLE);
|
||||
}
|
||||
@@ -2978,7 +2998,7 @@ static rt_err_t rt_sdcard_init(rt_device_t dev)
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
|
||||
if (rt_sem_init(&sd_lock, "sdlock", 1, RT_IPC_FLAG_FIFO) != RT_EOK)
|
||||
{
|
||||
rt_kprintf("init sd lock semaphore failed\n");
|
||||
@@ -3009,7 +3029,7 @@ static rt_size_t rt_sdcard_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_
|
||||
|
||||
rt_sem_take(&sd_lock, RT_WAITING_FOREVER);
|
||||
retry = 3;
|
||||
/* read all sectors */
|
||||
/* read all sectors */
|
||||
for (i = 0; i < size / SECTOR_SIZE; i ++)
|
||||
{
|
||||
__retry:
|
||||
@@ -3017,9 +3037,10 @@ __retry:
|
||||
(uint32_t*)((rt_uint8_t*)buffer + i * SECTOR_SIZE),
|
||||
SECTOR_SIZE);
|
||||
if (status != SD_OK)
|
||||
{
|
||||
if (--retry != 0) goto __retry;
|
||||
break;
|
||||
{
|
||||
-- retry;
|
||||
if (retry != 0) goto __retry;
|
||||
else break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3130,4 +3151,3 @@ void rt_hw_sdcard_init()
|
||||
__return:
|
||||
rt_kprintf("sdcard init failed\n");
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ extern void finsh_set_device(const char* device);
|
||||
#endif
|
||||
extern int rt_application_init(void);
|
||||
extern rt_err_t wm8753_hw_init(void);
|
||||
|
||||
extern rt_err_t wm8978_hw_init(void);
|
||||
#ifdef DEBUG
|
||||
/*******************************************************************************
|
||||
* Function Name : assert_failed
|
||||
@@ -101,9 +101,13 @@ void rtthread_startup(void)
|
||||
#endif
|
||||
|
||||
/* init scheduler system */
|
||||
rt_system_scheduler_init();
|
||||
rt_system_scheduler_init();
|
||||
|
||||
#if CODEC_VERSION == 1
|
||||
wm8753_hw_init();
|
||||
#elif CODEC_VERSION == 2
|
||||
wm8978_hw_init();
|
||||
#endif
|
||||
|
||||
/* init hardware serial device */
|
||||
rt_hw_usart_init();
|
||||
|
||||
+25
-321
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user