From 70a3749dbe2cf7d23c685b0e3b3ce350a7c9db05 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Mon, 20 Sep 2021 18:38:18 +0200 Subject: [PATCH] added option to open gpio by label instead of gpiochip* --- .../fsfw_hal/common/gpio/gpioDefinitions.h | 14 ++++++++- .../fsfw_hal/linux/gpio/LinuxLibgpioIF.cpp | 29 +++++++++++++++---- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/hal/src/fsfw_hal/common/gpio/gpioDefinitions.h b/hal/src/fsfw_hal/common/gpio/gpioDefinitions.h index 710b2e2c..f3bafc42 100644 --- a/hal/src/fsfw_hal/common/gpio/gpioDefinitions.h +++ b/hal/src/fsfw_hal/common/gpio/gpioDefinitions.h @@ -85,7 +85,19 @@ public: GpioBase(gpio::GpioTypes::GPIO_REGULAR, consumer_, gpio::Direction::IN, 0), chipname(chipname_), lineNum(lineNum_) { } - std::string chipname; + + GpiodRegular(std::string consumer_, gpio::Direction direction_, int initValue_, + std::string label_, int lineNum_) : + GpioBase(gpio::GpioTypes::GPIO_REGULAR, consumer_, direction_, initValue_), label( + label_), lineNum(lineNum_) { + } + + GpiodRegular(std::string consumer_, std::string label_, int lineNum_) : + GpioBase(gpio::GpioTypes::GPIO_REGULAR, consumer_, gpio::Direction::IN, 0), label( + label_), lineNum(lineNum_) { + } + std::string chipname = "NONE"; + std::string label = "NONE"; int lineNum = 0; struct gpiod_line* lineHandle = nullptr; }; diff --git a/hal/src/fsfw_hal/linux/gpio/LinuxLibgpioIF.cpp b/hal/src/fsfw_hal/linux/gpio/LinuxLibgpioIF.cpp index eef61e58..4ee0749b 100644 --- a/hal/src/fsfw_hal/linux/gpio/LinuxLibgpioIF.cpp +++ b/hal/src/fsfw_hal/linux/gpio/LinuxLibgpioIF.cpp @@ -20,7 +20,7 @@ LinuxLibgpioIF::~LinuxLibgpioIF() { ReturnValue_t LinuxLibgpioIF::addGpios(GpioCookie* gpioCookie) { ReturnValue_t result; if(gpioCookie == nullptr) { - sif::error << "LinuxLibgpioIF::initialize: Invalid cookie" << std::endl; + sif::error << "LinuxLibgpioIF::addGpios: Invalid cookie" << std::endl; return RETURN_FAILED; } @@ -72,6 +72,7 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) { ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, GpiodRegular *regularGpio) { std::string chipname; + std::string label; unsigned int lineNum; struct gpiod_chip *chip; gpio::Direction direction; @@ -80,11 +81,27 @@ ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, GpiodRegular int result = 0; chipname = regularGpio->chipname; - chip = gpiod_chip_open_by_name(chipname.c_str()); - if (!chip) { - sif::warning << "LinuxLibgpioIF::configureRegularGpio: Failed to open chip " - << chipname << ". Gpio ID: " << gpioId << std::endl; - return RETURN_FAILED; + + if (chipname != "NONE") { + chip = gpiod_chip_open_by_name(chipname.c_str()); + if (!chip) { + sif::warning << "LinuxLibgpioIF::configureRegularGpio: Failed to open chip " + << chipname << ". Gpio ID: " << gpioId << std::endl; + return RETURN_FAILED; + } + } + else if (label != "NONE") { + label = regularGpio->label; + chip = gpiod_chip_open_by_label(label.c_str()); + if (!chip) { + sif::warning << "LinuxLibgpioIF::configureRegularGpio: Failed to open gpio from gpio " + << "group with label " << label << ". Gpio ID: " << gpioId << std::endl; + return RETURN_FAILED; + } + } + else { + sif::warning << "LinuxLibgpioIF::configureRegularGpio: No gpio group specified" + << std::endl; } lineNum = regularGpio->lineNum;