⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yampp7_usb.c

📁 yampp 7 USB firmware v 2.44 checked, working, latest
💻 C
📖 第 1 页 / 共 5 页
字号:
	// start playing the song
	//
	isPlaying = 1;
	if (info_flag == 0)
		Playlist_name();

#if (BACKLIGHT_TIME == 0)
	PORTB |= _BV(LED_PIN);					// LED ON
#endif
	vs1001_reset();
	LoudSet();
}

void next_playlist(void)
{
	YADL_PLAY_LIST_ENTRY *pListEntry = get_pl_entry(curPlaylist);

	if(pListEntry->next_playlist != (u16)-1)		// check for next playlist number
		curPlaylist = pListEntry->next_playlist;
	else
		curPlaylist++;

	if((curPlaylist == (u16)-1) || (curPlaylist >= playlist_qty))
		curPlaylist = 0;

	pListEntry = get_pl_entry(curPlaylist);
	InitRnd();							// init randomizer table

	curIndex = (bRandom) ? do_rand(pListEntry->entry_qty) : 0;
}

void prev_playlist(void)
{
	if(--curPlaylist == (u16)-1)					// playlist down
		curPlaylist = playlist_qty - 1;				// go to last playlist
	YADL_PLAY_LIST_ENTRY *pListEntry = get_pl_entry(curPlaylist);	// update playlist data
	InitRnd();

	curIndex = (bRandom) ? do_rand(pListEntry->entry_qty) : 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(ClusterCount)
			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 not End of playlist
		goto GO_PLAY;
	else
	{
		InitRnd();					// init randomizer table
		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 || Repeat == 3)			// normal play and repeat one song, next playlist after end of playlist
		{						// fixed by Roger Nilson
			if (mode == 2)
				prev_playlist();
			else
				next_playlist();
GO_PLAY:		play_song();
		}
	}
}

//----------------------------------------------------------------------------

void set_contrast(void)
{
	event_e event = EV_IDLE;
	u08 contrast = eeprom_read_byte((u08 *)EEPROM_LCD_CONTRAST);
	lcd_clrscr();
	puts("Adjust contras\nt with volume \nkeys, STOP=End");
	goto SETC;
	while(1)
	{
  		wdt_reset();						// reset the watchdog
		time_flag = 0;
		sleepcount = 0;						// power off blocking
		event = get_event();
		switch(event)
		{
			default:
			case EV_IDLE: 
				break;

			case EV_UP:
			case EV_NEXT:
				if (contrast < 0x58)
					contrast++;
				goto SETC;

			case EV_DOWN:
			case EV_PREV:
				if (contrast > 0x20)
					contrast--;
SETC:
				lcd_gotoxy(2,4);
				lcd_bar((contrast-0x20),0x38);
				lcd_contrast(contrast);
				break;

			case EV_STOP:
				eeprom_write_byte((u08 *)EEPROM_LCD_CONTRAST,contrast);
				lcd_clrscr();
				set_event(EV_STOP);
				return;
		}
		event = EV_IDLE;
	}
}

#if defined (__AVR_ATmega162__)
 void set_cpu_speed(u08 speed)
 {
	asm volatile("ldi r25, 128");
	asm volatile("cli");
	asm volatile("sts 0x61, r25");
	asm volatile("sts 0x61, r24");
	asm volatile("sei");
 }
#endif


