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::SimpleTmi1638FastInterface< T_DIO_PIN, T_CLK_PIN, T_STB_PIN, T_DELAY_MICROS > Class Template Reference

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
 
SimpleTmi1638FastInterfaceoperator= (const SimpleTmi1638FastInterface &)=default
 

Detailed Description

template<uint8_t T_DIO_PIN, uint8_t T_CLK_PIN, uint8_t T_STB_PIN, uint8_t T_DELAY_MICROS>
class ace_tmi::SimpleTmi1638FastInterface< T_DIO_PIN, T_CLK_PIN, T_STB_PIN, T_DELAY_MICROS >

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.

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

Definition at line 74 of file SimpleTmi1638FastInterface.h.

Member Function Documentation

◆ begin()

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

◆ read()

template<uint8_t T_DIO_PIN, uint8_t T_CLK_PIN, uint8_t T_STB_PIN, uint8_t T_DELAY_MICROS>
uint8_t ace_tmi::SimpleTmi1638FastInterface< T_DIO_PIN, T_CLK_PIN, T_STB_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 159 of file SimpleTmi1638FastInterface.h.

◆ write()

template<uint8_t T_DIO_PIN, uint8_t T_CLK_PIN, uint8_t T_STB_PIN, uint8_t T_DELAY_MICROS>
void ace_tmi::SimpleTmi1638FastInterface< T_DIO_PIN, T_CLK_PIN, T_STB_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 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.


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