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

NOTE: This library is in beta right now. As far as I know, everything here works, but there are many features that are lacking so far. Most notably containers, button handling, and display drivers other than the SSD1306.

Committer:
neilt6
Date:
Tue May 27 21:41:28 2014 +0000
Revision:
3:a8f72d4864e6
Parent:
2:bbfc18022ee5
Syntax improvements

Who changed what in which revision?

UserRevisionLine numberNew contents of line
neilt6 2:bbfc18022ee5 1 /* NeatGUI Library
neilt6 2:bbfc18022ee5 2 * Copyright (c) 2013 Neil Thiessen
neilt6 2:bbfc18022ee5 3 *
neilt6 2:bbfc18022ee5 4 * Licensed under the Apache License, Version 2.0 (the "License");
neilt6 2:bbfc18022ee5 5 * you may not use this file except in compliance with the License.
neilt6 2:bbfc18022ee5 6 * You may obtain a copy of the License at
neilt6 2:bbfc18022ee5 7 *
neilt6 2:bbfc18022ee5 8 * http://www.apache.org/licenses/LICENSE-2.0
neilt6 2:bbfc18022ee5 9 *
neilt6 2:bbfc18022ee5 10 * Unless required by applicable law or agreed to in writing, software
neilt6 2:bbfc18022ee5 11 * distributed under the License is distributed on an "AS IS" BASIS,
neilt6 2:bbfc18022ee5 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
neilt6 2:bbfc18022ee5 13 * See the License for the specific language governing permissions and
neilt6 2:bbfc18022ee5 14 * limitations under the License.
neilt6 2:bbfc18022ee5 15 */
neilt6 2:bbfc18022ee5 16
neilt6 2:bbfc18022ee5 17 #ifndef SSD1351_SPI_H
neilt6 2:bbfc18022ee5 18 #define SSD1351_SPI_H
neilt6 2:bbfc18022ee5 19
neilt6 2:bbfc18022ee5 20 #include "mbed.h"
neilt6 2:bbfc18022ee5 21 #include "Display.h"
neilt6 2:bbfc18022ee5 22
neilt6 2:bbfc18022ee5 23 /** SSD1351_SPI class.
neilt6 2:bbfc18022ee5 24 * Used for controlling an SSD1351-based OLED display connected to SPI.
neilt6 2:bbfc18022ee5 25 */
neilt6 2:bbfc18022ee5 26 class SSD1351_SPI : public Display
neilt6 2:bbfc18022ee5 27 {
neilt6 2:bbfc18022ee5 28 public:
neilt6 2:bbfc18022ee5 29
neilt6 2:bbfc18022ee5 30 /** Create an SSD1351 object connected to the specified SPI pins with the specified /CS and DC pins
neilt6 2:bbfc18022ee5 31 *
neilt6 2:bbfc18022ee5 32 * @param mosi The SPI data out pin.
neilt6 2:bbfc18022ee5 33 * @param miso The SPI data in pin.
neilt6 2:bbfc18022ee5 34 * @param sclk The SPI clock pin.
neilt6 2:bbfc18022ee5 35 * @param cs The SPI chip select pin.
neilt6 2:bbfc18022ee5 36 * @param dc The data/command pin.
neilt6 2:bbfc18022ee5 37 */
neilt6 2:bbfc18022ee5 38 SSD1351_SPI(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName dc);
neilt6 2:bbfc18022ee5 39
neilt6 2:bbfc18022ee5 40 /** Probe for the SSD1351 and initialize it if present
neilt6 2:bbfc18022ee5 41 *
neilt6 2:bbfc18022ee5 42 * @returns
neilt6 2:bbfc18022ee5 43 * 'true' if the device exists on the bus,
neilt6 2:bbfc18022ee5 44 * 'false' if the device doesn't exist on the bus.
neilt6 2:bbfc18022ee5 45 */
neilt6 2:bbfc18022ee5 46 virtual bool open();
neilt6 2:bbfc18022ee5 47
neilt6 2:bbfc18022ee5 48 /** Send the buffer to the SSD1351
neilt6 2:bbfc18022ee5 49 */
neilt6 2:bbfc18022ee5 50 virtual void flush();
neilt6 2:bbfc18022ee5 51
neilt6 2:bbfc18022ee5 52 /** Get the current state of the SSD1351
neilt6 2:bbfc18022ee5 53 *
neilt6 2:bbfc18022ee5 54 * @returns The current state as a Display::State enum.
neilt6 2:bbfc18022ee5 55 */
neilt6 2:bbfc18022ee5 56 virtual Display::State state();
neilt6 2:bbfc18022ee5 57
neilt6 2:bbfc18022ee5 58 /** Set the state of the SSD1351
neilt6 2:bbfc18022ee5 59 *
neilt6 2:bbfc18022ee5 60 * @param mode The new state as a Display::State enum.
neilt6 2:bbfc18022ee5 61 */
neilt6 2:bbfc18022ee5 62 virtual void state(State s);
neilt6 2:bbfc18022ee5 63
neilt6 2:bbfc18022ee5 64 /** Draw a single pixel at the specified coordinates
neilt6 2:bbfc18022ee5 65 *
neilt6 2:bbfc18022ee5 66 * @param x The X coordinate.
neilt6 2:bbfc18022ee5 67 * @param y The Y coordinate.
neilt6 2:bbfc18022ee5 68 * @param c The color of the pixel as a 32-bit ARGB value.
neilt6 2:bbfc18022ee5 69 */
neilt6 2:bbfc18022ee5 70 virtual void drawPixel(int x, int y, unsigned int c);
neilt6 2:bbfc18022ee5 71
neilt6 2:bbfc18022ee5 72 private:
neilt6 2:bbfc18022ee5 73 //Commands
neilt6 2:bbfc18022ee5 74 enum Command {
neilt6 2:bbfc18022ee5 75 CMD_SETCOLUMN = 0x15,
neilt6 2:bbfc18022ee5 76 CMD_SETROW = 0x75,
neilt6 2:bbfc18022ee5 77 CMD_WRITERAM = 0x5C,
neilt6 2:bbfc18022ee5 78 CMD_READRAM = 0x5D,
neilt6 2:bbfc18022ee5 79 CMD_SETREMAP = 0xA0,
neilt6 2:bbfc18022ee5 80 CMD_STARTLINE = 0xA1,
neilt6 2:bbfc18022ee5 81 CMD_DISPLAYOFFSET = 0xA2,
neilt6 2:bbfc18022ee5 82 CMD_DISPLAYALLOFF = 0xA4,
neilt6 2:bbfc18022ee5 83 CMD_DISPLAYALLON = 0xA5,
neilt6 2:bbfc18022ee5 84 CMD_NORMALDISPLAY = 0xA6,
neilt6 2:bbfc18022ee5 85 CMD_INVERTDISPLAY = 0xA7,
neilt6 2:bbfc18022ee5 86 CMD_FUNCTIONSELECT = 0xAB,
neilt6 2:bbfc18022ee5 87 CMD_DISPLAYOFF = 0xAE,
neilt6 2:bbfc18022ee5 88 CMD_DISPLAYON = 0xAF,
neilt6 2:bbfc18022ee5 89 CMD_PRECHARGE = 0xB1,
neilt6 2:bbfc18022ee5 90 CMD_DISPLAYENHANCE = 0xB2,
neilt6 2:bbfc18022ee5 91 CMD_CLOCKDIV = 0xB3,
neilt6 2:bbfc18022ee5 92 CMD_SETVSL = 0xB4,
neilt6 2:bbfc18022ee5 93 CMD_SETGPIO = 0xB5,
neilt6 2:bbfc18022ee5 94 CMD_PRECHARGE2 = 0xB6,
neilt6 2:bbfc18022ee5 95 CMD_SETGRAY = 0xB8,
neilt6 2:bbfc18022ee5 96 CMD_USELUT = 0xB9,
neilt6 2:bbfc18022ee5 97 CMD_PRECHARGELEVEL = 0xBB,
neilt6 2:bbfc18022ee5 98 CMD_VCOMH = 0xBE,
neilt6 2:bbfc18022ee5 99 CMD_CONTRASTABC = 0xC1,
neilt6 2:bbfc18022ee5 100 CMD_CONTRASTMASTER = 0xC7,
neilt6 2:bbfc18022ee5 101 CMD_MUXRATIO = 0xCA,
neilt6 2:bbfc18022ee5 102 CMD_COMMANDLOCK = 0xFD,
neilt6 2:bbfc18022ee5 103 CMD_HORIZSCROLL = 0x96,
neilt6 2:bbfc18022ee5 104 CMD_STOPSCROLL = 0x9E,
neilt6 2:bbfc18022ee5 105 CMD_STARTSCROLL = 0x9F
neilt6 2:bbfc18022ee5 106 };
neilt6 2:bbfc18022ee5 107
neilt6 2:bbfc18022ee5 108 //SPI interface variables
neilt6 2:bbfc18022ee5 109 SPI m_SPI;
neilt6 2:bbfc18022ee5 110 DigitalOut m_CS;
neilt6 2:bbfc18022ee5 111 DigitalOut m_DC;
neilt6 2:bbfc18022ee5 112
neilt6 2:bbfc18022ee5 113 //Caching variables
neilt6 2:bbfc18022ee5 114 int m_StartX;
neilt6 2:bbfc18022ee5 115 int m_StartY;
neilt6 2:bbfc18022ee5 116 int m_CursX;
neilt6 2:bbfc18022ee5 117 int m_CursY;
neilt6 2:bbfc18022ee5 118 char m_Cache[1024];
neilt6 2:bbfc18022ee5 119 int m_CacheIndex;
neilt6 2:bbfc18022ee5 120
neilt6 2:bbfc18022ee5 121 //Command and data helpers
neilt6 2:bbfc18022ee5 122 void writeCommand(char command);
neilt6 2:bbfc18022ee5 123 void writeData(char data);
neilt6 2:bbfc18022ee5 124 };
neilt6 2:bbfc18022ee5 125
neilt6 2:bbfc18022ee5 126 #endif