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,
"Setting up Emc2101 sensor...");
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,
"Communication with EMC2101 failed!");
99 ESP_LOGCONFIG(TAG,
" Mode: %s", this->
dac_mode_ ?
"DAC" :
"PWM");
104 ESP_LOGCONFIG(TAG,
" PWM Divider: %02X", this->
pwm_divider_);
106 ESP_LOGCONFIG(TAG,
" Inverted: %s", YESNO(this->
inverted_));
111 ESP_LOGD(TAG,
"Setting duty fan setting to %02X", duty_cycle);
112 if (!this->
write_byte(EMC2101_REGISTER_FAN_SETTING, duty_cycle)) {
113 ESP_LOGE(TAG,
"Communication with EMC2101 failed!");
121 if (!this->
read_byte(EMC2101_REGISTER_FAN_SETTING, &duty_cycle)) {
122 ESP_LOGE(TAG,
"Communication with EMC2101 failed!");
132 ESP_LOGE(TAG,
"Communication with EMC2101 failed!");
142 if (!this->
read_byte(EMC2101_REGISTER_EXTERNAL_TEMP_MSB, &msb) ||
143 !this->
read_byte(EMC2101_REGISTER_EXTERNAL_TEMP_LSB, &lsb)) {
144 ESP_LOGE(TAG,
"Communication with EMC2101 failed!");
150 uint16_t
raw = (msb << 8 | lsb) >> 5;
157 if (!this->
read_byte(EMC2101_REGISTER_TACH_LSB, &lsb) || !this->
read_byte(EMC2101_REGISTER_TACH_MSB, &msb)) {
158 ESP_LOGE(TAG,
"Communication with EMC2101 failed!");
164 uint16_t tach = msb << 8 | lsb;
165 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).