From a2befb15de94ddee6488080e5e781ee6d12acc48 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 24 Nov 2021 14:10:05 +0700 Subject: [PATCH 1/3] add end() to de-init i2c peripheral --- Adafruit_I2CDevice.cpp | 6 ++++++ Adafruit_I2CDevice.h | 1 + 2 files changed, 7 insertions(+) diff --git a/Adafruit_I2CDevice.cpp b/Adafruit_I2CDevice.cpp index 9db9095..0e761be 100644 --- a/Adafruit_I2CDevice.cpp +++ b/Adafruit_I2CDevice.cpp @@ -35,6 +35,12 @@ bool Adafruit_I2CDevice::begin(bool addr_detect) { return true; } +void Adafruit_I2CDevice::end(void) +{ + _wire->end(); + _begun = false; +} + /*! * @brief Scans I2C for the address - note will give a false-positive * if there's no pullups on I2C diff --git a/Adafruit_I2CDevice.h b/Adafruit_I2CDevice.h index 1e27416..5baa6fd 100644 --- a/Adafruit_I2CDevice.h +++ b/Adafruit_I2CDevice.h @@ -10,6 +10,7 @@ public: Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire = &Wire); uint8_t address(void); bool begin(bool addr_detect = true); + void end(void); bool detected(void); bool read(uint8_t *buffer, size_t len, bool stop = true); From 6804a451b3a64cdd20f05dfb4544b4b6fe748571 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 24 Nov 2021 17:55:52 +0700 Subject: [PATCH 2/3] skip wire end() for ESP8266 --- Adafruit_I2CDevice.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Adafruit_I2CDevice.cpp b/Adafruit_I2CDevice.cpp index 0e761be..ca36f21 100644 --- a/Adafruit_I2CDevice.cpp +++ b/Adafruit_I2CDevice.cpp @@ -35,9 +35,12 @@ bool Adafruit_I2CDevice::begin(bool addr_detect) { return true; } -void Adafruit_I2CDevice::end(void) -{ +void Adafruit_I2CDevice::end(void) { +#ifndef ESP8266 + // ESP8266 does not implement Wire::end() _wire->end(); +#endif + _begun = false; } From 5d6fa8dfaf9ed2b316309ed14451b8ca45f4ac30 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 24 Nov 2021 18:05:49 +0700 Subject: [PATCH 3/3] fix doxygen --- Adafruit_I2CDevice.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Adafruit_I2CDevice.cpp b/Adafruit_I2CDevice.cpp index ca36f21..bbe869c 100644 --- a/Adafruit_I2CDevice.cpp +++ b/Adafruit_I2CDevice.cpp @@ -35,6 +35,9 @@ bool Adafruit_I2CDevice::begin(bool addr_detect) { return true; } +/*! + * @brief De-initialize device, turn off the Wire interface + */ void Adafruit_I2CDevice::end(void) { #ifndef ESP8266 // ESP8266 does not implement Wire::end()