diff --git a/libraries/PCA9634/PCA9634.cpp b/libraries/PCA9634/PCA9634.cpp index f262be40..c60319f6 100644 --- a/libraries/PCA9634/PCA9634.cpp +++ b/libraries/PCA9634/PCA9634.cpp @@ -2,13 +2,14 @@ // FILE: PCA9634.cpp // AUTHOR: Rob Tillaart // DATE: 03-01-2022 -// VERSION: 0.1.1 +// VERSION: 0.1.2 // PURPOSE: Arduino library for PCA9634 I2C LED driver // URL: https://github.com/RobTillaart/PCA9634 // // HISTORY: // 0.1.0 2022-01-03 initial version -- based upon 0.3.2 PCA9635 // 0.1.1 2022-01-04 minor fixes +// 0.1.2 2022-04-13 issue #7 add constants and functions for mode registers. #include "PCA9634.h" @@ -64,7 +65,9 @@ void PCA9634::reset() { _data = 0; _error = 0; - writeReg(PCA9634_MODE1, 0x81); // AUTOINCR | NOSLEEP | ALLADRR + + uint8_t mode1_mask = PCA9634_MODE1_AUTOINCR2 | PCA9634_MODE1_ALLCALL; + writeReg(PCA9634_MODE1, mode1_mask); // AUTOINCR | NOSLEEP | ALLADRR 0x81 } diff --git a/libraries/PCA9634/PCA9634.h b/libraries/PCA9634/PCA9634.h index 1b6a21b7..c059e5cd 100644 --- a/libraries/PCA9634/PCA9634.h +++ b/libraries/PCA9634/PCA9634.h @@ -3,7 +3,7 @@ // FILE: PCA9634.h // AUTHOR: Rob Tillaart // DATE: 03-01-2022 -// VERSION: 0.1.1 +// VERSION: 0.1.2 // PURPOSE: Arduino library for PCA9634 I2C LED driver, 8 channel // URL: https://github.com/RobTillaart/PCA9634 @@ -12,11 +12,14 @@ #include "Wire.h" -#define PCA9634_LIB_VERSION (F("0.1.1")) +#define PCA9634_LIB_VERSION (F("0.1.2")) #define PCA9634_MODE1 0x00 #define PCA9634_MODE2 0x01 -#define PCA9634_PWM(x) (0x82+(x)) // Auto-Increment for all registers. + +// 0x80 bit ==> Auto-Increment for all registers. +// used in writeN() - see issue #9 +#define PCA9634_PWM(x) (0x82+(x)) #define PCA9634_GRPPWM 0x0A #define PCA9634_GRPFREQ 0x0B @@ -37,6 +40,24 @@ #define PCA9634_ERR_REG 0xFB #define PCA9634_ERR_I2C 0xFA + +// Configuration bits MODE1 register +#define PCA9634_MODE1_AUTOINCR2 0x80 // RO, 0 = disable 1 = enable +#define PCA9634_MODE1_AUTOINCR1 0x40 // RO, bit1 +#define PCA9634_MODE1_AUTOINCR0 0x20 // RO bit0 +#define PCA9634_MODE1_SLEEP 0x10 // 0 = normal 1 = sleep +#define PCA9634_MODE1_SUB1 0x08 // 0 = disable 1 = enable +#define PCA9634_MODE1_SUB2 0x04 // 0 = disable 1 = enable +#define PCA9634_MODE1_SUB3 0x02 // 0 = disable 1 = enable +#define PCA9634_MODE1_ALLCALL 0x01 // 0 = disable 1 = enable + +// Configuration bits MODE2 register +#define PCA9634_MODE2_BLINK 0x20 // 0 = dim 1 = blink +#define PCA9634_MODE2_INVERT 0x10 // 0 = normal 1 = inverted +#define PCA9634_MODE2_STOP 0x08 // 0 = on STOP 1 = on ACK +#define PCA9634_MODE2_TOTEMPOLE 0x04 // 0 = open drain 1 = totem-pole + + // NOT IMPLEMENTED YET #define PCA9634_SUBADR(x) (0x0E +(x)) // x = 1..3 #define PCA9634_ALLCALLADR 0x11 @@ -71,6 +92,12 @@ public: // reg = 1, 2 check datasheet for values uint8_t writeMode(uint8_t reg, uint8_t value); uint8_t readMode(uint8_t reg); + // convenience wrappers + uint8_t setMode1(uint8_t value) { return writeMode(PCA9634_MODE1, value); }; + uint8_t setMode2(uint8_t value) { return writeMode(PCA9634_MODE2, value); }; + uint8_t getMode1() { return readMode(PCA9634_MODE1); }; + uint8_t getMode2() { return readMode(PCA9634_MODE2); }; + // TODO PWM also in %% ? void setGroupPWM(uint8_t value) { writeReg(PCA9634_GRPPWM, value); } diff --git a/libraries/PCA9634/README.md b/libraries/PCA9634/README.md index f64401be..872572bf 100644 --- a/libraries/PCA9634/README.md +++ b/libraries/PCA9634/README.md @@ -36,6 +36,7 @@ multiple Wire instances (yet). - **bool isConnected()** checks if address is available on I2C bus. - **uint8_t channelCount()** returns the number of channels = 8. + ### LedDriverMode - **uint8_t setLedDriverMode(uint8_t channel, uint8_t mode)** mode is 0..3 See datasheet for full details. @@ -60,10 +61,57 @@ typical use is to write R, G, B values for a full colour LED. - **uint8_t writeN(uint8_t channel, uint8_t \* array, uint8_t count)** write count consecutive PWM registers. May return **PCA9634_ERR_WRITE** if array has too many elements (including channel as offset). + + +### Mode registers + - **uint8_t writeMode(uint8_t reg, uint8_t value)** configuration of one of the two configuration registers. check datasheet for details. - **uint8_t readMode(uint8_t reg)** reads back the configured mode, useful to add or remove a single flag (bit masking). +- **uint8_t setMode1(uint8_t value)** convenience wrapper. +- **uint8_t setMode2(uint8_t value)** convenience wrapper. +- **uint8_t getMode1()** convenience wrapper. +- **uint8_t getMode2()** convenience wrapper. + + +#### Constants for mode registers + +(added 0.1.2) + +| Name | Value | Description | +|:------------------------|:-----:|:--------------------------------| +| PCA9634_MODE1_AUTOINCR2 | 0x80 | RO, 0 = disable 1 = enable | +| PCA9634_MODE1_AUTOINCR1 | 0x40 | RO, bit1 | +| PCA9634_MODE1_AUTOINCR0 | 0x20 | RO bit0 | +| PCA9634_MODE1_SLEEP | 0x10 | 0 = normal 1 = sleep | +| PCA9634_MODE1_SUB1 | 0x08 | 0 = disable 1 = enable | +| PCA9634_MODE1_SUB2 | 0x04 | 0 = disable 1 = enable | +| PCA9634_MODE1_SUB3 | 0x02 | 0 = disable 1 = enable | +| PCA9634_MODE1_ALLCALL | 0x01 | 0 = disable 1 = enable | +| | | | +| PCA9634_MODE2_BLINK | 0x20 | 0 = dim 1 = blink | +| PCA9634_MODE2_INVERT | 0x10 | 0 = normal 1 = inverted | +| PCA9634_MODE2_STOP | 0x08 | 0 = on STOP 1 = on ACK | +| PCA9634_MODE2_TOTEMPOLE | 0x04 | 0 = open drain 1 = totem-pole | + + +These constants makes it easier to set modes without using a non descriptive +bitmask. The constants can be merged by OR-ing them together, see snippet: + +```cpp +ledArray.writeMode(PCA9634_MODE2, 0b00110100); + +// would become + +uint8_t mode2_mask = PCA9634_MODE2_BLINK | PCA9634_MODE2_INVERT | PCA9634_MODE2_TOTEMPOLE; +ledArray.writeMode(PCA9634_MODE2, mode2_mask); + +// or even + +ledArray.setMode2(PCA9634_MODE2_BLINK | PCA9634_MODE2_INVERT | PCA9634_MODE2_TOTEMPOLE); + +``` ### Group PWM and frequency @@ -86,7 +134,7 @@ useful to add or remove a single flag (bit masking). | PCA9634_ERR_CHAN | 0xFD | Channel out of range | PCA9634_ERR_MODE | 0xFC | Invalid mode | PCA9634_ERR_REG | 0xFB | Invalid register -| PCA9634_ERR_I2C | 0xFA | PCA9634 I2C communication error +| PCA9634_ERR_I2C | 0xFA | I2C communication error ## Operation diff --git a/libraries/PCA9634/examples/PCA9634_test01/PCA9634_test01.ino b/libraries/PCA9634/examples/PCA9634_test01/PCA9634_test01.ino index 9586c477..f4e53b40 100644 --- a/libraries/PCA9634/examples/PCA9634_test01/PCA9634_test01.ino +++ b/libraries/PCA9634/examples/PCA9634_test01/PCA9634_test01.ino @@ -2,7 +2,7 @@ // FILE: PCA9634_test01.ino // AUTHOR: Rob Tillaart // DATE: 2022-01-03 -// PUPROSE: test PCA9634 library +// PURPOSE: test PCA9634 library #include "Arduino.h" diff --git a/libraries/PCA9634/examples/PCA9634_test_multiple/PCA9634_test_multiple.ino b/libraries/PCA9634/examples/PCA9634_test_multiple/PCA9634_test_multiple.ino index fd2dd54e..4b3dd337 100644 --- a/libraries/PCA9634/examples/PCA9634_test_multiple/PCA9634_test_multiple.ino +++ b/libraries/PCA9634/examples/PCA9634_test_multiple/PCA9634_test_multiple.ino @@ -2,7 +2,7 @@ // FILE: PCA9634_test_multiple.ino // AUTHOR: Rob Tillaart // DATE: 2022-01-03 -// PUPROSE: test PCA9634 library +// PURPOSE: test PCA9634 library #include "Arduino.h" diff --git a/libraries/PCA9634/keywords.txt b/libraries/PCA9634/keywords.txt index 4bf1f534..1c7a171f 100644 --- a/libraries/PCA9634/keywords.txt +++ b/libraries/PCA9634/keywords.txt @@ -19,6 +19,10 @@ writeN KEYWORD2 writeMode KEYWORD2 readMode KEYWORD2 +setMode1 KEYWORD2 +setMode2 KEYWORD2 +getMode1 KEYWORD2 +getMode2 KEYWORD2 setGroupPWM KEYWORD2 getGroupPWM KEYWORD2 @@ -36,4 +40,18 @@ PCA9634_ERR_WRITE LITERAL1 PCA9634_ERR_CHAN LITERAL1 PCA9634_ERR_MODE LITERAL1 PCA9634_ERR_REG LITERAL1 -PCA9634_ERR_I2C LITERAL1 \ No newline at end of file +PCA9634_ERR_I2C LITERAL1 + +PCA9634_MODE1_AUTOINCR2 LITERAL1 +PCA9634_MODE1_AUTOINCR1 LITERAL1 +PCA9634_MODE1_AUTOINCR0 LITERAL1 +PCA9634_MODE1_SLEEP LITERAL1 +PCA9634_MODE1_SUB1 LITERAL1 +PCA9634_MODE1_SUB2 LITERAL1 +PCA9634_MODE1_SUB3 LITERAL1 +PCA9634_MODE1_ALLCALL LITERAL1 + +PCA9634_MODE2_BLINK LITERAL1 +PCA9634_MODE2_INVERT LITERAL1 +PCA9634_MODE2_STOP LITERAL1 +PCA9634_MODE2_TOTEMPOLE LITERAL1 diff --git a/libraries/PCA9634/library.json b/libraries/PCA9634/library.json index cc0dfebf..82771dc6 100644 --- a/libraries/PCA9634/library.json +++ b/libraries/PCA9634/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/PCA9634.git" }, - "version": "0.1.1", + "version": "0.1.2", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/libraries/PCA9634/library.properties b/libraries/PCA9634/library.properties index ae1f7d58..3c90020d 100644 --- a/libraries/PCA9634/library.properties +++ b/libraries/PCA9634/library.properties @@ -1,5 +1,5 @@ name=PCA9634 -version=0.1.1 +version=0.1.2 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for PCA9634 I2C LED driver 8 channel