Arduino_STM32 icon indicating copy to clipboard operation
Arduino_STM32 copied to clipboard

Add a way to remap I2C1 pins after construction of standard Wire instance

Open gmcn42 opened this issue 5 years ago • 3 comments

Normally there is no way to edit the dev_flags variable after Wire has been constructed. It is sometimes helpful to do so though. Example: u8g2 uses the builtin Wire instance to communicate with I2C displays which is normally set to the standard pins.

Using the added functions from this PR it is possible to:

//during setup():
uint8_t df = Wire.getDevFlags();
df |= I2C_REMAP;
Wire.setDevFlags(df);

After that u8g2 will nicely communicate with an I2C display connected to the alternate pins.

gmcn42 avatar Dec 05 '19 14:12 gmcn42

@gmcn42 , could you eventually define these functions in the header file only, so that the Wire.cpp remains untouched?

stevstrong2 avatar Dec 25 '19 19:12 stevstrong2

Sure. Amended PR.

gmcn42 avatar Jan 06 '20 12:01 gmcn42

I think there is a small mistake, the input parameter should be df if I'm not wrong. Can you please correct that?

stevstrong avatar Nov 03 '23 09:11 stevstrong