Skip to content

Commit 5a06843

Browse files
Add GPIO_DETECT_PA portduino config, and support 13302 detection with it (#9741)
* Add GPIO_DETECT_PA portduino config, and support 13302 detection with it. * Tweak PA detect gpio to use pinMapping * minor yaml output fixes --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
1 parent a93d4d7 commit 5a06843

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

bin/config.d/lora-hat-rak-6421-pi-hat.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ Lora:
99
DIO3_TCXO_VOLTAGE: true
1010
DIO2_AS_RF_SWITCH: true
1111
spidev: spidev0.0
12+
GPIO_DETECT_PA: 13
13+
TX_GAIN_LORA: [8, 8, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 9, 8, 8, 7]

bin/config.d/lora-usb-umesh-1262-30dbm.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ Lora:
1313
# USB_Serialnum: 12345678
1414
SX126X_MAX_POWER: 22
1515
# Reduce output power to improve EMI
16-
NUM_PA_POINTS: 22
17-
TX_GAIN_LORA: 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 9, 8, 8, 7
16+
TX_GAIN_LORA: [12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 9, 8, 8, 7]
1817
# Note: This module integrates an additional PA to achieve higher output power.
1918
# The 'power' parameter here does not represent the actual RF output.
2019
# TX_GAIN_LORA defines the gain offset applied at each SX1262 input power step (1–22 dBm).

bin/config.d/lora-usb-umesh-1268-30dbm.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ Lora:
1313
# USB_Serialnum: 12345678
1414
SX126X_MAX_POWER: 22
1515
# Reduce output power to improve EMI
16-
NUM_PA_POINTS: 22
17-
TX_GAIN_LORA: 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 9, 8, 8, 7
16+
TX_GAIN_LORA: [12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 9, 8, 8, 7]
1817
# Note: This module integrates an additional PA to achieve higher output power.
1918
# The 'power' parameter here does not represent the actual RF output.
2019
# TX_GAIN_LORA defines the gain offset applied at each SX1262 input power step (1–22 dBm).

src/platform/portduino/PortduinoGlue.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,27 @@ void portduinoSetup()
537537
}
538538
}
539539

540+
// In one test, this dance seemed necessary to trigger the pin to detect properly.
541+
if (portduino_config.lora_pa_detect_pin.enabled) {
542+
pinMode(portduino_config.lora_pa_detect_pin.pin, INPUT_PULLDOWN);
543+
sleep(1);
544+
if (digitalRead(portduino_config.lora_pa_detect_pin.pin) == LOW) {
545+
std::cout << "Pin " << portduino_config.lora_pa_detect_pin.pin << " PULLDOWN is LOW" << std::endl;
546+
}
547+
pinMode(portduino_config.lora_pa_detect_pin.pin, INPUT_PULLUP);
548+
sleep(1);
549+
if (digitalRead(portduino_config.lora_pa_detect_pin.pin) == HIGH) {
550+
std::cout << "Pin " << portduino_config.lora_pa_detect_pin.pin << " PULLUP is HIGH, dropping PA curve" << std::endl;
551+
portduino_config.num_pa_points = 1;
552+
portduino_config.tx_gain_lora[0] = 0;
553+
} else {
554+
std::cout << "Pin " << portduino_config.lora_pa_detect_pin.pin << " PULLUP is LOW, using PA curve" << std::endl;
555+
}
556+
557+
// disable bias once finished
558+
pinMode(portduino_config.lora_pa_detect_pin.pin, INPUT);
559+
}
560+
540561
// Only initialize the radio pins when dealing with real, kernel controlled SPI hardware
541562
if (portduino_config.lora_spi_dev != "" && portduino_config.lora_spi_dev != "ch341") {
542563
SPI.begin(portduino_config.lora_spi_dev.c_str());

src/platform/portduino/PortduinoGlue.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ extern struct portduino_config_struct {
107107
pinMapping lora_txen_pin = {"Lora", "TXen"};
108108
pinMapping lora_rxen_pin = {"Lora", "RXen"};
109109
pinMapping lora_sx126x_ant_sw_pin = {"Lora", "SX126X_ANT_SW"};
110+
pinMapping lora_pa_detect_pin = {"Lora", "GPIO_DETECT_PA"};
110111
std::vector<pinMapping> extra_pins = {};
111112

112113
// GPS
@@ -194,13 +195,14 @@ extern struct portduino_config_struct {
194195
int maxtophone = 100;
195196
int MaxNodes = 200;
196197

197-
pinMapping *all_pins[20] = {&lora_cs_pin,
198+
pinMapping *all_pins[21] = {&lora_cs_pin,
198199
&lora_irq_pin,
199200
&lora_busy_pin,
200201
&lora_reset_pin,
201202
&lora_txen_pin,
202203
&lora_rxen_pin,
203204
&lora_sx126x_ant_sw_pin,
205+
&lora_pa_detect_pin,
204206
&displayDC,
205207
&displayCS,
206208
&displayBacklight,
@@ -255,18 +257,23 @@ extern struct portduino_config_struct {
255257
out << YAML::Key << "TX_GAIN_LORA" << YAML::Value << tx_gain_lora[0];
256258
}
257259

258-
out << YAML::Key << "DIO2_AS_RF_SWITCH" << YAML::Value << dio2_as_rf_switch;
260+
if (dio2_as_rf_switch)
261+
out << YAML::Key << "DIO2_AS_RF_SWITCH" << YAML::Value << dio2_as_rf_switch;
259262
if (dio3_tcxo_voltage != 0)
260263
out << YAML::Key << "DIO3_TCXO_VOLTAGE" << YAML::Value << YAML::Precision(3) << (float)dio3_tcxo_voltage / 1000;
261264
if (lora_usb_pid != 0x5512)
262265
out << YAML::Key << "USB_PID" << YAML::Value << YAML::Hex << lora_usb_pid;
263266
if (lora_usb_vid != 0x1A86)
264267
out << YAML::Key << "USB_VID" << YAML::Value << YAML::Hex << lora_usb_vid;
265-
if (lora_spi_dev != "")
268+
if (lora_spi_dev != "" && !(lora_spi_dev == "/dev/spidev0.0" && lora_module == use_autoconf)) {
269+
if (lora_spi_dev.find("/dev/") != std::string::npos)
270+
lora_spi_dev = lora_spi_dev.substr(5);
266271
out << YAML::Key << "spidev" << YAML::Value << lora_spi_dev;
272+
}
267273
if (lora_usb_serial_num != "")
268274
out << YAML::Key << "USB_Serialnum" << YAML::Value << lora_usb_serial_num;
269-
out << YAML::Key << "spiSpeed" << YAML::Value << spiSpeed;
275+
if (spiSpeed != 2000000)
276+
out << YAML::Key << "spiSpeed" << YAML::Value << spiSpeed;
270277
if (rfswitch_dio_pins[0] != RADIOLIB_NC) {
271278
out << YAML::Key << "rfswitch_table" << YAML::Value << YAML::BeginMap;
272279

0 commit comments

Comments
 (0)