Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of TLC5940 by
TLC5940Mux.cpp
- Committer:
- Spencer
- Date:
- 2013-05-20
- Revision:
- 0:be9399a34b15
- Child:
- 3:e5ed5650eb15
File content as of revision 0:be9399a34b15:
#include "mbed.h"
#include "TLC5940.h"
TLC5940Mux::TLC5940Mux(PinName SCLK, PinName MOSI, PinName GSCLK, PinName BLANK, 
                       PinName XLAT, PinName DCPRG, PinName VPRG, const int number, 
                       const int rows, void (*SetRows)(int)) : TLC5940(SCLK, MOSI, GSCLK, BLANK, XLAT, DCPRG, VPRG, number),
                                                               rows(rows),
                                                               SetRows(SetRows),
                                                               index(0)
{
    // Create a data buffer to store the current LED states
    dataBuffer = new unsigned short[rows * 16 * number];
    
    // Zero the buffer
    memset(dataBuffer, 0x00, rows * 16 * number * 2);
}
TLC5940Mux::~TLC5940Mux()
{
    // Delete the buffer
    delete[] dataBuffer;
}
unsigned short* TLC5940Mux::operator=(unsigned short* data)
{
    // Copy the memory from data to the data buffer
    memcpy(dataBuffer, data, rows * 16 * number * 2);
    return data;
}
unsigned short* TLC5940Mux::operator[](int index)
{
    // Return the start of the correct data chunk
    return dataBuffer + (index * 16 * number);
}
void TLC5940Mux::setNextData()
{
    // Move into the dataBuffer and return a pointer corresponding to the start of the correct data block
    setNewGSData(dataBuffer + (index * 16 * number));
    
    // Since the data we sent on the previous reset was just latched in,
    // we must enable the row for the previous index so it is displayed in the right position
    // The ternary is used in case index is zero (we can't have an index of -1)
    SetRows((index ? (index - 1) : (rows - 1)));
    
    // Go to next index
    if (index == (rows - 1))
        index = 0;
    else
        index++;
}
            
    