lcd: remove i2c context from LCD base class

This commit removes the I2C context from the LCD base class and moves
it into each of the drivers.

In addition, the createChar() virtual function was removed from the
base class, as it directly used the now non-existant i2c context, and
it would not work on anything other than hd44780 based controllers and
displays anyway. Also, it is likely the capability itself, as well as
the data required to implement it, is going to be different from
device to device.

createChar() has been added to the Lcm1602 driver which can support it.

While doing this work, the LCD base class m_name is now set appropriately
in the driver constructors.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Jon Trulson
2015-07-09 13:54:49 -06:00
committed by Mihai Tudor Panu
parent 56f7e97536
commit 1647f572ff
10 changed files with 84 additions and 36 deletions

View File

@ -33,9 +33,18 @@
using namespace upm;
Lcm1602::Lcm1602(int bus_in, int addr_in) : LCD(bus_in, addr_in)
Lcm1602::Lcm1602(int bus_in, int addr_in) : m_i2c_lcd_control(bus_in)
{
mraa_result_t error = MRAA_SUCCESS;
m_name = "Lcm1602 (I2C)";
m_lcd_control_address = addr_in;
error = m_i2c_lcd_control.address(m_lcd_control_address);
if (error != MRAA_SUCCESS) {
fprintf(stderr, "Failed to initialize i2c bus\n");
return;
}
usleep(50000);
expandWrite(LCD_BACKLIGHT);
@ -104,6 +113,21 @@ Lcm1602::home()
return send(LCD_RETURNHOME, 0);
}
mraa_result_t
Lcm1602::createChar(uint8_t charSlot, uint8_t charData[])
{
mraa_result_t error = MRAA_SUCCESS;
charSlot &= 0x07; // only have 8 positions we can set
error = m_i2c_lcd_control.writeReg(LCD_CMD, LCD_SETCGRAMADDR | (charSlot << 3));
if (error == MRAA_SUCCESS) {
for (int i = 0; i < 8; i++) {
error = m_i2c_lcd_control.writeReg(LCD_DATA, charData[i]);
}
}
return error;
}
/*
* **************
* private area