11PROGMEM_STRING_TABLE(GyroRangeStrings,
"±16°/s",
"±32°/s",
"±64°/s",
"±128°/s",
"±256°/s",
"±512°/s",
"±1024°/s",
16static constexpr float ACCEL_SCALE[] = {
24static constexpr float GYRO_SCALE[] = {
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();
33 if (!this->
check_chip_id(
this, QMI8658_REG_WHO_AM_I, QMI8658_WHO_AM_I_VALUE))
37 if (!this->
write_byte(QMI8658_REG_RESET, QMI8658_RESET_CMD)) {
44 if (!this->
write_byte(QMI8658_REG_CTRL1, QMI8658_CTRL1_VALUE)) {
45 this->
mark_failed(LOG_STR(
"Failed to write REG_CTRL1"));
51 this->
mark_failed(LOG_STR(
"Failed to write REG_CTRL2"));
57 this->
mark_failed(LOG_STR(
"Failed to write REG_CTRL3"));
62 if (!this->
write_byte(QMI8658_REG_CTRL5, 0x00)) {
63 this->
mark_failed(LOG_STR(
"Failed to write REG_CTRL5"));
68 if (!this->
write_byte(QMI8658_REG_CTRL7, QMI8658_CTRL7_ACC_EN | QMI8658_CTRL7_GYR_EN)) {
69 this->
mark_failed(LOG_STR(
"Failed to write REG_CTRL7"));
73 ESP_LOGCONFIG(TAG,
"QMI8658 initialised successfully");
77 ESP_LOGCONFIG(TAG,
"QMI8658 IMU:");
82 ESP_LOGCONFIG(TAG,
" Accel range : %s",
83 LOG_STR_ARG(AccelRangeStrings::get_log_str(this->
accel_range_ >> 4, AccelRangeStrings::LAST_INDEX)));
84 ESP_LOGCONFIG(TAG,
" Gyro range : %s",
85 LOG_STR_ARG(GyroRangeStrings::get_log_str(this->
gyro_range_ >> 4, GyroRangeStrings::LAST_INDEX)));
86 MotionComponent::dump_config();
94 uint8_t raw_data[REG_READ_LEN];
95 if (!this->
read_bytes(QMI8658_REG_TEMP_L, raw_data, REG_READ_LEN)) {
96 ESP_LOGW(TAG,
"Failed to read IMU data");
105 ESP_LOGV(TAG,
"Read raw accel data: %d, %d, %d", raw_x, raw_y, raw_z);
106 data.acceleration[motion::X_AXIS] = raw_x * scale;
107 data.acceleration[motion::Y_AXIS] = raw_y * scale;
108 data.acceleration[motion::Z_AXIS] = raw_z * scale;
114 ESP_LOGV(TAG,
"Read raw gyro data: %d, %d, %d", raw_x, raw_y, raw_z);
115 data.angular_rate[motion::X_AXIS] = raw_x * scale;
116 data.angular_rate[motion::Y_AXIS] = raw_y * scale;
117 data.angular_rate[motion::Z_AXIS] = raw_z * scale;
void mark_failed()
Mark this component as failed.
bool check_chip_id(Component *component, uint8_t a_register, uint8_t expected, uint8_t mask=0xFF)
Read the 8-bit ID at a_register and accept it when it matches expected in the bits set in mask.
bool write_byte(uint8_t a_register, uint8_t data) const
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
void dump_config() override
QMI8658AccelRange accel_range_
QMI8658GyroRange gyro_range_
QMI8658AccelODR accel_odr_
bool update_data(motion::MotionData &data) override
LazyCallbackManager< void(float)> temperature_callback_
PROGMEM_STRING_TABLE(AccelRangeStrings, "±2g", "±4g", "±8g", "±16g")
ESPHOME_LOG_TAG(TAG, "qmi8658")
constexpr T encode_value_le(const uint8_t *bytes)
Encode a value from its constituent bytes (from least to most significant) in an array with length si...
void HOT delay(uint32_t ms)