From 7bd7e80b2eecefa3f79423d48abb8ce6b7083ff0 Mon Sep 17 00:00:00 2001 From: Clark Scheff Date: Wed, 25 Feb 2015 05:17:59 +0000 Subject: [PATCH] i2clcd: Add createChar method LCDs based on the HD44780 allow for setting 8 custom characters. This patch adds a method that exposes this capability. Signed-off-by: Clark Scheff Signed-off-by: Mihai Tudor Panu --- src/lcd/i2clcd.cxx | 14 ++++++++++++++ src/lcd/i2clcd.h | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/src/lcd/i2clcd.cxx b/src/lcd/i2clcd.cxx index 318c27c1..8d94fa1f 100644 --- a/src/lcd/i2clcd.cxx +++ b/src/lcd/i2clcd.cxx @@ -47,6 +47,20 @@ I2CLcd::write (int row, int column, std::string msg) { write (msg); } +mraa_result_t +I2CLcd::createChar(uint8_t charSlot, uint8_t charData[]) { + mraa_result_t error = MRAA_SUCCESS; + charSlot &= 0x07; // only have 8 positions we can set + error = i2Cmd(m_i2c_lcd_control, LCD_SETCGRAMADDR | (charSlot << 3)); + if (error == MRAA_SUCCESS) { + for (int i = 0; i < 8; i++) { + error = i2cData(m_i2c_lcd_control, charData[i]); + } + } + + return error; +} + mraa_result_t I2CLcd::close() { return mraa_i2c_stop(m_i2c_lcd_control); diff --git a/src/lcd/i2clcd.h b/src/lcd/i2clcd.h index 57588864..98e73de1 100644 --- a/src/lcd/i2clcd.h +++ b/src/lcd/i2clcd.h @@ -68,6 +68,9 @@ namespace upm { #define LCD_5x10DOTS 0x04 #define LCD_5x8DOTS 0x00 +// flags for CGRAM +#define LCD_SETCGRAMADDR 0x40 + #define LCD_EN 0x04 // Enable bit #define LCD_RW 0x02 // Read/Write bit #define LCD_RS 0x01 // Register select bit @@ -85,6 +88,7 @@ class I2CLcd { virtual mraa_result_t setCursor (int row, int column) = 0; virtual mraa_result_t clear () = 0; virtual mraa_result_t home () = 0; + virtual mraa_result_t createChar(uint8_t charSlot, uint8_t charData[]); virtual mraa_result_t i2Cmd (mraa_i2c_context ctx, uint8_t value); virtual mraa_result_t i2cReg (mraa_i2c_context ctx, int deviceAdress, int addr, uint8_t data); virtual mraa_result_t i2cData (mraa_i2c_context ctx, uint8_t value);