Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | /***************************************************************************** |
2 | * Module for Microchip Graphics Library |
||
3 | * Solomon Systech. SSD1906 LCD controller driver |
||
4 | ***************************************************************************** |
||
5 | * FileName: SSD1906.c |
||
6 | * Dependencies: Graphics.h |
||
7 | * Processor: PIC24, PIC32 |
||
8 | * Compiler: MPLAB C30, MPLAB C32 |
||
9 | * Linker: MPLAB LINK30, MPLAB LINK32 |
||
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 12/19/07 |
||
39 | * Anton Alkhimenok 01/31/08 combined portrait and landscape, PIC32 support |
||
40 | * Anton Alkhimenok 08/22/08 driver configuration is simplified, |
||
41 | * new image rotation modes |
||
42 | * PAT 03/26/10 Removed DelayMs() function. |
||
43 | *****************************************************************************/ |
||
44 | #include "Graphics\Graphics.h" |
||
45 | |||
46 | // Color |
||
47 | WORD _color; |
||
48 | |||
49 | // Clipping region control |
||
50 | SHORT _clipRgn; |
||
51 | |||
52 | // Clipping region borders |
||
53 | SHORT _clipLeft; |
||
54 | SHORT _clipTop; |
||
55 | SHORT _clipRight; |
||
56 | SHORT _clipBottom; |
||
57 | |||
58 | /////////////////////// LOCAL FUNCTIONS PROTOTYPES //////////////////////////// |
||
59 | #ifdef __PIC32MX |
||
60 | DWORD _address; // current video buffer address for PIC32 implementation |
||
61 | #define SetAddress(address) _address = address |
||
62 | #else |
||
63 | void SetAddress(DWORD address); |
||
64 | #endif |
||
65 | void SetReg(WORD index, BYTE value); |
||
66 | BYTE GetReg(WORD index); |
||
67 | |||
68 | void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch); |
||
69 | void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch); |
||
70 | void PutImage8BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch); |
||
71 | void PutImage16BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch); |
||
72 | |||
73 | void PutImage1BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch); |
||
74 | void PutImage4BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch); |
||
75 | void PutImage8BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch); |
||
76 | void PutImage16BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch); |
||
77 | |||
78 | #if (DISPLAY_PANEL == TFT_G240320LTSW_118W_E) |
||
79 | #include "TCON_SSD1289.c" |
||
80 | |||
81 | #elif (DISPLAY_PANEL == TFT_G320240DTSW_69W_TP_E) |
||
82 | #include "TCON_HX8238.c" |
||
83 | |||
84 | #elif (DISPLAY_PANEL == PH480272T_005_I06Q) |
||
85 | #include "TCON_HX8257.c" |
||
86 | |||
87 | #else |
||
88 | #include "TCON_Custom.c" |
||
89 | #endif |
||
90 | |||
91 | /********************************************************************* |
||
92 | * Function: void SetAddress(DWORD address) |
||
93 | * |
||
94 | * PreCondition: none |
||
95 | * |
||
96 | * Input: address - address |
||
97 | * |
||
98 | * Output: none |
||
99 | * |
||
100 | * Side Effects: none |
||
101 | * |
||
102 | * Overview: sets the address for read/write operations |
||
103 | * |
||
104 | * Note: none |
||
105 | * |
||
106 | ********************************************************************/ |
||
107 | #ifndef __PIC32MX |
||
108 | |||
109 | /* */ |
||
110 | void SetAddress(DWORD address) |
||
111 | { |
||
112 | PMADDR = ((DWORD_VAL) address).w[0]; |
||
113 | A17_LAT_BIT = 0; |
||
114 | if(((DWORD_VAL) address).w[1]) |
||
115 | A17_LAT_BIT = 1; |
||
116 | } |
||
117 | |||
118 | #endif |
||
119 | #ifdef __PIC32MX |
||
120 | |||
121 | /********************************************************************* |
||
122 | * Function: void WriteData(WORD value) |
||
123 | * |
||
124 | * PreCondition: none |
||
125 | * |
||
126 | * Input: value - value to be written |
||
127 | * |
||
128 | * Output: none |
||
129 | * |
||
130 | * Side Effects: none |
||
131 | * |
||
132 | * Overview: writes 16-bit word into video buffer at current address. |
||
133 | * The address pointer is incremented after the operation. |
||
134 | * |
||
135 | * Note: none |
||
136 | * |
||
137 | ********************************************************************/ |
||
138 | void WriteData(WORD value) |
||
139 | { |
||
140 | RS_LAT_BIT = 1; // set RS line to low for register space access |
||
141 | A17_LAT_BIT = 0; // set address[17] |
||
142 | if(((DWORD_VAL) _address).w[1] & 0x0001) |
||
143 | A17_LAT_BIT = 1; |
||
144 | PMADDR = ((DWORD_VAL) _address).w[0]; // set address[16:1] |
||
145 | A0_LAT_BIT = 1; // set address[0] |
||
146 | PMDIN1 = ((WORD_VAL) value).v[0]; // write low byte |
||
147 | _address++; |
||
148 | PMPWaitBusy(); // wait for the transmission end |
||
149 | A0_LAT_BIT = 0; // set address[0] |
||
150 | PMDIN1 = ((WORD_VAL) value).v[1]; // write high byte |
||
151 | PMPWaitBusy(); // wait for the transmission end |
||
152 | } |
||
153 | |||
154 | #endif |
||
155 | |||
156 | /********************************************************************* |
||
157 | * Function: void SetReg(WORD index, BYTE value) |
||
158 | * |
||
159 | * PreCondition: none |
||
160 | * |
||
161 | * Input: index - register number |
||
162 | * value - value to be set |
||
163 | * |
||
164 | * Output: none |
||
165 | * |
||
166 | * Side Effects: none |
||
167 | * |
||
168 | * Overview: sets graphics controller register (byte access) |
||
169 | * |
||
170 | * Note: none |
||
171 | * |
||
172 | ********************************************************************/ |
||
173 | void SetReg(WORD index, BYTE value) |
||
174 | { |
||
175 | #ifndef __PIC32MX |
||
176 | PMMODEbits.MODE16 = 0; // turn off 16 bit data mode |
||
177 | PMCONbits.PTBEEN = 0; // disable BE line for 16-bit access |
||
178 | #endif |
||
179 | RS_LAT_BIT = 0; // set RS line to low for register space access |
||
180 | CS_LAT_BIT = 0; // enable SSD1906 |
||
181 | A17_LAT_BIT = 0; // set address[17] |
||
182 | PMADDR = index >> 1; // set address[16:1] |
||
183 | A0_LAT_BIT = index & 0x0001; // set address[0] |
||
184 | PMDIN1 = value; // write value |
||
185 | PMPWaitBusy(); // wait for the transmission end |
||
186 | CS_LAT_BIT = 1; // disable SSD1906 |
||
187 | #ifndef __PIC32MX |
||
188 | PMCONbits.PTBEEN = 1; // enable BE line for 16-bit access |
||
189 | PMMODEbits.MODE16 = 1; // restore 16 bit data mode |
||
190 | #endif |
||
191 | } |
||
192 | |||
193 | /********************************************************************* |
||
194 | * Function: BYTE GetReg(WORD index) |
||
195 | * |
||
196 | * PreCondition: none |
||
197 | * |
||
198 | * Input: index - register number |
||
199 | * |
||
200 | * Output: none |
||
201 | * |
||
202 | * Side Effects: none |
||
203 | * |
||
204 | * Overview: returns graphics controller register value (byte access) |
||
205 | * |
||
206 | * Note: none |
||
207 | * |
||
208 | ********************************************************************/ |
||
209 | BYTE GetReg(WORD index) |
||
210 | { |
||
211 | BYTE value; |
||
212 | |||
213 | #ifndef __PIC32MX |
||
214 | PMMODEbits.MODE16 = 0; // turn off 16 bit data mode |
||
215 | PMCONbits.PTBEEN = 0; // disable BE line for 16-bit access |
||
216 | #endif |
||
217 | RS_LAT_BIT = 0; // set RS line to low for register space access |
||
218 | CS_LAT_BIT = 0; // enable SSD1906 |
||
219 | A17_LAT_BIT = 0; // set address[17] |
||
220 | PMADDR = index >> 1; // set address[16:1] |
||
221 | A0_LAT_BIT = index & 0x0001; // set address[0] |
||
222 | value = PMDIN1; // start transmission, read dummy value |
||
223 | PMPWaitBusy(); // wait for the transmission end |
||
224 | CS_LAT_BIT = 1; // disable SSD1906 |
||
225 | PMCONbits.PMPEN = 0; // suspend PMP |
||
226 | value = PMDIN1; // read value |
||
227 | PMCONbits.PMPEN = 1; // resume PMP |
||
228 | #ifndef __PIC32MX |
||
229 | PMCONbits.PTBEEN = 1; // enable BE line for 16-bit access |
||
230 | PMMODEbits.MODE16 = 1; // restore 16 bit data mode |
||
231 | #endif |
||
232 | return (value); |
||
233 | } |
||
234 | |||
235 | /********************************************************************* |
||
236 | * Function: void ResetDevice() |
||
237 | * |
||
238 | * PreCondition: none |
||
239 | * |
||
240 | * Input: none |
||
241 | * |
||
242 | * Output: none |
||
243 | * |
||
244 | * Side Effects: none |
||
245 | * |
||
246 | * Overview: resets LCD, initializes PMP |
||
247 | * |
||
248 | * Note: none |
||
249 | * |
||
250 | ********************************************************************/ |
||
251 | void ResetDevice(void) |
||
252 | { |
||
253 | BYTE bReg; |
||
254 | |||
255 | RST_LAT_BIT = 0; // hold in reset by default |
||
256 | RST_TRIS_BIT = 0; // enable RESET line |
||
257 | A0_TRIS_BIT = 0; // enable A0 line for byte access |
||
258 | A17_TRIS_BIT = 0; // enable A17 line |
||
259 | RS_TRIS_BIT = 0; // enable RS line |
||
260 | CS_LAT_BIT = 1; // SSD1906 is not selected by default |
||
261 | CS_TRIS_BIT = 0; // enable 1906 CS line |
||
262 | |||
263 | // PMP setup |
||
264 | PMMODE = 0; |
||
265 | PMAEN = 0; |
||
266 | PMCON = 0; |
||
267 | PMMODEbits.MODE = 2; // Intel 80 master interface |
||
268 | #ifdef __PIC32MX |
||
269 | PMMODEbits.WAITB = 3; |
||
270 | PMMODEbits.WAITM = 13; |
||
271 | PMMODEbits.WAITE = 3; |
||
272 | PMMODEbits.INCM = 0; // auto increment address |
||
273 | #else |
||
274 | PMMODEbits.WAITB = 1; |
||
275 | PMMODEbits.WAITM = 5; |
||
276 | PMMODEbits.WAITE = 1; |
||
277 | PMMODEbits.INCM = 1; // auto increment address |
||
278 | #endif |
||
279 | #ifdef __PIC32MX |
||
280 | PMMODEbits.MODE16 = 0; // 16 bit data are multiplexed |
||
281 | #else |
||
282 | PMMODEbits.MODE16 = 1; // 16 bit data are multiplexed |
||
283 | #endif |
||
284 | PMAENbits.PTEN0 = 1; // enable low address latch |
||
285 | PMAENbits.PTEN1 = 1; // enable high address latch |
||
286 | #ifndef __PIC32MX |
||
287 | PMCONbits.PTBEEN = 1; // enable data latch line |
||
288 | #endif |
||
289 | PMCONbits.ADRMUX = 2; // address is multiplexed on data bus |
||
290 | PMCONbits.CSF = 0; |
||
291 | PMCONbits.ALP = 1; // set address latch control polarity |
||
292 | PMCONbits.PTRDEN = 1; // enable RD line |
||
293 | PMCONbits.PTWREN = 1; // enable WR line |
||
294 | PMCONbits.PMPEN = 1; // enable PMP |
||
295 | DelayMs(40); |
||
296 | RST_LAT_BIT = 1; // release from reset |
||
297 | DelayMs(20); |
||
298 | |||
299 | ///////////////////////////////////////////////////////////////////// |
||
300 | // Clock and Panel Configuration |
||
301 | // For SSD1906 SCKI input frequency 25MHz pixel clock is 6.25MHz. |
||
302 | // TFT display with 18 bit RGB parallel interface. |
||
303 | ///////////////////////////////////////////////////////////////////// |
||
304 | SetReg(REG_MEMCLK_CONFIG, 0x00); // Reg 4h |
||
305 | SetReg(REG_PCLK_CONFIG, 0x32); // Reg 5h |
||
306 | SetReg(REG_PANEL_TYPE, 0x61); // Reg 10h |
||
307 | |||
308 | ///////////////////////////////////////////////////////////////////// |
||
309 | |||
310 | // Horizontal total HT (reg 12h) |
||
311 | ///////////////////////////////////////////////////////////////////// |
||
312 | #define HT (DISP_HOR_PULSE_WIDTH + DISP_HOR_BACK_PORCH + DISP_HOR_FRONT_PORCH + DISP_HOR_RESOLUTION) |
||
313 | SetReg(REG_HORIZ_TOTAL, HT / 8 - 1); |
||
314 | |||
315 | ///////////////////////////////////////////////////////////////////// |
||
316 | // Horizontal display period HDP (reg 14h) |
||
317 | ///////////////////////////////////////////////////////////////////// |
||
318 | SetReg(REG_HDP, DISP_HOR_RESOLUTION / 8 - 1); |
||
319 | |||
320 | ///////////////////////////////////////////////////////////////////// |
||
321 | // Horizontal display period start HDPS (regs 16h, 17h) |
||
322 | ///////////////////////////////////////////////////////////////////// |
||
323 | #define HDPS (DISP_HOR_PULSE_WIDTH + DISP_HOR_BACK_PORCH) |
||
324 | SetReg(REG_HDP_START_POS0, HDPS & 0x00FF); |
||
325 | SetReg(REG_HDP_START_POS1, (HDPS >> 8) & 0x00FF); |
||
326 | |||
327 | ///////////////////////////////////////////////////////////////////// |
||
328 | // Horizontal syncronization pulse width HPW (reg 20h) |
||
329 | ///////////////////////////////////////////////////////////////////// |
||
330 | SetReg(REG_HSYNC_PULSE_WIDTH, DISP_HOR_PULSE_WIDTH - 1); |
||
331 | |||
332 | ///////////////////////////////////////////////////////////////////// |
||
333 | // Vertical total VT (regs 18h, 19h) |
||
334 | ///////////////////////////////////////////////////////////////////// |
||
335 | #define VT (DISP_VER_PULSE_WIDTH + DISP_VER_BACK_PORCH + DISP_VER_FRONT_PORCH + DISP_VER_RESOLUTION) |
||
336 | SetReg(REG_VERT_TOTAL0, VT & 0x00FF); |
||
337 | SetReg(REG_VERT_TOTAL1, (VT >> 8) & 0x00FF); |
||
338 | |||
339 | ///////////////////////////////////////////////////////////////////// |
||
340 | // Vertical display period VDP (regs 1ch, 1dh) |
||
341 | ///////////////////////////////////////////////////////////////////// |
||
342 | #define VDP (DISP_VER_RESOLUTION - 1) |
||
343 | SetReg(REG_VDP0, VDP & 0x00FF); |
||
344 | SetReg(REG_VDP1, (VDP >> 8) & 0x00FF); |
||
345 | |||
346 | ///////////////////////////////////////////////////////////////////// |
||
347 | // Vertical display period start VDPS (regs 1eh, 1fh) |
||
348 | ///////////////////////////////////////////////////////////////////// |
||
349 | #define VDPS (DISP_VER_PULSE_WIDTH + DISP_VER_BACK_PORCH) |
||
350 | SetReg(REG_VDP_START_POS0, VDPS & 0x00FF); |
||
351 | SetReg(REG_VDP_START_POS1, (VDPS >> 8) & 0x00FF); |
||
352 | |||
353 | ///////////////////////////////////////////////////////////////////// |
||
354 | // Vertical syncronization pulse width VPW (reg 24h) |
||
355 | ///////////////////////////////////////////////////////////////////// |
||
356 | SetReg(REG_VSYNC_PULSE_WIDTH, DISP_VER_PULSE_WIDTH - 1); |
||
357 | |||
358 | ///////////////////////////////////////////////////////////////////// |
||
359 | // ROTATION MODE |
||
360 | #if (DISP_ORIENTATION == 0) |
||
361 | #define WIN_START_ADDR 0ul |
||
362 | #define ROTATION 0 |
||
363 | |||
364 | #elif (DISP_ORIENTATION == 90) |
||
365 | #define WIN_START_ADDR (((DWORD) GetMaxX() + 1) / 2 - 1) |
||
366 | #define ROTATION 1 |
||
367 | |||
368 | #elif (DISP_ORIENTATION == 180) |
||
369 | #define WIN_START_ADDR ((((DWORD) GetMaxX() + 1) * (GetMaxY() + 1)) / 2 - 1) |
||
370 | #define ROTATION 2 |
||
371 | |||
372 | #elif (DISP_ORIENTATION == 270) |
||
373 | #define WIN_START_ADDR ((((DWORD) GetMaxX() + 1) * GetMaxY()) / 2) |
||
374 | #define ROTATION 3 |
||
375 | #endif |
||
376 | |||
377 | ///////////////////////////////////////////////////////////////////// |
||
378 | // Special Effects Register (reg 71h) |
||
379 | ///////////////////////////////////////////////////////////////////// |
||
380 | SetReg(REG_SPECIAL_EFFECTS, 0x40 | ROTATION); |
||
381 | |||
382 | ///////////////////////////////////////////////////////////////////// |
||
383 | // Main Window Display Start Address (regs 74h, 75h, 76h) |
||
384 | ///////////////////////////////////////////////////////////////////// |
||
385 | SetReg(REG_MAIN_WIN_DISP_START_ADDR0, WIN_START_ADDR & 0x00FF); |
||
386 | SetReg(REG_MAIN_WIN_DISP_START_ADDR1, (WIN_START_ADDR >> 8) & 0x00FF); |
||
387 | SetReg(REG_MAIN_WIN_DISP_START_ADDR2, (WIN_START_ADDR >> 16) & 0x00FF); |
||
388 | |||
389 | ///////////////////////////////////////////////////////////////////// |
||
390 | // Main Window Display Offset (regs 78h, 79h) |
||
391 | ///////////////////////////////////////////////////////////////////// |
||
392 | #define WIN_OFFSET ((GetMaxX() + 1) / 2) |
||
393 | SetReg(REG_MAIN_WIN_ADDR_OFFSET0, WIN_OFFSET & 0x00FF); |
||
394 | SetReg(REG_MAIN_WIN_ADDR_OFFSET1, (WIN_OFFSET >> 8) & 0x00FF); |
||
395 | |||
396 | ///////////////////////////////////////////////////////////////////// |
||
397 | // Display Mode Register (reg 70h) |
||
398 | ///////////////////////////////////////////////////////////////////// |
||
399 | SetReg(REG_DISPLAY_MODE, 0x04); // 16 BPP, enable RAM content to screen |
||
400 | |||
401 | ///////////////////////////////////////////////////////////////////// |
||
402 | |||
403 | // Power Saving Configuration Register (reg a0h) |
||
404 | ///////////////////////////////////////////////////////////////////// |
||
405 | SetReg(REG_POWER_SAVE_CONFIG, 0x00); // wake up |
||
406 | |||
407 | ///////////////////////////////////////////////////////////////////// |
||
408 | |||
409 | // GPIO Status/Control Register (reg adh) |
||
410 | // GPO must be connected to POWER_ON input of the LCD |
||
411 | ///////////////////////////////////////////////////////////////////// |
||
412 | SetReg(REG_GPIO_STATUS_CONTROL1, 0x80); // set GPO high to turn on LCD panel |
||
413 | |||
414 | ///////////////////////////////////////////////////////////////////// |
||
415 | |||
416 | // Use the timing controller if the display panel used requires it |
||
417 | ///////////////////////////////////////////////////////////////////// |
||
418 | TCON_Init(); |
||
419 | } |
||
420 | |||
421 | /********************************************************************* |
||
422 | * Function: void PutPixel(SHORT x, SHORT y) |
||
423 | * |
||
424 | * PreCondition: none |
||
425 | * |
||
426 | * Input: x,y - pixel coordinates |
||
427 | * |
||
428 | * Output: none |
||
429 | * |
||
430 | * Side Effects: none |
||
431 | * |
||
432 | * Overview: puts pixel |
||
433 | * |
||
434 | * Note: none |
||
435 | * |
||
436 | ********************************************************************/ |
||
437 | void PutPixel(SHORT x, SHORT y) |
||
438 | { |
||
439 | DWORD address; |
||
440 | if(_clipRgn) |
||
441 | { |
||
442 | if(x < _clipLeft) |
||
443 | return; |
||
444 | if(x > _clipRight) |
||
445 | return; |
||
446 | if(y < _clipTop) |
||
447 | return; |
||
448 | if(y > _clipBottom) |
||
449 | return; |
||
450 | } |
||
451 | |||
452 | address = (DWORD) (GetMaxX() + 1) * y + x; |
||
453 | SetAddress(address); |
||
454 | CS_LAT_BIT = 0; |
||
455 | WriteData(_color); |
||
456 | CS_LAT_BIT = 1; |
||
457 | } |
||
458 | |||
459 | /********************************************************************* |
||
460 | * Function: WORD GetPixel(SHORT x, SHORT y) |
||
461 | * |
||
462 | * PreCondition: none |
||
463 | * |
||
464 | * Input: x,y - pixel coordinates |
||
465 | * |
||
466 | * Output: pixel color |
||
467 | * |
||
468 | * Side Effects: none |
||
469 | * |
||
470 | * Overview: returns pixel color at x,y position |
||
471 | * |
||
472 | * Note: none |
||
473 | * |
||
474 | ********************************************************************/ |
||
475 | WORD GetPixel(SHORT x, SHORT y) |
||
476 | { |
||
477 | DWORD address; |
||
478 | WORD value; |
||
479 | |||
480 | address = (long)(GetMaxX() + 1) * y + x; |
||
481 | SetAddress(address); |
||
482 | |||
483 | CS_LAT_BIT = 0; // enable SSD1906 |
||
484 | #ifdef __PIC32MX |
||
485 | A17_LAT_BIT = 0; // set address[17] |
||
486 | if(((DWORD_VAL) _address).w[1] & 0x0001) |
||
487 | A17_LAT_BIT = 1; |
||
488 | PMADDR = ((DWORD_VAL) _address).w[0]; // set address[16:1] |
||
489 | A0_LAT_BIT = 1; // set address[0] |
||
490 | ((WORD_VAL) value).v[0] = PMDIN; // start transmission, read dummy value |
||
491 | PMPWaitBusy(); // wait for the transmission end |
||
492 | A0_LAT_BIT = 0; // set address[0] |
||
493 | ((WORD_VAL) value).v[0] = PMDIN; // start transmission, read low byte |
||
494 | #else |
||
495 | value = PMDIN1; // start transmission, read dummy value |
||
496 | #endif |
||
497 | PMPWaitBusy(); // wait for the transmission end |
||
498 | CS_LAT_BIT = 1; // disable SSD1906 |
||
499 | PMCONbits.PMPEN = 0; // suspend PMP |
||
500 | #ifdef __PIC32MX |
||
501 | ((WORD_VAL) value).v[0] = PMDIN; // read high byte |
||
502 | #else |
||
503 | value = PMDIN1; // read value |
||
504 | #endif |
||
505 | PMCONbits.PMPEN = 1; // resume PMP |
||
506 | return (value); |
||
507 | } |
||
508 | |||
509 | /********************************************************************* |
||
510 | * Function: WORD Bar(SHORT left, SHORT top, SHORT right, SHORT bottom) |
||
511 | * |
||
512 | * PreCondition: none |
||
513 | * |
||
514 | * Input: left,top - top left corner coordinates, |
||
515 | * right,bottom - bottom right corner coordinates |
||
516 | * |
||
517 | * Output: none |
||
518 | * |
||
519 | * Side Effects: For NON-Blocking configuration: |
||
520 | * - Returns 0 when device is busy and the shape is not yet completely drawn. |
||
521 | * - Returns 1 when the shape is completely drawn. |
||
522 | * For Blocking configuration: |
||
523 | * - Always return 1. |
||
524 | * |
||
525 | * Overview: draws rectangle filled with current color |
||
526 | * |
||
527 | * Note: none |
||
528 | * |
||
529 | ********************************************************************/ |
||
530 | WORD Bar(SHORT left, SHORT top, SHORT right, SHORT bottom) |
||
531 | { |
||
532 | DWORD address; |
||
533 | register SHORT x, y; |
||
534 | |||
535 | #ifndef USE_NONBLOCKING_CONFIG |
||
536 | while(IsDeviceBusy() != 0); |
||
537 | |||
538 | /* Ready */ |
||
539 | #else |
||
540 | if(IsDeviceBusy() != 0) |
||
541 | return (0); |
||
542 | #endif |
||
543 | if(_clipRgn) |
||
544 | { |
||
545 | if(left < _clipLeft) |
||
546 | left = _clipLeft; |
||
547 | if(right > _clipRight) |
||
548 | right = _clipRight; |
||
549 | if(top < _clipTop) |
||
550 | top = _clipTop; |
||
551 | if(bottom > _clipBottom) |
||
552 | bottom = _clipBottom; |
||
553 | } |
||
554 | |||
555 | address = (DWORD) (GetMaxX() + 1) * top + left; |
||
556 | |||
557 | CS_LAT_BIT = 0; |
||
558 | for(y = top; y < bottom + 1; y++) |
||
559 | { |
||
560 | SetAddress(address); |
||
561 | for(x = left; x < right + 1; x++) |
||
562 | { |
||
563 | WriteData(_color); |
||
564 | } |
||
565 | |||
566 | address += (GetMaxX() + 1); |
||
567 | } |
||
568 | |||
569 | CS_LAT_BIT = 1; |
||
570 | return (1); |
||
571 | } |
||
572 | |||
573 | /********************************************************************* |
||
574 | * Function: void ClearDevice(void) |
||
575 | * |
||
576 | * PreCondition: none |
||
577 | * |
||
578 | * Input: none |
||
579 | * |
||
580 | * Output: none |
||
581 | * |
||
582 | * Side Effects: none |
||
583 | * |
||
584 | * Overview: clears screen with current color |
||
585 | * |
||
586 | * Note: none |
||
587 | * |
||
588 | ********************************************************************/ |
||
589 | void ClearDevice(void) |
||
590 | { |
||
591 | DWORD counter; |
||
592 | |||
593 | SetAddress(0); |
||
594 | CS_LAT_BIT = 0; |
||
595 | for(counter = 0; counter < (DWORD) (GetMaxX() + 1) * (GetMaxY() + 1); counter++) |
||
596 | { |
||
597 | WriteData(_color); |
||
598 | } |
||
599 | |||
600 | CS_LAT_BIT = 1; |
||
601 | } |
||
602 | |||
603 | /********************************************************************* |
||
604 | * Function: WORD PutImage(SHORT left, SHORT top, void* bitmap, BYTE stretch) |
||
605 | * |
||
606 | * PreCondition: none |
||
607 | * |
||
608 | * Input: left,top - left top image corner, |
||
609 | * bitmap - image pointer, |
||
610 | * stretch - image stretch factor |
||
611 | * |
||
612 | * Output: For NON-Blocking configuration: |
||
613 | * - Returns 0 when device is busy and the image is not yet completely drawn. |
||
614 | * - Returns 1 when the image is completely drawn. |
||
615 | * For Blocking configuration: |
||
616 | * - Always return 1. |
||
617 | * |
||
618 | * Side Effects: none |
||
619 | * |
||
620 | * Overview: outputs image starting from left,top coordinates |
||
621 | * |
||
622 | * Note: image must be located in flash |
||
623 | * |
||
624 | ********************************************************************/ |
||
625 | WORD PutImage(SHORT left, SHORT top, void *bitmap, BYTE stretch) |
||
626 | { |
||
627 | FLASH_BYTE *flashAddress; |
||
628 | BYTE colorDepth; |
||
629 | WORD colorTemp; |
||
630 | |||
631 | #ifndef USE_NONBLOCKING_CONFIG |
||
632 | while(IsDeviceBusy() != 0); |
||
633 | |||
634 | /* Ready */ |
||
635 | #else |
||
636 | if(IsDeviceBusy() != 0) |
||
637 | return (0); |
||
638 | #endif |
||
639 | |||
640 | // Save current color |
||
641 | colorTemp = _color; |
||
642 | |||
643 | switch(*((SHORT *)bitmap)) |
||
644 | { |
||
645 | #ifdef USE_BITMAP_FLASH |
||
646 | |||
647 | case FLASH: |
||
648 | |||
649 | // Image address |
||
650 | flashAddress = ((BITMAP_FLASH *)bitmap)->address; |
||
651 | |||
652 | // Read color depth |
||
653 | colorDepth = *(flashAddress + 1); |
||
654 | |||
655 | // Draw picture |
||
656 | switch(colorDepth) |
||
657 | { |
||
658 | case 1: PutImage1BPP(left, top, flashAddress, stretch); break; |
||
659 | case 4: PutImage4BPP(left, top, flashAddress, stretch); break; |
||
660 | case 8: PutImage8BPP(left, top, flashAddress, stretch); break; |
||
661 | case 16: PutImage16BPP(left, top, flashAddress, stretch); break; |
||
662 | } |
||
663 | |||
664 | break; |
||
665 | #endif |
||
666 | #ifdef USE_BITMAP_EXTERNAL |
||
667 | |||
668 | case EXTERNAL: |
||
669 | |||
670 | // Get color depth |
||
671 | ExternalMemoryCallback(bitmap, 1, 1, &colorDepth); |
||
672 | |||
673 | // Draw picture |
||
674 | switch(colorDepth) |
||
675 | { |
||
676 | case 1: PutImage1BPPExt(left, top, bitmap, stretch); break; |
||
677 | case 4: PutImage4BPPExt(left, top, bitmap, stretch); break; |
||
678 | case 8: PutImage8BPPExt(left, top, bitmap, stretch); break; |
||
679 | case 16: PutImage16BPPExt(left, top, bitmap, stretch); break; |
||
680 | default: break; |
||
681 | } |
||
682 | |||
683 | break; |
||
684 | #endif |
||
685 | |||
686 | default: |
||
687 | break; |
||
688 | } |
||
689 | |||
690 | // Restore current color |
||
691 | _color = colorTemp; |
||
692 | return (1); |
||
693 | } |
||
694 | |||
695 | #ifdef USE_BITMAP_FLASH |
||
696 | |||
697 | /********************************************************************* |
||
698 | * Function: void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch) |
||
699 | * |
||
700 | * PreCondition: none |
||
701 | * |
||
702 | * Input: left,top - left top image corner, |
||
703 | * bitmap - image pointer, |
||
704 | * stretch - image stretch factor |
||
705 | * |
||
706 | * Output: none |
||
707 | * |
||
708 | * Side Effects: none |
||
709 | * |
||
710 | * Overview: outputs monochrome image starting from left,top coordinates |
||
711 | * |
||
712 | * Note: image must be located in flash |
||
713 | * |
||
714 | ********************************************************************/ |
||
715 | void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch) |
||
716 | { |
||
717 | register DWORD address; |
||
718 | register FLASH_BYTE *flashAddress; |
||
719 | register FLASH_BYTE *tempFlashAddress; |
||
720 | BYTE temp; |
||
721 | WORD sizeX, sizeY; |
||
722 | WORD x, y; |
||
723 | BYTE stretchX, stretchY; |
||
724 | WORD pallete[2]; |
||
725 | BYTE mask; |
||
726 | |||
727 | // Move pointer to size information |
||
728 | flashAddress = bitmap + 2; |
||
729 | |||
730 | // Set start address |
||
731 | address = (long)(GetMaxX() + 1) * top + left; |
||
732 | |||
733 | // Read image size |
||
734 | sizeY = *((FLASH_WORD *)flashAddress); |
||
735 | flashAddress += 2; |
||
736 | sizeX = *((FLASH_WORD *)flashAddress); |
||
737 | flashAddress += 2; |
||
738 | pallete[0] = *((FLASH_WORD *)flashAddress); |
||
739 | flashAddress += 2; |
||
740 | pallete[1] = *((FLASH_WORD *)flashAddress); |
||
741 | flashAddress += 2; |
||
742 | |||
743 | CS_LAT_BIT = 0; |
||
744 | for(y = 0; y < sizeY; y++) |
||
745 | { |
||
746 | tempFlashAddress = flashAddress; |
||
747 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
748 | { |
||
749 | flashAddress = tempFlashAddress; |
||
750 | SetAddress(address); |
||
751 | mask = 0; |
||
752 | for(x = 0; x < sizeX; x++) |
||
753 | { |
||
754 | |||
755 | // Read 8 pixels from flash |
||
756 | if(mask == 0) |
||
757 | { |
||
758 | temp = *flashAddress; |
||
759 | flashAddress++; |
||
760 | mask = 0x80; |
||
761 | } |
||
762 | |||
763 | // Set color |
||
764 | if(mask & temp) |
||
765 | { |
||
766 | SetColor(pallete[1]); |
||
767 | } |
||
768 | else |
||
769 | { |
||
770 | SetColor(pallete[0]); |
||
771 | } |
||
772 | |||
773 | // Write pixel to screen |
||
774 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
775 | { |
||
776 | WriteData(_color); |
||
777 | } |
||
778 | |||
779 | // Shift to the next pixel |
||
780 | mask >>= 1; |
||
781 | } |
||
782 | |||
783 | address += (GetMaxX() + 1); |
||
784 | } |
||
785 | } |
||
786 | |||
787 | CS_LAT_BIT = 1; |
||
788 | } |
||
789 | |||
790 | /********************************************************************* |
||
791 | * Function: void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch) |
||
792 | * |
||
793 | * PreCondition: none |
||
794 | * |
||
795 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
796 | * stretch - image stretch factor |
||
797 | * |
||
798 | * Output: none |
||
799 | * |
||
800 | * Side Effects: none |
||
801 | * |
||
802 | * Overview: outputs 16 color image starting from left,top coordinates |
||
803 | * |
||
804 | * Note: image must be located in flash |
||
805 | * |
||
806 | ********************************************************************/ |
||
807 | void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch) |
||
808 | { |
||
809 | register DWORD address; |
||
810 | register FLASH_BYTE *flashAddress; |
||
811 | register FLASH_BYTE *tempFlashAddress; |
||
812 | WORD sizeX, sizeY; |
||
813 | register WORD x, y; |
||
814 | BYTE temp; |
||
815 | register BYTE stretchX, stretchY; |
||
816 | WORD pallete[16]; |
||
817 | WORD counter; |
||
818 | |||
819 | // Move pointer to size information |
||
820 | flashAddress = bitmap + 2; |
||
821 | |||
822 | // Set start address |
||
823 | address = (long)(GetMaxX() + 1) * top + left; |
||
824 | |||
825 | // Read image size |
||
826 | sizeY = *((FLASH_WORD *)flashAddress); |
||
827 | flashAddress += 2; |
||
828 | sizeX = *((FLASH_WORD *)flashAddress); |
||
829 | flashAddress += 2; |
||
830 | |||
831 | // Read pallete |
||
832 | for(counter = 0; counter < 16; counter++) |
||
833 | { |
||
834 | pallete[counter] = *((FLASH_WORD *)flashAddress); |
||
835 | flashAddress += 2; |
||
836 | } |
||
837 | |||
838 | CS_LAT_BIT = 0; |
||
839 | for(y = 0; y < sizeY; y++) |
||
840 | { |
||
841 | tempFlashAddress = flashAddress; |
||
842 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
843 | { |
||
844 | flashAddress = tempFlashAddress; |
||
845 | SetAddress(address); |
||
846 | for(x = 0; x < sizeX; x++) |
||
847 | { |
||
848 | |||
849 | // Read 2 pixels from flash |
||
850 | if(x & 0x0001) |
||
851 | { |
||
852 | |||
853 | // second pixel in byte |
||
854 | SetColor(pallete[temp >> 4]); |
||
855 | } |
||
856 | else |
||
857 | { |
||
858 | temp = *flashAddress; |
||
859 | flashAddress++; |
||
860 | |||
861 | // first pixel in byte |
||
862 | SetColor(pallete[temp & 0x0f]); |
||
863 | } |
||
864 | |||
865 | // Write pixel to screen |
||
866 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
867 | { |
||
868 | WriteData(_color); |
||
869 | } |
||
870 | |||
871 | // Shift to the next pixel |
||
872 | //temp >>= 4; |
||
873 | } |
||
874 | |||
875 | address += (GetMaxX() + 1); |
||
876 | } |
||
877 | } |
||
878 | |||
879 | CS_LAT_BIT = 1; |
||
880 | } |
||
881 | |||
882 | /********************************************************************* |
||
883 | * Function: void PutImage8BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch) |
||
884 | * |
||
885 | * PreCondition: none |
||
886 | * |
||
887 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
888 | * stretch - image stretch factor |
||
889 | * |
||
890 | * Output: none |
||
891 | * |
||
892 | * Side Effects: none |
||
893 | * |
||
894 | * Overview: outputs 256 color image starting from left,top coordinates |
||
895 | * |
||
896 | * Note: image must be located in flash |
||
897 | * |
||
898 | ********************************************************************/ |
||
899 | void PutImage8BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch) |
||
900 | { |
||
901 | register DWORD address; |
||
902 | register FLASH_BYTE *flashAddress; |
||
903 | register FLASH_BYTE *tempFlashAddress; |
||
904 | WORD sizeX, sizeY; |
||
905 | WORD x, y; |
||
906 | BYTE temp; |
||
907 | BYTE stretchX, stretchY; |
||
908 | WORD pallete[256]; |
||
909 | WORD counter; |
||
910 | |||
911 | // Move pointer to size information |
||
912 | flashAddress = bitmap + 2; |
||
913 | |||
914 | // Set start address |
||
915 | address = (long)(GetMaxX() + 1) * top + left; |
||
916 | |||
917 | // Read image size |
||
918 | sizeY = *((FLASH_WORD *)flashAddress); |
||
919 | flashAddress += 2; |
||
920 | sizeX = *((FLASH_WORD *)flashAddress); |
||
921 | flashAddress += 2; |
||
922 | |||
923 | // Read pallete |
||
924 | for(counter = 0; counter < 256; counter++) |
||
925 | { |
||
926 | pallete[counter] = *((FLASH_WORD *)flashAddress); |
||
927 | flashAddress += 2; |
||
928 | } |
||
929 | |||
930 | CS_LAT_BIT = 0; |
||
931 | for(y = 0; y < sizeY; y++) |
||
932 | { |
||
933 | tempFlashAddress = flashAddress; |
||
934 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
935 | { |
||
936 | flashAddress = tempFlashAddress; |
||
937 | SetAddress(address); |
||
938 | for(x = 0; x < sizeX; x++) |
||
939 | { |
||
940 | |||
941 | // Read pixels from flash |
||
942 | temp = *flashAddress; |
||
943 | flashAddress++; |
||
944 | |||
945 | // Set color |
||
946 | SetColor(pallete[temp]); |
||
947 | |||
948 | // Write pixel to screen |
||
949 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
950 | { |
||
951 | WriteData(_color); |
||
952 | } |
||
953 | } |
||
954 | |||
955 | address += (GetMaxX() + 1); |
||
956 | } |
||
957 | } |
||
958 | |||
959 | CS_LAT_BIT = 1; |
||
960 | } |
||
961 | |||
962 | /********************************************************************* |
||
963 | * Function: void PutImage16BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch) |
||
964 | * |
||
965 | * PreCondition: none |
||
966 | * |
||
967 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
968 | * stretch - image stretch factor |
||
969 | * |
||
970 | * Output: none |
||
971 | * |
||
972 | * Side Effects: none |
||
973 | * |
||
974 | * Overview: outputs hicolor image starting from left,top coordinates |
||
975 | * |
||
976 | * Note: image must be located in flash |
||
977 | * |
||
978 | ********************************************************************/ |
||
979 | void PutImage16BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch) |
||
980 | { |
||
981 | register DWORD address; |
||
982 | register FLASH_WORD *flashAddress; |
||
983 | register FLASH_WORD *tempFlashAddress; |
||
984 | WORD sizeX, sizeY; |
||
985 | register WORD x, y; |
||
986 | WORD temp; |
||
987 | register BYTE stretchX, stretchY; |
||
988 | |||
989 | // Move pointer to size information |
||
990 | flashAddress = (FLASH_WORD *)bitmap + 1; |
||
991 | |||
992 | // Set start address |
||
993 | address = (long)(GetMaxX() + 1) * top + left; |
||
994 | |||
995 | // Read image size |
||
996 | sizeY = *flashAddress; |
||
997 | flashAddress++; |
||
998 | sizeX = *flashAddress; |
||
999 | flashAddress++; |
||
1000 | |||
1001 | CS_LAT_BIT = 0; |
||
1002 | for(y = 0; y < sizeY; y++) |
||
1003 | { |
||
1004 | tempFlashAddress = flashAddress; |
||
1005 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
1006 | { |
||
1007 | flashAddress = tempFlashAddress; |
||
1008 | SetAddress(address); |
||
1009 | for(x = 0; x < sizeX; x++) |
||
1010 | { |
||
1011 | |||
1012 | // Read pixels from flash |
||
1013 | temp = *flashAddress; |
||
1014 | flashAddress++; |
||
1015 | |||
1016 | // Set color |
||
1017 | SetColor(temp); |
||
1018 | |||
1019 | // Write pixel to screen |
||
1020 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
1021 | { |
||
1022 | WriteData(_color); |
||
1023 | } |
||
1024 | } |
||
1025 | |||
1026 | address += (GetMaxX() + 1); |
||
1027 | } |
||
1028 | } |
||
1029 | |||
1030 | CS_LAT_BIT = 1; |
||
1031 | } |
||
1032 | |||
1033 | #endif |
||
1034 | #ifdef USE_BITMAP_EXTERNAL |
||
1035 | |||
1036 | /********************************************************************* |
||
1037 | * Function: void PutImage1BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch) |
||
1038 | * |
||
1039 | * PreCondition: none |
||
1040 | * |
||
1041 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
1042 | * stretch - image stretch factor |
||
1043 | * |
||
1044 | * Output: none |
||
1045 | * |
||
1046 | * Side Effects: none |
||
1047 | * |
||
1048 | * Overview: outputs monochrome image starting from left,top coordinates |
||
1049 | * |
||
1050 | * Note: image must be located in external memory |
||
1051 | * |
||
1052 | ********************************************************************/ |
||
1053 | void PutImage1BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch) |
||
1054 | { |
||
1055 | register DWORD address; |
||
1056 | register DWORD memOffset; |
||
1057 | BITMAP_HEADER bmp; |
||
1058 | WORD pallete[2]; |
||
1059 | BYTE lineBuffer[((GetMaxX() + 1) / 8) + 1]; |
||
1060 | BYTE *pData; |
||
1061 | SHORT byteWidth; |
||
1062 | |||
1063 | BYTE temp; |
||
1064 | BYTE mask; |
||
1065 | WORD sizeX, sizeY; |
||
1066 | WORD x, y; |
||
1067 | BYTE stretchX, stretchY; |
||
1068 | |||
1069 | // Set start address |
||
1070 | address = (long)(GetMaxX() + 1) * top + left; |
||
1071 | |||
1072 | // Get bitmap header |
||
1073 | ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp); |
||
1074 | |||
1075 | // Get pallete (2 entries) |
||
1076 | ExternalMemoryCallback(bitmap, sizeof(BITMAP_HEADER), 2 * sizeof(WORD), pallete); |
||
1077 | |||
1078 | // Set offset to the image data |
||
1079 | memOffset = sizeof(BITMAP_HEADER) + 2 * sizeof(WORD); |
||
1080 | |||
1081 | // Line width in bytes |
||
1082 | byteWidth = bmp.width >> 3; |
||
1083 | if(bmp.width & 0x0007) |
||
1084 | byteWidth++; |
||
1085 | |||
1086 | // Get size |
||
1087 | sizeX = bmp.width; |
||
1088 | sizeY = bmp.height; |
||
1089 | |||
1090 | for(y = 0; y < sizeY; y++) |
||
1091 | { |
||
1092 | |||
1093 | // Get line |
||
1094 | ExternalMemoryCallback(bitmap, memOffset, byteWidth, lineBuffer); |
||
1095 | memOffset += byteWidth; |
||
1096 | |||
1097 | CS_LAT_BIT = 0; |
||
1098 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
1099 | { |
||
1100 | pData = lineBuffer; |
||
1101 | SetAddress(address); |
||
1102 | mask = 0; |
||
1103 | for(x = 0; x < sizeX; x++) |
||
1104 | { |
||
1105 | |||
1106 | // Read 8 pixels from flash |
||
1107 | if(mask == 0) |
||
1108 | { |
||
1109 | temp = *pData++; |
||
1110 | mask = 0x80; |
||
1111 | } |
||
1112 | |||
1113 | // Set color |
||
1114 | if(mask & temp) |
||
1115 | { |
||
1116 | SetColor(pallete[1]); |
||
1117 | } |
||
1118 | else |
||
1119 | { |
||
1120 | SetColor(pallete[0]); |
||
1121 | } |
||
1122 | |||
1123 | // Write pixel to screen |
||
1124 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
1125 | { |
||
1126 | WriteData(_color); |
||
1127 | } |
||
1128 | |||
1129 | // Shift to the next pixel |
||
1130 | mask >>= 1; |
||
1131 | } |
||
1132 | |||
1133 | address += (GetMaxX() + 1); |
||
1134 | } |
||
1135 | |||
1136 | CS_LAT_BIT = 1; |
||
1137 | } |
||
1138 | } |
||
1139 | |||
1140 | /********************************************************************* |
||
1141 | * Function: void PutImage4BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch) |
||
1142 | * |
||
1143 | * PreCondition: none |
||
1144 | * |
||
1145 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
1146 | * stretch - image stretch factor |
||
1147 | * |
||
1148 | * Output: none |
||
1149 | * |
||
1150 | * Side Effects: none |
||
1151 | * |
||
1152 | * Overview: outputs monochrome image starting from left,top coordinates |
||
1153 | * |
||
1154 | * Note: image must be located in external memory |
||
1155 | * |
||
1156 | ********************************************************************/ |
||
1157 | void PutImage4BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch) |
||
1158 | { |
||
1159 | register DWORD address; |
||
1160 | register DWORD memOffset; |
||
1161 | BITMAP_HEADER bmp; |
||
1162 | WORD pallete[16]; |
||
1163 | BYTE lineBuffer[((GetMaxX() + 1) / 2) + 1]; |
||
1164 | BYTE *pData; |
||
1165 | SHORT byteWidth; |
||
1166 | |||
1167 | BYTE temp; |
||
1168 | WORD sizeX, sizeY; |
||
1169 | WORD x, y; |
||
1170 | BYTE stretchX, stretchY; |
||
1171 | |||
1172 | // Set start address |
||
1173 | address = (long)(GetMaxX() + 1) * top + left; |
||
1174 | |||
1175 | // Get bitmap header |
||
1176 | ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp); |
||
1177 | |||
1178 | // Get pallete (16 entries) |
||
1179 | ExternalMemoryCallback(bitmap, sizeof(BITMAP_HEADER), 16 * sizeof(WORD), pallete); |
||
1180 | |||
1181 | // Set offset to the image data |
||
1182 | memOffset = sizeof(BITMAP_HEADER) + 16 * sizeof(WORD); |
||
1183 | |||
1184 | // Line width in bytes |
||
1185 | byteWidth = bmp.width >> 1; |
||
1186 | if(bmp.width & 0x0001) |
||
1187 | byteWidth++; |
||
1188 | |||
1189 | // Get size |
||
1190 | sizeX = bmp.width; |
||
1191 | sizeY = bmp.height; |
||
1192 | |||
1193 | for(y = 0; y < sizeY; y++) |
||
1194 | { |
||
1195 | |||
1196 | // Get line |
||
1197 | ExternalMemoryCallback(bitmap, memOffset, byteWidth, lineBuffer); |
||
1198 | memOffset += byteWidth; |
||
1199 | CS_LAT_BIT = 0; |
||
1200 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
1201 | { |
||
1202 | pData = lineBuffer; |
||
1203 | SetAddress(address); |
||
1204 | |||
1205 | for(x = 0; x < sizeX; x++) |
||
1206 | { |
||
1207 | |||
1208 | // Read 2 pixels from flash |
||
1209 | if(x & 0x0001) |
||
1210 | { |
||
1211 | |||
1212 | // second pixel in byte |
||
1213 | SetColor(pallete[temp >> 4]); |
||
1214 | } |
||
1215 | else |
||
1216 | { |
||
1217 | temp = *pData++; |
||
1218 | |||
1219 | // first pixel in byte |
||
1220 | SetColor(pallete[temp & 0x0f]); |
||
1221 | } |
||
1222 | |||
1223 | // Write pixel to screen |
||
1224 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
1225 | { |
||
1226 | WriteData(_color); |
||
1227 | } |
||
1228 | } |
||
1229 | |||
1230 | address += (GetMaxX() + 1); |
||
1231 | } |
||
1232 | |||
1233 | CS_LAT_BIT = 1; |
||
1234 | } |
||
1235 | } |
||
1236 | |||
1237 | /********************************************************************* |
||
1238 | * Function: void PutImage8BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch) |
||
1239 | * |
||
1240 | * PreCondition: none |
||
1241 | * |
||
1242 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
1243 | * stretch - image stretch factor |
||
1244 | * |
||
1245 | * Output: none |
||
1246 | * |
||
1247 | * Side Effects: none |
||
1248 | * |
||
1249 | * Overview: outputs monochrome image starting from left,top coordinates |
||
1250 | * |
||
1251 | * Note: image must be located in external memory |
||
1252 | * |
||
1253 | ********************************************************************/ |
||
1254 | void PutImage8BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch) |
||
1255 | { |
||
1256 | register DWORD address; |
||
1257 | register DWORD memOffset; |
||
1258 | BITMAP_HEADER bmp; |
||
1259 | WORD pallete[256]; |
||
1260 | BYTE lineBuffer[(GetMaxX() + 1)]; |
||
1261 | BYTE *pData; |
||
1262 | |||
1263 | BYTE temp; |
||
1264 | WORD sizeX, sizeY; |
||
1265 | WORD x, y; |
||
1266 | BYTE stretchX, stretchY; |
||
1267 | |||
1268 | // Set start address |
||
1269 | address = (long)(GetMaxX() + 1) * top + left; |
||
1270 | |||
1271 | // Get bitmap header |
||
1272 | ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp); |
||
1273 | |||
1274 | // Get pallete (256 entries) |
||
1275 | ExternalMemoryCallback(bitmap, sizeof(BITMAP_HEADER), 256 * sizeof(WORD), pallete); |
||
1276 | |||
1277 | // Set offset to the image data |
||
1278 | memOffset = sizeof(BITMAP_HEADER) + 256 * sizeof(WORD); |
||
1279 | |||
1280 | // Get size |
||
1281 | sizeX = bmp.width; |
||
1282 | sizeY = bmp.height; |
||
1283 | |||
1284 | for(y = 0; y < sizeY; y++) |
||
1285 | { |
||
1286 | |||
1287 | // Get line |
||
1288 | ExternalMemoryCallback(bitmap, memOffset, sizeX, lineBuffer); |
||
1289 | memOffset += sizeX; |
||
1290 | CS_LAT_BIT = 0; |
||
1291 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
1292 | { |
||
1293 | pData = lineBuffer; |
||
1294 | SetAddress(address); |
||
1295 | |||
1296 | for(x = 0; x < sizeX; x++) |
||
1297 | { |
||
1298 | temp = *pData++; |
||
1299 | SetColor(pallete[temp]); |
||
1300 | |||
1301 | // Write pixel to screen |
||
1302 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
1303 | { |
||
1304 | WriteData(_color); |
||
1305 | } |
||
1306 | } |
||
1307 | |||
1308 | address += (GetMaxX() + 1); |
||
1309 | } |
||
1310 | |||
1311 | CS_LAT_BIT = 1; |
||
1312 | } |
||
1313 | } |
||
1314 | |||
1315 | /********************************************************************* |
||
1316 | * Function: void PutImage16BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch) |
||
1317 | * |
||
1318 | * PreCondition: none |
||
1319 | * |
||
1320 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
1321 | * stretch - image stretch factor |
||
1322 | * |
||
1323 | * Output: none |
||
1324 | * |
||
1325 | * Side Effects: none |
||
1326 | * |
||
1327 | * Overview: outputs monochrome image starting from left,top coordinates |
||
1328 | * |
||
1329 | * Note: image must be located in external memory |
||
1330 | * |
||
1331 | ********************************************************************/ |
||
1332 | void PutImage16BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch) |
||
1333 | { |
||
1334 | register DWORD address; |
||
1335 | register DWORD memOffset; |
||
1336 | BITMAP_HEADER bmp; |
||
1337 | WORD lineBuffer[(GetMaxX() + 1)]; |
||
1338 | WORD *pData; |
||
1339 | WORD byteWidth; |
||
1340 | |||
1341 | WORD temp; |
||
1342 | WORD sizeX, sizeY; |
||
1343 | WORD x, y; |
||
1344 | BYTE stretchX, stretchY; |
||
1345 | |||
1346 | // Set start address |
||
1347 | address = (long)(GetMaxX() + 1) * top + left; |
||
1348 | |||
1349 | // Get bitmap header |
||
1350 | ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp); |
||
1351 | |||
1352 | // Set offset to the image data |
||
1353 | memOffset = sizeof(BITMAP_HEADER); |
||
1354 | |||
1355 | // Get size |
||
1356 | sizeX = bmp.width; |
||
1357 | sizeY = bmp.height; |
||
1358 | |||
1359 | byteWidth = sizeX << 1; |
||
1360 | |||
1361 | for(y = 0; y < sizeY; y++) |
||
1362 | { |
||
1363 | |||
1364 | // Get line |
||
1365 | ExternalMemoryCallback(bitmap, memOffset, byteWidth, lineBuffer); |
||
1366 | memOffset += byteWidth; |
||
1367 | CS_LAT_BIT = 0; |
||
1368 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
1369 | { |
||
1370 | pData = lineBuffer; |
||
1371 | SetAddress(address); |
||
1372 | |||
1373 | for(x = 0; x < sizeX; x++) |
||
1374 | { |
||
1375 | temp = *pData++; |
||
1376 | SetColor(temp); |
||
1377 | |||
1378 | // Write pixel to screen |
||
1379 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
1380 | { |
||
1381 | WriteData(_color); |
||
1382 | } |
||
1383 | } |
||
1384 | |||
1385 | address += (GetMaxX() + 1); |
||
1386 | } |
||
1387 | |||
1388 | CS_LAT_BIT = 1; |
||
1389 | } |
||
1390 | } |
||
1391 | |||
1392 | #endif |
Powered by WebSVN v2.8.3