diff --git a/libraries/TLC5917/.arduino-ci.yml b/libraries/TLC5917/.arduino-ci.yml new file mode 100644 index 00000000..10c0e10b --- /dev/null +++ b/libraries/TLC5917/.arduino-ci.yml @@ -0,0 +1,28 @@ +platforms: + rpipico: + board: rp2040:rp2040:rpipico + package: rp2040:rp2040 + gcc: + features: + defines: + - ARDUINO_ARCH_RP2040 + warnings: + flags: + +packages: + rp2040:rp2040: + url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json + +compile: + # Choosing to run compilation tests on 2 different Arduino platforms + platforms: + - uno + # - due + # - zero + # - leonardo + - m4 + - esp32 + # - esp8266 + # - mega2560 + - rpipico + diff --git a/libraries/TLC5917/.github/FUNDING.yml b/libraries/TLC5917/.github/FUNDING.yml new file mode 100644 index 00000000..554358c3 --- /dev/null +++ b/libraries/TLC5917/.github/FUNDING.yml @@ -0,0 +1,4 @@ +# These are supported funding model platforms + +github: RobTillaart +custom: "https://www.paypal.me/robtillaart" diff --git a/libraries/TLC5917/.github/workflows/arduino-lint.yml b/libraries/TLC5917/.github/workflows/arduino-lint.yml new file mode 100644 index 00000000..982a5df2 --- /dev/null +++ b/libraries/TLC5917/.github/workflows/arduino-lint.yml @@ -0,0 +1,16 @@ + +name: Arduino-lint + +on: [push, pull_request] +jobs: + lint: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v4 + - uses: arduino/arduino-lint-action@v1 + with: + library-manager: update + compliance: strict + verbose: false + diff --git a/libraries/TLC5917/.github/workflows/arduino_test_runner.yml b/libraries/TLC5917/.github/workflows/arduino_test_runner.yml new file mode 100644 index 00000000..393c2257 --- /dev/null +++ b/libraries/TLC5917/.github/workflows/arduino_test_runner.yml @@ -0,0 +1,19 @@ +--- +name: Arduino CI + +on: [push, pull_request] + +jobs: + runTest: + runs-on: ubuntu-latest + timeout-minutes: 20 + + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + - run: | + sudo sysctl vm.mmap_rnd_bits=28 + gem install arduino_ci + arduino_ci.rb diff --git a/libraries/TLC5917/.github/workflows/jsoncheck.yml b/libraries/TLC5917/.github/workflows/jsoncheck.yml new file mode 100644 index 00000000..fd05f5f8 --- /dev/null +++ b/libraries/TLC5917/.github/workflows/jsoncheck.yml @@ -0,0 +1,19 @@ +name: JSON check + +on: + push: + paths: + - '**.json' + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v4 + - name: json-syntax-check + uses: limitusus/json-syntax-check@v2 + with: + pattern: "\\.json$" + diff --git a/libraries/TLC5917/CHANGELOG.md b/libraries/TLC5917/CHANGELOG.md new file mode 100644 index 00000000..32f9d7c0 --- /dev/null +++ b/libraries/TLC5917/CHANGELOG.md @@ -0,0 +1,12 @@ +# Change Log TLC5917 + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/) +and this project adheres to [Semantic Versioning](http://semver.org/). + + +## [0.1.0] - 2024-03-17 +- initial version + + diff --git a/libraries/TLC5917/LICENSE b/libraries/TLC5917/LICENSE new file mode 100644 index 00000000..37fe70e5 --- /dev/null +++ b/libraries/TLC5917/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024-2024 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 +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/libraries/TLC5917/README.md b/libraries/TLC5917/README.md new file mode 100644 index 00000000..962497c8 --- /dev/null +++ b/libraries/TLC5917/README.md @@ -0,0 +1,182 @@ + +[![Arduino CI](https://github.com/RobTillaart/TLC5917/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) +[![Arduino-lint](https://github.com/RobTillaart/TLC5917/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/TLC5917/actions/workflows/arduino-lint.yml) +[![JSON check](https://github.com/RobTillaart/TLC5917/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/TLC5917/actions/workflows/jsoncheck.yml) +[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/TLC5917.svg)](https://github.com/RobTillaart/TLC5917/issues) + +[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/TLC5917/blob/master/LICENSE) +[![GitHub release](https://img.shields.io/github/release/RobTillaart/TLC5917.svg?maxAge=3600)](https://github.com/RobTillaart/TLC5917/releases) +[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/TLC5917.svg)](https://registry.platformio.org/libraries/robtillaart/TLC5917) + + +# TLC5917 + +TLC5917 is an Arduino library for TLC5917 8-Channel Constant-Current LED Sink Drivers. + + +## Description + +**Experimental** + +This library allows control over the 8 channels of a TLC5917 device. + + +TODO: Elaborate. + +The TLC5916 is a derived class that is functional identical to the TLC5917 (for now). +When implementation proceeds this might change. + +The library is **experimental** and needs testing with Hardware. +Please share your experiences. + + +(Changes of the interface are definitely possible). + + +#### Daisy chaining + +This library supports daisy chaining. +A constructor takes the number of devices as parameter and +an internal buffer is allocated (8 elements per device). +This internal buffer is clocked into the devices with **write()**. + + +#### Related + +- https://www.adafruit.com/product/1429 +- https://github.com/RobTillaart/TLC5917 +- https://github.com/RobTillaart/TLC5947 +- https://github.com/RobTillaart/PCA9634 (I2C) +- https://github.com/RobTillaart/PCA9635 (I2C) +- https://github.com/RobTillaart/PCA9685 (I2C) + + +## Interface + +```cpp +#include TLC5917.h +``` + +#### Constructor + +- **TLC5917(uint8_t clock, uint8_t data, uint8_t latch, uint8_t blank)** constructor. +Single device constructor. +Defines the pins used for uploading / writing the PWM data to the module. +The blank pin is explained in more detail below. +- **TLC5917(int deviceCount, uint8_t clock, uint8_t data, uint8_t latch, uint8_t blank)** constructor. +To be used for multiple devices, typical 2 or more. +Defines the pins used for uploading / writing the PWM data to the module. +The blank pin is explained in more detail below. +- **~TLC5917()** destructor + +#### Base + +- **bool begin()** set the pinModes of the pins and their initial values. +The TLC is disabled by default, as the device has random values in its grey-scale register. +One must call **enable()** explicitly. +- **int getChannels()** return the amount of channels == 8 x number of devices. +- **bool setChannel(uint8_t channel, bool on)** set a channel on or off in the buffer. +- **bool setChannel(uint8_t \* array)** copy a preset of channel settings in one call. +- **bool setAll(bool on)** set all channels on or off. +- **bool getChannel(uint8_t channel)** get current state of a channel in the cached buffer. +- **void write()** writes the whole buffer (deviceCount x 8 values) to the device(s). +- **void write(int n)** writes a part of the buffer (only **n** values) to the device. +Typical used to speed up if less than max number e.g. only 17 channels are used +and needs to be updated. +**experimental, might have side effects** + + +**write()** must be called after setting all values one wants to change. +Doing that per channel is far less efficient if one wants to update multiple +channels as fast as possible. +See also **TLC5917_performance.ino** for an indication of time. + + +#### Blank line TODO CHECK + +The blank pin (OE line) is used to set all channels on or off. +This allows to "preload" the registers with values and enable them all at once +with very precise timing. + +Default a TLC device is disabled (by begin), so one should enable it "manually". +(P13 datasheet) + +- **void enable()** all channels reflect last PWM values written. +- **void disable()** all channels are off / 0. +- **bool isEnabled()** returns status of blank line. + +The library only supports one **enable() / blank line**. If you want +a separate **enable()** per device you might need to connect the devices +"in parallel" instead of "in series" (daisy chained). +The blank parameter in the constructor should be set to -1 (out of range value). + + +#### Configure gain + +See datasheet page 23 for details. + +- **void setCurrentAdjustMode()** +- **void setNormalMode()** +- **void writeConfiguration(uint8_t config)** See page 23 datasheet + +| bit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +|:---------:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:| +| meaning | CM | HC | CC0 | CC1 | CC2 | CC3 | CC4 | CC5 | +| default | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | + +CM limits the output current range. +- High Current Multiplier (CM = 1): 10 mA to 120 mA. +- Low Current Multiplier (CM = 0): 3 mA to 40 mA. + +VG (voltage gain) = (1 + HC) × (1 + D/64) / 4 +where D = CC0 × 32 + CC1 × 16 + CC2 × 8 + CC3 × 4 + CC4 × 2 + CC5 + +CG (current gain) = VG x pow(3, CM - 1) + +``` +Default +CG = VG x 3; +VG = 2 x ( 1 + 63/64) / 4 = 127/128 +``` + +TODO test with hardware to understand this in detail. +Actual current depends on Rext (see datasheet). + + +## Performance + +See **TLC5917_performance.ino** for an indicative test. + + +## Future + +#### Must + +- update documentation +- buy hardware + - test test test +- get basic functionality running + +#### Should + +- get basic functionality running +- investigate daisy chaining. (hardware needed). + - max CLOCK speed when chained (50% DutyCycle) + - what is clock in practice (e.g. an ESP32 240 MHz) + +#### Could + +- add examples + +#### Wont + + +## Support + +If you appreciate my libraries, you can support the development and maintenance. +Improve the quality of the libraries by providing issues and Pull Requests, or +donate through PayPal or GitHub sponsors. + +Thank you, + + diff --git a/libraries/TLC5917/TLC5917.cpp b/libraries/TLC5917/TLC5917.cpp new file mode 100644 index 00000000..ae6a79e6 --- /dev/null +++ b/libraries/TLC5917/TLC5917.cpp @@ -0,0 +1,294 @@ +// +// FILE: TLC5917.cpp +// AUTHOR: Rob Tillaart +// VERSION: 0.1.0 +// DATE: 2024-03-17 +// PURPOSE: Arduino library for TLC5917 8-Channel Constant-Current LED Sink Drivers. +// URL: https://github.com/RobTillaart/TLC5917 + + +#include "TLC5917.h" + + +TLC5917::TLC5917(uint8_t clock, uint8_t data, uint8_t LE, uint8_t OE) +{ + TLC5917(1, clock, data, LE, OE); +} + + +TLC5917::TLC5917(int deviceCount, uint8_t clock, uint8_t data, uint8_t LE, uint8_t OE) +{ + if (deviceCount <= 0) deviceCount = 1; + _channels = deviceCount * 8; + _clock = clock; + _data = data; + _le = LE; + _oe = OE; + _buffer = (uint8_t *) calloc(_channels, sizeof(uint8_t)); +} + + +TLC5917::~TLC5917() +{ + if (_buffer) free(_buffer); +} + + +bool TLC5917::begin() +{ + pinMode(_clock, OUTPUT); + pinMode(_data, OUTPUT); + pinMode(_le, OUTPUT); + pinMode(_oe, OUTPUT); + digitalWrite(_clock, LOW); + digitalWrite(_data, LOW); + digitalWrite(_le, LOW); + // disable by default, safest option. + disable(); + return true; +} + + +int TLC5917::getChannels() +{ + return _channels; +} + + +bool TLC5917::setChannel(uint8_t channel, bool on) +{ + if (channel >= _channels) return false; + if (on) _buffer[channel / 8] |= (1 << channel & 0x07); + else _buffer[channel / 8] &= ~(1 << channel & 0x07); + return true; +} + + +bool TLC5917::setChannel(uint8_t * array) +{ + for (int i = 0; i < _channels / 8; i++) + { + _buffer[i] = array[i]; + } + return true; +} + + +bool TLC5917::setAll(bool on) +{ + uint8_t mask = on ? 0xFF : 0x00; + for (int i = 0; i < _channels / 8; i++) + { + _buffer[i] = mask; + } + return true; +} + + +bool TLC5917::getChannel(uint8_t channel) +{ + if (channel >= _channels) return false; + return (_buffer[channel / 8] & (1 << (channel & 0x07))) > 0; +} + + +////////////////////////////////////////////////// +// +// WRITE +// +// MAX speed single device 30 MHz +// multi device 15 MHz CHECK TODO +void TLC5917::write() +{ + write(_channels); +} + + +void TLC5917::write(int chan) +{ + if (chan > _channels) chan = _channels; + if (chan < 0) return; + +#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) + + // register level optimized AVR + uint8_t port = digitalPinToPort(_data); + volatile uint8_t *_dataOutRegister = portOutputRegister(port); + uint8_t outmask1 = digitalPinToBitMask(_data); + uint8_t outmask2 = ~outmask1; + + port = digitalPinToPort(_clock); + volatile uint8_t *_clockRegister = portOutputRegister(port); + uint8_t cbmask1 = digitalPinToBitMask(_clock); + uint8_t cbmask2 = ~cbmask1; + + for (int channel = chan - 1; channel >= 0; channel--) + { + for (uint8_t mask = 0x80; mask; mask >>= 1) + { + *_clockRegister &= cbmask2; + if (_buffer[channel] & mask) + { + *_dataOutRegister |= outmask1; + } + else + { + *_dataOutRegister &= outmask2; + } + *_clockRegister |= cbmask1; + } + } + *_clockRegister &= cbmask2; + +#else + + // also write when blank == LOW + // to "preload the registers" + // local variables to maximize speed. + uint8_t _clk = _clock; + uint8_t _dat = _data; + + for (int channel = chan - 1; channel >= 0; channel--) + { + for (uint8_t mask = 0x80; mask; mask >>= 1) + { + digitalWrite(_clk, LOW); + digitalWrite(_dat, _buffer[channel] & mask ? HIGH : LOW); + digitalWrite(_clk, HIGH); + } + } + digitalWrite(_clk, LOW); + +#endif + + // pulse latch to hold the signals + digitalWrite(_le, HIGH); + digitalWrite(_le, LOW); +} + + +////////////////////////////////////////////////// +// +// ENABLE +// +void TLC5917::enable() +{ + digitalWrite(_oe, LOW); +} + + +void TLC5917::disable() +{ + digitalWrite(_oe, HIGH); +} + + +bool TLC5917::isEnabled() +{ + return (digitalRead(_oe) == LOW); +} + + +////////////////////////////////////////////////// +// +// CONFIGURATION +// +// NOT OPTIMIZED +// +// Page 19 +void TLC5917::setCurrentAdjustMode() +{ + digitalWrite(_le, LOW); + digitalWrite(_oe, HIGH); + + digitalWrite(_clock, HIGH); + digitalWrite(_clock, LOW); + + digitalWrite(_oe, LOW); + digitalWrite(_clock, HIGH); + digitalWrite(_clock, LOW); + + digitalWrite(_oe, HIGH); + digitalWrite(_clock, HIGH); + digitalWrite(_clock, LOW); + + digitalWrite(_le, HIGH); + digitalWrite(_clock, HIGH); + digitalWrite(_clock, LOW); + + digitalWrite(_le, LOW); + digitalWrite(_clock, HIGH); + digitalWrite(_clock, LOW); +} + + +// Page 19 +void TLC5917::setNormalMode() +{ + digitalWrite(_le, LOW); + digitalWrite(_oe, HIGH); + digitalWrite(_clock, HIGH); + digitalWrite(_clock, LOW); + + digitalWrite(_oe, LOW); + digitalWrite(_clock, HIGH); + digitalWrite(_clock, LOW); + + digitalWrite(_oe, HIGH); + digitalWrite(_clock, HIGH); + digitalWrite(_clock, LOW); + + digitalWrite(_clock, HIGH); + digitalWrite(_clock, LOW); + + digitalWrite(_clock, HIGH); + digitalWrite(_clock, LOW); +} + + +void TLC5917::writeConfiguration(uint8_t config) +{ + uint8_t _clk = _clock; + uint8_t _dat = _data; + uint8_t _devices = _channels/8; + + // write same config to all devices + for (int i = 0; i < _devices; i++) + { + for (uint8_t mask = 0x80; mask; mask >>= 1) + { + digitalWrite(_clk, LOW); + digitalWrite(_dat, config & mask ? HIGH : LOW); + digitalWrite(_clk, HIGH); + } + digitalWrite(_clk, LOW); + } + + // pulse latch to hold the signals in configuration register. + // not exactly like Page 18 figure 13. + digitalWrite(_le, HIGH); + digitalWrite(_le, LOW); +} + + + +///////////////////////////////////////////////////////////// +// +// DERIVED CLASS +// +TLC5916::TLC5916(uint8_t clock, uint8_t data, uint8_t LE, uint8_t OE) + :TLC5917(clock, data, LE, OE) +{ + // optional code, later. + // type field? +} + + +TLC5916::TLC5916(int deviceCount, uint8_t clock, uint8_t data, uint8_t LE, uint8_t OE) + :TLC5917(deviceCount, clock, data, LE, OE) +{ +} + + +// -- END OF FILE -- + diff --git a/libraries/TLC5917/TLC5917.h b/libraries/TLC5917/TLC5917.h new file mode 100644 index 00000000..7190dfb3 --- /dev/null +++ b/libraries/TLC5917/TLC5917.h @@ -0,0 +1,81 @@ +#pragma once +// +// FILE: TLC5917.h +// AUTHOR: Rob Tillaart +// VERSION: 0.1.0 +// DATE: 2024-03-17 +// PURPOSE: Arduino library for TLC5917 8-Channel Constant-Current LED Sink Drivers. +// URL: https://github.com/RobTillaart/TLC5917 + + +#define TLC5917_LIB_VERSION (F("0.1.0")) + + +#include "Arduino.h" + + +#define TLC5917_OK 0x0000 +#define TLC5917_CHANNEL_ERROR 0xFFFF + + +class TLC5917 +{ +public: + // single device constructor + TLC5917(uint8_t clock, uint8_t data, uint8_t LE, uint8_t OE); + // multi device constructor - for daisy chaining) + TLC5917(int deviceCount, uint8_t clock, uint8_t data, uint8_t LE, uint8_t OE); + virtual ~TLC5917(); + + bool begin(); + int getChannels(); + + bool setChannel(uint8_t channel, bool on); + bool setChannel(uint8_t * array); // size must be deviceCount. + bool setAll(bool on); + bool getChannel(uint8_t channel); + + // write the buffer to the TLC5917 device(s). + void write(int n); + void write(); + + // control the blank (OE) line. + void enable(); + void disable(); + bool isEnabled(); // returns status + + // configuration mode + // TODO test if this works for single device. + // TODO test if this works for cascaded devices. + void setCurrentAdjustMode(); + void setNormalMode(); + void writeConfiguration(uint8_t config); + + +protected: + int _channels; + uint8_t * _buffer; + uint8_t _clock; + uint8_t _data; + uint8_t _le; // latch enable + uint8_t _oe; // output enable +}; + + +///////////////////////////////////////////////////////////// +// +// DERIVED CLASS +// +class TLC5916 : public TLC5917 +{ +public: + // single device constructor + TLC5916(uint8_t clock, uint8_t data, uint8_t LE, uint8_t OE); + // multi device constructor - for daisy chaining) + TLC5916(int deviceCount, uint8_t clock, uint8_t data, uint8_t LE, uint8_t OE); + virtual ~TLC5916() {}; +}; + + +// -- END OF FILE -- + diff --git a/libraries/TLC5917/examples/TLC5917_NightRider/TLC5917_NightRider.ino b/libraries/TLC5917/examples/TLC5917_NightRider/TLC5917_NightRider.ino new file mode 100644 index 00000000..681fac93 --- /dev/null +++ b/libraries/TLC5917/examples/TLC5917_NightRider/TLC5917_NightRider.ino @@ -0,0 +1,58 @@ +// +// FILE: TLC5917_NightRider.ino +// AUTHOR: Rob Tillaart +// PURPOSE: demo +// URL: https://github.com/RobTillaart/TLC5917 + + +#include "TLC5917.h" + +int DEVICES = 1; +const int CLOCK = 13; +const int DATA = 12; +const int LATCH = 11; +const int BLANK = 10; + +TLC5917 tlc(DEVICES, CLOCK, DATA, LATCH, BLANK); + + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.print("TLC5917_LIB_VERSION: \t"); + Serial.println(TLC5917_LIB_VERSION); + + tlc.begin(); + tlc.enable(); +} + + +void loop() +{ + static int pos = 0; + static int delta = 1; + + // clear; + for (int i = 0; i < tlc.getChannels(); i++) + { + tlc.setChannel(i, false); + } + tlc.write(); + + Serial.println(pos); + tlc.setChannel(pos, true); + tlc.write(); + delay(100); + tlc.setChannel(pos, false); + tlc.write(); + + pos += delta; + if ((pos == 0) || (pos == tlc.getChannels())) + { + delta = -delta; + } +} + + +// -- END OF FILE -- diff --git a/libraries/TLC5917/examples/TLC5917_demo/TLC5917_demo.ino b/libraries/TLC5917/examples/TLC5917_demo/TLC5917_demo.ino new file mode 100644 index 00000000..d38b806e --- /dev/null +++ b/libraries/TLC5917/examples/TLC5917_demo/TLC5917_demo.ino @@ -0,0 +1,53 @@ +// +// FILE: TLC5917_demo.ino +// AUTHOR: Rob Tillaart +// PURPOSE: demo +// URL: https://github.com/RobTillaart/TLC5917 + + +#include "TLC5917.h" + +const int DEVICES = 2; +const int CLOCK = 13; +const int DATA = 12; +const int LE = 11; +const int OE = 10; + +TLC5917 tlc(DEVICES, CLOCK, DATA, LE, OE); + + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.print("TLC5917_LIB_VERSION: \t"); + Serial.println(TLC5917_LIB_VERSION); + + if (tlc.begin() == false) + { + Serial.println("error"); + while(1); + } + + Serial.print("Channels: "); + Serial.println(tlc.getChannels()); + + tlc.enable(); + + for (int ch = 0; ch < tlc.getChannels(); ch++) + { + tlc.setChannel(ch, true); + tlc.write(); + delay(100); + tlc.setChannel(ch, false); + } + tlc.write(); +} + + +void loop() +{ +} + + +// -- END OF FILE -- diff --git a/libraries/TLC5917/examples/TLC5917_performance/TLC5917_performance.ino b/libraries/TLC5917/examples/TLC5917_performance/TLC5917_performance.ino new file mode 100644 index 00000000..78a1dc4c --- /dev/null +++ b/libraries/TLC5917/examples/TLC5917_performance/TLC5917_performance.ino @@ -0,0 +1,95 @@ +// +// FILE: TLC5917_performance.ino +// AUTHOR: Rob Tillaart +// PURPOSE: test performance main functions. +// URL: https://github.com/RobTillaart/TLC5917 + + +#include "TLC5917.h" + +const int DEVICES = 100; +const int CLOCK = 13; +const int DATA = 12; +const int LATCH = 11; +const int BLANK = 10; + +TLC5916 tlc(DEVICES, CLOCK, DATA, LATCH, BLANK); + +uint32_t start, stop; + + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.print("TLC5917_LIB_VERSION: \t"); + Serial.println(TLC5917_LIB_VERSION); + + if (tlc.begin() == false) + { + Serial.println("Error"); + while (1); + } + + Serial.print("Channels:\t\t"); + Serial.println(tlc.getChannels()); + + tlc.enable(); + + testSetChannel(); + testWrite(); + + Serial.println("\nDone..."); +} + + +void loop() +{ +} + + +void testSetChannel() +{ + delay(100); + int channels = tlc.getChannels(); + start = micros(); + for (int channel = 0; channel < channels; channel++) + { + tlc.setChannel(channel, true); + } + stop = micros(); + Serial.print("SETCHANNEL TRUE:\t"); + Serial.println(stop - start); + delay(100); + + start = micros(); + for (int channel = 0; channel < channels; channel++) + { + tlc.setChannel(channel, false); + } + stop = micros(); + Serial.print("SETCHANNEL FALSE:\t"); + Serial.println(stop - start); + delay(100); + + start = micros(); + tlc.setAll(true); + stop = micros(); + Serial.print("SETALL TRUE:\t\t"); + Serial.println(stop - start); + delay(100); +} + + +void testWrite() +{ + delay(100); + start = micros(); + tlc.write(); + stop = micros(); + Serial.print("WRITE:\t\t\t"); + Serial.println(stop - start); +} + + +// -- END OF FILE -- diff --git a/libraries/TLC5917/examples/TLC5917_performance/performance_0.1.0.txt b/libraries/TLC5917/examples/TLC5917_performance/performance_0.1.0.txt new file mode 100644 index 00000000..b22a038c --- /dev/null +++ b/libraries/TLC5917/examples/TLC5917_performance/performance_0.1.0.txt @@ -0,0 +1,24 @@ +Arduino UNO +IDE: 1.8.19 + +(AVR optimized write() on UNO) +TLC5917_performance\TLC5917_performance.ino +TLC5917_LIB_VERSION: 0.1.0 +Channels: 800 +SETCHANNEL TRUE: 9908 +SETCHANNEL FALSE: 9960 +SETALL TRUE: 228 +WRITE: 14300 + +Done... + + +(default write() on UNO for reference) +TLC5917_LIB_VERSION: 0.1.0 +Channels: 800 +SETCHANNEL TRUE: 9908 +SETCHANNEL FALSE: 9960 +SETALL TRUE: 228 +WRITE: 75364 + +Done... diff --git a/libraries/TLC5917/keywords.txt b/libraries/TLC5917/keywords.txt new file mode 100644 index 00000000..d18faa1c --- /dev/null +++ b/libraries/TLC5917/keywords.txt @@ -0,0 +1,36 @@ +# Syntax Colouring Map For TLC5917 + + +# Data types (KEYWORD1) +TLC5916 KEYWORD1 +TLC5917 KEYWORD1 + + +# Methods and Functions (KEYWORD2) +begin KEYWORD2 +getChannels KEYWORD2 + +setChannel KEYWORD2 +setAll KEYWORD2 +getChannel KEYWORD2 + +write KEYWORD2 + +enable KEYWORD2 +disable KEYWORD2 +isEnabled KEYWORD2 + +setCurrentAdjustMode KEYWORD2 +setNormalMode KEYWORD2 +writeConfiguration KEYWORD2 + + +# Instances (KEYWORD2) + + +# Constants (LITERAL1) +TLC5917_LIB_VERSION LITERAL1 + +TLC5917_OK LITERAL1 +TLC5917_CHANNEL_ERROR LITERAL1 + diff --git a/libraries/TLC5917/library.json b/libraries/TLC5917/library.json new file mode 100644 index 00000000..6681f423 --- /dev/null +++ b/libraries/TLC5917/library.json @@ -0,0 +1,23 @@ +{ + "name": "TLC5917", + "keywords": "TLC5916, TLC5917", + "description": "Arduino library for TLC5917 8-Channel Constant-Current LED Sink Drivers.", + "authors": + [ + { + "name": "Rob Tillaart", + "email": "Rob.Tillaart@gmail.com", + "maintainer": true + } + ], + "repository": + { + "type": "git", + "url": "https://github.com/RobTillaart/TLC5917.git" + }, + "version": "0.1.0", + "license": "MIT", + "frameworks": "*", + "platforms": "*", + "headers": "TLC5917.h" +} diff --git a/libraries/TLC5917/library.properties b/libraries/TLC5917/library.properties new file mode 100644 index 00000000..37926424 --- /dev/null +++ b/libraries/TLC5917/library.properties @@ -0,0 +1,11 @@ +name=TLC5917 +version=0.1.0 +author=Rob Tillaart +maintainer=Rob Tillaart +sentence=Arduino library for TLC5917 8-Channel Constant-Current LED Sink Drivers. +paragraph=TLC5916 +category=Sensors +url=https://github.com/RobTillaart/TLC5917 +architectures=* +includes=TLC5917.h +depends= diff --git a/libraries/TLC5917/test/unit_test_001.cpp b/libraries/TLC5917/test/unit_test_001.cpp new file mode 100644 index 00000000..89e78d6f --- /dev/null +++ b/libraries/TLC5917/test/unit_test_001.cpp @@ -0,0 +1,70 @@ +// +// FILE: unit_test_001.cpp +// AUTHOR: Rob Tillaart +// DATE: 2024-03-17 +// PURPOSE: unit tests for the TLC5917 library. +// https://github.com/RobTillaart/TLC5917 +// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md +// + +// supported assertions +// ---------------------------- +// assertEqual(expected, actual); // a == b +// assertNotEqual(unwanted, actual); // a != b +// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b)) +// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b)) +// assertLess(upperBound, actual); // a < b +// assertMore(lowerBound, actual); // a > b +// assertLessOrEqual(upperBound, actual); // a <= b +// assertMoreOrEqual(lowerBound, actual); // a >= b +// assertTrue(actual); +// assertFalse(actual); +// assertNull(actual); + +// // special cases for floats +// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon +// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon +// assertInfinity(actual); // isinf(a) +// assertNotInfinity(actual); // !isinf(a) +// assertNAN(arg); // isnan(a) +// assertNotNAN(arg); // !isnan(a) + + +#include + + +#include "Arduino.h" +#include "TLC5917.h" + + + +unittest_setup() +{ + fprintf(stderr, "TLC5917_LIB_VERSION: %s\n", (char *) TLC5917_LIB_VERSION); +} + + +unittest_teardown() +{ +} + + +unittest(test_begin) +{ + TLC5917 tlc1(1, 13, 12, 11, 10); + + assertTrue(tlc1.begin()); + assertEqual(8, tlc1.getChannels()); + + TLC5917 tlc(21, 13, 12, 11, 10); + + assertTrue(tlc.begin()); + assertEqual(168, tlc.getChannels()); +} + + +unittest_main() + + +// -- END OF FILE -- +