1 |
581 |
jeremybenn |
//*****************************************************************************
|
2 |
|
|
//
|
3 |
|
|
// osram96x16.c - Driver for the OSRAM 96x16 graphical OLED display.
|
4 |
|
|
//
|
5 |
|
|
// Copyright (c) 2006-2007 Luminary Micro, Inc. All rights reserved.
|
6 |
|
|
//
|
7 |
|
|
// Software License Agreement
|
8 |
|
|
//
|
9 |
|
|
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
|
10 |
|
|
// exclusively on LMI's microcontroller products.
|
11 |
|
|
//
|
12 |
|
|
// The software is owned by LMI and/or its suppliers, and is protected under
|
13 |
|
|
// applicable copyright laws. All rights are reserved. Any use in violation
|
14 |
|
|
// of the foregoing restrictions may subject the user to criminal sanctions
|
15 |
|
|
// under applicable laws, as well as to civil liability for the breach of the
|
16 |
|
|
// terms and conditions of this license.
|
17 |
|
|
//
|
18 |
|
|
// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
|
19 |
|
|
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
|
20 |
|
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
|
21 |
|
|
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
|
22 |
|
|
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
|
23 |
|
|
//
|
24 |
|
|
// This is part of revision 1049 of the Stellaris Driver Library.
|
25 |
|
|
//
|
26 |
|
|
//*****************************************************************************
|
27 |
|
|
|
28 |
|
|
//*****************************************************************************
|
29 |
|
|
//
|
30 |
|
|
//! \addtogroup ev_lm3s811_api
|
31 |
|
|
//! @{
|
32 |
|
|
//
|
33 |
|
|
//*****************************************************************************
|
34 |
|
|
|
35 |
|
|
#include "hw_i2c.h"
|
36 |
|
|
#include "hw_memmap.h"
|
37 |
|
|
#include "hw_sysctl.h"
|
38 |
|
|
#include "hw_types.h"
|
39 |
|
|
#include "debug.h"
|
40 |
|
|
#include "gpio.h"
|
41 |
|
|
#include "i2c.h"
|
42 |
|
|
#include "sysctl.h"
|
43 |
|
|
#include "osram96x16.h"
|
44 |
|
|
|
45 |
|
|
//*****************************************************************************
|
46 |
|
|
//
|
47 |
|
|
// The I2C slave address of the SSD0303 controller on the OLED display.
|
48 |
|
|
//
|
49 |
|
|
//*****************************************************************************
|
50 |
|
|
#define SSD0303_ADDR 0x3d
|
51 |
|
|
|
52 |
|
|
//*****************************************************************************
|
53 |
|
|
//
|
54 |
|
|
// A 5x7 font (in a 6x8 cell, where the sixth column is omitted from this
|
55 |
|
|
// table) for displaying text on the OLED display. The data is organized as
|
56 |
|
|
// bytes from the left column to the right column, with each byte containing
|
57 |
|
|
// the top row in the LSB and the bottom row in the MSB.
|
58 |
|
|
//
|
59 |
|
|
//*****************************************************************************
|
60 |
|
|
static const unsigned char g_pucFont[95][5] =
|
61 |
|
|
{
|
62 |
|
|
{ 0x00, 0x00, 0x00, 0x00, 0x00 }, // " "
|
63 |
|
|
{ 0x00, 0x00, 0x4f, 0x00, 0x00 }, // !
|
64 |
|
|
{ 0x00, 0x07, 0x00, 0x07, 0x00 }, // "
|
65 |
|
|
{ 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #
|
66 |
|
|
{ 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $
|
67 |
|
|
{ 0x23, 0x13, 0x08, 0x64, 0x62 }, // %
|
68 |
|
|
{ 0x36, 0x49, 0x55, 0x22, 0x50 }, // &
|
69 |
|
|
{ 0x00, 0x05, 0x03, 0x00, 0x00 }, // '
|
70 |
|
|
{ 0x00, 0x1c, 0x22, 0x41, 0x00 }, // (
|
71 |
|
|
{ 0x00, 0x41, 0x22, 0x1c, 0x00 }, // )
|
72 |
|
|
{ 0x14, 0x08, 0x3e, 0x08, 0x14 }, // *
|
73 |
|
|
{ 0x08, 0x08, 0x3e, 0x08, 0x08 }, // +
|
74 |
|
|
{ 0x00, 0x50, 0x30, 0x00, 0x00 }, // ,
|
75 |
|
|
{ 0x08, 0x08, 0x08, 0x08, 0x08 }, // -
|
76 |
|
|
{ 0x00, 0x60, 0x60, 0x00, 0x00 }, // .
|
77 |
|
|
{ 0x20, 0x10, 0x08, 0x04, 0x02 }, // /
|
78 |
|
|
{ 0x3e, 0x51, 0x49, 0x45, 0x3e }, // 0
|
79 |
|
|
{ 0x00, 0x42, 0x7f, 0x40, 0x00 }, // 1
|
80 |
|
|
{ 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2
|
81 |
|
|
{ 0x21, 0x41, 0x45, 0x4b, 0x31 }, // 3
|
82 |
|
|
{ 0x18, 0x14, 0x12, 0x7f, 0x10 }, // 4
|
83 |
|
|
{ 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5
|
84 |
|
|
{ 0x3c, 0x4a, 0x49, 0x49, 0x30 }, // 6
|
85 |
|
|
{ 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7
|
86 |
|
|
{ 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8
|
87 |
|
|
{ 0x06, 0x49, 0x49, 0x29, 0x1e }, // 9
|
88 |
|
|
{ 0x00, 0x36, 0x36, 0x00, 0x00 }, // :
|
89 |
|
|
{ 0x00, 0x56, 0x36, 0x00, 0x00 }, // ;
|
90 |
|
|
{ 0x08, 0x14, 0x22, 0x41, 0x00 }, // <
|
91 |
|
|
{ 0x14, 0x14, 0x14, 0x14, 0x14 }, // =
|
92 |
|
|
{ 0x00, 0x41, 0x22, 0x14, 0x08 }, // >
|
93 |
|
|
{ 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?
|
94 |
|
|
{ 0x32, 0x49, 0x79, 0x41, 0x3e }, // @
|
95 |
|
|
{ 0x7e, 0x11, 0x11, 0x11, 0x7e }, // A
|
96 |
|
|
{ 0x7f, 0x49, 0x49, 0x49, 0x36 }, // B
|
97 |
|
|
{ 0x3e, 0x41, 0x41, 0x41, 0x22 }, // C
|
98 |
|
|
{ 0x7f, 0x41, 0x41, 0x22, 0x1c }, // D
|
99 |
|
|
{ 0x7f, 0x49, 0x49, 0x49, 0x41 }, // E
|
100 |
|
|
{ 0x7f, 0x09, 0x09, 0x09, 0x01 }, // F
|
101 |
|
|
{ 0x3e, 0x41, 0x49, 0x49, 0x7a }, // G
|
102 |
|
|
{ 0x7f, 0x08, 0x08, 0x08, 0x7f }, // H
|
103 |
|
|
{ 0x00, 0x41, 0x7f, 0x41, 0x00 }, // I
|
104 |
|
|
{ 0x20, 0x40, 0x41, 0x3f, 0x01 }, // J
|
105 |
|
|
{ 0x7f, 0x08, 0x14, 0x22, 0x41 }, // K
|
106 |
|
|
{ 0x7f, 0x40, 0x40, 0x40, 0x40 }, // L
|
107 |
|
|
{ 0x7f, 0x02, 0x0c, 0x02, 0x7f }, // M
|
108 |
|
|
{ 0x7f, 0x04, 0x08, 0x10, 0x7f }, // N
|
109 |
|
|
{ 0x3e, 0x41, 0x41, 0x41, 0x3e }, // O
|
110 |
|
|
{ 0x7f, 0x09, 0x09, 0x09, 0x06 }, // P
|
111 |
|
|
{ 0x3e, 0x41, 0x51, 0x21, 0x5e }, // Q
|
112 |
|
|
{ 0x7f, 0x09, 0x19, 0x29, 0x46 }, // R
|
113 |
|
|
{ 0x46, 0x49, 0x49, 0x49, 0x31 }, // S
|
114 |
|
|
{ 0x01, 0x01, 0x7f, 0x01, 0x01 }, // T
|
115 |
|
|
{ 0x3f, 0x40, 0x40, 0x40, 0x3f }, // U
|
116 |
|
|
{ 0x1f, 0x20, 0x40, 0x20, 0x1f }, // V
|
117 |
|
|
{ 0x3f, 0x40, 0x38, 0x40, 0x3f }, // W
|
118 |
|
|
{ 0x63, 0x14, 0x08, 0x14, 0x63 }, // X
|
119 |
|
|
{ 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y
|
120 |
|
|
{ 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z
|
121 |
|
|
{ 0x00, 0x7f, 0x41, 0x41, 0x00 }, // [
|
122 |
|
|
{ 0x02, 0x04, 0x08, 0x10, 0x20 }, // "\"
|
123 |
|
|
{ 0x00, 0x41, 0x41, 0x7f, 0x00 }, // ]
|
124 |
|
|
{ 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^
|
125 |
|
|
{ 0x40, 0x40, 0x40, 0x40, 0x40 }, // _
|
126 |
|
|
{ 0x00, 0x01, 0x02, 0x04, 0x00 }, // `
|
127 |
|
|
{ 0x20, 0x54, 0x54, 0x54, 0x78 }, // a
|
128 |
|
|
{ 0x7f, 0x48, 0x44, 0x44, 0x38 }, // b
|
129 |
|
|
{ 0x38, 0x44, 0x44, 0x44, 0x20 }, // c
|
130 |
|
|
{ 0x38, 0x44, 0x44, 0x48, 0x7f }, // d
|
131 |
|
|
{ 0x38, 0x54, 0x54, 0x54, 0x18 }, // e
|
132 |
|
|
{ 0x08, 0x7e, 0x09, 0x01, 0x02 }, // f
|
133 |
|
|
{ 0x0c, 0x52, 0x52, 0x52, 0x3e }, // g
|
134 |
|
|
{ 0x7f, 0x08, 0x04, 0x04, 0x78 }, // h
|
135 |
|
|
{ 0x00, 0x44, 0x7d, 0x40, 0x00 }, // i
|
136 |
|
|
{ 0x20, 0x40, 0x44, 0x3d, 0x00 }, // j
|
137 |
|
|
{ 0x7f, 0x10, 0x28, 0x44, 0x00 }, // k
|
138 |
|
|
{ 0x00, 0x41, 0x7f, 0x40, 0x00 }, // l
|
139 |
|
|
{ 0x7c, 0x04, 0x18, 0x04, 0x78 }, // m
|
140 |
|
|
{ 0x7c, 0x08, 0x04, 0x04, 0x78 }, // n
|
141 |
|
|
{ 0x38, 0x44, 0x44, 0x44, 0x38 }, // o
|
142 |
|
|
{ 0x7c, 0x14, 0x14, 0x14, 0x08 }, // p
|
143 |
|
|
{ 0x08, 0x14, 0x14, 0x18, 0x7c }, // q
|
144 |
|
|
{ 0x7c, 0x08, 0x04, 0x04, 0x08 }, // r
|
145 |
|
|
{ 0x48, 0x54, 0x54, 0x54, 0x20 }, // s
|
146 |
|
|
{ 0x04, 0x3f, 0x44, 0x40, 0x20 }, // t
|
147 |
|
|
{ 0x3c, 0x40, 0x40, 0x20, 0x7c }, // u
|
148 |
|
|
{ 0x1c, 0x20, 0x40, 0x20, 0x1c }, // v
|
149 |
|
|
{ 0x3c, 0x40, 0x30, 0x40, 0x3c }, // w
|
150 |
|
|
{ 0x44, 0x28, 0x10, 0x28, 0x44 }, // x
|
151 |
|
|
{ 0x0c, 0x50, 0x50, 0x50, 0x3c }, // y
|
152 |
|
|
{ 0x44, 0x64, 0x54, 0x4c, 0x44 }, // z
|
153 |
|
|
{ 0x00, 0x08, 0x36, 0x41, 0x00 }, // {
|
154 |
|
|
{ 0x00, 0x00, 0x7f, 0x00, 0x00 }, // |
|
155 |
|
|
{ 0x00, 0x41, 0x36, 0x08, 0x00 }, // }
|
156 |
|
|
{ 0x02, 0x01, 0x02, 0x04, 0x02 }, // ~
|
157 |
|
|
};
|
158 |
|
|
|
159 |
|
|
//*****************************************************************************
|
160 |
|
|
//
|
161 |
|
|
// The sequence of commands used to initialize the SSD0303 controller. Each
|
162 |
|
|
// command is described as follows: there is a byte specifying the number of
|
163 |
|
|
// bytes in the I2C transfer, followed by that many bytes of command data.
|
164 |
|
|
//
|
165 |
|
|
//*****************************************************************************
|
166 |
|
|
static const unsigned char g_pucOSRAMInit[] =
|
167 |
|
|
{
|
168 |
|
|
//
|
169 |
|
|
// Turn off the panel
|
170 |
|
|
//
|
171 |
|
|
0x04, 0x80, 0xae, 0x80, 0xe3,
|
172 |
|
|
|
173 |
|
|
//
|
174 |
|
|
// Set lower column address
|
175 |
|
|
//
|
176 |
|
|
0x04, 0x80, 0x04, 0x80, 0xe3,
|
177 |
|
|
|
178 |
|
|
//
|
179 |
|
|
// Set higher column address
|
180 |
|
|
//
|
181 |
|
|
0x04, 0x80, 0x12, 0x80, 0xe3,
|
182 |
|
|
|
183 |
|
|
//
|
184 |
|
|
// Set contrast control register
|
185 |
|
|
//
|
186 |
|
|
0x06, 0x80, 0x81, 0x80, 0x2b, 0x80, 0xe3,
|
187 |
|
|
|
188 |
|
|
//
|
189 |
|
|
// Set segment re-map
|
190 |
|
|
//
|
191 |
|
|
0x04, 0x80, 0xa1, 0x80, 0xe3,
|
192 |
|
|
|
193 |
|
|
//
|
194 |
|
|
// Set display start line
|
195 |
|
|
//
|
196 |
|
|
0x04, 0x80, 0x40, 0x80, 0xe3,
|
197 |
|
|
|
198 |
|
|
//
|
199 |
|
|
// Set display offset
|
200 |
|
|
//
|
201 |
|
|
0x06, 0x80, 0xd3, 0x80, 0x00, 0x80, 0xe3,
|
202 |
|
|
|
203 |
|
|
//
|
204 |
|
|
// Set multiplex ratio
|
205 |
|
|
//
|
206 |
|
|
0x06, 0x80, 0xa8, 0x80, 0x0f, 0x80, 0xe3,
|
207 |
|
|
|
208 |
|
|
//
|
209 |
|
|
// Set the display to normal mode
|
210 |
|
|
//
|
211 |
|
|
0x04, 0x80, 0xa4, 0x80, 0xe3,
|
212 |
|
|
|
213 |
|
|
//
|
214 |
|
|
// Non-inverted display
|
215 |
|
|
//
|
216 |
|
|
0x04, 0x80, 0xa6, 0x80, 0xe3,
|
217 |
|
|
|
218 |
|
|
//
|
219 |
|
|
// Set the page address
|
220 |
|
|
//
|
221 |
|
|
0x04, 0x80, 0xb0, 0x80, 0xe3,
|
222 |
|
|
|
223 |
|
|
//
|
224 |
|
|
// Set COM output scan direction
|
225 |
|
|
//
|
226 |
|
|
0x04, 0x80, 0xc8, 0x80, 0xe3,
|
227 |
|
|
|
228 |
|
|
//
|
229 |
|
|
// Set display clock divide ratio/oscillator frequency
|
230 |
|
|
//
|
231 |
|
|
0x06, 0x80, 0xd5, 0x80, 0x72, 0x80, 0xe3,
|
232 |
|
|
|
233 |
|
|
//
|
234 |
|
|
// Enable mono mode
|
235 |
|
|
//
|
236 |
|
|
0x06, 0x80, 0xd8, 0x80, 0x00, 0x80, 0xe3,
|
237 |
|
|
|
238 |
|
|
//
|
239 |
|
|
// Set pre-charge period
|
240 |
|
|
//
|
241 |
|
|
0x06, 0x80, 0xd9, 0x80, 0x22, 0x80, 0xe3,
|
242 |
|
|
|
243 |
|
|
//
|
244 |
|
|
// Set COM pins hardware configuration
|
245 |
|
|
//
|
246 |
|
|
0x06, 0x80, 0xda, 0x80, 0x12, 0x80, 0xe3,
|
247 |
|
|
|
248 |
|
|
//
|
249 |
|
|
// Set VCOM deslect level
|
250 |
|
|
//
|
251 |
|
|
0x06, 0x80, 0xdb, 0x80, 0x0f, 0x80, 0xe3,
|
252 |
|
|
|
253 |
|
|
//
|
254 |
|
|
// Set DC-DC on
|
255 |
|
|
//
|
256 |
|
|
0x06, 0x80, 0xad, 0x80, 0x8b, 0x80, 0xe3,
|
257 |
|
|
|
258 |
|
|
//
|
259 |
|
|
// Turn on the panel
|
260 |
|
|
//
|
261 |
|
|
0x04, 0x80, 0xaf, 0x80, 0xe3,
|
262 |
|
|
};
|
263 |
|
|
|
264 |
|
|
//*****************************************************************************
|
265 |
|
|
//
|
266 |
|
|
// The inter-byte delay required by the SSD0303 OLED controller.
|
267 |
|
|
//
|
268 |
|
|
//*****************************************************************************
|
269 |
|
|
static unsigned long g_ulDelay;
|
270 |
|
|
|
271 |
|
|
//*****************************************************************************
|
272 |
|
|
//
|
273 |
|
|
//! \internal
|
274 |
|
|
//!
|
275 |
|
|
//! Provide a small delay.
|
276 |
|
|
//!
|
277 |
|
|
//! \param ulCount is the number of delay loop iterations to perform.
|
278 |
|
|
//!
|
279 |
|
|
//! Since the SSD0303 controller needs a delay between bytes written to it over
|
280 |
|
|
//! the I2C bus, this function provides a means of generating that delay. It
|
281 |
|
|
//! is written in assembly to keep the delay consistent across tool chains,
|
282 |
|
|
//! avoiding the need to tune the delay based on the tool chain in use.
|
283 |
|
|
//!
|
284 |
|
|
//! \return None.
|
285 |
|
|
//
|
286 |
|
|
//*****************************************************************************
|
287 |
|
|
#if defined(ewarm)
|
288 |
|
|
static void
|
289 |
|
|
OSRAMDelay(unsigned long ulCount)
|
290 |
|
|
{
|
291 |
|
|
__asm(" subs r0, #1\n"
|
292 |
|
|
" bne OSRAMDelay\n"
|
293 |
|
|
" bx lr");
|
294 |
|
|
}
|
295 |
|
|
#endif
|
296 |
|
|
#if defined(gcc)
|
297 |
|
|
static void __attribute__((naked))
|
298 |
|
|
OSRAMDelay(unsigned long ulCount)
|
299 |
|
|
{
|
300 |
|
|
__asm(" subs r0, #1\n"
|
301 |
|
|
" bne OSRAMDelay\n"
|
302 |
|
|
" bx lr");
|
303 |
|
|
}
|
304 |
|
|
#endif
|
305 |
|
|
#if defined(rvmdk) || defined(__ARMCC_VERSION)
|
306 |
|
|
__asm void
|
307 |
|
|
OSRAMDelay(unsigned long ulCount)
|
308 |
|
|
{
|
309 |
|
|
subs r0, #1;
|
310 |
|
|
bne OSRAMDelay;
|
311 |
|
|
bx lr;
|
312 |
|
|
}
|
313 |
|
|
#endif
|
314 |
|
|
|
315 |
|
|
//*****************************************************************************
|
316 |
|
|
//
|
317 |
|
|
//! \internal
|
318 |
|
|
//!
|
319 |
|
|
//! Start a transfer to the SSD0303 controller.
|
320 |
|
|
//!
|
321 |
|
|
//! \param ucChar is the first byte to be written to the controller.
|
322 |
|
|
//!
|
323 |
|
|
//! This function will start a transfer to the SSD0303 controller via the I2C
|
324 |
|
|
//! bus.
|
325 |
|
|
//!
|
326 |
|
|
//! The data is written in a polled fashion; this function will not return
|
327 |
|
|
//! until the byte has been written to the controller.
|
328 |
|
|
//!
|
329 |
|
|
//! \return None.
|
330 |
|
|
//
|
331 |
|
|
//*****************************************************************************
|
332 |
|
|
static void
|
333 |
|
|
OSRAMWriteFirst(unsigned char ucChar)
|
334 |
|
|
{
|
335 |
|
|
//
|
336 |
|
|
// Set the slave address.
|
337 |
|
|
//
|
338 |
|
|
I2CMasterSlaveAddrSet(I2C_MASTER_BASE, SSD0303_ADDR, false);
|
339 |
|
|
|
340 |
|
|
//
|
341 |
|
|
// Write the first byte to the controller.
|
342 |
|
|
//
|
343 |
|
|
I2CMasterDataPut(I2C_MASTER_BASE, ucChar);
|
344 |
|
|
|
345 |
|
|
//
|
346 |
|
|
// Start the transfer.
|
347 |
|
|
//
|
348 |
|
|
I2CMasterControl(I2C_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
|
349 |
|
|
}
|
350 |
|
|
|
351 |
|
|
//*****************************************************************************
|
352 |
|
|
//
|
353 |
|
|
//! \internal
|
354 |
|
|
//!
|
355 |
|
|
//! Write a byte to the SSD0303 controller.
|
356 |
|
|
//!
|
357 |
|
|
//! \param ucChar is the byte to be transmitted to the controller.
|
358 |
|
|
//!
|
359 |
|
|
//! This function continues a transfer to the SSD0303 controller by writing
|
360 |
|
|
//! another byte over the I2C bus. This must only be called after calling
|
361 |
|
|
//! OSRAMWriteFirst(), but before calling OSRAMWriteFinal().
|
362 |
|
|
//!
|
363 |
|
|
//! The data is written in a polled faashion; this function will not return
|
364 |
|
|
//! until the byte has been written to the controller.
|
365 |
|
|
//!
|
366 |
|
|
//! \return None.
|
367 |
|
|
//
|
368 |
|
|
//*****************************************************************************
|
369 |
|
|
static void
|
370 |
|
|
OSRAMWriteByte(unsigned char ucChar)
|
371 |
|
|
{
|
372 |
|
|
//
|
373 |
|
|
// Wait until the current byte has been transferred.
|
374 |
|
|
//
|
375 |
|
|
while(I2CMasterIntStatus(I2C_MASTER_BASE, false) == 0)
|
376 |
|
|
{
|
377 |
|
|
}
|
378 |
|
|
|
379 |
|
|
//
|
380 |
|
|
// Provide the required inter-byte delay.
|
381 |
|
|
//
|
382 |
|
|
OSRAMDelay(g_ulDelay);
|
383 |
|
|
|
384 |
|
|
//
|
385 |
|
|
// Write the next byte to the controller.
|
386 |
|
|
//
|
387 |
|
|
I2CMasterDataPut(I2C_MASTER_BASE, ucChar);
|
388 |
|
|
|
389 |
|
|
//
|
390 |
|
|
// Continue the transfer.
|
391 |
|
|
//
|
392 |
|
|
I2CMasterControl(I2C_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
|
393 |
|
|
}
|
394 |
|
|
|
395 |
|
|
//*****************************************************************************
|
396 |
|
|
//
|
397 |
|
|
//! \internal
|
398 |
|
|
//!
|
399 |
|
|
//! Write a sequence of bytes to the SSD0303 controller.
|
400 |
|
|
//!
|
401 |
|
|
//! This function continues a transfer to the SSD0303 controller by writing a
|
402 |
|
|
//! sequence of bytes over the I2C bus. This must only be called after calling
|
403 |
|
|
//! OSRAMWriteFirst(), but before calling OSRAMWriteFinal().
|
404 |
|
|
//!
|
405 |
|
|
//! The data is written in a polled fashion; this function will not return
|
406 |
|
|
//! until the entire byte sequence has been written to the controller.
|
407 |
|
|
//!
|
408 |
|
|
//! \return None.
|
409 |
|
|
//
|
410 |
|
|
//*****************************************************************************
|
411 |
|
|
static void
|
412 |
|
|
OSRAMWriteArray(const unsigned char *pucBuffer, unsigned long ulCount)
|
413 |
|
|
{
|
414 |
|
|
//
|
415 |
|
|
// Loop while there are more bytes left to be transferred.
|
416 |
|
|
//
|
417 |
|
|
while(ulCount != 0)
|
418 |
|
|
{
|
419 |
|
|
//
|
420 |
|
|
// Wait until the current byte has been transferred.
|
421 |
|
|
//
|
422 |
|
|
while(I2CMasterIntStatus(I2C_MASTER_BASE, false) == 0)
|
423 |
|
|
{
|
424 |
|
|
}
|
425 |
|
|
|
426 |
|
|
//
|
427 |
|
|
// Provide the required inter-byte delay.
|
428 |
|
|
//
|
429 |
|
|
OSRAMDelay(g_ulDelay);
|
430 |
|
|
|
431 |
|
|
//
|
432 |
|
|
// Write the next byte to the controller.
|
433 |
|
|
//
|
434 |
|
|
I2CMasterDataPut(I2C_MASTER_BASE, *pucBuffer++);
|
435 |
|
|
ulCount--;
|
436 |
|
|
|
437 |
|
|
//
|
438 |
|
|
// Continue the transfer.
|
439 |
|
|
//
|
440 |
|
|
I2CMasterControl(I2C_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
|
441 |
|
|
}
|
442 |
|
|
}
|
443 |
|
|
|
444 |
|
|
//*****************************************************************************
|
445 |
|
|
//
|
446 |
|
|
//! \internal
|
447 |
|
|
//!
|
448 |
|
|
//! Finish a transfer to the SSD0303 controller.
|
449 |
|
|
//!
|
450 |
|
|
//! \param ucChar is the final byte to be written to the controller.
|
451 |
|
|
//!
|
452 |
|
|
//! This function will finish a transfer to the SSD0303 controller via the I2C
|
453 |
|
|
//! bus. This must only be called after calling OSRAMWriteFirst().
|
454 |
|
|
//!
|
455 |
|
|
//! The data is written in a polled fashion; this function will not return
|
456 |
|
|
//! until the byte has been written to the controller.
|
457 |
|
|
//!
|
458 |
|
|
//! \return None.
|
459 |
|
|
//
|
460 |
|
|
//*****************************************************************************
|
461 |
|
|
static void
|
462 |
|
|
OSRAMWriteFinal(unsigned char ucChar)
|
463 |
|
|
{
|
464 |
|
|
//
|
465 |
|
|
// Wait until the current byte has been transferred.
|
466 |
|
|
//
|
467 |
|
|
while(I2CMasterIntStatus(I2C_MASTER_BASE, false) == 0)
|
468 |
|
|
{
|
469 |
|
|
}
|
470 |
|
|
|
471 |
|
|
//
|
472 |
|
|
// Provide the required inter-byte delay.
|
473 |
|
|
//
|
474 |
|
|
OSRAMDelay(g_ulDelay);
|
475 |
|
|
|
476 |
|
|
//
|
477 |
|
|
// Write the final byte to the controller.
|
478 |
|
|
//
|
479 |
|
|
I2CMasterDataPut(I2C_MASTER_BASE, ucChar);
|
480 |
|
|
|
481 |
|
|
//
|
482 |
|
|
// Finish the transfer.
|
483 |
|
|
//
|
484 |
|
|
I2CMasterControl(I2C_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
|
485 |
|
|
|
486 |
|
|
//
|
487 |
|
|
// Wait until the final byte has been transferred.
|
488 |
|
|
//
|
489 |
|
|
while(I2CMasterIntStatus(I2C_MASTER_BASE, false) == 0)
|
490 |
|
|
{
|
491 |
|
|
}
|
492 |
|
|
|
493 |
|
|
//
|
494 |
|
|
// Provide the required inter-byte delay.
|
495 |
|
|
//
|
496 |
|
|
OSRAMDelay(g_ulDelay);
|
497 |
|
|
}
|
498 |
|
|
|
499 |
|
|
//*****************************************************************************
|
500 |
|
|
//
|
501 |
|
|
//! Clears the OLED display.
|
502 |
|
|
//!
|
503 |
|
|
//! This function will clear the display. All pixels in the display will be
|
504 |
|
|
//! turned off.
|
505 |
|
|
//!
|
506 |
|
|
//! This function is contained in <tt>osram96x16.c</tt>, with
|
507 |
|
|
//! <tt>osram96x16.h</tt> containing the API definition for use by
|
508 |
|
|
//! applications.
|
509 |
|
|
//!
|
510 |
|
|
//! \return None.
|
511 |
|
|
//
|
512 |
|
|
//*****************************************************************************
|
513 |
|
|
void
|
514 |
|
|
OSRAMClear(void)
|
515 |
|
|
{
|
516 |
|
|
static const unsigned char pucRow1[] =
|
517 |
|
|
{
|
518 |
|
|
0xb0, 0x80, 0x04, 0x80, 0x12, 0x40
|
519 |
|
|
};
|
520 |
|
|
static const unsigned char pucRow2[] =
|
521 |
|
|
{
|
522 |
|
|
0xb1, 0x80, 0x04, 0x80, 0x12, 0x40
|
523 |
|
|
};
|
524 |
|
|
unsigned long ulIdx;
|
525 |
|
|
|
526 |
|
|
//
|
527 |
|
|
// Move the display cursor to the first column of the first row.
|
528 |
|
|
//
|
529 |
|
|
OSRAMWriteFirst(0x80);
|
530 |
|
|
OSRAMWriteArray(pucRow1, sizeof(pucRow1));
|
531 |
|
|
|
532 |
|
|
//
|
533 |
|
|
// Fill this row with zeros.
|
534 |
|
|
//
|
535 |
|
|
for(ulIdx = 0; ulIdx < 95; ulIdx++)
|
536 |
|
|
{
|
537 |
|
|
OSRAMWriteByte(0x00);
|
538 |
|
|
}
|
539 |
|
|
OSRAMWriteFinal(0x00);
|
540 |
|
|
|
541 |
|
|
//
|
542 |
|
|
// Move the display cursor to the first column of the second row.
|
543 |
|
|
//
|
544 |
|
|
OSRAMWriteFirst(0x80);
|
545 |
|
|
OSRAMWriteArray(pucRow2, sizeof(pucRow2));
|
546 |
|
|
|
547 |
|
|
//
|
548 |
|
|
// Fill this row with zeros.
|
549 |
|
|
//
|
550 |
|
|
for(ulIdx = 0; ulIdx < 95; ulIdx++)
|
551 |
|
|
{
|
552 |
|
|
OSRAMWriteByte(0x00);
|
553 |
|
|
}
|
554 |
|
|
OSRAMWriteFinal(0x00);
|
555 |
|
|
}
|
556 |
|
|
|
557 |
|
|
//*****************************************************************************
|
558 |
|
|
//
|
559 |
|
|
//! Displays a string on the OLED display.
|
560 |
|
|
//!
|
561 |
|
|
//! \param pcStr is a pointer to the string to display.
|
562 |
|
|
//! \param ulX is the horizontal position to display the string, specified in
|
563 |
|
|
//! columns from the left edge of the display.
|
564 |
|
|
//! \param ulY is the vertical position to display the string, specified in
|
565 |
|
|
//! eight scan line blocks from the top of the display (i.e. only 0 and 1 are
|
566 |
|
|
//! valid).
|
567 |
|
|
//!
|
568 |
|
|
//! This function will draw a string on the display. Only the ASCII characters
|
569 |
|
|
//! between 32 (space) and 126 (tilde) are supported; other characters will
|
570 |
|
|
//! result in random data being draw on the display (based on whatever appears
|
571 |
|
|
//! before/after the font in memory). The font is mono-spaced, so characters
|
572 |
|
|
//! such as "i" and "l" have more white space around them than characters such
|
573 |
|
|
//! as "m" or "w".
|
574 |
|
|
//!
|
575 |
|
|
//! If the drawing of the string reaches the right edge of the display, no more
|
576 |
|
|
//! characters will be drawn. Therefore, special care is not required to avoid
|
577 |
|
|
//! supplying a string that is "too long" to display.
|
578 |
|
|
//!
|
579 |
|
|
//! This function is contained in <tt>osram96x16.c</tt>, with
|
580 |
|
|
//! <tt>osram96x16.h</tt> containing the API definition for use by
|
581 |
|
|
//! applications.
|
582 |
|
|
//!
|
583 |
|
|
//! \return None.
|
584 |
|
|
//
|
585 |
|
|
//*****************************************************************************
|
586 |
|
|
void
|
587 |
|
|
OSRAMStringDraw(const char *pcStr, unsigned long ulX, unsigned long ulY)
|
588 |
|
|
{
|
589 |
|
|
//
|
590 |
|
|
// Check the arguments.
|
591 |
|
|
//
|
592 |
|
|
ASSERT(ulX < 96);
|
593 |
|
|
ASSERT(ulY < 2);
|
594 |
|
|
|
595 |
|
|
//
|
596 |
|
|
// Move the display cursor to the requested position on the display.
|
597 |
|
|
//
|
598 |
|
|
OSRAMWriteFirst(0x80);
|
599 |
|
|
OSRAMWriteByte((ulY == 0) ? 0xb0 : 0xb1);
|
600 |
|
|
OSRAMWriteByte(0x80);
|
601 |
|
|
OSRAMWriteByte((ulX + 36) & 0x0f);
|
602 |
|
|
OSRAMWriteByte(0x80);
|
603 |
|
|
OSRAMWriteByte(0x10 | (((ulX + 36) >> 4) & 0x0f));
|
604 |
|
|
OSRAMWriteByte(0x40);
|
605 |
|
|
|
606 |
|
|
//
|
607 |
|
|
// Loop while there are more characters in the string.
|
608 |
|
|
//
|
609 |
|
|
while(*pcStr != 0)
|
610 |
|
|
{
|
611 |
|
|
//
|
612 |
|
|
// See if there is enough space on the display for this entire
|
613 |
|
|
// character.
|
614 |
|
|
//
|
615 |
|
|
if(ulX <= 90)
|
616 |
|
|
{
|
617 |
|
|
//
|
618 |
|
|
// Write the contents of this character to the display.
|
619 |
|
|
//
|
620 |
|
|
OSRAMWriteArray(g_pucFont[*pcStr - ' '], 5);
|
621 |
|
|
|
622 |
|
|
//
|
623 |
|
|
// See if this is the last character to display (either because the
|
624 |
|
|
// right edge has been reached or because there are no more
|
625 |
|
|
// characters).
|
626 |
|
|
//
|
627 |
|
|
if((ulX == 90) || (pcStr[1] == 0))
|
628 |
|
|
{
|
629 |
|
|
//
|
630 |
|
|
// Write the final column of the display.
|
631 |
|
|
//
|
632 |
|
|
OSRAMWriteFinal(0x00);
|
633 |
|
|
|
634 |
|
|
//
|
635 |
|
|
// The string has been displayed.
|
636 |
|
|
//
|
637 |
|
|
return;
|
638 |
|
|
}
|
639 |
|
|
|
640 |
|
|
//
|
641 |
|
|
// Write the inter-character padding column.
|
642 |
|
|
//
|
643 |
|
|
OSRAMWriteByte(0x00);
|
644 |
|
|
}
|
645 |
|
|
else
|
646 |
|
|
{
|
647 |
|
|
//
|
648 |
|
|
// Write the portion of the character that will fit onto the
|
649 |
|
|
// display.
|
650 |
|
|
//
|
651 |
|
|
OSRAMWriteArray(g_pucFont[*pcStr - ' '], 95 - ulX);
|
652 |
|
|
OSRAMWriteFinal(g_pucFont[*pcStr - ' '][95 - ulX]);
|
653 |
|
|
|
654 |
|
|
//
|
655 |
|
|
// The string has been displayed.
|
656 |
|
|
//
|
657 |
|
|
return;
|
658 |
|
|
}
|
659 |
|
|
|
660 |
|
|
//
|
661 |
|
|
// Advance to the next character.
|
662 |
|
|
//
|
663 |
|
|
pcStr++;
|
664 |
|
|
|
665 |
|
|
//
|
666 |
|
|
// Increment the X coordinate by the six columns that were just
|
667 |
|
|
// written.
|
668 |
|
|
//
|
669 |
|
|
ulX += 6;
|
670 |
|
|
}
|
671 |
|
|
}
|
672 |
|
|
|
673 |
|
|
//*****************************************************************************
|
674 |
|
|
//
|
675 |
|
|
//! Displays an image on the OLED display.
|
676 |
|
|
//!
|
677 |
|
|
//! \param pucImage is a pointer to the image data.
|
678 |
|
|
//! \param ulX is the horizontal position to display this image, specified in
|
679 |
|
|
//! columns from the left edge of the display.
|
680 |
|
|
//! \param ulY is the vertical position to display this image, specified in
|
681 |
|
|
//! eight scan line blocks from the top of the display (i.e. only 0 and 1 are
|
682 |
|
|
//! valid).
|
683 |
|
|
//! \param ulWidth is the width of the image, specified in columns.
|
684 |
|
|
//! \param ulHeight is the height of the image, specified in eight row blocks
|
685 |
|
|
//! (i.e. only 1 and 2 are valid).
|
686 |
|
|
//!
|
687 |
|
|
//! This function will display a bitmap graphic on the display. The image to
|
688 |
|
|
//! be displayed must be a multiple of eight scan lines high (i.e. one row) and
|
689 |
|
|
//! will be drawn at a vertical position that is a multiple of eight scan lines
|
690 |
|
|
//! (i.e. scan line zero or scan line eight, corresponding to row zero or row
|
691 |
|
|
//! one).
|
692 |
|
|
//!
|
693 |
|
|
//! The image data is organized with the first row of image data appearing left
|
694 |
|
|
//! to right, followed immediately by the second row of image data. Each byte
|
695 |
|
|
//! contains the data for the eight scan lines of the column, with the top scan
|
696 |
|
|
//! line being in the least significant bit of the byte and the bottom scan
|
697 |
|
|
//! line being in the most significant bit of the byte.
|
698 |
|
|
//!
|
699 |
|
|
//! For example, an image four columns wide and sixteen scan lines tall would
|
700 |
|
|
//! be arranged as follows (showing how the eight bytes of the image would
|
701 |
|
|
//! appear on the display):
|
702 |
|
|
//!
|
703 |
|
|
//! \verbatim
|
704 |
|
|
//! +-------+ +-------+ +-------+ +-------+
|
705 |
|
|
//! | | 0 | | | 0 | | | 0 | | | 0 |
|
706 |
|
|
//! | B | 1 | | B | 1 | | B | 1 | | B | 1 |
|
707 |
|
|
//! | y | 2 | | y | 2 | | y | 2 | | y | 2 |
|
708 |
|
|
//! | t | 3 | | t | 3 | | t | 3 | | t | 3 |
|
709 |
|
|
//! | e | 4 | | e | 4 | | e | 4 | | e | 4 |
|
710 |
|
|
//! | | 5 | | | 5 | | | 5 | | | 5 |
|
711 |
|
|
//! | 0 | 6 | | 1 | 6 | | 2 | 6 | | 3 | 6 |
|
712 |
|
|
//! | | 7 | | | 7 | | | 7 | | | 7 |
|
713 |
|
|
//! +-------+ +-------+ +-------+ +-------+
|
714 |
|
|
//!
|
715 |
|
|
//! +-------+ +-------+ +-------+ +-------+
|
716 |
|
|
//! | | 0 | | | 0 | | | 0 | | | 0 |
|
717 |
|
|
//! | B | 1 | | B | 1 | | B | 1 | | B | 1 |
|
718 |
|
|
//! | y | 2 | | y | 2 | | y | 2 | | y | 2 |
|
719 |
|
|
//! | t | 3 | | t | 3 | | t | 3 | | t | 3 |
|
720 |
|
|
//! | e | 4 | | e | 4 | | e | 4 | | e | 4 |
|
721 |
|
|
//! | | 5 | | | 5 | | | 5 | | | 5 |
|
722 |
|
|
//! | 4 | 6 | | 5 | 6 | | 6 | 6 | | 7 | 6 |
|
723 |
|
|
//! | | 7 | | | 7 | | | 7 | | | 7 |
|
724 |
|
|
//! +-------+ +-------+ +-------+ +-------+
|
725 |
|
|
//! \endverbatim
|
726 |
|
|
//!
|
727 |
|
|
//! This function is contained in <tt>osram96x16.c</tt>, with
|
728 |
|
|
//! <tt>osram96x16.h</tt> containing the API definition for use by
|
729 |
|
|
//! applications.
|
730 |
|
|
//!
|
731 |
|
|
//! \return None.
|
732 |
|
|
//
|
733 |
|
|
//*****************************************************************************
|
734 |
|
|
void
|
735 |
|
|
OSRAMImageDraw(const unsigned char *pucImage, unsigned long ulX,
|
736 |
|
|
unsigned long ulY, unsigned long ulWidth,
|
737 |
|
|
unsigned long ulHeight)
|
738 |
|
|
{
|
739 |
|
|
//
|
740 |
|
|
// Check the arguments.
|
741 |
|
|
//
|
742 |
|
|
ASSERT(ulX < 96);
|
743 |
|
|
ASSERT(ulY < 2);
|
744 |
|
|
ASSERT((ulX + ulWidth) <= 96);
|
745 |
|
|
ASSERT((ulY + ulHeight) <= 2);
|
746 |
|
|
|
747 |
|
|
//
|
748 |
|
|
// The first 36 columns of the LCD buffer are not displayed, so increment
|
749 |
|
|
// the X coorddinate by 36 to account for the non-displayed frame buffer
|
750 |
|
|
// memory.
|
751 |
|
|
//
|
752 |
|
|
ulX += 36;
|
753 |
|
|
|
754 |
|
|
//
|
755 |
|
|
// Loop while there are more rows to display.
|
756 |
|
|
//
|
757 |
|
|
while(ulHeight--)
|
758 |
|
|
{
|
759 |
|
|
//
|
760 |
|
|
// Write the starting address within this row.
|
761 |
|
|
//
|
762 |
|
|
OSRAMWriteFirst(0x80);
|
763 |
|
|
OSRAMWriteByte((ulY == 0) ? 0xb0 : 0xb1);
|
764 |
|
|
OSRAMWriteByte(0x80);
|
765 |
|
|
OSRAMWriteByte(ulX & 0x0f);
|
766 |
|
|
OSRAMWriteByte(0x80);
|
767 |
|
|
OSRAMWriteByte(0x10 | ((ulX >> 4) & 0x0f));
|
768 |
|
|
OSRAMWriteByte(0x40);
|
769 |
|
|
|
770 |
|
|
//
|
771 |
|
|
// Write this row of image data.
|
772 |
|
|
//
|
773 |
|
|
OSRAMWriteArray(pucImage, ulWidth - 1);
|
774 |
|
|
OSRAMWriteFinal(pucImage[ulWidth - 1]);
|
775 |
|
|
|
776 |
|
|
//
|
777 |
|
|
// Advance to the next row of the image.
|
778 |
|
|
//
|
779 |
|
|
pucImage += ulWidth;
|
780 |
|
|
ulY++;
|
781 |
|
|
}
|
782 |
|
|
}
|
783 |
|
|
|
784 |
|
|
//*****************************************************************************
|
785 |
|
|
//
|
786 |
|
|
//! Initialize the OLED display.
|
787 |
|
|
//!
|
788 |
|
|
//! \param bFast is a boolean that is \e true if the I2C interface should be
|
789 |
|
|
//! run at 400 kbps and \e false if it should be run at 100 kbps.
|
790 |
|
|
//!
|
791 |
|
|
//! This function initializes the I2C interface to the OLED display and
|
792 |
|
|
//! configures the SSD0303 controller on the panel.
|
793 |
|
|
//!
|
794 |
|
|
//! This function is contained in <tt>osram96x16.c</tt>, with
|
795 |
|
|
//! <tt>osram96x16.h</tt> containing the API definition for use by
|
796 |
|
|
//! applications.
|
797 |
|
|
//!
|
798 |
|
|
//! \return None.
|
799 |
|
|
//
|
800 |
|
|
//*****************************************************************************
|
801 |
|
|
void
|
802 |
|
|
OSRAMInit(tBoolean bFast)
|
803 |
|
|
{
|
804 |
|
|
unsigned long ulIdx;
|
805 |
|
|
|
806 |
|
|
//
|
807 |
|
|
// Enable the I2C and GPIO port B blocks as they are needed by this driver.
|
808 |
|
|
//
|
809 |
|
|
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C);
|
810 |
|
|
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
|
811 |
|
|
|
812 |
|
|
//
|
813 |
|
|
// Configure the I2C SCL and SDA pins for I2C operation.
|
814 |
|
|
//
|
815 |
|
|
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);
|
816 |
|
|
|
817 |
|
|
//
|
818 |
|
|
// Initialize the I2C master.
|
819 |
|
|
//
|
820 |
|
|
I2CMasterInit(I2C_MASTER_BASE, bFast);
|
821 |
|
|
|
822 |
|
|
//
|
823 |
|
|
// Compute the inter-byte delay for the SSD0303 controller. This delay is
|
824 |
|
|
// dependent upon the I2C bus clock rate; the slower the clock the longer
|
825 |
|
|
// the delay required.
|
826 |
|
|
//
|
827 |
|
|
// The derivation of this formula is based on a measured delay of
|
828 |
|
|
// OSRAMDelay(1700) for a 100 kHz I2C bus with the CPU running at 50 MHz
|
829 |
|
|
// (referred to as C). To scale this to the delay for a different CPU
|
830 |
|
|
// speed (since this is just a CPU-based delay loop) is:
|
831 |
|
|
//
|
832 |
|
|
// f(CPU)
|
833 |
|
|
// C * ----------
|
834 |
|
|
// 50,000,000
|
835 |
|
|
//
|
836 |
|
|
// To then scale this to the actual I2C rate (since it won't always be
|
837 |
|
|
// precisely 100 kHz):
|
838 |
|
|
//
|
839 |
|
|
// f(CPU) 100,000
|
840 |
|
|
// C * ---------- * -------
|
841 |
|
|
// 50,000,000 f(I2C)
|
842 |
|
|
//
|
843 |
|
|
// This equation will give the inter-byte delay required for any
|
844 |
|
|
// configuration of the I2C master. But, as arranged it is impossible to
|
845 |
|
|
// directly compute in 32-bit arithmetic (without loosing a lot of
|
846 |
|
|
// accuracy). So, the equation is simplified.
|
847 |
|
|
//
|
848 |
|
|
// Since f(I2C) is generated by dividing down from f(CPU), replace it with
|
849 |
|
|
// the equivalent (where TPR is the value programmed into the Master Timer
|
850 |
|
|
// Period Register of the I2C master, with the 1 added back):
|
851 |
|
|
//
|
852 |
|
|
// 100,000
|
853 |
|
|
// f(CPU) -------
|
854 |
|
|
// C * ---------- * f(CPU)
|
855 |
|
|
// 50,000,000 ------------
|
856 |
|
|
// 2 * 10 * TPR
|
857 |
|
|
//
|
858 |
|
|
// Inverting the dividend in the last term:
|
859 |
|
|
//
|
860 |
|
|
// f(CPU) 100,000 * 2 * 10 * TPR
|
861 |
|
|
// C * ---------- * ----------------------
|
862 |
|
|
// 50,000,000 f(CPU)
|
863 |
|
|
//
|
864 |
|
|
// The f(CPU) now cancels out.
|
865 |
|
|
//
|
866 |
|
|
// 100,000 * 2 * 10 * TPR
|
867 |
|
|
// C * ----------------------
|
868 |
|
|
// 50,000,000
|
869 |
|
|
//
|
870 |
|
|
// Since there are no clock frequencies left in the equation, this equation
|
871 |
|
|
// also works for 400 kHz bus operation as well, since the 100,000 in the
|
872 |
|
|
// numerator becomes 400,000 but C is 1/4, which cancel out each other.
|
873 |
|
|
// Reducing the constants gives:
|
874 |
|
|
//
|
875 |
|
|
// TPR TPR TPR
|
876 |
|
|
// C * --- = 1700 * --- = 340 * --- = 68 * TPR
|
877 |
|
|
// 25 25 5
|
878 |
|
|
//
|
879 |
|
|
// Note that the constant C is actually a bit larger than it needs to be in
|
880 |
|
|
// order to provide some safety margin.
|
881 |
|
|
//
|
882 |
|
|
g_ulDelay = 68 * (HWREG(I2C_MASTER_BASE + I2C_MASTER_O_TPR) + 1);
|
883 |
|
|
|
884 |
|
|
//
|
885 |
|
|
// Initialize the SSD0303 controller. Loop through the initialization
|
886 |
|
|
// sequence doing a single I2C transfer for each command.
|
887 |
|
|
//
|
888 |
|
|
for(ulIdx = 0; ulIdx < sizeof(g_pucOSRAMInit);
|
889 |
|
|
ulIdx += g_pucOSRAMInit[ulIdx] + 1)
|
890 |
|
|
{
|
891 |
|
|
//
|
892 |
|
|
// Send this command.
|
893 |
|
|
//
|
894 |
|
|
OSRAMWriteFirst(g_pucOSRAMInit[ulIdx + 1]);
|
895 |
|
|
OSRAMWriteArray(g_pucOSRAMInit + ulIdx + 2, g_pucOSRAMInit[ulIdx] - 2);
|
896 |
|
|
OSRAMWriteFinal(g_pucOSRAMInit[ulIdx + g_pucOSRAMInit[ulIdx]]);
|
897 |
|
|
}
|
898 |
|
|
|
899 |
|
|
//
|
900 |
|
|
// Clear the frame buffer.
|
901 |
|
|
//
|
902 |
|
|
OSRAMClear();
|
903 |
|
|
}
|
904 |
|
|
|
905 |
|
|
//*****************************************************************************
|
906 |
|
|
//
|
907 |
|
|
//! Turns on the OLED display.
|
908 |
|
|
//!
|
909 |
|
|
//! This function will turn on the OLED display, causing it to display the
|
910 |
|
|
//! contents of its internal frame buffer.
|
911 |
|
|
//!
|
912 |
|
|
//! This function is contained in <tt>osram96x16.c</tt>, with
|
913 |
|
|
//! <tt>osram96x16.h</tt> containing the API definition for use by
|
914 |
|
|
//! applications.
|
915 |
|
|
//!
|
916 |
|
|
//! \return None.
|
917 |
|
|
//
|
918 |
|
|
//*****************************************************************************
|
919 |
|
|
void
|
920 |
|
|
OSRAMDisplayOn(void)
|
921 |
|
|
{
|
922 |
|
|
unsigned long ulIdx;
|
923 |
|
|
|
924 |
|
|
//
|
925 |
|
|
// Re-initialize the SSD0303 controller. Loop through the initialization
|
926 |
|
|
// sequence doing a single I2C transfer for each command.
|
927 |
|
|
//
|
928 |
|
|
for(ulIdx = 0; ulIdx < sizeof(g_pucOSRAMInit);
|
929 |
|
|
ulIdx += g_pucOSRAMInit[ulIdx] + 1)
|
930 |
|
|
{
|
931 |
|
|
//
|
932 |
|
|
// Send this command.
|
933 |
|
|
//
|
934 |
|
|
OSRAMWriteFirst(g_pucOSRAMInit[ulIdx + 1]);
|
935 |
|
|
OSRAMWriteArray(g_pucOSRAMInit + ulIdx + 2, g_pucOSRAMInit[ulIdx] - 2);
|
936 |
|
|
OSRAMWriteFinal(g_pucOSRAMInit[ulIdx + g_pucOSRAMInit[ulIdx]]);
|
937 |
|
|
}
|
938 |
|
|
}
|
939 |
|
|
|
940 |
|
|
//*****************************************************************************
|
941 |
|
|
//
|
942 |
|
|
//! Turns off the OLED display.
|
943 |
|
|
//!
|
944 |
|
|
//! This function will turn off the OLED display. This will stop the scanning
|
945 |
|
|
//! of the panel and turn off the on-chip DC-DC converter, preventing damage to
|
946 |
|
|
//! the panel due to burn-in (it has similar characters to a CRT in this
|
947 |
|
|
//! respect).
|
948 |
|
|
//!
|
949 |
|
|
//! This function is contained in <tt>osram96x16.c</tt>, with
|
950 |
|
|
//! <tt>osram96x16.h</tt> containing the API definition for use by
|
951 |
|
|
//! applications.
|
952 |
|
|
//!
|
953 |
|
|
//! \return None.
|
954 |
|
|
//
|
955 |
|
|
//*****************************************************************************
|
956 |
|
|
void
|
957 |
|
|
OSRAMDisplayOff(void)
|
958 |
|
|
{
|
959 |
|
|
//
|
960 |
|
|
// Turn off the DC-DC converter and the display.
|
961 |
|
|
//
|
962 |
|
|
OSRAMWriteFirst(0x80);
|
963 |
|
|
OSRAMWriteByte(0xae);
|
964 |
|
|
OSRAMWriteByte(0x80);
|
965 |
|
|
OSRAMWriteByte(0xad);
|
966 |
|
|
OSRAMWriteByte(0x80);
|
967 |
|
|
OSRAMWriteFinal(0x8a);
|
968 |
|
|
}
|
969 |
|
|
|
970 |
|
|
//*****************************************************************************
|
971 |
|
|
//
|
972 |
|
|
// Close the Doxygen group.
|
973 |
|
|
//! @}
|
974 |
|
|
//
|
975 |
|
|
//*****************************************************************************
|