IICLcd::close() {
return maa_i2c_stop(m_i2c_lcd_control);
}
+
+maa_result_t
+IICLcd::i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) {
+ maa_result_t error = MAA_SUCCESS;
+
+ uint8_t data[2] = { addr, value };
+ error = maa_i2c_address (ctx, deviceAdress);
+ error = maa_i2c_write (ctx, data, 2);
+
+ return error;
+}
+
+maa_result_t
+IICLcd::i2Cmd (maa_i2c_context ctx, uint8_t value) {
+ maa_result_t error = MAA_SUCCESS;
+
+ uint8_t data[2] = { LCD_CMD, value };
+ error = maa_i2c_address (ctx, m_lcd_control_address);
+ error = maa_i2c_write (ctx, data, 2);
+
+ return error;
+}
+
+maa_result_t
+IICLcd::i2cData (maa_i2c_context ctx, uint8_t value) {
+ maa_result_t error = MAA_SUCCESS;
+
+ uint8_t data[2] = { LCD_DATA, value };
+ error = maa_i2c_address (ctx, m_lcd_control_address);
+ error = maa_i2c_write (ctx, data, 2);
+
+ return error;
+}
#define LCD_DISPLAYCONTROL 0x08
#define LCD_CURSORSHIFT 0x10
#define LCD_FUNCTIONSET 0x20
-#define LCD_SETCGRAMADDR 0x40
-#define LCD_SETDDRAMADDR 0x80
+#define LCD_DATA 0x40
+#define LCD_CMD 0x80
#define LCD_BACKLIGHT 0x08
#define LCD_NOBACKLIGHT 0x00
class IICLcd {
public:
IICLcd (int bus, int lcdAddress);
- virtual maa_result_t write (std::string msg) = 0;
maa_result_t write (int x, int y, std::string msg);
+
+ virtual maa_result_t write (std::string msg) = 0;
virtual maa_result_t setCursor (int row, int column) = 0;
virtual maa_result_t clear () = 0;
virtual maa_result_t home () = 0;
+ virtual maa_result_t i2Cmd (maa_i2c_context ctx, uint8_t value);
+ virtual maa_result_t i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
+ virtual maa_result_t i2cData (maa_i2c_context ctx, uint8_t value);
+
maa_result_t close();
std::string name()
{
}
usleep(50000);
- cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
+ i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
usleep(4500);
- cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
+ i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
usleep(4500);
- cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
+ i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
usleep(4500);
- cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
+ i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
- cmd (m_i2c_lcd_control, LCD_DISPLAYCONTROL | LCD_DISPLAYON);
+ i2Cmd (m_i2c_lcd_control, LCD_DISPLAYCONTROL | LCD_DISPLAYON);
clear ();
usleep(4500);
- cmd (m_i2c_lcd_control, LCD_ENTRYMODESET |
- LCD_ENTRYLEFT |
- LCD_ENTRYSHIFTDECREMENT);
+ i2Cmd (m_i2c_lcd_control, LCD_ENTRYMODESET |
+ LCD_ENTRYLEFT |
+ LCD_ENTRYSHIFTDECREMENT);
- setReg (m_i2c_lcd_rgb, m_rgb_address, 0, 0);
- setReg (m_i2c_lcd_rgb, m_rgb_address, 1, 0);
- setReg (m_i2c_lcd_rgb, m_rgb_address, 0x08, 0xAA);
+ i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0, 0);
+ i2cReg (m_i2c_lcd_rgb, m_rgb_address, 1, 0);
+ i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x08, 0xAA);
- setReg (m_i2c_lcd_rgb, m_rgb_address, 0x04, 255);
- setReg (m_i2c_lcd_rgb, m_rgb_address, 0x03, 255);
- setReg (m_i2c_lcd_rgb, m_rgb_address, 0x02, 255);
+ i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x04, 255);
+ i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x03, 255);
+ i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x02, 255);
}
Jhd1313m1::~Jhd1313m1() {
maa_result_t error = MAA_SUCCESS;
uint8_t data[2] = {0x40, 0};
for (std::string::size_type i = 0; i < msg.size(); ++i) {
- data[1] = msg[i];
- error = maa_i2c_address (m_i2c_lcd_control, m_lcd_control_address);
- error = maa_i2c_write (m_i2c_lcd_control, data, 2);
+ error = i2cData (m_i2c_lcd_control, msg[i]);
}
return error;
maa_result_t
Jhd1313m1::setCursor (int row, int column) {
maa_result_t error = MAA_SUCCESS;
-
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
uint8_t offset = ((column % 16) + row_addr[row]);
-
- uint8_t data[2] = { 0x80, offset };
- error = maa_i2c_address (m_i2c_lcd_control, m_lcd_control_address);
- error = maa_i2c_write (m_i2c_lcd_control, data, 2);
+ error = i2Cmd (m_i2c_lcd_control, offset);
return error;
}
maa_result_t
Jhd1313m1::clear () {
- return cmd (m_i2c_lcd_control, LCD_CLEARDISPLAY);
+ return i2Cmd (m_i2c_lcd_control, LCD_CLEARDISPLAY);
}
maa_result_t
Jhd1313m1::home () {
- return cmd (m_i2c_lcd_control, LCD_RETURNHOME);
-}
-
-/*
- * **************
- * private area
- * **************
- */
-maa_result_t
-Jhd1313m1::setReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) {
- maa_result_t error = MAA_SUCCESS;
-
- uint8_t data[2] = { addr, value };
- error = maa_i2c_address (ctx, deviceAdress);
- error = maa_i2c_write (ctx, data, 2);
-
- return error;
-}
-
-maa_result_t
-Jhd1313m1::cmd (maa_i2c_context ctx, uint8_t value) {
- maa_result_t error = MAA_SUCCESS;
-
- uint8_t data[2] = { 0x80, value };
- error = maa_i2c_address (ctx, m_lcd_control_address);
- error = maa_i2c_write (ctx, data, 2);
-
- return error;
+ return i2Cmd (m_i2c_lcd_control, LCD_RETURNHOME);
}
maa_result_t home ();
private:
- maa_result_t cmd (maa_i2c_context ctx, uint8_t value);
- maa_result_t setReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
-
int m_rgb_address;
maa_i2c_context m_i2c_lcd_rgb;
};
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
uint8_t offset = ((column % 16) + row_addr[row]);
- return send (LCD_SETDDRAMADDR | offset, 0);
+ return send (LCD_CMD | offset, 0);
}
maa_result_t
* **************
*/
maa_result_t
-SSD1308::i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) {
- maa_result_t error = MAA_SUCCESS;
-
- uint8_t data[2] = { addr, value };
- error = maa_i2c_address (ctx, deviceAdress);
- error = maa_i2c_write (ctx, data, 2);
-
- return error;
-}
-
-maa_result_t
-SSD1308::i2Cmd (maa_i2c_context ctx, uint8_t value) {
- maa_result_t error = MAA_SUCCESS;
-
- uint8_t data[2] = { 0x80, value };
- error = maa_i2c_address (ctx, m_lcd_control_address);
- error = maa_i2c_write (ctx, data, 2);
-
- return error;
-}
-
-maa_result_t
-SSD1308::i2cData (maa_i2c_context ctx, uint8_t value) {
- maa_result_t error = MAA_SUCCESS;
-
- uint8_t data[2] = { 0x40, value };
- error = maa_i2c_address (ctx, m_lcd_control_address);
- error = maa_i2c_write (ctx, data, 2);
-
- return error;
-}
-
-maa_result_t
SSD1308::writeChar (maa_i2c_context ctx, uint8_t value) {
if (value < 0x20 || value > 0x7F) {
value = 0x20; // space
~SSD1308 ();
maa_result_t draw(uint8_t *data, int bytes);
- // virtual methods
+ // pure virtual methods
maa_result_t write (std::string msg);
maa_result_t setCursor (int row, int column);
maa_result_t clear ();
maa_result_t home ();
private:
- maa_result_t i2Cmd (maa_i2c_context ctx, uint8_t value);
- maa_result_t i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
- maa_result_t i2cData (maa_i2c_context ctx, uint8_t value);
maa_result_t writeChar (maa_i2c_context ctx, uint8_t value);
maa_result_t setNormalDisplay ();
maa_result_t setAddressingMode (displayAddressingMode mode);