AceTMI
0.6
Interfaces for communicating with the TM1637 and TM1638 LED controllers on Arduino platforms
|
Exactly the same as SimpleTmi1638Interface except that this uses the digitalWriteFast
library on AVR processors.
More...
#include <SimpleTmi1638FastInterface.h>
Public Member Functions | |
SimpleTmi1638FastInterface ()=default | |
Constructor. | |
void | begin () const |
Initialize the DIO, CLK, and STB pins. More... | |
void | end () const |
Set pins to INPUT mode. | |
void | beginTransaction () const |
Generate the SPI-like start condition. | |
void | endTransaction () const |
Generate the SPI-like stop condition. | |
void | write (uint8_t data) const |
Send the data byte on the data bus, with LSB first instead of the usual MSB first for SPI. More... | |
uint8_t | read () const |
Read the data byte on the data bus, with LSB first instead of the usual MSB first for SPI. More... | |
SimpleTmi1638FastInterface (const SimpleTmi1638FastInterface &)=default | |
SimpleTmi1638FastInterface & | operator= (const SimpleTmi1638FastInterface &)=default |
Exactly the same as SimpleTmi1638Interface except that this uses the digitalWriteFast
library on AVR processors.
Normally, the digitalWriteFast library is used to get faster speeds over digitalWrite()
and pinMode()
functions.
The reason that you may want to use digitalWriteFast
library is because it consumes far less flash memory than normal digitalWrite()
. The benchmarks in MemoryBenchmark shows that using this SimpleTmi1638FastInterface
instead of SimpleTmi1638Interface
saves ~500 bytes of flash on an AVR processor.
Caution: There might be a use-case where the normal SimpleTmi1638Interface
might consume less flash memory. If your application uses more than one TM1638 LED Module, you will need to create multiple instances of the Tm1638Module
. But the pin numbers of this class must be a compile-time constants, so different pins means that a different template class is generated. Since the Tm1638Module
class takes a SimpleTmi1638FastInterface
as a template argument, each LED Module generate a new template instance of the Tm1638Module
class.
When there are more than some number of TM1638 LED modules, it may actually be more efficient to use the non-fast SimpleTmi1638Interface
, because you will generate only a single template instantiation. I have not currently done any experiments to see where the break-even point would be.
The delayMicroseconds()
may not be accurate for small values on some processors (e.g. AVR) . The actual minimum value of T_DELAY_MICROS will depend on the capacitance and resistance on the DIO and CLK lines, and the accuracy of the delayMicroseconds()
function.
T_DIO_PIN | pin attached to the DIO data line |
T_CLK_PIN | pin attached to the CLK clock line |
T_STB_PIN | pin attached to the STB strobe line |
T_DELAY_MICROS | delay after each bit transition of DIO or CLK |
Definition at line 74 of file SimpleTmi1638FastInterface.h.
|
inline |
Initialize the DIO, CLK, and STB pins.
DIO is an open-drain line with pull-up resistors. We must not drive them HIGH actively since that could damage the transitor at the other end of the line pulling LOW. Instead, we go into INPUT mode to let the line to HIGH through the pullup resistor, then go to OUTPUT mode only to pull down.
Definition at line 88 of file SimpleTmi1638FastInterface.h.
|
inline |
Read the data byte on the data bus, with LSB first instead of the usual MSB first for SPI.
This loop generates slightly asymmetric logic signals because clockLow() lasts for 2*bitDelay(), but clockHigh() lasts for only 1*bitDelay(). This does not seem to cause any problems with the LED modules that I have tested.
Definition at line 159 of file SimpleTmi1638FastInterface.h.
|
inline |
Send the data byte on the data bus, with LSB first instead of the usual MSB first for SPI.
This loop generates slightly asymmetric logic signals because clockLow() lasts for 2*bitDelay(), but clockHigh() lasts for only 1*bitDelay(). This does not seem to cause any problems with the LED modules that I have tested.
Definition at line 126 of file SimpleTmi1638FastInterface.h.