esp32-i2c-lcd1602
ESP32-compatible C library for LCD1602 display via I2C backpack.
 All Data Structures Files Functions Variables Enumerations Enumerator Macros
i2c-lcd1602.h
Go to the documentation of this file.
1 /*
2  * MIT License
3  *
4  * Copyright (c) 2018 David Antliff
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
35 #ifndef I2C_LCD1602_H
36 #define I2C_LCD1602_H
37 
38 #include <stdbool.h>
39 #include "smbus.h"
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
48 typedef struct
49 {
50  bool init;
51  smbus_info_t * smbus_info;
52  uint8_t backlight_flag;
53  uint8_t num_rows;
54  uint8_t num_columns;
57  uint8_t entry_mode_flags;
59 
60 
61 // Special characters for ROM Code A00
62 
63 // Use the second set (0bxxxx1xxx) to avoid placing the null character within a string
64 #define I2C_LCD1602_CHARACTER_CUSTOM_0 0b00001000
65 #define I2C_LCD1602_CHARACTER_CUSTOM_1 0b00001001
66 #define I2C_LCD1602_CHARACTER_CUSTOM_2 0b00001010
67 #define I2C_LCD1602_CHARACTER_CUSTOM_3 0b00001011
68 #define I2C_LCD1602_CHARACTER_CUSTOM_4 0b00001100
69 #define I2C_LCD1602_CHARACTER_CUSTOM_5 0b00001101
70 #define I2C_LCD1602_CHARACTER_CUSTOM_6 0b00001110
71 #define I2C_LCD1602_CHARACTER_CUSTOM_7 0b00001111
72 
73 #define I2C_LCD1602_CHARACTER_ALPHA 0b11100000
74 #define I2C_LCD1602_CHARACTER_BETA 0b11100010
75 #define I2C_LCD1602_CHARACTER_THETA 0b11110010
76 #define I2C_LCD1602_CHARACTER_PI 0b11110111
77 #define I2C_LCD1602_CHARACTER_OMEGA 0b11110100
78 #define I2C_LCD1602_CHARACTER_SIGMA 0b11110110
79 #define I2C_LCD1602_CHARACTER_INFINITY 0b11110011
80 #define I2C_LCD1602_CHARACTER_DEGREE 0b11011111
81 #define I2C_LCD1602_CHARACTER_ARROW_RIGHT 0b01111110
82 #define I2C_LCD1602_CHARACTER_ARROW_LEFT 0b01111111
83 #define I2C_LCD1602_CHARACTER_SQUARE 0b11011011
84 #define I2C_LCD1602_CHARACTER_DOT 0b10100101
85 #define I2C_LCD1602_CHARACTER_DIVIDE 0b11111101
86 #define I2C_LCD1602_CHARACTER_BLOCK 0b11111111
87 
88 
91 typedef enum
92 {
102 
103 #define I2C_LCD1602_ERROR_CHECK(x) do { \
104  esp_err_t rc = (x); \
105  if (rc != ESP_OK) { \
106  ESP_LOGW(TAG, "I2C error %d at %s:%d", rc, __FILE__, __LINE__); \
107  } \
108  } while(0);
109 
117 
123 void i2c_lcd1602_free(i2c_lcd1602_info_t ** tsl2561_info);
124 
136 esp_err_t i2c_lcd1602_init(i2c_lcd1602_info_t * i2c_lcd1602_info, smbus_info_t * smbus_info,
137  bool backlight, uint8_t num_rows, uint8_t num_columns, uint8_t num_visible_columns);
138 
145 esp_err_t i2c_lcd1602_reset(const i2c_lcd1602_info_t * i2c_lcd1602_info);
146 
154 esp_err_t i2c_lcd1602_clear(const i2c_lcd1602_info_t * i2c_lcd1602_info);
155 
163 esp_err_t i2c_lcd1602_home(const i2c_lcd1602_info_t * i2c_lcd1602_info);
164 
173 esp_err_t i2c_lcd1602_move_cursor(const i2c_lcd1602_info_t * i2c_lcd1602_info, uint8_t col, uint8_t row);
174 
182 esp_err_t i2c_lcd1602_set_backlight(i2c_lcd1602_info_t * i2c_lcd1602_info, bool enable);
183 
193 esp_err_t i2c_lcd1602_set_display(i2c_lcd1602_info_t * i2c_lcd1602_info, bool enable);
194 
204 esp_err_t i2c_lcd1602_set_cursor(i2c_lcd1602_info_t * i2c_lcd1602_info, bool enable);
205 
215 esp_err_t i2c_lcd1602_set_blink(i2c_lcd1602_info_t * i2c_lcd1602_info, bool enable);
216 
223 esp_err_t i2c_lcd1602_set_left_to_right(i2c_lcd1602_info_t * i2c_lcd1602_info);
224 
231 esp_err_t i2c_lcd1602_set_right_to_left(i2c_lcd1602_info_t * i2c_lcd1602_info);
232 
244 esp_err_t i2c_lcd1602_set_auto_scroll(i2c_lcd1602_info_t * i2c_lcd1602_info, bool enable);
245 
252 esp_err_t i2c_lcd1602_scroll_display_left(const i2c_lcd1602_info_t * i2c_lcd1602_info);
253 
259 esp_err_t i2c_lcd1602_scroll_display_right(const i2c_lcd1602_info_t * i2c_lcd1602_info);
260 
268 esp_err_t i2c_lcd1602_move_cursor_left(const i2c_lcd1602_info_t * i2c_lcd1602_info);
269 
277 esp_err_t i2c_lcd1602_move_cursor_right(const i2c_lcd1602_info_t * i2c_lcd1602_info);
278 
301 esp_err_t i2c_lcd1602_define_char(const i2c_lcd1602_info_t * i2c_lcd1602_info, i2c_lcd1602_custom_index_t index, const uint8_t pixelmap[]);
302 
314 esp_err_t i2c_lcd1602_write_char(const i2c_lcd1602_info_t * i2c_lcd1602_info, uint8_t chr);
315 
327 esp_err_t i2c_lcd1602_write_string(const i2c_lcd1602_info_t * i2c_lcd1602_info, const char * string);
328 
329 #ifdef __cplusplus
330 }
331 #endif
332 
333 #endif // I2C_LCD1602_H
esp_err_t i2c_lcd1602_set_backlight(i2c_lcd1602_info_t *i2c_lcd1602_info, bool enable)
Enable or disable the LED backlight.
Definition: i2c-lcd1602.c:455
esp_err_t i2c_lcd1602_reset(const i2c_lcd1602_info_t *i2c_lcd1602_info)
Reset the display. Custom characters will be cleared.
Definition: i2c-lcd1602.c:316
esp_err_t i2c_lcd1602_set_right_to_left(i2c_lcd1602_info_t *i2c_lcd1602_info)
Set cursor movement direction following each character write to produce right-to-left text...
Definition: i2c-lcd1602.c:510
esp_err_t i2c_lcd1602_set_blink(i2c_lcd1602_info_t *i2c_lcd1602_info, bool enable)
Enable or disable display of the blinking block cursor. If enabled, this visually indicates where the...
Definition: i2c-lcd1602.c:488
esp_err_t i2c_lcd1602_home(const i2c_lcd1602_info_t *i2c_lcd1602_info)
Move cursor to home position. Also resets any display shift that may have occurred. DDRAM content is not changed. CGRAM content is not changed.
Definition: i2c-lcd1602.c:422
bool init
True if struct has been initialised, otherwise false.
Definition: i2c-lcd1602.h:50
uint8_t num_visible_columns
Number of visible columns.
Definition: i2c-lcd1602.h:55
i2c_lcd1602_custom_index_t
Enum of valid indexes for definitions of user-defined characters.
Definition: i2c-lcd1602.h:91
Structure containing information related to the I2C-LCD1602 device.
Definition: i2c-lcd1602.h:48
esp_err_t i2c_lcd1602_clear(const i2c_lcd1602_info_t *i2c_lcd1602_info)
Clears entire display (clears DDRAM) and returns cursor to home position. DDRAM content is cleared...
Definition: i2c-lcd1602.c:408
esp_err_t i2c_lcd1602_write_string(const i2c_lcd1602_info_t *i2c_lcd1602_info, const char *string)
Write a string of characters to the display, starting at the current position of the cursor...
Definition: i2c-lcd1602.c:601
esp_err_t i2c_lcd1602_set_cursor(i2c_lcd1602_info_t *i2c_lcd1602_info, bool enable)
Enable or disable display of the underline cursor. If enabled, this visually indicates where the next...
Definition: i2c-lcd1602.c:477
esp_err_t i2c_lcd1602_set_left_to_right(i2c_lcd1602_info_t *i2c_lcd1602_info)
Set cursor movement direction following each character write to produce left-to-right text...
Definition: i2c-lcd1602.c:499
uint8_t display_control_flags
Currently active display control flags.
Definition: i2c-lcd1602.h:56
uint8_t entry_mode_flags
Currently active entry mode flags.
Definition: i2c-lcd1602.h:57
Index of eighth user-defined custom symbol.
Definition: i2c-lcd1602.h:100
esp_err_t i2c_lcd1602_init(i2c_lcd1602_info_t *i2c_lcd1602_info, smbus_info_t *smbus_info, bool backlight, uint8_t num_rows, uint8_t num_columns, uint8_t num_visible_columns)
Initialise a I2C-LCD1602 info instance with the specified SMBus information.
Definition: i2c-lcd1602.c:281
esp_err_t i2c_lcd1602_move_cursor_right(const i2c_lcd1602_info_t *i2c_lcd1602_info)
Move the cursor one position to the right, even if it is invisible. This affects where the next chara...
Definition: i2c-lcd1602.c:565
uint8_t num_columns
Number of configured columns, including offscreen columns.
Definition: i2c-lcd1602.h:54
esp_err_t i2c_lcd1602_set_display(i2c_lcd1602_info_t *i2c_lcd1602_info, bool enable)
Enable or disable the display. When disabled, the backlight is not affected, but any contents of the ...
Definition: i2c-lcd1602.c:466
Index of fourth user-defined custom symbol.
Definition: i2c-lcd1602.h:96
esp_err_t i2c_lcd1602_move_cursor(const i2c_lcd1602_info_t *i2c_lcd1602_info, uint8_t col, uint8_t row)
Move cursor to specified column and row position. This is where a new character will appear...
Definition: i2c-lcd1602.c:436
uint8_t num_rows
Number of configured columns.
Definition: i2c-lcd1602.h:53
Index of second user-defined custom symbol.
Definition: i2c-lcd1602.h:94
void i2c_lcd1602_free(i2c_lcd1602_info_t **tsl2561_info)
Delete an existing I2C-LCD1602 info instance.
Definition: i2c-lcd1602.c:267
Index of sixth user-defined custom symbol.
Definition: i2c-lcd1602.h:98
esp_err_t i2c_lcd1602_move_cursor_left(const i2c_lcd1602_info_t *i2c_lcd1602_info)
Move the cursor one position to the left, even if it is invisible. This affects where the next charac...
Definition: i2c-lcd1602.c:554
Index of seventh user-defined custom symbol.
Definition: i2c-lcd1602.h:99
Index of first user-defined custom symbol.
Definition: i2c-lcd1602.h:93
esp_err_t i2c_lcd1602_define_char(const i2c_lcd1602_info_t *i2c_lcd1602_info, i2c_lcd1602_custom_index_t index, const uint8_t pixelmap[])
Define a custom character from an array of pixel data.
Definition: i2c-lcd1602.c:576
smbus_info_t * smbus_info
Pointer to associated SMBus info.
Definition: i2c-lcd1602.h:51
i2c_lcd1602_info_t * i2c_lcd1602_malloc(void)
Construct a new I2C-LCD1602 info instance. New instance should be initialised before calling other fu...
Definition: i2c-lcd1602.c:252
Index of third user-defined custom symbol.
Definition: i2c-lcd1602.h:95
esp_err_t i2c_lcd1602_scroll_display_left(const i2c_lcd1602_info_t *i2c_lcd1602_info)
Scroll the display one position to the left. On-screen text will appear to move to the right...
Definition: i2c-lcd1602.c:532
uint8_t backlight_flag
Non-zero if backlight is to be enabled, otherwise zero.
Definition: i2c-lcd1602.h:52
esp_err_t i2c_lcd1602_scroll_display_right(const i2c_lcd1602_info_t *i2c_lcd1602_info)
Scroll the display one position to the right. On-screen text will appear to move to the left...
Definition: i2c-lcd1602.c:543
esp_err_t i2c_lcd1602_set_auto_scroll(i2c_lcd1602_info_t *i2c_lcd1602_info, bool enable)
Enable or disable auto-scroll of display. When enabled, the display will scroll as characters are wri...
Definition: i2c-lcd1602.c:521
Index of fifth user-defined custom symbol.
Definition: i2c-lcd1602.h:97
esp_err_t i2c_lcd1602_write_char(const i2c_lcd1602_info_t *i2c_lcd1602_info, uint8_t chr)
Write a single character to the display at the current position of the cursor. Depending on the activ...
Definition: i2c-lcd1602.c:591