10 static const char *
const TAG =
"mmc5983";
13 constexpr uint8_t IC0_ADDR = 0x09;
14 constexpr uint8_t IC1_ADDR = 0x0a;
15 constexpr uint8_t IC2_ADDR = 0x0b;
16 constexpr uint8_t IC3_ADDR = 0x0c;
17 constexpr uint8_t PRODUCT_ID_ADDR = 0x2f;
19 float 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 ESP_LOGCONFIG(TAG,
"Setting up MMC5983...");
73 const uint8_t mmc5983_product_id = 0x30;
77 ESP_LOGE(TAG,
"Reading product id failed with i2c error %d", err);
81 if (
id != mmc5983_product_id) {
82 ESP_LOGE(TAG,
"Product id 0x%02x does not match expected value 0x%02x",
id, mmc5983_product_id);
89 const uint8_t zero = 0;
92 ESP_LOGE(TAG,
"Initializing Internal Control 0 failed with i2c error %d", err);
99 ESP_LOGE(TAG,
"Initializing Internal Control 1 failed with i2c error %d", err);
106 ESP_LOGE(TAG,
"Initializing Internal Control 2 failed with i2c error %d", err);
113 ESP_LOGE(TAG,
"Initializing Internal Control 3 failed with i2c error %d", err);
121 const uint8_t ic2_value = 0b00001101;
124 ESP_LOGE(TAG,
"Writing Internal Control 2 failed with i2c error %d", err);
131 ESP_LOGD(TAG,
"MMC5983:");
132 LOG_I2C_DEVICE(
this);
const float DATA
For components that import data from directly connected sensors like DHT.
sensor::Sensor * y_sensor_
ErrorCode read_register(uint8_t a_register, uint8_t *data, size_t len, bool stop=true)
reads an array of bytes from a specific register in the I²C device
void status_set_warning(const char *message="unspecified")
T id(T value)
Helper function to make id(var) known from lambdas work in custom components.
sensor::Sensor * x_sensor_
void publish_state(float state)
Publish a new state to the front-end.
sensor::Sensor * z_sensor_
void dump_config() override
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
ErrorCode write_register(uint8_t a_register, const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a specific register in the I²C device
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
float get_setup_priority() const override