ESPHome
2026.6.0-dev
Loading...
Searching...
No Matches
esphome
components
lcd_pcf8574
pcf8574_display.cpp
Go to the documentation of this file.
1
#include "
pcf8574_display.h
"
2
#include "
esphome/core/log.h
"
3
#include "
esphome/core/hal.h
"
4
5
namespace
esphome::lcd_pcf8574
{
6
7
static
const
char
*
const
TAG =
"lcd_pcf8574"
;
8
9
static
const
uint8_t LCD_DISPLAY_BACKLIGHT_ON = 0x08;
10
static
const
uint8_t LCD_DISPLAY_BACKLIGHT_OFF = 0x00;
11
12
void
PCF8574LCDDisplay::setup
() {
13
this->
backlight_value_
= LCD_DISPLAY_BACKLIGHT_ON;
14
if
(!this->
write_bytes
(this->
backlight_value_
,
nullptr
, 0)) {
15
this->
mark_failed
();
16
return
;
17
}
18
19
LCDDisplay::setup();
20
}
21
void
PCF8574LCDDisplay::dump_config
() {
22
ESP_LOGCONFIG(TAG,
23
"PCF8574 LCD Display:\n"
24
" Columns: %u, Rows: %u"
,
25
this->
columns_
, this->
rows_
);
26
LOG_I2C_DEVICE(
this
);
27
LOG_UPDATE_INTERVAL(
this
);
28
if
(this->
is_failed
()) {
29
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
30
}
31
}
32
void
PCF8574LCDDisplay::write_n_bits
(uint8_t value, uint8_t n) {
33
if
(n == 4) {
34
// Ugly fix: in the super setup() with n == 4 value needs to be shifted left
35
value <<= 4;
36
}
37
uint8_t data = value | this->
backlight_value_
;
// Set backlight state
38
this->
write_bytes
(data,
nullptr
, 0);
39
// Pulse ENABLE
40
this->
write_bytes
(data | 0x04,
nullptr
, 0);
41
delayMicroseconds
(1);
// >450ns
42
this->
write_bytes
(data,
nullptr
, 0);
43
delayMicroseconds
(100);
// >37us
44
}
45
void
PCF8574LCDDisplay::send
(uint8_t value,
bool
rs) {
46
this->
write_n_bits
((value & 0xF0) | rs, 0);
47
this->
write_n_bits
(((value << 4) & 0xF0) | rs, 0);
48
}
49
void
PCF8574LCDDisplay::backlight
() {
50
this->
backlight_value_
= LCD_DISPLAY_BACKLIGHT_ON;
51
this->
write_bytes
(this->
backlight_value_
,
nullptr
, 0);
52
}
53
void
PCF8574LCDDisplay::no_backlight
() {
54
this->
backlight_value_
= LCD_DISPLAY_BACKLIGHT_OFF;
55
this->
write_bytes
(this->
backlight_value_
,
nullptr
, 0);
56
}
57
58
}
// namespace esphome::lcd_pcf8574
esphome::Component::mark_failed
void mark_failed()
Mark this component as failed.
Definition
component.cpp:274
esphome::Component::is_failed
bool is_failed() const
Definition
component.h:272
esphome::i2c::I2CDevice::write_bytes
bool write_bytes(uint8_t a_register, const uint8_t *data, uint8_t len) const
Definition
i2c.h:251
esphome::lcd_base::LCDDisplay::rows_
uint8_t rows_
Definition
lcd_display.h:59
esphome::lcd_base::LCDDisplay::columns_
uint8_t columns_
Definition
lcd_display.h:58
esphome::lcd_pcf8574::PCF8574LCDDisplay::dump_config
void dump_config() override
Definition
pcf8574_display.cpp:21
esphome::lcd_pcf8574::PCF8574LCDDisplay::backlight
void backlight()
Definition
pcf8574_display.cpp:49
esphome::lcd_pcf8574::PCF8574LCDDisplay::send
void send(uint8_t value, bool rs) override
Definition
pcf8574_display.cpp:45
esphome::lcd_pcf8574::PCF8574LCDDisplay::backlight_value_
uint8_t backlight_value_
Definition
pcf8574_display.h:30
esphome::lcd_pcf8574::PCF8574LCDDisplay::write_n_bits
void write_n_bits(uint8_t value, uint8_t n) override
Definition
pcf8574_display.cpp:32
esphome::lcd_pcf8574::PCF8574LCDDisplay::no_backlight
void no_backlight()
Definition
pcf8574_display.cpp:53
esphome::lcd_pcf8574::PCF8574LCDDisplay::setup
void setup() override
Definition
pcf8574_display.cpp:12
hal.h
log.h
esphome::lcd_pcf8574
Definition
pcf8574_display.cpp:5
esphome::delayMicroseconds
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition
hal.cpp:48
pcf8574_display.h
Generated by
1.12.0