/**
  ******************************************************************************
  * @file    vk3816.h 
  * @author  
  * @version V1.0.0
  * @date    12-17-2025
  * @brief   Header files for vk3816
  ******************************************************************************
  * @attention
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __vk3816_H
#define __vk3816_H

/* Includes ------------------------------------------------------------------*/
//此包含文件根据客户单片机做相应的修改
#include "M451Series.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported define -----------------------------------------------------------*/
#define OK	 							0	
#define FAIL	 						1	  

//基本设置
//I2C地址
//#define VK3816_ADDR            0x50 //A1=0 A2=0
//#define VK3816_ADDR            0x51 //A1=0 A2=1
//#define VK3816_ADDR            0x52 //A1=1 A2=0
//#define VK3816_ADDR            0x53 //A1=1 A2=1
//I2C地址写
//#define VK3816_ADDRWR            0xA0//A1=0 A2=0
//#define VK3816_ADDRWR            0xA2 //A1=0 A2=1
//#define VK3816_ADDRWR            0xA4 //A1=1 A2=0
#define VK3816_ADDRWR            0xA6 //A1=1 A2=1
//I2C地址读
//#define VK3816_ADDRRD          0xA1//A1=0 A2=0
//#define VK3816_ADDRRD            0xA3 //A1=0 A2=1
//#define VK3816_ADDRRD            0xA5 //A1=1 A2=0
#define VK3816_ADDRRD            0xA7 //A1=1 A2=1
//设置命令
//Data byte 1 配置
#define I2CM_PCLINK                0x00//按键模式
#define I2CM_Slide                 0x80//滑条模式 def

#define Output_Multiple            0x00//多键
#define Output_Single              0x20//单键 def

#define AutoAdjust_Off             0x00//基准值自动调整关闭
#define AutoAdjust_On              0x10//基准值自动调整开启 def

#define PowerSave_Off              0x00//省电模式关闭
#define PowerSave_On               0x08//省电模式开启 def

#define DT_Off                     0x00//动态阈值关闭 def
#define DT_On                      0x04//动态阈值开启 

//自动重置时间配置
#define AutoResetTime_Off          0x00//自动重置时间关闭
#define AutoResetTime_15S          0x01//自动重置时间15S def
#define AutoResetTime_30S          0x02//自动重置时间30S
#define AutoResetTime_60S          0x03//自动重置时间60S

//Data byte 2 按键数配置
#define KeyNum_Off                 0x00
#define KeyNum_1                   0x08//1 key
#define KeyNum_2                   0x10//2 keys
#define KeyNum_3                   0x18//3 keys
#define KeyNum_4                   0x20//4 keys
#define KeyNum_5                   0x28//5 keys
#define KeyNum_6                   0x30//6 keys
#define KeyNum_7                   0x38//7 keys
#define KeyNum_8                   0x40//8 keys
#define KeyNum_9                   0x48//9 keys
#define KeyNum_10                  0x50//10 keys
#define KeyNum_11                  0x58//11 keys
#define KeyNum_12                  0x60//12 keys
#define KeyNum_13                  0x68//13 keys
#define KeyNum_14                  0x70//14 keys
#define KeyNum_15                  0x78//15 keys
#define KeyNum_16                  0x80//16 keys def

// 按键消抖时间配置 
#define KEY_ACK_TIME_1           0x00  // 1次
#define KEY_ACK_TIME_2           0x01  // 2次
#define KEY_ACK_TIME_3           0x02  // 3次
#define KEY_ACK_TIME_4           0x03  // 4次 (def)
#define KEY_ACK_TIME_5           0x04  // 5次
#define KEY_ACK_TIME_6           0x05  // 6次
#define KEY_ACK_TIME_7           0x06  // 7次
#define KEY_ACK_TIME_8           0x07  // 8次

