Skip to content

Commit

Permalink
refactor API, begin() (#31)
Browse files Browse the repository at this point in the history
= refactor API, begin()
- add **uint8_t getAddress()**
- update readme.md
- update examples
  • Loading branch information
RobTillaart authored Dec 11, 2023
1 parent cb315a9 commit 7d4e04e
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 34 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.5.0] - 2023-12-11
= refactor API, begin()
- add **uint8_t getAddress()**
- update readme.md
- update examples

----

## [0.4.7] - 2023-09-24
- add Wire1 support for ESP32
- update readme.md
- minor edits


## [0.4.6] - 2023-05-24
- renaming #defines PCA963X... to prepare merge with PCA9634.
- old defines will work until next major release
Expand Down
25 changes: 7 additions & 18 deletions PCA9635.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// FILE: PCA9635.cpp
// AUTHOR: Rob Tillaart
// DATE: 23-apr-2016
// VERSION: 0.4.7
// VERSION: 0.5.0
// PURPOSE: Arduino library for PCA9635 I2C LED driver, 16 channel PWM, 8 bit
// URL: https://github.com/RobTillaart/PCA9635

Expand All @@ -24,25 +24,8 @@ PCA9635::PCA9635(const uint8_t deviceAddress, TwoWire *wire)
}


#if defined (ESP8266) || defined(ESP32)
bool PCA9635::begin(int sda, int scl, uint8_t mode1_mask, uint8_t mode2_mask)
{
if ((sda < 255) && (scl < 255))
{
_wire->begin(sda, scl);
} else {
_wire->begin();
}
if (! isConnected()) return false;
configure(mode1_mask, mode2_mask);
return true;
}
#endif


bool PCA9635::begin(uint8_t mode1_mask, uint8_t mode2_mask)
{
_wire->begin();
if (! isConnected()) return false;
configure(mode1_mask, mode2_mask);
return true;
Expand All @@ -57,6 +40,12 @@ bool PCA9635::isConnected()
}


uint8_t PCA9635::getAddress()
{
return _address;
}


/////////////////////////////////////////////////////
//
// CONFIGURATION
Expand Down
10 changes: 3 additions & 7 deletions PCA9635.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// FILE: PCA9635.h
// AUTHOR: Rob Tillaart
// DATE: 23-apr-2016
// VERSION: 0.4.7
// VERSION: 0.5.0
// PURPOSE: Arduino library for PCA9635 I2C LED driver, 16 channel PWM, 8 bit
// URL: https://github.com/RobTillaart/PCA9635

Expand All @@ -12,7 +12,7 @@
#include "Wire.h"


#define PCA9635_LIB_VERSION (F("0.4.7"))
#define PCA9635_LIB_VERSION (F("0.5.0"))


// mode codes
Expand Down Expand Up @@ -140,14 +140,10 @@ class PCA9635
public:
explicit PCA9635(const uint8_t deviceAddress, TwoWire *wire = &Wire);

#if defined (ESP8266) || defined(ESP32)
bool begin(int sda, int scl,
uint8_t mode1_mask = PCA963X_MODE1_ALLCALL,
uint8_t mode2_mask = PCA963X_MODE2_NONE);
#endif
bool begin(uint8_t mode1_mask = PCA963X_MODE1_ALLCALL,
uint8_t mode2_mask = PCA963X_MODE2_NONE);
bool isConnected();
uint8_t getAddress();


/////////////////////////////////////////////////////
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ This allows for better than 1% fine tuning of the duty-cycle
of the PWM signal.


#### 0.5.0 Breaking change

Version 0.5.0 introduced a breaking change.
You cannot set the pins in **begin()** any more.
This reduces the dependency of processor dependent Wire implementations.
The user has to call **Wire.begin()** and can optionally set the Wire pins
before calling **begin()**.


#### Related

