Skip to content

Commit

Permalink
#45
Browse files Browse the repository at this point in the history
  • Loading branch information
moononournation committed Sep 30, 2023
1 parent 3499377 commit 5ffdce3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
11 changes: 5 additions & 6 deletions src/databus/Arduino_XCA9554SWSPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
//#define XCA9554_DEBUG

Arduino_XCA9554SWSPI::Arduino_XCA9554SWSPI(int8_t rst, int8_t cs, int8_t sck, int8_t mosi, TwoWire *wire, uint8_t i2c_addr)
: _rst(rst), _cs(cs), _sck(sck), _mosi(mosi), _wire(wire), _address(i2c_addr)
: _rst(rst), _cs(cs), _sck(sck), _mosi(mosi), _wire(wire), _i2c_addr(i2c_addr)
{
}

bool Arduino_XCA9554SWSPI::begin(int32_t, int8_t)
{
_wire->begin();
_wire->beginTransmission(_address);
_wire->beginTransmission(_i2c_addr);
if (!_wire->endTransmission())
{
Serial.println("Found xCA9554");
Expand Down Expand Up @@ -148,7 +148,7 @@ void Arduino_XCA9554SWSPI::writeRegister(uint8_t reg, uint8_t *data, size_t len)
#ifdef XCA9554_DEBUG
Serial.printf("Writing to $%02X: ", reg);
#endif
_wire->beginTransmission(_address);
_wire->beginTransmission(_i2c_addr);
_wire->write(reg);
for (size_t i = 0; i < len; i++)
{
Expand All @@ -165,13 +165,13 @@ void Arduino_XCA9554SWSPI::writeRegister(uint8_t reg, uint8_t *data, size_t len)

uint8_t Arduino_XCA9554SWSPI::readRegister(uint8_t reg, uint8_t *data, size_t len)
{
_wire->beginTransmission(_address);
_wire->beginTransmission(_i2c_addr);
_wire->write(reg);
#ifdef XCA9554_DEBUG
Serial.printf("Read from $%02X: ", reg);
#endif
_wire->endTransmission();
_wire->requestFrom(_address, len);
_wire->requestFrom(_i2c_addr, len);
size_t index = 0;
while (index < len) {
data[index++] = _wire->read();
Expand Down Expand Up @@ -225,7 +225,6 @@ int Arduino_XCA9554SWSPI::digitalRead(uint8_t pin)
{
if (is_found)
{
int state = 0;
uint8_t port = 0;
this->readRegister(XCA9554_INPUT_PORT_REG, &port, 1);
//Serial.printf("Read 0x%02X\n", port);
Expand Down
7 changes: 4 additions & 3 deletions src/databus/Arduino_XCA9554SWSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "Arduino_DataBus.h"

#define XCA9554_IIC_ADDRESS 0x38
#define XCA9554_IIC_i2c_addr 0x38

#define XCA9554_INPUT_PORT_REG 0x00
#define XCA9554_OUTPUT_PORT_REG 0x01
Expand All @@ -15,7 +15,7 @@
class Arduino_XCA9554SWSPI : public Arduino_DataBus
{
public:
Arduino_XCA9554SWSPI(int8_t rst, int8_t cs, int8_t sck, int8_t mosi, TwoWire *wire = &Wire, uint8_t i2c_addr = XCA9554_IIC_ADDRESS);
Arduino_XCA9554SWSPI(int8_t rst, int8_t cs, int8_t sck, int8_t mosi, TwoWire *wire = &Wire, uint8_t i2c_addr = XCA9554_IIC_i2c_addr);

bool begin(int32_t speed = GFX_NOT_DEFINED, int8_t dataMode = GFX_NOT_DEFINED) override;
void beginWrite() override;
Expand All @@ -39,11 +39,12 @@ class Arduino_XCA9554SWSPI : public Arduino_DataBus
void writeRegister(uint8_t reg, uint8_t *data, size_t len);
uint8_t readRegister(uint8_t reg, uint8_t *data, size_t len);

uint8_t _address, output_buf = 0;
uint8_t output_buf = 0;
bool is_found;

int8_t _rst, _cs, _sck, _mosi;
TwoWire *_wire;
uint8_t _i2c_addr;

private:
};
Expand Down

0 comments on commit 5ffdce3

Please sign in to comment.