13static const uint8_t EMC2101_CHIP_ID = 0x16;
14static const uint8_t EMC2101_ALT_CHIP_ID = 0x28;
17static const uint8_t EMC2101_REGISTER_INTERNAL_TEMP = 0x00;
18static const uint8_t EMC2101_REGISTER_EXTERNAL_TEMP_MSB = 0x01;
19static const uint8_t EMC2101_REGISTER_DAC_CONV_RATE = 0x04;
20static const uint8_t EMC2101_REGISTER_EXTERNAL_TEMP_LSB = 0x10;
21static const uint8_t EMC2101_REGISTER_CONFIG = 0x03;
22static const uint8_t EMC2101_REGISTER_TACH_LSB = 0x46;
23static const uint8_t EMC2101_REGISTER_TACH_MSB = 0x47;
24static const uint8_t EMC2101_REGISTER_FAN_CONFIG = 0x4A;
25static const uint8_t EMC2101_REGISTER_FAN_SETTING = 0x4C;
26static const uint8_t EMC2101_REGISTER_PWM_FREQ = 0x4D;
27static const uint8_t EMC2101_REGISTER_PWM_DIV = 0x4E;
28static const uint8_t EMC2101_REGISTER_WHOAMI = 0xFD;
36static const uint8_t EMC2101_ALT_TCH_BIT = 1 << 2;
41static const uint8_t EMC2101_DAC_BIT = 1 << 4;
48static const uint8_t EMC2101_CLK_OVR_BIT = 1 << 2;
55static const uint8_t EMC2101_POLARITY_BIT = 1 << 4;
61 uint8_t chip_id =
reg(EMC2101_REGISTER_WHOAMI).
get();
62 if ((chip_id != EMC2101_CHIP_ID) && (chip_id != EMC2101_ALT_CHIP_ID)) {
63 ESP_LOGE(TAG,
"Wrong chip ID %02X", chip_id);
70 config |= EMC2101_ALT_TCH_BIT;
72 config |= EMC2101_DAC_BIT;
75 reg(EMC2101_REGISTER_FAN_CONFIG) |= EMC2101_POLARITY_BIT;
83 reg(EMC2101_REGISTER_FAN_CONFIG) |= EMC2101_CLK_OVR_BIT;
92 ESP_LOGCONFIG(TAG,
"Emc2101 component:");
94 ESP_LOGCONFIG(TAG,
" Mode: %s", this->
dac_mode_ ? LOG_STR_LITERAL(
"DAC") : LOG_STR_LITERAL(
"PWM"));
99 " PWM Resolution: %02X\n"
100 " PWM Divider: %02X",
103 ESP_LOGCONFIG(TAG,
" Inverted: %s", YESNO(this->
inverted_));
108 ESP_LOGD(TAG,
"Setting duty fan setting to %02X", duty_cycle);
109 if (!this->
write_byte(EMC2101_REGISTER_FAN_SETTING, duty_cycle)) {
110 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
118 if (!this->
read_byte(EMC2101_REGISTER_FAN_SETTING, &duty_cycle)) {
119 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
129 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
139 if (!this->
read_byte(EMC2101_REGISTER_EXTERNAL_TEMP_MSB, &msb) ||
140 !this->
read_byte(EMC2101_REGISTER_EXTERNAL_TEMP_LSB, &lsb)) {
141 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
154 if (!this->
read_byte(EMC2101_REGISTER_TACH_LSB, &lsb) || !this->
read_byte(EMC2101_REGISTER_TACH_MSB, &msb)) {
155 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
162 return tach == 0xFFFF ? 0.0f : 5400000.0f / tach;
void mark_failed()
Mark this component as failed.
void status_set_warning()
void setup() override
Used by ESPHome framework.
float get_duty_cycle()
Gets the Fan output duty cycle.
void dump_config() override
Used by ESPHome framework.
float get_setup_priority() const override
Used by ESPHome framework.
float get_speed()
Gets the tachometer speed sensor reading.
float get_internal_temperature()
Gets the internal temperature sensor reading.
uint8_t max_output_value_
float get_external_temperature()
Gets the external temperature sensor reading.
Emc2101DACConversionRate dac_conversion_rate_
void set_duty_cycle(float value)
Sets the Fan output duty cycle.
bool write_byte(uint8_t a_register, uint8_t data) const
bool read_byte(uint8_t a_register, uint8_t *data)
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
This class is used to create I2CRegister objects that act as proxies to read/write internal registers...
uint8_t get() const
returns the register value
ESPHOME_LOG_TAG(TAG, "EMC2101")
constexpr float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
T remap(U value, U min, U max, T min_out, T max_out)
Remap value from the range (min, max) to (min_out, max_out).