adns2080.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /**
  2. * Copyright (c) 2009 - 2018, 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 ADNS2080_H
  41. #define ADNS2080_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 ADNS2080 mouse sensor driver
  50. *
  51. * @defgroup nrf_drivers_adns2080 ADNS2080 driver
  52. * @{
  53. * @ingroup ext_drivers
  54. * @brief ADNS2080 mouse sensor driver.
  55. */
  56. /**
  57. * Describes return values for @ref adns2080_init.
  58. */
  59. typedef enum
  60. {
  61. ADNS2080_OK, /*!< Operation was succesful */
  62. ADNS2080_SERIAL_COMM_FAILURE, /*!< Serial communication failed */
  63. ADNS2080_CHIP_NOT_DETECTED, /*!< Product/Revision ID was not what was expected */
  64. ADNS2080_INVALID_PARAMETER /*!< Given parameters were not valid */
  65. } adns2080_status_t;
  66. /**
  67. * ADNS2080 motion output pin polarity values.
  68. */
  69. typedef enum
  70. {
  71. ADNS2080_MOTION_OUTPUT_POLARITY_LOW = 0, /*!< Motion output polarity active low */
  72. ADNS2080_MOTION_OUTPUT_POLARITY_HIGH = 1 /*!< Motion output polarity active high */
  73. } motion_output_polarity_t;
  74. /**
  75. * Motion output pin configuration.
  76. */
  77. typedef enum
  78. {
  79. ADNS2080_MOTION_OUTPUT_SENSITIVITY_LEVEL = 0, /*!< Motion output pin will be driven low/high (depending on the polarity setting) as long as there is motion data in DELTA registers */
  80. ADNS2080_MOTION_OUTPUT_SENSITIVITY_EDGE = 1 /*!< Motion output pin will be driven low/high (depending on the polarity setting) for 380 ns when motion is detected during rest modes */
  81. } motion_output_sensitivity_t;
  82. /**
  83. * Mouse sensor resolution values.
  84. */
  85. typedef enum
  86. {
  87. ADNS2080_RESOLUTION_250DPI = 1, /*!< 250 dpi resolution */
  88. ADNS2080_RESOLUTION_500DPI = 2, /*!< 500 dpi resolution */
  89. ADNS2080_RESOLUTION_1000DPI = 0, /*!< 1000 dpi resolution */
  90. ADNS2080_RESOLUTION_1250DPI = 3, /*!< 1250 dpi resolution */
  91. ADNS2080_RESOLUTION_1500DPI = 4, /*!< 1500 dpi resolution */
  92. ADNS2080_RESOLUTION_1750DPI = 5, /*!< 1750 dpi resolution */
  93. ADNS2080_RESOLUTION_2000DPI = 6 /*!< 2000 dpi resolution */
  94. } adns2080_resolution_t;
  95. /**
  96. * Mouse sensor forced mode options.
  97. */
  98. typedef enum
  99. {
  100. ADNS2080_MODE_NORMAL = 0, /*!< Normal operation mode */
  101. ADNS2080_MODE_REST1 = 1, /*!< Rest1 operation mode */
  102. ADNS2080_MODE_REST2 = 2, /*!< Rest2 operation mode */
  103. ADNS2080_MODE_REST3 = 3, /*!< Rest3 operation mode */
  104. ADNS2080_MODE_RUN1 = 4, /*!< Run1 operation mode */
  105. ADNS2080_MODE_RUN2 = 5, /*!< Run2 operation mode */
  106. ADNS2080_MODE_IDLE = 6 /*!< Idle operation mode */
  107. } adns2080_mode_t;
  108. /**
  109. * Mouse sensor motion reporting bits.
  110. */
  111. typedef enum
  112. {
  113. ADNS2080_MOTION_BITS_8 = 0, /*!< Motion reporting uses 8 bits */
  114. ADNS2080_MOTION_BITS_12 = 1 /*!< Motion reporting uses 12 bits */
  115. } adns2080_motion_bits_t;
  116. /**
  117. * @brief Function for initializing the mouse sensor chip.
  118. *
  119. * Valid mouse sensor information will be available 50 milliseconds after this
  120. * function finishes.
  121. *
  122. * @return
  123. * @retval ADNS2080_OK Mouse sensor was initialized succesfully.
  124. * @retval ADNS2080_SERIAL_COMM_FAILURE Serial communications failure.
  125. * @retval ADNS2080_CHIP_NOT_DETECTED Could not find revision 0 ADNS2080 chip.
  126. */
  127. adns2080_status_t adns2080_init(void);
  128. /**
  129. * @brief Function for resetting the mouse sensor chip.
  130. *
  131. * Valid mouse sensor information will be available 50 milliseconds after this
  132. * function finishes.
  133. * All register settings will be lost and need to be reloaded.
  134. *
  135. */
  136. void adns2080_reset(void);
  137. /**
  138. * @brief Function for reading mouse sensor product ID.
  139. *
  140. * Chip is expected to be initialized before calling this function.
  141. * Returned product ID should always be 0x2A.
  142. *
  143. * @return Product ID.
  144. */
  145. uint8_t adns2080_product_id_read(void);
  146. /**
  147. * @brief Function for reading mouse sensor revision ID.
  148. *
  149. * Chip is expected to be initialized before calling this function.
  150. *
  151. * @return Product ID.
  152. */
  153. uint8_t adns2080_revision_id_read(void); // also note there is "not rev id" register
  154. /**
  155. * @brief Function for powering down the mouse sensor.
  156. *
  157. * Chip is expected to be initialized before calling this function.
  158. * Serial port should not be accessed during the power down. To exit the power
  159. * down mode, @ref adns2080_wakeup must be called.
  160. *
  161. */
  162. void adns2080_powerdown(void);
  163. /**
  164. * @brief Function for waking up the mouse sensor.
  165. *
  166. * After wakeup, all mouse sensor settings must be reloaded. Valid mouse sensor
  167. * information will be available 55 milliseconds after this function finishes.
  168. */
  169. void adns2080_wakeup(void);
  170. /**
  171. * @brief Function for configuring the MOTION interrupt output pin.
  172. *
  173. * When motion is detected by the mouse sensor, the chip has a MOTION pin
  174. * indicating there is motion data in DELTA_X and DELTA_Y registers. This
  175. * function configures the polarity and sensitivity of that pin.
  176. *
  177. * Chip is expected to be initialized before calling this function.
  178. *
  179. * @param polarity MOTION output pin is either active LOW (default) or active HIGH
  180. * @param sensitivity Level or Edge (default) sensitive
  181. * @return
  182. * @retval ADNS2080_OK Operation succeeded.
  183. * @retval ADNS2080_INVALID_PARAMETER One of the parameters was not within valid range.
  184. */
  185. adns2080_status_t adns2080_motion_interrupt_set(motion_output_polarity_t polarity, motion_output_sensitivity_t sensitivity);
  186. /**
  187. * @brief Function for setting mouse sensor resolution.
  188. *
  189. * Chip is expected to be initialized before calling this function.
  190. *
  191. * @param resolution Desired resolution.
  192. * @return
  193. * @retval ADNS2080_OK Operation succeeded.
  194. * @retval ADNS2080_INVALID_PARAMETER One of the parameters was not within valid range.
  195. */
  196. adns2080_status_t adns2080_resolution_set(adns2080_resolution_t resolution);
  197. /**
  198. * @brief Function for setting number of bits used for mouse sensor motion reporting.
  199. *
  200. * Chip is expected to be initialized before calling this function.
  201. *
  202. * @param motion_bits Desired number of bits.
  203. * @return
  204. * @retval ADNS2080_OK Operation succeeded.
  205. * @retval ADNS2080_INVALID_PARAMETER One of the parameters was not within valid range.
  206. */
  207. adns2080_status_t adns2080_motion_bits_set(adns2080_motion_bits_t motion_bits);
  208. /**
  209. * @brief Function for reading number of bits used for mouse sensor motion reporting.
  210. *
  211. * Chip is expected to be initialized before calling this function.
  212. *
  213. * @return motion_bits Number of bits.
  214. */
  215. adns2080_motion_bits_t adns2080_motion_bits_read(void);
  216. /**
  217. * @brief Function for reading X- and Y-axis movement (in counts) since last report.
  218. *
  219. * Absolute value is determined by resolution.
  220. * Chip is expected to be initialized before calling this function.
  221. *
  222. * @param p_delta_x Location to store X-axis movement
  223. * @param p_delta_y Location to store Y-axis movement
  224. */
  225. void adns2080_movement_read(int16_t *p_delta_x, int16_t *p_delta_y);
  226. /**
  227. * @brief Function for checking if motion has been detected since last call.
  228. *
  229. * Chip is expected to be initialized before calling this function.
  230. *
  231. * @return
  232. * @retval true, if movement has been detected
  233. * @retval false, if no movement has been detected
  234. */
  235. bool adns2080_is_motion_detected(void);
  236. /**
  237. * @brief Function for setting mouse sensor Rest1, Rest2 and Rest3 mode motion detection time period.
  238. *
  239. * Allowed range for the periods is 0x01 to 0xFD.
  240. * Resulting period is derived from the following equation :
  241. * Period = (Rest period + 1) * 10 milliseconds
  242. * Chip is expected to be initialized before calling this function.
  243. *
  244. * @param rest1_period Rest1 period
  245. * @param rest2_period Rest2 period
  246. * @param rest3_period Rest3 period
  247. */
  248. void adns2080_rest_periods_set(uint8_t rest1_period, uint8_t rest2_period, uint8_t rest3_period);
  249. /**
  250. * @brief Function for setting mouse sensor mode downshift time periods.
  251. *
  252. * Allowed range for run_to_rest1_mode_time period is 0x00 to 0xFF.
  253. * Allowed range for rest1_to_rest2_mode_time period is 0x01 to 0xFF.
  254. * Allowed range for rest2_to_rest3_mode_time period is 0x01 to 0xFF.
  255. *
  256. * Chip is expected to be initialized before calling this function.
  257. *
  258. * @param run_to_rest1_mode_time Run mode to Rest1 mode downshift time period (Time = run_to_rest1_mode_time * 8 * 4)
  259. * @param rest1_to_rest2_mode_time Rest1 mode to Rest2 mode downshift time period (Time = rest1_to_rest2_mode_time * rest1_period * 16)
  260. * @param rest2_to_rest3_mode_time Rest2 mode to Rest3 mode downshift time period (Time = rest2_to_rest3_mode_time * rest2_period * 128)
  261. */
  262. void adns2080_downshift_times_set(uint8_t run_to_rest1_mode_time, uint8_t rest1_to_rest2_mode_time, uint8_t rest2_to_rest3_mode_time);
  263. /**
  264. * @brief Function for forcing mouse sensor to a certain operating mode.
  265. *
  266. * Chip is expected to be initialized before calling this function.
  267. * Normal operation will not continue until this function is called with ADNS2080_MODE_NORMAL parameter.
  268. *
  269. * @param mode Mode to force the sensor to.
  270. */
  271. void adns2080_force_mode_set(adns2080_mode_t mode);
  272. /**
  273. * @brief Function for reading the current forced operating mode.
  274. *
  275. * Chip is expected to be initialized before calling this function.
  276. *
  277. * @return Mode the sensor is forced to.
  278. */
  279. adns2080_mode_t adns2080_force_mode_read(void);
  280. /**
  281. *@}
  282. **/
  283. /*lint --flb "Leave library region" */
  284. #ifdef __cplusplus
  285. }
  286. #endif
  287. #endif