?? 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 "board.h" /* board definition */
#include "modules\display\disp.h" /* display definition */
#include "modules\file\file.h" /* file definition */
#include "modules\mode\mode_task.h" /* mode task definition */
#include "modules\display\disp_task.h" /* display definition */
#include "modules\mem\mem_task.h" /* memory task definition */
#include "lib_mcu\clock\clock.h" /* clock definition */
#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 */
#ifndef REFD /* add compatibility with refd/demo */
#error
#define disp_end_of_play()
#endif
Byte song_state; /* task state */
static bit song_loop; /* auto replay */
/*_____ 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())
{
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;
}
if (gl_mem_failure)
{ /* hardware failure */
song_state = SONG_ERROR; /* in case of read error */
break;
}
}
while (Mp3_frame_request()); /* until frame request */
while (Mp3_frame_request()) /* frame request ? */
{
Mp3_load(Fgetc()); /* send data while requested */
if (gl_mem_failure)
{ /* hardware failure */
song_state = SONG_ERROR; /* in case of read error */
break;
}
}
}
switch (song_state)
{
case SONG_START:
{
print_mode_song(); /* select song icon */
print_state_blank(); /* select blank icon */
print_screen(SONG_SCREEN); /* display song screen */
print_sound_level(); /* display volume level */
song_state = SONG_INSTALL;
break;
}
case SONG_INSTALL:
{
if (mem_status() != MEM_BUSY) /* wait end of memory install */
{
if (mem_status() == MEM_READY)
{ /* disk formated */
/* this may be changed to retrieve last saved position */
if (File_entry_root(FILE_MP3 | FILE_DIR) == OK) /* goto root directory */
{
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;
}
}
else
{ /* disk not formated */
print_state_error(); /* error icon when not formated */
if (gl_key_press) /* a key is pressed? */
{
switch (gl_key)
{
case KEY_MEM:
mem_select_next(); /* select next memory */
song_state = SONG_START;
break;
case KEY_MODE:
mode_set_init(); /* exit from song task */
song_state = SONG_START;
break;
}
gl_key_press = FALSE; /* ack key usage */
}
else
{ /* check card presence */
if (mem_check_card() == KO)
{
mem_select_next();
song_state = SONG_START; /* card has been unplugged */
}
}
}
}
else
{
if (gl_key_press) /* stop key is pressed? */
{
if (gl_key == KEY_MODE)
{
mode_set_init(); /* exit from song task */
song_state = SONG_START;
}
gl_key_press = FALSE; /* ack key usage */
}
}
break;
}
case SONG_IDLE: /* no file openned */
{
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;
case KEY_MODE:
mode_set_init(); /* exit from song task */
disp_name_stop();
song_state = SONG_START;
break;
case KEY_MEM:
mem_select_next(); /* select next memory */
disp_name_stop();
song_state = SONG_START;
break;
default:
break;
}
gl_key_press = FALSE; /* ack key usage */
}
else
{ /* check card presence */
if (mem_check_card() == KO)
{
disp_name_stop();
mem_select_next();
song_state = SONG_START; /* card has been unplugged */
}
}
break;
}
case SONG_INIT:
{
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_state = SONG_PLL;
}
}
else
{
song_state = SONG_ERROR;
}
break;
}
case SONG_PLL:
{
if (Pll_get_lock()) /* pll locked? */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -