OSDN Git Service

Added progress bar drawing feature.
[kozos-expbrd/kozos_expbrd.git] / firm / sample / sample1 / os / task_display.c
1 #include "task_display.h"
2 #include "sg12232c.h"
3 #include "kozos.h"
4 #include "lib.h"
5 #include "led.h"
6
7 #define DISPLAY_CMD_LCD_CLEAR       'c' /* LCD\e$B$N>C5n\e(B */
8 #define DISPLAY_CMD_LCD_DRAW_BOX    'b' /* BOX\e$BIA2h%3%^%s%I\e(B */
9 #define DISPLAY_CMD_LCD_DRAW_LOGO   'l' /* LOGO\e$BIA2h%3%^%s%I\e(B */
10 #define DISPLAY_CMD_LCD_DRAW_TEXT   't' /* TEXT\e$BIA2h%3%^%s%I\e(B */
11 #define DISPLAY_CMD_LCD_DRAW_PBAR   'p' /* PBAR\e$BIA2h%3%^%s%I\e(B */
12 #define DISPLAY_CMD_LED_ON          '1' /* LED\e$B$NE@Et\e(B */
13 #define DISPLAY_CMD_LED_OFF         '0' /* LED\e$B$N>CEt\e(B */
14 #define DISPLAY_CMD_LED_TOGGLE      'a' /* LED\e$B$N%H%0%k\e(B */
15
16 void display_led_write(int target, int state)
17 {
18   char *p;
19   p = kz_kmalloc(2);
20   p[0] = state ? DISPLAY_CMD_LED_ON : DISPLAY_CMD_LED_OFF;
21   p[1] = '0' + target;
22   kz_send(MSGBOX_ID_DISPLAY, 2, p);
23 }
24
25 void display_led_toggle(int target)
26 {
27   char *p;
28   p = kz_kmalloc(2);
29   p[0] = DISPLAY_CMD_LED_TOGGLE;
30   p[1] = '0' + target;
31   kz_send(MSGBOX_ID_DISPLAY, 2, p);
32 }
33
34 void display_clear(void)
35 {
36   char *p;
37   p = kz_kmalloc(1);
38   p[0] = DISPLAY_CMD_LCD_CLEAR;
39   kz_send(MSGBOX_ID_DISPLAY, 1, p);
40 }
41
42 void display_draw_box(int x1, int y1, int x2, int y2, int on)
43 {
44   char *p;
45   p = kz_kmalloc(6);
46   p[0] = DISPLAY_CMD_LCD_DRAW_BOX;
47   p[1] = x1;
48   p[2] = y1;
49   p[3] = x2;
50   p[4] = y2;
51   p[5] = !on;
52   kz_send(MSGBOX_ID_DISPLAY, 6, p);
53 }
54
55 void display_draw_logo(int x, int y, int size)
56 {
57   char *p;
58   p = kz_kmalloc(4);
59   p[0] = DISPLAY_CMD_LCD_DRAW_LOGO;
60   p[1] = x;
61   p[2] = y;
62   p[3] = size;
63   kz_send(MSGBOX_ID_DISPLAY, 4, p);
64 }
65
66 void display_draw_text(int x, int y, char *str)
67 {
68   char *p;
69   int len;
70   len = strlen(str);
71   p = kz_kmalloc(3 + len + 1);
72   p[0] = DISPLAY_CMD_LCD_DRAW_TEXT;
73   p[1] = x;
74   p[2] = y;
75   memcpy(&p[3], str, len);
76   p[3 + len] = '\0';
77   kz_send(MSGBOX_ID_DISPLAY, 3 + len + 1, p);
78 }
79
80 void display_draw_progressbar(
81         int x1, int y1, int x2, int y2,
82         int min, int max, int value)
83 {
84   char *p;
85   p = kz_kmalloc(8);
86   p[0] = DISPLAY_CMD_LCD_DRAW_PBAR;
87   p[1] = x1;
88   p[2] = y1;
89   p[3] = x2;
90   p[4] = y2;
91   p[5] = min;
92   p[6] = max;
93   p[7] = value;
94   kz_send(MSGBOX_ID_DISPLAY, 8, p);
95 }
96
97 static void draw_logo(const int ofsx, const int ofsy, const int size)
98 {
99   static const uint8 logo_40x32[] = {
100       0x00,0x00,0x00,0x00,0x00,
101       0x00,0x00,0x00,0x00,0x00,
102       0x00,0x1f,0xfc,0x00,0x00,
103       0x00,0x1f,0xff,0xc0,0x00,
104       0x00,0x1f,0xff,0xf0,0x00,
105       0x00,0x0f,0x7f,0xfc,0x00,
106       0x00,0x0f,0x7f,0xff,0x00,
107       0x00,0x0f,0x7f,0xff,0xc0,
108       0x00,0x0f,0x7f,0xff,0xe0,
109       0x00,0x07,0x3f,0xff,0xf0,
110       0x00,0x07,0x9f,0xff,0xfc,
111       0x00,0x07,0xc1,0xff,0xfe,
112       0x3f,0xff,0xff,0xff,0xff,
113       0x3f,0xff,0xff,0xff,0xff,
114       0x1f,0xff,0xff,0xff,0xff,
115       0x1f,0xff,0xff,0xff,0xff,
116       0x1f,0xff,0xfc,0xff,0xff,
117       0x1f,0xff,0xf0,0x3f,0xff,
118       0x1f,0xff,0xf0,0x07,0xff,
119       0x1f,0xff,0xe0,0x41,0xff,
120       0x0f,0xff,0xe0,0x21,0xff,
121       0x0f,0xff,0xe2,0x13,0xff,
122       0x07,0xff,0xf1,0x07,0xff,
123       0x07,0xff,0xf8,0x8f,0xff,
124       0x03,0xff,0xf8,0x1f,0xff,
125       0x03,0xff,0xfc,0x3f,0xff,
126       0x01,0xff,0xfc,0x7f,0xff,
127       0x00,0xff,0xfe,0xff,0xff,
128       0x00,0xff,0xff,0xff,0xff,
129       0x00,0x7f,0xff,0xff,0xff,
130       0x00,0x3f,0xff,0xff,0xff,
131       0x00,0x1f,0xff,0xff,0xff,
132   };
133   static const uint8 logo_30x24[] = {
134       0x00,0x00,0x00,0x00,
135       0x00,0xfe,0x00,0x00,
136       0x00,0xff,0xe0,0x00,
137       0x00,0x7f,0xf8,0x00,
138       0x00,0x77,0xff,0x00,
139       0x00,0x77,0xff,0x80,
140       0x00,0x77,0xff,0xe0,
141       0x00,0x73,0xff,0xf0,
142       0x00,0x38,0x7f,0xf8,
143       0x3f,0xff,0xff,0xfc,
144       0x3f,0xff,0xff,0xfc,
145       0x3f,0xff,0xff,0xfc,
146       0x3f,0xff,0x1f,0xfc,
147       0x3f,0xfe,0x07,0xfc,
148       0x1f,0xfe,0x23,0xfc,
149       0x1f,0xfc,0x11,0xfc,
150       0x1f,0xfe,0x8b,0xfc,
151       0x0f,0xfe,0x47,0xfc,
152       0x0f,0xff,0x2f,0xfc,
153       0x07,0xff,0x1f,0xfc,
154       0x03,0xff,0xbf,0xfc,
155       0x03,0xff,0xff,0xfc,
156       0x01,0xff,0xff,0xfc,
157       0x00,0xff,0xff,0xfc,
158   };
159   static const uint8 logo_20x16[] = {
160       0x00,0x00,0x00,
161       0x03,0xf0,0x00,
162       0x03,0xfe,0x00,
163       0x03,0x7f,0x00,
164       0x03,0x7f,0xc0,
165       0x03,0x8f,0xe0,
166       0x7f,0xff,0xf0,
167       0x7f,0xff,0xf0,
168       0x7f,0xc7,0xf0,
169       0x3f,0x89,0xf0,
170       0x3f,0xa5,0xf0,
171       0x3f,0x93,0xf0,
172       0x1f,0xc7,0xf0,
173       0x0f,0xef,0xf0,
174       0x0f,0xff,0xf0,
175       0x07,0xff,0xf0,
176   };
177   int x, y;
178   uint8 c = 0;
179   switch (size) {
180     case 0:
181       for (y = 0; y < 16; y++) {
182         for (x = 0; x < 20; x++) {
183           if ((x % 8) == 0) {
184             c = logo_20x16[(y * 3) + (x / 8)];
185           }
186           int pix = (c & (1 << (7 - (x % 8)))) ? 1 : 0;
187           sg12232c_set_pixel(ofsx + x, ofsy + y, pix);
188         }
189       }
190       break;
191     case 1:
192       for (y = 0; y < 24; y++) {
193         for (x = 0; x < 30; x++) {
194           if ((x % 8) == 0) {
195             c = logo_30x24[(y * 4) + (x / 8)];
196           }
197           int pix = (c & (1 << (7 - (x % 8)))) ? 1 : 0;
198           sg12232c_set_pixel(ofsx + x, ofsy + y, pix);
199         }
200       }
201       break;
202     case 2:
203       for (y = 0; y < 32; y++) {
204         for (x = 0; x < 40; x++) {
205           if ((x % 8) == 0) {
206             c = logo_40x32[(y * 5) + (x / 8)];
207           }
208           int pix = (c & (1 << (7 - (x % 8)))) ? 1 : 0;
209           sg12232c_set_pixel(ofsx + x, ofsy + y, pix);
210         }
211       }
212       break;
213   }
214 }
215
216 /* \e$B%9%l%C%I$+$i$NMW5a$r=hM}$9$k\e(B */
217 static int display_cmdproc(char *p)
218 {
219   int cmd = p[0];
220   switch (cmd) {
221   case DISPLAY_CMD_LCD_CLEAR:
222     sg12232c_clear();
223     break;
224   case DISPLAY_CMD_LCD_DRAW_BOX:
225     sg12232c_draw_box(p[1], p[2], p[3], p[4], p[5]);
226     break;
227   case DISPLAY_CMD_LCD_DRAW_LOGO:
228     draw_logo(p[1], p[2], p[3]);
229     break;
230   case DISPLAY_CMD_LCD_DRAW_TEXT:
231     sg12232c_draw_string(p[1], p[2], &p[3], 0);
232     break;
233   case DISPLAY_CMD_LCD_DRAW_PBAR:
234     sg12232c_draw_progressbar(
235             p[1], p[2], p[3], p[4], p[5], p[6], p[7], 0);
236     break;
237   case DISPLAY_CMD_LED_ON:
238     led_write(p[1] - '0', LedOn);
239     break;
240   case DISPLAY_CMD_LED_OFF:
241     led_write(p[1] - '0', LedOff);
242     break;
243   case DISPLAY_CMD_LED_TOGGLE:
244     led_toggle(p[1] - '0');
245     break;
246   default:
247     break;
248   }
249   kz_kmfree(p);
250
251   return 0;
252 }
253
254 int task_display(int argc, char *argv[])
255 {
256   int size;
257   char *p;
258
259   while (1) {
260     kz_recv(MSGBOX_ID_DISPLAY, &size, &p);
261     display_cmdproc(p);
262   }
263
264   return 0;
265 }
266