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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_LM3Sxxxx_Rowley/] [rit128x96x4.c] - Blame information for rev 595

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 581 jeremybenn
//*****************************************************************************
2
//
3
// rit128x96x4.c - Driver for the RIT 128x96x4 graphical OLED display.
4
//
5
// Copyright (c) 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 1504-conf of the Stellaris Peripheral Driver Library.
25
//
26
//*****************************************************************************
27
 
28
//*****************************************************************************
29
//
30
//! \addtogroup ek_lm3sLM3S8962_api
31
//! @{
32
//
33
//*****************************************************************************
34
 
35
#include "hw_ssi.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 "ssi.h"
42
#include "sysctl.h"
43
#include "rit128x96x4.h"
44
 
45
//*****************************************************************************
46
//
47
// Macros that define the peripheral, port, and pin used for the OLEDDC
48
// panel control signal.
49
//
50
//*****************************************************************************
51
 
52
unsigned long ulGPIOId = 0, ulGPIOBase = 0, ulOLEDDC_PIN = 0, ulOLEDEN_PIN = 0;
53
 
54
#define LM3S8962_SYSCTL_PERIPH_GPIO_OLEDDC   SYSCTL_PERIPH_GPIOA
55
#define LM3S8962_GPIO_OLEDDC_BASE            GPIO_PORTA_BASE
56
#define LM3S8962_GPIO_OLEDDC_PIN             GPIO_PIN_6
57
#define LM3S8962_GPIO_OLEDEN_PIN             GPIO_PIN_7
58
 
59
#define LM3S1968_SYSCTL_PERIPH_GPIO_OLEDDC   SYSCTL_PERIPH_GPIOH
60
#define LM3S1968_GPIO_OLEDDC_BASE            GPIO_PORTH_BASE
61
#define LM3S1968_GPIO_OLEDDC_PIN             GPIO_PIN_2
62
#define LM3S1968_GPIO_OLEDEN_PIN             GPIO_PIN_3
63
 
64
 
65
//*****************************************************************************
66
//
67
// Flag to indicate if SSI port is enabled for display usage.
68
//
69
//*****************************************************************************
70
static volatile tBoolean g_bSSIEnabled = false;
71
 
72
//*****************************************************************************
73
//
74
// Buffer for storing sequences of command and data for the display.
75
//
76
//*****************************************************************************
77
static unsigned char g_pucBuffer[8];
78
 
79
//*****************************************************************************
80
//
81
// Define the SSD1329 128x96x4 Remap Setting(s).  This will be used in
82
// several places in the code to switch between vertical and horizontal
83
// address incrementing.  Note that the controller support 128 rows while
84
// the RIT display only uses 96.
85
//
86
// The Remap Command (0xA0) takes one 8-bit parameter.  The parameter is
87
// defined as follows.
88
//
89
// Bit 7: Reserved
90
// Bit 6: Disable(0)/Enable(1) COM Split Odd Even
91
//        When enabled, the COM signals are split Odd on one side, even on
92
//        the other.  Otherwise, they are split 0-63 on one side, 64-127 on
93
//        the other.
94
// Bit 5: Reserved
95
// Bit 4: Disable(0)/Enable(1) COM Remap
96
//        When Enabled, ROW 0-127 map to COM 127-0 (i.e. reverse row order)
97
// Bit 3: Reserved
98
// Bit 2: Horizontal(0)/Vertical(1) Address Increment
99
//        When set, data RAM address will increment along the column rather
100
//        than along the row.
101
// Bit 1: Disable(0)/Enable(1) Nibble Remap
102
//        When enabled, the upper and lower nibbles in the DATA bus for access
103
//        to the data RAM are swapped.
104
// Bit 0: Disable(0)/Enable(1) Column Address Remap
105
//        When enabled, DATA RAM columns 0-63 are remapped to Segment Columns
106
//        127-0.
107
//
108
//*****************************************************************************
109
#define RIT_INIT_REMAP      0x52 // app note says 0x51
110
#define RIT_INIT_OFFSET     0x00
111
static const unsigned char g_pucRIT128x96x4VerticalInc[]   = { 0xA0, 0x56 };
112
static const unsigned char g_pucRIT128x96x4HorizontalInc[] = { 0xA0, 0x52 };
113
 
