mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-19 08:17:26 +00:00
Add spidev: ch341 option in meshtasticd config.yaml
This commit is contained in:
parent
991a12a705
commit
98661c5b13
24
src/main.cpp
24
src/main.cpp
@ -215,6 +215,9 @@ static OSThread *powerFSMthread;
|
|||||||
static OSThread *ambientLightingThread;
|
static OSThread *ambientLightingThread;
|
||||||
|
|
||||||
RadioInterface *rIf = NULL;
|
RadioInterface *rIf = NULL;
|
||||||
|
#ifdef ARCH_PORTDUINO
|
||||||
|
RadioLibHal *RadioLibHAL = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some platforms (nrf52) might provide an alterate version that suppresses calling delay from sleep.
|
* Some platforms (nrf52) might provide an alterate version that suppresses calling delay from sleep.
|
||||||
@ -713,7 +716,9 @@ void setup()
|
|||||||
SPI.begin(false);
|
SPI.begin(false);
|
||||||
#endif // HW_SPI1_DEVICE
|
#endif // HW_SPI1_DEVICE
|
||||||
#elif !defined(ARCH_ESP32) // ARCH_RP2040
|
#elif !defined(ARCH_ESP32) // ARCH_RP2040
|
||||||
SPI.begin();
|
if (settingsStrings[spidev] != "ch341") {
|
||||||
|
SPI.begin();
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
// ESP32
|
// ESP32
|
||||||
SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS);
|
SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS);
|
||||||
@ -817,10 +822,12 @@ void setup()
|
|||||||
if (settingsMap[use_sx1262]) {
|
if (settingsMap[use_sx1262]) {
|
||||||
if (!rIf) {
|
if (!rIf) {
|
||||||
LOG_DEBUG("Activate sx1262 radio on SPI port %s", settingsStrings[spidev].c_str());
|
LOG_DEBUG("Activate sx1262 radio on SPI port %s", settingsStrings[spidev].c_str());
|
||||||
Ch341Hal *RadioLibHAL = new Ch341Hal(0);
|
if (settingsStrings[spidev] == "ch341") {
|
||||||
/* LockingArduinoHal *RadioLibHAL =
|
RadioLibHAL = new Ch341Hal(0);
|
||||||
new LockingArduinoHal(SPI, spiSettings, (settingsMap[ch341Quirk] ? settingsMap[busy] : RADIOLIB_NC));
|
} else {
|
||||||
*/
|
RadioLibHAL =
|
||||||
|
new LockingArduinoHal(SPI, spiSettings, (settingsMap[ch341Quirk] ? settingsMap[busy] : RADIOLIB_NC));
|
||||||
|
}
|
||||||
rIf = new SX1262Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset],
|
rIf = new SX1262Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset],
|
||||||
settingsMap[busy]);
|
settingsMap[busy]);
|
||||||
if (!rIf->init()) {
|
if (!rIf->init()) {
|
||||||
@ -834,8 +841,7 @@ void setup()
|
|||||||
} else if (settingsMap[use_rf95]) {
|
} else if (settingsMap[use_rf95]) {
|
||||||
if (!rIf) {
|
if (!rIf) {
|
||||||
LOG_DEBUG("Activate rf95 radio on SPI port %s", settingsStrings[spidev].c_str());
|
LOG_DEBUG("Activate rf95 radio on SPI port %s", settingsStrings[spidev].c_str());
|
||||||
LockingArduinoHal *RadioLibHAL =
|
RadioLibHAL = new LockingArduinoHal(SPI, spiSettings, (settingsMap[ch341Quirk] ? settingsMap[busy] : RADIOLIB_NC));
|
||||||
new LockingArduinoHal(SPI, spiSettings, (settingsMap[ch341Quirk] ? settingsMap[busy] : RADIOLIB_NC));
|
|
||||||
rIf = new RF95Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset],
|
rIf = new RF95Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset],
|
||||||
settingsMap[busy]);
|
settingsMap[busy]);
|
||||||
if (!rIf->init()) {
|
if (!rIf->init()) {
|
||||||
@ -850,7 +856,7 @@ void setup()
|
|||||||
} else if (settingsMap[use_sx1280]) {
|
} else if (settingsMap[use_sx1280]) {
|
||||||
if (!rIf) {
|
if (!rIf) {
|
||||||
LOG_DEBUG("Activate sx1280 radio on SPI port %s", settingsStrings[spidev].c_str());
|
LOG_DEBUG("Activate sx1280 radio on SPI port %s", settingsStrings[spidev].c_str());
|
||||||
LockingArduinoHal *RadioLibHAL = new LockingArduinoHal(SPI, spiSettings);
|
RadioLibHAL = new LockingArduinoHal(SPI, spiSettings);
|
||||||
rIf = new SX1280Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset],
|
rIf = new SX1280Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset],
|
||||||
settingsMap[busy]);
|
settingsMap[busy]);
|
||||||
if (!rIf->init()) {
|
if (!rIf->init()) {
|
||||||
@ -865,7 +871,7 @@ void setup()
|
|||||||
} else if (settingsMap[use_sx1268]) {
|
} else if (settingsMap[use_sx1268]) {
|
||||||
if (!rIf) {
|
if (!rIf) {
|
||||||
LOG_DEBUG("Activate sx1268 radio on SPI port %s", settingsStrings[spidev].c_str());
|
LOG_DEBUG("Activate sx1268 radio on SPI port %s", settingsStrings[spidev].c_str());
|
||||||
LockingArduinoHal *RadioLibHAL = new LockingArduinoHal(SPI, spiSettings);
|
RadioLibHAL = new LockingArduinoHal(SPI, spiSettings);
|
||||||
rIf = new SX1268Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset],
|
rIf = new SX1268Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset],
|
||||||
settingsMap[busy]);
|
settingsMap[busy]);
|
||||||
if (!rIf->init()) {
|
if (!rIf->init()) {
|
||||||
|
@ -57,8 +57,6 @@ template <typename T> bool SX126xInterface<T>::init()
|
|||||||
digitalWrite(settingsMap[sx126x_ant_sw], HIGH);
|
digitalWrite(settingsMap[sx126x_ant_sw], HIGH);
|
||||||
pinMode(settingsMap[sx126x_ant_sw], OUTPUT);
|
pinMode(settingsMap[sx126x_ant_sw], OUTPUT);
|
||||||
}
|
}
|
||||||
// lora.XTAL = true;
|
|
||||||
// lora.standbyXOSC = true;
|
|
||||||
// FIXME: correct logic to default to not using TCXO if no voltage is specified for SX126X_DIO3_TCXO_VOLTAGE
|
// 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)
|
#elif !defined(SX126X_DIO3_TCXO_VOLTAGE)
|
||||||
float tcxoVoltage =
|
float tcxoVoltage =
|
||||||
|
@ -152,47 +152,11 @@ void portduinoSetup()
|
|||||||
// 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
|
||||||
// TODO: Can we do this in the for loop above?
|
// TODO: Can we do this in the for loop above?
|
||||||
// TODO: If one of these fails, we should log and terminate
|
// 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (settingsMap.count(irq) > 0 && settingsMap[irq] != RADIOLIB_NC) {
|
|
||||||
if (initGPIOPin(settingsMap[irq], gpioChipName) != ERRNO_OK) {
|
|
||||||
settingsMap[irq] = RADIOLIB_NC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (settingsMap.count(busy) > 0 && settingsMap[busy] != RADIOLIB_NC) {
|
|
||||||
if (initGPIOPin(settingsMap[busy], gpioChipName) != ERRNO_OK) {
|
|
||||||
settingsMap[busy] = RADIOLIB_NC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (settingsMap.count(reset) > 0 && settingsMap[reset] != RADIOLIB_NC) {
|
|
||||||
if (initGPIOPin(settingsMap[reset], gpioChipName) != ERRNO_OK) {
|
|
||||||
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 (settingsMap.count(user) > 0 && settingsMap[user] != RADIOLIB_NC) {
|
||||||
if (initGPIOPin(settingsMap[user], gpioChipName) != ERRNO_OK) {
|
if (initGPIOPin(settingsMap[user], gpioChipName) != ERRNO_OK) {
|
||||||
settingsMap[user] = RADIOLIB_NC;
|
settingsMap[user] = RADIOLIB_NC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (settingsMap.count(rxen) > 0 && settingsMap[rxen] != RADIOLIB_NC) {
|
|
||||||
if (initGPIOPin(settingsMap[rxen], gpioChipName) != ERRNO_OK) {
|
|
||||||
settingsMap[rxen] = RADIOLIB_NC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (settingsMap.count(txen) > 0 && settingsMap[txen] != RADIOLIB_NC) {
|
|
||||||
if (initGPIOPin(settingsMap[txen], gpioChipName) != ERRNO_OK) {
|
|
||||||
settingsMap[txen] = RADIOLIB_NC;
|
|
||||||
}
|
|
||||||
} */
|
|
||||||
|
|
||||||
if (settingsMap[displayPanel] != no_screen) {
|
if (settingsMap[displayPanel] != no_screen) {
|
||||||
if (settingsMap[displayCS] > 0)
|
if (settingsMap[displayCS] > 0)
|
||||||
initGPIOPin(settingsMap[displayCS], gpioChipName);
|
initGPIOPin(settingsMap[displayCS], gpioChipName);
|
||||||
@ -210,7 +174,43 @@ void portduinoSetup()
|
|||||||
initGPIOPin(settingsMap[touchscreenIRQ], gpioChipName);
|
initGPIOPin(settingsMap[touchscreenIRQ], gpioChipName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settingsStrings[spidev] != "") {
|
// Only initialize the radio pins when dealing with real, kernel controlled SPI hardware
|
||||||
|
if (settingsStrings[spidev] != "" && settingsStrings[spidev] != "ch341") {
|
||||||
|
if (settingsMap.count(cs) > 0 && settingsMap[cs] != RADIOLIB_NC) {
|
||||||
|
if (initGPIOPin(settingsMap[cs], gpioChipName) != ERRNO_OK) {
|
||||||
|
settingsMap[cs] = RADIOLIB_NC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (settingsMap.count(irq) > 0 && settingsMap[irq] != RADIOLIB_NC) {
|
||||||
|
if (initGPIOPin(settingsMap[irq], gpioChipName) != ERRNO_OK) {
|
||||||
|
settingsMap[irq] = RADIOLIB_NC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (settingsMap.count(busy) > 0 && settingsMap[busy] != RADIOLIB_NC) {
|
||||||
|
if (initGPIOPin(settingsMap[busy], gpioChipName) != ERRNO_OK) {
|
||||||
|
settingsMap[busy] = RADIOLIB_NC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (settingsMap.count(reset) > 0 && settingsMap[reset] != RADIOLIB_NC) {
|
||||||
|
if (initGPIOPin(settingsMap[reset], gpioChipName) != ERRNO_OK) {
|
||||||
|
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(rxen) > 0 && settingsMap[rxen] != RADIOLIB_NC) {
|
||||||
|
if (initGPIOPin(settingsMap[rxen], gpioChipName) != ERRNO_OK) {
|
||||||
|
settingsMap[rxen] = RADIOLIB_NC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (settingsMap.count(txen) > 0 && settingsMap[txen] != RADIOLIB_NC) {
|
||||||
|
if (initGPIOPin(settingsMap[txen], gpioChipName) != ERRNO_OK) {
|
||||||
|
settingsMap[txen] = RADIOLIB_NC;
|
||||||
|
}
|
||||||
|
}
|
||||||
SPI.begin(settingsStrings[spidev].c_str());
|
SPI.begin(settingsStrings[spidev].c_str());
|
||||||
}
|
}
|
||||||
if (settingsStrings[traceFilename] != "") {
|
if (settingsStrings[traceFilename] != "") {
|
||||||
@ -296,14 +296,19 @@ bool loadConfig(const char *configPath)
|
|||||||
settingsMap[ch341Quirk] = yamlConfig["Lora"]["ch341_quirk"].as<bool>(false);
|
settingsMap[ch341Quirk] = yamlConfig["Lora"]["ch341_quirk"].as<bool>(false);
|
||||||
settingsMap[spiSpeed] = yamlConfig["Lora"]["spiSpeed"].as<int>(2000000);
|
settingsMap[spiSpeed] = yamlConfig["Lora"]["spiSpeed"].as<int>(2000000);
|
||||||
|
|
||||||
settingsStrings[spidev] = "/dev/" + yamlConfig["Lora"]["spidev"].as<std::string>("spidev0.0");
|
settingsStrings[spidev] = yamlConfig["Lora"]["spidev"].as<std::string>("spidev0.0");
|
||||||
if (settingsStrings[spidev].length() == 14) {
|
if (settingsStrings[spidev] != "ch341") {
|
||||||
int x = settingsStrings[spidev].at(11) - '0';
|
settingsStrings[spidev] = "/dev/" + settingsStrings[spidev];
|
||||||
int y = settingsStrings[spidev].at(13) - '0';
|
if (settingsStrings[spidev].length() == 14) {
|
||||||
if (x >= 0 && x < 10 && y >= 0 && y < 10) {
|
int x = settingsStrings[spidev].at(11) - '0';
|
||||||
settingsMap[spidev] = x + y << 4;
|
int y = settingsStrings[spidev].at(13) - '0';
|
||||||
settingsMap[displayspidev] = settingsMap[spidev];
|
// Pretty sure this is always true
|
||||||
settingsMap[touchscreenspidev] = settingsMap[spidev];
|
if (x >= 0 && x < 10 && y >= 0 && y < 10) {
|
||||||
|
// I believe this bit of weirdness is specifically for the new GUI
|
||||||
|
settingsMap[spidev] = x + y << 4;
|
||||||
|
settingsMap[displayspidev] = settingsMap[spidev];
|
||||||
|
settingsMap[touchscreenspidev] = settingsMap[spidev];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user