17 return LOG_STR(
"±125dps");
19 return LOG_STR(
"±250dps");
21 return LOG_STR(
"±500dps");
23 return LOG_STR(
"±1000dps");
25 return LOG_STR(
"±2000dps");
27 return LOG_STR(
"unknown");
33 case LSM6DS_WHO_AM_I_LSM6DS3:
34 return LOG_STR(
"LSM6DS3");
35 case LSM6DS_WHO_AM_I_LSM6DS3TR_C:
36 return LOG_STR(
"LSM6DS3TR-C");
37 case LSM6DS_WHO_AM_I_LSM6DSO:
38 return LOG_STR(
"LSM6DSO");
45 return who_am_i == LSM6DS_WHO_AM_I_LSM6DS3 ? 16 : 256;
49 MotionComponent::setup();
52 ESP_LOGE(TAG,
"Failed to read WHO_AM_I — check wiring and I2C address");
57 if (chip_name ==
nullptr) {
58 ESP_LOGE(TAG,
"Unknown WHO_AM_I: 0x%02X", who_am_i);
59 this->
mark_failed(LOG_STR(
"Unknown WHO_AM_I value"));
62 ESP_LOGD(TAG,
"Found %s (WHO_AM_I = 0x%02X)", LOG_STR_ARG(chip_name), who_am_i);
68 this->
mark_failed(LOG_STR(
"Software reset failed"));
77 uint8_t ctrl3 = CTRL3_C_IF_INC | CTRL3_C_BDU;
87 this->
mark_failed(LOG_STR(
"Failed to configure accelerometer"));
95 this->
mark_failed(LOG_STR(
"Failed to configure gyroscope"));
118 LOG_I2C_DEVICE(
this);
119 LOG_UPDATE_INTERVAL(
this);
124 " Accel range : %s\n"
125 " Accel data rate : %dHz\n"
127 " Gyro data rate : %dHz",
128 LOG_STR_ARG(AccelRangeStrings::get_log_str(this->
accel_range_, AccelRangeStrings::LAST_INDEX)),
129 accel_odr, LOG_STR_ARG(gyro_range_to_str(this->
gyro_range_)), gyro_odr);
143 uint8_t
raw[LSM6DS_BURST_LEN];
144 if (!this->
read_bytes(LSM6DS_REG_OUTX_L_G,
raw, LSM6DS_BURST_LEN)) {
153 static constexpr float GYRO_SCALE[] = {
178 static constexpr float ACCEL_SCALE[] = {
196 if (this->
read_bytes(LSM6DS_REG_OUT_TEMP_L, raw_t, 2)) {
void mark_failed()
Mark this component as failed.
void status_clear_error()
ErrorCode write_register(uint8_t a_register, const uint8_t *data, size_t len) const
writes an array of bytes to a specific register in the I²C device
ErrorCode read_register(uint8_t a_register, uint8_t *data, size_t len)
reads an array of bytes from a specific register in the I²C device
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
LazyCallbackManager< void(float)> temperature_callback_
LSM6DSAccelODR accel_odr_
uint16_t temperature_sensitivity_
bool update_data(motion::MotionData &data) override
LSM6DSGyroRange gyro_range_
LSM6DSAccelRange accel_range_
const LogString * chip_name_
@ ERROR_OK
No error found during execution of method.
uint16_t temperature_sensitivity_from_who_am_i(uint8_t who_am_i)
Temperature sensitivity in LSB/°C for a supported WHO_AM_I value, from the chip's datasheet.
ESPHOME_LOG_TAG(TAG, "lsm6ds")
const LogString * chip_name_from_who_am_i(uint8_t who_am_i)
Chip name for a WHO_AM_I value, or nullptr when the chip is not supported.
PROGMEM_STRING_TABLE(AccelRangeStrings, "±2g", "±16g", "±4g", "±8g")
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)