Compare commits

...

5 Commits

7 changed files with 184 additions and 56 deletions

View File

@@ -151,6 +151,10 @@
#endif #endif
#endif #endif
#define LORA_PA_UNKNOWN 0x00
#define LORA_PA_GC1109 0x01
#define LORA_PA_KCT8103L 0x02
#define HAS_DISPLAY false #define HAS_DISPLAY false
#define HAS_BLUETOOTH false #define HAS_BLUETOOTH false
#define HAS_BLE false #define HAS_BLE false
@@ -363,7 +367,7 @@
#define HAS_SLEEP true #define HAS_SLEEP true
#define PIN_WAKEUP GPIO_NUM_0 #define PIN_WAKEUP GPIO_NUM_0
#define WAKEUP_LEVEL 0 #define WAKEUP_LEVEL 0
#define OCP_TUNED 0x18 #define OCP_TUNED 0x28
const int pin_btn_usr1 = 0; const int pin_btn_usr1 = 0;
@@ -411,8 +415,9 @@
#define HAS_LORA_LNA true #define HAS_LORA_LNA true
#define PIN_WAKEUP GPIO_NUM_0 #define PIN_WAKEUP GPIO_NUM_0
#define WAKEUP_LEVEL 0 #define WAKEUP_LEVEL 0
#define OCP_TUNED 0x18 #define OCP_TUNED 0x28
#define Vext GPIO_NUM_36 #define Vext GPIO_NUM_36
#define LORA_PA_MODEL LORA_PA_UNKNOWN;
const int pin_btn_usr1 = 0; const int pin_btn_usr1 = 0;
@@ -434,14 +439,17 @@
#define LORA_LNA_GAIN 17 #define LORA_LNA_GAIN 17
#define LORA_LNA_GVT 12 #define LORA_LNA_GVT 12
#define LORA_PA_GC1109 true
#define LORA_PA_PWR_EN 7 #define LORA_PA_PWR_EN 7
#define LORA_PA_CSD 2 #define LORA_PA_CSD 2 // Same pin on GC1109
#define LORA_PA_CPS 46 #define LORA_PA_CPS 46 // Same pin on GC1109
#define LORA_PA_CTX 5 // Only used on KCT8103
#define PA_MAX_OUTPUT 28 #define PA_MAX_OUTPUT 28
#define PA_GAIN_POINTS 22 #define PA_GAIN_POINTS 22
#define PA_GAIN_VALUES 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 9, 9, 8, 7
#define LORA_LNA_KCT8103L_GAIN 21
const int PA_GC1109_VALUES[PA_GAIN_POINTS] = {11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 9, 9, 8, 7};
const int PA_KCT8103L_VALUES[PA_GAIN_POINTS] = {13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 11, 11, 10, 9, 8, 7};
const int pin_cs = 8; const int pin_cs = 8;
const int pin_busy = 13; const int pin_busy = 13;
@@ -529,13 +537,10 @@
const int pin_np = 12; const int pin_np = 12;
const int pin_dac = 25; const int pin_dac = 25;
const int pin_adc = 34; const int pin_adc = 34;
// CBA already defined by framework const int SD_MISO = 2;
//const int SD_MISO = 2; const int SD_MOSI = 15;
// CBA already defined by framework
//const int SD_MOSI = 15;
const int SD_CLK = 14; const int SD_CLK = 14;
// CBA already defined by framework const int SD_CS = 13;
//const int SD_CS = 13;
#if HAS_NP == false #if HAS_NP == false
#if defined(EXTERNAL_LEDS) #if defined(EXTERNAL_LEDS)
const int pin_led_rx = 12; const int pin_led_rx = 12;
@@ -980,7 +985,7 @@
// Default OCP value if not specified // Default OCP value if not specified
// in board configuration // in board configuration
#ifndef OCP_TUNED #ifndef OCP_TUNED
#define OCP_TUNED 0x18 #define OCP_TUNED 0x28
#endif #endif
#ifndef PA_MAX_OUTPUT #ifndef PA_MAX_OUTPUT

View File

@@ -20,7 +20,7 @@
#define CONFIG_H #define CONFIG_H
#define MAJ_VERS 0x01 #define MAJ_VERS 0x01
#define MIN_VERS 0x55 #define MIN_VERS 0x56
#define MODE_HOST 0x11 #define MODE_HOST 0x11
#define MODE_TNC 0x12 #define MODE_TNC 0x12

View File

@@ -1586,7 +1586,7 @@ void serial_callback(uint8_t sbyte) {
if (txp > 13) txp = 13; if (txp > 13) txp = 13;
#endif #endif
#else #else
if (txp > 17) txp = 17; if (txp > 20) txp = 20;
#endif #endif
lora_txp = txp; lora_txp = txp;
@@ -2648,7 +2648,13 @@ void sleep_now() {
#if BOARD_MODEL == BOARD_HELTEC32_V4 #if BOARD_MODEL == BOARD_HELTEC32_V4
headless_led_off(); headless_led_off();
headless_led_detach_pwm(); headless_led_detach_pwm();
#if LORA_PA_AUTO_DETECT
if (sx126x_modem.isKCT8103L()) {
digitalWrite(LORA_PA_CTX, LOW);
} else {
digitalWrite(LORA_PA_CPS, LOW); digitalWrite(LORA_PA_CPS, LOW);
}
#endif
digitalWrite(LORA_PA_CSD, LOW); digitalWrite(LORA_PA_CSD, LOW);
digitalWrite(LORA_PA_PWR_EN, LOW); digitalWrite(LORA_PA_PWR_EN, LOW);
digitalWrite(Vext, HIGH); digitalWrite(Vext, HIGH);

View File

@@ -1383,11 +1383,33 @@ int getTxPower() {
} }
#if HAS_LORA_PA #if HAS_LORA_PA
#if BOARD_MODEL == BOARD_HELTEC32_V4
bool pa_values_determined = false;
int tx_gain[PA_GAIN_POINTS] = {100};
#else
bool pa_values_determined = true;
const int tx_gain[PA_GAIN_POINTS] = {PA_GAIN_VALUES}; const int tx_gain[PA_GAIN_POINTS] = {PA_GAIN_VALUES};
#endif
#endif #endif
extern uint8_t lora_pa_model;
void determine_pa_values() {
#if BOARD_MODEL == BOARD_HELTEC32_V4
if (lora_pa_model == LORA_PA_GC1109) {
for (int i=0; i < PA_GAIN_POINTS; i++) { tx_gain[i] = PA_GC1109_VALUES[i]; }
pa_values_determined = true;
for (int i=0; i < PA_GAIN_POINTS; i++) { Serial.print(" "); Serial.printf("%d", tx_gain[i]); }
} else if (lora_pa_model == LORA_PA_KCT8103L) {
for (int i=0; i < PA_GAIN_POINTS; i++) { tx_gain[i] = PA_KCT8103L_VALUES[i]; }
pa_values_determined = true;
for (int i=0; i < PA_GAIN_POINTS; i++) { Serial.print(" "); Serial.printf("%d", tx_gain[i]); }
}
#endif
}
int map_target_power_to_modem_output(int target_tx_power) { int map_target_power_to_modem_output(int target_tx_power) {
#if HAS_LORA_PA #if HAS_LORA_PA
if (!pa_values_determined) { determine_pa_values(); }
int modem_output_dbm = -9; int modem_output_dbm = -9;
for (int i = 0; i < PA_GAIN_POINTS; i++) { for (int i = 0; i < PA_GAIN_POINTS; i++) {
int gain = tx_gain[i]; int gain = tx_gain[i];

View File

@@ -34,7 +34,7 @@ build_src_filter = +<*> -<variants/>
extra_scripts = pre:extra_script.py extra_scripts = pre:extra_script.py
[env:rnode-ng-20] [env:rnode-ng-20]
platform = espressif32 platform = espressif32@6.12.0
board = ttgo-lora32-v2 board = ttgo-lora32-v2
custom_variant = ng20 custom_variant = ng20
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -48,7 +48,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:rnode-ng-21] [env:rnode-ng-21]
platform = espressif32 platform = espressif32@6.12.0
board = ttgo-lora32-v21 board = ttgo-lora32-v21
custom_variant = ng21 custom_variant = ng21
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -62,7 +62,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:ttgo-t-beam] [env:ttgo-t-beam]
platform = espressif32 platform = espressif32@6.12.0
board = ttgo-t-beam board = ttgo-t-beam
custom_variant = tbeam custom_variant = tbeam
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -76,7 +76,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:ttgo-t-beam-sx1262] [env:ttgo-t-beam-sx1262]
platform = espressif32 platform = espressif32@6.12.0
board = ttgo-t-beam board = ttgo-t-beam
custom_variant = tbeam_sx1262 custom_variant = tbeam_sx1262
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -91,7 +91,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:ttgo-t-beam-supreme] [env:ttgo-t-beam-supreme]
platform = espressif32 platform = espressif32@6.12.0
board = ttgo-t-beam board = ttgo-t-beam
custom_variant = tbeam_supreme custom_variant = tbeam_supreme
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -108,7 +108,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:lilygo-t3-s3] [env:lilygo-t3-s3]
platform = espressif32 platform = espressif32@6.12.0
board = lilygo-t3-s3 board = lilygo-t3-s3
custom_variant = t3s3 custom_variant = t3s3
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -123,7 +123,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:lilygo-t3-s3-sx127x] [env:lilygo-t3-s3-sx127x]
platform = espressif32 platform = espressif32@6.12.0
board = lilygo-t3-s3 board = lilygo-t3-s3
custom_variant = t3s3_sx127x custom_variant = t3s3_sx127x
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -138,7 +138,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:lilygo-t3-s3-sx1280-pa] [env:lilygo-t3-s3-sx1280-pa]
platform = espressif32 platform = espressif32@6.12.0
board = lilygo-t3-s3 board = lilygo-t3-s3
custom_variant = t3s3_sx1280_pa custom_variant = t3s3_sx1280_pa
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -153,7 +153,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:lilygo-t-deck] [env:lilygo-t-deck]
platform = espressif32 platform = espressif32@6.12.0
board = esp32-s3-devkitc-1 board = esp32-s3-devkitc-1
custom_variant = tdeck custom_variant = tdeck
board_build.filesystem = littlefs board_build.filesystem = littlefs
@@ -176,7 +176,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:ttgo-lora32-v1] [env:ttgo-lora32-v1]
platform = espressif32 platform = espressif32@6.12.0
board = ttgo-lora32-v1 board = ttgo-lora32-v1
custom_variant = lora32v10 custom_variant = lora32v10
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -190,7 +190,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:ttgo-lora32-v2] [env:ttgo-lora32-v2]
platform = espressif32 platform = espressif32@6.12.0
board = ttgo-lora32-v2 board = ttgo-lora32-v2
custom_variant = lora32v20 custom_variant = lora32v20
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -204,7 +204,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:ttgo-lora32-v2-extled] [env:ttgo-lora32-v2-extled]
platform = espressif32 platform = espressif32@6.12.0
board = ttgo-lora32-v2 board = ttgo-lora32-v2
custom_variant = lora32v20_extled custom_variant = lora32v20_extled
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -219,7 +219,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:ttgo-lora32-v21] [env:ttgo-lora32-v21]
platform = espressif32 platform = espressif32@6.12.0
board = ttgo-lora32-v21 board = ttgo-lora32-v21
custom_variant = lora32v21 custom_variant = lora32v21
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -233,7 +233,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:ttgo-lora32-v21-extled] [env:ttgo-lora32-v21-extled]
platform = espressif32 platform = espressif32@6.12.0
board = ttgo-lora32-v21 board = ttgo-lora32-v21
custom_variant = lora32v21_extled custom_variant = lora32v21_extled
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -248,7 +248,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:ttgo-lora32-v21-tcxo] [env:ttgo-lora32-v21-tcxo]
platform = espressif32 platform = espressif32@6.12.0
board = ttgo-lora32-v21 board = ttgo-lora32-v21
custom_variant = lora32v21_extled custom_variant = lora32v21_extled
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -263,7 +263,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:heltec_wifi_lora_32_V2] [env:heltec_wifi_lora_32_V2]
platform = espressif32 platform = espressif32@6.12.0
board = heltec_wifi_lora_32_V2 board = heltec_wifi_lora_32_V2
custom_variant = heltec32v2 custom_variant = heltec32v2
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -277,7 +277,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:heltec_wifi_lora_32_V2-extled] [env:heltec_wifi_lora_32_V2-extled]
platform = espressif32 platform = espressif32@6.12.0
board = heltec_wifi_lora_32_V2 board = heltec_wifi_lora_32_V2
custom_variant = heltec32v2_extled custom_variant = heltec32v2_extled
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -292,7 +292,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:heltec_wifi_lora_32_V3] [env:heltec_wifi_lora_32_V3]
platform = espressif32 platform = espressif32@6.12.0
board = heltec_wifi_lora_32_V3 board = heltec_wifi_lora_32_V3
custom_variant = heltec32v3 custom_variant = heltec32v3
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -306,7 +306,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:heltec_V3_boundary] [env:heltec_V3_boundary]
platform = espressif32 platform = espressif32@6.12.0
board = heltec_wifi_lora_32_V3 board = heltec_wifi_lora_32_V3
custom_variant = heltec32v3 custom_variant = heltec32v3
board_build.filesystem = littlefs board_build.filesystem = littlefs
@@ -333,7 +333,7 @@ lib_deps =
monitor_filters = esp32_exception_decoder monitor_filters = esp32_exception_decoder
[env:heltec_wifi_lora_32_V4] [env:heltec_wifi_lora_32_V4]
platform = espressif32 platform = espressif32@6.12.0
board = esp32-s3-devkitc-1 board = esp32-s3-devkitc-1
custom_variant = heltec32v4 custom_variant = heltec32v4
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -348,7 +348,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:meshadventurer_S3_boundary] [env:meshadventurer_S3_boundary]
platform = espressif32 platform = espressif32@6.12.0
board = esp32-s3-devkitc-1 board = esp32-s3-devkitc-1
custom_variant = meshadventurer_s3_boundary custom_variant = meshadventurer_s3_boundary
board_build.filesystem = littlefs board_build.filesystem = littlefs
@@ -376,7 +376,7 @@ lib_deps =
monitor_filters = esp32_exception_decoder monitor_filters = esp32_exception_decoder
[env:heltec_V4_boundary] [env:heltec_V4_boundary]
platform = espressif32 platform = espressif32@6.12.0
board = esp32-s3-devkitc-1 board = esp32-s3-devkitc-1
custom_variant = heltec32v4_boundary custom_variant = heltec32v4_boundary
board_build.filesystem = littlefs board_build.filesystem = littlefs
@@ -404,7 +404,7 @@ lib_deps =
monitor_filters = esp32_exception_decoder monitor_filters = esp32_exception_decoder
[env:heltec_V4_boundary-local] [env:heltec_V4_boundary-local]
platform = espressif32 platform = espressif32@6.12.0
board = esp32-s3-devkitc-1 board = esp32-s3-devkitc-1
custom_variant = heltec32v4_boundary_local custom_variant = heltec32v4_boundary_local
board_build.filesystem = littlefs board_build.filesystem = littlefs
@@ -429,7 +429,7 @@ lib_deps =
monitor_filters = esp32_exception_decoder monitor_filters = esp32_exception_decoder
[env:featheresp32] [env:featheresp32]
platform = espressif32 platform = espressif32@6.12.0
board = featheresp32 board = featheresp32
custom_variant = featheresp32 custom_variant = featheresp32
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -443,7 +443,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:seeed_xiao_esp32s3] [env:seeed_xiao_esp32s3]
platform = espressif32 platform = espressif32@6.12.0
board = seeed_xiao_esp32s3 board = seeed_xiao_esp32s3
custom_variant = xiao_esp32s3 custom_variant = xiao_esp32s3
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -457,7 +457,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:generic-esp32] [env:generic-esp32]
platform = espressif32 platform = espressif32@6.12.0
board = esp32dev board = esp32dev
custom_variant = esp32_generic custom_variant = esp32_generic
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv
@@ -489,7 +489,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4 adafruit/Adafruit NeoPixel@^1.15.4
[env:ttgo-t-beam-local] [env:ttgo-t-beam-local]
platform = espressif32 platform = espressif32@6.12.0
board = ttgo-t-beam board = ttgo-t-beam
upload_speed = 460800 upload_speed = 460800
custom_variant = tbeam_local custom_variant = tbeam_local
@@ -507,7 +507,7 @@ lib_deps =
monitor_filters = esp32_exception_decoder monitor_filters = esp32_exception_decoder
[env:ttgo-lora32-v21-local] [env:ttgo-lora32-v21-local]
platform = espressif32 platform = espressif32@6.12.0
board = ttgo-lora32-v21 board = ttgo-lora32-v21
upload_speed = 460800 upload_speed = 460800
custom_variant = lora32v21_local custom_variant = lora32v21_local
@@ -523,7 +523,7 @@ lib_deps =
monitor_filters = esp32_exception_decoder monitor_filters = esp32_exception_decoder
[env:heltec_wifi_lora_32_V4-local] [env:heltec_wifi_lora_32_V4-local]
platform = espressif32 platform = espressif32@6.12.0
board = esp32-s3-devkitc-1 board = esp32-s3-devkitc-1
custom_variant = heltec32v4_local custom_variant = heltec32v4_local
board_build.partitions = no_ota.csv board_build.partitions = no_ota.csv

