0.1.1 TLC5917

This commit is contained in:
Rob Tillaart 2024-06-02 14:21:16 +02:00
parent 3360ecdaaf
commit 199eb0e90e
12 changed files with 126 additions and 40 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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 <stdint.h>
#include <cstdlib>
#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;

View File

@ -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;
}

View File

@ -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();

View File

@ -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++)
{

View File

@ -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

View File

@ -8,7 +8,7 @@ TLC5917 KEYWORD1
# Methods and Functions (KEYWORD2)
begin KEYWORD2
getChannels KEYWORD2
channelCount KEYWORD2
setChannel KEYWORD2
setAll KEYWORD2

View File

@ -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": "*",

View File

@ -1,5 +1,5 @@
name=TLC5917
version=0.1.0
version=0.1.1
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for TLC5917 8-Channel Constant-Current LED Sink Drivers.

View File

@ -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());
}