#ifndef _HALL_SENSOR_H__
#define _HALL_SENSOR_H__
#include "libs/types.h"
#include "hal/hal.h"

#define NEGATIVE          (int8_t)-1
#define POSITIVE          (int8_t)1

#define STATE_0 (uint8_t)0
#define STATE_1 (uint8_t)1
#define STATE_2 (uint8_t)2
#define STATE_3 (uint8_t)3
#define STATE_4 (uint8_t)4
#define STATE_5 (uint8_t)5
#define STATE_6 (uint8_t)6
#define STATE_7 (uint8_t)7

#define THETA_NONE        (float)0xFFFF
typedef struct {
	bool  alignmnet;
	float theta;
	float est_theta;
	float e_rpm;        //每分钟转速，电转速，不是机械转速
	u8    state;
	u32   ticks;
	bool  working;
	s8    direction;
	float degree_per_s; //每秒度， ext: 10度/s
	float phase_offset;
}hall_t;

#define SAMPLE_MAX_COUNT 6

typedef struct {
	float angle[SAMPLE_MAX_COUNT];
	u32   ticks[SAMPLE_MAX_COUNT];
	u32   index;
	bool  full;
}hall_sample_t;

void hall_sensor_init(void);
float hall_sensor_get_theta(void); //return degree
float hall_sensor_get_speed(void); //return rpm
int hall_sensor_calibrate(float current, u16 *hall_table);

#endif /* _HALL_SENSOR_H__ */

