1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

fix double start of i2c bus driver and move channel map to header

Signed-off-by: Niklas Eiling <niklas.eiling@eonerc.rwth-aachen.de>
This commit is contained in:
Niklas Eiling 2024-01-08 10:43:22 +01:00 committed by Niklas Eiling
parent 48846ace39
commit 810b1259f8
2 changed files with 11 additions and 10 deletions

View file

@ -18,6 +18,13 @@ namespace villas {
namespace fpga {
namespace ip {
#define I2C_SWTICH_ADDR 0x70
#define I2C_SWITCH_CHANNEL_MAP \
{ 0x20, 0x80, 0x02, 0x08, 0x10, 0x40, 0x01, 0x04 }
#define I2C_IOEXT_ADDR 0x20
#define I2C_IOEXT_REG_DIR 0x03
#define I2C_IOEXT_REG_OUT 0x01
#define I2C_EEPROM_ADDR 0x50
class I2c : public Node {
public:
friend class I2cFactory;
@ -25,7 +32,7 @@ public:
I2c();
virtual ~I2c();
virtual bool init() override;
bool reset() override;
virtual bool reset() override;
bool write(u8 address, std::vector<u8> &data);
bool read(u8 address, std::vector<u8> &data, size_t max_read);
@ -50,7 +57,7 @@ public:
uint8_t channel;
bool readOnce;
};
Switch &getSwitch(uint8_t address = 0x70) {
Switch &getSwitch(uint8_t address = I2C_SWTICH_ADDR) {
if (switchInstance == nullptr) {
switchInstance = std::make_unique<Switch>(this, address);
} else {

View file

@ -154,11 +154,6 @@ bool I2c::read(u8 address, std::vector<u8> &data, size_t max_read) {
int retries = 10;
while (receiveIntrs == 0 && retries > 0) {
ret = XIic_Start(&xIic);
if (ret != XST_SUCCESS) {
throw RuntimeError("Failed to start I2C");
}
int intrRetries = 1;
do {
ret = XIic_MasterRecv(&xIic, dataPtr, max_read);
@ -189,10 +184,9 @@ bool I2c::read(u8 address, std::vector<u8> &data, size_t max_read) {
return XST_SUCCESS;
}
static const uint8_t CHANNEL_MAP[] = {0x20, 0x80, 0x02, 0x08,
0x10, 0x40, 0x01, 0x04};
static const uint8_t CHANNEL_MAP[] = I2C_SWITCH_CHANNEL_MAP;
void I2c::Switch::setChannel(uint8_t channel) {
if (channel > sizeof(CHANNEL_MAP) / sizeof(CHANNEL_MAP[0])) {
if (channel >= sizeof(CHANNEL_MAP) / sizeof(CHANNEL_MAP[0])) {
throw RuntimeError("Invalid channel number {}", channel);
}
this->channel = channel;