upm  0.8.0
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(uint8_t rs, uint8_t enable,
101  uint8_t d0, uint8_t d1, uint8_t d2, uint8_t 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  // Backlight
259  uint8_t m_backlight;
260 
261  // Add a command() and data() virtual member functions, with a
262  // default implementation in lcm1602. This is expected to be
263  // implemented by derived classes with different needs (Jhd1313m1,
264  // for example).
265  virtual mraa::Result command(uint8_t cmd);
266  virtual mraa::Result data(uint8_t data);
267 
268  int m_lcd_control_address;
269  mraa::I2c* m_i2c_lcd_control;
270 
271  private:
272 
273  // true if using i2c, false otherwise (gpio)
274  bool m_isI2C;
275 
276  // gpio operation
277  mraa::Gpio* m_gpioRS;
278  mraa::Gpio* m_gpioEnable;
279  mraa::Gpio* m_gpioD0;
280  mraa::Gpio* m_gpioD1;
281  mraa::Gpio* m_gpioD2;
282  mraa::Gpio* m_gpioD3;
283 };
284 }
mraa::Result cursorOff()
Definition: lcm1602.cxx:309
mraa::Result autoscrollOff()
Definition: lcm1602.cxx:367
mraa::Result clear()
Definition: lcm1602.cxx:259
~Lcm1602()
Definition: lcm1602.cxx:168
mraa::Result write(std::string msg)
Definition: lcm1602.cxx:193
mraa::Result displayOff()
Definition: lcm1602.cxx:297
mraa::Result backlightOff()
Definition: lcm1602.cxx:333
mraa::Result cursorOn()
Definition: lcm1602.cxx:303
mraa::Result cursorBlinkOn()
Definition: lcm1602.cxx:315
mraa::Result scrollDisplayRight()
Definition: lcm1602.cxx:344
Definition: lcd.hpp:37
mraa::Result cursorBlinkOff()
Definition: lcm1602.cxx:321
mraa::Result scrollDisplayLeft()
Definition: lcm1602.cxx:339
mraa::Result entryLeftToRight()
Definition: lcm1602.cxx:349
mraa::Result createChar(uint8_t charSlot, uint8_t charData[])
Definition: lcm1602.cxx:277
Lcm1602(int bus=0, int address=0x27, bool isExpander=true, uint8_t numColumns=16, uint8_t numRows=2)
Definition: lcm1602.cxx:43
mraa::Result home()
Definition: lcm1602.cxx:268
mraa::Result backlightOn()
Definition: lcm1602.cxx:327
mraa::Result autoscrollOn()
Definition: lcm1602.cxx:361
mraa::Result setCursor(int row, int column)
Definition: lcm1602.cxx:203
mraa::Result entryRightToLeft()
Definition: lcm1602.cxx:355
API for the LCM1602 I2C controller for HD44780-based displays.
Definition: lcm1602.hpp:70
mraa::Result displayOn()
Definition: lcm1602.cxx:291