8static const char *
const TAG =
"mmc5603";
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->
read_byte(MMC56X3_PRODUCT_ID, &
id)) {
42 if (
id != 0 &&
id != MMC56X3_CHIP_ID) {
43 ESP_LOGCONFIG(TAG,
"Chip Wrong");
49 if (!this->
write_byte(MMC56X3_CTRL1_REG, 0x80)) {
50 ESP_LOGCONFIG(TAG,
"Control 1 Failed for set bit");
56 if (!this->
write_byte(MMC56X3_CTRL0_REG, 0x08)) {
57 ESP_LOGCONFIG(TAG,
"Control 0 Failed for set bit");
63 if (!this->
write_byte(MMC56X3_CTRL0_REG, 0x10)) {
72 if (!this->
write_byte(MMC56X3_CTRL2_REG, ctrl_2)) {
79 ESP_LOGCONFIG(TAG,
"MMC5603:");
82 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
84 ESP_LOGE(TAG,
"The ID registers don't match - Is this really an MMC5603?");
86 LOG_UPDATE_INTERVAL(
this);
87 ESP_LOGCONFIG(TAG,
" Auto set/reset: %s", ONOFF(this->
auto_set_reset_));
89 LOG_SENSOR(
" ",
"X Axis", this->
x_sensor_);
90 LOG_SENSOR(
" ",
"Y Axis", this->
y_sensor_);
91 LOG_SENSOR(
" ",
"Z Axis", this->
z_sensor_);
97 if (!this->
write_byte(MMC56X3_CTRL0_REG, ctrl0)) {
130 raw_x |=
buffer[2] & 0x0F;
132 const float x = 0.00625 * (raw_x - 524288);
137 raw_y |=
buffer[5] & 0x0F;
139 const float y = 0.00625 * (raw_y - 524288);
144 raw_z |=
buffer[8] & 0x0F;
146 const float z = 0.00625 * (raw_z - 524288);
148 const float heading = atan2f(0.0f -
x,
y) * 180.0f / std::numbers::pi_v<float>;
149 ESP_LOGD(TAG,
"Got x=%0.02fµT y=%0.02fµT z=%0.02fµT heading=%0.01f°",
x,
y,
z, heading);