?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 32

Line No. Rev Author Line
1 32 kaklik /*****************************************************************************
2 * Module for Microchip Graphics Library
3 * UltraChip UC1610 controller driver
4 *****************************************************************************
5 * FileName: UC1610.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 © 2009 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 02/25/09
39 *****************************************************************************/
40 #include "Graphics\Graphics.h"
41  
42 // Color
43 BYTE _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 PutImage1BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch);
58 void PutImage4BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch);
59  
60  
61 /*********************************************************************
62 * Function: void ResetDevice()
63 *
64 * PreCondition: none
65 *
66 * Input: none
67 *
68 * Output: none
69 *
70 * Side Effects: none
71 *
72 * Overview: resets LCD, initializes PMP
73 *
74 * Note: none
75 *
76 ********************************************************************/
77 void ResetDevice(void)
78 {
79 // Initialize the device
80 DeviceInit();
81  
82 DeviceSelect();
83  
84 DeviceSetCommand();
85 // set Vbias
86 DeviceWrite(CMD_BIAS_RATIO_12);
87 DeviceWrite(CMD_CONTRAST);
88 DeviceWrite(82);
89  
90 // set panel loading
91 DeviceWrite(CMD_PANEL_LOADING_38NF);
92  
93 // set connected COM electrodes
94 DeviceWrite(CMD_DISPLAY_START);
95 DeviceWrite(4 * (DISP_START_PAGE + 1) - 1);
96 DeviceWrite(CMD_DISPLAY_END);
97 DeviceWrite(4 * (DISP_END_PAGE + 1) - 1);
98 DeviceWrite(CMD_COM_END);
99 DeviceWrite(4 * (DISP_END_PAGE + 1) - 1);
100  
101 // set line rate
102 DeviceWrite(CMD_LINE_RATE_12KLPS);
103  
104 DeviceWrite(CMD_MAPPING_MY);
105  
106 // inverse color
107 DeviceWrite(CMD_INVERSE_ON);
108  
109 // set programm window
110 DeviceWrite(CMD_WND_PRG_DISABLE);
111 DeviceWrite(CMD_START_COLUMN);
112 DeviceWrite(DISP_START_COLUMN);
113 DeviceWrite(CMD_END_COLUMN);
114 DeviceWrite(DISP_END_COLUMN);
115 DeviceWrite(CMD_START_PAGE);
116 DeviceWrite(DISP_START_PAGE);
117 DeviceWrite(CMD_END_PAGE);
118 DeviceWrite(DISP_END_PAGE);
119 DeviceWrite(CMD_WND_PRG_ENABLE);
120  
121 // set autoincrement
122 DeviceWrite(CMD_RAM_ADDR_INCR_ON);
123  
124 DeviceWrite(CMD_DISPLAY_ON);
125  
126 DeviceSetData();
127  
128 DeviceDeselect();
129 }
130  
131 /*********************************************************************
132 * Function: void ContrastSet(BYTE contrast)
133 *
134 * PreCondition: none
135 *
136 * Input: contrast value
137 *
138 * Output: none
139 *
140 * Side Effects: none
141 *
142 * Overview: sets contrast
143 *
144 * Note: none
145 *
146 ********************************************************************/
147 void ContrastSet(BYTE contrast)
148 {
149 DeviceSelect();
150 DeviceSetCommand();
151 DeviceWrite(CMD_CONTRAST);
152 DeviceWrite(contrast);
153 DeviceSetData(0;
154 DeviceDeselect();
155 }
156  
157 /*********************************************************************
158 * Function: void PutPixel(SHORT x, SHORT y)
159 *
160 * PreCondition: none
161 *
162 * Input: pixel position
163 *
164 * Output: none
165 *
166 * Side Effects: none
167 *
168 * Overview: puts pixel with current color at given position
169 *
170 * Note: none
171 *
172 ********************************************************************/
173 void PutPixel(SHORT x, SHORT y)
174 {
175 BYTE value;
176  
177 if(_clipRgn)
178 {
179 if(x < _clipLeft)
180 return;
181 if(x > _clipRight)
182 return;
183 if(y < _clipTop)
184 return;
185 if(y > _clipBottom)
186 return;
187 }
188  
189 x += DISP_START_COLUMN;
190  
191 DeviceSelect();
192  
193 // set address
194 DeviceSetCommand();
195 DeviceWrite(CMD_COLUMN_ADDR_LSB | (x & 0x0f));
196 DeviceWrite(CMD_COLUMN_ADDR_MSB | ((x >> 4) & 0x0f));
197 DeviceWrite(CMD_PAGE_ADDR | (DISP_START_PAGE + (y >> 2)));
198 DeviceSetData();
199  
200 // read 4 pixels
201 value = DeviceRead();
202 value = DeviceRead();
203  
204 // set pixel
205 switch(y & 0x03)
206 {
207 case 0: value &= 0 b11111100; value |= _color; break;
208 case 1: value &= 0 b11110011; value |= _color << 2; break;
209 case 2: value &= 0 b11001111; value |= _color << 4; break;
210 case 3: value &= 0 b00111111; value |= _color << 6; break;
211 }
212  
213 // set address
214 DeviceSetCommand();
215 DeviceWrite(CMD_COLUMN_ADDR_LSB | (x & 0x0f));
216 DeviceWrite(CMD_COLUMN_ADDR_MSB | ((x >> 4) & 0x0f));
217 DeviceWrite(CMD_PAGE_ADDR | (DISP_START_PAGE + (y >> 2)));
218 DeviceSetData();
219  
220 // write 4 pixels back
221 WriteData(value);
222  
223 DeviceDeselect();
224 }
225  
226 /*********************************************************************
227 * Function: WORD GetPixel(SHORT x, SHORT y)
228 *
229 * PreCondition: none
230 *
231 * Input: pixel position
232 *
233 * Output: pixel color
234 *
235 * Side Effects: none
236 *
237 * Overview: returns pixel at given position
238 *
239 * Note: none
240 *
241 ********************************************************************/
242 WORD GetPixel(SHORT x, SHORT y)
243 {
244 BYTE value;
245  
246 x += DISP_START_COLUMN;
247  
248 DeviceSelect();
249  
250 // set address
251 DeviceSetCommand();
252 DeviceWrite(CMD_COLUMN_ADDR_LSB | (x & 0x0f));
253 DeviceWrite(CMD_COLUMN_ADDR_MSB | ((x >> 4) & 0x0f));
254 DeviceWrite(CMD_PAGE_ADDR | (DISP_START_PAGE + (y >> 2)));
255 DeviceSetData();
256  
257 // read 4 pixels
258 value = DeviceRead();
259 value = DeviceRead();
260  
261 DeviceDeselect();
262  
263 // get pixel
264 switch(y & 0x03)
265 {
266 case 0: break;
267 case 1: value >>= 2; break;
268 case 2: value >>= 4; break;
269 case 3: value >>= 6; break;
270 }
271  
272 value &= 0x03;
273 return (value);
274 }
275  
276 /*********************************************************************
277 * Function: void ClearDevice(void)
278 *
279 * PreCondition: none
280 *
281 * Input: none
282 *
283 * Output: none
284 *
285 * Side Effects: none
286 *
287 * Overview: clears screen with current color
288 *
289 * Note: none
290 *
291 ********************************************************************/
292 void ClearDevice(void)
293 {
294 WORD counter;
295 BYTE pattern;
296  
297 pattern = _color;
298 pattern |= pattern << 2;
299 pattern |= pattern << 4;
300  
301 DeviceSelect();
302 DeviceSetCommand();
303 DeviceWrite(CMD_COLUMN_ADDR_LSB | (DISP_START_COLUMN & 0x0f));
304 DeviceWrite(CMD_COLUMN_ADDR_MSB | ((DISP_START_COLUMN >> 4) & 0x0f));
305 DeviceWrite(CMD_PAGE_ADDR | DISP_START_PAGE);
306 DeviceSetData();
307  
308 for(counter = 0; counter < (DWORD) (GetMaxX() + 1) * (GetMaxY() + 1) / 4; counter++)
309 {
310 WriteData(pattern);
311 }
312  
313 DeviceDeselect();
314 }
315  
316 /*********************************************************************
317 * Function: WORD PutImage(SHORT left, SHORT top, void* bitmap, BYTE stretch)
318 *
319 * PreCondition: none
320 *
321 * Input: left,top - left top image corner,
322 * bitmap - image pointer,
323 * stretch - image stretch factor
324 *
325 * Output: For NON-Blocking configuration:
326 * - Returns 0 when device is busy and the image is not yet completely drawn.
327 * - Returns 1 when the image is completely drawn.
328 * For Blocking configuration:
329 * - Always return 1.
330 *
331 * Side Effects: none
332 *
333 * Overview: outputs image starting from left,top coordinates
334 *
335 * Note: image must be located in flash
336 *
337 ********************************************************************/
338 WORD PutImage(SHORT left, SHORT top, void *bitmap, BYTE stretch)
339 {
340 FLASH_BYTE *flashAddress;
341 BYTE colorDepth;
342 BYTE colorTemp;
343  
344 #ifndef USE_NONBLOCKING_CONFIG
345 while(IsDeviceBusy() != 0);
346  
347 /* Ready */
348 #else
349 if(IsDeviceBusy() != 0)
350 return (0);
351 #endif
352  
353 // Save current color
354 colorTemp = _color;
355  
356 switch(*((SHORT *)bitmap))
357 {
358 #ifdef USE_BITMAP_FLASH
359  
360 case FLASH:
361  
362 // Image address
363 flashAddress = ((BITMAP_FLASH *)bitmap)->address;
364  
365 // Read color depth
366 colorDepth = *(flashAddress + 1);
367  
368 // Draw picture
369 switch(colorDepth)
370 {
371 case 1: PutImage1BPP(left, top, flashAddress, stretch); break;
372 case 4: PutImage4BPP(left, top, flashAddress, stretch); break;
373 default: break;
374 }
375  
376 break;
377 #endif
378 #ifdef USE_BITMAP_EXTERNAL
379  
380 case EXTERNAL:
381  
382 // Get color depth
383 ExternalMemoryCallback(bitmap, 1, 1, &colorDepth);
384  
385 // Draw picture
386 switch(colorDepth)
387 {
388 case 1: PutImage1BPPExt(left, top, bitmap, stretch); break;
389 case 4: PutImage4BPPExt(left, top, bitmap, stretch); break;
390 default: break;
391 }
392  
393 break;
394 #endif
395  
396 default:
397 break;
398 }
399  
400 // Restore current color
401 _color = colorTemp;
402 return (1);
403 }
404  
405 #ifdef USE_BITMAP_FLASH
406  
407 /*********************************************************************
408 * Function: void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch)
409 *
410 * PreCondition: none
411 *
412 * Input: left,top - left top image corner,
413 * bitmap - image pointer,
414 * stretch - image stretch factor
415 *
416 * Output: none
417 *
418 * Side Effects: none
419 *
420 * Overview: outputs monochrome image starting from left,top coordinates
421 *
422 * Note: image must be located in flash
423 *
424 ********************************************************************/
425 void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch)
426 {
427 register FLASH_BYTE *flashAddress;
428 register FLASH_BYTE *tempFlashAddress;
429 BYTE temp;
430 WORD sizeX, sizeY;
431 WORD x, y;
432 WORD cx, cy;
433 BYTE stretchX, stretchY;
434 BYTE palette[2];
435 BYTE mask;
436  
437 // Move pointer to size information
438 flashAddress = bitmap + 2;
439  
440 // Read image size
441 sizeY = *((FLASH_WORD *)flashAddress);
442 flashAddress += 2;
443 sizeX = *((FLASH_WORD *)flashAddress);
444 flashAddress += 2;
445 palette[0] = (BYTE) * (flashAddress + 1);
446 palette[0] >>= 3;
447 palette[0] &= 0x03;
448 flashAddress += 2;
449 palette[1] = (BYTE) * (flashAddress + 1);
450 palette[1] >>= 3;
451 palette[1] &= 0x03;
452 flashAddress += 2;
453  
454 cy = top;
455 for(y = 0; y < sizeY; y++)
456 {
457 tempFlashAddress = flashAddress;
458 for(stretchY = 0; stretchY < stretch; stretchY++)
459 {
460 flashAddress = tempFlashAddress;
461 cx = left;
462 mask = 0;
463 for(x = 0; x < sizeX; x++)
464 {
465  
466 // Read 8 pixels from flash
467 if(mask == 0)
468 {
469 temp = *flashAddress;
470 flashAddress++;
471 mask = 0x80;
472 }
473  
474 // Set color
475 if(mask & temp)
476 {
477 SetColor(palette[1]);
478 }
479 else
480 {
481 SetColor(palette[0]);
482 }
483  
484 // Write pixel to screen
485 for(stretchX = 0; stretchX < stretch; stretchX++)
486 {
487 PutPixel(cx++, cy);
488 }
489  
490 // Shift to the next pixel
491 mask >>= 1;
492 }
493  
494 cy++;
495 }
496 }
497 }
498  
499 /*********************************************************************
500 * Function: void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch)
501 *
502 * PreCondition: none
503 *
504 * Input: left,top - left top image corner, bitmap - image pointer,
505 * stretch - image stretch factor
506 *
507 * Output: none
508 *
509 * Side Effects: none
510 *
511 * Overview: outputs 16 color image starting from left,top coordinates
512 *
513 * Note: image must be located in flash
514 *
515 ********************************************************************/
516 void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch)
517 {
518 register FLASH_BYTE *flashAddress;
519 register FLASH_BYTE *tempFlashAddress;
520 WORD sizeX, sizeY;
521 WORD x, y;
522 WORD cx, cy;
523 BYTE temp;
524 register BYTE stretchX, stretchY;
525 BYTE palette[16];
526 WORD counter;
527  
528 // Move pointer to size information
529 flashAddress = bitmap + 2;
530  
531 // Read image size
532 sizeY = *((FLASH_WORD *)flashAddress);
533 flashAddress += 2;
534 sizeX = *((FLASH_WORD *)flashAddress);
535 flashAddress += 2;
536  
537 // Read pallete
538 for(counter = 0; counter < 16; counter++)
539 {
540 palette[counter] = (BYTE) * (flashAddress + 1);
541 palette[counter] >>= 3;
542 palette[counter] &= 0x03;
543 flashAddress += 2;
544 }
545  
546 cy = top;
547 for(y = 0; y < sizeY; y++)
548 {
549 tempFlashAddress = flashAddress;
550 for(stretchY = 0; stretchY < stretch; stretchY++)
551 {
552 flashAddress = tempFlashAddress;
553 cx = left;
554 for(x = 0; x < sizeX; x++)
555 {
556  
557 // Read 2 pixels from flash
558 if(x & 0x0001)
559 {
560  
561 // second pixel in byte
562 SetColor(palette[temp >> 4]);
563 }
564 else
565 {
566 temp = *flashAddress;
567 flashAddress++;
568  
569 // first pixel in byte
570 SetColor(palette[temp & 0x0f]);
571 }
572  
573 // Write pixel to screen
574 for(stretchX = 0; stretchX < stretch; stretchX++)
575 {
576 PutPixel(cx++, cy);
577 }
578 }
579  
580 cy++;
581 }
582 }
583 }
584  
585 #endif
586 #ifdef USE_BITMAP_EXTERNAL
587  
588 /*********************************************************************
589 * Function: void PutImage1BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch)
590 *
591 * PreCondition: none
592 *
593 * Input: left,top - left top image corner, bitmap - image pointer,
594 * stretch - image stretch factor
595 *
596 * Output: none
597 *
598 * Side Effects: none
599 *
600 * Overview: outputs monochrome image starting from left,top coordinates
601 *
602 * Note: image must be located in external memory
603 *
604 ********************************************************************/
605 void PutImage1BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch)
606 {
607 register DWORD memOffset;
608 BITMAP_HEADER bmp;
609 WORD pallete[2];
610 BYTE lineBuffer[((GetMaxX() + 1) / 8) + 1];
611 BYTE *pData;
612 SHORT byteWidth;
613  
614 BYTE temp;
615 BYTE mask;
616 WORD sizeX, sizeY;
617 WORD x, y;
618 WORD cx, cy;
619 BYTE stretchX, stretchY;
620  
621 // Get bitmap header
622 ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp);
623  
624 // Get pallete (2 entries)
625 ExternalMemoryCallback(bitmap, sizeof(BITMAP_HEADER), 2 * sizeof(WORD), palette);
626  
627 palette[0] >>= 3;
628 palette[0] &= 0x03;
629 palette[1] >>= 3;
630 palette[1] &= 0x03;
631  
632 // Set offset to the image data
633 memOffset = sizeof(BITMAP_HEADER) + 2 * sizeof(WORD);
634  
635 // Line width in bytes
636 byteWidth = bmp.width >> 3;
637 if(bmp.width & 0x0007)
638 byteWidth++;
639  
640 // Get size
641 sizeX = bmp.width;
642 sizeY = bmp.height;
643  
644 cy = top;
645 for(y = 0; y < sizeY; y++)
646 {
647  
648 // Get line
649 ExternalMemoryCallback(bitmap, memOffset, byteWidth, lineBuffer);
650 memOffset += byteWidth;
651 for(stretchY = 0; stretchY < stretch; stretchY++)
652 {
653 pData = lineBuffer;
654 cx = left;
655 mask = 0;
656 for(x = 0; x < sizeX; x++)
657 {
658  
659 // Read 8 pixels from flash
660 if(mask == 0)
661 {
662 temp = *pData++;
663 mask = 0x80;
664 }
665  
666 // Set color
667 if(mask & temp)
668 {
669 SetColor(palette[1]);
670 }
671 else
672 {
673 SetColor(palette[0]);
674 }
675  
676 // Write pixel to screen
677 for(stretchX = 0; stretchX < stretch; stretchX++)
678 {
679 PutPixel(cx++, cy);
680 }
681  
682 // Shift to the next pixel
683 mask >>= 1;
684 }
685  
686 cy++;
687 }
688 }
689 }
690  
691 /*********************************************************************
692 * Function: void PutImage4BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch)
693 *
694 * PreCondition: none
695 *
696 * Input: left,top - left top image corner, bitmap - image pointer,
697 * stretch - image stretch factor
698 *
699 * Output: none
700 *
701 * Side Effects: none
702 *
703 * Overview: outputs monochrome image starting from left,top coordinates
704 *
705 * Note: image must be located in external memory
706 *
707 ********************************************************************/
708 void PutImage4BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch)
709 {
710 register DWORD memOffset;
711 BITMAP_HEADER bmp;
712 WORD palette[16];
713 BYTE lineBuffer[((GetMaxX() + 1) / 2) + 1];
714 BYTE *pData;
715 SHORT byteWidth;
716  
717 BYTE temp;
718 WORD sizeX, sizeY;
719 WORD x, y;
720 WORD cx, cy;
721 BYTE stretchX, stretchY;
722  
723 // Get bitmap header
724 ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp);
725  
726 // Get pallete (16 entries)
727 ExternalMemoryCallback(bitmap, sizeof(BITMAP_HEADER), 16 * sizeof(WORD), palette);
728  
729 for(temp = 0; temp < 16; temp++)
730 {
731 palette[temp] >>= 3;
732 palette[temp] &= 0x03;
733 }
734  
735 // Set offset to the image data
736 memOffset = sizeof(BITMAP_HEADER) + 16 * sizeof(WORD);
737  
738 // Line width in bytes
739 byteWidth = bmp.width >> 1;
740 if(bmp.width & 0x0001)
741 byteWidth++;
742  
743 // Get size
744 sizeX = bmp.width;
745 sizeY = bmp.height;
746  
747 cy = top;
748 for(y = 0; y < sizeY; y++)
749 {
750  
751 // Get line
752 ExternalMemoryCallback(bitmap, memOffset, byteWidth, lineBuffer);
753 memOffset += byteWidth;
754 for(stretchY = 0; stretchY < stretch; stretchY++)
755 {
756 pData = lineBuffer;
757 cx = left;
758  
759 for(x = 0; x < sizeX; x++)
760 {
761  
762 // Read 2 pixels from flash
763 if(x & 0x0001)
764 {
765  
766 // second pixel in byte
767 SetColor(palette[temp >> 4]);
768 }
769 else
770 {
771 temp = *pData++;
772  
773 // first pixel in byte
774 SetColor(palette[temp & 0x0f]);
775 }
776  
777 // Write pixel to screen
778 for(stretchX = 0; stretchX < stretch; stretchX++)
779 {
780 PutPixel(cx++, cy);
781 }
782 }
783  
784 cy++;
785 }
786 }
787 }
788  
789 #endif
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3