• Home
  • Raw
  • Download

Lines Matching +full:display +full:- +full:width +full:- +full:chars

1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (C) 2000-2008, Willy Tarreau <w@1wt.eu>
6 * Copyright (C) 2016-2017 Glider bvba
33 #define LCD_FLAG_D 0x0010 /* Display on */
35 #define LCD_FLAG_N 0x0040 /* 2-rows mode */
39 #define LCD_CMD_DISPLAY_CLEAR 0x01 /* Clear entire display */
44 #define LCD_CMD_DISPLAY_CTRL 0x08 /* Display control */
45 #define LCD_CMD_DISPLAY_ON 0x04 /* Set display on */
49 #define LCD_CMD_SHIFT 0x10 /* Shift cursor/display */
50 #define LCD_CMD_DISPLAY_SHIFT 0x08 /* Shift display instead of cursor */
51 #define LCD_CMD_SHIFT_RIGHT 0x04 /* Shift display/cursor to the right */
55 #define LCD_CMD_TWO_LINES 0x08 /* Set to two display lines */
60 #define LCD_CMD_SET_DDRAM_ADDR 0x80 /* Set display data RAM address */
62 #define LCD_ESCAPE_LEN 24 /* Max chars for LCD escape command */
83 /* Current escape sequence and it's length or -1 if outside */
94 /* Device single-open policy control */
108 if (!lcd->ops->backlight) in charlcd_backlight()
111 mutex_lock(&priv->bl_tempo_lock); in charlcd_backlight()
112 if (!priv->bl_tempo) in charlcd_backlight()
113 lcd->ops->backlight(lcd, on); in charlcd_backlight()
114 mutex_unlock(&priv->bl_tempo_lock); in charlcd_backlight()
123 mutex_lock(&priv->bl_tempo_lock); in charlcd_bl_off()
124 if (priv->bl_tempo) { in charlcd_bl_off()
125 priv->bl_tempo = false; in charlcd_bl_off()
126 if (!(priv->flags & LCD_FLAG_L)) in charlcd_bl_off()
127 priv->lcd.ops->backlight(&priv->lcd, 0); in charlcd_bl_off()
129 mutex_unlock(&priv->bl_tempo_lock); in charlcd_bl_off()
137 if (!lcd->ops->backlight) in charlcd_poke()
140 cancel_delayed_work_sync(&priv->bl_work); in charlcd_poke()
142 mutex_lock(&priv->bl_tempo_lock); in charlcd_poke()
143 if (!priv->bl_tempo && !(priv->flags & LCD_FLAG_L)) in charlcd_poke()
144 lcd->ops->backlight(lcd, 1); in charlcd_poke()
145 priv->bl_tempo = true; in charlcd_poke()
146 schedule_delayed_work(&priv->bl_work, LCD_BL_TEMPO_PERIOD * HZ); in charlcd_poke()
147 mutex_unlock(&priv->bl_tempo_lock); in charlcd_poke()
160 addr = priv->addr.x < lcd->bwidth ? priv->addr.x & (lcd->hwidth - 1) in charlcd_gotoxy()
161 : lcd->bwidth - 1; in charlcd_gotoxy()
162 if (priv->addr.y & 1) in charlcd_gotoxy()
163 addr += lcd->hwidth; in charlcd_gotoxy()
164 if (priv->addr.y & 2) in charlcd_gotoxy()
165 addr += lcd->bwidth; in charlcd_gotoxy()
166 lcd->ops->write_cmd(lcd, LCD_CMD_SET_DDRAM_ADDR | addr); in charlcd_gotoxy()
173 priv->addr.x = 0; in charlcd_home()
174 priv->addr.y = 0; in charlcd_home()
182 if (priv->addr.x < lcd->bwidth) { in charlcd_print()
183 if (lcd->char_conv) in charlcd_print()
184 c = lcd->char_conv[(unsigned char)c]; in charlcd_print()
185 lcd->ops->write_data(lcd, c); in charlcd_print()
186 priv->addr.x++; in charlcd_print()
189 if (priv->addr.x == lcd->bwidth) in charlcd_print()
200 if (lcd->ops->clear_fast) in charlcd_clear_fast()
201 lcd->ops->clear_fast(lcd); in charlcd_clear_fast()
203 for (pos = 0; pos < min(2, lcd->height) * lcd->hwidth; pos++) in charlcd_clear_fast()
204 lcd->ops->write_data(lcd, ' '); in charlcd_clear_fast()
209 /* clears the display and resets X/Y */
214 lcd->ops->write_cmd(lcd, LCD_CMD_DISPLAY_CLEAR); in charlcd_clear_display()
215 priv->addr.x = 0; in charlcd_clear_display()
216 priv->addr.y = 0; in charlcd_clear_display()
227 if (lcd->ifwidth != 4 && lcd->ifwidth != 8) in charlcd_init_display()
228 return -EINVAL; in charlcd_init_display()
230 priv->flags = ((lcd->height > 1) ? LCD_FLAG_N : 0) | LCD_FLAG_D | in charlcd_init_display()
233 long_sleep(20); /* wait 20 ms after power-up for the paranoid */ in charlcd_init_display()
236 * 8-bit mode, 1 line, small fonts; let's do it 3 times, to make sure in charlcd_init_display()
237 * the LCD is in 8-bit mode afterwards in charlcd_init_display()
240 if (lcd->ifwidth == 4) { in charlcd_init_display()
242 write_cmd_raw = lcd->ops->write_cmd_raw4; in charlcd_init_display()
244 write_cmd_raw = lcd->ops->write_cmd; in charlcd_init_display()
253 if (lcd->ifwidth == 4) { in charlcd_init_display()
254 /* Switch to 4-bit mode, 1 line, small fonts */ in charlcd_init_display()
255 lcd->ops->write_cmd_raw4(lcd, LCD_CMD_FUNCTION_SET >> 4); in charlcd_init_display()
260 lcd->ops->write_cmd(lcd, in charlcd_init_display()
262 ((lcd->ifwidth == 8) ? LCD_CMD_DATA_LEN_8BITS : 0) | in charlcd_init_display()
263 ((priv->flags & LCD_FLAG_F) ? LCD_CMD_FONT_5X10_DOTS : 0) | in charlcd_init_display()
264 ((priv->flags & LCD_FLAG_N) ? LCD_CMD_TWO_LINES : 0)); in charlcd_init_display()
267 /* display off, cursor off, blink off */ in charlcd_init_display()
268 lcd->ops->write_cmd(lcd, LCD_CMD_DISPLAY_CTRL); in charlcd_init_display()
271 lcd->ops->write_cmd(lcd, in charlcd_init_display()
272 LCD_CMD_DISPLAY_CTRL | /* set display mode */ in charlcd_init_display()
273 ((priv->flags & LCD_FLAG_D) ? LCD_CMD_DISPLAY_ON : 0) | in charlcd_init_display()
274 ((priv->flags & LCD_FLAG_C) ? LCD_CMD_CURSOR_ON : 0) | in charlcd_init_display()
275 ((priv->flags & LCD_FLAG_B) ? LCD_CMD_BLINK_ON : 0)); in charlcd_init_display()
277 charlcd_backlight(lcd, (priv->flags & LCD_FLAG_L) ? 1 : 0); in charlcd_init_display()
282 lcd->ops->write_cmd(lcd, LCD_CMD_ENTRY_MODE | LCD_CMD_CURSOR_INC); in charlcd_init_display()
290 * any number of subcommands of the form "(x|y)[0-9]+".
296 * - ";" returns (<original x>, <original y>).
297 * - "x1;" returns (1, <original y>).
298 * - "y2x1;" returns (1, 2).
299 * - "x12y34x56;" returns (56, 34).
300 * - "" fails.
301 * - "x" fails.
302 * - "x;" fails.
303 * - "x1" fails.
304 * - "xy12;" fails.
305 * - "x12yy12;" fails.
306 * - "xx" fails.
356 char *esc = priv->esc_seq.buf + 2; in handle_lcd_special_code()
357 int oldflags = priv->flags; in handle_lcd_special_code()
359 /* check for display mode flags */ in handle_lcd_special_code()
361 case 'D': /* Display ON */ in handle_lcd_special_code()
362 priv->flags |= LCD_FLAG_D; in handle_lcd_special_code()
365 case 'd': /* Display OFF */ in handle_lcd_special_code()
366 priv->flags &= ~LCD_FLAG_D; in handle_lcd_special_code()
370 priv->flags |= LCD_FLAG_C; in handle_lcd_special_code()
374 priv->flags &= ~LCD_FLAG_C; in handle_lcd_special_code()
378 priv->flags |= LCD_FLAG_B; in handle_lcd_special_code()
382 priv->flags &= ~LCD_FLAG_B; in handle_lcd_special_code()
386 priv->flags |= LCD_FLAG_L; in handle_lcd_special_code()
389 case '-': /* Back light OFF */ in handle_lcd_special_code()
390 priv->flags &= ~LCD_FLAG_L; in handle_lcd_special_code()
398 priv->flags &= ~LCD_FLAG_F; in handle_lcd_special_code()
402 priv->flags |= LCD_FLAG_F; in handle_lcd_special_code()
406 priv->flags &= ~LCD_FLAG_N; in handle_lcd_special_code()
410 priv->flags |= LCD_FLAG_N; in handle_lcd_special_code()
414 if (priv->addr.x > 0) { in handle_lcd_special_code()
416 if (priv->addr.x < lcd->bwidth) in handle_lcd_special_code()
417 lcd->ops->write_cmd(lcd, LCD_CMD_SHIFT); in handle_lcd_special_code()
418 priv->addr.x--; in handle_lcd_special_code()
423 if (priv->addr.x < lcd->width) { in handle_lcd_special_code()
425 if (priv->addr.x < (lcd->bwidth - 1)) in handle_lcd_special_code()
426 lcd->ops->write_cmd(lcd, in handle_lcd_special_code()
428 priv->addr.x++; in handle_lcd_special_code()
432 case 'L': /* shift display left */ in handle_lcd_special_code()
433 lcd->ops->write_cmd(lcd, LCD_CMD_SHIFT | LCD_CMD_DISPLAY_SHIFT); in handle_lcd_special_code()
436 case 'R': /* shift display right */ in handle_lcd_special_code()
437 lcd->ops->write_cmd(lcd, in handle_lcd_special_code()
445 for (x = priv->addr.x; x < lcd->bwidth; x++) in handle_lcd_special_code()
446 lcd->ops->write_data(lcd, ' '); in handle_lcd_special_code()
453 case 'I': /* reinitialize display */ in handle_lcd_special_code()
478 cgaddr = *(esc++) - '0'; in handle_lcd_special_code()
503 lcd->ops->write_cmd(lcd, LCD_CMD_SET_CGRAM_ADDR | (cgaddr * 8)); in handle_lcd_special_code()
505 lcd->ops->write_data(lcd, cgbytes[addr]); in handle_lcd_special_code()
514 if (priv->esc_seq.buf[priv->esc_seq.len - 1] != ';') in handle_lcd_special_code()
518 if (parse_xy(esc, &priv->addr.x, &priv->addr.y)) in handle_lcd_special_code()
528 if (oldflags == priv->flags) in handle_lcd_special_code()
532 if ((oldflags ^ priv->flags) & in handle_lcd_special_code()
534 /* set display mode */ in handle_lcd_special_code()
535 lcd->ops->write_cmd(lcd, in handle_lcd_special_code()
537 ((priv->flags & LCD_FLAG_D) ? LCD_CMD_DISPLAY_ON : 0) | in handle_lcd_special_code()
538 ((priv->flags & LCD_FLAG_C) ? LCD_CMD_CURSOR_ON : 0) | in handle_lcd_special_code()
539 ((priv->flags & LCD_FLAG_B) ? LCD_CMD_BLINK_ON : 0)); in handle_lcd_special_code()
541 else if ((oldflags ^ priv->flags) & (LCD_FLAG_F | LCD_FLAG_N)) in handle_lcd_special_code()
542 lcd->ops->write_cmd(lcd, in handle_lcd_special_code()
544 ((lcd->ifwidth == 8) ? LCD_CMD_DATA_LEN_8BITS : 0) | in handle_lcd_special_code()
545 ((priv->flags & LCD_FLAG_F) ? LCD_CMD_FONT_5X10_DOTS : 0) | in handle_lcd_special_code()
546 ((priv->flags & LCD_FLAG_N) ? LCD_CMD_TWO_LINES : 0)); in handle_lcd_special_code()
548 else if ((oldflags ^ priv->flags) & LCD_FLAG_L) in handle_lcd_special_code()
549 charlcd_backlight(lcd, !!(priv->flags & LCD_FLAG_L)); in handle_lcd_special_code()
559 if ((c != '\n') && priv->esc_seq.len >= 0) { in charlcd_write_char()
561 priv->esc_seq.buf[priv->esc_seq.len++] = c; in charlcd_write_char()
562 priv->esc_seq.buf[priv->esc_seq.len] = '\0'; in charlcd_write_char()
565 priv->esc_seq.len = -1; in charlcd_write_char()
570 priv->esc_seq.len = 0; in charlcd_write_char()
571 priv->esc_seq.buf[priv->esc_seq.len] = '\0'; in charlcd_write_char()
575 if (priv->addr.x > 0) { in charlcd_write_char()
580 if (priv->addr.x < lcd->bwidth) in charlcd_write_char()
582 lcd->ops->write_cmd(lcd, LCD_CMD_SHIFT); in charlcd_write_char()
583 priv->addr.x--; in charlcd_write_char()
586 lcd->ops->write_data(lcd, ' '); in charlcd_write_char()
588 lcd->ops->write_cmd(lcd, LCD_CMD_SHIFT); in charlcd_write_char()
591 /* quickly clear the display */ in charlcd_write_char()
599 for (; priv->addr.x < lcd->bwidth; priv->addr.x++) in charlcd_write_char()
600 lcd->ops->write_data(lcd, ' '); in charlcd_write_char()
601 priv->addr.x = 0; in charlcd_write_char()
602 priv->addr.y = (priv->addr.y + 1) % lcd->height; in charlcd_write_char()
607 priv->addr.x = 0; in charlcd_write_char()
625 if (priv->esc_seq.len >= 2) { in charlcd_write_char()
628 if (!strcmp(priv->esc_seq.buf, "[2J")) { in charlcd_write_char()
629 /* clear the display */ in charlcd_write_char()
632 } else if (!strcmp(priv->esc_seq.buf, "[H")) { in charlcd_write_char()
638 else if ((priv->esc_seq.len >= 3) && in charlcd_write_char()
639 (priv->esc_seq.buf[0] == '[') && in charlcd_write_char()
640 (priv->esc_seq.buf[1] == 'L')) { in charlcd_write_char()
649 if (processed || (priv->esc_seq.len >= LCD_ESCAPE_LEN)) in charlcd_write_char()
650 priv->esc_seq.len = -1; in charlcd_write_char()
662 for (; count-- > 0; (*ppos)++, tmp++) { in charlcd_write()
671 return -EFAULT; in charlcd_write()
676 return tmp - buf; in charlcd_write()
684 ret = -EBUSY; in charlcd_open()
688 ret = -EPERM; in charlcd_open()
689 if (file->f_mode & FMODE_READ) /* device is write-only */ in charlcd_open()
692 if (priv->must_clear) { in charlcd_open()
693 charlcd_clear_display(&priv->lcd); in charlcd_open()
694 priv->must_clear = false; in charlcd_open()
727 for (; count-- > 0; tmp++) { in charlcd_puts()
742 #define LCD_INIT_TEXT "Linux-" UTS_RELEASE "\n"
750 #define LCD_INIT_BL "\x1b[L-"
759 if (lcd->ops->backlight) { in charlcd_init()
760 mutex_init(&priv->bl_tempo_lock); in charlcd_init()
761 INIT_DELAYED_WORK(&priv->bl_work, charlcd_bl_off); in charlcd_init()
765 * before this line, we must NOT send anything to the display. in charlcd_init()
773 /* display a short message */ in charlcd_init()
776 /* clear the display on the next device opening */ in charlcd_init()
777 priv->must_clear = true; in charlcd_init()
791 priv->esc_seq.len = -1; in charlcd_alloc()
793 lcd = &priv->lcd; in charlcd_alloc()
794 lcd->ifwidth = 8; in charlcd_alloc()
795 lcd->bwidth = DEFAULT_LCD_BWIDTH; in charlcd_alloc()
796 lcd->hwidth = DEFAULT_LCD_HWIDTH; in charlcd_alloc()
797 lcd->drvdata = priv->drvdata; in charlcd_alloc()
860 charlcd_puts(lcd, "\x0cLCD driver unloaded.\x1b[Lc\x1b[Lb\x1b[L-"); in charlcd_unregister()
863 if (lcd->ops->backlight) { in charlcd_unregister()
864 cancel_delayed_work_sync(&priv->bl_work); in charlcd_unregister()
865 priv->lcd.ops->backlight(&priv->lcd, 0); in charlcd_unregister()