Skip to content

Commit 28415c1

Browse files
ABOSTMfpistm
authored andcommitted
Dual pad analog switch: skip gpio configuration in case of direct ADC
Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
1 parent 291cebc commit 28415c1

File tree

1 file changed

+52
-14
lines changed

1 file changed

+52
-14
lines changed

libraries/SrcWrapper/src/stm32/pinmap.c

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,35 +68,64 @@ const uint32_t pin_map_ll[16] = {
6868
#if defined(DUALPAD_ANALOG_SWITCH)
6969
/**
7070
* Configure Analog dualpad switch if necessary
71+
* LL_AnalogSwitch: LL define to be used to configure Analog switch
7172
*/
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)
73106
{
74107
PinAnalogSwitch *AnalogSwitch = (PinAnalogSwitch *) PinMapAnalogSwitch;
75108

76109
/* Read through PinMapAnalogSwitch array */
77110
while (AnalogSwitch->pin != NC) {
78111
/* Check whether pin is or is associated to dualpad Analog Input */
79112
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)
81115
&& ((pin & PDUAL) == PDUAL)) {
82116
/**
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
85119
*/
86-
LL_SYSCFG_CloseAnalogSwitch(AnalogSwitch->LL_AnalogSwitch);
87-
return ;
120+
return false;
88121
} 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;
96123
}
97124
}
98125
AnalogSwitch ++;
99126
}
127+
*pLL_AnalogSwitch = 0;
128+
return true;
100129
}
101130
#endif /* DUALPAD_ANALOG_SWITCH */
102131

@@ -168,6 +197,15 @@ void pin_function(PinName pin, int function)
168197
}
169198
#endif
170199

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+
171209
/* Enable GPIO clock */
172210
GPIO_TypeDef *gpio = set_GPIO_Port_Clock(port);
173211

@@ -235,7 +273,7 @@ void pin_function(PinName pin, int function)
235273
pin_PullConfig(gpio, ll_pin, STM_PIN_PUPD(function));
236274

237275
#if defined(DUALPAD_ANALOG_SWITCH)
238-
configure_dualpad_switch(pin, function);
276+
configure_dualpad_switch(pin, function, LL_AnalogSwitch);
239277
#endif /* DUALPAD_ANALOG_SWITCH */
240278

241279
pin_DisconnectDebug(pin);

0 commit comments

Comments
 (0)