From 862d8eeadd3b0a9016e26ba71ee1223825b4253e Mon Sep 17 00:00:00 2001 From: "Morgan 'ARR\\!' Allen" Date: Thu, 27 Feb 2020 08:18:53 -0800 Subject: [PATCH] add long missing set bandwidth function --- include/esp32-lora.h | 3 ++- main/esp32-lora.c | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/esp32-lora.h b/include/esp32-lora.h index 22ebc8e..b219707 100644 --- a/include/esp32-lora.h +++ b/include/esp32-lora.h @@ -81,7 +81,7 @@ enum freq { } lora32_freq; enum bandwidth { - B78, B104, B156, B208, B3125, B417, B625, B125, B250 + B78, B104, B156, B208, B3125, B417, B625, B125, B250, B500 }; const long long frequencies[3]; @@ -130,6 +130,7 @@ void lora32_dump_regs(lora32_cfg_t *lora); void lora32_enable_continuous_rx(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_set_bandwidth(lora32_cfg_t *lora, enum bandwidth 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); diff --git a/main/esp32-lora.c b/main/esp32-lora.c index 91a7ea1..d1cd17f 100644 --- a/main/esp32-lora.c +++ b/main/esp32-lora.c @@ -262,6 +262,14 @@ void lora32_enable_cad(lora32_cfg_t *lora) { lora32_write_reg(lora, REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_CAD_DETECT); } +void lora32_set_bandwidth(lora32_cfg_t *lora, enum bandwidth bw) { + uint8_t modem_config_1 = lora32_read_reg(lora, REG_MODEM_CONFIG_1); + + ESP_LOGI(TAG, "lora32_set_bandwidth: %d", bw); + + lora32_write_reg(lora, REG_MODEM_CONFIG_1, (modem_config_1 & 0x0F) | (bw << 4)); +} + void lora32_set_coding_rate(lora32_cfg_t *lora, uint8_t cr) { if(cr < 5) cr = 5; else if(cr > 8) cr = 8;