0.4.6 PCA9635

This commit is contained in:
Rob Tillaart 2023-05-26 16:22:43 +02:00
parent 1e88244dfc
commit 013d11f3ce
7 changed files with 112 additions and 71 deletions

View File

@ -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.4.6] - 2023-05-24
- renaming #defines PCA963X... to prepare merge with PCA9634.
- old defines will work until next major release
- update keywords.txt
## [0.4.5] - 2023-04-26
- add **writeLedOut(reg, mask)** experimental
- add **readLedOut(reg)** experimental
@ -19,7 +25,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- update readme.md
- minor edits
## [0.4.4] - 2023-01-23
- fix #22 update documentation
- add **I2C_SoftwareReset()** experimental

View File

@ -2,7 +2,7 @@
// FILE: PCA9635.cpp
// AUTHOR: Rob Tillaart
// DATE: 23-apr-2016
// VERSION: 0.4.5
// VERSION: 0.4.6
// PURPOSE: Arduino library for PCA9635 I2C LED driver
// URL: https://github.com/RobTillaart/PCA9635
@ -310,9 +310,9 @@ bool PCA9635::enableSubCall(uint8_t nr)
if ((nr == 0) || (nr > 3)) return false;
uint8_t prev = getMode1();
uint8_t mask = prev;
if (nr == 1) mask |= PCA9635_MODE1_SUB1;
else if (nr == 2) mask |= PCA9635_MODE1_SUB2;
else mask |= PCA9635_MODE1_SUB3;
if (nr == 1) mask |= PCA963X_MODE1_SUB1;
else if (nr == 2) mask |= PCA963X_MODE1_SUB2;
else mask |= PCA963X_MODE1_SUB3;
// only update if changed.
if (mask != prev)
{
@ -328,9 +328,9 @@ bool PCA9635::disableSubCall(uint8_t nr)
if ((nr == 0) || (nr > 3)) return false;
uint8_t prev = getMode1();
uint8_t mask = prev;
if (nr == 1) mask &= ~PCA9635_MODE1_SUB1;
else if (nr == 2) mask &= ~PCA9635_MODE1_SUB2;
else mask &= ~PCA9635_MODE1_SUB3;
if (nr == 1) mask &= ~PCA963X_MODE1_SUB1;
else if (nr == 2) mask &= ~PCA963X_MODE1_SUB2;
else mask &= ~PCA963X_MODE1_SUB3;
// only update if changed.
if (mask != prev)
{
@ -345,9 +345,9 @@ bool PCA9635::isEnabledSubCall(uint8_t nr)
{
if ((nr == 0) || (nr > 3)) return false;
uint8_t mask = getMode1();
if (nr == 1) return (mask & PCA9635_MODE1_SUB1) > 0;
if (nr == 2) return (mask & PCA9635_MODE1_SUB2) > 0;
return (mask & PCA9635_MODE1_SUB3) > 0;
if (nr == 1) return (mask & PCA963X_MODE1_SUB1) > 0;
if (nr == 2) return (mask & PCA963X_MODE1_SUB2) > 0;
return (mask & PCA963X_MODE1_SUB3) > 0;
}
@ -358,7 +358,7 @@ bool PCA9635::setSubCallAddress(uint8_t nr, uint8_t address)
// _error = ?? TODO
return false;
}
writeReg(PCA9635_SUBADR(nr), address);
writeReg(PCA963X_SUBADR(nr), address);
return true;
}
@ -370,7 +370,7 @@ uint8_t PCA9635::getSubCallAddress(uint8_t nr)
// _error = ?? TODO
return 0;
}
uint8_t address = readReg(PCA9635_SUBADR(nr));
uint8_t address = readReg(PCA963X_SUBADR(nr));
return address;
}
@ -378,7 +378,7 @@ uint8_t PCA9635::getSubCallAddress(uint8_t nr)
bool PCA9635::enableAllCall()
{
uint8_t prev = getMode1();
uint8_t mask = prev | PCA9635_MODE1_ALLCALL;
uint8_t mask = prev | PCA963X_MODE1_ALLCALL;
// only update if changed.
if (mask != prev)
{
@ -392,7 +392,7 @@ bool PCA9635::enableAllCall()
bool PCA9635::disableAllCall()
{
uint8_t prev = getMode1();
uint8_t mask = prev & ~PCA9635_MODE1_ALLCALL;
uint8_t mask = prev & ~PCA963X_MODE1_ALLCALL;
// only update if changed.
if (mask != prev)
{
@ -406,20 +406,20 @@ bool PCA9635::disableAllCall()
bool PCA9635::isEnabledAllCall()
{
uint8_t mask = getMode1();
return mask & PCA9635_MODE1_ALLCALL;
return mask & PCA963X_MODE1_ALLCALL;
}
bool PCA9635::setAllCallAddress(uint8_t address)
{
writeReg(PCA9635_ALLCALLADR, address);
writeReg(PCA963X_ALLCALLADR, address);
return true;
}
uint8_t PCA9635::getAllCallAddress()
{
uint8_t address = readReg(PCA9635_ALLCALLADR);
uint8_t address = readReg(PCA963X_ALLCALLADR);
return address;
}

View File

@ -3,7 +3,7 @@
// FILE: PCA9635.h
// AUTHOR: Rob Tillaart
// DATE: 23-apr-2016
// VERSION: 0.4.5
// VERSION: 0.4.6
// PURPOSE: Arduino library for PCA9635 I2C LED driver, 16 channel
// URL: https://github.com/RobTillaart/PCA9635
@ -12,7 +12,7 @@
#include "Wire.h"
#define PCA9635_LIB_VERSION (F("0.4.5"))
#define PCA9635_LIB_VERSION (F("0.4.6"))
// mode codes
@ -70,7 +70,17 @@
// Configuration bits MODE1 register
// OLD (todo)
// NEW
#define PCA963X_MODE1_AUTOINCR2 0x80 // ReadOnly, 0 = disable 1 = enable
#define PCA963X_MODE1_AUTOINCR1 0x40 // ReadOnly, bit1
#define PCA963X_MODE1_AUTOINCR0 0x20 // ReadOnly, bit0
#define PCA963X_MODE1_SLEEP 0x10 // 0 = normal 1 = sleep
#define PCA963X_MODE1_SUB1 0x08 // 0 = disable 1 = enable
#define PCA963X_MODE1_SUB2 0x04 // 0 = disable 1 = enable
#define PCA963X_MODE1_SUB3 0x02 // 0 = disable 1 = enable
#define PCA963X_MODE1_ALLCALL 0x01 // 0 = disable 1 = enable
#define PCA963X_MODE1_NONE 0x00
// OLD
#define PCA9635_MODE1_AUTOINCR2 0x80 // ReadOnly, 0 = disable 1 = enable
#define PCA9635_MODE1_AUTOINCR1 0x40 // ReadOnly, bit1
#define PCA9635_MODE1_AUTOINCR0 0x20 // ReadOnly, bit0
@ -83,7 +93,13 @@
// Configuration bits MODE2 register
// OLD (todo)
// NEW
#define PCA963X_MODE2_BLINK 0x20 // 0 = dim 1 = blink
#define PCA963X_MODE2_INVERT 0x10 // 0 = normal 1 = inverted
#define PCA963X_MODE2_ACK 0x08 // 0 = on STOP 1 = on ACK
#define PCA963X_MODE2_TOTEMPOLE 0x04 // 0 = open drain 1 = totem-pole
#define PCA963X_MODE2_NONE 0x00
// OLD
#define PCA9635_MODE2_BLINK 0x20 // 0 = dim 1 = blink
#define PCA9635_MODE2_INVERT 0x10 // 0 = normal 1 = inverted
#define PCA9635_MODE2_ACK 0x08 // 0 = on STOP 1 = on ACK
@ -91,12 +107,30 @@
#define PCA9635_MODE2_NONE 0x00
// NOT IMPLEMENTED YET (todo check)
// NOT IMPLEMENTED YET (TODO check)
//
// Registers in which the ALLCALL and sub-addresses are stored
// NEW
#define PCA963X_SUBADR(x) (0x17 +(x)) // x = 1..3
#define PCA963X_ALLCALLADR 0x1B
// OLD
#define PCA9635_SUBADR(x) (0x17+(x)) // x = 1..3
#define PCA9635_ALLCALLADR 0x1B
// Standard ALLCALL and sub-addresses --> only work for write commands and NOT for read commands
// TODO
//#define PCA963X_ALLCALL 0x70 // TDS of chip says 0xE0, however,
// in this library the LSB is added during the write command
// (0xE0 --> 0b11100000, 0x70 --> 0b1110000)
//#define PCA963X_SUB1 0x71 // see line above (0xE2 --> 0x71)
//#define PCA963X_SUB2 0x72 // see line above (0xE4 --> 0x72)
//#define PCA963X_SUB3 0x74 // see line above (0xE8 --> 0x74)
/////////////////////////////////////////////////////
//
// CLASS
@ -108,11 +142,11 @@ public:
#if defined (ESP8266) || defined(ESP32)
bool begin(int sda, int scl,
uint8_t mode1_mask = PCA9635_MODE1_ALLCALL,
uint8_t mode2_mask = PCA9635_MODE2_NONE);
uint8_t mode1_mask = PCA963X_MODE1_ALLCALL,
uint8_t mode2_mask = PCA963X_MODE2_NONE);
#endif
bool begin(uint8_t mode1_mask = PCA9635_MODE1_ALLCALL,
uint8_t mode2_mask = PCA9635_MODE2_NONE);
bool begin(uint8_t mode1_mask = PCA963X_MODE1_ALLCALL,
uint8_t mode2_mask = PCA963X_MODE2_NONE);
bool isConnected();

View File

@ -32,18 +32,19 @@ of the PWM signal.
#include "PCA9635.h"
```
#### Constructor
- **PCA9635(uint8_t deviceAddress, TwoWire \*wire = &Wire)** Constructor with I2C device address,
- **PCA9635(uint8_t deviceAddress, TwoWire \*wire = &Wire)** Constructor with I2C device address,
and optional the Wire interface as parameter.
- **bool begin(uint8_t mode1_mask = PCA9635_MODE1_ALLCALL, uint8_t mode2_mask = PCA9635_MODE2_NONE)**
- **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 = PCA9635_MODE1_ALLCALL, uint8_t mode2_mask = PCA9635_MODE2_NONE)**
- **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)**
- **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.
See PCA9635.h and datasheet for settings possible.
- **bool isConnected()** checks if address is available on I2C bus.
- **uint8_t channelCount()** returns the number of channels = 16.
@ -100,25 +101,24 @@ useful to add or remove a single flag (bit masking).
#### Constants for mode registers
(added 0.3.4)
| Name | Value | Description |
|:--------------------------|:-------:|:-------------------------------------|
| PCA9635_MODE1_AUTOINCR2 | 0x80 | Read Only, 0 = disable 1 = enable |
| PCA9635_MODE1_AUTOINCR1 | 0x40 | Read Only, bit1 |
| PCA9635_MODE1_AUTOINCR0 | 0x20 | Read Only, bit0 |
| PCA9635_MODE1_SLEEP | 0x10 | 0 = normal 1 = sleep |
| PCA9635_MODE1_SUB1 | 0x08 | 0 = disable 1 = enable |
| PCA9635_MODE1_SUB2 | 0x04 | 0 = disable 1 = enable |
| PCA9635_MODE1_SUB3 | 0x02 | 0 = disable 1 = enable |
| PCA9635_MODE1_ALLCALL | 0x01 | 0 = disable 1 = enable |
| PCA9635_MODE1_NONE | 0x00 | |
| PCA963X_MODE1_AUTOINCR2 | 0x80 | Read Only, 0 = disable 1 = enable |
| PCA963X_MODE1_AUTOINCR1 | 0x40 | Read Only, bit1 |
| PCA963X_MODE1_AUTOINCR0 | 0x20 | Read Only, bit0 |
| PCA963X_MODE1_SLEEP | 0x10 | 0 = normal 1 = sleep |
| PCA963X_MODE1_SUB1 | 0x08 | 0 = disable 1 = enable |
| PCA963X_MODE1_SUB2 | 0x04 | 0 = disable 1 = enable |
| PCA963X_MODE1_SUB3 | 0x02 | 0 = disable 1 = enable |
| PCA963X_MODE1_ALLCALL | 0x01 | 0 = disable 1 = enable |
| PCA963X_MODE1_NONE | 0x00 | |
| ---- | | |
| PCA9635_MODE2_BLINK | 0x20 | 0 = dim 1 = blink |
| PCA9635_MODE2_INVERT | 0x10 | 0 = normal 1 = inverted |
| PCA9635_MODE2_STOP | 0x08 | 0 = on STOP 1 = on ACK |
| PCA9635_MODE2_TOTEMPOLE | 0x04 | 0 = open drain 1 = totem-pole |
| PCA9635_MODE2_NONE | 0x00 | |
| PCA963X_MODE2_BLINK | 0x20 | 0 = dim 1 = blink |
| PCA963X_MODE2_INVERT | 0x10 | 0 = normal 1 = inverted |
| PCA963X_MODE2_STOP | 0x08 | 0 = on STOP 1 = on ACK |
| PCA963X_MODE2_TOTEMPOLE | 0x04 | 0 = open drain 1 = totem-pole |
| PCA963X_MODE2_NONE | 0x00 | |
These constants makes it easier to set modes without using a non descriptive
@ -129,12 +129,12 @@ ledArray.writeMode(PCA963X_MODE2, 0b00110100);
// would become
uint8_t mode2_mask = PCA9635_MODE2_BLINK | PCA9635_MODE2_INVERT | PCA9635_MODE2_TOTEMPOLE;
uint8_t mode2_mask = PCA963X_MODE2_BLINK | PCA963X_MODE2_INVERT | PCA963X_MODE2_TOTEMPOLE;
ledArray.writeMode(PCA963X_MODE2, mode2_mask);
// or even
ledArray.setMode2(PCA9635_MODE2_BLINK | PCA9635_MODE2_INVERT | PCA9635_MODE2_TOTEMPOLE);
ledArray.setMode2(PCA963X_MODE2_BLINK | PCA963X_MODE2_INVERT | PCA963X_MODE2_TOTEMPOLE);
```
@ -209,13 +209,13 @@ The functions to enable all/sub-addresses are straightforward:
Since 0.4.3 (experimental) support to control the OE (Output Enable) pin of the PCA9635.
This OE pin can control all LEDs simultaneously.
It also allows to control multiple PCA9635 modules by connecting the OE pins.
It also allows to control multiple devices by connecting the OE pins.
Think of simultaneous switching ON/OFF or get dimming with a high frequency PWM.
Or use 2 modules alternatively by placing an inverter in between.
See datasheet for the details
- **bool setOutputEnablePin(uint8_t pin = 255)** sets the IO pin to connect to the OE pin of the PCA9635.
- **bool setOutputEnablePin(uint8_t pin = 255)** sets the IO pin to connect to the OE pin of the device.
A value of 255 indicates no pin set/selected.
Sets the OE pin to HIGH.
Returns true on success.
@ -317,19 +317,21 @@ PCA.writeLedOut(1, mask);
- read/writeLedOut()
- **setOutputEnablePWM(uint16_t value)** PWM support ?
- getter?
- merge with PCA9635 and a PCA963X base class if possible
- restructure function groups
- in .cpp to match .h
- readme.md
- **setGroupPWM()**
- PWM also in %% ?
- **setGroupFreq()**
- set time in milliseconds and round to nearest value?
#### Wont
- consider implementing
- clearMode1() and clearMode2() functions.
- only upon request.
- merge with PCA9634/5 and a PCA963X base class if possible
- not easy, more alignment is desirable.
- only upon request.
- **setGroupPWM()**
- PWM also in %% ? (trivial for user)

View File

@ -61,21 +61,21 @@ PCA963X_ERR_MODE LITERAL1
PCA963X_ERR_REG LITERAL1
PCA963X_ERR_I2C LITERAL1
PCA9635_MODE1_AUTOINCR2 LITERAL1
PCA9635_MODE1_AUTOINCR1 LITERAL1
PCA9635_MODE1_AUTOINCR0 LITERAL1
PCA9635_MODE1_SLEEP LITERAL1
PCA9635_MODE1_SUB1 LITERAL1
PCA9635_MODE1_SUB2 LITERAL1
PCA9635_MODE1_SUB3 LITERAL1
PCA9635_MODE1_ALLCALL LITERAL1
PCA9635_MODE1_NONE LITERAL1
PCA963X_MODE1_AUTOINCR2 LITERAL1
PCA963X_MODE1_AUTOINCR1 LITERAL1
PCA963X_MODE1_AUTOINCR0 LITERAL1
PCA963X_MODE1_SLEEP LITERAL1
PCA963X_MODE1_SUB1 LITERAL1
PCA963X_MODE1_SUB2 LITERAL1
PCA963X_MODE1_SUB3 LITERAL1
PCA963X_MODE1_ALLCALL LITERAL1
PCA963X_MODE1_NONE LITERAL1
PCA9635_MODE2_BLINK LITERAL1
PCA9635_MODE2_INVERT LITERAL1
PCA9635_MODE2_ACK LITERAL1
PCA9635_MODE2_TOTEMPOLE LITERAL1
PCA9635_MODE2_NONE LITERAL1
PCA963X_MODE2_BLINK LITERAL1
PCA963X_MODE2_INVERT LITERAL1
PCA963X_MODE2_ACK LITERAL1
PCA963X_MODE2_TOTEMPOLE LITERAL1
PCA963X_MODE2_NONE LITERAL1
PCA963X_LEDOFF LITERAL1
PCA963X_LEDON LITERAL1

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/PCA9635.git"
},
"version": "0.4.5",
"version": "0.4.6",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=PCA9635
version=0.4.5
version=0.4.6
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for PCA9635 I2C LED driver 16 channel