adding get_bandwidth, get_spreadfactor, reverted bandwidths to ...e3 numbers
This commit is contained in:
parent
50d7497c0f
commit
58cd70d9ba
2 changed files with 44 additions and 12 deletions
|
@ -63,8 +63,8 @@
|
||||||
#define MAX_PKT_LENGTH 255
|
#define MAX_PKT_LENGTH 255
|
||||||
|
|
||||||
#define DETECT_OPT_SF6 0xC5
|
#define DETECT_OPT_SF6 0xC5
|
||||||
#define DETECT_OPT_OTHER 0xC3
|
|
||||||
#define DETECT_THRES_SF6 0x0C
|
#define DETECT_THRES_SF6 0x0C
|
||||||
|
#define DETECT_OPT_OTHER 0xC3
|
||||||
#define DETECT_THRES_OTHER 0x0A
|
#define DETECT_THRES_OTHER 0x0A
|
||||||
|
|
||||||
#define DEFAULT_SF 7
|
#define DEFAULT_SF 7
|
||||||
|
@ -104,7 +104,7 @@ typedef struct lora32_cfg_t {
|
||||||
uint8_t fifoIdx;
|
uint8_t fifoIdx;
|
||||||
|
|
||||||
long frequency;
|
long frequency;
|
||||||
bandwidth bandwidth;
|
uint8_t bandwidth;
|
||||||
|
|
||||||
uint8_t spreadingFactor;
|
uint8_t spreadingFactor;
|
||||||
uint8_t codingRate;
|
uint8_t codingRate;
|
||||||
|
@ -132,7 +132,7 @@ void lora32_dump_regs(lora32_cfg_t *lora);
|
||||||
void lora32_enable_continuous_rx(lora32_cfg_t *lora);
|
void lora32_enable_continuous_rx(lora32_cfg_t *lora);
|
||||||
void lora32_enable_cad(lora32_cfg_t *lora);
|
void lora32_enable_cad(lora32_cfg_t *lora);
|
||||||
void lora32_send(lora32_cfg_t *config, uint8_t *data, uint8_t len);
|
void lora32_send(lora32_cfg_t *config, uint8_t *data, uint8_t len);
|
||||||
void lora32_set_bandwidth(lora32_cfg_t *lora, bandwidth bw);
|
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_coding_rate(lora32_cfg_t *lora, uint8_t cr);
|
||||||
void lora32_set_spreadfactor(lora32_cfg_t *lora, uint8_t factor);
|
void lora32_set_spreadfactor(lora32_cfg_t *lora, uint8_t factor);
|
||||||
void lora32_read_data(lora32_cfg_t *lora, uint8_t *data);
|
void lora32_read_data(lora32_cfg_t *lora, uint8_t *data);
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#define PA_OUTPUT_PA_BOOST_PIN 1
|
#define PA_OUTPUT_PA_BOOST_PIN 1
|
||||||
|
|
||||||
const long long frequencies[] = { 433e+6, 866e+6, 915e+6 };
|
const long long frequencies[] = { 433e+6, 866e+6, 915e+6 };
|
||||||
const long bandwidths[] = { 7.8, 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250, 500 };
|
const long bandwidths[] = { 7.8e3, 10.4e3, 15.6e3, 20.8e3, 31.25e3, 41.7e3, 62.5e3, 125e3, 250e3, 500e3 };
|
||||||
|
|
||||||
const char *TAG = "LoRa32";
|
const char *TAG = "LoRa32";
|
||||||
|
|
||||||
|
@ -159,6 +159,7 @@ void lora32_send(lora32_cfg_t *lora, uint8_t *data, uint8_t len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void lora32_set_frequency(lora32_cfg_t *lora, long frequency) {
|
void lora32_set_frequency(lora32_cfg_t *lora, long frequency) {
|
||||||
|
ESP_LOGI(TAG, "lora32_set_frequency: %lu", frequency);
|
||||||
uint64_t frf = ((uint64_t)frequency << 19) / 32000000;
|
uint64_t frf = ((uint64_t)frequency << 19) / 32000000;
|
||||||
|
|
||||||
ESP_LOGI(TAG, "REG_FRF_MSB: 0x%2X", (uint8_t)(frf >> 16));
|
ESP_LOGI(TAG, "REG_FRF_MSB: 0x%2X", (uint8_t)(frf >> 16));
|
||||||
|
@ -247,6 +248,10 @@ void lora32_toggle_reset(lora32_cfg_t *config) {
|
||||||
vTaskDelay(100 / portTICK_PERIOD_MS); // 5ms before available
|
vTaskDelay(100 / portTICK_PERIOD_MS); // 5ms before available
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t lora32_get_spreadingfactor(lora32_cfg_t *lora) {
|
||||||
|
return (lora32_read_reg(lora, REG_MODEM_CONFIG_2) >> 4);
|
||||||
|
}
|
||||||
|
|
||||||
void lora32_set_spreadfactor(lora32_cfg_t *lora, uint8_t factor) {
|
void lora32_set_spreadfactor(lora32_cfg_t *lora, uint8_t factor) {
|
||||||
if(factor <= 6) {
|
if(factor <= 6) {
|
||||||
factor = 6;
|
factor = 6;
|
||||||
|
@ -287,12 +292,39 @@ void lora32_enable_cad(lora32_cfg_t *lora) {
|
||||||
lora32_write_reg(lora, REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_CAD_DETECT);
|
lora32_write_reg(lora, REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_CAD_DETECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lora32_set_bandwidth(lora32_cfg_t *lora, bandwidth bw) {
|
long lora32_get_bandwidth(lora32_cfg_t *lora) {
|
||||||
uint8_t modem_config_1 = lora32_read_reg(lora, REG_MODEM_CONFIG_1);
|
uint8_t bw = (lora32_read_reg(lora, REG_MODEM_CONFIG_1) >> 4);
|
||||||
|
ESP_LOGI(TAG, "lora32_get_bandwidth: %d", bw);
|
||||||
|
|
||||||
|
if(bw > 9) return -1;
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "lora32_get_bandwidth: %ld", bandwidths[bw]);
|
||||||
|
|
||||||
|
return bandwidths[bw];
|
||||||
|
}
|
||||||
|
|
||||||
|
void lora32_set_ldo_flag(lora32_cfg_t *lora) {
|
||||||
|
long symbolDuration = 1000 / (lora32_get_bandwidth(lora) / (1L << lora32_get_spreadingfactor(lora)));
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "symbolDuration: %ld", symbolDuration);
|
||||||
|
|
||||||
|
bool ldoOn = symbolDuration > 16;
|
||||||
|
ESP_LOGI(TAG, "ldoOn: %d", ldoOn);
|
||||||
|
|
||||||
|
uint8_t modem_config_3 = lora32_read_reg(lora, REG_MODEM_CONFIG_3);
|
||||||
|
ESP_LOGI(TAG, "modem_config_3: %d", modem_config_3);
|
||||||
|
modem_config_3 |= ldoOn << 3;
|
||||||
|
ESP_LOGI(TAG, "modem_config_3: %d", modem_config_3);
|
||||||
|
lora32_write_reg(lora, REG_MODEM_CONFIG_3, modem_config_3);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lora32_set_bandwidth(lora32_cfg_t *lora, uint8_t bw) {
|
||||||
ESP_LOGI(TAG, "lora32_set_bandwidth: %d", bw);
|
ESP_LOGI(TAG, "lora32_set_bandwidth: %d", bw);
|
||||||
|
|
||||||
|
uint8_t modem_config_1 = lora32_read_reg(lora, REG_MODEM_CONFIG_1);
|
||||||
lora32_write_reg(lora, REG_MODEM_CONFIG_1, (modem_config_1 & 0x0F) | (bw << 4));
|
lora32_write_reg(lora, REG_MODEM_CONFIG_1, (modem_config_1 & 0x0F) | (bw << 4));
|
||||||
|
|
||||||
|
lora32_set_ldo_flag(lora);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lora32_set_coding_rate(lora32_cfg_t *lora, uint8_t cr) {
|
void lora32_set_coding_rate(lora32_cfg_t *lora, uint8_t cr) {
|
||||||
|
@ -448,9 +480,9 @@ uint8_t lora32_init(lora32_cfg_t *lora) {
|
||||||
|
|
||||||
// TODO: VERIFY
|
// TODO: VERIFY
|
||||||
lora32_set_frequency(lora, lora->frequency);
|
lora32_set_frequency(lora, lora->frequency);
|
||||||
|
lora32_set_spreadfactor(lora, lora->spreadingFactor);
|
||||||
lora32_set_bandwidth(lora, lora->bandwidth);
|
lora32_set_bandwidth(lora, lora->bandwidth);
|
||||||
lora32_set_coding_rate(lora, lora->codingRate);
|
lora32_set_coding_rate(lora, lora->codingRate);
|
||||||
lora32_set_spreadfactor(lora, lora->spreadingFactor);
|
|
||||||
|
|
||||||
lora32_write_reg(lora, REG_FIFO_TX_BASE_ADDR, 0x00);
|
lora32_write_reg(lora, REG_FIFO_TX_BASE_ADDR, 0x00);
|
||||||
lora32_write_reg(lora, REG_FIFO_RX_BASE_ADDR, 0x00);
|
lora32_write_reg(lora, REG_FIFO_RX_BASE_ADDR, 0x00);
|
||||||
|
@ -458,7 +490,7 @@ uint8_t lora32_init(lora32_cfg_t *lora) {
|
||||||
|
|
||||||
lora32_set_lna(lora, 0x03);
|
lora32_set_lna(lora, 0x03);
|
||||||
|
|
||||||
// enabling AGC
|
// enable auto AGC
|
||||||
lora32_write_reg(lora, REG_MODEM_CONFIG_3, 0x04);
|
lora32_write_reg(lora, REG_MODEM_CONFIG_3, 0x04);
|
||||||
|
|
||||||
// TODO make based on config
|
// TODO make based on config
|
||||||
|
|
Loading…
Reference in a new issue