mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-19 09:12:45 +00:00
Move to portduino GPIO, adding user button support
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
#ifdef ARCH_RASPBERRY_PI
|
||||
#include "PortduinoGlue.h"
|
||||
#include "linux/gpio/LinuxGPIOPin.h"
|
||||
#include "pigpio.h"
|
||||
#include "yaml-cpp/yaml.h"
|
||||
#include <iostream>
|
||||
@@ -101,6 +102,7 @@ void portduinoSetup()
|
||||
printf("Setting up Meshtastic on Portduino...\n");
|
||||
|
||||
#ifdef ARCH_RASPBERRY_PI
|
||||
gpioInit();
|
||||
YAML::Node yamlConfig;
|
||||
|
||||
if (access("config.yaml", R_OK) == 0) {
|
||||
@@ -138,6 +140,9 @@ void portduinoSetup()
|
||||
settingsMap[busy] = yamlConfig["Lora"]["Busy"].as<int>(RADIOLIB_NC);
|
||||
settingsMap[reset] = yamlConfig["Lora"]["Reset"].as<int>(RADIOLIB_NC);
|
||||
}
|
||||
if (yamlConfig["GPIO"]) {
|
||||
settingsMap[user] = yamlConfig["GPIO"]["User"].as<int>(RADIOLIB_NC);
|
||||
}
|
||||
|
||||
} catch (YAML::Exception e) {
|
||||
std::cout << "*** Exception " << e.what() << std::endl;
|
||||
@@ -147,6 +152,34 @@ void portduinoSetup()
|
||||
std::cout << "Cannot read Bluetooth MAC Address. Please run as root" << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Need to bind all the configured GPIO pins so they're not simulated
|
||||
if (settingsMap.count(cs) > 0 && settingsMap[cs] != RADIOLIB_NC) {
|
||||
if (initGPIOPin(settingsMap[cs]) != ERRNO_OK) {
|
||||
settingsMap[cs] = RADIOLIB_NC;
|
||||
}
|
||||
}
|
||||
if (settingsMap.count(irq) > 0 && settingsMap[irq] != RADIOLIB_NC) {
|
||||
if (initGPIOPin(settingsMap[irq]) != ERRNO_OK) {
|
||||
settingsMap[irq] = RADIOLIB_NC;
|
||||
}
|
||||
}
|
||||
if (settingsMap.count(busy) > 0 && settingsMap[busy] != RADIOLIB_NC) {
|
||||
if (initGPIOPin(settingsMap[busy]) != ERRNO_OK) {
|
||||
settingsMap[busy] = RADIOLIB_NC;
|
||||
}
|
||||
}
|
||||
if (settingsMap.count(reset) > 0 && settingsMap[reset] != RADIOLIB_NC) {
|
||||
if (initGPIOPin(settingsMap[reset]) != ERRNO_OK) {
|
||||
settingsMap[reset] = RADIOLIB_NC;
|
||||
}
|
||||
}
|
||||
if (settingsMap.count(user) > 0 && settingsMap[user] != RADIOLIB_NC) {
|
||||
if (initGPIOPin(settingsMap[user]) != ERRNO_OK) {
|
||||
settingsMap[user] = RADIOLIB_NC;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
#endif
|
||||
|
||||
@@ -194,4 +227,21 @@ void portduinoSetup()
|
||||
// gpioBind((new SimGPIOPin(LORA_RESET, "LORA_RESET")));
|
||||
// gpioBind((new SimGPIOPin(LORA_CS, "LORA_CS"))->setSilent());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ARCH_RASPBERRY_PI
|
||||
int initGPIOPin(int pinNum)
|
||||
{
|
||||
std::string gpio_name = "GPIO" + std::to_string(pinNum);
|
||||
try {
|
||||
GPIOPin *csPin;
|
||||
csPin = new LinuxGPIOPin(pinNum, "gpiochip0", pinNum, gpio_name.c_str());
|
||||
csPin->setSilent();
|
||||
gpioBind(csPin);
|
||||
return ERRNO_OK;
|
||||
} catch (std::invalid_argument &e) {
|
||||
std::cout << "Warning, cannot claim pin" << gpio_name << std::endl;
|
||||
return ERRNO_DISABLED;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user