diff --git a/libraries/TCA9548/CHANGELOG.md b/libraries/TCA9548/CHANGELOG.md index 20e29103..31d70f6f 100644 --- a/libraries/TCA9548/CHANGELOG.md +++ b/libraries/TCA9548/CHANGELOG.md @@ -6,11 +6,20 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.3.0] - 2024-04-15 +- Fix #20, **disableChannel()** bug + optimize. +- Fix **isConnected(address, channel)** bug. +- update keywords.txt +- update readme.md +- add **uint8_t find(address)** function, returns mask. +- update / add examples. + +---- + ## [0.2.2] - 2024-01-01 - add **bool isConnected(uint8_t address, uint8_t channel)** - minor edits - ## [0.2.1] - 2023-12-09 - add derived classes - PCA9543 (2 channel), PCA9545 (4 channel), PCA9546 (4 channel) diff --git a/libraries/TCA9548/README.md b/libraries/TCA9548/README.md index 84c3a7fa..60c2fb8d 100644 --- a/libraries/TCA9548/README.md +++ b/libraries/TCA9548/README.md @@ -99,9 +99,6 @@ There are however small differences, check the data sheets to see the details. deviceAddress = 0x70 .. 0x77, wire = Wire or WireN. - **bool begin(uint8_t mask = 0x00)** set mask of channels to be enabled, default all disabled. - **bool isConnected()** returns true if address of the multiplexer is found on I2C bus. -- **bool isConnected(uint8_t address, uint8_t channel)** find address on selected channel. -Note that this changes the selected and or enabled channels. -Returns true if found. The derived classes PCA9548/PCA9546 have the same interface, except constructor. (see #15) @@ -114,9 +111,17 @@ The derived classes PCA9548/PCA9546 have the same interface, except constructor. #### Find device -- **bool isConnected(uint8_t address)** returns true if arbitrary address is found on I2C bus. -This can be used to verify if a certain device is available (or not) on an **enabled** channel. -So it does not scan all 8 channels to see if any of them has a device with the address given. +- **bool isConnected(uint8_t address)** returns true if arbitrary address is found on the +current I2C bus + selected channels. +This can be used to verify if a certain device is available (or not) on any **enabled** channel. +So it does not scan all (8) channels to see if any of them has a device with the address given. +- **bool isConnected(uint8_t address, uint8_t channel)** find address on selected channel. +Note that this function changes the selected and or enabled channels. +Returns true if found. +- **uint8_t find(uint8_t address)** returns a mask with bits set for channels +where the address is found. It scans all channels available. +Note that this function changes the selected and or enabled channels. +Returns 0 when the address is not found on any channel, or one bit set per channel found. #### Channel functions @@ -145,9 +150,10 @@ Optional the library can reset the device. - **void setResetPin(uint8_t resetPin)** sets the pin to reset the chip. - **void reset()** trigger the reset pin. + #### Debug -- **int getError()** returns the last I2C error. +- **int getError()** returns the last (I2C) status / error. #### Forced IO @@ -155,7 +161,8 @@ Optional the library can reset the device. When forced IO is set, all writes and read, e.g. **uint8_t getChannelMask()**, will go to the device. If the **forced-IO** flag is set to false, it will cache the value of the channels enabled. This will result in far more responsive and faster calls. -Note that writes are only optimized if the channels are already set. +Note that writes are only optimized if the channels are already set. +Forced IO is also used to speed up **getChannelMask()**. - **void setForced(bool forced = false)** set forced write, slower but more robust. - forced == false == fast mode (default). @@ -165,6 +172,8 @@ Note that writes are only optimized if the channels are already set. #### Interrupts +(not tested) + The PCA9545 and PCA9543 support interrupts. These two derived classes have implemented the @@ -200,6 +209,10 @@ Not implemented yet, preparation for future. - set an "always enabled" mask. - investigate the consequences! - extend the unit tests. +- **uint8_t find(address)** returns a mask of channel where address is found +- restore channel in **isConnected(address, channel); +- add guard in **reset()**, is the pin set? + #### Wont diff --git a/libraries/TCA9548/TCA9548.cpp b/libraries/TCA9548/TCA9548.cpp index 13547d5c..58a7b769 100644 --- a/libraries/TCA9548/TCA9548.cpp +++ b/libraries/TCA9548/TCA9548.cpp @@ -1,7 +1,7 @@ // // FILE: TCA9548.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.2.2 +// VERSION: 0.3.0 // DATE: 2021-03-16 // PURPOSE: Arduino Library for TCA9548 I2C multiplexer and compatibles. @@ -45,7 +45,20 @@ bool TCA9548::isConnected(uint8_t address) bool TCA9548::isConnected(uint8_t address, uint8_t channel) { if (!selectChannel(channel)) return false; - return isConnected(_address); + return isConnected(address); +} + + +uint8_t TCA9548::find(uint8_t address) +{ + uint8_t mask = 0x00; + for (uint8_t ch = 0; ch < _channels; ch++) + { + // will work partially if MP is off line (by choice). + selectChannel(ch); + if (isConnected(address)) mask |= (1 << ch); + } + return mask; } @@ -58,30 +71,21 @@ uint8_t TCA9548::channelCount() bool TCA9548::enableChannel(uint8_t channel) { if (channel >= _channels) return false; - if (!isEnabled(channel)) - { - setChannelMask(_mask | (0x01 << channel)); - } - return true; + return setChannelMask(_mask | (0x01 << channel)); } bool TCA9548::disableChannel(uint8_t channel) { if (channel >= _channels) return false; - if (!isEnabled(channel)) - { - setChannelMask(_mask & ~(0x01 << channel)); - } - return true; + return setChannelMask(_mask & ~(0x01 << channel)); } bool TCA9548::selectChannel(uint8_t channel) { if (channel >= _channels) return false; - setChannelMask(0x01 << channel); - return true; + return setChannelMask(0x01 << channel); } diff --git a/libraries/TCA9548/TCA9548.h b/libraries/TCA9548/TCA9548.h index e09acd0d..77198578 100644 --- a/libraries/TCA9548/TCA9548.h +++ b/libraries/TCA9548/TCA9548.h @@ -2,7 +2,7 @@ // // FILE: TCA9548.h // AUTHOR: Rob Tillaart -// VERSION: 0.2.2 +// VERSION: 0.3.0 // DATE: 2021-03-16 // PURPOSE: Arduino Library for TCA9548 I2C multiplexer and compatibles. // URL: https://github.com/RobTillaart/TCA9548 @@ -12,7 +12,7 @@ #include "Wire.h" -#define TCA9548_LIB_VERSION (F("0.2.2")) +#define TCA9548_LIB_VERSION (F("0.3.0")) // ERROR CODES (to be elaborated) @@ -33,6 +33,8 @@ public: bool isConnected(uint8_t address); // find any address on I2C bus bool isConnected(uint8_t address, uint8_t channel); // find address on selected channel + uint8_t find(uint8_t address); // returns a mask with channels + // channel = 0..channelCount()-1 uint8_t channelCount(); bool enableChannel(uint8_t channel); // enable this channel non exclusive @@ -61,13 +63,13 @@ public: protected: - uint8_t _address; - TwoWire* _wire; - uint8_t _mask; // caching mask = status of channels - uint8_t _resetPin; // default not set == -1 (255) - bool _forced; - int _error; - uint8_t _channels; // PCA954x support. + uint8_t _address; + TwoWire * _wire; + uint8_t _mask; // caching mask = status of channels + uint8_t _resetPin; // default not set == -1 (255) + bool _forced; + int _error; + uint8_t _channels; // PCA954x support. }; diff --git a/libraries/TCA9548/examples/TCA9548_find/TCA9548_find.ino b/libraries/TCA9548/examples/TCA9548_find/TCA9548_find.ino new file mode 100644 index 00000000..432d4a59 --- /dev/null +++ b/libraries/TCA9548/examples/TCA9548_find/TCA9548_find.ino @@ -0,0 +1,52 @@ +// +// FILE: TCA9548_find.ino +// AUTHOR: Rob Tillaart +// PURPOSE: demo TCA9548 I2C multiplexer +// URL: https://github.com/RobTillaart/TCA9548 + + +#include "TCA9548.h" + +TCA9548 MP(0x70); + +uint8_t channels = 0; + + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.print("TCA9548_LIB_VERSION: "); + Serial.println(TCA9548_LIB_VERSION); + Serial.println(); + + Wire.begin(); + if (MP.begin() == false) + { + Serial.println("COULD NOT CONNECT TO MULTIPLEXER"); + } + + channels = MP.channelCount(); + Serial.print("CHAN:\t"); + Serial.println(MP.channelCount()); + + // adjust address range to your needs. + for (uint8_t addr = 60; addr < 70; addr++) + { + if (addr % 10 == 0) Serial.println(); + Serial.print(addr); + Serial.print("\t"); + Serial.print(MP.find(addr), BIN); + Serial.println(); + } + + Serial.println("done..."); +} + + +void loop() +{ +} + + +// -- END OF FILE -- diff --git a/libraries/TCA9548/examples/tca9548_demo/tca9548_demo.ino b/libraries/TCA9548/examples/tca9548_demo/tca9548_demo.ino index 2e55e0fd..eb796d81 100644 --- a/libraries/TCA9548/examples/tca9548_demo/tca9548_demo.ino +++ b/libraries/TCA9548/examples/tca9548_demo/tca9548_demo.ino @@ -1,5 +1,5 @@ // -// FILE: tca9548_demo.ino +// FILE: TCA9548_demo.ino // AUTHOR: Rob Tillaart // PURPOSE: demo TCA9548 I2C multiplexer // URL: https://github.com/RobTillaart/TCA9548 diff --git a/libraries/TCA9548/examples/tca9548_search_device/tca9548_search_device.ino b/libraries/TCA9548/examples/tca9548_search_device/tca9548_search_device.ino index a28e4f87..98aef523 100644 --- a/libraries/TCA9548/examples/tca9548_search_device/tca9548_search_device.ino +++ b/libraries/TCA9548/examples/tca9548_search_device/tca9548_search_device.ino @@ -1,8 +1,10 @@ // -// FILE: tca9548_search_device.ino +// FILE: TCA9548_search_device.ino // AUTHOR: Rob Tillaart // PURPOSE: demo TCA9548 I2C multiplexer // URL: https://github.com/RobTillaart/TCA9548 +// +// NOTE: since 0.3.0 a find function is added. #include "TCA9548.h" @@ -28,7 +30,7 @@ void setup() } Serial.println("\nScan the channels of the multiplexer for searchAddress.\n"); - for (int chan = 0; chan < 8; chan++) + for (int chan = 0; chan < MP.channelCount(); chan++) { MP.selectChannel(chan); bool b = MP.isConnected(searchAddress); diff --git a/libraries/TCA9548/keywords.txt b/libraries/TCA9548/keywords.txt index b4e5632d..a9648ec0 100644 --- a/libraries/TCA9548/keywords.txt +++ b/libraries/TCA9548/keywords.txt @@ -11,7 +11,9 @@ PCA9543 KEYWORD1 # Methods and Functions (KEYWORD2) begin KEYWORD2 isConnected KEYWORD2 +find KEYWORD2 +channelCount KEYWORD2 enableChannel KEYWORD2 disableChannel KEYWORD2 selectChannel KEYWORD2 @@ -29,6 +31,8 @@ getForced KEYWORD2 getError KEYWORD2 + +# Devices with interrupt getInterruptMask KEYWORD2 diff --git a/libraries/TCA9548/library.json b/libraries/TCA9548/library.json index 73569524..d15f1ccd 100644 --- a/libraries/TCA9548/library.json +++ b/libraries/TCA9548/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/TCA9548" }, - "version": "0.2.2", + "version": "0.3.0", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/libraries/TCA9548/library.properties b/libraries/TCA9548/library.properties index 79ba11e4..abae8b65 100644 --- a/libraries/TCA9548/library.properties +++ b/libraries/TCA9548/library.properties @@ -1,5 +1,5 @@ name=TCA9548 -version=0.2.2 +version=0.3.0 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino Library for TCA9548 I2C multiplexer and compatibles.