lexus2k / lcdgfx

Driver for LCD displays running on Arduino/Avr/ESP32/Linux (including Rasperry) platforms
MIT License
389 stars 55 forks source link

Enable TwoWire pin configuration for stm32 #99

Open Gibol opened 1 year ago

Gibol commented 1 year ago

This change allows i2c displays to work with non-default i2c pins on STM32. Tested on custom board with STM32F072C8T6 and SH1106 128x64 display with I2C2 peripheral on PB10 and PB11

CLAassistant commented 1 year ago

CLA assistant check
All committers have signed the CLA.

lexus2k commented 1 year ago

There is a problem in your commit: if this is not ESP32/ESP8266/STM32 platform then Wire.begin() will not be executed and the library will be broken for other platforms.

It is better to do like this:


void ArduinoI2c::begin()
{
#if defined(ESP8266) || defined(ESP32) || defined(ESP31B) || defined(ARDUINO_ARCH_STM32)
    if ( (m_scl >= 0) && (m_sda >= 0) )
    {
#if defined(ESP8266) || defined(ESP32) || defined(ESP31B)
        Wire.begin(m_sda, m_scl);
#elif defined(ARDUINO_ARCH_STM32)
        // Wire.begin(m_sda, m_scl) does not work for stm32duino core
        Wire.setSCL(m_scl);
        Wire.setSDA(m_sda);
        Wire.begin();
#endif
    }
    else
#endif
    {
        Wire.begin();
    }
#ifdef SSD1306_WIRE_CLOCK_CONFIGURABLE
    Wire.setClock(400000);
#endif
}