OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_AT91SAM3U256_IAR/] [AT91Lib/] [components/] [hx8347/] [hx8347.c] - Blame information for rev 580

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 580 jeremybenn
/* ----------------------------------------------------------------------------
2
 *         ATMEL Microcontroller Software Support
3
 * ----------------------------------------------------------------------------
4
 * Copyright (c) 2008, Atmel Corporation
5
 *
6
 * All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions are met:
10
 *
11
 * - Redistributions of source code must retain the above copyright notice,
12
 * this list of conditions and the disclaimer below.
13
 *
14
 * Atmel's name may not be used to endorse or promote products derived from
15
 * this software without specific prior written permission.
16
 *
17
 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20
 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 * ----------------------------------------------------------------------------
28
 */
29
 
30
//------------------------------------------------------------------------------
31
/// \unit
32
///
33
/// !Purpose
34
///
35
/// HX8347 driver
36
///
37
/// !Usage
38
///
39
/// Explanation on the usage of the code made available through the header file.
40
//------------------------------------------------------------------------------
41
 
42
//------------------------------------------------------------------------------
43
//         Headers
44
//------------------------------------------------------------------------------
45
#include <board.h>
46
#include <stdio.h>
47
 
48
#ifdef BOARD_LCD_HX8347
49
 
50
#include "hx8347.h"
51
 
52
//------------------------------------------------------------------------------
53
//         Types
54
//------------------------------------------------------------------------------
55
typedef volatile unsigned short REG16;
56
 
57
//------------------------------------------------------------------------------
58
//         Definitions
59
//------------------------------------------------------------------------------
60
/// LCD index register address
61
#define LCD_IR(baseAddr) (*((REG16 *)(baseAddr)))
62
/// LCD status register address
63
#define LCD_SR(baseAddr) (*((REG16 *)(baseAddr)))
64
/// LCD data address
65
#define LCD_D(baseAddr)  (*((REG16 *)((unsigned int)(baseAddr) + BOARD_LCD_RS)))
66
 
67
/// HX8347 ID code
68
#define HX8347_HIMAXID_CODE    0x47
69
 
70
/// HX8347 LCD Registers
71
#define HX8347_R00H        0x00
72
#define HX8347_R01H        0x01
73
#define HX8347_R02H        0x02
74
#define HX8347_R03H        0x03
75
#define HX8347_R04H        0x04
76
#define HX8347_R05H        0x05
77
#define HX8347_R06H        0x06
78
#define HX8347_R07H        0x07
79
#define HX8347_R08H        0x08
80
#define HX8347_R09H        0x09
81
#define HX8347_R0AH        0x0A
82
#define HX8347_R0CH        0x0C
83
#define HX8347_R0DH        0x0D
84
#define HX8347_R0EH        0x0E
85
#define HX8347_R0FH        0x0F
86
#define HX8347_R10H        0x10
87
#define HX8347_R11H        0x11
88
#define HX8347_R12H        0x12
89
#define HX8347_R13H        0x13
90
#define HX8347_R14H        0x14
91
#define HX8347_R15H        0x15
92
#define HX8347_R16H        0x16
93
#define HX8347_R18H        0x18
94
#define HX8347_R19H        0x19
95
#define HX8347_R1AH        0x1A
96
#define HX8347_R1BH        0x1B
97
#define HX8347_R1CH        0x1C
98
#define HX8347_R1DH        0x1D
99
#define HX8347_R1EH        0x1E
100
#define HX8347_R1FH        0x1F
101
#define HX8347_R20H        0x20
102
#define HX8347_R21H        0x21
103
#define HX8347_R22H        0x22
104
#define HX8347_R23H        0x23
105
#define HX8347_R24H        0x24
106
#define HX8347_R25H        0x25
107
#define HX8347_R26H        0x26
108
#define HX8347_R27H        0x27
109
#define HX8347_R28H        0x28
110
#define HX8347_R29H        0x29
111
#define HX8347_R2AH        0x2A
112
#define HX8347_R2BH        0x2B
113
#define HX8347_R2CH        0x2C
114
#define HX8347_R2DH        0x2D
115
#define HX8347_R35H        0x35
116
#define HX8347_R36H        0x36
117
#define HX8347_R37H        0x37
118
#define HX8347_R38H        0x38
119
#define HX8347_R39H        0x39
120
#define HX8347_R3AH        0x3A
121
#define HX8347_R3BH        0x3B
122
#define HX8347_R3CH        0x3C
123
#define HX8347_R3DH        0x3D
124
#define HX8347_R3EH        0x3E
125
#define HX8347_R40H        0x40
126
#define HX8347_R41H        0x41
127
#define HX8347_R42H        0x42
128
#define HX8347_R43H        0x43
129
#define HX8347_R44H        0x44
130
#define HX8347_R45H        0x45
131
#define HX8347_R46H        0x46
132
#define HX8347_R47H        0x47
133
#define HX8347_R48H        0x48
134
#define HX8347_R49H        0x49
135
#define HX8347_R4AH        0x4A
136
#define HX8347_R4BH        0x4B
137
#define HX8347_R4CH        0x4C
138
#define HX8347_R4DH        0x4D
139
#define HX8347_R4EH        0x4E
140
#define HX8347_R4FH        0x4F
141
#define HX8347_R50H        0x50
142
#define HX8347_R51H        0x51
143
#define HX8347_R64H        0x64
144
#define HX8347_R65H        0x65
145
#define HX8347_R66H        0x66
146
#define HX8347_R67H        0x67
147
#define HX8347_R70H        0x70
148
#define HX8347_R72H        0x72
149
#define HX8347_R90H        0x90
150
#define HX8347_R91H        0x91
151
#define HX8347_R93H        0x93
152
#define HX8347_R94H        0x94
153
#define HX8347_R95H        0x95
154
 
