diff --git a/src/driver/spi_bmi270.c b/src/driver/spi_bmi270.c index 339054734..85041998c 100644 --- a/src/driver/spi_bmi270.c +++ b/src/driver/spi_bmi270.c @@ -200,14 +200,9 @@ void bmi270_read_data(uint8_t reg, uint8_t *data, uint32_t size) { void bmi270_read_gyro_data(gyro_data_t *data) { spi_bus_device_reconfigure(&gyro_bus, SPI_MODE_TRAILING_EDGE, SPI_SPEED_FAST); + spi_txn_wait(&gyro_bus); - uint8_t buf[12]; - const spi_txn_segment_t gyro_segs[] = { - spi_make_seg_const(BMI270_REG_ACC_DATA_X_LSB | 0x80), - spi_make_seg_const(0xFF), - spi_make_seg_buffer(buf, NULL, 12), - }; - spi_seg_submit_wait(&gyro_bus, gyro_segs); + static uint8_t buf[12]; data->accel.axis[0] = -(int16_t)((buf[1] << 8) | buf[0]); data->accel.axis[1] = -(int16_t)((buf[3] << 8) | buf[2]); @@ -233,6 +228,13 @@ void bmi270_read_gyro_data(gyro_data_t *data) { data->gyro.axis[2] = gyro_data[2]; data->temp = 0; + + const spi_txn_segment_t segs[] = { + spi_make_seg_const(BMI270_REG_ACC_DATA_X_LSB | 0x80), + spi_make_seg_const(0xFF), + spi_make_seg_buffer(buf, NULL, 12), + }; + spi_seg_submit_continue(&gyro_bus, NULL, segs); } const uint8_t bmi270_config_file[8192] = { diff --git a/src/driver/spi_bmi323.c b/src/driver/spi_bmi323.c index 4651f9806..ff0e4e941 100644 --- a/src/driver/spi_bmi323.c +++ b/src/driver/spi_bmi323.c @@ -181,14 +181,9 @@ void bmi3_read_data(uint8_t reg, uint8_t *data, uint32_t size) { void bmi323_read_gyro_data(gyro_data_t *data) { spi_bus_device_reconfigure(&gyro_bus, SPI_MODE_TRAILING_EDGE, SPI_SPEED_FAST); + spi_txn_wait(&gyro_bus); - uint8_t buf[12]; - const spi_txn_segment_t gyro_segs[] = { - spi_make_seg_const(BMI323_REG_ACC_DATA_X_LSB | 0x80), - spi_make_seg_const(0xFF), - spi_make_seg_buffer(buf, NULL, 12), - }; - spi_seg_submit_wait(&gyro_bus, gyro_segs); + static uint8_t buf[12]; data->accel.axis[0] = -(int16_t)((buf[1] << 8) | buf[0]); data->accel.axis[1] = -(int16_t)((buf[3] << 8) | buf[2]); @@ -214,6 +209,13 @@ void bmi323_read_gyro_data(gyro_data_t *data) { data->gyro.axis[2] = gyro_data[2]; data->temp = 0; + + const spi_txn_segment_t gyro_segs[] = { + spi_make_seg_const(BMI323_REG_ACC_DATA_X_LSB | 0x80), + spi_make_seg_const(0xFF), + spi_make_seg_buffer(buf, NULL, 12), + }; + spi_seg_submit_continue(&gyro_bus, NULL, gyro_segs); } #endif \ No newline at end of file diff --git a/src/driver/spi_gyro.c b/src/driver/spi_gyro.c index b10745e02..cb5453972 100644 --- a/src/driver/spi_gyro.c +++ b/src/driver/spi_gyro.c @@ -108,6 +108,8 @@ uint8_t gyro_spi_init() { break; } + gyro_spi_read(); // dummy read to fill buffers + return gyro_type; } diff --git a/src/driver/spi_icm42605.c b/src/driver/spi_icm42605.c index 629961828..de167866d 100644 --- a/src/driver/spi_icm42605.c +++ b/src/driver/spi_icm42605.c @@ -109,13 +109,9 @@ void icm42605_write(uint8_t reg, uint8_t data) { void icm42605_read_gyro_data(gyro_data_t *data) { spi_bus_device_reconfigure(&gyro_bus, SPI_MODE_TRAILING_EDGE, SPI_SPEED_FAST); + spi_txn_wait(&gyro_bus); - uint8_t buf[14]; - const spi_txn_segment_t segs[] = { - spi_make_seg_const(ICM42605_TEMP_DATA1 | 0x80), - spi_make_seg_buffer(buf, NULL, 14), - }; - spi_seg_submit_wait(&gyro_bus, segs); + static uint8_t buf[14]; data->temp = (float)((int16_t)((buf[0] << 8) | buf[1])) / 132.48f + 25.f; @@ -126,5 +122,11 @@ void icm42605_read_gyro_data(gyro_data_t *data) { data->gyro.axis[1] = (int16_t)((buf[8] << 8) | buf[9]); data->gyro.axis[0] = (int16_t)((buf[10] << 8) | buf[11]); data->gyro.axis[2] = (int16_t)((buf[12] << 8) | buf[13]); + + const spi_txn_segment_t segs[] = { + spi_make_seg_const(ICM42605_TEMP_DATA1 | 0x80), + spi_make_seg_buffer(buf, NULL, 14), + }; + spi_seg_submit_continue(&gyro_bus, NULL, segs); } #endif \ No newline at end of file diff --git a/src/driver/spi_mpu6xxx.c b/src/driver/spi_mpu6xxx.c index 254eec977..6263565db 100644 --- a/src/driver/spi_mpu6xxx.c +++ b/src/driver/spi_mpu6xxx.c @@ -114,13 +114,9 @@ void mpu6xxx_write(uint8_t reg, uint8_t data) { void mpu6xxx_read_gyro_data(gyro_data_t *data) { spi_bus_device_reconfigure(&gyro_bus, SPI_MODE_TRAILING_EDGE, mpu6xxx_fast_divider()); + spi_txn_wait(&gyro_bus); - uint8_t buf[14]; - const spi_txn_segment_t segs[] = { - spi_make_seg_const(MPU_RA_ACCEL_XOUT_H | 0x80), - spi_make_seg_buffer(buf, NULL, 14), - }; - spi_seg_submit_wait(&gyro_bus, segs); + static uint8_t buf[14]; data->accel.axis[0] = -(int16_t)((buf[0] << 8) | buf[1]); data->accel.axis[1] = -(int16_t)((buf[2] << 8) | buf[3]); @@ -131,6 +127,12 @@ void mpu6xxx_read_gyro_data(gyro_data_t *data) { data->gyro.axis[1] = (int16_t)((buf[8] << 8) | buf[9]); data->gyro.axis[0] = (int16_t)((buf[10] << 8) | buf[11]); data->gyro.axis[2] = (int16_t)((buf[12] << 8) | buf[13]); + + const spi_txn_segment_t segs[] = { + spi_make_seg_const(MPU_RA_ACCEL_XOUT_H | 0x80), + spi_make_seg_buffer(buf, NULL, 14), + }; + spi_seg_submit_continue(&gyro_bus, NULL, segs); } #endif \ No newline at end of file