From 6ae7887ff44f35b1116d0264fd90fc6d5fc6a2c9 Mon Sep 17 00:00:00 2001 From: gmcn42 Date: Thu, 5 Dec 2019 15:19:13 +0100 Subject: [PATCH 1/4] Add a way to remap I2C1 pins after construction of Wire 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. --- STM32F1/libraries/Wire/Wire.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/STM32F1/libraries/Wire/Wire.h b/STM32F1/libraries/Wire/Wire.h index a2890c196..59ae2b26b 100644 --- a/STM32F1/libraries/Wire/Wire.h +++ b/STM32F1/libraries/Wire/Wire.h @@ -72,6 +72,13 @@ class TwoWire : public WireBase { * Sets the hardware I2C clock */ void setClock(uint32_t frequencyHz); + + /* + * Useful to remap I2C1 to alternate pins PB8, PB9 + * after construction by adding flag I2C_REMAP + */ + void setDevFlags(uint8 dev_flags); + uint8 getDevFlags(void); /* * Disables the I2C device and remove the device address. */ From c921568b40e42504e65b38f6d9c4a0b75ce75a43 Mon Sep 17 00:00:00 2001 From: gmcn42 Date: Thu, 5 Dec 2019 15:22:13 +0100 Subject: [PATCH 2/4] Add a way to remap I2C1 pins after construction of Wire 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. --- STM32F1/libraries/Wire/Wire.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/STM32F1/libraries/Wire/Wire.cpp b/STM32F1/libraries/Wire/Wire.cpp index 3c62a97dc..3d0959c31 100644 --- a/STM32F1/libraries/Wire/Wire.cpp +++ b/STM32F1/libraries/Wire/Wire.cpp @@ -102,4 +102,12 @@ void TwoWire::setClock(uint32_t frequencyHz) } } +void TwoWire::setDevFlags(uint8 df) { + dev_flags = df; +} + +uint8 TwoWire::getDevFlags(void) { + return dev_flags; +} + TwoWire Wire(1); From 79483adf5e4eb17e07ef3eb6d6988b0c9ddc617b Mon Sep 17 00:00:00 2001 From: gmcn42 Date: Mon, 6 Jan 2020 13:37:04 +0100 Subject: [PATCH 3/4] Make new functions header-only. --- STM32F1/libraries/Wire/Wire.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/STM32F1/libraries/Wire/Wire.h b/STM32F1/libraries/Wire/Wire.h index 59ae2b26b..082c85097 100644 --- a/STM32F1/libraries/Wire/Wire.h +++ b/STM32F1/libraries/Wire/Wire.h @@ -77,8 +77,14 @@ class TwoWire : public WireBase { * Useful to remap I2C1 to alternate pins PB8, PB9 * after construction by adding flag I2C_REMAP */ - void setDevFlags(uint8 dev_flags); - uint8 getDevFlags(void); + void setDevFlags(uint8 dev_flags) { + dev_flags = df; + } + + uint8 getDevFlags(void) { + return dev_flags; + } + /* * Disables the I2C device and remove the device address. */ From 5dea3583b1d95da267f7e2e1a9d2918f39ae7635 Mon Sep 17 00:00:00 2001 From: gmcn42 Date: Mon, 6 Jan 2020 13:37:41 +0100 Subject: [PATCH 4/4] Make new functions header-only --- STM32F1/libraries/Wire/Wire.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/STM32F1/libraries/Wire/Wire.cpp b/STM32F1/libraries/Wire/Wire.cpp index 3d0959c31..3c62a97dc 100644 --- a/STM32F1/libraries/Wire/Wire.cpp +++ b/STM32F1/libraries/Wire/Wire.cpp @@ -102,12 +102,4 @@ void TwoWire::setClock(uint32_t frequencyHz) } } -void TwoWire::setDevFlags(uint8 df) { - dev_flags = df; -} - -uint8 TwoWire::getDevFlags(void) { - return dev_flags; -} - TwoWire Wire(1);