155
//------------------------------------------------------------------------------
156
//         External functions
157
//------------------------------------------------------------------------------
158
// External delay 1 ms function
159
#include "FreeRTOS.h"
160
#include "task.h"
161
#define Delay(ms) vTaskDelay(ms/portTICK_RATE_MS)
162
 
163
//------------------------------------------------------------------------------
164
//         Global functions
165
//------------------------------------------------------------------------------
166
 
167
//------------------------------------------------------------------------------
168
/// Write data to LCD Register.
169
/// \param pLcdBase   LCD base address.
170
/// \param reg        Register address.
171
/// \param data       Data to be written.
172
//------------------------------------------------------------------------------
173
void LCD_WriteReg(void *pLcdBase, unsigned char reg, unsigned short data)
174
{
175
    LCD_IR(pLcdBase) = reg;
176
    LCD_D(pLcdBase)  = data;
177
}
178
 
179
//------------------------------------------------------------------------------
180
/// Read data from LCD Register.
181
/// \param pLcdBase   LCD base address.
182
/// \param reg        Register address.
183
/// \return data      Data to be read.
184
//------------------------------------------------------------------------------
185
unsigned short LCD_ReadReg(void *pLcdBase, unsigned char reg)
186
{
187
    LCD_IR(pLcdBase) = reg;
188
    return LCD_D(pLcdBase);
189
}
190
 
191
//------------------------------------------------------------------------------
192
/// Read LCD status Register.
193
/// \param pLcdBase   LCD base address.
194
/// \param reg        Register address.
195
/// \return data      Status Data.
196
//------------------------------------------------------------------------------
197
unsigned short LCD_ReadStatus(void *pLcdBase)
198
{
199
    return LCD_SR(pLcdBase);
200
}
201
 
202
//------------------------------------------------------------------------------
203
/// Prepare to write GRAM data.
204
/// \param pLcdBase   LCD base address.
205
//------------------------------------------------------------------------------
206
void LCD_WriteRAM_Prepare(void *pLcdBase)
207
{
208
    LCD_IR(pLcdBase) = HX8347_R22H;
209
}
210
 
211
//------------------------------------------------------------------------------
212
/// Write data to LCD GRAM.
213
/// \param pLcdBase   LCD base address.
214
/// \param color      16-bits RGB color.
215
//------------------------------------------------------------------------------
216
void LCD_WriteRAM(void *pLcdBase, unsigned short color)
217
{
218
    // Write 16-bit GRAM Reg
219
    LCD_D(pLcdBase) = color;
220
}
221
 
222
//------------------------------------------------------------------------------
223
/// Read GRAM data.
224
/// \param pLcdBase   LCD base address.
225
/// \return           16-bits RGB color.
226
//------------------------------------------------------------------------------
227
unsigned short LCD_ReadRAM(void *pLcdBase)
228
{
229
    // Read 16-bit GRAM Reg
230
    return LCD_D(pLcdBase);
231
}
232
 
233
//------------------------------------------------------------------------------
234
/// Dump register data.
235
/// \param pLcdBase   LCD base address.
236
/// \param startAddr  Register start address.
237
/// \param endAddr    Register end address.
238
//------------------------------------------------------------------------------
239
void LCD_DumpReg(void *pLcdBase, unsigned char startAddr, unsigned char endAddr)
240
{
241
    unsigned short tmp;
242
    unsigned char addr;
243
 
244
    for (addr = startAddr; addr <= endAddr; addr++) {
245
 
246
        tmp = LCD_ReadReg(pLcdBase, addr);
247
        printf("LCD.r 0x%x = 0x%x\n\r", addr, tmp);
248
    }
249
}
250
 
