]> git.sur5r.net Git - freertos/blob - Demo/CORTEX_LM3Sxxxx_IAR_Keil/formike128x128x16.c
Start to re-arrange files to include FreeRTOS+ in main download.
[freertos] / Demo / CORTEX_LM3Sxxxx_IAR_Keil / formike128x128x16.c
1 //*****************************************************************************\r
2 //\r
3 // formike128x128x16.c - Display driver for the Formike Electronic\r
4 //                       KWH015C04-F01 CSTN panel with an ST7637 controller.\r
5 //\r
6 // Copyright (c) 2008 Luminary Micro, Inc.  All rights reserved.\r
7 // \r
8 // Software License Agreement\r
9 // \r
10 // Luminary Micro, Inc. (LMI) is supplying this software for use solely and\r
11 // exclusively on LMI's microcontroller products.\r
12 // \r
13 // The software is owned by LMI and/or its suppliers, and is protected under\r
14 // applicable copyright laws.  All rights are reserved.  You may not combine\r
15 // this software with "viral" open-source software in order to form a larger\r
16 // program.  Any use in violation of the foregoing restrictions may subject\r
17 // the user to criminal sanctions under applicable laws, as well as to civil\r
18 // liability for the breach of the terms and conditions of this license.\r
19 // \r
20 // THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
21 // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
22 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
23 // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR\r
24 // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.\r
25 // \r
26 // This is part of revision 2523 of the Stellaris Peripheral Driver Library.\r
27 //\r
28 //*****************************************************************************\r
29 \r
30 //*****************************************************************************\r
31 //\r
32 //! \addtogroup ek_lm3s3748_api\r
33 //! @{\r
34 //\r
35 //*****************************************************************************\r
36 \r
37 #include "hw_gpio.h"\r
38 #include "hw_memmap.h"\r
39 #include "hw_types.h"\r
40 #include "gpio.h"\r
41 #include "sysctl.h"\r
42 #include "rom.h"\r
43 #include "grlib.h"\r
44 #include "formike128x128x16.h"\r
45 #include <string.h>\r
46 \r
47 //*****************************************************************************\r
48 //\r
49 // Defines for the pins that are used to communicate with the ST7637.\r
50 //\r
51 //*****************************************************************************\r
52 #define LCD_A0_BASE            GPIO_PORTB_BASE\r
53 #define LCD_A0_PIN             GPIO_PIN_2\r
54 #define LCD_WR_BASE            GPIO_PORTC_BASE\r
55 #define LCD_WR_PIN             GPIO_PIN_4\r
56 #define LCD_RD_BASE            GPIO_PORTC_BASE\r
57 #define LCD_RD_PIN             GPIO_PIN_5\r
58 #define LCD_BL_BASE            GPIO_PORTF_BASE\r
59 #define LCD_BL_PIN             GPIO_PIN_1\r
60 #define LCD_DATA_BASE          GPIO_PORTG_BASE\r
61 \r
62 //*****************************************************************************\r
63 //\r
64 // Translates a 24-bit RGB color to a display driver-specific color.\r
65 //\r
66 // \param c is the 24-bit RGB color.  The least-significant byte is the blue\r
67 // channel, the next byte is the green channel, and the third byte is the red\r
68 // channel.\r
69 //\r
70 // This macro translates a 24-bit RGB color into a value that can be written\r
71 // into the display's frame buffer in order to reproduce that color, or the\r
72 // closest possible approximation of that color.\r
73 //\r
74 // \return Returns the display-driver specific color.\r
75 //\r
76 //*****************************************************************************\r
77 #define DPYCOLORTRANSLATE(c)    ((((c) & 0x00ff0000) >> 19) |               \\r
78                                  ((((c) & 0x0000ff00) >> 5) & 0x000007e0) | \\r
79                                  ((((c) & 0x000000ff) << 8) & 0x0000f800))\r
80 \r
81 //*****************************************************************************\r
82 //\r
83 // Writes a data word to the ST7637.\r
84 //\r
85 //*****************************************************************************\r
86 static void\r
87 WriteData(unsigned char ucData)\r
88 {\r
89     //\r
90     // Write the data to the data bus.\r
91     //\r
92     HWREG(LCD_DATA_BASE + GPIO_O_DATA + (0xff << 2)) = ucData;\r
93 \r
94     //\r
95     // Assert the write enable signal.\r
96     //\r
97     HWREG(LCD_WR_BASE + GPIO_O_DATA + (LCD_WR_PIN << 2)) = 0;\r
98 \r
99     //\r
100     // Deassert the write enable signal.\r
101     //\r
102     HWREG(LCD_WR_BASE + GPIO_O_DATA + (LCD_WR_PIN << 2)) = LCD_WR_PIN;\r
103 }\r
104 \r
105 //*****************************************************************************\r
106 //\r
107 // Writes a command to the ST7637.\r
108 //\r
109 //*****************************************************************************\r
110 static void\r
111 WriteCommand(unsigned char ucData)\r
112 {\r
113     //\r
114     // Write the command to the data bus.\r
115     //\r
116     HWREG(LCD_DATA_BASE + GPIO_O_DATA + (0xff << 2)) = ucData;\r
117 \r
118     //\r
119     // Set the A0 signal low, indicating a command.\r
120     //\r
121     HWREG(LCD_A0_BASE + GPIO_O_DATA + (LCD_A0_PIN << 2)) = 0;\r
122 \r
123     //\r
124     // Assert the write enable signal.\r
125     //\r
126     HWREG(LCD_WR_BASE + GPIO_O_DATA + (LCD_WR_PIN << 2)) = 0;\r
127 \r
128     //\r
129     // Deassert the write enable signal.\r
130     //\r
131     HWREG(LCD_WR_BASE + GPIO_O_DATA + (LCD_WR_PIN << 2)) = LCD_WR_PIN;\r
132 \r
133     //\r
134     // Set the A0 signal high, indicating that following writes are data.\r
135     //\r
136     HWREG(LCD_A0_BASE + GPIO_O_DATA + (LCD_A0_PIN << 2)) = LCD_A0_PIN;\r
137 }\r
138 \r
139 //*****************************************************************************\r
140 //\r
141 //! Initializes the display driver.\r
142 //!\r
143 //! This function initializes the ST7637 display controller on the panel,\r
144 //! preparing it to display data.\r
145 //!\r
146 //! \return None.\r
147 //\r
148 //*****************************************************************************\r
149 void\r
150 Formike128x128x16Init(void)\r
151 {\r
152     unsigned long ulClockMS, ulCount;\r
153 \r
154     //\r
155     // Get the value to pass to SysCtlDelay() in order to delay for 1 ms.\r
156     //\r
157     ulClockMS = SysCtlClockGet() / (3 * 1000);\r
158 \r
159     //\r
160     // Enable the GPIO peripherals used to interface to the ST7637.\r
161     //\r
162     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);\r
163     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);\r
164     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);\r
165     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);\r
166 \r
167     //\r
168     // Configure the pins that connect to the LCD as GPIO outputs.\r
169     //\r
170     GPIOPinTypeGPIOOutput(LCD_A0_BASE, LCD_A0_PIN);\r
171     GPIOPinTypeGPIOOutput(LCD_WR_BASE, LCD_WR_PIN);\r
172     GPIOPinTypeGPIOOutput(LCD_RD_BASE, LCD_RD_PIN);\r
173     GPIOPinTypeGPIOOutput(LCD_BL_BASE, LCD_BL_PIN);\r
174     GPIOPinTypeGPIOOutput(LCD_DATA_BASE, 0xff);\r
175 \r
176     //\r
177     // Set the LCD control pins to their default values.\r
178     //\r
179     GPIOPinWrite(LCD_A0_BASE, LCD_A0_PIN, LCD_A0_PIN);\r
180     GPIOPinWrite(LCD_WR_BASE, LCD_WR_PIN | LCD_RD_PIN,\r
181                      LCD_WR_PIN | LCD_RD_PIN);\r
182     GPIOPinWrite(LCD_BL_BASE, LCD_BL_PIN, 0);\r
183     GPIOPinWrite(LCD_DATA_BASE, 0xff, 0x00);\r
184 \r
185     //\r
186     // Perform a software reset of the ST7637.\r
187     //\r
188     WriteCommand(0x01);\r
189 \r
190     //\r
191     // Delay for 120ms.\r
192     //\r
193     SysCtlDelay(ulClockMS * 120);\r
194 \r
195     //\r
196     // Disable auto-load of mask rom data.\r
197     //\r
198     WriteCommand(0xD7);\r
199     WriteData(0xBF);\r
200 \r
201     //\r
202     // Set the OTP control mode to read.\r
203     //\r
204     WriteCommand(0xE0);\r
205     WriteData(0x00);\r
206 \r
207     //\r
208     // Delay for 10ms.\r
209     //\r
210     SysCtlDelay(ulClockMS * 10);\r
211 \r
212     //\r
213     // Start the OTP read.\r
214     //\r
215     WriteCommand(0xE3);\r
216 \r
217     //\r
218     // Delay for 20ms.\r
219     //\r
220     SysCtlDelay(ulClockMS * 20);\r
221 \r
222     //\r
223     // Cancel the OTP read (it should have finished by now).\r
224     //\r
225     WriteCommand(0xE1);\r
226 \r
227     //\r
228     // Turn off the display.\r
229     //\r
230     WriteCommand(0x28);\r
231 \r
232     //\r
233     // Exit sleep mode.\r
234     //\r
235     WriteCommand(0x11);\r
236 \r
237     //\r
238     // Delay for 50ms.\r
239     //\r
240     SysCtlDelay(ulClockMS * 50);\r
241 \r
242     //\r
243     // Program the LCD supply voltage V0 to 14V.\r
244     //\r
245     WriteCommand(0xC0);\r
246     WriteData(0x04);\r
247     WriteData(0x01);\r
248 \r
249     //\r
250     // Select an LCD bias voltage ratio of 1/12.\r
251     //\r
252     WriteCommand(0xC3);\r
253     WriteData(0x00);\r
254 \r
255     //\r
256     // Enable the x8 booster circuit.\r
257     //\r
258     WriteCommand(0xC4);\r
259     WriteData(0x07);\r
260 \r
261     //\r
262     // Invert the column scan direction for the panel.\r
263     //\r
264     WriteCommand(0xB7);\r
265     WriteData(0xC0);\r
266 \r
267     //\r
268     // Select 16bpp, 5-6-5 data input mode.\r
269     //\r
270     WriteCommand(0x3A);\r
271     WriteData(0x05);\r
272 \r
273     //\r
274     // Select the memory scanning direction.  The scanning mode does not matter\r
275     // for this driver since the row/column selects will constrain the writes\r
276     // to the desired area of the display.\r
277     //\r
278     WriteCommand(0x36);\r
279     WriteData(0x00);\r
280 \r
281     //\r
282     // Turn on the display.\r
283     //\r
284     WriteCommand(0x29);\r
285 \r
286     //\r
287     // Clear the contents of the display buffer.\r
288     //\r
289     WriteCommand(0x2A);\r
290     WriteData(0x00);\r
291     WriteData(0x7F);\r
292     WriteCommand(0x2B);\r
293     WriteData(0x01);\r
294     WriteData(0x80);\r
295     WriteCommand(0x2c);\r
296     for(ulCount = 0; ulCount < (128 * 128); ulCount++)\r
297     {\r
298         WriteData(0x00);\r
299         WriteData(0x00);\r
300     }\r
301 \r
302     //\r
303     // Enable normal operation of the LCD.\r
304     //\r
305     WriteCommand(0x13);\r
306 }\r
307 \r
308 //*****************************************************************************\r
309 //\r
310 //! Turns on the backlight.\r
311 //!\r
312 //! This function turns on the backlight on the display.\r
313 //!\r
314 //! \return None.\r
315 //\r
316 //*****************************************************************************\r
317 void\r
318 Formike128x128x16BacklightOn(void)\r
319 {\r
320     //\r
321     // Assert the signal that turns on the backlight.\r
322     //\r
323     HWREG(LCD_BL_BASE + GPIO_O_DATA + (LCD_BL_PIN << 2)) = LCD_BL_PIN;\r
324 }\r
325 \r
326 //*****************************************************************************\r
327 //\r
328 //! Turns off the backlight.\r
329 //!\r
330 //! This function turns off the backlight on the display.\r
331 //!\r
332 //! \return None.\r
333 //\r
334 //*****************************************************************************\r
335 void\r
336 Formike128x128x16BacklightOff(void)\r
337 {\r
338     //\r
339     // Deassert the signal that turns on the backlight.\r
340     //\r
341     HWREG(LCD_BL_BASE + GPIO_O_DATA + (LCD_BL_PIN << 2)) = 0;\r
342 }\r
343 \r
344 //*****************************************************************************\r
345 //\r
346 //! Draws a pixel on the screen.\r
347 //!\r
348 //! \param pvDisplayData is a pointer to the driver-specific data for this\r
349 //! display driver.\r
350 //! \param lX is the X coordinate of the pixel.\r
351 //! \param lY is the Y coordinate of the pixel.\r
352 //! \param ulValue is the color of the pixel.\r
353 //!\r
354 //! This function sets the given pixel to a particular color.  The coordinates\r
355 //! of the pixel are assumed to be within the extents of the display.\r
356 //!\r
357 //! \return None.\r
358 //\r
359 //*****************************************************************************\r
360 static void\r
361 Formike128x128x16PixelDraw(void *pvDisplayData, long lX, long lY,\r
362                            unsigned long ulValue)\r
363 {\r
364     //\r
365     // Set the X address of the display cursor.\r
366     //\r
367     WriteCommand(0x2a);\r
368     WriteData(lX);\r
369     WriteData(lX);\r
370 \r
371     //\r
372     // Set the Y address of the display cursor.\r
373     //\r
374     WriteCommand(0x2b);\r
375     WriteData(lY + 1);\r
376     WriteData(lY + 1);\r
377 \r
378     //\r
379     // Write the pixel value.\r
380     //\r
381     WriteCommand(0x2c);\r
382     WriteData(ulValue >> 8);\r
383     WriteData(ulValue);\r
384 }\r
385 \r
386 //*****************************************************************************\r
387 //\r
388 //! Draws a horizontal sequence of pixels on the screen.\r
389 //!\r
390 //! \param pvDisplayData is a pointer to the driver-specific data for this\r
391 //! display driver.\r
392 //! \param lX is the X coordinate of the first pixel.\r
393 //! \param lY is the Y coordinate of the first pixel.\r
394 //! \param lX0 is sub-pixel offset within the pixel data, which is valid for 1\r
395 //! or 4 bit per pixel formats.\r
396 //! \param lCount is the number of pixels to draw.\r
397 //! \param lBPP is the number of bits per pixel; must be 1, 4, or 8.\r
398 //! \param pucData is a pointer to the pixel data.  For 1 and 4 bit per pixel\r
399 //! formats, the most significant bit(s) represent the left-most pixel.\r
400 //! \param pucPalette is a pointer to the palette used to draw the pixels.\r
401 //!\r
402 //! This function draws a horizontal sequence of pixels on the screen, using\r
403 //! the supplied palette.  For 1 bit per pixel format, the palette contains\r
404 //! pre-translated colors; for 4 and 8 bit per pixel formats, the palette\r
405 //! contains 24-bit RGB values that must be translated before being written to\r
406 //! the display.\r
407 //!\r
408 //! \return None.\r
409 //\r
410 //*****************************************************************************\r
411 static void\r
412 Formike128x128x16PixelDrawMultiple(void *pvDisplayData, long lX, long lY,\r
413                                    long lX0, long lCount, long lBPP,\r
414                                    const unsigned char *pucData,\r
415                                    const unsigned char *pucPalette)\r
416 {\r
417     unsigned long ulByte;\r
418 \r
419     //\r
420     // Set the extent of the line along the X axis.\r
421     //\r
422     WriteCommand(0x2a);\r
423     WriteData(lX);\r
424     WriteData(lX + lCount - 1);\r
425 \r
426     //\r
427     // Set the Y address of the display cursor.\r
428     //\r
429     WriteCommand(0x2b);\r
430     WriteData(lY + 1);\r
431     WriteData(lY + 1);\r
432 \r
433     //\r
434     // Write the data RAM write command.\r
435     //\r
436     WriteCommand(0x2c);\r
437 \r
438     //\r
439     // Determine how to interpret the pixel data based on the number of bits\r
440     // per pixel.\r
441     //\r
442     switch(lBPP)\r
443     {\r
444         //\r
445         // The pixel data is in 1 bit per pixel format.\r
446         //\r
447         case 1:\r
448         {\r
449             //\r
450             // Loop while there are more pixels to draw.\r
451             //\r
452             while(lCount)\r
453             {\r
454                 //\r
455                 // Get the next byte of image data.\r
456                 //\r
457                 ulByte = *pucData++;\r
458 \r
459                 //\r
460                 // Loop through the pixels in this byte of image data.\r
461                 //\r
462                 for(; (lX0 < 8) && lCount; lX0++, lCount--)\r
463                 {\r
464                     //\r
465                     // Draw this pixel in the appropriate color.\r
466                     //\r
467                     lBPP = ((unsigned long *)pucPalette)[(ulByte >>\r
468                                                           (7 - lX0)) & 1];\r
469                     WriteData(lBPP >> 8);\r
470                     WriteData(lBPP);\r
471                 }\r
472 \r
473                 //\r
474                 // Start at the beginning of the next byte of image data.\r
475                 //\r
476                 lX0 = 0;\r
477             }\r
478 \r
479             //\r
480             // The image data has been drawn.\r
481             //\r
482             break;\r
483         }\r
484 \r
485         //\r
486         // The pixel data is in 4 bit per pixel format.\r
487         //\r
488         case 4:\r
489         {\r
490             //\r
491             // Loop while there are more pixels to draw.  "Duff's device" is\r
492             // used to jump into the middle of the loop if the first nibble of\r
493             // the pixel data should not be used.  Duff's device makes use of\r
494             // the fact that a case statement is legal anywhere within a\r
495             // sub-block of a switch statement.  See\r
496             // http://en.wikipedia.org/wiki/Duff's_device for detailed\r
497             // information about Duff's device.\r
498             //\r
499             switch(lX0 & 1)\r
500             {\r
501                 case 0:\r
502                     while(lCount)\r
503                     {\r
504                         //\r
505                         // Get the upper nibble of the next byte of pixel data\r
506                         // and extract the corresponding entry from the\r
507                         // palette.\r
508                         //\r
509                         ulByte = (*pucData >> 4) * 3;\r
510                         ulByte = (*(unsigned long *)(pucPalette + ulByte) &\r
511                                   0x00ffffff);\r
512 \r
513                         //\r
514                         // Translate this palette entry and write it to the\r
515                         // screen.\r
516                         //\r
517                         ulByte = DPYCOLORTRANSLATE(ulByte);\r
518                         WriteData(ulByte >> 8);\r
519                         WriteData(ulByte);\r
520 \r
521                         //\r
522                         // Decrement the count of pixels to draw.\r
523                         //\r
524                         lCount--;\r
525 \r
526                         //\r
527                         // See if there is another pixel to draw.\r
528                         //\r
529                         if(lCount)\r
530                         {\r
531                 case 1:\r
532                             //\r
533                             // Get the lower nibble of the next byte of pixel\r
534                             // data and extract the corresponding entry from\r
535                             // the palette.\r
536                             //\r
537                             ulByte = (*pucData++ & 15) * 3;\r
538                             ulByte = (*(unsigned long *)(pucPalette + ulByte) &\r
539                                       0x00ffffff);\r
540 \r
541                             //\r
542                             // Translate this palette entry and write it to the\r
543                             // screen.\r
544                             //\r
545                             ulByte = DPYCOLORTRANSLATE(ulByte);\r
546                             WriteData(ulByte >> 8);\r
547                             WriteData(ulByte);\r
548 \r
549                             //\r
550                             // Decrement the count of pixels to draw.\r
551                             //\r
552                             lCount--;\r
553                         }\r
554                     }\r
555             }\r
556 \r
557             //\r
558             // The image data has been drawn.\r
559             //\r
560             break;\r
561         }\r
562 \r
563         //\r
564         // The pixel data is in 8 bit per pixel format.\r
565         //\r
566         case 8:\r
567         {\r
568             //\r
569             // Loop while there are more pixels to draw.\r
570             //\r
571             while(lCount--)\r
572             {\r
573                 //\r
574                 // Get the next byte of pixel data and extract the\r
575                 // corresponding entry from the palette.\r
576                 //\r
577                 ulByte = *pucData++ * 3;\r
578                 ulByte = *(unsigned long *)(pucPalette + ulByte) & 0x00ffffff;\r
579 \r
580                 //\r
581                 // Translate this palette entry and write it to the screen.\r
582                 //\r
583                 ulByte = DPYCOLORTRANSLATE(ulByte);\r
584                 WriteData(ulByte >> 8);\r
585                 WriteData(ulByte);\r
586             }\r
587 \r
588             //\r
589             // The image data has been drawn.\r
590             //\r
591             break;\r
592         }\r
593     }\r
594 }\r
595 \r
596 //*****************************************************************************\r
597 //\r
598 //! Flushes any cached drawing operations.\r
599 //!\r
600 //! \param pvDisplayData is a pointer to the driver-specific data for this\r
601 //! display driver.\r
602 //!\r
603 //! This functions flushes any cached drawing operations to the display.  This\r
604 //! is useful when a local frame buffer is used for drawing operations, and the\r
605 //! flush would copy the local frame buffer to the display.  For the ST7637\r
606 //! driver, the flush is a no operation.\r
607 //!\r
608 //! \return None.\r
609 //\r
610 //*****************************************************************************\r
611 static void\r
612 Formike128x128x16Flush(void *pvDisplayData)\r
613 {\r
614     //\r
615     // There is nothing to be done.\r
616     //\r
617 }\r
618 \r
619 //*****************************************************************************\r
620 //\r
621 //! Draws a horizontal line.\r
622 //!\r
623 //! \param pvDisplayData is a pointer to the driver-specific data for this\r
624 //! display driver.\r
625 //! \param lX1 is the X coordinate of the start of the line.\r
626 //! \param lX2 is the X coordinate of the end of the line.\r
627 //! \param lY is the Y coordinate of the line.\r
628 //! \param ulValue is the color of the line.\r
629 //!\r
630 //! This function draws a horizontal line on the display.  The coordinates of\r
631 //! the line are assumed to be within the extents of the display.\r
632 //!\r
633 //! \return None.\r
634 //\r
635 //*****************************************************************************\r
636 static void\r
637 Formike128x128x16LineDrawH(void *pvDisplayData, long lX1, long lX2, long lY,\r
638                            unsigned long ulValue)\r
639 {\r
640     //\r
641     // Set the extent of the line along the X axis.\r
642     //\r
643     WriteCommand(0x2a);\r
644     WriteData(lX1);\r
645     WriteData(lX2);\r
646 \r
647     //\r
648     // Set the Y address of the display cursor.\r
649     //\r
650     WriteCommand(0x2b);\r
651     WriteData(lY + 1);\r
652     WriteData(lY + 1);\r
653 \r
654     //\r
655     // Write the data RAM write command.\r
656     //\r
657     WriteCommand(0x2c);\r
658 \r
659     //\r
660     // Loop through the pixels of this horizontal line.\r
661     //\r
662     while(lX1++ <= lX2)\r
663     {\r
664         //\r
665         // Write the pixel value.\r
666         //\r
667         WriteData(ulValue >> 8);\r
668         WriteData(ulValue);\r
669     }\r
670 }\r
671 \r
672 //*****************************************************************************\r
673 //\r
674 //! Draws a vertical line.\r
675 //!\r
676 //! \param pvDisplayData is a pointer to the driver-specific data for this\r
677 //! display driver.\r
678 //! \param lX is the X coordinate of the line.\r
679 //! \param lY1 is the Y coordinate of the start of the line.\r
680 //! \param lY2 is the Y coordinate of the end of the line.\r
681 //! \param ulValue is the color of the line.\r
682 //!\r
683 //! This function draws a vertical line on the display.  The coordinates of the\r
684 //! line are assumed to be within the extents of the display.\r
685 //!\r
686 //! \return None.\r
687 //\r
688 //*****************************************************************************\r
689 static void\r
690 Formike128x128x16LineDrawV(void *pvDisplayData, long lX, long lY1, long lY2,\r
691                            unsigned long ulValue)\r
692 {\r
693     //\r
694     // Set the X address of the display cursor.\r
695     //\r
696     WriteCommand(0x2a);\r
697     WriteData(lX);\r
698     WriteData(lX);\r
699 \r
700     //\r
701     // Set the extent of the line along the Y axis.\r
702     //\r
703     WriteCommand(0x2b);\r
704     WriteData(lY1 + 1);\r
705     WriteData(lY2 + 1);\r
706 \r
707     //\r
708     // Write the data RAM write command.\r
709     //\r
710     WriteCommand(0x2c);\r
711 \r
712     //\r
713     // Loop through the pixels of this vertical line.\r
714     //\r
715     while(lY1++ <= lY2)\r
716     {\r
717         //\r
718         // Write the pixel value.\r
719         //\r
720         WriteData(ulValue >> 8);\r
721         WriteData(ulValue);\r
722     }\r
723 }\r
724 \r
725 //*****************************************************************************\r
726 //\r
727 //! Fills a rectangle.\r
728 //!\r
729 //! \param pvDisplayData is a pointer to the driver-specific data for this\r
730 //! display driver.\r
731 //! \param pRect is a pointer to the structure describing the rectangle.\r
732 //! \param ulValue is the color of the rectangle.\r
733 //!\r
734 //! This function fills a rectangle on the display.  The coordinates of the\r
735 //! rectangle are assumed to be within the extents of the display, and the\r
736 //! rectangle specification is fully inclusive (i.e. both sXMin and sXMax are\r
737 //! drawn, along with sYMin and sYMax).\r
738 //!\r
739 //! \return None.\r
740 //\r
741 //*****************************************************************************\r
742 static void\r
743 Formike128x128x16RectFill(void *pvDisplayData, const tRectangle *pRect,\r
744                           unsigned long ulValue)\r
745 {\r
746     long lCount;\r
747 \r
748     //\r
749     // Set the extent of the rectangle along the X axis.\r
750     //\r
751     WriteCommand(0x2a);\r
752     WriteData(pRect->sXMin);\r
753     WriteData(pRect->sXMax);\r
754 \r
755     //\r
756     // Set the extent of the rectangle along the Y axis.\r
757     //\r
758     WriteCommand(0x2b);\r
759     WriteData(pRect->sYMin + 1);\r
760     WriteData(pRect->sYMax + 1);\r
761 \r
762     //\r
763     // Write the data RAM write command.\r
764     //\r
765     WriteCommand(0x2c);\r
766 \r
767     //\r
768     // Loop through the pixels in this rectangle.\r
769     //\r
770     for(lCount = ((pRect->sXMax - pRect->sXMin + 1) *\r
771                   (pRect->sYMax - pRect->sYMin + 1)); lCount > 0; lCount--)\r
772     {\r
773         //\r
774         // Write the pixel value.\r
775         //\r
776         WriteData(ulValue >> 8);\r
777         WriteData(ulValue);\r
778     }\r
779 }\r
780 \r
781 //*****************************************************************************\r
782 //\r
783 //! Translates a 24-bit RGB color to a display driver-specific color.\r
784 //!\r
785 //! \param pvDisplayData is a pointer to the driver-specific data for this\r
786 //! display driver.\r
787 //! \param ulValue is the 24-bit RGB color.  The least-significant byte is the\r
788 //! blue channel, the next byte is the green channel, and the third byte is the\r
789 //! red channel.\r
790 //!\r
791 //! This function translates a 24-bit RGB color into a value that can be\r
792 //! written into the display's frame buffer in order to reproduce that color,\r
793 //! or the closest possible approximation of that color.\r
794 //!\r
795 //! \return Returns the display-driver specific color.\r
796 //\r
797 //*****************************************************************************\r
798 static unsigned long\r
799 Formike128x128x16ColorTranslate(void *pvDisplayData, unsigned long ulValue)\r
800 {\r
801     //\r
802     // Translate from a 24-bit RGB color to a 5-6-5 RGB color.\r
803     //\r
804     return(DPYCOLORTRANSLATE(ulValue));\r
805 }\r
806 \r
807 //*****************************************************************************\r
808 //\r
809 //! The display structure that describes the driver for the Formike Electronic\r
810 //! KWH015C04-F01 CSTN panel with an ST7637 controller.\r
811 //\r
812 //*****************************************************************************\r
813 const tDisplay g_sFormike128x128x16 =\r
814 {\r
815     sizeof(tDisplay),\r
816     0,\r
817     128,\r
818     128,\r
819     Formike128x128x16PixelDraw,\r
820     Formike128x128x16PixelDrawMultiple,\r
821     Formike128x128x16LineDrawH,\r
822     Formike128x128x16LineDrawV,\r
823     Formike128x128x16RectFill,\r
824     Formike128x128x16ColorTranslate,\r
825     Formike128x128x16Flush\r
826 };\r
827 \r
828 //*****************************************************************************\r
829 //\r
830 // Close the Doxygen group.\r
831 //! @}\r
832 //\r
833 //*****************************************************************************\r
834 \r
835 \r
836 \r
837 \r
838 \r
839 \r
840 \r
841 \r
842 \r
843 \r
844 \r
845 \r
846 \r
847 \r
848 \r
849 \r
850 /* FreeRTOS.org demo wrappers.  These are required so the prototypes for the\r
851 functions are the same as for the display drivers used by other evaluation\r
852 kits. */\r
853 \r
854 static tContext sContext;\r
855 \r
856 void vFormike128x128x16Clear( void )\r
857 {\r
858 const tRectangle xRectangle = { 0, 0, 127, 127 };\r
859 \r
860     GrContextForegroundSet( &sContext, ClrBlack );\r
861     GrRectFill( &sContext, &xRectangle );\r
862         GrContextForegroundSet(&sContext, ClrWhite);\r
863 }\r
864 /*-----------------------------------------------------------*/\r
865 \r
866 void vFormike128x128x16StringDraw( const char *pcString, unsigned long lX, unsigned long lY, unsigned char ucColor )\r
867 {\r
868         GrContextForegroundSet(&sContext, ClrWhite);\r
869         GrStringDraw( &sContext, pcString, strlen( pcString ), lX, lY, false );\r
870 }\r
871 /*-----------------------------------------------------------*/\r
872 \r
873 void vFormike128x128x16Init( unsigned long ul )\r
874 {\r
875 tRectangle rectScreen;\r
876 \r
877         ( void ) ul;\r
878         \r
879     Formike128x128x16Init();\r
880     Formike128x128x16BacklightOn();\r
881     GrContextInit(&sContext, &g_sFormike128x128x16);\r
882     GrContextFontSet(&sContext, &g_sFontCmss12);\r
883     rectScreen.sXMin = 0;\r
884 \r
885         /* Fill the screen with a black rectangle. */\r
886     rectScreen.sYMin = 0;\r
887     rectScreen.sXMax = g_sFormike128x128x16.usWidth - 1;\r
888     rectScreen.sYMax = g_sFormike128x128x16.usHeight - 1;\r
889     GrContextForegroundSet(&sContext, ClrBlack);\r
890     GrRectFill(&sContext, &rectScreen);\r
891 }\r
892 /*-----------------------------------------------------------*/\r
893 \r
894 void vFormike128x128x16ImageDraw( const unsigned char *pucImage, unsigned long ulX, unsigned long ulY, unsigned long ulWidth, unsigned long ulHeight )\r
895 {\r
896         GrImageDraw( &sContext, pucImage, ( long ) ulX, ( long ) ulY);\r
897 \r
898 }\r
899 \r
900 \r
901 \r
902 \r