Example #1
0
File: cdc.c Project: Bediko/r0ket
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);
    }
}
Example #2
0
void ram(void) {
    struct NRF_CFG config;
    uint8_t buf[16];
    
    // Space to save signal strength and username.
    uint8_t count = 0;
    char usernames[8][16];
    uint8_t strength[8];

    config.nrmacs=1;
    config.maclen[0] = 16;
    config.channel = 81;
    memcpy(config.mac0, "\x01\x02\x03\x02\x01", 5);
    nrf_config_set(&config);
    lcdClear();
    lcdPrintln("Track it:");
    lcdPrintln("---------");
    lcdRefresh();
    do{
        if( nrf_rcv_pkt_time(64,sizeof(buf),buf) == 16 ){
            buf[14] = 0;
            // TODO: allow last package parameter 0x25
            if( buf[1] == 0x23 || buf[1] == 0x24){
                if(0==insertUser(usernames, strength, (char *)buf+6, buf[3],
                  count)) {
                  if(count<8) ++count;
                  printNames(usernames, strength, count);
                }
            }
        }
    }while ((getInputRaw())==BTN_NONE);
}
Example #3
0
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);
};
Example #4
0
void playGame(void)
{
    int len;
    struct packet p;
    lcdPrintln("Now playing:");
    lcdPrintln(gameTitle);
    lcdRefresh();

    while(1){
        uint8_t button = getInputRaw();
        sendButton(button);
        
        while(1){
            if( flags & FLAGS_LONG_RECV )
                len = nrf_rcv_pkt_time(64,sizeof(p),(uint8_t*)&p);
            else
                len = nrf_rcv_pkt_time(32,sizeof(p),(uint8_t*)&p);
                
            if(len==sizeof(p)){
                processPacket(&p);
            }else{
                break;
            }
        }
        int rnd = getRandom() % jitter;
        delayms(interval*5+rnd);
        
        volatile uint16_t i;
        i = getRandom()&0xfff;
        while(i--);

    };
}
Example #5
0
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();
};
Example #6
0
//# 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);
};
Example #7
0
void main_final(void) {
    init_nick();
	if(GLOBAL(privacy)>2){ //firstboot
        if(execute_file("1boot.int",0,0)){
            lcdPrintln("Badge SETUP");
            lcdPrintln("error.");
            lcdPrintln("Features may");
            lcdPrintln("be broken.");
            lcdRefresh();
            getInputWait();
            getInputWaitRelease();
            GLOBAL(privacy)=0;
        }else{
            saveConfig();
        };
    };
    //checkFirstBoot();
    init_final();
    menuflags|=MENU_TIMEOUT;

    while(1){
#ifndef FINAL
        if(getInputRaw()==BTN_LEFT)
            ISPandReset();
#endif
        if(getInput()){
            handleMenu(&mainmenu);
            getInputWaitRelease();
            init_nick();
        };
        work_queue();
        fancyNickname();
    };
};
Example #8
0
File: spam.c Project: astro/lun1k
void ram() {
    lcdClear();

    lcdPrintln("SPAM:");
    while(getInputRaw() != BTN_LEFT) {
        char c[2] = {0, 0};
        c[0] = (char)getRandom();

        uint8_t pkt[32];
        MO_TYPE_set(pkt, c[0]);
        MO_GEN_set(pkt, 0xFF);
        if (c[0] >= 'A' && c[0] <= 'Z')
            MO_TIME_set(pkt, 1313803870);
        else if (c[0] >= 'a' && c[0] <= 'z')
            MO_TIME_set(pkt, getRandom() % 16777216);
        else
            MO_TIME_set(pkt, (uint32_t)getRandom());
        strcpy((char *)MO_BODY(pkt), "chaosbay.camp.ccc.de");

        if (!mesh_sanity(pkt)) {
            lcdPrint("Sending: ");
            lcdPrintln(c);
            lcdRefresh();

            MPKT *mpkt = meshGetMessage(c[0]);
            mpkt->flags = MF_USED;
            memcpy(mpkt->pkt, pkt, 32);
        }
    }
}
Example #9
0
void ram(void) {
    lcdClear();
    lcdPrintln("r0ket");
    lcdPrintln("Release: ");
    lcdPrintln(IntToStrX(getrelease(),8));
    lcdRefresh();
    while(!getInputRaw())work_queue();
}
Example #10
0
void board_menu_draw(board_t* b)
{
  setTextColor(0, 0xff);
  setIntFont(&Font_7x8);

  const int lineh = getFontHeight();

  lcdSetCrsr(0, 0);
  lcdPrintln("0xb number game");
  lcdPrintln("Push < > ^ v");
  lcdPrintln("Add same blocks");
  lcdPrint("Try to reach '");
  setTextColor(colors[N_COLORS-1].bg, colors[N_COLORS-1].fg);
  lcdPrint("b");
  setTextColor(0, 0xff);
  lcdPrintln("'!");
  lcdNl();

  for (uint i = 0; i < menu_N; i ++) {
    if (i == b->menu_item)
      lcdPrint(">> ");
    else
      lcdPrint("   ");
    lcdPrint(menu_str[i]);

    switch (i) {
      case 3:
        // width
        lcdPrint(" = ");
        lcdPrint(IntToStr(b->w, 2, 0));
        break;
      case 4:
        // height
        lcdPrint(" = ");
        lcdPrint(IntToStr(b->h, 2, 0));
      default:
        break;
    }
    lcdNl();
  }

  if (b->menu_item == 2) {
    lcdPrintln(font_list[b->font]);
    if (b->font == FONT_NONE) {
      uint w = RESX / N_COLORS;
      for (uint8_t i = 0; i < N_COLORS; i++) {
        const color_t* col = colors + i;
        setTextColor(col->bg, col->fg);
        DoRect(i*w, 120, w, 10);
      }
    }
    else {
      setExtFont(font_list[b->font]);
      lcdPrint("789ab");
    }
  }
}
Example #11
0
void ram(void){
  if (lcdShowImageFile("nick.lcd") != 0) {
    lcdClear();
    lcdNl();
    lcdPrintln("File nick.lcd");
    lcdPrintln("not present.");
    lcdNl();
    lcdDisplay();
  }
}
Example #12
0
//# MENU config
void changer(void){
    if(execute_file("config.int")){
        lcdClear();
        lcdPrintln("config");
        lcdPrintln("l0dable");
        lcdPrintln("not found");
        lcdRefresh();
        getInputWait();
        getInputWaitRelease();
    }
}
Example #13
0
void full_msc() {
    MSCenable();
    lcdPrintln("MSC enabled.");
    lcdDisplay();
    while(getInputRaw()!=BTN_ENTER) {
        __WFI();
    };
    lcdPrintln("MSC disabled");
    lcdDisplay();
    MSCdisable();
};
Example #14
0
void printNames(char (*usernames)[16], uint8_t * strength, uint8_t count) {
  int i;
  lcdPrintln("Track it:");
  lcdPrintln("-------------------");
  lcdPrintln(IntToStr(count,5,0));
  for(i=0; i<count; ++i) {
    lcdPrint(usernames[i]);
    lcdPrint(" strength ");
    lcdPrintln(IntToStr(strength[i],5,0));
  }
  lcdRefresh();
}
Example #15
0
void msc_menu(void){
    MSCenable();
    lcdPrintln("MSC enabled.");
    lcdDisplay();
    getInputWaitRelease();
    getInputWait();
    lcdPrintln("disconnect");
    lcdDisplay();
    MSCdisable();
    fsReInit();
    getInputWaitRelease();
}
Example #16
0
int main(uint32_t startloc) {
	cpu_clock_init();
	ssp_clock_init();
	systickInit();

//	cpu_clock_set(204);

	SETUPgout(EN_VDD);
	SETUPgout(MIXER_EN);
	SETUPgout(MIC_AMP_DIS);

	SETUPgout(LED1);
	SETUPgout(LED2);
	SETUPgout(LED3);
	SETUPgout(LED4);
	inputInit();
	flashInit();

	lcdInit();
	fsInit();
	lcdFill(0xff); /* Display BL Image here */

	sli=startloc;

	if (startloc != (uintptr_t)&_app_start){ /* not booted via DFU, do autoboot */ 
        char filename[FLEN];
        switch(getInputRaw()){
            case BTN_LEFT:
                getInputWaitRelease();
                doRealExec(1);
                break;
            case BTN_UP:
                doMSC();
            default:
            case BTN_NONE:
                readTextFile(BOOTCFG, filename, FLEN);
                lcdPrintln("Booting:");
                lcdPrintln(filename);
                bootFile(filename);
                break;
		};
	};
	static const struct MENU main={ "Bootloader", {
		{ "Exec Firmware", &doExec},
		{ "MSC", &doMSC},
		{ "Flash Boot Ldr", &doFlash},
		{ "Info", &doInfo},
		{NULL,NULL}
	}};
	do {
		handleMenu(&main);
	}while(1);
}
Example #17
0
/** reaction.c
 *  First l0dable for my r0ket
 *  Improvement is welcome
 *
 * AUTHOR: hubba
*/
void ram(void)
{
    char x = gpioGetValue(RB_LED1);
    int rand_wait = 0;
    int react_time=0;
    int start_time = 0;
    int end_time = 0;

    gpioSetValue (RB_LED1,0);           //upperleft LED off
    lcdClear();
    lcdPrintln("Hello");
    lcdPrintln(GLOBAL(nickname));
    lcdPrintln("ReACTION");
    lcdRefresh();
    delayms(500);
    while(1)
    {
        react_time = 0;
        lcdPrintln("Press ENTER if ");
        lcdPrintln("LED is on!");
        lcdRefresh();
        rand_wait = getRandom();
        rand_wait = rand_wait%50;
        rand_wait = 40 + rand_wait*4;        // Minimum pause time is 400ms
        for(int i =0; i<=rand_wait; i++)     //directly calling delayms(rand_wait) didn't work
        {
            delayms(10);
        }
        gpioSetValue (RB_LED1, 1);          //upperleft LED ON
        getInputWaitRelease();
        start_time = getTimer()*(SYSTICKSPEED);
        while (getInputWait() != BTN_ENTER);    //wait for user input
        {

        }
        end_time =  getTimer()*(SYSTICKSPEED);
        react_time = end_time - start_time;     //measure  used time
        lcdClear();
        lcdPrint("Needed ");
        lcdPrintInt(react_time);
        lcdPrintln(" ms");
        lcdPrintln("DOWN: Exit");
        lcdPrintln("0ther: New game");
        lcdRefresh();
        gpioSetValue (RB_LED1,0);           //upperleft LED off

        getInputWaitRelease();
        if(getInputWait() ==  BTN_DOWN)     //Check for Exit/new game
        {
            gpioSetValue (RB_LED1, x);      //upperleft LED as before l0dable executed
            return;
        }
    }
    /* NEVER LAND HERE */
    lcdPrintln("Flow-Error");
    lcdRefresh();
    return;
};
Example #18
0
//# 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();
	};
};
Example #19
0
void fsInit(){
	FRESULT res;
	res=f_mount(&FatFs,"/",0);
	if(res == FR_OK){
		DIR dir;                /* Directory object */
		res = f_opendir(&dir, "0:");
	};
	if(res != FR_OK){
		lcdPrintln("FS init error");
		lcdPrintln(f_get_rc_string(res));
		lcdDisplay();
		getInputWait();
		return;
	};
}
Example #20
0
int input_int(char prompt[], int initial, int min, int max, int digits) {
	setSystemFont();
  setTextColor(0xFF,0x00);
	intinInit(prompt, initial, min, max, digits);
	while (!s_int.done) {
		intinDraw();
		lcdDisplay();
		intinMove();
    intinClean();
	}
  lcdPrintln("");
  lcdPrint("number: ");
  lcdPrintln(IntToStr(s_int.the_number,s_int.digits,F_LONG|F_ZEROS));
	return s_int.the_number;
}
Example #21
0
//# 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();
};
Example #22
0
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;
}
Example #23
0
int saveConfig(void){
    FIL file;            /* File object */
    UINT writebytes;
    UINT allwrite=0;
    int res;
#if DEBUG
    lcdClear();
#endif

	res=f_open(&file, CONFFILE, FA_OPEN_ALWAYS|FA_WRITE);
#if DEBUG
	lcdPrint("create:");
	lcdPrintln(f_get_rc_string(res));
#endif
	if(res){
		return 1;
	};

    CONF_ITER{
        res = f_write(&file, &the_config[i].value, sizeof(uint8_t), &writebytes);
        allwrite+=writebytes;
        if(res){
#if DEBUG
            lcdPrint("write:");
            lcdPrintln(f_get_rc_string(res));
#endif
            return 1;
        };
    };
#if DEBUG
	lcdPrint("write:");
	lcdPrintln(f_get_rc_string(res));
	lcdPrint(" (");
	lcdPrintInt(allwrite);
	lcdPrintln("b)");
#endif

	res=f_close(&file);
#if DEBUG
	lcdPrint("close:");
	lcdPrintln(f_get_rc_string(res));
#endif
	if(res){
		return 1;
	};
	return 0;
}
Example #24
0
//# MENU nick changeFont
void doFont(void){
    getInputWaitRelease();
    if( selectFile(GLOBAL(nickfont),"F0N") != 0){
        lcdPrintln("No file selected.");
        return;
    };
	writeFile("font.cfg",GLOBAL(nickfont),strlen(GLOBAL(nickfont)));

    lcdClear();
    setIntFont(&Font_7x8);
    lcdPrintln("Test:");
    setExtFont(GLOBAL(nickfont));
    lcdPrintln(GLOBAL(nickname));
    lcdDisplay();
    setIntFont(&Font_7x8);
    while(!getInputRaw())delayms(10);
}
Example #25
0
void startServer(void){
	mode = MODE_SERVER;
	lcdClear();
	lcdPrintln("Server started");
	lcdRefresh();

	configNrf();
}
Example #26
0
//# MENU rgb_leds
void selectLedFile(void){
    if( selectFile(GLOBAL(ledfile),"L3D") != 0){
        lcdPrintln("No file selected.");
        return;
    };
	writeFile("ledfile.cfg",GLOBAL(ledfile),strlen(GLOBAL(ledfile)));
	init_rgbLeds();
}
Example #27
0
uint8_t joinGame()
{
    int i;
    struct packet p;
    struct packet ack;
    memset((void*)&p, 0, sizeof(p));
    memset((void*)&ack, 0, sizeof(ack));
    p.len=sizeof(p); 
    p.protocol='G';
    p.command='J';
    p.id= id;
    p.ctr= ++ctr;
    p.c.join.gameId=gameId;
    lcdPrintln("Joining game");
    lcdRefresh();

    for(i=0; i<10; i++){
        nrf_snd_pkt_crc(sizeof(p),(uint8_t*)&p);

        int len = nrf_rcv_pkt_time(30,sizeof(ack),(uint8_t*)&ack);
        if( len==sizeof(ack) ){
            if( (ack.len==32) && (ack.protocol=='G') && ack.command=='a' ){   //check sanity, protocol
                if( ack.id == id && ack.ctr == ctr ){
                    if( ack.c.ack.flags & FLAGS_ACK_JOINOK ){
                        lcdPrintln("Join OK");
                        lcdRefresh();
                        return 1;
                    }else{
                        lcdPrintln("Join rejected");
                        lcdRefresh();
                        getInputWait();
                        getInputWaitRelease();
                        return 0;
                    }
                }
            }
        }
        delayms(70);
    }
    lcdPrintln("timeout :(");
    lcdRefresh();
    getInputWait();
    getInputWaitRelease();

    return 0;
}
Example #28
0
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);

};
Example #29
0
//# 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();
}
Example #30
0
//# 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;
            }
        }
    }
}