// Data byte 3 滑条配置
#define SlideNumSet_DISABLE      0x00  // 禁用滑条
#define SlideNumSet_DISABLE1     0x01  // 禁用滑条
#define SlideNumSet_3            0x02  // 3按键滑条
#define SlideNumSet_4            0x03  // 4按键滑条
#define SlideNumSet_5            0x04  // 5按键滑条
#define SlideNumSet_6            0x05  // 6按键滑条
#define SlideNumSet_7            0x06  // 7按键滑条
#define SlideNumSet_8            0x07  // 8按键滑条
#define SlideNumSet_9            0x08  // 9按键滑条
#define SlideNumSet_10           0x09  // 10按键滑条
#define SlideNumSet_11           0x0A  // 11按键滑条
#define SlideNumSet_12           0x0B  // 12按键滑条
#define SlideNumSet_13           0x0C  // 13按键滑条
#define SlideNumSet_14           0x0D  // 14按键滑条
#define SlideNumSet_15           0x0E  // 15按键滑条
#define SlideNumSet_16           0x0F  // 16按键滑条


//Data byte 4
//多重按键配置
#define KeyOffNum_DISABLE        0x00  // 禁用 def
#define KeyOffNum_2              0x10  // 2按键重置
#define KeyOffNum_3              0x20  // 3按键重置
#define KeyOffNum_4              0x30  // 4按键重置
#define KeyOffNum_5              0x40  // 5按键重置
#define KeyOffNum_6              0x50  // 6按键重置
#define KeyOffNum_7              0x60  // 7按键重置
#define KeyOffNum_8              0x70  // 8按键重置
#define KeyOffNum_9              0x80  // 9按键重置
#define KeyOffNum_10             0x90  // 10按键重置
#define KeyOffNum_11             0xA0  // 11按键重置
#define KeyOffNum_12             0xB0  // 12按键重置
#define KeyOffNum_13             0xC0  // 13按键重置
#define KeyOffNum_14             0xD0  // 14按键重置
#define KeyOffNum_15             0xE0  // 15按键重置
#define KeyOffNum_16             0xF0  // 16按键重置

// 自定义阈值命令 
#define CUSTOM_THRESHOLD_CMD_BASE  0xC0  // IICM=1, CT=1, Item=0
#define SLEEP_THRESHOLD_CMD        0xD0  // IICM=1, CT=1, Item=1

// 默认阈值设置
#define DEFAULT_THRESHOLD          0x010  // 默认阈值0x010
#define SLEEP_THRESHOLD            0x002  // 睡眠唤醒阈值0x002

//以下管脚配置根据客户单片机做相应的修改 
#define VK3816_SCL_PIN           BIT15
#define VK3816_SCL_PORT          PB
#define VK3816_SCL_IO            PB15

#define VK3816_SDA_PIN           BIT5
#define VK3816_SDA_PORT          PB
#define VK3816_SDA_IO            PB5

#define VK3816_INT_PIN           BIT12
#define VK3816_INT_PORT          PB
#define VK3816_INT_IO            PB12

//以下管脚输出定义根据客户单片机做相应的修改
#define VK3816_SCL_H() VK3816_SCL_IO = 1
#define VK3816_SCL_L() VK3816_SCL_IO = 0

#define VK3816_SDA_H() VK3816_SDA_IO = 1
#define VK3816_SDA_L() VK3816_SDA_IO = 0

#define VK3816_GET_SDA() 	VK3816_SDA_IO
#define VK3816_GET_INT() 	VK3816_INT_IO

/* Exported functions ------------------------------------------------------- */
unsigned char VK3816SetCmd(unsigned char *pdata,unsigned char cnt);
unsigned char VK3816ReaData(unsigned char *pdata,unsigned char cnt);
void VK3816_Init(void);
void VK3816_Main(void);

unsigned char VK3816_SetSlideConfig(unsigned char slide1_keys, unsigned char slide2_keys, unsigned char slide3_keys);
unsigned char VK3816_SetThreshold(unsigned char tp_num, unsigned int threshold);
unsigned char VK3816_SetAllThresholds(unsigned int threshold);
unsigned char VK3816_SetSleepThreshold(unsigned int threshold);
#endif  /*__vk3816_H*/

/************************END OF FILE****/
