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 SSD1306_SPI_H
jonebuckman 0:90962b684403 18 #define SSD1306_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 /** SSD1306_SPI class.
jonebuckman 0:90962b684403 24 * Used for controlling an SSD1306-based OLED display connected to SPI.
jonebuckman 0:90962b684403 25 */
jonebuckman 0:90962b684403 26 class SSD1306_SPI : public Display
jonebuckman 0:90962b684403 27 {
jonebuckman 0:90962b684403 28 public:
jonebuckman 0:90962b684403 29
jonebuckman 0:90962b684403 30 /** Create an SSD1306 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 sclk The SPI chip select pin.
jonebuckman 0:90962b684403 36 * @param sclk The data/command pin.
jonebuckman 0:90962b684403 37 */
jonebuckman 0:90962b684403 38 SSD1306_SPI(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName dc);
jonebuckman 0:90962b684403 39
jonebuckman 0:90962b684403 40 /** Probe for the SSD1306 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 SSD1306
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 SSD1306
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 SSD1306
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 //void display();
jonebuckman 0:90962b684403 65
jonebuckman 0:90962b684403 66 /** Draw a single pixel at the specified coordinates
jonebuckman 0:90962b684403 67 *
jonebuckman 0:90962b684403 68 * @param x The X coordinate.
jonebuckman 0:90962b684403 69 * @param y The Y coordinate.
jonebuckman 0:90962b684403 70 * @param c The color of the pixel as a 32-bit ARGB value.
jonebuckman 0:90962b684403 71 */
jonebuckman 0:90962b684403 72 virtual void drawPixel(int x, int y, unsigned int c);
jonebuckman 0:90962b684403 73
jonebuckman 0:90962b684403 74 private:
jonebuckman 0:90962b684403 75 //Commands
jonebuckman 0:90962b684403 76 enum Command {
jonebuckman 0:90962b684403 77 CMD_SETCONTRAST = 0x81,
jonebuckman 0:90962b684403 78 CMD_DISPLAYALLON_RESUME = 0xA4,
jonebuckman 0:90962b684403 79 CMD_DISPLAYALLON = 0xA5,
jonebuckman 0:90962b684403 80 CMD_NORMALDISPLAY = 0xA6,
jonebuckman 0:90962b684403 81 CMD_INVERTDISPLAY = 0xA7,
jonebuckman 0:90962b684403 82 CMD_DISPLAYOFF = 0xAE,
jonebuckman 0:90962b684403 83 CMD_DISPLAYON = 0xAF,
jonebuckman 0:90962b684403 84 CMD_SETDISPLAYOFFSET = 0xD3,
jonebuckman 0:90962b684403 85 CMD_SETCOMPINS = 0xDA,
jonebuckman 0:90962b684403 86 CMD_SETVCOMDETECT = 0xDB,
jonebuckman 0:90962b684403 87 CMD_SETDISPLAYCLOCKDIV = 0xD5,
jonebuckman 0:90962b684403 88 CMD_SETPRECHARGE = 0xD9,
jonebuckman 0:90962b684403 89 CMD_SETMULTIPLEX = 0xA8,
jonebuckman 0:90962b684403 90 CMD_SETLOWCOLUMN = 0x00,
jonebuckman 0:90962b684403 91 CMD_SETHIGHCOLUMN = 0x10,
jonebuckman 0:90962b684403 92 CMD_SETSTARTLINE = 0x40,
jonebuckman 0:90962b684403 93 CMD_MEMORYMODE = 0x20,
jonebuckman 0:90962b684403 94 CMD_COMSCANINC = 0xC0,
jonebuckman 0:90962b684403 95 CMD_COMSCANDEC = 0xC8,
jonebuckman 0:90962b684403 96 CMD_SEGREMAP = 0xA0,
jonebuckman 0:90962b684403 97 CMD_CHARGEPUMP = 0x8D,
jonebuckman 0:90962b684403 98 CMD_CHARGEPUMPON = 0x14,
jonebuckman 0:90962b684403 99 CMD_CHARGEPUMPOFF = 0x10,
jonebuckman 0:90962b684403 100 CMD_ACTIVATE_SCROLL = 0x2F,
jonebuckman 0:90962b684403 101 CMD_DEACTIVATE_SCROLL = 0x2E,
jonebuckman 0:90962b684403 102 CMD_SET_VERTICAL_SCROLL_AREA = 0xA3,
jonebuckman 0:90962b684403 103 CMD_RIGHT_HORIZONTAL_SCROLL = 0x26,
jonebuckman 0:90962b684403 104 CMD_LEFT_HORIZONTAL_SCROLL = 0x27,
jonebuckman 0:90962b684403 105 CMD_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL = 0x29,
jonebuckman 0:90962b684403 106 CMD_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL = 0x2A
jonebuckman 0:90962b684403 107 };
jonebuckman 0:90962b684403 108
jonebuckman 0:90962b684403 109 //SPI interface variables
jonebuckman 0:90962b684403 110 SPI m_SPI;
jonebuckman 0:90962b684403 111 DigitalOut m_CS;
jonebuckman 0:90962b684403 112 DigitalOut m_DC;
jonebuckman 0:90962b684403 113
jonebuckman 0:90962b684403 114 //Back buffer
jonebuckman 0:90962b684403 115 char m_Buffer[1024];
jonebuckman 0:90962b684403 116
jonebuckman 0:90962b684403 117 //Command and data helpers
jonebuckman 0:90962b684403 118 void writeCommand(char command);
jonebuckman 0:90962b684403 119 void writeData(char data);
jonebuckman 0:90962b684403 120 };
jonebuckman 0:90962b684403 121
jonebuckman 0:90962b684403 122 #endif