A test example using the OLED display on the Embedded Artists Xpresso baseboard

Dependencies:   mbed

Committer:
simon
Date:
Sun Feb 28 16:04:59 2010 +0000
Revision:
0:f42b25503fd1

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:f42b25503fd1 1 // test library for Embedded Artists OLED used on Xpresso Baseboard
simon 0:f42b25503fd1 2
simon 0:f42b25503fd1 3 #include "EAOLED.h"
simon 0:f42b25503fd1 4 #include "mbed.h"
simon 0:f42b25503fd1 5
simon 0:f42b25503fd1 6 EAOLED::EAOLED(PinName mosi, PinName dnc, PinName sclk, PinName cs, PinName power)
simon 0:f42b25503fd1 7 : _spi(mosi, NC, sclk), _data(dnc), _cs(cs), _power(power) {
simon 0:f42b25503fd1 8 reset();
simon 0:f42b25503fd1 9 }
simon 0:f42b25503fd1 10
simon 0:f42b25503fd1 11 void EAOLED::command(int value) {
simon 0:f42b25503fd1 12 _data = 0;
simon 0:f42b25503fd1 13 _cs = 0;
simon 0:f42b25503fd1 14 _spi.write(value);
simon 0:f42b25503fd1 15 _cs = 1;
simon 0:f42b25503fd1 16 }
simon 0:f42b25503fd1 17
simon 0:f42b25503fd1 18 void EAOLED::data(int value) {
simon 0:f42b25503fd1 19 _data = 1;
simon 0:f42b25503fd1 20 _cs = 0;
simon 0:f42b25503fd1 21 _spi.write(value);
simon 0:f42b25503fd1 22 _cs = 1;
simon 0:f42b25503fd1 23 }
simon 0:f42b25503fd1 24
simon 0:f42b25503fd1 25 void EAOLED::reset() {
simon 0:f42b25503fd1 26 _power = 0;
simon 0:f42b25503fd1 27 _cs = 1;
simon 0:f42b25503fd1 28
simon 0:f42b25503fd1 29 // Startup sequence recommended by embedded artists baseboard reference code
simon 0:f42b25503fd1 30 command(0x02); // set low column address
simon 0:f42b25503fd1 31 command(0x12); // set high column address
simon 0:f42b25503fd1 32 command(0x40); // display start set
simon 0:f42b25503fd1 33 command(0x2e); // stop horzontal scroll
simon 0:f42b25503fd1 34 command(0x81); // set contrast control register
simon 0:f42b25503fd1 35 command(0x32); //
simon 0:f42b25503fd1 36 command(0x82); // brightness for color banks
simon 0:f42b25503fd1 37 command(0x80); // display on
simon 0:f42b25503fd1 38 command(0xa1); // set segment re-map
simon 0:f42b25503fd1 39 command(0xa6); // set normal/inverse display
simon 0:f42b25503fd1 40 command(0xa8); // set multiplex ratio
simon 0:f42b25503fd1 41 command(0x3F); //
simon 0:f42b25503fd1 42 command(0xd3); // set display offset
simon 0:f42b25503fd1 43 command(0x40); //
simon 0:f42b25503fd1 44 command(0xad); // set dc-dc on/off
simon 0:f42b25503fd1 45 command(0x8E); //
simon 0:f42b25503fd1 46 command(0xc8); // set com output scan direction
simon 0:f42b25503fd1 47 command(0xd5); // set display clock divide ratio/oscillator/frequency
simon 0:f42b25503fd1 48 command(0xf0); //
simon 0:f42b25503fd1 49 command(0xd8); // set area color mode on/off & low power display mode
simon 0:f42b25503fd1 50 command(0x05); //
simon 0:f42b25503fd1 51 command(0xd9); // set pre-charge period
simon 0:f42b25503fd1 52 command(0xF1); //
simon 0:f42b25503fd1 53 command(0xda); // set com pins hardware configuration
simon 0:f42b25503fd1 54 command(0x12); //
simon 0:f42b25503fd1 55 command(0xdb); // set vcom deselect level
simon 0:f42b25503fd1 56 command(0x34); //
simon 0:f42b25503fd1 57 command(0x91); // set look up table for area color
simon 0:f42b25503fd1 58 command(0x3f); //
simon 0:f42b25503fd1 59 command(0x3f); //
simon 0:f42b25503fd1 60 command(0x3f); //
simon 0:f42b25503fd1 61 command(0x3f); //
simon 0:f42b25503fd1 62 command(0xaf); // display on
simon 0:f42b25503fd1 63 command(0xa4); // display on
simon 0:f42b25503fd1 64
simon 0:f42b25503fd1 65 wait_us(10);
simon 0:f42b25503fd1 66
simon 0:f42b25503fd1 67 _power = 1;
simon 0:f42b25503fd1 68 }
simon 0:f42b25503fd1 69
simon 0:f42b25503fd1 70 #define OLED_DISPLAY_WIDTH 96
simon 0:f42b25503fd1 71 #define OLED_DISPLAY_HEIGHT 64
simon 0:f42b25503fd1 72
simon 0:f42b25503fd1 73 void EAOLED::pixel(int x, int y, int colour) {
simon 0:f42b25503fd1 74 int page = y >> 3;
simon 0:f42b25503fd1 75 int address = 18 + x;
simon 0:f42b25503fd1 76
simon 0:f42b25503fd1 77 int lo = (address >> 0) & 0x0F;
simon 0:f42b25503fd1 78 int hi = (address >> 4) | 0x10;
simon 0:f42b25503fd1 79 int mask = 1 << (y & 0x7);
simon 0:f42b25503fd1 80 int byte = page * OLED_DISPLAY_WIDTH + x;
simon 0:f42b25503fd1 81
simon 0:f42b25503fd1 82 if(colour) {
simon 0:f42b25503fd1 83 framebuffer[byte] |= mask;
simon 0:f42b25503fd1 84 } else {
simon 0:f42b25503fd1 85 framebuffer[byte] &= ~mask;
simon 0:f42b25503fd1 86 }
simon 0:f42b25503fd1 87
simon 0:f42b25503fd1 88 command(0xB0 + page);
simon 0:f42b25503fd1 89 command(lo);
simon 0:f42b25503fd1 90 command(hi);
simon 0:f42b25503fd1 91 data(framebuffer[byte]);
simon 0:f42b25503fd1 92 }
simon 0:f42b25503fd1 93
simon 0:f42b25503fd1 94 /*void EAOLED::cls() {
simon 0:f42b25503fd1 95 for(int y=0; y<64; y++) {
simon 0:f42b25503fd1 96 for (int x=0; x<96; x++) {
simon 0:f42b25503fd1 97 pixel(x, y, 0xFFFFFF);
simon 0:f42b25503fd1 98 }
simon 0:f42b25503fd1 99 }
simon 0:f42b25503fd1 100 }*/
simon 0:f42b25503fd1 101