Library for the OLED display, as used on the mbed LPCXpresso Baseboard

Dependencies:   mbed

Dependents:   EAOLED_HelloWorld EA_BigBen NetClock_aitendoOLED_from_EA_and_nucho

Committer:
simon
Date:
Sun Jun 06 19:33:24 2010 +0000
Revision:
0:8fe8b0fe5134

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:8fe8b0fe5134 1 /* mbed Embedded Artists OLED library, as found on the LPCXpresso Baseboard
simon 0:8fe8b0fe5134 2 * Copyright (c) 2010, sford
simon 0:8fe8b0fe5134 3 *
simon 0:8fe8b0fe5134 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
simon 0:8fe8b0fe5134 5 * of this software and associated documentation files (the "Software"), to deal
simon 0:8fe8b0fe5134 6 * in the Software without restriction, including without limitation the rights
simon 0:8fe8b0fe5134 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
simon 0:8fe8b0fe5134 8 * copies of the Software, and to permit persons to whom the Software is
simon 0:8fe8b0fe5134 9 * furnished to do so, subject to the following conditions:
simon 0:8fe8b0fe5134 10 *
simon 0:8fe8b0fe5134 11 * The above copyright notice and this permission notice shall be included in
simon 0:8fe8b0fe5134 12 * all copies or substantial portions of the Software.
simon 0:8fe8b0fe5134 13 *
simon 0:8fe8b0fe5134 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
simon 0:8fe8b0fe5134 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
simon 0:8fe8b0fe5134 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
simon 0:8fe8b0fe5134 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
simon 0:8fe8b0fe5134 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
simon 0:8fe8b0fe5134 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
simon 0:8fe8b0fe5134 20 * THE SOFTWARE.
simon 0:8fe8b0fe5134 21 */
simon 0:8fe8b0fe5134 22
simon 0:8fe8b0fe5134 23 #include "EAOLED.h"
simon 0:8fe8b0fe5134 24 #include "mbed.h"
simon 0:8fe8b0fe5134 25
simon 0:8fe8b0fe5134 26 EAOLED::EAOLED(PinName mosi, PinName dnc, PinName sclk, PinName cs, PinName power)
simon 0:8fe8b0fe5134 27 : _spi(mosi, NC, sclk), _data(dnc), _cs(cs), _power(power) {
simon 0:8fe8b0fe5134 28 reset();
simon 0:8fe8b0fe5134 29 }
simon 0:8fe8b0fe5134 30
simon 0:8fe8b0fe5134 31 void EAOLED::command(int value) {
simon 0:8fe8b0fe5134 32 _data = 0;
simon 0:8fe8b0fe5134 33 _cs = 0;
simon 0:8fe8b0fe5134 34 _spi.write(value);
simon 0:8fe8b0fe5134 35 _cs = 1;
simon 0:8fe8b0fe5134 36 }
simon 0:8fe8b0fe5134 37
simon 0:8fe8b0fe5134 38 void EAOLED::data(int value) {
simon 0:8fe8b0fe5134 39 _data = 1;
simon 0:8fe8b0fe5134 40 _cs = 0;
simon 0:8fe8b0fe5134 41 _spi.write(value);
simon 0:8fe8b0fe5134 42 _cs = 1;
simon 0:8fe8b0fe5134 43 }
simon 0:8fe8b0fe5134 44
simon 0:8fe8b0fe5134 45 void EAOLED::reset() {
simon 0:8fe8b0fe5134 46 _power = 0;
simon 0:8fe8b0fe5134 47 _cs = 1;
simon 0:8fe8b0fe5134 48
simon 0:8fe8b0fe5134 49 // Startup sequence recommended by embedded artists baseboard reference code
simon 0:8fe8b0fe5134 50 command(0x02); // set low column address
simon 0:8fe8b0fe5134 51 command(0x12); // set high column address
simon 0:8fe8b0fe5134 52 command(0x40); // display start set
simon 0:8fe8b0fe5134 53 command(0x2e); // stop horzontal scroll
simon 0:8fe8b0fe5134 54 command(0x81); // set contrast control register
simon 0:8fe8b0fe5134 55 command(0x32); //
simon 0:8fe8b0fe5134 56 command(0x82); // brightness for color banks
simon 0:8fe8b0fe5134 57 command(0x80); // display on
simon 0:8fe8b0fe5134 58 command(0xa1); // set segment re-map
simon 0:8fe8b0fe5134 59 command(0xa6); // set normal/inverse display
simon 0:8fe8b0fe5134 60 command(0xa8); // set multiplex ratio
simon 0:8fe8b0fe5134 61 command(0x3F); //
simon 0:8fe8b0fe5134 62 command(0xd3); // set display offset
simon 0:8fe8b0fe5134 63 command(0x40); //
simon 0:8fe8b0fe5134 64 command(0xad); // set dc-dc on/off
simon 0:8fe8b0fe5134 65 command(0x8E); //
simon 0:8fe8b0fe5134 66 command(0xc8); // set com output scan direction
simon 0:8fe8b0fe5134 67 command(0xd5); // set display clock divide ratio/oscillator/frequency
simon 0:8fe8b0fe5134 68 command(0xf0); //
simon 0:8fe8b0fe5134 69 command(0xd8); // set area color mode on/off & low power display mode
simon 0:8fe8b0fe5134 70 command(0x05); //
simon 0:8fe8b0fe5134 71 command(0xd9); // set pre-charge period
simon 0:8fe8b0fe5134 72 command(0xF1); //
simon 0:8fe8b0fe5134 73 command(0xda); // set com pins hardware configuration
simon 0:8fe8b0fe5134 74 command(0x12); //
simon 0:8fe8b0fe5134 75 command(0xdb); // set vcom deselect level
simon 0:8fe8b0fe5134 76 command(0x34); //
simon 0:8fe8b0fe5134 77 command(0x91); // set look up table for area color
simon 0:8fe8b0fe5134 78 command(0x3f); //
simon 0:8fe8b0fe5134 79 command(0x3f); //
simon 0:8fe8b0fe5134 80 command(0x3f); //
simon 0:8fe8b0fe5134 81 command(0x3f); //
simon 0:8fe8b0fe5134 82 command(0xaf); // display on
simon 0:8fe8b0fe5134 83 command(0xa4); // display on
simon 0:8fe8b0fe5134 84
simon 0:8fe8b0fe5134 85 wait_us(10);
simon 0:8fe8b0fe5134 86
simon 0:8fe8b0fe5134 87 _power = 1;
simon 0:8fe8b0fe5134 88 }
simon 0:8fe8b0fe5134 89
simon 0:8fe8b0fe5134 90 #define OLED_DISPLAY_WIDTH 96
simon 0:8fe8b0fe5134 91 #define OLED_DISPLAY_HEIGHT 64
simon 0:8fe8b0fe5134 92
simon 0:8fe8b0fe5134 93 void EAOLED::pixel(int x, int y, int colour) {
simon 0:8fe8b0fe5134 94 int page = y >> 3;
simon 0:8fe8b0fe5134 95 int address = 18 + x;
simon 0:8fe8b0fe5134 96
simon 0:8fe8b0fe5134 97 int lo = (address >> 0) & 0x0F;
simon 0:8fe8b0fe5134 98 int hi = (address >> 4) | 0x10;
simon 0:8fe8b0fe5134 99 int mask = 1 << (y & 0x7);
simon 0:8fe8b0fe5134 100 int byte = page * OLED_DISPLAY_WIDTH + x;
simon 0:8fe8b0fe5134 101
simon 0:8fe8b0fe5134 102 if(colour) {
simon 0:8fe8b0fe5134 103 framebuffer[byte] |= mask;
simon 0:8fe8b0fe5134 104 } else {
simon 0:8fe8b0fe5134 105 framebuffer[byte] &= ~mask;
simon 0:8fe8b0fe5134 106 }
simon 0:8fe8b0fe5134 107
simon 0:8fe8b0fe5134 108 command(0xB0 + page);
simon 0:8fe8b0fe5134 109 command(lo);
simon 0:8fe8b0fe5134 110 command(hi);
simon 0:8fe8b0fe5134 111 data(framebuffer[byte]);
simon 0:8fe8b0fe5134 112 }
simon 0:8fe8b0fe5134 113
simon 0:8fe8b0fe5134 114 /*void EAOLED::cls() {
simon 0:8fe8b0fe5134 115 for(int y=0; y<64; y++) {
simon 0:8fe8b0fe5134 116 for (int x=0; x<96; x++) {
simon 0:8fe8b0fe5134 117 pixel(x, y, 0xFFFFFF);
simon 0:8fe8b0fe5134 118 }
simon 0:8fe8b0fe5134 119 }
simon 0:8fe8b0fe5134 120 }*/
simon 0:8fe8b0fe5134 121