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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [Common/] [drivers/] [Atmel/] [at91lib/] [peripherals/] [lcd/] [lcd.c] - Blame information for rev 608

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 608 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
//         Headers
32
//------------------------------------------------------------------------------
33
 
34
#include "lcd.h"
35
#include <board.h>
36
#include <utility/assert.h>
37
 
38
//------------------------------------------------------------------------------
39
//         Exported functions
40
//------------------------------------------------------------------------------
41
 
42
//------------------------------------------------------------------------------
43
/// Enables the LCD controller, after waiting for the specified number of
44
/// frames.
45
/// \param frames  Number of frames before the LCD is enabled.
46
//------------------------------------------------------------------------------
47
void LCD_Enable(unsigned int frames)
48
{
49
    ASSERT((frames & 0xFFFFFF80) == 0,
50
           "LCD_Enable: Wrong frames value.\n\r");
51
    AT91C_BASE_LCDC->LCDC_PWRCON = AT91C_LCDC_PWR | (frames << 1);
52
}
53
 
54
//------------------------------------------------------------------------------
55
/// Disables the LCD controller, after waiting for the specified number of
56
/// frames.
57
/// \param frames  Number of frames before the LCD is shut down.
58
//------------------------------------------------------------------------------
59
void LCD_Disable(unsigned int frames)
60
{
61
    ASSERT((frames & 0xFFFFFF80) == 0,
62
           "LCD_Disable: Wrong frames value.\n\r");
63
    AT91C_BASE_LCDC->LCDC_PWRCON = frames << 1;
64
}
65
 
66
//------------------------------------------------------------------------------
67
/// Enables the DMA of the LCD controller.
68
//------------------------------------------------------------------------------
69
void LCD_EnableDma()
70
{
71
    AT91C_BASE_LCDC->LCDC_DMACON = AT91C_LCDC_DMAEN;
72
}
73
 
74
//------------------------------------------------------------------------------
75
/// Disables the DMA of the LCD controller.
76
//------------------------------------------------------------------------------
77
void LCD_DisableDma()
78
{
79
    AT91C_BASE_LCDC->LCDC_DMACON = 0;
80
}
81
 
82
//------------------------------------------------------------------------------
83
/// Configures the internal clock of the LCD controller given the master clock of
84
/// the system and the desired pixel clock in MHz.
85
/// \param masterClock  Master clock frequency.
86
/// \param pixelClock  Pixel clock frequency.
87
//------------------------------------------------------------------------------
88
void LCD_SetPixelClock(unsigned int masterClock, unsigned int pixelClock)
89
{
90
    AT91C_BASE_LCDC->LCDC_LCDCON1 = ((masterClock / (2 * pixelClock)) - 1) << 12;
91
}
92
 
93
//------------------------------------------------------------------------------
94
/// Sets the type of display used with the LCD controller.
95
/// \param displayType  Type of display used.
96
//------------------------------------------------------------------------------
97
void LCD_SetDisplayType(unsigned int displayType)
98
{
99
    unsigned int value;
100
 
101
    ASSERT((displayType & ~AT91C_LCDC_DISTYPE) == 0,
102
           "LCD_SetDisplayType: Wrong display type value.\n\r");
103
 
104
    value = AT91C_BASE_LCDC->LCDC_LCDCON2;
105
    value &= ~AT91C_LCDC_DISTYPE;
106
    value |= displayType;
107
    AT91C_BASE_LCDC->LCDC_LCDCON2 = value;
108
}
109
 
110
//------------------------------------------------------------------------------
111
/// Sets the scan mode used by the LCD (either single scan or double-scan).
112
/// \param scanMode  Scan mode to use.
113
//------------------------------------------------------------------------------
114
void LCD_SetScanMode(unsigned int scanMode)
115
{
116
    unsigned int value;
117
 
118
    ASSERT((scanMode & ~AT91C_LCDC_SCANMOD) == 0,
119
           "LCD_SetScanMode: Wrong scan mode value.\n\r");
120
 
121
    value = AT91C_BASE_LCDC->LCDC_LCDCON2;
122
    value &= ~AT91C_LCDC_SCANMOD;
123
    value |= scanMode;
124
    AT91C_BASE_LCDC->LCDC_LCDCON2 = value;
125
}
126
 
