EAOLEDExample
« Back to documentation index
Show/hide line numbers
EAOLED.cpp Source File
EAOLED.cpp
00001
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
00030 command(0x02);
00031 command(0x12);
00032 command(0x40);
00033 command(0x2e);
00034 command(0x81);
00035 command(0x32);
00036 command(0x82);
00037 command(0x80);
00038 command(0xa1);
00039 command(0xa6);
00040 command(0xa8);
00041 command(0x3F);
00042 command(0xd3);
00043 command(0x40);
00044 command(0xad);
00045 command(0x8E);
00046 command(0xc8);
00047 command(0xd5);
00048 command(0xf0);
00049 command(0xd8);
00050 command(0x05);
00051 command(0xd9);
00052 command(0xF1);
00053 command(0xda);
00054 command(0x12);
00055 command(0xdb);
00056 command(0x34);
00057 command(0x91);
00058 command(0x3f);
00059 command(0x3f);
00060 command(0x3f);
00061 command(0x3f);
00062 command(0xaf);
00063 command(0xa4);
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
00095
00096
00097
00098
00099
00100
00101