Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions Boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,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;
Expand All @@ -422,14 +422,17 @@

#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;
Expand Down
8 changes: 7 additions & 1 deletion RNode_Firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1767,7 +1767,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);
Expand Down
8 changes: 7 additions & 1 deletion Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,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) {
Expand Down
1 change: 0 additions & 1 deletion arduino-cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
74 changes: 36 additions & 38 deletions sx126x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,39 +335,39 @@ 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);

setModulationParams(_sf, _bw, _cr, _ldro);
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);

// 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.
delay(1);
pinMode(LORA_PA_CSD, INPUT);
delay(1);
_kct8103l = (digitalRead(LORA_PA_CSD) == HIGH);

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

Expand All @@ -378,12 +378,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

Expand Down Expand Up @@ -595,14 +595,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

Expand Down
3 changes: 3 additions & 0 deletions sx126x.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class sx126x : public Stream {

void dumpRegisters(Stream& out);

bool isKCT8103L() { return _kct8103l; }

private:
void explicitHeaderMode();
void implicitHeaderMode();
Expand Down Expand Up @@ -137,6 +139,7 @@ class sx126x : public Stream {
int _fifo_rx_addr_ptr;
uint8_t _packet[255];
bool _preinit_done;
bool _kct8103l;
void (*_onReceive)(int);
};

Expand Down