22 if (!this->
write_byte(BMI270_REG_PWR_CONF, 0x00))
27 if (!this->
write_byte(BMI270_REG_INIT_CTRL, 0x00))
31 const uint8_t *cfg = BMI270_CONFIG_FILE;
32 constexpr size_t cfg_len =
sizeof(BMI270_CONFIG_FILE);
35 while (index != cfg_len) {
37 uint8_t addr_lsb = (uint8_t) ((index / 2) & 0x0F);
38 uint8_t addr_msb = (uint8_t) ((index / 2) >> 4);
39 if (!this->
write_byte(BMI270_REG_INIT_ADDR_0, addr_lsb))
41 if (!this->
write_byte(BMI270_REG_INIT_ADDR_0 + 1, addr_msb))
45 size_t burst =
clamp_at_most(cfg_len - index, MAX_I2C_BUFFER_SIZE);
53 if (!this->
write_byte(BMI270_REG_INIT_CTRL, 0x01))
61 if ((
status & 0x0F) != 0x01) {
62 ESP_LOGE(TAG,
"Config load failed: INTERNAL_STATUS=0x%02X (expected 0x01)",
status);
71 MotionComponent::setup();
74 if (!this->
read_byte(BMI270_REG_CHIP_ID, &chip_id)) {
75 ESP_LOGE(TAG,
"Failed to read chip ID – check wiring / address");
79 if (chip_id != BMI270_CHIP_ID_VALUE) {
80 ESP_LOGE(TAG,
"Wrong chip ID: 0x%02X (expected 0x%02X)", chip_id, BMI270_CHIP_ID_VALUE);
84 ESP_LOGD(TAG,
"Chip ID: 0x%02X", chip_id);
95 ESP_LOGE(TAG,
"Config file upload failed");
99 ESP_LOGD(TAG,
"Config blob uploaded ✓");
103 uint8_t acc_conf = (uint8_t) (
accel_odr_) | (0x2 << 4) | (1 << 7);
104 if (!this->
write_byte(BMI270_REG_ACC_CONF, acc_conf)) {
115 uint8_t gyr_conf = (uint8_t) (
gyro_odr_) | (0x2 << 4) | (1 << 6) | (1 << 7);
116 if (!this->
write_byte(BMI270_REG_GYR_CONF, gyr_conf)) {
127 if (!this->
write_byte(BMI270_REG_PWR_CTRL, 0x0E)) {
135 if (!this->
write_byte(BMI270_REG_PWR_CONF, 0x02)) {
140 ESP_LOGCONFIG(TAG,
"BMI270 initialised successfully");
167 uint8_t raw_data[REG_READ_LEN];
168 if (!this->
read_bytes(BMI270_REG_DATA_8, raw_data, REG_READ_LEN)) {
169 ESP_LOGW(TAG,
"Failed to read IMU data");
174 static constexpr float ACCEL_SCALE[] = {
182 data.
acceleration[motion::X_AXIS] = (int16_t) ((raw_data[1] << 8) | raw_data[0]) * scale;
183 data.acceleration[motion::Y_AXIS] = (int16_t) ((raw_data[3] << 8) | raw_data[2]) * scale;
184 data.acceleration[motion::Z_AXIS] = (int16_t) ((raw_data[5] << 8) | raw_data[4]) * scale;
188 static constexpr float GYRO_SCALE[] = {
189 2000.0f / 32768.0f, 1000.0f / 32768.0f, 500.0f / 32768.0f, 250.0f / 32768.0f, 125.0f / 32768.0f,
191 static constexpr uint8_t GYR_OFFS = BMI270_REG_DATA_14 - BMI270_REG_DATA_8;
194 data.
angular_rate[motion::X_AXIS] = (int16_t) ((raw_data[GYR_OFFS + 1] << 8) | raw_data[GYR_OFFS + 0]) * scale;
195 data.angular_rate[motion::Y_AXIS] = (int16_t) ((raw_data[GYR_OFFS + 3] << 8) | raw_data[GYR_OFFS + 2]) * scale;
196 data.angular_rate[motion::Z_AXIS] = (int16_t) ((raw_data[GYR_OFFS + 5] << 8) | raw_data[GYR_OFFS + 4]) * scale;
202 static constexpr uint8_t TEMP_OFFS = BMI270_REG_TEMP_0 - BMI270_REG_DATA_8;
203 int16_t raw_t = (int16_t) ((raw_data[TEMP_OFFS + 1] << 8) | raw_data[TEMP_OFFS + 0]);