SimpleFOClibrary 2.4.0
Loading...
Searching...
No Matches
stm32g4_utils.cpp
Go to the documentation of this file.
1#include "../stm32_adc_utils.h"
2
3#if defined(STM32G4xx) && !defined(ARDUINO_B_G431B_ESC1)
4
5// timer to injected TRGO
6// https://github.com/stm32duino/Arduino_Core_STM32/blob/6588dee03382e73ed42c4a5e473900ab3b79d6e4/system/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_adc_ex.h#L217
7uint32_t _timerToInjectedTRGO(TIM_HandleTypeDef* timer){
8 if(timer->Instance == TIM1)
9 return ADC_EXTERNALTRIGINJEC_T1_TRGO;
10#ifdef TIM2 // if defined timer 2
11 else if(timer->Instance == TIM2)
12 return ADC_EXTERNALTRIGINJEC_T2_TRGO;
13#endif
14#ifdef TIM3 // if defined timer 3
15 else if(timer->Instance == TIM3)
16 return ADC_EXTERNALTRIGINJEC_T3_TRGO;
17#endif
18#ifdef TIM4 // if defined timer 4
19 else if(timer->Instance == TIM4)
20 return ADC_EXTERNALTRIGINJEC_T4_TRGO;
21#endif
22#ifdef TIM6 // if defined timer 6
23 else if(timer->Instance == TIM6)
24 return ADC_EXTERNALTRIGINJEC_T6_TRGO;
25#endif
26#ifdef TIM7 // if defined timer 7
27 else if(timer->Instance == TIM7)
28 return ADC_EXTERNALTRIGINJEC_T7_TRGO;
29#endif
30#ifdef TIM8 // if defined timer 8
31 else if(timer->Instance == TIM8)
32 return ADC_EXTERNALTRIGINJEC_T8_TRGO;
33#endif
34#ifdef TIM15 // if defined timer 15
35 else if(timer->Instance == TIM15)
36 return ADC_EXTERNALTRIGINJEC_T15_TRGO;
37#endif
38#ifdef TIM20 // if defined timer 15
39 else if(timer->Instance == TIM20)
40 return ADC_EXTERNALTRIGINJEC_T20_TRGO;
41#endif
42 else
43 return _TRGO_NOT_AVAILABLE;
44}
45
46// timer to regular TRGO
47// https://github.com/stm32duino/Arduino_Core_STM32/blob/6588dee03382e73ed42c4a5e473900ab3b79d6e4/system/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_adc.h#L519
48uint32_t _timerToRegularTRGO(TIM_HandleTypeDef* timer){
49 if(timer->Instance == TIM1)
50 return ADC_EXTERNALTRIG_T1_TRGO;
51#ifdef TIM2 // if defined timer 2
52 else if(timer->Instance == TIM2)
53 return ADC_EXTERNALTRIG_T2_TRGO;
54#endif
55#ifdef TIM3 // if defined timer 3
56 else if(timer->Instance == TIM3)
57 return ADC_EXTERNALTRIG_T3_TRGO;
58#endif
59#ifdef TIM4 // if defined timer 4
60 else if(timer->Instance == TIM4)
61 return ADC_EXTERNALTRIG_T4_TRGO;
62#endif
63#ifdef TIM6 // if defined timer 6
64 else if(timer->Instance == TIM6)
65 return ADC_EXTERNALTRIG_T6_TRGO;
66#endif
67#ifdef TIM7 // if defined timer 7
68 else if(timer->Instance == TIM7)
69 return ADC_EXTERNALTRIG_T7_TRGO;
70#endif
71#ifdef TIM8 // if defined timer 8
72 else if(timer->Instance == TIM8)
73 return ADC_EXTERNALTRIG_T7_TRGO;
74#endif
75#ifdef TIM15 // if defined timer 15
76 else if(timer->Instance == TIM15)
77 return ADC_EXTERNALTRIG_T15_TRGO;
78#endif
79#ifdef TIM20 // if defined timer 15
80 else if(timer->Instance == TIM20)
81 return ADC_EXTERNALTRIG_T20_TRGO;
82#endif
83 else
84 return _TRGO_NOT_AVAILABLE;
85}
86
87#endif