X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Fradios%2Fnrf.c;h=76c396c6c5a0cafe61b79d30daae3623b686fee2;hp=1e1f937a7b98bfa4ebfb5852af4cf3890c4d8d8c;hb=6373a97ac3426c9d9966cf6a08286ecd13cc2ced;hpb=8013ee4ccda1a36d1e92de299710b1709b010c33 diff --git a/firmware/apps/radios/nrf.c b/firmware/apps/radios/nrf.c index 1e1f937..76c396c 100644 --- a/firmware/apps/radios/nrf.c +++ b/firmware/apps/radios/nrf.c @@ -9,32 +9,48 @@ #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 -#define CE BIT5; +//! 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, -#define RADIOACTIVE P5OUT|=CE -#define RADIOPASSIVE P5OUT&=~CE + /* 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+CE; - + SETSS; + SPIDIR&=~MISO; + SPIDIR|=MOSI+SCK; + DIRSS; + DIRCE; //Begin a new transaction. - P5OUT&=~SS; - P5OUT|=SS; + CLRSS; + SETSS; } //! Read and write an NRF byte. @@ -64,65 +80,66 @@ 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