greiman / SSD1306Ascii

Text only Arduino Library for SSD1306 OLED displays
MIT License
504 stars 121 forks source link

Add ability to select I2C bus #62

Closed ksuszka closed 5 years ago

ksuszka commented 5 years ago

I'm using this library with stm32 based board which has two i2c buses. I've added ability to initialize SSD1306AsciiWire object with specific instance of TwoWire library.

greiman commented 5 years ago

There are I2C implementations for some boards that don't use the type TwoWire. The current implementation does not depend on the type of Wire.

I want to try to allow both alternate type and port/bus. I have seen libraries that use a template to do this. See this.

I will experiment with the template idea. This will also allow software I2C implementations and optimized hardware implementations.

greiman commented 5 years ago

Please try the update that allows I2C port selection.

I decided to add a configuration option MULTIPLE_I2C_PORTS. The default is nonzero except for AVR boards.

This allows any board with a problem to use the old code. It saves some flash and a tiny bit of SRAM on AVR.

I changed m_wire to m_oledWire since I am using this define when MULTIPLE_I2C_PORTS is zero. A bit less likely to already be defined.

#define m_oledWire Wire

I use decltype(Wire) instead of TwoWire in case Wire is not type TwoWire.

I tried some other Ideas to avoid the define but had problems with a board package called MightyCore.

ksuszka commented 5 years ago

I just checked your version and it works for me. Thanks for this fix!