From db793416f1ab317bf98dae82e800e5a253350c8d Mon Sep 17 00:00:00 2001 From: lady ada Date: Thu, 14 May 2020 16:56:27 -0400 Subject: [PATCH] add i2c speed change --- Adafruit_I2CDevice.cpp | 17 ++++++++++++++++- Adafruit_I2CDevice.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Adafruit_I2CDevice.cpp b/Adafruit_I2CDevice.cpp index eeb863c..7f394f8 100644 --- a/Adafruit_I2CDevice.cpp +++ b/Adafruit_I2CDevice.cpp @@ -114,7 +114,7 @@ bool Adafruit_I2CDevice::write(uint8_t *buffer, size_t len, bool stop, DEBUG_SERIAL.print(F("0x")); DEBUG_SERIAL.print(buffer[i], HEX); DEBUG_SERIAL.print(F(", ")); - if (len % 32 == 31) { + if (i % 32 == 31) { DEBUG_SERIAL.println(); } } @@ -215,3 +215,18 @@ bool Adafruit_I2CDevice::write_then_read(uint8_t *write_buffer, * @return The 7-bit address of this device */ uint8_t Adafruit_I2CDevice::address(void) { return _addr; } + +/*! + * @brief Change the I2C clock speed to desired (relies on + * underlying Wire support! + * @return True if this platform supports changing I2C speed. + * Not necessarily that the speed was achieved! + */ +bool Adafruit_I2CDevice::setSpeed(uint32_t desiredclk) { +#if (ARDUINO >= 157) && !defined(ARDUINO_STM32_FEATHER) + _wire->setClock(desiredclk); + return true; +#else + return false; +#endif +} diff --git a/Adafruit_I2CDevice.h b/Adafruit_I2CDevice.h index 25d9d5c..0dcfc50 100644 --- a/Adafruit_I2CDevice.h +++ b/Adafruit_I2CDevice.h @@ -17,6 +17,7 @@ public: bool write_then_read(uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len, bool stop = false); + bool setSpeed(uint32_t desiredclk); /*! @brief How many bytes we can read in a transaction * @return The size of the Wire receive/transmit buffer */