refactored GPIO to support callbacks
This commit is contained in:
parent
c042bbea63
commit
434d0586b3
@ -10,7 +10,7 @@ ReturnValue_t gpio::createRpiGpioConfig(GpioCookie* cookie, gpioId_t gpioId, int
|
|||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
GpioConfig_t config;
|
GpiodRegular config;
|
||||||
/* Default chipname for Raspberry Pi. There is still gpiochip1 for expansion, but most users
|
/* Default chipname for Raspberry Pi. There is still gpiochip1 for expansion, but most users
|
||||||
will not need this */
|
will not need this */
|
||||||
config.chipname = "gpiochip0";
|
config.chipname = "gpiochip0";
|
||||||
|
@ -13,7 +13,7 @@ LibgpiodTest::LibgpiodTest(object_id_t objectId, object_id_t gpioIfobjectId,
|
|||||||
if (gpioInterface == nullptr) {
|
if (gpioInterface == nullptr) {
|
||||||
sif::error << "LibgpiodTest::LibgpiodTest: Invalid Gpio interface." << std::endl;
|
sif::error << "LibgpiodTest::LibgpiodTest: Invalid Gpio interface." << std::endl;
|
||||||
}
|
}
|
||||||
gpioInterface->initialize(gpioCookie);
|
gpioInterface->addGpios(gpioCookie);
|
||||||
testCase = TestCases::LOOPBACK;
|
testCase = TestCases::LOOPBACK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,10 +4,10 @@
|
|||||||
GpioCookie::GpioCookie() {
|
GpioCookie::GpioCookie() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpioConfig_t& gpioConfig){
|
ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpiodRegular& gpioConfig){
|
||||||
auto gpioMapIter = gpioMap.find(gpioId);
|
auto gpioMapIter = gpioMap.find(gpioId);
|
||||||
if(gpioMapIter == gpioMap.end()) {
|
if(gpioMapIter == gpioMap.end()) {
|
||||||
auto statusPair = gpioMap.emplace(gpioId, gpioConfig);
|
auto statusPair = gpioMap.emplace(gpioId, new GpiodRegular(gpioConfig));
|
||||||
if (statusPair.second == false) {
|
if (statusPair.second == false) {
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
sif::error << "GpioCookie::addGpio: Failed to add GPIO " << gpioId <<
|
sif::error << "GpioCookie::addGpio: Failed to add GPIO " << gpioId <<
|
||||||
|
@ -23,7 +23,7 @@ public:
|
|||||||
|
|
||||||
virtual ~GpioCookie();
|
virtual ~GpioCookie();
|
||||||
|
|
||||||
ReturnValue_t addGpio(gpioId_t gpioId, GpioConfig_t& gpioConfig);
|
ReturnValue_t addGpio(gpioId_t gpioId, GpiodRegular& gpioConfig);
|
||||||
/**
|
/**
|
||||||
* @brief Get map with registered GPIOs.
|
* @brief Get map with registered GPIOs.
|
||||||
*/
|
*/
|
||||||
|
@ -22,7 +22,7 @@ public:
|
|||||||
* @param cookie Cookie specifying informations of the GPIOs required
|
* @param cookie Cookie specifying informations of the GPIOs required
|
||||||
* by a object.
|
* by a object.
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t initialize(GpioCookie* cookie) = 0;
|
virtual ReturnValue_t addGpios(GpioCookie* cookie) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief By implementing this function a child must provide the
|
* @brief By implementing this function a child must provide the
|
||||||
|
@ -2,18 +2,20 @@
|
|||||||
#include "GpioCookie.h"
|
#include "GpioCookie.h"
|
||||||
|
|
||||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||||
|
#include <linux/gpio/gpioDefinitions.h>
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <gpiod.h>
|
#include <gpiod.h>
|
||||||
|
|
||||||
|
|
||||||
LinuxLibgpioIF::LinuxLibgpioIF(object_id_t objectId) : SystemObject(objectId) {
|
LinuxLibgpioIF::LinuxLibgpioIF(object_id_t objectId) : SystemObject(objectId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
LinuxLibgpioIF::~LinuxLibgpioIF() {
|
LinuxLibgpioIF::~LinuxLibgpioIF() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::initialize(GpioCookie* gpioCookie){
|
ReturnValue_t LinuxLibgpioIF::addGpios(GpioCookie* gpioCookie) {
|
||||||
ReturnValue_t result;
|
ReturnValue_t result;
|
||||||
if(gpioCookie == nullptr) {
|
if(gpioCookie == nullptr) {
|
||||||
sif::error << "LinuxLibgpioIF::initialize: Invalid cookie" << std::endl;
|
sif::error << "LinuxLibgpioIF::initialize: Invalid cookie" << std::endl;
|
||||||
@ -32,101 +34,153 @@ ReturnValue_t LinuxLibgpioIF::initialize(GpioCookie* gpioCookie){
|
|||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register new GPIOs in gpioMap*/
|
/* Register new GPIOs in gpioMap */
|
||||||
gpioMap.insert(mapToAdd.begin(), mapToAdd.end());
|
gpioMap.insert(mapToAdd.begin(), mapToAdd.end());
|
||||||
|
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) {
|
ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) {
|
||||||
|
for(auto& gpioConfig: mapToAdd) {
|
||||||
|
switch(gpioConfig.second->gpioType) {
|
||||||
|
case(gpio::GpioTypes::NONE): {
|
||||||
|
return GPIO_INVALID_INSTANCE;
|
||||||
|
}
|
||||||
|
case(gpio::GpioTypes::GPIOD_REGULAR): {
|
||||||
|
GpiodRegular* regularGpio = dynamic_cast<GpiodRegular*>(gpioConfig.second);
|
||||||
|
configureRegularGpio(gpioConfig.first, regularGpio);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(gpio::GpioTypes::CALLBACK): {
|
||||||
|
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
|
||||||
|
if(gpioCallback->callback == nullptr) {
|
||||||
|
return GPIO_INVALID_INSTANCE;
|
||||||
|
}
|
||||||
|
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::READ,
|
||||||
|
0, gpioCallback->callbackArgs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, GpiodRegular *regularGpio) {
|
||||||
std::string chipname;
|
std::string chipname;
|
||||||
unsigned int lineNum;
|
unsigned int lineNum;
|
||||||
struct gpiod_chip *chip;
|
struct gpiod_chip *chip;
|
||||||
gpio::Direction direction;
|
gpio::Direction direction;
|
||||||
std::string consumer;
|
std::string consumer;
|
||||||
struct gpiod_line *lineHandle;
|
struct gpiod_line *lineHandle;
|
||||||
int result;
|
int result = 0;
|
||||||
|
|
||||||
for(auto& gpioConfig: mapToAdd) {
|
chipname = regularGpio->chipname;
|
||||||
chipname = gpioConfig.second.chipname;
|
chip = gpiod_chip_open_by_name(chipname.c_str());
|
||||||
chip = gpiod_chip_open_by_name(chipname.c_str());
|
if (!chip) {
|
||||||
if (!chip) {
|
sif::error << "LinuxLibgpioIF::configureGpios: Failed to open chip "
|
||||||
sif::error << "LinuxLibgpioIF::configureGpios: Failed to open chip "
|
<< chipname << ". Gpio ID: " << gpioId << std::endl;
|
||||||
<< chipname << ". Gpio ID: " << gpioConfig.first << std::endl;
|
|
||||||
return RETURN_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
lineNum = gpioConfig.second.lineNum;
|
|
||||||
lineHandle = gpiod_chip_get_line(chip, lineNum);
|
|
||||||
if (!lineHandle) {
|
|
||||||
sif::error << "LinuxLibgpioIF::configureGpios: Failed to open line" << std::endl;
|
|
||||||
gpiod_chip_close(chip);
|
|
||||||
return RETURN_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
direction = gpioConfig.second.direction;
|
|
||||||
consumer = gpioConfig.second.consumer;
|
|
||||||
/* Configure direction and add a description to the GPIO */
|
|
||||||
switch (direction) {
|
|
||||||
case gpio::OUT:
|
|
||||||
result = gpiod_line_request_output(lineHandle, consumer.c_str(),
|
|
||||||
gpioConfig.second.initValue);
|
|
||||||
if (result < 0) {
|
|
||||||
sif::error << "LinuxLibgpioIF::configureGpios: Failed to request line "
|
|
||||||
<< lineNum << " from GPIO instance with ID: " << gpioConfig.first
|
|
||||||
<< std::endl;
|
|
||||||
gpiod_line_release(lineHandle);
|
|
||||||
return RETURN_FAILED;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case gpio::IN:
|
|
||||||
result = gpiod_line_request_input(lineHandle, consumer.c_str());
|
|
||||||
if (result < 0) {
|
|
||||||
sif::error << "LinuxLibgpioIF::configureGpios: Failed to request line "
|
|
||||||
<< lineNum << " from GPIO instance with ID: " << gpioConfig.first
|
|
||||||
<< std::endl;
|
|
||||||
gpiod_line_release(lineHandle);
|
|
||||||
return RETURN_FAILED;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
sif::error << "LinuxLibgpioIF::configureGpios: Invalid direction specified"
|
|
||||||
<< std::endl;
|
|
||||||
return RETURN_FAILED;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Write line handle to GPIO configuration instance so it can later be used to set or
|
|
||||||
* read states of GPIOs.
|
|
||||||
*/
|
|
||||||
gpioConfig.second.lineHandle = lineHandle;
|
|
||||||
}
|
|
||||||
return RETURN_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::pullHigh(gpioId_t gpioId){
|
|
||||||
return driveGpio(gpioId, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::pullLow(gpioId_t gpioId){
|
|
||||||
return driveGpio(gpioId, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId,
|
|
||||||
unsigned int logiclevel) {
|
|
||||||
int result;
|
|
||||||
struct gpiod_line *lineHandle;
|
|
||||||
|
|
||||||
gpioMapIter = gpioMap.find(gpioId);
|
|
||||||
if (gpioMapIter == gpioMap.end()){
|
|
||||||
sif::debug << "LinuxLibgpioIF::driveGpio: Unknown gpio id " << gpioId << std::endl;
|
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
lineHandle = gpioMapIter->second.lineHandle;
|
lineNum = regularGpio->lineNum;
|
||||||
result = gpiod_line_set_value(lineHandle, logiclevel);
|
lineHandle = gpiod_chip_get_line(chip, lineNum);
|
||||||
|
if (!lineHandle) {
|
||||||
|
sif::error << "LinuxLibgpioIF::configureGpios: Failed to open line" << std::endl;
|
||||||
|
gpiod_chip_close(chip);
|
||||||
|
return RETURN_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
direction = regularGpio->direction;
|
||||||
|
consumer = regularGpio->consumer;
|
||||||
|
/* Configure direction and add a description to the GPIO */
|
||||||
|
switch (direction) {
|
||||||
|
case(gpio::OUT): {
|
||||||
|
result = gpiod_line_request_output(lineHandle, consumer.c_str(),
|
||||||
|
regularGpio->initValue);
|
||||||
|
if (result < 0) {
|
||||||
|
sif::error << "LinuxLibgpioIF::configureGpios: Failed to request line " << lineNum <<
|
||||||
|
" from GPIO instance with ID: " << gpioId << std::endl;
|
||||||
|
gpiod_line_release(lineHandle);
|
||||||
|
return RETURN_FAILED;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(gpio::IN): {
|
||||||
|
result = gpiod_line_request_input(lineHandle, consumer.c_str());
|
||||||
|
if (result < 0) {
|
||||||
|
sif::error << "LinuxLibgpioIF::configureGpios: Failed to request line "
|
||||||
|
<< lineNum << " from GPIO instance with ID: " << gpioId << std::endl;
|
||||||
|
gpiod_line_release(lineHandle);
|
||||||
|
return RETURN_FAILED;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
sif::error << "LinuxLibgpioIF::configureGpios: Invalid direction specified"
|
||||||
|
<< std::endl;
|
||||||
|
return GPIO_INVALID_INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Write line handle to GPIO configuration instance so it can later be used to set or
|
||||||
|
* read states of GPIOs.
|
||||||
|
*/
|
||||||
|
regularGpio->lineHandle = lineHandle;
|
||||||
|
return RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LinuxLibgpioIF::pullHigh(gpioId_t gpioId) {
|
||||||
|
gpioMapIter = gpioMap.find(gpioId);
|
||||||
|
if (gpioMapIter == gpioMap.end()) {
|
||||||
|
sif::warning << "LinuxLibgpioIF::driveGpio: Unknown GPIOD ID " << gpioId << std::endl;
|
||||||
|
return UNKNOWN_GPIO_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(gpioMapIter->second->gpioType == gpio::GpioTypes::GPIOD_REGULAR) {
|
||||||
|
return driveGpio(gpioId, dynamic_cast<GpiodRegular*>(gpioMapIter->second), 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
|
||||||
|
if(gpioCallback->callback == nullptr) {
|
||||||
|
return GPIO_INVALID_INSTANCE;
|
||||||
|
}
|
||||||
|
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE,
|
||||||
|
1, gpioCallback->callbackArgs);
|
||||||
|
}
|
||||||
|
return GPIO_TYPE_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LinuxLibgpioIF::pullLow(gpioId_t gpioId) {
|
||||||
|
gpioMapIter = gpioMap.find(gpioId);
|
||||||
|
if (gpioMapIter == gpioMap.end()) {
|
||||||
|
sif::warning << "LinuxLibgpioIF::driveGpio: Unknown GPIOD ID " << gpioId << std::endl;
|
||||||
|
return UNKNOWN_GPIO_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(gpioMapIter->second->gpioType == gpio::GpioTypes::GPIOD_REGULAR) {
|
||||||
|
return driveGpio(gpioId, dynamic_cast<GpiodRegular*>(gpioMapIter->second), 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
|
||||||
|
if(gpioCallback->callback == nullptr) {
|
||||||
|
return GPIO_INVALID_INSTANCE;
|
||||||
|
}
|
||||||
|
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE,
|
||||||
|
0, gpioCallback->callbackArgs);
|
||||||
|
}
|
||||||
|
return GPIO_TYPE_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId,
|
||||||
|
GpiodRegular* regularGpio, unsigned int logicLevel) {
|
||||||
|
if(regularGpio == nullptr) {
|
||||||
|
return GPIO_TYPE_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int result = gpiod_line_set_value(regularGpio->lineHandle, logicLevel);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
sif::error << "LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID "
|
sif::warning << "LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID " << gpioId <<
|
||||||
<< gpioId << " to logic level " << logiclevel << std::endl;
|
" to logic level " << logicLevel << std::endl;
|
||||||
return DRIVE_GPIO_FAILURE;
|
return DRIVE_GPIO_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,38 +188,76 @@ ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, int* gpioState) {
|
ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, int* gpioState) {
|
||||||
struct gpiod_line *lineHandle;
|
|
||||||
|
|
||||||
gpioMapIter = gpioMap.find(gpioId);
|
gpioMapIter = gpioMap.find(gpioId);
|
||||||
if (gpioMapIter == gpioMap.end()){
|
if (gpioMapIter == gpioMap.end()){
|
||||||
sif::debug << "LinuxLibgpioIF::readGpio: Unknown gpio id " << gpioId << std::endl;
|
sif::warning << "LinuxLibgpioIF::readGpio: Unknown GPIOD ID " << gpioId << std::endl;
|
||||||
return RETURN_FAILED;
|
return UNKNOWN_GPIO_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(gpioMapIter->second->gpioType == gpio::GpioTypes::GPIOD_REGULAR) {
|
||||||
|
GpiodRegular* regularGpio = dynamic_cast<GpiodRegular*>(gpioMapIter->second);
|
||||||
|
if(regularGpio == nullptr) {
|
||||||
|
return GPIO_TYPE_FAILURE;
|
||||||
|
}
|
||||||
|
*gpioState = gpiod_line_get_value(regularGpio->lineHandle);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lineHandle = gpioMapIter->second.lineHandle;
|
|
||||||
*gpioState = gpiod_line_get_value(lineHandle);
|
|
||||||
|
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd){
|
ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd){
|
||||||
gpioId_t gpioId;
|
ReturnValue_t status = HasReturnvaluesIF::RETURN_OK;
|
||||||
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
for(auto& gpioConfig: mapToAdd) {
|
for(auto& gpioConfig: mapToAdd) {
|
||||||
gpioId = gpioConfig.first;
|
switch(gpioConfig.second->gpioType) {
|
||||||
/* Cross check with private map */
|
case(gpio::GpioTypes::GPIOD_REGULAR): {
|
||||||
gpioMapIter = gpioMap.find(gpioId);
|
auto regularGpio = dynamic_cast<GpiodRegular*>(gpioConfig.second);
|
||||||
if(gpioMapIter != mapToAdd.end()) {
|
if(regularGpio == nullptr) {
|
||||||
/* An entry for this GPIO already exists. Check if configuration
|
return GPIO_TYPE_FAILURE;
|
||||||
* of direction is equivalent */
|
|
||||||
if (gpioConfig.second.direction != gpioMapIter->second.direction){
|
|
||||||
sif::error << "LinuxLibgpioIF::checkForConflicts: Detected conflict for GPIO " <<
|
|
||||||
gpioConfig.first << std::endl;
|
|
||||||
return RETURN_FAILED;
|
|
||||||
}
|
}
|
||||||
/* Remove element from map to add because a entry for this GPIO
|
result = checkForConflictsRegularGpio(gpioConfig.first, regularGpio);
|
||||||
* already exists */
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
mapToAdd.erase(gpioConfig.first);
|
status = result;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return RETURN_OK;
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ReturnValue_t LinuxLibgpioIF::checkForConflictsRegularGpio(gpioId_t gpioIdToCheck,
|
||||||
|
GpiodRegular* gpioToCheck) {
|
||||||
|
/* Cross check with private map */
|
||||||
|
gpioMapIter = gpioMap.find(gpioIdToCheck);
|
||||||
|
if(gpioMapIter != gpioMap.end()) {
|
||||||
|
if(gpioMapIter->second->gpioType == gpio::GpioTypes::GPIOD_REGULAR) {
|
||||||
|
auto ownRegularGpio = dynamic_cast<GpiodRegular*>(gpioMapIter->second);
|
||||||
|
if(ownRegularGpio == nullptr) {
|
||||||
|
return GPIO_TYPE_FAILURE;
|
||||||
|
}
|
||||||
|
/* An entry for this GPIO already exists. Check if configuration
|
||||||
|
* of direction is equivalent */
|
||||||
|
if (gpioToCheck->direction != ownRegularGpio->direction){
|
||||||
|
sif::error << "LinuxLibgpioIF::checkForConflicts: Detected conflict for GPIO " <<
|
||||||
|
gpioIdToCheck << std::endl;
|
||||||
|
return RETURN_FAILED;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove element from map to add because a entry for this GPIO
|
||||||
|
* already exists */
|
||||||
|
gpioMap.erase(gpioIdToCheck);
|
||||||
|
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,21 @@ class GpioCookie;
|
|||||||
class LinuxLibgpioIF : public GpioIF, public SystemObject {
|
class LinuxLibgpioIF : public GpioIF, public SystemObject {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static const uint8_t INTERFACE_ID = CLASS_ID::LINUX_LIBGPIO_IF;
|
static const uint8_t gpioRetvalId = CLASS_ID::LINUX_LIBGPIO_IF;
|
||||||
|
|
||||||
static const ReturnValue_t DRIVE_GPIO_FAILURE = MAKE_RETURN_CODE(0x2);
|
static constexpr ReturnValue_t UNKNOWN_GPIO_ID =
|
||||||
|
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 1);
|
||||||
|
static constexpr ReturnValue_t DRIVE_GPIO_FAILURE =
|
||||||
|
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 2);
|
||||||
|
static constexpr ReturnValue_t GPIO_TYPE_FAILURE =
|
||||||
|
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 3);
|
||||||
|
static constexpr ReturnValue_t GPIO_INVALID_INSTANCE =
|
||||||
|
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 4);
|
||||||
|
|
||||||
LinuxLibgpioIF(object_id_t objectId);
|
LinuxLibgpioIF(object_id_t objectId);
|
||||||
virtual ~LinuxLibgpioIF();
|
virtual ~LinuxLibgpioIF();
|
||||||
|
|
||||||
ReturnValue_t initialize(GpioCookie* gpioCookie) override;
|
ReturnValue_t addGpios(GpioCookie* gpioCookie) override;
|
||||||
ReturnValue_t pullHigh(gpioId_t gpioId) override;
|
ReturnValue_t pullHigh(gpioId_t gpioId) override;
|
||||||
ReturnValue_t pullLow(gpioId_t gpioId) override;
|
ReturnValue_t pullLow(gpioId_t gpioId) override;
|
||||||
ReturnValue_t readGpio(gpioId_t gpioId, int* gpioState) override;
|
ReturnValue_t readGpio(gpioId_t gpioId, int* gpioState) override;
|
||||||
@ -40,7 +47,9 @@ private:
|
|||||||
* @param gpioId The GPIO ID of the GPIO to drive.
|
* @param gpioId The GPIO ID of the GPIO to drive.
|
||||||
* @param logiclevel The logic level to set. O or 1.
|
* @param logiclevel The logic level to set. O or 1.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t driveGpio(gpioId_t gpioId, unsigned int logiclevel);
|
ReturnValue_t driveGpio(gpioId_t gpioId, GpiodRegular* regularGpio, unsigned int logiclevel);
|
||||||
|
|
||||||
|
ReturnValue_t configureRegularGpio(gpioId_t gpioId, GpiodRegular* regularGpio);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function checks if GPIOs are already registered and whether
|
* @brief This function checks if GPIOs are already registered and whether
|
||||||
@ -53,6 +62,8 @@ private:
|
|||||||
*/
|
*/
|
||||||
ReturnValue_t checkForConflicts(GpioMap& mapToAdd);
|
ReturnValue_t checkForConflicts(GpioMap& mapToAdd);
|
||||||
|
|
||||||
|
ReturnValue_t checkForConflictsRegularGpio(gpioId_t gpiodId, GpiodRegular* regularGpio);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Performs the initial configuration of all GPIOs specified in the GpioMap mapToAdd.
|
* @brief Performs the initial configuration of all GPIOs specified in the GpioMap mapToAdd.
|
||||||
*/
|
*/
|
||||||
|
@ -12,6 +12,17 @@ enum Direction {
|
|||||||
OUT = 1
|
OUT = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum GpioOperation {
|
||||||
|
READ,
|
||||||
|
WRITE
|
||||||
|
};
|
||||||
|
|
||||||
|
enum GpioTypes {
|
||||||
|
NONE,
|
||||||
|
GPIOD_REGULAR,
|
||||||
|
CALLBACK
|
||||||
|
};
|
||||||
|
|
||||||
static constexpr gpioId_t NO_GPIO = -1;
|
static constexpr gpioId_t NO_GPIO = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,23 +40,52 @@ static constexpr gpioId_t NO_GPIO = -1;
|
|||||||
* @param lineHandle The handle returned by gpiod_chip_get_line will be later written to this
|
* @param lineHandle The handle returned by gpiod_chip_get_line will be later written to this
|
||||||
* pointer.
|
* pointer.
|
||||||
*/
|
*/
|
||||||
typedef struct GpioConfig {
|
class GpioBase {
|
||||||
GpioConfig(): chipname(), lineNum(0), consumer(), direction(gpio::Direction::OUT),
|
public:
|
||||||
initValue(0) {};
|
|
||||||
|
|
||||||
GpioConfig(std::string chipname_, int lineNum_, std::string consumer_,
|
GpioBase() = default;
|
||||||
gpio::Direction direction_, int initValue_):
|
|
||||||
chipname(chipname_), lineNum(lineNum_), consumer(consumer_),
|
GpioBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
|
||||||
direction(direction_), initValue(initValue_) {}
|
int initValue):
|
||||||
std::string chipname;
|
gpioType(gpioType), consumer(consumer),direction(direction), initValue(initValue) {}
|
||||||
int lineNum;
|
|
||||||
|
virtual~ GpioBase() {};
|
||||||
|
|
||||||
|
/* Can be used to cast GpioBase to a concrete child implementation */
|
||||||
|
gpio::GpioTypes gpioType = gpio::GpioTypes::NONE;
|
||||||
std::string consumer;
|
std::string consumer;
|
||||||
gpio::Direction direction;
|
gpio::Direction direction = gpio::Direction::IN;
|
||||||
int initValue;
|
int initValue = 0;
|
||||||
struct gpiod_line* lineHandle = nullptr;
|
};
|
||||||
} GpioConfig_t;
|
|
||||||
|
|
||||||
using GpioMap = std::unordered_map<gpioId_t, GpioConfig_t>;
|
class GpiodRegular: public GpioBase {
|
||||||
|
public:
|
||||||
|
GpiodRegular(): GpioBase() {};
|
||||||
|
|
||||||
|
GpiodRegular(std::string chipname_, int lineNum_, std::string consumer_,
|
||||||
|
gpio::Direction direction_, int initValue_):
|
||||||
|
GpioBase(gpio::GpioTypes::GPIOD_REGULAR, consumer_, direction_, initValue_),
|
||||||
|
chipname(chipname_), lineNum(lineNum_) {}
|
||||||
|
std::string chipname;
|
||||||
|
int lineNum = 0;
|
||||||
|
struct gpiod_line* lineHandle = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
class GpioCallback: public GpioBase {
|
||||||
|
public:
|
||||||
|
GpioCallback(std::string consumer, gpio::Direction direction_, int initValue_,
|
||||||
|
void (* callback) (gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, void* args),
|
||||||
|
void* callbackArgs):
|
||||||
|
GpioBase(gpio::GpioTypes::CALLBACK, consumer, direction_, initValue_),
|
||||||
|
callback(callback), callbackArgs(callbackArgs) {}
|
||||||
|
|
||||||
|
void (* callback) (gpioId_t gpioId, gpio::GpioOperation gpioOp,
|
||||||
|
int value, void* args) = nullptr;
|
||||||
|
void* callbackArgs = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
using GpioMap = std::unordered_map<gpioId_t, GpioBase*>;
|
||||||
using GpioMapIter = GpioMap::iterator;
|
using GpioMapIter = GpioMap::iterator;
|
||||||
|
|
||||||
#endif /* LINUX_GPIO_GPIODEFINITIONS_H_ */
|
#endif /* LINUX_GPIO_GPIODEFINITIONS_H_ */
|
||||||
|
@ -39,7 +39,7 @@ ReturnValue_t SolarArrayDeploymentHandler::initialize() {
|
|||||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = gpioInterface->initialize(dynamic_cast<GpioCookie*>(gpioCookie));
|
result = gpioInterface->addGpios(dynamic_cast<GpioCookie*>(gpioCookie));
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
sif::error << "SolarArrayDeploymentHandler::initialize: Failed to initialize Gpio interface"
|
sif::error << "SolarArrayDeploymentHandler::initialize: Failed to initialize Gpio interface"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user