This library allows control of the TLC5940 PWM driver IC. It supports both normal operation and controlling multiplexed displays.

Dependencies:   FastPWM

Dependents:   TLC5940LEDtreiber

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TLC5940Mux.cpp Source File

TLC5940Mux.cpp

00001 #include "mbed.h"
00002 #include "TLC5940.h"
00003 
00004 
00005 TLC5940Mux::TLC5940Mux(PinName SCLK, PinName MOSI, PinName GSCLK, PinName BLANK, 
00006                        PinName XLAT, PinName DCPRG, PinName VPRG, const int number, 
00007                        const int rows, void (*SetRows)(int)) : TLC5940(SCLK, MOSI, GSCLK, BLANK, XLAT, DCPRG, VPRG, number),
00008                                                                rows(rows),
00009                                                                SetRows(SetRows),
00010                                                                currentIndex(0)
00011 
00012 {
00013     // Create a data buffer to store the current LED states
00014     dataBuffer = new unsigned short[rows * 16 * number];
00015     
00016     // Zero the buffer
00017     memset(dataBuffer, 0x00, rows * 16 * number * 2);
00018 }
00019 
00020 TLC5940Mux::~TLC5940Mux()
00021 {
00022     // Delete the buffer
00023     delete[] dataBuffer;
00024 }
00025 
00026 unsigned short* TLC5940Mux::operator=(unsigned short* data)
00027 {
00028     // Copy the memory from data to the data buffer
00029     memcpy(dataBuffer, data, rows * 16 * number * 2);
00030 
00031     return data;
00032 }
00033 
00034 unsigned short* TLC5940Mux::operator[](int index)
00035 {
00036     // Return the start of the correct data chunk
00037     return dataBuffer + (index * 16 * number);
00038 }
00039 
00040 void TLC5940Mux::setNextData()
00041 {
00042     // Move into the dataBuffer and return a pointer corresponding to the start of the correct data block
00043     setNewGSData(dataBuffer + (currentIndex * 16 * number));
00044     
00045     // Since the data we sent on the previous reset was just latched in,
00046     // we must enable the row for the previous index so it is displayed in the right position
00047     // The ternary is used in case index is zero (we can't have an index of -1)
00048     SetRows((currentIndex ? (currentIndex - 1) : (rows - 1)));
00049     
00050     // Go to next index
00051     if (currentIndex == (rows - 1))
00052         currentIndex = 0;
00053     else
00054         currentIndex++;
00055 }