X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Fradios%2Fnrf.c;h=ca701130eee5a896609bd16181be5d98048a89b2;hp=d105af547e08ecd6054ce7cfa68a2d86bc8256cf;hb=97143fece53250662a3ffd22f141619a4902eda7;hpb=b0274fc1ffccf73492660c02600e8df12c0ba5b2 diff --git a/firmware/apps/radios/nrf.c b/firmware/apps/radios/nrf.c index d105af5..ca70113 100644 --- a/firmware/apps/radios/nrf.c +++ b/firmware/apps/radios/nrf.c @@ -15,27 +15,25 @@ #include "nrf.h" #include "spi.h" -//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; - P5DIR|=MOSI+SCK+SS; + SETSS; P5DIR&=~MISO; + P5DIR|=MOSI+SCK; + DIRSS; + DIRCE; //Begin a new transaction. - P5OUT&=~SS; - P5OUT|=SS; + CLRSS; + SETSS; } - //! Read and write an NRF byte. -unsigned char nrftrans8(unsigned char byte){ +u8 nrftrans8(u8 byte){ register unsigned int bit; //This function came from the NRF Wikipedia article. //Minor alterations. @@ -59,47 +57,102 @@ unsigned char nrftrans8(unsigned char byte){ } +//! Writes a register +u8 nrf_regwrite(u8 reg, const u8 *buf, int len){ + CLRSS; + + reg=nrftrans8(reg); + while(len--) + nrftrans8(*buf++); + + SETSS; + return reg;//status +} +//! Reads a register +u8 nrf_regread(u8 reg, u8 *buf, int len){ + CLRSS; + + reg=nrftrans8(reg); + while(len--) + *buf++=nrftrans8(0); + + SETSS; + return reg;//status +} + //! Handles a Nordic RF command. void nrfhandle(unsigned char app, unsigned char verb, 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(); - debugstr("NRF Handler"); - switch(verb){ //PEEK and POKE might come later. - case READ: + case READ: case WRITE: - P5OUT&=~SS; //Drop !SS to begin transaction. + CLRSS; //Drop !SS to begin transaction. for(i=0;i