Skip to content

Commit

Permalink
Merge pull request #485 from obones/cc1101_async_serial
Browse files Browse the repository at this point in the history
Introduce asynchronous reception and transmission for CC1101
  • Loading branch information
jgromes authored Mar 4, 2022
2 parents 64817ed + 1418470 commit 2e7067d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
43 changes: 35 additions & 8 deletions src/modules/CC1101/CC1101.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
20 changes: 19 additions & 1 deletion src/modules/CC1101/CC1101.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
};
Expand Down

0 comments on commit 2e7067d

Please sign in to comment.