[CC1101] General reformatting

This commit is contained in:
jgromes 2023-04-23 09:47:42 +02:00
parent 78a576df12
commit 5c6628b6eb
2 changed files with 667 additions and 702 deletions

View file

@ -3,19 +3,19 @@
#if !defined(RADIOLIB_EXCLUDE_CC1101) #if !defined(RADIOLIB_EXCLUDE_CC1101)
CC1101::CC1101(Module* module) : PhysicalLayer(RADIOLIB_CC1101_FREQUENCY_STEP_SIZE, RADIOLIB_CC1101_MAX_PACKET_LENGTH) { CC1101::CC1101(Module* module) : PhysicalLayer(RADIOLIB_CC1101_FREQUENCY_STEP_SIZE, RADIOLIB_CC1101_MAX_PACKET_LENGTH) {
_mod = module; this->mod = module;
} }
Module* CC1101::getMod() { Module* CC1101::getMod() {
return(_mod); return(this->mod);
} }
int16_t CC1101::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLength) { int16_t CC1101::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLength) {
// set module properties // set module properties
_mod->SPIreadCommand = RADIOLIB_CC1101_CMD_READ; this->mod->SPIreadCommand = RADIOLIB_CC1101_CMD_READ;
_mod->SPIwriteCommand = RADIOLIB_CC1101_CMD_WRITE; this->mod->SPIwriteCommand = RADIOLIB_CC1101_CMD_WRITE;
_mod->init(); this->mod->init();
_mod->hal->pinMode(_mod->getIrq(), _mod->hal->GpioModeInput); this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput);
// try to find the CC1101 chip // try to find the CC1101 chip
uint8_t i = 0; uint8_t i = 0;
@ -26,14 +26,14 @@ int16_t CC1101::begin(float freq, float br, float freqDev, float rxBw, int8_t po
flagFound = true; flagFound = true;
} else { } else {
RADIOLIB_DEBUG_PRINTLN("CC1101 not found! (%d of 10 tries) RADIOLIB_CC1101_REG_VERSION == 0x%04X, expected 0x0004/0x0014", i + 1, version); RADIOLIB_DEBUG_PRINTLN("CC1101 not found! (%d of 10 tries) RADIOLIB_CC1101_REG_VERSION == 0x%04X, expected 0x0004/0x0014", i + 1, version);
_mod->hal->delay(10); this->mod->hal->delay(10);
i++; i++;
} }
} }
if(!flagFound) { if(!flagFound) {
RADIOLIB_DEBUG_PRINTLN("No CC1101 found!"); RADIOLIB_DEBUG_PRINTLN("No CC1101 found!");
_mod->term(); this->mod->term();
return(RADIOLIB_ERR_CHIP_NOT_FOUND); return(RADIOLIB_ERR_CHIP_NOT_FOUND);
} else { } else {
RADIOLIB_DEBUG_PRINTLN("M\tCC1101"); RADIOLIB_DEBUG_PRINTLN("M\tCC1101");
@ -68,7 +68,7 @@ int16_t CC1101::begin(float freq, float br, float freqDev, float rxBw, int8_t po
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// configure default preamble length // configure default preamble length
state = setPreambleLength(preambleLength); state = setPreambleLength(preambleLength, preambleLength - 4);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set default data shaping // set default data shaping
@ -85,37 +85,48 @@ int16_t CC1101::begin(float freq, float br, float freqDev, float rxBw, int8_t po
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// flush FIFOs // flush FIFOs
SPIsendCommand(RADIOLIB_CC1101_CMD_FLUSH_RX); SPIsendCommand(RADIOLIB_CC1101_CMD_FLUSH_RX | RADIOLIB_CC1101_CMD_READ);
SPIsendCommand(RADIOLIB_CC1101_CMD_FLUSH_TX); SPIsendCommand(RADIOLIB_CC1101_CMD_FLUSH_TX);
return(state); return(state);
} }
void CC1101::reset() {
// this is the manual power-on-reset sequence
this->mod->hal->digitalWrite(this->mod->getCs(), LOW);
this->mod->hal->delayMicroseconds(5);
this->mod->hal->digitalWrite(this->mod->getCs(), HIGH);
this->mod->hal->delayMicroseconds(40);
this->mod->hal->digitalWrite(this->mod->getCs(), LOW);
this->mod->hal->delay(10);
SPIsendCommand(RADIOLIB_CC1101_CMD_RESET);
}
int16_t CC1101::transmit(uint8_t* data, size_t len, uint8_t addr) { int16_t CC1101::transmit(uint8_t* data, size_t len, uint8_t addr) {
// calculate timeout (5ms + 500 % of expected time-on-air) // calculate timeout (5ms + 500 % of expected time-on-air)
uint32_t timeout = 5000000 + (uint32_t)((((float)(len * 8)) / (_br * 1000.0)) * 5000000.0); uint32_t timeout = 5000000 + (uint32_t)((((float)(len * 8)) / (this->bitRate * 1000.0)) * 5000000.0);
// start transmission // start transmission
int16_t state = startTransmit(data, len, addr); int16_t state = startTransmit(data, len, addr);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// wait for transmission start or timeout // wait for transmission start or timeout
uint32_t start = _mod->hal->micros(); uint32_t start = this->mod->hal->micros();
while(!_mod->hal->digitalRead(_mod->getGpio())) { while(!this->mod->hal->digitalRead(this->mod->getGpio())) {
_mod->hal->yield(); this->mod->hal->yield();
if(_mod->hal->micros() - start > timeout) { if(this->mod->hal->micros() - start > timeout) {
finishTransmit(); finishTransmit();
return(RADIOLIB_ERR_TX_TIMEOUT); return(RADIOLIB_ERR_TX_TIMEOUT);
} }
} }
// wait for transmission end or timeout // wait for transmission end or timeout
start = _mod->hal->micros(); start = this->mod->hal->micros();
while(_mod->hal->digitalRead(_mod->getGpio())) { while(this->mod->hal->digitalRead(this->mod->getGpio())) {
_mod->hal->yield(); this->mod->hal->yield();
if(_mod->hal->micros() - start > timeout) { if(this->mod->hal->micros() - start > timeout) {
finishTransmit(); finishTransmit();
return(RADIOLIB_ERR_TX_TIMEOUT); return(RADIOLIB_ERR_TX_TIMEOUT);
} }
@ -126,18 +137,18 @@ int16_t CC1101::transmit(uint8_t* data, size_t len, uint8_t addr) {
int16_t CC1101::receive(uint8_t* data, size_t len) { int16_t CC1101::receive(uint8_t* data, size_t len) {
// calculate timeout (500 ms + 400 full max-length packets at current bit rate) // calculate timeout (500 ms + 400 full max-length packets at current bit rate)
uint32_t timeout = 500000 + (1.0/(_br*1000.0))*(RADIOLIB_CC1101_MAX_PACKET_LENGTH*400.0); uint32_t timeout = 500000 + (1.0/(this->bitRate*1000.0))*(RADIOLIB_CC1101_MAX_PACKET_LENGTH*400.0);
// start reception // start reception
int16_t state = startReceive(); int16_t state = startReceive();
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// wait for packet or timeout // wait for packet or timeout
uint32_t start = _mod->hal->micros(); uint32_t start = this->mod->hal->micros();
while(!_mod->hal->digitalRead(_mod->getIrq())) { while(!this->mod->hal->digitalRead(this->mod->getIrq())) {
_mod->hal->yield(); this->mod->hal->yield();
if(_mod->hal->micros() - start > timeout) { if(this->mod->hal->micros() - start > timeout) {
standby(); standby();
SPIsendCommand(RADIOLIB_CC1101_CMD_FLUSH_RX); SPIsendCommand(RADIOLIB_CC1101_CMD_FLUSH_RX);
return(RADIOLIB_ERR_RX_TIMEOUT); return(RADIOLIB_ERR_RX_TIMEOUT);
@ -153,7 +164,7 @@ int16_t CC1101::standby() {
SPIsendCommand(RADIOLIB_CC1101_CMD_IDLE); SPIsendCommand(RADIOLIB_CC1101_CMD_IDLE);
// set RF switch (if present) // set RF switch (if present)
_mod->setRfSwitchState(Module::MODE_IDLE); this->mod->setRfSwitchState(Module::MODE_IDLE);
return(RADIOLIB_ERR_NONE); return(RADIOLIB_ERR_NONE);
} }
@ -172,7 +183,7 @@ int16_t CC1101::transmitDirectAsync(uint32_t frf) {
int16_t CC1101::transmitDirect(bool sync, uint32_t frf) { int16_t CC1101::transmitDirect(bool sync, uint32_t frf) {
// set RF switch (if present) // set RF switch (if present)
_mod->setRfSwitchState(Module::MODE_TX); this->mod->setRfSwitchState(Module::MODE_TX);
// user requested to start transmitting immediately (required for RTTY) // user requested to start transmitting immediately (required for RTTY)
if(frf != 0) { if(frf != 0) {
@ -202,7 +213,7 @@ int16_t CC1101::receiveDirectAsync() {
int16_t CC1101::receiveDirect(bool sync) { int16_t CC1101::receiveDirect(bool sync) {
// set RF switch (if present) // set RF switch (if present)
_mod->setRfSwitchState(Module::MODE_RX); this->mod->setRfSwitchState(Module::MODE_RX);
// activate direct mode // activate direct mode
int16_t state = directMode(sync); int16_t state = directMode(sync);
@ -216,31 +227,33 @@ int16_t CC1101::receiveDirect(bool sync) {
int16_t CC1101::packetMode() { int16_t CC1101::packetMode() {
int16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_PKTCTRL1, RADIOLIB_CC1101_CRC_AUTOFLUSH_OFF | RADIOLIB_CC1101_APPEND_STATUS_ON | RADIOLIB_CC1101_ADR_CHK_NONE, 3, 0); int16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_PKTCTRL1, RADIOLIB_CC1101_CRC_AUTOFLUSH_OFF | RADIOLIB_CC1101_APPEND_STATUS_ON | RADIOLIB_CC1101_ADR_CHK_NONE, 3, 0);
state |= SPIsetRegValue(RADIOLIB_CC1101_REG_PKTCTRL0, RADIOLIB_CC1101_WHITE_DATA_OFF | RADIOLIB_CC1101_PKT_FORMAT_NORMAL, 6, 4); state |= SPIsetRegValue(RADIOLIB_CC1101_REG_PKTCTRL0, RADIOLIB_CC1101_WHITE_DATA_OFF | RADIOLIB_CC1101_PKT_FORMAT_NORMAL, 6, 4);
state |= SPIsetRegValue(RADIOLIB_CC1101_REG_PKTCTRL0, RADIOLIB_CC1101_CRC_ON | _packetLengthConfig, 2, 0); state |= SPIsetRegValue(RADIOLIB_CC1101_REG_PKTCTRL0, RADIOLIB_CC1101_CRC_ON | this->packetLengthConfig, 2, 0);
return(state); return(state);
} }
void CC1101::setGdo0Action(void (*func)(void), uint32_t dir) { void CC1101::setGdo0Action(void (*func)(void), uint32_t dir) {
_mod->hal->attachInterrupt(_mod->hal->pinToInterrupt(_mod->getIrq()), func, dir); this->mod->hal->attachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq()), func, dir);
} }
void CC1101::clearGdo0Action() { void CC1101::clearGdo0Action() {
_mod->hal->detachInterrupt(_mod->hal->pinToInterrupt(_mod->getIrq())); this->mod->hal->detachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq()));
}
} }
void CC1101::setGdo2Action(void (*func)(void), uint32_t dir) { void CC1101::setGdo2Action(void (*func)(void), uint32_t dir) {
if(_mod->getGpio() == RADIOLIB_NC) { if(this->mod->getGpio() == RADIOLIB_NC) {
return; return;
} }
_mod->hal->pinMode(_mod->getGpio(), _mod->hal->GpioModeInput); this->mod->hal->pinMode(this->mod->getGpio(), this->mod->hal->GpioModeInput);
_mod->hal->attachInterrupt(_mod->hal->pinToInterrupt(_mod->getGpio()), func, dir); this->mod->hal->attachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getGpio()), func, dir);
} }
void CC1101::clearGdo2Action() { void CC1101::clearGdo2Action() {
if(_mod->getGpio() == RADIOLIB_NC) { if(this->mod->getGpio() == RADIOLIB_NC) {
return; return;
} }
_mod->hal->detachInterrupt(_mod->hal->pinToInterrupt(_mod->getGpio())); this->mod->hal->detachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getGpio()));
} }
int16_t CC1101::startTransmit(uint8_t* data, size_t len, uint8_t addr) { int16_t CC1101::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
@ -256,16 +269,16 @@ int16_t CC1101::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
SPIsendCommand(RADIOLIB_CC1101_CMD_FLUSH_TX); SPIsendCommand(RADIOLIB_CC1101_CMD_FLUSH_TX);
// set GDO0 mapping // set GDO0 mapping
int16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_IOCFG2, RADIOLIB_CC1101_GDOX_SYNC_WORD_SENT_OR_RECEIVED, 5, 0); int16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_IOCFG2, RADIOLIB_CC1101_GDOX_SYNC_WORD_SENT_OR_PKT_RECEIVED, 5, 0);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// data put on FIFO. // data put on FIFO
uint8_t dataSent = 0; uint8_t dataSent = 0;
// optionally write packet length // optionally write packet length
if (_packetLengthConfig == RADIOLIB_CC1101_LENGTH_CONFIG_VARIABLE) { if (this->packetLengthConfig == RADIOLIB_CC1101_LENGTH_CONFIG_VARIABLE) {
// enforce variable len limit. // enforce variable len limit
if (len > RADIOLIB_CC1101_MAX_PACKET_LENGTH - 1) { if (len > RADIOLIB_CC1101_MAX_PACKET_LENGTH - 1) {
return (RADIOLIB_ERR_PACKET_TOO_LONG); return (RADIOLIB_ERR_PACKET_TOO_LONG);
} }
@ -281,36 +294,37 @@ int16_t CC1101::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
dataSent += 1; dataSent += 1;
} }
// fill the FIFO. // fill the FIFO
uint8_t initialWrite = min((uint8_t)len, (uint8_t)(RADIOLIB_CC1101_FIFO_SIZE - dataSent)); uint8_t initialWrite = min((uint8_t)len, (uint8_t)(RADIOLIB_CC1101_FIFO_SIZE - dataSent));
SPIwriteRegisterBurst(RADIOLIB_CC1101_REG_FIFO, data, initialWrite); SPIwriteRegisterBurst(RADIOLIB_CC1101_REG_FIFO, data, initialWrite);
dataSent += initialWrite; dataSent += initialWrite;
// set RF switch (if present) // set RF switch (if present)
_mod->setRfSwitchState(Module::MODE_TX); this->mod->setRfSwitchState(Module::MODE_TX);
// set mode to transmit // set mode to transmit
SPIsendCommand(RADIOLIB_CC1101_CMD_TX); SPIsendCommand(RADIOLIB_CC1101_CMD_TX);
// keep feeding the FIFO until the packet is over.
// keep feeding the FIFO until the packet is over
while (dataSent < len) { while (dataSent < len) {
// get number of bytes in FIFO. // get number of bytes in FIFO
uint8_t bytesInFIFO = SPIgetRegValue(RADIOLIB_CC1101_REG_TXBYTES, 6, 0); uint8_t bytesInFIFO = SPIgetRegValue(RADIOLIB_CC1101_REG_TXBYTES, 6, 0);
// if there's room then put other data. // if there's room then put other data
if (bytesInFIFO < RADIOLIB_CC1101_FIFO_SIZE) { if (bytesInFIFO < RADIOLIB_CC1101_FIFO_SIZE) {
uint8_t bytesToWrite = min((uint8_t)(RADIOLIB_CC1101_FIFO_SIZE - bytesInFIFO), (uint8_t)(len - dataSent)); uint8_t bytesToWrite = min((uint8_t)(RADIOLIB_CC1101_FIFO_SIZE - bytesInFIFO), (uint8_t)(len - dataSent));
SPIwriteRegisterBurst(RADIOLIB_CC1101_REG_FIFO, &data[dataSent], bytesToWrite); SPIwriteRegisterBurst(RADIOLIB_CC1101_REG_FIFO, &data[dataSent], bytesToWrite);
dataSent += bytesToWrite; dataSent += bytesToWrite;
} else { } else {
// wait for radio to send some data. // wait for radio to send some data
/* /*
* Does this work for all rates? If 1 ms is longer than the 1ms delay * Does this work for all rates? If 1 ms is longer than the 1ms delay
* then the entire FIFO will be transmitted during that delay. * then the entire FIFO will be transmitted during that delay.
* *
* TODO: test this on real hardware * TODO: test this on real hardware
*/ */
_mod->hal->delayMicroseconds(250); this->mod->hal->delayMicroseconds(250);
} }
} }
@ -320,6 +334,7 @@ int16_t CC1101::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
int16_t CC1101::finishTransmit() { int16_t CC1101::finishTransmit() {
// set mode to standby to disable transmitter/RF switch // set mode to standby to disable transmitter/RF switch
int16_t state = standby(); int16_t state = standby();
RADIOLIB_ASSERT(state);
// flush Tx FIFO // flush Tx FIFO
SPIsendCommand(RADIOLIB_CC1101_CMD_FLUSH_TX); SPIsendCommand(RADIOLIB_CC1101_CMD_FLUSH_TX);
@ -329,18 +344,19 @@ int16_t CC1101::finishTransmit() {
int16_t CC1101::startReceive() { int16_t CC1101::startReceive() {
// set mode to standby // set mode to standby
standby(); int16_t state = standby();
RADIOLIB_ASSERT(state);
// flush Rx FIFO // flush Rx FIFO
SPIsendCommand(RADIOLIB_CC1101_CMD_FLUSH_RX); SPIsendCommand(RADIOLIB_CC1101_CMD_FLUSH_RX);
// set GDO0 mapping: Asserted when RX FIFO > 4 bytes. // set GDO0 mapping: Asserted when RX FIFO > 4 bytes.
int16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_IOCFG0, RADIOLIB_CC1101_GDOX_RX_FIFO_FULL_OR_PKT_END); state = SPIsetRegValue(RADIOLIB_CC1101_REG_IOCFG0, RADIOLIB_CC1101_GDOX_RX_FIFO_FULL_OR_PKT_END);
state |= SPIsetRegValue(RADIOLIB_CC1101_REG_FIFOTHR, RADIOLIB_CC1101_FIFO_THR_TX_61_RX_4, 3, 0); state |= SPIsetRegValue(RADIOLIB_CC1101_REG_FIFOTHR, RADIOLIB_CC1101_FIFO_THR_TX_61_RX_4, 3, 0);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set RF switch (if present) // set RF switch (if present)
_mod->setRfSwitchState(Module::MODE_RX); this->mod->setRfSwitchState(Module::MODE_RX);
// set mode to receive // set mode to receive
SPIsendCommand(RADIOLIB_CC1101_CMD_RX); SPIsendCommand(RADIOLIB_CC1101_CMD_RX);
@ -372,17 +388,17 @@ int16_t CC1101::readData(uint8_t* data, size_t len) {
uint8_t bytesInFIFO = SPIgetRegValue(RADIOLIB_CC1101_REG_RXBYTES, 6, 0); uint8_t bytesInFIFO = SPIgetRegValue(RADIOLIB_CC1101_REG_RXBYTES, 6, 0);
size_t readBytes = 0; size_t readBytes = 0;
uint32_t lastPop = _mod->hal->millis(); uint32_t lastPop = this->mod->hal->millis();
// keep reading from FIFO until we get all the packet. // keep reading from FIFO until we get all the packet.
while (readBytes < length) { while (readBytes < length) {
if (bytesInFIFO == 0) { if (bytesInFIFO == 0) {
if (_mod->hal->millis() - lastPop > 5) { if (this->mod->hal->millis() - lastPop > 5) {
// readData was required to read a packet longer than the one received. // readData was required to read a packet longer than the one received.
RADIOLIB_DEBUG_PRINTLN("No data for more than 5mS. Stop here."); RADIOLIB_DEBUG_PRINTLN("No data for more than 5mS. Stop here.");
break; break;
} else { } else {
_mod->hal->delay(1); this->mod->hal->delay(1);
bytesInFIFO = SPIgetRegValue(RADIOLIB_CC1101_REG_RXBYTES, 6, 0); bytesInFIFO = SPIgetRegValue(RADIOLIB_CC1101_REG_RXBYTES, 6, 0);
continue; continue;
} }
@ -392,7 +408,7 @@ int16_t CC1101::readData(uint8_t* data, size_t len) {
uint8_t bytesToRead = min((uint8_t)(length - readBytes), bytesInFIFO); uint8_t bytesToRead = min((uint8_t)(length - readBytes), bytesInFIFO);
SPIreadRegisterBurst(RADIOLIB_CC1101_REG_FIFO, bytesToRead, &(data[readBytes])); SPIreadRegisterBurst(RADIOLIB_CC1101_REG_FIFO, bytesToRead, &(data[readBytes]));
readBytes += bytesToRead; readBytes += bytesToRead;
lastPop = _mod->hal->millis(); lastPop = this->mod->hal->millis();
// Get how many bytes are left in FIFO. // Get how many bytes are left in FIFO.
bytesInFIFO = SPIgetRegValue(RADIOLIB_CC1101_REG_RXBYTES, 6, 0); bytesInFIFO = SPIgetRegValue(RADIOLIB_CC1101_REG_RXBYTES, 6, 0);
@ -402,26 +418,26 @@ int16_t CC1101::readData(uint8_t* data, size_t len) {
bool isAppendStatus = SPIgetRegValue(RADIOLIB_CC1101_REG_PKTCTRL1, 2, 2) == RADIOLIB_CC1101_APPEND_STATUS_ON; bool isAppendStatus = SPIgetRegValue(RADIOLIB_CC1101_REG_PKTCTRL1, 2, 2) == RADIOLIB_CC1101_APPEND_STATUS_ON;
// for some reason, we need this delay here to get the correct status bytes // for some reason, we need this delay here to get the correct status bytes
_mod->hal->delay(3); this->mod->hal->delay(3);
// If status byte is enabled at least 2 bytes (2 status bytes + any following packet) will remain in FIFO. // If status byte is enabled at least 2 bytes (2 status bytes + any following packet) will remain in FIFO.
if (isAppendStatus) { if (isAppendStatus) {
// read RSSI byte // read RSSI byte
_rawRSSI = SPIgetRegValue(RADIOLIB_CC1101_REG_FIFO); this->rawRSSI = SPIgetRegValue(RADIOLIB_CC1101_REG_FIFO);
// read LQI and CRC byte // read LQI and CRC byte
uint8_t val = SPIgetRegValue(RADIOLIB_CC1101_REG_FIFO); uint8_t val = SPIgetRegValue(RADIOLIB_CC1101_REG_FIFO);
_rawLQI = val & 0x7F; this->rawLQI = val & 0x7F;
// check CRC // check CRC
if (_crcOn && (val & RADIOLIB_CC1101_CRC_OK) == RADIOLIB_CC1101_CRC_ERROR) { if (this->crcOn && (val & RADIOLIB_CC1101_CRC_OK) == RADIOLIB_CC1101_CRC_ERROR) {
_packetLengthQueried = false; this->packetLengthQueried = false;
return (RADIOLIB_ERR_CRC_MISMATCH); return (RADIOLIB_ERR_CRC_MISMATCH);
} }
} }
// clear internal flag so getPacketLength can return the new packet length // clear internal flag so getPacketLength can return the new packet length
_packetLengthQueried = false; this->packetLengthQueried = false;
// Flush then standby according to RXOFF_MODE (default: RADIOLIB_CC1101_RXOFF_IDLE) // Flush then standby according to RXOFF_MODE (default: RADIOLIB_CC1101_RXOFF_IDLE)
if (SPIgetRegValue(RADIOLIB_CC1101_REG_MCSM1, 3, 2) == RADIOLIB_CC1101_RXOFF_IDLE) { if (SPIgetRegValue(RADIOLIB_CC1101_REG_MCSM1, 3, 2) == RADIOLIB_CC1101_RXOFF_IDLE) {
@ -455,11 +471,11 @@ int16_t CC1101::setFrequency(float freq) {
state |= SPIsetRegValue(RADIOLIB_CC1101_REG_FREQ0, FRF & 0x0000FF, 7, 0); state |= SPIsetRegValue(RADIOLIB_CC1101_REG_FREQ0, FRF & 0x0000FF, 7, 0);
if(state == RADIOLIB_ERR_NONE) { if(state == RADIOLIB_ERR_NONE) {
_freq = freq; this->freq = freq;
} }
// Update the TX power accordingly to new freq. (PA values depend on chosen freq) // Update the TX power accordingly to new freq. (PA values depend on chosen freq)
return(setOutputPower(_power)); return(setOutputPower(this->power));
} }
int16_t CC1101::setBitRate(float br) { int16_t CC1101::setBitRate(float br) {
@ -477,7 +493,7 @@ int16_t CC1101::setBitRate(float br) {
int16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG4, e, 3, 0); int16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG4, e, 3, 0);
state |= SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG3, m); state |= SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG3, m);
if(state == RADIOLIB_ERR_NONE) { if(state == RADIOLIB_ERR_NONE) {
_br = br; this->bitRate = br;
} }
return(state); return(state);
} }
@ -536,7 +552,7 @@ int16_t CC1101::getFrequencyDeviation(float *freqDev) {
} }
// if ASK/OOK, deviation makes no sense // if ASK/OOK, deviation makes no sense
if (_modulation == RADIOLIB_CC1101_MOD_FORMAT_ASK_OOK) { if (this->modulation == RADIOLIB_CC1101_MOD_FORMAT_ASK_OOK) {
*freqDev = 0.0; *freqDev = 0.0;
return(RADIOLIB_ERR_NONE); return(RADIOLIB_ERR_NONE);
@ -558,13 +574,13 @@ int16_t CC1101::getFrequencyDeviation(float *freqDev) {
int16_t CC1101::setOutputPower(int8_t power) { int16_t CC1101::setOutputPower(int8_t power) {
// round to the known frequency settings // round to the known frequency settings
uint8_t f; uint8_t f;
if(_freq < 374.0) { if(this->freq < 374.0) {
// 315 MHz // 315 MHz
f = 0; f = 0;
} else if(_freq < 650.5) { } else if(this->freq < 650.5) {
// 434 MHz // 434 MHz
f = 1; f = 1;
} else if(_freq < 891.5) { } else if(this->freq < 891.5) {
// 868 MHz // 868 MHz
f = 2; f = 2;
} else { } else {
@ -613,9 +629,9 @@ int16_t CC1101::setOutputPower(int8_t power) {
} }
// store the value // store the value
_power = power; this->power = power;
if(_modulation == RADIOLIB_CC1101_MOD_FORMAT_ASK_OOK){ if(this->modulation == RADIOLIB_CC1101_MOD_FORMAT_ASK_OOK){
// Amplitude modulation: // Amplitude modulation:
// PA_TABLE[0] is the power to be used when transmitting a 0 (no power) // PA_TABLE[0] is the power to be used when transmitting a 0 (no power)
// PA_TABLE[1] is the power to be used when transmitting a 1 (full power) // PA_TABLE[1] is the power to be used when transmitting a 1 (full power)
@ -659,10 +675,10 @@ int16_t CC1101::setSyncWord(uint8_t syncH, uint8_t syncL, uint8_t maxErrBits, bo
return(setSyncWord(syncWord, sizeof(syncWord), maxErrBits, requireCarrierSense)); return(setSyncWord(syncWord, sizeof(syncWord), maxErrBits, requireCarrierSense));
} }
int16_t CC1101::setPreambleLength(uint8_t preambleLength) { int16_t CC1101::setPreambleLength(uint8_t preambleLength, uint8_t qualityThreshold) {
// check allowed values // check allowed values
uint8_t value; uint8_t value;
switch(preambleLength){ switch(preambleLength) {
case 16: case 16:
value = RADIOLIB_CC1101_NUM_PREAMBLE_2; value = RADIOLIB_CC1101_NUM_PREAMBLE_2;
break; break;
@ -691,7 +707,14 @@ int16_t CC1101::setPreambleLength(uint8_t preambleLength) {
return(RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH); return(RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH);
} }
return(SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG1, value, 6, 4)); // set preabmble quality threshold and the actual length
uint8_t pqt = qualityThreshold/4;
if(pqt > 7) {
pqt = 7;
}
int16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_PKTCTRL1, pqt << 5, 7, 5);
state |= SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG1, value, 6, 4);
return(state);
} }
int16_t CC1101::setNodeAddress(uint8_t nodeAddr, uint8_t numBroadcastAddrs) { int16_t CC1101::setNodeAddress(uint8_t nodeAddr, uint8_t numBroadcastAddrs) {
@ -727,7 +750,7 @@ int16_t CC1101::setOOK(bool enableOOK) {
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// update current modulation // update current modulation
_modulation = RADIOLIB_CC1101_MOD_FORMAT_ASK_OOK; this->modulation = RADIOLIB_CC1101_MOD_FORMAT_ASK_OOK;
} else { } else {
int16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG2, RADIOLIB_CC1101_MOD_FORMAT_2_FSK, 6, 4); int16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG2, RADIOLIB_CC1101_MOD_FORMAT_2_FSK, 6, 4);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
@ -737,21 +760,21 @@ int16_t CC1101::setOOK(bool enableOOK) {
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// update current modulation // update current modulation
_modulation = RADIOLIB_CC1101_MOD_FORMAT_2_FSK; this->modulation = RADIOLIB_CC1101_MOD_FORMAT_2_FSK;
} }
// Update PA_TABLE values according to the new _modulation. // Update PA_TABLE values according to the new this->modulation.
return(setOutputPower(_power)); return(setOutputPower(this->power));
} }
float CC1101::getRSSI() { float CC1101::getRSSI() {
float rssi; float rssi;
if (_directMode) { if (this->directModeEnabled) {
if(_rawRSSI >= 128) { if(this->rawRSSI >= 128) {
rssi = (((float)_rawRSSI - 256.0)/2.0) - 74.0; rssi = (((float)this->rawRSSI - 256.0)/2.0) - 74.0;
} else { } else {
rssi = (((float)_rawRSSI)/2.0) - 74.0; rssi = (((float)this->rawRSSI)/2.0) - 74.0;
} }
} else { } else {
uint8_t rawRssi = SPIreadRegister(RADIOLIB_CC1101_REG_RSSI); uint8_t rawRssi = SPIreadRegister(RADIOLIB_CC1101_REG_RSSI);
@ -768,21 +791,25 @@ float CC1101::getRSSI() {
} }
uint8_t CC1101::getLQI() const { uint8_t CC1101::getLQI() const {
return(_rawLQI); return(this->rawLQI);
} }
size_t CC1101::getPacketLength(bool update) { size_t CC1101::getPacketLength(bool update) {
if(!_packetLengthQueried && update) { if(!this->packetLengthQueried && update) {
if (_packetLengthConfig == RADIOLIB_CC1101_LENGTH_CONFIG_VARIABLE) { if (this->packetLengthConfig == RADIOLIB_CC1101_LENGTH_CONFIG_VARIABLE) {
_packetLength = SPIreadRegister(RADIOLIB_CC1101_REG_FIFO); this->packetLength = 0;
while(this->packetLength == 0) {
this->packetLength = SPIreadRegister(RADIOLIB_CC1101_REG_FIFO);
}
} else { } else {
_packetLength = SPIreadRegister(RADIOLIB_CC1101_REG_PKTLEN); this->packetLength = SPIreadRegister(RADIOLIB_CC1101_REG_PKTLEN);
} }
_packetLengthQueried = true; this->packetLengthQueried = true;
} }
return(_packetLength); return(this->packetLength);
} }
int16_t CC1101::fixedPacketLengthMode(uint8_t len) { int16_t CC1101::fixedPacketLengthMode(uint8_t len) {
@ -794,20 +821,27 @@ int16_t CC1101::variablePacketLengthMode(uint8_t maxLen) {
} }
int16_t CC1101::enableSyncWordFiltering(uint8_t maxErrBits, bool requireCarrierSense) { int16_t CC1101::enableSyncWordFiltering(uint8_t maxErrBits, bool requireCarrierSense) {
switch(maxErrBits){ int16_t state = RADIOLIB_ERR_NONE;
switch(maxErrBits) {
case 0: case 0:
// in 16 bit sync word, expect all 16 bits // in 16 bit sync word, expect all 16 bits
return(SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG2, (requireCarrierSense ? RADIOLIB_CC1101_SYNC_MODE_16_16_THR : RADIOLIB_CC1101_SYNC_MODE_16_16), 2, 0)); state |= SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG2, (requireCarrierSense ? RADIOLIB_CC1101_SYNC_MODE_16_16_THR : RADIOLIB_CC1101_SYNC_MODE_16_16), 2, 0);
break;
case 1: case 1:
// in 16 bit sync word, expect at least 15 bits // in 16 bit sync word, expect at least 15 bits
return(SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG2, (requireCarrierSense ? RADIOLIB_CC1101_SYNC_MODE_15_16_THR : RADIOLIB_CC1101_SYNC_MODE_15_16), 2, 0)); state |= SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG2, (requireCarrierSense ? RADIOLIB_CC1101_SYNC_MODE_15_16_THR : RADIOLIB_CC1101_SYNC_MODE_15_16), 2, 0);
break;
default: default:
return(RADIOLIB_ERR_INVALID_SYNC_WORD); state = RADIOLIB_ERR_INVALID_SYNC_WORD;
break;
} }
return(state);
} }
int16_t CC1101::disableSyncWordFiltering(bool requireCarrierSense) { int16_t CC1101::disableSyncWordFiltering(bool requireCarrierSense) {
return(SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG2, (requireCarrierSense ? RADIOLIB_CC1101_SYNC_MODE_NONE_THR : RADIOLIB_CC1101_SYNC_MODE_NONE), 2, 0)); int16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG2, (requireCarrierSense ? RADIOLIB_CC1101_SYNC_MODE_NONE_THR : RADIOLIB_CC1101_SYNC_MODE_NONE), 2, 0);
return(state);
} }
int16_t CC1101::setCrcFiltering(bool crcOn) { int16_t CC1101::setCrcFiltering(bool crcOn) {
@ -820,14 +854,14 @@ int16_t CC1101::setCrcFiltering(bool crcOn) {
} }
} }
int16_t CC1101::setPromiscuousMode(bool promiscuous) { int16_t CC1101::setPromiscuousMode(bool enable) {
int16_t state = RADIOLIB_ERR_NONE; int16_t state = RADIOLIB_ERR_NONE;
if (_promiscuous == promiscuous) { if(this->promiscuous == enable) {
return(state); return(state);
} }
if (promiscuous == true) { if(enable) {
// disable sync word filtering and insertion // disable sync word filtering and insertion
// this also disables preamble // this also disables preamble
state = disableSyncWordFiltering(); state = disableSyncWordFiltering();
@ -836,7 +870,7 @@ int16_t CC1101::setPromiscuousMode(bool promiscuous) {
// disable CRC filtering // disable CRC filtering
state = setCrcFiltering(false); state = setCrcFiltering(false);
} else { } else {
state = setPreambleLength(RADIOLIB_CC1101_DEFAULT_PREAMBLELEN); state = setPreambleLength(RADIOLIB_CC1101_DEFAULT_PREAMBLELEN, RADIOLIB_CC1101_DEFAULT_PREAMBLELEN/4);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// enable sync word filtering and insertion // enable sync word filtering and insertion
@ -847,13 +881,13 @@ int16_t CC1101::setPromiscuousMode(bool promiscuous) {
state = setCrcFiltering(true); state = setCrcFiltering(true);
} }
_promiscuous = promiscuous; this->promiscuous = enable;
return(state); return(state);
} }
bool CC1101::getPromiscuousMode() { bool CC1101::getPromiscuousMode() {
return (_promiscuous); return (this->promiscuous);
} }
int16_t CC1101::setDataShaping(uint8_t sh) { int16_t CC1101::setDataShaping(uint8_t sh) {
@ -900,11 +934,11 @@ int16_t CC1101::setEncoding(uint8_t encoding) {
} }
void CC1101::setRfSwitchPins(uint32_t rxEn, uint32_t txEn) { void CC1101::setRfSwitchPins(uint32_t rxEn, uint32_t txEn) {
_mod->setRfSwitchPins(rxEn, txEn); this->mod->setRfSwitchPins(rxEn, txEn);
} }
void CC1101::setRfSwitchTable(const uint32_t (&pins)[Module::RFSWITCH_MAX_PINS], const Module::RfSwitchMode_t table[]) { void CC1101::setRfSwitchTable(const uint32_t (&pins)[Module::RFSWITCH_MAX_PINS], const Module::RfSwitchMode_t table[]) {
_mod->setRfSwitchTable(pins, table); this->mod->setRfSwitchTable(pins, table);
} }
uint8_t CC1101::randomByte() { uint8_t CC1101::randomByte() {
@ -913,7 +947,7 @@ uint8_t CC1101::randomByte() {
RADIOLIB_DEBUG_PRINTLN("CC1101::randomByte"); RADIOLIB_DEBUG_PRINTLN("CC1101::randomByte");
// wait a bit for the RSSI reading to stabilise // wait a bit for the RSSI reading to stabilise
_mod->hal->delay(10); this->mod->hal->delay(10);
// read RSSI value 8 times, always keep just the least significant bit // read RSSI value 8 times, always keep just the least significant bit
uint8_t randByte = 0x00; uint8_t randByte = 0x00;
@ -933,30 +967,39 @@ int16_t CC1101::getChipVersion() {
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE) #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
void CC1101::setDirectAction(void (*func)(void)) { void CC1101::setDirectAction(void (*func)(void)) {
setGdo0Action(func, _mod->hal->GpioInterruptRising); setGdo0Action(func, this->mod->hal->GpioInterruptRising);
} }
void CC1101::readBit(uint32_t pin) { void CC1101::readBit(uint32_t pin) {
updateDirectBuffer((uint8_t)_mod->hal->digitalRead(pin)); updateDirectBuffer((uint8_t)this->mod->hal->digitalRead(pin));
} }
#endif #endif
int16_t CC1101::setDIOMapping(uint32_t pin, uint32_t value) { int16_t CC1101::setDIOMapping(uint32_t pin, uint32_t value) {
if (pin > 2) if(pin > 2) {
return RADIOLIB_ERR_INVALID_DIO_PIN; return(RADIOLIB_ERR_INVALID_DIO_PIN);
}
return(SPIsetRegValue(RADIOLIB_CC1101_REG_IOCFG0 - pin, value)); return(SPIsetRegValue(RADIOLIB_CC1101_REG_IOCFG0 - pin, value));
} }
int16_t CC1101::config() { int16_t CC1101::config() {
// Reset the radio. Registers may be dirty from previous usage. // Reset the radio. Registers may be dirty from previous usage.
SPIsendCommand(RADIOLIB_CC1101_CMD_RESET); reset();
// Wait a ridiculous amount of time to be sure radio is ready. // Wait a ridiculous amount of time to be sure radio is ready.
_mod->hal->delay(150); this->mod->hal->delay(150);
// enable automatic frequency synthesizer calibration standby();
// enable automatic frequency synthesizer calibration and disable pin control
int16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_MCSM0, RADIOLIB_CC1101_FS_AUTOCAL_IDLE_TO_RXTX, 5, 4); int16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_MCSM0, RADIOLIB_CC1101_FS_AUTOCAL_IDLE_TO_RXTX, 5, 4);
state |= SPIsetRegValue(RADIOLIB_CC1101_REG_MCSM0, RADIOLIB_CC1101_PIN_CTRL_OFF, 1, 1);
RADIOLIB_ASSERT(state);
// set GDOs to Hi-Z so that it doesn't output clock on startup (might confuse GDO0 action)
state = SPIsetRegValue(RADIOLIB_CC1101_REG_IOCFG0, RADIOLIB_CC1101_GDOX_HIGH_Z, 5, 0);
state |= SPIsetRegValue(RADIOLIB_CC1101_REG_IOCFG2, RADIOLIB_CC1101_GDOX_HIGH_Z, 5, 0);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set packet mode // set packet mode
@ -970,16 +1013,15 @@ int16_t CC1101::directMode(bool sync) {
SPIsendCommand(RADIOLIB_CC1101_CMD_IDLE); SPIsendCommand(RADIOLIB_CC1101_CMD_IDLE);
int16_t state = 0; int16_t state = 0;
_directMode = sync; this->directModeEnabled = sync;
if (sync) { if(sync) {
// set GDO0 and GDO2 mapping // set GDO0 and GDO2 mapping
state |= SPIsetRegValue(RADIOLIB_CC1101_REG_IOCFG0, RADIOLIB_CC1101_GDOX_SERIAL_CLOCK , 5, 0); state |= SPIsetRegValue(RADIOLIB_CC1101_REG_IOCFG0, RADIOLIB_CC1101_GDOX_SERIAL_CLOCK , 5, 0);
state |= SPIsetRegValue(RADIOLIB_CC1101_REG_IOCFG2, RADIOLIB_CC1101_GDOX_SERIAL_DATA_SYNC , 5, 0); state |= SPIsetRegValue(RADIOLIB_CC1101_REG_IOCFG2, RADIOLIB_CC1101_GDOX_SERIAL_DATA_SYNC , 5, 0);
// set continuous mode // set continuous mode
state |= SPIsetRegValue(RADIOLIB_CC1101_REG_PKTCTRL0, RADIOLIB_CC1101_PKT_FORMAT_SYNCHRONOUS, 5, 4); state |= SPIsetRegValue(RADIOLIB_CC1101_REG_PKTCTRL0, RADIOLIB_CC1101_PKT_FORMAT_SYNCHRONOUS, 5, 4);
} } else {
else {
// set GDO0 mapping // set GDO0 mapping
state |= SPIsetRegValue(RADIOLIB_CC1101_REG_IOCFG0, RADIOLIB_CC1101_GDOX_SERIAL_DATA_ASYNC , 5, 0); state |= SPIsetRegValue(RADIOLIB_CC1101_REG_IOCFG0, RADIOLIB_CC1101_GDOX_SERIAL_DATA_ASYNC , 5, 0);
@ -1032,8 +1074,8 @@ int16_t CC1101::setPacketMode(uint8_t mode, uint16_t len) {
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// update the cached value // update the cached value
_packetLength = len; this->packetLength = len;
_packetLengthConfig = mode; this->packetLengthConfig = mode;
return(state); return(state);
} }
@ -1043,7 +1085,7 @@ int16_t CC1101::SPIgetRegValue(uint8_t reg, uint8_t msb, uint8_t lsb) {
reg |= RADIOLIB_CC1101_CMD_ACCESS_STATUS_REG; reg |= RADIOLIB_CC1101_CMD_ACCESS_STATUS_REG;
} }
return(_mod->SPIgetRegValue(reg, msb, lsb)); return(this->mod->SPIgetRegValue(reg, msb, lsb));
} }
int16_t CC1101::SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb, uint8_t lsb, uint8_t checkInterval) { int16_t CC1101::SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb, uint8_t lsb, uint8_t checkInterval) {
@ -1052,11 +1094,11 @@ int16_t CC1101::SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb, uint8_t
reg |= RADIOLIB_CC1101_CMD_ACCESS_STATUS_REG; reg |= RADIOLIB_CC1101_CMD_ACCESS_STATUS_REG;
} }
return(_mod->SPIsetRegValue(reg, value, msb, lsb, checkInterval)); return(this->mod->SPIsetRegValue(reg, value, msb, lsb, checkInterval));
} }
void CC1101::SPIreadRegisterBurst(uint8_t reg, uint8_t numBytes, uint8_t* inBytes) { void CC1101::SPIreadRegisterBurst(uint8_t reg, uint8_t numBytes, uint8_t* inBytes) {
_mod->SPIreadRegisterBurst(reg | RADIOLIB_CC1101_CMD_BURST, numBytes, inBytes); this->mod->SPIreadRegisterBurst(reg | RADIOLIB_CC1101_CMD_BURST, numBytes, inBytes);
} }
uint8_t CC1101::SPIreadRegister(uint8_t reg) { uint8_t CC1101::SPIreadRegister(uint8_t reg) {
@ -1065,7 +1107,7 @@ uint8_t CC1101::SPIreadRegister(uint8_t reg) {
reg |= RADIOLIB_CC1101_CMD_ACCESS_STATUS_REG; reg |= RADIOLIB_CC1101_CMD_ACCESS_STATUS_REG;
} }
return(_mod->SPIreadRegister(reg)); return(this->mod->SPIreadRegister(reg));
} }
void CC1101::SPIwriteRegister(uint8_t reg, uint8_t data) { void CC1101::SPIwriteRegister(uint8_t reg, uint8_t data) {
@ -1074,26 +1116,28 @@ void CC1101::SPIwriteRegister(uint8_t reg, uint8_t data) {
reg |= RADIOLIB_CC1101_CMD_ACCESS_STATUS_REG; reg |= RADIOLIB_CC1101_CMD_ACCESS_STATUS_REG;
} }
return(_mod->SPIwriteRegister(reg, data)); return(this->mod->SPIwriteRegister(reg, data));
} }
void CC1101::SPIwriteRegisterBurst(uint8_t reg, uint8_t* data, size_t len) { void CC1101::SPIwriteRegisterBurst(uint8_t reg, uint8_t* data, size_t len) {
_mod->SPIwriteRegisterBurst(reg | RADIOLIB_CC1101_CMD_BURST, data, len); this->mod->SPIwriteRegisterBurst(reg | RADIOLIB_CC1101_CMD_BURST, data, len);
} }
void CC1101::SPIsendCommand(uint8_t cmd) { void CC1101::SPIsendCommand(uint8_t cmd) {
// pull NSS low // pull NSS low
_mod->hal->digitalWrite(_mod->getCs(), _mod->hal->GpioLevelLow); this->mod->hal->digitalWrite(this->mod->getCs(), this->mod->hal->GpioLevelLow);
// start transfer // start transfer
_mod->hal->spiBeginTransaction(); this->mod->hal->spiBeginTransaction();
// send the command byte // send the command byte
_mod->hal->spiTransfer(cmd); uint8_t status = this->mod->hal->spiTransfer(cmd);
// stop transfer // stop transfer
_mod->hal->spiEndTransaction(); this->mod->hal->spiEndTransaction();
_mod->hal->digitalWrite(_mod->getCs(), _mod->hal->GpioLevelHigh); this->mod->hal->digitalWrite(this->mod->getCs(), this->mod->hal->GpioLevelHigh);
RADIOLIB_VERBOSE_PRINTLN("CMD\tW\t%02X\t%02X", cmd, status);
(void)status;
} }
#endif #endif

File diff suppressed because it is too large Load diff