Commit 7471142cdf75c562f2ac8f07c021e0ba80bde6bd

Authored by Hannes Petermaier
Committed by Anatolij Gustschin
1 parent a202c5bd24

common/lcd_console: move single static variables into common (static) structure

For coming implementation of lcd_console rotation, we will need some more
variables for holding information about framebuffer size, rotation, ...

For better readability we catch all them into a common structure.

Signed-off-by: Hannes Petermaier <hannes.petermaier@br-automation.com>
Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>
Acked-by: Nikita Kiryanov <nikita@compulab.co.il>

Showing 1 changed file with 38 additions and 38 deletions Side-by-side Diff

common/lcd_console.c
... ... @@ -11,48 +11,49 @@
11 11 #include <video_font.h> /* Get font data, width and height */
12 12  
13 13 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
14   -#define CONSOLE_ROW_FIRST lcd_console_address
15   -#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * console_rows)
  14 +#define CONSOLE_ROW_FIRST cons.lcd_address
  15 +#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * cons.rows)
16 16  
17   -static short console_curr_col;
18   -static short console_curr_row;
19   -static short console_cols;
20   -static short console_rows;
21   -static void *lcd_console_address;
  17 +struct console_t {
  18 + short curr_col, curr_row;
  19 + short cols, rows;
  20 + void *lcd_address;
  21 +};
  22 +static struct console_t cons;
22 23  
23 24 void lcd_init_console(void *address, int rows, int cols)
24 25 {
25   - console_curr_col = 0;
26   - console_curr_row = 0;
27   - console_cols = cols;
28   - console_rows = rows;
29   - lcd_console_address = address;
  26 + memset(&cons, 0, sizeof(cons));
  27 + cons.cols = cols;
  28 + cons.rows = rows;
  29 + cons.lcd_address = address;
  30 +
30 31 }
31 32  
32 33 void lcd_set_col(short col)
33 34 {
34   - console_curr_col = col;
  35 + cons.curr_col = col;
35 36 }
36 37  
37 38 void lcd_set_row(short row)
38 39 {
39   - console_curr_row = row;
  40 + cons.curr_row = row;
40 41 }
41 42  
42 43 void lcd_position_cursor(unsigned col, unsigned row)
43 44 {
44   - console_curr_col = min_t(short, col, console_cols - 1);
45   - console_curr_row = min_t(short, row, console_rows - 1);
  45 + cons.curr_col = min_t(short, col, cons.cols - 1);
  46 + cons.curr_row = min_t(short, row, cons.rows - 1);
46 47 }
47 48  
48 49 int lcd_get_screen_rows(void)
49 50 {
50   - return console_rows;
  51 + return cons.rows;
51 52 }
52 53  
53 54 int lcd_get_screen_columns(void)
54 55 {
55   - return console_cols;
  56 + return cons.cols;
56 57 }
57 58  
58 59 static void lcd_putc_xy(ushort x, ushort y, char c)
... ... @@ -63,7 +64,7 @@
63 64 int bg_color = lcd_getbgcolor();
64 65 int i;
65 66  
66   - dest = (uchar *)(lcd_console_address +
  67 + dest = (uchar *)(cons.lcd_address +
67 68 y * lcd_line_length + x * NBITS(LCD_BPP) / 8);
68 69  
69 70 for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
... ... @@ -91,7 +92,7 @@
91 92  
92 93 /* Copy up rows ignoring those that will be overwritten */
93 94 memcpy(CONSOLE_ROW_FIRST,
94   - lcd_console_address + CONSOLE_ROW_SIZE * rows,
  95 + cons.lcd_address + CONSOLE_ROW_SIZE * rows,
95 96 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
96 97  
97 98 /* Clear the last rows */
... ... @@ -99,7 +100,7 @@
99 100 memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
100 101 bg_color, CONSOLE_ROW_SIZE * rows);
101 102 #else
102   - u32 *ppix = lcd_console_address +
  103 + u32 *ppix = cons.lcd_address +
103 104 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows;
104 105 u32 i;
105 106 for (i = 0;
106 107  
107 108  
108 109  
109 110  
... ... @@ -109,27 +110,27 @@
109 110 }
110 111 #endif
111 112 lcd_sync();
112   - console_curr_row -= rows;
  113 + cons.curr_row -= rows;
113 114 }
114 115  
115 116 static inline void console_back(void)
116 117 {
117   - if (--console_curr_col < 0) {
118   - console_curr_col = console_cols - 1;
119   - if (--console_curr_row < 0)
120   - console_curr_row = 0;
  118 + if (--cons.curr_col < 0) {
  119 + cons.curr_col = cons.cols - 1;
  120 + if (--cons.curr_row < 0)
  121 + cons.curr_row = 0;
121 122 }
122 123  
123   - lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH,
124   - console_curr_row * VIDEO_FONT_HEIGHT, ' ');
  124 + lcd_putc_xy(cons.curr_col * VIDEO_FONT_WIDTH,
  125 + cons.curr_row * VIDEO_FONT_HEIGHT, ' ');
125 126 }
126 127  
127 128 static inline void console_newline(void)
128 129 {
129   - console_curr_col = 0;
  130 + cons.curr_col = 0;
130 131  
131 132 /* Check if we need to scroll the terminal */
132   - if (++console_curr_row >= console_rows)
  133 + if (++cons.curr_row >= cons.rows)
133 134 console_scrollup();
134 135 else
135 136 lcd_sync();
136 137  
137 138  
... ... @@ -145,18 +146,17 @@
145 146  
146 147 switch (c) {
147 148 case '\r':
148   - console_curr_col = 0;
149   -
  149 + cons.curr_col = 0;
150 150 return;
151 151 case '\n':
152 152 console_newline();
153 153  
154 154 return;
155 155 case '\t': /* Tab (8 chars alignment) */
156   - console_curr_col += 8;
157   - console_curr_col &= ~7;
  156 + cons.curr_col += 8;
  157 + cons.curr_col &= ~7;
158 158  
159   - if (console_curr_col >= console_cols)
  159 + if (cons.curr_col >= cons.cols)
160 160 console_newline();
161 161  
162 162 return;
... ... @@ -165,9 +165,9 @@
165 165  
166 166 return;
167 167 default:
168   - lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH,
169   - console_curr_row * VIDEO_FONT_HEIGHT, c);
170   - if (++console_curr_col >= console_cols)
  168 + lcd_putc_xy(cons.curr_col * VIDEO_FONT_WIDTH,
  169 + cons.curr_row * VIDEO_FONT_HEIGHT, c);
  170 + if (++cons.curr_col >= cons.cols)
171 171 console_newline();
172 172 }
173 173 }