fsfw/src/fsfw_hal/linux/i2c/I2cComIF.h

56 lines
1.8 KiB
C
Raw Normal View History

2021-07-13 19:19:25 +02:00
#ifndef LINUX_I2C_I2COMIF_H_
#define LINUX_I2C_I2COMIF_H_
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
2022-02-02 10:29:30 +01:00
#include <fsfw/objectmanager/SystemObject.h>
2021-07-13 19:19:25 +02:00
#include <unordered_map>
#include <vector>
2022-02-02 10:29:30 +01:00
#include "I2cCookie.h"
2021-07-13 19:19:25 +02:00
/**
* @brief This is the communication interface for I2C devices connected
* 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
*/
2022-02-02 10:29:30 +01:00
class I2cComIF : public DeviceCommunicationIF, public SystemObject {
public:
I2cComIF(object_id_t objectId);
virtual ~I2cComIF();
ReturnValue_t initializeInterface(CookieIF *cookie) override;
ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) override;
ReturnValue_t getSendSuccess(CookieIF *cookie) override;
ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) override;
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) override;
private:
struct I2cInstance {
std::vector<uint8_t> replyBuffer;
size_t replyLen;
};
using I2cDeviceMap = std::unordered_map<address_t, I2cInstance>;
/* In this map all i2c devices will be registered with their address and
* the appropriate file descriptor will be stored */
I2cDeviceMap i2cDeviceMap;
/**
* @brief This function opens an I2C device and binds the opened file
* to a specific I2C address.
* @param deviceFile The name of the device file. E.g. i2c-0
* @param i2cAddress The address of the i2c slave device.
* @param fileDescriptor Pointer to device descriptor.
2022-08-16 12:12:21 +02:00
* @return returnvalue::OK if successful, otherwise returnvalue::FAILED.
2022-02-02 10:29:30 +01:00
*/
2023-02-18 13:07:38 +01:00
ReturnValue_t openI2cSlave(const std::string& deviceFile, address_t i2cAddress, int fileDescriptor);
2021-07-13 19:19:25 +02:00
};
#endif /* LINUX_I2C_I2COMIF_H_ */