upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
lcm1602.h
1 /*
2  * The MIT License (MIT)
3  *
4  * Author: Daniel Mosquera
5  * Copyright (c) 2013 Daniel Mosquera
6  *
7  * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
8  * Copyright (c) 2014 Intel Corporation.
9  *
10  * Contributions: Jon Trulson <jtrulson@ics.com>
11  * Sergey Kiselev <sergey.kiselev@intel.com>
12  *
13  * Permission is hereby granted, free of uint8_tge, to any person
14  * obtaining a copy of this software and associated documentation
15  * files (the "Software"), to deal in the Software without
16  * restriction, including without limitation the rights to use, copy,
17  * modify, merge, publish, distribute, sublicense, and/or sell copies
18  * of the Software, and to permit persons to whom the Software is
19  * furnished to do so, subject to the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31  * SOFTWARE.
32  */
33 
34 #pragma once
35 
36 #include <string>
37 #include <mraa/i2c.hpp>
38 
39 #include <mraa/gpio.hpp>
40 
41 #include "lcd.h"
42 
43 namespace upm
44 {
70 class Lcm1602 : public LCD
71 {
72  public:
81  Lcm1602(int bus, int address, bool isExpander=true,
82  uint8_t numColumns = 16, uint8_t numRows = 4);
83 
96  Lcm1602(uint8_t rs, uint8_t enable,
97  uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
98  uint8_t numColumns = 16, uint8_t numRows = 4);
99 
103  ~Lcm1602();
111  mraa::Result write(std::string msg);
119  mraa::Result setCursor(int row, int column);
125  mraa::Result clear();
131  mraa::Result home();
132 
140  mraa::Result createChar(uint8_t charSlot, uint8_t charData[]);
141 
147  mraa::Result displayOn();
148 
154  mraa::Result displayOff();
155 
161  mraa::Result cursorOn();
162 
168  mraa::Result cursorOff();
169 
175  mraa::Result cursorBlinkOn();
176 
182  mraa::Result cursorBlinkOff();
183 
189  mraa::Result scrollDisplayLeft();
190 
196  mraa::Result scrollDisplayRight();
197 
203  mraa::Result entryLeftToRight();
204 
210  mraa::Result entryRightToLeft();
211 
217  mraa::Result autoscrollOn();
218 
224  mraa::Result autoscrollOff();
225 
226 
227  protected:
228  mraa::Result send(uint8_t value, int mode);
229  mraa::Result write4bits(uint8_t value);
230  mraa::Result expandWrite(uint8_t value);
231  mraa::Result pulseEnable(uint8_t value);
232 
233  uint8_t m_displayControl;
234  uint8_t m_entryDisplayMode;
235 
236  // Display size
237  uint8_t m_numColumns;
238  uint8_t m_numRows;
239 
240  // Add a command() and data() virtual member functions, with a
241  // default implementation in lcm1602. This is expected to be
242  // implemented by derived classes with different needs (Jhd1313m1,
243  // for example).
244  virtual mraa::Result command(uint8_t cmd);
245  virtual mraa::Result data(uint8_t data);
246 
247  int m_lcd_control_address;
248  mraa::I2c* m_i2c_lcd_control;
249 
250  private:
251 
252  // true if using i2c, false otherwise (gpio)
253  bool m_isI2C;
254 
255  // gpio operation
256  mraa::Gpio* m_gpioRS;
257  mraa::Gpio* m_gpioEnable;
258  mraa::Gpio* m_gpioD0;
259  mraa::Gpio* m_gpioD1;
260  mraa::Gpio* m_gpioD2;
261  mraa::Gpio* m_gpioD3;
262 };
263 }
mraa::Result cursorOff()
Definition: lcm1602.cxx:307
mraa::Result autoscrollOff()
Definition: lcm1602.cxx:353
mraa::Result clear()
Definition: lcm1602.cxx:257
~Lcm1602()
Definition: lcm1602.cxx:166
mraa::Result write(std::string msg)
Definition: lcm1602.cxx:191
mraa::Result displayOff()
Definition: lcm1602.cxx:295
mraa::Result cursorOn()
Definition: lcm1602.cxx:301
mraa::Result cursorBlinkOn()
Definition: lcm1602.cxx:313
mraa::Result scrollDisplayRight()
Definition: lcm1602.cxx:330
Definition: lcd.h:37
mraa::Result cursorBlinkOff()
Definition: lcm1602.cxx:319
mraa::Result scrollDisplayLeft()
Definition: lcm1602.cxx:325
Lcm1602(int bus, int address, bool isExpander=true, uint8_t numColumns=16, uint8_t numRows=4)
Definition: lcm1602.cxx:43
mraa::Result entryLeftToRight()
Definition: lcm1602.cxx:335
mraa::Result createChar(uint8_t charSlot, uint8_t charData[])
Definition: lcm1602.cxx:275
mraa::Result home()
Definition: lcm1602.cxx:266
mraa::Result autoscrollOn()
Definition: lcm1602.cxx:347
mraa::Result setCursor(int row, int column)
Definition: lcm1602.cxx:201
mraa::Result entryRightToLeft()
Definition: lcm1602.cxx:341
API for the LCM1602 I2C controller for HD44780-based displays.
Definition: lcm1602.h:70
mraa::Result displayOn()
Definition: lcm1602.cxx:289