eGUI alias D4D  Release 3.0
Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
d4dlcdhw_k70_lcdc.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 D4DTCH_FUNCTIONS structure + "_ID"
52 // it is used for enable the code for compilation
53 #define d4dlcdhw_k70_lcdc_ID 1
54 
55 
56 // copilation enable preprocessor condition
57 // the string d4dtch_k70_lcdc_ID must be replaced by define created one line up
58 #if (D4D_MK_STR(D4D_LLD_LCD_HW) == d4dlcdhw_k70_lcdc_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  #define MOUSE_CURSOR_GRPHCW_PRTY_KEYCLR_MASK 0x00FFFFFF
69  #define MOUSE_CURSOR_GRPHCW_PRTY_CURSRIX_MASK 0x0F000000
70  #define MOUSE_CURSOR_GRPHCW_PRTY_CHNG_MASK 0x80000000
71  #define MOUSE_CURSOR_GRPHCW_PRTY_SHOW_MASK 0x40000000
72 
73  #define MOUSE_CURSOR_GRPHCW_PRTY_CURSRIX_SHIFT 24
74 
75  /******************************************************************************
76  * Internal function prototypes
77  ******************************************************************************/
78 
79  static unsigned char D4DLCDHW_Init_K70LCDC(void);
80  static unsigned char D4DLCDHW_DeInit_K70LCDC(void);
81  static void D4DLCDHW_WriteData_K70LCDC(unsigned long addr, D4D_COLOR value);
82  static D4D_COLOR D4DLCDHW_ReadData_K70LCDC(unsigned long addr);
83  static D4DLCD_FRAMEBUFF_DESC* D4DLCDHW_GetFbDescriptor_K70LCDC(void);
84  static unsigned char D4DLCDHW_PinCtl_K70LCDC(D4DLCDHW_PINS pinId, D4DHW_PIN_STATE setState);
85  static void D4DLCDHW_FlushBuffer_K70LCDC(D4DLCD_FLUSH_MODE mode);
86 
87 #ifdef D4D_LLD_MOUSE
88  static unsigned char D4DMOUSE_Init_K70LCDC(void);
89  static void D4DMOUSE_SetCoor_K70LCDC(unsigned short x, unsigned short y);
90  static void D4DMOUSE_SetPointerBmp_K70LCDC(void** pPntrData, D4D_INDEX cnt, D4D_COLOR keyColor);
91  static void D4DMOUSE_SetPointer_K70LCDC(D4D_INDEX ix, D4D_BOOL show);
92  static unsigned char D4DMOUSE_DeInit_K70LCDC(void);
93  static D4DMOUSE_DESC* D4DMOUSE_GetDescriptor_K70LCDC(void);
94 #endif
95 
96 
97 #if D4DLCDHWFB_DOUBLE_BUFFER
98  static void D4DLCDHW_CopyBuffers_K70LCDC(unsigned long second2first);
99  void D4DLCDHW_ISR_K70DMA(void);
100 #endif
101 
102 
103  void D4DLCDHW_ISR_K70LCDC(void);
104 
105 
106 
107 
108  /**************************************************************/
114  // the main structure that contains low level driver api functions
115  // the name fo this structure is used for recognizing of configured low level driver of whole D4D
116  // so this name has to be used in main configuration header file of D4D driver to enable this driver
117  const D4DLCDHWFB_FUNCTIONS d4dlcdhw_k70_lcdc =
118  {
119  D4DLCDHW_Init_K70LCDC,
120  D4DLCDHW_WriteData_K70LCDC,
121  D4DLCDHW_ReadData_K70LCDC,
122  D4DLCDHW_GetFbDescriptor_K70LCDC,
123  D4DLCDHW_PinCtl_K70LCDC,
124  D4DLCDHW_FlushBuffer_K70LCDC,
125  D4DLCDHW_DeInit_K70LCDC
126  };
127 
128  #ifdef D4D_LLD_MOUSE
129  const D4DMOUSE_FUNCTIONS d4dmouse_k70_lcdc =
130  {
131  D4DMOUSE_Init_K70LCDC,
132  D4DMOUSE_SetCoor_K70LCDC,
133  D4DMOUSE_SetPointerBmp_K70LCDC,
134  D4DMOUSE_SetPointer_K70LCDC,
135  D4DMOUSE_GetDescriptor_K70LCDC,
136  D4DMOUSE_DeInit_K70LCDC
137  };
138 #endif
139  /**************************************************************/
145  static D4DLCD_FRAMEBUFF_DESC d4dlcdhw_k70_lcdc_desc =
146  {
151  };
152 
153 #ifdef D4D_LLD_MOUSE
154  static const D4DMOUSE_DESC d4dmouse_descriptor =
155  {
159  };
160 #endif
161 
162  static volatile sLWord enableWrite = 0;
163 
164 #ifdef D4D_LLD_MOUSE
165  static volatile LWord graphicWindowPrty = (D4D_COLOR_RGB(0x3F, 0x3F, 0x3F) & MOUSE_CURSOR_GRPHCW_PRTY_KEYCLR_MASK);
166  static volatile LWord* cursorBmpPtr = NULL;
167  static volatile LWord cursorOffsets[D4D_MOUSE_CURSOR_TYPE_CNT];
168 #endif
169 
170 #if D4DLCDHWFB_DOUBLE_BUFFER
171  static unsigned long fb_start_addr_2nd = D4DLCDHWFB_START_ADDRESS_2ND;
172  static volatile signed long fb_draw_2nd = 0;
173  static volatile unsigned long fb_switch = 0;
174  static volatile unsigned long lastUpdateStart, lastUpdateEnd;
175 #endif
176  /**************************************************************/
183  //-----------------------------------------------------------------------------
184  // FUNCTION: D4DLCDHW_Init_K70LCDC
185  // SCOPE: Low Level Driver API function
186  // DESCRIPTION: The function is used for initialization of this low level driver
187  //
188  // PARAMETERS: none
189  //
190  // RETURNS: result: 1 - Success
191  // 0 - Failed
192  //-----------------------------------------------------------------------------
193 static unsigned char D4DLCDHW_Init_K70LCDC(void)
194 {
195  unsigned long * pTmp;
196  unsigned long i;
197  /* Enable LCDC and DDR Modules */
198  SIM_SCGC3 |= SIM_SCGC3_LCDC_MASK;
199 
200 #ifdef LCDC_DEBUG
201  PORTB_PCR10 = PORT_PCR_MUX(1);
202  PORTB_PCR11 = PORT_PCR_MUX(1);
203  PORTB_PCR16 = PORT_PCR_MUX(1);
204  PORTB_PCR17 = PORT_PCR_MUX(1);
205  PORTB_PCR18 = PORT_PCR_MUX(1);
206 
207  GPIOB_PDDR |= (1<<10) | (1<<11) | (1<<16) | (1<<17) | (1<<18);
208  GPIOB_PCOR |= (1<<10) | (1<<11) | (1<<16) | (1<<17) | (1<<18);
209 #endif
210 
212  return 0;
213 
214 
215  // Registrer interrupt service routines
216  #ifdef D4D_OS_MQX
217  if(!_int_install_kernel_isr(INT_LCD, D4DLCDHW_ISR_K70LCDC))
218  return 0;
219  _bsp_int_init(INT_LCD, 3, 0, TRUE);
220  #else
221  NVIC_IP(INT_LCD) = 3;
222  NVIC_ISER(INT_LCD / 32) |= (1 << (INT_LCD % 32));
223  #warning The LCDC K70 driver is is using interrupts, please registry the "D4DLCDHW_ISR_K70LCDC" on interrupt vector of LCDC (113).
224  #endif
225 
226 
227  #if D4DLCDHWFB_START_ADDRESS == 0
228  // Allocate frame buffer memory
229  if(d4dlcdhw_k70_lcdc_desc.fb_start_addr)
230  {
231  D4D_MemFree((void*)d4dlcdhw_k70_lcdc_desc.fb_start_addr);
232  d4dlcdhw_k70_lcdc_desc.fb_start_addr = 0;
233  }
234  d4dlcdhw_k70_lcdc_desc.fb_start_addr = (unsigned long)D4D_MemAlloc(D4DLCDHWFB_FRAMEBUFFER_SIZE);
235  if(!d4dlcdhw_k70_lcdc_desc.fb_start_addr)
236  return 0;
237  #endif
238 
239  // Clear the previous contents of buffer
240  pTmp = (unsigned long*)d4dlcdhw_k70_lcdc_desc.fb_start_addr;
241  for(i=0;i<(D4DLCDHWFB_X_MAX * D4DLCDHWFB_Y_MAX);i++)
242  *(pTmp++) = 0; // Black color
243 
244  #if D4DLCDHWFB_DOUBLE_BUFFER
245  #if D4DLCDHWFB_START_ADDRESS_2ND == 0
246  // Allocate frame buffer memory
247  if(fb_start_addr_2nd)
248  {
249  D4D_MemFree((void*)fb_start_addr_2nd);
250  fb_start_addr_2nd = 0;
251  }
252  fb_start_addr_2nd = (unsigned long)D4D_MemAlloc(D4DLCDHWFB_FRAMEBUFFER_SIZE);
253  if(!fb_start_addr_2nd)
254  return 0;
255  #endif
256  fb_switch = 0;
257  fb_draw_2nd = fb_start_addr_2nd - d4dlcdhw_k70_lcdc_desc.fb_start_addr;
258  lastUpdateStart = 0xFFFFFFFF;
259  lastUpdateEnd = 0;
260 
261 #if D4DLCDHWFB_DMA_ENABLE
262  SIM_SCGC7 |= SIM_SCGC7_DMA_MASK;
263  SIM_SCGC6 |= SIM_SCGC6_DMAMUX0_MASK;
264  #if D4DLCDHWFB_DMA_CHANNEL < 16
265  SIM_SCGC6 |= SIM_SCGC6_DMAMUX0_MASK;
266  DMAMUX0_CHCFG(D4DLCDHWFB_DMA_CHANNEL) = DMAMUX_CHCFG_ENBL_MASK | DMAMUX_CHCFG_SOURCE(63);
267  #else
268  SIM_SCGC6 |= SIM_SCGC6_DMAMUX1_MASK;
269  DMAMUX1_CHCFG(D4DLCDHWFB_DMA_CHANNEL - 16) = DMAMUX_CHCFG_ENBL_MASK | DMAMUX_CHCFG_SOURCE(63);
270  #endif
271  // Copy the buffer
272 
273  // set up the channel priority
274  *(unsigned char*)((unsigned long)&DMA_DCHPRI3 + (3 - (D4DLCDHWFB_DMA_CHANNEL % 4)) + ((D4DLCDHWFB_DMA_CHANNEL / 4) * 4)) = D4DLCDHWFB_DMA_CHPRI;
275 
276  DMA_SOFF(D4DLCDHWFB_DMA_CHANNEL) = 16;
277  DMA_NBYTES_MLNO(D4DLCDHWFB_DMA_CHANNEL) = 16;
278  DMA_DOFF(D4DLCDHWFB_DMA_CHANNEL) = 16;
279  DMA_ATTR(D4DLCDHWFB_DMA_CHANNEL) = DMA_ATTR_SMOD(0) | DMA_ATTR_SSIZE(4) | DMA_ATTR_DMOD(0) | DMA_ATTR_DSIZE(4); // no circular addressing S&D, 32 bit S&D
280  DMA_SLAST(D4DLCDHWFB_DMA_CHANNEL) = 0; // source address will continue X times to allow defined multiply length of buffer // to do
281  DMA_DLAST_SGA(D4DLCDHWFB_DMA_CHANNEL) = 0; // no final last adjustment ( does not move )
282  DMA_CSR(D4DLCDHWFB_DMA_CHANNEL) = DMA_CSR_INTMAJOR_MASK; // major interrupt when done
283 
284  // Registrer interrupt service routines
285  #ifdef D4D_OS_MQX
286  if(!_int_install_kernel_isr(D4DLCDHWFB_DMA_INTVECT, D4DLCDHW_ISR_K70DMA))
287  {
288  D4DLCDHW_DeInit_K70LCDC();
289  return 0;
290  }
291 
292  _bsp_int_init(D4DLCDHWFB_DMA_INTVECT, 3, 0, TRUE);
293  #else
294  NVIC_IP(D4DLCDHWFB_DMA_INTVECT) = 3;
295  NVIC_ISER(D4DLCDHWFB_DMA_INTVECT / 32) |= (1 << (D4DLCDHWFB_DMA_INTVECT % 32));
296  #warning The LCDC K70 driver is is using interrupts, please registry the "D4DLCDHW_ISR_K70DMA" on right interrupt vector for selected DMA channel by D4DLCDHWFB_DMA_CHANNEL.
297  #endif
298 
299 #endif
300  // Clear the previous contents of buffer
301  pTmp = (unsigned long*)fb_start_addr_2nd;
302  for(i=0;i<(D4DLCDHWFB_X_MAX * D4DLCDHWFB_Y_MAX);i++)
303  *(pTmp++) = 0; // Black color
304 
305  #endif
306 
307  enableWrite = 1;
308 #ifdef LCDC_DEBUG
309  GPIOB_PSOR |= 1<<10;
310 #endif
311 
312  #if D4DLCDHWFB_MIRROWED == 1
313  LCDC_LSSAR = d4dlcdhw_k70_lcdc_desc.fb_start_addr + D4DLCDHWFB_X_MAX * D4DLCDHWFB_Y_MAX * D4DLCDHWFB_BPP_BYTE;
314  #else
315  LCDC_LSSAR = d4dlcdhw_k70_lcdc_desc.fb_start_addr;
316  #endif
317 
318 #ifdef LCDC_DEBUG
319  GPIOB_PSOR |= 1<<11;
320 #endif
321 
322  LCDC_LSR = (D4DLCDHWFB_X_MAX / 16) << 20 | (D4DLCDHWFB_Y_MAX);
323 
324  // set LCD virtual page width
325  LCDC_LVPWR = LCDC_LVPWR_VPW( D4DLCDHWFB_X_MAX / (4 / D4DLCDHWFB_BPP_BYTE));
326 
327  // set LCD cursor positon & settings (turn off)
328  LCDC_LCPR = 0;
329  LCDC_LCWHB = 0;
330 
331  // set LCD panning offset
332  LCDC_LPOR = 0;
333 
334  // set LCD interrupt configuration
335  LCDC_LICR = 0;
336 
337  // set LCD interrupt enable
338  LCDC_LIER = LCDC_LIER_EOF_EN_MASK;
339 
340  //Set background plane DMA to burst mode
341  LCDC_LDCR &= ~(LCDC_LDCR_BURST_MASK);
342 
344 
345  #if D4DLCDHWFB_MIRROWED == 1
346  LCDC_LPCR |= LCDC_LPCR_REV_VS_MASK;
347  #endif
348  /* Enable LCD */
349  SIM_MCR|=SIM_MCR_LCDSTART_MASK;
350 
351 
352  return 1;
353 }
354 
355 
356  //-----------------------------------------------------------------------------
357  // FUNCTION: D4DLCDHW_DeInit_K70LCDC
358  // SCOPE: Low Level Driver API function
359  // DESCRIPTION: The function is used for deinitialization of this low level driver
360  //
361  // PARAMETERS: none
362  //
363  // RETURNS: result: 1 - Success
364  // 0 - Failed
365  //-----------------------------------------------------------------------------
366  static unsigned char D4DLCDHW_DeInit_K70LCDC(void)
367  {
368  #if D4DLCDHWFB_START_ADDRESS == 0
369  if(d4dlcdhw_k70_lcdc_desc.fb_start_addr)
370  {
371  D4D_MemFree((void*)d4dlcdhw_k70_lcdc_desc.fb_start_addr);
372  d4dlcdhw_k70_lcdc_desc.fb_start_addr = 0;
373  }
374  #endif
375 
376  #if D4DLCDHWFB_DOUBLE_BUFFER
377  #if D4DLCDHWFB_START_ADDRESS_2ND == 0
378  if(fb_start_addr_2nd)
379  {
380  D4D_MemFree((void*)fb_start_addr_2nd);
381  fb_start_addr_2nd = 0;
382  }
383  #endif
384  #endif
385 
386  return 1;
387  }
388 
389  //-----------------------------------------------------------------------------
390  // FUNCTION: D4DLCDHW_SendDataWord_K70LCDC
391  // SCOPE: Low Level Driver API function
392  // DESCRIPTION: The function send the one 16 bit variable into LCD
393  //
394  // PARAMETERS: unsigned long addr address to write data
395  // unsigned short value variable to send
396  //
397  // RETURNS: none
398  //-----------------------------------------------------------------------------
399  static void D4DLCDHW_WriteData_K70LCDC(unsigned long addr, D4D_COLOR value)
400  {
401  unsigned long data;
402 
403  #if D4D_COLOR_SYSTEM == D4D_COLOR_SYSTEM_RGB888
404  data = value;
405  #else
406  data = D4D_COLOR_RGB888(D4D_COLOR_GET_R(value), D4D_COLOR_GET_G(value), D4D_COLOR_GET_B(value));
407  #endif
408 
409  while(enableWrite <= 0);
410 
411  #if D4DLCDHWFB_DOUBLE_BUFFER
412  addr += fb_draw_2nd;
413 
414 
415 
416  if(addr > lastUpdateEnd)
417  {
418  // 16 Byte alligment
419  if(addr & 0x0000000f)
420  lastUpdateEnd = (addr & 0xFFFFFFF0) + 0x00000010;
421  else
422  lastUpdateEnd = addr;
423  }
424 
425  if(addr < lastUpdateStart)
426  {
427  // 16 Byte alligment
428  lastUpdateStart = addr & 0xFFFFFFF0;
429  }
430 
431  #endif
432 
433  *((unsigned long*)addr) = data;
434  }
435 
436 
437  //-----------------------------------------------------------------------------
438  // FUNCTION: D4DLCDHW_ReadDataWord_K70LCDC
439  // SCOPE: Low Level Driver API function
440  // DESCRIPTION: The function reads the one 16 bit variable from LCD (if this function is supported)
441  //
442  // PARAMETERS: unsigned long addr address to read data
443  //
444  // RETURNS: unsigned short - the readed value
445  //
446  //-----------------------------------------------------------------------------
447  static D4D_COLOR D4DLCDHW_ReadData_K70LCDC(unsigned long addr)
448  {
449  #if D4DLCDHWFB_DOUBLE_BUFFER
450  while(enableWrite <= 0);
451  addr += fb_draw_2nd;
452  // to do pocat az sa dokonci kopirovani - nebo jeste lepe pokud neni dokoncene kopirovani brat s jineho
453  #endif
454 
455  #if D4D_COLOR_SYSTEM == D4D_COLOR_SYSTEM_RGB888
456  return *((unsigned long*)addr);
457  #else
458  unsigned long value = *((unsigned long*)addr);
460  #endif
461  }
462 
463 
464  //-----------------------------------------------------------------------------
465  // FUNCTION: D4DLCDHW_GetFbDescriptor_K70LCDC
466  // SCOPE: Low Level Driver API function
467  // DESCRIPTION: The function return the pointer on filled frame buffer descriptor
468  //
469  // PARAMETERS: none
470  //
471  // RETURNS: D4DLCD_FRAMEBUFF_DESC* - pointer on frame buffer descriptor
472  //
473  //-----------------------------------------------------------------------------
474  static D4DLCD_FRAMEBUFF_DESC* D4DLCDHW_GetFbDescriptor_K70LCDC(void)
475  {
476  return (D4DLCD_FRAMEBUFF_DESC*) &d4dlcdhw_k70_lcdc_desc;
477  }
478 
479  //-----------------------------------------------------------------------------
480  // FUNCTION: D4DLCDHW_PinCtl_K70LCDC
481  // SCOPE: Low Level Driver API function
482  // DESCRIPTION: allows control GPIO pins for LCD conrol purposes
483  //
484  // PARAMETERS: D4DLCDHW_PINS pinId - Pin identification
485  // D4DHW_PIN_STATE setState - Pin action
486  // RETURNS: for Get action retuns the pin value
487  //-----------------------------------------------------------------------------
488  static unsigned char D4DLCDHW_PinCtl_K70LCDC(D4DLCDHW_PINS pinId, D4DHW_PIN_STATE setState)
489  {
490  (void)pinId;
491  (void)setState;
492  return 0;
493  }
494 
495  //-----------------------------------------------------------------------------
496  // FUNCTION: D4DLCD_FlushBuffer_K70LCDC
497  // SCOPE: Low Level Driver API function
498  // DESCRIPTION: For buffered low level interfaces is used to inform
499  // driver the complete object is drawed and pending pixels should be flushed
500  //
501  // PARAMETERS: none
502  //
503  // RETURNS: none
504  //-----------------------------------------------------------------------------
505  static void D4DLCDHW_FlushBuffer_K70LCDC(D4DLCD_FLUSH_MODE mode)
506  {
507 
508 #if (D4DLCDHWFB_DOUBLE_BUFFER == 0) && (D4DLCDHWFB_CACHE_FLUSH_ENABLE == 0)
509  D4D_UNUSED(mode);
510 #endif
511 
512 #if D4DLCDHWFB_CACHE_FLUSH_ENABLE || D4DLCDHWFB_DOUBLE_BUFFER
513  if(mode == D4DLCD_FLSH_SCR_END || mode == D4DLCD_FLSH_FORCE)
514  {
515 #if D4DLCDHWFB_CACHE_FLUSH_ENABLE
516  LMEM_PSCCR |= LMEM_PSCCR_GO_MASK | LMEM_PSCCR_PUSHW0_MASK | LMEM_PSCCR_PUSHW1_MASK;
517  /* wait until the command completes */
518  while (LMEM_PSCCR & LMEM_PSCCR_GO_MASK)
519  {};
520 #endif
521 #if D4DLCDHWFB_DOUBLE_BUFFER
522  enableWrite = 0;
523 #ifdef LCDC_DEBUG
524  GPIOB_PCOR |= 1<<10;
525  GPIOB_PTOR |= 1<<16;
526 #endif
527 
528  D4DLCDHW_CopyBuffers_K70LCDC(fb_draw_2nd);
529  fb_switch = 1;
530 #endif
531  }
532 #endif
533  }
534 
535  //-----------------------------------------------------------------------------
536  // FUNCTION: D4DLCDHW_ISR_K70LCDC
537  // SCOPE: Low Level Driver API function
538  // DESCRIPTION: For interrupt handler of LCDC events
539  //
540  // PARAMETERS: none (pData)
541  //
542  // RETURNS: none
543  //-----------------------------------------------------------------------------
544 
545  void D4DLCDHW_ISR_K70LCDC(void)
546  {
547 #ifdef LCDC_DEBUG
548  GPIOB_PTOR |= 1<<18;
549 #endif
550  LWord status = LCDC_LISR;
551 
552  if((LCDC_LIER & LCDC_LIER_EOF_EN_MASK) && (status & LCDC_LISR_EOF_MASK))
553  {
554  // End of drawing screen
555 
556 
557 #if D4DLCDHWFB_DOUBLE_BUFFER
558  if(fb_switch)
559  {
560  fb_switch = 0;
561 
562  // Switch the frame buffer
563  if(!fb_draw_2nd)
564  {
565  fb_draw_2nd = fb_start_addr_2nd - d4dlcdhw_k70_lcdc_desc.fb_start_addr;
566 
567  #ifdef LCDC_DEBUG
568  GPIOB_PSOR |= 1<<11;
569  #endif
570 
571  #if D4DLCDHWFB_MIRROWED == 1
572  LCDC_LSSAR = d4dlcdhw_k70_lcdc_desc.fb_start_addr + D4DLCDHWFB_X_MAX * D4DLCDHWFB_Y_MAX * D4DLCDHWFB_BPP_BYTE;
573  #else
574  LCDC_LSSAR = d4dlcdhw_k70_lcdc_desc.fb_start_addr;
575  #endif
576  }
577  else
578  {
579  fb_draw_2nd = 0;
580  #ifdef LCDC_DEBUG
581  GPIOB_PCOR |= 1<<11;
582  #endif
583 
584  #if D4DLCDHWFB_MIRROWED == 1
585  LCDC_LSSAR = fb_start_addr_2nd + D4DLCDHWFB_X_MAX * D4DLCDHWFB_Y_MAX * D4DLCDHWFB_BPP_BYTE;
586  #else
587  LCDC_LSSAR = fb_start_addr_2nd;
588  #endif
589  }
590  if(enableWrite < 0)
591  enableWrite = 1;
592  else
593  enableWrite = -1;
594  }
595 
596 #endif
597 
598 #if (D4DLCDHWFB_DOUBLE_BUFFER == 0) || defined(D4D_LLD_MOUSE)
599 
600 #if (D4DLCDHWFB_DOUBLE_BUFFER == 0)
601  enableWrite = 1;
602 #endif
603 
604  #ifdef LCDC_DEBUG
605  GPIOB_PSOR |= 1<<10;
606  #endif
607 
608  //NOTE: LICR[INTCON] must be 1 to use the BOF interrupt.
609  LCDC_LICR = LCDC_LICR_INTCON_MASK /*| LCDC_LICR_INTSYN_MASK*/;
610  LCDC_LIER &= ~LCDC_LIER_EOF_EN_MASK;
611  LCDC_LIER |= LCDC_LIER_BOF_EN_MASK;
612 
613 #endif
614  }
615 
616 
617 
618  else if((LCDC_LIER & LCDC_LIER_BOF_EN_MASK) && (status & LCDC_LISR_BOF_MASK))
619  {
620 #if (D4DLCDHWFB_DOUBLE_BUFFER == 0)
621  enableWrite = 0;
622 #endif
623  #ifdef LCDC_DEBUG
624  GPIOB_PCOR |= 1<<10;
625  #endif
626 
627  //NOTE: LICR[INTCON] must be 0 to use the EOF interrupt.
628  LCDC_LICR = LCDC_LICR_INTSYN_MASK;
629  LCDC_LIER &= ~LCDC_LIER_BOF_EN_MASK;
630  LCDC_LIER |= LCDC_LIER_EOF_EN_MASK;
631  }
632 
633 
634 #if defined(D4D_LLD_MOUSE)
635  if((LCDC_LIER & LCDC_LIER_GW_EOF_EN_MASK) && (status & LCDC_LISR_GW_EOF_MASK))
636  {
637  unsigned char alpha = (LCDC_LGWCR & LCDC_LGWCR_GWAV_MASK)>> LCDC_LGWCR_GWAV_SHIFT ;
638 
639  // Start of drawing screen
640  if(graphicWindowPrty & MOUSE_CURSOR_GRPHCW_PRTY_CHNG_MASK)
641  {
642  unsigned char r,b,g;
643  // Change the cursor pointer
644  SIM_MCR &= ~SIM_MCR_LCDSTART_MASK;
645 
646  r = D4D_COLOR_GET_R(graphicWindowPrty) & 0x3F;
647  g = D4D_COLOR_GET_G(graphicWindowPrty) & 0x3F;
648  b = D4D_COLOR_GET_B(graphicWindowPrty) & 0x3F;
649 
650  // Enable graphic window
651  // Change KeyColor
652  // set LCD graphic window control
653  LCDC_LGWCR &= ~(LCDC_LGWCR_GWCKR_MASK | LCDC_LGWCR_GWCKG_MASK | LCDC_LGWCR_GWCKB_MASK);
654  LCDC_LGWCR |= LCDC_LGWCR_GWCKR(r) | LCDC_LGWCR_GWCKG(g) | LCDC_LGWCR_GWCKB(b);// color key
655  SIM_MCR |= SIM_MCR_LCDSTART_MASK;
656 
657  graphicWindowPrty &= ~MOUSE_CURSOR_GRPHCW_PRTY_CHNG_MASK;
658  }
659 
660  LCDC_LGWSAR = (unsigned long)((char*)cursorBmpPtr + cursorOffsets[(graphicWindowPrty & MOUSE_CURSOR_GRPHCW_PRTY_CURSRIX_MASK) >> MOUSE_CURSOR_GRPHCW_PRTY_CURSRIX_SHIFT]);
661  LCDC_LIER &= ~LCDC_LIER_GW_EOF_EN_MASK;
662 // LCDC_LGWCR &= ~LCDC_LGWCR_GWAV_MASK;
663 //
664 // if(graphicWindowPrty & MOUSE_CURSOR_GRPHCW_PRTY_SHOW_MASK)
665 // {
666 // // make visible cursor
667 // if(alpha > 0xF7)
668 // {
669 // alpha = 0xFF;
670 // LCDC_LIER &= ~LCDC_LIER_GW_EOF_EN_MASK;
671 // }
672 // else
673 // {
674 // alpha += 8;
675 // }
676 // }else
677 // {
678 // // make visible cursor
679 // if(alpha < 8)
680 // {
681 // alpha = 0;
682 // LCDC_LIER &= ~LCDC_LIER_GW_EOF_EN_MASK;
683 // }
684 // else
685 // {
686 // alpha -= 8;
687 // }
688 // }
689 // LCDC_LGWCR |= LCDC_LGWCR_GWAV(alpha);
690 
691 
692 
693 
694  }
695 #endif
696 
697  }
698 
699  #if D4DLCDHWFB_DOUBLE_BUFFER
700 
701  //-----------------------------------------------------------------------------
702  // FUNCTION: D4DLCDHW_CopyBuffers_K70LCDC
703  // SCOPE: Low Level Driver API function
704  // DESCRIPTION: The function update the last showed buffer with current data
705  //
706  // PARAMETERS: none
707  //
708  // RETURNS: none
709  //-----------------------------------------------------------------------------
710  static void D4DLCDHW_CopyBuffers_K70LCDC(unsigned long second2first)
711  {
712  LWord* pSource;
713  LWord* pDest;
714  LWord cnt = lastUpdateEnd;
715  cnt -= lastUpdateStart;
716 
717  pSource = (LWord*)lastUpdateStart;
718  if(second2first)
719  pDest = (LWord*)(d4dlcdhw_k70_lcdc_desc.fb_start_addr + (lastUpdateStart - fb_start_addr_2nd));
720  else
721  pDest = (LWord*)(fb_start_addr_2nd + (lastUpdateStart - d4dlcdhw_k70_lcdc_desc.fb_start_addr));
722 
723 
724  #if D4DLCDHWFB_DMA_ENABLE
725  DMA_SADDR(D4DLCDHWFB_DMA_CHANNEL) = (LWord)pSource;
726  DMA_DADDR(D4DLCDHWFB_DMA_CHANNEL) = (LWord)pDest;
727 
728  DMA_CITER_ELINKNO(D4DLCDHWFB_DMA_CHANNEL) = cnt / 16;
729  DMA_BITER_ELINKNO(D4DLCDHWFB_DMA_CHANNEL) = cnt / 16;
730 
731  DMA_ERQ |= 1<<D4DLCDHWFB_DMA_CHANNEL;
732  DMA_SSRT = D4DLCDHWFB_DMA_CHANNEL;
733 
734  if(DMA_ES)
735  {
736  DMA_CERR = DMA_CERR_CAEI_MASK;
737  enableWrite = 1;
738  }
739  #else
740  cnt /= 4;
741 
742  while(cnt--)
743  *pDest++ = *pSource++;
744 
745  if(enableWrite < 0)
746  enableWrite = 1;
747  else
748  enableWrite = -1;
749 
750  #ifdef LCDC_DEBUG
751  GPIOB_PSOR |= 1<<10;
752  #endif
753 
754  #endif
755  lastUpdateStart = 0xFFFFFFFF;
756  lastUpdateEnd = 0;
757  }
758 
759  #if D4DLCDHWFB_DMA_ENABLE
760  //-----------------------------------------------------------------------------
761  // FUNCTION: D4DLCDHW_ISR_K70DMA
762  // SCOPE: Low Level Driver API function
763  // DESCRIPTION: For interrupt handler of LCDC events
764  //
765  // PARAMETERS: none (pData)
766  //
767  // RETURNS: none
768  //-----------------------------------------------------------------------------
769 
770  void D4DLCDHW_ISR_K70DMA(void)
771  {
772  #ifdef LCDC_DEBUG
773  GPIOB_PTOR |= 1<<17;
774  #endif
775 
776  if(DMA_INT & (1<<D4DLCDHWFB_DMA_CHANNEL))
777  {
778  DMA_INT |= (1<<D4DLCDHWFB_DMA_CHANNEL);
779  DMA_ERQ &= ~(1<<D4DLCDHWFB_DMA_CHANNEL);
780  if(enableWrite < 0)
781  enableWrite = 1;
782  else
783  enableWrite = -1;
784  #ifdef LCDC_DEBUG
785  GPIOB_PSOR |= 1<<10;
786  #endif
787  }
788  }
789  #endif
790 
791  #endif
792 
793 #ifdef D4D_LLD_MOUSE
794 
795  /**************************************************************/
801  //-----------------------------------------------------------------------------
802  // FUNCTION: D4DMOUSE_Init_K70LCDC
803  // SCOPE: Low Level Driver API function
804  // DESCRIPTION: The function is used for initialization of this mouse low level driver
805  //
806  // PARAMETERS: none
807  //
808  // RETURNS: result: 1 - Success
809  // 0 - Failed
810  //-----------------------------------------------------------------------------
811  static unsigned char D4DMOUSE_Init_K70LCDC(void)
812  {
813  if(!(SIM_SCGC3 & SIM_SCGC3_LCDC_MASK))
814  return D4D_FALSE;
815 
816  SIM_MCR &= ~SIM_MCR_LCDSTART_MASK;
817 
818  // set LCD graphic window start address - at the momnet there is no know any picture data
819  LCDC_LGWSAR = 0x20000000;
820 
821  // set LCD graphic window size
822  LCDC_LGWSR = LCDC_LGWSR_GWW(1) | LCDC_LGWSR_GWH(16);
823 
824  // set LCD graphic window virtual page width
825  LCDC_LGWVPWR = 16;
826 
827  // set LCD graphic window panning offset
828  LCDC_LGWPOR = 0;
829 
830  // set LCD graphic window position
831  LCDC_LGWPR = LCDC_LGWPR_GWXP(0) | LCDC_LGWPR_GWYP(0);
832 
833  //Set graphic window DMA to burst mode
834  LCDC_LGWDCR &= ~(LCDC_LGWDCR_GWBT_MASK);
835 
836  graphicWindowPrty = (D4D_COLOR_RGB(0x3F, 0x3F, 0x3F) & MOUSE_CURSOR_GRPHCW_PRTY_KEYCLR_MASK); // is also used to as flag to change
837  cursorBmpPtr = NULL;
838 
839  for(int i=0; i < D4D_MOUSE_CURSOR_TYPE_CNT;i++)
840  cursorOffsets[i] = 0;
841 
842 
843  // Enable graphic window
844  // Change KeyColor
845  // set LCD graphic window control
846  LCDC_LGWCR = LCDC_LGWCR_GWAV(1) | // alpha-transparent
847  LCDC_LGWCR_GWCKE_MASK | // enable color keying
848  LCDC_LGWCR_GWE_MASK | // enable graphic window
849  //LCDC_LGWCR_GW_RVS_MASK | // reverse vertical scan
850  LCDC_LGWCR_GWCKR(0x3F) | // color key
851  LCDC_LGWCR_GWCKG(0x3F) |
852  LCDC_LGWCR_GWCKB(0x3F);
853 
854  SIM_MCR |= SIM_MCR_LCDSTART_MASK;
855  return D4D_TRUE;
856  }
857 
858  //-----------------------------------------------------------------------------
859  // FUNCTION: D4DMOUSE_SetCoor_K70LCDC
860  // SCOPE: Low Level Driver API function
861  // DESCRIPTION: The function is used for change/set the coordination of cursor
862  //
863  // PARAMETERS: x- coordination in axis X
864  // y- coordination in axis Y
865  //
866  // RETURNS: none
867  //-----------------------------------------------------------------------------
868  static void D4DMOUSE_SetCoor_K70LCDC(unsigned short x, unsigned short y)
869  {
870  // set LCD graphic window position
871  LCDC_LGWPR = LCDC_LGWPR_GWXP(x) | LCDC_LGWPR_GWYP(y);
872  }
873 
874  //-----------------------------------------------------------------------------
875  // FUNCTION: D4DMOUSE_SetPointerBmp_K70LCDC
876  // SCOPE: Low Level Driver API function
877  // DESCRIPTION: The function is used for sets the new set of cursor bitmaps
878  //
879  // PARAMETERS: pPntrData- pointer on graphic data (must be in 8-8-8 format)
880  // cnt - count of bitmaps
881  // keyColor - keycolor of these bitmaps
882  //
883  // RETURNS: none
884  //-----------------------------------------------------------------------------
885  static void D4DMOUSE_SetPointerBmp_K70LCDC(void** pPntrData, D4D_INDEX cnt, D4D_COLOR keyColor)
886  {
887  int uniqueBmp = 0;
888  int filledArray = 0;
889  if(!pPntrData)
890  return;
891 
892  if(cnt > D4D_MOUSE_CURSOR_TYPE_CNT)
893  return;
894 
895  // Get the count of unigue bitmaps
896  for(int i=0; i < cnt;i++)
897  {
898  int j = i;
899  if(pPntrData[i])
900  {
901  uniqueBmp++;
902 
903  while(j)
904  {
905  j--;
906  if(pPntrData[i] == pPntrData[j])
907  {
908  uniqueBmp--;
909  break;
910  }
911  }
912  }
913  cursorOffsets[i] = (uniqueBmp - 1) * D4DMOUSE_CURSOR_SIZE_X * D4DMOUSE_CURSOR_SIZE_Y * D4DLCDHWFB_BPP_BYTE;
914  }
915 
916  // alloc the memory for the unique bitmaps
917 
918  if(cursorBmpPtr)
919  D4D_MemFree((void*)cursorBmpPtr);
920 
921  cursorBmpPtr = D4D_MemAlloc(D4DMOUSE_CURSOR_SIZE_X * D4DMOUSE_CURSOR_SIZE_Y * D4DLCDHWFB_BPP_BYTE * uniqueBmp);
922 
923  if(!cursorBmpPtr)
924  return;
925 
926  // Copy the bitmpa data to RAM (just only unique bitmaps)
927  for(int i=0; i < uniqueBmp;i++)
928  {
929  int j = cursorOffsets[i] / (D4DMOUSE_CURSOR_SIZE_X * D4DMOUSE_CURSOR_SIZE_Y * D4DLCDHWFB_BPP_BYTE);
930 
931  if(filledArray <= j)
932  {
933  char* pDst = ((char*)cursorBmpPtr) + filledArray * (D4DMOUSE_CURSOR_SIZE_X * D4DMOUSE_CURSOR_SIZE_Y * D4DLCDHWFB_BPP_BYTE);
934  char* pSrc = (char*)pPntrData[i];
935 
936  D4D_MemCopy(pDst, pSrc, (D4DMOUSE_CURSOR_SIZE_X * D4DMOUSE_CURSOR_SIZE_Y * D4DLCDHWFB_BPP_BYTE));
937  filledArray++;
938  }
939  }
940 
941  graphicWindowPrty &= ~MOUSE_CURSOR_GRPHCW_PRTY_KEYCLR_MASK;
942  graphicWindowPrty = MOUSE_CURSOR_GRPHCW_PRTY_CHNG_MASK | (keyColor & MOUSE_CURSOR_GRPHCW_PRTY_KEYCLR_MASK);
943  LCDC_LIER |= LCDC_LIER_GW_EOF_EN_MASK;
944  }
945 
946  //-----------------------------------------------------------------------------
947  // FUNCTION: D4DMOUSE_SetPointer_K70LCDC
948  // SCOPE: Low Level Driver API function
949  // DESCRIPTION: The function is used for switch off/set the cursor bitmap
950  //
951  // PARAMETERS: pPntrData- pointer on graphic data (must be in 8-8-8 format)
952  //
953  // RETURNS: none
954  //-----------------------------------------------------------------------------
955  static void D4DMOUSE_SetPointer_K70LCDC(D4D_INDEX ix, D4D_BOOL show)
956  {
957  LWord bck_graphicWindowPrty = graphicWindowPrty;
958  if(show)
959  {
960  graphicWindowPrty &= ~MOUSE_CURSOR_GRPHCW_PRTY_CURSRIX_MASK;
961  graphicWindowPrty |= ((ix << MOUSE_CURSOR_GRPHCW_PRTY_CURSRIX_SHIFT) & MOUSE_CURSOR_GRPHCW_PRTY_CURSRIX_MASK) | MOUSE_CURSOR_GRPHCW_PRTY_SHOW_MASK;
962  LCDC_LGWCR |= LCDC_LGWCR_GWAV(0xFF);
963  }else
964  {
965  if(graphicWindowPrty & MOUSE_CURSOR_GRPHCW_PRTY_SHOW_MASK)
966  {
967  // switch off
968  graphicWindowPrty &= ~MOUSE_CURSOR_GRPHCW_PRTY_SHOW_MASK;
969  LCDC_LGWCR &= ~LCDC_LGWCR_GWAV_MASK;
970  }
971  }
972 
973  if(graphicWindowPrty != bck_graphicWindowPrty)
974  LCDC_LIER |= LCDC_LIER_GW_EOF_EN_MASK;
975 
976  }
977 
978  //-----------------------------------------------------------------------------
979  // FUNCTION: D4DMOUSE_GetDescriptor_K70LCDC
980  // SCOPE: Low Level Driver API function
981  // DESCRIPTION: The function return pointer on Mouse Cursor descriptor
982  //
983  // PARAMETERS: none
984  //
985  // RETURNS: pointer to Mouse cursor
986  //-----------------------------------------------------------------------------
987  static D4DMOUSE_DESC* D4DMOUSE_GetDescriptor_K70LCDC(void)
988  {
989  return (D4DMOUSE_DESC*)&d4dmouse_descriptor;
990  }
991 
992  //-----------------------------------------------------------------------------
993  // FUNCTION: D4DMOUSE_DeInit_K70LCDC
994  // SCOPE: Low Level Driver API function
995  // DESCRIPTION: The function is used for deinicialization of driver
996  //
997  // PARAMETERS: none
998  //
999  // RETURNS: result: 1 - Success
1000  // 0 - Failed
1001  //-----------------------------------------------------------------------------
1002  static unsigned char D4DMOUSE_DeInit_K70LCDC(void)
1003  {
1004  return D4D_FALSE;
1005  }
1006 
1007 #endif
1008 
1009 
1010 #endif //(D4D_MK_STR(D4D_LLD_LCD_HW) == d4dlcdhw_k70_lcdc_ID)
#define D4DLCDHWFB_START_ADDRESS
#define D4DLCDHWFB_BPP_BYTE
#define D4D_MemAlloc(size)
Mem Alloc eGUI definition. If not defined by user config any special user function, it used standard system function.
Definition: d4d_extsrc.h:320
#define D4DLCDHWFB_DMA_INTVECT
#define D4D_COLOR_GET_B(color)
Definition: d4d_scheme.h:438
signed long sLWord
Type definition of sLWord (signed 32-bit).
Definition: d4d_types.h:171
D4D driver - k70_lcdc hardware lcd driver function header file.
The notification that the end of screen is draw.
Definition: d4d_lldapi.h:140
#define D4D_FALSE
This is definition of boolean operation value in eGUI - FALSE.
Definition: d4d_types.h:104
#define D4D_COLOR_RGB(R, G, B)
Definition: d4d_scheme.h:434
#define D4DLCDHWFB_DMA_CHPRI
#define D4D_COLOR_RGB888(R, G, B)
The macro create the color from the color component Red/Green/Blue to 24-bit RGB888 format (the input...
Definition: d4d_scheme.h:239
#define D4DLCDHWFB_DMA_CHANNEL
#define D4D_TRUE
This is definition of boolean operation value in eGUI - TRUE.
Definition: d4d_types.h:106
D4D driver - k70_lcdc hardware lcd driver function header file.
D4D low level mouse pointer interface API structure.
Definition: d4d_lldapi.h:219
D4D Driver main header file.
D4DHW_PIN_STATE
D4D low level MCU pin state enumeration type.
Definition: d4d_lldapi.h:73
D4DLCD_FLUSH_MODE
D4D low level eGUI flush screen types enumeration.
Definition: d4d_lldapi.h:136
D4D Driver private header file.
D4DLCDHW_PINS
D4D low level MCU types definition for general LCD screen control signals.
Definition: d4d_lldapi.h:96
D4D low level frame buffer LCD interface API structure.
Definition: d4d_lldapi.h:179
#define D4D_COLOR888_GET_R(color)
The macro gets the Red component from 24-bit standard format to 8-bit component format.
Definition: d4d_scheme.h:235
#define D4D_COLOR888_GET_B(color)
The macro gets the Blue component from 24-bit standard format to 8-bit component format.
Definition: d4d_scheme.h:237
D4D low level frame buffer description structure.
Definition: d4d_lldapi.h:117
#define NULL
Type definition of null pointer.
Definition: d4d_types.h:184
#define D4D_MemFree(pMem)
Mem Free eGUI definition. If not defined by user config any special user function, it used standard system function.
Definition: d4d_extsrc.h:329
unsigned long LWord
Type definition of LWord (unsigned 32-bit).
Definition: d4d_types.h:167
#define D4D_MemCopy(pDst, pSrc, size)
Mem Copy eGUI definition. If not defined by user config any special user function, it used standard system function.
Definition: d4d_extsrc.h:338
#define D4D_COLOR888_GET_G(color)
The macro gets the Green component from 24-bit standard format to 8-bit component format...
Definition: d4d_scheme.h:236
#define D4DMOUSE_CURSOR_SIZE_Y
#define D4DMOUSE_CURSOR_BMPFORMAT
LWord D4D_INDEX
Type definition of eGUI general index variables.
Definition: d4d_types.h:206
unsigned char(* D4DLCDHWFBK70LCDC_InitPanel)(void)
const D4DLCDHWFBK70LCDC_FUNCTIONS D4D_LLD_LCD_HW_K70LCDC
#define D4DLCDHWFB_X_MAX
#define D4DMOUSE_CURSOR_SIZE_X
LWord D4D_BOOL
Type definition of eGUI boolean.
Definition: d4d_types.h:204
#define D4D_UNUSED(x)
Macro used just for notify compiler that the input parameter is not used.
Definition: d4d_base.h:504
#define D4D_COLOR_GET_G(color)
Definition: d4d_scheme.h:437
Just system define that specified the count of cursors, must be kept on end of the enumeration field...
Definition: d4d_mouse.h:128
#define D4DLCDHWFB_START_ADDRESS_2ND
unsigned long fb_start_addr
The address of frame buffer.
Definition: d4d_lldapi.h:119
D4D driver - resistive touch screen driver function header file.
D4D low level mouse pointer structure.
Definition: d4d_lldapi.h:128
LWord D4D_COLOR
Type definition of eGUI color variables.
Definition: d4d_types.h:262
#define D4DLCDHWFB_FRAMEBUFFER_SIZE
The notification of forcing flush by user code.
Definition: d4d_lldapi.h:141
#define D4D_COLOR_GET_R(color)
Definition: d4d_scheme.h:436
#define D4DLCDHWFB_Y_MAX