From 514d1036efd176e5f313c19e6a937f08bf223ab6 Mon Sep 17 00:00:00 2001 From: rob tillaart Date: Thu, 23 Dec 2021 10:41:42 +0100 Subject: [PATCH] 0.3.2 PCA9635 --- libraries/PCA9635/.arduino-ci.yml | 10 +- .../.github/workflows/arduino_test_runner.yml | 10 +- libraries/PCA9635/LICENSE | 2 +- libraries/PCA9635/PCA9635.cpp | 10 +- libraries/PCA9635/PCA9635.h | 5 +- libraries/PCA9635/README.md | 104 ++++++++++-------- .../PCA9635_test01/PCA9635_test01.ino | 16 ++- .../PCA9635_test_multiple.ino | 7 +- libraries/PCA9635/keywords.txt | 5 +- libraries/PCA9635/library.json | 5 +- libraries/PCA9635/library.properties | 2 +- libraries/PCA9635/test/unit_test_001.cpp | 29 ++++- 12 files changed, 136 insertions(+), 69 deletions(-) diff --git a/libraries/PCA9635/.arduino-ci.yml b/libraries/PCA9635/.arduino-ci.yml index ff5659b9..e7cb4633 100644 --- a/libraries/PCA9635/.arduino-ci.yml +++ b/libraries/PCA9635/.arduino-ci.yml @@ -2,6 +2,10 @@ compile: # Choosing to run compilation tests on 2 different Arduino platforms platforms: - uno - - leonardo - - due - - zero + # - due + # - zero + # - leonardo + - m4 + - esp32 + # - esp8266 + # - mega2560 \ No newline at end of file diff --git a/libraries/PCA9635/.github/workflows/arduino_test_runner.yml b/libraries/PCA9635/.github/workflows/arduino_test_runner.yml index 476456bb..096b975b 100644 --- a/libraries/PCA9635/.github/workflows/arduino_test_runner.yml +++ b/libraries/PCA9635/.github/workflows/arduino_test_runner.yml @@ -4,10 +4,14 @@ name: Arduino CI on: [push, pull_request] jobs: - arduino_ci: + runTest: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: Arduino-CI/action@master - # Arduino-CI/action@v0.1.1 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + - run: | + gem install arduino_ci + arduino_ci.rb diff --git a/libraries/PCA9635/LICENSE b/libraries/PCA9635/LICENSE index 46c49382..ce6d6f88 100644 --- a/libraries/PCA9635/LICENSE +++ b/libraries/PCA9635/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2016-2021 Rob Tillaart +Copyright (c) 2016-2022 Rob Tillaart Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/libraries/PCA9635/PCA9635.cpp b/libraries/PCA9635/PCA9635.cpp index b20a1d47..3732f353 100644 --- a/libraries/PCA9635/PCA9635.cpp +++ b/libraries/PCA9635/PCA9635.cpp @@ -2,15 +2,17 @@ // FILE: PCA9635.cpp // AUTHOR: Rob Tillaart // DATE: 23-apr-2016 -// VERSION: 0.3.1 +// VERSION: 0.3.2 // PURPOSE: Arduino library for PCA9635 I2C LED driver // URL: https://github.com/RobTillaart/PCA9635 // // HISTORY: +// 0.3.2 2021-12-23 update library.json, readme, license, minor edits // 0.3.1 2021-04-25 fix writeN by aspyra // 0.3.0 2021-01-18 support Wire1..WireN +// // 0.2.2 2021-01-13 refactor + fix register index error. -// 0.2.1 2021-01-05 arduino-CI + unit test +// 0.2.1 2021-01-05 Arduino-CI + unit test // 0.2.0 2020-05-26 major refactor; ESP32 support // 0.1.2 2020-05-07 fix for PCA9635_MODE1 // 0.1.1 2016-04-24 set autoincr in constructor @@ -149,7 +151,7 @@ uint8_t PCA9635::setLedDriverMode(uint8_t channel, uint8_t mode) _error = PCA9635_ERR_CHAN; return PCA9635_ERROR; } - if (mode > 3) + if (mode > 3) { _error = PCA9635_ERR_MODE; return PCA9635_ERROR; @@ -222,4 +224,6 @@ uint8_t PCA9635::readReg(uint8_t reg) return _data; } + // -- END OF FILE -- + diff --git a/libraries/PCA9635/PCA9635.h b/libraries/PCA9635/PCA9635.h index d0867e87..71b755ba 100644 --- a/libraries/PCA9635/PCA9635.h +++ b/libraries/PCA9635/PCA9635.h @@ -3,17 +3,16 @@ // FILE: PCA9635.H // AUTHOR: Rob Tillaart // DATE: 23-apr-2016 -// VERSION: 0.3.1 +// VERSION: 0.3.2 // PURPOSE: Arduino library for PCA9635 I2C LED driver // URL: https://github.com/RobTillaart/PCA9635 -// #include "Arduino.h" #include "Wire.h" -#define PCA9635_LIB_VERSION (F("0.3.1")) +#define PCA9635_LIB_VERSION (F("0.3.2")) #define PCA9635_MODE1 0x00 #define PCA9635_MODE2 0x01 diff --git a/libraries/PCA9635/README.md b/libraries/PCA9635/README.md index 56e1eab4..8c595fa3 100644 --- a/libraries/PCA9635/README.md +++ b/libraries/PCA9635/README.md @@ -1,84 +1,100 @@ [![Arduino CI](https://github.com/RobTillaart/PCA9635/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) +[![Arduino-lint](https://github.com/RobTillaart/PCA9635/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/PCA9635/actions/workflows/arduino-lint.yml) +[![JSON check](https://github.com/RobTillaart/PCA9635/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/PCA9635/actions/workflows/jsoncheck.yml) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/PCA9635/blob/master/LICENSE) [![GitHub release](https://img.shields.io/github/release/RobTillaart/PCA9635.svg?maxAge=3600)](https://github.com/RobTillaart/PCA9635/releases) # PCA9635 -Arduino library for PCA9635 I2C 8 bit PWM LED driver +Arduino library for PCA9635 I2C 8 bit PWM LED driver. -# Description +## Description This library is to control the I2C PCA9635 PWM extender. The 16 channels are independently configurable is steps of 1/256. -this allows for better than 1% finetuning of the duty-cycle +this allows for better than 1% fine tuning of the duty-cycle of the PWM signal. ## Interface + ### Constructor -- **PCA9635(deviceAddress, TwoWire \*wire = &Wire)** Constructor with I2C device address, and optional the Wire interface as parameter. -- **begin()** initializes the library after startup. Mandatory. -- **begin(sda, scl)** idem, ESP32 ESP8266 only. Library does not support +- **PCA9635(uint8_t deviceAddress, TwoWire \*wire = &Wire)** Constructor with I2C device address, +and optional the Wire interface as parameter. +- **bool begin()** initializes the library after startup. Mandatory. +- **bool begin(uint8_t sda, uint8_t scl)** idem, ESP32 ESP8266 only. Library does not support multiple Wire instances (yet). -- **reset()** resets the library to start up conditions. -- **isConnected()** checks if address is available on I2C bus. +- **void reset()** resets the library to start up conditions. +- **bool isConnected()** checks if address is available on I2C bus. ### LedDriverMode -- **setLedDriverMode(channel, mode)** mode is 0..3 See datasheet for full details. -- **getLedDriverMode(channel)** returns the current mode of the channel. +- **uint8_t setLedDriverMode(uint8_t channel, uint8_t mode)** mode is 0..3 See datasheet for full details. +- **uint8_t getLedDriverMode(uint8_t channel)** returns the current mode of the channel. -| LED mode | Value | Description | -|:----|:----:|:----| -| PCA9635_LEDOFF | 0x00 | led is 100% off, default @startup -| PCA9635_LEDON | 0x01 | led is 100% on. -| PCA9635_LEDPWM | 0x02 | set LED in PWM mode, 0..255 -| PCA9635_LEDGRPPWM | 0x03 | add LED to the GRPPWM* +| LED mode | Value | Description | +|:-------------------|:-----:|:------------| +| PCA9635_LEDOFF | 0x00 | led is 100% off, default @startup +| PCA9635_LEDON | 0x01 | led is 100% on. +| PCA9635_LEDPWM | 0x02 | set LED in PWM mode, 0..255 +| PCA9635_LEDGRPPWM | 0x03 | add LED to the GRPPWM* -\* all leds in the group GRPPWM can be set to the same PWM value in one set. -This is ideal to trigger e.g. multiple LEDS (servo's) at same time. +\* all LEDs in the group GRPPWM can be set to the same PWM value in one set. +This is ideal to trigger e.g. multiple LEDs (servo's) at same time. ### Read and write -- **write1(channel, value)** writes a single 8 bit PWM value. -- **write3(channel, R, G, B)** writes three consecutive PWM registers. -- **writeN(channel, array, count)** write count consecutive PWM registers. +- **uint8_t write1(uint8_t channel, uint8_t value)** writes a single 8 bit PWM value. +- **uint8_t write3(uint8_t channel, uint8_t R, uint8_t G, uint8_t B)** writes three consecutive PWM registers. +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 **PCA9635_ERR_WRITE** if array has too many elements -(including channel as offset) -- **writeMode(reg, mode)** configuration of one of the two configuration registers. +(including channel as offset). +- **uint8_t writeMode(uint8_t reg, uint8_t value)** configuration of one of the two configuration registers. check datasheet for details. -- **readMode(reg)** reads back the configured mode, useful to add or remove a -single flag (bit masking) +- **uint8_t readMode(uint8_t reg)** reads back the configured mode, +useful to add or remove a single flag (bit masking). + ### Group PWM and frequency -- **setGroupPWM(uint8_t value)** sets all channels that are part of the PWM group to value. -- **getGroupPWM()** get the current PWM setting of the group. -- **setGroupFREQ(value)** see datasheet for details. -- **getGroupFREQ()** returns the freq of the PWM group. - -### Misc - -- **lastError()** returns **PCA9635_OK** if all is OK, and other error codes otherwise. - -| Error code | Value | Description | -|:----|:----:|:----| -| PCA9635_OK | 0x00 | Everything went well -| PCA9635_ERROR | 0xFF | Generic error -| PCA9635_ERR_WRITE | 0xFE | Tries to write more elements than PWM channels -| PCA9635_ERR_CHAN | 0xFD | Channel out of range -| PCA9635_ERR_MODE | 0xFC | Invalid mode -| PCA9635_ERR_REG | 0xFB | Invalid register -| PCA9635_ERR_I2C | 0xFA | PCA9635 I2C communication error +- **void setGroupPWM(uint8_t value)** sets all channels that are part of the PWM group to value. +- **uint8_t getGroupPWM()** get the current PWM setting of the group. +- **void setGroupFREQ(value)** see datasheet for details. +- **uint8_t getGroupFREQ()** returns the freq of the PWM group. -# Operation +### Miscellaneous + +- **int lastError()** returns **PCA9635_OK** if all is OK, and other error codes otherwise. + +| Error code | Value | Description | +|:------------------|:-----:|:------------| +| PCA9635_OK | 0x00 | Everything went well +| PCA9635_ERROR | 0xFF | Generic error +| PCA9635_ERR_WRITE | 0xFE | Tries to write more elements than PWM channels +| PCA9635_ERR_CHAN | 0xFD | Channel out of range +| PCA9635_ERR_MODE | 0xFC | Invalid mode +| PCA9635_ERR_REG | 0xFB | Invalid register +| PCA9635_ERR_I2C | 0xFA | PCA9635 I2C communication error + + +## Operation See examples + + +## Future + +- improve documentation +- unit tests +- add examples + + diff --git a/libraries/PCA9635/examples/PCA9635_test01/PCA9635_test01.ino b/libraries/PCA9635/examples/PCA9635_test01/PCA9635_test01.ino index 1dfd154f..567dcc1b 100644 --- a/libraries/PCA9635/examples/PCA9635_test01/PCA9635_test01.ino +++ b/libraries/PCA9635/examples/PCA9635_test01/PCA9635_test01.ino @@ -2,15 +2,15 @@ // FILE: PCA9635_test01.ino // AUTHOR: Rob Tillaart // DATE: 23-APR-2016 -// VERSION: 0.2.0 // PUPROSE: test PCA9635 library -// + #include "PCA9635.h" #include PCA9635 ledArray(0x20); + void setup() { Serial.begin(115200); @@ -34,6 +34,7 @@ void setup() Serial.println("done..."); } + void testSetLedDriverModeLEDON() { Serial.print(millis()); @@ -52,6 +53,7 @@ void testSetLedDriverModeLEDON() } } + void testPWMMode() { Serial.print(millis()); @@ -72,6 +74,7 @@ void testPWMMode() } } + void testWrite1() { Serial.print(millis()); @@ -97,6 +100,7 @@ void testWrite1() } } + void testWrite3() { Serial.print(millis()); @@ -111,6 +115,7 @@ void testWrite3() } } + void testWriteN() { Serial.print(millis()); @@ -120,6 +125,7 @@ void testWriteN() ledArray.writeN(0, arr, 16); } + void testSetGroupPWM_FREQ() { Serial.print(millis()); @@ -166,6 +172,7 @@ void testSetGroupPWM_FREQ() } } + void testSetAndReadMode() { Serial.print(millis()); @@ -185,6 +192,7 @@ void testSetAndReadMode() Serial.println(regval); } + void testSetLedDriverModeLEDOFF() { Serial.print(millis()); @@ -203,9 +211,11 @@ void testSetLedDriverModeLEDOFF() } } + void loop() { - } + // -- END OF FILE -- + diff --git a/libraries/PCA9635/examples/PCA9635_test_multiple/PCA9635_test_multiple.ino b/libraries/PCA9635/examples/PCA9635_test_multiple/PCA9635_test_multiple.ino index 981371e3..f7ff0059 100644 --- a/libraries/PCA9635/examples/PCA9635_test_multiple/PCA9635_test_multiple.ino +++ b/libraries/PCA9635/examples/PCA9635_test_multiple/PCA9635_test_multiple.ino @@ -2,9 +2,7 @@ // FILE: PCA9635_test_multiple.ino // AUTHOR: Rob Tillaart // DATE: 2018-02-18 -// VERSION: 0.2.1 // PUPROSE: test PCA9635 library -// #include "PCA9635.h" @@ -14,6 +12,7 @@ PCA9635 ledArray(0x20); PCA9635 ledArray2(0x21); + void setup() { Serial.begin(115200); @@ -50,9 +49,11 @@ void setup() Serial.println("done..."); } + void loop() { - } + // -- END OF FILE -- + diff --git a/libraries/PCA9635/keywords.txt b/libraries/PCA9635/keywords.txt index a07d2dbb..96906593 100644 --- a/libraries/PCA9635/keywords.txt +++ b/libraries/PCA9635/keywords.txt @@ -1,13 +1,14 @@ -# Syntax Coloring Map for PCA9635 +# Syntax Colouring Map for PCA9635 -# Datatypes (KEYWORD1) +# Data types (KEYWORD1) PCA9635 KEYWORD1 # Methods and Functions (KEYWORD2) begin KEYWORD2 reset KEYWORD2 + isConnected KEYWORD2 setLedDriverMode KEYWORD2 getLedDriverMode KEYWORD2 diff --git a/libraries/PCA9635/library.json b/libraries/PCA9635/library.json index 2b6bf607..9abeb9b7 100644 --- a/libraries/PCA9635/library.json +++ b/libraries/PCA9635/library.json @@ -15,8 +15,9 @@ "type": "git", "url": "https://github.com/RobTillaart/PCA9635.git" }, - "version":"0.3.1", + "version": "0.3.2", "license": "MIT", "frameworks": "arduino", - "platforms": "*" + "platforms": "*", + "headers": "PCA9635.h" } diff --git a/libraries/PCA9635/library.properties b/libraries/PCA9635/library.properties index c930aaf6..bd4deba9 100644 --- a/libraries/PCA9635/library.properties +++ b/libraries/PCA9635/library.properties @@ -1,5 +1,5 @@ name=PCA9635 -version=0.3.1 +version=0.3.2 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for PCA9635 I2C LED driver diff --git a/libraries/PCA9635/test/unit_test_001.cpp b/libraries/PCA9635/test/unit_test_001.cpp index 009ddbb8..e12a48ff 100644 --- a/libraries/PCA9635/test/unit_test_001.cpp +++ b/libraries/PCA9635/test/unit_test_001.cpp @@ -37,17 +37,44 @@ unittest_setup() { + fprintf(stderr, "PCA9635_LIB_VERSION: %s\n", (char *) PCA9635_LIB_VERSION); } + unittest_teardown() { } +unittest(test_constants) +{ + assertEqual(PCA9635_MODE1 , 0x00); + assertEqual(PCA9635_MODE2 , 0x01); + + assertEqual(PCA9635_GRPPWM , 0x12); + assertEqual(PCA9635_GRPFREQ , 0x13); + assertEqual(PCA9635_LEDOUT_BASE, 0x14); + + assertEqual(PCA9635_LEDOFF , 0x00); + assertEqual(PCA9635_LEDON , 0x01); + assertEqual(PCA9635_LEDPWM , 0x02); + assertEqual(PCA9635_LEDGRPPWM , 0x03); + + fprintf(stderr, "\nerrorcodes"); + assertEqual(PCA9635_OK , 0x00); + assertEqual(PCA9635_ERROR , 0xFF); + assertEqual(PCA9635_ERR_WRITE , 0xFE); + assertEqual(PCA9635_ERR_CHAN , 0xFD); + assertEqual(PCA9635_ERR_MODE , 0xFC); + assertEqual(PCA9635_ERR_REG , 0xFB); + assertEqual(PCA9635_ERR_I2C , 0xFA); +} + + unittest(test_constructor) { fprintf(stderr, "VERSION: %s\n", PCA9635_LIB_VERSION); - + PCA9635 ledArray(0x20); assertTrue(ledArray.begin()); assertTrue(ledArray.isConnected());