Extra pins (#9260)
* Maybe add working extra GPIO pins to portduino * Fix typo and add config.yaml example for ExtraPins * Write extra pins back out with -y flag
This commit is contained in:
co-authored by
GitHub
parent
8cf8fbb8e0
commit
b6b129650a
@@ -105,6 +105,8 @@ Lora:
|
|||||||
|
|
||||||
GPS:
|
GPS:
|
||||||
# SerialPath: /dev/ttyS0
|
# SerialPath: /dev/ttyS0
|
||||||
|
# ExtraPins:
|
||||||
|
# - 22
|
||||||
|
|
||||||
### Specify I2C device, or leave blank for none
|
### Specify I2C device, or leave blank for none
|
||||||
|
|
||||||
|
|||||||
@@ -487,6 +487,11 @@ void portduinoSetup()
|
|||||||
max_GPIO = i->pin;
|
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.
|
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
|
// Need to bind all the configured GPIO pins so they're not simulated
|
||||||
@@ -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
|
// 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") {
|
||||||
@@ -717,6 +735,16 @@ bool loadConfig(const char *configPath)
|
|||||||
portduino_config.has_gps = 1;
|
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"]) {
|
if (yamlConfig["I2C"]) {
|
||||||
portduino_config.i2cdev = yamlConfig["I2C"]["I2CDevice"].as<std::string>("");
|
portduino_config.i2cdev = yamlConfig["I2C"]["I2CDevice"].as<std::string>("");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "LR11x0Interface.h"
|
#include "LR11x0Interface.h"
|
||||||
#include "Module.h"
|
#include "Module.h"
|
||||||
@@ -97,6 +98,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"};
|
||||||
|
std::vector<pinMapping> extra_pins = {};
|
||||||
|
|
||||||
// GPS
|
// GPS
|
||||||
bool has_gps = false;
|
bool has_gps = false;
|
||||||
@@ -300,6 +302,20 @@ extern struct portduino_config_struct {
|
|||||||
}
|
}
|
||||||
out << YAML::EndMap; // Lora
|
out << YAML::EndMap; // Lora
|
||||||
|
|
||||||
|
if (!extra_pins.empty()) {
|
||||||
|
out << YAML::Key << "GPIO" << YAML::Value << YAML::BeginMap;
|
||||||
|
out << YAML::Key << "ExtraPins" << YAML::Value << YAML::BeginSeq;
|
||||||
|
for (auto extra : extra_pins) {
|
||||||
|
out << YAML::BeginMap;
|
||||||
|
out << YAML::Key << "pin" << YAML::Value << extra.pin;
|
||||||
|
out << YAML::Key << "line" << YAML::Value << extra.line;
|
||||||
|
out << YAML::Key << "gpiochip" << YAML::Value << extra.gpiochip;
|
||||||
|
out << YAML::EndMap;
|
||||||
|
}
|
||||||
|
out << YAML::EndSeq;
|
||||||
|
out << YAML::EndMap; // GPIO
|
||||||
|
}
|
||||||
|
|
||||||
if (i2cdev != "") {
|
if (i2cdev != "") {
|
||||||
out << YAML::Key << "I2C" << YAML::Value << YAML::BeginMap;
|
out << YAML::Key << "I2C" << YAML::Value << YAML::BeginMap;
|
||||||
out << YAML::Key << "I2CDevice" << YAML::Value << i2cdev;
|
out << YAML::Key << "I2CDevice" << YAML::Value << i2cdev;
|
||||||
|
|||||||
Reference in New Issue
Block a user