OSDN Git Service

Moved some unused codes.
[kozos-expbrd/kozos_expbrd.git] / misc / hwtest / 10 / os / driver / driver_lcd.c
1 #include "driver_lcd.h"
2 #include "sg12232c.h"
3 #include "kozos.h"
4 #include "lib.h"
5
6 #define LCDDRV_CMD_LCD_CLEAR        'c' /* LCD\e$B$N>C5n\e(B */
7 #define LCDDRV_CMD_LCD_DRAW_BOX     'b' /* BOX\e$BIA2h%3%^%s%I\e(B */
8 #define LCDDRV_CMD_LCD_DRAW_LOGO    'l' /* LOGO\e$BIA2h%3%^%s%I\e(B */
9 #define LCDDRV_CMD_LCD_DRAW_TEXT    't' /* TEXT\e$BIA2h%3%^%s%I\e(B */
10
11 void lcddrv_clear(void)
12 {
13   char *p;
14   p = kz_kmalloc(1);
15   p[0] = LCDDRV_CMD_LCD_CLEAR;
16   kz_send(MSGBOX_ID_LCDDRIVE, 1, p);
17 }
18
19 void lcddrv_draw_box(int x1, int y1, int x2, int y2, int on)
20 {
21   char *p;
22   p = kz_kmalloc(6);
23   p[0] = LCDDRV_CMD_LCD_DRAW_BOX;
24   p[1] = x1;
25   p[2] = y1;
26   p[3] = x2;
27   p[4] = y2;
28   p[5] = !on;
29   kz_send(MSGBOX_ID_LCDDRIVE, 6, p);
30 }
31
32 void lcddrv_draw_logo(int x, int y, int size)
33 {
34   char *p;
35   p = kz_kmalloc(4);
36   p[0] = LCDDRV_CMD_LCD_DRAW_LOGO;
37   p[1] = x;
38   p[2] = y;
39   p[3] = size;
40   kz_send(MSGBOX_ID_LCDDRIVE, 4, p);
41 }
42
43 void lcddrv_draw_text(int x, int y, char *str)
44 {
45   char *p;
46   int len;
47   len = strlen(str);
48   p = kz_kmalloc(3 + len + 1);
49   p[0] = LCDDRV_CMD_LCD_DRAW_TEXT;
50   p[1] = x;
51   p[2] = y;
52   memcpy(&p[3], str, len);
53   p[3 + len] = '\0';
54   kz_send(MSGBOX_ID_LCDDRIVE, 3 + len + 1, p);
55 }
56
57 static void draw_logo(const int ofsx, const int ofsy, const int size)
58 {
59   static const uint8 logo_40x32[] = {
60       0x00,0x00,0x00,0x00,0x00,
61       0x00,0x00,0x00,0x00,0x00,
62       0x00,0x1f,0xfc,0x00,0x00,
63       0x00,0x1f,0xff,0xc0,0x00,
64       0x00,0x1f,0xff,0xf0,0x00,
65       0x00,0x0f,0x7f,0xfc,0x00,
66       0x00,0x0f,0x7f,0xff,0x00,
67       0x00,0x0f,0x7f,0xff,0xc0,
68       0x00,0x0f,0x7f,0xff,0xe0,
69       0x00,0x07,0x3f,0xff,0xf0,
70       0x00,0x07,0x9f,0xff,0xfc,
71       0x00,0x07,0xc1,0xff,0xfe,
72       0x3f,0xff,0xff,0xff,0xff,
73       0x3f,0xff,0xff,0xff,0xff,
74       0x1f,0xff,0xff,0xff,0xff,
75       0x1f,0xff,0xff,0xff,0xff,
76       0x1f,0xff,0xfc,0xff,0xff,
77       0x1f,0xff,0xf0,0x3f,0xff,
78       0x1f,0xff,0xf0,0x07,0xff,
79       0x1f,0xff,0xe0,0x41,0xff,
80       0x0f,0xff,0xe0,0x21,0xff,
81       0x0f,0xff,0xe2,0x13,0xff,
82       0x07,0xff,0xf1,0x07,0xff,
83       0x07,0xff,0xf8,0x8f,0xff,
84       0x03,0xff,0xf8,0x1f,0xff,
85       0x03,0xff,0xfc,0x3f,0xff,
86       0x01,0xff,0xfc,0x7f,0xff,
87       0x00,0xff,0xfe,0xff,0xff,
88       0x00,0xff,0xff,0xff,0xff,
89       0x00,0x7f,0xff,0xff,0xff,
90       0x00,0x3f,0xff,0xff,0xff,
91       0x00,0x1f,0xff,0xff,0xff,
92   };
93   static const uint8 logo_30x24[] = {
94       0x00,0x00,0x00,0x00,
95       0x00,0xfe,0x00,0x00,
96       0x00,0xff,0xe0,0x00,
97       0x00,0x7f,0xf8,0x00,
98       0x00,0x77,0xff,0x00,
99       0x00,0x77,0xff,0x80,
100       0x00,0x77,0xff,0xe0,
101       0x00,0x73,0xff,0xf0,
102       0x00,0x38,0x7f,0xf8,
103       0x3f,0xff,0xff,0xfc,
104       0x3f,0xff,0xff,0xfc,
105       0x3f,0xff,0xff,0xfc,
106       0x3f,0xff,0x1f,0xfc,
107       0x3f,0xfe,0x07,0xfc,
108       0x1f,0xfe,0x23,0xfc,
109       0x1f,0xfc,0x11,0xfc,
110       0x1f,0xfe,0x8b,0xfc,
111       0x0f,0xfe,0x47,0xfc,
112       0x0f,0xff,0x2f,0xfc,
113       0x07,0xff,0x1f,0xfc,
114       0x03,0xff,0xbf,0xfc,
115       0x03,0xff,0xff,0xfc,
116       0x01,0xff,0xff,0xfc,
117       0x00,0xff,0xff,0xfc,
118   };
119   static const uint8 logo_20x16[] = {
120       0x00,0x00,0x00,
121       0x03,0xf0,0x00,
122       0x03,0xfe,0x00,
123       0x03,0x7f,0x00,
124       0x03,0x7f,0xc0,
125       0x03,0x8f,0xe0,
126       0x7f,0xff,0xf0,
127       0x7f,0xff,0xf0,
128       0x7f,0xc7,0xf0,
129       0x3f,0x89,0xf0,
130       0x3f,0xa5,0xf0,
131       0x3f,0x93,0xf0,
132       0x1f,0xc7,0xf0,
133       0x0f,0xef,0xf0,
134       0x0f,0xff,0xf0,
135       0x07,0xff,0xf0,
136   };
137   int x, y;
138   uint8 c = 0;
139   switch (size) {
140     case 0:
141       for (y = 0; y < 16; y++) {
142         for (x = 0; x < 20; x++) {
143           if ((x % 8) == 0) {
144             c = logo_20x16[(y * 3) + (x / 8)];
145           }
146           int pix = (c & (1 << (7 - (x % 8)))) ? 1 : 0;
147           sg12232c_set_pixel(ofsx + x, ofsy + y, pix);
148         }
149       }
150       break;
151     case 1:
152       for (y = 0; y < 24; y++) {
153         for (x = 0; x < 30; x++) {
154           if ((x % 8) == 0) {
155             c = logo_30x24[(y * 4) + (x / 8)];
156           }
157           int pix = (c & (1 << (7 - (x % 8)))) ? 1 : 0;
158           sg12232c_set_pixel(ofsx + x, ofsy + y, pix);
159         }
160       }
161       break;
162     case 2:
163       for (y = 0; y < 32; y++) {
164         for (x = 0; x < 40; x++) {
165           if ((x % 8) == 0) {
166             c = logo_40x32[(y * 5) + (x / 8)];
167           }
168           int pix = (c & (1 << (7 - (x % 8)))) ? 1 : 0;
169           sg12232c_set_pixel(ofsx + x, ofsy + y, pix);
170         }
171       }
172       break;
173   }
174 }
175
176 /* \e$B%9%l%C%I$+$i$NMW5a$r=hM}$9$k\e(B */
177 static int lcddrv_command(char *p)
178 {
179   int cmd = p[0];
180   switch (cmd) {
181   case LCDDRV_CMD_LCD_CLEAR:
182     sg12232c_clear();
183     break;
184   case LCDDRV_CMD_LCD_DRAW_BOX:
185     sg12232c_draw_box(p[1], p[2], p[3], p[4], p[5]);
186     break;
187   case LCDDRV_CMD_LCD_DRAW_LOGO:
188     draw_logo(p[1], p[2], p[3]);
189     break;
190   case LCDDRV_CMD_LCD_DRAW_TEXT:
191     sg12232c_draw_string(p[1], p[2], &p[3], 0);
192     break;
193   default:
194     break;
195   }
196   kz_kmfree(p);
197
198   return 0;
199 }
200
201 int driver_lcd(int argc, char *argv[])
202 {
203   int size;
204   char *p;
205
206   sg12232c_init();
207
208   while (1) {
209     kz_recv(MSGBOX_ID_LCDDRIVE, &size, &p);
210     lcddrv_command(p);
211   }
212
213   return 0;
214 }