386def9214b0012f9c67de7bc461eb6b1458a775
[contrib/upm.git] / src / lcd / 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  * Permission is hereby granted, free of uint8_tge, to any person obtaining a copy of
11  * this software and associated documentation files (the "Software"), to deal in
12  * the Software without restriction, including without limitation the rights to
13  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
14  * the Software, and to permit persons to whom the Software is furnished to do so,
15  * subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included in all
18  * copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
22  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
23  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27
28 #pragma once
29
30 #include <string>
31 #include "i2clcd.h"
32
33 namespace upm {
34
35 /**
36  * @brief C++ API for LCM1602 i2c controller for HD44780 based displays
37  *
38  * This supports all sizes of HD44780 displays from 16x2 to 4x20, the
39  * controller has no idea of the actual display hardware so will let you write
40  * further than you can see
41  *
42  * @snippet lcm-lcd.cxx Interesting
43  */
44 class Lcm1602 : public I2CLcd {
45     public:
46        /**
47         * Lcm1602 Constructor, calls libmraa initialisation functions
48         *
49         * @param bus i2c bus to use
50         * @param address the slave address the lcd is registered on
51         */
52         Lcm1602(int bus, int address);
53        /**
54         * Lcm1602 Destructor
55         */
56         ~Lcm1602();
57        /**
58         * Write a string to LCD
59         *
60         * @param msg The std::string to write to display, note only ascii
61         *     chars are supported
62         * @return Result of operation
63         */
64         mraa_result_t write(std::string msg);
65        /**
66         * Set cursor to a coordinate
67         *
68         * @param row The row to set cursor to
69         * @param column The column to set cursor to
70         * @return Result of operation
71         */
72         mraa_result_t setCursor(int row, int column);
73        /**
74         * Clear display from characters
75         *
76         * @return Result of operatio
77         */
78         mraa_result_t clear();
79        /**
80         * Return to coordinate 0,0
81         *
82         * @return Result of operation
83         */
84         mraa_result_t home();
85
86     private :
87         mraa_result_t send(uint8_t value, int mode);
88         mraa_result_t write4bits(uint8_t value);
89         mraa_result_t expandWrite(uint8_t value);
90         mraa_result_t pulseEnable(uint8_t value);
91     };
92 }