ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
gpio_lcd_display.cpp
Go to the documentation of this file.
1#include "gpio_lcd_display.h"
2#include "esphome/core/log.h"
3
4namespace esphome {
5namespace lcd_gpio {
6
7static const char *const TAG = "lcd_gpio";
8
10 this->rs_pin_->setup(); // OUTPUT
11 this->rs_pin_->digital_write(false);
12 if (this->rw_pin_ != nullptr) {
13 this->rw_pin_->setup(); // OUTPUT
14 this->rw_pin_->digital_write(false);
15 }
16 this->enable_pin_->setup(); // OUTPUT
17 this->enable_pin_->digital_write(false);
18
19 for (uint8_t i = 0; i < (uint8_t) (this->is_four_bit_mode() ? 4u : 8u); i++) {
20 this->data_pins_[i]->setup(); // OUTPUT
21 this->data_pins_[i]->digital_write(false);
22 }
23 LCDDisplay::setup();
24}
26 ESP_LOGCONFIG(TAG,
27 "GPIO LCD Display:\n"
28 " Columns: %u, Rows: %u",
29 this->columns_, this->rows_);
30 LOG_PIN(" RS Pin: ", this->rs_pin_);
31 LOG_PIN(" RW Pin: ", this->rw_pin_);
32 LOG_PIN(" Enable Pin: ", this->enable_pin_);
33
34 LOG_PIN(" Data Pin 0: ", data_pins_[0]);
35 LOG_PIN(" Data Pin 1: ", data_pins_[1]);
36 LOG_PIN(" Data Pin 2: ", data_pins_[2]);
37 LOG_PIN(" Data Pin 3: ", data_pins_[3]);
38 if (!is_four_bit_mode()) {
39 LOG_PIN(" Data Pin 4: ", data_pins_[4]);
40 LOG_PIN(" Data Pin 5: ", data_pins_[5]);
41 LOG_PIN(" Data Pin 6: ", data_pins_[6]);
42 LOG_PIN(" Data Pin 7: ", data_pins_[7]);
43 }
44 LOG_UPDATE_INTERVAL(this);
45}
46void GPIOLCDDisplay::write_n_bits(uint8_t value, uint8_t n) {
47 for (uint8_t i = 0; i < n; i++)
48 this->data_pins_[i]->digital_write(value & (1 << i));
49
50 this->enable_pin_->digital_write(true);
51 delayMicroseconds(1); // >450ns
52 this->enable_pin_->digital_write(false);
53 delayMicroseconds(40); // >37us
54}
55void GPIOLCDDisplay::send(uint8_t value, bool rs) {
56 this->rs_pin_->digital_write(rs);
57
58 if (this->is_four_bit_mode()) {
59 this->write_n_bits(value >> 4, 4);
60 this->write_n_bits(value, 4);
61 } else {
62 this->write_n_bits(value, 8);
63 }
64}
65
66} // namespace lcd_gpio
67} // namespace esphome
virtual void setup()=0
virtual void digital_write(bool value)=0
void send(uint8_t value, bool rs) override
void write_n_bits(uint8_t value, uint8_t n) override
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition core.cpp:31