Skip to content

Commit

Permalink
Add sx126x_ant_sw for Native (#4887)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
  • Loading branch information
jp-bennett and thebentern authored Sep 28, 2024
1 parent 482361b commit fd1b685
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion bin/config-dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Lora:
# IRQ: 16
# Busy: 20
# Reset: 18
# SX126X_ANT_SW: 6

# Module: sx1262 # Waveshare SX1302 LISTEN ONLY AT THIS TIME!
# CS: 7
Expand Down Expand Up @@ -153,4 +154,4 @@ Webserver:

General:
MaxNodes: 200
MaxMessageQueue: 100
MaxMessageQueue: 100
4 changes: 4 additions & 0 deletions src/mesh/SX126xInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ template <typename T> bool SX126xInterface<T>::init()
float tcxoVoltage = 0;
if (settingsMap[dio3_tcxo_voltage])
tcxoVoltage = 1.8;
if (settingsMap[sx126x_ant_sw] != RADIOLIB_NC) {
digitalWrite(settingsMap[sx126x_ant_sw], HIGH);
pinMode(settingsMap[sx126x_ant_sw], OUTPUT);
}
// FIXME: correct logic to default to not using TCXO if no voltage is specified for SX126X_DIO3_TCXO_VOLTAGE
#elif !defined(SX126X_DIO3_TCXO_VOLTAGE)
float tcxoVoltage =
Expand Down
11 changes: 10 additions & 1 deletion src/platform/portduino/PortduinoGlue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void portduinoSetup()
irq,
busy,
reset,
sx126x_ant_sw,
txen,
rxen,
displayDC,
Expand Down Expand Up @@ -180,6 +181,7 @@ void portduinoSetup()
settingsMap[reset] = yamlConfig["Lora"]["Reset"].as<int>(RADIOLIB_NC);
settingsMap[txen] = yamlConfig["Lora"]["TXen"].as<int>(RADIOLIB_NC);
settingsMap[rxen] = yamlConfig["Lora"]["RXen"].as<int>(RADIOLIB_NC);
settingsMap[sx126x_ant_sw] = yamlConfig["Lora"]["SX126X_ANT_SW"].as<int>(RADIOLIB_NC);
settingsMap[gpiochip] = yamlConfig["Lora"]["gpiochip"].as<int>(0);
settingsMap[ch341Quirk] = yamlConfig["Lora"]["ch341_quirk"].as<bool>(false);
settingsMap[spiSpeed] = yamlConfig["Lora"]["spiSpeed"].as<int>(2000000);
Expand Down Expand Up @@ -305,6 +307,8 @@ void portduinoSetup()
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
// TODO: Can we do this in the for loop above?
// TODO: If one of these fails, we should log and terminate
if (settingsMap.count(cs) > 0 && settingsMap[cs] != RADIOLIB_NC) {
if (initGPIOPin(settingsMap[cs], gpioChipName) != ERRNO_OK) {
settingsMap[cs] = RADIOLIB_NC;
Expand All @@ -325,6 +329,11 @@ void portduinoSetup()
settingsMap[reset] = RADIOLIB_NC;
}
}
if (settingsMap.count(sx126x_ant_sw) > 0 && settingsMap[sx126x_ant_sw] != RADIOLIB_NC) {
if (initGPIOPin(settingsMap[sx126x_ant_sw], gpioChipName) != ERRNO_OK) {
settingsMap[sx126x_ant_sw] = RADIOLIB_NC;
}
}
if (settingsMap.count(user) > 0 && settingsMap[user] != RADIOLIB_NC) {
if (initGPIOPin(settingsMap[user], gpioChipName) != ERRNO_OK) {
settingsMap[user] = RADIOLIB_NC;
Expand Down Expand Up @@ -391,4 +400,4 @@ int initGPIOPin(int pinNum, const std::string gpioChipName)
#else
return ERRNO_OK;
#endif
}
}
3 changes: 2 additions & 1 deletion src/platform/portduino/PortduinoGlue.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ enum configNames {
irq,
busy,
reset,
sx126x_ant_sw,
txen,
rxen,
dio2_as_rf_switch,
Expand Down Expand Up @@ -63,4 +64,4 @@ enum { level_error, level_warn, level_info, level_debug, level_trace };
extern std::map<configNames, int> settingsMap;
extern std::map<configNames, std::string> settingsStrings;
extern std::ofstream traceFile;
int initGPIOPin(int pinNum, std::string gpioChipname);
int initGPIOPin(int pinNum, std::string gpioChipname);

0 comments on commit fd1b685

Please sign in to comment.