Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions bin/config-dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ Lora:

GPS:
# SerialPath: /dev/ttyS0
# ExtraPins:
# - 22

### Specify I2C device, or leave blank for none

Expand Down
28 changes: 28 additions & 0 deletions src/platform/portduino/PortduinoGlue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,11 @@ void portduinoSetup()
max_GPIO = i->pin;
}

for (auto i : portduino_config.extra_pins) {
if (i.enabled && i.pin > max_GPIO)
max_GPIO = i.pin;
}

gpioInit(max_GPIO + 1); // Done here so we can inform Portduino how many GPIOs we need.

// Need to bind all the configured GPIO pins so they're not simulated
Expand All @@ -504,6 +509,19 @@ void portduinoSetup()
}
}
}
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) {
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);
}
}
}

// 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") {
Expand Down Expand Up @@ -717,6 +735,16 @@ bool loadConfig(const char *configPath)
portduino_config.has_gps = 1;
}
}
if (yamlConfig["GPIO"]["ExtraPins"]) {
for (auto extra_pin : yamlConfig["GPIO"]["ExtraPins"]) {
portduino_config.extra_pins.push_back(pinMapping());
portduino_config.extra_pins.back().config_section = "GPIO";
portduino_config.extra_pins.back().config_name = "ExtraPins";
portduino_config.extra_pins.back().enabled = true;
readGPIOFromYaml(extra_pin, portduino_config.extra_pins.back());
}
}

if (yamlConfig["I2C"]) {
portduino_config.i2cdev = yamlConfig["I2C"]["I2CDevice"].as<std::string>("");
}
Expand Down
2 changes: 2 additions & 0 deletions src/platform/portduino/PortduinoGlue.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <fstream>
#include <map>
#include <unordered_map>
#include <vector>

#include "LR11x0Interface.h"
#include "Module.h"
Expand Down Expand Up @@ -97,6 +98,7 @@ extern struct portduino_config_struct {
pinMapping lora_txen_pin = {"Lora", "TXen"};
pinMapping lora_rxen_pin = {"Lora", "RXen"};
pinMapping lora_sx126x_ant_sw_pin = {"Lora", "SX126X_ANT_SW"};
std::vector<pinMapping> extra_pins = {};
Comment thread
jp-bennett marked this conversation as resolved.
Resolved

// GPS
bool has_gps = false;
Expand Down
Loading