25 16.0f / 32768.0f, 32.0f / 32768.0f, 64.0f / 32768.0f, 128.0f / 32768.0f,
26 256.0f / 32768.0f, 512.0f / 32768.0f, 1024.0f / 32768.0f, 2048.0f / 32768.0f,
30 MotionComponent::setup();
34 if (!this->
read_byte(QMI8658_REG_WHO_AM_I, &who_am_i)) {
35 this->
mark_failed(LOG_STR(
"Failed to read chip ID - check wiring / address"));
38 if (who_am_i != QMI8658_WHO_AM_I_VALUE) {
39 ESP_LOGE(TAG,
"Wrong chip ID: 0x%02X (expected 0x%02X)", who_am_i, QMI8658_WHO_AM_I_VALUE);
45 if (!this->
write_byte(QMI8658_REG_RESET, QMI8658_RESET_CMD)) {
52 if (!this->
write_byte(QMI8658_REG_CTRL1, QMI8658_CTRL1_VALUE)) {
53 this->
mark_failed(LOG_STR(
"Failed to write REG_CTRL1"));
59 this->
mark_failed(LOG_STR(
"Failed to write REG_CTRL2"));
65 this->
mark_failed(LOG_STR(
"Failed to write REG_CTRL3"));
70 if (!this->
write_byte(QMI8658_REG_CTRL5, 0x00)) {
71 this->
mark_failed(LOG_STR(
"Failed to write REG_CTRL5"));
76 if (!this->
write_byte(QMI8658_REG_CTRL7, QMI8658_CTRL7_ACC_EN | QMI8658_CTRL7_GYR_EN)) {
77 this->
mark_failed(LOG_STR(
"Failed to write REG_CTRL7"));
81 ESP_LOGCONFIG(TAG,
"QMI8658 initialised successfully");
85 ESP_LOGCONFIG(TAG,
"QMI8658 IMU:");
90 ESP_LOGCONFIG(TAG,
" Accel range : %s",
91 LOG_STR_ARG(AccelRangeStrings::get_log_str(this->
accel_range_ >> 4, AccelRangeStrings::LAST_INDEX)));
92 ESP_LOGCONFIG(TAG,
" Gyro range : %s",
93 LOG_STR_ARG(GyroRangeStrings::get_log_str(this->
gyro_range_ >> 4, GyroRangeStrings::LAST_INDEX)));
94 MotionComponent::dump_config();
102 uint8_t raw_data[REG_READ_LEN];
103 if (!this->
read_bytes(QMI8658_REG_TEMP_L, raw_data, REG_READ_LEN)) {
104 ESP_LOGW(TAG,
"Failed to read IMU data");
110 int16_t raw_x =
encode_uint16(raw_data[ACC_OFFS + 1], raw_data[ACC_OFFS + 0]);
111 int16_t raw_y =
encode_uint16(raw_data[ACC_OFFS + 3], raw_data[ACC_OFFS + 2]);
112 int16_t raw_z =
encode_uint16(raw_data[ACC_OFFS + 5], raw_data[ACC_OFFS + 4]);
113 ESP_LOGV(TAG,
"Read raw accel data: %d, %d, %d", raw_x, raw_y, raw_z);
114 data.acceleration[motion::X_AXIS] = raw_x * scale;
115 data.acceleration[motion::Y_AXIS] = raw_y * scale;
116 data.acceleration[motion::Z_AXIS] = raw_z * scale;
119 raw_x =
encode_uint16(raw_data[GYR_OFFS + 1], raw_data[GYR_OFFS + 0]);
120 raw_y =
encode_uint16(raw_data[GYR_OFFS + 3], raw_data[GYR_OFFS + 2]);
121 raw_z =
encode_uint16(raw_data[GYR_OFFS + 5], raw_data[GYR_OFFS + 4]);
122 ESP_LOGV(TAG,
"Read raw gyro data: %d, %d, %d", raw_x, raw_y, raw_z);
123 data.angular_rate[motion::X_AXIS] = raw_x * scale;
124 data.angular_rate[motion::Y_AXIS] = raw_y * scale;
125 data.angular_rate[motion::Z_AXIS] = raw_z * scale;
130 int16_t raw_t = (int16_t) ((raw_data[TEMP_OFFS + 1] << 8) | raw_data[TEMP_OFFS + 0]);