//----------------------------------------------------------------------------
// Main part
//----------------------------------------------------------------------------
int main(void) 
{
 
 //------------------------------
 // Initialize 
 //------------------------------

//////////////////////////////////////////////////////////////////
// B - Port
//////////////////////////////////////////////////////////////////

	PORTB = 0x0A;
	DDRB = 0xff;

//	cbi(PORTB,LED_PIN);
//	sbi(DDRB, LED_PIN);		// pin PB0 is output for LED or backlight
//	sbi(PORTB,RESET_PIN);		// RESET- hi
//	sbi(DDRB, RESET_PIN);		// pin PB1 is output, RESET- 

	// PB2 is BSYNC pin to VS1001 and RST pin to FTDI chip
	// PB3 is MP3 signal to VS1001
	// PB4 is SCE signal for LCD dosplay
	// PB5 (MOSI) is used for SPI
	// PB6 (MISO) is used for SPI
	// PB7 (SCK) is used for SPI
	
//////////////////////////////////////////////////////////////////
// D - Port
//////////////////////////////////////////////////////////////////

	PORTD = 0xFF;			// activate pullups
	DDRD  = 0xC0;

	// pin PD0 is DREQ input
	// pin PD1, PD4 and PD5 is keyboard input, enable pullup
	// PD2 and PD3 are RXF and TXE input pins from FTDI
	// PD6 and PD7 are WR and RD signals for CF and FTDI chip.

//////////////////////////////////////////////////////////////////
// E - Port
//////////////////////////////////////////////////////////////////


	PORTE |= _BV(BUTTON_1);				// pin PE0 is keyboard input, enable pullup

#ifndef PCB_REV_D
	CHARGE_DDR &= ~ _BV(CHARGE_PIN);		// set pin as input
	CHARGE_PORT |= _BV(CHARGE_PIN);		// activate pullup
#endif

#if defined (__AVR_ATmega162__)
	EMCUCR = 0;
	set_cpu_speed(CLKDIV);			// CPU clock = XTAL / M162CLKDIV
						// eg about 3-4MHz
 #if (BACKLIGHT_TIME != 0)
	OCR0 = 0;				// PWM duty = 0%
	TCCR0 = _BV(WGM00) | _BV(COM01) | _BV(CS01);	// Timer 0 normal PWM mode, CLK/8
 #endif
#endif

	MCUCR = _BV(SRE);			// enable external bus interface

	delayms(50);
	usb_init();
	wdt_enable(7);

	//
	// setup timer1 for a 100mS periodic interrupt
	//	

	TCCR1A = 0;
	TCCR1B = 4;				// prescaler /256  tPeriod = 32 uS
	TCNT1 = TI1_V;				// load timer 
	TIMSK |= _BV(TOIE1);	 		// enable timer1 interrupt

	// setup some buffers
	SectorBuffer = (u08 *) card_sbuf;	// 512 bytes

// *********************************************************************

	u08 tmp;

// *********************************************************************

	sei();
#ifdef LCD_NEGATIV
	lcd_init(1);
#else
	lcd_init(0);
#endif

	tmp = eeprom_read_byte((u08 *)EEPROM_LCD_CONTRAST);
	if (tmp > 0x58 || tmp < 0x20)
	{
		tmp = 0x45;
		eeprom_write_byte((u08 *)EEPROM_LCD_CONTRAST,tmp);
	}
	lcd_contrast(tmp);
	lcd_clrscr();
 #if (BACKLIGHT_TIME != 0)
	light_mode = eeprom_read_byte((u08 *)EEPROM_BACKLIGHT) % 6;
	backlight_on();
 #endif
	logo = 4+lcd_logo(0);
	if (logo == 4)
		lcd_gotoxy(3,logo);
	else
		_p_puts(model_txt);
	puts(" v.");
	_p_puts(version_txt);

	// init VS1001
	PORTB &= ~ _BV(RESET_PIN);			// RESET- lo
	delayms(2);
	PORTB |= _BV(RESET_PIN);			// RESET- hi
	delayms(10);
	vs1001_init_io();				// init VS1001
	vs1001_setcomp(F_VS1001);
	vs1001_reset();

	if ((volume = eeprom_read_byte((u08 *)EEPROM_VOLUME)) > MIN_VOLUME)
		volume = MIN_VOLUME / 2;		// half scale
	balance 	= eeprom_read_byte((u08 *)EEPROM_BALANCE) & 0xfe;
	bLoudness = eeprom_read_byte((u08 *)EEPROM_LOUDNESS) % 13;
	bRandom 	= eeprom_read_byte((u08 *)EEPROM_RANDOM);
	Repeat 	= eeprom_read_byte((u08 *)EEPROM_REPEAT) % 4;
	timemode 	= eeprom_read_byte((u08 *)EEPROM_TIME);
	autolock 	= eeprom_read_byte((u08 *)EEPROM_AUTOLOCK);
	curIndex 	= eeprom_read_word((uint16_t *)EEPROM_SONGPOS);
	curPlaylist = eeprom_read_word((uint16_t *)EEPROM_PLAYLIST);

	vs1001_setvolume(volume,balance);

#ifdef BATT_MONITOR
	lobatt = 12;
#endif
#if defined(BATT_MONITOR) && (BATT_MAX == 0) && (BATT_MIN == 0)
	lcd_clrscr();
	while(1)
	{
  		wdt_reset();					// reset the watchdog
		time_flag = 0;
		sleepcount = 0;					// power off blocking
		lcd_gotoxy(0, 2);
		printf( "Batt Value: %u  ", BatteryMeasure() );
		usb_handler();
		delayms(300);
	}
#endif

	// Init and wait for CARD ready
 	puts("\nInit Card...\n");

#ifdef MMC_CARD
	MMC_Reset();
#else
	ATA_SetDrive(0);
#endif
	delayms(10);
#ifndef FIXED_RESET
	tmp = 4;
	while(tmp--)					// for propper CF init after card removing.
	{
		wdt_reset();
		logo = CARD_SW_Reset2();		// for now logo variable is second temp variable
		if (logo)				// if card is ready
			break;
		else
			beep(SINE_800,50);
	}

	if (!logo)					// if card is not ready
		PowerOff();				// power off
#else
	wdt_reset();
	if (!CARD_SW_Reset2())
	{
		delayms(800);
		PowerOff();				// power off
	}
#endif

#ifndef MMC_CARD
	WriteBYTE(ATA_SectorCount, SLEEP_TIME);		// CF standby time * 5 milisecond (0=disable)
	WriteBYTE(ATAPI_Cmd, 0xE3);			// set CF standby timer and execute IDLE
	ATA_WaitBusy();
#endif
	logo = 4+lcd_card_logo();
	if (logo == 4)
		lcd_clrline(5);
	else
		lcd_gotoxy(0,2);

  	puts("Ready!\n");

	beep(SINE_1500,100);				// Wakeup beep

	ACSR = 0x40;				// Enable Analog Comparator and Bandgap reference

	init_stuff();

	InitRnd();					// init randomizer table
	LoudSet();
	if (curPlaylist >= playlist_qty)
		curPlaylist = curIndex = 0;

	delayms(1000);
	wdt_enable(6);

///////////////////////////////////////////////////////////////////////////////
// start things rolling
///////////////////////////////////////////////////////////////////////////////

	event_e event = EV_IDLE;
	YADL_PLAY_LIST_ENTRY *pListEntry;

	set_event(EV_STOP);

	//
	// main loop
	//
  	while (1) 
  	{
		event = get_event();
		switch (event)
		{
			default:
			case EV_IDLE: 
				continue;

			case EV_MENU:
				info_flag = 2;				// disable displaying
				menu_event = browse_menu() + 1;

				if(menu_event)
				{
					set_event(menu_event);
					break;
				}
				else
				{
BROWSE_BREAK:		info_flag = 0;			// enable displaying
					menu_event = EV_IDLE;
					if (isPlaying)
						Playlist_name();	// show Playlist name
					else
						set_event(EV_STOP);
					break;
				}

			case EV_CONTRAST:
				set_contrast();
				break;
				
#if (BACKLIGHT_TIME != 0)
			case EV_LIGHTMODE:
				lcd_gotoxy(0,5);
 #if defined (__AVR_ATmega162__)
				light_mode =(u08)(light_mode + 1) % 6;
				if(light_mode == 0)
					puts("OFF");
				else if(light_mode == 1)
					puts("OFF/DIMM");
				else if(light_mode == 2)
					puts("OFF/ON");
				else if(light_mode == 3)
					puts("DIMM");
				else if(light_mode == 4)
					puts("DIMM/ON");
				else
					puts("ON");
				puts("       ");
 #else
				light_mode =(u08)(light_mode + 1) % 3;
				if(light_mode == 0)
					puts("OFF");
				else if(light_mode == 1)
					puts("AUTO");
				else
					puts("ON");
				puts("   ");
 #endif
				if(light_mode)
					backlight_on();
				else
					backlight_off();
				break;
#endif
			case EV_TIME:
				timemode = !timemode;				// change mode of time displaying (normal<->remain)
				lcd_gotoxy(0,5);
				if(timemode)
					puts("REMAIN ");
				else
					puts("NORMAL ");

				break;

			case EV_PLAYLIST:
				event = EV_IDLE;
				info_flag = 2;					// disable displaying
				u16 Index = browse_songs();			// browse songs within playlist
				if (Index == (u16)-1)
					goto BROWSE_BREAK;

				curIndex = Index;
				menu_event = EV_IDLE;
				info_flag = 0;
				InitRnd();
				isPlaying = 0;

			case EV_PLAY:
				if (menu_event)
				{
					set_event(menu_event);
					time_flag = 0;
					continue;
				}

				if (isPlaying)					// Pause function
				{
					while(get_event() != EV_IDLE)		// Wait for release key
						wdt_reset();

					lobatt_time = 0;
					MCUCR = 0xA0;				// enable SLEEP mode
					u08 cc = 6;
					isPlaying = 0;
					do 
					{
						asm volatile ("sleep");		// go to sleep
						asm volatile ("nop");
						wdt_reset();
						if (cc-- == 0)
							cc=8;

						lcd_gotoxy(8,3);		// position for "Paused" string
						if (cc > 4)
						{
#if (BACKLIGHT_TIME == 0)
							PORTB &= ~_BV(LED_PIN);	// LED off
#endif
							asm volatile ("nop");
						}
						else
						{
#if (BAC

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -