make TX done async
This commit is contained in:
parent
4825c93600
commit
0c394d30a7
2 changed files with 10 additions and 12 deletions
|
@ -86,6 +86,7 @@ const long long frequencies[3];
|
|||
const long bandwidths[9];
|
||||
|
||||
typedef void (*receiveCallback)(uint8_t size);
|
||||
typedef void (*txdoneCallback)();
|
||||
|
||||
typedef struct {
|
||||
EventGroupHandle_t events;
|
||||
|
@ -108,6 +109,7 @@ typedef struct lora32_cfg_t {
|
|||
bool implicitHeader;
|
||||
|
||||
receiveCallback receive;
|
||||
txdoneCallback tx_done;
|
||||
spi_device_handle_t spi;
|
||||
|
||||
lora32_handle_t handle;
|
||||
|
|
|
@ -133,6 +133,8 @@ void lora32_enable_tx(lora32_cfg_t *lora) {
|
|||
}
|
||||
|
||||
void lora32_send(lora32_cfg_t *lora, uint8_t *data, uint8_t len) {
|
||||
lora32_write_reg(lora, REG_DIO_MAPPING_1, DIO0_MODE_TXDONE);
|
||||
|
||||
lora32_enable_tx(lora);
|
||||
|
||||
uint8_t i = 0;
|
||||
|
@ -143,18 +145,7 @@ void lora32_send(lora32_cfg_t *lora, uint8_t *data, uint8_t len) {
|
|||
|
||||
lora32_write_reg(lora, REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_TX);
|
||||
|
||||
lora32_write_reg(lora, REG_DIO_MAPPING_1, DIO0_MODE_TXDONE);
|
||||
|
||||
ESP_LOGD(TAG, "lora32_send waiting for TX to finish");
|
||||
|
||||
// can be made async by waiting for DIO0 and checking for IRQ_TX_DONE_MASK
|
||||
while((lora32_read_reg(lora, REG_IRQ_FLAGS) & IRQ_TX_DONE_MASK) == 0) {
|
||||
vTaskDelay(1 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "lora32_send TX done");
|
||||
|
||||
lora32_write_reg(lora, REG_IRQ_FLAGS, IRQ_TX_DONE_MASK);
|
||||
}
|
||||
|
||||
void lora32_set_frequency(lora32_cfg_t *lora, long frequency) {
|
||||
|
@ -294,9 +285,14 @@ static void IRAM_ATTR lora32_dio0_task(void *arg) {
|
|||
lora32_write_reg(lora, REG_IRQ_FLAGS, irqs);
|
||||
|
||||
// is this the right check? seems to work but looks off
|
||||
if((irqs & IRQ_RX_DONE_MASK) == IRQ_RX_DONE_MASK) {
|
||||
// TODO handle header validation
|
||||
if((irqs & IRQ_RX_DONE) == IRQ_RX_DONE) {
|
||||
lora32_handle_receive(lora);
|
||||
}
|
||||
|
||||
if((irqs & IRQ_TX_DONE) == IRQ_TX_DONE) {
|
||||
if(lora->tx_done != NULL) lora->tx_done();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue