mirror of
https://github.com/alexhopeoconnor/firmware.git
synced 2026-10-15 07:51:19 +10:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1dff791462 | ||
|
|
a54dccf3f1 | ||
|
|
0bf5381a8c | ||
|
|
350ca1f0ca | ||
|
|
bd36921d29 | ||
|
|
6391baf557 | ||
|
|
6b34d72fba |
@@ -5,7 +5,11 @@ Lora:
|
|||||||
IRQ: 22 #IO6
|
IRQ: 22 #IO6
|
||||||
Reset: 16 # IO4
|
Reset: 16 # IO4
|
||||||
Busy: 24 # IO5
|
Busy: 24 # IO5
|
||||||
# Ant_sw: 13 # IO3
|
Enable_Pins:
|
||||||
|
- 12
|
||||||
|
- 13
|
||||||
DIO3_TCXO_VOLTAGE: true
|
DIO3_TCXO_VOLTAGE: true
|
||||||
DIO2_AS_RF_SWITCH: true
|
DIO2_AS_RF_SWITCH: true
|
||||||
spidev: spidev0.0
|
spidev: spidev0.0
|
||||||
|
GPIO_DETECT_PA: 13
|
||||||
|
TX_GAIN_LORA: [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]
|
||||||
@@ -13,8 +13,7 @@ Lora:
|
|||||||
# USB_Serialnum: 12345678
|
# USB_Serialnum: 12345678
|
||||||
SX126X_MAX_POWER: 22
|
SX126X_MAX_POWER: 22
|
||||||
# Reduce output power to improve EMI
|
# Reduce output power to improve EMI
|
||||||
NUM_PA_POINTS: 22
|
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]
|
||||||
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
|
|
||||||
# Note: This module integrates an additional PA to achieve higher output power.
|
# Note: This module integrates an additional PA to achieve higher output power.
|
||||||
# The 'power' parameter here does not represent the actual RF output.
|
# The 'power' parameter here does not represent the actual RF output.
|
||||||
# TX_GAIN_LORA defines the gain offset applied at each SX1262 input power step (1–22 dBm).
|
# TX_GAIN_LORA defines the gain offset applied at each SX1262 input power step (1–22 dBm).
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ Lora:
|
|||||||
# USB_Serialnum: 12345678
|
# USB_Serialnum: 12345678
|
||||||
SX126X_MAX_POWER: 22
|
SX126X_MAX_POWER: 22
|
||||||
# Reduce output power to improve EMI
|
# Reduce output power to improve EMI
|
||||||
NUM_PA_POINTS: 22
|
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]
|
||||||
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
|
|
||||||
# Note: This module integrates an additional PA to achieve higher output power.
|
# Note: This module integrates an additional PA to achieve higher output power.
|
||||||
# The 'power' parameter here does not represent the actual RF output.
|
# The 'power' parameter here does not represent the actual RF output.
|
||||||
# TX_GAIN_LORA defines the gain offset applied at each SX1262 input power step (1–22 dBm).
|
# TX_GAIN_LORA defines the gain offset applied at each SX1262 input power step (1–22 dBm).
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -496,14 +497,19 @@ void portduinoSetup()
|
|||||||
randomSeed(time(NULL));
|
randomSeed(time(NULL));
|
||||||
|
|
||||||
std::string defaultGpioChipName = gpioChipName + std::to_string(portduino_config.lora_default_gpiochip);
|
std::string defaultGpioChipName = gpioChipName + std::to_string(portduino_config.lora_default_gpiochip);
|
||||||
|
|
||||||
|
std::set<int> used_pins;
|
||||||
|
|
||||||
for (const auto *i : portduino_config.all_pins) {
|
for (const auto *i : portduino_config.all_pins) {
|
||||||
if (i->enabled && i->pin > max_GPIO)
|
if (i->enabled && i->pin > max_GPIO) {
|
||||||
max_GPIO = i->pin;
|
max_GPIO = i->pin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto i : portduino_config.extra_pins) {
|
for (auto i : portduino_config.extra_pins) {
|
||||||
if (i.enabled && i.pin > max_GPIO)
|
if (i.enabled && i.pin > max_GPIO) {
|
||||||
max_GPIO = i.pin;
|
max_GPIO = i.pin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gpioInit(max_GPIO + 1); // Done here so we can inform Portduino how many GPIOs we need.
|
gpioInit(max_GPIO + 1); // Done here so we can inform Portduino how many GPIOs we need.
|
||||||
@@ -517,12 +523,18 @@ void portduinoSetup()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (i->enabled) {
|
if (i->enabled) {
|
||||||
if (initGPIOPin(i->pin, gpioChipName + std::to_string(i->gpiochip), i->line) != ERRNO_OK) {
|
if (used_pins.find(i->pin) != used_pins.end()) {
|
||||||
printf("Error setting pin number %d. It may not exist, or may already be in use.\n", i->line);
|
printf("Pin %d is in use for multiple purposes\n", i->pin);
|
||||||
exit(EXIT_FAILURE);
|
} else {
|
||||||
|
if (initGPIOPin(i->pin, gpioChipName + std::to_string(i->gpiochip), i->line) != ERRNO_OK) {
|
||||||
|
printf("Error setting pin number %d. It may not exist, or may already be in use.\n", i->line);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
used_pins.insert(i->pin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
printf("Initializing extra pins\n");
|
||||||
for (auto i : portduino_config.extra_pins) {
|
for (auto i : portduino_config.extra_pins) {
|
||||||
// In the case of a ch341 Lora device, we don't want to touch the system GPIO lines for Lora
|
// In the case of a ch341 Lora device, we don't want to touch the system GPIO lines for Lora
|
||||||
// Those GPIO are handled in our usermode driver instead.
|
// Those GPIO are handled in our usermode driver instead.
|
||||||
@@ -530,13 +542,51 @@ void portduinoSetup()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (i.enabled) {
|
if (i.enabled) {
|
||||||
if (initGPIOPin(i.pin, gpioChipName + std::to_string(i.gpiochip), i.line) != ERRNO_OK) {
|
if (used_pins.find(i.pin) != used_pins.end()) {
|
||||||
printf("Error setting pin number %d. It may not exist, or may already be in use.\n", i.line);
|
printf("Pin %d is in use for multiple purposes\n", i.pin);
|
||||||
exit(EXIT_FAILURE);
|
} else {
|
||||||
|
if (initGPIOPin(i.pin, gpioChipName + std::to_string(i.gpiochip), i.line) != ERRNO_OK) {
|
||||||
|
printf("Error setting pin number %d. It may not exist, or may already be in use.\n", i.line);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
used_pins.insert(i.pin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In one test, this dance seemed necessary to trigger the pin to detect properly.
|
||||||
|
if (portduino_config.lora_pa_detect_pin.enabled) {
|
||||||
|
pinMode(portduino_config.lora_pa_detect_pin.pin, INPUT_PULLDOWN);
|
||||||
|
sleep(1);
|
||||||
|
if (digitalRead(portduino_config.lora_pa_detect_pin.pin) == LOW) {
|
||||||
|
std::cout << "Pin " << portduino_config.lora_pa_detect_pin.pin << " PULLDOWN is LOW" << std::endl;
|
||||||
|
}
|
||||||
|
pinMode(portduino_config.lora_pa_detect_pin.pin, INPUT_PULLUP);
|
||||||
|
sleep(1);
|
||||||
|
if (digitalRead(portduino_config.lora_pa_detect_pin.pin) == HIGH) {
|
||||||
|
std::cout << "Pin " << portduino_config.lora_pa_detect_pin.pin << " PULLUP is HIGH, dropping PA curve" << std::endl;
|
||||||
|
portduino_config.num_pa_points = 1;
|
||||||
|
portduino_config.tx_gain_lora[0] = 0;
|
||||||
|
} else {
|
||||||
|
std::cout << "Pin " << portduino_config.lora_pa_detect_pin.pin << " PULLUP is LOW, using PA curve" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// disable bias once finished
|
||||||
|
pinMode(portduino_config.lora_pa_detect_pin.pin, INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto i : portduino_config.extra_pins) {
|
||||||
|
// In the case of a ch341 Lora device, we don't want to touch the system GPIO lines for Lora
|
||||||
|
// Those GPIO are handled in our usermode driver instead.
|
||||||
|
if (i.config_section == "Lora" && portduino_config.lora_spi_dev == "ch341") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (i.enabled && i.default_high) {
|
||||||
|
pinMode(i.pin, OUTPUT);
|
||||||
|
digitalWrite(i.pin, HIGH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Only initialize the radio pins when dealing with real, kernel controlled SPI hardware
|
// Only initialize the radio pins when dealing with real, kernel controlled SPI hardware
|
||||||
if (portduino_config.lora_spi_dev != "" && portduino_config.lora_spi_dev != "ch341") {
|
if (portduino_config.lora_spi_dev != "" && portduino_config.lora_spi_dev != "ch341") {
|
||||||
SPI.begin(portduino_config.lora_spi_dev.c_str());
|
SPI.begin(portduino_config.lora_spi_dev.c_str());
|
||||||
@@ -691,6 +741,17 @@ bool loadConfig(const char *configPath)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (yamlConfig["Lora"]["Enable_Pins"]) {
|
||||||
|
for (auto extra_pin : yamlConfig["Lora"]["Enable_Pins"]) {
|
||||||
|
portduino_config.extra_pins.push_back(pinMapping());
|
||||||
|
portduino_config.extra_pins.back().config_section = "Lora";
|
||||||
|
portduino_config.extra_pins.back().config_name = "Enable_Pins";
|
||||||
|
portduino_config.extra_pins.back().enabled = true;
|
||||||
|
portduino_config.extra_pins.back().default_high = true;
|
||||||
|
readGPIOFromYaml(extra_pin, portduino_config.extra_pins.back());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
portduino_config.spiSpeed = yamlConfig["Lora"]["spiSpeed"].as<int>(2000000);
|
portduino_config.spiSpeed = yamlConfig["Lora"]["spiSpeed"].as<int>(2000000);
|
||||||
portduino_config.lora_usb_serial_num = yamlConfig["Lora"]["USB_Serialnum"].as<std::string>("");
|
portduino_config.lora_usb_serial_num = yamlConfig["Lora"]["USB_Serialnum"].as<std::string>("");
|
||||||
portduino_config.lora_usb_pid = yamlConfig["Lora"]["USB_PID"].as<int>(0x5512);
|
portduino_config.lora_usb_pid = yamlConfig["Lora"]["USB_PID"].as<int>(0x5512);
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ struct pinMapping {
|
|||||||
int gpiochip;
|
int gpiochip;
|
||||||
int line;
|
int line;
|
||||||
bool enabled = false;
|
bool enabled = false;
|
||||||
|
bool default_high = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern std::ofstream traceFile;
|
extern std::ofstream traceFile;
|
||||||
@@ -107,6 +108,7 @@ extern struct portduino_config_struct {
|
|||||||
pinMapping lora_txen_pin = {"Lora", "TXen"};
|
pinMapping lora_txen_pin = {"Lora", "TXen"};
|
||||||
pinMapping lora_rxen_pin = {"Lora", "RXen"};
|
pinMapping lora_rxen_pin = {"Lora", "RXen"};
|
||||||
pinMapping lora_sx126x_ant_sw_pin = {"Lora", "SX126X_ANT_SW"};
|
pinMapping lora_sx126x_ant_sw_pin = {"Lora", "SX126X_ANT_SW"};
|
||||||
|
pinMapping lora_pa_detect_pin = {"Lora", "GPIO_DETECT_PA"};
|
||||||
std::vector<pinMapping> extra_pins = {};
|
std::vector<pinMapping> extra_pins = {};
|
||||||
|
|
||||||
// GPS
|
// GPS
|
||||||
@@ -194,13 +196,14 @@ extern struct portduino_config_struct {
|
|||||||
int maxtophone = 100;
|
int maxtophone = 100;
|
||||||
int MaxNodes = 200;
|
int MaxNodes = 200;
|
||||||
|
|
||||||
pinMapping *all_pins[20] = {&lora_cs_pin,
|
pinMapping *all_pins[21] = {&lora_cs_pin,
|
||||||
&lora_irq_pin,
|
&lora_irq_pin,
|
||||||
&lora_busy_pin,
|
&lora_busy_pin,
|
||||||
&lora_reset_pin,
|
&lora_reset_pin,
|
||||||
&lora_txen_pin,
|
&lora_txen_pin,
|
||||||
&lora_rxen_pin,
|
&lora_rxen_pin,
|
||||||
&lora_sx126x_ant_sw_pin,
|
&lora_sx126x_ant_sw_pin,
|
||||||
|
&lora_pa_detect_pin,
|
||||||
&displayDC,
|
&displayDC,
|
||||||
&displayCS,
|
&displayCS,
|
||||||
&displayBacklight,
|
&displayBacklight,
|
||||||
@@ -255,18 +258,23 @@ extern struct portduino_config_struct {
|
|||||||
out << YAML::Key << "TX_GAIN_LORA" << YAML::Value << tx_gain_lora[0];
|
out << YAML::Key << "TX_GAIN_LORA" << YAML::Value << tx_gain_lora[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
out << YAML::Key << "DIO2_AS_RF_SWITCH" << YAML::Value << dio2_as_rf_switch;
|
if (dio2_as_rf_switch)
|
||||||
|
out << YAML::Key << "DIO2_AS_RF_SWITCH" << YAML::Value << dio2_as_rf_switch;
|
||||||
if (dio3_tcxo_voltage != 0)
|
if (dio3_tcxo_voltage != 0)
|
||||||
out << YAML::Key << "DIO3_TCXO_VOLTAGE" << YAML::Value << YAML::Precision(3) << (float)dio3_tcxo_voltage / 1000;
|
out << YAML::Key << "DIO3_TCXO_VOLTAGE" << YAML::Value << YAML::Precision(3) << (float)dio3_tcxo_voltage / 1000;
|
||||||
if (lora_usb_pid != 0x5512)
|
if (lora_usb_pid != 0x5512)
|
||||||
out << YAML::Key << "USB_PID" << YAML::Value << YAML::Hex << lora_usb_pid;
|
out << YAML::Key << "USB_PID" << YAML::Value << YAML::Hex << lora_usb_pid;
|
||||||
if (lora_usb_vid != 0x1A86)
|
if (lora_usb_vid != 0x1A86)
|
||||||
out << YAML::Key << "USB_VID" << YAML::Value << YAML::Hex << lora_usb_vid;
|
out << YAML::Key << "USB_VID" << YAML::Value << YAML::Hex << lora_usb_vid;
|
||||||
if (lora_spi_dev != "")
|
if (lora_spi_dev != "" && !(lora_spi_dev == "/dev/spidev0.0" && lora_module == use_autoconf)) {
|
||||||
|
if (lora_spi_dev.find("/dev/") != std::string::npos)
|
||||||
|
lora_spi_dev = lora_spi_dev.substr(5);
|
||||||
out << YAML::Key << "spidev" << YAML::Value << lora_spi_dev;
|
out << YAML::Key << "spidev" << YAML::Value << lora_spi_dev;
|
||||||
|
}
|
||||||
if (lora_usb_serial_num != "")
|
if (lora_usb_serial_num != "")
|
||||||
out << YAML::Key << "USB_Serialnum" << YAML::Value << lora_usb_serial_num;
|
out << YAML::Key << "USB_Serialnum" << YAML::Value << lora_usb_serial_num;
|
||||||
out << YAML::Key << "spiSpeed" << YAML::Value << spiSpeed;
|
if (spiSpeed != 2000000)
|
||||||
|
out << YAML::Key << "spiSpeed" << YAML::Value << spiSpeed;
|
||||||
if (rfswitch_dio_pins[0] != RADIOLIB_NC) {
|
if (rfswitch_dio_pins[0] != RADIOLIB_NC) {
|
||||||
out << YAML::Key << "rfswitch_table" << YAML::Value << YAML::BeginMap;
|
out << YAML::Key << "rfswitch_table" << YAML::Value << YAML::BeginMap;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user