23
23
#include "lock_resource.h"
24
24
#endif
25
25
26
+ typedef struct {
27
+ PinName pin ;
28
+ uint32_t LL_AnalogSwitch ;
29
+ } PinAnalogSwitch ;
30
+
31
+ #if defined(STM32H7xx )
32
+ #define DUALPAD_ANALOG_SWITCH
33
+ const PinAnalogSwitch PinMapAnalogSwitch [] = {
34
+ {PA_0 , LL_SYSCFG_ANALOG_SWITCH_PA0 },
35
+ {PA_1 , LL_SYSCFG_ANALOG_SWITCH_PA1 },
36
+ {PC_2 , LL_SYSCFG_ANALOG_SWITCH_PC2 },
37
+ {PC_3 , LL_SYSCFG_ANALOG_SWITCH_PC3 },
38
+ {NC , 0 }
39
+ };
40
+ #else
41
+ /**
42
+ * Even if MP1 support some dual pad (analog switch), we don't consider it
43
+ * because its behavior is different from H7 and almost useless.
44
+ * Switches remains open all the time. No need to configure it */
45
+ #undef DUALPAD_ANALOG_SWITCH
46
+ #endif
47
+
26
48
/* Map STM_PIN to LL */
27
49
const uint32_t pin_map_ll [16 ] = {
28
50
LL_GPIO_PIN_0 ,
@@ -43,6 +65,41 @@ const uint32_t pin_map_ll[16] = {
43
65
LL_GPIO_PIN_15
44
66
};
45
67
68
+ #if defined(DUALPAD_ANALOG_SWITCH )
69
+ /**
70
+ * Configure Analog dualpad switch if necessary
71
+ */
72
+ void configure_dualpad_switch (PinName pin , int function )
73
+ {
74
+ PinAnalogSwitch * AnalogSwitch = (PinAnalogSwitch * ) PinMapAnalogSwitch ;
75
+
76
+ /* Read through PinMapAnalogSwitch array */
77
+ while (AnalogSwitch -> pin != NC ) {
78
+ /* Check whether pin is or is associated to dualpad Analog Input */
79
+ if ((AnalogSwitch -> pin | PDUAL ) == (pin | PDUAL )) {
80
+ if (((function & STM_MODE_ANALOG ) != STM_MODE_ANALOG )
81
+ && ((pin & PDUAL ) == PDUAL )) {
82
+ /**
83
+ * We don't configure an analog function but the pin is an analog pad
84
+ * (Pxy_C, ANA0 ...) In this cases Analog switch should be closed
85
+ */
86
+ LL_SYSCFG_CloseAnalogSwitch (AnalogSwitch -> LL_AnalogSwitch );
87
+ return ;
88
+ } else {
89
+ /**
90
+ * Either we configure an analog function,
91
+ * or it is not an analog function but it is not an analog pad
92
+ * (not Pxy_C, ANA0 ...). In both cases Analog switch should be opened
93
+ */
94
+ LL_SYSCFG_OpenAnalogSwitch (AnalogSwitch -> LL_AnalogSwitch );
95
+ return ;
96
+ }
97
+ }
98
+ AnalogSwitch ++ ;
99
+ }
100
+ }
101
+ #endif /* DUALPAD_ANALOG_SWITCH */
102
+
46
103
bool pin_in_pinmap (PinName pin , const PinMap * map )
47
104
{
48
105
if (pin != (PinName )NC ) {
@@ -177,6 +234,10 @@ void pin_function(PinName pin, int function)
177
234
178
235
pin_PullConfig (gpio , ll_pin , STM_PIN_PUPD (function ));
179
236
237
+ #if defined(DUALPAD_ANALOG_SWITCH )
238
+ configure_dualpad_switch (pin , function );
239
+ #endif /* DUALPAD_ANALOG_SWITCH */
240
+
180
241
pin_DisconnectDebug (pin );
181
242
182
243
hsem_unlock (CFG_HW_GPIO_SEMID );
0 commit comments