/******************************************************************************
*Copyright(C),2024-2024,万众一芯生
*van_BSP_Pwm_pump.h
* pwm 控制泵阀驱动
*修改历史
author				范义东			新建				2024/01/27
******************************************************************************/

#ifndef __VAN_BSP_COM_PWM_H
#define __VAN_BSP_COM_PWM_H

#include "van_com_define.h"
#define MAX_PWM_VALUE  10000

typedef enum
{
	PWM_CHIPKK5 = 30000,
	PWM_PIPE = 30001,
	PWM_TOPCON = 30002,
	PWM_BOTCON = 30003,
	PWM_PERIS1 = 30020,
	PWM_PERIS2 = 30021,
	PWM_DIAPHR = 30022,
} enPWM_004_V1;
	
typedef enum {
  PWM_BUMP_ST_IDLE,
  PWM_BUMP_ST_RUN,
  PWM_BUMP_ST_FEEDERR, /*转速反馈异常*/
} COM_PWM_State;

typedef enum {
  COM_PWM_BASE,
  COM_PWM_8870, 		/*带方向*/
  COM_PWM_8873, /*带转速反馈*/
  COM_PWM_DIR_FEED_CNT, /*带方向转速反馈*/
} COM_PWM_Type;


typedef struct {
  unsigned int ID;              //泵编号
  unsigned char Name[16];       //泵名
  COM_PWM_State state;         //状态
  COM_PWM_Type type;			//类型
  void* timerHandle;            /*定时器端口*/
  unsigned int pwmChanle;       /*定时器通道*/
  void* feedbackTimer;          /*反馈定时器*/
  unsigned int feedbackChanlen; /*反馈通道*/
  void* dirPort;                /*方向端口*/
  unsigned int dirPin;          /*方向管脚*/
  unsigned int 	dirState;	  // 正向电平
  unsigned int feedbackconter;  /*反馈脉冲数*/
  float setValue;               /*设定值*/ 
  float getValue;               /*反馈值*/
  float range_Max;               /*范围*/  
  float range_Min;               /*范围*/  
  unsigned int plusconter;		/*转动脉冲计数*/
} VAN_COM_PWM_Def, *P_VAN_COM_PWM_Def;


void com_pwm_Set(unsigned int devId, float value);
unsigned int com_pwm_Getconter(unsigned int devId);
bool com_pwm_test(unsigned int Id, int value);
void show_com_pwm(void);
bool com_pwm_FindChanle(unsigned int devId, P_VAN_COM_PWM_Def *pdev);
bool PWM_Find_feed_By_ch(unsigned int devId, P_VAN_COM_PWM_Def *pdev);
void Paltform_Set_PWM_Pause(unsigned int id);
void Paltform_Set_PWM_Resume(unsigned int id);
void thread_Proportiona_ctrl(void* );
void com_feed_Add_Pulse(uint16_t GPIO_Pin);
void check_Pwm_Plus_feedOK(void);
void Paltform_Get_PWM_Current(void *param);
void Paltform_Set_PWM_Goal(void *param) ;
void Paltform_Set_PWM_Stop(void *param);
unsigned int load_com_pwm_Cfg(pDeviceBasicInfdef pDevice);
#endif
