-
Notifications
You must be signed in to change notification settings - Fork 1
/
lcd_lib.h
149 lines (142 loc) · 4.29 KB
/
lcd_lib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* Filename: lcd_lib.h
* Date: 14/11/2019
* Description: header file for LCD library use LCD Driver
* Author: VietAnh Bui
*/
#ifndef _LCD_LIB_H_
#define _LCD_LIB_H_
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#define DEVICE_NODE "/dev/lcd_1602"
#define NUM_CHAR_PER_LINE 16
#define NUM_LINE 2
#define ENABLE 1
#define DISABLE 0
/*********************GPIO Configure************************/
/**********************Data Structure***********************/
typedef struct _custom_char
{
unsigned char location;
unsigned char *charmap;
}custom_character_t;
typedef struct _coordinate
{
unsigned char x;
unsigned char y;
}coordinate_t;
typedef struct _display_control
{
unsigned char display;
unsigned char cursor;
unsigned char blink;
}control_display_t;
/* Define command for IOCTL*/
#define MAGICAL_NUM 248
#define CLEAR_DISPLAY _IO(MAGICAL_NUM, 0)
#define GOTO_XY _IOW(MAGICAL_NUM, 1, coordinate_t *)
#define SET_DISPLAY _IOW(MAGICAL_NUM, 2, control_display_t *)
#define PUT_CHAR _IOW(MAGICAL_NUM, 3, unsigned char *)
#define SCROLL_LEFT _IO(MAGICAL_NUM, 4)
#define SCROLL_RIGHT _IO(MAGICAL_NUM, 5)
#define UPLOAD_CUSTOM_CHAR _IOW(MAGICAL_NUM, 6, custom_character_t *)
#define INIT_LCD _IO(MAGICAL_NUM, 7)
#define SET_AUTOSCROLL _IOW(MAGICAL_NUM, 8, unsigned char *)
/**********************Function Prototype ***********************/
/**
* @brief Init LCD
* Set cursor position to (0, 0), set enable cursor, enable blink
* The order of the connection pins has been defined in the driver
* The feature that provides configuration of connector pins will be updated in later versions
* @param void
* @return void
*/
void lcd_init(void);
/**
* @brief Open device file of LCD
* @param void
* @return file descriptor of device file
*/
static int lcd_open_dev(void);
/**
* @brief Close device file of LCD
* @param fd file descriptor
* @return close device file
*/
static void lcd_close_dev(int fd);
/**
* @brief Clear LCD display
* Clear screen of LCD and set cursor position to (1, 0)
* @param void
* @return void
*/
void lcd_clear_display(void);
/**
* @brief Set cursor goto line x, column y (LCD 16x02)
* @param x line number. (1 <= x <= 2)
* @param y column number. (0 <= y <= 15)
* @return void
*/
void lcd_goto_xy(unsigned char x, unsigned char y);
/**
* @brief Control Display
* Set option to control display LCD
* @param display to enable/disable display LCD. (ENABLE or DISABLE)
* @param cursor to enable/disable cursor LCD. (ENABLE or DISABLE)
* @param blink to enable/disable blink LCD. (ENABLE or DISABLE)
* @return void
*/
void lcd_set_display(unsigned char display, unsigned char cursor, unsigned char blink);
/**
* @brief Upload custom character to CGRAM (Character Generator RAM) in LCD
* CGRAM in LCD can contain maximum data display for 8 character with font 5x8
* @param location is address of custom character in CGRAM. (0-7)
* @param charmap is pointer to array contain data display for custom character. You can visit link: https://maxpromer.github.io/LCD-Character-Creator/
* @return void
*/
void lcd_upload_custom_char(unsigned char location, unsigned char *charmap);
/**
* @brief Scroll both of line to left LCD
* @param void
* @return void
*/
void lcd_scroll_left(void);
/**
* @brief Scroll both of line to right LCD
* @param void
* @return void
*/
void lcd_scroll_right(void);
/**
* @brief Put character to current cursor in LCD
* @param chr character
* @return void
*/
void lcd_put_char(unsigned char chr);
/**
* @brief Put string to screen
* If length of string over 16, do not put to line 2.
* So be careful when using this function.
* @param str pointer to string
* @return void
*/
void lcd_put_string(unsigned char *str);
/**
* @brief Put string to screen, if line not enough to display, cursor move to line 2
* @param str pointer to string
* @return void
*/
void lcd_put_string_super(unsigned char *str);
/**
* @brief Set enable or disable auto scroll
* Moves all the text one space to the left each time a letter is added
* @param status status (enable = ENABLE, disable = DISABLE)
* @return void
*/
int lcd_set_auto_scroll(unsigned char status);
#endif /*_LCD_LIB_H_*/