-
Notifications
You must be signed in to change notification settings - Fork 1
/
gpiolcd.c
718 lines (635 loc) · 17.3 KB
/
gpiolcd.c
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) Andriy Gapon <[email protected]>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
/*
* Control HD44780 LCD module hung off 8-pin GPIO.
*
* $FreeBSD$
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
#include <fcntl.h>
#include <unistd.h>
#include <err.h>
#include <errno.h>
#include <assert.h>
#include <sysexits.h>
#include <sys/gpio.h>
/******************************************************************************
* Driver for the Hitachi HD44780. This is probably *the* most common driver
* to be found on 1, 2 and 4-line alphanumeric LCDs.
*
* This driver assumes the following connections by default:
*
* GPIO LCD Module
* --------------------------------
* P0 RS
* P1 R/W
* P2 E
* P3 Backlight control circuit
* P4-P7 Data, DB4-DB7
*
* FIXME: this driver never reads from the device and never checks busy flag.
* Instead it uses fixed delays to wait for instruction completions.
*/
#define debug(lev, fmt, args...) if (debuglevel >= lev) fprintf(stderr, fmt "\n" , ## args);
static void usage(void);
static char *progname;
#define DEFAULT_DEVICE "/dev/gpioc0"
enum command {
CMD_RESET,
CMD_BKSP,
CMD_CLR,
CMD_NL,
CMD_CR,
CMD_HOME,
CMD_TAB,
CMD_FLASH,
};
enum reg_type {
HD_COMMAND,
HD_DATA
};
enum hd_pin_id {
HD_PIN_DAT0 = 0,
HD_PIN_DAT1,
HD_PIN_DAT2,
HD_PIN_DAT3,
HD_PIN_DAT4,
HD_PIN_DAT5,
HD_PIN_DAT6,
HD_PIN_DAT7,
HD_PIN_RS,
HD_PIN_RW,
HD_PIN_E,
HD_PIN_BL,
HD_PIN_COUNT,
};
static struct hd44780_state {
int hd_fd;
int hd_ifwidth;
int hd_lines;
int hd_cols;
int hd_blink;
int hd_cursor;
int hd_font;
int hd_bl_on;
int hd_col;
int hd_row;
int pins[HD_PIN_COUNT];
} hd44780_state;
/* Driver functions */
static void hd44780_prepare(char *devname, struct hd44780_state * state);
static void hd44780_finish(void);
static void hd44780_command(struct hd44780_state *state, enum command cmd);
static void hd44780_putc(struct hd44780_state *state, int c);
static void do_char(struct hd44780_state *state, char ch);
static int debuglevel = 0;
int
main(int argc, char *argv[])
{
struct hd44780_state *state = &hd44780_state;
extern char *optarg;
extern int optind;
char *cp, *endp;
char *devname = DEFAULT_DEVICE;
int ch, i;
if ((progname = strrchr(argv[0], '/'))) {
progname++;
} else {
progname = argv[0];
}
state->hd_lines = 2;
state->hd_cols = 20;
state->hd_ifwidth = 4;
for (i = 0; i < HD_PIN_COUNT; i++)
state->pins[i] = -1;
state->pins[HD_PIN_RS] = 0;
state->pins[HD_PIN_RW] = 1;
state->pins[HD_PIN_E] = 2;
state->pins[HD_PIN_DAT0] = 4;
while ((ch = getopt(argc, argv, "BCdD:E:f:Fh:I:L:OR:w:W:")) != -1) {
switch(ch) {
case 'd':
debuglevel++;
break;
case 'f':
devname = optarg;
break;
case 'h':
state->hd_lines = strtol(optarg, &endp, 10);
if (*endp != '\0') {
fprintf(stderr, "invalid number of lines %s\n", optarg);
usage();
}
break;
case 'w':
state->hd_cols = strtol(optarg, &endp, 10);
if (*endp != '\0') {
fprintf(stderr, "invalid number of columsn %s\n", optarg);
usage();
}
break;
case 'B':
state->hd_blink = 1;
break;
case 'C':
state->hd_cursor = 1;
break;
case 'F':
state->hd_font = 1;
break;
case 'O':
state->hd_bl_on = 1;
break;
case 'I':
state->hd_ifwidth = strtol(optarg, &endp, 10);
if (*endp != '\0') {
fprintf(stderr, "invalid interface width %s\n", optarg);
usage();
}
break;
case 'R':
state->pins[HD_PIN_RS] = strtol(optarg, &endp, 10);
if (*endp != '\0') {
fprintf(stderr, "invalid pin specification %s\n", optarg);
usage();
}
break;
case 'W':
state->pins[HD_PIN_RW] = strtol(optarg, &endp, 10);
if (*endp != '\0') {
fprintf(stderr, "invalid pin specification %s\n", optarg);
usage();
}
break;
case 'E':
state->pins[HD_PIN_E] = strtol(optarg, &endp, 10);
if (*endp != '\0') {
fprintf(stderr, "invalid pin specification %s\n", optarg);
usage();
}
break;
case 'L':
state->pins[HD_PIN_BL] = strtol(optarg, &endp, 10);
if (*endp != '\0') {
fprintf(stderr, "invalid pin specification %s\n", optarg);
usage();
}
break;
case 'D':
state->pins[HD_PIN_DAT0] = strtol(optarg, &endp, 10);
if (*endp != '\0') {
fprintf(stderr, "invalid pin specification %s\n", optarg);
usage();
}
break;
default:
usage();
}
}
argc -= optind;
argv += optind;
if (state->hd_ifwidth != 4) {
fprintf(stderr, "Unsupported data interface width %d\n", state->hd_ifwidth);
usage();
}
for (i = 1; i < state->hd_ifwidth; i++) {
state->pins[HD_PIN_DAT0 + i] = state->pins[HD_PIN_DAT0] + i;
}
if (state->hd_lines != 1 && state->hd_lines != 2 && state->hd_lines != 4) {
fprintf(stderr, "Unsupported number of lines %d\n", state->hd_lines);
usage();
}
if (state->hd_cols <= 0 || state->hd_lines * state->hd_cols > 80) {
fprintf(stderr, "Unsupported number of columns %d\n", state->hd_cols);
usage();
}
if (state->hd_bl_on && state->pins[HD_PIN_BL] == -1) {
fprintf(stderr, "Backlight pin is not specified\n");
usage();
}
hd44780_prepare(devname, state);
atexit(hd44780_finish);
if (argc > 0) {
debug(2, "reading input from %d argument%s", argc, (argc > 1) ? "s" : "");
for (i = 0; i < argc; i++)
for (cp = argv[i]; *cp; cp++)
do_char(state, *cp);
} else {
debug(2, "reading input from stdin");
setvbuf(stdin, NULL, _IONBF, 0);
while ((ch = fgetc(stdin)) != EOF)
do_char(state, (char)ch);
}
exit(EX_OK);
}
static void
usage(void)
{
fprintf(stderr, "usage: %s [-f device] [-d] [-B] [-C] [-F] [-O] "
"[-h <n>] [-w <n>] [-R <n>]\n"
"\t[-W <n>] [-E <n>] [-L <n>] [-D <n>] [-I <n>] [args...]\n",
progname);
fprintf(stderr, "Supported hardware: Hitachi HD44780 and compatibles\n");
fprintf(stderr, " -d Increase debugging\n");
fprintf(stderr, " -f Specify device, default is '%s'\n", DEFAULT_DEVICE);
fprintf(stderr, " -h <n> n-line display (default 2)\n"
" -w <n> n-column display (default 20)\n"
" -B Cursor blink enable\n"
" -C Cursor enable\n"
" -F Large font select\n"
" -R <n> R/S pin number (default 0)\n"
" -W <n> R/W pin number (default 1)\n"
" -E <n> E pin number (default 2)\n"
" -L <n> Backlight pin number (default none)\n"
" -O Turn backlight on (default off)\n"
" -D <n> First data pin number (default 4)\n"
" -I <n> Data interface width (only 4 is supported)\n");
fprintf(stderr, " args Message strings.\n");
fprintf(stderr, " Some ASCII control characters and escapes sequences are supported:\n");
fprintf(stderr, " <BS> (\\b) Backspace\n");
fprintf(stderr, " <LF> (\\f) Clear display, home cursor\n");
fprintf(stderr, " <NL> (\\n) Newline\n");
fprintf(stderr, " <CR> (\\r) Carriage return\n");
fprintf(stderr, " <HT> (\\t) Tab\n");
fprintf(stderr, " <BEL> (\\a) Flash screen\n");
fprintf(stderr, " <ESC>R Reset display\n");
fprintf(stderr, " <ESC>H Home cursor\n");
fprintf(stderr, " If args not supplied, strings are read from standard input\n");
exit(EX_USAGE);
}
static void
do_char(struct hd44780_state *state, char ch)
{
static int esc = 0;
if (esc) {
switch(ch) {
case 'R':
hd44780_command(state, CMD_RESET);
break;
case 'H':
hd44780_command(state, CMD_HOME);
break;
}
esc = 0;
return;
}
if (ch == 27) {
esc = 1;
return;
}
switch(ch) {
case '\n':
hd44780_command(state, CMD_NL);
break;
case '\r':
hd44780_command(state, CMD_CR);
break;
case '\t':
hd44780_command(state, CMD_TAB);
break;
case '\a':
hd44780_command(state, CMD_FLASH);
break;
case '\b':
hd44780_command(state, CMD_BKSP);
break;
case '\f':
hd44780_command(state, CMD_CLR);
break;
default:
if (isascii(ch) && isprint(ch))
hd44780_putc(state, ch);
break;
}
}
static void
hd44780_set_pin(struct hd44780_state *state, enum hd_pin_id pin, bool on)
{
struct gpio_req req;
int err;
assert(state->pins[pin] != -1);
req.gp_pin = state->pins[pin];
req.gp_value = on;
err = ioctl(state->hd_fd, GPIOSET, &req);
if (err != 0)
debug(1, "%s: error %d", __func__, errno);
}
static void
hd44780_strobe(struct hd44780_state *state)
{
usleep(20);
hd44780_set_pin(state, HD_PIN_E, true);
usleep(40);
hd44780_set_pin(state, HD_PIN_E, false);
usleep(20);
}
/* FIXME: hardcoded to 4-bit data interface. */
static void
hd44780_output(struct hd44780_state *state, enum reg_type type, uint8_t data)
{
int i;
debug(3, "%s -> 0x%02x", (type == HD_COMMAND) ? "cmd " : "data", data);
hd44780_set_pin(state, HD_PIN_RW, false);
if (type == HD_COMMAND)
hd44780_set_pin(state, HD_PIN_RS, false);
else
hd44780_set_pin(state, HD_PIN_RS, true);
/* Set upper nibble of data. */
for (i = 0; i < 4; i++) {
hd44780_set_pin(state, HD_PIN_DAT0 + i,
((1 << (i + 4)) & data) != 0);
}
hd44780_strobe(state);
/* Set lower nibble of data. */
for (i = 0; i < 4; i++) {
hd44780_set_pin(state, HD_PIN_DAT0 + i,
((1 << i) & data) != 0);
}
hd44780_strobe(state);
}
static void
hd44780_output4(struct hd44780_state *state, enum reg_type type, uint8_t data)
{
int i;
debug(3, "%s -> 0x%02x", (type == HD_COMMAND) ? "cmd " : "data", data);
hd44780_set_pin(state, HD_PIN_RW, false);
if (type == HD_COMMAND)
hd44780_set_pin(state, HD_PIN_RS, false);
else
hd44780_set_pin(state, HD_PIN_RS, true);
/* Set upper nibble of data. */
for (i = 0; i < 4; i++) {
hd44780_set_pin(state, HD_PIN_DAT0 + i,
((1 << (i + 4)) & data) != 0);
}
hd44780_strobe(state);
}
static void
hd44780_prepare(char *devname, struct hd44780_state *state)
{
struct gpio_pin cfg;
int error, i;
if ((state->hd_fd = open(devname, O_RDWR, 0)) == -1)
err(EX_OSFILE, "can't open '%s'", devname);
/*
* Before anything else set E as input to avoid triggering
* it as a possible side-effect of changing other pins.
*/
cfg.gp_pin = state->pins[HD_PIN_E];
cfg.gp_flags = GPIO_PIN_INPUT;
error = ioctl(state->hd_fd, GPIOSETCONFIG, &cfg);
if (error != 0)
err(1, "configuring pin %d as input failed",
cfg.gp_pin);
/* Configure GPIO pins. */
for (i = 0; i < HD_PIN_COUNT; i++) {
if (state->pins[i] == -1)
continue;
cfg.gp_pin = state->pins[i];
cfg.gp_flags = GPIO_PIN_INPUT;
(void)ioctl(state->hd_fd, GPIOSETCONFIG, &cfg);
}
for (i = 0; i < HD_PIN_COUNT; i++) {
if (state->pins[i] == -1)
continue;
cfg.gp_pin = state->pins[i];
cfg.gp_flags = GPIO_PIN_OUTPUT;
error = ioctl(state->hd_fd, GPIOSETCONFIG, &cfg);
if (error != 0)
err(1, "configuring pin %d as output failed",
cfg.gp_pin);
}
for (i = 0; i < HD_PIN_COUNT; i++) {
if (state->pins[i] == -1)
continue;
hd44780_set_pin(state, i, false);
}
usleep(20000);
hd44780_command(state, CMD_RESET);
if (state->hd_bl_on)
hd44780_set_pin(state, HD_PIN_BL, true);
}
static void
hd44780_finish(void)
{
close(hd44780_state.hd_fd);
}
#define HD_CMD_CLEAR 0x01
#define HD_CMD_HOME 0x02
#define HD_CMD_ENTRYMODE 0x04
#define HD_ENTRY_INCR 0x02
#define HD_DISP_SHIFT 0x01
#define HD_CMD_DISPCTRL 0x08
#define HD_DISP_ON 0x04
#define HD_CURSOR_ON 0x02
#define HD_BLINK_ON 0x01
#define HD_CMD_MOVE 0x10
#define HD_MOVE_DISP 0x08
#define HD_MOVE_CURSOR 0x00
#define HD_MOVE_RIGHT 0x04
#define HD_MOVE_LEFT 0x00
#define HD_CMD_SETMODE 0x20
#define HD_MODE_8BIT_IF 0x10
#define HD_MODE_2LINES 0x08
#define HD_MODE_LARGE_FONT 0x04
#define HD_CMD_SET_CGADDR 0x40
#define HD_CMD_SET_ADDR 0x80
#define HD_LINE_DRAM_SIZE 40
#define HD_LINE1_DRAM_OFFSET 0x40
static uint8_t
hd44780_calc_addr(struct hd44780_state *state)
{
uint8_t addr;
addr = state->hd_col;
if (state->hd_row == 1 || state->hd_row == 3)
addr += HD_LINE1_DRAM_OFFSET;
if (state->hd_row == 2 || state->hd_row == 3)
addr += state->hd_cols;
return (addr);
}
static void
hd44780_command(struct hd44780_state *state, enum command cmd)
{
int i;
uint8_t val;
switch (cmd) {
case CMD_RESET: /* full manual reset and reconfigure as per datasheet */
debug(1, "hd44780: reset to %d-bit interface, %d lines, "
"%s font,%s%s cursor",
state->hd_ifwidth, state->hd_lines,
state->hd_font ? "5x10" : "5x8",
state->hd_cursor ? "" : " no",
state->hd_blink ? " blinking" : "");
/*
* This needs to be repeated three times to guarantee a state
* where the desired mode can be configured.
*/
val = HD_CMD_SETMODE;
val |= HD_MODE_8BIT_IF;
hd44780_output4(state, HD_COMMAND, val);
usleep(10000);
hd44780_output4(state, HD_COMMAND, val);
usleep(1000);
hd44780_output4(state, HD_COMMAND, val);
usleep(1000);
val = HD_CMD_SETMODE;
if (state->hd_ifwidth == 8)
val |= HD_MODE_8BIT_IF;
if (state->hd_lines != 1)
val |= HD_MODE_2LINES;
if (state->hd_font)
val |= HD_MODE_LARGE_FONT;
/*
* At this point the display is in 8-bit mode, so execute
* a command to enter the 4-bit mode if needed.
*/
if (state->hd_ifwidth == 4)
hd44780_output4(state, HD_COMMAND, val);
hd44780_output(state, HD_COMMAND, val);
usleep(10000);
val = HD_CMD_DISPCTRL;
hd44780_output(state, HD_COMMAND, val);
usleep(1000);
val |= HD_DISP_ON;
if (state->hd_cursor)
val |= HD_CURSOR_ON;
if (state->hd_blink)
val |= HD_BLINK_ON;
hd44780_output(state, HD_COMMAND, val);
usleep(1000);
val = HD_CMD_ENTRYMODE;
val |= HD_ENTRY_INCR;
hd44780_output(state, HD_COMMAND, val);
usleep(1000);
/* FALLTHROUGH */
case CMD_CLR:
hd44780_output(state, HD_COMMAND, HD_CMD_CLEAR);
usleep(2000);
state->hd_col = 0;
state->hd_row = 0;
break;
case CMD_BKSP:
if (state->hd_col > 0) {
/*
* Move the cursor back, overwrite with a space
* and move back again.
*/
hd44780_output(state, HD_COMMAND, HD_CMD_MOVE |
HD_MOVE_CURSOR | HD_MOVE_LEFT);
state->hd_col--; /* NB: putc increments hd_col */
hd44780_putc(state, ' ');
hd44780_output(state, HD_COMMAND, HD_CMD_MOVE |
HD_MOVE_CURSOR | HD_MOVE_LEFT);
state->hd_col--;
} else {
/* XXX */
hd44780_command(state, CMD_FLASH);
}
usleep(1000);
break;
case CMD_NL:
/*
* Fill the remainder of the current line with spaces. If there
* is no space for another line, then the cursor is held at the
* end position. This way no characters will be output until
* the screen is cleared or the cursor is moved otherwise.
*/
while (state->hd_col < state->hd_cols) /* NB: putc increments hd_col */
hd44780_putc(state, ' ');
if (state->hd_row < state->hd_lines - 1) {
state->hd_row++;
state->hd_col = 0;
val = hd44780_calc_addr(state);
hd44780_output(state, HD_COMMAND, HD_CMD_SET_ADDR | val);
usleep(1000);
}
break;
case CMD_CR:
state->hd_col = 0;
val = hd44780_calc_addr(state);
hd44780_output(state, HD_COMMAND, HD_CMD_SET_ADDR | val);
usleep(1000);
break;
case CMD_HOME:
/* just move to address 0, also resets display shift */
hd44780_output(state, HD_COMMAND, HD_CMD_HOME);
usleep(2000);
state->hd_col = 0;
state->hd_row = 0;
break;
case CMD_TAB:
i = 8 - state->hd_col % 8;
if (state->hd_col + i > state->hd_cols)
i = state->hd_cols - state->hd_col;
while (i-- > 0)
hd44780_putc(state, ' ');
break;
case CMD_FLASH:
/* Turn the display off and on a couple of times. */
for (i = 0; i < 2; i++) {
val = HD_CMD_DISPCTRL;
hd44780_output(state, HD_COMMAND, val);
usleep(200000);
val |= HD_DISP_ON;
if (state->hd_cursor)
val |= HD_CURSOR_ON;
if (state->hd_blink)
val |= HD_BLINK_ON;
hd44780_output(state, HD_COMMAND, val);
if (i < 3)
usleep(200000);
else
usleep(1000);
}
break;
default:
if (isprint(cmd)) {
warnx("unknown command %c", cmd);
} else {
warnx("unknown command 0x%x", cmd);
}
}
}
static void
hd44780_putc(struct hd44780_state *state, int c)
{
/*
* Won't print beyond the screen even if there is off-screen DDRAM
* available.
* Screen shift commands are not supported yet.
*/
if (state->hd_col == state->hd_cols)
return;
hd44780_output(state, HD_DATA, c);
usleep(40);
state->hd_col++;
}