#ifndef _ENC_INTF_H__
#define _ENC_INTF_H__
#include "os/os_types.h"
#include "bsp/bsp.h"

#define PWM_TIME_CLK 9000000U


#define ENC_DIR_UP 1
#define ENC_DIR_DOWN 2

#define ENC_PWM_Calc_P(t) ((float)t / (float)PWM_TIME_CLK)

#define ENC_COUNT TIMER_CNT(ENC_TIMER)

#define ENC_Direction() ((TIMER_CTL0(ENC_TIMER) & TIMER_CTL0_DIR)?ENC_DIR_DOWN:ENC_DIR_UP)

#define ENC_OverFlow() ((TIMER_INTF(ENC_TIMER) & TIM_FLAG_UPDATE)?true:false)
#define ENC_ClearUpFlags() (TIMER_INTF(ENC_TIMER) = (~(uint32_t)TIM_FLAG_UPDATE))

void enc_intf_quadrature_init(u32 rate);
void enc_intf_pwm_counter(void);
void enc_intf_init(u32 rate);
float enc_get_pwm_freq(void);

#endif /*_ENC_INTF_H__*/