114
//*****************************************************************************
115
//
116
// A 5x7 font (in a 6x8 cell, where the sixth column is omitted from this
117
// table) for displaying text on the OLED display.  The data is organized as
118
// bytes from the left column to the right column, with each byte containing
119
// the top row in the LSB and the bottom row in the MSB.
120
//
121
// Note:  This is the same font data that is used in the EK-LM3S811
122
// osram96x16x1 driver.  The single bit-per-pixel is expaned in the StringDraw
123
// function to the appropriate four bit-per-pixel gray scale format.
124
//
125
//*****************************************************************************
126
static const unsigned char g_pucFont[96][5] =
127
{
128
    { 0x00, 0x00, 0x00, 0x00, 0x00 }, // " "
129
    { 0x00, 0x00, 0x4f, 0x00, 0x00 }, // !
130
    { 0x00, 0x07, 0x00, 0x07, 0x00 }, // "
131
    { 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #
132
    { 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $
133
    { 0x23, 0x13, 0x08, 0x64, 0x62 }, // %
134
    { 0x36, 0x49, 0x55, 0x22, 0x50 }, // &
135
    { 0x00, 0x05, 0x03, 0x00, 0x00 }, // '
136
    { 0x00, 0x1c, 0x22, 0x41, 0x00 }, // (
137
    { 0x00, 0x41, 0x22, 0x1c, 0x00 }, // )
138
    { 0x14, 0x08, 0x3e, 0x08, 0x14 }, // *
139
    { 0x08, 0x08, 0x3e, 0x08, 0x08 }, // +
140
    { 0x00, 0x50, 0x30, 0x00, 0x00 }, // ,
141
    { 0x08, 0x08, 0x08, 0x08, 0x08 }, // -
142
    { 0x00, 0x60, 0x60, 0x00, 0x00 }, // .
143
    { 0x20, 0x10, 0x08, 0x04, 0x02 }, // /
144
    { 0x3e, 0x51, 0x49, 0x45, 0x3e }, // 0
145
    { 0x00, 0x42, 0x7f, 0x40, 0x00 }, // 1
146
    { 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2
147
    { 0x21, 0x41, 0x45, 0x4b, 0x31 }, // 3
148
    { 0x18, 0x14, 0x12, 0x7f, 0x10 }, // 4
149
    { 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5
150
    { 0x3c, 0x4a, 0x49, 0x49, 0x30 }, // 6
151
    { 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7
152
    { 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8
153
    { 0x06, 0x49, 0x49, 0x29, 0x1e }, // 9
154
    { 0x00, 0x36, 0x36, 0x00, 0x00 }, // :
155
    { 0x00, 0x56, 0x36, 0x00, 0x00 }, // ;
156
    { 0x08, 0x14, 0x22, 0x41, 0x00 }, // <
157
    { 0x14, 0x14, 0x14, 0x14, 0x14 }, // =
158
    { 0x00, 0x41, 0x22, 0x14, 0x08 }, // >
159
    { 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?
160
    { 0x32, 0x49, 0x79, 0x41, 0x3e }, // @
161
    { 0x7e, 0x11, 0x11, 0x11, 0x7e }, // A
162
    { 0x7f, 0x49, 0x49, 0x49, 0x36 }, // B
163
    { 0x3e, 0x41, 0x41, 0x41, 0x22 }, // C
164
    { 0x7f, 0x41, 0x41, 0x22, 0x1c }, // D
165
    { 0x7f, 0x49, 0x49, 0x49, 0x41 }, // E
166
    { 0x7f, 0x09, 0x09, 0x09, 0x01 }, // F
167
    { 0x3e, 0x41, 0x49, 0x49, 0x7a }, // G
168
    { 0x7f, 0x08, 0x08, 0x08, 0x7f }, // H
169
    { 0x00, 0x41, 0x7f, 0x41, 0x00 }, // I
170
    { 0x20, 0x40, 0x41, 0x3f, 0x01 }, // J
171
    { 0x7f, 0x08, 0x14, 0x22, 0x41 }, // K
172
    { 0x7f, 0x40, 0x40, 0x40, 0x40 }, // L
173
    { 0x7f, 0x02, 0x0c, 0x02, 0x7f }, // M
174
    { 0x7f, 0x04, 0x08, 0x10, 0x7f }, // N
175
    { 0x3e, 0x41, 0x41, 0x41, 0x3e }, // O
176
    { 0x7f, 0x09, 0x09, 0x09, 0x06 }, // P
177
    { 0x3e, 0x41, 0x51, 0x21, 0x5e }, // Q
178
    { 0x7f, 0x09, 0x19, 0x29, 0x46 }, // R
179
    { 0x46, 0x49, 0x49, 0x49, 0x31 }, // S
180
    { 0x01, 0x01, 0x7f, 0x01, 0x01 }, // T
181
    { 0x3f, 0x40, 0x40, 0x40, 0x3f }, // U
182
    { 0x1f, 0x20, 0x40, 0x20, 0x1f }, // V
183
    { 0x3f, 0x40, 0x38, 0x40, 0x3f }, // W
184
    { 0x63, 0x14, 0x08, 0x14, 0x63 }, // X
185
    { 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y
186
    { 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z
187
    { 0x00, 0x7f, 0x41, 0x41, 0x00 }, // [
188
    { 0x02, 0x04, 0x08, 0x10, 0x20 }, // "\"
189
    { 0x00, 0x41, 0x41, 0x7f, 0x00 }, // ]
190
    { 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^
191
    { 0x40, 0x40, 0x40, 0x40, 0x40 }, // _
192
    { 0x00, 0x01, 0x02, 0x04, 0x00 }, // `
193
    { 0x20, 0x54, 0x54, 0x54, 0x78 }, // a
194
    { 0x7f, 0x48, 0x44, 0x44, 0x38 }, // b
195
    { 0x38, 0x44, 0x44, 0x44, 0x20 }, // c
196
    { 0x38, 0x44, 0x44, 0x48, 0x7f }, // d
197
    { 0x38, 0x54, 0x54, 0x54, 0x18 }, // e
198
    { 0x08, 0x7e, 0x09, 0x01, 0x02 }, // f
199
    { 0x0c, 0x52, 0x52, 0x52, 0x3e }, // g
200
    { 0x7f, 0x08, 0x04, 0x04, 0x78 }, // h
201
    { 0x00, 0x44, 0x7d, 0x40, 0x00 }, // i
202
    { 0x20, 0x40, 0x44, 0x3d, 0x00 }, // j
203
    { 0x7f, 0x10, 0x28, 0x44, 0x00 }, // k
204
    { 0x00, 0x41, 0x7f, 0x40, 0x00 }, // l
205
    { 0x7c, 0x04, 0x18, 0x04, 0x78 }, // m
206
    { 0x7c, 0x08, 0x04, 0x04, 0x78 }, // n
207
    { 0x38, 0x44, 0x44, 0x44, 0x38 }, // o
208
    { 0x7c, 0x14, 0x14, 0x14, 0x08 }, // p
209
    { 0x08, 0x14, 0x14, 0x18, 0x7c }, // q
210
    { 0x7c, 0x08, 0x04, 0x04, 0x08 }, // r
211
    { 0x48, 0x54, 0x54, 0x54, 0x20 }, // s
212
    { 0x04, 0x3f, 0x44, 0x40, 0x20 }, // t
213
    { 0x3c, 0x40, 0x40, 0x20, 0x7c }, // u
214
    { 0x1c, 0x20, 0x40, 0x20, 0x1c }, // v
215
    { 0x3c, 0x40, 0x30, 0x40, 0x3c }, // w
216
    { 0x44, 0x28, 0x10, 0x28, 0x44 }, // x
217
    { 0x0c, 0x50, 0x50, 0x50, 0x3c }, // y
218
    { 0x44, 0x64, 0x54, 0x4c, 0x44 }, // z
219
    { 0x00, 0x08, 0x36, 0x41, 0x00 }, // {
220
    { 0x00, 0x00, 0x7f, 0x00, 0x00 }, // |
221
    { 0x00, 0x41, 0x36, 0x08, 0x00 }, // }
222
    { 0x02, 0x01, 0x02, 0x04, 0x02 }, // ~
223
    { 0x02, 0x01, 0x02, 0x04, 0x02 }, // ~
224
};
225
 
226
//*****************************************************************************
227
//
228
// The sequence of commands used to initialize the SSD1329 controller.  Each
229
// command is described as follows:  there is a byte specifying the number of
230
// bytes in the command sequence, followed by that many bytes of command data.
231
// Note:  This initialization sequence is derived from RIT App Note for
232
// the P14201.  Values used are from the RIT app note, except where noted.
233
//
234
//*****************************************************************************
235
static const unsigned char g_pucRIT128x96x4Init[] =
236
{
237
    //
238
    // Unlock commands
239
    //
240
    3, 0xFD, 0x12, 0xe3,
241
 
242
    //
243
    // Display off
244
    //
245
    2, 0xAE, 0xe3,
246
 
247
    //
248
    // Icon off
249
    //
250
    3, 0x94, 0, 0xe3,
251
 
252
    //
253
    // Multiplex ratio
254
    //
255
    3, 0xA8, 95, 0xe3,
256
 
257
    //
258
    // Contrast
259
    //
260
    3, 0x81, 0xb7, 0xe3,
261
 
262
    //
263
    // Pre-charge current
264
    //
265
    3, 0x82, 0x3f, 0xe3,
266
 
267
    //
268
    // Display Re-map
269
    //
270
    3, 0xA0, RIT_INIT_REMAP, 0xe3,
271
 
272
    //
273
    // Display Start Line
274
    //
275
    3, 0xA1, 0, 0xe3,
276
 
277
    //
278
    // Display Offset
279
    //
280
    3, 0xA2, RIT_INIT_OFFSET, 0xe3,
281
 
282
    //
283
    // Display Mode Normal
284
    //
285
    2, 0xA4, 0xe3,
286
 
287
    //
288
    // Phase Length
289
    //
290
    3, 0xB1, 0x11, 0xe3,
291
 
292
    //
293
    // Frame frequency
294
    //
295
    3, 0xB2, 0x23, 0xe3,
296
 
297
    //
298
    // Front Clock Divider
299
    //
300
    3, 0xB3, 0xe2, 0xe3,
301
 
302
    //
303
    // Set gray scale table.  App note uses default command:
304
    // 2, 0xB7, 0xe3
305
    // This gray scale attempts some gamma correction to reduce the
306
    // the brightness of the low levels.
307
    //
308
    17, 0xB8, 1, 2, 3, 4, 5, 6, 8, 10, 12, 14, 16, 19, 22, 26, 30, 0xe3,
309
 
310
    //
311
    // Second pre-charge period. App note uses value 0x04.
312
    //
313
    3, 0xBB, 0x01, 0xe3,
314
 
315
    //
316
    // Pre-charge voltage
317
    //
318
    3, 0xBC, 0x3f, 0xe3,
319
 
320
    //
321
    // Display ON
322
    //
323
    2, 0xAF, 0xe3,
324
};
325
 
326
//*****************************************************************************
327
//
328
//! \internal
329
//!
330
//! Write a sequence of command bytes to the SSD1329 controller.
331
//!
332
//! The data is written in a polled fashion; this function will not return
333
//! until the entire byte sequence has been written to the controller.
334
//!
335
//! \return None.
336
//
337
//*****************************************************************************
338
static void
339
RITWriteCommand(const unsigned char *pucBuffer, unsigned long ulCount)
340
{
341
    unsigned long ulTemp;
342
 
343
    //
344
    // Return if SSI port is not enabled for RIT display.
345
    //
346
    if(!g_bSSIEnabled)
347
    {
348
        return;
349
    }
350
 
351
    //
352
    // Clear the command/control bit to enable command mode.
353
    //
354
    GPIOPinWrite(ulGPIOBase, ulOLEDDC_PIN, 0);
355
 
356
    //
357
    // Loop while there are more bytes left to be transferred.
358
    //
359
    while(ulCount != 0)
360
    {
361
        //
362
        // Write the next byte to the controller.
363
        //
364
        SSIDataPut(SSI0_BASE, *pucBuffer++);
365
 
366
        //
367
        // Dummy read to drain the fifo and time the GPIO signal.
368
        //
369
        SSIDataGet(SSI0_BASE, &ulTemp);
370
 
371
        //
372
        // Decrement the BYTE counter.
373
        //
374
        ulCount--;
375
    }
376
}
377
 
378
//*****************************************************************************
379
//
380
//! \internal
381
//!
382
//! Write a sequence of data bytes to the SSD1329 controller.
383
//!
384
//! The data is written in a polled fashion; this function will not return
385
//! until the entire byte sequence has been written to the controller.
386
//!
387
//! \return None.
388
//
389
//*****************************************************************************
390
static void
391
RITWriteData(const unsigned char *pucBuffer, unsigned long ulCount)
392
{
393
    unsigned long ulTemp;
394
 
395
    //
396
    // Return if SSI port is not enabled for RIT display.
397
    //
398
    if(!g_bSSIEnabled)
399
    {
400
        return;
401
    }
402
 
403
    //
404
    // Set the command/control bit to enable data mode.
405
    //
406
    GPIOPinWrite(ulGPIOBase, ulOLEDDC_PIN, ulOLEDDC_PIN);
407
 
408
    //
409
    // Loop while there are more bytes left to be transferred.
410
    //
411
    while(ulCount != 0)
412
    {
413
        //
414
        // Write the next byte to the controller.
415
        //
416
        SSIDataPut(SSI0_BASE, *pucBuffer++);
417
 
418
        //
419
        // Dummy read to drain the fifo and time the GPIO signal.
420
        //
421
        SSIDataGet(SSI0_BASE, &ulTemp);
422
 
423
        //
424
        // Decrement the BYTE counter.
425
        //
426
        ulCount--;
427
    }
428
}
429
 
430
//*****************************************************************************
431
//
432
//! Clears the OLED display.
433
//!
434
//! This function will clear the display RAM.  All pixels in the display will
435
//! be turned off.
436
//!
437
//! This function is contained in <tt>rit128x96x4.c</tt>, with
438
//! <tt>rit128x96x4.h</tt> containing the API definition for use by
439
//! applications.
440
//!
441
//! \return None.
442
//
443
//*****************************************************************************
444
void
445
RIT128x96x4Clear(void)
446
{
447
    static const unsigned char pucCommand1[] = { 0x15, 0, 63 };
448
    static const unsigned char pucCommand2[] = { 0x75, 0, 127 };
449
    unsigned long ulRow, ulColumn;
450
 
451
    //
452
    // Clear out the buffer used for sending bytes to the display.
453
    *(unsigned long *)&g_pucBuffer[0] = 0;
454
    *(unsigned long *)&g_pucBuffer[4] = 0;
455
 
456
    //
457
    // Set the window to fill the entire display.
458
    //
459
    RITWriteCommand(pucCommand1, sizeof(pucCommand1));
460
    RITWriteCommand(pucCommand2, sizeof(pucCommand2));
461
    RITWriteCommand(g_pucRIT128x96x4HorizontalInc,
462
                    sizeof(g_pucRIT128x96x4HorizontalInc));
463
 
464
    //
465
    // Loop through the rows
466
    //
467
    for(ulRow = 0; ulRow < 96; ulRow++)
468
    {
469
        //
470
        // Loop through the columns.  Each byte is two pixels,
471
        // and the buffer hold 8 bytes, so 16 pixels are cleared
472
        // at a time.
473
        //
474
        for(ulColumn = 0; ulColumn < 128; ulColumn += 8 * 2)
475
        {
476
            //
477
            // Write 8 clearing bytes to the display, which will
478
            // clear 16 pixels across.
479
            //
480
            RITWriteData(g_pucBuffer, sizeof(g_pucBuffer));
481
        }
482
    }
483
}
484
 
485
//*****************************************************************************
486
//
487
//! Displays a string on the OLED display.
488
//!
489
//! \param pcStr is a pointer to the string to display.
490
//! \param ulX is the horizontal position to display the string, specified in
491
//! columns from the left edge of the display.
492
//! \param ulY is the vertical position to display the string, specified in
493
//! rows from the top edge of the display.
494
//! \param ucLevel is the 4-bit grey scale value to be used for displayed text.
495
//!
496
//! This function will draw a string on the display.  Only the ASCII characters
497
//! between 32 (space) and 126 (tilde) are supported; other characters will
498
//! result in random data being draw on the display (based on whatever appears
499
//! before/after the font in memory).  The font is mono-spaced, so characters
500
//! such as "i" and "l" have more white space around them than characters such
501
//! as "m" or "w".
502
//!
503
//! If the drawing of the string reaches the right edge of the display, no more
504
//! characters will be drawn.  Therefore, special care is not required to avoid
505
//! supplying a string that is "too long" to display.
506
//!
507
//! This function is contained in <tt>rit128x96x4.c</tt>, with
508
//! <tt>rit128x96x4.h</tt> containing the API definition for use by
509
//! applications.
510
//!
511
//! \note Because the OLED display packs 2 pixels of data in a single byte, the
512
//! parameter \e ulX must be an even column number (e.g. 0, 2, 4, etc).
513
//!
514
//! \return None.
515
//
516
//*****************************************************************************
517
void
518
RIT128x96x4StringDraw(const char *pcStr, unsigned long ulX,
519
                      unsigned long ulY, unsigned char ucLevel)
520
{
521
    unsigned long ulIdx1, ulIdx2;
522
    unsigned char ucTemp;
523
 
524
    //
525
    // Check the arguments.
526
    //
527
    ASSERT(ulX < 128);
528
    ASSERT((ulX & 1) == 0);
529
    ASSERT(ulY < 96);
530
    ASSERT(ucLevel < 16);
531
 
532
    //
533
    // Setup a window starting at the specified column and row, ending
534
    // at the right edge of the display and 8 rows down (single character row).
535
    //
536
    g_pucBuffer[0] = 0x15;
537
    g_pucBuffer[1] = ulX / 2;
538
    g_pucBuffer[2] = 63;
539
    RITWriteCommand(g_pucBuffer, 3);
540
    g_pucBuffer[0] = 0x75;
541
    g_pucBuffer[1] = ulY;
542
    g_pucBuffer[2] = ulY + 7;
543
    RITWriteCommand(g_pucBuffer, 3);
544
    RITWriteCommand(g_pucRIT128x96x4VerticalInc,
545
                    sizeof(g_pucRIT128x96x4VerticalInc));
546
 
547
    //
548
    // Loop while there are more characters in the string.
549
    //
550
    while(*pcStr != 0)
551
    {
552
        //
553
        // Get a working copy of the current character and convert to an
554
        // index into the character bit-map array.
555
        //
556
        ucTemp = *pcStr;
557
        ucTemp &= 0x7F;
558
        if(ucTemp < ' ')
559
        {
560
            ucTemp = ' ';
561
        }
562
        else
563
        {
564
            ucTemp -= ' ';
565
        }
566
 
567
        //
568
        // Build and display the character buffer.
569
        //
570
        for(ulIdx1 = 0; ulIdx1 < 3; ulIdx1++)
571
        {
572
            //
573
            // Convert two columns of 1-bit font data into a single data
574
            // byte column of 4-bit font data.
575
            //
576
            for(ulIdx2 = 0; ulIdx2 < 8; ulIdx2++)
577
            {
578
                g_pucBuffer[ulIdx2] = 0;
579
                if(g_pucFont[ucTemp][ulIdx1*2] & (1 << ulIdx2))
580
                {
581
                    g_pucBuffer[ulIdx2] = ((ucLevel << 4) & 0xf0);
582
                }
583
                if((ulIdx1 < 2) &&
584
                    (g_pucFont[ucTemp][ulIdx1*2+1] & (1 << ulIdx2)))
585
                {
586
                    g_pucBuffer[ulIdx2] |= ((ucLevel << 0) & 0x0f);
587
                }
588
            }
589
 
590
            //
591
            // If there is room, dump the single data byte column to the
592
            // display.  Otherwise, bail out.
593
            //
594
            if(ulX < 126)
595
            {
596
                RITWriteData(g_pucBuffer, 8);
597
                ulX += 2;
598
            }
599
            else
600
            {
601
                return;
602
            }
603
        }
604
 
605
        //
606
        // Advance to the next character.
607
        //
608
        pcStr++;
609
    }
610
}
611
 
612
//*****************************************************************************
613
//
614
//! Displays an image on the OLED display.
615
//!
616
//! \param pucImage is a pointer to the image data.
617
//! \param ulX is the horizontal position to display this image, specified in
618
//! columns from the left edge of the display.
619
//! \param ulY is the vertical position to display this image, specified in
620
//! rows from the top of the display.
621
//! \param ulWidth is the width of the image, specified in columns.
622
//! \param ulHeight is the height of the image, specified in rows.
623
//!
624
//! This function will display a bitmap graphic on the display.  Because of the
625
//! format of the display RAM, the starting column (\e ulX) and the number of
626
//! columns (\e ulWidth) must be an integer multiple of two.
627
//!
628
//! The image data is organized with the first row of image data appearing left
629
//! to right, followed immediately by the second row of image data.  Each byte
630
//! contains the data for two columns in the current row, with the leftmost
631
//! column being contained in bits 7:4 and the rightmost column being contained
632
//! in bits 3:0.
633
//!
634
//! For example, an image six columns wide and seven scan lines tall would
635
//! be arranged as follows (showing how the twenty one bytes of the image would
636
//! appear on the display):
637
//!
638
//! \verbatim
639
//!     +-------------------+-------------------+-------------------+
640
//!     |      Byte 0       |      Byte 1       |      Byte 2       |
641
//!     +---------+---------+---------+---------+---------+---------+
642
//!     | 7 6 5 4 | 3 2 1 0 | 7 6 5 4 | 3 2 1 0 | 7 6 5 4 | 3 2 1 0 |
643
//!     +---------+---------+---------+---------+---------+---------+
644
//!     |      Byte 3       |      Byte 4       |      Byte 5       |
645
//!     +---------+---------+---------+---------+---------+---------+
646
//!     | 7 6 5 4 | 3 2 1 0 | 7 6 5 4 | 3 2 1 0 | 7 6 5 4 | 3 2 1 0 |
647
//!     +---------+---------+---------+---------+---------+---------+
648
//!     |      Byte 6       |      Byte 7       |      Byte 8       |
649
//!     +---------+---------+---------+---------+---------+---------+
650
//!     | 7 6 5 4 | 3 2 1 0 | 7 6 5 4 | 3 2 1 0 | 7 6 5 4 | 3 2 1 0 |
651
//!     +---------+---------+---------+---------+---------+---------+
652
//!     |      Byte 9       |      Byte 10      |      Byte 11      |
653
//!     +---------+---------+---------+---------+---------+---------+
654
//!     | 7 6 5 4 | 3 2 1 0 | 7 6 5 4 | 3 2 1 0 | 7 6 5 4 | 3 2 1 0 |
655
//!     +---------+---------+---------+---------+---------+---------+
656
//!     |      Byte 12      |      Byte 13      |      Byte 14      |
657
//!     +---------+---------+---------+---------+---------+---------+
658
//!     | 7 6 5 4 | 3 2 1 0 | 7 6 5 4 | 3 2 1 0 | 7 6 5 4 | 3 2 1 0 |
659
//!     +---------+---------+---------+---------+---------+---------+
660
//!     |      Byte 15      |      Byte 16      |      Byte 17      |
661
//!     +---------+---------+---------+---------+---------+---------+
662
//!     | 7 6 5 4 | 3 2 1 0 | 7 6 5 4 | 3 2 1 0 | 7 6 5 4 | 3 2 1 0 |
663
//!     +---------+---------+---------+---------+---------+---------+
664
//!     |      Byte 18      |      Byte 19      |      Byte 20      |
665
//!     +---------+---------+---------+---------+---------+---------+
666
//!     | 7 6 5 4 | 3 2 1 0 | 7 6 5 4 | 3 2 1 0 | 7 6 5 4 | 3 2 1 0 |
667
//!     +---------+---------+---------+---------+---------+---------+
668
//! \endverbatim
669
//!
670
//! This function is contained in <tt>rit128x96x4.c</tt>, with
671
//! <tt>rit128x96x4.h</tt> containing the API definition for use by
672
//! applications.
673
//!
674
//! \return None.
675
//
676
//*****************************************************************************
677
void
678
RIT128x96x4ImageDraw(const unsigned char *pucImage, unsigned long ulX,
679
                     unsigned long ulY, unsigned long ulWidth,
680
                     unsigned long ulHeight)
681
{
682
    //
683
    // Check the arguments.
684
    //
685
    ASSERT(ulX < 128);
686
    ASSERT((ulX & 1) == 0);
687
    ASSERT(ulY < 96);
688
    ASSERT((ulX + ulWidth) <= 128);
689
    ASSERT((ulY + ulHeight) <= 96);
690
    ASSERT((ulWidth & 1) == 0);
691
 
692
    //
693
    // Setup a window starting at the specified column and row, and ending
694
    // at the column + width and row+height.
695
    //
696
    g_pucBuffer[0] = 0x15;
697
    g_pucBuffer[1] = ulX / 2;
698
    g_pucBuffer[2] = (ulX + ulWidth - 2) / 2;
699
    RITWriteCommand(g_pucBuffer, 3);
700
    g_pucBuffer[0] = 0x75;
701
    g_pucBuffer[1] = ulY;
702
    g_pucBuffer[2] = ulY + ulHeight - 1;
703
    RITWriteCommand(g_pucBuffer, 3);
704
    RITWriteCommand(g_pucRIT128x96x4HorizontalInc,
705
                    sizeof(g_pucRIT128x96x4HorizontalInc));
706
 
707
    //
708
    // Loop while there are more rows to display.
709
    //
710
    while(ulHeight--)
711
    {
712
        //
713
        // Write this row of image data.
714
        //
715
        RITWriteData(pucImage, (ulWidth / 2));
716
 
717
        //
718
        // Advance to the next row of the image.
719
        //
720
        pucImage += (ulWidth / 2);
721
    }
722
}
723
 
724
//*****************************************************************************
725
//
726
//! Enable the SSI component of the OLED display driver.
727
//!
728
//! \param ulFrequency specifies the SSI Clock Frequency to be used.
729
//!
730
//! This function initializes the SSI interface to the OLED display.
731
//!
732
//! This function is contained in <tt>rit128x96x4.c</tt>, with
733
//! <tt>rit128x96x4.h</tt> containing the API definition for use by
734
//! applications.
735
//!
736
//! \return None.
737
//
738
//*****************************************************************************
739
void
740
RIT128x96x4Enable(unsigned long ulFrequency)
741
{
742
    unsigned long ulTemp;
743
 
744
    //
745
    // Disable the SSI port.
746
    //
747
    SSIDisable(SSI0_BASE);
748
 
749
    //
750
    // Configure the SSI0 port for master mode.
751
    //
752
    SSIConfig(SSI0_BASE, SSI_FRF_MOTO_MODE_2, SSI_MODE_MASTER, ulFrequency, 8);
753
 
754
    //
755
    // (Re)Enable SSI control of the FSS pin.
756
    //
757
    GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_3);
758
    GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_STRENGTH_8MA,
759
                     GPIO_PIN_TYPE_STD_WPU);
760
 
761
    //
762
    // Enable the SSI port.
763
    //
764
    SSIEnable(SSI0_BASE);
765
 
766
    //
767
    // Drain the receive fifo.
768
    //
769
    while(SSIDataNonBlockingGet(SSI0_BASE, &ulTemp) != 0)
770
    {
771
    }
772
 
773
    //
774
    // Indicate that the RIT driver can use the SSI Port.
775
    //
776
    g_bSSIEnabled = true;
777
}
778
 
779
//*****************************************************************************
780
//
781
//! Enable the SSI component of the OLED display driver.
782
//!
783
//! This function initializes the SSI interface to the OLED display.
784
//!
785
//! This function is contained in <tt>rit128x96x4.c</tt>, with
786
//! <tt>rit128x96x4.h</tt> containing the API definition for use by
787
//! applications.
788
//!
789
//! \return None.
790
//
791
//*****************************************************************************
792
void
793
RIT128x96x4Disable(void)
794
{
795
    unsigned long ulTemp;
796
 
797
    //
798
    // Indicate that the RIT driver can no longer use the SSI Port.
799
    //
800
    g_bSSIEnabled = false;
801
 
802
    //
803
    // Drain the receive fifo.
804
    //
805
    while(SSIDataNonBlockingGet(SSI0_BASE, &ulTemp) != 0)
806
    {
807
    }
808
 
809
    //
810
    // Disable the SSI port.
811
    //
812
    SSIDisable(SSI0_BASE);
813
 
814
    //
815
    // Disable SSI control of the FSS pin.
816
    //
817
    GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_3);
818
    GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_STRENGTH_8MA,
819
                     GPIO_PIN_TYPE_STD_WPU);
820
    GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_PIN_3);
821
}
822
 
823
//*****************************************************************************
824
//
825
//! Initialize the OLED display.
826
//!
827
//! \param ulFrequency specifies the SSI Clock Frequency to be used.
828
//!
829
//! This function initializes the SSI interface to the OLED display and
830
//! configures the SSD1329 controller on the panel.
831
//!
832
//! This function is contained in <tt>rit128x96x4.c</tt>, with
833
//! <tt>rit128x96x4.h</tt> containing the API definition for use by
834
//! applications.
835
//!
836
//! \return None.
837
//
838
//*****************************************************************************
839
void
840
RIT128x96x4Init(unsigned long ulFrequency)
841
{
842
    unsigned long ulIdx;
843
 
844
 
845
        /* Determine which board is being used. */
846
        if( SysCtlPeripheralPresent( SYSCTL_PERIPH_ETH ) )
847
        {
848
                /* Ethernet is present, we must be using the LM3S8962 EK. */
849
                ulGPIOId = LM3S8962_SYSCTL_PERIPH_GPIO_OLEDDC;
850
                ulGPIOBase = LM3S8962_GPIO_OLEDDC_BASE;
851
                ulOLEDDC_PIN = GPIO_PIN_6;
852
                ulOLEDEN_PIN = GPIO_PIN_7;
853
        }
854
        else
855
        {
856
                /* Ethernet is not present, we must be using the LM3S1968 EK. */
857
                ulGPIOId = LM3S1968_SYSCTL_PERIPH_GPIO_OLEDDC;
858
                ulGPIOBase = LM3S1968_GPIO_OLEDDC_BASE;
859
                ulOLEDDC_PIN = GPIO_PIN_2;
860
                ulOLEDEN_PIN = GPIO_PIN_3;
861
        }
862
 
863
    //
864
    // Enable the SSI0 and GPIO port blocks as they are needed by this driver.
865
    //
866
    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
867
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
868
    SysCtlPeripheralEnable(ulGPIOId);
869
 
870
    //
871
    // Configure the SSI0CLK and SSIOTX pins for SSI operation.
872
    //
873
    GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_5);
874
    GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_5,
875
                     GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD_WPU);
876
 
877
    //
878
    // Configure the GPIO port pin used as a D/Cn signal for OLED device,
879
    // and the port pin used to enable power to the OLED panel.
880
    //
881
    GPIOPinTypeGPIOOutput(ulGPIOBase, ulOLEDDC_PIN | ulOLEDEN_PIN);
882
    GPIOPadConfigSet(ulGPIOBase, ulOLEDDC_PIN | ulOLEDEN_PIN,
883
                     GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
884
    GPIOPinWrite(ulGPIOBase, ulOLEDDC_PIN | ulOLEDEN_PIN,
885
                 ulOLEDDC_PIN | ulOLEDEN_PIN);
886
 
887
    //
888
    // Configure and enable the SSI0 port for master mode.
889
    //
890
    RIT128x96x4Enable(ulFrequency);
891
 
892
    //
893
    // Clear the frame buffer.
894
    //
895
    RIT128x96x4Clear();
896
 
897
    //
898
    // Initialize the SSD1329 controller.  Loop through the initialization
899
    // sequence array, sending each command "string" to the controller.
900
    //
901
    for(ulIdx = 0; ulIdx < sizeof(g_pucRIT128x96x4Init);
902
        ulIdx += g_pucRIT128x96x4Init[ulIdx] + 1)
903
    {
904
        //
905
        // Send this command.
906
        //
907
        RITWriteCommand(g_pucRIT128x96x4Init + ulIdx + 1,
908
                        g_pucRIT128x96x4Init[ulIdx] - 1);
909
    }
910
}
911
 
912
//*****************************************************************************
913
//
914
//! Turns on the OLED display.
915
//!
916
//! This function will turn on the OLED display, causing it to display the
917
//! contents of its internal frame buffer.
918
//!
919
//! This function is contained in <tt>rit128x96x4.c</tt>, with
920
//! <tt>rit128x96x4.h</tt> containing the API definition for use by
921
//! applications.
922
//!
923
//! \return None.
924
//
925
//*****************************************************************************
926
void
927
RIT128x96x4DisplayOn(void)
928
{
929
    unsigned long ulIdx;
930
 
931
    //
932
    // Initialize the SSD1329 controller.  Loop through the initialization
933
    // sequence array, sending each command "string" to the controller.
934
    //
935
    for(ulIdx = 0; ulIdx < sizeof(g_pucRIT128x96x4Init);
936
        ulIdx += g_pucRIT128x96x4Init[ulIdx] + 1)
937
    {
938
        //
939
        // Send this command.
940
        //
941
        RITWriteCommand(g_pucRIT128x96x4Init + ulIdx + 1,
942
                        g_pucRIT128x96x4Init[ulIdx] - 1);
943
    }
944
}
945
 
946
//*****************************************************************************
947
//
948
//! Turns off the OLED display.
949
//!
950
//! This function will turn off the OLED display.  This will stop the scanning
951
//! of the panel and turn off the on-chip DC-DC converter, preventing damage to
952
//! the panel due to burn-in (it has similar characters to a CRT in this
953
//! respect).
954
//!
955
//! This function is contained in <tt>rit128x96x4.c</tt>, with
956
//! <tt>rit128x96x4.h</tt> containing the API definition for use by
957
//! applications.
958
//!
959
//! \return None.
960
//
961
//*****************************************************************************
962
void
963
RIT128x96x4DisplayOff(void)
964
{
965
    static const unsigned char pucCommand1[] =
966
    {
967
        0xAE, 0xe3
968
    };
969
 
970
    //
971
    // Put the display to sleep.
972
    //
973
    RITWriteCommand(pucCommand1, sizeof(pucCommand1));
974
}
975
 
976
//*****************************************************************************
977
//
978
// Close the Doxygen group.
979
//! @}
980
//
981
//*****************************************************************************

powered by: WebSVN 2.1.0

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