#ifndef _Encoder_H__
#define _Encoder_H__
#include "foc/core/PI_Controller.h"
typedef struct {
	bool  b_index_found; //I 对齐
	float enc_offset;
	u32   enc_count_off;
	u8    motor_poles;
	float pwm_angle;
	u32   pwm_count;
	float abi_angle;
	float cali_angle;
	float interpolation;
	float pll_bandwidth_shadow;
	float pll_bandwidth;
	float position;
	PLL_t est_pll;
	bool  b_timer_ov;
	bool  b_lock_pos;
	bool  b_cali_err;
	u32   cpr;
	u32   last_cnt;
	u32   b_index_cnt;
	u32   last_us;
	s8    direction; //motor running dir, 逆时针 正，顺时针负
	float est_vel_counts; //每秒多少个计数
	float est_angle_counts;
	float rpm;
	u8   *encoder_off_count;
	s16  *encoder_off_map;
}encoder_t;

void encoder_init(void);
void encoder_init_clear(void);
float encoder_get_theta(void);
float encoder_get_speed(void);
void encoder_detect_offset(float angle);
void encoder_set_direction(s8 direction);
float encoder_get_vel_count(void);
void encoder_lock_position(bool enable);
bool encoder_detect_finish(void);
float encoder_get_pwm_angle(void);
float encoder_zero_phase_detect(float *enc_off);
bool ENC_Check_error(void);
float encoder_get_abi_angle(void);
float encoder_get_position(void);
void encoder_detect_upload(void);
void encoder_clear_cnt_offset(void);
u32 encoder_get_cnt_offset(void);
bool encoder_get_cali_error(void);

#endif /* _Encoder_H__ */

