hook funk up to build. Add testing app, try to implement receiving

This commit is contained in:
Stefan `Sec` Zehl 2011-07-05 11:11:08 +02:00
parent 876ee2474f
commit f1c6b7c55c
4 changed files with 239 additions and 4 deletions

View File

@ -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)

View File

@ -0,0 +1,179 @@
#include <sysinit.h>
#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;
};

View File

@ -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;i<len;i++){
xmit_spi(data[i]);
};
};
void nrf_cmd_read_long(const uint8_t cmd, int *len, char* data){
xmit_spi(cmd);
// do i need to read the status byte here?
for(int i=0;i<*len;i++){
xmit_spi(0);
rcvr_spi_m(&data[i]);
};
};
void nrf_init() {
// Enable SPI correctly
sspInit(0, sspClockPolarity_Low, sspClockPhase_RisingEdge);
@ -72,6 +85,7 @@ void nrf_init() {
// Setup for nrf24l01+
// power up takes 1.5ms - 3.5ms (depending on crystal)
CS_LOW();
nrf_write_reg(R_CONFIG,
R_CONFIG_PRIM_RX| // Receive mode
R_CONFIG_PWR_UP| // Power on
@ -100,4 +114,32 @@ void nrf_init() {
nrf_write_reg(R_RF_SETUP,DEFAULT_SPEED|R_RF_SETUP_RF_PWR_3);
// XXX: or write R_CONFIG last?
CS_HIGH();
};
int nrf_rcv_pkt_time(int maxtime, int maxsize, char * pkt){
char buf;
int len;
CS_LOW();
nrf_write_reg(R_CONFIG,
R_CONFIG_PRIM_RX| // Receive mode
R_CONFIG_PWR_UP| // Power on
R_CONFIG_CRCO // 2-byte CRC
);
CE_HIGH();
delayms(maxtime); // XXX: check interrupt?
CE_LOW();
len=1;
nrf_cmd_read_long(C_R_RX_PL_WID,&len,&buf);
len=buf;
if(len>32 || 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;
};

View File

@ -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 */