maxint-rd / TM16xx

Arduino TM16xx library for LED & KEY and LED Matrix modules based on TM1638, TM1637, TM1640 and similar chips. Simply use print() on 7-segment and use Adafruit GFX on matrix.
164 stars 34 forks source link

Facilitate compilation for ESP32 #17

Closed KenWillmott closed 2 years ago

KenWillmott commented 2 years ago

The ESP32 tool chain provides min() and max() functions. These can not be easily over ridden by redefinition of the macros because the redefinition code can not detect functions. Secondly, there are two non-mandatory uses of min() in the code, that can only be fixed by casting. As a cast for such a simple purpose seems gratuitous, they have been replaced by a simple bit mask operation. It's driver code that uses bit concatenation, so low level logic is not inappropriate.

This change removes the redefinition code, and alter all instances of min() to use bit masking instead. The result is that the library will compile with the current ESP32 core. It was also tested for the AVR, choosing the UNO board for compilation.

See: https://github.com/esp8266/Arduino/issues/398#issuecomment-356034907

This is a prerequisite for further changes that fix a different issue, crashes due to the use of system functions in a constructor.

Edit - I realized this doesn't have the same effect on brightness parameters. I have a better solution so I'm going to try to close this.

KenWillmott commented 2 years ago

I realized this doesn't have the same effect on brightness parameters. I have a better solution so I'm going to try to close this.