X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Fradios%2Fnrf.c;h=6f65e0bfb09ce6698dca503474054d4e71b4722a;hp=f81afbafa9639f855dca25b9d12b0f42a2153fed;hb=12bb2a05d2b9a940f4bcdd7478d3c9d45cc8f50a;hpb=dffb4095b5c57ed45748646d224b719015ebd92f diff --git a/firmware/apps/radios/nrf.c b/firmware/apps/radios/nrf.c index f81afba..6f65e0b 100644 --- a/firmware/apps/radios/nrf.c +++ b/firmware/apps/radios/nrf.c @@ -15,27 +15,30 @@ #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) +//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 +#define CE BIT5; + +#define RADIOACTIVE P5OUT|=CE +#define RADIOPASSIVE P5OUT&=~CE //! Set up the pins for NRF mode. void nrfsetup(){ P5OUT|=SS; - P5DIR|=MOSI+SCK+SS; P5DIR&=~MISO; + P5DIR|=MOSI+SCK+SS+CE; + //Begin a new transaction. P5OUT&=~SS; P5OUT|=SS; } - //! 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,7 +62,28 @@ unsigned char nrftrans8(unsigned char byte){ } - +//! Writes a register +u8 nrf_regwrite(u8 reg, const u8 *buf, int len){ + P5OUT&=~SS; + + reg=nrftrans8(reg); + while(len--) + nrftrans8(*buf++); + + P5OUT|=SS; + return reg;//status +} +//! Reads a register +u8 nrf_regread(u8 reg, u8 *buf, int len){ + P5OUT&=~SS; + + reg=nrftrans8(reg); + while(len--) + *buf++=nrftrans8(0); + + P5OUT|=SS; + return reg;//status +} //! Handles a Nordic RF command. void nrfhandle(unsigned char app, @@ -67,13 +91,15 @@ void nrfhandle(unsigned char app, unsigned long len){ unsigned long i; + RADIOPASSIVE; + //Raise !SS to end transaction, just in case we forgot. P5OUT|=SS; nrfsetup(); switch(verb){ //PEEK and POKE might come later. - case READ: + case READ: case WRITE: P5OUT&=~SS; //Drop !SS to begin transaction. for(i=0;i