Linux Input Fixes

This commit is contained in:
Jonathan Bennett 2025-06-11 16:49:47 -05:00
parent 23c420fa31
commit c3e5e2397e
9 changed files with 93 additions and 29 deletions

View File

@ -48,8 +48,8 @@ bool ScanAndSelectInput::init()
// Short circuit: if selected pin conficts with the user button // Short circuit: if selected pin conficts with the user button
#if defined(ARCH_PORTDUINO) #if defined(ARCH_PORTDUINO)
int pinUserButton = 0; int pinUserButton = 0;
if (settingsMap.count(user) != 0) { if (settingsMap.count(userButtonPin) != 0) {
pinUserButton = settingsMap[user]; pinUserButton = settingsMap[userButtonPin];
} }
#elif defined(USERPREFS_BUTTON_PIN) #elif defined(USERPREFS_BUTTON_PIN)
int pinUserButton = config.device.button_gpio ? config.device.button_gpio : USERPREFS_BUTTON_PIN; int pinUserButton = config.device.button_gpio ? config.device.button_gpio : USERPREFS_BUTTON_PIN;

View File

@ -18,17 +18,27 @@ void TrackballInterruptBase::init(uint8_t pinDown, uint8_t pinUp, uint8_t pinLef
this->_eventRight = eventRight; this->_eventRight = eventRight;
this->_eventPressed = eventPressed; this->_eventPressed = eventPressed;
if (pinPress != 255) {
pinMode(pinPress, INPUT_PULLUP); pinMode(pinPress, INPUT_PULLUP);
pinMode(this->_pinDown, INPUT_PULLUP);
pinMode(this->_pinUp, INPUT_PULLUP);
pinMode(this->_pinLeft, INPUT_PULLUP);
pinMode(this->_pinRight, INPUT_PULLUP);
attachInterrupt(pinPress, onIntPress, RISING); attachInterrupt(pinPress, onIntPress, RISING);
}
if (this->_pinDown != 255) {
pinMode(this->_pinDown, INPUT_PULLUP);
attachInterrupt(this->_pinDown, onIntDown, RISING); attachInterrupt(this->_pinDown, onIntDown, RISING);
}
if (this->_pinUp != 255) {
pinMode(this->_pinUp, INPUT_PULLUP);
attachInterrupt(this->_pinUp, onIntUp, RISING); attachInterrupt(this->_pinUp, onIntUp, RISING);
}
if (this->_pinLeft != 255) {
pinMode(this->_pinLeft, INPUT_PULLUP);
attachInterrupt(this->_pinLeft, onIntLeft, RISING); attachInterrupt(this->_pinLeft, onIntLeft, RISING);
}
if (this->_pinRight != 255) {
pinMode(this->_pinRight, INPUT_PULLUP);
attachInterrupt(this->_pinRight, onIntRight, RISING); attachInterrupt(this->_pinRight, onIntRight, RISING);
}
LOG_DEBUG("Trackball GPIO initialized (%d, %d, %d, %d, %d)", this->_pinUp, this->_pinDown, this->_pinLeft, this->_pinRight, LOG_DEBUG("Trackball GPIO initialized (%d, %d, %d, %d, %d)", this->_pinUp, this->_pinDown, this->_pinLeft, this->_pinRight,
pinPress); pinPress);

View File

@ -6,17 +6,12 @@ TrackballInterruptImpl1 *trackballInterruptImpl1;
TrackballInterruptImpl1::TrackballInterruptImpl1() : TrackballInterruptBase("trackball1") {} TrackballInterruptImpl1::TrackballInterruptImpl1() : TrackballInterruptBase("trackball1") {}
void TrackballInterruptImpl1::init() void TrackballInterruptImpl1::init(uint8_t pinUp, uint8_t pinDown, uint8_t pinLeft, uint8_t pinRight, uint8_t pinPress)
{ {
#if !HAS_TRACKBALL #if !HAS_TRACKBALL
// Input device is disabled. // Input device is disabled.
return; return;
#else #else
uint8_t pinUp = TB_UP;
uint8_t pinDown = TB_DOWN;
uint8_t pinLeft = TB_LEFT;
uint8_t pinRight = TB_RIGHT;
uint8_t pinPress = TB_PRESS;
input_broker_event eventDown = INPUT_BROKER_DOWN; input_broker_event eventDown = INPUT_BROKER_DOWN;
input_broker_event eventUp = INPUT_BROKER_UP; input_broker_event eventUp = INPUT_BROKER_UP;

View File

@ -5,7 +5,7 @@ class TrackballInterruptImpl1 : public TrackballInterruptBase
{ {
public: public:
TrackballInterruptImpl1(); TrackballInterruptImpl1();
void init(); void init(uint8_t pinDown, uint8_t pinUp, uint8_t pinLeft, uint8_t pinRight, uint8_t pinPress);
static void handleIntDown(); static void handleIntDown();
static void handleIntUp(); static void handleIntUp();
static void handleIntLeft(); static void handleIntLeft();

View File

@ -105,7 +105,7 @@ NRF52Bluetooth *nrf52Bluetooth = nullptr;
ButtonThread *TouchButtonThread = nullptr; ButtonThread *TouchButtonThread = nullptr;
#endif #endif
#if defined(BUTTON_PIN) #if defined(BUTTON_PIN) || defined(ARCH_PORTDUINO)
ButtonThread *UserButtonThread = nullptr; ButtonThread *UserButtonThread = nullptr;
#endif #endif
@ -908,9 +908,20 @@ void setup()
#endif #endif
#if defined(ARCH_PORTDUINO) // make it work #if defined(ARCH_PORTDUINO) // make it work
if (settingsMap.count(user) != 0 && settingsMap[user] != RADIOLIB_NC) { if (settingsMap.count(userButtonPin) != 0 && settingsMap[userButtonPin] != RADIOLIB_NC) {
LOG_DEBUG("Use GPIO%02d for button", settingsMap[user]); LOG_DEBUG("Use GPIO%02d for button", settingsMap[userButtonPin]);
UserButtonThread = new ButtonThread("UserButton");
if (screen)
UserButtonThread->initButton(
settingsMap[userButtonPin], true, true, INPUT_PULLUP, // pull up bias
[]() {
UserButtonThread->userButton.tick();
runASAP = true;
BaseType_t higherWake = 0;
mainDelay.interruptFromISR(&higherWake);
},
INPUT_BROKER_USER_PRESS, INPUT_BROKER_SELECT);
} }
#endif #endif

View File

@ -206,7 +206,7 @@ void setupModules()
#if HAS_TRACKBALL && !MESHTASTIC_EXCLUDE_INPUTBROKER #if HAS_TRACKBALL && !MESHTASTIC_EXCLUDE_INPUTBROKER
if (config.display.displaymode != meshtastic_Config_DisplayConfig_DisplayMode_COLOR) { if (config.display.displaymode != meshtastic_Config_DisplayConfig_DisplayMode_COLOR) {
trackballInterruptImpl1 = new TrackballInterruptImpl1(); trackballInterruptImpl1 = new TrackballInterruptImpl1();
trackballInterruptImpl1->init(); trackballInterruptImpl1->init(TB_DOWN, TB_UP, TB_LEFT, TB_RIGHT, TB_PRESS);
} }
#endif #endif
#ifdef INPUTBROKER_EXPRESSLRSFIVEWAY_TYPE #ifdef INPUTBROKER_EXPRESSLRSFIVEWAY_TYPE

View File

@ -146,7 +146,7 @@ void portduinoSetup()
const configNames GPIO_lines[] = { const configNames GPIO_lines[] = {
cs_pin, irq_pin, busy_pin, reset_pin, sx126x_ant_sw_pin, txen_pin, cs_pin, irq_pin, busy_pin, reset_pin, sx126x_ant_sw_pin, txen_pin,
rxen_pin, displayDC, displayCS, displayBacklight, displayBacklightPWMChannel, displayReset, rxen_pin, displayDC, displayCS, displayBacklight, displayBacklightPWMChannel, displayReset,
touchscreenCS, touchscreenIRQ, user}; touchscreenCS, touchscreenIRQ, userButtonPin, tbUpPin, tbDownPin, tbLeftPin, tbRightPin, tbPressPin};
std::string gpioChipName = "gpiochip"; std::string gpioChipName = "gpiochip";
settingsStrings[i2cdev] = ""; settingsStrings[i2cdev] = "";
@ -313,9 +313,34 @@ 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: If one of these fails, we should log and terminate // TODO: If one of these fails, we should log and terminate
if (settingsMap.count(user) > 0 && settingsMap[user] != RADIOLIB_NC) { if (settingsMap.count(userButtonPin) > 0 && settingsMap[userButtonPin] != RADIOLIB_NC) {
if (initGPIOPin(settingsMap[user], defaultGpioChipName, settingsMap[user]) != ERRNO_OK) { if (initGPIOPin(settingsMap[userButtonPin], defaultGpioChipName, settingsMap[userButtonPin]) != ERRNO_OK) {
settingsMap[user] = RADIOLIB_NC; settingsMap[userButtonPin] = RADIOLIB_NC;
}
}
if (settingsMap.count(tbUpPin) > 0 && settingsMap[tbUpPin] != RADIOLIB_NC) {
if (initGPIOPin(settingsMap[tbUpPin], defaultGpioChipName, settingsMap[tbUpPin]) != ERRNO_OK) {
settingsMap[tbUpPin] = RADIOLIB_NC;
}
}
if (settingsMap.count(tbDownPin) > 0 && settingsMap[tbDownPin] != RADIOLIB_NC) {
if (initGPIOPin(settingsMap[tbDownPin], defaultGpioChipName, settingsMap[tbDownPin]) != ERRNO_OK) {
settingsMap[tbDownPin] = RADIOLIB_NC;
}
}
if (settingsMap.count(tbLeftPin) > 0 && settingsMap[tbLeftPin] != RADIOLIB_NC) {
if (initGPIOPin(settingsMap[tbLeftPin], defaultGpioChipName, settingsMap[tbLeftPin]) != ERRNO_OK) {
settingsMap[tbLeftPin] = RADIOLIB_NC;
}
}
if (settingsMap.count(tbRightPin) > 0 && settingsMap[tbRightPin] != RADIOLIB_NC) {
if (initGPIOPin(settingsMap[tbRightPin], defaultGpioChipName, settingsMap[tbRightPin]) != ERRNO_OK) {
settingsMap[tbRightPin] = RADIOLIB_NC;
}
}
if (settingsMap.count(tbPressPin) > 0 && settingsMap[tbPressPin] != RADIOLIB_NC) {
if (initGPIOPin(settingsMap[tbPressPin], defaultGpioChipName, settingsMap[tbPressPin]) != ERRNO_OK) {
settingsMap[tbPressPin] = RADIOLIB_NC;
} }
} }
if (settingsMap[displayPanel] != no_screen) { if (settingsMap[displayPanel] != no_screen) {
@ -377,6 +402,8 @@ int initGPIOPin(int pinNum, const std::string gpioChipName, int line)
{ {
#ifdef PORTDUINO_LINUX_HARDWARE #ifdef PORTDUINO_LINUX_HARDWARE
std::string gpio_name = "GPIO" + std::to_string(pinNum); std::string gpio_name = "GPIO" + std::to_string(pinNum);
std::cout << gpio_name;
printf("\n");
try { try {
GPIOPin *csPin; GPIOPin *csPin;
csPin = new LinuxGPIOPin(pinNum, gpioChipName.c_str(), line, gpio_name.c_str()); csPin = new LinuxGPIOPin(pinNum, gpioChipName.c_str(), line, gpio_name.c_str());
@ -498,7 +525,12 @@ bool loadConfig(const char *configPath)
} }
} }
if (yamlConfig["GPIO"]) { if (yamlConfig["GPIO"]) {
settingsMap[user] = yamlConfig["GPIO"]["User"].as<int>(RADIOLIB_NC); settingsMap[userButtonPin] = yamlConfig["GPIO"]["User"].as<int>(RADIOLIB_NC);
settingsMap[tbUpPin] = yamlConfig["GPIO"]["TrackballUp"].as<int>(RADIOLIB_NC);
settingsMap[tbDownPin] = yamlConfig["GPIO"]["TrackballDown"].as<int>(RADIOLIB_NC);
settingsMap[tbLeftPin] = yamlConfig["GPIO"]["TrackballLeft"].as<int>(RADIOLIB_NC);
settingsMap[tbRightPin] = yamlConfig["GPIO"]["TrackballRight"].as<int>(RADIOLIB_NC);
settingsMap[tbPressPin] = yamlConfig["GPIO"]["TrackballPress"].as<int>(RADIOLIB_NC);
} }
if (yamlConfig["GPS"]) { if (yamlConfig["GPS"]) {
std::string serialPath = yamlConfig["GPS"]["SerialPath"].as<std::string>(""); std::string serialPath = yamlConfig["GPS"]["SerialPath"].as<std::string>("");

View File

@ -57,7 +57,12 @@ enum configNames {
lora_usb_serial_num, lora_usb_serial_num,
lora_usb_pid, lora_usb_pid,
lora_usb_vid, lora_usb_vid,
user, userButtonPin,
tbUpPin,
tbDownPin,
tbLeftPin,
tbRightPin,
tbPressPin,
spidev, spidev,
spiSpeed, spiSpeed,
i2cdev, i2cdev,

View File

@ -8,6 +8,9 @@
#define HW_VENDOR meshtastic_HardwareModel_PORTDUINO #define HW_VENDOR meshtastic_HardwareModel_PORTDUINO
#ifndef HAS_BUTTON
#define HAS_BUTTON 1
#endif
#ifndef HAS_WIFI #ifndef HAS_WIFI
#define HAS_WIFI 1 #define HAS_WIFI 1
#endif #endif
@ -23,3 +26,11 @@
#ifndef HAS_SENSOR #ifndef HAS_SENSOR
#define HAS_SENSOR 1 #define HAS_SENSOR 1
#endif #endif
#ifndef HAS_TRACKBALL
#define HAS_TRACKBALL 1
#define TB_DOWN (uint8_t)settingsMap[tbDownPin]
#define TB_UP (uint8_t)settingsMap[tbUpPin]
#define TB_LEFT (uint8_t)settingsMap[tbLeftPin]
#define TB_RIGHT (uint8_t)settingsMap[tbRightPin]
#define TB_PRESS (uint8_t)settingsMap[tbPressPin]
#endif