Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | /***************************************************************************** |
2 | * Module for Microchip Graphics Library |
||
3 | * Solomon Systech SSD1339 OLED display controller driver |
||
4 | ***************************************************************************** |
||
5 | * FileName: SSD1339.c |
||
6 | * Dependencies: Graphics.h |
||
7 | * Processor: PIC24 |
||
8 | * Compiler: MPLAB C30 |
||
9 | * Linker: MPLAB LINK30 |
||
10 | * Company: Microchip Technology Incorporated |
||
11 | * |
||
12 | * Software License Agreement |
||
13 | * |
||
14 | * Copyright © 2008 Microchip Technology Inc. All rights reserved. |
||
15 | * Microchip licenses to you the right to use, modify, copy and distribute |
||
16 | * Software only when embedded on a Microchip microcontroller or digital |
||
17 | * signal controller, which is integrated into your product or third party |
||
18 | * product (pursuant to the sublicense terms in the accompanying license |
||
19 | * agreement). |
||
20 | * |
||
21 | * You should refer to the license agreement accompanying this Software |
||
22 | * for additional information regarding your rights and obligations. |
||
23 | * |
||
24 | * SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY |
||
25 | * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY |
||
26 | * OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR |
||
27 | * PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR |
||
28 | * OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, |
||
29 | * BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT |
||
30 | * DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, |
||
31 | * INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, |
||
32 | * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY |
||
33 | * CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), |
||
34 | * OR OTHER SIMILAR COSTS. |
||
35 | * |
||
36 | * Author Date Comment |
||
37 | *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||
38 | * Anton Alkhimenok 11/12/07 Version 1.0 release |
||
39 | *****************************************************************************/ |
||
40 | #include "Graphics\Graphics.h" |
||
41 | |||
42 | // Color |
||
43 | WORD_VAL _color; |
||
44 | |||
45 | // Clipping region control |
||
46 | SHORT _clipRgn; |
||
47 | |||
48 | // Clipping region borders |
||
49 | SHORT _clipLeft; |
||
50 | SHORT _clipTop; |
||
51 | SHORT _clipRight; |
||
52 | SHORT _clipBottom; |
||
53 | |||
54 | /////////////////////// LOCAL FUNCTIONS PROTOTYPES //////////////////////////// |
||
55 | void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch); |
||
56 | void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch); |
||
57 | void PutImage8BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch); |
||
58 | void PutImage16BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch); |
||
59 | |||
60 | void PutImage1BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch); |
||
61 | void PutImage4BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch); |
||
62 | void PutImage8BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch); |
||
63 | void PutImage16BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch); |
||
64 | |||
65 | |||
66 | /********************************************************************* |
||
67 | * Macros: SetAddress(x, y) |
||
68 | * |
||
69 | * PreCondition: none |
||
70 | * |
||
71 | * Input: x,y - start x,y position |
||
72 | * |
||
73 | * Output: none |
||
74 | * |
||
75 | * Side Effects: none |
||
76 | * |
||
77 | * Overview: sets pointer to to write/read operations |
||
78 | * |
||
79 | * Note: none |
||
80 | * |
||
81 | ********************************************************************/ |
||
82 | #define SetAddress(x, y) \ |
||
83 | DeviceSetCommand(); \ |
||
84 | DeviceWrite(CMD_COL); \ |
||
85 | DeviceSetData(); \ |
||
86 | DeviceWrite(x); \ |
||
87 | DeviceSetCommand(); \ |
||
88 | DeviceWrite(CMD_ROW); \ |
||
89 | DeviceSetData(); \ |
||
90 | DeviceWrite(y); |
||
91 | |||
92 | /********************************************************************* |
||
93 | * Function: void ResetDevice() |
||
94 | * |
||
95 | * PreCondition: none |
||
96 | * |
||
97 | * Input: none |
||
98 | * |
||
99 | * Output: none |
||
100 | * |
||
101 | * Side Effects: none |
||
102 | * |
||
103 | * Overview: resets LCD, initializes PMP |
||
104 | * |
||
105 | * Note: none |
||
106 | * |
||
107 | ********************************************************************/ |
||
108 | void ResetDevice(void) |
||
109 | { |
||
110 | // Initialize device |
||
111 | DeviceInit(); |
||
112 | |||
113 | // Enable LCD |
||
114 | DeviceSelect(); |
||
115 | |||
116 | // Setup display |
||
117 | DeviceSetCommand() |
||
118 | DeviceWrite(CMD_DISPON); |
||
119 | DeviceWrite(CMD_MODE); |
||
120 | DeviceSetData(); |
||
121 | DeviceWrite(0x74); |
||
122 | DeviceSetCommand(); |
||
123 | DeviceWrite(CMD_SRTLINE); |
||
124 | DeviceSetData(); |
||
125 | DeviceWrite(128); |
||
126 | |||
127 | // Disable LCD |
||
128 | DeviceDeselect(); |
||
129 | } |
||
130 | |||
131 | /********************************************************************* |
||
132 | * Function: void PutPixel(SHORT x, SHORT y) |
||
133 | * |
||
134 | * PreCondition: none |
||
135 | * |
||
136 | * Input: x,y - pixel coordinates |
||
137 | * |
||
138 | * Output: none |
||
139 | * |
||
140 | * Side Effects: none |
||
141 | * |
||
142 | * Overview: puts pixel |
||
143 | * |
||
144 | * Note: none |
||
145 | * |
||
146 | ********************************************************************/ |
||
147 | void PutPixel(SHORT x, SHORT y) |
||
148 | { |
||
149 | if(_clipRgn) |
||
150 | { |
||
151 | if(x < _clipLeft) |
||
152 | return; |
||
153 | if(x > _clipRight) |
||
154 | return; |
||
155 | if(y < _clipTop) |
||
156 | return; |
||
157 | if(y > _clipBottom) |
||
158 | return; |
||
159 | } |
||
160 | |||
161 | DeviceSelect(); |
||
162 | SetAddress(x, y); |
||
163 | DeviceSetCommand(); |
||
164 | DeviceWrite(CMD_WRITE); |
||
165 | DeviceSetData(); |
||
166 | DeviceWrite(_color.v[1]); |
||
167 | DeviceWrite(_color.v[0]); |
||
168 | DeviceDeselect(); |
||
169 | } |
||
170 | |||
171 | /********************************************************************* |
||
172 | * Function: WORD GetPixel(SHORT x, SHORT y) |
||
173 | * |
||
174 | * PreCondition: none |
||
175 | * |
||
176 | * Input: x,y - pixel coordinates |
||
177 | * |
||
178 | * Output: pixel color |
||
179 | * |
||
180 | * Side Effects: none |
||
181 | * |
||
182 | * Overview: return pixel color at x,y position |
||
183 | * |
||
184 | * Note: none |
||
185 | * |
||
186 | ********************************************************************/ |
||
187 | WORD GetPixel(SHORT x, SHORT y) |
||
188 | { |
||
189 | WORD_VAL result; |
||
190 | |||
191 | DeviceSelect(); |
||
192 | |||
193 | SetAddress(x, y); |
||
194 | |||
195 | DeviceSetCommand(); |
||
196 | DeviceWrite(CMD_READ); |
||
197 | DeviceSetData(); |
||
198 | |||
199 | result.v[0] = DeviceRead(); |
||
200 | result.v[1] = DeviceRead(); |
||
201 | |||
202 | DeviceDeselect(); |
||
203 | |||
204 | return (result.Val); |
||
205 | } |
||
206 | |||
207 | /********************************************************************* |
||
208 | * Function: WORD Bar(SHORT left, SHORT top, SHORT right, SHORT bottom) |
||
209 | * |
||
210 | * PreCondition: none |
||
211 | * |
||
212 | * Input: left,top - top left corner coordinates, |
||
213 | * right,bottom - bottom right corner coordinates |
||
214 | * |
||
215 | * Output: For NON-Blocking configuration: |
||
216 | * - Returns 0 when device is busy and the shape is not yet completely drawn. |
||
217 | * - Returns 1 when the shape is completely drawn. |
||
218 | * For Blocking configuration: |
||
219 | * - Always return 1. |
||
220 | * |
||
221 | * Side Effects: none |
||
222 | * |
||
223 | * Overview: draws rectangle filled with current color |
||
224 | * |
||
225 | * Note: none |
||
226 | * |
||
227 | ********************************************************************/ |
||
228 | WORD Bar(SHORT left, SHORT top, SHORT right, SHORT bottom) |
||
229 | { |
||
230 | SHORT x, y; |
||
231 | |||
232 | #ifndef USE_NONBLOCKING_CONFIG |
||
233 | while(IsDeviceBusy() != 0); |
||
234 | |||
235 | /* Ready */ |
||
236 | #else |
||
237 | if(IsDeviceBusy() != 0) |
||
238 | return (0); |
||
239 | #endif |
||
240 | if(_clipRgn) |
||
241 | { |
||
242 | if(left < _clipLeft) |
||
243 | left = _clipLeft; |
||
244 | if(right > _clipRight) |
||
245 | right = _clipRight; |
||
246 | if(top < _clipTop) |
||
247 | top = _clipTop; |
||
248 | if(bottom > _clipBottom) |
||
249 | bottom = _clipBottom; |
||
250 | } |
||
251 | |||
252 | DeviceSelect(); |
||
253 | |||
254 | for(y = top; y < bottom + 1; y++) |
||
255 | { |
||
256 | SetAddress(left, top); |
||
257 | DeviceSetCommand(); |
||
258 | DeviceWrite(CMD_WRITE); |
||
259 | DeviceSetData(); |
||
260 | for(x = left; x < right + 1; x++) |
||
261 | { |
||
262 | DeviceWrite(_color.v[1]); |
||
263 | DeviceWrite(_color.v[0]); |
||
264 | } |
||
265 | } |
||
266 | |||
267 | DeviceDeselect(); |
||
268 | return (1); |
||
269 | } |
||
270 | |||
271 | /********************************************************************* |
||
272 | * Function: void ClearDevice(void) |
||
273 | * |
||
274 | * PreCondition: none |
||
275 | * |
||
276 | * Input: none |
||
277 | * |
||
278 | * Output: none |
||
279 | * |
||
280 | * Side Effects: none |
||
281 | * |
||
282 | * Overview: clears screen with current color |
||
283 | * |
||
284 | * Note: none |
||
285 | * |
||
286 | ********************************************************************/ |
||
287 | void ClearDevice(void) |
||
288 | { |
||
289 | DWORD counter; |
||
290 | |||
291 | DeviceSelect(); |
||
292 | SetAddress(0, 0); |
||
293 | DeviceSetCommand(); |
||
294 | DeviceWrite(CMD_WRITE); |
||
295 | DeviceSetData(); |
||
296 | for(counter = 0; counter < (DWORD) (GetMaxX() + 1) * (GetMaxY() + 1); counter++) |
||
297 | { |
||
298 | DeviceWrite(_color.v[1]); |
||
299 | DeviceWrite(_color.v[0]); |
||
300 | } |
||
301 | |||
302 | DeviceDeselect(); |
||
303 | } |
||
304 | |||
305 | /********************************************************************* |
||
306 | * Function: WORD PutImage(SHORT left, SHORT top, void* bitmap, BYTE stretch) |
||
307 | * |
||
308 | * PreCondition: none |
||
309 | * |
||
310 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
311 | * stretch - image stretch factor |
||
312 | * |
||
313 | * Output: For NON-Blocking configuration: |
||
314 | * - Returns 0 when device is busy and the image is not yet completely drawn. |
||
315 | * - Returns 1 when the image is completely drawn. |
||
316 | * For Blocking configuration: |
||
317 | * - Always return 1. |
||
318 | * |
||
319 | * Side Effects: none |
||
320 | * |
||
321 | * Overview: outputs image starting from left,top coordinates |
||
322 | * |
||
323 | * Note: image must be located in flash |
||
324 | * |
||
325 | ********************************************************************/ |
||
326 | WORD PutImage(SHORT left, SHORT top, void *bitmap, BYTE stretch) |
||
327 | { |
||
328 | FLASH_BYTE *flashAddress; |
||
329 | BYTE colorDepth; |
||
330 | WORD colorTemp; |
||
331 | |||
332 | #ifndef USE_NONBLOCKING_CONFIG |
||
333 | while(IsDeviceBusy() != 0); |
||
334 | |||
335 | /* Ready */ |
||
336 | #else |
||
337 | if(IsDeviceBusy() != 0) |
||
338 | return (0); |
||
339 | #endif |
||
340 | |||
341 | // Save current color |
||
342 | colorTemp = _color.Val; |
||
343 | |||
344 | switch(*((SHORT *)bitmap)) |
||
345 | { |
||
346 | #ifdef USE_BITMAP_FLASH |
||
347 | |||
348 | case FLASH: |
||
349 | |||
350 | // Image address |
||
351 | flashAddress = ((BITMAP_FLASH *)bitmap)->address; |
||
352 | |||
353 | // Read color depth |
||
354 | colorDepth = *(flashAddress + 1); |
||
355 | |||
356 | // Draw picture |
||
357 | switch(colorDepth) |
||
358 | { |
||
359 | case 1: PutImage1BPP(left, top, flashAddress, stretch); break; |
||
360 | case 4: PutImage4BPP(left, top, flashAddress, stretch); break; |
||
361 | case 8: PutImage8BPP(left, top, flashAddress, stretch); break; |
||
362 | case 16: PutImage16BPP(left, top, flashAddress, stretch); break; |
||
363 | } |
||
364 | |||
365 | break; |
||
366 | #endif |
||
367 | #ifdef USE_BITMAP_EXTERNAL |
||
368 | |||
369 | case EXTERNAL: |
||
370 | |||
371 | // Get color depth |
||
372 | ExternalMemoryCallback(bitmap, 1, 1, &colorDepth); |
||
373 | |||
374 | // Draw picture |
||
375 | switch(colorDepth) |
||
376 | { |
||
377 | case 1: PutImage1BPPExt(left, top, bitmap, stretch); break; |
||
378 | case 4: PutImage4BPPExt(left, top, bitmap, stretch); break; |
||
379 | case 8: PutImage8BPPExt(left, top, bitmap, stretch); break; |
||
380 | case 16: PutImage16BPPExt(left, top, bitmap, stretch); break; |
||
381 | default: break; |
||
382 | } |
||
383 | |||
384 | break; |
||
385 | #endif |
||
386 | |||
387 | default: |
||
388 | break; |
||
389 | } |
||
390 | |||
391 | // Restore current color |
||
392 | _color.Val = colorTemp; |
||
393 | return (1); |
||
394 | } |
||
395 | |||
396 | #ifdef USE_BITMAP_FLASH |
||
397 | |||
398 | /********************************************************************* |
||
399 | * Function: void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch) |
||
400 | * |
||
401 | * PreCondition: none |
||
402 | * |
||
403 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
404 | * stretch - image stretch factor |
||
405 | * |
||
406 | * Output: none |
||
407 | * |
||
408 | * Side Effects: none |
||
409 | * |
||
410 | * Overview: outputs monochrome image starting from left,top coordinates |
||
411 | * |
||
412 | * Note: image must be located in flash |
||
413 | * |
||
414 | ********************************************************************/ |
||
415 | void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch) |
||
416 | { |
||
417 | register FLASH_BYTE *flashAddress; |
||
418 | register FLASH_BYTE *tempFlashAddress; |
||
419 | BYTE temp; |
||
420 | WORD sizeX, sizeY; |
||
421 | WORD x, y; |
||
422 | BYTE stretchX, stretchY; |
||
423 | WORD pallete[2]; |
||
424 | BYTE mask; |
||
425 | |||
426 | // Move pointer to size information |
||
427 | flashAddress = bitmap + 2; |
||
428 | |||
429 | // Read image size |
||
430 | sizeY = *((FLASH_WORD *)flashAddress); |
||
431 | flashAddress += 2; |
||
432 | sizeX = *((FLASH_WORD *)flashAddress); |
||
433 | flashAddress += 2; |
||
434 | pallete[0] = *((FLASH_WORD *)flashAddress); |
||
435 | flashAddress += 2; |
||
436 | pallete[1] = *((FLASH_WORD *)flashAddress); |
||
437 | flashAddress += 2; |
||
438 | |||
439 | DeviceSelect(); |
||
440 | for(y = 0; y < sizeY; y++) |
||
441 | { |
||
442 | tempFlashAddress = flashAddress; |
||
443 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
444 | { |
||
445 | flashAddress = tempFlashAddress; |
||
446 | SetAddress(left, top + y); |
||
447 | DeviceSetCommand(); |
||
448 | DeviceWrite(CMD_WRITE); |
||
449 | DeviceSetData(); |
||
450 | mask = 0; |
||
451 | for(x = 0; x < sizeX; x++) |
||
452 | { |
||
453 | |||
454 | // Read 8 pixels from flash |
||
455 | if(mask == 0) |
||
456 | { |
||
457 | temp = *flashAddress; |
||
458 | flashAddress++; |
||
459 | mask = 0x80; |
||
460 | } |
||
461 | |||
462 | // Set color |
||
463 | if(mask & temp) |
||
464 | { |
||
465 | SetColor(pallete[1]); |
||
466 | } |
||
467 | else |
||
468 | { |
||
469 | SetColor(pallete[0]); |
||
470 | } |
||
471 | |||
472 | // Write pixel to screen |
||
473 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
474 | { |
||
475 | DeviceWrite(_color.v[1]); |
||
476 | DeviceWrite(_color.v[0]); |
||
477 | } |
||
478 | |||
479 | // Shift to the next pixel |
||
480 | mask >>= 1; |
||
481 | } |
||
482 | } |
||
483 | } |
||
484 | |||
485 | DeviceDeselect(); |
||
486 | } |
||
487 | |||
488 | /********************************************************************* |
||
489 | * Function: void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch) |
||
490 | * |
||
491 | * PreCondition: none |
||
492 | * |
||
493 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
494 | * stretch - image stretch factor |
||
495 | * |
||
496 | * Output: none |
||
497 | * |
||
498 | * Side Effects: none |
||
499 | * |
||
500 | * Overview: outputs 16 color image starting from left,top coordinates |
||
501 | * |
||
502 | * Note: image must be located in flash |
||
503 | * |
||
504 | ********************************************************************/ |
||
505 | void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch) |
||
506 | { |
||
507 | register FLASH_BYTE *flashAddress; |
||
508 | register FLASH_BYTE *tempFlashAddress; |
||
509 | WORD sizeX, sizeY; |
||
510 | register WORD x, y; |
||
511 | BYTE temp; |
||
512 | register BYTE stretchX, stretchY; |
||
513 | WORD pallete[16]; |
||
514 | WORD counter; |
||
515 | |||
516 | // Move pointer to size information |
||
517 | flashAddress = bitmap + 2; |
||
518 | |||
519 | // Read image size |
||
520 | sizeY = *((FLASH_WORD *)flashAddress); |
||
521 | flashAddress += 2; |
||
522 | sizeX = *((FLASH_WORD *)flashAddress); |
||
523 | flashAddress += 2; |
||
524 | |||
525 | // Read pallete |
||
526 | for(counter = 0; counter < 16; counter++) |
||
527 | { |
||
528 | pallete[counter] = *((FLASH_WORD *)flashAddress); |
||
529 | flashAddress += 2; |
||
530 | } |
||
531 | |||
532 | DeviceSelect(); |
||
533 | for(y = 0; y < sizeY; y++) |
||
534 | { |
||
535 | tempFlashAddress = flashAddress; |
||
536 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
537 | { |
||
538 | flashAddress = tempFlashAddress; |
||
539 | SetAddress(left, top + y); |
||
540 | DeviceSetCommand(); |
||
541 | DeviceWrite(CMD_WRITE); |
||
542 | DeviceSetData(); |
||
543 | for(x = 0; x < sizeX; x++) |
||
544 | { |
||
545 | |||
546 | // Read 2 pixels from flash |
||
547 | if((x & 0x0001) == 0) |
||
548 | { |
||
549 | |||
550 | // Set color |
||
551 | SetColor(pallete[temp >> 4]); |
||
552 | } |
||
553 | else |
||
554 | { |
||
555 | temp = *flashAddress; |
||
556 | flashAddress++; |
||
557 | |||
558 | // Set color |
||
559 | SetColor(pallete[temp & 0x0f]); |
||
560 | } |
||
561 | |||
562 | // Write pixel to screen |
||
563 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
564 | { |
||
565 | DeviceWrite(_color.v[1]); |
||
566 | DeviceWrite(_color.v[0]); |
||
567 | } |
||
568 | |||
569 | // Shift to the next pixel |
||
570 | temp >>= 4; |
||
571 | } |
||
572 | } |
||
573 | } |
||
574 | |||
575 | DeviceDeselect; |
||
576 | } |
||
577 | |||
578 | /********************************************************************* |
||
579 | * Function: void PutImage8BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch) |
||
580 | * |
||
581 | * PreCondition: none |
||
582 | * |
||
583 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
584 | * stretch - image stretch factor |
||
585 | * |
||
586 | * Output: none |
||
587 | * |
||
588 | * Side Effects: none |
||
589 | * |
||
590 | * Overview: outputs 256 color image starting from left,top coordinates |
||
591 | * |
||
592 | * Note: image must be located in flash |
||
593 | * |
||
594 | ********************************************************************/ |
||
595 | void PutImage8BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch) |
||
596 | { |
||
597 | register FLASH_BYTE *flashAddress; |
||
598 | register FLASH_BYTE *tempFlashAddress; |
||
599 | WORD sizeX, sizeY; |
||
600 | WORD x, y; |
||
601 | BYTE temp; |
||
602 | BYTE stretchX, stretchY; |
||
603 | WORD pallete[256]; |
||
604 | WORD counter; |
||
605 | |||
606 | // Move pointer to size information |
||
607 | flashAddress = bitmap + 2; |
||
608 | |||
609 | // Read image size |
||
610 | sizeY = *((FLASH_WORD *)flashAddress); |
||
611 | flashAddress += 2; |
||
612 | sizeX = *((FLASH_WORD *)flashAddress); |
||
613 | flashAddress += 2; |
||
614 | |||
615 | // Read pallete |
||
616 | for(counter = 0; counter < 256; counter++) |
||
617 | { |
||
618 | pallete[counter] = *((FLASH_WORD *)flashAddress); |
||
619 | flashAddress += 2; |
||
620 | } |
||
621 | |||
622 | DeviceSelect(); |
||
623 | for(y = 0; y < sizeY; y++) |
||
624 | { |
||
625 | tempFlashAddress = flashAddress; |
||
626 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
627 | { |
||
628 | flashAddress = tempFlashAddress; |
||
629 | SetAddress(left, top + y); |
||
630 | DeviceSetCommand(); |
||
631 | DeviceWrite(CMD_WRITE); |
||
632 | DeviceSetData(); |
||
633 | for(x = 0; x < sizeX; x++) |
||
634 | { |
||
635 | |||
636 | // Read pixels from flash |
||
637 | temp = *flashAddress; |
||
638 | flashAddress++; |
||
639 | |||
640 | // Set color |
||
641 | SetColor(pallete[temp]); |
||
642 | |||
643 | // Write pixel to screen |
||
644 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
645 | { |
||
646 | DeviceWrite(_color.v[1]); |
||
647 | DeviceWrite(_color.v[0]); |
||
648 | } |
||
649 | } |
||
650 | } |
||
651 | } |
||
652 | |||
653 | DeviceDeselect(); |
||
654 | } |
||
655 | |||
656 | /********************************************************************* |
||
657 | * Function: void PutImage16BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch) |
||
658 | * |
||
659 | * PreCondition: none |
||
660 | * |
||
661 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
662 | * stretch - image stretch factor |
||
663 | * |
||
664 | * Output: none |
||
665 | * |
||
666 | * Side Effects: none |
||
667 | * |
||
668 | * Overview: outputs hicolor image starting from left,top coordinates |
||
669 | * |
||
670 | * Note: image must be located in flash |
||
671 | * |
||
672 | ********************************************************************/ |
||
673 | void PutImage16BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch) |
||
674 | { |
||
675 | register FLASH_WORD *flashAddress; |
||
676 | register FLASH_WORD *tempFlashAddress; |
||
677 | WORD sizeX, sizeY; |
||
678 | register WORD x, y; |
||
679 | WORD temp; |
||
680 | register BYTE stretchX, stretchY; |
||
681 | |||
682 | // Move pointer to size information |
||
683 | flashAddress = (FLASH_WORD *)bitmap + 1; |
||
684 | |||
685 | // Read image size |
||
686 | sizeY = *flashAddress; |
||
687 | flashAddress++; |
||
688 | sizeX = *flashAddress; |
||
689 | flashAddress++; |
||
690 | |||
691 | DeviceSelect(); |
||
692 | for(y = 0; y < sizeY; y++) |
||
693 | { |
||
694 | tempFlashAddress = flashAddress; |
||
695 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
696 | { |
||
697 | flashAddress = tempFlashAddress; |
||
698 | SetAddress(left, top + y); |
||
699 | DeviceSetCommand(); |
||
700 | DeviceWrite(CMD_WRITE); |
||
701 | DeviceSetData(); |
||
702 | for(x = 0; x < sizeX; x++) |
||
703 | { |
||
704 | |||
705 | // Read pixels from flash |
||
706 | temp = *flashAddress; |
||
707 | flashAddress++; |
||
708 | |||
709 | // Set color |
||
710 | SetColor(temp); |
||
711 | |||
712 | // Write pixel to screen |
||
713 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
714 | { |
||
715 | DeviceWrite(_color.v[1]); |
||
716 | DeviceWrite(_color.v[0]); |
||
717 | } |
||
718 | } |
||
719 | } |
||
720 | } |
||
721 | |||
722 | DeviceDeselect(); |
||
723 | } |
||
724 | |||
725 | #endif |
||
726 | #ifdef USE_BITMAP_EXTERNAL |
||
727 | |||
728 | /********************************************************************* |
||
729 | * Function: void PutImage1BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch) |
||
730 | * |
||
731 | * PreCondition: none |
||
732 | * |
||
733 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
734 | * stretch - image stretch factor |
||
735 | * |
||
736 | * Output: none |
||
737 | * |
||
738 | * Side Effects: none |
||
739 | * |
||
740 | * Overview: outputs monochrome image starting from left,top coordinates |
||
741 | * |
||
742 | * Note: image must be located in flash |
||
743 | * |
||
744 | ********************************************************************/ |
||
745 | void PutImage1BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch) |
||
746 | { |
||
747 | register DWORD memOffset; |
||
748 | BITMAP_HEADER bmp; |
||
749 | WORD pallete[2]; |
||
750 | BYTE lineBuffer[((GetMaxX() + 1) / 8) + 1]; |
||
751 | BYTE *pData; |
||
752 | SHORT byteWidth; |
||
753 | |||
754 | BYTE temp; |
||
755 | BYTE mask; |
||
756 | WORD sizeX, sizeY; |
||
757 | WORD x, y; |
||
758 | BYTE stretchX, stretchY; |
||
759 | |||
760 | // Get bitmap header |
||
761 | ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp); |
||
762 | |||
763 | // Get pallete (2 entries) |
||
764 | ExternalMemoryCallback(bitmap, sizeof(BITMAP_HEADER), 2 * sizeof(WORD), pallete); |
||
765 | |||
766 | // Set offset to the image data |
||
767 | memOffset = sizeof(BITMAP_HEADER) + 2 * sizeof(WORD); |
||
768 | |||
769 | // Line width in bytes |
||
770 | byteWidth = bmp.width >> 3; |
||
771 | if(bmp.width & 0x0007) |
||
772 | byteWidth++; |
||
773 | |||
774 | // Get size |
||
775 | sizeX = bmp.width; |
||
776 | sizeY = bmp.height; |
||
777 | |||
778 | for(y = 0; y < sizeY; y++) |
||
779 | { |
||
780 | |||
781 | // Get line |
||
782 | ExternalMemoryCallback(bitmap, memOffset, byteWidth, lineBuffer); |
||
783 | memOffset += byteWidth; |
||
784 | DeviceSelect(); |
||
785 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
786 | { |
||
787 | pData = lineBuffer; |
||
788 | SetAddress(left, top + y); |
||
789 | DeviceSetCommand(); |
||
790 | DeviceWrite(CMD_WRITE); |
||
791 | DeviceSetData(); |
||
792 | mask = 0; |
||
793 | for(x = 0; x < sizeX; x++) |
||
794 | { |
||
795 | |||
796 | // Read 8 pixels from flash |
||
797 | if(mask == 0) |
||
798 | { |
||
799 | temp = *pData++; |
||
800 | mask = 0x80; |
||
801 | } |
||
802 | |||
803 | // Set color |
||
804 | if(mask & temp) |
||
805 | { |
||
806 | SetColor(pallete[1]); |
||
807 | } |
||
808 | else |
||
809 | { |
||
810 | SetColor(pallete[0]); |
||
811 | } |
||
812 | |||
813 | // Write pixel to screen |
||
814 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
815 | { |
||
816 | DeviceWrite(_color.v[1]); |
||
817 | DeviceWrite(_color.v[0]); |
||
818 | } |
||
819 | |||
820 | // Shift to the next pixel |
||
821 | mask >>= 1; |
||
822 | } |
||
823 | } |
||
824 | |||
825 | DeviceDeselect(); |
||
826 | } |
||
827 | } |
||
828 | |||
829 | /********************************************************************* |
||
830 | * Function: void PutImage4BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch) |
||
831 | * |
||
832 | * PreCondition: none |
||
833 | * |
||
834 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
835 | * stretch - image stretch factor |
||
836 | * |
||
837 | * Output: none |
||
838 | * |
||
839 | * Side Effects: none |
||
840 | * |
||
841 | * Overview: outputs monochrome image starting from left,top coordinates |
||
842 | * |
||
843 | * Note: image must be located in flash |
||
844 | * |
||
845 | ********************************************************************/ |
||
846 | void PutImage4BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch) |
||
847 | { |
||
848 | register DWORD memOffset; |
||
849 | BITMAP_HEADER bmp; |
||
850 | WORD pallete[16]; |
||
851 | BYTE lineBuffer[((GetMaxX() + 1) / 2) + 1]; |
||
852 | BYTE *pData; |
||
853 | SHORT byteWidth; |
||
854 | |||
855 | BYTE temp; |
||
856 | WORD sizeX, sizeY; |
||
857 | WORD x, y; |
||
858 | BYTE stretchX, stretchY; |
||
859 | |||
860 | // Get bitmap header |
||
861 | ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp); |
||
862 | |||
863 | // Get pallete (16 entries) |
||
864 | ExternalMemoryCallback(bitmap, sizeof(BITMAP_HEADER), 16 * sizeof(WORD), pallete); |
||
865 | |||
866 | // Set offset to the image data |
||
867 | memOffset = sizeof(BITMAP_HEADER) + 16 * sizeof(WORD); |
||
868 | |||
869 | // Line width in bytes |
||
870 | byteWidth = bmp.width >> 1; |
||
871 | if(bmp.width & 0x0001) |
||
872 | byteWidth++; |
||
873 | |||
874 | // Get size |
||
875 | sizeX = bmp.width; |
||
876 | sizeY = bmp.height; |
||
877 | |||
878 | for(y = 0; y < sizeY; y++) |
||
879 | { |
||
880 | |||
881 | // Get line |
||
882 | ExternalMemoryCallback(bitmap, memOffset, byteWidth, lineBuffer); |
||
883 | memOffset += byteWidth; |
||
884 | DeviceSelect(); |
||
885 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
886 | { |
||
887 | pData = lineBuffer; |
||
888 | SetAddress(left, top + y); |
||
889 | DeviceSetCommand(); |
||
890 | DeviceWrite(CMD_WRITE); |
||
891 | DeviceSetData(); |
||
892 | for(x = 0; x < sizeX; x++) |
||
893 | { |
||
894 | |||
895 | // Read 2 pixels from flash |
||
896 | if(x & 0x0001) |
||
897 | { |
||
898 | |||
899 | // second pixel in byte |
||
900 | SetColor(pallete[temp >> 4]); |
||
901 | } |
||
902 | else |
||
903 | { |
||
904 | temp = *pData++; |
||
905 | |||
906 | // first pixel in byte |
||
907 | SetColor(pallete[temp & 0x0f]); |
||
908 | } |
||
909 | |||
910 | // Set color |
||
911 | SetColor(pallete[temp & 0x0f]); |
||
912 | |||
913 | // Write pixel to screen |
||
914 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
915 | { |
||
916 | DeviceWrite(_color.v[1]); |
||
917 | DeviceWrite(_color.v[0]); |
||
918 | } |
||
919 | |||
920 | // Shift to the next pixel |
||
921 | temp >>= 4; |
||
922 | } |
||
923 | } |
||
924 | |||
925 | DeviceDeselect(); |
||
926 | } |
||
927 | } |
||
928 | |||
929 | /********************************************************************* |
||
930 | * Function: void PutImage8BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch) |
||
931 | * |
||
932 | * PreCondition: none |
||
933 | * |
||
934 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
935 | * stretch - image stretch factor |
||
936 | * |
||
937 | * Output: none |
||
938 | * |
||
939 | * Side Effects: none |
||
940 | * |
||
941 | * Overview: outputs monochrome image starting from left,top coordinates |
||
942 | * |
||
943 | * Note: image must be located in flash |
||
944 | * |
||
945 | ********************************************************************/ |
||
946 | void PutImage8BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch) |
||
947 | { |
||
948 | register DWORD memOffset; |
||
949 | BITMAP_HEADER bmp; |
||
950 | WORD pallete[256]; |
||
951 | BYTE lineBuffer[(GetMaxX() + 1)]; |
||
952 | BYTE *pData; |
||
953 | |||
954 | BYTE temp; |
||
955 | WORD sizeX, sizeY; |
||
956 | WORD x, y; |
||
957 | BYTE stretchX, stretchY; |
||
958 | |||
959 | // Get bitmap header |
||
960 | ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp); |
||
961 | |||
962 | // Get pallete (256 entries) |
||
963 | ExternalMemoryCallback(bitmap, sizeof(BITMAP_HEADER), 256 * sizeof(WORD), pallete); |
||
964 | |||
965 | // Set offset to the image data |
||
966 | memOffset = sizeof(BITMAP_HEADER) + 256 * sizeof(WORD); |
||
967 | |||
968 | // Get size |
||
969 | sizeX = bmp.width; |
||
970 | sizeY = bmp.height; |
||
971 | |||
972 | for(y = 0; y < sizeY; y++) |
||
973 | { |
||
974 | |||
975 | // Get line |
||
976 | ExternalMemoryCallback(bitmap, memOffset, sizeX, lineBuffer); |
||
977 | memOffset += sizeX; |
||
978 | DeviceSelect(); |
||
979 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
980 | { |
||
981 | pData = lineBuffer; |
||
982 | SetAddress(left, top + y); |
||
983 | DeviceSetCommand(); |
||
984 | DeviceWrite(CMD_WRITE); |
||
985 | DeviceSetData(); |
||
986 | for(x = 0; x < sizeX; x++) |
||
987 | { |
||
988 | |||
989 | // Read pixels from flash |
||
990 | temp = *pData++; |
||
991 | |||
992 | // Set color |
||
993 | SetColor(pallete[temp]); |
||
994 | |||
995 | // Write pixel to screen |
||
996 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
997 | { |
||
998 | DeviceWrite(_color.v[1]); |
||
999 | DeviceWrite(_color.v[0]); |
||
1000 | } |
||
1001 | } |
||
1002 | } |
||
1003 | |||
1004 | DeviceDeselect(); |
||
1005 | } |
||
1006 | } |
||
1007 | |||
1008 | /********************************************************************* |
||
1009 | * Function: void PutImage16BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch) |
||
1010 | * |
||
1011 | * PreCondition: none |
||
1012 | * |
||
1013 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
1014 | * stretch - image stretch factor |
||
1015 | * |
||
1016 | * Output: none |
||
1017 | * |
||
1018 | * Side Effects: none |
||
1019 | * |
||
1020 | * Overview: outputs monochrome image starting from left,top coordinates |
||
1021 | * |
||
1022 | * Note: image must be located in flash |
||
1023 | * |
||
1024 | ********************************************************************/ |
||
1025 | void PutImage16BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch) |
||
1026 | { |
||
1027 | register DWORD memOffset; |
||
1028 | BITMAP_HEADER bmp; |
||
1029 | WORD lineBuffer[(GetMaxX() + 1)]; |
||
1030 | WORD *pData; |
||
1031 | WORD byteWidth; |
||
1032 | |||
1033 | WORD temp; |
||
1034 | WORD sizeX, sizeY; |
||
1035 | WORD x, y; |
||
1036 | BYTE stretchX, stretchY; |
||
1037 | |||
1038 | // Get bitmap header |
||
1039 | ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp); |
||
1040 | |||
1041 | // Set offset to the image data |
||
1042 | memOffset = sizeof(BITMAP_HEADER); |
||
1043 | |||
1044 | // Get size |
||
1045 | sizeX = bmp.width; |
||
1046 | sizeY = bmp.height; |
||
1047 | |||
1048 | byteWidth = sizeX << 1; |
||
1049 | |||
1050 | for(y = 0; y < sizeY; y++) |
||
1051 | { |
||
1052 | |||
1053 | // Get line |
||
1054 | ExternalMemoryCallback(bitmap, memOffset, byteWidth, lineBuffer); |
||
1055 | memOffset += byteWidth; |
||
1056 | DeviceSelect(); |
||
1057 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
1058 | { |
||
1059 | pData = lineBuffer; |
||
1060 | SetAddress(left, top + y); |
||
1061 | DeviceSetCommand(); |
||
1062 | DeviceWrite(CMD_WRITE); |
||
1063 | DeviceSetData(); |
||
1064 | for(x = 0; x < sizeX; x++) |
||
1065 | { |
||
1066 | |||
1067 | // Read pixels from flash |
||
1068 | temp = *pData++; |
||
1069 | |||
1070 | // Set color |
||
1071 | SetColor(temp); |
||
1072 | |||
1073 | // Write pixel to screen |
||
1074 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
1075 | { |
||
1076 | DeviceWrite(_color.v[1]); |
||
1077 | DeviceWrite(_color.v[0]); |
||
1078 | } |
||
1079 | } |
||
1080 | } |
||
1081 | |||
1082 | DeviceDeselect(); |
||
1083 | } |
||
1084 | } |
||
1085 | |||
1086 | #endif |
Powered by WebSVN v2.8.3