X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=firmware%2Fapps%2Fradios%2Fnrf.c;h=ca701130eee5a896609bd16181be5d98048a89b2;hb=5fb51d7210531187ca33cf44f1126de793f94520;hp=f65d2e537e2a97a76995a677b8e923083133ff5a;hpb=8bba67a8aeb9e40bb81ba2749710b9fef660d689;p=goodfet diff --git a/firmware/apps/radios/nrf.c b/firmware/apps/radios/nrf.c index f65d2e5..ca70113 100644 --- a/firmware/apps/radios/nrf.c +++ b/firmware/apps/radios/nrf.c @@ -15,28 +15,21 @@ #include "nrf.h" #include "spi.h" -//Weird HOPE badge wiring. This was a fuckup. -//BIT0 should be SS, but in point of fact it is IRQ. -//BIT4 is actually SS, BIT5 is CE. -#define SS BIT4 - -//This could be more accurate. -//Does it ever need to be? -#define NRFSPEED 0 -#define NRFDELAY(x) -//delay(x) +#define RADIOACTIVE SETCE +#define RADIOPASSIVE CLRCE //! Set up the pins for NRF mode. void nrfsetup(){ - P5OUT|=SS; + SETSS; P5DIR&=~MISO; - P5DIR|=MOSI+SCK+SS; - + P5DIR|=MOSI+SCK; + DIRSS; + DIRCE; //Begin a new transaction. - P5OUT&=~SS; - P5OUT|=SS; + CLRSS; + SETSS; } //! Read and write an NRF byte. @@ -66,23 +59,25 @@ u8 nrftrans8(u8 byte){ //! Writes a register u8 nrf_regwrite(u8 reg, const u8 *buf, int len){ - P5OUT&=~SS; + CLRSS; reg=nrftrans8(reg); while(len--) nrftrans8(*buf++); - P5OUT|=SS; + SETSS; + return reg;//status } //! Reads a register u8 nrf_regread(u8 reg, u8 *buf, int len){ - P5OUT&=~SS; + CLRSS; reg=nrftrans8(reg); while(len--) *buf++=nrftrans8(0); - P5OUT|=SS; + SETSS; + return reg;//status } //! Handles a Nordic RF command. @@ -91,43 +86,73 @@ void nrfhandle(unsigned char app, unsigned long len){ unsigned long i; + //Drop CE to passify radio. + RADIOPASSIVE; //Raise !SS to end transaction, just in case we forgot. - P5OUT|=SS; + SETSS; nrfsetup(); - + switch(verb){ //PEEK and POKE might come later. case READ: case WRITE: - P5OUT&=~SS; //Drop !SS to begin transaction. + CLRSS; //Drop !SS to begin transaction. for(i=0;i