15 MotionComponent::setup();
18 ESP_LOGE(TAG,
"Failed to read WHO_AM_I — check wiring and I2C address");
22 const char *chip_name =
nullptr;
23 for (
const auto &chip : CHIP_IDS) {
25 chip_name = chip.name;
29 if (chip_name ==
nullptr) {
30 ESP_LOGE(TAG,
"Unknown WHO_AM_I: 0x%02X",
who_am_i);
31 this->
mark_failed(LOG_STR(
"Unknown WHO_AM_I value"));
34 ESP_LOGD(TAG,
"Found %s (WHO_AM_I = 0x%02X)", chip_name,
who_am_i);
39 this->
mark_failed(LOG_STR(
"Software reset failed"));
48 uint8_t ctrl3 = CTRL3_C_IF_INC | CTRL3_C_BDU;
58 this->
mark_failed(LOG_STR(
"Failed to configure accelerometer"));
66 this->
mark_failed(LOG_STR(
"Failed to configure gyroscope"));
137 uint8_t
raw[LSM6DS_BURST_LEN];
138 if (!this->
read_bytes(LSM6DS_REG_OUTX_L_G,
raw, LSM6DS_BURST_LEN)) {
147 static constexpr float GYRO_SCALE[] = {
165 data.angular_rate[motion::Y_AXIS] = (int16_t) ((
raw[3] << 8) |
raw[2]) * gyro_scale;
166 data.angular_rate[motion::Z_AXIS] = (int16_t) ((
raw[5] << 8) |
raw[4]) * gyro_scale;
172 static constexpr float ACCEL_SCALE[] = {
181 (int16_t) ((
raw[LSM6DS_ACCEL_OFFSET + 1] << 8) |
raw[LSM6DS_ACCEL_OFFSET + 0]) * accel_scale;
182 data.acceleration[motion::Y_AXIS] =
183 (int16_t) ((
raw[LSM6DS_ACCEL_OFFSET + 3] << 8) |
raw[LSM6DS_ACCEL_OFFSET + 2]) * accel_scale;
184 data.acceleration[motion::Z_AXIS] =
185 (int16_t) ((
raw[LSM6DS_ACCEL_OFFSET + 5] << 8) |
raw[LSM6DS_ACCEL_OFFSET + 4]) * accel_scale;
193 if (this->
read_bytes(LSM6DS_REG_OUT_TEMP_L, raw_t, 2)) {
194 int16_t temp_raw = (int16_t) ((raw_t[1] << 8) | raw_t[0]);