Browse Source

add incremental encoder functions

Arnaud Vergnet 3 years ago
parent
commit
30a898b7cc
4 changed files with 71 additions and 3 deletions
  1. 6
    2
      MyDrivers/Timer.c
  2. 8
    1
      MyDrivers/Timer.h
  3. 23
    0
      Services/IncrementalEncoder.c
  4. 34
    0
      Services/IncrementalEncoder.h

+ 6
- 2
MyDrivers/Timer.c View File

@@ -237,7 +237,11 @@ int Timer_encoder_getAngle(TIM_TypeDef * timer)
237 237
 	return LL_TIM_GetCounter(timer);
238 238
 }
239 239
 
240
-int Timer_encoder_getDirection(TIM_TypeDef * timer)
240
+enum CounterDirection Timer_encoder_getDirection(TIM_TypeDef * timer)
241 241
 {
242
-	return LL_TIM_GetDirection(timer);
242
+	const int dir = LL_TIM_GetDirection(timer);
243
+	if (dir == LL_TIM_COUNTERDIRECTION_UP)
244
+		return CLOCKWISE;
245
+	else
246
+		return COUNTER_CLOCKWISE;
243 247
 }

+ 8
- 1
MyDrivers/Timer.h View File

@@ -2,6 +2,13 @@
2 2
 #define TIMER_H
3 3
 
4 4
 #include "stm32f103xb.h" 
5
+#include "stm32f1xx_ll_tim.h" // Pour les timers
6
+
7
+enum CounterDirection {
8
+	CLOCKWISE = LL_TIM_COUNTERDIRECTION_UP,
9
+	COUNTER_CLOCKWISE = LL_TIM_COUNTERDIRECTION_DOWN,
10
+};
11
+
5 12
 
6 13
 /****************************************************************************
7 14
   *																	INTERRUPTIONS
@@ -125,6 +132,6 @@ int Timer_encoder_getAngle(TIM_TypeDef * timer);
125 132
 	* @param  TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4
126 133
   * @retval None
127 134
   */
128
-int Timer_encoder_getDirection(TIM_TypeDef * timer);
135
+enum CounterDirection Timer_encoder_getDirection(TIM_TypeDef * timer);
129 136
 
130 137
 #endif

+ 23
- 0
Services/IncrementalEncoder.c View File

@@ -1 +1,24 @@
1 1
 #include "IncrementalEncoder.h"
2
+
3
+#include "Timer.h"
4
+
5
+void IncrementalEncoder_conf(TIM_TypeDef * timer)
6
+{
7
+	Timer_encoder_conf(timer);
8
+	// TODO GPIO config
9
+}
10
+
11
+void IncrementalEncoder_start(TIM_TypeDef * timer)
12
+{
13
+	Timer_start(timer);
14
+}
15
+
16
+int IncrementalEncoder_getAngle(TIM_TypeDef * timer)
17
+{
18
+	return Timer_encoder_getAngle(timer);
19
+}
20
+
21
+enum CounterDirection IncrementalEncoder_getDirection(TIM_TypeDef * timer)
22
+{
23
+	return Timer_encoder_getDirection(timer);
24
+}

+ 34
- 0
Services/IncrementalEncoder.h View File

@@ -1,4 +1,38 @@
1 1
 #ifndef INC_ENCODER_H
2 2
 #define INC_ENCODER_H
3 3
 
4
+#include "stm32f103xb.h"
5
+
6
+/**
7
+	* @brief  Configure le codeur incrémental associé au timer donné
8
+  * @note   
9
+	* @param  TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4
10
+  * @retval None
11
+  */
12
+void IncrementalEncoder_conf(TIM_TypeDef * timer);
13
+
14
+/**
15
+	* @brief  Démarre le codeur incrémental associé au timer donné
16
+  * @note   
17
+	* @param  TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4
18
+  * @retval None
19
+  */
20
+void IncrementalEncoder_start(TIM_TypeDef * timer);
21
+
22
+/**
23
+	* @brief  Récupère l'angle du codeur incrémental associé au timer donné
24
+  * @note   
25
+	* @param  TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4
26
+  * @retval int angle
27
+  */
28
+int IncrementalEncoder_getAngle(TIM_TypeDef * timer);
29
+
30
+/**
31
+	* @brief  Récupère la direction du codeur incrémental associé au timer donné
32
+  * @note   
33
+	* @param  TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4
34
+  * @retval int dir
35
+  */
36
+enum CounterDirection IncrementalEncoder_getDirection(TIM_TypeDef * timer);
37
+
4 38
 #endif

Loading…
Cancel
Save