1313#include "py/runtime.h"
1414#include "py/mperrno.h"
1515
16+
17+ /* Note: The MAX32690 assigns the same alternate function to multiple sets
18+ * of pins. The drivers will enable both sets so that either can be used.
19+ * Users should ensure the unused set is left unconnected.
20+ *
21+ * See MAX32690 Rev A2 Errata #16:
22+ * https://www.analog.com/media/en/technical-documentation/data-sheets/max32690_a2_errata_rev2.pdf
23+ *
24+ * Additionally, note that the TQFN package does not expose some of the duplicate pins. For this package,
25+ * enabling the un-routed GPIOs has been shown to cause initialization issues with the I2C block.
26+ * To work around this, "MAX32690GTK_PACKAGE_TQFN" can be defined by the build system. The recommend place
27+ * to do it is in the "board.mk" file of the BSP. This will prevent the inaccessible pins from being configured.
28+ */
29+
1630const mxc_gpio_cfg_t i2c_maps [NUM_I2C ] = {
31+ // I2C0
32+ { MXC_GPIO2 , (MXC_GPIO_PIN_7 | MXC_GPIO_PIN_8 ), MXC_GPIO_FUNC_ALT1 ,
33+ MXC_GPIO_PAD_NONE , MXC_GPIO_VSSEL_VDDIO , MXC_GPIO_DRVSTR_0 };
34+ // I2C1
35+ { MXC_GPIO0 , (MXC_GPIO_PIN_11 | MXC_GPIO_PIN_12 ), MXC_GPIO_FUNC_ALT1 ,
36+ MXC_GPIO_PAD_NONE , MXC_GPIO_VSSEL_VDDIO , MXC_GPIO_DRVSTR_0 };
37+ // I2C2
38+ { MXC_GPIO1 , (MXC_GPIO_PIN_7 | MXC_GPIO_PIN_8 ), MXC_GPIO_FUNC_ALT3 ,
39+ MXC_GPIO_PAD_NONE , MXC_GPIO_VSSEL_VDDIOH , MXC_GPIO_DRVSTR_0 };,
40+ };
41+ #ifndef MAX32690GTK_PACKAGE_TQFN
42+ const mxc_gpio_cfg_t i2c_maps_extra [NUM_I2C ] = {
1743 // I2C0A
1844 { MXC_GPIO0 , (MXC_GPIO_PIN_30 | MXC_GPIO_PIN_31 ), MXC_GPIO_FUNC_ALT1 ,
1945 MXC_GPIO_PAD_PULL_UP , MXC_GPIO_VSSEL_VDDIOH , MXC_GPIO_DRVSTR_0 },
2046 // I2C1A
2147 { MXC_GPIO2 , (MXC_GPIO_PIN_17 | MXC_GPIO_PIN_18 ), MXC_GPIO_FUNC_ALT1 ,
2248 MXC_GPIO_PAD_PULL_UP , MXC_GPIO_VSSEL_VDDIOH , MXC_GPIO_DRVSTR_0 },
49+ // I2C2C
50+ { MXC_GPIO0 , (MXC_GPIO_PIN_13 | MXC_GPIO_PIN_14 ), MXC_GPIO_FUNC_ALT3 ,
51+ MXC_GPIO_PAD_NONE , MXC_GPIO_VSSEL_VDDIO , MXC_GPIO_DRVSTR_0 };,
2352};
53+ #endif
2454
2555int pinsToI2c (const mcu_pin_obj_t * sda , const mcu_pin_obj_t * scl ) {
2656 for (int i = 0 ; i < NUM_I2C ; i ++ ) {
@@ -29,6 +59,17 @@ int pinsToI2c(const mcu_pin_obj_t *sda, const mcu_pin_obj_t *scl) {
2959 return i ;
3060 }
3161 }
62+
63+ // Additional for loop to cover alternate potential I2C maps
64+ #ifndef MAX32690GTK_PACKAGE_TQFN
65+ for (int i = 0 ; i < NUM_I2C ; i ++ ) {
66+ if ((i2c_maps_extra [i ].port == (MXC_GPIO_GET_GPIO (sda -> port )))
67+ && (i2c_maps_extra [i ].mask == ((sda -> mask ) | (scl -> mask )))) {
68+ return i ;
69+ }
70+ }
71+ #endif
72+
3273 mp_raise_RuntimeError_varg (MP_ERROR_TEXT ("ERR: Unable to find an I2C matching pins...\nSCL: port %d mask %d\nSDA: port %d mask %d\n" ),
3374 sda -> port , sda -> mask , scl -> port , scl -> mask );
3475 return -1 ;
0 commit comments