blob: 3339e8c2554e206c619d59cc3564eb4e75083ed2 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01002/*
3 * Character LCD driver for Linux
4 *
5 * Copyright (C) 2000-2008, Willy Tarreau <w@1wt.eu>
6 * Copyright (C) 2016-2017 Glider bvba
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01007 */
8
Masahiro Yamada390235c2019-08-06 16:14:45 +09009#ifndef _CHARLCD_H
10#define _CHARLCD_H
11
Lars Poeschel01ec46d2020-11-03 10:58:17 +010012#define LCD_FLAG_B 0x0004 /* Blink on */
13#define LCD_FLAG_C 0x0008 /* Cursor on */
14#define LCD_FLAG_D 0x0010 /* Display on */
15#define LCD_FLAG_F 0x0020 /* Large font mode */
16#define LCD_FLAG_N 0x0040 /* 2-rows mode */
17#define LCD_FLAG_L 0x0080 /* Backlight enabled */
18
Lars Poeschel66ce7d52020-11-03 10:58:04 +010019enum charlcd_onoff {
20 CHARLCD_OFF = 0,
21 CHARLCD_ON,
22};
23
Lars Poescheld2f21872020-11-03 10:58:18 +010024enum charlcd_shift_dir {
25 CHARLCD_SHIFT_LEFT,
26 CHARLCD_SHIFT_RIGHT,
27};
28
29enum charlcd_fontsize {
30 CHARLCD_FONTSIZE_SMALL,
31 CHARLCD_FONTSIZE_LARGE,
32};
33
34enum charlcd_lines {
35 CHARLCD_LINES_1,
36 CHARLCD_LINES_2,
37};
38
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +010039struct charlcd {
40 const struct charlcd_ops *ops;
41 const unsigned char *char_conv; /* Optional */
42
43 int height;
44 int width;
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +010045
Lars Poeschel11588b52020-11-03 10:58:10 +010046 /* Contains the LCD X and Y offset */
47 struct {
48 unsigned long x;
49 unsigned long y;
50 } addr;
51
Lars Poeschel2545c1c2020-11-03 10:58:06 +010052 void *drvdata;
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +010053};
54
Lars Poeschelb26deab2020-11-03 10:58:11 +010055/**
56 * struct charlcd_ops - Functions used by charlcd. Drivers have to implement
57 * these.
58 * @clear_fast: Clear the whole display and set cursor to position 0, 0.
59 * Optional.
60 * @backlight: Turn backlight on or off. Optional.
61 * @print: Print one character to the display at current cursor position.
Lars Poeschelb26deab2020-11-03 10:58:11 +010062 * The buffered cursor position is advanced by charlcd. The cursor should not
63 * wrap to the next line at the end of a line.
Lars Poescheld3a2fb82020-11-03 10:58:12 +010064 * @gotoxy: Set cursor to x, y. The x and y values to set the cursor to are
65 * previously set in addr.x and addr.y by charlcd.
Lars Poeschel88645a82020-11-03 10:58:13 +010066 * @home: Set cursor to 0, 0. The values in addr.x and addr.y are set to 0, 0 by
67 * charlcd prior to calling this function.
Lars Poeschel45421ff2020-11-03 10:58:14 +010068 * @clear_display: Again clear the whole display, set the cursor to 0, 0. The
69 * values in addr.x and addr.y are set to 0, 0 by charlcd prior to calling this
70 * function.
Lars Poeschel01ec46d2020-11-03 10:58:17 +010071 * @init_display: Initialize the display.
Lars Poescheld2f21872020-11-03 10:58:18 +010072 * @shift_cursor: Shift cursor left or right one position.
73 * @shift_display: Shift whole display content left or right.
74 * @display: Turn display on or off.
75 * @cursor: Turn cursor on or off.
76 * @blink: Turn cursor blink on or off.
77 * @lines: One or two lines.
Lars Poeschel339acb02020-11-03 10:58:20 +010078 * @redefine_char: Redefine the actual pixel matrix of character.
Lars Poeschelb26deab2020-11-03 10:58:11 +010079 */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +010080struct charlcd_ops {
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +010081 void (*clear_fast)(struct charlcd *lcd);
Lars Poeschel66ce7d52020-11-03 10:58:04 +010082 void (*backlight)(struct charlcd *lcd, enum charlcd_onoff on);
Lars Poeschelb26deab2020-11-03 10:58:11 +010083 int (*print)(struct charlcd *lcd, int c);
Lars Poescheld3a2fb82020-11-03 10:58:12 +010084 int (*gotoxy)(struct charlcd *lcd);
Lars Poeschel88645a82020-11-03 10:58:13 +010085 int (*home)(struct charlcd *lcd);
Lars Poeschel45421ff2020-11-03 10:58:14 +010086 int (*clear_display)(struct charlcd *lcd);
Lars Poeschel01ec46d2020-11-03 10:58:17 +010087 int (*init_display)(struct charlcd *lcd);
Lars Poescheld2f21872020-11-03 10:58:18 +010088 int (*shift_cursor)(struct charlcd *lcd, enum charlcd_shift_dir dir);
89 int (*shift_display)(struct charlcd *lcd, enum charlcd_shift_dir dir);
90 int (*display)(struct charlcd *lcd, enum charlcd_onoff on);
91 int (*cursor)(struct charlcd *lcd, enum charlcd_onoff on);
92 int (*blink)(struct charlcd *lcd, enum charlcd_onoff on);
93 int (*fontsize)(struct charlcd *lcd, enum charlcd_fontsize size);
94 int (*lines)(struct charlcd *lcd, enum charlcd_lines lines);
Lars Poeschel339acb02020-11-03 10:58:20 +010095 int (*redefine_char)(struct charlcd *lcd, char *esc);
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +010096};
97
Lars Poeschel2bf82b52020-11-03 10:58:15 +010098void charlcd_backlight(struct charlcd *lcd, enum charlcd_onoff on);
Lars Poeschel2545c1c2020-11-03 10:58:06 +010099struct charlcd *charlcd_alloc(void);
Andy Shevchenko8e44fc82019-03-12 16:44:30 +0200100void charlcd_free(struct charlcd *lcd);
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100101
102int charlcd_register(struct charlcd *lcd);
103int charlcd_unregister(struct charlcd *lcd);
104
105void charlcd_poke(struct charlcd *lcd);
Masahiro Yamada390235c2019-08-06 16:14:45 +0900106
107#endif /* CHARLCD_H */