251
//------------------------------------------------------------------------------
252
/// Initialize the LCD controller.
253
/// \param pLcdBase   LCD base address.
254
//------------------------------------------------------------------------------
255
void LCD_Initialize(void *pLcdBase)
256
{
257
    unsigned short chipid;
258
 
259
    // Check HX8347 chipid
260
    chipid = LCD_ReadReg(pLcdBase, HX8347_R67H);
261
    if(chipid != HX8347_HIMAXID_CODE) {
262
 
263
        printf("Read HX8347 chip ID error, skip initialization.\r\n");
264
        return ;
265
    }
266
 
267
    // Start internal OSC
268
    LCD_WriteReg(pLcdBase, HX8347_R19H, 0x49); // OSCADJ=10 0000, OSD_EN=1 //60Hz
269
    LCD_WriteReg(pLcdBase, HX8347_R93H, 0x0C); // RADJ=1100
270
 
271
    // Power on flow
272
    LCD_WriteReg(pLcdBase, HX8347_R44H, 0x4D); // VCM=100 1101
273
    LCD_WriteReg(pLcdBase, HX8347_R45H, 0x11); // VDV=1 0001
274
    LCD_WriteReg(pLcdBase, HX8347_R20H, 0x40); // BT=0100
275
    LCD_WriteReg(pLcdBase, HX8347_R1DH, 0x07); // VC1=111
276
    LCD_WriteReg(pLcdBase, HX8347_R1EH, 0x00); // VC3=000
277
    LCD_WriteReg(pLcdBase, HX8347_R1FH, 0x04); // VRH=0100
278
 
279
    LCD_WriteReg(pLcdBase, HX8347_R1CH, 0x04); // AP=100
280
    LCD_WriteReg(pLcdBase, HX8347_R1BH, 0x10); // GASENB=0, PON=1, DK=0, XDK=0, DDVDH_TRI=0, STB=0
281
    Delay(50);
282
 
283
    LCD_WriteReg(pLcdBase, HX8347_R43H, 0x80); // Set VCOMG=1
284
    Delay(50);
285
 
286
    // Gamma for CMO 2.8
287
    LCD_WriteReg(pLcdBase, HX8347_R46H, 0x95);
288
    LCD_WriteReg(pLcdBase, HX8347_R47H, 0x51);
289
    LCD_WriteReg(pLcdBase, HX8347_R48H, 0x00);
290
    LCD_WriteReg(pLcdBase, HX8347_R49H, 0x36);
291
    LCD_WriteReg(pLcdBase, HX8347_R4AH, 0x11);
292
    LCD_WriteReg(pLcdBase, HX8347_R4BH, 0x66);
293
    LCD_WriteReg(pLcdBase, HX8347_R4CH, 0x14);
294
    LCD_WriteReg(pLcdBase, HX8347_R4DH, 0x77);
295
    LCD_WriteReg(pLcdBase, HX8347_R4EH, 0x13);
296
    LCD_WriteReg(pLcdBase, HX8347_R4FH, 0x4C);
297
    LCD_WriteReg(pLcdBase, HX8347_R50H, 0x46);
298
    LCD_WriteReg(pLcdBase, HX8347_R51H, 0x46);
299
 
300
    //240x320 window setting
301
    LCD_WriteReg(pLcdBase, HX8347_R02H, 0x00); // Column address start2
302
    LCD_WriteReg(pLcdBase, HX8347_R03H, 0x00); // Column address start1
303
    LCD_WriteReg(pLcdBase, HX8347_R04H, 0x00); // Column address end2
304
    LCD_WriteReg(pLcdBase, HX8347_R05H, 0xEF); // Column address end1
305
    LCD_WriteReg(pLcdBase, HX8347_R06H, 0x00); // Row address start2
306
    LCD_WriteReg(pLcdBase, HX8347_R07H, 0x00); // Row address start1
307
    LCD_WriteReg(pLcdBase, HX8347_R08H, 0x01); // Row address end2
308
    LCD_WriteReg(pLcdBase, HX8347_R09H, 0x3F); // Row address end1
309
 
310
    // Display Setting
311
    LCD_WriteReg(pLcdBase, HX8347_R01H, 0x06); // IDMON=0, INVON=1, NORON=1, PTLON=0
312
    LCD_WriteReg(pLcdBase, HX8347_R16H, 0xC8); // MY=1, MX=1, MV=0, BGR=1
313
    LCD_WriteReg(pLcdBase, HX8347_R23H, 0x95); // N_DC=1001 0101
314
    LCD_WriteReg(pLcdBase, HX8347_R24H, 0x95); // P_DC=1001 0101
315
    LCD_WriteReg(pLcdBase, HX8347_R25H, 0xFF); // I_DC=1111 1111
316
    LCD_WriteReg(pLcdBase, HX8347_R27H, 0x06); // N_BP=0000 0110
317
    LCD_WriteReg(pLcdBase, HX8347_R28H, 0x06); // N_FP=0000 0110
318
    LCD_WriteReg(pLcdBase, HX8347_R29H, 0x06); // P_BP=0000 0110
319
    LCD_WriteReg(pLcdBase, HX8347_R2AH, 0x06); // P_FP=0000 0110
320
    LCD_WriteReg(pLcdBase, HX8347_R2CH, 0x06); // I_BP=0000 0110
321
    LCD_WriteReg(pLcdBase, HX8347_R2DH, 0x06); // I_FP=0000 0110
322
    LCD_WriteReg(pLcdBase, HX8347_R3AH, 0x01); // N_RTN=0000, N_NW=001
323
    LCD_WriteReg(pLcdBase, HX8347_R3BH, 0x01); // P_RTN=0000, P_NW=001
324
    LCD_WriteReg(pLcdBase, HX8347_R3CH, 0xF0); // I_RTN=1111, I_NW=000
325
    LCD_WriteReg(pLcdBase, HX8347_R3DH, 0x00); // DIV=00
326
    LCD_WriteReg(pLcdBase, HX8347_R3EH, 0x38); // SON=38h
327
    LCD_WriteReg(pLcdBase, HX8347_R40H, 0x0F); // GDON=0Fh
328
    LCD_WriteReg(pLcdBase, HX8347_R41H, 0xF0); // GDOF=F0h
329
}
330
 
