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_I2C_H
jonebuckman 0:90962b684403 18 #define SSD1306_I2C_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_I2C class.
jonebuckman 0:90962b684403 24 * Used for controlling an SSD1306-based OLED display connected to i2c.
jonebuckman 0:90962b684403 25 */
jonebuckman 0:90962b684403 26 class SSD1306_I2C : public Display
jonebuckman 0:90962b684403 27 {
jonebuckman 0:90962b684403 28 public:
jonebuckman 0:90962b684403 29 /** Represents the different I2C address possibilities for the SSD1306
jonebuckman 0:90962b684403 30 */
jonebuckman 0:90962b684403 31 enum Address {
jonebuckman 0:90962b684403 32 ADDRESS_0 = (0x3C << 1), /**< SA0 pin = 0 */
jonebuckman 0:90962b684403 33 ADDRESS_1 = (0x3D << 1), /**< SA0 pin = 1 */
jonebuckman 0:90962b684403 34 };
jonebuckman 0:90962b684403 35
jonebuckman 0:90962b684403 36 /** Create an SSD1306 object connected to the specified I2C pins with the specified I2C slave address
jonebuckman 0:90962b684403 37 *
jonebuckman 0:90962b684403 38 * @param sda The I2C data pin.
jonebuckman 0:90962b684403 39 * @param scl The I2C clock pin.
jonebuckman 0:90962b684403 40 * @param addr The I2C slave address.
jonebuckman 0:90962b684403 41 */
jonebuckman 0:90962b684403 42 SSD1306_I2C(PinName sda, PinName scl, Address addr);
jonebuckman 0:90962b684403 43
jonebuckman 0:90962b684403 44 /** Create an SSD1306 object connected to the specified SPI pins with the specified /CS and DC pins
jonebuckman 0:90962b684403 45 *
jonebuckman 0:90962b684403 46 * @param mosi The SPI data out pin.
jonebuckman 0:90962b684403 47 * @param miso The SPI data in pin.
jonebuckman 0:90962b684403 48 * @param sclk The SPI clock pin.
jonebuckman 0:90962b684403 49 * @param sclk The SPI chip select pin.
jonebuckman 0:90962b684403 50 * @param sclk The data/command pin.
jonebuckman 0:90962b684403 51 */
jonebuckman 0:90962b684403 52 //SSD1306_SPI(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName dc);
jonebuckman 0:90962b684403 53
jonebuckman 0:90962b684403 54 /** Probe for the SSD1306 and initialize it if present
jonebuckman 0:90962b684403 55 *
jonebuckman 0:90962b684403 56 * @returns
jonebuckman 0:90962b684403 57 * 'true' if the device exists on the bus,
jonebuckman 0:90962b684403 58 * 'false' if the device doesn't exist on the bus.
jonebuckman 0:90962b684403 59 */
jonebuckman 0:90962b684403 60 virtual bool open();
jonebuckman 0:90962b684403 61
jonebuckman 0:90962b684403 62 /** Send the buffer to the SSD1306
jonebuckman 0:90962b684403 63 */
jonebuckman 0:90962b684403 64 virtual void flush();
jonebuckman 0:90962b684403 65
jonebuckman 0:90962b684403 66 /** Get the current state of the SSD1306
jonebuckman 0:90962b684403 67 *
jonebuckman 0:90962b684403 68 * @returns The current state as a Display::State enum.
jonebuckman 0:90962b684403 69 */
jonebuckman 0:90962b684403 70 virtual Display::State state();
jonebuckman 0:90962b684403 71
jonebuckman 0:90962b684403 72 /** Set the state of the SSD1306
jonebuckman 0:90962b684403 73 *
jonebuckman 0:90962b684403 74 * @param mode The new state as a Display::State enum.
jonebuckman 0:90962b684403 75 */
jonebuckman 0:90962b684403 76 virtual void state(State s);
jonebuckman 0:90962b684403 77
jonebuckman 0:90962b684403 78 //void display();
jonebuckman 0:90962b684403 79
jonebuckman 0:90962b684403 80 /** Draw a single pixel at the specified coordinates
jonebuckman 0:90962b684403 81 *
jonebuckman 0:90962b684403 82 * @param x The X coordinate.
jonebuckman 0:90962b684403 83 * @param y The Y coordinate.
jonebuckman 0:90962b684403 84 * @param c The color of the pixel as a 32-bit ARGB value.
jonebuckman 0:90962b684403 85 */
jonebuckman 0:90962b684403 86 virtual void drawPixel(int x, int y, unsigned int c);
jonebuckman 0:90962b684403 87
jonebuckman 0:90962b684403 88 private:
jonebuckman 0:90962b684403 89 //Commands
jonebuckman 0:90962b684403 90 enum Command {
jonebuckman 0:90962b684403 91 CMD_SETCONTRAST = 0x81,
jonebuckman 0:90962b684403 92 CMD_DISPLAYALLON_RESUME = 0xA4,
jonebuckman 0:90962b684403 93 CMD_DISPLAYALLON = 0xA5,
jonebuckman 0:90962b684403 94 CMD_NORMALDISPLAY = 0xA6,
jonebuckman 0:90962b684403 95 CMD_INVERTDISPLAY = 0xA7,
jonebuckman 0:90962b684403 96 CMD_DISPLAYOFF = 0xAE,
jonebuckman 0:90962b684403 97 CMD_DISPLAYON = 0xAF,
jonebuckman 0:90962b684403 98 CMD_SETDISPLAYOFFSET = 0xD3,
jonebuckman 0:90962b684403 99 CMD_SETCOMPINS = 0xDA,
jonebuckman 0:90962b684403 100 CMD_SETVCOMDETECT = 0xDB,
jonebuckman 0:90962b684403 101 CMD_SETDISPLAYCLOCKDIV = 0xD5,
jonebuckman 0:90962b684403 102 CMD_SETPRECHARGE = 0xD9,
jonebuckman 0:90962b684403 103 CMD_SETMULTIPLEX = 0xA8,
jonebuckman 0:90962b684403 104 CMD_SETLOWCOLUMN = 0x00,
jonebuckman 0:90962b684403 105 CMD_SETHIGHCOLUMN = 0x10,
jonebuckman 0:90962b684403 106 CMD_SETSTARTLINE = 0x40,
jonebuckman 0:90962b684403 107 CMD_MEMORYMODE = 0x20,
jonebuckman 0:90962b684403 108 CMD_COMSCANINC = 0xC0,
jonebuckman 0:90962b684403 109 CMD_COMSCANDEC = 0xC8,
jonebuckman 0:90962b684403 110 CMD_SEGREMAP = 0xA0,
jonebuckman 0:90962b684403 111 CMD_CHARGEPUMP = 0x8D,
jonebuckman 0:90962b684403 112 CMD_CHARGEPUMPON = 0x14,
jonebuckman 0:90962b684403 113 CMD_CHARGEPUMPOFF = 0x10,
jonebuckman 0:90962b684403 114 CMD_ACTIVATE_SCROLL = 0x2F,
jonebuckman 0:90962b684403 115 CMD_DEACTIVATE_SCROLL = 0x2E,
jonebuckman 0:90962b684403 116 CMD_SET_VERTICAL_SCROLL_AREA = 0xA3,
jonebuckman 0:90962b684403 117 CMD_RIGHT_HORIZONTAL_SCROLL = 0x26,
jonebuckman 0:90962b684403 118 CMD_LEFT_HORIZONTAL_SCROLL = 0x27,
jonebuckman 0:90962b684403 119 CMD_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL = 0x29,
jonebuckman 0:90962b684403 120 CMD_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL = 0x2A
jonebuckman 0:90962b684403 121 };
jonebuckman 0:90962b684403 122
jonebuckman 0:90962b684403 123 //Control bytes for the I2C interface
jonebuckman 0:90962b684403 124 enum I2CControlByte {
jonebuckman 0:90962b684403 125 CONTROL_COMMAND = 0x00,
jonebuckman 0:90962b684403 126 CONTROL_DATA = 0x40
jonebuckman 0:90962b684403 127 };
jonebuckman 0:90962b684403 128
jonebuckman 0:90962b684403 129 //I2C interface variables
jonebuckman 0:90962b684403 130 I2C m_I2C;
jonebuckman 0:90962b684403 131 const int m_ADDR;
jonebuckman 0:90962b684403 132
jonebuckman 0:90962b684403 133 //Back buffer
jonebuckman 0:90962b684403 134 char m_Buffer[1025];
jonebuckman 0:90962b684403 135
jonebuckman 0:90962b684403 136 //Command and data helpers
jonebuckman 0:90962b684403 137 void writeCommand(char command);
jonebuckman 0:90962b684403 138 void writeData(char data);
jonebuckman 0:90962b684403 139 };
jonebuckman 0:90962b684403 140
jonebuckman 0:90962b684403 141 #endif