AceTMI  0.6
Interfaces for communicating with the TM1637 and TM1638 LED controllers on Arduino platforms
Public Member Functions | List of all members
ace_tmi::SimpleTmi1637FastInterface< T_DIO_PIN, T_CLK_PIN, T_DELAY_MICROS > Class Template Reference

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
 
SimpleTmi1637FastInterfaceoperator= (const SimpleTmi1637FastInterface &)=default
 

Detailed Description

template<uint8_t T_DIO_PIN, uint8_t T_CLK_PIN, uint8_t T_DELAY_MICROS>
class ace_tmi::SimpleTmi1637FastInterface< T_DIO_PIN, T_CLK_PIN, T_DELAY_MICROS >

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.

Template Parameters
T_DIO_PINpin attached to the data line
T_CLK_PINpin attached to the clock line
T_DELAY_MICROSdelay after each bit transition of DIO or CLK

Definition at line 75 of file SimpleTmi1637FastInterface.h.

Member Function Documentation

◆ begin()

template<uint8_t T_DIO_PIN, uint8_t T_CLK_PIN, uint8_t T_DELAY_MICROS>
void ace_tmi::SimpleTmi1637FastInterface< T_DIO_PIN, T_CLK_PIN, T_DELAY_MICROS >::begin ( ) const
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.

◆ read()

template<uint8_t T_DIO_PIN, uint8_t T_CLK_PIN, uint8_t T_DELAY_MICROS>
uint8_t ace_tmi::SimpleTmi1637FastInterface< T_DIO_PIN, T_CLK_PIN, T_DELAY_MICROS >::read ( ) const
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.

Returns
the data byte

Definition at line 169 of file SimpleTmi1637FastInterface.h.

◆ write()

template<uint8_t T_DIO_PIN, uint8_t T_CLK_PIN, uint8_t T_DELAY_MICROS>
uint8_t ace_tmi::SimpleTmi1637FastInterface< T_DIO_PIN, T_CLK_PIN, T_DELAY_MICROS >::write ( uint8_t  data) const
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.

Returns
1 if device responded with ACK, 0 for NACK. (This retains consistency with AceWire's I2C write() methods which return the number of bytes transfered.)

Definition at line 134 of file SimpleTmi1637FastInterface.h.


The documentation for this class was generated from the following file: