12constexpr uint8_t IC0_ADDR = 0x09;
13constexpr uint8_t IC1_ADDR = 0x0a;
14constexpr uint8_t IC2_ADDR = 0x0b;
15constexpr uint8_t IC3_ADDR = 0x0c;
16constexpr uint8_t PRODUCT_ID_ADDR = 0x2f;
17constexpr uint8_t MMC5983_PRODUCT_ID = 0x30;
19float convert_data_to_millitesla(uint8_t data_17_10, uint8_t data_9_2, uint8_t data_1_0) {
20 int32_t counts = (data_17_10 << 10) | (data_9_2 << 2) | data_1_0;
24 return counts / 163840.0f;
33 const uint8_t ic0_value = 0b10000;
36 ESP_LOGW(TAG,
"Writing Internal Control 0 failed with i2c error %d", err);
44 ESP_LOGW(TAG,
"Reading data failed with i2c error %d", err);
70 if (!this->
check_chip_id(
this, PRODUCT_ID_ADDR, MMC5983_PRODUCT_ID))
75 const uint8_t zero = 0;
78 ESP_LOGE(TAG,
"Initializing Internal Control 0 failed with i2c error %d", err);
85 ESP_LOGE(TAG,
"Initializing Internal Control 1 failed with i2c error %d", err);
92 ESP_LOGE(TAG,
"Initializing Internal Control 2 failed with i2c error %d", err);
99 ESP_LOGE(TAG,
"Initializing Internal Control 3 failed with i2c error %d", err);
107 const uint8_t ic2_value = 0b00001101;
110 ESP_LOGE(TAG,
"Writing Internal Control 2 failed with i2c error %d", err);
117 ESP_LOGD(TAG,
"MMC5983:");
118 LOG_I2C_DEVICE(
this);
void mark_failed()
Mark this component as failed.
void status_set_warning()
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
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.
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
sensor::Sensor * x_sensor_
void dump_config() override
sensor::Sensor * y_sensor_
sensor::Sensor * z_sensor_
void publish_state(float state)
Publish a new state to the front-end.
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
@ ERROR_OK
No error found during execution of method.
ESPHOME_LOG_TAG(TAG, "mmc5983")