Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable TwoWire pin configuration for stm32 #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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