@@ -68,35 +68,64 @@ const uint32_t pin_map_ll[16] = {
68
68
#if defined(DUALPAD_ANALOG_SWITCH )
69
69
/**
70
70
* Configure Analog dualpad switch if necessary
71
+ * LL_AnalogSwitch: LL define to be used to configure Analog switch
71
72
*/
72
- void configure_dualpad_switch (PinName pin , int function )
73
+ static void configure_dualpad_switch (PinName pin , int function , uint32_t LL_AnalogSwitch )
74
+ {
75
+ if (LL_AnalogSwitch == 0 ) {
76
+ return ;
77
+ }
78
+
79
+ if (((function & STM_MODE_ANALOG ) != STM_MODE_ANALOG )
80
+ && ((pin & PDUAL ) == PDUAL )) {
81
+ /**
82
+ * We don't configure an analog function but the pin is an analog pad
83
+ * Pxy_C. In this cases Analog switch should be closed
84
+ */
85
+ LL_SYSCFG_CloseAnalogSwitch (LL_AnalogSwitch );
86
+ return ;
87
+ } else {
88
+ /**
89
+ * Either we configure an analog function,
90
+ * or it is not an analog function but it is not an analog pad Pxy_C.
91
+ * In both cases Analog switch should be opened
92
+ * Note: direct ADC is restricted to Pxy_C, pin only
93
+ */
94
+ LL_SYSCFG_OpenAnalogSwitch (LL_AnalogSwitch );
95
+ return ;
96
+ }
97
+ }
98
+
99
+ /**
100
+ * In case of dual pad, determine whether gpio needs to be configured
101
+ * pLL_AnalogSwitch: pointer used to retrun LL define to be used to configure
102
+ * Analog switch
103
+ * return: true when gpio must be configured
104
+ */
105
+ static bool is_dualpad_switch_gpio_configurable (PinName pin , int function , uint32_t * pLL_AnalogSwitch )
73
106
{
74
107
PinAnalogSwitch * AnalogSwitch = (PinAnalogSwitch * ) PinMapAnalogSwitch ;
75
108
76
109
/* Read through PinMapAnalogSwitch array */
77
110
while (AnalogSwitch -> pin != NC ) {
78
111
/* Check whether pin is or is associated to dualpad Analog Input */
79
112
if ((AnalogSwitch -> pin | PDUAL ) == (pin | PDUAL )) {
80
- if (((function & STM_MODE_ANALOG ) != STM_MODE_ANALOG )
113
+ * pLL_AnalogSwitch = AnalogSwitch -> LL_AnalogSwitch ;
114
+ if (((function & STM_MODE_ANALOG ) == STM_MODE_ANALOG )
81
115
&& ((pin & PDUAL ) == PDUAL )) {
82
116
/**
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
117
+ * We configure an analog function and the pin is an analog pad Pxy_C
118
+ * In this case gpio configuration must be skipped
85
119
*/
86
- LL_SYSCFG_CloseAnalogSwitch (AnalogSwitch -> LL_AnalogSwitch );
87
- return ;
120
+ return false;
88
121
} 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 ;
122
+ return true;
96
123
}
97
124
}
98
125
AnalogSwitch ++ ;
99
126
}
127
+ * pLL_AnalogSwitch = 0 ;
128
+ return true;
100
129
}
101
130
#endif /* DUALPAD_ANALOG_SWITCH */
102
131
@@ -168,6 +197,15 @@ void pin_function(PinName pin, int function)
168
197
}
169
198
#endif
170
199
200
+ #if defined(DUALPAD_ANALOG_SWITCH )
201
+ uint32_t LL_AnalogSwitch = 0 ;
202
+ if (!is_dualpad_switch_gpio_configurable (pin , function , & LL_AnalogSwitch )) {
203
+ /* Skip gpio configuration */
204
+ configure_dualpad_switch (pin , function , LL_AnalogSwitch );
205
+ return ;
206
+ }
207
+ #endif /* DUALPAD_ANALOG_SWITCH */
208
+
171
209
/* Enable GPIO clock */
172
210
GPIO_TypeDef * gpio = set_GPIO_Port_Clock (port );
173
211
@@ -235,7 +273,7 @@ void pin_function(PinName pin, int function)
235
273
pin_PullConfig (gpio , ll_pin , STM_PIN_PUPD (function ));
236
274
237
275
#if defined(DUALPAD_ANALOG_SWITCH )
238
- configure_dualpad_switch (pin , function );
276
+ configure_dualpad_switch (pin , function , LL_AnalogSwitch );
239
277
#endif /* DUALPAD_ANALOG_SWITCH */
240
278
241
279
pin_DisconnectDebug (pin );
0 commit comments