Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: EAOLED_HelloWorld EA_BigBen NetClock_aitendoOLED_from_EA_and_nucho
EAOLED.cpp
00001 /* mbed Embedded Artists OLED library, as found on the LPCXpresso Baseboard 00002 * Copyright (c) 2010, sford 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy 00005 * of this software and associated documentation files (the "Software"), to deal 00006 * in the Software without restriction, including without limitation the rights 00007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 * copies of the Software, and to permit persons to whom the Software is 00009 * furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included in 00012 * all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 * THE SOFTWARE. 00021 */ 00022 00023 #include "EAOLED.h" 00024 #include "mbed.h" 00025 00026 EAOLED::EAOLED(PinName mosi, PinName dnc, PinName sclk, PinName cs, PinName power) 00027 : _spi(mosi, NC, sclk), _data(dnc), _cs(cs), _power(power) { 00028 reset(); 00029 } 00030 00031 void EAOLED::command(int value) { 00032 _data = 0; 00033 _cs = 0; 00034 _spi.write(value); 00035 _cs = 1; 00036 } 00037 00038 void EAOLED::data(int value) { 00039 _data = 1; 00040 _cs = 0; 00041 _spi.write(value); 00042 _cs = 1; 00043 } 00044 00045 void EAOLED::reset() { 00046 _power = 0; 00047 _cs = 1; 00048 00049 // Startup sequence recommended by embedded artists baseboard reference code 00050 command(0x02); // set low column address 00051 command(0x12); // set high column address 00052 command(0x40); // display start set 00053 command(0x2e); // stop horzontal scroll 00054 command(0x81); // set contrast control register 00055 command(0x32); // 00056 command(0x82); // brightness for color banks 00057 command(0x80); // display on 00058 command(0xa1); // set segment re-map 00059 command(0xa6); // set normal/inverse display 00060 command(0xa8); // set multiplex ratio 00061 command(0x3F); // 00062 command(0xd3); // set display offset 00063 command(0x40); // 00064 command(0xad); // set dc-dc on/off 00065 command(0x8E); // 00066 command(0xc8); // set com output scan direction 00067 command(0xd5); // set display clock divide ratio/oscillator/frequency 00068 command(0xf0); // 00069 command(0xd8); // set area color mode on/off & low power display mode 00070 command(0x05); // 00071 command(0xd9); // set pre-charge period 00072 command(0xF1); // 00073 command(0xda); // set com pins hardware configuration 00074 command(0x12); // 00075 command(0xdb); // set vcom deselect level 00076 command(0x34); // 00077 command(0x91); // set look up table for area color 00078 command(0x3f); // 00079 command(0x3f); // 00080 command(0x3f); // 00081 command(0x3f); // 00082 command(0xaf); // display on 00083 command(0xa4); // display on 00084 00085 wait_us(10); 00086 00087 _power = 1; 00088 } 00089 00090 #define OLED_DISPLAY_WIDTH 96 00091 #define OLED_DISPLAY_HEIGHT 64 00092 00093 void EAOLED::pixel(int x, int y, int colour) { 00094 int page = y >> 3; 00095 int address = 18 + x; 00096 00097 int lo = (address >> 0) & 0x0F; 00098 int hi = (address >> 4) | 0x10; 00099 int mask = 1 << (y & 0x7); 00100 int byte = page * OLED_DISPLAY_WIDTH + x; 00101 00102 if(colour) { 00103 framebuffer[byte] |= mask; 00104 } else { 00105 framebuffer[byte] &= ~mask; 00106 } 00107 00108 command(0xB0 + page); 00109 command(lo); 00110 command(hi); 00111 data(framebuffer[byte]); 00112 } 00113 00114 /*void EAOLED::cls() { 00115 for(int y=0; y<64; y++) { 00116 for (int x=0; x<96; x++) { 00117 pixel(x, y, 0xFFFFFF); 00118 } 00119 } 00120 }*/ 00121
Generated on Tue Jul 12 2022 18:31:07 by
1.7.2