From 199eb0e90ed80650c13a22ecef0954afc2b898de Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Sun, 2 Jun 2024 14:21:16 +0200 Subject: [PATCH] 0.1.1 TLC5917 --- libraries/TLC5917/CHANGELOG.md | 8 ++++ libraries/TLC5917/README.md | 18 +++++--- libraries/TLC5917/TLC5917.cpp | 43 ++++++++++-------- libraries/TLC5917/TLC5917.h | 23 ++++++++-- .../TLC5917_NightRider/TLC5917_NightRider.ino | 5 ++- .../examples/TLC5917_demo/TLC5917_demo.ino | 10 +++-- .../TLC5917_performance.ino | 4 +- .../TLC5917_performance/performance_0.1.1.txt | 45 +++++++++++++++++++ libraries/TLC5917/keywords.txt | 2 +- libraries/TLC5917/library.json | 2 +- libraries/TLC5917/library.properties | 2 +- libraries/TLC5917/test/unit_test_001.cpp | 4 +- 12 files changed, 126 insertions(+), 40 deletions(-) create mode 100644 libraries/TLC5917/examples/TLC5917_performance/performance_0.1.1.txt diff --git a/libraries/TLC5917/CHANGELOG.md b/libraries/TLC5917/CHANGELOG.md index 32f9d7c0..68be5355 100644 --- a/libraries/TLC5917/CHANGELOG.md +++ b/libraries/TLC5917/CHANGELOG.md @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.1.1] - 2024-06-02 +- fix **setChannel()** +- rename **getChannels()** to **channelCount()** +- update examples +- update readme.md +- minor edits + + ## [0.1.0] - 2024-03-17 - initial version diff --git a/libraries/TLC5917/README.md b/libraries/TLC5917/README.md index 962497c8..96eaf3a3 100644 --- a/libraries/TLC5917/README.md +++ b/libraries/TLC5917/README.md @@ -20,16 +20,14 @@ TLC5917 is an Arduino library for TLC5917 8-Channel Constant-Current LED Sink Dr This library allows control over the 8 channels of a TLC5917 device. - -TODO: Elaborate. +The library allows to set outputs individually or a group in one call. 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. +The library is **experimental** and needs more testing with hardware. Please share your experiences. - (Changes of the interface are definitely possible). @@ -74,9 +72,16 @@ The blank pin is explained in more detail below. - **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 channelCount()** return the amount of channels == 8 x number of devices. - **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. +Will be obsolete in 0.2.0. + +#### Set/Get channels + +- **bool setChannel(uint8_t channel, bool on)** set a channel on or off in the +internal buffer. The value is not written yet to the device(s). - **bool setChannel(uint8_t \* array)** copy a preset of channel settings in one call. +The user has to take care the the size of array holds the right amount of bytes. - **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). @@ -167,6 +172,9 @@ See **TLC5917_performance.ino** for an indicative test. #### Could - add examples +- **void getChannel(uint8_t array)** fill array with current data +- **index operator []** to set channels? + #### Wont diff --git a/libraries/TLC5917/TLC5917.cpp b/libraries/TLC5917/TLC5917.cpp index ae6a79e6..d297b0a2 100644 --- a/libraries/TLC5917/TLC5917.cpp +++ b/libraries/TLC5917/TLC5917.cpp @@ -1,7 +1,7 @@ // // FILE: TLC5917.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.0 +// VERSION: 0.1.1 // DATE: 2024-03-17 // PURPOSE: Arduino library for TLC5917 8-Channel Constant-Current LED Sink Drivers. // URL: https://github.com/RobTillaart/TLC5917 @@ -19,12 +19,12 @@ TLC5917::TLC5917(uint8_t clock, uint8_t data, uint8_t LE, uint8_t 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)); + _channelCount = deviceCount * 8; + _clock = clock; + _data = data; + _le = LE; + _oe = OE; + _buffer = (uint8_t *) calloc(_channelCount, sizeof(uint8_t)); } @@ -49,24 +49,29 @@ bool TLC5917::begin() } -int TLC5917::getChannels() +int TLC5917::channelCount() { - return _channels; + return _channelCount; +} + +int TLC5917::getChannels() // OBSOLETE +{ + return _channelCount; } 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); + if (channel >= _channelCount) 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++) + for (int i = 0; i < _channelCount / 8; i++) { _buffer[i] = array[i]; } @@ -77,7 +82,7 @@ bool TLC5917::setChannel(uint8_t * array) bool TLC5917::setAll(bool on) { uint8_t mask = on ? 0xFF : 0x00; - for (int i = 0; i < _channels / 8; i++) + for (int i = 0; i < _channelCount / 8; i++) { _buffer[i] = mask; } @@ -87,7 +92,7 @@ bool TLC5917::setAll(bool on) bool TLC5917::getChannel(uint8_t channel) { - if (channel >= _channels) return false; + if (channel >= _channelCount) return false; return (_buffer[channel / 8] & (1 << (channel & 0x07))) > 0; } @@ -100,13 +105,13 @@ bool TLC5917::getChannel(uint8_t channel) // multi device 15 MHz CHECK TODO void TLC5917::write() { - write(_channels); + write(_channelCount); } void TLC5917::write(int chan) { - if (chan > _channels) chan = _channels; + if (chan > _channelCount) chan = _channelCount; if (chan < 0) return; #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) @@ -250,9 +255,9 @@ void TLC5917::writeConfiguration(uint8_t config) { uint8_t _clk = _clock; uint8_t _dat = _data; - uint8_t _devices = _channels/8; + uint8_t _devices = _channelCount/8; - // write same config to all devices + // write same configuration to all devices for (int i = 0; i < _devices; i++) { for (uint8_t mask = 0x80; mask; mask >>= 1) diff --git a/libraries/TLC5917/TLC5917.h b/libraries/TLC5917/TLC5917.h index 7190dfb3..889d1627 100644 --- a/libraries/TLC5917/TLC5917.h +++ b/libraries/TLC5917/TLC5917.h @@ -2,18 +2,32 @@ // // FILE: TLC5917.h // AUTHOR: Rob Tillaart -// VERSION: 0.1.0 +// VERSION: 0.1.1 // 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")) +#define TLC5917_LIB_VERSION (F("0.1.1")) #include "Arduino.h" +// non Arduino environment need to fix these. +/* +#include +#include + +#define pinMode(X, Y) {} +#define digitalWrite(X, Y) {} +#define digitalRead(X) (1) + +#define HIGH 1 +#define LOW 0 +#define OUTPUT 0 +*/ + #define TLC5917_OK 0x0000 #define TLC5917_CHANNEL_ERROR 0xFFFF @@ -28,7 +42,8 @@ public: virtual ~TLC5917(); bool begin(); - int getChannels(); + int channelCount(); // replaces getChannels which looks too much like getChannel. + int getChannels(); // will be obsolete in 0.2.0 bool setChannel(uint8_t channel, bool on); bool setChannel(uint8_t * array); // size must be deviceCount. @@ -53,7 +68,7 @@ public: protected: - int _channels; + int _channelCount; uint8_t * _buffer; uint8_t _clock; uint8_t _data; diff --git a/libraries/TLC5917/examples/TLC5917_NightRider/TLC5917_NightRider.ino b/libraries/TLC5917/examples/TLC5917_NightRider/TLC5917_NightRider.ino index 681fac93..c884de49 100644 --- a/libraries/TLC5917/examples/TLC5917_NightRider/TLC5917_NightRider.ino +++ b/libraries/TLC5917/examples/TLC5917_NightRider/TLC5917_NightRider.ino @@ -7,6 +7,7 @@ #include "TLC5917.h" + int DEVICES = 1; const int CLOCK = 13; const int DATA = 12; @@ -34,7 +35,7 @@ void loop() static int delta = 1; // clear; - for (int i = 0; i < tlc.getChannels(); i++) + for (int i = 0; i < tlc.channelCount(); i++) { tlc.setChannel(i, false); } @@ -48,7 +49,7 @@ void loop() tlc.write(); pos += delta; - if ((pos == 0) || (pos == tlc.getChannels())) + if ((pos == 0) || (pos == (tlc.channelCount() - 1))) { delta = -delta; } diff --git a/libraries/TLC5917/examples/TLC5917_demo/TLC5917_demo.ino b/libraries/TLC5917/examples/TLC5917_demo/TLC5917_demo.ino index d38b806e..4f76a2fa 100644 --- a/libraries/TLC5917/examples/TLC5917_demo/TLC5917_demo.ino +++ b/libraries/TLC5917/examples/TLC5917_demo/TLC5917_demo.ino @@ -7,6 +7,7 @@ #include "TLC5917.h" + const int DEVICES = 2; const int CLOCK = 13; const int DATA = 12; @@ -22,19 +23,22 @@ void setup() Serial.println(__FILE__); Serial.print("TLC5917_LIB_VERSION: \t"); Serial.println(TLC5917_LIB_VERSION); + Serial.println(); + + Serial.println(sizeof(tlc)); if (tlc.begin() == false) { Serial.println("error"); - while(1); + while (1); } Serial.print("Channels: "); - Serial.println(tlc.getChannels()); + Serial.println(tlc.channelCount()); tlc.enable(); - for (int ch = 0; ch < tlc.getChannels(); ch++) + for (int ch = 0; ch < tlc.channelCount(); ch++) { tlc.setChannel(ch, true); tlc.write(); diff --git a/libraries/TLC5917/examples/TLC5917_performance/TLC5917_performance.ino b/libraries/TLC5917/examples/TLC5917_performance/TLC5917_performance.ino index 78a1dc4c..7765c7cb 100644 --- a/libraries/TLC5917/examples/TLC5917_performance/TLC5917_performance.ino +++ b/libraries/TLC5917/examples/TLC5917_performance/TLC5917_performance.ino @@ -32,7 +32,7 @@ void setup() } Serial.print("Channels:\t\t"); - Serial.println(tlc.getChannels()); + Serial.println(tlc.channelCount()); tlc.enable(); @@ -51,7 +51,7 @@ void loop() void testSetChannel() { delay(100); - int channels = tlc.getChannels(); + int channels = tlc.channelCount(); start = micros(); for (int channel = 0; channel < channels; channel++) { diff --git a/libraries/TLC5917/examples/TLC5917_performance/performance_0.1.1.txt b/libraries/TLC5917/examples/TLC5917_performance/performance_0.1.1.txt new file mode 100644 index 00000000..f6f2b1ae --- /dev/null +++ b/libraries/TLC5917/examples/TLC5917_performance/performance_0.1.1.txt @@ -0,0 +1,45 @@ +Arduino UNO +IDE: 1.8.19 + +(AVR optimized write() on UNO) +TLC5917_performance\TLC5917_performance.ino +TLC5917_LIB_VERSION: 0.1.1 +Channels: 800 +SETCHANNEL TRUE: 2572 +SETCHANNEL FALSE: 2848 +SETALL TRUE: 232 +WRITE: 14304 + +Done... + + +(default write() on UNO for reference) +TLC5917_LIB_VERSION: 0.1.1 +Channels: 800 +SETCHANNEL TRUE: 2572 +SETCHANNEL FALSE: 2848 +SETALL TRUE: 232 +WRITE: 75368 + +Done... + + +------------- + +From https://github.com/RobTillaart/TLC5917/issues/4#issuecomment-2143814271 + +Arduino NANO V3 (old Bootloader) +TLC5917_LIB_VERSION: 0.1.0 +Channels: 800 +SETCHANNEL TRUE: 2572 +SETCHANNEL FALSE: 2848 +SETALL TRUE: 232 +WRITE: 14300 + +LGT8F328P MiniEVB +TLC5917_LIB_VERSION: 0.1.0 +Channels: 800 +SETCHANNEL TRUE: 1156 +SETCHANNEL FALSE: 1294 +reset at this point + diff --git a/libraries/TLC5917/keywords.txt b/libraries/TLC5917/keywords.txt index d18faa1c..3fe82b57 100644 --- a/libraries/TLC5917/keywords.txt +++ b/libraries/TLC5917/keywords.txt @@ -8,7 +8,7 @@ TLC5917 KEYWORD1 # Methods and Functions (KEYWORD2) begin KEYWORD2 -getChannels KEYWORD2 +channelCount KEYWORD2 setChannel KEYWORD2 setAll KEYWORD2 diff --git a/libraries/TLC5917/library.json b/libraries/TLC5917/library.json index 6681f423..b1acf800 100644 --- a/libraries/TLC5917/library.json +++ b/libraries/TLC5917/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/TLC5917.git" }, - "version": "0.1.0", + "version": "0.1.1", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/libraries/TLC5917/library.properties b/libraries/TLC5917/library.properties index 37926424..b4f78b1a 100644 --- a/libraries/TLC5917/library.properties +++ b/libraries/TLC5917/library.properties @@ -1,5 +1,5 @@ name=TLC5917 -version=0.1.0 +version=0.1.1 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for TLC5917 8-Channel Constant-Current LED Sink Drivers. diff --git a/libraries/TLC5917/test/unit_test_001.cpp b/libraries/TLC5917/test/unit_test_001.cpp index 89e78d6f..a4a50380 100644 --- a/libraries/TLC5917/test/unit_test_001.cpp +++ b/libraries/TLC5917/test/unit_test_001.cpp @@ -54,12 +54,12 @@ unittest(test_begin) TLC5917 tlc1(1, 13, 12, 11, 10); assertTrue(tlc1.begin()); - assertEqual(8, tlc1.getChannels()); + assertEqual(8, tlc1.channelCount()); TLC5917 tlc(21, 13, 12, 11, 10); assertTrue(tlc.begin()); - assertEqual(168, tlc.getChannels()); + assertEqual(168, tlc.channelCount()); }