ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
mt6701_i2c.h
Go to the documentation of this file.
1#pragma once
2
5
6namespace esphome::mt6701_i2c {
7
8// Angle: D[13:6] at 0x03, D[5:0] in bits 7:2 of 0x04
9static constexpr uint8_t REG_ANGLE_H = 0x03;
10static constexpr uint8_t REG_ANGLE_L = 0x04;
11
12// EEPROM programming (datasheet 8.2) needs more than 600 ms left alone afterwards
13static constexpr uint8_t REG_EEPROM_KEY = 0x09;
14static constexpr uint8_t REG_EEPROM_CMD = 0x0A;
15static constexpr uint8_t EEPROM_KEY_VALUE = 0xB3;
16static constexpr uint8_t EEPROM_CMD_VALUE = 0x05;
17static constexpr uint32_t EEPROM_PROGRAM_DELAY_MS = 700;
18
19// Configuration registers; reserved bits make every write a read-modify-write
20static constexpr uint8_t REG_ABZ_MUX_DIR = 0x29; // bit6 ABZ_MUX, bit1 DIR
21static constexpr uint8_t REG_RES_H = 0x30; // bits7:4 UVW_RES, bits1:0 ABZ_RES[9:8]
22static constexpr uint8_t REG_ABZ_RES_L = 0x31; // ABZ_RES[7:0]
23static constexpr uint8_t REG_CONFIG_H = 0x32; // bit7 HYST[2], bits6:4 Z_PULSE_WIDTH, bits3:0 ZERO[11:8]
24static constexpr uint8_t REG_ZERO_L = 0x33; // ZERO[7:0]
25static constexpr uint8_t REG_HYST_L = 0x34; // bits7:6 HYST[1:0]
26static constexpr uint8_t REG_OUT = 0x38; // bit7 PWM_FREQ, bit6 PWM_POL, bit5 OUT_MODE
27static constexpr uint8_t REG_A_HIGH = 0x3E; // bits7:4 A_STOP[11:8], bits3:0 A_START[11:8]
28static constexpr uint8_t REG_A_START_L = 0x3F; // A_START[7:0]
29static constexpr uint8_t REG_A_STOP_L = 0x40; // A_STOP[7:0]
30
33 public:
34 void setup() override;
35 void dump_config() override;
36
37 // Options left unset are never written, so the chip keeps its EEPROM defaults
38 void set_direction(uint8_t direction) { this->direction_ = direction; }
39 void set_zero_offset(uint16_t position) { this->zero_offset_ = position; }
40 void set_hysteresis(uint8_t hysteresis) { this->hysteresis_ = hysteresis; }
41 void set_output_mode(uint8_t output_mode) { this->output_mode_ = output_mode; }
42 void set_abz_pulses_per_revolution(uint16_t pulses) { this->abz_pulses_per_revolution_ = pulses; }
43 void set_z_pulse_width(uint8_t width) { this->z_pulse_width_ = width; }
44 void set_uvw_pole_pairs(uint8_t pole_pairs) { this->uvw_pole_pairs_ = pole_pairs; }
45 void set_out_pin_mode(uint8_t out_pin_mode) { this->out_pin_mode_ = out_pin_mode; }
46 void set_pwm_frequency(uint8_t pwm_frequency) { this->pwm_frequency_ = pwm_frequency; }
47 void set_pwm_polarity(uint8_t pwm_polarity) { this->pwm_polarity_ = pwm_polarity; }
48 void set_analog_start(uint16_t position) { this->analog_start_ = position; }
49 void set_analog_stop(uint16_t position) { this->analog_stop_ = position; }
50
53 void save_eeprom();
54
55 protected:
56 bool read_count(uint16_t &count) override;
57
58 void apply_config_();
59 bool update_register_(uint8_t reg, uint8_t mask, uint8_t value);
60
61 // Unset options sit above their field's range
62 static constexpr uint16_t UNSET_U16 = 0xFFFF;
63 static constexpr uint8_t UNSET_U8 = 0xFF;
64
77};
78
79} // namespace esphome::mt6701_i2c
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:144
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
Definition i2c.h:164
Bus-independent core; the I2C and SSI hubs provide read_count(), the entities poll it.
Definition mt6701.h:13
MT6701 over I2C, with the configuration registers.
Definition mt6701_i2c.h:32
void set_zero_offset(uint16_t position)
Definition mt6701_i2c.h:39
void set_analog_stop(uint16_t position)
Definition mt6701_i2c.h:49
void save_eeprom()
Write the registers to the EEPROM: pauses sampling for the programming time.
static constexpr uint16_t UNSET_U16
Definition mt6701_i2c.h:62
void set_uvw_pole_pairs(uint8_t pole_pairs)
Definition mt6701_i2c.h:44
void set_output_mode(uint8_t output_mode)
Definition mt6701_i2c.h:41
bool read_count(uint16_t &count) override
void set_hysteresis(uint8_t hysteresis)
Definition mt6701_i2c.h:40
static constexpr uint8_t UNSET_U8
Definition mt6701_i2c.h:63
void set_pwm_polarity(uint8_t pwm_polarity)
Definition mt6701_i2c.h:47
void set_analog_start(uint16_t position)
Definition mt6701_i2c.h:48
void set_direction(uint8_t direction)
Definition mt6701_i2c.h:38
void set_pwm_frequency(uint8_t pwm_frequency)
Definition mt6701_i2c.h:46
void set_abz_pulses_per_revolution(uint16_t pulses)
Definition mt6701_i2c.h:42
void set_out_pin_mode(uint8_t out_pin_mode)
Definition mt6701_i2c.h:45
bool update_register_(uint8_t reg, uint8_t mask, uint8_t value)
float position
Definition cover.h:0
FanDirection direction
Definition fan.h:5
unsigned count
Definition gif.cpp:51
static void uint32_t