Compare commits

..

No commits in common. "db9b74ec761e356fdba9f9f282a17ba5e1ac3215" and "7141d876806712555ea484b5e8326ab061f5a6c4" have entirely different histories.

2 changed files with 15 additions and 38 deletions

View file

@ -77,7 +77,7 @@
#define EV_DIO0 (1 << 0)
#define ERR_LOR_VERSION_MISMATCH (01)
#define ERR_LOR_ID_MISMATCH (00)
enum freq {
F433, F866, F915
@ -138,7 +138,6 @@ uint8_t lora32_data_available(lora32_cfg_t *lora);
double lora32_calc_datarate(lora32_cfg_t *lora);
void lora32_dump_regs(lora32_cfg_t *lora);
void lora32_enable_continuous_rx(lora32_cfg_t *lora);
void lora32_enable_single_rx(lora32_cfg_t *lora);
void lora32_enable_cad(lora32_cfg_t *lora);
void lora32_toggle_reset(lora32_cfg_t *lora);
void lora32_send(lora32_cfg_t *config, uint8_t *data, uint8_t len);
@ -146,7 +145,5 @@ void lora32_set_bandwidth(lora32_cfg_t *lora, uint8_t bw);
void lora32_set_coding_rate(lora32_cfg_t *lora, uint8_t cr);
void lora32_set_spreadfactor(lora32_cfg_t *lora, uint8_t factor);
void lora32_read_data(lora32_cfg_t *lora, uint8_t *data);
void lora32_sleep(lora32_cfg_t *lora);
void lora32_standby(lora32_cfg_t *lora);
#endif // _LORA32_H__

View file

@ -31,7 +31,7 @@ static TaskHandle_t dio_task_handle;
static SemaphoreHandle_t spi_semaphore;
uint8_t lora32_read_reg(lora32_cfg_t *lora, uint8_t address) {
xSemaphoreTake(spi_semaphore, portMAX_DELAY);
//xSemaphoreTake(spi_semaphore, portMAX_DELAY);
spi_transaction_t t;
memset(&t, 0, sizeof(spi_transaction_t));
@ -45,13 +45,13 @@ uint8_t lora32_read_reg(lora32_cfg_t *lora, uint8_t address) {
ESP_LOGV(TAG, "<%2X<%2X", address, t.rx_data[1]);
xSemaphoreGive(spi_semaphore);
//xSemaphoreGive(spi_semaphore);
return t.rx_data[1];
}
void lora32_write_reg(lora32_cfg_t *lora, uint8_t address, uint8_t value) {
xSemaphoreTake(spi_semaphore, portMAX_DELAY);
//xSemaphoreTake(spi_semaphore, portMAX_DELAY);
spi_device_handle_t spi = lora->spi;
@ -67,7 +67,7 @@ void lora32_write_reg(lora32_cfg_t *lora, uint8_t address, uint8_t value) {
ESP_ERROR_CHECK(spi_device_transmit(spi, &t));
xSemaphoreGive(spi_semaphore);
//xSemaphoreGive(spi_semaphore);
};
double lora32_calc_datarate(lora32_cfg_t *lora) {
@ -91,20 +91,20 @@ void lora23_set_implicit_header(lora32_cfg_t *lora) {
lora32_write_reg(lora, REG_MODEM_CONFIG_1, lora32_read_reg(lora, REG_MODEM_CONFIG_1) | 0x01);
}
void lora32_standby(lora32_cfg_t *lora) {
ESP_LOGV(TAG, "MODE_STANDBY");
void lora32_idle(lora32_cfg_t *lora) {
ESP_LOGD(TAG, "MODE_STANDBY");
lora32_write_reg(lora, REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_STANDBY);
}
void lora32_sleep(lora32_cfg_t *lora) {
ESP_LOGV(TAG, "MODE_SLEEP");
ESP_LOGD(TAG, "MODE_SLEEP");
lora32_write_reg(lora, REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_SLEEP);
}
void lora32_enable_tx(lora32_cfg_t *lora) {
lora32_standby(lora);
lora32_idle(lora);
if(lora->implicitHeader)
lora23_set_implicit_header(lora);
@ -117,7 +117,7 @@ void lora32_enable_tx(lora32_cfg_t *lora) {
}
void lora32_send(lora32_cfg_t *lora, uint8_t *data, uint8_t len) {
ESP_ERROR_CHECK(spi_device_acquire_bus(lora->spi, portMAX_DELAY));
spi_device_acquire_bus(lora->spi, portMAX_DELAY);
lora32_write_reg(lora, REG_DIO_MAPPING_1, DIO0_MODE_TXDONE);
@ -246,18 +246,6 @@ void lora32_set_spreadfactor(lora32_cfg_t *lora, uint8_t factor) {
lora32_write_reg(lora, REG_MODEM_CONFIG_2, (lora32_read_reg(lora, REG_MODEM_CONFIG_2) & 0x0F) | ((factor << 4) & 0xF0));
}
void lora32_enable_single_rx(lora32_cfg_t *lora) {
ESP_LOGD(TAG, "MODE_RX_SINGLE");
if(lora->receive != NULL) {
lora32_write_reg(lora, REG_DIO_MAPPING_1, DIO0_MODE_RXDONE);
}
lora32_standby(lora);
lora32_write_reg(lora, REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_RX_SINGLE);
}
void lora32_enable_continuous_rx(lora32_cfg_t *lora) {
ESP_LOGD(TAG, "MODE_RX_CONTINUOUS");
@ -265,8 +253,6 @@ void lora32_enable_continuous_rx(lora32_cfg_t *lora) {
lora32_write_reg(lora, REG_DIO_MAPPING_1, DIO0_MODE_RXDONE);
}
lora32_standby(lora);
lora32_write_reg(lora, REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_RX_CONTINUOUS);
}
@ -375,8 +361,6 @@ static void IRAM_ATTR lora32_dio_task(void *arg) {
ESP_LOGD(TAG, "clearing irqs");
lora32_write_reg(lora, REG_IRQ_FLAGS, irqs);
spi_device_release_bus(lora->spi);
// TODO handle header validation
if((irqs & IRQ_RX_DONE) == IRQ_RX_DONE) {
lora32_handle_receive(lora);
@ -401,6 +385,8 @@ static void IRAM_ATTR lora32_dio_task(void *arg) {
// these *should* fire at the same time, defaults to false
if(lora->cad_done != NULL) lora->cad_done(lora, cad_detected);
}
spi_device_release_bus(lora->spi);
}
}
@ -477,13 +463,7 @@ uint8_t lora32_init(lora32_cfg_t *lora) {
uint8_t version = lora32_read_reg(lora, REG_VERSION);
ESP_LOGD(TAG, "lora32_get_id() == 0x%2X", version);
// if ID does not match, something is likely wrong on the SPI bus
if(version != 0x12) {
ESP_LOGD(TAG, "REG_VERSION returned incorrectly. Expected 0x12 got 0x%02X", version);
return ERR_LOR_VERSION_MISMATCH;
}
assert(version == 0x12);
// TODO: confirm this is happening. Before/after power measurements?
lora32_sleep(lora);
@ -508,8 +488,8 @@ uint8_t lora32_init(lora32_cfg_t *lora) {
lora32_set_tx_power(lora, 17, PA_OUTPUT_PA_BOOST_PIN);
ESP_LOGI(TAG, "lora32_set_tx_power");
lora32_standby(lora);
ESP_LOGI(TAG, "lora32_standby");
lora32_idle(lora);
ESP_LOGI(TAG, "lora32_idle");
// TODO setup shouldn't be based on just receive callback
if(lora->receive != NULL) {