Skip to content

Commit

Permalink
add getType() (#10)
Browse files Browse the repository at this point in the history
- add pin numbers TCA_P00 -- TCA_P17
- add **uint8_t getType()** + example
- update unit test
  • Loading branch information
RobTillaart committed Jan 12, 2023
1 parent 3ce0cfe commit 66ad046
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 13 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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?


Expand Down
10 changes: 9 additions & 1 deletion TCA9555.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -26,6 +26,7 @@ TCA9555::TCA9555(uint8_t address, TwoWire *wire)
_address = address;
_wire = wire;
_error = TCA9555_OK;
_type = 55;
}


Expand Down Expand Up @@ -307,6 +308,12 @@ int TCA9555::lastError()
}


uint8_t TCA9555::getType()
{
return _type;
}


////////////////////////////////////////////////////
//
// PRIVATE
Expand Down Expand Up @@ -352,6 +359,7 @@ uint8_t TCA9555::readRegister(uint8_t reg)
TCA9535::TCA9535(uint8_t address, TwoWire *wire)
:TCA9555(address, wire)
{
_type = 35;
}


Expand Down
30 changes: 28 additions & 2 deletions TCA9555.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -71,6 +94,8 @@ class TCA9555


int lastError();
uint8_t getType();


protected:
bool writeRegister(uint8_t reg, uint8_t value);
Expand All @@ -79,6 +104,7 @@ class TCA9555
uint8_t _address;
TwoWire* _wire;
uint8_t _error;
uint8_t _type;
};


Expand Down
32 changes: 32 additions & 0 deletions examples/TCA9555_getType/TCA9555_getType.ino
Original file line number Diff line number Diff line change
@@ -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 --
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=TCA9555
version=0.1.4
version=0.1.5
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for I2C TCA9555 16 channel port expander - 16 IO-lines
Expand Down
25 changes: 24 additions & 1 deletion test/unit_test_001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ unittest(test_constructor_TCA9555)

assertTrue(TCA.begin());
assertTrue(TCA.isConnected());
assertEqual(55, TCA.getType());
}


Expand All @@ -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);
Expand All @@ -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()

// --------

0 comments on commit 66ad046

Please sign in to comment.