eGUI alias D4D  Release 3.0
Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
d4dlcd_frame_buffer.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_frame_buffer_ID 1
54 
55 
56 // copilation enable preprocessor condition
57 // the string d4dlcd_frame_buffer_ID must be replaced by define created one line up
58 #if (D4D_MK_STR(D4D_LLD_LCD) == d4dlcd_frame_buffer_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
63 
65  /******************************************************************************
66  * Macros
67  ******************************************************************************/
68 
69  /******************************************************************************
70  * Internal function prototypes
71  ******************************************************************************/
72 
73  static unsigned char D4DLCD_Init_FrameBuffer(void);
74  static unsigned char D4DLCD_SetWindow_FrameBuffer(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2);
75  static unsigned char D4DLCD_SetOrientation_FrameBuffer(D4DLCD_ORIENTATION new_orientation);
76  static void D4DLCD_Send_PixelColor_FrameBuffer(D4D_COLOR value) ;
77  static D4D_COLOR D4DLCD_Read_PixelColor_FrameBuffer(void);
78  static void D4DLCD_Flush_FrameBuffer(D4DLCD_FLUSH_MODE mode);
79  static unsigned char D4DLCD_DeInit_FrameBuffer(void);
80 
81  static void D4DLCD_ComputeCurAdrr(void);
82 
83  /**************************************************************/
89  // the main structure that contains low level driver api functions
90  // the name fo this structure is used for recognizing of configured low level driver of whole D4D
91  // so this name has to be used in main configuration header file of D4D driver to enable this driver
92  const D4DLCD_FUNCTIONS d4dlcd_frame_buffer =
93  {
94  D4DLCD_Init_FrameBuffer,
95  D4DLCD_SetWindow_FrameBuffer,
96  D4DLCD_SetOrientation_FrameBuffer,
97  D4DLCD_Send_PixelColor_FrameBuffer,
98  D4DLCD_Read_PixelColor_FrameBuffer,
99  D4DLCD_Flush_FrameBuffer,
101  D4DLCD_DeInit_FrameBuffer,
102  };
103 
104  /**************************************************************/
110  static unsigned long win_cur_addr;
111  static unsigned long win_cur_w;
112  static unsigned long win_cur_h;
113 
114  static unsigned long win_x;
115  static unsigned long win_y;
116  static unsigned long win_width;
117  static unsigned long win_height;
118 
119  static signed long win_const1;
120  static signed long win_const2;
121  static signed long win_const3;
122 
123  static unsigned long pix_cnt;
124 
125  static unsigned long bpp_byte;
126 
127 
128  static D4DLCD_ORIENTATION lcd_orient = Portrait;
129  static D4DLCD_ORIENTATION hw_orient = Portrait;
130  static D4DLCD_FRAMEBUFF_DESC* p_fbDesc = NULL;
131 
132 
133  /**************************************************************/
140  //-----------------------------------------------------------------------------
141  // FUNCTION: D4DLCD_Init_FrameBuffer
142  // SCOPE: Low Level Driver API function
143  // DESCRIPTION: The function is used for initialization of this low level driver
144  //
145  // PARAMETERS: none
146  //
147  // RETURNS: result: 1 - Success
148  // 0 - Failed
149  //-----------------------------------------------------------------------------
150  static unsigned char D4DLCD_Init_FrameBuffer(void)
151  {
152  if(!D4D_LLD_LCD_HW.D4DLCDHW_Init())
153  return 0;
154 
155  p_fbDesc = D4D_LLD_LCD_HW.D4DLCDHW_GetFbDescriptor();
156 
157  if(p_fbDesc == NULL)
158  return 0;
159 
160  win_cur_addr = p_fbDesc->fb_start_addr;
161  win_width = 0;
162  win_height = 0;
163 
164  if(p_fbDesc->lcd_x_max < p_fbDesc->lcd_y_max)
165  {
166  hw_orient = Portrait;
167  }
168  else
169  {
170  hw_orient = Landscape;
171  }
172 
173  pix_cnt = (unsigned long)(p_fbDesc->lcd_x_max * p_fbDesc->lcd_y_max);
174 
175  bpp_byte = p_fbDesc->bpp_byte;
176 
177  return 1;
178  }
179 
180  //-----------------------------------------------------------------------------
181  // FUNCTION: D4DLCD_DeInit_FrameBuffer
182  // SCOPE: Low Level Driver API function
183  // DESCRIPTION: The function is used for deinitialization of this low level driver
184  //
185  // PARAMETERS: none
186  //
187  // RETURNS: result: 1 - Success
188  // 0 - Failed
189  //-----------------------------------------------------------------------------
190  static unsigned char D4DLCD_DeInit_FrameBuffer(void)
191  {
192  return D4D_LLD_LCD_HW.D4DLCDHW_DeInit();
193  }
194 
195  //-----------------------------------------------------------------------------
196  // FUNCTION: D4DLCD_SetWindow_FrameBuffer
197  // SCOPE: Low Level Driver API function
198  // DESCRIPTION: The function sets the logic window in memory of LCD driver
199  //
200  // PARAMETERS: unsigned short x1 - left cordination of logic window
201  // unsigned short y1 - top cordination of logic window
202  // unsigned short x2 - right cordination of logic window
203  // unsigned short y2 - bottom cordination of logic window
204  //
205  // RETURNS: result: 1 - Success
206  // 0 - Failed
207  //-----------------------------------------------------------------------------
208  static unsigned char D4DLCD_SetWindow_FrameBuffer(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2)
209  {
210  win_x = x1;
211  win_y = y1;
212 
213  win_width = (unsigned short)(x2 - x1);
214  win_height = (unsigned short)(y2 - y1);
215 
216  win_cur_w = win_width;
217  win_cur_h = win_height;
218 
219  switch(lcd_orient)
220  {
221  case Portrait:
222  win_const1 = (signed long)(p_fbDesc->fb_start_addr + (p_fbDesc->lcd_x_max * win_y + win_x) * bpp_byte);
223  win_const2 = (signed long)((p_fbDesc->lcd_x_max - win_width) * bpp_byte);
224  win_const3 = (signed long)(bpp_byte);
225  break;
226 
227  case Portrait180:
228  win_const1 = (signed long)((p_fbDesc->fb_start_addr + (pix_cnt * bpp_byte)) - (p_fbDesc->lcd_x_max * win_y + win_x) * bpp_byte);
229  win_const2 = (signed long)((p_fbDesc->lcd_x_max - win_width) * -1 * bpp_byte);
230  win_const3 = (signed long)(-1 * bpp_byte);
231  break;
232 
233  case Landscape180:
234  win_const1 = (signed long)(p_fbDesc->fb_start_addr + (p_fbDesc->lcd_x_max * win_x + p_fbDesc->lcd_x_max - win_y - 1) * bpp_byte);
235  win_const2 = (signed long)((win_width * p_fbDesc->lcd_x_max + 1) * -1 * bpp_byte);
236  win_const3 = (signed long)((p_fbDesc->lcd_x_max) * bpp_byte);
237  break;
238 
239  case Landscape:
240  win_const1 = (signed long)((p_fbDesc->fb_start_addr + (pix_cnt * bpp_byte)) - (p_fbDesc->lcd_x_max * win_x + p_fbDesc->lcd_x_max - win_y) * bpp_byte);
241  win_const2 = (signed long)((win_width * p_fbDesc->lcd_x_max + 1) * bpp_byte);
242  win_const3 = (signed long)((p_fbDesc->lcd_x_max) * -1 * bpp_byte);
243  break;
244 
245  }
246 
247 
248  D4DLCD_ComputeCurAdrr();
249  // SIM_MCR &= ~SIM_MCR_LCDSTART_MASK; //Start LCDC
250  // SIM_SCGC3 &= ~SIM_SCGC3_LCDC_MASK;
251  return 1;
252  }
253 
254  //-----------------------------------------------------------------------------
255  // FUNCTION: D4DLCD_SetOrientation_FrameBuffer
256  // SCOPE: Low Level Driver API function
257  // DESCRIPTION: The function set the new orientation of LCD
258  //
259  // PARAMETERS: D4DLCD_ORIENTATION new_orientation the requested new orientation
260  //
261  // RETURNS: result: 1 - Success
262  // 0 - Failed
263  //-----------------------------------------------------------------------------
264  static unsigned char D4DLCD_SetOrientation_FrameBuffer(D4DLCD_ORIENTATION new_orientation)
265  {
266 
267  if(hw_orient == Portrait)
268  lcd_orient = new_orientation;
269  else
270  {
271  switch(new_orientation)
272  {
273  case Portrait:
274  lcd_orient = Landscape;
275  break;
276  case Portrait180:
277  lcd_orient = Landscape180;
278  break;
279  case Landscape:
280  lcd_orient = Portrait;
281  break;
282  case Landscape180:
283  lcd_orient = Portrait180;
284  break;
285  }
286  }
287  return 1;
288  }
289 
290  //-----------------------------------------------------------------------------
291  // FUNCTION: D4DLCD_Send_PixelColor_FrameBuffer
292  // SCOPE: Low Level Driver API function
293  // DESCRIPTION: The function send the one pixel (Word) into LCD
294  //
295  // PARAMETERS: unsigned short Value value of pixel color
296  //
297  // RETURNS: none
298  //-----------------------------------------------------------------------------
299  static void D4DLCD_Send_PixelColor_FrameBuffer(D4D_COLOR value)
300  {
301  #if D4DLCDHWFB_DIRECT_MEM_ACCESS == 1
302 
303 #ifdef D4D_COLOR_TRANSPARENT
304  if(value != D4D_COLOR_TRANSPARENT)
305 #endif
306  *((D4D_COLOR*)win_cur_addr) = value;
307  D4DLCD_ComputeCurAdrr();
308 
309  #else
310 #ifdef D4D_COLOR_TRANSPARENT
311  if(value != D4D_COLOR_TRANSPARENT)
312 #endif
313  D4D_LLD_LCD_HW.D4DLCDHW_WriteData(win_cur_addr, value);
314  D4DLCD_ComputeCurAdrr();
315 
316  #endif
317  }
318 
319  //-----------------------------------------------------------------------------
320  // FUNCTION: D4DLCD_Read_PixelColor_FrameBuffer
321  // SCOPE: Low Level Driver API function
322  // DESCRIPTION: The function reads the one Word(Pixel) from LCD (if this function is supported)
323  //
324  // PARAMETERS: none
325  //
326  // RETURNS: unsigned short - the readed value
327  //
328  //-----------------------------------------------------------------------------
329  static D4D_COLOR D4DLCD_Read_PixelColor_FrameBuffer(void)
330  {
331  D4D_COLOR value;
332 
333  #if D4DLCDHWFB_DIRECT_MEM_ACCESS == 1
334  value = *((D4D_COLOR*)win_cur_addr);
335  D4DLCD_ComputeCurAdrr();
336  return value;
337  #else
338  value = D4D_LLD_LCD_HW.D4DLCDHW_ReadData(win_cur_addr);
339  D4DLCD_ComputeCurAdrr();
340  return value;
341  #endif
342  }
343 
344  //-----------------------------------------------------------------------------
345  // FUNCTION: D4DLCD_Flush_FrameBuffer
346  // SCOPE: Low Level Driver API function
347  // DESCRIPTION: For buffered low level interfaces is used to inform
348  // driver the complete object is drawed and pending pixels should be flushed
349  //
350  // PARAMETERS: none
351  //
352  // RETURNS: none
353  //-----------------------------------------------------------------------------
354  static void D4DLCD_Flush_FrameBuffer(D4DLCD_FLUSH_MODE mode)
355  {
356  D4D_LLD_LCD_HW.D4DLCDHW_FlushBuffer(mode);
357  // SIM_MCR|=SIM_MCR_LCDSTART_MASK; //Start LCDC
358  //SIM_SCGC3 |= SIM_SCGC3_LCDC_MASK;
359  }
360 
361 
362  static void D4DLCD_ComputeCurAdrr(void)
363  {
364  win_cur_w++;
365  if(win_cur_w > win_width)
366  {
367  win_cur_w = 0;
368  win_cur_h++;
369  if(win_cur_h > win_height)
370  {
371  win_cur_h = 0;
372  win_cur_addr = (unsigned long)(win_const1);
373  }
374  else
375  win_cur_addr += win_const2;
376  }
377  else
378  win_cur_addr += win_const3;
379  }
380 
381 
382 #endif //(D4D_MK_STR(D4D_LLD_LCD) == d4dlcd_frame_buffer_ID)
D4D low level standard LCD interface API structure.
Definition: d4d_lldapi.h:147
D4D driver - frame_buffer lcd driver function header file.
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.
unsigned short lcd_x_max
The resolution of LCD in axis X.
Definition: d4d_lldapi.h:120
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
D4D low level frame buffer description structure.
Definition: d4d_lldapi.h:117
#define NULL
Type definition of null pointer.
Definition: d4d_types.h:184
unsigned short lcd_y_max
The resolution of LCD in axis Y.
Definition: d4d_lldapi.h:121
unsigned char bpp_byte
The bytes per pixel.
Definition: d4d_lldapi.h:122
unsigned long fb_start_addr
The address of frame buffer.
Definition: d4d_lldapi.h:119
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