comparison packages/hal/arm/sa11x0/assabet/current/misc/lcd_test.c @ 126:518f42066aba ecos-sw-2000-09-19

Merge from eCos master repository on 2000-09-19-06:25:26-BST
author jlarmour
date Tue, 19 Sep 2000 05:53:51 +0000
parents 0ec04793409a
children 0c2b7be0d798
comparison
equal deleted inserted replaced
125:b4407dc7f59d 126:518f42066aba
49 #include <cyg/hal/assabet.h> 49 #include <cyg/hal/assabet.h>
50 #include <cyg/hal/hal_cache.h> 50 #include <cyg/hal/hal_cache.h>
51 51
52 #include "eCos.xpm" 52 #include "eCos.xpm"
53 #include "redhat.xpm" 53 #include "redhat.xpm"
54 #include "redboot.xpm"
54 #include "escw.xpm" 55 #include "escw.xpm"
55 56
56 #ifndef FALSE 57 #ifndef FALSE
57 #define FALSE 0 58 #define FALSE 0
58 #define TRUE 1 59 #define TRUE 1
138 colors[i] = 0x0000; 139 colors[i] = 0x0000;
139 } 140 }
140 for (i = 0; i < nclrs; i++) { 141 for (i = 0; i < nclrs; i++) {
141 cp = xpm[i+1]; 142 cp = xpm[i+1];
142 colors[(unsigned int)*cp] = parse_color(&cp[4]); 143 colors[(unsigned int)*cp] = parse_color(&cp[4]);
144 // printf("Color[%c] = %x\n", *cp, colors[(unsigned int)*cp]);
143 } 145 }
144 146
145 for (row = 0; row < nrows; row++) { 147 for (row = 0; row < nrows; row++) {
146 cp = xpm[nclrs+1+row]; 148 cp = xpm[nclrs+1+row];
147 for (col = 0; col < ncols; col++) { 149 for (col = 0; col < ncols; col++) {
148 #if 0
149 if (*cp++ != '.') {
150 fp->pixels[row][col] = 0x0000;
151 } else {
152 fp->pixels[row][col] = 0xFFFF;
153 }
154 #else
155 fp->pixels[row][col] = colors[(unsigned int)*cp++]; 150 fp->pixels[row][col] = colors[(unsigned int)*cp++];
156 #endif
157 } 151 }
158 } 152 }
159 cyg_thread_delay(100); 153 cyg_thread_delay(100);
160 } 154 }
161 155
162 static void 156
163 lcd_test(cyg_addrword_t p) 157 // 8x8 Font - from Helios
164 { 158
165 int i, pix, row, col; 159 #define FIRST_CHAR 0x20
160 #define LAST_CHAR 0x7E
161 #define FONT_HEIGHT 8
162 #define FONT_WIDTH 8
163 #define CURSOR_ON 0x5F
164 #define CURSOR_OFF 0x20
165 static char font_table[LAST_CHAR-FIRST_CHAR+1][8] =
166 {
167 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* */
168 { 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x00 }, /* ! */
169 { 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* " */
170 { 0x6C, 0x6C, 0xFE, 0x6C, 0xFE, 0x6C, 0x6C, 0x00 }, /* # */
171 { 0x30, 0xFC, 0x16, 0x7C, 0xD0, 0x7E, 0x18, 0x00 }, /* $ */
172 { 0x06, 0x66, 0x30, 0x18, 0x0C, 0x66, 0x60, 0x00 }, /* % */
173 { 0x1C, 0x36, 0x36, 0x1C, 0xB6, 0x66, 0xDC, 0x00 }, /* & */
174 { 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* ' */
175 { 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x18, 0x30, 0x00 }, /* ( */
176 { 0x0C, 0x18, 0x30, 0x30, 0x30, 0x18, 0x0C, 0x00 }, /* ) */
177 { 0x00, 0x18, 0x7E, 0x3C, 0x7E, 0x18, 0x00, 0x00 }, /* * */
178 { 0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x00 }, /* + */
179 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x0C }, /* , */
180 { 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00 }, /* - */
181 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00 }, /* . */
182 { 0x00, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x00, 0x00 }, /* / */
183 { 0x3C, 0x66, 0x76, 0x7E, 0x6E, 0x66, 0x3C, 0x00 }, /* 0 */
184 { 0x18, 0x1C, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x00 }, /* 1 */
185 { 0x3C, 0x66, 0x60, 0x30, 0x18, 0x0C, 0x7E, 0x00 }, /* 2 */
186 { 0x3C, 0x66, 0x60, 0x38, 0x60, 0x66, 0x3C, 0x00 }, /* 3 */
187 { 0x30, 0x38, 0x3C, 0x36, 0x7E, 0x30, 0x30, 0x00 }, /* 4 */
188 { 0x7E, 0x06, 0x3E, 0x60, 0x60, 0x66, 0x3C, 0x00 }, /* 5 */
189 { 0x38, 0x0C, 0x06, 0x3E, 0x66, 0x66, 0x3C, 0x00 }, /* 6 */
190 { 0x7E, 0x60, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x00 }, /* 7 */
191 { 0x3C, 0x66, 0x66, 0x3C, 0x66, 0x66, 0x3C, 0x00 }, /* 8 */
192 { 0x3C, 0x66, 0x66, 0x7C, 0x60, 0x30, 0x1C, 0x00 }, /* 9 */
193 { 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00 }, /* : */
194 { 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x0C }, /* ; */
195 { 0x30, 0x18, 0x0C, 0x06, 0x0C, 0x18, 0x30, 0x00 }, /* < */
196 { 0x00, 0x00, 0x7E, 0x00, 0x7E, 0x00, 0x00, 0x00 }, /* = */
197 { 0x0C, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0C, 0x00 }, /* > */
198 { 0x3C, 0x66, 0x30, 0x18, 0x18, 0x00, 0x18, 0x00 }, /* ? */
199 { 0x3C, 0x66, 0x76, 0x56, 0x76, 0x06, 0x3C, 0x00 }, /* @ */
200 { 0x3C, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66, 0x00 }, /* A */
201 { 0x3E, 0x66, 0x66, 0x3E, 0x66, 0x66, 0x3E, 0x00 }, /* B */
202 { 0x3C, 0x66, 0x06, 0x06, 0x06, 0x66, 0x3C, 0x00 }, /* C */
203 { 0x1E, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1E, 0x00 }, /* D */
204 { 0x7E, 0x06, 0x06, 0x3E, 0x06, 0x06, 0x7E, 0x00 }, /* E */
205 { 0x7E, 0x06, 0x06, 0x3E, 0x06, 0x06, 0x06, 0x00 }, /* F */
206 { 0x3C, 0x66, 0x06, 0x76, 0x66, 0x66, 0x3C, 0x00 }, /* G */
207 { 0x66, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66, 0x00 }, /* H */
208 { 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x00 }, /* I */
209 { 0x7C, 0x30, 0x30, 0x30, 0x30, 0x36, 0x1C, 0x00 }, /* J */
210 { 0x66, 0x36, 0x1E, 0x0E, 0x1E, 0x36, 0x66, 0x00 }, /* K */
211 { 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x7E, 0x00 }, /* L */
212 { 0xC6, 0xEE, 0xFE, 0xD6, 0xD6, 0xC6, 0xC6, 0x00 }, /* M */
213 { 0x66, 0x66, 0x6E, 0x7E, 0x76, 0x66, 0x66, 0x00 }, /* N */
214 { 0x3C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00 }, /* O */
215 { 0x3E, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x06, 0x00 }, /* P */
216 { 0x3C, 0x66, 0x66, 0x66, 0x56, 0x36, 0x6C, 0x00 }, /* Q */
217 { 0x3E, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x66, 0x00 }, /* R */
218 { 0x3C, 0x66, 0x06, 0x3C, 0x60, 0x66, 0x3C, 0x00 }, /* S */
219 { 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00 }, /* T */
220 { 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00 }, /* U */
221 { 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x00 }, /* V */
222 { 0xC6, 0xC6, 0xD6, 0xD6, 0xFE, 0xEE, 0xC6, 0x00 }, /* W */
223 { 0x66, 0x66, 0x3C, 0x18, 0x3C, 0x66, 0x66, 0x00 }, /* X */
224 { 0x66, 0x66, 0x66, 0x3C, 0x18, 0x18, 0x18, 0x00 }, /* Y */
225 { 0x7E, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x7E, 0x00 }, /* Z */
226 { 0x3E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x3E, 0x00 }, /* [ */
227 { 0x00, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x00, 0x00 }, /* \ */
228 { 0x7C, 0x60, 0x60, 0x60, 0x60, 0x60, 0x7C, 0x00 }, /* ] */
229 { 0x3C, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* ^ */
230 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF }, /* _ */
231 { 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* ` */
232 { 0x00, 0x00, 0x3C, 0x60, 0x7C, 0x66, 0x7C, 0x00 }, /* a */
233 { 0x06, 0x06, 0x3E, 0x66, 0x66, 0x66, 0x3E, 0x00 }, /* b */
234 { 0x00, 0x00, 0x3C, 0x66, 0x06, 0x66, 0x3C, 0x00 }, /* c */
235 { 0x60, 0x60, 0x7C, 0x66, 0x66, 0x66, 0x7C, 0x00 }, /* d */
236 { 0x00, 0x00, 0x3C, 0x66, 0x7E, 0x06, 0x3C, 0x00 }, /* e */
237 { 0x38, 0x0C, 0x0C, 0x3E, 0x0C, 0x0C, 0x0C, 0x00 }, /* f */
238 { 0x00, 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x60, 0x3C }, /* g */
239 { 0x06, 0x06, 0x3E, 0x66, 0x66, 0x66, 0x66, 0x00 }, /* h */
240 { 0x18, 0x00, 0x1C, 0x18, 0x18, 0x18, 0x3C, 0x00 }, /* i */
241 { 0x18, 0x00, 0x1C, 0x18, 0x18, 0x18, 0x18, 0x0E }, /* j */
242 { 0x06, 0x06, 0x66, 0x36, 0x1E, 0x36, 0x66, 0x00 }, /* k */
243 { 0x1C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00 }, /* l */
244 { 0x00, 0x00, 0x6C, 0xFE, 0xD6, 0xD6, 0xC6, 0x00 }, /* m */
245 { 0x00, 0x00, 0x3E, 0x66, 0x66, 0x66, 0x66, 0x00 }, /* n */
246 { 0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x00 }, /* o */
247 { 0x00, 0x00, 0x3E, 0x66, 0x66, 0x3E, 0x06, 0x06 }, /* p */
248 { 0x00, 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x60, 0xE0 }, /* q */
249 { 0x00, 0x00, 0x36, 0x6E, 0x06, 0x06, 0x06, 0x00 }, /* r */
250 { 0x00, 0x00, 0x7C, 0x06, 0x3C, 0x60, 0x3E, 0x00 }, /* s */
251 { 0x0C, 0x0C, 0x3E, 0x0C, 0x0C, 0x0C, 0x38, 0x00 }, /* t */
252 { 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x7C, 0x00 }, /* u */
253 { 0x00, 0x00, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x00 }, /* v */
254 { 0x00, 0x00, 0xC6, 0xD6, 0xD6, 0xFE, 0x6C, 0x00 }, /* w */
255 { 0x00, 0x00, 0x66, 0x3C, 0x18, 0x3C, 0x66, 0x00 }, /* x */
256 { 0x00, 0x00, 0x66, 0x66, 0x66, 0x7C, 0x60, 0x3C }, /* y */
257 { 0x00, 0x00, 0x7E, 0x30, 0x18, 0x0C, 0x7E, 0x00 }, /* z */
258 { 0x30, 0x18, 0x18, 0x0E, 0x18, 0x18, 0x30, 0x00 }, /* { */
259 { 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00 }, /* | */
260 { 0x0C, 0x18, 0x18, 0x70, 0x18, 0x18, 0x0C, 0x00 }, /* } */
261 { 0x8C, 0xD6, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00 } /* ~ */
262 };
263
264 #define LCD_WIDTH 320
265 #define LCD_HEIGHT 240
266 #define LCD_DEPTH 16
267
268 // This can be 1 or 2
269 #define SCREEN_SCALE 2
270 #define NIBBLES_PER_PIXEL (1*SCREEN_SCALE)
271 #define PIXELS_PER_BYTE (2/NIBBLES_PER_PIXEL)
272 #define PIXEL_MASK ((1<<PIXELS_PER_BYTE)-1)
273
274 // Physical screen info
275 static int lcd_depth = LCD_DEPTH; // Should be 1, 2, or 4
276 static int lcd_width = LCD_WIDTH;
277 static int lcd_height = LCD_HEIGHT;
278
279 // Virtual screen info
280 static int curX = 0; // Last used position
281 static int curY = 0;
282 static int width = LCD_WIDTH / (FONT_WIDTH*NIBBLES_PER_PIXEL);
283 static int height = LCD_HEIGHT / (FONT_HEIGHT*SCREEN_SCALE);
284 static int fg = RGB_RED(0) | RGB_GREEN(0) | RGB_BLUE(0);
285 static int bg = RGB_RED(31) | RGB_GREEN(63) | RGB_BLUE(31);
286 #define SCREEN_WIDTH (LCD_WIDTH/FONT_WIDTH)
287 #define SCREEN_HEIGHT (LCD_HEIGHT/FONT_HEIGHT)
288 static char screen[SCREEN_HEIGHT][SCREEN_WIDTH];
289
290 // Functions
291 static void lcd_drawc(cyg_int8 c, int x, int y);
292
293 void
294 lcd_init(int depth)
295 {
296 // Currently only color/16bpp supported
297
166 unsigned long _fp; 298 unsigned long _fp;
167 int on;
168
169 diag_printf("LCD test here\n");
170
171 // HAL_DCACHE_SYNC();
172 // HAL_DCACHE_DISABLE();
173 299
174 // Frame buffer must be aligned on a 16 byte boundary 300 // Frame buffer must be aligned on a 16 byte boundary
175 _fp = (((unsigned long)&lcd_frame_buffer) + 15) & ~15; 301 _fp = (((unsigned long)&lcd_frame_buffer) + 15) & ~15;
176 fp = (struct lcd_frame *)(_fp + SA11X0_RAM_BANK0_BASE); 302 fp = (struct lcd_frame *)(_fp + SA11X0_RAM_BANK0_BASE);
177 // Enable LCD in 320x240 16bpp 303 // Enable LCD in 320x240 16bpp
178 *SA1110_DBAR1 = (unsigned long)&(fp->palette); 304 *SA1110_DBAR1 = (unsigned long)&(fp->palette);
179 *SA1110_LCCR1 = 0x1D1D0930; 305 *SA1110_LCCR1 = 0x1D1D0930;
180 *SA1110_LCCR2 = 0xEF; 306 *SA1110_LCCR2 = 0xEF;
181 *SA1110_LCCR3 = 0x0c; 307 *SA1110_LCCR3 = 0x0c;
182 fp->palette[0] = 0x2000; // Tell controller 16 bits 308 fp->palette[0] = 0x2000; // Tell controller 16 bits
183 *SA1110_LCCR0 = 0xBB; // B&W 309 // *SA1110_LCCR0 = 0xBB; // B&W
184 *SA1110_LCCR0 = 0xB9; // Color 310 *SA1110_LCCR0 = 0xB9; // Color
185 assabet_BCR(SA1110_BCR_LCD_BPP, SA1110_BCR_LCD_12BPP); 311 // assabet_BCR(SA1110_BCR_LCD_BPP, SA1110_BCR_LCD_12BPP);
186 assabet_BCR(SA1110_BCR_LCD_BPP, SA1110_BCR_LCD_16BPP); 312 assabet_BCR(SA1110_BCR_LCD_BPP, SA1110_BCR_LCD_16BPP);
187 assabet_BCR(SA1110_BCR_LCD, SA1110_BCR_LCD_ON); 313 assabet_BCR(SA1110_BCR_LCD, SA1110_BCR_LCD_ON);
314 assabet_BCR(SA1110_BCR_BACKLIGHT, SA1110_BCR_BACKLIGHT);
315 }
316
317 // Clear screen
318 void
319 lcd_clear(void)
320 {
321 int row, col;
322 for (row = 0; row < lcd_height; row++) {
323 for (col = 0; col < lcd_width; col++) {
324 fp->pixels[row][col] = bg;
325 }
326 }
327 for (row = 0; row < SCREEN_HEIGHT; row++) {
328 for (col = 0; col < SCREEN_WIDTH; col++) {
329 screen[row][col] = ' ';
330 }
331 }
332 // Note: Row 0 seems to wrap incorrectly
333 curX = 0; curY = 1;
334 lcd_drawc(CURSOR_ON, curX, curY);
335 }
336
337 // Position cursor
338 void
339 lcd_moveto(int X, int Y)
340 {
341 lcd_drawc(CURSOR_OFF, curX, curY);
342 if (X < 0) X = 0;
343 if (X >= SCREEN_WIDTH) X = SCREEN_WIDTH-1;
344 curX = X;
345 // if (Y < 0) Y = 0;
346 if (Y < 1) Y = 1;
347 if (Y >= SCREEN_HEIGHT) Y = SCREEN_HEIGHT-1;
348 curY = Y;
349 lcd_drawc(CURSOR_ON, curX, curY);
350 }
351
352 // Render a character at position (X,Y) with current background/foreground
353 static void
354 lcd_drawc(cyg_int8 c, int x, int y)
355 {
356 // Currently hard-coded for 16bpp
357 cyg_uint8 bits;
358 cyg_uint16 *pixels;
359 int l, p, w;
360
361 screen[curY][curX] = c;
362 for (l = 0; l < FONT_HEIGHT; l++) {
363 bits = font_table[c-FIRST_CHAR][l];
364 pixels = &fp->pixels[curY*FONT_HEIGHT+l][curX*FONT_WIDTH];
365 for (p = 0; p < 8; p++) {
366 if (bits & 0x01) {
367 *pixels++ = fg;
368 } else {
369 *pixels++ = bg;
370 }
371 bits >>= 1;
372 }
373 }
374 }
375
376 static void
377 lcd_scroll(void)
378 {
379 int row, col;
380 cyg_uint8 *c1, *c2;
381 cyg_uint16 *p1, *p2;
382
383 // First scroll up the virtual screen
384 for (row = 1; row < SCREEN_HEIGHT; row++) {
385 c1 = &screen[row-1][0];
386 c2 = &screen[row][0];
387 for (col = 0; col < SCREEN_WIDTH; col++) {
388 *c1++ = *c2++;
389 }
390 }
391 c1 = &screen[SCREEN_HEIGHT-1][0];
392 for (col = 0; col < SCREEN_WIDTH; col++) {
393 *c1++ = 0x20;
394 }
395 // Now the physical screen
396 for (row = FONT_HEIGHT*2; row < LCD_HEIGHT; row++) {
397 p1 = &fp->pixels[row-FONT_HEIGHT][0];
398 p2 = &fp->pixels[row][0];
399 for (col = 0; col < LCD_WIDTH; col++) {
400 *p1++ = *p2++;
401 }
402 }
403 for (row = LCD_HEIGHT-FONT_HEIGHT; row < LCD_HEIGHT; row++) {
404 p1 = &fp->pixels[row][0];
405 for (col = 0; col < LCD_WIDTH; col++) {
406 *p1++ = bg;
407 }
408 }
409 }
410
411 // Draw one character at the current position
412 void
413 lcd_putc(cyg_int8 c)
414 {
415 lcd_drawc(CURSOR_OFF, curX, curY);
416 switch (c) {
417 case '\r':
418 curX = 0;
419 break;
420 case '\n':
421 curY++;
422 if (curY == SCREEN_HEIGHT) {
423 lcd_scroll();
424 curY--;
425 }
426 break;
427 case '\b':
428 curX--;
429 if (curX < 0) {
430 curY--;
431 if (curY < 0) curY = 0;
432 curX = SCREEN_WIDTH-1;
433 }
434 break;
435 default:
436 lcd_drawc(c, curX, curY);
437 curX++;
438 if (curX == SCREEN_WIDTH) {
439 curY++;
440 curX = 0;
441 }
442 }
443 lcd_drawc(CURSOR_ON, curX, curY);
444 }
445
446 // Basic LCD 'printf()' support
447
448 #ifndef FALSE
449 #define FALSE 0
450 #define TRUE 1
451 #endif
452
453 #include <stdarg.h>
454
455 #define is_digit(c) ((c >= '0') && (c <= '9'))
456
457 static int
458 _cvt(unsigned long val, char *buf, long radix, char *digits)
459 {
460 char temp[80];
461 char *cp = temp;
462 int length = 0;
463 if (val == 0) {
464 /* Special case */
465 *cp++ = '0';
466 } else {
467 while (val) {
468 *cp++ = digits[val % radix];
469 val /= radix;
470 }
471 }
472 while (cp != temp) {
473 *buf++ = *--cp;
474 length++;
475 }
476 *buf = '\0';
477 return (length);
478 }
479
480 int
481 lcd_vprintf(void (*putc)(cyg_int8), const char *fmt0, va_list ap)
482 {
483 char c, sign, *cp;
484 int left_prec, right_prec, zero_fill, length, pad, pad_on_right;
485 char buf[32];
486 long val;
487 while ((c = *fmt0++)) {
488 cp = buf;
489 length = 0;
490 if (c == '%') {
491 c = *fmt0++;
492 left_prec = right_prec = pad_on_right = 0;
493 if (c == '-') {
494 c = *fmt0++;
495 pad_on_right++;
496 }
497 if (c == '0') {
498 zero_fill = TRUE;
499 c = *fmt0++;
500 } else {
501 zero_fill = FALSE;
502 }
503 while (is_digit(c)) {
504 left_prec = (left_prec * 10) + (c - '0');
505 c = *fmt0++;
506 }
507 if (c == '.') {
508 c = *fmt0++;
509 zero_fill++;
510 while (is_digit(c)) {
511 right_prec = (right_prec * 10) + (c - '0');
512 c = *fmt0++;
513 }
514 } else {
515 right_prec = left_prec;
516 }
517 sign = '\0';
518 switch (c) {
519 case 'd':
520 case 'x':
521 case 'X':
522 val = va_arg(ap, long);
523 switch (c) {
524 case 'd':
525 if (val < 0) {
526 sign = '-';
527 val = -val;
528 }
529 length = _cvt(val, buf, 10, "0123456789");
530 break;
531 case 'x':
532 length = _cvt(val, buf, 16, "0123456789abcdef");
533 break;
534 case 'X':
535 length = _cvt(val, buf, 16, "0123456789ABCDEF");
536 break;
537 }
538 break;
539 case 's':
540 cp = va_arg(ap, char *);
541 length = strlen(cp);
542 break;
543 case 'c':
544 c = va_arg(ap, long /*char*/);
545 (*putc)(c);
546 continue;
547 default:
548 (*putc)('?');
549 }
550 pad = left_prec - length;
551 if (sign != '\0') {
552 pad--;
553 }
554 if (zero_fill) {
555 c = '0';
556 if (sign != '\0') {
557 (*putc)(sign);
558 sign = '\0';
559 }
560 } else {
561 c = ' ';
562 }
563 if (!pad_on_right) {
564 while (pad-- > 0) {
565 (*putc)(c);
566 }
567 }
568 if (sign != '\0') {
569 (*putc)(sign);
570 }
571 while (length-- > 0) {
572 (*putc)(c = *cp++);
573 if (c == '\n') {
574 (*putc)('\r');
575 }
576 }
577 if (pad_on_right) {
578 while (pad-- > 0) {
579 (*putc)(' ');
580 }
581 }
582 } else {
583 (*putc)(c);
584 if (c == '\n') {
585 (*putc)('\r');
586 }
587 }
588 }
589 }
590
591 int
592 lcd_printf(char const *fmt, ...)
593 {
594 int ret;
595 va_list ap;
596
597 va_start(ap, fmt);
598 ret = lcd_vprintf(lcd_putc, fmt, ap);
599 va_end(ap);
600 return (ret);
601 }
602
603 static void
604 lcd_test(cyg_addrword_t p)
605 {
606 int i, pix, row, col;
607 int on;
608
609 diag_printf("LCD test here\n");
610
611 lcd_init(16);
188 #if 0 612 #if 0
189 for (i = 0; i < 16; i++) { 613 for (i = 0; i < 16; i++) {
190 on = true; 614 on = true;
191 diag_printf("Fill with 0x%x\n", i); 615 diag_printf("Fill with 0x%x\n", i);
192 for (row = 0; row < 240; row++) { 616 for (row = 0; row < 240; row++) {
295 } 719 }
296 } 720 }
297 #endif 721 #endif
298 } 722 }
299 #endif 723 #endif
300 #if 1 724 #if 0
301 for (row = 0; row < 240; row++) { 725 for (row = 0; row < 240; row++) {
302 for (col = 0; col < 320; col++) { 726 for (col = 0; col < 320; col++) {
303 if (col == 59) { 727 if (col == 59) {
304 fp->pixels[row][col] = 0x0000; 728 fp->pixels[row][col] = 0x0000;
305 } else { 729 } else {
307 } 731 }
308 } 732 }
309 } 733 }
310 cyg_thread_delay(100); 734 cyg_thread_delay(100);
311 #endif 735 #endif
312 736 #if 0
313 for (i = 0; i < 5; i++) { 737 for (i = 0; i < 16; i++) {
314 show_xpm(eCos_xpm); 738 diag_printf("Value 0x%04x\n", (1<<i));
315 show_xpm(redhat_xpm); 739 for (row = 0; row < 240; row++) {
316 show_xpm(escw_xpm); 740 for (col = 0; col < 320; col++) {
317 } 741 fp->pixels[row][col] = (1<<i);
318 742 }
743 }
744 cyg_thread_delay(500);
745 }
746 #endif
747 #if 0
748 for (i = 0; i < 32; i++) {
749 diag_printf("Red at %d\n", i);
750 for (row = 0; row < 240; row++) {
751 for (col = 0; col < 320; col++) {
752 fp->pixels[row][col] = RGB_RED(i);
753 }
754 }
755 cyg_thread_delay(100);
756 }
757 #endif
758 #if 0
759 for (i = 0; i < 64; i++) {
760 diag_printf("Green at %d\n", i);
761 for (row = 0; row < 240; row++) {
762 for (col = 0; col < 320; col++) {
763 fp->pixels[row][col] = RGB_GREEN(i);
764 }
765 }
766 cyg_thread_delay(100);
767 }
768 #endif
769 #if 0
770 for (i = 0; i < 32; i++) {
771 diag_printf("BLUE at %d\n", i);
772 for (row = 0; row < 240; row++) {
773 for (col = 0; col < 320; col++) {
774 fp->pixels[row][col] = RGB_BLUE(i);
775 }
776 }
777 cyg_thread_delay(100);
778 }
779 #endif
780
781 for (i = 0; i < 1; i++) {
782 show_xpm(eCos_xpm);
783 show_xpm(redhat_xpm);
784 show_xpm(redboot_xpm);
785 show_xpm(escw_xpm);
786 }
787
788 #if 0
789 // This doesn't seem to do anything on my unit
319 assabet_BCR(SA1110_BCR_MOTOR, SA1110_BCR_MOTOR_ON); 790 assabet_BCR(SA1110_BCR_MOTOR, SA1110_BCR_MOTOR_ON);
320 cyg_thread_delay(2*100); 791 cyg_thread_delay(2*100);
321 assabet_BCR(SA1110_BCR_MOTOR, SA1110_BCR_MOTOR_OFF); 792 assabet_BCR(SA1110_BCR_MOTOR, SA1110_BCR_MOTOR_OFF);
793 #endif
794
795 lcd_clear();
796 lcd_printf("\n\n**** Hello world!\n");
797 cyg_thread_delay(200);
798 for (i = 0; i < 132; i++) {
799 lcd_printf("... testing line #%d\n", i);
800 }
801 cyg_thread_delay(200);
802 bg = RGB_RED(0) | RGB_GREEN(0) | RGB_BLUE(0);
803 fg = RGB_RED(31) | RGB_GREEN(63) | RGB_BLUE(0);
804 for (i = 0; i < 132; i++) {
805 lcd_printf("... testing line #%d\n", i);
806 }
807 cyg_thread_delay(200);
808 lcd_clear();
809 lcd_printf("*****");
810 cyg_thread_delay(200);
811
322 cyg_test_exit(); 812 cyg_test_exit();
323 } 813 }
324 814
325 externC void 815 externC void
326 cyg_start( void ) 816 cyg_start( void )