Skip to content

Commit 339acb0

Browse files
poeschelojeda
authored andcommitted
auxdisplay: Move char redefine code to hd44780_common
Take the code to redefine characters out of charlcd and move it to hd44780_common, as this is hd44780 specific. There is now a function hd44780_common_redefine_char that drivers use and charlcd calls it through its ops function pointer. Reviewed-by: Willy Tarreau <[email protected]> Signed-off-by: Lars Poeschel <[email protected]> Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 8a86270 commit 339acb0

File tree

6 files changed

+70
-55
lines changed

6 files changed

+70
-55
lines changed

drivers/auxdisplay/charlcd.c

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
/* Keep the backlight on this many seconds for each flash */
2626
#define LCD_BL_TEMPO_PERIOD 4
2727

28-
#define LCD_CMD_SET_CGRAM_ADDR 0x40 /* Set char generator RAM address */
29-
3028
#define LCD_ESCAPE_LEN 24 /* Max chars for LCD escape command */
3129
#define LCD_ESCAPE_CHAR 27 /* Use char 27 for escape command */
3230

@@ -344,61 +342,13 @@ static inline int handle_lcd_special_code(struct charlcd *lcd)
344342
LCD_FLAG_C | LCD_FLAG_B;
345343
processed = 1;
346344
break;
347-
case 'G': {
348-
/* Generator : LGcxxxxx...xx; must have <c> between '0'
349-
* and '7', representing the numerical ASCII code of the
350-
* redefined character, and <xx...xx> a sequence of 16
351-
* hex digits representing 8 bytes for each character.
352-
* Most LCDs will only use 5 lower bits of the 7 first
353-
* bytes.
354-
*/
355-
356-
unsigned char cgbytes[8];
357-
unsigned char cgaddr;
358-
int cgoffset;
359-
int shift;
360-
char value;
361-
int addr;
362-
363-
if (!strchr(esc, ';'))
364-
break;
365-
366-
esc++;
367-
368-
cgaddr = *(esc++) - '0';
369-
if (cgaddr > 7) {
345+
case 'G':
346+
if (lcd->ops->redefine_char)
347+
processed = lcd->ops->redefine_char(lcd, esc);
348+
else
370349
processed = 1;
371-
break;
372-
}
373-
374-
cgoffset = 0;
375-
shift = 0;
376-
value = 0;
377-
while (*esc && cgoffset < 8) {
378-
int half;
379-
380-
shift ^= 4;
381-
382-
half = hex_to_bin(*esc++);
383-
if (half < 0)
384-
continue;
385-
386-
value |= half << shift;
387-
if (shift == 0) {
388-
cgbytes[cgoffset++] = value;
389-
value = 0;
390-
}
391-
}
392-
393-
hdc->write_cmd(hdc, LCD_CMD_SET_CGRAM_ADDR | (cgaddr * 8));
394-
for (addr = 0; addr < cgoffset; addr++)
395-
hdc->write_data(hdc, cgbytes[addr]);
396-
397-
/* ensures that we stop writing to CGRAM */
398-
lcd->ops->gotoxy(lcd);
399-
processed = 1;
400350
break;
401-
}
351+
402352
case 'x': /* gotoxy : LxXXX[yYYY]; */
403353
case 'y': /* gotoxy : LyYYY[xXXX]; */
404354
if (priv->esc_seq.buf[priv->esc_seq.len - 1] != ';')

