void init(void) { DDRB &= 0xF3; // Disable USB Port PORTB &= 0xF3; DDRB |= 0x80; // LED PORTB |= 0x80; Sound_init(); ROE_init(); TFT_init(); Timer_init(); Tetris_mem_init(); eeprom_counter_increment(); srand(eeprom_counter()); eeprom_done(); Print_frame(); Tetris_init(); }
void GUI_init(void) { TFT_init(); }
int main(void) { int data; int index=0; char buffer[100]; Config32MHzClock(); CLK.PSCTRL = 0x00; // no division on peripheral clock UsartInit(); UsartWriteString("\r\n\r\nBOOT: Starting...\r\n"); //Analog Mux PORTF.DIR = 0b11111111; //Output PORTF.OUTCLR = PIN6_bm; PORTF.OUTCLR = PIN4_bm | PIN7_bm; PORTF.OUTSET = PIN5_bm; PORTF.OUTCLR = PIN0_bm | PIN1_bm | PIN2_bm | PIN3_bm; //PORTF.OUTSET = PIN1_bm; PORTF.OUTCLR = PIN6_bm; PORTF.OUTSET = PIN4_bm; PORTF.OUTCLR = PIN5_bm; PORTF.OUTSET = PIN7_bm; //WR UsartWriteString("BOOT: Analog Mux configured...\r\n"); //ADC PORTQ.DIR = 0b1111; //Output PORTQ.OUTCLR = PIN1_bm | PIN3_bm; //PWRDWN pins PORTQ.OUTSET = PIN0_bm | PIN2_bm; //ENCODE pins //Reading Values PORTD.DIR = 0b00000000; //Input PORTE.DIR = 0b00000000; //Input UsartWriteString("BOOT: ADC configured...\r\n"); //TFT LCD TFT_init(); Delay100ms(10); Delay100ms(10); Delay100ms(10); Delay100ms(10); Delay100ms(10); TSLCDFillRect(0,TS_SIZE_X-1,0,TS_SIZE_Y-1,TS_COL_BLUE,TS_MODE_NORMAL); /* TSLCDFillRect(0,TS_SIZE_X-1,0,70,TS_COL_WHITE,TS_MODE_NORMAL); TSLCDSetFontColor(TS_COL_BLUE); TSLCDPrintStr(2,6,"Testing ELT240320TP with AVR",TS_MODE_NORMAL); TSLCDFillRect(20,80,90,130,TS_COL_BLACK,TS_MODE_NORMAL); TSLCDFillRect(30,90,100,140,TS_COL_YELLOW,TS_MODE_NORMAL); TSLCDFillRect(20,80,160,200,TS_COL_BLACK,TS_MODE_NORMAL); TSLCDFillRect(30,90,170,210,TS_COL_RED,TS_MODE_NORMAL); TSLCDFillRect(195,205,71,TS_SIZE_Y-1,TS_COL_WHITE,TS_MODE_NORMAL); TSLCDFillCirc(200,155,60,TS_COL_WHITE,TS_MODE_NORMAL); TSLCDFillCirc(200,155,50,TS_COL_BLUE,TS_MODE_NORMAL); TSLCDFillCirc(200,155,40,TS_COL_BLACK,TS_MODE_NORMAL); TSLCDFillCirc(200,155,30,TS_COL_RED,TS_MODE_NORMAL); */ UsartWriteString("BOOT: TFT LCD configured...\r\n"); //Timing Lines //INT0: breakoutbar6 / A0 / frame //INT1: slicebin0 / A1 / pixel PORTA.INTCTRL = (PORTA.INTCTRL & ~PORT_INT0LVL_gm ) | PORT_INT0LVL_LO_gc; PORTA.INTCTRL = (PORTA.INTCTRL & ~PORT_INT1LVL_gm ) | PORT_INT1LVL_LO_gc; //Detect rising edge only PORTA.PIN0CTRL |= 0x01; PORTA.PIN0CTRL &= ~0x06; PORTA.PIN1CTRL |= 0x01; PORTA.PIN1CTRL &= ~0x06; PORTA.INT0MASK = PIN0_bm; PORTA.INT1MASK = PIN1_bm; UsartWriteString("BOOT: Interrupts configured...\r\n"); //EBI/SDRAM ebi_setup_port(12, 0, 0, EBI_PORT_3PORT | EBI_PORT_SDRAM); /* * Configure the EBI chip select for an 8 MB SDRAM located at * \ref BOARD_EBI_SDRAM_BASE. */ ebi_cs_set_mode(&cs_config, EBI_CS_MODE_SDRAM_gc); ebi_cs_set_address_size(&cs_config, EBI_CS_ASPACE_8MB_gc); ebi_cs_set_base_address(&cs_config, BOARD_EBI_SDRAM_BASE); /* Configure the EBI chip select to be in SDRAM mode. */ ebi_sdram_set_mode(&cs_config, EBI_CS_SDMODE_NORMAL_gc); /* Setup the number of SDRAM rows and columns. */ ebi_sdram_set_row_bits(&sdram_config, 12); ebi_sdram_set_col_bits(&sdram_config, 10); /* Further, setup the SDRAM timing. */ ebi_sdram_set_cas_latency(&sdram_config, 3); ebi_sdram_set_mode_delay(&sdram_config, EBI_MRDLY_2CLK_gc); ebi_sdram_set_row_cycle_delay(&sdram_config, EBI_ROWCYCDLY_7CLK_gc); ebi_sdram_set_row_to_precharge_delay(&sdram_config, EBI_RPDLY_7CLK_gc); ebi_sdram_set_write_recovery_delay(&sdram_config, EBI_WRDLY_1CLK_gc); ebi_sdram_set_self_refresh_to_active_delay(&sdram_config, EBI_ESRDLY_7CLK_gc); ebi_sdram_set_row_to_col_delay(&sdram_config, EBI_ROWCOLDLY_7CLK_gc); ebi_sdram_set_refresh_period(&sdram_config, BOARD_EBI_SDRAM_REFRESH); ebi_sdram_set_initialization_delay(&sdram_config, BOARD_EBI_SDRAM_INITDLY); /* Write SDRAM configuration into the EBI registers. */ ebi_sdram_write_config(&sdram_config); /* Write the chip select configuration into the EBI registers. */ ebi_cs_write_config(EBI_SDRAM_CS, &cs_config); ebi_enable_cs(EBI_SDRAM_CS, &cs_config); UsartWriteString("BOOT: SDRAM configured...\r\n"); do { // Wait for SDRAM to initialize. } while (!ebi_sdram_is_ready()); UsartWriteString("BOOT: SDRAM ready...\r\n"); status_code_t retval = ebi_test_data_bus((hugemem_ptr_t)BOARD_EBI_SDRAM_BASE); if (retval == STATUS_OK) { UsartWriteString("BOOT: SDRAM data bus test completed...\r\n"); } else { UsartWriteString("BOOT: WARNING: SDRAM data bus test failed...\r\n"); } retval = ebi_test_addr_bus((hugemem_ptr_t)BOARD_EBI_SDRAM_BASE,BOARD_EBI_SDRAM_SIZE); if (retval == STATUS_OK) { UsartWriteString("BOOT: SDRAM address bus test completed...\r\n"); } else { UsartWriteString("BOOT: WARNING: SDRAM address bus test failed...\r\n"); } //_delay_ms(1); //SD Card testing UsartWriteString("BOOT: SD Card testing...\r\n"); //_delay_ms(1); FRESULT f_err_code; static FATFS FATFS_Obj; UsartWriteString("BOOT: SD Card: initializing disk...\r\n"); disk_initialize(0); UsartWriteString("BOOT: SD Card: mounting disk...\r\n"); f_err_code = f_mount(0, &FATFS_Obj); if (f_err_code == FR_OK) { FIL fil_obj; int test_number = 5; UsartWriteString("BOOT: SD Card: opening file...\r\n"); f_open(&fil_obj, "asplfc.txt", FA_WRITE); UsartWriteString("BOOT: SD Card: writing file...\r\n"); int out = f_printf(&fil_obj, "moo %d", test_number); UsartWriteString("BOOT: SD Card: closing file...\r\n"); f_close(&fil_obj); } else { UsartWriteLine("BOOT: WARNING: No SD card found..."); } //PORTQ.OUTCLR = PIN2_bm | PIN4_bm; UsartWriteString("\n\rASP LFC firmware -- v0.1\r\n"); UsartWriteString("> "); while(1) { data=UsartReadChar(); // read char // check for carriage return and try to match/execute command if((data == '\r')||(index==sizeof(buffer))) { //PORTF.OUT ^= (1<<0); // switch LED buffer[index]=0; // null terminate index=0; // reset buffer index UsartWriteString("\n\r"); // echo newline ParseCommand(buffer); // attempt to parse command UsartWriteString("> "); } else if(data==8) // backspace character { if(index>0) index--; // backup one character UsartWriteChar(data); } else { buffer[index++]=data; UsartWriteChar(data); }; // UsartWriteChar(data); // write char // _delay_ms(100); // PORTF.OUT ^= (1<<0); // toggle LED }; };
void main(void) { // XBYTE[0xB091]=0x01; // 1.8v/3.3v regulator turn on XBYTE[0xB092]=0x78; // 3.2V & 2.0V // XBYTE[0xB093]=0x00; // LVR=2.4V // DSP initial XBYTE[0xB010]&=0xFE; // Disable DSP clock, Jimi 080729 for pop noise as 1st time play XBYTE[0xB002]&=0xFE; // Release DSP Reset, Jimi 080729 for pop noise as 1st time play XBYTE[0xB08a]|=0x08; //(JC)MCU:audio DAC on XBYTE[0xB08a]|=0x10; //(JC)MCU:Headphone driver on XBYTE[0xB08a]|=0x20; //(JC)MCU:Headphone driver DD comm-mode bias o/p XBYTE[0xB0ED]|=0x02; //(Jimi 091027)Audio DA zero cross reset bypass on XBYTE[0xB0C1]=0xB0; //(Jimi 091027)Pre-mux , post-mux and internal XCK select XBYTE[0xB0C4]=2; //(Jimi 091027)LCH speaker volume(i.e LCH OP Gain) XBYTE[0xB0C5]=2; //(Jimi 091027)RCH speaker volume(i.e RCH OP Gain) //SAR ADC init XBYTE[0xB05E] = 0; // disable SAR FS clock XBYTE[0xB05F] = 0x5F; // SAR clock = 12MHz/16/6 = 125kHz = 8us //-------------------------------------------- // gbt_Force_USB_FullSpeed =FALSE; gbt_USB_Detected = 0; gc_CardDetect = 0x00 ; gc_CardExist = 0x00 ; // bit 0 : Nand Flash bit 1: SD_Card gc_CardType = 0x01 ; // default Flash Interface gc_CardChangeStage =0x00; // bit 0 : Nand bit 1 : SD_Card gw_FileSkipNumber=0; gb_TriggerFileSkip=0; gb_FindFile=0; gbt_Support_Dummy_Capacity =0; // default disable dummy capacity function gc_bCBWLUN=0; gbt_enableCDROM =0; //09/04/24,joyce gc_CDROM_Size=0 ; init_system(); USB_PlugDetect(); // Detect USB plug //----------------------------------------------// Initial Flash module Init_Flash_Reg(); Init_Flash_Variable(); //-------------- Need search Bank,Dsp ,hzk block info ,first---------// FDBP.cFDev = 0; XBYTE[0xB40F] = FDBP.cFDev; FlashReadID(); Flash_State_Initial(); Search_BankCode_Block(); InitFlash(); Timer0_init(); XBYTE[0xB09F]|=0x06;//(JC)Vref Fast setup mode 'n Internal reference voltage power control gc_Vrefinit_Timer=60; XBYTE[0xB421]=0x13; // dbprintf("tftinit\n"); TFT_init(); #ifdef CAR_48 XBYTE[0xB102]|=0x3C; #else XBYTE[0xB102] |= 0x01; #endif // dbprintf("tftinit end\n"); TFT_PowerOnlogo(); if(gbt_USB_Detected) { USB_Task(); } gb_Host_Exist=1; gb_SD_Exist=1; if(!Host_DetectDevice()) { if(!Host_Initial()) { gc_CurrentCard = CURRENT_MEDIA_HOST; gb_FindFlag = 0; } else { gc_CurrentCard=0; } } else { if(SD_Card_Detect()) { if(SD_Identification_Flow()) { gc_CardExist |=0x02; gc_CurrentCard=2; } else { gc_CurrentCard=0; gc_CardExist &=0xFD; gb_FindFlag = 0; } } else { gb_SD_Exist=0; gc_CurrentCard = 0; } } XBYTE[0xB400] =0x01; XBYTE[0xB010]&=0xFE; // Disable DSP clock, Jimi 080729 for pop noise as 1st time play XBYTE[0xB002]&=0xFE; // Release DSP Reset, Jimi 080729 for pop noise as 1st time play XBYTE[0xB08a]|=0x08;//(JC)MCU:audio DAC on XBYTE[0xB08a]|=0x10;//(JC)MCU:Headphone driver on XBYTE[0xB08a]|=0x20;//(JC)MCU:Headphone driver DD comm-mode bias o/p //SAR ADC init XBYTE[0xB05E] = 0; // disable SAR FS clock XBYTE[0xB05F] = 0x5f; // SAR clock = 12MHz/16/6 = 125kHz = 8us Get_LogData_PageIndex(); //chiayen0808 USER_LogFile_ReadWrite(0);//use reserveblock for log if((gw_FM_frequency<875) || (gw_FM_frequency>1080)) { gw_FM_frequency=875; } FM_initial(); FM_drive(); gc_SetNumber = gw_PagesPerBlock >> 2; //1set=4pages for dir management, Ching 080816 //20090107 chiayen add gc_SetIndex = 0; //Ching 080816 //20090107 chiayen add USER_GetUISetIndex(); //for DIR table index //20090107 chiayen add gb_FindFlag = 0; if (DOS_Initialize()) //20090803 chiayen modify { gdw_HOSTStartSectorRead=0xFFFFFFF0; if(gc_CurrentCard==CURRENT_MEDIA_HOST) { if(SD_Card_Detect()) { gb_SD_Exist=1; if(SD_Identification_Flow()) { gc_CardExist |=0x02; gc_CurrentCard=2; } else { DEVICE_REG[0x00]= 0x01; gc_CurrentCard=0; gc_CardExist &=0xFD; gb_FindFlag = 0; } } else { DEVICE_REG[0x00]= 0x01; gb_SD_Exist=0; gc_CurrentCard = 0; } } else { DEVICE_REG[0x00]= 0x01; //20090730 chiayen add gc_CurrentCard=0; gc_CardExist &=0xFD; gb_FindFlag = 0; InitFlash(); } DOS_Initialize(); } gc_CurrentCard_backup=gc_CurrentCard; //20090803 chiayen move here gs_File_FCB[0].dw_FDB_StartCluster = gdw_DOS_RootDirClus; DOS_Search_File(C_File_All|C_Cnt_FileNo, C_MusicFileType, C_CmpExtName|C_Next);//(JC)count music file no. in root ir_init(); EA = 1; gc_Task_Current=C_Task_Play; gc_Task_Next=C_Task_Play; gc_PhaseInx=0; gw_init_needed=0xffff; Detect_USB(); Polling_TaskEvents(); if(gc_Task_Current!=gc_Task_Next) { gc_Task_Current=gc_Task_Next; } while(1) { switch(gc_Task_Current) { case C_Task_Play: Play_Task(); break; case C_Task_USB: USB_Task(); break; case C_Task_Dir: //20090107 chiayen add Dir_Task(); break; case C_Task_Jpeg: //20090107 chiayen add Jpeg_Task(); break; case C_Task_Mjpeg: //20090107 chiayen add Mjpeg_Task(); break; case C_Task_PlayMenu: //20090107 chiayen add // PlayMenuProcess(); break; case C_Task_PlayMenu_IR: //20090107 chiayen add // PlayMenuProcess_IR(); break; case C_Task_Setting: //20090107 chiayen add SetupMenuProcess(); break; case C_Task_Menu: MainMenuProcess(); break; case C_Task_PowerOff: PowerOffProcess(); break; } } }