ads7843e.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /****************************************************************************
  2. * drivers/input/ads7843e.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. /* References:
  21. * "Touch Screen Controller, ADS7843," Burr-Brown Products from Texas
  22. * Instruments, SBAS090B, September 2000, Revised May 2002"
  23. *
  24. * See also:
  25. * "Low Voltage I/O Touch Screen Controller, TSC2046," Burr-Brown Products
  26. * from Texas Instruments, SBAS265F, October 2002, Revised August 2007."
  27. *
  28. * "XPT2046 Data Sheet," Shenzhen XPTek Technology Co., Ltd, 2007
  29. */
  30. #ifndef __DRIVERS_INPUT_ADS7843E_H
  31. #define __DRIVERS_INPUT_ADS7843E_H
  32. /****************************************************************************
  33. * Included Files
  34. ****************************************************************************/
  35. #include <nuttx/config.h>
  36. #include <stdint.h>
  37. #include <poll.h>
  38. #include <nuttx/wqueue.h>
  39. #include <nuttx/wdog.h>
  40. #include <nuttx/clock.h>
  41. #include <nuttx/semaphore.h>
  42. #include <nuttx/spi/spi.h>
  43. #include <nuttx/input/ads7843e.h>
  44. /****************************************************************************
  45. * Pre-processor Definitions
  46. ****************************************************************************/
  47. /* Configuration ************************************************************/
  48. /* Reference counting is partially implemented, but not needed in the current
  49. * design.
  50. */
  51. #undef CONFIG_ADS7843E_REFCNT
  52. /* ADS7843E Interfaces ******************************************************/
  53. /* ADS7843E command bit settings */
  54. #define ADS7843E_CMD_PD0 (1 << 0) /* Bit 0: Power down mode select bit 0 */
  55. #define ADS7843E_CMD_PD1 (1 << 1) /* Bit 1: Power down mode select bit 1 */
  56. #define ADS7843E_CMD_SER (1 << 2) /* Bit 2: SER/DFR\: 0:DFR 1:SER */
  57. #define ADS7843E_CMD_MODE8 (1 << 3) /* Bit 3: Mode 1:8-bits 0:12-bits */
  58. #define ADS7843E_CMD_CHAN_SHIFT (4) /* Bits 4-6: Channel select bits */
  59. #define ADS7843E_CMD_CHAN_MASK (7 << ADS7843E_CMD_CHAN_SHIFT)
  60. #define ADS7843E_CMD_START (1 << 7) /* Bit 7: Start Bit */
  61. /* ADS7843E Commands */
  62. #define ADS7843_CMD_YPOSITION \
  63. ((1 << ADS7843E_CMD_CHAN_SHIFT)| ADS7843E_CMD_START | ADS7843E_CMD_PD0 | ADS7843E_CMD_PD1)
  64. #define ADS7843_CMD_XPOSITION \
  65. ((5 << ADS7843E_CMD_CHAN_SHIFT)| ADS7843E_CMD_START | ADS7843E_CMD_PD0 | ADS7843E_CMD_PD1)
  66. #define ADS7843_CMD_ENABPENIRQ \
  67. ((1 << ADS7843E_CMD_CHAN_SHIFT)| ADS7843E_CMD_START)
  68. /* Driver support ***********************************************************/
  69. /* This format is used to construct the /dev/input[n] device driver path. It
  70. * defined here so that it will be used consistently in all places.
  71. */
  72. #define DEV_FORMAT "/dev/input%d"
  73. #define DEV_NAMELEN 16
  74. /* Poll the pen position while the pen is down at this rate (50MS): */
  75. #define ADS7843E_WDOG_DELAY MSEC2TICK(50)
  76. /****************************************************************************
  77. * Public Types
  78. ****************************************************************************/
  79. /* This describes the state of one contact */
  80. enum ads7843e_contact_e
  81. {
  82. CONTACT_NONE = 0, /* No contact */
  83. CONTACT_DOWN, /* First contact */
  84. CONTACT_MOVE, /* Same contact, possibly different position */
  85. CONTACT_UP, /* Contact lost */
  86. };
  87. /* This structure describes the results of one ADS7843E sample */
  88. struct ads7843e_sample_s
  89. {
  90. uint8_t id; /* Sampled touch point ID */
  91. uint8_t contact; /* Contact state (see enum ads7843e_contact_e) */
  92. bool valid; /* True: x,y contain valid, sampled data */
  93. uint16_t x; /* Measured X position */
  94. uint16_t y; /* Measured Y position */
  95. };
  96. /* This structure describes the state of one ADS7843E driver instance */
  97. struct ads7843e_dev_s
  98. {
  99. #ifdef CONFIG_ADS7843E_MULTIPLE
  100. FAR struct ads7843e_dev_s *flink; /* Supports a singly linked list of drivers */
  101. #endif
  102. #ifdef CONFIG_ADS7843E_REFCNT
  103. uint8_t crefs; /* Number of times the device has been opened */
  104. #endif
  105. uint8_t nwaiters; /* Number of threads waiting for ADS7843E data */
  106. uint8_t id; /* Current touch point ID */
  107. volatile bool penchange; /* An unreported event is buffered */
  108. uint16_t threshx; /* Thresholding X value */
  109. uint16_t threshy; /* Thresholding Y value */
  110. sem_t devsem; /* Manages exclusive access to this structure */
  111. sem_t waitsem; /* Used to wait for the availability of data */
  112. FAR struct ads7843e_config_s *config; /* Board configuration data */
  113. FAR struct spi_dev_s *spi; /* Saved SPI driver instance */
  114. struct work_s work; /* Supports the interrupt handling "bottom half" */
  115. struct ads7843e_sample_s sample; /* Last sampled touch point data */
  116. struct wdog_s wdog; /* Poll the position while the pen is down */
  117. /* The following is a list if poll structures of threads waiting for
  118. * driver events. The 'struct pollfd' reference for each open is also
  119. * retained in the f_priv field of the 'struct file'.
  120. */
  121. struct pollfd *fds[CONFIG_ADS7843E_NPOLLWAITERS];
  122. };
  123. /****************************************************************************
  124. * Public Function Prototypes
  125. ****************************************************************************/
  126. #ifdef __cplusplus
  127. #define EXTERN extern "C"
  128. extern "C"
  129. {
  130. #else
  131. #define EXTERN extern
  132. #endif
  133. #undef EXTERN
  134. #ifdef __cplusplus
  135. }
  136. #endif
  137. #endif /* __DRIVERS_INPUT_ADS7843E_H */