Skip to content

Commit f8ddc9c

Browse files
ABOSTMfpistm
authored andcommitted
Manage dualpad analog switch
Currently only H7 is concerned. MP1 hardware also have dualpad analog switch but behavior is different and in our case, switch should always remain open. Signed-off-by: Alexandre Bourdiol <[email protected]>
1 parent 088209c commit f8ddc9c

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

libraries/SrcWrapper/src/stm32/pinmap.c

+61
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,28 @@
2323
#include "lock_resource.h"
2424
#endif
2525

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+
2648
/* Map STM_PIN to LL */
2749
const uint32_t pin_map_ll[16] = {
2850
LL_GPIO_PIN_0,
@@ -43,6 +65,41 @@ const uint32_t pin_map_ll[16] = {
4365
LL_GPIO_PIN_15
4466
};
4567

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+
46103
bool pin_in_pinmap(PinName pin, const PinMap *map)
47104
{
48105
if (pin != (PinName)NC) {
@@ -177,6 +234,10 @@ void pin_function(PinName pin, int function)
177234

178235
pin_PullConfig(gpio, ll_pin, STM_PIN_PUPD(function));
179236

237+
#if defined(DUALPAD_ANALOG_SWITCH)
238+
configure_dualpad_switch(pin, function);
239+
#endif /* DUALPAD_ANALOG_SWITCH */
240+
180241
pin_DisconnectDebug(pin);
181242

182243
hsem_unlock(CFG_HW_GPIO_SEMID);

0 commit comments

Comments
 (0)