Merge pull request 'I2C Info, minor fixes, GPIO ctor for simple input pins' (#10) from meier/master into master
Reviewed-on: #10
This commit is contained in:
commit
4cff1aa021
@ -61,7 +61,7 @@ public:
|
|||||||
|
|
||||||
virtual~ GpioBase() {};
|
virtual~ GpioBase() {};
|
||||||
|
|
||||||
/* Can be used to cast GpioBase to a concrete child implementation */
|
// Can be used to cast GpioBase to a concrete child implementation
|
||||||
gpio::GpioTypes gpioType = gpio::GpioTypes::NONE;
|
gpio::GpioTypes gpioType = gpio::GpioTypes::NONE;
|
||||||
std::string consumer;
|
std::string consumer;
|
||||||
gpio::Direction direction = gpio::Direction::IN;
|
gpio::Direction direction = gpio::Direction::IN;
|
||||||
@ -70,13 +70,21 @@ public:
|
|||||||
|
|
||||||
class GpiodRegular: public GpioBase {
|
class GpiodRegular: public GpioBase {
|
||||||
public:
|
public:
|
||||||
GpiodRegular(): GpioBase(gpio::GpioTypes::GPIO_REGULAR, std::string(),
|
GpiodRegular() :
|
||||||
gpio::Direction::IN, 0) {};
|
GpioBase(gpio::GpioTypes::GPIO_REGULAR, std::string(), gpio::Direction::IN, 0) {
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
GpiodRegular(std::string chipname_, int lineNum_, std::string consumer_,
|
GpiodRegular(std::string chipname_, int lineNum_, std::string consumer_,
|
||||||
gpio::Direction direction_, int initValue_) :
|
gpio::Direction direction_, int initValue_) :
|
||||||
GpioBase(gpio::GpioTypes::GPIO_REGULAR, consumer_, direction_, initValue_),
|
GpioBase(gpio::GpioTypes::GPIO_REGULAR, consumer_, direction_, initValue_),
|
||||||
chipname(chipname_), lineNum(lineNum_) {}
|
chipname(chipname_), lineNum(lineNum_) {
|
||||||
|
}
|
||||||
|
|
||||||
|
GpiodRegular(std::string chipname_, int lineNum_, std::string consumer_) :
|
||||||
|
GpioBase(gpio::GpioTypes::GPIO_REGULAR, consumer_, gpio::Direction::IN, 0),
|
||||||
|
chipname(chipname_), lineNum(lineNum_) {
|
||||||
|
}
|
||||||
std::string chipname;
|
std::string chipname;
|
||||||
int lineNum = 0;
|
int lineNum = 0;
|
||||||
struct gpiod_line* lineHandle = nullptr;
|
struct gpiod_line* lineHandle = nullptr;
|
||||||
|
@ -17,7 +17,7 @@ class GpioCookie;
|
|||||||
class LinuxLibgpioIF : public GpioIF, public SystemObject {
|
class LinuxLibgpioIF : public GpioIF, public SystemObject {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static const uint8_t gpioRetvalId = CLASS_ID::LINUX_LIBGPIO_IF;
|
static const uint8_t gpioRetvalId = CLASS_ID::HAL_GPIO;
|
||||||
|
|
||||||
static constexpr ReturnValue_t UNKNOWN_GPIO_ID =
|
static constexpr ReturnValue_t UNKNOWN_GPIO_ID =
|
||||||
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 1);
|
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 1);
|
||||||
|
@ -38,7 +38,7 @@ ReturnValue_t I2cComIF::initializeInterface(CookieIF* cookie) {
|
|||||||
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
|
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
|
||||||
if(i2cDeviceMapIter == i2cDeviceMap.end()) {
|
if(i2cDeviceMapIter == i2cDeviceMap.end()) {
|
||||||
size_t maxReplyLen = i2cCookie->getMaxReplyLen();
|
size_t maxReplyLen = i2cCookie->getMaxReplyLen();
|
||||||
I2cInstance_t i2cInstance = {std::vector<uint8_t>(maxReplyLen), 0};
|
I2cInstance i2cInstance = {std::vector<uint8_t>(maxReplyLen), 0};
|
||||||
auto statusPair = i2cDeviceMap.emplace(i2cAddress, i2cInstance);
|
auto statusPair = i2cDeviceMap.emplace(i2cAddress, i2cInstance);
|
||||||
if (not statusPair.second) {
|
if (not statusPair.second) {
|
||||||
sif::error << "I2cComIF::initializeInterface: Failed to insert device with address " <<
|
sif::error << "I2cComIF::initializeInterface: Failed to insert device with address " <<
|
||||||
@ -146,10 +146,16 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie,
|
|||||||
|
|
||||||
uint8_t* replyBuffer = i2cDeviceMapIter->second.replyBuffer.data();
|
uint8_t* replyBuffer = i2cDeviceMapIter->second.replyBuffer.data();
|
||||||
|
|
||||||
if (read(fd, replyBuffer, requestLen) != static_cast<int>(requestLen)) {
|
int readLen = read(fd, replyBuffer, requestLen);
|
||||||
|
|
||||||
|
if (readLen != static_cast<int>(requestLen)) {
|
||||||
|
#if FSFW_VERBOSE_LEVEL >= 1 and FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "I2cComIF::requestReceiveMessage: Reading from I2C "
|
sif::error << "I2cComIF::requestReceiveMessage: Reading from I2C "
|
||||||
<< "device failed with error code " << errno <<". Description"
|
<< "device failed with error code " << errno <<". Description"
|
||||||
<< " of error: " << strerror(errno) << std::endl;
|
<< " of error: " << strerror(errno) << std::endl;
|
||||||
|
sif::error << "I2cComIF::requestReceiveMessage: Read only " << readLen << " from "
|
||||||
|
<< requestLen << " bytes" << std::endl;
|
||||||
|
#endif
|
||||||
i2cDeviceMapIter->second.replyLen = 0;
|
i2cDeviceMapIter->second.replyLen = 0;
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,10 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This is the communication interface for i2c devices connected
|
* @brief This is the communication interface for I2C devices connected
|
||||||
* to a system running a linux OS.
|
* to a system running a Linux OS.
|
||||||
|
*
|
||||||
|
* @note The Xilinx Linux kernel might not support to read more than 255 bytes at once.
|
||||||
*
|
*
|
||||||
* @author J. Meier
|
* @author J. Meier
|
||||||
*/
|
*/
|
||||||
@ -31,12 +33,12 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
typedef struct I2cInstance {
|
struct I2cInstance {
|
||||||
std::vector<uint8_t> replyBuffer;
|
std::vector<uint8_t> replyBuffer;
|
||||||
size_t replyLen;
|
size_t replyLen;
|
||||||
} I2cInstance_t;
|
};
|
||||||
|
|
||||||
using I2cDeviceMap = std::unordered_map<address_t, I2cInstance_t>;
|
using I2cDeviceMap = std::unordered_map<address_t, I2cInstance>;
|
||||||
using I2cDeviceMapIter = I2cDeviceMap::iterator;
|
using I2cDeviceMapIter = I2cDeviceMap::iterator;
|
||||||
|
|
||||||
/* In this map all i2c devices will be registered with their address and
|
/* In this map all i2c devices will be registered with their address and
|
||||||
|
@ -22,7 +22,7 @@ class SpiCookie;
|
|||||||
*/
|
*/
|
||||||
class SpiComIF: public DeviceCommunicationIF, public SystemObject {
|
class SpiComIF: public DeviceCommunicationIF, public SystemObject {
|
||||||
public:
|
public:
|
||||||
static constexpr uint8_t spiRetvalId = CLASS_ID::LINUX_SPI_COM_IF;
|
static constexpr uint8_t spiRetvalId = CLASS_ID::HAL_SPI;
|
||||||
static constexpr ReturnValue_t OPENING_FILE_FAILED =
|
static constexpr ReturnValue_t OPENING_FILE_FAILED =
|
||||||
HasReturnvaluesIF::makeReturnCode(spiRetvalId, 0);
|
HasReturnvaluesIF::makeReturnCode(spiRetvalId, 0);
|
||||||
/* Full duplex (ioctl) transfer failure */
|
/* Full duplex (ioctl) transfer failure */
|
||||||
|
Loading…
Reference in New Issue
Block a user