Merge pull request #485 from obones/cc1101_async_serial
Introduce asynchronous reception and transmission for CC1101
This commit is contained in:
commit
2e7067de81
2 changed files with 54 additions and 9 deletions
|
@ -174,6 +174,14 @@ int16_t CC1101::standby() {
|
|||
}
|
||||
|
||||
int16_t CC1101::transmitDirect(uint32_t frf) {
|
||||
return transmitDirect(true, frf);
|
||||
}
|
||||
|
||||
int16_t CC1101::transmitDirectAsync(uint32_t frf) {
|
||||
return transmitDirect(false, frf);
|
||||
}
|
||||
|
||||
int16_t CC1101::transmitDirect(bool sync, uint32_t frf) {
|
||||
// set RF switch (if present)
|
||||
_mod->setRfSwitchState(LOW, HIGH);
|
||||
|
||||
|
@ -187,7 +195,7 @@ int16_t CC1101::transmitDirect(uint32_t frf) {
|
|||
}
|
||||
|
||||
// activate direct mode
|
||||
int16_t state = directMode();
|
||||
int16_t state = directMode(sync);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// start transmitting
|
||||
|
@ -196,11 +204,19 @@ int16_t CC1101::transmitDirect(uint32_t frf) {
|
|||
}
|
||||
|
||||
int16_t CC1101::receiveDirect() {
|
||||
return receiveDirect(true);
|
||||
}
|
||||
|
||||
int16_t CC1101::receiveDirectAsync() {
|
||||
return receiveDirect(false);
|
||||
}
|
||||
|
||||
int16_t CC1101::receiveDirect(bool sync) {
|
||||
// set RF switch (if present)
|
||||
_mod->setRfSwitchState(HIGH, LOW);
|
||||
|
||||
// activate direct mode
|
||||
int16_t state = directMode();
|
||||
int16_t state = directMode(sync);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// start receiving
|
||||
|
@ -888,16 +904,27 @@ int16_t CC1101::config() {
|
|||
return(state);
|
||||
}
|
||||
|
||||
int16_t CC1101::directMode() {
|
||||
int16_t CC1101::directMode(bool sync) {
|
||||
// set mode to standby
|
||||
SPIsendCommand(RADIOLIB_CC1101_CMD_IDLE);
|
||||
|
||||
// set GDO0 and GDO2 mapping
|
||||
int16_t 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);
|
||||
int16_t state = 0;
|
||||
if (sync) {
|
||||
// set GDO0 and GDO2 mapping
|
||||
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);
|
||||
|
||||
// set continuous mode
|
||||
state |= SPIsetRegValue(RADIOLIB_CC1101_REG_PKTCTRL0, RADIOLIB_CC1101_PKT_FORMAT_SYNCHRONOUS, 5, 4);
|
||||
}
|
||||
else {
|
||||
// set GDO0 mapping
|
||||
state |= SPIsetRegValue(RADIOLIB_CC1101_REG_IOCFG0, RADIOLIB_CC1101_GDOX_SERIAL_DATA_ASYNC , 5, 0);
|
||||
|
||||
// set asynchronous continuous mode
|
||||
state |= SPIsetRegValue(RADIOLIB_CC1101_REG_PKTCTRL0, RADIOLIB_CC1101_PKT_FORMAT_ASYNCHRONOUS, 5, 4);
|
||||
}
|
||||
|
||||
// set continuous mode
|
||||
state |= SPIsetRegValue(RADIOLIB_CC1101_REG_PKTCTRL0, RADIOLIB_CC1101_PKT_FORMAT_SYNCHRONOUS, 5, 4);
|
||||
state |= SPIsetRegValue(RADIOLIB_CC1101_REG_PKTCTRL0, RADIOLIB_CC1101_LENGTH_CONFIG_INFINITE, 1, 0);
|
||||
return(state);
|
||||
}
|
||||
|
|
|
@ -591,6 +591,22 @@ class CC1101: public PhysicalLayer {
|
|||
*/
|
||||
int16_t receiveDirect() override;
|
||||
|
||||
/*!
|
||||
\brief Starts asynchronous direct mode transmission.
|
||||
|
||||
\param frf Raw RF frequency value. Defaults to 0, required for quick frequency shifts in RTTY.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t transmitDirectAsync(uint32_t frf = 0);
|
||||
|
||||
/*!
|
||||
\brief Starts asynchronous direct mode reception.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t receiveDirectAsync();
|
||||
|
||||
/*!
|
||||
\brief Stops direct mode. It is required to call this method to switch from direct transmissions to packet-based transmissions.
|
||||
*/
|
||||
|
@ -952,7 +968,9 @@ class CC1101: public PhysicalLayer {
|
|||
int8_t _power = 0;
|
||||
|
||||
int16_t config();
|
||||
int16_t directMode();
|
||||
int16_t transmitDirect(bool sync, uint32_t frf);
|
||||
int16_t receiveDirect(bool sync);
|
||||
int16_t directMode(bool sync);
|
||||
static void getExpMant(float target, uint16_t mantOffset, uint8_t divExp, uint8_t expMax, uint8_t& exp, uint8_t& mant);
|
||||
int16_t setPacketMode(uint8_t mode, uint16_t len);
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue