diff --git a/Boards.h b/Boards.h index af72286..15e4923 100644 --- a/Boards.h +++ b/Boards.h @@ -373,10 +373,10 @@ const int pin_miso = 19; const int pin_mosi = 23; const int pin_busy = 32; - const int pin_reset = 34; + const int pin_reset = 25; const int pin_dio = 33; - const int pin_txen = -1; - const int pin_rxen = -1; + const int pin_txen = 16; + const int pin_rxen = 17; const int pin_tcxo_enable = -1; const int pin_btn_usr1 = 39; @@ -555,7 +555,7 @@ #define HAS_LORA_LNA true #define PIN_WAKEUP GPIO_NUM_0 #define WAKEUP_LEVEL 0 - #define OCP_TUNED 0x18 + #define OCP_TUNED 0x38 #define Vext GPIO_NUM_36 const int pin_btn_usr1 = 0; @@ -579,13 +579,18 @@ #define LORA_LNA_GAIN 17 #define LORA_LNA_GVT 12 #define LORA_PA_GC1109 true + #define LORA_PA_AUTO_DETECT true #define LORA_PA_PWR_EN 7 - #define LORA_PA_CSD 2 - #define LORA_PA_CPS 46 - #define PA_MAX_OUTPUT 28 - #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_PA_CSD 2 // GC1109: PA_EN | KCT8103L: CSD (same pin, different pull resistor) + #define LORA_PA_CTX 5 // KCT8103L: TX/LNA select (CTX=LOW=LNA, CTX=HIGH=PA) + #define LORA_PA_CPS 46 // GC1109: TX_EN + + #define PA_MAX_OUTPUT 28 + #define PA_GAIN_POINTS 22 + #define PA_GC1109_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 PA_KCT8103L_GAIN_VALUES 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 11, 11, 10, 9, 8, 7 + #define PA_GAIN_VALUES PA_KCT8103L_GAIN_VALUES // compile-time fallback; runtime detection selects correct table const int pin_cs = 8; const int pin_busy = 13; diff --git a/Config.h b/Config.h index 0f1f081..be6cd6e 100644 --- a/Config.h +++ b/Config.h @@ -236,7 +236,7 @@ uint8_t display_addr = 0xFF; volatile bool display_updating = false; bool display_blanking_enabled = false; - bool display_diagnostics = true; + bool display_diagnostics = true; bool device_init_done = false; bool eeprom_ok = false; bool firmware_update_mode = false; diff --git a/Display.h b/Display.h index c5cbad9..1dc2871 100644 --- a/Display.h +++ b/Display.h @@ -53,7 +53,7 @@ #elif BOARD_MODEL == BOARD_HELTEC32_V2 || BOARD_MODEL == BOARD_LORA32_V1_0 #define DISP_RST 16 #define DISP_ADDR 0x3C - #define OBSCL_OLED 15 + #define SCL_OLED 15 #define SDA_OLED 4 #elif BOARD_MODEL == BOARD_HELTEC32_V3 #define DISP_RST 21 @@ -73,7 +73,7 @@ #elif BOARD_MODEL == BOARD_MESHADVENTURER_S3 #define DISP_RST -1 #define DISP_ADDR 0x3C - #define SCL_OLED 44 + #define SCL_OLED 0 #define SDA_OLED 42 #elif BOARD_MODEL == BOARD_MESHADVENTURER #define DISP_RST -1 diff --git a/Makefile b/Makefile index 22a4c56..bf92056 100644 --- a/Makefile +++ b/Makefile @@ -76,29 +76,29 @@ check_bt_buffers: firmware: arduino-cli compile --log --fqbn unsignedio:avr:rnode -firmware-mega2560: - arduino-cli compile --log --fqbn arduino:avr:mega +firmware-aethernode: check_bt_buffers + arduino-cli compile --log --fqbn esp32:esp32:esp32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x35\"" -firmware-tbeam: check_bt_buffers - arduino-cli compile --log --fqbn esp32:esp32:t-beam -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x33\"" +firmware-diy_v1: check_bt_buffers + arduino-cli compile --log --fqbn esp32:esp32:esp32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0xF6\"" -firmware-tbeam_sx126x: check_bt_buffers - arduino-cli compile --log --fqbn esp32:esp32:t-beam -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x33\" \"-DMODEM=0x03\"" +firmware-featheresp32: check_bt_buffers + arduino-cli compile --log --fqbn esp32:esp32:featheresp32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x34\"" -firmware-t3s3: - arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\" \"-DMODEM=0x03\"" +firmware-heltec32_v2: check_bt_buffers + arduino-cli compile --log --fqbn esp32:esp32:heltec_wifi_lora_32_V2 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x38\"" -firmware-t3s3_sx127x: - arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\" \"-DMODEM=0x01\"" +firmware-heltec32_v2_extled: check_bt_buffers + arduino-cli compile --log --fqbn esp32:esp32:heltec_wifi_lora_32_V2 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x38\" \"-DEXTERNAL_LEDS=true\"" -firmware-t3s3_sx1280_pa: - arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\" \"-DMODEM=0x04\"" +firmware-heltec32_v3: + arduino-cli compile --log --fqbn esp32:esp32:heltec_wifi_lora_32_V3 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3A\"" -firmware-tdeck: - arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3B\"" +firmware-heltec32_v4: + arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3F\"" -firmware-tbeam_supreme: - arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=-DBOARD_MODEL=0x3D" +firmware-heltec_t114: + arduino-cli compile --log --fqbn Heltec_nRF52:Heltec_nRF52:HT-n5262 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3C\"" firmware-lora32_v10: check_bt_buffers arduino-cli compile --log --fqbn esp32:esp32:ttgo-lora32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x39\"" @@ -118,17 +118,14 @@ firmware-lora32_v21_extled: check_bt_buffers firmware-lora32_v21_tcxo: check_bt_buffers arduino-cli compile --log --fqbn esp32:esp32:ttgo-lora32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x37\" \"-DENABLE_TCXO=true\"" -firmware-heltec32_v2: check_bt_buffers - arduino-cli compile --log --fqbn esp32:esp32:heltec_wifi_lora_32_V2 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x38\"" +firmware-meshadventurer: check_bt_buffers + arduino-cli compile --log --fqbn esp32:esp32:esp32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0xF4\"" -firmware-heltec32_v2_extled: check_bt_buffers - arduino-cli compile --log --fqbn esp32:esp32:heltec_wifi_lora_32_V2 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x38\" \"-DEXTERNAL_LEDS=true\"" +firmware-meshadventurer_s3: check_bt_buffers + arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0xF2\"" -firmware-heltec32_v3: - arduino-cli compile --log --fqbn esp32:esp32:heltec_wifi_lora_32_V3 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3A\"" - -firmware-heltec32_v4: - arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3F\"" +firmware-meshadventurer_s3_nocdc: check_bt_buffers + arduino-cli compile --log --fqbn "esp32:esp32:esp32s3" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0xF2\"" firmware-rnode_ng_20: check_bt_buffers arduino-cli compile --log --fqbn esp32:esp32:ttgo-lora32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x40\"" @@ -136,32 +133,32 @@ firmware-rnode_ng_20: check_bt_buffers firmware-rnode_ng_21: check_bt_buffers arduino-cli compile --log --fqbn esp32:esp32:ttgo-lora32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x41\"" -firmware-featheresp32: check_bt_buffers - arduino-cli compile --log --fqbn esp32:esp32:featheresp32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x34\"" - -firmware-genericesp32: check_bt_buffers - arduino-cli compile --log --fqbn esp32:esp32:esp32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x35\"" - -firmware-meshadventurer_s3: check_bt_buffers - arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0xF2\"" - -firmware-meshadventurer: check_bt_buffers - arduino-cli compile --log --fqbn esp32:esp32:esp32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0xF4\"" - -firmware-diy_v1: check_bt_buffers - arduino-cli compile --log --fqbn esp32:esp32:esp32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0xF6\"" - -firmware-aethernode: check_bt_buffers - arduino-cli compile --log --fqbn esp32:esp32:esp32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x35\"" +firmware-promicro: + arduino-cli compile --log --fqbn promicro:nrf52:nicenanov2:softdevice=s140v6 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0xF5\"" firmware-rak4631: arduino-cli compile --log --fqbn rakwireless:nrf52:WisCoreRAK4631Board -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x51\"" -firmware-heltec_t114: - arduino-cli compile --log --fqbn Heltec_nRF52:Heltec_nRF52:HT-n5262 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3C\"" +firmware-t3s3: + arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\" \"-DMODEM=0x03\"" -firmware-promicro: - arduino-cli compile --log --fqbn promicro:nrf52:nicenanov2:softdevice=s140v6 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0xF5\"" +firmware-t3s3_sx127x: + arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\" \"-DMODEM=0x01\"" + +firmware-t3s3_sx1280_pa: + arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\" \"-DMODEM=0x04\"" + +firmware-tbeam: check_bt_buffers + arduino-cli compile --log --fqbn esp32:esp32:t-beam -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x33\"" + +firmware-tbeam_supreme: + arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=-DBOARD_MODEL=0x3D" + +firmware-tbeam_sx126x: check_bt_buffers + arduino-cli compile --log --fqbn esp32:esp32:t-beam -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x33\" \"-DMODEM=0x03\"" + +firmware-tdeck: + arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3B\"" firmware-techo: arduino-cli compile --log --fqbn adafruit:nrf52:pca10056 -e --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x44\"" @@ -169,6 +166,12 @@ firmware-techo: firmware-xiao_s3: arduino-cli compile --log --fqbn "esp32:esp32:XIAO_ESP32S3" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3E\"" +firmware-genericesp32: check_bt_buffers + arduino-cli compile --log --fqbn esp32:esp32:esp32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x35\"" + +firmware-mega2560: + arduino-cli compile --log --fqbn arduino:avr:mega + upload: arduino-cli upload -p /dev/ttyUSB0 --fqbn unsignedio:avr:rnode @@ -184,7 +187,14 @@ upload-meshadventurer_s3: # @sleep 1 # rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin) @sleep 3 - python ./Release/esptool/esptool.py --chip esp32 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin + python ./Release/esptool/esptool.py --chip esp32s3 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin + +upload-meshadventurer_s3_usb: + arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:esp32s3 +# @sleep 1 +# rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin) + @sleep 3 + python ./Release/esptool/esptool.py --chip esp32s3 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin upload-meshadventurer: arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:esp32 @@ -257,28 +267,28 @@ upload-heltec32_v3: @sleep 1 rnodeconf /dev/ttyUSB0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.heltec_wifi_lora_32_V3/RNode_Firmware.ino.bin) @sleep 3 - python ./Release/esptool/esptool.py --chip esp32-s3 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin + python ./Release/esptool/esptool.py --chip esp32s3 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin upload-heltec32_v4: arduino-cli upload -p /dev/ttyACM0 --fqbn esp32:esp32:esp32s3 @sleep 1 rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin) @sleep 3 - python ./Release/esptool/esptool.py --chip esp32-s3 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin + python ./Release/esptool/esptool.py --chip esp32s3 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin upload-tdeck: arduino-cli upload -p /dev/ttyACM0 --fqbn esp32:esp32:esp32s3 @sleep 1 rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin) @sleep 3 - python ./Release/esptool/esptool.py --chip esp32-s3 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin + python ./Release/esptool/esptool.py --chip esp32s3 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin upload-tbeam_supreme: arduino-cli upload -p /dev/ttyACM0 --fqbn esp32:esp32:esp32s3 @sleep 1 rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin) @sleep 3 - python ./Release/esptool/esptool.py --chip esp32-s3 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin + python ./Release/esptool/esptool.py --chip esp32s3 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin upload-rnode_ng_20: arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:ttgo-lora32 diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino index 6ec4882..29e58a6 100644 --- a/RNode_Firmware.ino +++ b/RNode_Firmware.ino @@ -1781,7 +1781,13 @@ void sleep_now() { #endif #endif #if BOARD_MODEL == BOARD_HELTEC32_V4 - digitalWrite(LORA_PA_CPS, LOW); + #if LORA_PA_AUTO_DETECT + if (sx126x_modem.isKCT8103L()) { + digitalWrite(LORA_PA_CTX, LOW); + } else { + digitalWrite(LORA_PA_CPS, LOW); + } + #endif digitalWrite(LORA_PA_CSD, LOW); digitalWrite(LORA_PA_PWR_EN, LOW); digitalWrite(Vext, HIGH); diff --git a/Utilities.h b/Utilities.h index 85fe004..381e1dd 100644 --- a/Utilities.h +++ b/Utilities.h @@ -1322,7 +1322,13 @@ int getTxPower() { } #if HAS_LORA_PA - const int tx_gain[PA_GAIN_POINTS] = {PA_GAIN_VALUES}; + #if LORA_PA_AUTO_DETECT + static const int gc1109_tx_gain[PA_GAIN_POINTS] = {PA_GC1109_GAIN_VALUES}; + static const int kct8103l_tx_gain[PA_GAIN_POINTS] = {PA_KCT8103L_GAIN_VALUES}; + const int* tx_gain = sx126x_modem.isKCT8103L() ? kct8103l_tx_gain : gc1109_tx_gain; + #else + const int tx_gain[PA_GAIN_POINTS] = {PA_GAIN_VALUES}; + #endif #endif int map_target_power_to_modem_output(int target_tx_power) { diff --git a/energysave.patch b/energysave.patch deleted file mode 100644 index 249d38c..0000000 --- a/energysave.patch +++ /dev/null @@ -1,133 +0,0 @@ -diff --git a/Display.h b/Display.h -index 7d903b9..882af8d 100644 ---- a/Display.h -+++ b/Display.h -@@ -1071,6 +1071,7 @@ void update_display(bool blank = false) { - #if BOARD_MODEL == BOARD_HELTEC_T114 - display.clear(); - display.display(); -+ digitalWrite(PIN_T114_TFT_BLGT, HIGH); - #elif BOARD_MODEL != BOARD_TDECK && BOARD_MODEL != BOARD_TECHO - display.clearDisplay(); - display.display(); -@@ -1128,6 +1129,9 @@ void update_display(bool blank = false) { - - void display_unblank() { - last_unblank_event = millis(); -+ #if BOARD_MODEL == BOARD_HELTEC_T114 -+ digitalWrite(PIN_T114_TFT_BLGT, LOW); -+ #endif - } - - void ext_fb_enable() { -diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino -index 5649206..ba157e6 100644 ---- a/RNode_Firmware.ino -+++ b/RNode_Firmware.ino -@@ -535,7 +535,9 @@ bool startRadio() { - // Flash an info pattern to indicate - // that the radio is now on - kiss_indicate_radiostate(); -- led_indicate_info(3); -+ if (!display_blanked) { -+ led_indicate_info(3); -+ } - return true; - } - -@@ -575,7 +577,7 @@ volatile bool queue_flushing = false; - void flush_queue(void) { - if (!queue_flushing) { - queue_flushing = true; -- led_tx_on(); -+ if (!display_blanked) { led_tx_on(); } - - #if MCU_VARIANT == MCU_ESP32 || MCU_VARIANT == MCU_NRF52 - while (!fifo16_isempty(&packet_starts)) { -@@ -596,7 +598,7 @@ void flush_queue(void) { - } - } - -- lora_receive(); led_tx_off(); -+ lora_receive(); if (!display_blanked) { led_tx_off(); } - } - - queue_height = 0; -@@ -615,7 +617,8 @@ void flush_queue(void) { - - void pop_queue() { - if (!queue_flushing) { -- queue_flushing = true; led_tx_on(); -+ queue_flushing = true; -+ if (!display_blanked) { led_tx_on(); } - - #if MCU_VARIANT == MCU_ESP32 || MCU_VARIANT == MCU_NRF52 - if (!fifo16_isempty(&packet_starts)) { -@@ -637,7 +640,8 @@ void pop_queue() { - queued_bytes -= length; - } - -- lora_receive(); led_tx_off(); -+ lora_receive(); -+ if (!display_blanked) { led_tx_off(); } - } - - #if MCU_VARIANT == MCU_ESP32 || MCU_VARIANT == MCU_NRF52 -@@ -751,7 +755,7 @@ void transmit(uint16_t size) { - add_airtime(written); - - } else { -- led_tx_on(); uint16_t written = 0; -+ if (!display_blanked) { led_tx_on(); } uint16_t written = 0; - if (size > SINGLE_MTU) { size = SINGLE_MTU; } - if (!implicit) { LoRa->beginPacket(); } - else { LoRa->beginPacket(size); } -@@ -984,7 +988,7 @@ void serial_callback(uint8_t sbyte) { - } else if (command == CMD_RADIO_LOCK) { - update_radio_lock(); - kiss_indicate_radio_lock(); -- } else if (command == CMD_BLINK) { -+ } else if (command == CMD_BLINK && !display_blanked) { - led_indicate_info(sbyte); - } else if (command == CMD_RANDOM) { - kiss_indicate_random(getRandom()); -@@ -1431,13 +1435,15 @@ void update_modem_status() { - if (carrier_detected) { dcd = true; } else { dcd = false; } - - dcd_led = dcd; -- if (dcd_led) { led_rx_on(); } -+ if (!display_blanked && dcd_led) { led_rx_on(); } - else { - if (interference_detected) { -- if (led_id_filter >= LED_ID_TRIG && noise_floor_sampled) { led_id_on(); } -+ if (led_id_filter >= LED_ID_TRIG && noise_floor_sampled && !display_blanked) { led_id_on(); } - } else { -- if (airtime_lock) { led_indicate_airtime_lock(); } -- else { led_rx_off(); led_id_off(); } -+ if (airtime_lock && !display_blanked) { led_indicate_airtime_lock(); } -+ else { -+ if (!display_blanked) { led_rx_off(); led_id_off(); } -+ } - } - } - } -@@ -1707,7 +1713,9 @@ void loop() { - console_loop(); - #endif - } else { -- led_indicate_standby(); -+ if (!display_blanked) { -+ led_indicate_standby(); -+ } - } - } else { - -diff --git a/arduino-cli.yaml b/arduino-cli.yaml -index 6dd5f8d..d358070 100644 ---- a/arduino-cli.yaml -+++ b/arduino-cli.yaml -@@ -4,4 +4,3 @@ board_manager: - - https://raw.githubusercontent.com/RAKwireless/RAKwireless-Arduino-BSP-Index/main/package_rakwireless_index.json - - https://github.com/HelTecAutomation/Heltec_nRF52/releases/download/1.7.0/package_heltec_nrf_index.json - - https://adafruit.github.io/arduino-board-index/package_adafruit_index.json -- - http://unsigned.io/arduino/package_unsignedio_UnsignedBoards_index.json diff --git a/sx126x.cpp b/sx126x.cpp index ad1fca1..d0e6c05 100644 --- a/sx126x.cpp +++ b/sx126x.cpp @@ -363,7 +363,9 @@ int sx126x::begin(long frequency) { setFrequency(frequency); setTxPower(2); 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 executeOpcode(OP_BUFFER_BASE_ADDR_6X, basebuf, 2); @@ -371,31 +373,29 @@ int sx126x::begin(long frequency) { setPacketParams(_preambleLength, _implicitHeaderMode, _payloadLength, _crcMode); #if HAS_LORA_PA - #if LORA_PA_GC1109 - // Enable Vfem_ctl for supply to - // PA power net. + #if LORA_PA_AUTO_DETECT + // Power up the FEM, then read GPIO LORA_PA_CSD as input. + // The V4.2 (GC1109) board pulls it LOW; V4.3 (KCT8103L) pulls it HIGH. pinMode(LORA_PA_PWR_EN, OUTPUT); digitalWrite(LORA_PA_PWR_EN, HIGH); + delay(1); + pinMode(LORA_PA_CSD, INPUT); + delay(1); + _kct8103l = (digitalRead(LORA_PA_CSD) == HIGH); - // Enable PA LNA and TX standby - pinMode(LORA_PA_CSD, OUTPUT); - digitalWrite(LORA_PA_CSD, HIGH); - - // Keep PA CPS low until actual - // transmit. Does it save power? - // Who knows? Will have to measure. - // Note from the future: Nope. - // Power consumption is the same, - // and turning it on and off is - // not something that it likes. - // Keeping it high for now. - pinMode(LORA_PA_CPS, OUTPUT); - digitalWrite(LORA_PA_CPS, HIGH); - - // On Heltec V4, the PA CTX pin - // is driven by the SX1262 DIO2 - // pin directly, so we do not - // need to manually raise this. + if (_kct8103l) { + // KCT8103L (V4.3): CSD=HIGH enables chip, CTX=LOW=LNA/RX, CTX=HIGH=PA/TX + pinMode(LORA_PA_CSD, OUTPUT); + digitalWrite(LORA_PA_CSD, HIGH); + pinMode(LORA_PA_CTX, OUTPUT); + digitalWrite(LORA_PA_CTX, LOW); // LNA enabled by default + } else { + // GC1109 (V4.2): PA_EN=HIGH enables chip, CPS=HIGH=full PA mode + pinMode(LORA_PA_CSD, OUTPUT); + digitalWrite(LORA_PA_CSD, HIGH); + pinMode(LORA_PA_CPS, OUTPUT); + digitalWrite(LORA_PA_CPS, HIGH); + } #endif #endif @@ -406,12 +406,12 @@ void sx126x::end() { sleep(); SPI.end(); _preinit_done = false; } int sx126x::beginPacket(int implicitHeader) { #if HAS_LORA_PA - #if LORA_PA_GC1109 - // Enable PA CPS for transmit - // digitalWrite(LORA_PA_CPS, HIGH); - // Disabled since we're keeping it - // on permanently as long as the - // radio is powered up. + #if LORA_PA_AUTO_DETECT + if (_kct8103l) { + // CTX=HIGH: switch KCT8103L to PA/TX mode. + digitalWrite(LORA_PA_CTX, HIGH); + } + // GC1109: CPS kept HIGH permanently, no action needed. #endif #endif @@ -628,14 +628,12 @@ void sx126x::onReceive(void(*callback)(int)){ void sx126x::receive(int size) { #if HAS_LORA_PA - #if LORA_PA_GC1109 - // Disable PA CPS for receive - // digitalWrite(LORA_PA_CPS, LOW); - // That turned out to be a bad idea. - // The LNA goes wonky if it's toggled - // on and off too quickly. We'll keep - // it on permanently, as long as the - // radio is powered up. + #if LORA_PA_AUTO_DETECT + if (_kct8103l) { + // CTX=LOW: switch KCT8103L to LNA/RX mode. + digitalWrite(LORA_PA_CTX, LOW); + } + // GC1109: CPS kept HIGH permanently, no action needed. #endif #endif diff --git a/sx126x.h b/sx126x.h index d3237d0..0efb29f 100644 --- a/sx126x.h +++ b/sx126x.h @@ -98,6 +98,8 @@ public: void dumpRegisters(Stream& out); + bool isKCT8103L() { return _kct8103l; } + private: void explicitHeaderMode(); void implicitHeaderMode(); @@ -139,6 +141,7 @@ private: int _fifo_rx_addr_ptr; uint8_t _packet[255]; bool _preinit_done; + bool _kct8103l; void (*_onReceive)(int); };