127
//------------------------------------------------------------------------------
128
/// Sets the number of bits per pixel used by the LCD display.
129
/// \param bitsPerPixel  Number of bits per pixel to use.
130
//------------------------------------------------------------------------------
131
void LCD_SetBitsPerPixel(unsigned int bitsPerPixel)
132
{
133
    unsigned int value;
134
 
135
    ASSERT((bitsPerPixel & ~AT91C_LCDC_PIXELSIZE) == 0,
136
           "LCD_SetScanMode: Wrong bitsPerPixel value.\n\r");
137
 
138
    value = AT91C_BASE_LCDC->LCDC_LCDCON2;
139
    value &= ~AT91C_LCDC_PIXELSIZE;
140
    value |= bitsPerPixel;
141
    AT91C_BASE_LCDC->LCDC_LCDCON2 = value;
142
}
143
 
144
//------------------------------------------------------------------------------
145
/// Sets the LCDD, LCDVSYNC, LCDHSYNC, LCDDOTCLK and LCDDEN signal polarities.
146
/// \param lcdd  LCDD signal polarity.
147
/// \param lcdvsync  LCDVSYNC signal polarity.
148
/// \param lcdhsync  LCDHSYNC signal polarity.
149
/// \param lcddotclk  LCDDOTCLK signal polarity.
150
/// \param lcdden  LCDDEN signal polarity.
151
//------------------------------------------------------------------------------
152
void LCD_SetPolarities(
153
    unsigned int lcdd,
154
    unsigned int lcdvsync,
155
    unsigned int lcdhsync,
156
    unsigned int lcddotclk,
157
    unsigned int lcdden)
158
{
159
    unsigned int value;
160
 
161
    ASSERT((lcdd & ~AT91C_LCDC_INVVD) == 0,
162
           "LCD_SetPolarities: Wrong lcdd value.\n\r");
163
    ASSERT((lcdvsync & ~AT91C_LCDC_INVFRAME) == 0,
164
           "LCD_SetPolarities: Wrong lcdvsync value.\n\r");
165
    ASSERT((lcdhsync & ~AT91C_LCDC_INVLINE) == 0,
166
           "LCD_SetPolarities: Wrong lcdhsync value.\n\r");
167
    ASSERT((lcddotclk & ~AT91C_LCDC_INVCLK) == 0,
168
           "LCD_SetPolarities: Wrong lcddotclk value.\n\r");
169
    ASSERT((lcdden & ~AT91C_LCDC_INVDVAL) == 0,
170
           "LCD_SetPolarities: Wrong lcdden value.\n\r");
171
 
172
    value = AT91C_BASE_LCDC->LCDC_LCDCON2;
173
    value &= 0xFFFFE0FF;
174
    value |= lcdd | lcdvsync | lcdhsync | lcddotclk | lcdden;
175
    AT91C_BASE_LCDC->LCDC_LCDCON2 = value;
176
}
177
 
178
//------------------------------------------------------------------------------
179
/// Sets the LCD clock mode, i.e. always active or active only during display
180
/// period.
181
/// \param clockMode  Clock mode to use.
182
//------------------------------------------------------------------------------
183
void LCD_SetClockMode(unsigned int clockMode)
184
{
185
    unsigned int value;
186
 
187
    ASSERT((clockMode & ~AT91C_LCDC_CLKMOD) == 0,
188
           "LCD_SetScanMode: Wrong scan mode value.\n\r");
189
 
190
    value = AT91C_BASE_LCDC->LCDC_LCDCON2;
191
    value &= ~AT91C_LCDC_CLKMOD;
192
    value |= clockMode;
193
    AT91C_BASE_LCDC->LCDC_LCDCON2 = value;
194
}
195
 
