From 07736774c7ec35fc9686e3a88c1d3cee31ad8ef5 Mon Sep 17 00:00:00 2001 From: Daniel Peter Chokola Date: Tue, 13 Jun 2023 20:30:45 -0400 Subject: [PATCH] add sx127x_txdone() function to poll for Tx done --- Inc/sx127x.h | 1 + Src/sx127x.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/Inc/sx127x.h b/Inc/sx127x.h index 73505ca..fbe9124 100644 --- a/Inc/sx127x.h +++ b/Inc/sx127x.h @@ -35,5 +35,6 @@ int32_t sx127x_rx(sx127x_t *sx127x, uint8_t *buf); int32_t sx127x_snr(sx127x_t *sx127x); int32_t sx127x_rssi(sx127x_t *sx127x); int32_t sx127x_rand(sx127x_t *sx127x); +int32_t sx127x_txdone(sx127x_t *sx127x); #endif /* SX127X_INC_SX127X_H_ */ diff --git a/Src/sx127x.c b/Src/sx127x.c index 6b4134e..244542c 100644 --- a/Src/sx127x.c +++ b/Src/sx127x.c @@ -440,6 +440,18 @@ int32_t sx127x_rand(sx127x_t *sx127x) return tmp; } +int32_t sx127x_txdone(sx127x_t *sx127x) +{ + uint8_t irq; + + /* read IRQ flags */ + return_val_if_fail(sx127x_readbyte(sx127x, SX127X_REG_IRQFLAGS, &irq) == 0, -1); + /* clear the TXDONE flag */ + return_val_if_fail(sx127x_writebyte(sx127x, SX127X_REG_IRQFLAGS, irq & ~SX127X_IRQFLAGS_TXDONE) == 0, -1); + + return irq & SX127X_IRQFLAGS_TXDONE; +} + static int32_t sx127x_writebyte(sx127x_t *sx127x, uint8_t reg, uint8_t byte) { uint8_t txdata[2] = { WREG(reg), byte };