drivers/auxdisplay/charlcd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ struct charlcd {
7575
* @cursor: Turn cursor on or off.
7676
* @blink: Turn cursor blink on or off.
7777
* @lines: One or two lines.
78+
* @redefine_char: Redefine the actual pixel matrix of character.
7879
*/
7980
struct charlcd_ops {
8081
void (*clear_fast)(struct charlcd *lcd);
@@ -91,6 +92,7 @@ struct charlcd_ops {
9192
int (*blink)(struct charlcd *lcd, enum charlcd_onoff on);
9293
int (*fontsize)(struct charlcd *lcd, enum charlcd_fontsize size);
9394
int (*lines)(struct charlcd *lcd, enum charlcd_lines lines);
95+
int (*redefine_char)(struct charlcd *lcd, char *esc);
9496
};
9597

9698
void charlcd_backlight(struct charlcd *lcd, enum charlcd_onoff on);

drivers/auxdisplay/hd44780.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ static const struct charlcd_ops hd44780_ops_gpio8 = {
138138
.blink = hd44780_common_blink,
139139
.fontsize = hd44780_common_fontsize,
140140
.lines = hd44780_common_lines,
141+
.redefine_char = hd44780_common_redefine_char,
141142
};
142143

143144
/* Send a command to the LCD panel in 4 bit GPIO mode */
@@ -193,6 +194,7 @@ static const struct charlcd_ops hd44780_ops_gpio4 = {
193194
.blink = hd44780_common_blink,
194195
.fontsize = hd44780_common_fontsize,
195196
.lines = hd44780_common_lines,
197+
.redefine_char = hd44780_common_redefine_char,
196198
};
197199

198200
static int hd44780_probe(struct platform_device *pdev)

drivers/auxdisplay/hd44780_common.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#define LCD_CMD_TWO_LINES 0x08 /* Set to two display lines */
2727
#define LCD_CMD_FONT_5X10_DOTS 0x04 /* Set char font to 5x10 dots */
2828

29+
#define LCD_CMD_SET_CGRAM_ADDR 0x40 /* Set char generator RAM address */
30+
2931
#define LCD_CMD_SET_DDRAM_ADDR 0x80 /* Set display data RAM address */
3032

3133
/* sleeps that many milliseconds with a reschedule */
@@ -289,6 +291,61 @@ int hd44780_common_lines(struct charlcd *lcd, enum charlcd_lines lines)
289291
}
290292
EXPORT_SYMBOL_GPL(hd44780_common_lines);
291293

294+
int hd44780_common_redefine_char(struct charlcd *lcd, char *esc)
295+
{
296+
/* Generator : LGcxxxxx...xx; must have <c> between '0'
297+
* and '7', representing the numerical ASCII code of the
298+
* redefined character, and <xx...xx> a sequence of 16
299+
* hex digits representing 8 bytes for each character.
300+
* Most LCDs will only use 5 lower bits of the 7 first
301+
* bytes.
302+
*/
303+
304+
struct hd44780_common *hdc = lcd->drvdata;
305+
unsigned char cgbytes[8];
306+
unsigned char cgaddr;
307+
int cgoffset;
308+
int shift;
309+
char value;
310+
int addr;
311+
312+
if (!strchr(esc, ';'))
313+
return 0;
314+
315+
esc++;
316+
317+
cgaddr = *(esc++) - '0';
318+
if (cgaddr > 7)
319+
return 1;
320+
321+
cgoffset = 0;
322+
shift = 0;
323+
value = 0;
324+
while (*esc && cgoffset < 8) {
325+
int half;
326+
327+
shift ^= 4;
328+
half = hex_to_bin(*esc++);
329+
if (half < 0)
330+
continue;
331+
332+
value |= half << shift;
333+
if (shift == 0) {
334+
cgbytes[cgoffset++] = value;
335+
value = 0;
336+
}
337+
}
338+
339+
hdc->write_cmd(hdc, LCD_CMD_SET_CGRAM_ADDR | (cgaddr * 8));
340+
for (addr = 0; addr < cgoffset; addr++)
341+
hdc->write_data(hdc, cgbytes[addr]);
342+
343+
/* ensures that we stop writing to CGRAM */
344+
lcd->ops->gotoxy(lcd);
345+
return 1;
346+
}
347+
EXPORT_SYMBOL_GPL(hd44780_common_redefine_char);
348+
292349
struct hd44780_common *hd44780_common_alloc(void)
293350
{
294351
struct hd44780_common *hd;

drivers/auxdisplay/hd44780_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ int hd44780_common_cursor(struct charlcd *lcd, enum charlcd_onoff on);
2929
int hd44780_common_blink(struct charlcd *lcd, enum charlcd_onoff on);
3030
int hd44780_common_fontsize(struct charlcd *lcd, enum charlcd_fontsize size);
3131
int hd44780_common_lines(struct charlcd *lcd, enum charlcd_lines lines);
32+
int hd44780_common_redefine_char(struct charlcd *lcd, char *esc);
3233
struct hd44780_common *hd44780_common_alloc(void);

drivers/auxdisplay/panel.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@ static const struct charlcd_ops charlcd_serial_ops = {
886886
.blink = hd44780_common_blink,
887887
.fontsize = hd44780_common_fontsize,
888888
.lines = hd44780_common_lines,
889+
.redefine_char = hd44780_common_redefine_char,
889890
};
890891

891892
static const struct charlcd_ops charlcd_parallel_ops = {
@@ -902,6 +903,7 @@ static const struct charlcd_ops charlcd_parallel_ops = {
902903
.blink = hd44780_common_blink,
903904
.fontsize = hd44780_common_fontsize,
904905
.lines = hd44780_common_lines,
906+
.redefine_char = hd44780_common_redefine_char,
905907
};
906908

907909
static const struct charlcd_ops charlcd_tilcd_ops = {
@@ -918,6 +920,7 @@ static const struct charlcd_ops charlcd_tilcd_ops = {
918920
.blink = hd44780_common_blink,
919921
.fontsize = hd44780_common_fontsize,
920922
.lines = hd44780_common_lines,
923+
.redefine_char = hd44780_common_redefine_char,
921924
};
922925

923926
/* initialize the LCD driver */

0 commit comments

Comments
 (0)