Skip to content

Commit 40c2b72

Browse files
poeschelojeda
authored andcommitted
auxdisplay: Change gotoxy calling interface
Change the calling interface for gotoxy from supplying the x and y coordinates in the charlcd struct to explicitly supplying x and y in the function arguments. This is more intuitive and allows for moving the cursor to positions independent from the position saved in the charlcd struct. Reviewed-by: Willy Tarreau <[email protected]> Signed-off-by: Lars Poeschel <[email protected]> Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 6e49eea commit 40c2b72

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

drivers/auxdisplay/charlcd.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static void charlcd_print(struct charlcd *lcd, char c)
119119

120120
/* prevents the cursor from wrapping onto the next line */
121121
if (lcd->addr.x == lcd->width)
122-
lcd->ops->gotoxy(lcd);
122+
lcd->ops->gotoxy(lcd, lcd->addr.x - 1, lcd->addr.y);
123123
}
124124

125125
static void charlcd_clear_display(struct charlcd *lcd)
@@ -325,7 +325,7 @@ static inline int handle_lcd_special_code(struct charlcd *lcd)
325325
/* restore cursor position */
326326
lcd->addr.x = xs;
327327
lcd->addr.y = ys;
328-
lcd->ops->gotoxy(lcd);
328+
lcd->ops->gotoxy(lcd, lcd->addr.x, lcd->addr.y);
329329
processed = 1;
330330
break;
331331
}
@@ -349,7 +349,7 @@ static inline int handle_lcd_special_code(struct charlcd *lcd)
349349

350350
/* If the command is valid, move to the new address */
351351
if (parse_xy(esc, &lcd->addr.x, &lcd->addr.y))
352-
lcd->ops->gotoxy(lcd);
352+
lcd->ops->gotoxy(lcd, lcd->addr.x, lcd->addr.y);
353353

354354
/* Regardless of its validity, mark as processed */
355355
processed = 1;
@@ -407,12 +407,12 @@ static void charlcd_write_char(struct charlcd *lcd, char c)
407407

408408
lcd->addr.x = 0;
409409
lcd->addr.y = (lcd->addr.y + 1) % lcd->height;
410-
lcd->ops->gotoxy(lcd);
410+
lcd->ops->gotoxy(lcd, lcd->addr.x, lcd->addr.y);
411411
break;
412412
case '\r':
413413
/* go to the beginning of the same line */
414414
lcd->addr.x = 0;
415-
lcd->ops->gotoxy(lcd);
415+
lcd->ops->gotoxy(lcd, lcd->addr.x, lcd->addr.y);
416416
break;
417417
case '\t':
418418
/* print a space instead of the tab */

drivers/auxdisplay/charlcd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct charlcd {
7878
struct charlcd_ops {
7979
void (*backlight)(struct charlcd *lcd, enum charlcd_onoff on);
8080
int (*print)(struct charlcd *lcd, int c);
81-
int (*gotoxy)(struct charlcd *lcd);
81+
int (*gotoxy)(struct charlcd *lcd, unsigned int x, unsigned int y);
8282
int (*home)(struct charlcd *lcd);
8383
int (*clear_display)(struct charlcd *lcd);
8484
int (*init_display)(struct charlcd *lcd);

drivers/auxdisplay/hd44780_common.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int hd44780_common_print(struct charlcd *lcd, int c)
4949
}
5050
EXPORT_SYMBOL_GPL(hd44780_common_print);
5151

52-
int hd44780_common_gotoxy(struct charlcd *lcd)
52+
int hd44780_common_gotoxy(struct charlcd *lcd, unsigned int x, unsigned int y)
5353
{
5454
struct hd44780_common *hdc = lcd->drvdata;
5555
unsigned int addr;
@@ -58,11 +58,10 @@ int hd44780_common_gotoxy(struct charlcd *lcd)
5858
* we force the cursor to stay at the end of the
5959
* line if it wants to go farther
6060
*/
61-
addr = lcd->addr.x < hdc->bwidth ? lcd->addr.x & (hdc->hwidth - 1)
62-
: hdc->bwidth - 1;
63-
if (lcd->addr.y & 1)
61+
addr = x < hdc->bwidth ? x & (hdc->hwidth - 1) : hdc->bwidth - 1;
62+
if (y & 1)
6463
addr += hdc->hwidth;
65-
if (lcd->addr.y & 2)
64+
if (y & 2)
6665
addr += hdc->bwidth;
6766
hdc->write_cmd(hdc, LCD_CMD_SET_DDRAM_ADDR | addr);
6867
return 0;
@@ -71,9 +70,7 @@ EXPORT_SYMBOL_GPL(hd44780_common_gotoxy);
7170

7271
int hd44780_common_home(struct charlcd *lcd)
7372
{
74-
lcd->addr.x = 0;
75-
lcd->addr.y = 0;
76-
return hd44780_common_gotoxy(lcd);
73+
return hd44780_common_gotoxy(lcd, 0, 0);
7774
}
7875
EXPORT_SYMBOL_GPL(hd44780_common_home);
7976

@@ -341,7 +338,7 @@ int hd44780_common_redefine_char(struct charlcd *lcd, char *esc)
341338
hdc->write_data(hdc, cgbytes[addr]);
342339

343340
/* ensures that we stop writing to CGRAM */
344-
lcd->ops->gotoxy(lcd);
341+
lcd->ops->gotoxy(lcd, lcd->addr.x, lcd->addr.y);
345342
return 1;
346343
}
347344
EXPORT_SYMBOL_GPL(hd44780_common_redefine_char);

drivers/auxdisplay/hd44780_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct hd44780_common {
1616
};
1717

1818
int hd44780_common_print(struct charlcd *lcd, int c);
19-
int hd44780_common_gotoxy(struct charlcd *lcd);
19+
int hd44780_common_gotoxy(struct charlcd *lcd, unsigned int x, unsigned int y);
2020
int hd44780_common_home(struct charlcd *lcd);
2121
int hd44780_common_clear_display(struct charlcd *lcd);
2222
int hd44780_common_init_display(struct charlcd *lcd);

0 commit comments

Comments
 (0)