1 |
582 |
jeremybenn |
//*****************************************************************************
|
2 |
|
|
// +--+
|
3 |
|
|
// | ++----+
|
4 |
|
|
// +-++ |
|
5 |
|
|
// | |
|
6 |
|
|
// +-+--+ |
|
7 |
|
|
// | +--+--+
|
8 |
|
|
// +----+ Copyright (c) 2009 Code Red Technologies Ltd.
|
9 |
|
|
//
|
10 |
|
|
// lcd_driver.c contains the lowest level access routines for the Sitronix
|
11 |
|
|
// ST7637 LCD Controller/driver used on the RDB1768 development board.
|
12 |
|
|
//
|
13 |
|
|
//
|
14 |
|
|
// Software License Agreement
|
15 |
|
|
//
|
16 |
|
|
// The software is owned by Code Red Technologies and/or its suppliers, and is
|
17 |
|
|
// protected under applicable copyright laws. All rights are reserved. Any
|
18 |
|
|
// use in violation of the foregoing restrictions may subject the user to criminal
|
19 |
|
|
// sanctions under applicable laws, as well as to civil liability for the breach
|
20 |
|
|
// of the terms and conditions of this license.
|
21 |
|
|
//
|
22 |
|
|
// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
|
23 |
|
|
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
|
24 |
|
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
|
25 |
|
|
// USE OF THIS SOFTWARE FOR COMMERCIAL DEVELOPMENT AND/OR EDUCATION IS SUBJECT
|
26 |
|
|
// TO A CURRENT END USER LICENSE AGREEMENT (COMMERCIAL OR EDUCATIONAL) WITH
|
27 |
|
|
// CODE RED TECHNOLOGIES LTD.
|
28 |
|
|
|
29 |
|
|
#include "NXP/LPC17xx/LPC17xx.h"
|
30 |
|
|
#include "lcd_driver.h"
|
31 |
|
|
#include "lcd_commands.h"
|
32 |
|
|
|
33 |
|
|
// Bits within GPIO port 2 used for LCD driver
|
34 |
|
|
#define LCD_CSB_PIN (1<<13)
|
35 |
|
|
#define LCD_A0_PIN (1<<8)
|
36 |
|
|
#define LCD_WR_PIN (1<<11)
|
37 |
|
|
#define LCD_RD_PIN (1<<12)
|
38 |
|
|
#define LCD_DATA_PIN 0xff
|
39 |
|
|
|
40 |
|
|
// Bit within GPIO port 3 used for LCD driver
|
41 |
|
|
#define LCD_RESB_PIN (1<<25)
|
42 |
|
|
|
43 |
|
|
// Bits to configure as outputs for driving LCD
|
44 |
|
|
#define LCD_PORT2_DIRECTIONS (LCD_CSB_PIN | LCD_A0_PIN | LCD_WR_PIN | LCD_RD_PIN | LCD_DATA_PIN)
|
45 |
|
|
#define LCD_PORT3_DIRECTIONS (LCD_RESB_PIN)
|
46 |
|
|
|
47 |
|
|
// Define names for GPIO port 2 and 3 registers to better indicate in code
|
48 |
|
|
// the operation being carried out on the LCD driver hardware.
|
49 |
|
|
#define LCD_DATA_CLR FIO2CLR
|
50 |
|
|
#define LCD_DATA_SET FIO2SET
|
51 |
|
|
|
52 |
|
|
#define LCD_CSB_CLR FIO2CLR
|
53 |
|
|
#define LCD_CSB_SET FIO2SET
|
54 |
|
|
|
55 |
|
|
#define LCD_RESB_CLR FIO3CLR
|
56 |
|
|
#define LCD_RESB_SET FIO3SET
|
57 |
|
|
|
58 |
|
|
#define LCD_A0_CLR FIO2CLR
|
59 |
|
|
#define LCD_A0_SET FIO2SET
|
60 |
|
|
|
61 |
|
|
#define LCD_WR_CLR FIO2CLR
|
62 |
|
|
#define LCD_WR_SET FIO2SET
|
63 |
|
|
|
64 |
|
|
#define LCD_RD_CLR FIO2CLR
|
65 |
|
|
#define LCD_RD_SET FIO2SET
|
66 |
|
|
|
67 |
|
|
// Routine to write data to LCD driver. Normally called in combination
|
68 |
|
|
// with LCDdriver_WriteCom() routine
|
69 |
|
|
void LCDdriver_WriteData(unsigned char LCD_Data)
|
70 |
|
|
{
|
71 |
|
|
LCD_DATA_CLR = LCD_DATA_PIN;
|
72 |
|
|
LCD_DATA_SET = LCD_Data;
|
73 |
|
|
LCD_CSB_CLR = LCD_CSB_PIN;
|
74 |
|
|
LCD_WR_CLR = LCD_WR_PIN;
|
75 |
|
|
LCD_WR_SET = LCD_WR_PIN;
|
76 |
|
|
LCD_CSB_SET = LCD_CSB_PIN;
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
// Routine to configure set LCD driver to accept particular command.
|
80 |
|
|
// A call to this routine will normally be followed by a call
|
81 |
|
|
// to LCDdriver_WriteData() to transfer appropriate parameters to driver.
|
82 |
|
|
void LCDdriver_WriteCom(unsigned char LCD_Command)
|
83 |
|
|
{
|
84 |
|
|
LCD_DATA_CLR = LCD_DATA_PIN;
|
85 |
|
|
LCD_DATA_SET = LCD_Command;
|
86 |
|
|
LCD_A0_CLR = LCD_A0_PIN;
|
87 |
|
|
LCD_CSB_CLR = LCD_CSB_PIN;
|
88 |
|
|
LCD_WR_CLR = LCD_WR_PIN;
|
89 |
|
|
LCD_WR_SET = LCD_WR_PIN;
|
90 |
|
|
LCD_CSB_SET = LCD_CSB_PIN;
|
91 |
|
|
LCD_A0_SET = LCD_A0_PIN;
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
// Function to add short delays in writing things to the LCD.
|
95 |
|
|
void ms_delay(int n)
|
96 |
|
|
{
|
97 |
|
|
volatile int d;
|
98 |
|
|
for (d=0; d<n*3000; d++){}
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
// Initialize GPIO connection to the LCD driver
|
103 |
|
|
void LCDdriver_ConfigGPIOtoLCD(void)
|
104 |
|
|
{
|
105 |
|
|
// set direction to outputs
|
106 |
|
|
FIO2DIR |= LCD_PORT2_DIRECTIONS;
|
107 |
|
|
FIO3DIR |= LCD_PORT3_DIRECTIONS;
|
108 |
|
|
|
109 |
|
|
// Set GPIO outputs connected to LCD to default values
|
110 |
|
|
LCD_CSB_SET = LCD_CSB_PIN;
|
111 |
|
|
LCD_A0_SET = LCD_A0_PIN;
|
112 |
|
|
LCD_WR_SET = LCD_WR_PIN;
|
113 |
|
|
LCD_RD_SET = LCD_RD_PIN;
|
114 |
|
|
LCD_RESB_SET = LCD_RESB_PIN;
|
115 |
|
|
LCD_DATA_CLR = 0xff; // data bus to zero
|
116 |
|
|
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
// Initialisation routine to set up LCD
|
121 |
|
|
void LCDdriver_initialisation(void)
|
122 |
|
|
{
|
123 |
|
|
int i; // temp loop variable
|
124 |
|
|
|
125 |
|
|
LCDdriver_ConfigGPIOtoLCD(); // Initialize the GPIO for the display
|
126 |
|
|
|
127 |
|
|
LCDdriver_WriteCom(DD_SWRESET); // SW reset
|
128 |
|
|
ms_delay(120); // Small delay
|
129 |
|
|
|
130 |
|
|
LCDdriver_WriteCom(DD_AUTOLOADSET); // disable auto loading of mask rom data
|
131 |
|
|
LCDdriver_WriteData(0xBF);
|
132 |
|
|
|
133 |
|
|
LCDdriver_WriteCom(DD_EPCTIN); // OTP control mode=read
|
134 |
|
|
LCDdriver_WriteData(0x00);
|
135 |
|
|
ms_delay(10); // Small delay
|
136 |
|
|
|
137 |
|
|
LCDdriver_WriteCom(DD_EPREAD); // Start the OTP read.
|
138 |
|
|
ms_delay(20); // Small delay
|
139 |
|
|
|
140 |
|
|
LCDdriver_WriteCom(DD_EPCTOUT); // Cancel the OTP read (20ms should have been enough)
|
141 |
|
|
|
142 |
|
|
LCDdriver_WriteCom(DD_DISPOFF); // display off
|
143 |
|
|
|
144 |
|
|
LCDdriver_WriteCom(DD_SLPOUT); // Exit sleep mode.
|
145 |
|
|
ms_delay(50); // Small delay
|
146 |
|
|
|
147 |
|
|
LCDdriver_WriteCom(DD_VopSet); // set LCD operating voltage to 14V.
|
148 |
|
|
LCDdriver_WriteData(0x04);
|
149 |
|
|
LCDdriver_WriteData(0x01);
|
150 |
|
|
|
151 |
|
|
LCDdriver_WriteCom(DD_BiasSel); // Select an LCD bias voltage ratio of 1/12.
|
152 |
|
|
LCDdriver_WriteData(0x00);
|
153 |
|
|
|
154 |
|
|
LCDdriver_WriteCom(DD_BstMbpXSel); // x8 booster circuit on
|
155 |
|
|
LCDdriver_WriteData(0x07);
|
156 |
|
|
|
157 |
|
|
LCDdriver_WriteCom(DD_ColScanDir); // Invert the column scan direction for the panel.
|
158 |
|
|
LCDdriver_WriteData(0xC0);
|
159 |
|
|
|
160 |
|
|
LCDdriver_WriteCom(DD_COLORMOD); // 16bpp, 5-6-5 data input mode.
|
161 |
|
|
LCDdriver_WriteData(0x05);
|
162 |
|
|
|
163 |
|
|
LCDdriver_WriteCom(DD_MADCTR); // mem scan direction
|
164 |
|
|
LCDdriver_WriteData(0x00);
|
165 |
|
|
|
166 |
|
|
LCDdriver_WriteCom(DD_DISPON); // display on
|
167 |
|
|
|
168 |
|
|
// Now Clear the Screen
|
169 |
|
|
LCDdriver_WriteCom(DD_CASET);
|
170 |
|
|
LCDdriver_WriteData(0x00);
|
171 |
|
|
LCDdriver_WriteData(0x7F);
|
172 |
|
|
|
173 |
|
|
LCDdriver_WriteCom(DD_RASET);
|
174 |
|
|
LCDdriver_WriteData(0x01);
|
175 |
|
|
LCDdriver_WriteData(0x80);
|
176 |
|
|
|
177 |
|
|
LCDdriver_WriteCom(DD_RAMWR);
|
178 |
|
|
for(i = 0; i < (128 * 128); i++)
|
179 |
|
|
{
|
180 |
|
|
LCDdriver_WriteData(0x00);
|
181 |
|
|
LCDdriver_WriteData(0x00);
|
182 |
|
|
}
|
183 |
|
|
|
184 |
|
|
LCDdriver_WriteCom(DD_NORON); // normal operation mode
|
185 |
|
|
}
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
|