icm_datatypes.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * icm_datatypes.h
  3. *
  4. * Created on: 8. 1. 2023
  5. * Author: juraj
  6. */
  7. #ifndef ICM_DATATYPES_H_
  8. #define ICM_DATATYPES_H_
  9. #if defined(STM32F401xC) || defined(STM32F401xE)
  10. #include "stm32f4xx_hal.h"
  11. #endif
  12. #if defined (STM32L432xx)
  13. #include "stm32l4xx_hal.h"
  14. #endif
  15. #if defined (STM32L031xx)
  16. #include "stm32l0xx_hal.h"
  17. #endif
  18. #define ICM20948_ACCEL 0x10
  19. #define ICM20948_GYRO 0x20
  20. #define ICM20948_MAG 0x30
  21. #define ICM20948_TEMP 0x40
  22. #define GET2BYTES(ptr,offset) ((((uint16_t)*(ptr+(offset)))<<8) + *(ptr+(offset)+1))
  23. typedef enum
  24. {
  25. sensorAll = 0,
  26. sensorAccIndex = ICM20948_ACCEL >> 4,
  27. sensorGyroIndex = ICM20948_GYRO >> 4,
  28. sensorMagIndex = ICM20948_MAG >> 4,
  29. }Icm20948_sensorIndex;
  30. typedef struct
  31. {
  32. uint8_t type;
  33. float x;
  34. float y;
  35. float z;
  36. } axisesF;
  37. typedef struct
  38. {
  39. uint8_t type;
  40. int16_t x;
  41. int16_t y;
  42. int16_t z;
  43. } axisesI;
  44. typedef enum
  45. {
  46. GYRO_FS_250dps,
  47. GYRO_FS_500dps,
  48. GYRO_FS_1000dps,
  49. GYRO_FS_2000dps,
  50. GYRO_FS_None = 0xFF
  51. } gyro_full_scale;
  52. typedef enum
  53. {
  54. ACCEL_FS_2g,
  55. ACCEL_FS_4g,
  56. ACCEL_FS_8g,
  57. ACCEL_FS_16g,
  58. ACCEL_FS_NoneG = 0xFF
  59. } accel_full_scale;
  60. /**
  61. * @brief Acceleroemter settings: register ACCEL_CONFIG_1 (Bank 2).
  62. */
  63. typedef enum
  64. {
  65. /** output rate = 4500Hz */
  66. ACCEL_lpf_OFF = 0xFE,
  67. /** output rate = determined by @ref icm20948ACCEL_sample_rate_divider function, @ref accel_samplerate respectivelly */
  68. //ACCEL_lpf_246Hz = 0x0,
  69. ACCEL_lpf_246Hz = 0x1,
  70. ACCEL_lpf_114_4Hz = 0x2,
  71. ACCEL_lpf_050_4Hz = 0x3,
  72. ACCEL_lpf_023_9Hz = 0x4,
  73. ACCEL_lpf_011_5Hz = 0x5,
  74. ACCEL_lpf_005_7Hz = 0x6,
  75. ACCEL_lpf_473Hz = 0x7,
  76. ACCEL_lpf_None = 0xFF,
  77. } accel_dlp_cfg;
  78. typedef enum
  79. {
  80. ACCEL_samplerate_562_5Hz = 0,
  81. ACCEL_samplerate_281_3Hz = 1,
  82. ACCEL_samplerate_187_5Hz = 2,
  83. ACCEL_samplerate_140_6Hz = 3,
  84. ACCEL_samplerate_102_3Hz = 4,
  85. ACCEL_samplerate_70_3Hz = 5,
  86. ACCEL_samplerate_48_9Hz = 6,
  87. ACCEL_samplerate_35_2Hz = 7,
  88. ACCEL_samplerate_17_6Hz = 8,
  89. ACCEL_samplerate_8_8Hz = 9,
  90. ACCEL_samplerate_4_4Hz = 10,
  91. ACCEL_samplerate_2_2Hz = 11,
  92. ACCEL_samplerate_1_1Hz = 12,
  93. ACCEL_samplerate_0_55Hz = 13,
  94. ACCEL_samplerate_0_27Hz = 14,
  95. ACCEL_samplerate_None = 255,
  96. } accel_samplerate;
  97. typedef enum
  98. {
  99. GYRO_samplerate_562_5Hz = 1,
  100. GYRO_samplerate_375_0Hz = 2,
  101. GYRO_samplerate_281_3Hz = 3,
  102. GYRO_samplerate_225_0Hz = 4,
  103. GYRO_samplerate_187_5Hz = 5,
  104. GYRO_samplerate_140_6Hz = 7,
  105. GYRO_samplerate_125_0Hz = 8,
  106. GYRO_samplerate_102_3Hz = 10,
  107. GYRO_samplerate_070_3Hz = 15,
  108. GYRO_samplerate_066_2Hz = 16,
  109. GYRO_samplerate_048_9Hz = 22,
  110. GYRO_samplerate_035_2Hz = 31,
  111. GYRO_samplerate_034_1Hz = 32,
  112. GYRO_samplerate_017_6Hz = 63,
  113. GYRO_samplerate_017_3Hz = 64,
  114. GYRO_samplerate_004_4Hz = 255,
  115. GYRO_samplerate_None = 254, //0xFE
  116. } gyro_samplerate;
  117. /**
  118. * @brief Gyroscope settings: register GYRO_CONFIG_1 (Bank 2).
  119. */
  120. typedef enum
  121. {
  122. /** output rate = 9000Hz */
  123. GYRO_low_pass_OFF = 0xFE,
  124. /** output rate = determined by @ref icm20948_gyro_sample_rate_divider function, @ref accel_samplerate respectivelly */
  125. GYRO_lpf_196_6Hz = 0x0,
  126. GYRO_lpf_151_8Hz = 0x1,
  127. GYRO_lpf_119_5Hz = 0x2,
  128. GYRO_lpf_051_2Hz = 0x3,
  129. GYRO_lpf_023_9Hz = 0x4,
  130. GYRO_lpf_011_6Hz = 0x5,
  131. GYRO_lpf_005_7Hz = 0x6,
  132. GYRO_lpf_361_4Hz = 0x7,
  133. GYRO_lpf_None = 0xFF,
  134. } gyro_dlp_cfg;
  135. typedef enum
  136. {
  137. mag_mode_power_down = 0,
  138. mag_mode_single_measurement = 1,
  139. mag_mode_cont_measurement_010hz = 2,
  140. mag_mode_cont_measurement_020hz = 4,
  141. mag_mode_cont_measurement_050hz = 6,
  142. mag_mode_cont_measurement_100hz = 8
  143. } AK09916_operation_mode;
  144. typedef enum
  145. {
  146. interrupt_disable = 0,
  147. /** Enable DMP interrupt to propagate to interrupt pin 1. */
  148. interrupt_DMP_INT1_EN = 1 << 1,
  149. /** Enable PLL RDY interrupt (PLL RDY means PLL is running and in use as the clock source for the system) to propagate to interrupt pin 1. */
  150. interrupt_PLL_RDY_EN = 1 << 2,
  151. /** Enable interrupt for wake on motion to propagate to interrupt pin 1. */
  152. interrupt_WOM_INT_EN = 1 << 3,
  153. /** Enable wake on FSYNC interrupt. */
  154. interrupt_REG_WOF_EN = 1 << 7,
  155. /** Enable raw data ready interrupt from any sensor to propagate to interrupt pin 1.*/
  156. interrupt_RAW_DATA_0_RDY_EN = 1 << 8
  157. }interrupt_source_enum;
  158. typedef struct
  159. {
  160. uint8_t I2C_MST_INT : 1;
  161. uint8_t DMP_INT1 : 1;
  162. uint8_t PLL_RDY_INT : 1;
  163. uint8_t WOM_INT : 1;
  164. uint8_t reserved_0 : 4;
  165. } ICM_INT_STATUS_t;
  166. typedef struct{
  167. GPIO_TypeDef *port;
  168. uint16_t pin;
  169. }McuPin_typeDef;
  170. typedef struct
  171. {
  172. accel_dlp_cfg low_pass_filter;// = ACCEL_lpf_OFF;
  173. accel_samplerate sample_rate;// = ACCEL_samplerate_562_5Hz;
  174. accel_full_scale full_scale;// = _4g;
  175. }Config_Accel_t;
  176. typedef struct
  177. {
  178. gyro_dlp_cfg low_pass_filter;// = GYRO_low_pass_OFF;
  179. gyro_samplerate sample_rate;// = GYRO_samplerate_375_0Hz;
  180. gyro_full_scale full_scale;// = _250dps;
  181. }Config_Gyro_t;
  182. typedef struct
  183. {
  184. AK09916_operation_mode mode;// = mag_mode_power_down;
  185. }Config_Mag_t;
  186. typedef struct
  187. {
  188. McuPin_typeDef *pinCS;// = NULL;
  189. //McuPin_typeDef *pinINT = NULL;
  190. McuPin_typeDef *pinLED;// = NULL;
  191. Config_Accel_t accel;
  192. Config_Gyro_t gyro;
  193. Config_Mag_t mag;
  194. interrupt_source_enum int_source;// = interrupt_disable;
  195. }icm20948_Config;
  196. #endif /* ICM_DATATYPES_H_ */