diff --git a/fpga/include/villas/fpga/ips/i2c.hpp b/fpga/include/villas/fpga/ips/i2c.hpp index b257ad91d..0736c7d0e 100644 --- a/fpga/include/villas/fpga/ips/i2c.hpp +++ b/fpga/include/villas/fpga/ips/i2c.hpp @@ -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 &data); bool read(u8 address, std::vector &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(this, address); } else { diff --git a/fpga/lib/ips/i2c.cpp b/fpga/lib/ips/i2c.cpp index b868ce471..fd69c08e5 100644 --- a/fpga/lib/ips/i2c.cpp +++ b/fpga/lib/ips/i2c.cpp @@ -154,11 +154,6 @@ bool I2c::read(u8 address, std::vector &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 &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;