upm/src/lcd/jhd1313m1.cxx
Jon Trulson f133b6eb4c lcd: jhd1313m1: rewrite to use Lcm1602 as a base class
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2015-08-05 11:13:23 -07:00

131 lines
4.0 KiB
C++

/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Contributions: Jon Trulson <jtrulson@ics.com>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <stdexcept>
#include <unistd.h>
#include "lcd_private.h"
#include "hd44780_bits.h"
#include "jhd1313m1.h"
using namespace upm;
Jhd1313m1::Jhd1313m1(int bus, int lcdAddress, int rgbAddress)
: m_i2c_lcd_rgb(bus), Lcm1602(bus, lcdAddress, false)
{
m_rgb_address = rgbAddress;
m_name = "Jhd1313m1";
mraa_result_t ret = m_i2c_lcd_rgb.address(m_rgb_address);
if (ret != MRAA_SUCCESS) {
fprintf(stderr, "Messed up i2c bus\n");
}
usleep(50000);
ret = command(LCD_FUNCTIONSET | LCD_2LINE);
if (!ret) {
ret = command(LCD_FUNCTIONSET | LCD_2LINE);
UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the LCD controller");
}
usleep(100);
ret = displayOn();
UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the LCD controller");
usleep(100);
ret = clear();
UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the LCD controller");
usleep(2000);
ret = command(LCD_ENTRYMODESET | LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT);
UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the LCD controller");
ret = m_i2c_lcd_rgb.writeReg(0, 0);
UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the RGB controller");
ret = m_i2c_lcd_rgb.writeReg(1, 0);
UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the RGB controller");
ret = m_i2c_lcd_rgb.writeReg(0x08, 0xAA);
UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the RGB controller");
ret = m_i2c_lcd_rgb.writeReg(0x04, 0xFF);
UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the RGB controller");
ret = m_i2c_lcd_rgb.writeReg(0x03, 0xFF);
UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the RGB controller");
ret = m_i2c_lcd_rgb.writeReg(0x02, 0xFF);
UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the RGB controller");
}
Jhd1313m1::~Jhd1313m1()
{
clear();
setColor(0x00, 0x00, 0x00);
}
mraa_result_t
Jhd1313m1::setColor(uint8_t r, uint8_t g, uint8_t b)
{
mraa_result_t ret;
ret = m_i2c_lcd_rgb.writeReg(0, 0);
UPM_GOTO_ON_MRAA_FAIL(ret, beach);
ret = m_i2c_lcd_rgb.writeReg(1, 0);
UPM_GOTO_ON_MRAA_FAIL(ret, beach);
ret = m_i2c_lcd_rgb.writeReg(0x08, 0xAA);
UPM_GOTO_ON_MRAA_FAIL(ret, beach);
ret = m_i2c_lcd_rgb.writeReg(0x04, r);
UPM_GOTO_ON_MRAA_FAIL(ret, beach);
ret = m_i2c_lcd_rgb.writeReg(0x03, g);
UPM_GOTO_ON_MRAA_FAIL(ret, beach);
ret = m_i2c_lcd_rgb.writeReg(0x02, b);
beach:
return ret;
}
mraa_result_t
Jhd1313m1::scroll(bool direction)
{
if (direction) {
return scrollDisplayLeft();
} else {
return scrollDisplayRight();
}
}
mraa_result_t Jhd1313m1::command(uint8_t cmd)
{
return m_i2c_lcd_control->writeReg(LCD_CMD, cmd);
}
mraa_result_t Jhd1313m1::data(uint8_t cmd)
{
return m_i2c_lcd_control->writeReg(LCD_DATA, cmd);
}