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,15 +33,23 @@
using namespace upm;
Jhd1313m1::Jhd1313m1(int bus, int lcdAddress, int rgbAddress)
: LCD(bus, lcdAddress), m_i2c_lcd_rgb(bus)
: m_i2c_lcd_rgb(bus), m_i2c_lcd_control(bus)
{
m_rgb_address = rgbAddress;
m_name = "Jhd1313m1";
m_lcd_control_address = lcdAddress;
mraa_result_t ret = m_i2c_lcd_rgb.address(m_rgb_address);
if (ret != MRAA_SUCCESS) {
fprintf(stderr, "Messed up i2c bus\n");
}
ret = m_i2c_lcd_control.address(m_lcd_control_address);
if (ret != MRAA_SUCCESS) {
fprintf(stderr, "Messed up i2c bus\n");
}
usleep(50000);
ret = m_i2c_lcd_control.writeReg(LCD_CMD, LCD_FUNCTIONSET | LCD_2LINE);

View File

@ -24,6 +24,7 @@
#pragma once
#include <string>
#include <mraa/i2c.hpp>
#include "lcd.h"
namespace upm
@ -113,5 +114,7 @@ class Jhd1313m1 : public LCD
private:
int m_rgb_address;
mraa::I2c m_i2c_lcd_rgb;
int m_lcd_control_address;
mraa::I2c m_i2c_lcd_control;
};
}

View File

@ -26,20 +26,12 @@
#include <unistd.h>
#include "lcd.h"
#include "hd44780_bits.h"
#include "lcd_private.h"
using namespace upm;
LCD::LCD(int bus, int lcdAddress) : m_i2c_lcd_control(bus)
LCD::LCD()
{
m_lcd_control_address = lcdAddress;
m_bus = bus;
mraa_result_t ret = m_i2c_lcd_control.address(m_lcd_control_address);
if (ret != MRAA_SUCCESS) {
fprintf(stderr, "Messed up i2c bus\n");
}
m_name = "LCD";
}
LCD::~LCD()
@ -53,21 +45,6 @@ LCD::write(int row, int column, std::string msg)
return write(msg);
}
mraa_result_t
LCD::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;
}
std::string
LCD::name()
{

View File

@ -24,7 +24,7 @@
#pragma once
#include <string>
#include <mraa/i2c.hpp>
#include <mraa.h>
namespace upm
{
@ -36,7 +36,7 @@ namespace upm
class LCD
{
public:
LCD(int bus, int lcdAddress);
LCD();
virtual ~LCD();
mraa_result_t write(int x, int y, std::string msg);
@ -44,15 +44,10 @@ class LCD
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[]);
std::string name();
protected:
std::string m_name;
int m_lcd_control_address;
int m_bus;
mraa::I2c m_i2c_lcd_control;
};
}

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

View File

@ -28,6 +28,7 @@
#pragma once
#include <string>
#include <mraa/i2c.hpp>
#include "lcd.h"
namespace upm
@ -95,10 +96,23 @@ class Lcm1602 : public LCD
*/
mraa_result_t home();
/**
* Create a custom character
*
* @param charSlot the character slot to write, only 8 are available
* @param charData The character data (8 bytes) making up the character
* @return Result of operation
*/
mraa_result_t createChar(uint8_t charSlot, uint8_t charData[]);
private:
mraa_result_t send(uint8_t value, int mode);
mraa_result_t write4bits(uint8_t value);
mraa_result_t expandWrite(uint8_t value);
mraa_result_t pulseEnable(uint8_t value);
int m_lcd_control_address;
mraa::I2c m_i2c_lcd_control;
};
}

View File

@ -30,8 +30,17 @@
using namespace upm;
SSD1308::SSD1308(int bus_in, int addr_in) : LCD(bus_in, addr_in)
SSD1308::SSD1308(int bus_in, int addr_in) : m_i2c_lcd_control(bus_in)
{
m_lcd_control_address = addr_in;
m_name = "SSD1308";
mraa_result_t error = m_i2c_lcd_control.address(m_lcd_control_address);
if (error != MRAA_SUCCESS) {
fprintf(stderr, "Failed to initialize i2c bus\n");
return;
}
m_i2c_lcd_control.writeReg(LCD_CMD, DISPLAY_CMD_OFF); // display off
usleep(4500);
m_i2c_lcd_control.writeReg(LCD_CMD, DISPLAY_CMD_ON); // display on

View File

@ -25,6 +25,7 @@
#pragma once
#include <string>
#include <mraa/i2c.hpp>
#include "lcd.h"
#include "ssd.h"
@ -108,5 +109,8 @@ class SSD1308 : public LCD
mraa_result_t writeChar(uint8_t value);
mraa_result_t setNormalDisplay();
mraa_result_t setAddressingMode(displayAddressingMode mode);
int m_lcd_control_address;
mraa::I2c m_i2c_lcd_control;
};
}

View File

@ -33,9 +33,19 @@ using namespace upm;
#define INIT_SLEEP 50000
#define CMD_SLEEP 10000
SSD1327::SSD1327(int bus_in, int addr_in) : LCD(bus_in, addr_in)
SSD1327::SSD1327(int bus_in, int addr_in) : m_i2c_lcd_control(bus_in)
{
mraa_result_t error = MRAA_SUCCESS;
m_lcd_control_address = addr_in;
m_name = "SSD1327";
error = m_i2c_lcd_control.address(m_lcd_control_address);
if (error != MRAA_SUCCESS) {
fprintf(stderr, "Failed to initialize i2c bus\n");
return;
}
usleep(INIT_SLEEP);
m_i2c_lcd_control.writeReg(LCD_CMD, 0xFD); // Unlock OLED driver IC MCU
// interface from entering command.

View File

@ -25,6 +25,7 @@
#pragma once
#include <string>
#include <mraa/i2c.hpp>
#include "lcd.h"
#include "ssd.h"
@ -119,5 +120,8 @@ class SSD1327 : public LCD
uint8_t grayHigh;
uint8_t grayLow;
int m_lcd_control_address;
mraa::I2c m_i2c_lcd_control;
};
}