icm_datatypes.h 4.1 KB

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