A simple yet powerful library for controlling graphical displays. Multiple display controllers are supported using inheritance.
Dependents: mbed_rifletool Hexi_Bubble_Game Hexi_Catch-the-dot_Game Hexi_Acceleromagnetic_Synth
SSD1351_SPI.h
00001 /* NeatGUI Library 00002 * Copyright (c) 2013 Neil Thiessen 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef SSD1351_SPI_H 00018 #define SSD1351_SPI_H 00019 00020 #include "mbed.h" 00021 #include "Display.h" 00022 00023 /** SSD1351_SPI class. 00024 * Used for controlling an SSD1351-based OLED display connected to SPI. 00025 */ 00026 class SSD1351_SPI : public Display 00027 { 00028 public: 00029 00030 /** Create an SSD1351 object connected to the specified SPI pins with the specified /CS and DC pins 00031 * 00032 * @param mosi The SPI data out pin. 00033 * @param miso The SPI data in pin. 00034 * @param sclk The SPI clock pin. 00035 * @param cs The SPI chip select pin. 00036 * @param dc The data/command pin. 00037 */ 00038 SSD1351_SPI(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName dc); 00039 00040 /** Probe for the SSD1351 and initialize it if present 00041 * 00042 * @returns 00043 * 'true' if the device exists on the bus, 00044 * 'false' if the device doesn't exist on the bus. 00045 */ 00046 virtual bool open(); 00047 00048 /** Send the buffer to the SSD1351 00049 */ 00050 virtual void flush(); 00051 00052 /** Get the current state of the SSD1351 00053 * 00054 * @returns The current state as a Display::State enum. 00055 */ 00056 virtual Display::State state(); 00057 00058 /** Set the state of the SSD1351 00059 * 00060 * @param mode The new state as a Display::State enum. 00061 */ 00062 virtual void state(State s); 00063 00064 /** Draw a single pixel at the specified coordinates 00065 * 00066 * @param x The X coordinate. 00067 * @param y The Y coordinate. 00068 * @param c The color of the pixel as a 32-bit ARGB value. 00069 */ 00070 virtual void drawPixel(int x, int y, unsigned int c); 00071 00072 private: 00073 //Commands 00074 enum Command { 00075 CMD_SETCOLUMN = 0x15, 00076 CMD_SETROW = 0x75, 00077 CMD_WRITERAM = 0x5C, 00078 CMD_READRAM = 0x5D, 00079 CMD_SETREMAP = 0xA0, 00080 CMD_STARTLINE = 0xA1, 00081 CMD_DISPLAYOFFSET = 0xA2, 00082 CMD_DISPLAYALLOFF = 0xA4, 00083 CMD_DISPLAYALLON = 0xA5, 00084 CMD_NORMALDISPLAY = 0xA6, 00085 CMD_INVERTDISPLAY = 0xA7, 00086 CMD_FUNCTIONSELECT = 0xAB, 00087 CMD_DISPLAYOFF = 0xAE, 00088 CMD_DISPLAYON = 0xAF, 00089 CMD_PRECHARGE = 0xB1, 00090 CMD_DISPLAYENHANCE = 0xB2, 00091 CMD_CLOCKDIV = 0xB3, 00092 CMD_SETVSL = 0xB4, 00093 CMD_SETGPIO = 0xB5, 00094 CMD_PRECHARGE2 = 0xB6, 00095 CMD_SETGRAY = 0xB8, 00096 CMD_USELUT = 0xB9, 00097 CMD_PRECHARGELEVEL = 0xBB, 00098 CMD_VCOMH = 0xBE, 00099 CMD_CONTRASTABC = 0xC1, 00100 CMD_CONTRASTMASTER = 0xC7, 00101 CMD_MUXRATIO = 0xCA, 00102 CMD_COMMANDLOCK = 0xFD, 00103 CMD_HORIZSCROLL = 0x96, 00104 CMD_STOPSCROLL = 0x9E, 00105 CMD_STARTSCROLL = 0x9F 00106 }; 00107 00108 //SPI interface variables 00109 SPI m_SPI; 00110 DigitalOut m_CS; 00111 DigitalOut m_DC; 00112 00113 //Caching variables 00114 int m_StartX; 00115 int m_StartY; 00116 int m_CursX; 00117 int m_CursY; 00118 char m_Cache[1024]; 00119 int m_CacheIndex; 00120 00121 //Command and data helpers 00122 void writeCommand(char command); 00123 void writeData(char data); 00124 }; 00125 00126 #endif
Generated on Tue Jul 12 2022 20:26:18 by 1.7.2