X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Fradios%2Fnrf.c;h=e607bf61c5426921764ef72eaabc3eae7e949611;hp=f65d2e537e2a97a76995a677b8e923083133ff5a;hb=9a334c8d47da8f96662e1fa2c424d383004ab873;hpb=8bba67a8aeb9e40bb81ba2749710b9fef660d689 diff --git a/firmware/apps/radios/nrf.c b/firmware/apps/radios/nrf.c index f65d2e5..e607bf6 100644 --- a/firmware/apps/radios/nrf.c +++ b/firmware/apps/radios/nrf.c @@ -15,28 +15,42 @@ #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, + + /* handle fn */ + nrf_handle_fn, -//This could be more accurate. -//Does it ever need to be? -#define NRFSPEED 0 -#define NRFDELAY(x) -//delay(x) + /* 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. @@ -66,68 +80,101 @@ 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. -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 WRITE: - P5OUT&=~SS; //Drop !SS to begin transaction. + CLRSS; //Drop !SS to begin transaction. for(i=0;i