#include #include #include "core/ssp/ssp.h" #define CHANNEL_BEACON 81 #define DEFAULT_SPEED R_RF_SETUP_DR_2M #define MAC_BEACON "BEACO" /*-----------------------------------------------------------------------*/ /* Transmit a byte via SPI */ /*-----------------------------------------------------------------------*/ inline void xmit_spi(uint8_t dat) { sspSend(0, (uint8_t*) &dat, 1); } #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(); }; void nrf_read_long(const uint8_t reg, int len, uint8_t* data){ CS_LOW(); xmit_spi(reg); for(int i=0;i32 || len==0){ return 0; // no packet }; if(len>maxsize){ return -1; // packet too large }; nrf_read_long(C_R_RX_PAYLOAD,len,pkt); CS_HIGH(); return len; };