2 * The MIT License (MIT)
4 * Author: Daniel Mosquera
5 * Copyright (c) 2013 Daniel Mosquera
7 * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
8 * Copyright (c) 2014 Intel Corporation.
10 * Permission is hereby granted, free of charge, to any person obtaining a copy of
11 * this software and associated documentation files (the "Software"), to deal in
12 * the Software without restriction, including without limitation the rights to
13 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
14 * the Software, and to permit persons to whom the Software is furnished to do so,
15 * subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in all
18 * copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
23 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 Lcm1602::Lcm1602(int bus_in, int addr_in) : IICLcd (bus_in, addr_in) {
36 maa_result_t error = MAA_SUCCESS;
39 expandWrite(LCD_BACKLIGHT);
42 write4bits(0x03 << 4);
49 // Put into 4 bit mode
52 // Set numeber of lines
53 send(LCD_FUNCTIONSET | 0x0f, 0);
54 send(LCD_DISPLAYCONTROL | LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF, 0);
58 send(LCD_ENTRYMODESET | LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT, 0);
63 Lcm1602::~Lcm1602 () {
73 Lcm1602::write (std::string msg) {
74 maa_result_t error = MAA_SUCCESS;
75 for (std::string::size_type i = 0; i < msg.size(); ++i) {
76 error = send (msg[i], LCD_RS);
82 Lcm1602::setCursor (int row, int column) {
83 maa_result_t error = MAA_SUCCESS;
85 int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
86 uint8_t offset = ((column % 16) + row_addr[row]);
88 return send (LCD_SETDDRAMADDR | offset, 0);
93 return send(LCD_CLEARDISPLAY, 0);
98 return send(LCD_RETURNHOME, 0);
107 Lcm1602::send (uint8_t value, int mode) {
108 maa_result_t ret = MAA_SUCCESS;
109 uint8_t h = value & 0xf0;
110 uint8_t l = (value << 4) & 0xf0;
111 ret = write4bits(h | mode);
112 ret = write4bits(l | mode);
117 Lcm1602::write4bits(uint8_t value)
119 maa_result_t ret = MAA_SUCCESS;
120 ret = expandWrite(value);
121 ret = pulseEnable(value);
126 Lcm1602::expandWrite(uint8_t value)
128 uint8_t buffer = value | LCD_BACKLIGHT;
129 return maa_i2c_write_byte(m_i2c_lcd_control, buffer);
133 Lcm1602::pulseEnable(uint8_t value)
135 maa_result_t ret = MAA_SUCCESS;
136 ret = expandWrite(value | LCD_EN);
138 ret = expandWrite(value & ~LCD_EN);