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 "slcdc.h"
|
35 |
|
|
#include <board.h>
|
36 |
|
|
#include <utility/assert.h>
|
37 |
|
|
|
38 |
|
|
#include <string.h>
|
39 |
|
|
|
40 |
|
|
//------------------------------------------------------------------------------
|
41 |
|
|
// Local definitions
|
42 |
|
|
//------------------------------------------------------------------------------
|
43 |
|
|
|
44 |
|
|
/// Size of SLCDC buffer in bytes.
|
45 |
|
|
#define BUFFER_SIZE 320
|
46 |
|
|
|
47 |
|
|
//------------------------------------------------------------------------------
|
48 |
|
|
// Global functions
|
49 |
|
|
//------------------------------------------------------------------------------
|
50 |
|
|
|
51 |
|
|
//------------------------------------------------------------------------------
|
52 |
|
|
/// Initializes the Segment LCD controller.
|
53 |
|
|
/// \param commons Number of commons used by the display.
|
54 |
|
|
/// \param segments Number of segments used by the display.
|
55 |
|
|
/// \param bias Bias value.
|
56 |
|
|
/// \param timeSetting Buffer timing value.
|
57 |
|
|
//------------------------------------------------------------------------------
|
58 |
|
|
void SLCDC_Configure(
|
59 |
|
|
unsigned int commons,
|
60 |
|
|
unsigned int segments,
|
61 |
|
|
unsigned int bias,
|
62 |
|
|
unsigned int timeSetting)
|
63 |
|
|
{
|
64 |
|
|
SANITY_CHECK((commons > 0) && (commons <= 10));
|
65 |
|
|
SANITY_CHECK((segments > 0) && (segments <= 40));
|
66 |
|
|
SANITY_CHECK((bias & ~AT91C_SLCDC_BIAS) == 0);
|
67 |
|
|
SANITY_CHECK((timeSetting & ~(0xF << 16)) == 0);
|
68 |
|
|
SANITY_CHECK((timeSetting >> 16) < 0x0A);
|
69 |
|
|
|
70 |
|
|
// Enable peripheral clock
|
71 |
|
|
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_SLCD;
|
72 |
|
|
AT91C_BASE_SLCDC->SLCDC_MR = (commons - 1) | ((segments - 1) << 8) | bias | timeSetting;
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
//------------------------------------------------------------------------------
|
76 |
|
|
/// Clears the SLCD display buffer.
|
77 |
|
|
//------------------------------------------------------------------------------
|
78 |
|
|
void SLCDC_Clear(void)
|
79 |
|
|
{
|
80 |
|
|
memset((void *) AT91C_BASE_SLCDC->SLCDC_MEM, 0, BUFFER_SIZE);
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
//------------------------------------------------------------------------------
|
84 |
|
|
/// Enables the SLCD controller.
|
85 |
|
|
//------------------------------------------------------------------------------
|
86 |
|
|
void SLCDC_Enable(void)
|
87 |
|
|
{
|
88 |
|
|
AT91C_BASE_SLCDC->SLCDC_CR = AT91C_SLCDC_LCDEN;
|
89 |
|
|
while (AT91C_BASE_SLCDC -> SLCDC_SR != AT91C_SLCDC_ENA);
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
//------------------------------------------------------------------------------
|
93 |
|
|
/// Disables the SLCD controller.
|
94 |
|
|
//------------------------------------------------------------------------------
|
95 |
|
|
void SLCDC_Disable(void)
|
96 |
|
|
{
|
97 |
|
|
AT91C_BASE_SLCDC->SLCDC_CR = AT91C_SLCDC_LCDDIS;
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
//------------------------------------------------------------------------------
|
101 |
|
|
/// Enables the SLCD low power mode.
|
102 |
|
|
//------------------------------------------------------------------------------
|
103 |
|
|
void SLCDC_EnableLowPowerMode(void)
|
104 |
|
|
{
|
105 |
|
|
unsigned int value;
|
106 |
|
|
|
107 |
|
|
value = AT91C_BASE_SLCDC->SLCDC_MR;
|
108 |
|
|
value &= ~AT91C_SLCDC_LPMODE;
|
109 |
|
|
value |=AT91C_SLCDC_LPMODE;
|
110 |
|
|
AT91C_BASE_SLCDC->SLCDC_MR = value;
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
//------------------------------------------------------------------------------
|
114 |
|
|
/// Disables the SLCD low power mode
|
115 |
|
|
//------------------------------------------------------------------------------
|
116 |
|
|
void SLCDC_DisableLowPowerMode(void)
|
117 |
|
|
{
|
118 |
|
|
unsigned int value;
|
119 |
|
|
|
120 |
|
|
value = AT91C_BASE_SLCDC->SLCDC_MR;
|
121 |
|
|
value &= ~AT91C_SLCDC_LPMODE;
|
122 |
|
|
AT91C_BASE_SLCDC->SLCDC_MR = value;
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
//------------------------------------------------------------------------------
|
126 |
|
|
/// Adjusts the frame frequency. Frequency = FsCLK / (prescaler * divider . NCOM)
|
127 |
|
|
/// \param prescalerValue Prescaler value
|
128 |
|
|
/// \param dividerValue Divider value
|
129 |
|
|
//------------------------------------------------------------------------------
|
130 |
|
|
void SLCDC_SetFrameFreq(unsigned int prescalerValue, unsigned int dividerValue)
|
131 |
|
|
{
|
132 |
|
|
SANITY_CHECK((prescalerValue & ~AT91C_SLCDC_PRESC) == 0);
|
133 |
|
|
SANITY_CHECK((dividerValue & (~(0x07 << 8))) == 0);
|
134 |
|
|
|
135 |
|
|
AT91C_BASE_SLCDC->SLCDC_FRR = prescalerValue | dividerValue;
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
//------------------------------------------------------------------------------
|
139 |
|
|
/// Sets the display mode (normal/force off/force on/blinking).
|
140 |
|
|
/// \param mode Display mode to be set
|
141 |
|
|
//------------------------------------------------------------------------------
|
142 |
|
|
void SLCDC_SetDisplayMode(unsigned int mode)
|
143 |
|
|
{
|
144 |
|
|
unsigned int value;
|
145 |
|
|
|
146 |
|
|
SANITY_CHECK(mode < 8);
|
147 |
|
|
|
148 |
|
|
value = AT91C_BASE_SLCDC->SLCDC_DR;
|
149 |
|
|
value &= ~AT91C_SLCDC_DISPMODE;
|
150 |
|
|
value |= mode;
|
151 |
|
|
AT91C_BASE_SLCDC->SLCDC_DR = value;
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
//------------------------------------------------------------------------------
|
155 |
|
|
/// Adjusts the display blinking frequency.
|
156 |
|
|
/// Blinking frequency = Frame Frequency / LCDBLKFREQ.
|
157 |
|
|
/// \param frequency Frequency value.
|
158 |
|
|
//------------------------------------------------------------------------------
|
159 |
|
|
void SLCDC_SetBlinkFreq(unsigned int frequency)
|
160 |
|
|
{
|
161 |
|
|
unsigned int value;
|
162 |
|
|
|
163 |
|
|
SANITY_CHECK((frequency & ~(0xFF << 8)) == 0);
|
164 |
|
|
|
165 |
|
|
value = AT91C_BASE_SLCDC->SLCDC_DR;
|
166 |
|
|
value &= ~AT91C_SLCDC_BLKFREQ;
|
167 |
|
|
value |= frequency;
|
168 |
|
|
AT91C_BASE_SLCDC->SLCDC_DR = frequency;
|
169 |
|
|
}
|
170 |
|
|
|
171 |
|
|
//------------------------------------------------------------------------------
|
172 |
|
|
/// Enables the selected SLCDC interrupt sources.
|
173 |
|
|
/// \param sources Interrupt sources to enable.
|
174 |
|
|
//------------------------------------------------------------------------------
|
175 |
|
|
void SLCDC_EnableInterrupts(unsigned int sources)
|
176 |
|
|
{
|
177 |
|
|
SANITY_CHECK((sources & 0xFFFFFFFA) == 0);
|
178 |
|
|
|
179 |
|
|
AT91C_BASE_SLCDC->SLCDC_IER = sources;
|
180 |
|
|
}
|
181 |
|
|
|
182 |
|
|
//------------------------------------------------------------------------------
|
183 |
|
|
/// Disables the selected SLCDC interrupt sources.
|
184 |
|
|
/// \param sources Interrupt sources to disable.
|
185 |
|
|
//------------------------------------------------------------------------------
|
186 |
|
|
void SLCDC_DisableInterrupts(unsigned int sources)
|
187 |
|
|
{
|
188 |
|
|
SANITY_CHECK((sources & 0xFFFFFFFA) == 0);
|
189 |
|
|
|
190 |
|
|
AT91C_BASE_SLCDC->SLCDC_IDR = sources;
|
191 |
|
|
}
|
192 |
|
|
|