ESPHome 2025.6.3
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 ESP_LOGCONFIG(TAG, "Running setup");
11 this->rs_pin_->setup(); // OUTPUT
12 this->rs_pin_->digital_write(false);
13 if (this->rw_pin_ != nullptr) {
14 this->rw_pin_->setup(); // OUTPUT
15 this->rw_pin_->digital_write(false);
16 }
17 this->enable_pin_->setup(); // OUTPUT
18 this->enable_pin_->digital_write(false);
19
20 for (uint8_t i = 0; i < (uint8_t) (this->is_four_bit_mode() ? 4u : 8u); i++) {
21 this->data_pins_[i]->setup(); // OUTPUT
22 this->data_pins_[i]->digital_write(false);
23 }
24 LCDDisplay::setup();
25}
27 ESP_LOGCONFIG(TAG,
28 "GPIO LCD Display:\n"
29 " Columns: %u, Rows: %u",
30 this->columns_, this->rows_);
31 LOG_PIN(" RS Pin: ", this->rs_pin_);
32 LOG_PIN(" RW Pin: ", this->rw_pin_);
33 LOG_PIN(" Enable Pin: ", this->enable_pin_);
34
35 LOG_PIN(" Data Pin 0: ", data_pins_[0]);
36 LOG_PIN(" Data Pin 1: ", data_pins_[1]);
37 LOG_PIN(" Data Pin 2: ", data_pins_[2]);
38 LOG_PIN(" Data Pin 3: ", data_pins_[3]);
39 if (!is_four_bit_mode()) {
40 LOG_PIN(" Data Pin 4: ", data_pins_[4]);
41 LOG_PIN(" Data Pin 5: ", data_pins_[5]);
42 LOG_PIN(" Data Pin 6: ", data_pins_[6]);
43 LOG_PIN(" Data Pin 7: ", data_pins_[7]);
44 }
45 LOG_UPDATE_INTERVAL(this);
46}
47void GPIOLCDDisplay::write_n_bits(uint8_t value, uint8_t n) {
48 for (uint8_t i = 0; i < n; i++)
49 this->data_pins_[i]->digital_write(value & (1 << i));
50
51 this->enable_pin_->digital_write(true);
52 delayMicroseconds(1); // >450ns
53 this->enable_pin_->digital_write(false);
54 delayMicroseconds(40); // >37us
55}
56void GPIOLCDDisplay::send(uint8_t value, bool rs) {
57 this->rs_pin_->digital_write(rs);
58
59 if (this->is_four_bit_mode()) {
60 this->write_n_bits(value >> 4, 4);
61 this->write_n_bits(value, 4);
62 } else {
63 this->write_n_bits(value, 8);
64 }
65}
66
67} // namespace lcd_gpio
68} // 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