|
| 1 | +#ifndef BMI088_IMU_H |
| 2 | +#define BMI088_IMU_H |
| 3 | + |
| 4 | +#include "stm32f4xx_hal.h" |
| 5 | +#include "main.h" |
| 6 | + |
| 7 | +/* Register defines */ |
| 8 | +#define BMI_GYR_I2C_ADDRESS 0x68 |
| 9 | +#define BMI_ACC_I2C_ADDRESS 0x18 |
| 10 | + |
| 11 | +#define BMI_ACC_CHIP_ID 0x00 |
| 12 | +#define BMI_ACC_DATA 0x12 |
| 13 | +#define BMI_TEMP_DATA 0x22 |
| 14 | +#define BMI_ACC_CONF 0x40 |
| 15 | +#define BMI_ACC_RANGE 0x41 |
| 16 | +#define BMI_INT1_IO_CONF 0x53 |
| 17 | +#define BMI_INT1_INT2_MAP_DATA 0x58 |
| 18 | +#define BMI_ACC_PWR_CONF 0x7C |
| 19 | +#define BMI_ACC_PWR_CTRL 0x7D |
| 20 | +#define BMI_ACC_SOFTRESET 0x7E |
| 21 | + |
| 22 | +#define BMI_GYR_CHIP_ID 0x00 |
| 23 | +#define BMI_GYR_DATA 0x02 |
| 24 | +#define BMI_GYR_RANGE 0x0F |
| 25 | +#define BMI_GYR_BANDWIDTH 0x10 |
| 26 | +#define BMI_GYR_SOFTRESET 0x14 |
| 27 | +#define BMI_GYR_INT_CTRL 0x15 |
| 28 | +#define BMI_INT3_INT4_IO_CONF 0x16 |
| 29 | +#define BMI_INT3_INT4_IO_MAP 0x18 |
| 30 | + |
| 31 | +typedef struct { |
| 32 | + |
| 33 | + /* I2C */ |
| 34 | + I2C_HandleTypeDef *m_i2c_handle; |
| 35 | +// GPIO_TypeDef *csAccPinBank; |
| 36 | +// GPIO_TypeDef *csGyrPinBank; |
| 37 | +// uint16_t csAccPin; |
| 38 | +// uint16_t csGyrPin; |
| 39 | + |
| 40 | + /* DMA */ |
| 41 | + uint8_t readingAcc; |
| 42 | + uint8_t readingGyr; |
| 43 | + uint8_t accTxBuf[8]; |
| 44 | + uint8_t gyrTxBuf[7]; |
| 45 | + volatile uint8_t accRxBuf[8]; |
| 46 | + volatile uint8_t gyrRxBuf[7]; |
| 47 | + |
| 48 | + /* Conversion constants (raw to m/s^2 and raw to rad/s) */ |
| 49 | + float accConversion; |
| 50 | + float gyrConversion; |
| 51 | + |
| 52 | + /* x-y-z measurements */ |
| 53 | + float acc_mps2[3]; |
| 54 | + float gyr_rps[3]; |
| 55 | + |
| 56 | +} BMI088; |
| 57 | + |
| 58 | +/* |
| 59 | + * |
| 60 | + * INITIALISATION |
| 61 | + * |
| 62 | + */ |
| 63 | +uint8_t BMI088_Init(BMI088 *imu, I2C_HandleTypeDef *m_i2c_handle); |
| 64 | + |
| 65 | +/* |
| 66 | + * |
| 67 | + * LOW-LEVEL REGISTER FUNCTIONS |
| 68 | + * |
| 69 | + */ |
| 70 | +uint8_t BMI088_ReadAccRegister(BMI088 *imu, uint8_t regAddr, uint8_t *data); |
| 71 | +uint8_t BMI088_ReadGyrRegister(BMI088 *imu, uint8_t regAddr, uint8_t *data); |
| 72 | + |
| 73 | +uint8_t BMI088_WriteAccRegister(BMI088 *imu, uint8_t regAddr, uint8_t data); |
| 74 | +uint8_t BMI088_WriteGyrRegister(BMI088 *imu, uint8_t regAddr, uint8_t data); |
| 75 | + |
| 76 | +/* |
| 77 | + * |
| 78 | + * POLLING |
| 79 | + * |
| 80 | + */ |
| 81 | +uint8_t BMI088_ReadAccelerometer(BMI088 *imu); |
| 82 | +uint8_t BMI088_ReadGyroscope(BMI088 *imu); |
| 83 | +uint8_t readGyroscopeFromBMI088(I2C_HandleTypeDef *hi2c, int16_t *gyroX, int16_t *gyroY, int16_t *gyroZ); |
| 84 | + |
| 85 | +/* |
| 86 | + * |
| 87 | + * DMA |
| 88 | + * |
| 89 | + */ |
| 90 | +uint8_t BMI088_ReadAccelerometerDMA(BMI088 *imu); |
| 91 | +void BMI088_ReadAccelerometerDMA_Complete(BMI088 *imu); |
| 92 | + |
| 93 | +uint8_t BMI088_ReadGyroscopeDMA(BMI088 *imu); |
| 94 | +void BMI088_ReadGyroscopeDMA_Complete(BMI088 *imu); |
| 95 | + |
| 96 | +/* |
| 97 | + * |
| 98 | + * WORKAROUND |
| 99 | + * |
| 100 | + */ |
| 101 | +void generateClocks2(uint8_t num_clocks, uint8_t send_stop_bits); |
| 102 | + |
| 103 | +#endif |
0 commit comments