mraa: change all existing code to use libmraa.
[contrib/upm.git] / src / lcd / i2clcd.h
1 /*
2  * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3  * Copyright (c) 2014 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25
26 #include <string>
27 #include <mraa/i2c.h>
28
29 namespace upm {
30
31 // commands
32 #define LCD_CLEARDISPLAY 0x01
33 #define LCD_RETURNHOME 0x02
34 #define LCD_ENTRYMODESET 0x04
35 #define LCD_DISPLAYCONTROL 0x08
36 #define LCD_CURSORSHIFT 0x10
37 #define LCD_FUNCTIONSET 0x20
38 #define LCD_DATA 0x40
39 #define LCD_CMD 0x80
40
41 #define LCD_BACKLIGHT 0x08
42 #define LCD_NOBACKLIGHT 0x00
43
44 // flags for display entry mode
45 #define LCD_ENTRYRIGHT 0x00
46 #define LCD_ENTRYLEFT 0x02
47 #define LCD_ENTRYSHIFTINCREMENT 0x01
48 #define LCD_ENTRYSHIFTDECREMENT 0x00
49
50 // flags for display on/off control
51 #define LCD_DISPLAYON 0x04
52 #define LCD_DISPLAYOFF 0x00
53 #define LCD_CURSORON 0x02
54 #define LCD_CURSOROFF 0x00
55 #define LCD_BLINKON 0x01
56 #define LCD_BLINKOFF 0x00
57
58 // flags for function set
59 #define LCD_8BITMODE 0x10
60 #define LCD_4BITMODE 0x00
61 #define LCD_2LINE 0x08
62 #define LCD_1LINE 0x00
63 #define LCD_5x10DOTS 0x04
64 #define LCD_5x8DOTS 0x00
65
66 #define LCD_EN 0x04 // Enable bit
67 #define LCD_RW 0x02 // Read/Write bit
68 #define LCD_RS 0x01 // Register select bit
69
70 class I2CLcd {
71     public:
72         I2CLcd (int bus, int lcdAddress);
73         mraa_result_t write (int x, int y, std::string msg);
74         
75         virtual mraa_result_t write (std::string msg) = 0;
76         virtual mraa_result_t setCursor (int row, int column) = 0;
77         virtual mraa_result_t clear () = 0;
78         virtual mraa_result_t home () = 0;
79         virtual mraa_result_t i2Cmd (mraa_i2c_context ctx, uint8_t value);
80         virtual mraa_result_t i2cReg (mraa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
81         virtual mraa_result_t i2cData (mraa_i2c_context ctx, uint8_t value);
82         
83         mraa_result_t close();
84         std::string name()
85         {
86             return m_name;
87         }
88     protected:
89         std::string m_name;
90         int m_lcd_control_address;
91         int m_bus;
92         mraa_i2c_context m_i2c_lcd_control;
93 };
94
95 }