TSC2046_spi.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef __XPT2046_SPI_H
  2. #define __XPT2046_SPI_H
  3. #include "stm32f0xx_gpio.h"
  4. #include "stm32f0xx_spi.h"
  5. #include "stm32f0xx_rcc.h"
  6. #include "stm32f0xx_exti.h"
  7. #include "stdint.h"
  8. #define TSC2046_GetCounts 10 /* 每次采集的次数,取其平均值 */
  9. //XPT2046 与 STM32103VET6 的连线方式
  10. //TP_DOUT PA6(MISO) 复用推挽输出
  11. //TP_DIN PA7(MOSI) 复用推挽输出
  12. //TP_DCLK PA5(SCK) 复用推挽输出
  13. //TP_CS PA1 通用推挽输出
  14. //TP_BUSY PC6 上拉输入
  15. //TP_IRQ PA10 上拉输入
  16. #define TP_BUSY_GPIO GPIOC
  17. #define TP_BUSY_PIN GPIO_Pin_6
  18. #define TP_CS_GPIO GPIOA
  19. #define TP_CS_PIN GPIO_Pin_1
  20. #define TP_IRQ_GPIO GPIOA
  21. #define TP_IRQ_PIN GPIO_Pin_10
  22. #define TP_SPI SPI1
  23. #define TP_GetIRQStatus() GPIO_ReadInputDataBit(TP_IRQ_GPIO,TP_IRQ_PIN) //PC6->BUSY
  24. #define TP_WaitInq() GPIO_ReadInputDataBit(TP_IRQ_GPIO,TP_IRQ_PIN) //PC6->BUSY
  25. /* 获取芯片忙标志 */
  26. //#define TP_GetBusyStatus() GPIO_ReadInputDataBit(TP_BUSY_GPIO,TP_BUSY_PIN) //PC6->BUSY
  27. #define TP_GetBusyStatus() 0U
  28. /* 片选信号线 */
  29. #define TP_CS_HIGH() GPIO_SetBits(TP_CS_GPIO, TP_CS_PIN)
  30. #define TP_CS_LOW() GPIO_ResetBits(TP_CS_GPIO, TP_CS_PIN)
  31. #define TSC2046_CMD_CHY ((uint8_t)0x90) //1001 0000 差分方式读取Y位置
  32. #define TSC2046_CMD_CHX ((uint8_t)0xD0) //1101 0000 差分方式读取X位置
  33. void TSC2046_PinConfig(void);
  34. uint8_t TSC2046_Read_Single(uint16_t *X_Position, uint16_t *Y_Position);
  35. /* 中断处理方式时调用 */
  36. void TSC2046_EXIT_Init(void);
  37. void TSC2046_NVIC_Config(void);
  38. void TSC2046_IntProccess(void);
  39. uint8_t TP_Read_XY(void);
  40. typedef struct {
  41. uint16_t u16cnt;
  42. uint8_t tpstate;
  43. uint8_t tpflag;
  44. uint8_t tpLedflag;
  45. uint16_t rf_X_add;
  46. uint16_t rf_Y_add;
  47. uint32_t tf_X_Y_add;
  48. uint16_t rf_tp[30];
  49. } T_TP_CFG;
  50. /*------------------------------------------------------------------------------
  51. * E X T E R N
  52. *------------------------------------------------------------------------------*/
  53. extern T_TP_CFG gtTp;
  54. void TP_TASK(void);
  55. #endif