196
//------------------------------------------------------------------------------
197
/// Sets the format of the frame buffer memory.
198
/// \param format  Memory ordering format.
199
//------------------------------------------------------------------------------
200
void LCD_SetMemoryFormat(unsigned int format)
201
{
202
    unsigned int value;
203
 
204
    ASSERT((format & ~AT91C_LCDC_MEMOR) == 0,
205
           "LCD_SetMemoryFormat: Wrong memory format value.\n\r");
206
 
207
    value = AT91C_BASE_LCDC->LCDC_LCDCON2;
208
    value &= ~AT91C_LCDC_MEMOR;
209
    value |= format;
210
    AT91C_BASE_LCDC->LCDC_LCDCON2 = value;
211
}
212
 
213
//------------------------------------------------------------------------------
214
/// Sets the size in pixel of the LCD display.
215
/// \param width  Width in pixel of the LCD display.
216
/// \param height  Height in pixel of the LCD display.
217
//------------------------------------------------------------------------------
218
void LCD_SetSize(unsigned int width, unsigned int height)
219
{
220
    ASSERT(((width - 1) & 0xFFFFF800) == 0,
221
           "LCD_SetSize: Wrong width value.\n\r");
222
    ASSERT(((height - 1) & 0xFFFFF800) == 0,
223
           "LCD_SetSize: Wrong height value.\n\r");
224
 
225
    AT91C_BASE_LCDC->LCDC_LCDFRCFG = ((width - 1) << 21) | (height - 1);
226
}
227
 
228
//------------------------------------------------------------------------------
229
/// Sets the vertical timings of the LCD controller. Only meaningful when
230
/// using a TFT display.
231
/// \param vfp  Number of idle lines at the end of a frame.
232
/// \param vbp  Number of idle lines at the beginning of a frame.
233
/// \param vpw  Vertical synchronization pulse width in number of lines.
234
/// \param vhdly  Delay between LCDVSYNC edge and LCDHSYNC rising edge, in
235
///               LCDDOTCLK cycles.
236
//------------------------------------------------------------------------------
237
void LCD_SetVerticalTimings(
238
    unsigned int vfp,
239
    unsigned int vbp,
240
    unsigned int vpw,
241
    unsigned int vhdly)
242
{
243
    ASSERT((vfp & 0xFFFFFF00) == 0,
244
           "LCD_SetVerticalTimings: Wrong vfp value.\n\r");
245
    ASSERT((vbp & 0xFFFFFF00) == 0,
246
           "LCD_SetVerticalTimings: Wrong vbp value.\n\r");
247
    ASSERT(((vpw-1) & 0xFFFFFFC0) == 0,
248
           "LCD_SetVerticalTimings: Wrong vpw value.\n\r");
249
    ASSERT(((vhdly-1) & 0xFFFFFFF0) == 0,
250
           "LCD_SetVerticalTimings: Wrong vhdly value.\n\r");
251
 
252
    AT91C_BASE_LCDC->LCDC_TIM1 = vfp
253
                                 | (vbp << 8)
254
                                 | ((vpw-1) << 16)
255
                                 | ((vhdly-1) << 24);
256
}
257
 
258
//------------------------------------------------------------------------------
259
/// Sets the horizontal timings of the LCD controller. Meaningful for both
260
/// STN and TFT displays.
261
/// \param hbp  Number of idle LCDDOTCLK cycles at the beginning of a line.
262
/// \param hpw  Width of the LCDHSYNC pulse, in LCDDOTCLK cycles.
263
/// \param hfp  Number of idel LCDDOTCLK cycles at the end of a line.
264
//------------------------------------------------------------------------------
265
void LCD_SetHorizontalTimings(
266
    unsigned int hbp,
267
    unsigned int hpw,
268
    unsigned int hfp)
269
{
270
    ASSERT(((hbp-1) & 0xFFFFFF00) == 0,
271
           "LCD_SetHorizontalTimings: Wrong hbp value.\n\r");
272
    ASSERT(((hpw-1) & 0xFFFFFFC0) == 0,
273
           "LCD_SetHorizontalTimings: Wrong hpw value.\n\r");
274
    ASSERT(((hfp-1) & 0xFFFFFF00) == 0,
275
           "LCD_SetHorizontalTimings: Wrong hfp value.\n\r");
276
 
277
    AT91C_BASE_LCDC->LCDC_TIM2 = (hbp-1) | ((hpw-1) << 8) | ((hfp-1) << 24);
278
}
279
 
