📄 yampp3_usb.c
字号:
#endif
load_sectors(buffer1);
load_sectors(buffer2);
#ifdef ENABLE_UART
u08 *brstr = (br > OPTION_BR_VBR) ? "VBR, average " : ""; // test VBR signature
uprintf("\n\nSong: %u , %s - %s\nPlaying Time %u:%02u, Bitrate %s%ukbps\n",
curIndex+1, artistname, titlename, songtime / 60, songtime % 60, brstr, bitrate);
#endif
create_scroll_data(); // create scroll line data
//
// start playing the song
//
eeprom_ww(EEPROM_PLAYLIST,curPlaylist); // save playlist number
eeprom_ww(EEPROM_SONGPOS,curIndex); // save song number within current playlist
start_playing();
lcd_frame(); // display song info on 4 lines lcd and progress bar outline
}
void plist_info(YADL_PLAY_LIST_ENTRY * pListEntry) // print info about playlist on terminal
{
#ifdef ENABLE_UART
uprintf("\n\nPlaylist: %s , Playlist Time %u:%02u:%02u\n",
pListEntry->name, pListEntry->length_hours,
pListEntry->length_minutes, pListEntry->length_seconds);
#endif
}
void next_playlist(void)
{
YADL_PLAY_LIST_ENTRY *pListEntry = get_pl_entry(curPlaylist);
if(pListEntry->next_playlist != 0xffff) // check for next playlist number
curPlaylist = pListEntry->next_playlist;
else
curPlaylist++;
if((curPlaylist == 0xffff) || (curPlaylist >= playlist_qty))
curPlaylist = 0;
pListEntry = get_pl_entry(curPlaylist);
plist_info(pListEntry); // print pl info
InitRnd(); // init randomizer table
if (bRandom)
curIndex = do_rand(pListEntry->entry_qty);
else
curIndex = 0;
}
void prev_playlist(void)
{
if(--curPlaylist == 0xffff) // playlist down
curPlaylist = playlist_qty - 1; // go to last playlist
YADL_PLAY_LIST_ENTRY *pListEntry = get_pl_entry(curPlaylist); // update playlist data
plist_info(pListEntry); // print pl info
InitRnd(); // init randomizer table
if (bRandom)
curIndex = do_rand(pListEntry->entry_qty);
else
curIndex = pListEntry->entry_qty-1;
}
void next_song(u08 mode)
{
YADL_PLAY_LIST_ENTRY *pListEntry = get_pl_entry(curPlaylist);
if (Repeat == 3 && mode == 0) // repeat one song
goto GO_PLAY;
if (mode == 2)
{
#ifdef NEW_PREW
if(BackStepPos)
goto GO_PLAY;
else
#endif
curIndex = (bRandom) ? do_rand(pListEntry->entry_qty) : curIndex-1;
}
else
curIndex = (bRandom) ? do_rand(pListEntry->entry_qty) : curIndex+1;
if (curIndex < (pListEntry->entry_qty)) // if End of playlist
goto GO_PLAY;
else
{
InitRnd();
if(Repeat == 2) // repeat playlist
{
if (bRandom)
curIndex = do_rand(pListEntry->entry_qty);
else
curIndex = 0;
goto GO_PLAY;
}
if(Repeat == 0)
{
set_event(EV_STOP); // normal play, stop after end of playlist
return;
}
if(Repeat == 1) // normal play, next playlist after end of playlist
{
if (mode == 2)
prev_playlist();
else
next_playlist();
GO_PLAY: play_song();
}
}
}
void disp_mod(u08 mod) // display ON/OFF information
{
#ifdef GRAPH_LCD
status_display();
#else
Vlcd_progputs((mod) ? PSTR("N ") : PSTR("FF"));
time_flag = 0; // prevent display overvrite
info_flag = 1; // allow scroll
#endif
}
//----------------------------------------------------------------------------
// Main part
//----------------------------------------------------------------------------
int main(void)
{
//------------------------------
// Initialize
//------------------------------
//////////////////////////////////////////////////////////////////
// B - Port
//////////////////////////////////////////////////////////////////
/*
sbi(PORTB, 0); // DIOW- hi
sbi(DDRB, 0); // pin PB0 is output, DIOW-
sbi(PORTB, 1); // DIOR- hi
sbi(DDRB, 1); // pin PB1 is output, DIOR-
cbi(DDRB, 2); // pin PB2 is input, DEMAND
sbi(PORTB, 2); // activate pullup
// PB3 and PB4 is used for BSYNC and MP3 signals to VS1001
// PB5 (MOSI) is used for SPI
// PB6 (MISO) is used for SPI
// PB7 (SCK) is used for SPI
*/
outp(0x07, PORTB);
outp(0x03, DDRB);
//////////////////////////////////////////////////////////////////
// D - Port
//////////////////////////////////////////////////////////////////
// PD0 and PD1 are TX and RX signals
/*
sbi(PORTD,PD3); // pin PD3 is keyboard input, enable pullup
sbi(PORTD,PD4); // PD4 is available but need a pullup to avoid noise
sbi(PORTD,PD5); // PD5
// PD6 and PD7 are RD and WR signals
// but we need to set their default states used
// when the external memory interface is disabled
// they should then both be high to avoid disturbing
// RAM contents
sbi(DDRD, 6); // as outputs
sbi(DDRD, 7);
sbi(PORTD, 6); // and both hi
sbi(PORTD, 7);
*/
outp(0xff, PORTD);
outp(0xC0, DDRD);
// PORTE need setup of ALE in idle mode
outp(0x01, PORTE);
outp(0x06, DDRE);
/*
cbi(DDRE, PE0); // PE0 is IR input
sbi(PORTE, PE0); // activate pullup
sbi(DDRE, PE1); // set ALE pin as output
cbi(PORTE, PE1); // and set it low (inactive)
*/
//////////////////////////////////////////////////////////////////
// USB
//////////////////////////////////////////////////////////////////
usb_init();
//////////////////////////////////////////////////////////////////
// Timer 1
//////////////////////////////////////////////////////////////////
//
// setup timer1 for a 100mS periodic interrupt
//
outp(0, TCCR1A);
outp(4, TCCR1B); // prescaler /256 tPeriod = 32 uS
outp(TI1_H, TCNT1H); // load counter value hi
outp(TI1_L, TCNT1L); // load counter value lo
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
// enable external SRAM and wait states
outp((1<<SRE)|(1<<SRW10), MCUCR);
#if defined(ENABLE_UART) || defined(SATTELITE)
uart_init(UART_BAUD_SELECT); // init RS-232 link
#endif
delayms(100);
#ifdef SATTELITE
u08 i = 10;
while(Sattelite_init() && i--);
#else
Vlcd_init(0, LCD_FUNCTION_DEFAULT, (LCD_LINES<<8)+LCD_LINE_LENGTH); // does clrscr too
#endif
delayms(20);
#ifdef GRAPH_LCD
Vlcd_contrast(GRAPHICS_LCD_CONTRAST);
if (Vlcd_logo())
Vlcd_progputs(PSTR("Hi, MP3 world!\n yampp-3/USB\n Alive !"));
#else //GRAPH_LCD
#if (LCD_LINE_LENGTH == 16)
both_progputs(PSTR(" Hi, MP3 world!\nyampp3/USB Alive\n"));
#else //(LCD_LINE_LENGTH == 16)
both_progputs(PSTR(" Hi, MP3 world!\n yampp-3/USB Alive\n"));
#endif //(LCD_LINE_LENGTH == 16)
#endif //GRAPH_LCD
// setup some buffers
extern u08 ata_sbuf[512];
SectorBuffer = ata_sbuf;
buffer1 = (u08 *) BUFFERSTART; // 8 k
buffer2 = (u08 *) buffer1 + BUFFERSIZE; // 8 k
buffer3 = (u08 *) buffer2 + BUFFERSIZE; // end pointer
#ifdef ENABLE_UART
// say hello
uart_progputs(firmver_txt);
uart_putchar(':');
uart_progputs(version_txt);
uart_progputs(PSTR(" - "));
uart_progputs(date_txt);
uart_EOL();
#endif
#if defined(ROTTARY_CONTROL) && !defined(SATTELITE)
rotary_init();
#endif
// init VS1001
vs1001_init_io(); // init VS1001
vs1001_setcomp(F_VS1001);
bLoudness = eeprom_rb(EEPROM_LOUDNESS) & 0x8f;
Repeat = eeprom_rb(EEPROM_REPEAT) % 4;
bRandom = eeprom_rb(EEPROM_RANDOM);
timemode = eeprom_rb(EEPROM_TIME);
balance = eeprom_rb(EEPROM_BALANCE) & 0xfe;
vs1001_reset(0);
// Init and wait for drive
#ifdef ENABLE_UART
uart_progputs(PSTR("Disk Init... "));
#endif
ATA_SetDrive(0);
ATA_SW_Reset2();
#ifdef ENABLE_UART
uart_progputs(PSTR("Ready!\n"));
#endif
// init randomizer from timer
seed = 1 + inp(TCNT1L);
if ((volume = eeprom_rb(EEPROM_VOLUME)) == 255)
volume = 12; // -6 dB
// Send three sinewave beeps to indicate we're starting up okay
#ifdef PWR_BEEPS
LoudSet();
send_sinewave_beeps();
#endif
#ifdef VOL_UP_RAMP
volume_ramp = (eeprom_rb(EEPROM_AUTOPLAY)) ? (MIN_VOLUME-volume)>>1 : 0;
#endif
ir_standard = eeprom_rb(EEPROM_IRSTAND) % STANDARDS_COUNT; // get remote controller standard
// enable timer1 interrupt
sbi(TIMSK, TOIE1);
init_stuff();
LoudSet();
#ifndef SATTELITE
ATA_Read(4, 1, (u08*)BBK_MEMORY); // Load user chars into temp buffer
memcpy((u08*)LANGTAB_MEMORY, (u08*)BBK_MEMORY, 180); // store chars to LANGTAB
// check for pressing local "PLAY" key to enter remote IR setup procedure
ramdisable();
outp(0xff, DDRA); // set port as output
outp(0xff, PORTA);
asm volatile("nop"); // allow time for port to activate
if(bit_is_set(PIND, PD3)) // if not permanent short to GND
{
outp(0xfe, PORTA); // set D0 pin to 0
asm volatile("nop"); // allow time for port to activate
if(bit_is_clear(PIND, PD3)) // if KEY 0 (PLAY) pressed
setup_rem(); // go to remote IR setup procedure
}
ramenable();
#endif
InitRnd();
// load autoplay and position settings
if(eeprom_rb(EEPROM_AUTOPLAY) == 1)
set_event(EV_PLAY);
else
set_event(EV_STOP);
curIndex = eeprom_rw(EEPROM_SONGPOS);
curPlaylist = eeprom_rw(EEPROM_PLAYLIST);
if (curPlaylist >= playlist_qty)
curPlaylist = curIndex = 0;
ATA_Standby(HDD_STANDBY_TIME / 5); // set automatic standby timer
///////////////////////////////////////////////////////////////////////////////
// start things rolling
///////////////////////////////////////////////////////////////////////////////
event_e event = EV_IDLE;
YADL_PLAY_LIST_ENTRY *pListEntry;
#ifdef ENABLE_USB_PLAYING
static char usb_txt[] __attribute__ ((progmem)) = "Playing via USB";
#endif
//
// main loop
//
while (1)
{
event = get_event();
switch (event)
{
default:
case EV_IDLE:
break;
case EV_PLAYLIST:
event = EV_IDLE;
info_flag = 3; // disable displaying
if (browse_playlist()) // browse playlist
goto BROWSE_BREAK;
uart_EOL();
info_flag = 4; // enable auto song change
u16 Index = browse_songs(); // browse songs within playlist
uart_EOL();
if (Index == 0xffff)
{ // browse terminate
BROWSE_BREAK: pListEntry = get_pl_entry(curPlaylist); // reload playlist cache
info_flag = 0; // enable displaying
Vlcd_clrscr();
if (isPlaying)
lcd_frame();
else
set_event(EV_STOP);
break;
}
curPlaylist = selected_Playlist;
curIndex = Index;
InitRnd();
isPlaying = 0;
case EV_PLAY:
if (menu_event)
{
set_event(menu_event);
time_flag = 0;
continue;
}
if (isPlaying) // Pause function
{
#ifdef OLD_VS1001
u16 oldPlayT = wPlayT;
#endif
while(get_event() != EV_IDLE); // Wait for release key
Send_state(STATE_PAUSED);
ATA_Standby(0); // disable automatic standby timer
Vlcd_gotoxy(LCD_LINE_LENGTH - 6, LCD_LINES - 1);
Vlcd_progputs(PSTR("Paused"));
#ifdef SONGPOS_RESTORE
eeprom_ww(EEPROM_STARTPOS, BackStepPos);
#endif
do
{
control_handler();
} while(event_queue_head == event_queue_tail);
get_event();
ATA_Standby(HDD_STANDBY_TIME / 5); // enable automatic standby timer
ATA_Read(1,1,(u08*) BBK_MEMORY);
Send_state(STATE_PLAYING);
#ifdef SONGPOS_RESTORE
eeprom_ww(EEPROM_STARTPOS, 0xffff);
#endif
#ifdef OLD_VS1001
wPlayT = oldPlayT;
#endif
break;
}
else // Play function
{
if(curPlaylist < playlist_qty && playlist_qty > 0)
{
#ifdef ENABLE_UART
plist_info(get_pl_entry(curPlaylist));
#endif
info_flag = 0;
play_song();
eeprom_wb(EEPROM_AUTOPLAY,1); // store autoplay flag
}
break;
}
#ifdef ENABLE_USB_PLAYING
case EV_PLAY_USB:
#ifdef ENABLE_UART
uart_EOL();
uart_progputs(usb_txt);
uart_EOL();
#endif
strcpy_P(scroll_line,usb_txt);
usb_play = 1;
create_scroll_data();
#ifdef ENABLE_UART
uprintf("Song: %s - %s\r\n",artistname, titlename);
#endif
start_playing();
lcd_frame();
updbuf = buffer2;
break;
#endif
case EV_STOP:
if (isPlaying)
eeprom_wb(EEPROM_AUTOPLAY,0); // store autoplay flag
isPlaying = 0;
#ifdef ENABLE_USB_PLAYING
usb_play = 0;
#endif
#ifdef VOL_UP_RAMP
volume_ramp = 0;
#endif
Send_state(STATE_STOP);
vs1001_reset(0);
vs1001_write(0x0A,0);
Vlcd_clrscr();
#ifdef GRAPH_LCD
if(Vlcd_logo())
lcd_centerprint(2, (u08*)&model_txt[0], 1);
status_display();
#if(LCD_TYPE == 7)
Vlcd_gotoxy(10,5);
#else
Vlcd_goto
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -