eGUI alias D4D  Release 3.0
Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
d4dlcd_FSA506.c
Go to the documentation of this file.
1 /**************************************************************************
2 *
3 * Copyright 2014 by Petr Gargulak. eGUI Community.
4 * Copyright 2009-2013 by Petr Gargulak. Freescale Semiconductor, Inc.
5 *
6 ***************************************************************************
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License Version 3
9 * or later (the "LGPL").
10 *
11 * As a special exception, the copyright holders of the eGUI project give you
12 * permission to link the eGUI sources with independent modules to produce an
13 * executable, regardless of the license terms of these independent modules,
14 * and to copy and distribute the resulting executable under terms of your
15 * choice, provided that you also meet, for each linked independent module,
16 * the terms and conditions of the license of that module.
17 * An independent module is a module which is not derived from or based
18 * on this library.
19 * If you modify the eGUI sources, you may extend this exception
20 * to your version of the eGUI sources, but you are not obligated
21 * to do so. If you do not wish to do so, delete this
22 * exception statement from your version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27 *
28 * You should have received a copy of the GNU General Public License
29 * and the GNU Lesser General Public License along with this program.
30 * If not, see <http://www.gnu.org/licenses/>.
31 *
32 ***************************************************************************/
46 #include "d4d.h" // include of all public items (types, function etc) of D4D driver
47 #include "common_files/d4d_lldapi.h" // include non public low level driver interface header file (types, function prototypes, enums etc. )
48 #include "common_files/d4d_private.h" // include the private header file that contains perprocessor macros as D4D_MK_STR
49 
50 
51 // identification string of driver - must be same as name D4DLCD_FUNCTIONS structure + "_ID"
52 // it is used for enable the code for compilation
53 #define d4dlcd_fsa506_ID 1
54 
55 
56 // copilation enable preprocessor condition
57 // the string d4dlcd_fsa506_ID must be replaced by define created one line up
58 #if (D4D_MK_STR(D4D_LLD_LCD) == d4dlcd_fsa506_ID)
59 
60  // include of low level driver heaser file
61  // it will be included into wole project only in case that this driver is selected in main D4D configuration file
64  /******************************************************************************
65  * Macros
66  ******************************************************************************/
67  #if D4D_COLOR_SYSTEM != D4D_COLOR_SYSTEM_RGB565
68  #error The eGUI low level driver "d4dlcd_fsa506" not supported selected type of D4D_COLOR_SYSTEM. To run this driver just select D4D_COLOR_SYSTEM_RGB565.
69  #endif
70  /******************************************************************************
71  * Internal function prototypes
72  ******************************************************************************/
73 
74  static unsigned char D4DLCD_Init_FSA506(void);
75  static unsigned char D4DLCD_SetWindow_FSA506(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2);
76  static unsigned char D4DLCD_SetOrientation_FSA506(D4DLCD_ORIENTATION new_orientation);
77  static void D4DLCD_Send_PixelColor_FSA506(D4D_COLOR Value) ;
78  static D4D_COLOR D4DLCD_Get_PixelColor_FSA506(void);
79  static void D4DLCD_Flush_FSA506(D4DLCD_FLUSH_MODE mode);
80  static unsigned char D4DLCD_DeInit_FSA506(void);
81 
82  static void FSA506_Command_Write(Byte Addr, Byte Data);
83  static Byte FSA506_Command_Read(Byte Addr);
84  static void FSA506_DisplayRAM_WriteDisable(void);
85  static void FSA506_DisplayRAM_WriteEnable(void);
86 
87  /**************************************************************/
93  // the main structure that contains low level driver api functions
94  // the name fo this structure is used for recognizing of configured low level driver of whole D4D
95  // so this name has to be used in main configuration header file of D4D driver to enable this driver
96  const D4DLCD_FUNCTIONS d4dlcd_fsa506 =
97  {
98  D4DLCD_Init_FSA506,
99  D4DLCD_SetWindow_FSA506,
100  D4DLCD_SetOrientation_FSA506,
101  D4DLCD_Send_PixelColor_FSA506,
102  D4DLCD_Get_PixelColor_FSA506,
103  D4DLCD_Flush_FSA506,
105  D4DLCD_DeInit_FSA506,
106  };
107 
108  /**************************************************************/
114  /**************************************************************/
121  //-----------------------------------------------------------------------------
122  // FUNCTION: D4DLCD_Init_FSA506
123  // SCOPE: Low Level Driver API function
124  // DESCRIPTION: The function is used for initialization of this low level driver
125  //
126  // PARAMETERS: none
127  //
128  // RETURNS: result: 1 - Success
129  // 0 - Failed
130  //-----------------------------------------------------------------------------
131  static unsigned char D4DLCD_Init_FSA506(void)
132  {
133  Byte temp_reg = 0;
134  Word i = 0;
135 
136  if(D4D_LLD_LCD_HW.D4DLCDHW_Init == NULL)
137  return 0;
138  if(D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord == NULL)
139  return 0;
140  if(D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord == NULL)
141  return 0;
142  if(D4D_LLD_LCD_HW.D4DLCDHW_ReadDataWord == NULL)
143  return 0;
144  if(D4D_LLD_LCD_HW.D4DLCDHW_ReadCmdWord == NULL)
145  return 0;
146  if(D4D_LLD_LCD_HW.D4DLCDHW_PinCtl == NULL)
147  return 0;
148  if(D4D_LLD_LCD_HW.D4DLCDHW_FlushBuffer == NULL)
149  return 0;
150  if(D4D_LLD_LCD_HW.D4DLCDHW_DeInit == NULL)
151  return 0;
152 
153 
154  if(!D4D_LLD_LCD_HW.D4DLCDHW_Init())
155  return 0;
156 
159 
162 
166 
167 
168  temp_reg = FSA506_Command_Read(0x40);
169  FSA506_Command_Write(0x40,0x12); /*[7:6] Reserved
170  [5] PLL control pins to select out frequency range
171  0: 20MHz ~ 100MHz 1: 100MHz ~ 300MHz
172  [4] Reserved [3] Reserved
173  [2:1] Output Driving Capability
174  00: 4mA 01: 8mA 10: 12mA 11: 16mA
175  [0] Output slew rate
176  0: Fast 1: Slow
177  */
178 
179  temp_reg = FSA506_Command_Read(0x40);
180  FSA506_Command_Write(0x41,0x01); //Set PLL=40Mhz * (0x42) / (0x41)
181  FSA506_Command_Write(0x42,0x01); //0x41 [7:6] Reserved [5:0] PLL Programmable pre-divider, 6bit(1~63)
182  //0x42 [7:6] Reserved [5:0] PLL Programmable loop divider, 6bit(1~63)
183 
184  FSA506_Command_Write(0x00,0x00); // MSB of horizontal start coordinate value
185  FSA506_Command_Write(0x01,0x00); // LSB of horizontal start coordinate value
186  FSA506_Command_Write(0x02,0x01); // MSB of horizontal end coordinate value
187  FSA506_Command_Write(0x03,0x3F); // LSB of horizontal end coordinate value
188  FSA506_Command_Write(0x04,0x00); // MSB of vertical start coordinate value
189  FSA506_Command_Write(0x05,0x00); // LSB of vertical start coordinate value
190  FSA506_Command_Write(0x06,0x00); // MSB of vertical end coordinate value
191  FSA506_Command_Write(0x07,0xEF); // LSB of vertical end coordinate value
192 
193  FSA506_Command_Write(0x08,0x01); // MSB of input image horizontal resolution
194  FSA506_Command_Write(0x09,0x40); // LSB of input image horizontal resolution
195  FSA506_Command_Write(0x0a,0x00); //[17:16] bits of memory write start address
196  FSA506_Command_Write(0x0b,0x00); //[15:8] bits of memory write start address
197  FSA506_Command_Write(0x0c,0x00); //[7:0] bits of memory write start address
198 
199  //FSA506_Command_Write(0x10,_Register_0x10_CLKSelect_Mod4+_Register_0x10_PanelSelect_Parallel+_Register_0x10_Blanking_On);
200  FSA506_Command_Write(0x10,0x0d);
201 
202  /* Please set
203  [7] Output data bits swap 0: Normal 1:Swap
204  [6] Output test mode enable 0: disable 1: enable
205  [5:4] Serial mode data out bus selection
206  00: X_ODATA17 ~ X_ODATA12 active , others are set to zero
207  01: X_ODATA11 ~ X_ODATA06 active , others are set to zero
208  10: X_ODATA05 ~ X_ODATA00 active , others are set to zero
209  11: reserved
210  [3] Output data blanking
211  0: set output data to 0
212  1: Normal display
213  [2] Parallel or serial mode selection
214  0: serial data out
215  1: parallel data output[7:0] bits of memory write start address
216  [1:0] Output clock selection
217  00: system clock divided by 2
218  01: system clock divided by 4
219  10: system clock divided by 8
220  11: reserved */
221 
222  FSA506_Command_Write(0x11,0x05); /*[7] Reserved
223  [6:4] Even line of serial panel data out sequence or data bus order of parallel panel
224  000: RGB
225  001: RBG
226  010: GRB
227  011: GBR
228  100: BRG
229  101: BGR
230  Others: reserved
231  [3] Reversed
232  [2:0] Odd line of serial panel data out sequence
233  000: RGB
234  001: RBG
235  010: GRB
236  011: GBR
237  100: BRG
238  101: BGR
239  Others: reserved
240  */
241  FSA506_Command_Write(0x12,0x00); //[7:4] Reserved [3:0] MSB of output H sync. pulse start position
242  FSA506_Command_Write(0x13,0x00); //[7:0] LSB of output H sync. pulse start position
243  FSA506_Command_Write(0x14,0x00); //[7:4] Reserved [3:0] MSB of output H sync. pulse width
244 
245  FSA506_Command_Write(0x15,0x10); //[7:0] LSB of output H sync. pulse width
246  FSA506_Command_Write(0x16,0x00); //[7:4] Reserved [3:0] MSB of output DE horizontal start position
247  FSA506_Command_Write(0x17,0x38); //[7:0] LSB of output DE horizontal start position
248  FSA506_Command_Write(0x18,0x01); //[7:4] Reserved [3:0] MSB of output DE horizontal active region in pixel
249  FSA506_Command_Write(0x19,0x40); //[7:0] LSB of output DE horizontal active region in pixel
250 
251  FSA506_Command_Write(0x1a,0x01); //[7:4] Reserved [3:0] MSB of output H total in pixel
252  FSA506_Command_Write(0x1b,0xb8); //[7:0] LSB of output H total in pixel
253 
254  FSA506_Command_Write(0x1c,0x00); //[7:4] Reserved [3:0] MSB of output V sync. pulse start position
255  FSA506_Command_Write(0x1d,0x00); //[7:0] of output V sync. pulse start position
256 
257  FSA506_Command_Write(0x1e,0x00); //[7:4] Reserved [3:0] MSB of output V sync. pulse width
258  FSA506_Command_Write(0x1f,0x08); //[7:0] LSB of output V sync. pulse width
259 
260  FSA506_Command_Write(0x20,0x00); //[7:4] Reserved [3:0] MSB of output DE vertical start position
261  FSA506_Command_Write(0x21,0x12); //[7:0] LSB of output DE vertical start position
262 
263  FSA506_Command_Write(0x22,0x00); //[7:4] Reserved [3:0] MSB of output DE vertical active region in line
264  FSA506_Command_Write(0x23,0xf0); //[7:0] LSB of output DE vertical active region in line
265 
266  FSA506_Command_Write(0x24,0x01); //[7:4] Reversed [3:0] MSB of output V total in line
267  FSA506_Command_Write(0x25,0x09); //[7:0] LSB of output V total in line
268 
269  FSA506_Command_Write(0x26,0x00); //[7:2] Reserved [1:0] [17:16] bits of memory read start address
270  FSA506_Command_Write(0x27,0x00); //[7:0] [15:8] bits of memory read start address
271  FSA506_Command_Write(0x28,0x00); //[7:0] [7:0] bits of memory read start address
272 
273  FSA506_Command_Write(0x29,0x01); //[7:1] Reversed [0] Load output timing related setting (H sync., V sync. and DE) to take effect
274 
275  FSA506_Command_Write(0x2d,0x08); /* [7:4] Reserved
276  [3] Output pin X_DCON level control
277  [2] Output clock inversion 0: Normal 1: Inverse
278  [1:0] Image rotate
279  00: 0¢X 01: 90¢X 10: 270¢X 11: 180¢X
280  */
281 
282  FSA506_Command_Write(0x30,0x00); //[7:4] Reserved [3:0] MSB of image horizontal shift value
283  FSA506_Command_Write(0x31,0x00); //[7:0] LSB of image horizontal shift value
284 
285  FSA506_Command_Write(0x32,0x00); //[7:4] Reserved [3:0] MSB of image vertical shift value
286  FSA506_Command_Write(0x33,0x00); //[7:0] LSB of image vertical shift value
287 
288  FSA506_Command_Write(0x34,0x01); //[7:4] Reserved [3:0] MSB of image horizontal physical resolution in memory
289  FSA506_Command_Write(0x35,0x40); //[7:0] LSB of image horizontal physical resolution in memory
290 
291  FSA506_Command_Write(0x36,0x00); //[7:4] Reserved [3:0] MSB of image vertical physical resolution in memory
292  FSA506_Command_Write(0x37,0xF0); //[7:0] LSB of image vertical physical resolution in memory
293 
294  return 1;
295  }
296 
297  //-----------------------------------------------------------------------------
298  // FUNCTION: D4DLCD_DeInit_FSA506
299  // SCOPE: Low Level Driver API function
300  // DESCRIPTION: The function is used for deinitialization of this low level driver
301  //
302  // PARAMETERS: none
303  //
304  // RETURNS: result: 1 - Success
305  // 0 - Failed
306  //-----------------------------------------------------------------------------
307  static unsigned char D4DLCD_DeInit_FSA506(void)
308  {
309  return 0;
310  }
311 
312  //-----------------------------------------------------------------------------
313  // FUNCTION: D4DLCD_SetWindow_FSA506
314  // SCOPE: Low Level Driver API function
315  // DESCRIPTION: The function sets the logic window in memory of LCD driver
316  //
317  // PARAMETERS: unsigned int x1 - left cordination of logic window
318  // unsigned int y1 - top cordination of logic window
319  // unsigned int x2 - right cordination of logic window
320  // unsigned int y2 - bottom cordination of logic window
321  //
322  // RETURNS: result: 1 - Success
323  // 0 - Failed
324  //-----------------------------------------------------------------------------
325  static unsigned char D4DLCD_SetWindow_FSA506(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2)
326  {
327  FSA506_DisplayRAM_WriteDisable();
328  D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(0x00);
329  D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((Byte)((x1)>>8));
330  D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((Byte)(x1));
331  D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((Byte)((x2)>>8));
332  D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((Byte)(x2));
333  D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((Byte)(y1>>8));
334  D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((Byte)(y1));
335  D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((Byte)((y2)>>8));
336  D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((Byte)(y2));
337 
338  FSA506_DisplayRAM_WriteEnable();
339 
340  return 1;
341  }
342 
343  //-----------------------------------------------------------------------------
344  // FUNCTION: D4DLCD_SetOrientation_FSA506
345  // SCOPE: Low Level Driver API function
346  // DESCRIPTION: The function set the new orientation of LCD
347  //
348  // PARAMETERS: D4DLCD_ORIENTATION new_orientation the requested new orientation
349  //
350  // RETURNS: result: 1 - Success
351  // 0 - Failed
352  //-----------------------------------------------------------------------------
353  static unsigned char D4DLCD_SetOrientation_FSA506(D4DLCD_ORIENTATION new_orientation)
354  {
355  Byte data;
356 
357  switch (new_orientation)
358  {
359  default:
360  // Invalid! Fall through to portrait mode
361  case Portrait:
362  data = 0x0A;
363  break;
364  case Portrait180:
365  data = 0x09;
366  break;
367  case Landscape:
368  data = 0x08;
369  break;
370  case Landscape180:
371  data = 0x0B;
372  break;
373  }
374  FSA506_DisplayRAM_WriteDisable();
375  FSA506_Command_Write(0x2d,data);
376  D4DLCD_SetWindow_FSA506(0, 0, D4D_SCREEN_SIZE_LONGER_SIDE - 1, D4D_SCREEN_SIZE_SHORTER_SIDE - 1);
377 
378  return 1;
379  }
380 
381  //-----------------------------------------------------------------------------
382  // FUNCTION: D4DLCD_Send_PixelColor_FSA506
383  // SCOPE: Low Level Driver API function
384  // DESCRIPTION: The function send the one pixel (Word) into LCD
385  //
386  // PARAMETERS: unsigned short Value value of pixel color
387  //
388  // RETURNS: none
389  //-----------------------------------------------------------------------------
390  static void D4DLCD_Send_PixelColor_FSA506(D4D_COLOR Value)
391  {
392  D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((Byte)((Value)>>8));
393  D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((Byte)(Value));
394  }
395 
396  //-----------------------------------------------------------------------------
397  // FUNCTION: D4DLCD_Get_PixelColor_FSA506
398  // SCOPE: Low Level Driver API function
399  // DESCRIPTION: The function reads the one Word(Pixel) from LCD (if this function is supported)
400  //
401  // PARAMETERS: none
402  //
403  // RETURNS: unsigned short - the readed value
404  //
405  //-----------------------------------------------------------------------------
406  static D4D_COLOR D4DLCD_Get_PixelColor_FSA506(void)
407  {
408  return 0;
409  }
410 
411  //-----------------------------------------------------------------------------
412  // FUNCTION: D4DLCD_Flush_FSA506
413  // SCOPE: Low Level Driver API function
414  // DESCRIPTION: For buffered low level interfaces is used to inform
415  // driver the complete object is drawed and pending pixels should be flushed
416  //
417  // PARAMETERS: none
418  //
419  // RETURNS: none
420  //-----------------------------------------------------------------------------
421  static void D4DLCD_Flush_FSA506(D4DLCD_FLUSH_MODE mode)
422  {
423  D4D_UNUSED(mode);
424  }
425 
426 
427  // NON API function
428 
429  static void FSA506_Command_Write(Byte Addr, Byte Data) {
430 
431  D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(Addr);
432  D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord(Data);
433 
434  }
435 
436  static Byte FSA506_Command_Read(Byte Addr) {
437 
438  D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(Addr);
439  return (Byte)D4D_LLD_LCD_HW.D4DLCDHW_ReadCmdWord();
440  }
441 
442  static void FSA506_DisplayRAM_WriteDisable(void)
443  {
444 
445  D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(0x80);
446 
447  }
448 
449  static void FSA506_DisplayRAM_WriteEnable(void)
450  {
451 
452  D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(0xc1);
453 
454  }
455 
456 
457 #endif //(D4D_MK_STR(D4D_LLD_LCD) == d4dlcd_fsa506_ID)
D4D low level standard LCD interface API structure.
Definition: d4d_lldapi.h:147
#define D4D_SCREEN_SIZE_LONGER_SIDE
This macro is used to define the size of longer side of LCD. If not defined, the longer side is set t...
Definition: d4d_base.h:101
Orientation LandScape up side down.
Definition: d4d_lldapi.h:69
#define D4D_LLD_LCD_HW
Definition: d4d_types.h:76
D4D Driver main header file.
Orientation LandScape.
Definition: d4d_lldapi.h:68
D4DLCD_FLUSH_MODE
D4D low level eGUI flush screen types enumeration.
Definition: d4d_lldapi.h:136
D4D Driver private header file.
Orientation Portrait up side down.
Definition: d4d_lldapi.h:67
D4DLCD_ORIENTATION
D4D low level screen orientation enumeration type.
Definition: d4d_lldapi.h:64
unsigned char Byte
Type definition of Byte (unsigned 8-bit).
Definition: d4d_types.h:151
Switch pin to output mode.
Definition: d4d_lldapi.h:77
#define NULL
Type definition of null pointer.
Definition: d4d_types.h:184
Set pin output register to logic 1.
Definition: d4d_lldapi.h:80
LCD device backlight enable signal.
Definition: d4d_lldapi.h:99
#define D4D_SCREEN_SIZE_SHORTER_SIDE
This macro is used to define the size of shorter side of LCD. If not defined, the shorter side is set...
Definition: d4d_base.h:108
#define D4D_UNUSED(x)
Macro used just for notify compiler that the input parameter is not used.
Definition: d4d_base.h:504
Set pin output register to logic 0.
Definition: d4d_lldapi.h:79
D4D driver - common low level driver header file.
void D4DLCD_Delay_ms_Common(unsigned short period)
Orientation Portrait.
Definition: d4d_lldapi.h:66
D4D driver - resistive touch screen driver function header file.
D4D driver - fsa506 lcd driver function header file.
LWord D4D_COLOR
Type definition of eGUI color variables.
Definition: d4d_types.h:262
unsigned short Word
Type definition of Word (unsigned 16-bit).
Definition: d4d_types.h:159
LCD device reset signal.
Definition: d4d_lldapi.h:98