void ram() { char *nick = "Pentagon V1LLAG3"; char nickbuf[32]; // 16? do { lcdFill(0); DoString(0, 0, "Getting"); lcdDisplay(); uint32_t score = highscore_get(nickbuf); gpioSetValue (RB_LED2, 1); lcdFill(0); DoString(0, 0, "Highscore:"); DoString(0, 16, nickbuf); DoInt(0, 32, score); lcdDisplay(); if (strcmp(nick, nickbuf) != 0) { lcdFill(0); DoString(0, 48, "Setting"); lcdDisplay(); delayms_queue(500); highscore_set(score+1, nick); } } while(getInputWaitTimeout(500) != BTN_UP); }
//# MENU SD_USB void menu_sdcard(void){ lcdClear(); sdmmc_setup(); uint32_t r = sdmmc_acquire(); if(r) { lcdPrintln("SD card found."); lcdPrintln("No. of blocks:"); lcdPrintln(IntToStr(Chip_SDMMC_GetDeviceBlocks(LPC_SDMMC), 10, 0)); lcdPrintln("in USB MSC mode"); // SD I/O needs higher interrupt prio than USB so it works within // the USB callbacks NVIC_SetPriority(USB0_IRQn, 2); NVIC_SetPriority(SDIO_IRQn, 0); SD_MSCenable(); } else { lcdPrintln("No SD card found."); } lcdDisplay(); while(getInputRaw()==BTN_NONE){ /* wait */ __asm__ volatile ("nop"); }; lcdPrintln("goodbye!"); lcdDisplay(); MSCdisable(); Chip_SDIF_DeInit(LPC_SDMMC); }
void doFlash(){ uint32_t addr = 0; uint16_t len = (uintptr_t)&_bin_size; uint8_t * data = (uint8_t *)&_reloc_ep; lcdPrintln("Flashing"); lcdPrint(IntToStr(len,6,0)); lcdPrintln(" bytes"); lcdDisplay(); flash_random_write(addr, len, data); lcdPrintln("done."); lcdDisplay(); flash_read(addr, len, &_app_start); uint16_t idx; int err=0; for (idx=0;idx<len;idx++){ if ((&_app_start)[idx] != data[idx]){ lcdPrint(IntToStr(idx,4,F_HEX)); lcdPrint(": "); lcdPrint(IntToStr((&_app_start)[idx],2,F_HEX)); lcdPrint("!="); lcdPrint(IntToStr(data[idx],2,F_HEX)); lcdNl(); err++; lcdDisplay(); }; if(err%4==1){ getInputWait(); }; }; getInputWait(); };
void ram(void) { board_t b; board_init(&b, 4, 4, 0); const int anim_N = 10; do { if (b.menu_active) { lcdFill(0x00); board_menu_draw(&b); lcdDisplay(); } else { for (int anim_i = 1; anim_i <= anim_N; anim_i ++) { lcdFill(0x00); board_draw(&b, anim_i, anim_N); lcdDisplay(); } board_drop_new_value(&b); lcdFill(0x00); board_draw(&b, anim_N, anim_N); lcdDisplay(); } } while(board_handle_input(&b)); setTextColor(0xFF,0x00); return; }
//# MENU cpld void cpld_flash() { SETUPgout(EN_1V8); ON(EN_1V8); delay(1000000); /* wait until cpld boot */ cpu_clock_set(204); lcdPrintln("Program CPLD"); bytes=0; lcdPrint(IntToStr(bytes,5,F_LONG)); lcdPrint(" bytes..."); lcdNl(); #define WAIT_LOOP_DELAY (6000000) #define ALL_LEDS (PIN_LED1|PIN_LED2|PIN_LED3) int i; int error; refill_cpld_buffer_fs(); error = cpld_jtag_program(sizeof(cpld_xsvf_buffer), cpld_xsvf_buffer, refill_cpld_buffer_fs); if(error) { lcdPrintln("Programming failed!"); lcdPrintln(IntToStr(error,5,0)); lcdDisplay(); /* LED3 (Red) steady on error */ ON(LED4); while (1); }; lcdPrintln("Success."); lcdDisplay(); OFF(EN_1V8); };
void ram(void) { lcdClear(); lcdPrintln(""); lcdPrintln(""); lcdPrintln(" BRICKS"); lcdPrintln(""); lcdPrintln(""); lcdPrintln(""); lcdPrintln(" by briks"); lcdDisplay(); delayms(1000); int pause = PAUSE_INITIAL; for (int i = 1; true; i++) { lcdClear(); lcdPrintln(""); lcdPrintln(""); lcdPrintln(""); lcdPrintln(" Level"); lcdPrintln(""); lcdPrint(" "); lcdPrintln(IntToStr(i, 2, 0)); lcdDisplay(); delayms(1000); if (playLevel(i % LEVELS, pause) == 0) { return; } pause = pause - (pause / 4); // shorten pause (increases speed) } }
void bootFile(const char * filename){ FIL file; UINT readbytes; FRESULT res; res=f_open(&file, filename, FA_OPEN_EXISTING|FA_READ); if(res!=F_OK){ lcdPrintln("FOPEN ERROR"); lcdPrintln(f_get_rc_string(res)); lcdDisplay(); getInputWait(); return; }; uint8_t *destination=&_app_start; #define BLOCK 1024 * 128 do { res=f_read(&file, destination, BLOCK, &readbytes); destination+=readbytes; }while(res==F_OK && readbytes==BLOCK); lcdDisplay(); if(res!=F_OK){ lcdPrint("Read Error:"); lcdPrintln(f_get_rc_string(res)); lcdDisplay(); getInputWait(); return; }; systick_interrupt_disable(); /* TODO: maybe disable all interrupts? */ boot((void*)&_app_start); };
//# MENU cpld void cpld_menu(){ getInputWaitRelease(); SETUPgout(EN_1V8); ON(EN_1V8); delayNop(1000000); /* wait until cpld boot */ cpu_clock_set(204); lcdClear(); lcdPrintln("CPLD"); lcdNl(); lcdNl(); bytes=0; lcdPrint(IntToStr(bytes,5,F_LONG)); lcdPrint(" bytes..."); lcdNl(); #define WAIT_LOOP_DELAY (6000000) #define ALL_LEDS (PIN_LED1|PIN_LED2|PIN_LED3) int i; int error; FRESULT res; res=f_open(&file, "cpld.xsv", FA_OPEN_EXISTING|FA_READ); if(res!=FR_OK){ lcdPrintln("FOPEN ERROR"); lcdPrintln(f_get_rc_string(res)); lcdDisplay(); getInputWait(); return; }; refill_cpld_buffer_fs(); error = cpld_jtag_program(sizeof(cpld_xsvf_buffer), cpld_xsvf_buffer, refill_cpld_buffer_fs); if(error){ lcdPrintln("Programming failed!"); lcdPrintln(IntToStr(error,5,0)); lcdDisplay(); /* LED3 (Red) steady on error */ ON(LED3); while (1); }; lcdPrintln("Success."); lcdDisplay(); for (res=0;res<10;res++){ /* blink LED1, LED2, and LED3 on success */ TOGGLE(LED1); TOGGLE(LED2); TOGGLE(LED3); for (i = 0; i < WAIT_LOOP_DELAY; i++) /* Wait a bit. */ __asm__("nop"); }; /* XXX: Maybe power toggle needed to start CPLD? */ OFF(EN_1V8); };
void full_msc() { MSCenable(); lcdPrintln("MSC enabled."); lcdDisplay(); while(getInputRaw()!=BTN_ENTER) { __WFI(); }; lcdPrintln("MSC disabled"); lcdDisplay(); MSCdisable(); };
void msc_menu(void){ MSCenable(); lcdPrintln("MSC enabled."); lcdDisplay(); getInputWaitRelease(); getInputWait(); lcdPrintln("disconnect"); lcdDisplay(); MSCdisable(); fsReInit(); getInputWaitRelease(); }
//# MENU Apack void ppack_menu() { lcdClear(); lcdPrintln("PPack port"); lcdPrintln(""); lcdPrintln("up=enable"); lcdDisplay(); dac_init(false); cpu_clock_set(204); // WARP SPEED! :-) hackrf_clock_init(); rf_path_pin_setup(); /* Configure external clock in */ scu_pinmux(SCU_PINMUX_GP_CLKIN, SCU_CLK_IN | SCU_CONF_FUNCTION1); sgpio_configure_pin_functions(); ON(EN_VDD); ON(EN_1V8); OFF(MIC_AMP_DIS); complex_s8_t * samples; while(1){ switch(getInputRaw()){ case BTN_UP: // ON(MIXER_EN); // hackrf does this cpu_clock_set(204); // WARP SPEED! :-) si5351_init(); portapack_init(); getInputWaitRelease(); break; case BTN_DOWN: lcdPrintln("file"); writeFile("samples.8", (char*)0x20000000,(uintptr_t)s8ram-0x20000000); break; case BTN_LEFT: lcdPrintln("reset"); s8ram=(complex_s8_t*)0x20000000; break; case BTN_RIGHT: break; case BTN_ENTER: return; }; TOGGLE(LED2); delayms(40); lcdPrint(IntToStr((uintptr_t)s8ram,8,F_HEX)); lcdPrint(" "); lcdPrintln(IntToStr(sctr,7,F_LONG)); lcdDisplay(); }; };
//# MENU led void led_menu(){ getInputWaitRelease(); uint8_t leds=0; uint8_t adc=0; while(1){ lcdClear(); lcdPrintln("LED:"); lcdPrintln(""); lcdPrintln("U Toggle LEDs"); lcdPrintln("D Toggle ADC"); lcdPrintln(""); lcdDisplay(); switch(getInput()){ case BTN_UP: adc=0; leds=1-leds; SETUPgout(LED4); if(leds){ ON(LED1); ON(LED2); ON(LED3); ON(LED4); }else{ OFF(LED1); OFF(LED2); OFF(LED3); OFF(LED4); }; break; case BTN_DOWN: adc=1; SETUPadc(LED4); break; case BTN_ENTER: SETUPgout(LED1); SETUPgout(LED2); SETUPgout(LED3); SETUPgout(LED4); return; }; if(adc){ lcdPrint("LED4: "); lcdPrint(IntToStr(adc_get_single(ADC0,ADC_CR_CH6)*2*330/1023,4,F_LONG)); lcdNl(); lcdDisplay(); }; getInputWaitRelease(); }; };
void ram(void) { while(1) { if (!screen_intro()){ setTextColor(0xff,0x00); return; } game.rokets = 3; game.level = 1; game.score = 0; init_game(); screen_level(); while (game.rokets>=0) { ////checkISP(); lcdFill(0x00); check_end(); move_ufo(); move_shot(); move_shots(); move_player(); move_enemy(); draw_score(); draw_ufo(); draw_bunker(); draw_player(); draw_enemy(); draw_shots(); // draw_status(); lcdDisplay(); delayms(12); } if (!screen_gameover()) setTextColor(0xff,0x00); return; } }
void ram(void) { splash_scene(); long frame_count = 0; init_game(); while(1) { frame_count++; lcdFill(0); update_platforms(frame_count); move_player(frame_count); draw_platforms(); draw_player(); draw_hud(); blink_led(); lcdDisplay(); if(!game.running) { if(!gameover_scene()){ delayms_queue_plus(10,1); return; } init_game(); } delayms_queue_plus(24,0); } }
static bool gameover_scene() { int dy = getFontHeight(); int s1x = DoString(0, 0, "GAME OVER!"); s1x = (RESX-s1x)/2; int s2x = DoString(0, 0, "HIGHTSCORE!"); s2x = (RESX-s2x)/2; char key = 0; while(key != BTN_UP && key != BTN_DOWN) { lcdClear(); if(highscore_set(game.scroll_pos / 15, GLOBAL(nickname))) DoString (s2x, dy, "HIGHSCORE!"); else DoString(s1x, dy, "GAME OVER!"); int x = DoInt(0, 3*dy, game.scroll_pos / 15); DoChar(x, 3*dy, 'm'); DoString(0, 5*dy, "UP to play"); DoString(0, 6*dy, "DOWN to quit"); lcdDisplay(); key = getInputWaitTimeout(5000); } return !(key==BTN_DOWN); }
//# MENU rgb_leds void selectLedFile(void){ if(GLOBAL(rgbleds)) { if(init_selectFile("L3D")){ while(selectFileRepeat(GLOBAL(ledfile),"L3D") >= 0) { writeFile("ledfile.cfg", GLOBAL(ledfile), strlen(GLOBAL(ledfile))); init_rgbLeds(); } } } else { lcdClear(); lcdNl(); lcdPrintln("You need to enable"); lcdPrintln("<rgbleds> in the"); lcdPrintln("config to use"); lcdPrintln("this!"); lcdNl(); lcdPrintln(" LEFT: back"); lcdPrintln(" ENTER/RIGHT:"); lcdPrintln(" open config"); lcdDisplay(); while(1){ switch(getInput()){ case BTN_LEFT: return; case BTN_RIGHT: case BTN_ENTER: menu_config(); return; } } } }
void main_cdc(void) { int dx = 0; //lastTick = systickGetTicks(); // Used to control output/printf timing lcdPrintln("Init USB"); lcdRefresh(); CDC_Init(); // Initialise VCOM USB_Init(); // USB Initialization USB_Connect(TRUE); // USB Connect // Wait until USB is configured or timeout occurs uint32_t usbTimeout = 0; while ( usbTimeout < CFG_USBCDC_INITTIMEOUT / 10 ) { if (USB_Configuration) break; delayms(10); // Wait 10ms usbTimeout++; } lcdPrintln("Done"); lcdRefresh(); uint8_t buf[2] = {0,0}; int l; while(1){ CDC_OutBufAvailChar(&l); if( l ){ l = 1; CDC_RdOutBuf (buf, &l); puts(buf); dx=DoString(dx,0,buf); lcdDisplay(); } //puts("hello world\r\n"); //delayms(1); } }
int main(void) { cpu_clock_init(); /* CPU Clock is now 104 MHz */ ssp_clock_init(); systickInit(); SETUPgout(EN_VDD); SETUPgout(MIXER_EN); SETUPgout(MIC_AMP_DIS); SETUPgout(LED1); SETUPgout(LED2); SETUPgout(LED3); SETUPgout(LED4); inputInit(); lcdInit(); lcdFill(0xff); lcdPrintln("Flash-App"); lcdNl(); lcdDisplay(); cpld_flash(); cpu_clock_set(50); full_msc(); return 0; }
static void renderHighscore() { lcdClear(); if (points>highscore) { setTextColor(0xff,0b11100000); DoString(0,10, " NEW HIGHSCORE"); } setTextColor(0xff,0x00); DoString(0,RESY/2-33, " Your Score"); // Display own score in green color, if it's higher than high score, else red if (points>highscore) { setTextColor(0xff,0b00011100); } else { setTextColor(0xff,0b11100000); } DoString(RESX/2-4, RESY/2-25, IntToStr(points,6,0)); setTextColor(0xff,0x00); DoString(0,RESY/2-10, " Last Highscore"); setTextColor(0xff,0b00000011); DoString(RESX/2-4, RESY/2-2, IntToStr(highscore,6,0)); setTextColor(0xff,0x00); DoString(0, RESY/2+18, " UP to play "); DoString(0, RESY/2+26, "RIGHT to reset HI "); DoString(0, RESY/2+34, "DOWN to quit "); lcdDisplay(); }
void ram(void) { int c=0, pos=0,del=0; struct pos_s tail[MAX_SNAKE_LEN]; snake.tail = tail; // load the highscore highscore = highscore_get(); // initially reset everything reset(); while (1) { if(!(++c % snake.speed)) { handle_input(); pos = (snake.t_start+1) % MAX_SNAKE_LEN; snake.tail[pos].x = snake.tail[snake.t_start].x; snake.tail[pos].y = snake.tail[snake.t_start].y; if(snake.dir == 0) snake.tail[pos].x++; else if(snake.dir == 1) snake.tail[pos].y++; else if(snake.dir == 2) snake.tail[pos].x--; else if(snake.dir == 3) snake.tail[pos].y--; snake.t_start = pos; if (pos < snake.len) { del = MAX_SNAKE_LEN - (snake.len - pos); } else del = pos - snake.len; // remove last, add first line draw_block(snake.tail[del].x, snake.tail[del].y, 0xFF); draw_block(snake.tail[pos].x, snake.tail[pos].y, 0b00011000); // check for obstacle hit.. if (hitWall() || hitSelf()) { death_anim(); if (showHighscore()) break; reset(); } else if (hitFood()) next_level(); lcdDisplay(); } #ifdef SIMULATOR delayms(50); #else delayms(3); #endif } }
//# MENU MSC void msc_menu(){ MSCenable(); lcdPrintln("MSC enabled."); getInputWaitRelease(); while(getInputRaw()!=BTN_ENTER){ if(getInputRaw()==BTN_RIGHT) lcdPrintln("."); lcdDisplay(); __WFI(); }; lcdPrintln("disconnect"); lcdDisplay(); MSCdisable(); fsReInit(); getInputWaitRelease(); };
static bool screen_intro() { uint32_t highscore; char highnick[20]; char key=0; bool step = false; //getInputWaitRelease(); while(key==0) { getInputWaitRelease(); lcdFill(0x00); setIntFont(&Font_Invaders); setTextColor(0x00,0b11100000); lcdSetCrsr(28+18,25+15);lcdPrint(step?"ABC":"abc"); setIntFont(&Font_7x8); setTextColor(0x00,0b00011000); lcdSetCrsr(28+18,40+15);lcdPrint("SPACE"); setTextColor(0x00,0b11111000); lcdSetCrsr(18+18,50+15);lcdPrint("INVADERS"); highscore = highscore_get(highnick); setTextColor(0x00,0xff); lcdSetCrsr(0,0);lcdPrint(IntToStr(highscore,6,F_LONG)); // lcdSetCrsr(0,9);lcdPrint(highnick); lcdDisplay(); step = !step; key=getInputWaitTimeout(1000); } //getInputWaitRelease(); return !(key==BTN_LEFT); }
static void splash_scene() { uint32_t highscore; char highnick[20]; char key = 0; while(key == 0) { getInputWaitRelease(); int dy = getFontHeight(); int s1x = DoString(0, 0, "r0ket"); s1x = (RESX-s1x)/2; int s2x = DoString(0, 0, "JUMP!"); s2x = (RESX-s2x)/2; lcdFill(0); DoString(s1x, 3*dy, "r0ket"); DoString(s2x, 4*dy, "JUMP!"); DoString(0, 7*dy, "by webholics"); highscore = highscore_get(highnick); int s3x = DoInt(0, 0, highscore); DoChar(s3x, 0, 'm'); DoString (0, dy, highnick); lcdDisplay(); key = getInputWaitTimeout(1000); } }
static bool screen_intro() { uint32_t highscore; char highnick[20]; char key=0; bool step = false; //getInputWaitRelease(); while(key==0) { getInputWaitRelease(); lcdFill(0); font = &Font_Invaders; DoString(28,25,step?"ABC":"abc"); font = &Font_7x8; DoString (28,40,"SPACE"); DoString (18,50,"INVADERS"); highscore = highscore_get(highnick); DoInt(0, 0, highscore); DoString (0, 9, highnick); lcdDisplay(); step = !step; key=getInputWaitTimeout(1000); } //getInputWaitRelease(); return !(key==BTN_LEFT); }
void doExec(){ char filename[FLEN]; FATFS FatFs; FRESULT res; if(selectFile(filename,"BIN")){ lcdPrintln("Select ERROR"); lcdDisplay(); getInputWait(); return; }; lcdPrintln("Loading:"); lcdPrintln(filename); lcdDisplay(); bootFile(filename,1); };
static void refill_cpld_buffer_fs(void) { memcpy(cpld_xsvf_buffer,default_xsvf+bytes,BLOCK); lcdMoveCrsr(0,-8); bytes+=BLOCK; lcdPrint(IntToStr(bytes,5,F_LONG)); lcdPrint(" bytes..."); lcdNl(); lcdDisplay(); }
//# MENU CDC void cdc_menu(){ uint32_t prompt = 0, rdCnt = 0; static uint8_t g_rxBuff[256]; CDCenable(); lcdPrintln("CDC enabled."); lcdDisplay(); getInputWaitRelease(); while(getInputRaw()!=BTN_ENTER){ if(getInputRaw()==BTN_RIGHT){ lcdPrint("status:"); lcdPrint(IntToStr(g_vCOM.tx_flags,3,F_HEX)); lcdPrint(", "); lcdPrint("c="); lcdPrint(IntToStr(prompt,1,F_LONG)); lcdPrintln("."); lcdDisplay(); getInputWaitRelease(); }; if(getInputRaw()==BTN_LEFT){ vcom_write((uint8_t *)"Hello World!\r\n", 14); getInputWaitRelease(); }; if ((vcom_connected() != 0) && (prompt == 0)) { prompt = 1; } /* If VCOM port is opened echo whatever we receive back to host. */ if (prompt) { rdCnt = vcom_bread(&g_rxBuff[0], 256); if (rdCnt) { vcom_write((uint8_t*)"[", 1); while(g_vCOM.tx_flags & VCOM_TX_BUSY) __WFI(); // Wait for buffer emtpy vcom_write(&g_rxBuff[0], rdCnt); while(g_vCOM.tx_flags & VCOM_TX_BUSY) __WFI(); // Wait for buffer emtpy vcom_write((uint8_t*)"]", 1); } } /* Sleep until next IRQ happens */ __WFI(); }; lcdPrintln("disconnect"); lcdDisplay(); CDCdisable(); getInputWaitRelease(); }
static void screen_level() { lcdFill(0); draw_score(); font = &Font_7x8; int dx = DoString(20,32, "Level "); DoInt(dx,32,game.level); lcdDisplay(); delayms_queue(500); }
void bootFile(const char * filename, uint8_t write){ FIL file; UINT readbytes; FRESULT res; res=f_open(&file, filename, FA_OPEN_EXISTING|FA_READ); if(res!=F_OK){ lcdPrintln("FOPEN ERROR"); lcdPrintln(f_get_rc_string(res)); lcdDisplay(); getInputWait(); return; }; uint8_t *destination=&_app_start; #define BLOCK 1024 * 128 do { res=f_read(&file, destination, BLOCK, &readbytes); destination+=readbytes; }while(res==F_OK && readbytes==BLOCK); lcdDisplay(); if(res!=F_OK){ lcdPrint("Read Error:"); lcdPrintln(f_get_rc_string(res)); lcdDisplay(); getInputWait(); return; }; if(write){ res=writeFile(BOOTCFG, filename, strlen(filename)+1); if(res<0){ lcdPrint("write Error:"); lcdPrintln(f_get_rc_string(-res)); lcdDisplay(); getInputWait(); }; lcdPrint("write Done:"); lcdPrintln(IntToStr(res,3,0)); lcdPrintln(IntToStr(strlen(filename),3,0)); lcdDisplay(); getInputWait(); }; boot((void*)&_app_start); };
void ram(void){ if (lcdShowImageFile("nick.lcd") != 0) { lcdClear(); lcdNl(); lcdPrintln("File nick.lcd"); lcdPrintln("not present."); lcdNl(); lcdDisplay(); } }