331
//------------------------------------------------------------------------------
332
/// Turn on the LCD.
333
/// \param pLcdBase   LCD base address.
334
//------------------------------------------------------------------------------
335
void LCD_On(void *pLcdBase)
336
{
337
    // Display ON Setting
338
    LCD_WriteReg(pLcdBase, HX8347_R90H, 0x7F); // SAP=0111 1111
339
    LCD_WriteReg(pLcdBase, HX8347_R26H, 0x04); // GON=0, DTE=0, D=01
340
    Delay(100);
341
    LCD_WriteReg(pLcdBase, HX8347_R26H, 0x24); // GON=1, DTE=0, D=01
342
    LCD_WriteReg(pLcdBase, HX8347_R26H, 0x2C); // GON=1, DTE=0, D=11
343
    Delay(100);
344
    LCD_WriteReg(pLcdBase, HX8347_R26H, 0x3C); // GON=1, DTE=1, D=11
345
}
346
 
347
//------------------------------------------------------------------------------
348
/// Turn off the LCD.
349
/// \param pLcdBase   LCD base address.
350
//------------------------------------------------------------------------------
351
void LCD_Off(void *pLcdBase)
352
{
353
    LCD_WriteReg(pLcdBase, HX8347_R90H, 0x00); // SAP=0000 0000
354
    LCD_WriteReg(pLcdBase, HX8347_R26H, 0x00); // GON=0, DTE=0, D=00
355
}
356
 
357
//------------------------------------------------------------------------------
358
/// Set cursor of LCD srceen.
359
/// \param pLcdBase   LCD base address.
360
/// \param x          X-coordinate of upper-left corner on LCD.
361
/// \param y          Y-coordinate of upper-left corner on LCD.
362
//------------------------------------------------------------------------------
363
void LCD_SetCursor(void *pLcdBase, unsigned short x, unsigned short y)
364
{
365
    unsigned char x1, x2, y1, y2;
366
 
367
    x1 = x & 0xff;
368
    x2 = (x & 0xff00) >>8;
369
    y1 = y & 0xff;
370
    y2 = (y & 0xff00) >>8;
371
    LCD_WriteReg(pLcdBase, HX8347_R02H, x2); // column high
372
    LCD_WriteReg(pLcdBase, HX8347_R03H, x1); // column low
373
    LCD_WriteReg(pLcdBase, HX8347_R06H, y2); // row high
374
    LCD_WriteReg(pLcdBase, HX8347_R07H, y1); // row low
375
}
376
#endif //#ifdef BOARD_LCD_HX8347

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.