10static const char *
const TAG =
"EMC2101";
12static const uint8_t EMC2101_CHIP_ID = 0x16;
13static const uint8_t EMC2101_ALT_CHIP_ID = 0x28;
16static const uint8_t EMC2101_REGISTER_INTERNAL_TEMP = 0x00;
17static const uint8_t EMC2101_REGISTER_EXTERNAL_TEMP_MSB = 0x01;
18static const uint8_t EMC2101_REGISTER_DAC_CONV_RATE = 0x04;
19static const uint8_t EMC2101_REGISTER_EXTERNAL_TEMP_LSB = 0x10;
20static const uint8_t EMC2101_REGISTER_CONFIG = 0x03;
21static const uint8_t EMC2101_REGISTER_TACH_LSB = 0x46;
22static const uint8_t EMC2101_REGISTER_TACH_MSB = 0x47;
23static const uint8_t EMC2101_REGISTER_FAN_CONFIG = 0x4A;
24static const uint8_t EMC2101_REGISTER_FAN_SETTING = 0x4C;
25static const uint8_t EMC2101_REGISTER_PWM_FREQ = 0x4D;
26static const uint8_t EMC2101_REGISTER_PWM_DIV = 0x4E;
27static const uint8_t EMC2101_REGISTER_WHOAMI = 0xFD;
35static const uint8_t EMC2101_ALT_TCH_BIT = 1 << 2;
40static const uint8_t EMC2101_DAC_BIT = 1 << 4;
47static const uint8_t EMC2101_CLK_OVR_BIT = 1 << 2;
54static const uint8_t EMC2101_POLARITY_BIT = 1 << 4;
60 uint8_t chip_id =
reg(EMC2101_REGISTER_WHOAMI).
get();
61 if ((chip_id != EMC2101_CHIP_ID) && (chip_id != EMC2101_ALT_CHIP_ID)) {
62 ESP_LOGE(TAG,
"Wrong chip ID %02X", chip_id);
69 config |= EMC2101_ALT_TCH_BIT;
71 config |= EMC2101_DAC_BIT;
74 reg(EMC2101_REGISTER_FAN_CONFIG) |= EMC2101_POLARITY_BIT;
82 reg(EMC2101_REGISTER_FAN_CONFIG) |= EMC2101_CLK_OVR_BIT;
91 ESP_LOGCONFIG(TAG,
"Emc2101 component:");
94 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
96 ESP_LOGCONFIG(TAG,
" Mode: %s", this->
dac_mode_ ?
"DAC" :
"PWM");
101 " PWM Resolution: %02X\n"
102 " PWM Divider: %02X",
105 ESP_LOGCONFIG(TAG,
" Inverted: %s", YESNO(this->
inverted_));
110 ESP_LOGD(TAG,
"Setting duty fan setting to %02X", duty_cycle);
111 if (!this->
write_byte(EMC2101_REGISTER_FAN_SETTING, duty_cycle)) {
112 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
120 if (!this->
read_byte(EMC2101_REGISTER_FAN_SETTING, &duty_cycle)) {
121 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
131 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
141 if (!this->
read_byte(EMC2101_REGISTER_EXTERNAL_TEMP_MSB, &msb) ||
142 !this->
read_byte(EMC2101_REGISTER_EXTERNAL_TEMP_LSB, &lsb)) {
143 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
149 uint16_t
raw = (msb << 8 | lsb) >> 5;
156 if (!this->
read_byte(EMC2101_REGISTER_TACH_LSB, &lsb) || !this->
read_byte(EMC2101_REGISTER_TACH_MSB, &msb)) {
157 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
163 uint16_t tach = msb << 8 | lsb;
164 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
constexpr float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
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).