From f006188814513f5ce97cf697759f54b600c54834 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 14 Feb 2021 12:57:09 +0100 Subject: [PATCH] moved some files --- bsp_q7s/boardtest/LibgpiodTest.h | 4 +- bsp_q7s/gpio/CMakeLists.txt | 4 - linux/gpio/CMakeLists.txt | 1 + {bsp_q7s => linux}/gpio/LinuxLibgpioIF.cpp | 112 ++++++++++----------- {bsp_q7s => linux}/gpio/LinuxLibgpioIF.h | 0 5 files changed, 59 insertions(+), 62 deletions(-) delete mode 100644 bsp_q7s/gpio/CMakeLists.txt rename {bsp_q7s => linux}/gpio/LinuxLibgpioIF.cpp (64%) rename {bsp_q7s => linux}/gpio/LinuxLibgpioIF.h (100%) diff --git a/bsp_q7s/boardtest/LibgpiodTest.h b/bsp_q7s/boardtest/LibgpiodTest.h index bc87a5c4..678c06a3 100644 --- a/bsp_q7s/boardtest/LibgpiodTest.h +++ b/bsp_q7s/boardtest/LibgpiodTest.h @@ -2,8 +2,8 @@ #define TEST_TESTTASKS_LIBGPIODTEST_H_ #include "TestTask.h" -#include -#include +#include +#include #include /** diff --git a/bsp_q7s/gpio/CMakeLists.txt b/bsp_q7s/gpio/CMakeLists.txt deleted file mode 100644 index 1041cea7..00000000 --- a/bsp_q7s/gpio/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -target_sources(${TARGET_NAME} PUBLIC - LinuxLibgpioIF.cpp -) - diff --git a/linux/gpio/CMakeLists.txt b/linux/gpio/CMakeLists.txt index 642555fe..052173b3 100644 --- a/linux/gpio/CMakeLists.txt +++ b/linux/gpio/CMakeLists.txt @@ -1,5 +1,6 @@ target_sources(${TARGET_NAME} PUBLIC GpioCookie.cpp + LinuxLibgpioIF.cpp ) diff --git a/bsp_q7s/gpio/LinuxLibgpioIF.cpp b/linux/gpio/LinuxLibgpioIF.cpp similarity index 64% rename from bsp_q7s/gpio/LinuxLibgpioIF.cpp rename to linux/gpio/LinuxLibgpioIF.cpp index 97d0cc12..e5db2934 100644 --- a/bsp_q7s/gpio/LinuxLibgpioIF.cpp +++ b/linux/gpio/LinuxLibgpioIF.cpp @@ -12,36 +12,36 @@ LinuxLibgpioIF::~LinuxLibgpioIF() { } ReturnValue_t LinuxLibgpioIF::initialize(CookieIF * cookie){ - ReturnValue_t result; - GpioMap mapToAdd; + ReturnValue_t result; + GpioMap mapToAdd; - if(cookie == nullptr) { - sif::error << "LinuxLibgpioIF::initialize: Invalid cookie" << std::endl; - return RETURN_FAILED; - } - GpioCookie* gpioCookie = dynamic_cast(cookie); - if(gpioCookie == nullptr) { - sif::error << "LinuxLibgpioIF: Invalid Gpio Cookie!" - << std::endl; - return RETURN_FAILED; - } + if(cookie == nullptr) { + sif::error << "LinuxLibgpioIF::initialize: Invalid cookie" << std::endl; + return RETURN_FAILED; + } + GpioCookie* gpioCookie = dynamic_cast(cookie); + if(gpioCookie == nullptr) { + sif::error << "LinuxLibgpioIF: Invalid Gpio Cookie!" + << std::endl; + return RETURN_FAILED; + } - mapToAdd = gpioCookie->getGpioMap(); + mapToAdd = gpioCookie->getGpioMap(); - result = checkForConflicts(mapToAdd); - if (result != RETURN_OK){ - return result; - } + result = checkForConflicts(mapToAdd); + if (result != RETURN_OK){ + return result; + } - result = configureGpios(&mapToAdd); - if (result != RETURN_OK) { - return RETURN_FAILED; - } + result = configureGpios(&mapToAdd); + if (result != RETURN_OK) { + return RETURN_FAILED; + } - /* Register new GPIOs in gpioMap*/ - gpioMap.insert(mapToAdd.begin(), mapToAdd.end()); + /* Register new GPIOs in gpioMap*/ + gpioMap.insert(mapToAdd.begin(), mapToAdd.end()); - return RETURN_OK; + return RETURN_OK; } ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap* mapToAdd) { @@ -100,7 +100,7 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap* mapToAdd) { break; default: sif::error << "LinuxLibgpioIF::configureGpios: Invalid direction specified" - << std::endl; + << std::endl; return RETURN_FAILED; } /** @@ -113,33 +113,33 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap* mapToAdd) { } ReturnValue_t LinuxLibgpioIF::pullHigh(gpioId_t gpioId){ - return driveGpio(gpioId, 1); + return driveGpio(gpioId, 1); } ReturnValue_t LinuxLibgpioIF::pullLow(gpioId_t gpioId){ - return driveGpio(gpioId, 0); + return driveGpio(gpioId, 0); } ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId, - unsigned int logiclevel) { + unsigned int logiclevel) { int result; - struct gpiod_line *lineHandle; + struct gpiod_line *lineHandle; - gpioMapIter = gpioMap.find(gpioId); + gpioMapIter = gpioMap.find(gpioId); if (gpioMapIter == gpioMap.end()){ sif::debug << "LinuxLibgpioIF::driveGpio: Unknown gpio id " << gpioId << std::endl; return RETURN_FAILED; } lineHandle = gpioMapIter->second.lineHandle; - result = gpiod_line_set_value(lineHandle, logiclevel); - if (result < 0) { - sif::error << "LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID " - << gpioId << " to logic level " << logiclevel << std::endl; - return DRIVE_GPIO_FAILURE; - } + result = gpiod_line_set_value(lineHandle, logiclevel); + if (result < 0) { + sif::error << "LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID " + << gpioId << " to logic level " << logiclevel << std::endl; + return DRIVE_GPIO_FAILURE; + } - return RETURN_OK; + return RETURN_OK; } ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, int* gpioState) { @@ -158,23 +158,23 @@ ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, int* gpioState) { } ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap mapToAdd){ - gpioId_t gpioId; - GpioMapIter mapToAddIter = mapToAdd.begin(); - for(; mapToAddIter != mapToAdd.end(); mapToAddIter++){ - gpioId = mapToAddIter->first; - gpioMapIter = gpioMap.find(gpioId); - if(gpioMapIter != mapToAdd.end()){ - /* An entry for this GPIO already exists. Check if configuration - * of direction is equivalent */ - if (mapToAddIter->second.direction != gpioMapIter->second.direction){ - sif::error << "LinuxLibgpioIF::checkForConflicts: Detected conflict " - << "for GPIO " << mapToAddIter->first << std::endl; - return RETURN_OK; - } - /* Remove element from map to add because a entry for this GPIO - * already exists */ - mapToAdd.erase(mapToAddIter); - } - } - return RETURN_OK; + gpioId_t gpioId; + GpioMapIter mapToAddIter = mapToAdd.begin(); + for(; mapToAddIter != mapToAdd.end(); mapToAddIter++){ + gpioId = mapToAddIter->first; + gpioMapIter = gpioMap.find(gpioId); + if(gpioMapIter != mapToAdd.end()){ + /* An entry for this GPIO already exists. Check if configuration + * of direction is equivalent */ + if (mapToAddIter->second.direction != gpioMapIter->second.direction){ + sif::error << "LinuxLibgpioIF::checkForConflicts: Detected conflict " + << "for GPIO " << mapToAddIter->first << std::endl; + return RETURN_OK; + } + /* Remove element from map to add because a entry for this GPIO + * already exists */ + mapToAdd.erase(mapToAddIter); + } + } + return RETURN_OK; } diff --git a/bsp_q7s/gpio/LinuxLibgpioIF.h b/linux/gpio/LinuxLibgpioIF.h similarity index 100% rename from bsp_q7s/gpio/LinuxLibgpioIF.h rename to linux/gpio/LinuxLibgpioIF.h