adns2080.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. #ifndef ADNS2080_H
  13. #define ADNS2080_H
  14. /*lint ++flb "Enter library region" */
  15. #include <stdbool.h>
  16. #include <stdint.h>
  17. /** @file
  18. * @brief ADNS2080 mouse sensor driver
  19. *
  20. * @defgroup nrf_drivers_adns2080 ADNS2080 driver
  21. * @{
  22. * @ingroup nrf_drivers
  23. * @brief ADNS2080 mouse sensor driver.
  24. */
  25. /**
  26. * Describes return values for @ref adns2080_init.
  27. */
  28. typedef enum
  29. {
  30. ADNS2080_OK, /*!< Operation was succesful */
  31. ADNS2080_SERIAL_COMM_FAILURE, /*!< Serial communication failed */
  32. ADNS2080_CHIP_NOT_DETECTED, /*!< Product/Revision ID was not what was expected */
  33. ADNS2080_INVALID_PARAMETER /*!< Given parameters were not valid */
  34. } adns2080_status_t;
  35. /**
  36. * ADNS2080 motion output pin polarity values.
  37. */
  38. typedef enum
  39. {
  40. ADNS2080_MOTION_OUTPUT_POLARITY_LOW = 0, /*!< Motion output polarity active low */
  41. ADNS2080_MOTION_OUTPUT_POLARITY_HIGH = 1 /*!< Motion output polarity active high */
  42. } motion_output_polarity_t;
  43. /**
  44. * Motion output pin configuration.
  45. */
  46. typedef enum
  47. {
  48. 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 */
  49. 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 */
  50. } motion_output_sensitivity_t;
  51. /**
  52. * Mouse sensor resolution values.
  53. */
  54. typedef enum
  55. {
  56. ADNS2080_RESOLUTION_250DPI = 1, /*!< 250 dpi resolution */
  57. ADNS2080_RESOLUTION_500DPI = 2, /*!< 500 dpi resolution */
  58. ADNS2080_RESOLUTION_1000DPI = 0, /*!< 1000 dpi resolution */
  59. ADNS2080_RESOLUTION_1250DPI = 3, /*!< 1250 dpi resolution */
  60. ADNS2080_RESOLUTION_1500DPI = 4, /*!< 1500 dpi resolution */
  61. ADNS2080_RESOLUTION_1750DPI = 5, /*!< 1750 dpi resolution */
  62. ADNS2080_RESOLUTION_2000DPI = 6 /*!< 2000 dpi resolution */
  63. } adns2080_resolution_t;
  64. /**
  65. * Mouse sensor forced mode options.
  66. */
  67. typedef enum
  68. {
  69. ADNS2080_MODE_NORMAL = 0, /*!< Normal operation mode */
  70. ADNS2080_MODE_REST1 = 1, /*!< Rest1 operation mode */
  71. ADNS2080_MODE_REST2 = 2, /*!< Rest2 operation mode */
  72. ADNS2080_MODE_REST3 = 3, /*!< Rest3 operation mode */
  73. ADNS2080_MODE_RUN1 = 4, /*!< Run1 operation mode */
  74. ADNS2080_MODE_RUN2 = 5, /*!< Run2 operation mode */
  75. ADNS2080_MODE_IDLE = 6 /*!< Idle operation mode */
  76. } adns2080_mode_t;
  77. /**
  78. * Mouse sensor motion reporting bits.
  79. */
  80. typedef enum
  81. {
  82. ADNS2080_MOTION_BITS_8 = 0, /*!< Motion reporting uses 8 bits */
  83. ADNS2080_MOTION_BITS_12 = 1 /*!< Motion reporting uses 12 bits */
  84. } adns2080_motion_bits_t;
  85. /**
  86. * @brief Function for initializing the mouse sensor chip.
  87. *
  88. * Valid mouse sensor information will be available 50 milliseconds after this
  89. * function finishes.
  90. *
  91. * @return
  92. * @retval ADNS2080_OK Mouse sensor was initialized succesfully.
  93. * @retval ADNS2080_SERIAL_COMM_FAILURE Serial communications failure.
  94. * @retval ADNS2080_CHIP_NOT_DETECTED Could not find revision 0 ADNS2080 chip.
  95. */
  96. adns2080_status_t adns2080_init(void);
  97. /**
  98. * @brief Function for resetting the mouse sensor chip.
  99. *
  100. * Valid mouse sensor information will be available 50 milliseconds after this
  101. * function finishes.
  102. * All register settings will be lost and need to be reloaded.
  103. *
  104. */
  105. void adns2080_reset(void);
  106. /**
  107. * @brief Function for reading mouse sensor product ID.
  108. *
  109. * Chip is expected to be initialized before calling this function.
  110. * Returned product ID should always be 0x2A.
  111. *
  112. * @return Product ID.
  113. */
  114. uint8_t adns2080_product_id_read(void);
  115. /**
  116. * @brief Function for reading mouse sensor revision ID.
  117. *
  118. * Chip is expected to be initialized before calling this function.
  119. *
  120. * @return Product ID.
  121. */
  122. uint8_t adns2080_revision_id_read(void); // also note there is "not rev id" register
  123. /**
  124. * @brief Function for powering down the mouse sensor.
  125. *
  126. * Chip is expected to be initialized before calling this function.
  127. * Serial port should not be accessed during the power down. To exit the power
  128. * down mode, @ref adns2080_wakeup must be called.
  129. *
  130. */
  131. void adns2080_powerdown(void);
  132. /**
  133. * @brief Function for waking up the mouse sensor.
  134. *
  135. * After wakeup, all mouse sensor settings must be reloaded. Valid mouse sensor
  136. * information will be available 55 milliseconds after this function finishes.
  137. */
  138. void adns2080_wakeup(void);
  139. /**
  140. * @brief Function for configuring the MOTION interrupt output pin.
  141. *
  142. * When motion is detected by the mouse sensor, the chip has a MOTION pin
  143. * indicating there is motion data in DELTA_X and DELTA_Y registers. This
  144. * function configures the polarity and sensitivity of that pin.
  145. *
  146. * Chip is expected to be initialized before calling this function.
  147. *
  148. * @param polarity MOTION output pin is either active LOW (default) or active HIGH
  149. * @param sensitivity Level or Edge (default) sensitive
  150. * @return
  151. * @retval ADNS2080_OK Operation succeeded.
  152. * @retval ADNS2080_INVALID_PARAMETER One of the parameters was not within valid range.
  153. */
  154. adns2080_status_t adns2080_motion_interrupt_set(motion_output_polarity_t polarity, motion_output_sensitivity_t sensitivity);
  155. /**
  156. * @brief Function for setting mouse sensor resolution.
  157. *
  158. * Chip is expected to be initialized before calling this function.
  159. *
  160. * @param resolution Desired resolution.
  161. * @return
  162. * @retval ADNS2080_OK Operation succeeded.
  163. * @retval ADNS2080_INVALID_PARAMETER One of the parameters was not within valid range.
  164. */
  165. adns2080_status_t adns2080_resolution_set(adns2080_resolution_t resolution);
  166. /**
  167. * @brief Function for setting number of bits used for mouse sensor motion reporting.
  168. *
  169. * Chip is expected to be initialized before calling this function.
  170. *
  171. * @param motion_bits Desired number of bits.
  172. * @return
  173. * @retval ADNS2080_OK Operation succeeded.
  174. * @retval ADNS2080_INVALID_PARAMETER One of the parameters was not within valid range.
  175. */
  176. adns2080_status_t adns2080_motion_bits_set(adns2080_motion_bits_t motion_bits);
  177. /**
  178. * @brief Function for reading number of bits used for mouse sensor motion reporting.
  179. *
  180. * Chip is expected to be initialized before calling this function.
  181. *
  182. * @return motion_bits Number of bits.
  183. */
  184. adns2080_motion_bits_t adns2080_motion_bits_read(void);
  185. /**
  186. * @brief Function for reading X- and Y-axis movement (in counts) since last report.
  187. *
  188. * Absolute value is determined by resolution.
  189. * Chip is expected to be initialized before calling this function.
  190. *
  191. * @param p_delta_x Location to store X-axis movement
  192. * @param p_delta_y Location to store Y-axis movement
  193. */
  194. void adns2080_movement_read(int16_t *p_delta_x, int16_t *p_delta_y);
  195. /**
  196. * @brief Function for checking if motion has been detected since last call.
  197. *
  198. * Chip is expected to be initialized before calling this function.
  199. *
  200. * @return
  201. * @retval true, if movement has been detected
  202. * @retval false, if no movement has been detected
  203. */
  204. bool adns2080_is_motion_detected(void);
  205. /**
  206. * @brief Function for setting mouse sensor Rest1, Rest2 and Rest3 mode motion detection time period.
  207. *
  208. * Allowed range for the periods is 0x01 to 0xFD.
  209. * Resulting period is derived from the following equation :
  210. * Period = (Rest period + 1) * 10 milliseconds
  211. * Chip is expected to be initialized before calling this function.
  212. *
  213. * @param rest1_period Rest1 period
  214. * @param rest2_period Rest2 period
  215. * @param rest3_period Rest3 period
  216. */
  217. void adns2080_rest_periods_set(uint8_t rest1_period, uint8_t rest2_period, uint8_t rest3_period);
  218. /**
  219. * @brief Function for setting mouse sensor mode downshift time periods.
  220. *
  221. * Allowed range for run_to_rest1_mode_time period is 0x00 to 0xFF.
  222. * Allowed range for rest1_to_rest2_mode_time period is 0x01 to 0xFF.
  223. * Allowed range for rest2_to_rest3_mode_time period is 0x01 to 0xFF.
  224. *
  225. * Chip is expected to be initialized before calling this function.
  226. *
  227. * @param run_to_rest1_mode_time Run mode to Rest1 mode downshift time period (Time = run_to_rest1_mode_time * 8 * 4)
  228. * @param rest1_to_rest2_mode_time Rest1 mode to Rest2 mode downshift time period (Time = rest1_to_rest2_mode_time * rest1_period * 16)
  229. * @param rest2_to_rest3_mode_time Rest2 mode to Rest3 mode downshift time period (Time = rest2_to_rest3_mode_time * rest2_period * 128)
  230. */
  231. 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);
  232. /**
  233. * @brief Function for forcing mouse sensor to a certain operating mode.
  234. *
  235. * Chip is expected to be initialized before calling this function.
  236. * Normal operation will not continue until this function is called with ADNS2080_MODE_NORMAL parameter.
  237. *
  238. * @param mode Mode to force the sensor to.
  239. */
  240. void adns2080_force_mode_set(adns2080_mode_t mode);
  241. /**
  242. * @brief Function for reading the current forced operating mode.
  243. *
  244. * Chip is expected to be initialized before calling this function.
  245. *
  246. * @return Mode the sensor is forced to.
  247. */
  248. adns2080_mode_t adns2080_force_mode_read(void);
  249. /**
  250. *@}
  251. **/
  252. /*lint --flb "Leave library region" */
  253. #endif