icm20608.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-09-03 Ernest Chen the first version
  9. */
  10. #ifndef __ICM20608_H__
  11. #define __ICM20608_H__
  12. #include <rthw.h>
  13. #include <rtthread.h>
  14. enum icm20608_set_cmd
  15. {
  16. ICM20608_PWR_MGMT1, // power management 1
  17. ICM20608_PWR_MGMT2, // power management 2
  18. ICM20608_GYRO_CONFIG, // gyroscope configuration(range)
  19. ICM20608_ACCEL_CONFIG1, // accelerometer configuration(range)
  20. ICM20608_ACCEL_CONFIG2, // accelerometer configuration2
  21. ICM20608_INT_ENABLE, //interrupt enable
  22. };
  23. typedef enum icm20608_set_cmd icm20608_set_cmd_t;
  24. enum icm20608_gyroscope_range
  25. {
  26. ICM20608_GYROSCOPE_RANGE0, // ±250dps
  27. ICM20608_GYROSCOPE_RANGE1, // ±500dps
  28. ICM20608_GYROSCOPE_RANGE2, // ±1000dps
  29. ICM20608_GYROSCOPE_RANGE3, // ±2000dps
  30. };
  31. typedef enum icm20608_gyroscope_range icm20608_gyro_range_t;
  32. enum icm20608_accelerometer_range
  33. {
  34. ICM20608_ACCELEROMETER_RANGE0, // ±2g
  35. ICM20608_ACCELEROMETER_RANGE1, // ±4g
  36. ICM20608_ACCELEROMETER_RANGE2, // ±8g
  37. ICM20608_ACCELEROMETER_RANGE3, // ±16g
  38. };
  39. typedef enum icm20608_accelerometer_range icm20608_accel_range_t;
  40. typedef struct cm20608_axes
  41. {
  42. rt_int16_t x;
  43. rt_int16_t y;
  44. rt_int16_t z;
  45. } cm20608_axes_t;
  46. struct icm20608_device
  47. {
  48. struct rt_i2c_bus_device *i2c;
  49. cm20608_axes_t accel_offset;
  50. cm20608_axes_t gyro_offset;
  51. rt_mutex_t lock;
  52. };
  53. typedef struct icm20608_device *icm20608_device_t;
  54. /**
  55. * This function initializes icm20608 registered device driver
  56. *
  57. * @param dev the name of icm20608 device
  58. *
  59. * @return the icm20608 device.
  60. */
  61. icm20608_device_t icm20608_init(const char *i2c_bus_name);
  62. /**
  63. * This function releases memory and deletes mutex lock
  64. *
  65. * @param dev the pointer of device driver structure.
  66. */
  67. void icm20608_deinit(icm20608_device_t dev);
  68. /**
  69. * This function gets accelerometer by icm20608 sensor measurement
  70. *
  71. * @param dev the pointer of device driver structure
  72. * @param accel_x the accelerometer of x-axis digital output
  73. * @param accel_y the accelerometer of y-axis digital output
  74. * @param accel_z the accelerometer of z-axis digital output
  75. *
  76. * @return the getting status of accelerometer, RT_EOK reprensents getting accelerometer successfully.
  77. */
  78. rt_err_t icm20608_get_accel(icm20608_device_t dev, rt_int16_t *accel_x, rt_int16_t *accel_y, rt_int16_t *accel_z);
  79. /**
  80. * This function gets gyroscope by icm20608 sensor measurement
  81. *
  82. * @param dev the pointer of device driver structure
  83. * @param gyro_x the gyroscope of x-axis digital output
  84. * @param gyro_y the gyroscope of y-axis digital output
  85. * @param gyro_z the gyroscope of z-axis digital output
  86. *
  87. * @return the getting status of gyroscope, RT_EOK reprensents getting gyroscope successfully.
  88. */
  89. rt_err_t icm20608_get_gyro(icm20608_device_t dev, rt_int16_t *gyro_x, rt_int16_t *gyro_y, rt_int16_t *gyro_z);
  90. /**
  91. * This function calibrates original gyroscope and accelerometer, which are bias, in calibration mode
  92. *
  93. * @param dev the pointer of device driver structure
  94. * @param times averaging times in calibration mode
  95. *
  96. * @return the getting original status, RT_EOK reprensents getting gyroscope successfully.
  97. */
  98. rt_err_t icm20608_calib_level(icm20608_device_t dev, rt_size_t times);
  99. /**
  100. * This function sets parameter of icm20608 sensor
  101. *
  102. * @param dev the pointer of device driver structure
  103. * @param cmd the parameter cmd of device
  104. * @param value for setting value in cmd register
  105. *
  106. * @return the setting parameter status, RT_EOK reprensents setting successfully.
  107. */
  108. rt_err_t icm20608_set_param(icm20608_device_t dev, icm20608_set_cmd_t cmd, rt_uint8_t value);
  109. /**
  110. * This function gets parameter of icm20608 sensor
  111. *
  112. * @param dev the pointer of device driver structure
  113. * @param cmd the parameter cmd of device
  114. * @param value to get value in cmd register
  115. *
  116. * @return the getting parameter status,RT_EOK reprensents getting successfully.
  117. */
  118. rt_err_t icm20608_get_param(icm20608_device_t dev, icm20608_set_cmd_t cmd, rt_uint8_t *value);
  119. #endif /*__DRV_ICM20608_H__ */