#ifndef JQDRIVER_H_
#define JQDRIVER_H_

#include "base/define.h"
#include "hardware/gpio_cfg.h"
#include "hardware/adc_cfg.h"
#include "base/delay.h"


#define JQBUS_IDLE						JQBUS_W_1
#define JQBUS_RWIDLE					JQBUS_W_1


#define JQBUS_H_PLUS					300
#define JQBUS_L_PLUS          700
#define JQ_Read_AD_Sample_C  		 140
#define JQ_Read_AD_Sample_C_IDLE 80

extern volatile uint16_t JQ_FreeBack_MaxCur;
extern volatile uint16_t JQ_FreeBack_MaxTime;
extern volatile uint16_t JQ_FreeBack_MinCur;
extern volatile uint16_t JQ_FreeBack_MinTime;
extern volatile uint16_t JQ_CommEnd_MaxCur ;
extern volatile uint8_t JQ_CommEnd_CurEn ;


//@brief 读OTP
uint8_t JQ_ReadOTP(uint16_t netid,uint8_t otp_bgaddr,uint8_t read_count,uint8_t* readbuf);
//@breif 读取单发状态
uint8_t JQ_ReadState(uint16_t netid,uint8_t* state);
//@brief 写延时
void JQ_WriteDelay(uint16_t netid,uint16_t delay);
//@brief 读延时
uint8_t JQ_ReadDelay(uint16_t netid,uint16_t* delaybuf);
//@brief 启动UID扫描
void JQ_ScanUIDBegin(void);
//@brief 扫描模式读取UID
uint8_t JQ_ScanReadUID(uint16_t begnet,uint8_t* uidbuf);
//@brief 充电
void JQ_Chage(uint16_t bgnet);
//@brief 放电
void JQ_DisChage(void);
//@brief 复位
void JQ_Reset(void);
//@brief 使能起爆
void JQ_BoomActive(void);
//@brief 时钟校准
void JQ_TimeAmend(uint16_t cycle,uint16_t delay_ms);
//写OTP使能
void JQ_EnWOTP(void);
//@brief 写OTP

uint8_t JQ_WriteOTP(uint8_t otp_bgaddr,uint8_t write_count,uint8_t* writebuf);
/*
@breif 起爆命令
@param cmd_count 起爆命令发送次数
@param read_buf 读取ACK数据，1bit代表一个网络号
@param run_type  0 不读取应答信号 =1 读取应答信号 >1 读取应答信号，且强制反馈收到应答
*/

void JQ_BoomCmd(uint8_t cmd_count,uint8_t* read_buf,uint8_t run_type);
/*
@breif 起爆命令
@param plus_count 巡检脉冲个数
@rtv   巡检应答Ack 的脉冲个数
*/
uint16_t JQ_CheckerBoomCmd(uint16_t plus_count,uint16_t* us_shake);
//@breif 巡检
void JQ_Inspect(uint16_t maxcount,uint8_t* buf,uint8_t state);
//@brief 设置充电检测判线
void JQ_ChargJudge(uint8_t dac);
//@brief 验证密码
void JQ_VerifyPWD(uint8_t* pwd);
//@breif 读芯片ID
uint8_t JQ_ReadChipID(uint16_t netid,uint16_t* chipid);
//@brief 快速放电
void JQ_FastDisChage(uint8_t sw);
/*
@brief 通信反码信息初始化
*/
void JQ_FreeBack_Prapare(uint8_t enable_flag);
#endif
