diff --git a/firmware/funk/Makefile b/firmware/funk/Makefile index 4fdde2b..88dbfc0 100644 --- a/firmware/funk/Makefile +++ b/firmware/funk/Makefile @@ -32,5 +32,5 @@ $(LIBFILE): $(OBJS) clean: rm -f $(OBJS) $(LIBFILE) -nrf24l01p.o: nrf24l01p.h +nrf24l01p.o: nrf24l01p.c nrf24l01p.h diff --git a/firmware/funk/nrf24l01p.c b/firmware/funk/nrf24l01p.c index 921b9e2..d63c4b5 100644 --- a/firmware/funk/nrf24l01p.c +++ b/firmware/funk/nrf24l01p.c @@ -7,69 +7,58 @@ #define MAC_BEACON "BEACO" /*-----------------------------------------------------------------------*/ -/* Transmit a byte via SPI (Platform dependent) */ +/* Transmit a byte via SPI */ /*-----------------------------------------------------------------------*/ -void xmit_spi(uint8_t dat) { +inline void xmit_spi(uint8_t dat) { sspSend(0, (uint8_t*) &dat, 1); } -/*-----------------------------------------------------------------------*/ -/* Receive a byte from MMC via SPI (Platform dependent) */ -/*-----------------------------------------------------------------------*/ -uint8_t rcvr_spi (void) { - uint8_t data = 0; - - sspReceive(0, &data, 1); - - return data; -} - -#define rcvr_spi_m(dst) \ - do { \ - sspReceive(0, (uint8_t*)(dst), 1); \ - } while(0) - #define CS_LOW() gpioSetValue(RB_SPI_NRF_CS, 0) #define CS_HIGH() gpioSetValue(RB_SPI_NRF_CS, 1) #define CE_LOW() gpioSetValue(RB_NRF_CE, 0) #define CE_HIGH() gpioSetValue(RB_NRF_CE, 1) void nrf_cmd(uint8_t cmd){ + CS_LOW(); xmit_spi(cmd); + CS_HIGH(); }; uint8_t nrf_cmd_status(uint8_t cmd){ + CS_LOW(); sspSendReceive(0, &cmd, 1); return cmd; + CS_HIGH(); }; +void nrf_cmd_rw_long(uint8_t* data, int len){ + CS_LOW(); + sspSendReceive(0,data,len); + CS_HIGH(); +}; + + void nrf_write_reg(const uint8_t reg, const uint8_t val){ + CS_LOW(); xmit_spi(C_W_REGISTER | reg); xmit_spi(val); + CS_HIGH(); }; -/* -uint8_t nrf_read_reg(const uint8_t reg, uint8_t val){ - xmit_spi(C_R_REGISTER | reg); - // do i need to read the status byte here? - xmit_spi(val); - return rcvr_spi(); -}; -*/ - -void nrf_write_reg_long(const uint8_t reg, int len, char* data){ - xmit_spi(C_W_REGISTER | reg); - for(int i=0;i32 || len==0){ return 0; // no packet @@ -138,7 +125,7 @@ int nrf_rcv_pkt_time(int maxtime, int maxsize, char * pkt){ if(len>maxsize){ return -1; // packet too large }; - nrf_cmd_read_long(C_R_RX_PAYLOAD,&len,pkt); + nrf_read_long(C_R_RX_PAYLOAD,len,pkt); CS_HIGH(); return len; }; diff --git a/firmware/funk/nrf24l01p.h b/firmware/funk/nrf24l01p.h index a19b6ab..6996bd0 100644 --- a/firmware/funk/nrf24l01p.h +++ b/firmware/funk/nrf24l01p.h @@ -93,13 +93,15 @@ #define R_RF_SETUP_DR_250K 0x20 /* exported functions */ -int nrf_rcv_pkt_time(int maxtime, int maxsize, char * pkt); +int nrf_rcv_pkt_time(int maxtime, int maxsize, uint8_t * pkt); void nrf_init() ; -void nrf_cmd_read_long(const uint8_t cmd, int *len, char* data); -void nrf_write_reg_long(const uint8_t reg, int len, char* data); -void nrf_write_reg(const uint8_t reg, const uint8_t val); -uint8_t nrf_cmd_status(uint8_t cmd); + void nrf_cmd(uint8_t cmd); +uint8_t nrf_cmd_status(uint8_t cmd); +void nrf_cmd_rw_long(uint8_t* data, int len); +void nrf_read_long(const uint8_t reg, int len, uint8_t* data); +void nrf_write_reg(const uint8_t reg, const uint8_t val); +void nrf_write_reg_long(const uint8_t reg, int len, uint8_t* data); /* END */