12extern SPI_HandleTypeDef
hspi1;
13extern SPI_HandleTypeDef
hspi2;
14extern SPI_HandleTypeDef
hspi3;
18extern UART_HandleTypeDef huart2;
23 return HAL_UART_Transmit(&huart2, data, strlen((
const char *)data) + 1, 100);
33int32_t
imuP_write(
void *handle, uint8_t reg_addr,
const uint8_t *buf, uint16_t len) {
41 if (HAL_SPI_Transmit(&
hspi2, ®_addr, 1, 100) ==
HAL_OK) {
42 if (HAL_SPI_Transmit(&
hspi2, (uint8_t *)buf, len, 100) ==
HAL_OK) {
52int32_t
imuP_read(
void *handle, uint8_t reg_addr, uint8_t *buf, uint16_t len) {
61 if (HAL_SPI_Transmit(&
hspi2, ®_addr, 1, 100) ==
HAL_OK) {
62 if (HAL_SPI_Receive(&
hspi2, buf, len, 100) ==
HAL_OK) {
71int32_t
imuP_read_2(
void *handle, uint8_t reg_addr, uint8_t *buf, uint16_t len) {
73 uint8_t tx_buffer[len + 1];
74 uint8_t rx_buffer[len + 1];
77 tx_buffer[0] = reg_addr;
80 for (
int i = 1; i <= len; i++) {
83 if(HAL_GPIO_ReadPin(BARO_CS_GPIO_Port,BARO_CS_Pin)!=GPIO_PIN_SET){BMP390_CS_HIGH;}
84 if(HAL_GPIO_ReadPin(MAG_CS_GPIO_Port,MAG_CS_Pin)!=GPIO_PIN_SET){MAG_CS_HIGH;}
89 if (HAL_SPI_TransmitReceive(&
hspi2, tx_buffer, rx_buffer, len + 1, 100) ==
HAL_OK) {
91 for (
int i = 0; i < len; i++) {
92 buf[i] = rx_buffer[i + 1];
103int8_t
bmp390_P_write(uint8_t reg_addr,
const uint8_t *buf, uint32_t len,
void *intf_ptr) {
106 if(HAL_GPIO_ReadPin(IMU_CS_GPIO_Port,IMU_CS_Pin)!=GPIO_PIN_SET){IMU_CS_HIGH;}
107 if(HAL_GPIO_ReadPin(MAG_CS_GPIO_Port,MAG_CS_Pin)!=GPIO_PIN_SET){MAG_CS_HIGH;}
109 if(HAL_GPIO_ReadPin(BARO_CS_GPIO_Port,BARO_CS_Pin)!=GPIO_PIN_RESET){BMP390_CS_LOW;}
111 if (HAL_SPI_Transmit(&
hspi2, ®_addr, 1, 100) ==
HAL_OK) {
112 if (HAL_SPI_Transmit(&
hspi2, (uint8_t *)buf, len, 100) ==
HAL_OK) {
117 if(HAL_GPIO_ReadPin(BARO_CS_GPIO_Port,BARO_CS_Pin)!=GPIO_PIN_SET){BMP390_CS_HIGH;}
122int8_t
bmp390_P_read(uint8_t reg_addr, uint8_t *buf, uint32_t len,
void *intf_ptr) {
126 uint8_t tx_buffer[len + 1];
127 uint8_t rx_buffer[len + 1];
130 tx_buffer[0] = reg_addr;
133 for (uint32_t i = 1; i <= len; i++) {
138 if(HAL_GPIO_ReadPin(IMU_CS_GPIO_Port,IMU_CS_Pin)!=GPIO_PIN_SET){IMU_CS_HIGH;}
139 if(HAL_GPIO_ReadPin(MAG_CS_GPIO_Port,MAG_CS_Pin)!=GPIO_PIN_SET){MAG_CS_HIGH;}
141 if(HAL_GPIO_ReadPin(BARO_CS_GPIO_Port,BARO_CS_Pin)!=GPIO_PIN_RESET){BMP390_CS_LOW;}
145 if (HAL_SPI_TransmitReceive(&
hspi2, tx_buffer, rx_buffer, len + 1, 100) ==
HAL_OK) {
147 for (uint32_t i = 0; i < len; i++) {
148 buf[i] = rx_buffer[i + 1];
155 if(HAL_GPIO_ReadPin(BARO_CS_GPIO_Port,BARO_CS_Pin)!=GPIO_PIN_SET){BMP390_CS_HIGH;}
167 for (i = 0; i < 96; i++) {
197 uint8_t who_am_i = 0;
203 imu -> handle = &
hspi2;
255 uint8_t settings_sel = 0;
368 float_t mean_acceleration_mg[3] = {0};
369 float_t mean_angular_rate_mdps[3] = {0};
370 float_t mean_temperature_degC = 0.0;
371 float_t acceleration_mg[3] = {0};
372 float_t angular_rate_mdps[3] = {0};
373 float_t temperature_degC = 0.0;
374 int16_t data_raw_acceleration[3] = {0};
375 int16_t data_raw_angular_rate[3] = {0};
376 int16_t data_raw_temperature = 0.0;
392 mean_acceleration_mg[0] += acceleration_mg[0];
393 mean_acceleration_mg[1] += acceleration_mg[1];
394 mean_acceleration_mg[2] += acceleration_mg[2];
396 mean_angular_rate_mdps[0] += angular_rate_mdps[0];
397 mean_angular_rate_mdps[1] += angular_rate_mdps[1];
398 mean_angular_rate_mdps[2] += angular_rate_mdps[2];
400 mean_temperature_degC += temperature_degC;
402 for (
int i = 0; i < iterationNum; i++) {
409 memset(data_raw_acceleration, 0x00, 3 *
sizeof(int16_t));
414 mean_acceleration_mg[0] += acceleration_mg[0];
415 mean_acceleration_mg[0] /= 2;
416 mean_acceleration_mg[1] += acceleration_mg[1];
417 mean_acceleration_mg[1] /= 2;
418 mean_acceleration_mg[2] += acceleration_mg[2];
419 mean_acceleration_mg[2] /= 2;
424 memset(data_raw_angular_rate, 0x00, 3 *
sizeof(int16_t));
429 mean_angular_rate_mdps[0] += angular_rate_mdps[0];
430 mean_angular_rate_mdps[0] /= 2;
431 mean_angular_rate_mdps[1] += angular_rate_mdps[1];
432 mean_angular_rate_mdps[1] /= 2;
433 mean_angular_rate_mdps[2] += angular_rate_mdps[2];
434 mean_angular_rate_mdps[2] /= 2;
439 memset(&data_raw_temperature, 0x00,
sizeof(int16_t));
442 mean_temperature_degC += temperature_degC;
443 mean_temperature_degC /= 2;
491 float mean_acceleration_x = mean_acceleration_mg[0] / 2;
492 float mean_acceleration_y = mean_acceleration_mg[1] / 2;
493 float mean_acceleration_z = mean_acceleration_mg[2] / 2;
495 float mean_acceleration = sqrtf(
496 mean_acceleration_mg[0]*mean_acceleration_mg[0] +
497 mean_acceleration_mg[1]*mean_acceleration_mg[1] +
498 mean_acceleration_mg[2]*mean_acceleration_mg[2]
501 float mean_acc_direction_x = mean_acceleration_x / mean_acceleration;
502 float mean_acc_direction_y = mean_acceleration_y / mean_acceleration;
503 float mean_acc_direction_z = mean_acceleration_z / mean_acceleration;
505 float gravity = 1000;
507 mean_acceleration_x -= mean_acc_direction_x*gravity;
508 mean_acceleration_y -= mean_acc_direction_y*gravity;
509 mean_acceleration_z -= mean_acc_direction_z*gravity;
511 int16_t offsetValX = (int16_t)mean_acceleration_x;
512 int16_t offsetValY = (int16_t)mean_acceleration_y;
513 int16_t offsetValZ = (int16_t)mean_acceleration_z;
515 if (offsetValX > -128 && offsetValX < 128 && offsetValY > -128 && offsetValY < 128
516 && offsetValZ > -128 && offsetValZ < 128) {
563int32_t
imuB_write(
void *handle, uint8_t reg_addr,
const uint8_t *buf, uint16_t len) {
571 if (HAL_SPI_Transmit(&
hspi3, ®_addr, 1, 100) ==
HAL_OK) {
572 if (HAL_SPI_Transmit(&
hspi3, (uint8_t *)buf, len, 100) ==
HAL_OK) {
582int32_t
imuB_read(
void *handle, uint8_t reg_addr, uint8_t *buf, uint16_t len) {
592 if (HAL_SPI_Transmit(&
hspi3, ®_addr, 1, 100) ==
HAL_OK) {
593 if (HAL_SPI_Receive(&
hspi3, buf, len, 100) ==
HAL_OK) {
603int8_t
bmp390_B_write(uint8_t reg_addr,
const uint8_t *buf, uint32_t len,
void *intf_ptr) {
608 if(HAL_GPIO_ReadPin(IMU_CS_GPIO_Port,IMU_CS_Pin)!=GPIO_PIN_SET){IMU_CS_HIGH;}
609 if(HAL_GPIO_ReadPin(MAG_CS_GPIO_Port,MAG_CS_Pin)!=GPIO_PIN_SET){MAG_CS_HIGH;}
612 if (HAL_SPI_Transmit(&
hspi3, ®_addr, 1, 100) ==
HAL_OK) {
613 if (HAL_SPI_Transmit(&
hspi3, (uint8_t *)buf, len, 100) ==
HAL_OK) {
623int8_t
bmp390_B_read(uint8_t reg_addr, uint8_t *buf, uint32_t len,
void *intf_ptr) {
627 if(HAL_GPIO_ReadPin(IMU_CS_GPIO_Port,IMU_CS_Pin)!=GPIO_PIN_SET){IMU_CS_HIGH;}
628 if(HAL_GPIO_ReadPin(MAG_CS_GPIO_Port,MAG_CS_Pin)!=GPIO_PIN_SET){MAG_CS_HIGH;}
633 if (HAL_SPI_Transmit(&
hspi3, ®_addr, 1, 100) ==
HAL_OK) {
634 if (HAL_SPI_Receive(&
hspi3, buf, len, 100) ==
HAL_OK) {
669 uint8_t who_am_i = 0;
675 imu -> handle = &
hspi3;
726 uint8_t settings_sel = 0;
780float_t
readAltitude(float_t seaLevelPa,float_t seaLevelT,float_t currentPa) {
int8_t bmp3_set_sensor_settings(uint32_t desired_settings, struct bmp3_settings *settings, struct bmp3_dev *dev)
This API sets the power control(pressure enable and temperature enable), over sampling,...
int8_t bmp3_set_op_mode(struct bmp3_settings *settings, struct bmp3_dev *dev)
This API sets the power mode of the sensor.
int8_t bmp3_init(struct bmp3_dev *dev)
This internal API converts the no. of frames required by the user to bytes so as to write in the wate...
#define BMP3_IIR_FILTER_DISABLE
#define BMP3_NO_OVERSAMPLING
#define BMP3_SEL_PRESS_EN
#define BMP3_SEL_IIR_FILTER
#define BMP3_SEL_PRESS_OS
int32_t lsm6dso32_angular_rate_raw_get(stmdev_ctx_t *ctx, int16_t *val)
Angular rate sensor. The value is expressed as a 16-bit word in two’s complement.[get].
int32_t lsm6dso32_temperature_raw_get(stmdev_ctx_t *ctx, int16_t *val)
Temperature data output register (r). L and H registers together express a 16-bit word in two’s compl...
int32_t lsm6dso32_acceleration_raw_get(stmdev_ctx_t *ctx, int16_t *val)
Linear acceleration output register. The value is expressed as a 16-bit word in two’s complement....
float_t lsm6dso32_from_lsb_to_celsius(int16_t lsb)
float_t lsm6dso32_from_fs16_to_mg(int16_t lsb)
float_t lsm6dso32_from_fs2000_to_mdps(int16_t lsb)
int32_t lsm6dso32_reset_get(stmdev_ctx_t *ctx, uint8_t *val)
Software reset. Restore the default values in user registers.[get].
int32_t lsm6dso32_reset_set(stmdev_ctx_t *ctx, uint8_t val)
Software reset. Restore the default values in user registers[set].
int32_t lsm6dso32_device_id_get(stmdev_ctx_t *ctx, uint8_t *buff)
Device "Who am I".[get].
int8_t calibrateIMU(stmdev_ctx_t *imu, uint16_t iterationNum, OFFSET_TYPE type)
Calibrates the IMU by calculating sensor offsets.
int32_t lsm6dso32_gy_full_scale_set(stmdev_ctx_t *ctx, lsm6dso32_fs_g_t val)
Gyroscope UI chain full-scale selection.[set].
int32_t imuP_read(void *handle, uint8_t reg_addr, uint8_t *buf, uint16_t len)
SPI read function for the primary IMU (LSM6DSO32).
int32_t lsm6dso32_xl_offset_weight_set(stmdev_ctx_t *ctx, lsm6dso32_usr_off_w_t val)
Weight of XL user offset bits of registers X_OFS_USR (73h), Y_OFS_USR (74h), Z_OFS_USR (75h)....
int32_t lsm6dso32_xl_full_scale_set(stmdev_ctx_t *ctx, lsm6dso32_fs_xl_t val)
Accelerometer full-scale selection.[set].
OFFSET_TYPE
Specifies the type of offset compensation to be used.
int32_t lsm6dso32_block_data_update_set(stmdev_ctx_t *ctx, uint8_t val)
Block data update.[set].
int32_t imuP_read_2(void *handle, uint8_t reg_addr, uint8_t *buf, uint16_t len)
SPI read function for the primary IMU (LSM6DSO32).
int32_t lsm6dso32_xl_usr_offset_z_set(stmdev_ctx_t *ctx, uint8_t *buff)
Accelerometer Z-axis user offset correction expressed in two’s complement, weight depends on USR_OFF_...
int32_t imuB_read(void *handle, uint8_t reg_addr, uint8_t *buf, uint16_t len)
SPI read function for the backup IMU (LSM6DSO32).
int32_t lsm6dso32_xl_data_rate_set(stmdev_ctx_t *ctx, lsm6dso32_odr_xl_t val)
Accelerometer UI data rate and power mode selection.[set].
int8_t init_imup(stmdev_ctx_t *imu, lsm6dso32_fs_xl_t acc_full_scale, lsm6dso32_fs_g_t gyro_full_scale, lsm6dso32_odr_xl_t acc_output_data_rate, lsm6dso32_odr_g_t gyro_output_data_rate)
Initializes the primary IMU (LSM6DSO32).
int32_t lsm6dso32_xl_usr_offset_y_set(stmdev_ctx_t *ctx, uint8_t *buff)
Accelerometer Y-axis user offset correction expressed in two’s complement, weight depends on USR_OFF_...
int32_t lsm6dso32_i3c_disable_set(stmdev_ctx_t *ctx, lsm6dso32_i3c_disable_t val)
I3C Enable/Disable communication protocol[.set].
int32_t lsm6dso32_xl_usr_offset_x_set(stmdev_ctx_t *ctx, uint8_t *buff)
Accelerometer X-axis user offset correction expressed in two’s complement, weight depends on USR_OFF_...
int32_t lsm6dso32_gy_data_rate_set(stmdev_ctx_t *ctx, lsm6dso32_odr_g_t val)
Gyroscope UI data rate selection.[set].
int32_t lsm6dso32_status_reg_get(stmdev_ctx_t *ctx, lsm6dso32_status_reg_t *val)
The STATUS_REG register is read by the primary interface.[get].
int32_t imuP_write(void *handle, uint8_t reg_addr, const uint8_t *buf, uint16_t len)
SPI write function for the primary IMU (LSM6DSO32).
int8_t init_imuB(stmdev_ctx_t *imu, lsm6dso32_fs_xl_t acc_full_scale, lsm6dso32_fs_g_t gyro_full_scale, lsm6dso32_odr_xl_t acc_output_data_rate, lsm6dso32_odr_g_t gyro_output_data_rate)
Initializes the backup IMU (LSM6DSO32).
int32_t imuB_write(void *handle, uint8_t reg_addr, const uint8_t *buf, uint16_t len)
SPI write function for the backup IMU (LSM6DSO32).
int32_t lsm6dso32_xl_usr_offset_set(stmdev_ctx_t *ctx, uint8_t val)
Enables user offset on out.[set].
@ HWOFFSET
Use the hardware's internal offset registers.
@ RESET_HWOFFSET
Reset the hardware offset registers to their default values.
#define TAU
Standard temperature lapse rate in K/m.
#define RAST
Specific gas constant for dry air in J/(kg·K).
#define GCONST
Standard gravity in m/s^2.
int8_t bmp390_P_read(uint8_t reg_addr, uint8_t *buf, uint32_t len, void *intf_ptr)
SPI read function for the primary Barometer (bmp390).
int8_t init_bmp390_B(struct bmp3_dev *bmp390)
Initializes the backup barometer (BMP390).
int8_t bmp390_B_read(uint8_t reg_addr, uint8_t *buf, uint32_t len, void *intf_ptr)
SPI read function for the backup Barometer (bmp390).
int8_t bmp390_B_write(uint8_t reg_addr, const uint8_t *buf, uint32_t len, void *intf_ptr)
SPI write function for the backup Barometer (bmp390).
int8_t init_bmp390_p(struct bmp3_dev *bmp390)
Initializes the primary barometer (BMP390).
int8_t bmp390_P_write(uint8_t reg_addr, const uint8_t *buf, uint32_t len, void *intf_ptr)
SPI write function for the primary Barometer (bmp390).
struct bmp3_int_ctrl_settings int_settings
struct bmp3_odr_filter_settings odr_filter
lsm6dso32_status_reg_t status_reg
float_t readAltitude(float_t seaLevelPa, float_t seaLevelT, float_t currentPa)
Calculates altitude based on the barometric formula.
static int8_t bmp3_B_spi_init(struct bmp3_dev *dev)
static void bmp390_delay_us(uint32_t period, void *intf_ptr)
static uint8_t bmp390_p_addr
uint16_t compute_air_density(float_t temperature, float_t pressure)
static int8_t bmp3_P_spi_init(struct bmp3_dev *dev)
static uint8_t bmp390_B_addr
Provides low-level hardware drivers, sensor initialization routines, and various utility functions fo...
#define SPECIFIC_GAS_CONSTANT
HAL_StatusTypeDef
HAL Status structures definition.