13
13
#include "py/runtime.h"
14
14
#include "py/mperrno.h"
15
15
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
+
16
30
const 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 ] = {
17
43
// I2C0A
18
44
{ MXC_GPIO0 , (MXC_GPIO_PIN_30 | MXC_GPIO_PIN_31 ), MXC_GPIO_FUNC_ALT1 ,
19
45
MXC_GPIO_PAD_PULL_UP , MXC_GPIO_VSSEL_VDDIOH , MXC_GPIO_DRVSTR_0 },
20
46
// I2C1A
21
47
{ MXC_GPIO2 , (MXC_GPIO_PIN_17 | MXC_GPIO_PIN_18 ), MXC_GPIO_FUNC_ALT1 ,
22
48
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 };,
23
52
};
53
+ #endif
24
54
25
55
int pinsToI2c (const mcu_pin_obj_t * sda , const mcu_pin_obj_t * scl ) {
26
56
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) {
29
59
return i ;
30
60
}
31
61
}
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
+
32
73
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" ),
33
74
sda -> port , sda -> mask , scl -> port , scl -> mask );
34
75
return -1 ;
0 commit comments