280
//------------------------------------------------------------------------------
281
/// Sets the address of the frame buffer in the LCD controller DMA. When using
282
/// dual-scan mode, this is the upper frame buffer.
283
/// \param address  Frame buffer address.
284
//------------------------------------------------------------------------------
285
void LCD_SetFrameBufferAddress(void *address)
286
{
287
    AT91C_BASE_LCDC->LCDC_BA1 = (unsigned int) address;
288
}
289
 
290
//------------------------------------------------------------------------------
291
/// Sets the size in pixels of a frame (height * width * bpp).
292
/// \param frameSize  Size of frame in pixels.
293
//------------------------------------------------------------------------------
294
void LCD_SetFrameSize(unsigned int frameSize)
295
{
296
    ASSERT((frameSize & 0xFF800000) == 0,
297
           "LCD_SetFrameSize: Wrong frameSize value.\n\r");
298
 
299
    AT91C_BASE_LCDC->LCDC_FRMCFG = frameSize | (AT91C_BASE_LCDC->LCDC_FRMCFG & 0xFF000000);
300
}
301
 
302
//------------------------------------------------------------------------------
303
/// Sets the DMA controller burst length.
304
/// \param burstLength  Desired burst length.
305
//------------------------------------------------------------------------------
306
void LCD_SetBurstLength(unsigned int burstLength)
307
{
308
    ASSERT(((burstLength-1) & 0xFFFFFF80) == 0,
309
           "LCD_SetBurstLength: Wrong burstLength value.\n\r");
310
 
311
    AT91C_BASE_LCDC->LCDC_FRMCFG &= 0x00FFFFFF;
312
    AT91C_BASE_LCDC->LCDC_FRMCFG |= ((burstLength-1) << 24);
313
 
314
    AT91C_BASE_LCDC->LCDC_FIFO = 2048 - (2 * burstLength + 3);
315
}
316
 
317
//------------------------------------------------------------------------------
318
/// Sets the prescaler value of the contrast control PWM.
319
/// \param prescaler  Desired prescaler value.
320
//------------------------------------------------------------------------------
321
void LCD_SetContrastPrescaler(unsigned int prescaler)
322
{
323
    ASSERT((prescaler & ~AT91C_LCDC_PS) == 0,
324
           "LCD_SetContrastPrescaler: Wrong prescaler value\n\r");
325
 
326
    AT91C_BASE_LCDC->LCDC_CTRSTCON &= ~AT91C_LCDC_PS;
327
    AT91C_BASE_LCDC->LCDC_CTRSTCON |= prescaler;
328
}
329
 
330
//------------------------------------------------------------------------------
331
/// Sets the polarity of the contrast PWM.
332
/// \param polarity  PWM polarity
333
//------------------------------------------------------------------------------
334
void LCD_SetContrastPolarity(unsigned int polarity)
335
{
336
    ASSERT((polarity & ~AT91C_LCDC_POL) == 0,
337
           "LCD_SetContrastPolarity: Wrong polarity value\n\r");
338
 
339
    AT91C_BASE_LCDC->LCDC_CTRSTCON &= ~AT91C_LCDC_POL;
340
    AT91C_BASE_LCDC->LCDC_CTRSTCON |= polarity;
341
}
342
 
343
//------------------------------------------------------------------------------
344
/// Sets the threshold value of the constrast PWM.
345
/// \param value  PWM threshold value.
346
//------------------------------------------------------------------------------
347
void LCD_SetContrastValue(unsigned int value)
348
{
349
    ASSERT((value & ~AT91C_LCDC_CVAL) == 0,
350
           "LCD_SetContrastValue: Wrong value.\n\r");
351
 
352
    AT91C_BASE_LCDC->LCDC_CTRSTVAL = value;
353
}
354
 
355
//------------------------------------------------------------------------------
356
/// Enables the contrast PWM generator.
357
//------------------------------------------------------------------------------
358
void LCD_EnableContrast()
359
{
360
    AT91C_BASE_LCDC->LCDC_CTRSTCON |= AT91C_LCDC_ENA_PWMGEMENABLED;
361
}
362
 

powered by: WebSVN 2.1.0

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