synaptics_touchpad.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /**
  2. * Copyright (c) 2009 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef SYNAPTICS_TOUCHPAD_H
  41. #define SYNAPTICS_TOUCHPAD_H
  42. /*lint ++flb "Enter library region" */
  43. #include <stdbool.h>
  44. #include <stdint.h>
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. /** @file
  49. * @brief Synaptics Touchpad driver
  50. *
  51. *
  52. * @defgroup nrf_drivers_synaptics_touchpad Synaptics Touchpad driver
  53. * @{
  54. * @ingroup ext_drivers
  55. * @brief Synaptics Touchpad driver.
  56. */
  57. /**
  58. Touchpad register addresses.
  59. */
  60. #define TOUCHPAD_INT_STATUS 0x14 //!< Interrupt status register
  61. #define TOUCHPAD_BUTTON_STATUS 0x41 //!< Button status register
  62. #define TOUCHPAD_FINGER0_REL 0x30 //!< First register in finger delta block
  63. #define TOUCHPAD_GESTURE_FLAGS 0x3A //!< Gesture flags 0
  64. #define TOUCHPAD_SCROLL 0x3F //!< Scroll zone X / horizontal multifinger scroll
  65. #define TOUCHPAD_CONTROL 0x42 //!< Device control register
  66. #define TOUCHPAD_COMMAND 0x8F //!< Device command register
  67. #define TOUCHPAD_RESET 0x54 //!< Address of reset
  68. #define TOUCHPAD_PAGESELECT 0xFF //!< Address of page select (can be found in every page at the same address)
  69. #define TOUCHPAD_PRODUCT_ID 0xA2 //!< Address of product ID string
  70. /**
  71. Operational states
  72. */
  73. typedef enum
  74. {
  75. SleepmodeNormal = 0x00, //!< Normal operation
  76. SleepmodeSensorSleep = 0x01 //!< Low power operation
  77. } TouchpadSleepMode_t;
  78. /**
  79. @brief Function for Touchpad initialization.
  80. @param device_address TWI address of the device in bits [6:0]
  81. @retval true Touchpad was successfully identified and initialized
  82. @retval false Unexpected product ID or communication failure
  83. */
  84. bool touchpad_init(uint8_t device_address);
  85. /**
  86. @brief Function for attempting to soft-reset the device.
  87. @retval true Reset succeeded
  88. @retval false Reset failed
  89. */
  90. bool touchpad_reset(void);
  91. /**
  92. @brief Function for reading the interrupt status register of the device. This clears all interrupts.
  93. @param interrupt_status Address to store interrupt status to.
  94. @retval true Register contents read successfully to interrupt_status
  95. @retval false Reading failed
  96. */
  97. bool touchpad_interrupt_status_read(uint8_t *interrupt_status);
  98. /**
  99. @brief Function for sleep mode configuration.
  100. @note In low power mode the touchpad do not generate interrupts from touch sensing.
  101. @param[in] mode Operational mode
  102. @retval true Sleep mode set successfully
  103. @retval false Sleep mode setting failed
  104. */
  105. bool touchpad_set_sleep_mode(TouchpadSleepMode_t mode);
  106. /**
  107. @brief Function for reading a touchpad register contents over TWI.
  108. @param[in] register_address Register address
  109. @param[out] value Pointer to a data buffer where read data will be stored
  110. @retval true Register read succeeded
  111. @retval false Register read failed
  112. */
  113. bool touchpad_read_register(uint8_t register_address, uint8_t *value);
  114. /**
  115. @brief Function for writing a touchpad register contents over TWI.
  116. @param[in] register_address Register address
  117. @param[in] value Value to write to register
  118. @retval true Register write succeeded
  119. @retval false Register write failed
  120. */
  121. bool touchpad_write_register(uint8_t register_address, uint8_t value);
  122. /**
  123. @brief Function for writing touchpad register contents over TWI.
  124. Writes one or more consecutive registers.
  125. @param[out] product_id Pointer to a address to store product ID. Memory must be allocated for product_id_bytes number of bytes.
  126. @param[in] product_id_bytes Number of bytes to read
  127. @retval true Product ID read succeeded
  128. @retval false Product ID read failed
  129. */
  130. bool touchpad_product_id_read(uint8_t *product_id, uint8_t product_id_bytes);
  131. /**
  132. @brief Function for reading and verifying touchpad's product ID.
  133. @retval true Product ID is what was expected
  134. @retval false Product ID was not what was expected
  135. */
  136. bool touchpad_product_id_verify(void);
  137. /**
  138. *@}
  139. **/
  140. /*lint --flb "Leave library region" */
  141. #ifdef __cplusplus
  142. }
  143. #endif
  144. #endif /* __TOUCHPAD_H__ */