add incremental encoder functions
This commit is contained in:
parent
96a831ae9e
commit
30a898b7cc
4 changed files with 71 additions and 3 deletions
|
@ -237,7 +237,11 @@ int Timer_encoder_getAngle(TIM_TypeDef * timer)
|
|||
return LL_TIM_GetCounter(timer);
|
||||
}
|
||||
|
||||
int Timer_encoder_getDirection(TIM_TypeDef * timer)
|
||||
enum CounterDirection Timer_encoder_getDirection(TIM_TypeDef * timer)
|
||||
{
|
||||
return LL_TIM_GetDirection(timer);
|
||||
const int dir = LL_TIM_GetDirection(timer);
|
||||
if (dir == LL_TIM_COUNTERDIRECTION_UP)
|
||||
return CLOCKWISE;
|
||||
else
|
||||
return COUNTER_CLOCKWISE;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,13 @@
|
|||
#define TIMER_H
|
||||
|
||||
#include "stm32f103xb.h"
|
||||
#include "stm32f1xx_ll_tim.h" // Pour les timers
|
||||
|
||||
enum CounterDirection {
|
||||
CLOCKWISE = LL_TIM_COUNTERDIRECTION_UP,
|
||||
COUNTER_CLOCKWISE = LL_TIM_COUNTERDIRECTION_DOWN,
|
||||
};
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* INTERRUPTIONS
|
||||
|
@ -125,6 +132,6 @@ int Timer_encoder_getAngle(TIM_TypeDef * timer);
|
|||
* @param TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4
|
||||
* @retval None
|
||||
*/
|
||||
int Timer_encoder_getDirection(TIM_TypeDef * timer);
|
||||
enum CounterDirection Timer_encoder_getDirection(TIM_TypeDef * timer);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1 +1,24 @@
|
|||
#include "IncrementalEncoder.h"
|
||||
|
||||
#include "Timer.h"
|
||||
|
||||
void IncrementalEncoder_conf(TIM_TypeDef * timer)
|
||||
{
|
||||
Timer_encoder_conf(timer);
|
||||
// TODO GPIO config
|
||||
}
|
||||
|
||||
void IncrementalEncoder_start(TIM_TypeDef * timer)
|
||||
{
|
||||
Timer_start(timer);
|
||||
}
|
||||
|
||||
int IncrementalEncoder_getAngle(TIM_TypeDef * timer)
|
||||
{
|
||||
return Timer_encoder_getAngle(timer);
|
||||
}
|
||||
|
||||
enum CounterDirection IncrementalEncoder_getDirection(TIM_TypeDef * timer)
|
||||
{
|
||||
return Timer_encoder_getDirection(timer);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,38 @@
|
|||
#ifndef INC_ENCODER_H
|
||||
#define INC_ENCODER_H
|
||||
|
||||
#include "stm32f103xb.h"
|
||||
|
||||
/**
|
||||
* @brief Configure le codeur incrémental associé au timer donné
|
||||
* @note
|
||||
* @param TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4
|
||||
* @retval None
|
||||
*/
|
||||
void IncrementalEncoder_conf(TIM_TypeDef * timer);
|
||||
|
||||
/**
|
||||
* @brief Démarre le codeur incrémental associé au timer donné
|
||||
* @note
|
||||
* @param TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4
|
||||
* @retval None
|
||||
*/
|
||||
void IncrementalEncoder_start(TIM_TypeDef * timer);
|
||||
|
||||
/**
|
||||
* @brief Récupère l'angle du codeur incrémental associé au timer donné
|
||||
* @note
|
||||
* @param TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4
|
||||
* @retval int angle
|
||||
*/
|
||||
int IncrementalEncoder_getAngle(TIM_TypeDef * timer);
|
||||
|
||||
/**
|
||||
* @brief Récupère la direction du codeur incrémental associé au timer donné
|
||||
* @note
|
||||
* @param TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4
|
||||
* @retval int dir
|
||||
*/
|
||||
enum CounterDirection IncrementalEncoder_getDirection(TIM_TypeDef * timer);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue