Merge pull request #684 from GUVWAF/irqFlagsMask

[SX126x/SX128x] Add user-configurable IRQ flags and mask to receive methods
This commit is contained in:
Jan Gromeš 2023-03-05 15:08:13 +01:00 committed by GitHub
commit 8174c58250
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 22 deletions

View file

@ -532,8 +532,8 @@ int16_t SX126x::finishTransmit() {
return(standby());
}
int16_t SX126x::startReceive(uint32_t timeout) {
int16_t state = startReceiveCommon(timeout);
int16_t SX126x::startReceive(uint32_t timeout, uint16_t irqFlags, uint16_t irqMask) {
int16_t state = startReceiveCommon(timeout, irqFlags, irqMask);
RADIOLIB_ASSERT(state);
// set RF switch (if present)
@ -545,7 +545,7 @@ int16_t SX126x::startReceive(uint32_t timeout) {
return(state);
}
int16_t SX126x::startReceiveDutyCycle(uint32_t rxPeriod, uint32_t sleepPeriod) {
int16_t SX126x::startReceiveDutyCycle(uint32_t rxPeriod, uint32_t sleepPeriod, uint16_t irqFlags, uint16_t irqMask) {
// datasheet claims time to go to sleep is ~500us, same to wake up, compensate for that with 1 ms + TCXO delay
uint32_t transitionTime = _tcxoDelay + 1000;
sleepPeriod -= transitionTime;
@ -564,7 +564,7 @@ int16_t SX126x::startReceiveDutyCycle(uint32_t rxPeriod, uint32_t sleepPeriod) {
return(RADIOLIB_ERR_INVALID_SLEEP_PERIOD);
}
int16_t state = startReceiveCommon();
int16_t state = startReceiveCommon(RADIOLIB_SX126X_RX_TIMEOUT_INF, irqFlags, irqMask);
RADIOLIB_ASSERT(state);
uint8_t data[6] = {(uint8_t)((rxPeriodRaw >> 16) & 0xFF), (uint8_t)((rxPeriodRaw >> 8) & 0xFF), (uint8_t)(rxPeriodRaw & 0xFF),
@ -572,7 +572,7 @@ int16_t SX126x::startReceiveDutyCycle(uint32_t rxPeriod, uint32_t sleepPeriod) {
return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_RX_DUTY_CYCLE, data, 6));
}
int16_t SX126x::startReceiveDutyCycleAuto(uint16_t senderPreambleLength, uint16_t minSymbols) {
int16_t SX126x::startReceiveDutyCycleAuto(uint16_t senderPreambleLength, uint16_t minSymbols, uint16_t irqFlags, uint16_t irqMask) {
if(senderPreambleLength == 0) {
senderPreambleLength = _preambleLength;
}
@ -584,7 +584,7 @@ int16_t SX126x::startReceiveDutyCycleAuto(uint16_t senderPreambleLength, uint16_
// if we're not to sleep at all, just use the standard startReceive.
if(2 * minSymbols > senderPreambleLength) {
return(startReceive());
return(startReceive(RADIOLIB_SX126X_RX_TIMEOUT_INF, irqFlags, irqMask));
}
uint32_t symbolLength = ((uint32_t)(10 * 1000) << _sf) / (10 * _bwKhz);
@ -606,19 +606,18 @@ int16_t SX126x::startReceiveDutyCycleAuto(uint16_t senderPreambleLength, uint16_
// If our sleep period is shorter than our transition time, just use the standard startReceive
if(sleepPeriod < _tcxoDelay + 1016) {
return(startReceive());
return(startReceive(RADIOLIB_SX126X_RX_TIMEOUT_INF, irqFlags, irqMask));
}
return(startReceiveDutyCycle(wakePeriod, sleepPeriod));
return(startReceiveDutyCycle(wakePeriod, sleepPeriod, irqFlags, irqMask));
}
int16_t SX126x::startReceiveCommon(uint32_t timeout) {
int16_t SX126x::startReceiveCommon(uint32_t timeout, uint16_t irqFlags, uint16_t irqMask) {
// set DIO mapping
uint16_t mask = RADIOLIB_SX126X_IRQ_RX_DONE;
if(timeout != RADIOLIB_SX126X_RX_TIMEOUT_INF) {
mask |= RADIOLIB_SX126X_IRQ_TIMEOUT;
irqMask |= RADIOLIB_SX126X_IRQ_TIMEOUT;
}
int16_t state = setDioIrqParams(RADIOLIB_SX126X_IRQ_RX_DONE | RADIOLIB_SX126X_IRQ_TIMEOUT | RADIOLIB_SX126X_IRQ_CRC_ERR | RADIOLIB_SX126X_IRQ_HEADER_ERR, mask);
int16_t state = setDioIrqParams(irqFlags, irqMask);
RADIOLIB_ASSERT(state);
// set buffer pointers

View file

@ -221,6 +221,7 @@
#define RADIOLIB_SX126X_IRQ_RADIOLIB_PREAMBLE_DETECTED 0b0000000000000100 // 2 2 preamble detected
#define RADIOLIB_SX126X_IRQ_RX_DONE 0b0000000000000010 // 1 1 packet received
#define RADIOLIB_SX126X_IRQ_TX_DONE 0b0000000000000001 // 0 0 packet transmission completed
#define RADIOLIB_SX126X_IRQ_RX_DEFAULT 0b0000001001100010 // 14 0 default for Rx (RX_DONE, TIMEOUT, CRC_ERR and HEADER_ERR)
#define RADIOLIB_SX126X_IRQ_ALL 0b0100001111111111 // 14 0 all interrupts
#define RADIOLIB_SX126X_IRQ_NONE 0b0000000000000000 // 14 0 no interrupts
@ -608,9 +609,13 @@ class SX126x: public PhysicalLayer {
\param timeout Raw timeout value, expressed as multiples of 15.625 us. Defaults to RADIOLIB_SX126X_RX_TIMEOUT_INF for infinite timeout (Rx continuous mode), set to RADIOLIB_SX126X_RX_TIMEOUT_NONE for no timeout (Rx single mode).
If timeout other than infinite is set, signal will be generated on DIO1.
\param irqFlags Sets the IRQ flags, defaults to RADIOLIB_SX126X_IRQ_RX_DEFAULT.
\param irqMask Sets the mask of IRQ flags that will trigger DIO1, defaults to RADIOLIB_SX126X_IRQ_RX_DONE.
\returns \ref status_codes
*/
int16_t startReceive(uint32_t timeout = RADIOLIB_SX126X_RX_TIMEOUT_INF);
int16_t startReceive(uint32_t timeout = RADIOLIB_SX126X_RX_TIMEOUT_INF, uint16_t irqFlags = RADIOLIB_SX126X_IRQ_RX_DEFAULT, uint16_t irqMask = RADIOLIB_SX126X_IRQ_RX_DONE);
/*!
\brief Interrupt-driven receive method where the device mostly sleeps and periodically wakes to listen.
@ -620,9 +625,13 @@ class SX126x: public PhysicalLayer {
\param sleepPeriod The duration the receiver will not be in Rx mode, in microseconds.
\param irqFlags Sets the IRQ flags, defaults to RADIOLIB_SX126X_IRQ_RX_DEFAULT.
\param irqMask Sets the mask of IRQ flags that will trigger DIO1, defaults to RADIOLIB_SX126X_IRQ_RX_DONE.
\returns \ref status_codes
*/
int16_t startReceiveDutyCycle(uint32_t rxPeriod, uint32_t sleepPeriod);
int16_t startReceiveDutyCycle(uint32_t rxPeriod, uint32_t sleepPeriod, uint16_t irqFlags = RADIOLIB_SX126X_IRQ_RX_DEFAULT, uint16_t irqMask = RADIOLIB_SX126X_IRQ_RX_DONE);
/*!
\brief Calls \ref startReceiveDutyCycle with rxPeriod and sleepPeriod set so the unit shouldn't miss any messages.
@ -633,9 +642,13 @@ class SX126x: public PhysicalLayer {
\param minSymbols Parameters will be chosen to ensure that the unit will catch at least this many symbols of any preamble of the specified length. Defaults to 8.
According to Semtech, receiver requires 8 symbols to reliably latch a preamble. This makes this method redundant when transmitter preamble length is less than 17 (2*minSymbols + 1).
\param irqFlags Sets the IRQ flags, defaults to RADIOLIB_SX126X_IRQ_RX_DEFAULT.
\param irqMask Sets the mask of IRQ flags that will trigger DIO1, defaults to RADIOLIB_SX126X_IRQ_RX_DONE.
\returns \ref status_codes
*/
int16_t startReceiveDutyCycleAuto(uint16_t senderPreambleLength = 0, uint16_t minSymbols = 8);
int16_t startReceiveDutyCycleAuto(uint16_t senderPreambleLength = 0, uint16_t minSymbols = 8, uint16_t irqFlags = RADIOLIB_SX126X_IRQ_RX_DEFAULT, uint16_t irqMask = RADIOLIB_SX126X_IRQ_RX_DONE);
/*!
\brief Reads the current IRQ status.
@ -1062,7 +1075,7 @@ class SX126x: public PhysicalLayer {
uint16_t getDeviceErrors();
int16_t clearDeviceErrors();
int16_t startReceiveCommon(uint32_t timeout = RADIOLIB_SX126X_RX_TIMEOUT_INF);
int16_t startReceiveCommon(uint32_t timeout = RADIOLIB_SX126X_RX_TIMEOUT_INF, uint16_t irqFlags = RADIOLIB_SX126X_IRQ_RX_DEFAULT, uint16_t irqMask = RADIOLIB_SX126X_IRQ_RX_DONE);
int16_t setFrequencyRaw(float freq);
int16_t setPacketMode(uint8_t mode, uint8_t len);
int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF);

View file

@ -546,20 +546,18 @@ int16_t SX128x::finishTransmit() {
return(standby());
}
int16_t SX128x::startReceive(uint16_t timeout) {
int16_t SX128x::startReceive(uint16_t timeout, uint16_t irqFlags, uint16_t irqMask) {
// check active modem
if(getPacketType() == RADIOLIB_SX128X_PACKET_TYPE_RANGING) {
return(RADIOLIB_ERR_WRONG_MODEM);
}
// set DIO mapping
uint16_t mask = RADIOLIB_SX128X_IRQ_RX_DONE;
if(timeout != RADIOLIB_SX128X_RX_TIMEOUT_INF) {
mask |= RADIOLIB_SX128X_IRQ_RX_TX_TIMEOUT;
irqMask |= RADIOLIB_SX128X_IRQ_RX_TX_TIMEOUT;
}
int16_t state = setDioIrqParams(RADIOLIB_SX128X_IRQ_RX_DONE | RADIOLIB_SX128X_IRQ_RX_TX_TIMEOUT | RADIOLIB_SX128X_IRQ_CRC_ERROR | RADIOLIB_SX128X_IRQ_HEADER_ERROR, mask);
int16_t state = setDioIrqParams(irqFlags, irqMask);
RADIOLIB_ASSERT(state);
// set buffer pointers

View file

@ -327,6 +327,7 @@
#define RADIOLIB_SX128X_IRQ_SYNC_WORD_VALID 0x0004 // 2 2 sync word valid
#define RADIOLIB_SX128X_IRQ_RX_DONE 0x0002 // 1 1 Rx done
#define RADIOLIB_SX128X_IRQ_TX_DONE 0x0001 // 0 0 Tx done
#define RADIOLIB_SX128X_IRQ_RX_DEFAULT 0x4062 // 15 0 default for Rx (RX_DONE, RX_TX_TIMEOUT, CRC_ERROR and HEADER_ERROR)
#define RADIOLIB_SX128X_IRQ_NONE 0x0000 // 15 0 none
#define RADIOLIB_SX128X_IRQ_ALL 0xFFFF // 15 0 all
@ -566,9 +567,13 @@ class SX128x: public PhysicalLayer {
\param timeout Raw timeout value, expressed as multiples of 15.625 us. Defaults to RADIOLIB_SX128X_RX_TIMEOUT_INF for infinite timeout (Rx continuous mode), set to RADIOLIB_SX128X_RX_TIMEOUT_NONE for no timeout (Rx single mode).
If timeout other than infinite is set, signal will be generated on DIO1.
\param irqFlags Sets the IRQ flags, defaults to RADIOLIB_SX128X_IRQ_RX_DEFAULT.
\param irqMask Sets the mask of IRQ flags that will trigger DIO1, defaults to RADIOLIB_SX128X_IRQ_RX_DONE.
\returns \ref status_codes
*/
int16_t startReceive(uint16_t timeout = RADIOLIB_SX128X_RX_TIMEOUT_INF);
int16_t startReceive(uint16_t timeout = RADIOLIB_SX128X_RX_TIMEOUT_INF, uint16_t irqFlags = RADIOLIB_SX128X_IRQ_RX_DEFAULT, uint16_t irqMask = RADIOLIB_SX128X_IRQ_RX_DONE);
/*!
\brief Reads the current IRQ status.