diff --git a/firmware/applications/s.c b/firmware/applications/s.c index e6d4910..f047c80 100644 --- a/firmware/applications/s.c +++ b/firmware/applications/s.c @@ -5,120 +5,34 @@ #include "lcd/render.h" #include "lcd/allfonts.h" -void ReinvokeISP(void); -void EnableWatchdog(uint32_t ms); -void delayms(uint32_t ms); +void backlightInit(void); /**************************************************************************/ void main_s(void) { - //Make PIO1_11 an analog input - gpioSetDir(RB_LED3, gpioDirection_Input); - IOCON_PIO1_11 = 0x41; - - backlightInit(); - - uint32_t j=0; - - //disable the JTAG on PIO3_3 - IOCON_PIO3_3 = 0x10; - - int yctr=8; - int dx=0; - - font_direction = FONT_DIR_LTR; // LeftToRight is the default - font = &Font_8x8; - - static FONT fonts[] = { - &Font_7x8, - &Font_Ubuntu18pt, // 3 byte-font - &Font_8x8, - }; - - int fontctr=0; - yctr=18; - - uint8_t trigger; - -#define SEND -#ifdef SEND - trigger=200; - gpioSetDir(RB_LED0, gpioDirection_Output); - IOCON_JTAG_TDI_PIO0_11 = 0x11; -#else - trigger=380; - gpioSetDir(RB_LED0, gpioDirection_Input); - IOCON_JTAG_TDI_PIO0_11 = 0x42; -#endif - - - uint32_t ctr=0; + uint8_t key; + //lcdClear(); while (1) { - ctr++; - uint32_t results; - lcdDisplay(); - delayms(10); + uint8_t contrast = lcdRead(0xDF); + lcdInit(); // display + lcdPrint("reg="); + lcdPrintCharHex(contrast); + lcdNl(); + lcdDisplay(); + while(1); + delayms(500); - font=fonts[fontctr]; + //key= getInputWait(); - if(gpioGetValue(RB_BTN3)==0){ - while(gpioGetValue(RB_BTN3)==0); - trigger +=10; - }; - if(gpioGetValue(RB_BTN2)==0){ - while(gpioGetValue(RB_BTN2)==0); - trigger -=10; - }; - //dx=DoString(0,0,"Trig:"); - //dx=DoInt(dx,0,trigger); - //DoString(dx,0," "); - - if(gpioGetValue(RB_BTN0)==0){ - while(gpioGetValue(RB_BTN0)==0); - DoString(0,8,"Enter ISP!"); - lcdDisplay(); - EnableWatchdog(1000*5); - ReinvokeISP(); - }; - - font = &Font_Ubuntu36pt; - static uint8_t ctrx=0, ctry=0, dirx=1, diry=1; - dx=DoString(ctrx,ctry,"S"); - if( dirx ){ - if(ctrx++ == 60) - dirx = 0; - }else{ - if(ctrx-- == 0) - dirx=1; + // Easy flashing + if(key==BTN_LEFT){ + DoString(0,8,"Enter ISP!"); + lcdDisplay(); + ISPandReset(); + } } - if( diry ){ - if(ctry++ == 12) - diry = 0; - }else{ - if(ctry-- == 0) - diry=1; - } - font = &Font_7x8; - - results = adcRead(1); - //dx=DoString(0,yctr+28,"Voltage:"); - results *= 10560; - results /= 1024; - //DoInt(dx,yctr+28,results); - - if( results < 3500 ){ - DoString(0,yctr+30,"Shutdown"); - gpioSetValue (RB_PWR_GOOD, 0); - gpioSetValue (RB_LCD_BL, 0); - SCB_SCR |= SCB_SCR_SLEEPDEEP; - PMU_PMUCTRL = PMU_PMUCTRL_DPDEN_DEEPPOWERDOWN; - __asm volatile ("WFI"); - }else{ - //DoString(0,yctr+30,"OK "); - ; - } - - } - - return; } + +void tick_minimal(void){ + return; +}; diff --git a/firmware/l0dable/EXPORTS b/firmware/l0dable/EXPORTS index 05a3962..ea15048 100644 --- a/firmware/l0dable/EXPORTS +++ b/firmware/l0dable/EXPORTS @@ -35,3 +35,15 @@ push_queue the_config the_queue work_queue +selectFile +nrf_snd_pkt_crc_encr +nrf_rcv_pkt_time_encr +getInput +ECIES_encyptkeygen +f_open +f_read +strlen +strcpy +xxtea_encode_words +getRandom +crc16 diff --git a/firmware/l0dable/loadable.ld b/firmware/l0dable/loadable.ld index fb4d66c..b569c2f 100644 --- a/firmware/l0dable/loadable.ld +++ b/firmware/l0dable/loadable.ld @@ -1,5 +1,5 @@ MEMORY { - sram(rwx): ORIGIN = 0x10002000 - 2048, LENGTH = 2048 + sram(rwx): ORIGIN = 0x10002000 - 2548, LENGTH = 2548 } INCLUDE ram.ld diff --git a/firmware/l0dable/sendcard.c b/firmware/l0dable/sendcard.c new file mode 100644 index 0000000..8bcf110 --- /dev/null +++ b/firmware/l0dable/sendcard.c @@ -0,0 +1,284 @@ +#include +#include +#include +#include +#include +#include "basic/basic.h" +#include "lcd/render.h" +#include "lcd/allfonts.h" +#include "basic/ecc.h" +#include "funk/nrf24l01p.h" +#include "filesystem/ff.h" +#include "filesystem/diskio.h" +#include "funk/filetransfer.h" +#include "lcd/print.h" +#include +#include "funk/nrf24l01p.h" +#include "funk/filetransfer.h" +#include "funk/rftransfer.h" +#include "basic/basic.h" +#include "basic/xxtea.h" +#include "filesystem/ff.h" +#include "funk/rftransfer.h" +#include "funk/nrf24l01p.h" +#include +#include +#include +//#include + +#include "usetable.h" + +//#include "lcd/print.h" + + + +uint8_t mac[5] = {1,2,3,2,1}; + +void ram(void) +{ + char file[13]; + selectFile(file,"TXT"); + sendFile(file); +} + +void sendR(uint8_t *rx, uint8_t *ry) +{ + uint8_t exp[2 + 4*NUMWORDS + 2]; + exp[0] = 'R'; + for(int i=0; i<4*NUMWORDS; i++) + exp[2+i] = rx[i]; + exp[1] = 'X'; + nrf_snd_pkt_crc(32, exp); + delayms(10); + exp[1] = 'Y'; + for(int i=0; i<4*NUMWORDS; i++) + exp[2+i] = ry[i]; + nrf_snd_pkt_crc(32, exp); + delayms(10); +} + +int receiveKey(uint8_t type, uint8_t *x, uint8_t *y) +{ + uint8_t buf[32]; + uint8_t n; + + n = nrf_rcv_pkt_time(1000, 32, buf); + if( n == 32 && buf[0] == type && buf[1] == 'X' ){ + for(int i=0; i MAXSIZE ) + return 1; //File to big + + res=f_open(&file, (const char*)filename, FA_OPEN_EXISTING|FA_READ); + if( res ) + return res; + + //res = f_read(&file, (char *)buf, size, &readbytes); + for(uint16_t i=0; i> 8; + metadata[21] = size & 0xFF; + + //nrf_get_tx_max(5,macbuf); + + //nrf_set_tx_mac(5, mac); + nrf_snd_pkt_crc_encr(32, metadata, k); + delayms(20); + xxtea_encode_words((uint32_t *)buf, wordcount, k); + rftransfer_send(wordcount*4, buf); + //nrf_set_tx_mac(5, macbuf); + return 0; +} + +#define MAXPACKET 32 +void rftransfer_send(uint16_t size, uint8_t *data) +{ + uint8_t buf[MAXPACKET]; + buf[0] = 'L'; + buf[1] = size >> 8; + buf[2] = size & 0xFF; + + uint16_t rand = getRandom() & 0xFFFF; + buf[3] = rand >> 8; + buf[4] = rand & 0xFF; + + nrf_snd_pkt_crc(32,buf); //setup packet + delayms(20); + uint16_t index = 0; + uint8_t i; + uint16_t crc = crc16(data,size); + + while(size){ + buf[0] = 'D'; + buf[1] = index >> 8; + buf[2] = index & 0xFF; + buf[3] = rand >> 8; + buf[4] = rand & 0xFF; + for(i=5; i0; i++,size--){ + buf[i] = *data++; + } + index++; + nrf_snd_pkt_crc(32,buf); //data packet + delayms(20); + } + + buf[0] = 'C'; + buf[1] = crc >> 8; + buf[2] = crc & 0xFF; + buf[3] = rand >> 8; + buf[4] = rand & 0xFF; + nrf_snd_pkt_crc(32,buf); //setup packet + delayms(20); +} + diff --git a/firmware/loadable/spaceinvaders.c b/firmware/loadable/spaceinvaders.c index c4f6457..fbcf38a 100644 --- a/firmware/loadable/spaceinvaders.c +++ b/firmware/loadable/spaceinvaders.c @@ -1,15 +1,13 @@ #include +#include #include "basic/basic.h" +#include "basic/random.h" #include "lcd/render.h" #include "lcd/display.h" #include "lcd/allfonts.h" -void ReinvokeISP(void); -void EnableWatchdog(uint32_t ms); -void delayms(uint32_t ms); - /**************************************************************************/ #define POS_PLAYER_Y 60 #define POS_PLAYER_X RESX/2-3 @@ -20,11 +18,11 @@ void delayms(uint32_t ms); #define UFO_PROB 1024 -#define TYPE_PLAYER 1 +#define TYPE_PLAYER 1 #define TYPE_ENEMY_A 3 #define TYPE_ENEMY_B 2 #define TYPE_ENEMY_C 4 -#define TYPE_UFO 5 +#define TYPE_UFO 5 #define BUNKERS 3 #define BUNKER_WIDTH 10 @@ -52,16 +50,19 @@ struct gamestate { char key; void init_game(); +void init_enemy(); void check_end(); void move_ufo(); +void move_shot(); void move_shots(); void move_player(); -void move_enemay(); +void move_enemy(); void draw_score(); void draw_bunker(); void draw_player(); void draw_enemy(); void draw_shots(); +void draw_sprite(char type, char x, char y); void draw_ufo(); void screen_intro(); void screen_gameover(); @@ -150,14 +151,20 @@ void init_game(void) { game.shot_y = 0; game.alive = ENEMY_ROWS*ENEMY_COLUMNS; game.move = 0; - game.direction = -1; - game.lastcol = ENEMY_COLUMNS-1; + if (getRandom()%2 == 0) { + game.direction = -1; + game.lastcol = ENEMY_COLUMNS-1; + } else { + game.direction = 1; + game.lastcol = 0; + } game.killed = 0; game.step = false; game.ufo = DISABLED; + game.score = 0; init_enemy(); - for (char col=0; colBUNKER_X[BUNKERS-1-b] && -// game.shot_xRESY-16) { -// int offset = BUNKER_WIDTH - (game.shot_x-BUNKER_X[BUNKERS-1-b]); -// if (game.bunker[b][offset]!=0) { -// game.bunker[b][offset]&=game.bunker[b][offset]<<1; -// game.shot_x=DISABLED; -// } -// } -// } - if (check_bunker(game.shot_x,game.shot_y-5,1 )) + + if (check_bunker(game.shot_x,game.shot_y-5,1 )) game.shot_x=DISABLED; //check for collision with enemy, kill enemy if @@ -242,12 +236,13 @@ void move_shot() { game.enemy_x[row][col]=DISABLED; game.shot_x = DISABLED; game.alive--; - game.score++; + game.score+=(3-row)*10; return; } } } } + //check for collision with ufo if (game.ufo != DISABLED && game.shot_x>game.ufo && @@ -255,7 +250,7 @@ void move_shot() { game.shot_y<8) { game.ufo = DISABLED; - game.score += 5; + game.score += 50; } game.shot_y -= 2; @@ -265,10 +260,10 @@ void move_shot() { void move_shots() { - for (char col = 0; colBUNKER_X[BUNKERS-1-b] && -// game.shots_x[col]RESY-16) { -// int offset = BUNKER_WIDTH - (game.shots_x[col]-BUNKER_X[BUNKERS-1-b])-1; -// if (game.bunker[b][offset]!=0) { -// game.bunker[b][offset]&=game.bunker[b][offset]>>1; -// game.shots_x[col]=DISABLED; -// } -// } -// } - //check for collision with player - + //check for collision with player if (game.shots_y[col] >= RESY-13 && game.shots_x[col] > game.player+1 && game.shots_x[col] < game.player+6) { @@ -363,25 +345,12 @@ void move_enemy() { game.killed = true; } check_bunker(pos,game.enemy_row_y[row]+8,-2); - //check for collision with bunker, dirty - // for (int b=0; b=BUNKER_X[BUNKERS-1-b] && - // pos<=BUNKER_X[BUNKERS-1-b]+BUNKER_WIDTH && - // game.enemy_row_y[row]+8RESY-16) { - // int offset = BUNKER_WIDTH - (pos-BUNKER_X[BUNKERS-1-b]); - // if (game.bunker[b][offset]!=0) { - // game.bunker[b][offset]&=game.bunker[b][offset]>>2; - // } - // } - // } - - + //Are we at the beginning or end? Direction change if((pos <=0 && game.direction != 1) || (pos >=RESX-10 && game.direction == 1)){ game.direction = (game.direction==1)?-1:1; - for (char r = 0; r=23?4:2; } return; @@ -395,7 +364,6 @@ void move_enemy() { } void draw_player() { - //draw_sprite(50, 20); draw_sprite(TYPE_PLAYER, game.player, POS_PLAYER_Y); } @@ -427,7 +395,7 @@ void draw_shots() { } } - for (char col = 0; col < ENEMY_COLUMNS; col++) { + for (int col = 0; col < ENEMY_COLUMNS; col++) { if (game.shots_x[col] != DISABLED) { for (int length=0; length<=5; length++) { lcdSetPixel(game.shots_x[col], game.shots_y[col]+length,true);