Arduino style GUI

Committer:
jonebuckman
Date:
Fri May 06 16:51:15 2016 +0000
Revision:
0:90962b684403
Updated drivers.

Who changed what in which revision?

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