?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 * LCD controller driver
4 * LG LGDP4531
5 * Renesas R61505
6 * Renesas R61580
7 * Samsung S6D0129
8 * Samsung S6D0139
9 * Orise Tech. SPFD5408
10 * Ilitek ILI9320
11 *****************************************************************************
12 * FileName: drvTFT001.c
13 * Dependencies: Graphics.h
14 * Processor: PIC24, PIC32
15 * Compiler: MPLAB C30, MPLAB C32
16 * Linker: MPLAB LINK30, MPLAB LINK32
17 * Company: Microchip Technology Incorporated
18 *
19 * Software License Agreement
20 *
21 * Copyright © 2008 Microchip Technology Inc. All rights reserved.
22 * Microchip licenses to you the right to use, modify, copy and distribute
23 * Software only when embedded on a Microchip microcontroller or digital
24 * signal controller, which is integrated into your product or third party
25 * product (pursuant to the sublicense terms in the accompanying license
26 * agreement).
27 *
28 * You should refer to the license agreement accompanying this Software
29 * for additional information regarding your rights and obligations.
30 *
31 * SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS” WITHOUT WARRANTY OF ANY
32 * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY
33 * OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR
34 * PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR
35 * OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION,
36 * BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT
37 * DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL,
38 * INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA,
39 * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY
40 * CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF),
41 * OR OTHER SIMILAR COSTS.
42 *
43 * Author Date Comment
44 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45 * Anton Alkhimenok 11/12/07 Version 1.0 release
46 * Anton Alkhimenok 01/30/08 combined version for landscape and portrait
47 * Sean Justice 01/30/08 PIC32 support
48 * Jayanth Murthy 06/25/09 dsPIC & PIC24H support
49 * Anton Alkhimenok 06/26/09 16-bit PMP support
50 *****************************************************************************/
51 #include "Graphics\Graphics.h"
52  
53 // Color
54 WORD _color;
55  
56 // Clipping region control
57 SHORT _clipRgn;
58  
59 // Clipping region borders
60 SHORT _clipLeft;
61 SHORT _clipTop;
62 SHORT _clipRight;
63 SHORT _clipBottom;
64  
65 /////////////////////// LOCAL FUNCTIONS PROTOTYPES ////////////////////////////
66 void SetReg(WORD index, WORD value);
67 void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch);
68 void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch);
69 void PutImage8BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch);
70 void PutImage16BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch);
71  
72 void PutImage1BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch);
73 void PutImage4BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch);
74 void PutImage8BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch);
75 void PutImage16BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch);
76  
77 /*********************************************************************
78 * Macro: WritePixel(color)
79 *
80 * PreCondition: none
81 *
82 * Input: color
83 *
84 * Output: none
85 *
86 * Side Effects: none
87 *
88 * Overview: writes pixel at the current address
89 *
90 * Note: chip select should be enabled
91 *
92 ********************************************************************/
93 #ifdef USE_16BIT_PMP
94 #define WritePixel(color) DeviceWrite(color)
95 #else
96 #define WritePixel(color) { DeviceWrite(((WORD_VAL)color).v[1]); DeviceWrite(((WORD_VAL)color).v[0]);}
97 #endif
98  
99 /*********************************************************************
100 * Macros: SetAddress(addr)
101 *
102 * Overview: Writes address pointer.
103 *
104 * PreCondition: none
105 *
106 * Input: add0 - 32-bit address.
107 *
108 * Output: none
109 *
110 * Side Effects: none
111 *
112 ********************************************************************/
113 #ifdef USE_16BIT_PMP
114 #define SetAddress(addr) \
115 {\
116 DeviceSetCommand(); \
117 DeviceWrite(0x0020); \
118 DeviceSetData(); \
119 DeviceWrite((WORD) addr & 0x00ff); \
120 DeviceSetCommand(); \
121 DeviceWrite(0x0021); \
122 DeviceSetData(); \
123 DeviceWrite((WORD) ((DWORD) addr >> 8));\
124 DeviceSetCommand(); \
125 DeviceWrite(0x0022); \
126 DeviceSetData(); \
127 }
128 #else
129 #define SetAddress(addr) \
130 {\
131 DeviceSetCommand(); \
132 DeviceWrite(0); \
133 DeviceWrite(0x20); \
134 DeviceSetData(); \
135 DeviceWrite(0); \
136 DeviceWrite(((DWORD_VAL) (DWORD) addr).v[0]);\
137 DeviceSetCommand(); \
138 DeviceWrite(0); \
139 DeviceWrite(0x21); \
140 DeviceSetData(); \
141 DeviceWrite(((DWORD_VAL) (DWORD) addr).v[2]);\
142 DeviceWrite(((DWORD_VAL) (DWORD) addr).v[1]);\
143 DeviceSetCommand(); \
144 DeviceWrite(0); \
145 DeviceWrite(0x22); \
146 DeviceSetData(); \
147 }
148 #endif
149  
150 /*********************************************************************
151 * Function: void SetReg(WORD index, WORD value)
152 *
153 * PreCondition: none
154 *
155 * Input: index - register number
156 * value - value to be set
157 *
158 * Output: none
159 *
160 * Side Effects: none
161 *
162 * Overview: sets graphics controller register
163 *
164 * Note: none
165 *
166 ********************************************************************/
167 void SetReg(WORD index, WORD value)
168 {
169 #ifdef USE_16BIT_PMP
170 DeviceSelect();
171 DeviceSetCommand();
172 DeviceWrite(index);
173 DeviceSetData();
174 DeviceWrite(value);
175 DeviceDeselect();
176 #else
177 DeviceSelect();
178 DeviceSetCommand();
179 DeviceWrite(((WORD_VAL)index).v[1]);
180 DeviceWrite(((WORD_VAL)index).v[0]);
181 DeviceSetData();
182 DeviceWrite(((WORD_VAL)value).v[1]);
183 DeviceWrite(((WORD_VAL)value).v[0]);
184 DeviceDeselect();
185 #endif
186 }
187  
188 /*********************************************************************
189 * Function: void ResetDevice()
190 *
191 * PreCondition: none
192 *
193 * Input: none
194 *
195 * Output: none
196 *
197 * Side Effects: none
198 *
199 * Overview: resets LCD, initializes PMP
200 *
201 * Note: none
202 *
203 ********************************************************************/
204 void ResetDevice(void)
205 {
206 // Set FLASH CS pin as output
207 CS_FLASH_TRIS_BIT = 0;
208  
209 // Initialize the device
210 DeviceInit();
211  
212 DelayMs(5);
213  
214 #if defined (GFX_PICTAIL_V2) || defined (GFX_PICTAIL_V250)
215 // Power on LCD
216 POWERON_LAT_BIT = 0;
217 POWERON_TRIS_BIT = 0;
218 #endif
219  
220 DelayMs(2);
221  
222 #if (DISPLAY_CONTROLLER == LGDP4531)
223  
224 /////////////////////////////////////////////////////////
225 // Synchronization after reset
226 DeviceSelect();
227 DeviceWrite(0);
228 DeviceWrite(0);
229 DeviceDeselect();
230  
231 // Setup display
232 SetReg(0x0010, 0x0628);
233 SetReg(0x0012, 0x0006);
234 SetReg(0x0013, 0x0A32);
235 SetReg(0x0011, 0x0040);
236 SetReg(0x0015, 0x0050);
237 SetReg(0x0012, 0x0016);
238 DelayMs(15);
239 SetReg(0x0010, 0x5660);
240 DelayMs(15);
241 SetReg(0x0013, 0x2A4E);
242 SetReg(0x0001, 0x0100);
243 SetReg(0x0002, 0x0300);
244  
245 #if (DISP_ORIENTATION == 0)
246 SetReg(0x0003, 0x1030);
247 #else
248 SetReg(0x0003, 0x1038);
249 #endif
250 SetReg(0x0008, 0x0202);
251 SetReg(0x000A, 0x0000);
252 SetReg(0x0030, 0x0000);
253 SetReg(0x0031, 0x0402);
254 SetReg(0x0032, 0x0106);
255 SetReg(0x0033, 0x0700);
256 SetReg(0x0034, 0x0104);
257 SetReg(0x0035, 0x0301);
258 SetReg(0x0036, 0x0707);
259 SetReg(0x0037, 0x0305);
260 SetReg(0x0038, 0x0208);
261 SetReg(0x0039, 0x0F0B);
262 DelayMs(15);
263 SetReg(0x0041, 0x0002);
264 SetReg(0x0060, 0x2700);
265 SetReg(0x0061, 0x0001);
266 SetReg(0x0090, 0x0119);
267 SetReg(0x0092, 0x010A);
268 SetReg(0x0093, 0x0004);
269 SetReg(0x00A0, 0x0100);
270 SetReg(0x0007, 0x0001);
271 DelayMs(15);
272 SetReg(0x0007, 0x0021);
273 DelayMs(15);
274 SetReg(0x0007, 0x0023);
275 DelayMs(15);
276 SetReg(0x0007, 0x0033);
277 DelayMs(15);
278 SetReg(0x0007, 0x0133);
279 DelayMs(15);
280 SetReg(0x00A0, 0x0000);
281 DelayMs(20);
282  
283 /////////////////////////////////////////////////////////
284 #elif (DISPLAY_CONTROLLER == R61505)
285  
286 // Setup display
287 SetReg(0x0000, 0x0000);
288 SetReg(0x0007, 0x0001);
289 DelayMs(5);
290 SetReg(0x0017, 0x0001);
291 DelayMs(5);
292 SetReg(0x0010, 0x17b0);
293 SetReg(0x0011, 0x0007);
294 SetReg(0x0012, 0x011a);
295 SetReg(0x0013, 0x0f00);
296 SetReg(0x0015, 0x0000);
297 SetReg(0x0029, 0x0009);
298 SetReg(0x00fd, 0x0000);
299 DelayMs(5);
300 SetReg(0x0012, 0x013a);
301 DelayMs(50);
302 SetReg(0x0001, 0x0100);
303 SetReg(0x0002, 0x0700);
304  
305 #if (DISP_ORIENTATION == 0)
306 SetReg(0x0003, 0x1030);
307 #else
308 SetReg(0x0003, 0x1038);
309 #endif
310 SetReg(0x0008, 0x0808);
311 SetReg(0x0009, 0x0000);
312 SetReg(0x000a, 0x0000);
313 SetReg(0x000c, 0x0000);
314 SetReg(0x000d, 0x0000);
315 SetReg(0x0030, 0x0000);
316 SetReg(0x0031, 0x0000);
317 SetReg(0x0032, 0x0000);
318 SetReg(0x0033, 0x0000);
319 SetReg(0x0034, 0x0000);
320 SetReg(0x0035, 0x0000);
321 SetReg(0x0036, 0x0000);
322 SetReg(0x0037, 0x0707);
323 SetReg(0x0038, 0x0707);
324 SetReg(0x0039, 0x0707);
325 SetReg(0x003a, 0x0303);
326 SetReg(0x003b, 0x0303);
327 SetReg(0x003c, 0x0707);
328 SetReg(0x003d, 0x0808);
329 SetReg(0x0050, 0x0000);
330 SetReg(0x0051, 0x00ef);
331 SetReg(0x0052, 0x0000);
332 SetReg(0x0053, 0x013f);
333 SetReg(0x0060, 0x2700);
334 SetReg(0x0061, 0x0001);
335 SetReg(0x006a, 0x0000);
336 SetReg(0x0090, 0x0010);
337 SetReg(0x0092, 0x0000);
338 SetReg(0x0093, 0x0000);
339 SetReg(0x0007, 0x0021);
340 DelayMs(1);
341 SetReg(0x0007, 0x0061);
342 DelayMs(50);
343 SetReg(0x0007, 0x0173);
344 SetReg(0x0020, 0x0000);
345 SetReg(0x0021, 0x0000);
346 SetReg(0x0022, 0x0000);
347 SetReg(0x0030, 0x0707);
348 SetReg(0x0031, 0x0407);
349 SetReg(0x0032, 0x0203);
350 SetReg(0x0033, 0x0303);
351 SetReg(0x0034, 0x0303);
352 SetReg(0x0035, 0x0202);
353 SetReg(0x0036, 0x001f);
354 SetReg(0x0037, 0x0707);
355 SetReg(0x0038, 0x0407);
356 SetReg(0x0039, 0x0203);
357 SetReg(0x003a, 0x0303);
358 SetReg(0x003b, 0x0303);
359 SetReg(0x003c, 0x0202);
360 SetReg(0x003d, 0x001f);
361 SetReg(0x0020, 0x0000);
362 SetReg(0x0021, 0x0000);
363  
364 /////////////////////////////////////////////////////////
365 #elif (DISPLAY_CONTROLLER == S6D0129) || (DISPLAY_CONTROLLER == S6D0139)
366  
367 // Setup display
368 SetReg(0x0000, 0x0001);
369 SetReg(0x0011, 0x1a00);
370 SetReg(0x0014, 0x2020);
371 SetReg(0x0010, 0x0900);
372 SetReg(0x0013, 0x0040);
373 SetReg(0x0013, 0x0060);
374 SetReg(0x0013, 0x0070);
375 SetReg(0x0011, 0x1a04);
376 SetReg(0x0010, 0x2f00);
377 SetReg(0x0001, 0x0127);
378 SetReg(0x0002, 0x0700);
379  
380 #if (DISP_ORIENTATION == 0)
381 SetReg(0x0003, 0x1030);
382 #else
383 SetReg(0x0003, 0x1038);
384 #endif
385 SetReg(0x0007, 0x0000);
386 SetReg(0x0008, 0x0808);
387 SetReg(0x0009, 0x0000);
388 SetReg(0x000b, 0x0000);
389 SetReg(0x000c, 0x0000);
390 SetReg(0x0040, 0x0000);
391 SetReg(0x0041, 0x0000);
392 SetReg(0x0042, 0x013f);
393 SetReg(0x0043, 0x0000);
394 SetReg(0x0044, 0x00ef);
395 SetReg(0x0045, 0x0000);
396 SetReg(0x0046, 0xef00);
397 SetReg(0x0047, 0x013f);
398 SetReg(0x0048, 0x0000);
399 SetReg(0x0007, 0x0014);
400 SetReg(0x0007, 0x0016);
401 SetReg(0x0007, 0x0017);
402 SetReg(0x0020, 0x0000);
403 SetReg(0x0021, 0x0000);
404 SetReg(0x0022, 0x0000);
405  
406 /////////////////////////////////////////////////////////
407 #elif (DISPLAY_CONTROLLER == SPFD5408)
408  
409 // Setup display
410 SetReg(0x0000, 0x0000);
411 SetReg(0x0001, 0x0000);
412 SetReg(0x0002, 0x0700);
413  
414 #if (DISP_ORIENTATION == 0)
415 SetReg(0x0003, 0x1010);
416 #else
417 SetReg(0x0003, 0x1028);
418 #endif
419 SetReg(0x0004, 0x0000);
420 SetReg(0x0008, 0x0207);
421 SetReg(0x0009, 0x0000);
422 SetReg(0x000a, 0x0000);
423 SetReg(0x000c, 0x0000);
424 SetReg(0x000d, 0x0000);
425 SetReg(0x000f, 0x0000);
426 SetReg(0x0007, 0x0101);
427 SetReg(0x0010, 0x12b0);
428 SetReg(0x0011, 0x0007);
429 SetReg(0x0017, 0x0001);
430 SetReg(0x0012, 0x01bb);
431 SetReg(0x0013, 0x1300);
432 SetReg(0x0029, 0x0010);
433  
434 SetReg(0x0030, 0x0100);
435 SetReg(0x0031, 0x0c19);
436 SetReg(0x0032, 0x111e);
437 SetReg(0x0033, 0x3819);
438 SetReg(0x0034, 0x350b);
439 SetReg(0x0035, 0x0e08);
440 SetReg(0x0036, 0x0d07);
441 SetReg(0x0037, 0x0318);
442 SetReg(0x0038, 0x0705);
443 SetReg(0x0039, 0x0303);
444 SetReg(0x003a, 0x0905);
445 SetReg(0x003b, 0x0801);
446 SetReg(0x003c, 0x030e);
447 SetReg(0x003d, 0x050d);
448 SetReg(0x003e, 0x0106);
449 SetReg(0x003f, 0x0408);
450  
451 SetReg(0x0050, 0x0000);
452 SetReg(0x0051, 0x00ef);
453 SetReg(0x0052, 0x0000);
454 SetReg(0x0053, 0x013f);
455 SetReg(0x0060, 0xa700);
456 SetReg(0x0061, 0x0001);
457 SetReg(0x006a, 0x0000);
458 SetReg(0x0080, 0x0000);
459 SetReg(0x0081, 0x0000);
460 SetReg(0x0082, 0x0000);
461 SetReg(0x0083, 0x0000);
462 SetReg(0x0084, 0x0000);
463 SetReg(0x0085, 0x0000);
464 SetReg(0x0090, 0x0010);
465 SetReg(0x0092, 0x0000);
466 SetReg(0x0093, 0x0103);
467 SetReg(0x0095, 0x0110);
468 SetReg(0x0097, 0x0000);
469 SetReg(0x0098, 0x0000);
470 SetReg(0x00f0, 0x5408);
471 SetReg(0x00f3, 0x0010);
472 SetReg(0x00f4, 0x001f);
473 SetReg(0x00f0, 0x0000);
474 SetReg(0x0007, 0x0133);
475  
476 /////////////////////////////////////////////////////////
477 #elif (DISPLAY_CONTROLLER == ILI9320)
478 SetReg(0x0000, 0x0001); //start Int. osc
479 DelayMs(15);
480 SetReg(0x0001, 0x0100); //Set SS bit (shift direction of outputs is from S720 to S1)
481 SetReg(0x0002, 0x0700); //select the line inversion
482 #if (DISP_ORIENTATION == 0)
483 SetReg(0x0003, 0x1030); //Entry mode(Horizontal : increment,Vertical : increment, AM=0)
484 #else
485 SetReg(0x0003, 0x1038); //Entry mode(Horizontal : increment,Vertical : increment, AM=1)
486 #endif
487 SetReg(0x0004, 0x0000); //Resize control(No resizing)
488 SetReg(0x0008, 0x0202); //front and back porch 2 lines
489 SetReg(0x0009, 0x0000); //select normal scan
490 SetReg(0x000A, 0x0000); //display control 4
491 SetReg(0x000C, 0x0000); //system interface(2 transfer /pixel), internal sys clock,
492 SetReg(0x000D, 0x0000); //Frame marker position
493 SetReg(0x000F, 0x0000); //selects clk, enable and sync signal polarity,
494 SetReg(0x0010, 0x0000); //
495 SetReg(0x0011, 0x0000); //power control 2 reference voltages = 1:1,
496 SetReg(0x0012, 0x0000); //power control 3 VRH
497 SetReg(0x0013, 0x0000); //power control 4 VCOM amplitude
498 DelayMs(20);
499 SetReg(0x0010, 0x17B0); //power control 1 BT,AP
500 SetReg(0x0011, 0x0137); //power control 2 DC,VC
501 DelayMs(50);
502 SetReg(0x0012, 0x0139); //power control 3 VRH
503 DelayMs(50);
504 SetReg(0x0013, 0x1d00); //power control 4 vcom amplitude
505 SetReg(0x0029, 0x0011); //power control 7 VCOMH
506 DelayMs(50);
507 SetReg(0x0030, 0x0007);
508 SetReg(0x0031, 0x0403);
509 SetReg(0x0032, 0x0404);
510 SetReg(0x0035, 0x0002);
511 SetReg(0x0036, 0x0707);
512 SetReg(0x0037, 0x0606);
513 SetReg(0x0038, 0x0106);
514 SetReg(0x0039, 0x0007);
515 SetReg(0x003c, 0x0700);
516 SetReg(0x003d, 0x0707);
517 SetReg(0x0020, 0x0000); //starting Horizontal GRAM Address
518 SetReg(0x0021, 0x0000); //starting Vertical GRAM Address
519 SetReg(0x0050, 0x0000); //Horizontal GRAM Start Position
520 SetReg(0x0051, 0x00EF); //Horizontal GRAM end Position
521 SetReg(0x0052, 0x0000); //Vertical GRAM Start Position
522 SetReg(0x0053, 0x013F); //Vertical GRAM end Position
523 SetReg(0x0060, 0x2700); //starts scanning from G1, and 320 drive lines
524 SetReg(0x0061, 0x0001); //fixed base display
525 SetReg(0x006a, 0x0000); //no scroll
526 SetReg(0x0090, 0x0010); //set Clocks/Line =16, Internal Operation Clock Frequency=fosc/1,
527 SetReg(0x0092, 0x0000); //set gate output non-overlap period=0
528 SetReg(0x0093, 0x0003); //set Source Output Position=3
529 SetReg(0x0095, 0x0110); //RGB interface(Clocks per line period=16 clocks)
530 SetReg(0x0097, 0x0110); //set Gate Non-overlap Period 0 locksc
531 SetReg(0x0098, 0x0110); //
532 SetReg(0x0007, 0x0173); //display On
533 /////////////////////////////////////////////////////////
534 #elif (DISPLAY_CONTROLLER == R61580)
535  
536 // Synchronization after reset
537 DelayMs(2);
538 SetReg(0x0000, 0x0000);
539 SetReg(0x0000, 0x0000);
540 SetReg(0x0000, 0x0000);
541 SetReg(0x0000, 0x0000);
542  
543 // Setup display
544 SetReg(0x00A4, 0x0001); // CALB=1
545 DelayMs(2);
546 SetReg(0x0060, 0xA700); // Driver Output Control
547 SetReg(0x0008, 0x0808); // Display Control BP=8, FP=8
548 SetReg(0x0030, 0x0111); // y control
549 SetReg(0x0031, 0x2410); // y control
550 SetReg(0x0032, 0x0501); // y control
551 SetReg(0x0033, 0x050C); // y control
552 SetReg(0x0034, 0x2211); // y control
553 SetReg(0x0035, 0x0C05); // y control
554 SetReg(0x0036, 0x2105); // y control
555 SetReg(0x0037, 0x1004); // y control
556 SetReg(0x0038, 0x1101); // y control
557 SetReg(0x0039, 0x1122); // y control
558 SetReg(0x0090, 0x0019); // 80Hz
559 SetReg(0x0010, 0x0530); // Power Control
560 SetReg(0x0011, 0x0237);
561 SetReg(0x0012, 0x01BF);
562 SetReg(0x0013, 0x1300);
563 DelayMs(100);
564  
565 SetReg(0x0001, 0x0100);
566 SetReg(0x0002, 0x0200);
567 #if (DISP_ORIENTATION == 0)
568 SetReg(0x0003, 0x1030);
569 #else
570 SetReg(0x0003, 0x1038);
571 #endif
572 SetReg(0x0009, 0x0001);
573 SetReg(0x000A, 0x0008);
574 SetReg(0x000C, 0x0001);
575 SetReg(0x000D, 0xD000);
576 SetReg(0x000E, 0x0030);
577 SetReg(0x000F, 0x0000);
578 SetReg(0x0020, 0x0000);
579 SetReg(0x0021, 0x0000);
580 SetReg(0x0029, 0x0077);
581 SetReg(0x0050, 0x0000);
582 SetReg(0x0051, 0xD0EF);
583 SetReg(0x0052, 0x0000);
584 SetReg(0x0053, 0x013F);
585 SetReg(0x0061, 0x0001);
586 SetReg(0x006A, 0x0000);
587 SetReg(0x0080, 0x0000);
588 SetReg(0x0081, 0x0000);
589 SetReg(0x0082, 0x005F);
590 SetReg(0x0093, 0x0701);
591 SetReg(0x0007, 0x0100);
592 SetReg(0x0022, 0x0000);
593 #else
594 #error Graphics controller is not supported.
595 #endif
596 DelayMs(20);
597 }
598  
599 /*********************************************************************
600 * Function: void PutPixel(SHORT x, SHORT y)
601 *
602 * PreCondition: none
603 *
604 * Input: x,y - pixel coordinates
605 *
606 * Output: none
607 *
608 * Side Effects: none
609 *
610 * Overview: puts pixel
611 *
612 * Note: none
613 *
614 ********************************************************************/
615 void PutPixel(SHORT x, SHORT y)
616 {
617 DWORD address;
618 if(_clipRgn)
619 {
620 if(x < _clipLeft)
621 return;
622 if(x > _clipRight)
623 return;
624 if(y < _clipTop)
625 return;
626 if(y > _clipBottom)
627 return;
628 }
629  
630 #if (DISP_ORIENTATION == 0)
631 address = (long)LINE_MEM_PITCH * y + x;
632  
633 #else
634 y = GetMaxY() - y;
635 address = (long)LINE_MEM_PITCH * x + y;
636 #endif
637 CS_LAT_BIT = 0;
638 SetAddress(address);
639 WritePixel(_color);
640 CS_LAT_BIT = 1;
641 }
642  
643 /*********************************************************************
644 * Function: WORD GetPixel(SHORT x, SHORT y)
645 *
646 * PreCondition: none
647 *
648 * Input: x,y - pixel coordinates
649 *
650 * Output: pixel color
651 *
652 * Side Effects: none
653 *
654 * Overview: returns pixel color at x,y position
655 *
656 * Note: none
657 *
658 ********************************************************************/
659 #ifndef __PIC24FJ256GB210__
660 #ifdef USE_16BIT_PMP
661  
662 /* */
663 WORD GetPixel(SHORT x, SHORT y)
664 {
665 DWORD address;
666 WORD result;
667 #if (DISP_ORIENTATION == 0)
668 address = (long)LINE_MEM_PITCH * y + x;
669 #else
670 y = GetMaxY() - y;
671 address = (long)LINE_MEM_PITCH * x + y;
672 #endif
673 CS_LAT_BIT = 0;
674  
675 SetAddress(address);
676  
677 // Temporary change wait cycles for reading (250ns = 4 cycles)
678 #if defined(__C30__)
679 PMMODEbits.WAITM = 4;
680 #elif defined(__PIC32MX__)
681 PMMODEbits.WAITM = 8;
682 #else
683 #error Need wait states for the device
684 #endif
685 RS_LAT_BIT = 1;
686  
687 // First RD cycle to move data from GRAM to Read Data Latch
688 result = PMDIN1;
689  
690 while(PMMODEbits.BUSY);
691  
692 // Second RD cycle to get data from Read Data Latch
693 result = PMDIN1;
694  
695 while(PMMODEbits.BUSY);
696  
697 // Disable LCD
698 CS_LAT_BIT = 1;
699  
700 // Disable PMP
701 PMCONbits.PMPEN = 1;
702  
703 // Read result
704 result = PMDIN1;
705  
706 // Restore wait cycles for writing (60ns)
707 #if defined(__dsPIC33F__) || defined(__PIC24H__)
708 PMMODEbits.WAITM = 2;
709 #else
710 PMMODEbits.WAITM = 1;
711 #endif
712  
713 // Enable PMP
714 PMCONbits.PMPEN = 1;
715  
716 return (result);
717 }
718  
719 #else
720  
721 /* */
722 WORD GetPixel(SHORT x, SHORT y)
723 {
724 DWORD address;
725 WORD_VAL result;
726  
727 #if (DISP_ORIENTATION == 0)
728 address = (long)LINE_MEM_PITCH * y + x;
729 #else
730 y = GetMaxY() - y;
731 address = (long)LINE_MEM_PITCH * x + y;
732 #endif
733 CS_LAT_BIT = 0;
734  
735 SetAddress(address);
736  
737 // Temporary change wait cycles for reading (250ns = 4 cycles)
738 #if defined(__C30__)
739 PMMODEbits.WAITM = 4;
740 #elif defined(__PIC32MX__)
741 PMMODEbits.WAITM = 8;
742 #else
743 #error Need wait states for the device
744 #endif
745 RS_LAT_BIT = 1;
746  
747 // First RD cycle to move data from GRAM to Read Data Latch
748 result.v[1] = PMDIN1;
749  
750 while(PMMODEbits.BUSY);
751  
752 #if (DISPLAY_CONTROLLER == ILI9320)
753 DelayForSync();
754 #endif
755  
756 // Second RD cycle to move data from GRAM to Read Data Latch
757 result.v[1] = PMDIN1;
758  
759 while(PMMODEbits.BUSY);
760 #if (DISPLAY_CONTROLLER == ILI9320)
761 DelayForSync();
762 #endif
763  
764 // First RD cycle to get data from Read Data Latch
765 // Read previous dummy value
766 result.v[1] = PMDIN1;
767  
768 while(PMMODEbits.BUSY);
769 #if (DISPLAY_CONTROLLER == ILI9320)
770 DelayForSync();
771 #endif
772  
773 // Second RD cycle to get data from Read Data Latch
774 // Read MSB
775 result.v[1] = PMDIN1;
776  
777 while(PMMODEbits.BUSY);
778 #if (DISPLAY_CONTROLLER == ILI9320)
779 DelayForSync();
780 #endif
781  
782 // Disable LCD
783 CS_LAT_BIT = 1;
784  
785 // Disable PMP
786 PMCONbits.PMPEN = 1;
787  
788 // Read LSB
789 result.v[0] = PMDIN1;
790 #if (DISPLAY_CONTROLLER == ILI9320)
791 DelayForSync();
792 #endif
793  
794 // Restore wait cycles for writing (60ns)
795 #if defined(__dsPIC33F__) || defined(__PIC24H__)
796 PMMODEbits.WAITM = 2;
797 #else
798 PMMODEbits.WAITM = 1;
799 #endif
800  
801 // Enable PMP
802 PMCONbits.PMPEN = 1;
803  
804 return (result.Val);
805 }
806  
807 #endif
808 #endif
809  
810 /*********************************************************************
811 * Function: WORD Bar(SHORT left, SHORT top, SHORT right, SHORT bottom)
812 *
813 * PreCondition: none
814 *
815 * Input: left,top - top left corner coordinates,
816 * right,bottom - bottom right corner coordinates
817 *
818 * Output: For NON-Blocking configuration:
819 * - Returns 0 when device is busy and the shape is not yet completely drawn.
820 * - Returns 1 when the shape is completely drawn.
821 * For Blocking configuration:
822 * - Always return 1.
823 *
824 * Side Effects: none
825 *
826 * Overview: draws rectangle filled with current color
827 *
828 * Note: none
829 *
830 ********************************************************************/
831 WORD Bar(SHORT left, SHORT top, SHORT right, SHORT bottom)
832 {
833 DWORD address;
834 register SHORT x, y;
835  
836 #ifndef USE_NONBLOCKING_CONFIG
837 while(IsDeviceBusy() != 0);
838  
839 /* Ready */
840 #else
841 if(IsDeviceBusy() != 0)
842 return (0);
843 #endif
844 if(_clipRgn)
845 {
846 if(left < _clipLeft)
847 left = _clipLeft;
848 if(right > _clipRight)
849 right = _clipRight;
850 if(top < _clipTop)
851 top = _clipTop;
852 if(bottom > _clipBottom)
853 bottom = _clipBottom;
854 }
855  
856 #if (DISP_ORIENTATION == 0)
857 address = (DWORD) LINE_MEM_PITCH * top + left;
858  
859 CS_LAT_BIT = 0;
860 for(y = top; y < bottom + 1; y++)
861 {
862 SetAddress(address);
863 for(x = left; x < right + 1; x++)
864 {
865 WritePixel(_color);
866 }
867  
868 address += LINE_MEM_PITCH;
869 }
870  
871 CS_LAT_BIT = 1;
872  
873 #else
874 top = GetMaxY() - top;
875 bottom = GetMaxY() - bottom;
876 address = (DWORD) LINE_MEM_PITCH * left + top;
877  
878 CS_LAT_BIT = 0;
879 for(y = bottom; y < top + 1; y++)
880 {
881 SetAddress(address);
882 for(x = left; x < right + 1; x++)
883 {
884 WritePixel(_color);
885 }
886  
887 address -= 1;
888 }
889  
890 CS_LAT_BIT = 1;
891 #endif
892 return (1);
893 }
894  
895 /*********************************************************************
896 * Function: void ClearDevice(void)
897 *
898 * PreCondition: none
899 *
900 * Input: none
901 *
902 * Output: none
903 *
904 * Side Effects: none
905 *
906 * Overview: clears screen with current color
907 *
908 * Note: none
909 *
910 ********************************************************************/
911 void ClearDevice(void)
912 {
913 DWORD counter;
914  
915 CS_LAT_BIT = 0;
916 SetAddress(0);
917 for(counter = 0; counter < (DWORD) (GetMaxX() + 1) * (GetMaxY() + 1); counter++)
918 {
919 WritePixel(_color);
920 }
921  
922 CS_LAT_BIT = 1;
923 }
924  
925 /*********************************************************************
926 * Function: WORD PutImage(SHORT left, SHORT top, void* bitmap, BYTE stretch)
927 *
928 * PreCondition: none
929 *
930 * Input: left,top - left top image corner,
931 * bitmap - image pointer,
932 * stretch - image stretch factor
933 *
934 * Output: For NON-Blocking configuration:
935 * - Returns 0 when device is busy and the image is not yet completely drawn.
936 * - Returns 1 when the image is completely drawn.
937 * For Blocking configuration:
938 * - Always return 1.
939 *
940 * Side Effects: none
941 *
942 * Overview: outputs image starting from left,top coordinates
943 *
944 * Note: image must be located in flash
945 *
946 ********************************************************************/
947 #ifdef USE_DRV_PUTIMAGE
948  
949 /* */
950 WORD PutImage(SHORT left, SHORT top, void *bitmap, BYTE stretch)
951 {
952 #if defined (USE_BITMAP_FLASH) || defined (USE_BITMAP_EXTERNAL)
953 FLASH_BYTE *flashAddress;
954 BYTE colorDepth;
955 #endif
956 WORD colorTemp;
957  
958 #ifndef USE_NONBLOCKING_CONFIG
959 while(IsDeviceBusy() != 0);
960  
961 /* Ready */
962 #else
963 if(IsDeviceBusy() != 0)
964 return (0);
965 #endif
966 #if (DISP_ORIENTATION == 90)
967 top = GetMaxY() - top;
968 #endif
969  
970 // Save current color
971 colorTemp = _color;
972  
973 switch(*((SHORT *)bitmap))
974 {
975 #ifdef USE_BITMAP_FLASH
976  
977 case FLASH:
978  
979 // Image address
980 flashAddress = ((BITMAP_FLASH *)bitmap)->address;
981  
982 // Read color depth
983 colorDepth = *(flashAddress + 1);
984  
985 // Draw picture
986 switch(colorDepth)
987 {
988 case 1: PutImage1BPP(left, top, flashAddress, stretch); break;
989 case 4: PutImage4BPP(left, top, flashAddress, stretch); break;
990 case 8: PutImage8BPP(left, top, flashAddress, stretch); break;
991 case 16: PutImage16BPP(left, top, flashAddress, stretch); break;
992 }
993  
994 break;
995 #endif
996 #ifdef USE_BITMAP_EXTERNAL
997  
998 case EXTERNAL:
999  
1000 // Get color depth
1001 ExternalMemoryCallback(bitmap, 1, 1, &colorDepth);
1002  
1003 // Draw picture
1004 switch(colorDepth)
1005 {
1006 case 1: PutImage1BPPExt(left, top, bitmap, stretch); break;
1007 case 4: PutImage4BPPExt(left, top, bitmap, stretch); break;
1008 case 8: PutImage8BPPExt(left, top, bitmap, stretch); break;
1009 case 16: PutImage16BPPExt(left, top, bitmap, stretch); break;
1010 default: break;
1011 }
1012  
1013 break;
1014 #endif
1015  
1016 default:
1017 break;
1018 }
1019  
1020 // Restore current color
1021 _color = colorTemp;
1022 return (1);
1023 }
1024  
1025 #ifdef USE_BITMAP_FLASH
1026  
1027 /*********************************************************************
1028 * Function: void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch)
1029 *
1030 * PreCondition: none
1031 *
1032 * Input: left,top - left top image corner,
1033 * bitmap - image pointer,
1034 * stretch - image stretch factor
1035 *
1036 * Output: none
1037 *
1038 * Side Effects: none
1039 *
1040 * Overview: outputs monochrome image starting from left,top coordinates
1041 *
1042 * Note: image must be located in flash
1043 *
1044 ********************************************************************/
1045 void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch)
1046 {
1047 register DWORD address;
1048 register FLASH_BYTE *flashAddress;
1049 register FLASH_BYTE *tempFlashAddress;
1050 BYTE temp = 0;
1051 WORD sizeX, sizeY;
1052 WORD x, y;
1053 BYTE stretchX, stretchY;
1054 WORD pallete[2];
1055 BYTE mask;
1056  
1057 // Move pointer to size information
1058 flashAddress = bitmap + 2;
1059  
1060 // Set start address
1061 #if (DISP_ORIENTATION == 0)
1062 address = (long)LINE_MEM_PITCH * top + left;
1063 #else
1064 address = (long)LINE_MEM_PITCH * left + top;
1065 #endif
1066  
1067 // Read image size
1068 sizeY = *((FLASH_WORD *)flashAddress);
1069 flashAddress += 2;
1070 sizeX = *((FLASH_WORD *)flashAddress);
1071 flashAddress += 2;
1072 pallete[0] = *((FLASH_WORD *)flashAddress);
1073 flashAddress += 2;
1074 pallete[1] = *((FLASH_WORD *)flashAddress);
1075 flashAddress += 2;
1076  
1077 CS_LAT_BIT = 0;
1078 for(y = 0; y < sizeY; y++)
1079 {
1080 tempFlashAddress = flashAddress;
1081 for(stretchY = 0; stretchY < stretch; stretchY++)
1082 {
1083 flashAddress = tempFlashAddress;
1084 SetAddress(address);
1085 mask = 0;
1086 for(x = 0; x < sizeX; x++)
1087 {
1088  
1089 // Read 8 pixels from flash
1090 if(mask == 0)
1091 {
1092 temp = *flashAddress;
1093 flashAddress++;
1094 mask = 0x80;
1095 }
1096  
1097 // Set color
1098 if(mask & temp)
1099 {
1100 SetColor(pallete[1]);
1101 }
1102 else
1103 {
1104 SetColor(pallete[0]);
1105 }
1106  
1107 // Write pixel to screen
1108 for(stretchX = 0; stretchX < stretch; stretchX++)
1109 {
1110 WritePixel(_color);
1111 }
1112  
1113 // Shift to the next pixel
1114 mask >>= 1;
1115 }
1116  
1117 #if (DISP_ORIENTATION == 0)
1118 address += LINE_MEM_PITCH;
1119 #else
1120 address -= 1;
1121 #endif
1122 }
1123 }
1124  
1125 CS_LAT_BIT = 1;
1126 }
1127  
1128 /*********************************************************************
1129 * Function: void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch)
1130 *
1131 * PreCondition: none
1132 *
1133 * Input: left,top - left top image corner, bitmap - image pointer,
1134 * stretch - image stretch factor
1135 *
1136 * Output: none
1137 *
1138 * Side Effects: none
1139 *
1140 * Overview: outputs 16 color image starting from left,top coordinates
1141 *
1142 * Note: image must be located in flash
1143 *
1144 ********************************************************************/
1145 void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch)
1146 {
1147 register DWORD address;
1148 register FLASH_BYTE *flashAddress;
1149 register FLASH_BYTE *tempFlashAddress;
1150 WORD sizeX, sizeY;
1151 register WORD x, y;
1152 BYTE temp = 0;
1153 register BYTE stretchX, stretchY;
1154 WORD pallete[16];
1155 WORD counter;
1156  
1157 // Move pointer to size information
1158 flashAddress = bitmap + 2;
1159  
1160 // Set start address
1161 #if (DISP_ORIENTATION == 0)
1162 address = (long)LINE_MEM_PITCH * top + left;
1163 #else
1164 address = (long)LINE_MEM_PITCH * left + top;
1165 #endif
1166  
1167 // Read image size
1168 sizeY = *((FLASH_WORD *)flashAddress);
1169 flashAddress += 2;
1170 sizeX = *((FLASH_WORD *)flashAddress);
1171 flashAddress += 2;
1172  
1173 // Read pallete
1174 for(counter = 0; counter < 16; counter++)
1175 {
1176 pallete[counter] = *((FLASH_WORD *)flashAddress);
1177 flashAddress += 2;
1178 }
1179  
1180 CS_LAT_BIT = 0;
1181 for(y = 0; y < sizeY; y++)
1182 {
1183 tempFlashAddress = flashAddress;
1184 for(stretchY = 0; stretchY < stretch; stretchY++)
1185 {
1186 flashAddress = tempFlashAddress;
1187 SetAddress(address);
1188 for(x = 0; x < sizeX; x++)
1189 {
1190  
1191 // Read 2 pixels from flash
1192 if(x & 0x0001)
1193 {
1194  
1195 // second pixel in byte
1196 SetColor(pallete[temp >> 4]);
1197 }
1198 else
1199 {
1200 temp = *flashAddress;
1201 flashAddress++;
1202  
1203 // first pixel in byte
1204 SetColor(pallete[temp & 0x0f]);
1205 }
1206  
1207 // Write pixel to screen
1208 for(stretchX = 0; stretchX < stretch; stretchX++)
1209 {
1210 WritePixel(_color);
1211 }
1212  
1213 // Shift to the next pixel
1214 //temp >>= 4;
1215 }
1216  
1217 #if (DISP_ORIENTATION == 0)
1218 address += LINE_MEM_PITCH;
1219 #else
1220 address -= 1;
1221 #endif
1222 }
1223 }
1224  
1225 CS_LAT_BIT = 1;
1226 }
1227  
1228 /*********************************************************************
1229 * Function: void PutImage8BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch)
1230 *
1231 * PreCondition: none
1232 *
1233 * Input: left,top - left top image corner, bitmap - image pointer,
1234 * stretch - image stretch factor
1235 *
1236 * Output: none
1237 *
1238 * Side Effects: none
1239 *
1240 * Overview: outputs 256 color image starting from left,top coordinates
1241 *
1242 * Note: image must be located in flash
1243 *
1244 ********************************************************************/
1245 void PutImage8BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch)
1246 {
1247 register DWORD address;
1248 register FLASH_BYTE *flashAddress;
1249 register FLASH_BYTE *tempFlashAddress;
1250 WORD sizeX, sizeY;
1251 WORD x, y;
1252 BYTE temp;
1253 BYTE stretchX, stretchY;
1254 WORD pallete[256];
1255 WORD counter;
1256  
1257 // Move pointer to size information
1258 flashAddress = bitmap + 2;
1259  
1260 // Set start address
1261 #if (DISP_ORIENTATION == 0)
1262 address = (long)LINE_MEM_PITCH * top + left;
1263 #else
1264 address = (long)LINE_MEM_PITCH * left + top;
1265 #endif
1266  
1267 // Read image size
1268 sizeY = *((FLASH_WORD *)flashAddress);
1269 flashAddress += 2;
1270 sizeX = *((FLASH_WORD *)flashAddress);
1271 flashAddress += 2;
1272  
1273 // Read pallete
1274 for(counter = 0; counter < 256; counter++)
1275 {
1276 pallete[counter] = *((FLASH_WORD *)flashAddress);
1277 flashAddress += 2;
1278 }
1279  
1280 CS_LAT_BIT = 0;
1281 for(y = 0; y < sizeY; y++)
1282 {
1283 tempFlashAddress = flashAddress;
1284 for(stretchY = 0; stretchY < stretch; stretchY++)
1285 {
1286 flashAddress = tempFlashAddress;
1287 SetAddress(address);
1288 for(x = 0; x < sizeX; x++)
1289 {
1290  
1291 // Read pixels from flash
1292 temp = *flashAddress;
1293 flashAddress++;
1294  
1295 // Set color
1296 SetColor(pallete[temp]);
1297  
1298 // Write pixel to screen
1299 for(stretchX = 0; stretchX < stretch; stretchX++)
1300 {
1301 WritePixel(_color);
1302 }
1303 }
1304  
1305 #if (DISP_ORIENTATION == 0)
1306 address += LINE_MEM_PITCH;
1307 #else
1308 address -= 1;
1309 #endif
1310 }
1311 }
1312  
1313 CS_LAT_BIT = 1;
1314 }
1315  
1316 /*********************************************************************
1317 * Function: void PutImage16BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch)
1318 *
1319 * PreCondition: none
1320 *
1321 * Input: left,top - left top image corner, bitmap - image pointer,
1322 * stretch - image stretch factor
1323 *
1324 * Output: none
1325 *
1326 * Side Effects: none
1327 *
1328 * Overview: outputs hicolor image starting from left,top coordinates
1329 *
1330 * Note: image must be located in flash
1331 *
1332 ********************************************************************/
1333 void PutImage16BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch)
1334 {
1335 register DWORD address;
1336 register FLASH_WORD *flashAddress;
1337 register FLASH_WORD *tempFlashAddress;
1338 WORD sizeX, sizeY;
1339 register WORD x, y;
1340 WORD temp;
1341 register BYTE stretchX, stretchY;
1342  
1343 // Move pointer to size information
1344 flashAddress = (FLASH_WORD *)bitmap + 1;
1345  
1346 // Set start address
1347 #if (DISP_ORIENTATION == 0)
1348 address = (long)LINE_MEM_PITCH * top + left;
1349 #else
1350 address = (long)LINE_MEM_PITCH * left + top;
1351 #endif
1352  
1353 // Read image size
1354 sizeY = *flashAddress;
1355 flashAddress++;
1356 sizeX = *flashAddress;
1357 flashAddress++;
1358  
1359 CS_LAT_BIT = 0;
1360 for(y = 0; y < sizeY; y++)
1361 {
1362 tempFlashAddress = flashAddress;
1363 for(stretchY = 0; stretchY < stretch; stretchY++)
1364 {
1365 flashAddress = tempFlashAddress;
1366 SetAddress(address);
1367 for(x = 0; x < sizeX; x++)
1368 {
1369  
1370 // Read pixels from flash
1371 temp = *flashAddress;
1372 flashAddress++;
1373  
1374 // Set color
1375 SetColor(temp);
1376  
1377 // Write pixel to screen
1378 for(stretchX = 0; stretchX < stretch; stretchX++)
1379 {
1380 WritePixel(_color);
1381 }
1382 }
1383  
1384 #if (DISP_ORIENTATION == 0)
1385 address += LINE_MEM_PITCH;
1386 #else
1387 address -= 1;
1388 #endif
1389 }
1390 }
1391  
1392 CS_LAT_BIT = 1;
1393 }
1394  
1395 #endif
1396 #ifdef USE_BITMAP_EXTERNAL
1397  
1398 /*********************************************************************
1399 * Function: void PutImage1BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch)
1400 *
1401 * PreCondition: none
1402 *
1403 * Input: left,top - left top image corner, bitmap - image pointer,
1404 * stretch - image stretch factor
1405 *
1406 * Output: none
1407 *
1408 * Side Effects: none
1409 *
1410 * Overview: outputs monochrome image starting from left,top coordinates
1411 *
1412 * Note: image must be located in external memory
1413 *
1414 ********************************************************************/
1415 void PutImage1BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch)
1416 {
1417 register DWORD address;
1418 register DWORD memOffset;
1419 BITMAP_HEADER bmp;
1420 WORD pallete[2];
1421 BYTE lineBuffer[((GetMaxX() + 1) / 8) + 1];
1422 BYTE *pData;
1423 SHORT byteWidth;
1424  
1425 BYTE temp = 0;
1426 BYTE mask;
1427 WORD sizeX, sizeY;
1428 WORD x, y;
1429 BYTE stretchX, stretchY;
1430  
1431 // Set start address
1432 #if (DISP_ORIENTATION == 0)
1433 address = (long)LINE_MEM_PITCH * top + left;
1434 #else
1435 address = (long)LINE_MEM_PITCH * left + top;
1436 #endif
1437  
1438 // Get bitmap header
1439 ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp);
1440  
1441 // Get pallete (2 entries)
1442 ExternalMemoryCallback(bitmap, sizeof(BITMAP_HEADER), 2 * sizeof(WORD), pallete);
1443  
1444 // Set offset to the image data
1445 memOffset = sizeof(BITMAP_HEADER) + 2 * sizeof(WORD);
1446  
1447 // Line width in bytes
1448 byteWidth = bmp.width >> 3;
1449 if(bmp.width & 0x0007)
1450 byteWidth++;
1451  
1452 // Get size
1453 sizeX = bmp.width;
1454 sizeY = bmp.height;
1455  
1456 for(y = 0; y < sizeY; y++)
1457 {
1458  
1459 // Get line
1460 ExternalMemoryCallback(bitmap, memOffset, byteWidth, lineBuffer);
1461 memOffset += byteWidth;
1462 CS_LAT_BIT = 0;
1463 for(stretchY = 0; stretchY < stretch; stretchY++)
1464 {
1465 pData = lineBuffer;
1466 SetAddress(address);
1467 mask = 0;
1468 for(x = 0; x < sizeX; x++)
1469 {
1470  
1471 // Read 8 pixels from flash
1472 if(mask == 0)
1473 {
1474 temp = *pData++;
1475 mask = 0x80;
1476 }
1477  
1478 // Set color
1479 if(mask & temp)
1480 {
1481 SetColor(pallete[1]);
1482 }
1483 else
1484 {
1485 SetColor(pallete[0]);
1486 }
1487  
1488 // Write pixel to screen
1489 for(stretchX = 0; stretchX < stretch; stretchX++)
1490 {
1491 WritePixel(_color);
1492 }
1493  
1494 // Shift to the next pixel
1495 mask >>= 1;
1496 }
1497  
1498 #if (DISP_ORIENTATION == 0)
1499 address += LINE_MEM_PITCH;
1500 #else
1501 address -= 1;
1502 #endif
1503 }
1504  
1505 CS_LAT_BIT = 1;
1506 }
1507 }
1508  
1509 /*********************************************************************
1510 * Function: void PutImage4BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch)
1511 *
1512 * PreCondition: none
1513 *
1514 * Input: left,top - left top image corner, bitmap - image pointer,
1515 * stretch - image stretch factor
1516 *
1517 * Output: none
1518 *
1519 * Side Effects: none
1520 *
1521 * Overview: outputs monochrome image starting from left,top coordinates
1522 *
1523 * Note: image must be located in external memory
1524 *
1525 ********************************************************************/
1526 void PutImage4BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch)
1527 {
1528 register DWORD address;
1529 register DWORD memOffset;
1530 BITMAP_HEADER bmp;
1531 WORD pallete[16];
1532 BYTE lineBuffer[((GetMaxX() + 1) / 2) + 1];
1533 BYTE *pData;
1534 SHORT byteWidth;
1535  
1536 BYTE temp = 0;
1537 WORD sizeX, sizeY;
1538 WORD x, y;
1539 BYTE stretchX, stretchY;
1540  
1541 // Set start address
1542 #if (DISP_ORIENTATION == 0)
1543 address = (long)LINE_MEM_PITCH * top + left;
1544 #else
1545 address = (long)LINE_MEM_PITCH * left + top;
1546 #endif
1547  
1548 // Get bitmap header
1549 ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp);
1550  
1551 // Get pallete (16 entries)
1552 ExternalMemoryCallback(bitmap, sizeof(BITMAP_HEADER), 16 * sizeof(WORD), pallete);
1553  
1554 // Set offset to the image data
1555 memOffset = sizeof(BITMAP_HEADER) + 16 * sizeof(WORD);
1556  
1557 // Line width in bytes
1558 byteWidth = bmp.width >> 1;
1559 if(bmp.width & 0x0001)
1560 byteWidth++;
1561  
1562 // Get size
1563 sizeX = bmp.width;
1564 sizeY = bmp.height;
1565  
1566 for(y = 0; y < sizeY; y++)
1567 {
1568  
1569 // Get line
1570 ExternalMemoryCallback(bitmap, memOffset, byteWidth, lineBuffer);
1571 memOffset += byteWidth;
1572 CS_LAT_BIT = 0;
1573 for(stretchY = 0; stretchY < stretch; stretchY++)
1574 {
1575 pData = lineBuffer;
1576 SetAddress(address);
1577  
1578 for(x = 0; x < sizeX; x++)
1579 {
1580  
1581 // Read 2 pixels from flash
1582 if(x & 0x0001)
1583 {
1584  
1585 // second pixel in byte
1586 SetColor(pallete[temp >> 4]);
1587 }
1588 else
1589 {
1590 temp = *pData++;
1591  
1592 // first pixel in byte
1593 SetColor(pallete[temp & 0x0f]);
1594 }
1595  
1596 // Write pixel to screen
1597 for(stretchX = 0; stretchX < stretch; stretchX++)
1598 {
1599 WritePixel(_color);
1600 }
1601 }
1602  
1603 #if (DISP_ORIENTATION == 0)
1604 address += LINE_MEM_PITCH;
1605 #else
1606 address -= 1;
1607 #endif
1608 }
1609  
1610 CS_LAT_BIT = 1;
1611 }
1612 }
1613  
1614 /*********************************************************************
1615 * Function: void PutImage8BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch)
1616 *
1617 * PreCondition: none
1618 *
1619 * Input: left,top - left top image corner, bitmap - image pointer,
1620 * stretch - image stretch factor
1621 *
1622 * Output: none
1623 *
1624 * Side Effects: none
1625 *
1626 * Overview: outputs monochrome image starting from left,top coordinates
1627 *
1628 * Note: image must be located in external memory
1629 *
1630 ********************************************************************/
1631 void PutImage8BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch)
1632 {
1633 register DWORD address;
1634 register DWORD memOffset;
1635 BITMAP_HEADER bmp;
1636 WORD pallete[256];
1637 BYTE lineBuffer[(GetMaxX() + 1)];
1638 BYTE *pData;
1639  
1640 BYTE temp;
1641 WORD sizeX, sizeY;
1642 WORD x, y;
1643 BYTE stretchX, stretchY;
1644  
1645 // Set start address
1646 #if (DISP_ORIENTATION == 0)
1647 address = (long)LINE_MEM_PITCH * top + left;
1648 #else
1649 address = (long)LINE_MEM_PITCH * left + top;
1650 #endif
1651  
1652 // Get bitmap header
1653 ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp);
1654  
1655 // Get pallete (256 entries)
1656 ExternalMemoryCallback(bitmap, sizeof(BITMAP_HEADER), 256 * sizeof(WORD), pallete);
1657  
1658 // Set offset to the image data
1659 memOffset = sizeof(BITMAP_HEADER) + 256 * sizeof(WORD);
1660  
1661 // Get size
1662 sizeX = bmp.width;
1663 sizeY = bmp.height;
1664  
1665 for(y = 0; y < sizeY; y++)
1666 {
1667  
1668 // Get line
1669 ExternalMemoryCallback(bitmap, memOffset, sizeX, lineBuffer);
1670 memOffset += sizeX;
1671 CS_LAT_BIT = 0;
1672 for(stretchY = 0; stretchY < stretch; stretchY++)
1673 {
1674 pData = lineBuffer;
1675 SetAddress(address);
1676  
1677 for(x = 0; x < sizeX; x++)
1678 {
1679 temp = *pData++;
1680 SetColor(pallete[temp]);
1681  
1682 // Write pixel to screen
1683 for(stretchX = 0; stretchX < stretch; stretchX++)
1684 {
1685 WritePixel(_color);
1686 }
1687 }
1688  
1689 #if (DISP_ORIENTATION == 0)
1690 address += LINE_MEM_PITCH;
1691 #else
1692 address -= 1;
1693 #endif
1694 }
1695  
1696 CS_LAT_BIT = 1;
1697 }
1698 }
1699  
1700 /*********************************************************************
1701 * Function: void PutImage16BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch)
1702 *
1703 * PreCondition: none
1704 *
1705 * Input: left,top - left top image corner, bitmap - image pointer,
1706 * stretch - image stretch factor
1707 *
1708 * Output: none
1709 *
1710 * Side Effects: none
1711 *
1712 * Overview: outputs monochrome image starting from left,top coordinates
1713 *
1714 * Note: image must be located in external memory
1715 *
1716 ********************************************************************/
1717 void PutImage16BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch)
1718 {
1719 register DWORD address;
1720 register DWORD memOffset;
1721 BITMAP_HEADER bmp;
1722 WORD lineBuffer[(GetMaxX() + 1)];
1723 WORD *pData;
1724 WORD byteWidth;
1725  
1726 WORD temp;
1727 WORD sizeX, sizeY;
1728 WORD x, y;
1729 BYTE stretchX, stretchY;
1730  
1731 // Set start address
1732 #if (DISP_ORIENTATION == 0)
1733 address = (long)LINE_MEM_PITCH * top + left;
1734 #else
1735 address = (long)LINE_MEM_PITCH * left + top;
1736 #endif
1737  
1738 // Get bitmap header
1739 ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp);
1740  
1741 // Set offset to the image data
1742 memOffset = sizeof(BITMAP_HEADER);
1743  
1744 // Get size
1745 sizeX = bmp.width;
1746 sizeY = bmp.height;
1747  
1748 byteWidth = sizeX << 1;
1749  
1750 for(y = 0; y < sizeY; y++)
1751 {
1752  
1753 // Get line
1754 ExternalMemoryCallback(bitmap, memOffset, byteWidth, lineBuffer);
1755 memOffset += byteWidth;
1756 CS_LAT_BIT = 0;
1757 for(stretchY = 0; stretchY < stretch; stretchY++)
1758 {
1759 pData = lineBuffer;
1760 SetAddress(address);
1761  
1762 for(x = 0; x < sizeX; x++)
1763 {
1764 temp = *pData++;
1765 SetColor(temp);
1766  
1767 // Write pixel to screen
1768 for(stretchX = 0; stretchX < stretch; stretchX++)
1769 {
1770 WritePixel(_color);
1771 }
1772 }
1773  
1774 #if (DISP_ORIENTATION == 0)
1775 address += LINE_MEM_PITCH;
1776 #else
1777 address -= 1;
1778 #endif
1779 }
1780  
1781 CS_LAT_BIT = 1;
1782 }
1783 }
1784  
1785 #endif // USE_DRV_PUTIMAGE
1786 #endif
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3