From f1c6b7c55c8515edabecc58912abda1e68c31e7f Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 5 Jul 2011 11:11:08 +0200 Subject: [PATCH] hook funk up to build. Add testing app, try to implement receiving --- firmware/Makefile | 6 +- firmware/applications/funk.c | 179 +++++++++++++++++++++++++++++++++++ firmware/funk/nrf24l01p.c | 48 +++++++++- firmware/funk/nrf24l01p.h | 10 ++ 4 files changed, 239 insertions(+), 4 deletions(-) create mode 100644 firmware/applications/funk.c diff --git a/firmware/Makefile b/firmware/Makefile index 1c474c6..65dbcf0 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -9,7 +9,7 @@ VPATH += OBJS += OBJS += basic/basic.o basic/reinvoke_isp.o basic/delayms.o basic/voltage.o OBJS += basic/keyin.o basic/uuid.o -LIBS += core/libcore.a lcd/liblcd.a applications/libapp.a filesystem/libfat.a usb/libusb.a +LIBS += core/libcore.a lcd/liblcd.a applications/libapp.a filesystem/libfat.a usb/libusb.a funk/libfunk.a ########################################################################## # GNU GCC compiler flags @@ -28,6 +28,7 @@ OBJS += $(TARGET)_handlers.o LPC1xxx_startup.o ########################################################################## LDLIBS = -lm LDLIBS += -Lapplications -lapp +LDLIBS += -Lfunk -lfunk LDLIBS += -Llcd -llcd LDLIBS += -Lusb -lusb LDLIBS += -Lfilesystem -lfat @@ -78,6 +79,9 @@ filesystem/libfat.a: usb/libusb.a: cd usb && $(MAKE) ROOT_PATH=../$(ROOT_PATH) +funk/libfunk.a: + cd funk && $(MAKE) ROOT_PATH=../$(ROOT_PATH) + ../tools/bootloader/lpcfix: cd ../tools/bootloader && $(MAKE) diff --git a/firmware/applications/funk.c b/firmware/applications/funk.c new file mode 100644 index 0000000..641813b --- /dev/null +++ b/firmware/applications/funk.c @@ -0,0 +1,179 @@ +#include + +#include "basic/basic.h" + +#include "lcd/render.h" +#include "lcd/backlight.h" +#include "lcd/allfonts.h" + +#include "funk/nrf24l01p.h" + +/**************************************************************************/ + +void f_init(void){ + nrf_init(); +}; + +void f_status(void){ + int status; + int dx=0; + status=nrf_cmd_status(C_NOP); + dx=DoString(0,8,"Status:"); + DoIntX(dx,8,status); +}; + +void f_recv(void){ +}; + +void gotoISP(void) { + DoString(0,0,"Enter ISP!"); + lcdDisplay(0); + ISPandReset(5); +} + +/**************************************************************************/ + +struct MENU_DEF { + char *text; + void (*callback)(void); +}; + +typedef const struct MENU_DEF * menuentry; + +struct MENU { + char *title; + menuentry *entries; +}; + +const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP}; +const struct MENU_DEF menu_init = {"F Init", &f_init}; +const struct MENU_DEF menu_status = {"F Status", &f_status}; +const struct MENU_DEF menu_rcv = {"F Recv", &f_recv}; +const struct MENU_DEF menu_nop = {"---", NULL}; + +static menuentry menu[] = { + &menu_init, + &menu_status, + &menu_rcv, + &menu_nop, + &menu_ISP, + NULL, +}; + +static const struct MENU mainmenu = {"Mainmenu", menu}; + +void handleMenu(const struct MENU *the_menu) ; + +void main_funk(void) { + + backlightInit(); + + while (1) { + lcdFill(0); // clear display buffer + lcdDisplay(0); + handleMenu(&mainmenu); + gotoISP(); + } + + return; +} + +void handleMenu(const struct MENU *the_menu) { + uint8_t back = 0; + int8_t menuselection = 0; + uint8_t numentries = 0; + uint8_t visible_lines = 0; + uint8_t current_offset = 0; + + if (the_menu == NULL) return; + + font = &Font_7x8; + + for (numentries = 0; the_menu->entries[numentries] != NULL; numentries++); + + visible_lines = RESY/font->u8Height; + + if (visible_lines < 2) return; + + visible_lines--; // subtract title line + + while (!back) { + uint8_t line = 0; + + lcdFill(0); // clear display buffer + + DoString(0, line, the_menu->title); + line += font->u8Height; + + for (uint8_t i = current_offset; i < (visible_lines + current_offset) && i < numentries; i++) { + DoString(14, line, the_menu->entries[i]->text); + if (i == menuselection) { + DoString(0, line, "* "); + } + line += font->u8Height; + } + + lcdDisplay(0); + + switch (getInput()) { + case BTN_UP: + menuselection--; + if (menuselection < current_offset) { + if (menuselection < 0) { + menuselection = numentries-1; + current_offset = ((numentries-1)/visible_lines) * visible_lines; + } else { + current_offset -= visible_lines; + } + } + break; + case BTN_DOWN: + menuselection++; + if (menuselection > (current_offset + visible_lines-1) || menuselection >= numentries) { + if (menuselection >= numentries) { + menuselection = 0; + current_offset = 0; + } else { + current_offset += visible_lines; + } + } + break; + case BTN_LEFT: + return; + case BTN_RIGHT: + if (the_menu->entries[menuselection]->callback!=NULL) + the_menu->entries[menuselection]->callback(); + while (getInput()==BTN_NONE) delayms(10); + break; + case BTN_ENTER: + lcdFill(0); + DoString(0,0,"Called...."); + lcdDisplay(0); + if (the_menu->entries[menuselection]->callback!=NULL) + the_menu->entries[menuselection]->callback(); + lcdDisplay(0); + while (getInput()==BTN_NONE) delayms(10); + + break; + default: + /* no button pressed */ + break; + } + + } + + return; +} + + +void tick_funk(void){ + static int foo=0; + static int toggle=0; + if(foo++>50){ + toggle=1-toggle; + foo=0; + gpioSetValue (RB_LED0, toggle); + }; + return; +}; + diff --git a/firmware/funk/nrf24l01p.c b/firmware/funk/nrf24l01p.c index 45c37e1..13ae5ba 100644 --- a/firmware/funk/nrf24l01p.c +++ b/firmware/funk/nrf24l01p.c @@ -31,6 +31,8 @@ uint8_t rcvr_spi (void) { #define CS_LOW() gpioSetValue(RB_SPI_NRF_CS, 0) #define CS_HIGH() gpioSetValue(RB_SPI_NRF_CS, 1) +#define CE_LOW() gpioSetValue(RB_NRF_CE, 0) +#define CE_HIGH() gpioSetValue(RB_NRF_CE, 1) void nrf_cmd(uint8_t cmd){ xmit_spi(cmd); @@ -41,25 +43,36 @@ uint8_t nrf_cmd_status(uint8_t cmd){ return rcvr_spi(); }; -void nrf_write_reg(uint8_t reg, uint8_t val){ +void nrf_write_reg(const uint8_t reg, const uint8_t val){ xmit_spi(C_W_REGISTER | reg); xmit_spi(val); }; -uint8_t nrf_read_reg(uint8_t reg, uint8_t val){ +/* +uint8_t nrf_read_reg(const uint8_t reg, uint8_t val){ xmit_spi(C_R_REGISTER | reg); // do i need to read the status byte here? xmit_spi(val); return rcvr_spi(); }; +*/ -void nrf_write_reg_long(uint8_t reg, int len, char* data){ +void nrf_write_reg_long(const uint8_t reg, int len, char* data){ xmit_spi(C_W_REGISTER | reg); for(int i=0;i32 || len==0){ + return 0; // no packet + }; + if(len>maxsize){ + return -1; // packet too large + }; + nrf_cmd_read_long(C_R_RX_PAYLOAD,&len,pkt); + CS_HIGH(); + return len; }; diff --git a/firmware/funk/nrf24l01p.h b/firmware/funk/nrf24l01p.h index 454d28f..a19b6ab 100644 --- a/firmware/funk/nrf24l01p.h +++ b/firmware/funk/nrf24l01p.h @@ -92,5 +92,15 @@ #define R_RF_SETUP_DR_2M 0x08 #define R_RF_SETUP_DR_250K 0x20 +/* exported functions */ +int nrf_rcv_pkt_time(int maxtime, int maxsize, char * pkt); +void nrf_init() ; +void nrf_cmd_read_long(const uint8_t cmd, int *len, char* data); +void nrf_write_reg_long(const uint8_t reg, int len, char* data); +void nrf_write_reg(const uint8_t reg, const uint8_t val); +uint8_t nrf_cmd_status(uint8_t cmd); +void nrf_cmd(uint8_t cmd); + +/* END */ #endif /* _NRF24L01P_H */