icm_datatypes.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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_low_pass_OFF = 0,
  43. /** output rate = determined by @ref icm20948ACCEL_sample_rate_divider function, @ref accel_samplerate respectivelly */
  44. ACCEL_lpf_246Hz = 0x9,
  45. ACCEL_lpf_114_4Hz = 0x11,
  46. ACCEL_lpf_050_4Hz = 0x19,
  47. ACCEL_lpf_023_9Hz = 0x21,
  48. ACCEL_lpf_011_5Hz = 0x29,
  49. ACCEL_lpf_005_7Hz = 0x31,
  50. ACCEL_lpf_473Hz = 0x39,
  51. } accel_dlp_cfg;
  52. typedef enum
  53. {
  54. ACCEL_samplerate_562_5Hz = 1,
  55. ACCEL_samplerate_281_3Hz = 3,
  56. ACCEL_samplerate_187_5Hz = 5,
  57. ACCEL_samplerate_140_6Hz = 7,
  58. ACCEL_samplerate_102_3Hz = 10,
  59. ACCEL_samplerate_70_3Hz = 15,
  60. ACCEL_samplerate_48_9Hz = 22,
  61. ACCEL_samplerate_35_2Hz = 31,
  62. ACCEL_samplerate_17_6Hz = 34,
  63. ACCEL_samplerate_8_8Hz = 127,
  64. ACCEL_samplerate_4_4Hz = 255,
  65. ACCEL_samplerate_2_2Hz = 513,
  66. ACCEL_samplerate_1_1Hz = 1022,
  67. ACCEL_samplerate_0_55Hz = 2044,
  68. ACCEL_samplerate_0_27Hz = 4095,
  69. } accel_samplerate;
  70. typedef enum
  71. {
  72. GYRO_samplerate_562_5Hz = 1,
  73. GYRO_samplerate_375_0Hz = 2,
  74. GYRO_samplerate_281_3Hz = 3,
  75. GYRO_samplerate_225_0Hz = 4,
  76. GYRO_samplerate_187_5Hz = 5,
  77. GYRO_samplerate_140_6Hz = 7,
  78. GYRO_samplerate_125_0Hz = 8,
  79. GYRO_samplerate_102_3Hz = 10,
  80. GYRO_samplerate_070_3Hz = 15,
  81. GYRO_samplerate_066_2Hz = 16,
  82. GYRO_samplerate_048_9Hz = 22,
  83. GYRO_samplerate_035_2Hz = 31,
  84. GYRO_samplerate_034_1Hz = 32,
  85. GYRO_samplerate_017_6Hz = 63,
  86. GYRO_samplerate_017_3Hz = 64,
  87. GYRO_samplerate_004_4Hz = 255,
  88. } gyro_samplerate;
  89. /**
  90. * @brief Gyroscope settings: register GYRO_CONFIG_1 (Bank 2).
  91. */
  92. typedef enum
  93. {
  94. /** output rate = 9000Hz */
  95. GYRO_low_pass_OFF = 0,
  96. /** output rate = determined by @ref icm20948_gyro_sample_rate_divider function, @ref accel_samplerate respectivelly */
  97. GYRO_lpf_196_6Hz = 0x1,
  98. GYRO_lpf_151_8Hz = 0x09,
  99. GYRO_lpf_119_5Hz = 0x11,
  100. GYRO_lpf_051_2Hz = 0x19,
  101. GYRO_lpf_023_9Hz = 0x21,
  102. GYRO_lpf_011_6Hz = 0x29,
  103. GYRO_lpf_005_7Hz = 0x31,
  104. GYRO_lpf_361_4Hz = 0x39,
  105. } gyro_dlp_cfg;
  106. typedef enum
  107. {
  108. mag_mode_power_down = 0,
  109. mag_mode_single_measurement = 1,
  110. mag_mode_cont_measurement_010hz = 2,
  111. mag_mode_cont_measurement_020hz = 4,
  112. mag_mode_cont_measurement_050hz = 6,
  113. mag_mode_cont_measurement_100hz = 8
  114. } AK09916_operation_mode;
  115. typedef enum
  116. {
  117. interrupt_disable = 0,
  118. /** Enable DMP interrupt to propagate to interrupt pin 1. */
  119. interrupt_DMP_INT1_EN = 1 << 1,
  120. /** 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. */
  121. interrupt_PLL_RDY_EN = 1 << 2,
  122. /** Enable interrupt for wake on motion to propagate to interrupt pin 1. */
  123. interrupt_WOM_INT_EN = 1 << 3,
  124. /** Enable wake on FSYNC interrupt. */
  125. interrupt_REG_WOF_EN = 1 << 7,
  126. /** Enable raw data ready interrupt from any sensor to propagate to interrupt pin 1.*/
  127. interrupt_RAW_DATA_0_RDY_EN = 1 << 8
  128. }interrupt_source_enum;
  129. typedef struct
  130. {
  131. uint8_t I2C_MST_INT : 1;
  132. uint8_t DMP_INT1 : 1;
  133. uint8_t PLL_RDY_INT : 1;
  134. uint8_t WOM_INT : 1;
  135. uint8_t reserved_0 : 4;
  136. } ICM_INT_STATUS_t;
  137. typedef struct{
  138. GPIO_TypeDef *port;
  139. uint16_t pin;
  140. }McuPin_typeDef;
  141. typedef struct
  142. {
  143. accel_dlp_cfg low_pass_filter = ACCEL_low_pass_OFF;
  144. accel_samplerate sample_rate = ACCEL_samplerate_562_5Hz;
  145. }Config_Accel_t;
  146. typedef struct
  147. {
  148. gyro_dlp_cfg low_pass_filter = GYRO_low_pass_OFF;
  149. gyro_samplerate sample_rate = GYRO_samplerate_375_0Hz;
  150. }Config_Gyro_t;
  151. typedef struct
  152. {
  153. AK09916_operation_mode mode = mag_mode_power_down;
  154. }Config_Mag_t;
  155. typedef struct
  156. {
  157. McuPin_typeDef *pinCS = NULL;
  158. McuPin_typeDef *pinINT = NULL;
  159. McuPin_typeDef *pinLED = NULL;
  160. Config_Accel_t accel;
  161. Config_Gyro_t gyro;
  162. Config_Mag_t mag;
  163. interrupt_source_enum int_source = interrupt_disable;
  164. }icm20948_Config;
  165. #endif /* ICM_DATATYPES_H_ */