- https://github.com/RobTillaart/PCA9634 (8 channel)
Expand All @@ -43,8 +52,6 @@ and optional the Wire interface as parameter.
- **bool begin(uint8_t mode1_mask = PCA963X_MODE1_ALLCALL, uint8_t mode2_mask = PCA963X_MODE2_NONE)**
initializes the library after startup. Optionally setting the MODE1 and MODE2 configuration registers.
See PCA9635.h and datasheet for settings possible.
- **bool begin(int sda, int scl, uint8_t mode1_mask = PCA963X_MODE1_ALLCALL, uint8_t mode2_mask = PCA963X_MODE2_NONE)**
idem, ESP32 ESP8266 only.
- **void configure(uint8_t mode1_mask, uint8_t mode2_mask)**
To configure the library after startup one can set the MODE1 and MODE2 configuration registers.
See PCA9635.h and datasheet for settings possible.
Expand Down
3 changes: 3 additions & 0 deletions examples/PCA9635_OE_control/PCA9635_OE_control.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ PCA9635 ledArray(0x20);
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("PCA9635 LIB version: ");
Serial.println(PCA9635_LIB_VERSION);
Serial.println();

Wire.begin();

ledArray.begin();

// just one channel
Expand Down
3 changes: 3 additions & 0 deletions examples/PCA9635_performance/PCA9635_performance.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ uint32_t start, stop;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("PCA9635 LIB version: ");
Serial.println(PCA9635_LIB_VERSION);
Serial.println();

Wire.begin();

ledArray.begin();

delay(100); // flush all Serial interrupts
Expand Down
3 changes: 3 additions & 0 deletions examples/PCA9635_shift_rotate/PCA9635_shift_rotate.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ uint8_t channels = 16;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("PCA9635 LIB version: ");
Serial.println(PCA9635_LIB_VERSION);
Serial.println();

Wire.begin();

ledArray.begin();

channels = ledArray.channelCount();
Expand Down
4 changes: 3 additions & 1 deletion examples/PCA9635_test01/PCA9635_test01.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//
// FILE: PCA9635_test01.ino
// AUTHOR: Rob Tillaart
// DATE: 23-APR-2016
// PURPOSE: test PCA9635 library
// URL: https://github.com/RobTillaart/PCA9635

Expand All @@ -17,10 +16,13 @@ PCA9635 ledArray(0x20);
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("PCA9635 LIB version: ");
Serial.println(PCA9635_LIB_VERSION);
Serial.println();

Wire.begin();

ledArray.begin();

testSetLedDriverModeLEDON();
Expand Down
4 changes: 3 additions & 1 deletion examples/PCA9635_test_multiple/PCA9635_test_multiple.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//
// FILE: PCA9635_test_multiple.ino
// AUTHOR: Rob Tillaart
// DATE: 2018-02-18
// PURPOSE: test PCA9635 library
// URL: https://github.com/RobTillaart/PCA9635

Expand All @@ -18,10 +17,13 @@ PCA9635 ledArray2(0x21);
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("PCA9635 LIB version: ");
Serial.println(PCA9635_LIB_VERSION);
Serial.println();

Wire.begin();

ledArray.begin();
ledArray2.begin();

Expand Down
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/PCA9635.git"
},
"version": "0.4.7",
"version": "0.5.0",
"license": "MIT",
"frameworks": "*",
"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=PCA9635
version=0.4.7
version=0.5.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for PCA9635 I2C LED driver, 16 channel PWM, 8 bit.
Expand Down
12 changes: 10 additions & 2 deletions test/unit_test_001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ unittest(test_constants)
unittest(test_constructor)
{
PCA9635 ledArray(0x20);

Wire.begin();

assertTrue(ledArray.begin());
assertTrue(ledArray.isConnected());
assertEqual(16, ledArray.channelCount());
Expand All @@ -86,22 +89,27 @@ unittest(test_constructor)
unittest(test_LedDriverMode)
{
PCA9635 ledArray(0x20);

Wire.begin();

assertTrue(ledArray.begin());

// TODO
// TODO
}


unittest(test_OutputEnable)
{
PCA9635 ledArray(0x20);

Wire.begin();

assertTrue(ledArray.begin());

assertEqual(HIGH, ledArray.getOutputEnable());

assertTrue(ledArray.setOutputEnablePin(12));
// assertEqual(HIGH, ledArray.getOutputEnable()); // need mock
// assertEqual(HIGH, ledArray.getOutputEnable()); // need mock

assertTrue(ledArray.setOutputEnable(true));
// assertEqual(LOW, ledArray.getOutputEnable());
Expand Down

0 comments on commit 7d4e04e

Please sign in to comment.