LPCOpen Platform for LPC18XX/43XX microcontrollers  18XX43XX
LPCOpen Platform for the NXP LPC18XX/43XX family of Microcontrollers
lcd_18xx_43xx.c
Go to the documentation of this file.
1 /*
2  * @brief LPC18xx/43xx LCD chip driver
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2012
6  * All rights reserved.
7  *
8  * @par
9  * Software that is described herein is for illustrative purposes only
10  * which provides customers with programming information regarding the
11  * LPC products. This software is supplied "AS IS" without any warranties of
12  * any kind, and NXP Semiconductors and its licensor disclaim any and
13  * all warranties, express or implied, including all implied warranties of
14  * merchantability, fitness for a particular purpose and non-infringement of
15  * intellectual property rights. NXP Semiconductors assumes no responsibility
16  * or liability for the use of the software, conveys no license or rights under any
17  * patent, copyright, mask work right, or any other intellectual property rights in
18  * or to any products. NXP Semiconductors reserves the right to make changes
19  * in the software without notification. NXP Semiconductors also makes no
20  * representation or warranty that such application will be suitable for the
21  * specified use without further testing or modification.
22  *
23  * @par
24  * Permission to use, copy, modify, and distribute this software and its
25  * documentation is hereby granted, under NXP Semiconductors' and its
26  * licensor's relevant copyrights in the software, without fee, provided that it
27  * is used in conjunction with NXP Semiconductors microcontrollers. This
28  * copyright, permission, and disclaimer notice must appear in all copies of
29  * this code.
30  */
31 
32 #include "chip.h"
33 
34 /*****************************************************************************
35  * Private types/enumerations/variables
36  ****************************************************************************/
37 
39 
40 /*****************************************************************************
41  * Public types/enumerations/variables
42  ****************************************************************************/
43 
44 /*****************************************************************************
45  * Private functions
46  ****************************************************************************/
47 
48 /*****************************************************************************
49  * Public functions
50  ****************************************************************************/
51 
52 /* Initialize the LCD controller */
53 void Chip_LCD_Init(LPC_LCD_T *pLCD, LCD_CONFIG_T *LCD_ConfigStruct)
54 {
55  uint32_t i, regValue, *pPal;
56  uint32_t pcd;
57 
58  /* Enable LCD Clock */
59  Chip_Clock_EnableOpts(CLK_MX_LCD, true, true, 1);
60 
61  /* disable the display */
62  pLCD->CTRL &= ~CLCDC_LCDCTRL_ENABLE;
63 
64  /* Setting LCD_TIMH register */
65  regValue = ( ((((LCD_ConfigStruct->PPL / 16) - 1) & 0x3F) << 2)
66  | (( (LCD_ConfigStruct->HSW - 1) & 0xFF) << 8)
67  | (( (LCD_ConfigStruct->HFP - 1) & 0xFF) << 16)
68  | (( (LCD_ConfigStruct->HBP - 1) & 0xFF) << 24) );
69  pLCD->TIMH = regValue;
70 
71  /* Setting LCD_TIMV register */
72  regValue = ((((LCD_ConfigStruct->LPP - 1) & 0x3FF) << 0)
73  | (((LCD_ConfigStruct->VSW - 1) & 0x03F) << 10)
74  | (((LCD_ConfigStruct->VFP - 1) & 0x0FF) << 16)
75  | (((LCD_ConfigStruct->VBP - 1) & 0x0FF) << 24) );
76  pLCD->TIMV = regValue;
77 
78  /* Generate the clock and signal polarity control word */
79  regValue = 0;
80  regValue = (((LCD_ConfigStruct->ACB - 1) & 0x1F) << 6);
81  regValue |= (LCD_ConfigStruct->IOE & 1) << 14;
82  regValue |= (LCD_ConfigStruct->IPC & 1) << 13;
83  regValue |= (LCD_ConfigStruct->IHS & 1) << 12;
84  regValue |= (LCD_ConfigStruct->IVS & 1) << 11;
85 
86  /* Compute clocks per line based on panel type */
87  switch (LCD_ConfigStruct->LCD) {
88  case LCD_MONO_4:
89  regValue |= ((((LCD_ConfigStruct->PPL / 4) - 1) & 0x3FF) << 16);
90  break;
91 
92  case LCD_MONO_8:
93  regValue |= ((((LCD_ConfigStruct->PPL / 8) - 1) & 0x3FF) << 16);
94  break;
95 
96  case LCD_CSTN:
97  regValue |= (((((LCD_ConfigStruct->PPL * 3) / 8) - 1) & 0x3FF) << 16);
98  break;
99 
100  case LCD_TFT:
101  default:
102  regValue |= /*1<<26 |*/ (((LCD_ConfigStruct->PPL - 1) & 0x3FF) << 16);
103  }
104 
105  /* panel clock divisor */
106  pcd = 5;// LCD_ConfigStruct->pcd; // TODO: should be calculated from LCDDCLK
107  pcd &= 0x3FF;
108  regValue |= ((pcd >> 5) << 27) | ((pcd) & 0x1F);
109  pLCD->POL = regValue;
110 
111  /* disable interrupts */
112  pLCD->INTMSK = 0;
113 
114  /* set bits per pixel */
115  regValue = LCD_ConfigStruct->BPP << 1;
116 
117  /* set color format RGB */
118  regValue |= LCD_ConfigStruct->color_format << 8;
119  regValue |= LCD_ConfigStruct->LCD << 4;
120  if (LCD_ConfigStruct->Dual == 1) {
121  regValue |= 1 << 7;
122  }
123  pLCD->CTRL = regValue;
124 
125  /* clear palette */
126  pPal = (uint32_t *) (&(pLCD->PAL));
127  for (i = 0; i < 128; i++) {
128  *pPal = 0;
129  pPal++;
130  }
131 }
132 
133 /* Shutdown the LCD controller */
135 {
137 }
138 
139 /* Configure Cursor */
140 void Chip_LCD_Cursor_Config(LPC_LCD_T *pLCD, LCD_CURSOR_SIZE_OPT_T cursor_size, bool sync)
141 {
142  LCD_Cursor_Size = cursor_size;
143  pLCD->CRSR_CFG = ((sync ? 1 : 0) << 1) | cursor_size;
144 }
145 
146 /* Write Cursor Image into Internal Cursor Image Buffer */
147 void Chip_LCD_Cursor_WriteImage(LPC_LCD_T *pLCD, uint8_t cursor_num, void *Image)
148 {
149  int i, j;
150  uint32_t *fifoptr, *crsr_ptr = (uint32_t *) Image;
151 
152  /* Check if Cursor Size was configured as 32x32 or 64x64*/
154  i = cursor_num * 64;
155  j = i + 64;
156  }
157  else {
158  i = 0;
159  j = 256;
160  }
161  fifoptr = (void *) &(pLCD->CRSR_IMG[0]);
162 
163  /* Copy Cursor Image content to FIFO */
164  for (; i < j; i++) {
165 
166  *fifoptr = *crsr_ptr;
167  crsr_ptr++;
168  fifoptr++;
169  }
170 }
171 
172 /* Load LCD Palette */
173 void Chip_LCD_LoadPalette(LPC_LCD_T *pLCD, void *palette)
174 {
175  LCD_PALETTE_ENTRY_T pal_entry = {0};
176  uint8_t i, *pal_ptr;
177  /* This function supports loading of the color palette from
178  the C file generated by the bmp2c utility. It expects the
179  palette to be passed as an array of 32-bit BGR entries having
180  the following format:
181  2:0 - Not used
182  7:3 - Blue
183  10:8 - Not used
184  15:11 - Green
185  18:16 - Not used
186  23:19 - Red
187  31:24 - Not used
188  arg = pointer to input palette table address */
189  pal_ptr = (uint8_t *) palette;
190 
191  /* 256 entry in the palette table */
192  for (i = 0; i < 256 / 2; i++) {
193  pal_entry.Bl = (*pal_ptr++) >> 3; /* blue first */
194  pal_entry.Gl = (*pal_ptr++) >> 3; /* get green */
195  pal_entry.Rl = (*pal_ptr++) >> 3; /* get red */
196  pal_ptr++; /* skip over the unused byte */
197  /* do the most significant halfword of the palette */
198  pal_entry.Bu = (*pal_ptr++) >> 3; /* blue first */
199  pal_entry.Gu = (*pal_ptr++) >> 3; /* get green */
200  pal_entry.Ru = (*pal_ptr++) >> 3; /* get red */
201  pal_ptr++; /* skip over the unused byte */
202 
203  pLCD->PAL[i] = *((uint32_t *)&pal_entry);
204  }
205 }
206