Arduino style GUI

Committer:
jonebuckman
Date:
Wed Feb 27 22:34:06 2019 +0000
Revision:
4:d353b314d244
Parent:
0:90962b684403
Updated writeCommand and writeData.

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 SSD1351_SPI_H
jonebuckman 0:90962b684403 18 #define SSD1351_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 /** SSD1351_SPI class.
jonebuckman 0:90962b684403 24 * Used for controlling an SSD1351-based OLED display connected to SPI.
jonebuckman 0:90962b684403 25 */
jonebuckman 0:90962b684403 26 class SSD1351_SPI : public Display
jonebuckman 0:90962b684403 27 {
jonebuckman 0:90962b684403 28 public:
jonebuckman 0:90962b684403 29
jonebuckman 0:90962b684403 30 /** Create an SSD1351 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 SSD1351_SPI(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName dc);
jonebuckman 0:90962b684403 39
jonebuckman 0:90962b684403 40 /** Probe for the SSD1351 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 SSD1351
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 SSD1351
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 SSD1351
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 /** Draw a single pixel at the specified coordinates
jonebuckman 0:90962b684403 65 *
jonebuckman 0:90962b684403 66 * @param x The X coordinate.
jonebuckman 0:90962b684403 67 * @param y The Y coordinate.
jonebuckman 0:90962b684403 68 * @param c The color of the pixel as a 32-bit ARGB value.
jonebuckman 0:90962b684403 69 */
jonebuckman 0:90962b684403 70 virtual void drawPixel(int x, int y, unsigned int c);
jonebuckman 0:90962b684403 71
jonebuckman 0:90962b684403 72 private:
jonebuckman 0:90962b684403 73 //Commands
jonebuckman 0:90962b684403 74 enum Command {
jonebuckman 0:90962b684403 75 CMD_SETCOLUMN = 0x15,
jonebuckman 0:90962b684403 76 CMD_SETROW = 0x75,
jonebuckman 0:90962b684403 77 CMD_WRITERAM = 0x5C,
jonebuckman 0:90962b684403 78 CMD_READRAM = 0x5D,
jonebuckman 0:90962b684403 79 CMD_SETREMAP = 0xA0,
jonebuckman 0:90962b684403 80 CMD_STARTLINE = 0xA1,
jonebuckman 0:90962b684403 81 CMD_DISPLAYOFFSET = 0xA2,
jonebuckman 0:90962b684403 82 CMD_DISPLAYALLOFF = 0xA4,
jonebuckman 0:90962b684403 83 CMD_DISPLAYALLON = 0xA5,
jonebuckman 0:90962b684403 84 CMD_NORMALDISPLAY = 0xA6,
jonebuckman 0:90962b684403 85 CMD_INVERTDISPLAY = 0xA7,
jonebuckman 0:90962b684403 86 CMD_FUNCTIONSELECT = 0xAB,
jonebuckman 0:90962b684403 87 CMD_DISPLAYOFF = 0xAE,
jonebuckman 0:90962b684403 88 CMD_DISPLAYON = 0xAF,
jonebuckman 0:90962b684403 89 CMD_PRECHARGE = 0xB1,
jonebuckman 0:90962b684403 90 CMD_DISPLAYENHANCE = 0xB2,
jonebuckman 0:90962b684403 91 CMD_CLOCKDIV = 0xB3,
jonebuckman 0:90962b684403 92 CMD_SETVSL = 0xB4,
jonebuckman 0:90962b684403 93 CMD_SETGPIO = 0xB5,
jonebuckman 0:90962b684403 94 CMD_PRECHARGE2 = 0xB6,
jonebuckman 0:90962b684403 95 CMD_SETGRAY = 0xB8,
jonebuckman 0:90962b684403 96 CMD_USELUT = 0xB9,
jonebuckman 0:90962b684403 97 CMD_PRECHARGELEVEL = 0xBB,
jonebuckman 0:90962b684403 98 CMD_VCOMH = 0xBE,
jonebuckman 0:90962b684403 99 CMD_CONTRASTABC = 0xC1,
jonebuckman 0:90962b684403 100 CMD_CONTRASTMASTER = 0xC7,
jonebuckman 0:90962b684403 101 CMD_MUXRATIO = 0xCA,
jonebuckman 0:90962b684403 102 CMD_COMMANDLOCK = 0xFD,
jonebuckman 0:90962b684403 103 CMD_HORIZSCROLL = 0x96,
jonebuckman 0:90962b684403 104 CMD_STOPSCROLL = 0x9E,
jonebuckman 0:90962b684403 105 CMD_STARTSCROLL = 0x9F
jonebuckman 0:90962b684403 106 };
jonebuckman 0:90962b684403 107
jonebuckman 0:90962b684403 108 //SPI interface variables
jonebuckman 0:90962b684403 109 SPI m_SPI;
jonebuckman 0:90962b684403 110 DigitalOut m_CS;
jonebuckman 0:90962b684403 111 DigitalOut m_DC;
jonebuckman 0:90962b684403 112
jonebuckman 0:90962b684403 113 //Caching variables
jonebuckman 0:90962b684403 114 int m_StartX;
jonebuckman 0:90962b684403 115 int m_StartY;
jonebuckman 0:90962b684403 116 int m_CursX;
jonebuckman 0:90962b684403 117 int m_CursY;
jonebuckman 0:90962b684403 118 char m_Cache[1024];
jonebuckman 0:90962b684403 119 int m_CacheIndex;
jonebuckman 0:90962b684403 120
jonebuckman 0:90962b684403 121 //Command and data helpers
jonebuckman 0:90962b684403 122 void writeCommand(char command);
jonebuckman 0:90962b684403 123 void writeData(char data);
jonebuckman 0:90962b684403 124 };
jonebuckman 0:90962b684403 125
jonebuckman 0:90962b684403 126 #endif