max11802.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /****************************************************************************
  2. * drivers/input/max11802.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. * "Low-Power, Ultra-Small Resistive Touch-Screen Controllers
  22. * with I2C/SPI Interface" Maxim IC, Rev 3, 10/2010
  23. */
  24. #ifndef __DRIVERS_INPUT_MAX11802_H
  25. #define __DRIVERS_INPUT_MAX11802_H
  26. /****************************************************************************
  27. * Included Files
  28. ****************************************************************************/
  29. #include <nuttx/config.h>
  30. #include <stdint.h>
  31. #include <poll.h>
  32. #include <nuttx/wqueue.h>
  33. #include <nuttx/wdog.h>
  34. #include <nuttx/clock.h>
  35. #include <nuttx/semaphore.h>
  36. #include <nuttx/spi/spi.h>
  37. #include <nuttx/input/max11802.h>
  38. /****************************************************************************
  39. * Pre-processor Definitions
  40. ****************************************************************************/
  41. /* MAX11802 Interfaces ******************************************************/
  42. /* LSB of register addresses specifies read (1) or write (0). */
  43. #define MAX11802_CMD_XPOSITION ((0x52 << 1) | 1)
  44. #define MAX11802_CMD_YPOSITION ((0x54 << 1) | 1)
  45. #define MAX11802_CMD_MEASUREXY (0x70 << 1)
  46. #define MAX11802_CMD_MODE_WR (0x0B << 1)
  47. #define MAX11802_CMD_MODE_RD ((0x0B << 1) | 1)
  48. #define MAX11802_CMD_AVG_WR (0x03 << 1)
  49. #define MAX11802_CMD_SAMPLE_WR (0x04 << 1)
  50. #define MAX11802_CMD_TIMING_WR (0x05 << 1)
  51. #define MAX11802_CMD_DELAY_WR (0x06 << 1)
  52. #define MAX11802_CMD_PULL_WR (0x07 << 1)
  53. /* Register values to set */
  54. #define MAX11802_MODE 0x06
  55. #define MAX11802_AVG 0x55
  56. #define MAX11802_SAMPLE 0xAA
  57. #define MAX11802_TIMING 0x77
  58. #define MAX11802_DELAY 0x55
  59. #define MAX11802_PULL 0x33
  60. /* Driver support ***********************************************************/
  61. /* This format is used to construct the /dev/input[n] device driver path. It
  62. * defined here so that it will be used consistently in all places.
  63. */
  64. #define DEV_FORMAT "/dev/input%d"
  65. #define DEV_NAMELEN 16
  66. /* Poll the pen position while the pen is down at this rate (50MS): */
  67. #define MAX11802_WDOG_DELAY MSEC2TICK(50)
  68. /****************************************************************************
  69. * Public Types
  70. ****************************************************************************/
  71. /* This describes the state of one contact */
  72. enum max11802_contact_3
  73. {
  74. CONTACT_NONE = 0, /* No contact */
  75. CONTACT_DOWN, /* First contact */
  76. CONTACT_MOVE, /* Same contact, possibly different position */
  77. CONTACT_UP, /* Contact lost */
  78. };
  79. /* This structure describes the results of one MAX11802 sample */
  80. struct max11802_sample_s
  81. {
  82. uint8_t id; /* Sampled touch point ID */
  83. uint8_t contact; /* Contact state (see enum ads7843e_contact_e) */
  84. bool valid; /* True: x,y contain valid, sampled data */
  85. uint16_t x; /* Measured X position */
  86. uint16_t y; /* Measured Y position */
  87. };
  88. /* This structure describes the state of one MAX11802 driver instance */
  89. struct max11802_dev_s
  90. {
  91. #ifdef CONFIG_ADS7843E_MULTIPLE
  92. FAR struct ads7843e_dev_s *flink; /* Supports a singly linked list of drivers */
  93. #endif
  94. uint8_t nwaiters; /* Number of threads waiting for MAX11802 data */
  95. uint8_t id; /* Current touch point ID */
  96. volatile bool penchange; /* An unreported event is buffered */
  97. uint16_t threshx; /* Thresholding X value */
  98. uint16_t threshy; /* Thresholding Y value */
  99. sem_t devsem; /* Manages exclusive access to this structure */
  100. sem_t waitsem; /* Used to wait for the availability of data */
  101. FAR struct max11802_config_s *config; /* Board configuration data */
  102. FAR struct spi_dev_s *spi; /* Saved SPI driver instance */
  103. struct work_s work; /* Supports the interrupt handling "bottom half" */
  104. struct max11802_sample_s sample; /* Last sampled touch point data */
  105. struct wdog_s wdog; /* Poll the position while the pen is down */
  106. /* The following is a list if poll structures of threads waiting for
  107. * driver events. The 'struct pollfd' reference for each open is also
  108. * retained in the f_priv field of the 'struct file'.
  109. */
  110. struct pollfd *fds[CONFIG_MAX11802_NPOLLWAITERS];
  111. };
  112. /****************************************************************************
  113. * Public Function Prototypes
  114. ****************************************************************************/
  115. #ifdef __cplusplus
  116. #define EXTERN extern "C"
  117. extern "C"
  118. {
  119. #else
  120. #define EXTERN extern
  121. #endif
  122. #undef EXTERN
  123. #ifdef __cplusplus
  124. }
  125. #endif
  126. #endif /* __DRIVERS_INPUT_ADS7843E_H */