Skip to content

Conversation

@Gibol
Copy link

@Gibol Gibol commented Jan 25, 2023

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
Copy link

CLAassistant commented Jan 25, 2023

CLA assistant check
All committers have signed the CLA.

@lexus2k
Copy link
Owner

lexus2k commented Jan 25, 2023

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants