9static const uint8_t MMC5603_ADDRESS = 0x30;
10static const uint8_t MMC56X3_PRODUCT_ID = 0x39;
12static const uint8_t MMC56X3_DEFAULT_ADDRESS = 0x30;
13static const uint8_t MMC56X3_CHIP_ID = 0x10;
15static const uint8_t MMC56X3_ADDR_XOUT0 = 0x00;
16static const uint8_t MMC56X3_ADDR_XOUT1 = 0x01;
17static const uint8_t MMC56X3_ADDR_XOUT2 = 0x06;
19static const uint8_t MMC56X3_ADDR_YOUT0 = 0x02;
20static const uint8_t MMC56X3_ADDR_YOUT1 = 0x03;
21static const uint8_t MMC56X3_ADDR_YOUT2 = 0x07;
23static const uint8_t MMC56X3_ADDR_ZOUT0 = 0x04;
24static const uint8_t MMC56X3_ADDR_ZOUT1 = 0x05;
25static const uint8_t MMC56X3_ADDR_ZOUT2 = 0x08;
27static const uint8_t MMC56X3_OUT_TEMP = 0x09;
28static const uint8_t MMC56X3_STATUS_REG = 0x18;
29static const uint8_t MMC56X3_CTRL0_REG = 0x1B;
30static const uint8_t MMC56X3_CTRL1_REG = 0x1C;
31static const uint8_t MMC56X3_CTRL2_REG = 0x1D;
32static const uint8_t MMC5603_ODR_REG = 0x1A;
36 if (!this->
check_chip_id(
this, MMC56X3_PRODUCT_ID, 0x00,
static_cast<uint8_t
>(~MMC56X3_CHIP_ID)))
39 if (!this->
write_byte(MMC56X3_CTRL1_REG, 0x80)) {
40 this->
mark_failed(LOG_STR(
"Control 1 failed for set bit"));
44 if (!this->
write_byte(MMC56X3_CTRL0_REG, 0x08)) {
45 this->
mark_failed(LOG_STR(
"Control 0 failed for set bit"));
49 if (!this->
write_byte(MMC56X3_CTRL0_REG, 0x10)) {
57 if (!this->
write_byte(MMC56X3_CTRL2_REG, ctrl_2)) {
63 ESP_LOGCONFIG(TAG,
"MMC5603:");
65 LOG_UPDATE_INTERVAL(
this);
66 ESP_LOGCONFIG(TAG,
" Auto set/reset: %s", ONOFF(this->
auto_set_reset_));
68 LOG_SENSOR(
" ",
"X Axis", this->
x_sensor_);
69 LOG_SENSOR(
" ",
"Y Axis", this->
y_sensor_);
70 LOG_SENSOR(
" ",
"Z Axis", this->
z_sensor_);
76 if (!this->
write_byte(MMC56X3_CTRL0_REG, ctrl0)) {
109 raw_x |=
buffer[2] & 0x0F;
111 const float x = 0.00625 * (raw_x - 524288);
116 raw_y |=
buffer[5] & 0x0F;
118 const float y = 0.00625 * (raw_y - 524288);
123 raw_z |=
buffer[8] & 0x0F;
125 const float z = 0.00625 * (raw_z - 524288);
127 const float heading = atan2f(0.0f -
x,
y) * 180.0f / std::numbers::pi_v<float>;
128 ESP_LOGD(TAG,
"Got x=%0.02fµT y=%0.02fµT z=%0.02fµT heading=%0.01f°",
x,
y,
z, heading);
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.