upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
lcm1602.h
Go to the documentation of this file.
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016 Intel Corporation.
4  *
5  * Based on UPM C++ drivers originally developed by:
6  * Author: Daniel Mosquera
7  * Copyright (c) 2013 Daniel Mosquera
8  *
9  * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
10  * Copyright (c) 2014 Intel Corporation.
11  *
12  * Contributions: Sergey Kiselev <sergey.kiselev@intel.com>
13  *
14  * Permission is hereby granted, free of charge, to any person obtaining
15  * a copy of this software and associated documentation files (the
16  * "Software"), to deal in the Software without restriction, including
17  * without limitation the rights to use, copy, modify, merge, publish,
18  * distribute, sublicense, and/or sell copies of the Software, and to
19  * permit persons to whom the Software is furnished to do so, subject to
20  * the following conditions:
21  *
22  * The above copyright notice and this permission notice shall be
23  * included in all copies or substantial portions of the Software.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32  */
33 
34 #pragma once
35 
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <upm.h>
39 
40 #include <mraa/i2c.h>
41 #include <mraa/gpio.h>
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 
59  typedef struct _lcm1602_context {
60  // A large number of GPIOs
61  mraa_gpio_context gpioRS;
62  mraa_gpio_context gpioEN;
63  mraa_gpio_context gpioD0;
64  mraa_gpio_context gpioD1;
65  mraa_gpio_context gpioD2;
66  mraa_gpio_context gpioD3;
67 
68  // I2C command control
69  mraa_i2c_context i2c;
70 
71  // what interface are we using?
72  bool isI2C;
73 
74  // configuration
75  unsigned int columns;
76  unsigned int rows;
77 
78  // display command
79  uint8_t displayControl;
80  uint8_t entryDisplayMode;
81  uint8_t backlight;
82  } *lcm1602_context;
83 
100  lcm1602_context lcm1602_i2c_init(int bus, int address, bool is_expander,
101  uint8_t num_columns, uint8_t num_rows);
102 
118  lcm1602_context lcm1602_gpio_init(int rs, int enable,
119  int d0, int d1, int d2,
120  int d3, uint8_t num_columns,
121  uint8_t num_rows);
122 
128  void lcm1602_close(lcm1602_context dev);
129 
139  upm_result_t lcm1602_write(const lcm1602_context dev, char *buffer,
140  int len);
141 
150  upm_result_t lcm1602_set_cursor(const lcm1602_context dev,
151  unsigned int row, unsigned int column);
152 
159  upm_result_t lcm1602_clear(const lcm1602_context dev);
160 
167  upm_result_t lcm1602_home(const lcm1602_context dev);
168 
177  upm_result_t lcm1602_create_char(const lcm1602_context dev,
178  unsigned int slot,
179  char *data);
180 
188  upm_result_t lcm1602_display_on(const lcm1602_context dev, bool on);
189 
197  upm_result_t lcm1602_cursor_on(const lcm1602_context dev, bool on);
198 
206  upm_result_t lcm1602_cursor_blink_on(const lcm1602_context dev, bool on);
207 
215  upm_result_t lcm1602_backlight_on(const lcm1602_context dev, bool on);
216 
223  upm_result_t lcm1602_scroll_display_left(const lcm1602_context dev);
224 
231  upm_result_t lcm1602_scroll_display_right(const lcm1602_context dev);
232 
241  upm_result_t lcm1602_entry_left_to_right(const lcm1602_context dev,
242  bool on);
243 
251  upm_result_t lcm1602_autoscroll_on(const lcm1602_context dev, bool on);
252 
262  upm_result_t lcm1602_command(const lcm1602_context dev, uint8_t cmd);
263 
273  upm_result_t lcm1602_data(const lcm1602_context dev, uint8_t data);
274 
275 
276 #ifdef __cplusplus
277 }
278 #endif
Definition: lcm1602.h:59
upm_result_t lcm1602_autoscroll_on(const lcm1602_context dev, bool on)
Definition: lcm1602.c:477
upm_result_t lcm1602_scroll_display_right(const lcm1602_context dev)
Definition: lcm1602.c:457
struct _lcm1602_context * lcm1602_context
void lcm1602_close(lcm1602_context dev)
Definition: lcm1602.c:262
upm_result_t lcm1602_home(const lcm1602_context dev)
Definition: lcm1602.c:368
upm_result_t lcm1602_entry_left_to_right(const lcm1602_context dev, bool on)
Definition: lcm1602.c:465
upm_result_t lcm1602_display_on(const lcm1602_context dev, bool on)
Definition: lcm1602.c:401
upm_result_t lcm1602_set_cursor(const lcm1602_context dev, unsigned int row, unsigned int column)
Definition: lcm1602.c:299
upm_result_t lcm1602_scroll_display_left(const lcm1602_context dev)
Definition: lcm1602.c:449
upm_result_t lcm1602_command(const lcm1602_context dev, uint8_t cmd)
Definition: lcm1602.c:489
upm_result_t lcm1602_write(const lcm1602_context dev, char *buffer, int len)
Definition: lcm1602.c:285
upm_result_t lcm1602_cursor_on(const lcm1602_context dev, bool on)
Definition: lcm1602.c:413
upm_result_t lcm1602_data(const lcm1602_context dev, uint8_t data)
Definition: lcm1602.c:496
upm_result_t lcm1602_backlight_on(const lcm1602_context dev, bool on)
Definition: lcm1602.c:437
upm_result_t lcm1602_create_char(const lcm1602_context dev, unsigned int slot, char *data)
Definition: lcm1602.c:378
upm_result_t lcm1602_clear(const lcm1602_context dev)
Definition: lcm1602.c:358
upm_result_t lcm1602_cursor_blink_on(const lcm1602_context dev, bool on)
Definition: lcm1602.c:425
lcm1602_context lcm1602_gpio_init(int rs, int enable, int d0, int d1, int d2, int d3, uint8_t num_columns, uint8_t num_rows)
Definition: lcm1602.c:138
lcm1602_context lcm1602_i2c_init(int bus, int address, bool is_expander, uint8_t num_columns, uint8_t num_rows)
Definition: lcm1602.c:49