eGUI alias D4D  Release 3.0
Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
d4dlcd_lgdp4531.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_lgdp4531_ID 1
54 
55 
56 // copilation enable preprocessor condition
57 // the string d4dlcd_lgdp4531_ID must be replaced by define created one line up
58 #if (D4D_MK_STR(D4D_LLD_LCD) == d4dlcd_lgdp4531_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_lgdp4531" 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_LGDP4531(void);
75  static unsigned char D4DLCD_SetWindow_LGDP4531(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2);
76  static unsigned char D4DLCD_SetOrientation_LGDP4531(D4DLCD_ORIENTATION new_orientation);
77  static void D4DLCD_Send_PixelColor_LGDP4531(D4D_COLOR value) ;
78  static D4D_COLOR D4DLCD_Get_PixelColor_LGDP4531(void);
79  static void D4DLCD_Flush_LGDP4531(D4DLCD_FLUSH_MODE mode);
80  static unsigned char D4DLCD_DeInit_LGDP4531(void);
81 
82  /**************************************************************/
88  // the main structure that contains low level driver api functions
89  // the name fo this structure is used for recognizing of configured low level driver of whole D4D
90  // so this name has to be used in main configuration header file of D4D driver to enable this driver
91  const D4DLCD_FUNCTIONS d4dlcd_lgdp4531 =
92  {
93  D4DLCD_Init_LGDP4531,
94  D4DLCD_SetWindow_LGDP4531,
95  D4DLCD_SetOrientation_LGDP4531,
96  D4DLCD_Send_PixelColor_LGDP4531,
97  D4DLCD_Get_PixelColor_LGDP4531,
98  D4DLCD_Flush_LGDP4531,
100  D4DLCD_DeInit_LGDP4531,
101  };
102 
103  /**************************************************************/
109  const unsigned int init_data1[] =
110  {
111  0x0010, 0x0628, 0x0012, 0x0006, 0x0013, 0x0A32, 0x0011, 0x0040, 0x0015, 0x0050,
112  0x0012, 0x0016,
113  // Delay 15ms
114  };
115  const unsigned int init_data2[] =
116  {
117  0x0010, 0x5660,
118  // Delay 15ms
119  };
120  const unsigned int init_data3[] =
121  {
122  0x0013, 0x2A4E, 0x0001, 0x0100, 0x0002, 0x0300, 0x0003, 0x1038, 0x0008, 0x0202,
123  0x000A, 0x0000, 0x0030, 0x0000, 0x0031, 0x0402, 0x0032, 0x0106, 0x0033, 0x0700,
124  0x0034, 0x0104, 0x0035, 0x0301, 0x0036, 0x0707, 0x0037, 0x0305, 0x0038, 0x0208,
125  0x0039, 0x0F0B,
126  // Delay 15ms
127  };
128  const unsigned int init_data4[] =
129  {
130  0x0041, 0x0002, 0x0060, 0x2700, 0x0061, 0x0001, 0x0090, 0x0119, 0x0092, 0x010A,
131  0x0093, 0x0004, 0x00A0, 0x0100, 0x0007, 0x0001,
132  // Delay 15ms
133  };
134  const unsigned int init_data5[] =
135  {
136  0x0007, 0x0021,
137  // Delay 15ms
138  };
139  const unsigned int init_data6[] =
140  {
141  0x0007, 0x0023,
142  // Delay 15ms
143  };
144  const unsigned int init_data7[] =
145  {
146  0x0007, 0x0033,
147  // Delay 15ms
148  };
149  const unsigned int init_data8[] =
150  {
151  0x0007, 0x0133,
152  // Delay 15ms
153  };
154  const unsigned int init_data9[] =
155  {
156  0x00A0, 0x0000,
157  // Delay 20ms
158  };
159 
160  static D4DLCD_ORIENTATION d4dlcd_orientation = Portrait;
161 
162  /**************************************************************/
167  // sends Command/Data sequence word (16 bit) or array with words - first 1 command, then 1 x data
168  static void D4DLCD_Index_Data(const unsigned int data[], unsigned int count)
169  {
170  int i;
171 
172  for (i=0; i<count; i+=2)
173  {
174  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord((unsigned short)data[i]);
175  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((unsigned short)data[i+1]);
176  }
177  }
178 
179 
180  //-----------------------------------------------------------------------------
181  // FUNCTION: D4DLCD_Init_LGDP4531
182  // SCOPE: Low Level Driver API function
183  // DESCRIPTION: The function is used for initialization of this low level driver
184  //
185  // PARAMETERS: none
186  //
187  // RETURNS: result: 1 - Success
188  // 0 - Failed
189  //-----------------------------------------------------------------------------
190  static unsigned char D4DLCD_Init_LGDP4531(void)
191  {
192 
193  if(D4D_LLD_LCD_HW.D4DLCDHW_Init == NULL)
194  return 0;
195  if(D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord == NULL)
196  return 0;
197  if(D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord == NULL)
198  return 0;
199  if(D4D_LLD_LCD_HW.D4DLCDHW_ReadDataWord == NULL)
200  return 0;
201  if(D4D_LLD_LCD_HW.D4DLCDHW_ReadCmdWord == NULL)
202  return 0;
203  if(D4D_LLD_LCD_HW.D4DLCDHW_PinCtl == NULL)
204  return 0;
205  if(D4D_LLD_LCD_HW.D4DLCDHW_FlushBuffer == NULL)
206  return 0;
207  if(D4D_LLD_LCD_HW.D4DLCDHW_DeInit == NULL)
208  return 0;
209 
210 
211  if(!D4D_LLD_LCD_HW.D4DLCDHW_Init())
212  return 0;
213 
214  (void)D4D_LLD_LCD_HW.D4DLCDHW_PinCtl(D4DLCD_BACKLIGHT_PIN, D4DHW_PIN_SET_1);
215  (void)D4D_LLD_LCD_HW.D4DLCDHW_PinCtl(D4DLCD_BACKLIGHT_PIN, D4DHW_PIN_OUT);
216 
217 
218  (void)D4D_LLD_LCD_HW.D4DLCDHW_PinCtl(D4DLCD_RESET_PIN, D4DHW_PIN_SET_0);
219  (void)D4D_LLD_LCD_HW.D4DLCDHW_PinCtl(D4DLCD_RESET_PIN, D4DHW_PIN_OUT);
220 
224 
225  // Initial synchronization transfers
226  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(0);
227  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(0);
228 
229  D4DLCD_Index_Data(init_data1, 12); D4DLCD_Delay_ms_Common(15);
230  D4DLCD_Index_Data(init_data2, 2); D4DLCD_Delay_ms_Common(15);
231  D4DLCD_Index_Data(init_data3, 32); D4DLCD_Delay_ms_Common(15);
232  D4DLCD_Index_Data(init_data4, 16); D4DLCD_Delay_ms_Common(15);
233  D4DLCD_Index_Data(init_data5, 2); D4DLCD_Delay_ms_Common(15);
234  D4DLCD_Index_Data(init_data6, 2); D4DLCD_Delay_ms_Common(15);
235  D4DLCD_Index_Data(init_data7, 2); D4DLCD_Delay_ms_Common(15);
236  D4DLCD_Index_Data(init_data8, 2); D4DLCD_Delay_ms_Common(15);
237  D4DLCD_Index_Data(init_data9, 2); D4DLCD_Delay_ms_Common(20);
238 
239 
240 
241  return 1;
242  }
243 
244  //-----------------------------------------------------------------------------
245  // FUNCTION: D4DLCD_DeInit_LGDP4531
246  // SCOPE: Low Level Driver API function
247  // DESCRIPTION: The function is used for deinitialization of this low level driver
248  //
249  // PARAMETERS: none
250  //
251  // RETURNS: result: 1 - Success
252  // 0 - Failed
253  //-----------------------------------------------------------------------------
254  static unsigned char D4DLCD_DeInit_LGDP4531(void)
255  {
256 
257  }
258 
259  //-----------------------------------------------------------------------------
260  // FUNCTION: D4DLCD_SetWindow_LGDP4531
261  // SCOPE: Low Level Driver API function
262  // DESCRIPTION: The function sets the logic window in memory of LCD driver
263  //
264  // PARAMETERS: unsigned short x1 - left cordination of logic window
265  // unsigned short y1 - top cordination of logic window
266  // unsigned short x2 - right cordination of logic window
267  // unsigned short y2 - bottom cordination of logic window
268  //
269  // RETURNS: result: 1 - Success
270  // 0 - Failed
271  //-----------------------------------------------------------------------------
272  static unsigned char D4DLCD_SetWindow_LGDP4531(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2)
273  {
274  unsigned short Addr1, Addr2;
275 
276  switch (d4dlcd_orientation)
277  {
278  default:
279  // Invalid! Fall through to portrait mode
280  case Portrait:
281  Addr1 = x1;
282  Addr2 = y1;
283  break;
284 
285  case Portrait180:
286  Addr1 = (unsigned short)(D4D_SCREEN_SIZE_SHORTER_SIDE - 1 - x1);
287  Addr2 = (unsigned short)(D4D_SCREEN_SIZE_LONGER_SIDE - 1 - y1);
288  x1 = (unsigned short)(D4D_SCREEN_SIZE_SHORTER_SIDE - 1 - x2);
289  x2 = Addr1; // pack X-Values into one word
290 
291  y1 = (unsigned short)(D4D_SCREEN_SIZE_LONGER_SIDE - 1 - y2);
292  y2 = Addr2;
293  break;
294 
295  case Landscape:
296  Addr1 = (unsigned short)(D4D_SCREEN_SIZE_SHORTER_SIDE - 1 - y1);
297  Addr2 = x1;
298  y1 = x1;
299  x1 = (unsigned short)(D4D_SCREEN_SIZE_SHORTER_SIDE - 1 - y2);
300  y2 = x2;
301  x2 = Addr1;
302  break;
303 
304  case Landscape180:
305  Addr1 = y1;
306  Addr2 = (unsigned short)(D4D_SCREEN_SIZE_LONGER_SIDE - 1 - x1); // pack X-Values into one word
307  x1 = y1;
308  y1 = (unsigned short)(D4D_SCREEN_SIZE_LONGER_SIDE - 1 - x2);
309  x2 = y2;
310  y2 = Addr2;
311  break;
312  }
313 
314  //Set Window
315  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(0x0050);
316  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((unsigned short)x1);
317 
318  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(0x0051);
319  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((unsigned short)x2);
320 
321  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(0x0052);
322  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((unsigned short)y1);
323 
324  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(0x0053);
325  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((unsigned short)y2);
326 
327  // Set Start Address counter
328 
329  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(0x0020);
330  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((unsigned short)Addr1);
331 
332  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(0x0021);
333  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((unsigned short)Addr2);
334 
335  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(0x0022);
336 
337  return 1;
338  }
339 
340  //-----------------------------------------------------------------------------
341  // FUNCTION: D4DLCD_SetOrientation_LGDP4531
342  // SCOPE: Low Level Driver API function
343  // DESCRIPTION: The function set the new orientation of LCD
344  //
345  // PARAMETERS: D4DLCD_ORIENTATION new_orientation the requested new orientation
346  //
347  // RETURNS: result: 1 - Success
348  // 0 - Failed
349  //-----------------------------------------------------------------------------
350  static unsigned char D4DLCD_SetOrientation_LGDP4531(D4DLCD_ORIENTATION new_orientation)
351  {
352  unsigned short LCD_EntryMode;
353 
354  d4dlcd_orientation = new_orientation;
355 
356  switch (d4dlcd_orientation)
357  {
358  default: // Invalid! Fall through to portrait mode
359  case Portrait:
360  LCD_EntryMode = 0x1030; break; // &B000100000110000
361  case Portrait180:
362  LCD_EntryMode = 0x1000; break; // &B000100000000000
363  case Landscape:
364  LCD_EntryMode = 0x1028; break; // &B000100000101000
365  case Landscape180:
366  LCD_EntryMode = 0x1018; break; // &B000100000011000
367  }
368  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(0x0003);
369  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord(LCD_EntryMode);
370 
371  (void)D4DLCD_SetWindow_LGDP4531(0, 0, 1, 1);
372 
373  return 1;
374  }
375 
376  //-----------------------------------------------------------------------------
377  // FUNCTION: D4DLCD_Send_PixelColor_LGDP4531
378  // SCOPE: Low Level Driver API function
379  // DESCRIPTION: The function send the one pixel (Word) into LCD
380  //
381  // PARAMETERS: unsigned short Value value of pixel color
382  //
383  // RETURNS: none
384  //-----------------------------------------------------------------------------
385  static void D4DLCD_Send_PixelColor_LGDP4531(D4D_COLOR value)
386  {
387  D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord(value);
388  }
389 
390  //-----------------------------------------------------------------------------
391  // FUNCTION: D4DLCD_Get_PixelColor_LGDP4531
392  // SCOPE: Low Level Driver API function
393  // DESCRIPTION: The function reads the one Word(Pixel) from LCD (if this function is supported)
394  //
395  // PARAMETERS: none
396  //
397  // RETURNS: unsigned short - the readed value
398  //
399  //-----------------------------------------------------------------------------
400  static D4D_COLOR D4DLCD_Get_PixelColor_LGDP4531(void)
401  {
402  return D4D_LLD_LCD_HW.D4DLCDHW_ReadDataWord();
403  }
404 
405  //-----------------------------------------------------------------------------
406  // FUNCTION: D4DLCD_Flush_LGDP4531
407  // SCOPE: Low Level Driver API function
408  // DESCRIPTION: For buffered low level interfaces is used to inform
409  // driver the complete object is drawed and pending pixels should be flushed
410  //
411  // PARAMETERS: none
412  //
413  // RETURNS: none
414  //-----------------------------------------------------------------------------
415  static void D4DLCD_Flush_LGDP4531(D4DLCD_FLUSH_MODE mode)
416  {
417  D4D_LLD_LCD_HW.D4DLCDHW_FlushBuffer(mode);
418  }
419 
420 
421 
422 #endif //(D4D_MK_STR(D4D_LLD_LCD) == d4dlcd_lgdp4531_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
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
Set pin output register to logic 0.
Definition: d4d_lldapi.h:79
D4D driver - common low level driver header file.
D4D driver - lgdp4531 lcd driver function 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.
LWord D4D_COLOR
Type definition of eGUI color variables.
Definition: d4d_types.h:262
LCD device reset signal.
Definition: d4d_lldapi.h:98