upm  1.0.2
Sensor/Actuator repository for libmraa (v1.1.1)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lcm1602.hpp
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.hpp"
42 
43 namespace upm
44 {
70 class Lcm1602 : public LCD
71 {
72  public:
83  Lcm1602(int bus = 0, int address = 0x27, bool isExpander=true,
84  uint8_t numColumns = 16, uint8_t numRows = 2);
85 
100  Lcm1602(int rs, int enable,
101  int d0, int d1, int d2, int d3,
102  uint8_t numColumns = 16, uint8_t numRows = 2);
103 
107  ~Lcm1602();
115  mraa::Result write(std::string msg);
123  mraa::Result setCursor(int row, int column);
129  mraa::Result clear();
135  mraa::Result home();
136 
144  mraa::Result createChar(uint8_t charSlot, uint8_t charData[]);
145 
151  mraa::Result displayOn();
152 
158  mraa::Result displayOff();
159 
165  mraa::Result cursorOn();
166 
172  mraa::Result cursorOff();
173 
179  mraa::Result cursorBlinkOn();
180 
186  mraa::Result cursorBlinkOff();
187 
193  mraa::Result backlightOn();
194 
200  mraa::Result backlightOff();
201 
207  mraa::Result scrollDisplayLeft();
208 
214  mraa::Result scrollDisplayRight();
215 
221  mraa::Result entryLeftToRight();
222 
228  mraa::Result entryRightToLeft();
229 
235  mraa::Result autoscrollOn();
236 
242  mraa::Result autoscrollOff();
243 
244 
245  protected:
246  mraa::Result send(uint8_t value, int mode);
247  mraa::Result write4bits(uint8_t value);
248  mraa::Result expandWrite(uint8_t value);
249  mraa::Result pulseEnable(uint8_t value);
250 
251  uint8_t m_displayControl;
252  uint8_t m_entryDisplayMode;
253 
254  // Display size
255  uint8_t m_numColumns;
256  uint8_t m_numRows;
257 
258  mraa::I2c* m_i2c_lcd_control;
259 
260  // gpio operation
261  mraa::Gpio* m_gpioRS;
262  mraa::Gpio* m_gpioEnable;
263  mraa::Gpio* m_gpioD0;
264  mraa::Gpio* m_gpioD1;
265  mraa::Gpio* m_gpioD2;
266  mraa::Gpio* m_gpioD3;
267 
268  // Backlight
269  uint8_t m_backlight;
270 
271  // Add a command() and data() virtual member functions, with a
272  // default implementation in lcm1602. This is expected to be
273  // implemented by derived classes with different needs (Jhd1313m1,
274  // for example).
275  virtual mraa::Result command(uint8_t cmd);
276  virtual mraa::Result data(uint8_t data);
277 
278  int m_lcd_control_address;
279 
280  private:
281 
282  // true if using i2c, false otherwise (gpio)
283  bool m_isI2C;
284 };
285 }
~Lcm1602()
Definition: lcm1602.cxx:167
mraa::Result home()
Definition: lcm1602.cxx:266
mraa::Result scrollDisplayRight()
Definition: lcm1602.cxx:342
mraa::Result autoscrollOff()
Definition: lcm1602.cxx:365
mraa::Result backlightOn()
Definition: lcm1602.cxx:325
mraa::Result cursorOn()
Definition: lcm1602.cxx:301
mraa::Result displayOff()
Definition: lcm1602.cxx:295
mraa::Result cursorBlinkOn()
Definition: lcm1602.cxx:313
mraa::Result scrollDisplayLeft()
Definition: lcm1602.cxx:337
Definition: lcd.hpp:37
mraa::Result displayOn()
Definition: lcm1602.cxx:289
mraa::Result write(std::string msg)
Definition: lcm1602.cxx:192
mraa::Result createChar(uint8_t charSlot, uint8_t charData[])
Definition: lcm1602.cxx:275
Lcm1602(int bus=0, int address=0x27, bool isExpander=true, uint8_t numColumns=16, uint8_t numRows=2)
Definition: lcm1602.cxx:43
mraa::Result entryLeftToRight()
Definition: lcm1602.cxx:347
mraa::Result backlightOff()
Definition: lcm1602.cxx:331
mraa::Result cursorBlinkOff()
Definition: lcm1602.cxx:319
mraa::Result entryRightToLeft()
Definition: lcm1602.cxx:353
mraa::Result setCursor(int row, int column)
Definition: lcm1602.cxx:202
mraa::Result autoscrollOn()
Definition: lcm1602.cxx:359
mraa::Result clear()
Definition: lcm1602.cxx:257
API for the LCM1602 I2C controller for HD44780-based displays.
Definition: lcm1602.hpp:70
mraa::Result cursorOff()
Definition: lcm1602.cxx:307