mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
I2C: Network support
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
#ifndef __I2CMESSAGE_H_
|
||||
#define __I2CMESSAGE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include <vector>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class I2CMessage : public Frame {
|
||||
public:
|
||||
enum class DeviceMode : uint8_t {
|
||||
Target = 0,
|
||||
Controller = 1
|
||||
};
|
||||
|
||||
enum class Direction : uint8_t {
|
||||
Write = 0,
|
||||
Read = 1
|
||||
};
|
||||
|
||||
bool isExtendedID = false;
|
||||
bool isTXMsg = false;
|
||||
bool txError = false;
|
||||
bool txLostArb = false;
|
||||
bool txAborted = false;
|
||||
bool txNack = false;
|
||||
bool txTimeout = false;
|
||||
uint16_t stats = static_cast<uint16_t>(0x0000u);
|
||||
uint16_t address;
|
||||
Direction direction;
|
||||
DeviceMode deviceMode;
|
||||
|
||||
//Must contain the target register address to read or write
|
||||
std::vector<uint8_t> controlBytes;
|
||||
|
||||
//The device expects a dataBytes payload even if you're reading
|
||||
//In the case of a read these bytes aren't interesting, but they have to be there
|
||||
//Add bytes to write, or the same number of junk bytes you expect the device send back
|
||||
std::vector<uint8_t> dataBytes;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,61 @@
|
||||
#ifndef __I2CPACKET_H__
|
||||
#define __I2CPACKET_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/communication/message/i2cmessage.h"
|
||||
#include "icsneo/api/eventmanager.h"
|
||||
#include "icsneo/communication/packetizer.h"
|
||||
#include "icsneo/communication/network.h"
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
static constexpr size_t I2CMaxLength = 1024u;
|
||||
|
||||
#pragma pack(push, 2)
|
||||
|
||||
struct I2CHeader {
|
||||
struct {
|
||||
// C1xI2C
|
||||
uint16_t ID : 10;// i2c address, 7-bit or 10-bit
|
||||
uint16_t EID : 1;// using extended addressing, i.e. 10-bit
|
||||
uint16_t CT : 1;// Controller/Target
|
||||
uint16_t DIR : 1;// read/write
|
||||
uint16_t RESERVED_0 : 3;
|
||||
|
||||
// C2xI2C
|
||||
uint16_t TXMsg: 1;
|
||||
uint16_t CBLen: 11;
|
||||
uint16_t RESERVED_1: 4;
|
||||
|
||||
// C3xI2C
|
||||
uint16_t TXTimeout : 1;
|
||||
uint16_t TXNack : 1;
|
||||
uint16_t TXAborted : 1;
|
||||
uint16_t TXLostArb : 1;
|
||||
uint16_t TXError : 1;
|
||||
uint16_t RESERVED_2: 11;
|
||||
} CoreMiniBitsI2C;
|
||||
|
||||
uint8_t coreMiniMessageData[8];
|
||||
uint16_t stats;
|
||||
|
||||
uint64_t timestamp;
|
||||
|
||||
uint16_t networkID;
|
||||
uint16_t length;
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
struct HardwareI2CPacket {
|
||||
static std::shared_ptr<Message> DecodeToMessage(const std::vector<uint8_t>& bytestream);
|
||||
static bool EncodeFromMessage(const I2CMessage& message, std::vector<uint8_t>& bytestream, const device_eventhandler_t& report);
|
||||
};
|
||||
}
|
||||
|
||||
#endif //_cplusplus
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user