Simon Ford
/
EAOLEDExample
A test example using the OLED display on the Embedded Artists Xpresso baseboard
Embed:
(wiki syntax)
Show/hide line numbers
EAOLED.cpp
00001 // test library for Embedded Artists OLED used on Xpresso Baseboard 00002 00003 #include "EAOLED.h" 00004 #include "mbed.h" 00005 00006 EAOLED::EAOLED(PinName mosi, PinName dnc, PinName sclk, PinName cs, PinName power) 00007 : _spi(mosi, NC, sclk), _data(dnc), _cs(cs), _power(power) { 00008 reset(); 00009 } 00010 00011 void EAOLED::command(int value) { 00012 _data = 0; 00013 _cs = 0; 00014 _spi.write(value); 00015 _cs = 1; 00016 } 00017 00018 void EAOLED::data(int value) { 00019 _data = 1; 00020 _cs = 0; 00021 _spi.write(value); 00022 _cs = 1; 00023 } 00024 00025 void EAOLED::reset() { 00026 _power = 0; 00027 _cs = 1; 00028 00029 // Startup sequence recommended by embedded artists baseboard reference code 00030 command(0x02); // set low column address 00031 command(0x12); // set high column address 00032 command(0x40); // display start set 00033 command(0x2e); // stop horzontal scroll 00034 command(0x81); // set contrast control register 00035 command(0x32); // 00036 command(0x82); // brightness for color banks 00037 command(0x80); // display on 00038 command(0xa1); // set segment re-map 00039 command(0xa6); // set normal/inverse display 00040 command(0xa8); // set multiplex ratio 00041 command(0x3F); // 00042 command(0xd3); // set display offset 00043 command(0x40); // 00044 command(0xad); // set dc-dc on/off 00045 command(0x8E); // 00046 command(0xc8); // set com output scan direction 00047 command(0xd5); // set display clock divide ratio/oscillator/frequency 00048 command(0xf0); // 00049 command(0xd8); // set area color mode on/off & low power display mode 00050 command(0x05); // 00051 command(0xd9); // set pre-charge period 00052 command(0xF1); // 00053 command(0xda); // set com pins hardware configuration 00054 command(0x12); // 00055 command(0xdb); // set vcom deselect level 00056 command(0x34); // 00057 command(0x91); // set look up table for area color 00058 command(0x3f); // 00059 command(0x3f); // 00060 command(0x3f); // 00061 command(0x3f); // 00062 command(0xaf); // display on 00063 command(0xa4); // display on 00064 00065 wait_us(10); 00066 00067 _power = 1; 00068 } 00069 00070 #define OLED_DISPLAY_WIDTH 96 00071 #define OLED_DISPLAY_HEIGHT 64 00072 00073 void EAOLED::pixel(int x, int y, int colour) { 00074 int page = y >> 3; 00075 int address = 18 + x; 00076 00077 int lo = (address >> 0) & 0x0F; 00078 int hi = (address >> 4) | 0x10; 00079 int mask = 1 << (y & 0x7); 00080 int byte = page * OLED_DISPLAY_WIDTH + x; 00081 00082 if(colour) { 00083 framebuffer[byte] |= mask; 00084 } else { 00085 framebuffer[byte] &= ~mask; 00086 } 00087 00088 command(0xB0 + page); 00089 command(lo); 00090 command(hi); 00091 data(framebuffer[byte]); 00092 } 00093 00094 /*void EAOLED::cls() { 00095 for(int y=0; y<64; y++) { 00096 for (int x=0; x<96; x++) { 00097 pixel(x, y, 0xFFFFFF); 00098 } 00099 } 00100 }*/ 00101
Generated on Wed Jul 13 2022 10:17:56 by 1.7.2