diff --git a/CHANGELOG.md b/CHANGELOG.md index a5a74ca..7d871dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.1.5] - 2022-12-30 +- add pin numbers TCA_P00 -- TCA_P17 +- add **uint8_t getType()** + example +- update unit test + + ## [0.1.4] - 2022-12-29 - Fix #7 missing public: - add unit test for TCA9535 constructor @@ -15,7 +21,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - update readme.md - update GitHub actions -> v3 - ## [0.1.3] - 2022-11-25 - Add RP2040 support to build-CI. - Add CHANGELOG.md diff --git a/README.md b/README.md index 4137f20..e321a0c 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ input and not driven. This reduces power consumption when the I/O is held low._ There is a TCA9535 class which is a (convenience) wrapper around the TCA9555 class. This allows one to create TCA9535 objects. + ## Hardware #### I2C addresses @@ -49,6 +50,7 @@ Check the datasheet for details - **TCA9555(uint8_t address, TwoWire \*wire = &Wire)** constructor, with default Wire interface. Can be overruled with Wire0..WireN. - **TCA9535(uint8_t address, TwoWire \*wire = &Wire)** idem. +- **uint8_t getType()** returns 35 or 55 depending on type. - **bool begin()** for UNO, returns true if successful. @@ -120,7 +122,8 @@ See examples #### Must - buy TCA9555 / TCA9535 -- test all functionality (initial version is written with no hardware around) +- test all functionality + - library is written without hardware #### Should @@ -130,16 +133,12 @@ See examples - investigate TCA9535 differences - pull up resistors - elaborate derived class -- add **getType()** to distinguish derived classes. - - int or uint8_t => 4 or 2 digits, define? - - or even a string (no)? - - constructor #### Could - rethink class hierarchy - -5535 has less functions so should be base class? + - TCA9535 has less functions so should be base class? - valid address range? diff --git a/TCA9555.cpp b/TCA9555.cpp index 2d0e5ab..dfa8848 100644 --- a/TCA9555.cpp +++ b/TCA9555.cpp @@ -1,7 +1,7 @@ // // FILE: TCA9555.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.4 +// VERSION: 0.1.5 // PURPOSE: Arduino library for I2C TCA9555 16 channel port expander // DATE: 2021-06-09 // URL: https://github.com/RobTillaart/TCA9555 @@ -26,6 +26,7 @@ TCA9555::TCA9555(uint8_t address, TwoWire *wire) _address = address; _wire = wire; _error = TCA9555_OK; + _type = 55; } @@ -307,6 +308,12 @@ int TCA9555::lastError() } +uint8_t TCA9555::getType() +{ + return _type; +} + + //////////////////////////////////////////////////// // // PRIVATE @@ -352,6 +359,7 @@ uint8_t TCA9555::readRegister(uint8_t reg) TCA9535::TCA9535(uint8_t address, TwoWire *wire) :TCA9555(address, wire) { + _type = 35; } diff --git a/TCA9555.h b/TCA9555.h index 5eb59c8..6f5e581 100644 --- a/TCA9555.h +++ b/TCA9555.h @@ -2,7 +2,7 @@ // // FILE: TCA9555.h // AUTHOR: Rob Tillaart -// VERSION: 0.1.4 +// VERSION: 0.1.5 // PURPOSE: Arduino library for I2C TCA9555 16 channel port expander // DATE: 2021-06-09 // URL: https://github.com/RobTillaart/TCA9555 @@ -12,7 +12,7 @@ #include "Wire.h" -#define TCA9555_LIB_VERSION (F("0.1.4")) +#define TCA9555_LIB_VERSION (F("0.1.5")) #define TCA9555_OK 0x00 #define TCA9555_PIN_ERROR 0x81 @@ -23,6 +23,29 @@ #define TCA9555_INVALID_READ -100 +#if !defined(TCA9555_PIN_NAMES) +#define TCA9555_PIN_NAMES + + #define TCA_P00 0 + #define TCA_P01 1 + #define TCA_P02 2 + #define TCA_P03 3 + #define TCA_P04 4 + #define TCA_P05 5 + #define TCA_P06 6 + #define TCA_P07 7 + #define TCA_P10 8 + #define TCA_P11 9 + #define TCA_P12 10 + #define TCA_P13 11 + #define TCA_P14 12 + #define TCA_P15 13 + #define TCA_P16 14 + #define TCA_P17 15 + +#endif + + class TCA9555 { public: @@ -71,6 +94,8 @@ class TCA9555 int lastError(); + uint8_t getType(); + protected: bool writeRegister(uint8_t reg, uint8_t value); @@ -79,6 +104,7 @@ class TCA9555 uint8_t _address; TwoWire* _wire; uint8_t _error; + uint8_t _type; }; diff --git a/examples/TCA9555_getType/TCA9555_getType.ino b/examples/TCA9555_getType/TCA9555_getType.ino new file mode 100644 index 0000000..9d4bb75 --- /dev/null +++ b/examples/TCA9555_getType/TCA9555_getType.ino @@ -0,0 +1,32 @@ +// +// FILE: TCA9555_getType.ino +// AUTHOR: Rob Tillaart +// PUPROSE: test TCA9555 library - TCA9535 derived class +// URL: https://github.com/RobTillaart/TCA9555 + + +#include "Wire.h" +#include "TCA9555.h" + + +TCA9555 TCA0(0x20); +TCA9535 TCA1(0x21); + + +void setup() +{ + Serial.begin(115200); + Serial.print("TCA9555_LIB_VERSION: "); + Serial.println(TCA9555_LIB_VERSION); + + Serial.println(TCA0.getType()); + Serial.println(TCA1.getType()); +} + + +void loop() +{ +} + + +// -- END OF FILE -- diff --git a/library.json b/library.json index 7f7ae8c..03f9e83 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/TCA9555.git" }, - "version": "0.1.4", + "version": "0.1.5", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/library.properties b/library.properties index 5ecd9d4..51869a2 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TCA9555 -version=0.1.4 +version=0.1.5 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for I2C TCA9555 16 channel port expander - 16 IO-lines diff --git a/test/unit_test_001.cpp b/test/unit_test_001.cpp index 030d556..50674e5 100644 --- a/test/unit_test_001.cpp +++ b/test/unit_test_001.cpp @@ -54,6 +54,7 @@ unittest(test_constructor_TCA9555) assertTrue(TCA.begin()); assertTrue(TCA.isConnected()); + assertEqual(55, TCA.getType()); } @@ -63,10 +64,11 @@ unittest(test_constructor_TCA9535) assertTrue(TCA.begin()); assertTrue(TCA.isConnected()); + assertEqual(35, TCA.getType()); } -unittest(test_constants) +unittest(test_constants_I) { assertEqual(0x00, TCA9555_OK); assertEqual(0x81, TCA9555_PIN_ERROR); @@ -77,6 +79,27 @@ unittest(test_constants) } +unittest(test_constants_II) +{ + assertEqual(0, TCA_P00); + assertEqual(1, TCA_P01); + assertEqual(2, TCA_P02); + assertEqual(3, TCA_P03); + assertEqual(4, TCA_P04); + assertEqual(5, TCA_P05); + assertEqual(6, TCA_P06); + assertEqual(7, TCA_P07); + assertEqual(8, TCA_P10); + assertEqual(9, TCA_P11); + assertEqual(10, TCA_P12); + assertEqual(11, TCA_P13); + assertEqual(12, TCA_P14); + assertEqual(13, TCA_P15); + assertEqual(14, TCA_P16); + assertEqual(15, TCA_P17); +} + + unittest_main() // --------