#ifndef PY32_TK_H
#define PY32_TK_H

#ifdef __cplusplus
extern "C"
{
#endif
#include "py32t0xx.h"
#include <stdio.h>

#define __weak 							__attribute__((weak))
#define MIDAC_MODE 						1  		//基线检测
#define APP_REF							1	 	//上位机
#define TK_SAMP_SYNC_ENABLE				1		//同步采样
#define TK_SLIDER_ENABLE				1		//滑条使能
#define TK_WATERPROOF_ENABLE			1		//防水使能
#define TK_WATERDETECT_ENABLE			1		//检水使能
#define TK_LED_SACN						1		//TK扫描LED
#define TK_REF_ENABLE					1		//内部参考通道使能
#define TK_SLEEP_ENABLE					1		//休眠使能
#define TK_TICK_USAGE					0		//CPU占用测试
#define LIB_09X							0		//092&090

#define TK_STDIV2 	(0x00U)
#define TK_STDIV4 	(0x01U)
#define TK_STDIV8 	(0x02U)
#define TK_STDIV12 	(0x03U)
#define TK_STDIV16 	(0x04U)
#define TK_STDIV24 	(0x05U)
#define TK_STDIV32 	(0x06U)
#define TK_STDIV36 	(0x07U)
#define TK_STDIV48 	(0x08U)

#define TK_DIV0 	(0x00U)
#define TK_DIV2 	(0x02U)
#define TK_DIV3 	(0x03U)
#define TK_DIV4 	(0x04U)
#define TK_DIV5 	(0x05U)
#define TK_DIV6 	(0x06U)
#define TK_DIV7 	(0x07U)

#define TK_CFT0 	(0x00U)
#define TK_CFT1 	(0x01U)
#define TK_CFT2 	(0x02U)
#define TK_CFT3 	(0x03U)
#define TK_CFT4 	(0x04U)
#define TK_CFT5 	(0x05U)
#define TK_CFT6 	(0x06U)
#define TK_CFT7 	(0x07U)

#define TK_MIDACSTEP_0_5UA 	(0x00U)
#define TK_MIDACSTEP_2UA 	(0x01U)

#define TK_VCC1CR_1_6V (0x00U)
#define TK_VCC1CR_2_0V (0x01U)
#define TK_VCC1CR_2_4V (0x02U)
#define TK_VCC1CR_2_8V (0x03U)
#define TK_VCC1CR_3_2V (0x04U)
#define TK_VCC1CR_3_6V (0x05U)
#define TK_VCC1CR_4_0V (0x06U)
#define TK_VCC1CR_4_4V (0x07U)

#define TK_COPADATA_OUTPUT_LOW 			(0x00U)
#define TK_COPADATA_OUTPUT_HIGH 		(0x01U)
#define TK_COPADATA_OUTPUT_S1_INVERSE 	(0x02U)
#define TK_COPADATA_OUTPUT_S1 			(0x03U)

#define TK_KVREF_0_6V (0x00U)
#define TK_KVREF_1_0V (0x01U)
#define TK_KVREF_1_5V (0x02U)
#define TK_KVREF_2_0V (0x03U)

#define TK_SHORTSW_NUM_0 (0x00U)
#define TK_SHORTSW_NUM_1 (0x01U)
#define TK_SHORTSW_NUM_2 (0x02U)
#define TK_SHORTSW_NUM_3 (0x03U)

#define TK_LPABNORMAL_MODE0 (0x00U)
#define TK_LPABNORMAL_MODE1 (0x01U)

#define TK_CTRLSOURCE_SW (0x00U)
#define TK_CTRLSOURCE_HW (0x01U)

#define TK_PWMM_PWM (0x00U)
#define TK_PWMM_PRS (0x01U)

#if LIB_09X
#define MAX_CHS 			32
#define INTEREN_SWITCH      1
#else
#define MAX_CHS 			26
#define INTEREN_SWITCH      0 
#endif
#define SLIDER_MAX 			4
#define SHIELD_CHS 			0XF0
#define INSIDE_CHS 			0XF1
#define SLEEP_CHS 			0XF0
typedef enum
{
	TK_OK 		= 0x00U,
	TK_ERROR 	= 0x01U,
	TK_BUSY 	= 0x02U,
	TK_TIMEOUT 	= 0x03U
} TK_Status;
/**
 * @brief LL TK Init Structure definition
 */
typedef uint32_t TK_Keyflag_Type;
#pragma pack(4)
typedef struct __TK_HandleTypeDef
{
	uint16_t LpCdr;          // 唤醒值数据
	uint32_t LpIsr;
	uint8_t WakeDelay; 
	uint8_t TrimState;  	   // 自适应状态
	uint8_t TrimRatio; 			// 校准窗口范围
	uint8_t CopaMode;          // 按键补偿使能
	uint8_t TrimIdac[MAX_CHS]; // 自适应电流值
	uint8_t RefIdac[2];
	uint8_t ShieldIdac[2];
	uint16_t Win;             	// 窗口时间
	TK_Keyflag_Type CopaChs;  	// IO补偿使能
	TK_Keyflag_Type TrimStep; 	// 自适应电流档位
	TK_Keyflag_Type Kenable; 	// 通道使能
	uint8_t RefStep;
} TK_HandleTypeDef;
#pragma pack()
void TK_SetSenseStart(uint32_t Chs, uint8_t TrimStep, uint8_t Midac); // 开始执行触摸扫描
void TK_LibInit(void);                                                // 触摸库初始化
void TK_LibDeInit(void);                                              // 触摸库
extern TK_HandleTypeDef TK_Handle;
#ifdef __cplusplus
}
#endif
/************************ (C) COPYRIGHT Puya *****END OF FILE******************/

#endif
