Handle two lines in the print method.
[ruwai.git] / software / c++ / ruwaicom / include / lcddisplay.h
blobacf4262e9234743a2571e908b038e23085b42c54
1 /*--------------------------------------------------------------------------*/
2 // LICENSE
3 //
4 // This file is part of ruwai.
5 //
6 // If you use ruwai_parser in any program or publication, please inform and
7 // acknowledge its author Stefan Mertl (stefan@mertl-research.at).
8 //
9 // ruwai is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 /*--------------------------------------------------------------------------*/
23 #ifndef LCDDISPLAY_H
24 #define LCDDISPLAY_H
26 #include "libgpio/gpio.h"
27 #include <string>
30 #define LCD_DELAY_ENABLE_PULSE 2
31 #define LCD_LONG_DELAY 1600
32 #define LCD_SHORT_DELAY 50
35 #define LCD_CMD_CLEAR_DISPLAY 0x01
36 #define LCD_CMD_RETURN_HOME 0x02
37 #define LCD_CMD_ENTRY_MODE_SET 0x04
38 #define LCD_CMD_DISPLAY 0x08
39 #define LCD_CMD_SHIFT 0x10
40 #define LCD_CMD_FUNCTION_SET 0x20
41 #define LCD_CMD_SET_CGRAM_ADDR 0x40
42 #define LCD_CMD_SET_DDRAM_ADDR 0x80
44 #define LCD_ENTRY_DISPLAY_SHIFT 0x01
45 #define LCD_ENTRY_CURSOR_INCREMENT 0x02
46 #define LCD_DISPLAY_CURSOR_BLINKS 0x01
47 #define LCD_DISPLAY_CURSOR_ON 0x02
48 #define LCD_DISPLAY_DISPLAY_ON 0X04
49 #define LCD_SHIFT_RIGHT 0x04
50 #define LCD_SHIFT_DISPLAY 0x08
51 #define LCD_FUNCTION_5X10_DOTS 0X04
52 #define LCD_FUNCTION_TWO_LINES 0X08
53 #define LCD_FUNCTION_8BIT_MODE 0X10
57 class LCDDisplay {
59 private:
60 GPIO* rs_gpio;
61 GPIO* e_gpio;
62 GPIO* db0_gpio;
63 GPIO* db1_gpio;
64 GPIO* db2_gpio;
65 GPIO* db3_gpio;
66 GPIO* db4_gpio;
67 GPIO* db5_gpio;
68 GPIO* db6_gpio;
69 GPIO* db7_gpio;
71 int mode;
73 public:
74 LCDDisplay(int rs_gpio, int e_gpio, int db0_gpio, int db1_gpio, int db2_gpio, int db3_gpio, int db4_gpio, int db5_gpio, int db6_gpio, int db7_gpio);
75 LCDDisplay(int rs_gpio, int e_gpio, int db4_gpio, int db5_gpio, int db6_gpio, int db7_gpio);
76 void init(void);
77 void clear(void);
78 void home(void);
79 void write_data(std::uint8_t data);
80 void print(std::string msg_line1, std::string msg_line2);
82 private:
83 void init_4bit(void);
84 void init_8bit(void);
85 void write_4bit(std::uint8_t data, bool command);
86 void write_4bit_high_only(std::uint8_t data, bool command);
87 void write_8bit(std::uint8_t data, bool command);
88 void write_command(std::uint8_t data);
89 void toggle_e(void);
93 #endif /* LCDDISPLAY_H */