View File

@@ -96,6 +96,14 @@
#define SPI spiModem #define SPI spiModem
#endif #endif
#if HAS_LORA_PA
uint8_t lora_pa_model = LORA_PA_MODEL;
#endif
#if HAS_LORA_LNA
int lora_lna_gain = LORA_LNA_GAIN;
#endif
extern SPIClass SPI; extern SPIClass SPI;
#define MAX_PKT_LENGTH 255 #define MAX_PKT_LENGTH 255
@@ -275,6 +283,21 @@ void sx126x::setPacketParams(long preamble_symbols, uint8_t headermode, uint8_t
buf[7] = 0x00; buf[7] = 0x00;
buf[8] = 0x00; buf[8] = 0x00;
executeOpcode(OP_PACKET_PARAMS_6X, buf, 9); executeOpcode(OP_PACKET_PARAMS_6X, buf, 9);
// SX1262 errata section 15.4: IQ polarity is inverted compared to
// SX1276. The SetPacketParams command resets register 0x0736 to an
// incorrect default. For standard IQ (no inversion), bit 2 must be
// SET after every SetPacketParams call. For inverted IQ, bit 2 must
// be CLEARED. Without this fix, LoRa RX demodulation fails silently
// while TX continues to work.
uint8_t iqreg = readRegister(0x0736);
if (buf[5] == 0x00) {
// Standard IQ: set bit 2
writeRegister(0x0736, iqreg | 0x04);
} else {
// Inverted IQ: clear bit 2
writeRegister(0x0736, iqreg & ~0x04);
}
} }
void sx126x::reset(void) { void sx126x::reset(void) {
@@ -287,6 +310,22 @@ void sx126x::reset(void) {
} }
} }
void sx126x::setDCDCRegulator(void) {
// Documentation
// 5. Power Distribution -> 5.1 Selecting DC-DC Converter or LDO Regulation
// 13.1.11 SetRegulatorMode
uint8_t mode_byte = MODE_STDBY_RC_6X;
executeOpcode(OP_STANDBY_6X, &mode_byte, 1);
// Enable DC-DC regulator for high power operation
uint8_t reg_mode = 0x01; // 0x00 = LDO, 0x01 = DC-DC
executeOpcode(OP_REGULATOR_MODE_6X, &reg_mode, 1);
delay(5);
waitOnBusy();
}
void sx126x::calibrate(void) { void sx126x::calibrate(void) {
// Put in STDBY_RC mode before calibration // Put in STDBY_RC mode before calibration
uint8_t mode_byte = MODE_STDBY_RC_6X; uint8_t mode_byte = MODE_STDBY_RC_6X;
@@ -319,10 +358,19 @@ int sx126x::begin(long frequency) {
if (_rxen != -1) { pinMode(_rxen, OUTPUT); } if (_rxen != -1) { pinMode(_rxen, OUTPUT); }
if (_txen != -1) { pinMode(_txen, OUTPUT); } if (_txen != -1) { pinMode(_txen, OUTPUT); }
//TODO: if it works, make it optional
//#ifdef SX1262_USE_DCDC_REGULATOR
setDCDCRegulator();
//#endif
calibrate(); calibrate();
calibrate_image(frequency); calibrate_image(frequency);
#if HAS_TCXO
enableTCXO(); enableTCXO();
//13.1.15 SetRxTxFallbackMode to STDBY_XOSC
uint8_t fallback_mode = 0x30; // STDBY_XOSC after TX/RX
executeOpcode(OP_RX_TX_FALLBACK_MODE_6X, &fallback_mode, 1);
#endif
loraMode(); loraMode();
standby(); standby();
@@ -339,7 +387,9 @@ int sx126x::begin(long frequency) {
setFrequency(frequency); setFrequency(frequency);
setTxPower(2); setTxPower(2);
enableCrc(); enableCrc();
writeRegister(REG_LNA_6X, 0x96); // Set LNA boost writeRegister(REG_LNA_6X, 0x96); // Set LNA boosted gain mode
// Undocumented SX1262 register patch recommended by Heltec/Semtech for improved RX sensitivity.
writeRegister(0x08B5, readRegister(0x08B5) | 0x01);
uint8_t basebuf[2] = {0}; // Set base addresses uint8_t basebuf[2] = {0}; // Set base addresses
executeOpcode(OP_BUFFER_BASE_ADDR_6X, basebuf, 2); executeOpcode(OP_BUFFER_BASE_ADDR_6X, basebuf, 2);
@@ -347,7 +397,22 @@ int sx126x::begin(long frequency) {
setPacketParams(_preambleLength, _implicitHeaderMode, _payloadLength, _crcMode); setPacketParams(_preambleLength, _implicitHeaderMode, _payloadLength, _crcMode);
#if HAS_LORA_PA #if HAS_LORA_PA
#if LORA_PA_GC1109 if (lora_pa_model == LORA_PA_UNKNOWN) {
#if BOARD_MODEL == BOARD_HELTEC32_V4
pinMode(LORA_PA_PWR_EN, OUTPUT);
pinMode(LORA_PA_CSD, INPUT);
digitalWrite(LORA_PA_PWR_EN, HIGH); delay(5);
if (digitalRead(LORA_PA_CSD) == HIGH) {
lora_pa_model = LORA_PA_KCT8103L;
lora_lna_gain = LORA_LNA_KCT8103L_GAIN;
} else {
lora_pa_model = LORA_PA_GC1109;
}
#endif
}
if (lora_pa_model == LORA_PA_GC1109) {
// Enable Vfem_ctl for supply to // Enable Vfem_ctl for supply to
// PA power net. // PA power net.
pinMode(LORA_PA_PWR_EN, OUTPUT); pinMode(LORA_PA_PWR_EN, OUTPUT);
@@ -372,7 +437,26 @@ int sx126x::begin(long frequency) {
// is driven by the SX1262 DIO2 // is driven by the SX1262 DIO2
// pin directly, so we do not // pin directly, so we do not
// need to manually raise this. // need to manually raise this.
#endif
} else if (lora_pa_model == LORA_PA_KCT8103L) {
// Enable Vfem_ctl for supply to
// PA power net.
pinMode(LORA_PA_PWR_EN, OUTPUT);
digitalWrite(LORA_PA_PWR_EN, HIGH);
// Enable KCT8103L chip
pinMode(LORA_PA_CSD, OUTPUT);
digitalWrite(LORA_PA_CSD, HIGH);
// Enable receive LNA
pinMode(LORA_PA_CTX, OUTPUT);
digitalWrite(LORA_PA_CTX, LOW);
// On Heltec V4.3, the PA CPS pin
// is driven by the SX1262 DIO2
// pin directly, so we do not
// need to manually raise this.
}
#endif #endif
return 1; return 1;
@@ -382,14 +466,17 @@ void sx126x::end() { sleep(); SPI.end(); _preinit_done = false; }
int sx126x::beginPacket(int implicitHeader) { int sx126x::beginPacket(int implicitHeader) {
#if HAS_LORA_PA #if HAS_LORA_PA
#if LORA_PA_GC1109 if (lora_pa_model == LORA_PA_GC1109) {
// Enable PA CPS for transmit // Enable PA CPS for transmit
// digitalWrite(LORA_PA_CPS, HIGH); // digitalWrite(LORA_PA_CPS, HIGH);
// Disabled since we're keeping it // Disabled since we're keeping it
// on permanently as long as the // on permanently as long as the
// radio is powered up. // radio is powered up.
} else if (lora_pa_model == LORA_PA_KCT8103L) {
digitalWrite(LORA_PA_CTX, HIGH);
}
#endif #endif
#endif
if (_txen != -1) { digitalWrite(_txen, HIGH); } //Set TXen high when transmitting if (_txen != -1) { digitalWrite(_txen, HIGH); } //Set TXen high when transmitting
standby(); standby();
@@ -405,6 +492,7 @@ int sx126x::beginPacket(int implicitHeader) {
int sx126x::endPacket() { int sx126x::endPacket() {
setPacketParams(_preambleLength, _implicitHeaderMode, _payloadLength, _crcMode); setPacketParams(_preambleLength, _implicitHeaderMode, _payloadLength, _crcMode);
if (_rxen != -1) { digitalWrite(_rxen, LOW); } //Set RXen low when transmitting if (_rxen != -1) { digitalWrite(_rxen, LOW); } //Set RXen low when transmitting
uint8_t timeout[3] = {0}; // Put in single TX mode uint8_t timeout[3] = {0}; // Put in single TX mode
@@ -479,7 +567,7 @@ int ISR_VECT sx126x::currentRssi() {
executeOpcodeRead(OP_CURRENT_RSSI_6X, &byte, 1); executeOpcodeRead(OP_CURRENT_RSSI_6X, &byte, 1);
int rssi = -(int(byte)) / 2; int rssi = -(int(byte)) / 2;
#if HAS_LORA_LNA #if HAS_LORA_LNA
rssi -= LORA_LNA_GAIN; rssi -= lora_lna_gain;
#endif #endif
return rssi; return rssi;
} }
@@ -495,7 +583,7 @@ int ISR_VECT sx126x::packetRssi() {
executeOpcodeRead(OP_PACKET_STATUS_6X, buf, 3); executeOpcodeRead(OP_PACKET_STATUS_6X, buf, 3);
int pkt_rssi = -buf[0] / 2; int pkt_rssi = -buf[0] / 2;
#if HAS_LORA_LNA #if HAS_LORA_LNA
pkt_rssi -= LORA_LNA_GAIN; pkt_rssi -= lora_lna_gain;
#endif #endif
return pkt_rssi; return pkt_rssi;
} }
@@ -602,7 +690,7 @@ void sx126x::onReceive(void(*callback)(int)){
void sx126x::receive(int size) { void sx126x::receive(int size) {
#if HAS_LORA_PA #if HAS_LORA_PA
#if LORA_PA_GC1109 if (lora_pa_model == LORA_PA_GC1109) {
// Disable PA CPS for receive // Disable PA CPS for receive
// digitalWrite(LORA_PA_CPS, LOW); // digitalWrite(LORA_PA_CPS, LOW);
// That turned out to be a bad idea. // That turned out to be a bad idea.
@@ -610,7 +698,9 @@ void sx126x::receive(int size) {
// on and off too quickly. We'll keep // on and off too quickly. We'll keep
// it on permanently, as long as the // it on permanently, as long as the
// radio is powered up. // radio is powered up.
#endif } else if (lora_pa_model == LORA_PA_KCT8103L) {
digitalWrite(LORA_PA_CTX, LOW);
}
#endif #endif
if (size > 0) { if (size > 0) {

View File

@@ -74,6 +74,7 @@ public:
void disableCrc(); void disableCrc();
void enableTCXO(); void enableTCXO();
void disableTCXO(); void disableTCXO();
void setDCDCRegulator();
void rxAntEnable(); void rxAntEnable();
void loraMode(); void loraMode();
@@ -97,6 +98,8 @@ public:
void dumpRegisters(Stream& out); void dumpRegisters(Stream& out);
bool isKCT8103L() { return _kct8103l; }
private: private:
void explicitHeaderMode(); void explicitHeaderMode();
void implicitHeaderMode(); void implicitHeaderMode();
@@ -107,7 +110,8 @@ public:
// Poll for deferred DIO0 interrupt (call from main loop) // Poll for deferred DIO0 interrupt (call from main loop)
void pollDio0(); void pollDio0();
private: uint8_t readRegister(uint16_t address); private:
uint8_t readRegister(uint16_t address);
void writeRegister(uint16_t address, uint8_t value); void writeRegister(uint16_t address, uint8_t value);
uint8_t singleTransfer(uint8_t opcode, uint16_t address, uint8_t value); uint8_t singleTransfer(uint8_t opcode, uint16_t address, uint8_t value);
@@ -142,6 +146,7 @@ private:
int _fifo_rx_addr_ptr; int _fifo_rx_addr_ptr;
uint8_t _packet[255]; uint8_t _packet[255];
bool _preinit_done; bool _preinit_done;
bool _kct8103l;
volatile bool _dio0_risen; volatile bool _dio0_risen;
void (*_onReceive)(int); void (*_onReceive)(int);
}; };