ESPHome  2024.3.2
gpio_lcd_display.cpp
Go to the documentation of this file.
1 #include "gpio_lcd_display.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace lcd_gpio {
6 
7 static const char *const TAG = "lcd_gpio";
8 
10  ESP_LOGCONFIG(TAG, "Setting up GPIO LCD Display...");
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  }
25 }
27  ESP_LOGCONFIG(TAG, "GPIO LCD Display:");
28  ESP_LOGCONFIG(TAG, " Columns: %u, Rows: %u", this->columns_, this->rows_);
29  LOG_PIN(" RS Pin: ", this->rs_pin_);
30  LOG_PIN(" RW Pin: ", this->rw_pin_);
31  LOG_PIN(" Enable Pin: ", this->enable_pin_);
32 
33  LOG_PIN(" Data Pin 0: ", data_pins_[0]);
34  LOG_PIN(" Data Pin 1: ", data_pins_[1]);
35  LOG_PIN(" Data Pin 2: ", data_pins_[2]);
36  LOG_PIN(" Data Pin 3: ", data_pins_[3]);
37  if (!is_four_bit_mode()) {
38  LOG_PIN(" Data Pin 4: ", data_pins_[4]);
39  LOG_PIN(" Data Pin 5: ", data_pins_[5]);
40  LOG_PIN(" Data Pin 6: ", data_pins_[6]);
41  LOG_PIN(" Data Pin 7: ", data_pins_[7]);
42  }
43  LOG_UPDATE_INTERVAL(this);
44 }
45 void GPIOLCDDisplay::write_n_bits(uint8_t value, uint8_t n) {
46  for (uint8_t i = 0; i < n; i++)
47  this->data_pins_[i]->digital_write(value & (1 << i));
48 
49  this->enable_pin_->digital_write(true);
50  delayMicroseconds(1); // >450ns
51  this->enable_pin_->digital_write(false);
52  delayMicroseconds(40); // >37us
53 }
54 void GPIOLCDDisplay::send(uint8_t value, bool rs) {
55  this->rs_pin_->digital_write(rs);
56 
57  if (this->is_four_bit_mode()) {
58  this->write_n_bits(value >> 4, 4);
59  this->write_n_bits(value, 4);
60  } else {
61  this->write_n_bits(value, 8);
62  }
63 }
64 
65 } // namespace lcd_gpio
66 } // namespace esphome
void setup()
virtual void digital_write(bool value)=0
virtual void setup()=0
void write_n_bits(uint8_t value, uint8_t n) override
void send(uint8_t value, bool rs) override
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition: core.cpp:28