icm_datatypes.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. typedef struct
  16. {
  17. uint8_t type;
  18. float x;
  19. float y;
  20. float z;
  21. } axises;
  22. typedef enum
  23. {
  24. _250dps,
  25. _500dps,
  26. _1000dps,
  27. _2000dps
  28. } gyro_full_scale;
  29. typedef enum
  30. {
  31. _2g,
  32. _4g,
  33. _8g,
  34. _16g
  35. } accel_full_scale;
  36. /**
  37. * @brief Acceleroemter settings: register ACCEL_CONFIG_1 (Bank 2).
  38. */
  39. typedef enum
  40. {
  41. /** output rate = 4500Hz */
  42. ACCEL_lpf_OFF = 0xFE,
  43. /** output rate = determined by @ref icm20948ACCEL_sample_rate_divider function, @ref accel_samplerate respectivelly */
  44. //ACCEL_lpf_246Hz = 0x0,
  45. ACCEL_lpf_246Hz = 0x1,
  46. ACCEL_lpf_114_4Hz = 0x2,
  47. ACCEL_lpf_050_4Hz = 0x3,
  48. ACCEL_lpf_023_9Hz = 0x4,
  49. ACCEL_lpf_011_5Hz = 0x5,
  50. ACCEL_lpf_005_7Hz = 0x6,
  51. ACCEL_lpf_473Hz = 0x7,
  52. } accel_dlp_cfg;
  53. typedef enum
  54. {
  55. ACCEL_samplerate_562_5Hz = 0,
  56. ACCEL_samplerate_281_3Hz = 1,
  57. ACCEL_samplerate_187_5Hz = 2,
  58. ACCEL_samplerate_140_6Hz = 3,
  59. ACCEL_samplerate_102_3Hz = 4,
  60. ACCEL_samplerate_70_3Hz = 5,
  61. ACCEL_samplerate_48_9Hz = 6,
  62. ACCEL_samplerate_35_2Hz = 7,
  63. ACCEL_samplerate_17_6Hz = 8,
  64. ACCEL_samplerate_8_8Hz = 9,
  65. ACCEL_samplerate_4_4Hz = 10,
  66. ACCEL_samplerate_2_2Hz = 11,
  67. ACCEL_samplerate_1_1Hz = 12,
  68. ACCEL_samplerate_0_55Hz = 13,
  69. ACCEL_samplerate_0_27Hz = 14,
  70. } accel_samplerate;
  71. typedef enum
  72. {
  73. GYRO_samplerate_562_5Hz = 0,
  74. GYRO_samplerate_375_0Hz = 1,
  75. GYRO_samplerate_281_3Hz = 2,
  76. GYRO_samplerate_225_0Hz = 3,
  77. GYRO_samplerate_187_5Hz = 4,
  78. GYRO_samplerate_140_6Hz = 5,
  79. GYRO_samplerate_125_0Hz = 6,
  80. GYRO_samplerate_102_3Hz = 7,
  81. GYRO_samplerate_070_3Hz = 8,
  82. GYRO_samplerate_066_2Hz = 9,
  83. GYRO_samplerate_048_9Hz = 10,
  84. GYRO_samplerate_035_2Hz = 11,
  85. GYRO_samplerate_034_1Hz = 12,
  86. GYRO_samplerate_017_6Hz = 13,
  87. GYRO_samplerate_017_3Hz = 14,
  88. GYRO_samplerate_004_4Hz = 15,
  89. } gyro_samplerate;
  90. /**
  91. * @brief Gyroscope settings: register GYRO_CONFIG_1 (Bank 2).
  92. */
  93. typedef enum
  94. {
  95. /** output rate = 9000Hz */
  96. GYRO_low_pass_OFF = 0xFE,
  97. /** output rate = determined by @ref icm20948_gyro_sample_rate_divider function, @ref accel_samplerate respectivelly */
  98. GYRO_lpf_196_6Hz = 0x0,
  99. GYRO_lpf_151_8Hz = 0x1,
  100. GYRO_lpf_119_5Hz = 0x2,
  101. GYRO_lpf_051_2Hz = 0x3,
  102. GYRO_lpf_023_9Hz = 0x4,
  103. GYRO_lpf_011_6Hz = 0x5,
  104. GYRO_lpf_005_7Hz = 0x6,
  105. GYRO_lpf_361_4Hz = 0x7,
  106. } gyro_dlp_cfg;
  107. typedef enum
  108. {
  109. mag_mode_power_down = 0,
  110. mag_mode_single_measurement = 1,
  111. mag_mode_cont_measurement_010hz = 2,
  112. mag_mode_cont_measurement_020hz = 4,
  113. mag_mode_cont_measurement_050hz = 6,
  114. mag_mode_cont_measurement_100hz = 8
  115. } AK09916_operation_mode;
  116. typedef enum
  117. {
  118. interrupt_disable = 0,
  119. /** Enable DMP interrupt to propagate to interrupt pin 1. */
  120. interrupt_DMP_INT1_EN = 1 << 1,
  121. /** 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. */
  122. interrupt_PLL_RDY_EN = 1 << 2,
  123. /** Enable interrupt for wake on motion to propagate to interrupt pin 1. */
  124. interrupt_WOM_INT_EN = 1 << 3,
  125. /** Enable wake on FSYNC interrupt. */
  126. interrupt_REG_WOF_EN = 1 << 7,
  127. /** Enable raw data ready interrupt from any sensor to propagate to interrupt pin 1.*/
  128. interrupt_RAW_DATA_0_RDY_EN = 1 << 8
  129. }interrupt_source_enum;
  130. typedef struct
  131. {
  132. uint8_t I2C_MST_INT : 1;
  133. uint8_t DMP_INT1 : 1;
  134. uint8_t PLL_RDY_INT : 1;
  135. uint8_t WOM_INT : 1;
  136. uint8_t reserved_0 : 4;
  137. } ICM_INT_STATUS_t;
  138. typedef struct{
  139. GPIO_TypeDef *port;
  140. uint16_t pin;
  141. }McuPin_typeDef;
  142. typedef struct
  143. {
  144. accel_dlp_cfg low_pass_filter = ACCEL_lpf_OFF;
  145. accel_samplerate sample_rate = ACCEL_samplerate_562_5Hz;
  146. }Config_Accel_t;
  147. typedef struct
  148. {
  149. gyro_dlp_cfg low_pass_filter = GYRO_low_pass_OFF;
  150. gyro_samplerate sample_rate = GYRO_samplerate_375_0Hz;
  151. }Config_Gyro_t;
  152. typedef struct
  153. {
  154. AK09916_operation_mode mode = mag_mode_power_down;
  155. }Config_Mag_t;
  156. typedef struct
  157. {
  158. McuPin_typeDef *pinCS = NULL;
  159. McuPin_typeDef *pinINT = NULL;
  160. McuPin_typeDef *pinLED = NULL;
  161. Config_Accel_t accel;
  162. Config_Gyro_t gyro;
  163. Config_Mag_t mag;
  164. interrupt_source_enum int_source = interrupt_disable;
  165. }icm20948_Config;
  166. #endif /* ICM_DATATYPES_H_ */