From 587469e398d78ce42b4bff93d7d4ee282583a842 Mon Sep 17 00:00:00 2001 From: Domen Ipavec Date: Tue, 22 Oct 2013 17:02:03 +0200 Subject: [PATCH] Added read, write options with constants --- cc1101.cpp | 42 ++++++++++++++++++++++++++ cc1101.h | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 127 insertions(+), 1 deletion(-) diff --git a/cc1101.cpp b/cc1101.cpp index bc45e6f..ba597f2 100644 --- a/cc1101.cpp +++ b/cc1101.cpp @@ -32,6 +32,7 @@ using namespace avr_cpp_lib; CC1101::CC1101(transceive_t t, OutputPin csn, InputPin so) : transceive(t), CSn(csn), SO(so) { + CSn.set(); } void CC1101::reset() { @@ -43,3 +44,44 @@ void CC1101::reset() { command(SRES); while (SO.isSet()); } + +void CC1101::command(const uint8_t address) { + CSn.clear(); + transceive(address); + CSn.set(); +} + +void CC1101::write(const uint8_t address, const uint8_t data) { + CSn.clear(); + transceive(address); + transceive(data); + CSn.set(); +} + +void CC1101::writeBurst(const uint8_t address, const uint8_t * data, uint8_t n) { + CSn.clear(); + transceive(address | BURST); + for (; n > 0; n--) { + transceive(*data); + data++; + } + CSn.set(); +} + +uint8_t CC1101::read(const uint8_t address) { + CSn.clear(); + transceive(address | READ); + uint8_t tmp = transceive(0); + CSn.set(); + return tmp; +} + +void CC1101::readBurst(const uint8_t address, uint8_t * data, uint8_t n) { + CSn.clear(); + transceive(address | READ | BURST); + for (; n > 0; n--) { + *data = transceive(0); + data++; + } + CSn.set(); +} diff --git a/cc1101.h b/cc1101.h index baa3557..fe9d036 100644 --- a/cc1101.h +++ b/cc1101.h @@ -38,7 +38,12 @@ namespace avr_cpp_lib { public: CC1101(transceive_t t, OutputPin csn, InputPin so); void reset(); - inline void command(const uint8_t address) { transceive(address); } + void command(const uint8_t address); + void write(const uint8_t address, const uint8_t data); + void writeBurst(const uint8_t address, const uint8_t * data, uint8_t n); + uint8_t read(const uint8_t address); + void readBurst(const uint8_t address, uint8_t * data, uint8_t n); + private: transceive_t transceive; OutputPin CSn; @@ -48,7 +53,86 @@ namespace avr_cpp_lib { static const uint8_t READ = 0x80; static const uint8_t BURST = 0x40; public: + // commands static const uint8_t SRES = 0x30; + static const uint8_t SFSTXON = 0x31; + static const uint8_t SXOFF = 0x32; + static const uint8_t SCAL = 0x33; + static const uint8_t SRX = 0x34; + static const uint8_t STX = 0x35; + static const uint8_t SIDLE = 0x36; + static const uint8_t SWOR = 0x38; + static const uint8_t SPWD = 0x39; + static const uint8_t SFRX = 0x3A; + static const uint8_t SFTX = 0x3B; + static const uint8_t SWORRST = 0x3C; + static const uint8_t SNOP = 0x3D; + + // addresses + static const uint8_t IOCFG2 = 0X00; + static const uint8_t IOCFG1 = 0X01; + static const uint8_t IOCFG0 = 0X02; + static const uint8_t FIFOTHR = 0X03; + static const uint8_t SYNC1 = 0X04; + static const uint8_t SYNC0 = 0X05; + static const uint8_t PKTLEN = 0X06; + static const uint8_t PKTCTRL1 = 0X07; + static const uint8_t PKTCTRL0 = 0X08; + static const uint8_t ADDR = 0X09; + static const uint8_t CHANNR = 0X0A; + static const uint8_t FSCTRL1 = 0X0B; + static const uint8_t FSCTRL0 = 0X0C; + static const uint8_t FREQ2 = 0X0D; + static const uint8_t FREQ1 = 0X0E; + static const uint8_t FREQ0 = 0X0F; + static const uint8_t MDMCFG4 = 0X10; + static const uint8_t MDMCFG3 = 0X11; + static const uint8_t MDMCFG2 = 0X12; + static const uint8_t MDMCFG1 = 0X13; + static const uint8_t MDMCFG0 = 0X14; + static const uint8_t DEVIATN = 0X15; + static const uint8_t MCSM2 = 0X16; + static const uint8_t MCSM1 = 0X17; + static const uint8_t MCSM0 = 0X18; + static const uint8_t FOCCFG = 0X19; + static const uint8_t BSCFG = 0X1A; + static const uint8_t AGCTRL2 = 0X1B; + static const uint8_t AGCTRL1 = 0X1C; + static const uint8_t AGCTRL0 = 0X1D; + static const uint8_t WOREVT1 = 0X1E; + static const uint8_t WOREVT0 = 0X1F; + static const uint8_t WORCTRL = 0X20; + static const uint8_t FREND1 = 0X21; + static const uint8_t FREND0 = 0X22; + static const uint8_t FSCAL3 = 0X23; + static const uint8_t FSCAL2 = 0X24; + static const uint8_t FSCAL1 = 0X25; + static const uint8_t FSCAL0 = 0X26; + static const uint8_t RCCTRL1 = 0X27; + static const uint8_t RCCTRL0 = 0X28; + static const uint8_t FSTEST = 0X29; + static const uint8_t PTEST = 0X2A; + static const uint8_t AGCTEST = 0X2B; + static const uint8_t TEST2 = 0X2C; + static const uint8_t TEST1 = 0X2D; + static const uint8_t TEST0 = 0X2E; + static const uint8_t PATABLE = 0X3E; + static const uint8_t FIFO = 0X3F; + // these are only readable with burst mode + static const uint8_t PARTNUM = 0X30; + static const uint8_t VERSION = 0X31; + static const uint8_t FREQEST = 0X32; + static const uint8_t LQI = 0X33; + static const uint8_t RSSI = 0X34; + static const uint8_t MARCSTATE = 0X35; + static const uint8_t WORTIME1 = 0X36; + static const uint8_t WORTIME0 = 0X37; + static const uint8_t PKTSTATUS = 0X38; + static const uint8_t VCO_VC_DAC = 0X39; + static const uint8_t TXBYTES = 0X3A; + static const uint8_t RXBYTES = 0X3B; + static const uint8_t RCCTRL1_STATUS = 0X3C; + static const uint8_t RCCTRL0_STATUS = 0X3D; }; }