AceTMI
0.6
Interfaces for communicating with the TM1637 and TM1638 LED controllers on Arduino platforms
|
Exactly the same as SimpleTmi1637Interface except that this uses the digitalWriteFast
library on AVR processors.
More...
#include <SimpleTmi1637FastInterface.h>
Public Member Functions | |
SimpleTmi1637FastInterface ()=default | |
Constructor. | |
void | begin () const |
Initialize the DIO and CLK pins. More... | |
void | end () const |
Set dio and clk pins to INPUT mode. | |
void | startCondition () const |
Generate the I2C-like start condition. | |
void | stopCondition () const |
Generate the I2C-like stop condition. | |
uint8_t | write (uint8_t data) const |
Send the data byte on the data bus, with LSB first instead of the usual MSB first for I2C. 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... | |
SimpleTmi1637FastInterface (const SimpleTmi1637FastInterface &)=default | |
SimpleTmi1637FastInterface & | operator= (const SimpleTmi1637FastInterface &)=default |
Exactly the same as SimpleTmi1637Interface 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. But speed of the digitalWrite()
functions is not the limiting factor in this library because every bit flip is followed by a delayMicroseconds()
which is far longer than the CPU cycle savings from digitalWritFast()
.
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 SimpleTmi1637FastInterface
instead of SimpleTmi1637Interface
saves 650-770 bytes of flash on an AVR processor.
Caution: There might be a use-case where the normal SimpleTmi1637Interface
might consume less flash memory. If your application uses more than one TM1637 LED Module, you will need to create multiple instances of the Tm1637Module
. 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 Tm1637Module
class takes a SimpleTmi1637FastInterface
as a template argument, each LED Module generate a new template instance of the Tm1637Module
class.
When there are more than some number of TM1637 LED modules, it may actually be more efficient to use the non-fast SimpleTmi1637Interface
, 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 data line |
T_CLK_PIN | pin attached to the clock line |
T_DELAY_MICROS | delay after each bit transition of DIO or CLK |
Definition at line 75 of file SimpleTmi1637FastInterface.h.
|
inline |
Initialize the DIO and CLK pins.
These are open-drain lines, 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 89 of file SimpleTmi1637FastInterface.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 169 of file SimpleTmi1637FastInterface.h.
|
inline |
Send the data byte on the data bus, with LSB first instead of the usual MSB first for I2C.
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.
write()
methods which return the number of bytes transfered.) Definition at line 134 of file SimpleTmi1637FastInterface.h.