From fd7e861ff5395d360f894de344ecc2df741cf522 Mon Sep 17 00:00:00 2001 From: "Andrew J.Swan" Date: Mon, 4 Apr 2022 02:13:59 +0300 Subject: [PATCH] Added a function to load custom characters in LCD display (#3279) Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> --- esphome/components/lcd_base/lcd_display.cpp | 7 +++++++ esphome/components/lcd_base/lcd_display.h | 3 +++ 2 files changed, 10 insertions(+) diff --git a/esphome/components/lcd_base/lcd_display.cpp b/esphome/components/lcd_base/lcd_display.cpp index b937e36c6c..180d5e93ac 100644 --- a/esphome/components/lcd_base/lcd_display.cpp +++ b/esphome/components/lcd_base/lcd_display.cpp @@ -167,6 +167,13 @@ void LCDDisplay::strftime(uint8_t column, uint8_t row, const char *format, time: } void LCDDisplay::strftime(const char *format, time::ESPTime time) { this->strftime(0, 0, format, time); } #endif +void LCDDisplay::loadchar(uint8_t location, uint8_t charmap[]) { + location &= 0x7; // we only have 8 locations 0-7 + this->command_(LCD_DISPLAY_COMMAND_SET_CGRAM_ADDR | (location << 3)); + for (int i = 0; i < 8; i++) { + this->send(charmap[i], true); + } +} } // namespace lcd_base } // namespace esphome diff --git a/esphome/components/lcd_base/lcd_display.h b/esphome/components/lcd_base/lcd_display.h index 0c9e59758c..c8ba39f0d4 100644 --- a/esphome/components/lcd_base/lcd_display.h +++ b/esphome/components/lcd_base/lcd_display.h @@ -51,6 +51,9 @@ class LCDDisplay : public PollingComponent { void strftime(const char *format, time::ESPTime time) __attribute__((format(strftime, 2, 0))); #endif + /// Load custom char to given location + void loadchar(uint8_t location, uint8_t charmap[]); + protected: virtual bool is_four_bit_mode() = 0; virtual void write_n_bits(uint8_t value, uint8_t n) = 0;