Skip to content

Commit 4151b08

Browse files
authored
Enable I2C Alternate Function Remapping
This adds support for using I2C with the alternate mappings PD1, PD0 and PC5, PC6. To use PD1 (the SWDIO pin), pinV32_DisconnectDebug(PD_1) must be called before Wire.begin(), not sure if this should be documented somewhere or added to the code? I also changed the existing default mapping to use AFIO_Remap_I2C1_DISABLE so that it is possible to change the pin mapping back to the default at runtime. Tested on CHV0003F4P6-EVT-R0. Source openwch/arduino_core_ch32#152
1 parent d767162 commit 4151b08

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

variants/CH32V00x/CH32V003F4/PeripheralPins.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,18 @@ WEAK const PinMap PinMap_ADC[] = {
4747
//*** I2C ***
4848
#ifdef I2C_MODULE_ENABLED
4949
WEAK const PinMap PinMap_I2C_SDA[] = {
50-
{PC_1, I2C1, CH_PIN_DATA(CH_MODE_OUTPUT_50MHz, CH_CNF_OUTPUT_AFOD, NOPULL, AFIO_NONE)},
50+
{PC_1, I2C1, CH_PIN_DATA(CH_MODE_OUTPUT_50MHz, CH_CNF_OUTPUT_AFOD, NOPULL, AFIO_Remap_I2C1_DISABLE)},
51+
{PD_0, I2C1, CH_PIN_DATA(CH_MODE_OUTPUT_50MHz, CH_CNF_OUTPUT_AFOD, NOPULL, AFIO_PartialRemap_I2C1_ENABLE)},
52+
{PC_6, I2C1, CH_PIN_DATA(CH_MODE_OUTPUT_50MHz, CH_CNF_OUTPUT_AFOD, NOPULL, AFIO_FullRemap_I2C1_ENABLE)},
5153
{NC, NP, 0}
5254
};
5355
#endif
5456

5557
#ifdef I2C_MODULE_ENABLED
5658
WEAK const PinMap PinMap_I2C_SCL[] = {
57-
{PC_2, I2C1, CH_PIN_DATA(CH_MODE_OUTPUT_50MHz, CH_CNF_OUTPUT_AFOD, NOPULL, AFIO_NONE)},
59+
{PC_2, I2C1, CH_PIN_DATA(CH_MODE_OUTPUT_50MHz, CH_CNF_OUTPUT_AFOD, NOPULL, AFIO_Remap_I2C1_DISABLE)},
60+
{PD_1, I2C1, CH_PIN_DATA(CH_MODE_OUTPUT_50MHz, CH_CNF_OUTPUT_AFOD, NOPULL, AFIO_PartialRemap_I2C1_ENABLE)},
61+
{PC_5, I2C1, CH_PIN_DATA(CH_MODE_OUTPUT_50MHz, CH_CNF_OUTPUT_AFOD, NOPULL, AFIO_FullRemap_I2C1_ENABLE)},
5862
{NC, NP, 0}
5963
};
6064
#endif

0 commit comments

Comments
 (0)