#ifndef __XPT2046_SPI_H #define __XPT2046_SPI_H #include "stm32f0xx_gpio.h" #include "stm32f0xx_spi.h" #include "stm32f0xx_rcc.h" #include "stm32f0xx_exti.h" #include "stdint.h" #define TSC2046_GetCounts 10 /* 每次采集的次数,取其平均值 */ //XPT2046 与 STM32103VET6 的连线方式 //TP_DOUT PA6(MISO) 复用推挽输出 //TP_DIN PA7(MOSI) 复用推挽输出 //TP_DCLK PA5(SCK) 复用推挽输出 //TP_CS PA1 通用推挽输出 //TP_BUSY PC6 上拉输入 //TP_IRQ PA10 上拉输入 #define TP_BUSY_GPIO GPIOC #define TP_BUSY_PIN GPIO_Pin_6 #define TP_CS_GPIO GPIOA #define TP_CS_PIN GPIO_Pin_1 #define TP_IRQ_GPIO GPIOA #define TP_IRQ_PIN GPIO_Pin_10 #define TP_SPI SPI1 #define TP_GetIRQStatus() GPIO_ReadInputDataBit(TP_IRQ_GPIO,TP_IRQ_PIN) //PC6->BUSY #define TP_WaitInq() GPIO_ReadInputDataBit(TP_IRQ_GPIO,TP_IRQ_PIN) //PC6->BUSY /* 获取芯片忙标志 */ //#define TP_GetBusyStatus() GPIO_ReadInputDataBit(TP_BUSY_GPIO,TP_BUSY_PIN) //PC6->BUSY #define TP_GetBusyStatus() 0U /* 片选信号线 */ #define TP_CS_HIGH() GPIO_SetBits(TP_CS_GPIO, TP_CS_PIN) #define TP_CS_LOW() GPIO_ResetBits(TP_CS_GPIO, TP_CS_PIN) #define TSC2046_CMD_CHY ((uint8_t)0x90) //1001 0000 差分方式读取Y位置 #define TSC2046_CMD_CHX ((uint8_t)0xD0) //1101 0000 差分方式读取X位置 void TSC2046_PinConfig(void); uint8_t TSC2046_Read_Single(uint16_t *X_Position, uint16_t *Y_Position); /* 中断处理方式时调用 */ void TSC2046_EXIT_Init(void); void TSC2046_NVIC_Config(void); void TSC2046_IntProccess(void); uint8_t TP_Read_XY(void); typedef struct { uint16_t u16cnt; uint8_t tpstate; uint8_t tpflag; uint8_t tpLedflag; uint16_t rf_X_add; uint16_t rf_Y_add; uint32_t tf_X_Y_add; uint16_t rf_tp[30]; } T_TP_CFG; /*------------------------------------------------------------------------------ * E X T E R N *------------------------------------------------------------------------------*/ extern T_TP_CFG gtTp; void TP_TASK(void); #endif