Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | /***************************************************************************** |
2 | * Module for Microchip Graphics Library |
||
3 | * Sitronix ST7529 controller driver |
||
4 | ***************************************************************************** |
||
5 | * FileName: ST7529.c |
||
6 | * Dependencies: Graphics.h |
||
7 | * Processor: PIC24 |
||
8 | * Compiler: MPLAB C30 |
||
9 | * Linker: MPLAB LINK30 |
||
10 | * Company: Microchip Technology Incorporated |
||
11 | * |
||
12 | * Software License Agreement |
||
13 | * |
||
14 | * Copyright © 2008 Microchip Technology Inc. All rights reserved. |
||
15 | * Microchip licenses to you the right to use, modify, copy and distribute |
||
16 | * Software only when embedded on a Microchip microcontroller or digital |
||
17 | * signal controller, which is integrated into your product or third party |
||
18 | * product (pursuant to the sublicense terms in the accompanying license |
||
19 | * agreement). |
||
20 | * |
||
21 | * You should refer to the license agreement accompanying this Software |
||
22 | * for additional information regarding your rights and obligations. |
||
23 | * |
||
24 | * SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY |
||
25 | * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY |
||
26 | * OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR |
||
27 | * PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR |
||
28 | * OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, |
||
29 | * BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT |
||
30 | * DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, |
||
31 | * INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, |
||
32 | * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY |
||
33 | * CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), |
||
34 | * OR OTHER SIMILAR COSTS. |
||
35 | * |
||
36 | * Author Date Comment |
||
37 | *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||
38 | * Anton Alkhimenok 03/20/08 |
||
39 | *****************************************************************************/ |
||
40 | #include "Graphics\Graphics.h" |
||
41 | |||
42 | // Color |
||
43 | BYTE _color; |
||
44 | |||
45 | // Clipping region control |
||
46 | SHORT _clipRgn; |
||
47 | |||
48 | // Clipping region borders |
||
49 | SHORT _clipLeft; |
||
50 | SHORT _clipTop; |
||
51 | SHORT _clipRight; |
||
52 | SHORT _clipBottom; |
||
53 | |||
54 | /////////////////////// LOCAL FUNCTIONS PROTOTYPES //////////////////////////// |
||
55 | void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch); |
||
56 | void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch); |
||
57 | void PutImage8BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch); |
||
58 | void PutImage1BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch); |
||
59 | void PutImage4BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch); |
||
60 | void PutImage8BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch); |
||
61 | |||
62 | /********************************************************************* |
||
63 | * Function: void ResetDevice() |
||
64 | * |
||
65 | * PreCondition: none |
||
66 | * |
||
67 | * Input: none |
||
68 | * |
||
69 | * Output: none |
||
70 | * |
||
71 | * Side Effects: none |
||
72 | * |
||
73 | * Overview: resets LCD, initializes PMP |
||
74 | * |
||
75 | * Note: none |
||
76 | * |
||
77 | ********************************************************************/ |
||
78 | void ResetDevice(void) |
||
79 | { |
||
80 | // Initialize device |
||
81 | DeviceInit(); |
||
82 | |||
83 | DelayMs(20); |
||
84 | DeviceSelect(); |
||
85 | |||
86 | DeviceSetCommand(); |
||
87 | DeviceWrite(EXTIN); //Ext = 0 |
||
88 | DeviceWrite(SLPOUT); //Sleep Out |
||
89 | DeviceWrite(OSCON); //OSC On |
||
90 | DeviceWrite(PWRCTRL); //Power Control Set |
||
91 | DeviceSetData(); |
||
92 | DeviceWrite(0x08); //Booster Must Be On First |
||
93 | DelayMs(2); |
||
94 | DeviceSetCommand(); |
||
95 | DeviceWrite(0x20); //Power Control Set |
||
96 | DeviceSetData(); |
||
97 | DeviceWrite(0x0B); //Booster, Regulator, Follower ON |
||
98 | DeviceSetCommand(); |
||
99 | DeviceWrite(VOLCTRL); //Electronic Control |
||
100 | DeviceSetData(); |
||
101 | DeviceWrite(0x3f); //Vop=18.0V |
||
102 | DeviceWrite(0x04); |
||
103 | DeviceSetCommand(); |
||
104 | DeviceWrite(DISCTRL); //Display Control |
||
105 | DeviceSetData(); |
||
106 | DeviceWrite(0x00); //CL=X1 |
||
107 | DeviceWrite(0x27); //Duty=160 |
||
108 | DeviceWrite(0x00); //FR Inverse-Set Value |
||
109 | DeviceSetCommand(); |
||
110 | DeviceWrite(DISNOR); // Normal Display |
||
111 | DeviceWrite(COMSCN); //COM Scan Direction |
||
112 | DeviceSetData(); |
||
113 | DeviceWrite(0x01); // 0->79 159->80 |
||
114 | DeviceSetCommand(); |
||
115 | DeviceWrite(DATSDR); //Data Scan Direction |
||
116 | DeviceSetData(); |
||
117 | #if (DISP_ORIENTATION == 180) |
||
118 | DeviceWrite(0x01); //Row Reverse |
||
119 | DeviceWrite(0x00); //Derect 3 Pixels Arrangement |
||
120 | #else |
||
121 | DeviceWrite(0x02); //Column Reverse |
||
122 | DeviceWrite(0x01); //Inverse 3 Pixels Arrangement |
||
123 | #endif |
||
124 | DeviceWrite(0x02); //3Byte 3Pixel mode |
||
125 | DeviceSetCommand(); |
||
126 | DeviceWrite(LASET); //Line Address Set(lines from 16 to 144 are used) |
||
127 | DeviceSetData(); |
||
128 | DeviceWrite(0x10); //Start Line=16 |
||
129 | DeviceWrite(0x8f); //End Line =144-1 |
||
130 | DeviceSetCommand(); |
||
131 | DeviceWrite(CASET); //Column Address Set |
||
132 | DeviceSetData(); |
||
133 | DeviceWrite(0x00); //Start Column=0 |
||
134 | DeviceWrite(0x54); //End Column =84 ((84+1)*3 == 255) |
||
135 | DeviceSetCommand(); |
||
136 | DeviceWrite(EXTOUT); //Ext = 1 |
||
137 | DeviceWrite(ANASET); //Analog Circuit Set |
||
138 | DeviceSetData(); |
||
139 | DeviceWrite(0x00); //OSC Frequency =000 (Default) |
||
140 | DeviceWrite(0x01); //Booster Efficiency=01(Default) |
||
141 | DeviceWrite(0x00); //Bias=1/14 |
||
142 | DeviceSetCommand(); |
||
143 | DeviceWrite(SWINT); //Software Initial |
||
144 | DeviceWrite(EXTIN); //Ext = 0 |
||
145 | DeviceWrite(DISON); //Display On |
||
146 | DeviceDeselect(); |
||
147 | DeviceSetData(); |
||
148 | DelayMs(100); |
||
149 | } |
||
150 | |||
151 | /********************************************************************* |
||
152 | * Function: void ContrastSet(WORD contrast) |
||
153 | * |
||
154 | * PreCondition: none |
||
155 | * |
||
156 | * Input: contrast value (LSB 10-0 are valid, MSB 15-11 are not used) |
||
157 | * |
||
158 | * Output: none |
||
159 | * |
||
160 | * Side Effects: none |
||
161 | * |
||
162 | * Overview: sets contrast |
||
163 | * |
||
164 | * Note: none |
||
165 | * |
||
166 | ********************************************************************/ |
||
167 | void ContrastSet(WORD contrast) |
||
168 | { |
||
169 | DeviceSelect(); |
||
170 | DeviceSetCommand(); |
||
171 | DeviceWrite(VOLCTRL); |
||
172 | DeviceSetData(); |
||
173 | DeviceWrite((((WORD_VAL) contrast).v[0])); |
||
174 | DeviceWrite((((WORD_VAL) contrast).v[1])); |
||
175 | DeviceDeselect(); |
||
176 | } |
||
177 | |||
178 | /********************************************************************* |
||
179 | * Function: void ContrastUp(void) |
||
180 | * |
||
181 | * PreCondition: none |
||
182 | * |
||
183 | * Input: none |
||
184 | * |
||
185 | * Output: none |
||
186 | * |
||
187 | * Side Effects: none |
||
188 | * |
||
189 | * Overview: increases contrast |
||
190 | * |
||
191 | * Note: none |
||
192 | * |
||
193 | ********************************************************************/ |
||
194 | void ContrastUp(void) |
||
195 | { |
||
196 | DeviceSelect(); |
||
197 | DeviceSetCommand(); |
||
198 | DeviceWrite(VOLUP); |
||
199 | DeviceDeselect(); |
||
200 | DeviceSetData(); |
||
201 | } |
||
202 | |||
203 | /********************************************************************* |
||
204 | * Function: void ContrastDown(void) |
||
205 | * |
||
206 | * PreCondition: none |
||
207 | * |
||
208 | * Input: none |
||
209 | * |
||
210 | * Output: none |
||
211 | * |
||
212 | * Side Effects: none |
||
213 | * |
||
214 | * Overview: decreases contrast |
||
215 | * |
||
216 | * Note: none |
||
217 | * |
||
218 | ********************************************************************/ |
||
219 | void ContrastDown(void) |
||
220 | { |
||
221 | DeviceSelect(); |
||
222 | DeviceSetCommand(); |
||
223 | DeviceWrite(VOLDOWN); //Electronic Control |
||
224 | DeviceDeselect(); |
||
225 | DeviceSetData(); |
||
226 | } |
||
227 | |||
228 | /********************************************************************* |
||
229 | * Function: void DisplayOn(void) |
||
230 | * |
||
231 | * PreCondition: none |
||
232 | * |
||
233 | * Input: none |
||
234 | * |
||
235 | * Output: none |
||
236 | * |
||
237 | * Side Effects: none |
||
238 | * |
||
239 | * Overview: turns on display |
||
240 | * |
||
241 | * Note: none |
||
242 | * |
||
243 | ********************************************************************/ |
||
244 | void DisplayOn(void) |
||
245 | { |
||
246 | DeviceSelect(); |
||
247 | DeviceSetCommand(); |
||
248 | DeviceWrite(DISON); |
||
249 | DeviceDeselect(); |
||
250 | DeviceSetData(); |
||
251 | } |
||
252 | |||
253 | /********************************************************************* |
||
254 | * Function: void DisplayOn(void) |
||
255 | * |
||
256 | * PreCondition: none |
||
257 | * |
||
258 | * Input: none |
||
259 | * |
||
260 | * Output: none |
||
261 | * |
||
262 | * Side Effects: none |
||
263 | * |
||
264 | * Overview: turns off display |
||
265 | * |
||
266 | * Note: none |
||
267 | * |
||
268 | ********************************************************************/ |
||
269 | void DisplayOff(void) |
||
270 | { |
||
271 | DeviceSelect(); |
||
272 | DeviceSetCommand(); |
||
273 | DeviceWrite(DISOFF); |
||
274 | DeviceDeselect(); |
||
275 | DeviceSetData(); |
||
276 | } |
||
277 | |||
278 | /********************************************************************* |
||
279 | * Function: void SleepIn(void) |
||
280 | * |
||
281 | * PreCondition: none |
||
282 | * |
||
283 | * Input: none |
||
284 | * |
||
285 | * Output: none |
||
286 | * |
||
287 | * Side Effects: none |
||
288 | * |
||
289 | * Overview: enters sleep mode |
||
290 | * |
||
291 | * Note: none |
||
292 | * |
||
293 | ********************************************************************/ |
||
294 | void SleepIn(void) |
||
295 | { |
||
296 | DeviceSelect(); |
||
297 | DeviceSetCommand(); |
||
298 | DeviceWrite(SLPIN); |
||
299 | DeviceDeselect(); |
||
300 | DeviceSetData(); |
||
301 | } |
||
302 | |||
303 | /********************************************************************* |
||
304 | * Function: void WakeUp(void) |
||
305 | * |
||
306 | * PreCondition: none |
||
307 | * |
||
308 | * Input: none |
||
309 | * |
||
310 | * Output: none |
||
311 | * |
||
312 | * Side Effects: none |
||
313 | * |
||
314 | * Overview: wakes up from sleep |
||
315 | * |
||
316 | * Note: none |
||
317 | * |
||
318 | ********************************************************************/ |
||
319 | void WakeUp(void) |
||
320 | { |
||
321 | DeviceSelect(); |
||
322 | DeviceSetCommand(); |
||
323 | DeviceWrite(SLPOUT); |
||
324 | DeviceDeselect(); |
||
325 | DeviceSetData(); |
||
326 | } |
||
327 | |||
328 | /********************************************************************* |
||
329 | * Function: void PutPixel(SHORT x, SHORT y) |
||
330 | * |
||
331 | * PreCondition: none |
||
332 | * |
||
333 | * Input: pixel position |
||
334 | * |
||
335 | * Output: none |
||
336 | * |
||
337 | * Side Effects: none |
||
338 | * |
||
339 | * Overview: puts pixel with current color at given position |
||
340 | * |
||
341 | * Note: none |
||
342 | * |
||
343 | ********************************************************************/ |
||
344 | void PutPixel(SHORT x, SHORT y) |
||
345 | { |
||
346 | BYTE columnPixel[3]; // 3 Pixels in each column |
||
347 | if(_clipRgn) |
||
348 | { |
||
349 | if(x < _clipLeft) |
||
350 | return; |
||
351 | if(x > _clipRight) |
||
352 | return; |
||
353 | if(y < _clipTop) |
||
354 | return; |
||
355 | if(y > _clipBottom) |
||
356 | return; |
||
357 | } |
||
358 | |||
359 | DeviceSelect(); |
||
360 | |||
361 | // Set Row and Column Address |
||
362 | DeviceSetCommand(); |
||
363 | DeviceWrite(LASET); |
||
364 | DeviceSetData(); |
||
365 | DeviceWrite(y + 16); |
||
366 | DeviceWrite(0x8f); |
||
367 | DeviceSetCommand(); |
||
368 | DeviceWrite(CASET); |
||
369 | DeviceSetData(); |
||
370 | DeviceWrite(x / 3); |
||
371 | DeviceWrite(0x54); |
||
372 | |||
373 | // Read Column |
||
374 | DeviceSetCommand(); |
||
375 | DeviceWrite(RMWIN); |
||
376 | DeviceSetData(); |
||
377 | columnPixel[0] = DeviceRead(); // Dummy reading |
||
378 | columnPixel[0] = DeviceRead(); // Start reading cycle for pixel 0 |
||
379 | columnPixel[1] = DeviceRead(); // Start reading cycle for pixel 1 |
||
380 | columnPixel[2] = DeviceRead(); // Start reading cycle for pixel 2 |
||
381 | |||
382 | // Modify pixel |
||
383 | columnPixel[x % 3] = _color; |
||
384 | |||
385 | // Write Column |
||
386 | DeviceWrite(columnPixel[0]); |
||
387 | DeviceWrite(columnPixel[1]); |
||
388 | DeviceWrite(columnPixel[2]); |
||
389 | |||
390 | DeviceSetCommand(); |
||
391 | DeviceWrite(RMWOUT); |
||
392 | DeviceDeselect(); |
||
393 | DeviceSetData(); |
||
394 | } |
||
395 | |||
396 | /********************************************************************* |
||
397 | * Function: WORD GetPixel(SHORT x, SHORT y) |
||
398 | * |
||
399 | * PreCondition: none |
||
400 | * |
||
401 | * Input: pixel position |
||
402 | * |
||
403 | * Output: pixel color |
||
404 | * |
||
405 | * Side Effects: none |
||
406 | * |
||
407 | * Overview: returns pixel at given position |
||
408 | * |
||
409 | * Note: none |
||
410 | * |
||
411 | ********************************************************************/ |
||
412 | WORD GetPixel(SHORT x, SHORT y) |
||
413 | { |
||
414 | BYTE columnPixel[3]; // 3 Pixels in each column |
||
415 | DeviceSelect(); |
||
416 | |||
417 | // Set Row and Column Address |
||
418 | DeviceSetCommand(); |
||
419 | DeviceWrite(LASET); |
||
420 | DeviceSetData(); |
||
421 | DeviceWrite(y + 16); |
||
422 | DeviceWrite(0x8f); |
||
423 | DeviceSetCommand(); |
||
424 | DeviceWrite(CASET); |
||
425 | DeviceSetData(); |
||
426 | DeviceWrite(x / 3); |
||
427 | DeviceWrite(0x54); |
||
428 | |||
429 | // Read Column |
||
430 | DeviceSetCommand(); |
||
431 | DeviceWrite(RMWIN); |
||
432 | DeviceSetData(); |
||
433 | columnPixel[0] = DeviceRead(); // Dummy |
||
434 | columnPixel[0] = DeviceRead(); // Start reading cycle for pixel 0 |
||
435 | columnPixel[1] = DeviceRead(); // Start reading cycle for pixel 1 |
||
436 | columnPixel[2] = DeviceRead(); // Start reading cycle for pixel 2 |
||
437 | DeviceSetCommand(); |
||
438 | DeviceWrite(RMWOUT); |
||
439 | DeviceDeselect(); |
||
440 | DeviceSetData(); |
||
441 | |||
442 | return (columnPixel[x % 3]); |
||
443 | } |
||
444 | |||
445 | /********************************************************************* |
||
446 | * Function: void ClearDevice(void) |
||
447 | * |
||
448 | * PreCondition: none |
||
449 | * |
||
450 | * Input: none |
||
451 | * |
||
452 | * Output: none |
||
453 | * |
||
454 | * Side Effects: none |
||
455 | * |
||
456 | * Overview: clears screen with current color |
||
457 | * |
||
458 | * Note: none |
||
459 | * |
||
460 | ********************************************************************/ |
||
461 | void ClearDevice(void) |
||
462 | { |
||
463 | WORD counter; |
||
464 | |||
465 | DeviceSelect(); |
||
466 | |||
467 | // Whole screen |
||
468 | DeviceSetCommand(); |
||
469 | DeviceWrite(LASET); //Line Address Set(lines from 16 to 144 are used) |
||
470 | DeviceSetData(); |
||
471 | DeviceWrite(0x10); //Start Line=16 |
||
472 | DeviceWrite(0x8f); //End Line =144-1 |
||
473 | DeviceSetCommand(); |
||
474 | DeviceWrite(CASET); //Column Address Set |
||
475 | DeviceSetData(); |
||
476 | DeviceWrite(0x00); //Start Column=0 |
||
477 | DeviceWrite(0x54); //End Column =84 ((84+1)*3 == 255) |
||
478 | DeviceSetCommand(); |
||
479 | DeviceWrite(RAMWR); |
||
480 | DeviceSetData(); |
||
481 | for(counter = 0; counter < (WORD) (GetMaxX() + 1) * (GetMaxY() + 1); counter++) |
||
482 | { |
||
483 | DeviceWrite(_color); |
||
484 | } |
||
485 | |||
486 | DeviceDeselect(); |
||
487 | } |
Powered by WebSVN v2.8.3