eGUI alias D4D  Release 3.0
Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
d4dlcd_SSD1289.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_ssd1289_ID 1
54 
55 
56 // copilation enable preprocessor condition
57 // the string d4dlcd_ssd1289_ID must be replaced by define created one line up
58 #if (D4D_MK_STR(D4D_LLD_LCD) == d4dlcd_ssd1289_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 
68  /******************************************************************************
69  * Internal function prototypes
70  ******************************************************************************/
71 
72  static unsigned char D4DLCD_Init_SSD1289(void);
73  static unsigned char D4DLCD_SetWindow_SSD1289(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2);
74  static unsigned char D4DLCD_SetOrientation_SSD1289(D4DLCD_ORIENTATION new_orientation);
75  static void D4DLCD_Send_PixelColor_SSD1289(D4D_COLOR value) ;
76  static D4D_COLOR D4DLCD_Get_PixelColor_SSD1289(void);
77  static void D4DLCD_Flush_SSD1289(D4DLCD_FLUSH_MODE mode);
78  static unsigned char D4DLCD_DeInit_SSD1289(void);
79 
80  /**************************************************************/
86  // the main structure that contains low level driver api functions
87  // the name fo this structure is used for recognizing of configured low level driver of whole D4D
88  // so this name has to be used in main configuration header file of D4D driver to enable this driver
89  const D4DLCD_FUNCTIONS d4dlcd_ssd1289 =
90  {
91  D4DLCD_Init_SSD1289,
92  D4DLCD_SetWindow_SSD1289,
93  D4DLCD_SetOrientation_SSD1289,
94  D4DLCD_Send_PixelColor_SSD1289,
95  D4DLCD_Get_PixelColor_SSD1289,
96  D4DLCD_Flush_SSD1289,
98  D4DLCD_DeInit_SSD1289,
99  };
100 
101  /**************************************************************/
106  static D4DLCD_ORIENTATION d4dlcd_orientation = Portrait;
107  /**************************************************************/
112  // sends Command/Data sequence word (16 bit) or array with words - first 1 command, then 1 x data
113  static void D4DLCD_Command_Data(const unsigned short data[], unsigned short count)
114  {
115  int i;
116 
117  for (i=0; i<count; i+=2)
118  {
119  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(data[i]);
120  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord(data[i+1]);
121  }
122  }
123 
124  //-----------------------------------------------------------------------------
125  // FUNCTION: D4DLCD_Init_SSD1289
126  // SCOPE: Low Level Driver API function
127  // DESCRIPTION: The function is used for initialization of this low level driver
128  //
129  // PARAMETERS: none
130  //
131  // RETURNS: result: 1 - Success
132  // 0 - Failed
133  //-----------------------------------------------------------------------------
134  static unsigned char D4DLCD_Init_SSD1289(void)
135  {
136  const unsigned short init_data[] =
137  {
138  0x0000, 0x0001,
139 
140  0x0003, 0xAEAC, 0x000C, 0x0007, 0x000D, 0x000F, 0x000E, 0x2900, 0x001E, 0x00B3,
141 
142  0x0001, 0x2B3F, 0x0002, 0x0600, 0x0010, 0x0000, 0x0011, 0x60B0,
143 
144  0x0005, 0x0000, 0x0006, 0x0000, 0x0016, 0xEF1C, 0x0017, 0x0003, 0x0007, 0x0233,
145  0x000B, 0x5312, 0x000F, 0x0000,
146 
147  0x0041, 0x0000, 0x0042, 0x0000, 0x0048, 0x0000, 0x0049, 0x013F, 0x0044, 0xEF00,
148  0x0045, 0x0000, 0x0046, 0x013F, 0x004A, 0x0000, 0x004B, 0x0000,
149 
150  0x0030, 0x0707, 0x0031, 0x0704, 0x0032, 0x0204, 0x0033, 0x0201, 0x0034, 0x0203,
151  0x0035, 0x0204, 0x0036, 0x0204, 0x0037, 0x0502, 0x003A, 0x0302, 0x003B, 0x0500,
152  0x0023 , 0x0000, 0x0024 , 0x0000
153  } ;
154 
155  if(D4D_LLD_LCD_HW.D4DLCDHW_Init == NULL)
156  return 0;
157  if(D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord == NULL)
158  return 0;
159  if(D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord == NULL)
160  return 0;
161  if(D4D_LLD_LCD_HW.D4DLCDHW_ReadDataWord == NULL)
162  return 0;
163  if(D4D_LLD_LCD_HW.D4DLCDHW_ReadCmdWord == NULL)
164  return 0;
165  if(D4D_LLD_LCD_HW.D4DLCDHW_PinCtl == NULL)
166  return 0;
167  if(D4D_LLD_LCD_HW.D4DLCDHW_FlushBuffer == NULL)
168  return 0;
169  if(D4D_LLD_LCD_HW.D4DLCDHW_DeInit == NULL)
170  return 0;
171 
172 
173  if(!D4D_LLD_LCD_HW.D4DLCDHW_Init())
174  return 0;
175 
176  (void)D4D_LLD_LCD_HW.D4DLCDHW_PinCtl(D4DLCD_BACKLIGHT_PIN, D4DHW_PIN_SET_1);
177  (void)D4D_LLD_LCD_HW.D4DLCDHW_PinCtl(D4DLCD_BACKLIGHT_PIN, D4DHW_PIN_OUT);
178 
179  (void)D4D_LLD_LCD_HW.D4DLCDHW_PinCtl(D4DLCD_RESET_PIN, D4DHW_PIN_SET_0);
180  (void)D4D_LLD_LCD_HW.D4DLCDHW_PinCtl(D4DLCD_RESET_PIN, D4DHW_PIN_OUT);
181 
185 
186  D4DLCD_Command_Data(&init_data[0], 2); D4DLCD_Delay_ms_Common(15);
187  D4DLCD_Command_Data(&init_data[2], 10); D4DLCD_Delay_ms_Common(15);
188  D4DLCD_Command_Data(&init_data[12], 8); D4DLCD_Delay_ms_Common(150);
189  D4DLCD_Command_Data(&init_data[20], 14); D4DLCD_Delay_ms_Common(20);
190  D4DLCD_Command_Data(&init_data[34], 18); D4DLCD_Delay_ms_Common(20);
191  D4DLCD_Command_Data(&init_data[52], 24); D4DLCD_Delay_ms_Common(31);
192 
193 
194  return 1;
195 
196  }
197 
198  //-----------------------------------------------------------------------------
199  // FUNCTION: D4DLCD_DeInit_SSD1289
200  // SCOPE: Low Level Driver API function
201  // DESCRIPTION: The function is used for deinitialization of this low level driver
202  //
203  // PARAMETERS: none
204  //
205  // RETURNS: result: 1 - Success
206  // 0 - Failed
207  //-----------------------------------------------------------------------------
208  static unsigned char D4DLCD_DeInit_SSD1289(void)
209  {
210  return 0;
211  }
212 
213  //-----------------------------------------------------------------------------
214  // FUNCTION: D4DLCD_SetWindow_SSD1289
215  // SCOPE: Low Level Driver API function
216  // DESCRIPTION: The function sets the logic window in memory of LCD driver
217  //
218  // PARAMETERS: unsigned int x1 - left cordination of logic window
219  // unsigned int y1 - top cordination of logic window
220  // unsigned int x2 - right cordination of logic window
221  // unsigned int y2 - bottom cordination of logic window
222  //
223  // RETURNS: result: 1 - Success
224  // 0 - Failed
225  //-----------------------------------------------------------------------------
226  static unsigned char D4DLCD_SetWindow_SSD1289(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2)
227  {
228  unsigned short x1_x2;
229  unsigned short Addr1, Addr2;
230 
231  switch (d4dlcd_orientation)
232  {
233  default:
234  // Invalid! Fall through to portrait mode
235  case Portrait:
236  Addr1 = x1;
237  Addr2 = y1;
238  x1_x2 = (unsigned short)((x2<<8) + x1); // pack X-Values into one word
239  break;
240 
241  case Portrait180:
242  Addr1 = (unsigned short)(D4D_SCREEN_SIZE_SHORTER_SIDE - 1 - x1);
243  Addr2 = (unsigned short)(D4D_SCREEN_SIZE_LONGER_SIDE - 1 - y1);
244  x1_x2 = (unsigned short)((Addr1<<8) + (D4D_SCREEN_SIZE_SHORTER_SIDE - 1 - x2)); // pack X-Values into one word
245  y1 = (unsigned short)(D4D_SCREEN_SIZE_LONGER_SIDE - 1 - y2);
246  y2 = Addr2;
247  break;
248 
249  case Landscape:
250  Addr1 = (unsigned short)(D4D_SCREEN_SIZE_SHORTER_SIDE - 1 - y1);
251  Addr2 = x1;
252  x1_x2 = (unsigned short)((Addr1<<8) + (D4D_SCREEN_SIZE_SHORTER_SIDE - 1 - y2)); // pack X-Values into one word
253  y1 = x1;
254  y2 = x2;
255  break;
256 
257  case Landscape180:
258  Addr1 = y1;
259  Addr2 = (unsigned short)(D4D_SCREEN_SIZE_LONGER_SIDE - 1 - x1); // pack X-Values into one word
260  x1_x2 = (unsigned short)((y2<<8) + y1);
261  y1 = (unsigned short)(D4D_SCREEN_SIZE_LONGER_SIDE - 1 - x2);
262  y2 = Addr2;
263  break;
264  }
265 
266  //Set Window
267  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(0x0044);
268  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((unsigned short)x1_x2);
269 
270  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(0x0045);
271  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((unsigned short)y1);
272 
273  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(0x0046);
274  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((unsigned short)y2);
275 
276  // Set Start Address counter
277 
278  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(0x004e);
279  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((unsigned short)Addr1);
280 
281  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(0x004f);
282  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((unsigned short)Addr2);
283 
284  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(0x0022);
285 
286  // Dummy read to prepare possible erad operation
287  //(void)D4D_LLD_LCD_HW.D4DLCDHW_ReadDataWord();
288 
289  return 1;
290  }
291 
292  //-----------------------------------------------------------------------------
293  // FUNCTION: D4DLCD_SetOrientation_SSD1289
294  // SCOPE: Low Level Driver API function
295  // DESCRIPTION: The function set the new orientation of LCD
296  //
297  // PARAMETERS: D4DLCD_ORIENTATION new_orientation the requested new orientation
298  //
299  // RETURNS: result: 1 - Success
300  // 0 - Failed
301  //-----------------------------------------------------------------------------
302  static unsigned char D4DLCD_SetOrientation_SSD1289(D4DLCD_ORIENTATION new_orientation)
303  {
304  unsigned short LCD_EntryMode = 0;
305 
306  d4dlcd_orientation = new_orientation;
307 
308  switch (d4dlcd_orientation)
309  {
310  default: // Invalid! Fall through to portrait mode
311  case Portrait:
312  LCD_EntryMode = 0x60b0; break; // &B110000010110000
313  case Portrait180:
314  LCD_EntryMode = 0x6080; break; // &B110000010000000
315  case Landscape:
316  LCD_EntryMode = 0x60a8; break; // &B110000010101000
317  case Landscape180:
318  LCD_EntryMode = 0x6098; break; // &B110000010011000
319  }
320  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendCmdWord(0x0011);
321  (void)D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord(LCD_EntryMode);
322 
323  (void)D4DLCD_SetWindow_SSD1289(0, 0, 1, 1);
324 
325  return 1;
326  }
327 
328  //-----------------------------------------------------------------------------
329  // FUNCTION: D4DLCD_Send_PixelColor_SSD1289
330  // SCOPE: Low Level Driver API function
331  // DESCRIPTION: The function send the one pixel (Word) into LCD
332  //
333  // PARAMETERS: unsigned short Value value of pixel color
334  //
335  // RETURNS: none
336  //-----------------------------------------------------------------------------
337  static void D4DLCD_Send_PixelColor_SSD1289(D4D_COLOR value)
338  {
339 
340 #ifdef D4D_COLOR_TRANSPARENT
341  if(value == D4D_COLOR_TRANSPARENT)
342  D4D_LLD_LCD_HW.D4DLCDHW_ReadDataWord();
343  else
344 #endif
345  {
346  #if D4D_COLOR_SYSTEM != D4D_COLOR_SYSTEM_RGB565
347  Word color = D4D_COLOR_RGB565(D4D_COLOR_GET_R(value), D4D_COLOR_GET_G(value), D4D_COLOR_GET_B(value));
348  D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord(color);
349  #else
350  D4D_LLD_LCD_HW.D4DLCDHW_SendDataWord((unsigned short)value);
351  #endif
352 
353  }
354  }
355 
356  //-----------------------------------------------------------------------------
357  // FUNCTION: D4DLCD_Read_PixelColor_SSD1289
358  // SCOPE: Low Level Driver API function
359  // DESCRIPTION: The function reads the one Word(Pixel) from LCD (if this function is supported)
360  //
361  // PARAMETERS: none
362  //
363  // RETURNS: unsigned short - the readed value
364  //
365  //-----------------------------------------------------------------------------
366  static D4D_COLOR D4DLCD_Get_PixelColor_SSD1289(void)
367  {
368  #if D4D_COLOR_SYSTEM != D4D_COLOR_SYSTEM_RGB565
369  Word color = D4D_LLD_LCD_HW.D4DLCDHW_ReadDataWord();
371  #else
372  return D4D_LLD_LCD_HW.D4DLCDHW_ReadDataWord();
373  #endif
374  }
375 
376  //-----------------------------------------------------------------------------
377  // FUNCTION: D4DLCD_Flush_SSD1289
378  // SCOPE: Low Level Driver API function
379  // DESCRIPTION: For buffered low level interfaces is used to inform
380  // driver the complete object is drawed and pending pixels should be flushed
381  //
382  // PARAMETERS: none
383  //
384  // RETURNS: none
385  //-----------------------------------------------------------------------------
386  static void D4DLCD_Flush_SSD1289(D4DLCD_FLUSH_MODE mode)
387  {
388  D4D_LLD_LCD_HW.D4DLCDHW_FlushBuffer(mode);
389  }
390 
391 
392 #endif //(D4D_MK_STR(D4D_LLD_LCD) == d4dlcd_ssd1289_ID)
#define D4D_COLOR_RGB565(R, G, B)
The macro create the color from the color component Red/Green/Blue to 16-bit RGB565 format (the input...
Definition: d4d_scheme.h:301
#define D4D_COLOR_GET_B(color)
Definition: d4d_scheme.h:438
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
#define D4D_COLOR_RGB(R, G, B)
Definition: d4d_scheme.h:434
Orientation LandScape up side down.
Definition: d4d_lldapi.h:69
#define D4D_LLD_LCD_HW
Definition: d4d_types.h:76
#define D4D_COLOR565_GET_B(color)
The macro gets the Blue component from 16-bit standard format to 8-bit component format.
Definition: d4d_scheme.h:299
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
D4D driver SSD1289 hardware level LCD header file.
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_COLOR565_GET_R(color)
The macro gets the Red component from 16-bit standard format to 8-bit component format.
Definition: d4d_scheme.h:297
#define D4D_COLOR_GET_G(color)
Definition: d4d_scheme.h:437
Set pin output register to logic 0.
Definition: d4d_lldapi.h:79
#define D4D_COLOR565_GET_G(color)
The macro gets the Green component from 16-bit standard format to 8-bit component format...
Definition: d4d_scheme.h:298
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.
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
#define D4D_COLOR_GET_R(color)
Definition: d4d_scheme.h:436