[SX127x] Rework generic IRQ to allow multiple flags
This commit is contained in:
parent
cc299053b1
commit
17de5754ae
2 changed files with 14 additions and 34 deletions
|
@ -386,21 +386,23 @@ int16_t SX127x::packetMode() {
|
|||
}
|
||||
|
||||
int16_t SX127x::startReceive() {
|
||||
return(this->startReceive(0, RADIOLIB_SX127X_RXCONTINUOUS));
|
||||
return(this->startReceive(0, RADIOLIB_SX127X_RXCONTINUOUS, RADIOLIB_IRQ_RX_DEFAULT_FLAGS, RADIOLIB_IRQ_RX_DEFAULT_MASK));
|
||||
}
|
||||
|
||||
int16_t SX127x::startReceive(uint8_t len, uint8_t mode) {
|
||||
int16_t SX127x::startReceive(uint8_t len, uint8_t mode, RadioLibIrqFlags_t irqFlags, RadioLibIrqFlags_t irqMask) {
|
||||
// set mode to standby
|
||||
int16_t state = setMode(RADIOLIB_SX127X_STANDBY);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set DIO pin mapping
|
||||
state = this->setIrqFlags(irqFlags & irqMask);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
int16_t modem = getActiveModem();
|
||||
if(modem == RADIOLIB_SX127X_LORA) {
|
||||
// set DIO pin mapping
|
||||
// in FHSS mode, enable channel change interrupt
|
||||
if(this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD) > RADIOLIB_SX127X_HOP_PERIOD_OFF) {
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_LORA_RX_DONE | RADIOLIB_SX127X_DIO1_LORA_FHSS_CHANGE_CHANNEL, 7, 4);
|
||||
} else {
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_LORA_RX_DONE | RADIOLIB_SX127X_DIO1_LORA_RX_TIMEOUT, 7, 4);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO1_LORA_FHSS_CHANGE_CHANNEL, 5, 4);
|
||||
}
|
||||
|
||||
// set expected packet length for SF6
|
||||
|
@ -421,10 +423,6 @@ int16_t SX127x::startReceive(uint8_t len, uint8_t mode) {
|
|||
RADIOLIB_ASSERT(state);
|
||||
|
||||
} else if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
||||
// set DIO pin mapping
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_PACK_PAYLOAD_READY, 7, 6);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// clear interrupt flags
|
||||
clearIrqFlags(RADIOLIB_SX127X_FLAGS_ALL);
|
||||
|
||||
|
@ -443,9 +441,7 @@ int16_t SX127x::startReceive(uint8_t len, uint8_t mode) {
|
|||
return(setMode(mode));
|
||||
}
|
||||
|
||||
int16_t SX127x::startReceive(uint32_t timeout, uint32_t irqFlags, uint32_t irqMask, size_t len) {
|
||||
(void)irqFlags;
|
||||
(void)irqMask;
|
||||
int16_t SX127x::startReceive(uint32_t timeout, RadioLibIrqFlags_t irqFlags, RadioLibIrqFlags_t irqMask, size_t len) {
|
||||
uint8_t mode = RADIOLIB_SX127X_RXCONTINUOUS;
|
||||
if(timeout != 0) {
|
||||
// for non-zero timeout value, change mode to Rx single and set the timeout
|
||||
|
@ -456,7 +452,7 @@ int16_t SX127x::startReceive(uint32_t timeout, uint32_t irqFlags, uint32_t irqMa
|
|||
state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_SYMB_TIMEOUT_LSB, lsb_sym);
|
||||
RADIOLIB_ASSERT(state);
|
||||
}
|
||||
return(startReceive((uint8_t)len, mode));
|
||||
return(startReceive((uint8_t)len, mode, irqFlags, irqMask));
|
||||
}
|
||||
|
||||
void SX127x::setDio0Action(void (*func)(void), uint32_t dir) {
|
||||
|
@ -1319,13 +1315,6 @@ RadioLibTime_t SX127x::calculateRxTimeout(RadioLibTime_t timeoutUs) {
|
|||
return(numSymbols);
|
||||
}
|
||||
|
||||
int16_t SX127x::irqRxDoneRxTimeout(uint32_t &irqFlags, uint32_t &irqMask) {
|
||||
// IRQ flags/masks are inverted to what seems logical for SX127x (0 being activated, 1 being deactivated)
|
||||
irqFlags = RADIOLIB_SX127X_MASK_IRQ_FLAG_RX_DEFAULT;
|
||||
irqMask = RADIOLIB_SX127X_MASK_IRQ_FLAG_RX_DONE & RADIOLIB_SX127X_MASK_IRQ_FLAG_RX_TIMEOUT;
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
uint32_t SX127x::getIrqFlags() {
|
||||
return((uint32_t)this->getIRQFlags());
|
||||
}
|
||||
|
|
|
@ -160,7 +160,6 @@
|
|||
#define RADIOLIB_SX127X_MASK_IRQ_FLAG_CAD_DONE 0b11111011 // 2 2 CAD complete
|
||||
#define RADIOLIB_SX127X_MASK_IRQ_FLAG_FHSS_CHANGE_CHANNEL 0b11111101 // 1 1 FHSS change channel
|
||||
#define RADIOLIB_SX127X_MASK_IRQ_FLAG_CAD_DETECTED 0b11111110 // 0 0 valid LoRa signal detected during CAD operation
|
||||
#define RADIOLIB_SX127X_MASK_IRQ_FLAG_RX_DEFAULT 0b00011111 // 7 0 default for Rx (RX_TIMEOUT, RX_DONE, CRC_ERR)
|
||||
|
||||
// RADIOLIB_SX127X_REG_FIFO_TX_BASE_ADDR
|
||||
#define RADIOLIB_SX127X_FIFO_TX_BASE_ADDR_MAX 0b00000000 // 7 0 allocate the entire FIFO buffer for TX only
|
||||
|
@ -820,7 +819,7 @@ class SX127x: public PhysicalLayer {
|
|||
\param mode Receive mode to be used. Defaults to RxContinuous.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t startReceive(uint8_t len, uint8_t mode = RADIOLIB_SX127X_RXCONTINUOUS);
|
||||
int16_t startReceive(uint8_t len, uint8_t mode = RADIOLIB_SX127X_RXCONTINUOUS, RadioLibIrqFlags_t irqFlags = RADIOLIB_IRQ_RX_DEFAULT_FLAGS, RadioLibIrqFlags_t irqMask = RADIOLIB_IRQ_RX_DEFAULT_MASK);
|
||||
|
||||
/*!
|
||||
\brief Interrupt-driven receive method, implemented for compatibility with PhysicalLayer.
|
||||
|
@ -828,12 +827,12 @@ class SX127x: public PhysicalLayer {
|
|||
When set to 0, the timeout will be infinite and the device will remain
|
||||
in Rx mode until explicitly commanded to stop (Rx continuous mode).
|
||||
When non-zero (maximum 1023), the device will be set to Rx single mode and timeout will be set.
|
||||
\param irqFlags Ignored.
|
||||
\param irqMask Ignored.
|
||||
\param irqFlags Sets the IRQ flags, defaults to RX done, RX timeout, CRC error and header error.
|
||||
\param irqMask Sets the mask of IRQ flags that will trigger DIO1, defaults to RX done.
|
||||
\param len Expected length of packet to be received. Required for LoRa spreading factor 6.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t startReceive(uint32_t timeout, uint32_t irqFlags, uint32_t irqMask, size_t len) override;
|
||||
int16_t startReceive(uint32_t timeout, RadioLibIrqFlags_t irqFlags, RadioLibIrqFlags_t irqMask, size_t len) override;
|
||||
|
||||
/*!
|
||||
\brief Reads data that was received after calling startReceive method. When the packet length is not known in advance,
|
||||
|
@ -1065,14 +1064,6 @@ class SX127x: public PhysicalLayer {
|
|||
*/
|
||||
RadioLibTime_t calculateRxTimeout(RadioLibTime_t timeoutUs) override;
|
||||
|
||||
/*!
|
||||
\brief Create the flags that make up RxDone and RxTimeout used for receiving downlinks
|
||||
\param irqFlags The flags for which IRQs must be triggered
|
||||
\param irqMask Mask indicating which IRQ triggers a DIO
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t irqRxDoneRxTimeout(uint32_t &irqFlags, uint32_t &irqMask) override;
|
||||
|
||||
/*!
|
||||
\brief Read currently active IRQ flags.
|
||||
\returns IRQ flags.
|
||||
|
|
Loading…
Add table
Reference in a new issue