11static const char *
const TAG =
"EMC2101";
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;
60 ESP_LOGCONFIG(TAG,
"Running setup");
63 uint8_t chip_id =
reg(EMC2101_REGISTER_WHOAMI).
get();
64 if ((chip_id != EMC2101_CHIP_ID) && (chip_id != EMC2101_ALT_CHIP_ID)) {
65 ESP_LOGE(TAG,
"Wrong chip ID %02X", chip_id);
72 config |= EMC2101_ALT_TCH_BIT;
74 config |= EMC2101_DAC_BIT;
77 config |= EMC2101_POLARITY_BIT;
85 reg(EMC2101_REGISTER_FAN_CONFIG) |= EMC2101_CLK_OVR_BIT;
94 ESP_LOGCONFIG(TAG,
"Emc2101 component:");
97 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
99 ESP_LOGCONFIG(TAG,
" Mode: %s", this->
dac_mode_ ?
"DAC" :
"PWM");
104 " PWM Resolution: %02X\n"
105 " PWM Divider: %02X",
108 ESP_LOGCONFIG(TAG,
" Inverted: %s", YESNO(this->
inverted_));
113 ESP_LOGD(TAG,
"Setting duty fan setting to %02X", duty_cycle);
114 if (!this->
write_byte(EMC2101_REGISTER_FAN_SETTING, duty_cycle)) {
115 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
123 if (!this->
read_byte(EMC2101_REGISTER_FAN_SETTING, &duty_cycle)) {
124 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
134 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
144 if (!this->
read_byte(EMC2101_REGISTER_EXTERNAL_TEMP_MSB, &msb) ||
145 !this->
read_byte(EMC2101_REGISTER_EXTERNAL_TEMP_LSB, &lsb)) {
146 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
152 uint16_t
raw = (msb << 8 | lsb) >> 5;
159 if (!this->
read_byte(EMC2101_REGISTER_TACH_LSB, &lsb) || !this->
read_byte(EMC2101_REGISTER_TACH_MSB, &msb)) {
160 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
166 uint16_t tach = msb << 8 | lsb;
167 return tach == 0xFFFF ? 0.0f : 5400000.0f / tach;
virtual void mark_failed()
Mark this component as failed.
void status_set_warning(const char *message="unspecified")
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, bool stop=true)
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
bool read_byte(uint8_t a_register, uint8_t *data, bool stop=true)
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
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Providing packet encoding functions for exchanging data with a remote host.
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).