X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Fradios%2Fnrf.c;h=76c396c6c5a0cafe61b79d30daae3623b686fee2;hp=90fc1a9f55939b8e7fb429621501eafbbc9430b3;hb=6373a97ac3426c9d9966cf6a08286ecd13cc2ced;hpb=c59e00857cea5dba2c38dcb5070594a237c297a6 diff --git a/firmware/apps/radios/nrf.c b/firmware/apps/radios/nrf.c index 90fc1a9..76c396c 100644 --- a/firmware/apps/radios/nrf.c +++ b/firmware/apps/radios/nrf.c @@ -9,41 +9,52 @@ #include "command.h" #include -#include +#include #include #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 +//! Handles a Nordic RF command. +void nrf_handle_fn( uint8_t const app, + uint8_t const verb, + uint32_t const len); + +// define the nrf app's app_t +app_t const nrf_app = { + + /* app number */ + NRF, -//This could be more accurate. -//Does it ever need to be? -#define NRFSPEED 0 -#define NRFDELAY(x) -//delay(x) + /* handle fn */ + nrf_handle_fn, + /* name */ + "NRF", + + /* desc */ + "\tThe NRF app adds support for the NordicRF register\n" + "\tinterface.\n" +}; + +#define RADIOACTIVE SETCE +#define RADIOPASSIVE CLRCE //! Set up the pins for NRF mode. void nrfsetup(){ - P5OUT|=SS; - P5DIR&=~MISO; - P5DIR|=MOSI+SCK+SS; - + SETSS; + SPIDIR&=~MISO; + SPIDIR|=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. @@ -67,49 +78,103 @@ 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){ +void nrf_handle_fn( uint8_t const app, + uint8_t const verb, + uint32_t const 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 READ: case WRITE: - P5OUT&=~SS; //Drop !SS to begin transaction. + CLRSS; //Drop !SS to begin transaction. for(i=0;i