📄 song_task.c
字号:
/*C**************************************************************************
* NAME: song_task.c
*----------------------------------------------------------------------------
* Copyright (c) 2003 Atmel.
*----------------------------------------------------------------------------
* RELEASE: snd1c-refd-nf-4_0_3
* REVISION: 1.16
*----------------------------------------------------------------------------
* PURPOSE:
* This file contains the song task and attached routines
*
* CONFIGURATION
* Three #define must be set in config.h:
* - PLAYER_PLAY_MODE
* PLAY_DIR play selected dir
* PLAY_DISK play whole disk including sub-directory
* - PLAYER_PLAY_START
* START_PLAY start playing after power-up
* START_STOP do not play after power-up
* - PLAYER_PLAY_LOOP
* PLAY_LOOP loop after last file of dir or disk has been played
* PLAY_NO_LOOP no loop after last file of dir or disk has been played
* NOTES:
* Global Variables:
* - gl_key_press: bit in bdata space
* - gl_key: byte in idata space
* - gl_mem_failure: bit in bdata space
*****************************************************************************/
/*_____ I N C L U D E S ____________________________________________________*/
#include "config.h" /* system configuration */
#include "lib_mcu\lcd\lcd_drv.h"
#include "modules\file\file.h" /* file definition */
#include "lib_mcu\clock\clock.h" /* clock definition */
#include "lib_mcu\kbd\key_drv.h"
#include "lib_mcu\aud\aud_drv.h" /* audio driver definition */
#include "lib_mcu\mp3\mp3_drv.h" /* mp3 driver definition */
#include "song_drv.h" /* song driver definition */
#include "song_task.h" /* song task definition */
/*_____ M A C R O S ________________________________________________________*/
/*_____ D E F I N I T I O N ________________________________________________*/
extern bdata bit gl_key_press; /* TRUE when a key is decoded */
extern idata Byte gl_key; /* value of the key pressed */
extern bdata bit gl_mem_failure; /* memory hardware failure */
Byte song_state; /* task state */
static bit song_loop; /* auto replay */
extern Byte mp3_volume;
/*_____ D E C L A R A T I O N ______________________________________________*/
/*F**************************************************************************
* NAME: song_task_init
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Song playing task initialization
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void song_task_init (void)
{
song_loop = PLAYER_PLAY_LOOP; /* default loop playing */
song_snd_init(); /* init sound control */
song_state = SONG_START;
}
/*F**************************************************************************
* NAME: song_task
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Song playing task
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void song_task (void)
{
// Byte cpt_data;
bit loop;
/*if (Mp3_frame_request())
{
// printch(0x96,"请求 ");
cpt_data = 0;
do
{
Mp3_load(Fgetc()); //send data while requested
cpt_data++;
// workaround for 320Kbs frame support
if ((cpt_data & 0x40) == 0x40)
{
Mp3_set_full();
Mp3_reset_full(); // ack 64 Bytes write
break;
}
}
while (Mp3_frame_request()); // until frame request */
while (Mp3_frame_request()) /* frame request ? */
{
Mp3_load(Fgetc()); /* send data while requested */
}
//}
switch (song_state)
{
case SONG_START:
{
printch(0x93,"标准 ");
Mp3_set_right_vol(0);
Mp3_set_left_vol(0);
song_state = SONG_INSTALL;
break;
}
case SONG_INSTALL:
{
if (File_entry_root(FILE_MP3 | FILE_DIR) == OK) /* goto root directory */
{
Mp3_set_right_vol(0);
Mp3_set_left_vol(0);
print_file_name(); /* display file name */
//#if PLAYER_PLAY_START == START_STOP
// song_state = SONG_IDLE;
//#else
if (File_type() == FILE_DIR)
{ /* file_type is dir */
#if PLAYER_PLAY_MODE == PLAY_DISK
song_state = SONG_NEW; /* enter dir and play */
#else
song_state = SONG_NEXT; /* stay in root dir */
#endif
}
else
{ /* file_type is MP3 */
song_state = SONG_INIT;
}
// #endif
}
else
{ /* root is empty of song & diretory */
song_state = SONG_NO_SONG;
}
break;
}
case SONG_IDLE: /* no file openned */
{
printch(0x90,"挂起 ");
if (gl_key_press) /* a key is pressed? */
{
switch (gl_key)
{
case KEY_PLAY:
if (File_type() == FILE_DIR)
{
file_entry_dir(FILE_MP3 | FILE_DIR); /* goto sub-directory */
print_file_name(); /* display directory name */
}
else
{ /* file_type is MP3 */
song_state = SONG_INIT;
}
break;
case KEY_NEXT:
file_seek_next(FILE_MP3 | FILE_DIR, TRUE); /* select next song with loop */
print_file_name(); /* display file name */
break;
case KEY_PREV:
file_seek_prev(FILE_MP3 | FILE_DIR, TRUE); /* select previous song */
print_file_name(); /* display file name */
break;
case KEY_INC:
song_snd_inc(); /* increment selected control */
print_sound_level(); /* display new level */
break;
case KEY_DEC:
song_snd_dec(); /* decrement selected control */
print_sound_level(); /* display new level */
break;
// case KEY_SOUND:
// song_snd_select(); /* select next sound control */
// print_sound(); /* display selected sound icon */
// print_sound_level(); /* display new level */
// break;
case KEY_PARENT:
File_goto_parent(FILE_MP3 | FILE_DIR); /* goto parent directory */
print_file_name(); /* display first file name */
break;
default:
break;
}
gl_key_press = FALSE; /* ack key usage */
}
break;
}
case SONG_INIT:
{
// printch(0x90,"就绪 ");
// disp_clock_reset(); /* reset clock timer */
if (Fopen(READ) == OK)
{
//if (song_init() != SONG_NO_ERR) /* init song playing */
//{
// song_stop(); /* stop playing song */
// Fclose();
// loop = song_loop;
// song_state = SONG_NEXT;
// }
//else
{
song_audio_init(); /* init audio interface */
clock_song_init();
song_state = SONG_PLL;
Mp3_set_right_vol(mp3_volume);
Mp3_set_left_vol(mp3_volume);
}
}
else
{
song_state = SONG_ERROR;
}
break;
}
case SONG_PLL:
{
if (Pll_get_lock()) /* pll locked? */
{
song_start(); /* start playing song */
//disp_clock_start(); /* start clock timer */
print_state_play(); /* display play icon */
song_state = SONG_PLAY;
}
break;
}
case SONG_PLAY:
{
// printch(0x94,"播放 ");
if (Feof() == TRUE)
{
Mp3_set_right_vol(0);
Mp3_set_left_vol(0);
//printch(0x90,"结束 ");/* end of file reached */
song_stop(); /* stop playing song */
//Fclose();
loop = song_loop;
song_state = SONG_NEXT;
gl_key_press = FALSE; /* no key usage */
}
if (gl_key_press) /* a key is pressed? */
{
gl_key_press = FALSE;
switch (gl_key)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -