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 20:05:29 2014 +0000
Revision:
2:bbfc18022ee5
Parent:
1:f7003ec66a51
Numerous changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
neilt6 1:f7003ec66a51 1 /* NeatGUI Library
neilt6 1:f7003ec66a51 2 * Copyright (c) 2013 Neil Thiessen
neilt6 1:f7003ec66a51 3 *
neilt6 1:f7003ec66a51 4 * Licensed under the Apache License, Version 2.0 (the "License");
neilt6 1:f7003ec66a51 5 * you may not use this file except in compliance with the License.
neilt6 1:f7003ec66a51 6 * You may obtain a copy of the License at
neilt6 1:f7003ec66a51 7 *
neilt6 1:f7003ec66a51 8 * http://www.apache.org/licenses/LICENSE-2.0
neilt6 1:f7003ec66a51 9 *
neilt6 1:f7003ec66a51 10 * Unless required by applicable law or agreed to in writing, software
neilt6 1:f7003ec66a51 11 * distributed under the License is distributed on an "AS IS" BASIS,
neilt6 1:f7003ec66a51 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
neilt6 1:f7003ec66a51 13 * See the License for the specific language governing permissions and
neilt6 1:f7003ec66a51 14 * limitations under the License.
neilt6 1:f7003ec66a51 15 */
neilt6 1:f7003ec66a51 16
neilt6 1:f7003ec66a51 17 #ifndef SSD1306_I2C_H
neilt6 1:f7003ec66a51 18 #define SSD1306_I2C_H
neilt6 1:f7003ec66a51 19
neilt6 1:f7003ec66a51 20 #include "mbed.h"
neilt6 1:f7003ec66a51 21 #include "Display.h"
neilt6 1:f7003ec66a51 22
neilt6 1:f7003ec66a51 23 /** SSD1306_I2C class.
neilt6 1:f7003ec66a51 24 * Used for controlling an SSD1306-based OLED display connected to i2c.
neilt6 1:f7003ec66a51 25 */
neilt6 1:f7003ec66a51 26 class SSD1306_I2C : public Display
neilt6 1:f7003ec66a51 27 {
neilt6 1:f7003ec66a51 28 public:
neilt6 1:f7003ec66a51 29 /** Represents the different I2C address possibilities for the SSD1306
neilt6 1:f7003ec66a51 30 */
neilt6 1:f7003ec66a51 31 enum Address {
neilt6 1:f7003ec66a51 32 ADDRESS_0 = (0x3C << 1), /**< SA0 pin = 0 */
neilt6 1:f7003ec66a51 33 ADDRESS_1 = (0x3D << 1), /**< SA0 pin = 1 */
neilt6 1:f7003ec66a51 34 };
neilt6 1:f7003ec66a51 35
neilt6 1:f7003ec66a51 36 /** Create an SSD1306 object connected to the specified I2C pins with the specified I2C slave address
neilt6 1:f7003ec66a51 37 *
neilt6 1:f7003ec66a51 38 * @param sda The I2C data pin.
neilt6 1:f7003ec66a51 39 * @param scl The I2C clock pin.
neilt6 1:f7003ec66a51 40 * @param addr The I2C slave address.
neilt6 1:f7003ec66a51 41 */
neilt6 1:f7003ec66a51 42 SSD1306_I2C(PinName sda, PinName scl, Address addr);
neilt6 1:f7003ec66a51 43
neilt6 1:f7003ec66a51 44 /** Create an SSD1306 object connected to the specified SPI pins with the specified /CS and DC pins
neilt6 1:f7003ec66a51 45 *
neilt6 1:f7003ec66a51 46 * @param mosi The SPI data out pin.
neilt6 1:f7003ec66a51 47 * @param miso The SPI data in pin.
neilt6 1:f7003ec66a51 48 * @param sclk The SPI clock pin.
neilt6 1:f7003ec66a51 49 * @param sclk The SPI chip select pin.
neilt6 1:f7003ec66a51 50 * @param sclk The data/command pin.
neilt6 1:f7003ec66a51 51 */
neilt6 1:f7003ec66a51 52 //SSD1306_SPI(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName dc);
neilt6 1:f7003ec66a51 53
neilt6 1:f7003ec66a51 54 /** Probe for the SSD1306 and initialize it if present
neilt6 1:f7003ec66a51 55 *
neilt6 1:f7003ec66a51 56 * @returns
neilt6 1:f7003ec66a51 57 * 'true' if the device exists on the bus,
neilt6 1:f7003ec66a51 58 * 'false' if the device doesn't exist on the bus.
neilt6 1:f7003ec66a51 59 */
neilt6 1:f7003ec66a51 60 virtual bool open();
neilt6 1:f7003ec66a51 61
neilt6 1:f7003ec66a51 62 /** Send the buffer to the SSD1306
neilt6 1:f7003ec66a51 63 */
neilt6 2:bbfc18022ee5 64 virtual void flush();
neilt6 1:f7003ec66a51 65
neilt6 1:f7003ec66a51 66 /** Get the current state of the SSD1306
neilt6 1:f7003ec66a51 67 *
neilt6 1:f7003ec66a51 68 * @returns The current state as a Display::State enum.
neilt6 1:f7003ec66a51 69 */
neilt6 1:f7003ec66a51 70 virtual Display::State state();
neilt6 1:f7003ec66a51 71
neilt6 1:f7003ec66a51 72 /** Set the state of the SSD1306
neilt6 1:f7003ec66a51 73 *
neilt6 1:f7003ec66a51 74 * @param mode The new state as a Display::State enum.
neilt6 1:f7003ec66a51 75 */
neilt6 1:f7003ec66a51 76 virtual void state(State s);
neilt6 1:f7003ec66a51 77
neilt6 1:f7003ec66a51 78 //void display();
neilt6 1:f7003ec66a51 79
neilt6 1:f7003ec66a51 80 /** Draw a single pixel at the specified coordinates
neilt6 1:f7003ec66a51 81 *
neilt6 1:f7003ec66a51 82 * @param x The X coordinate.
neilt6 1:f7003ec66a51 83 * @param y The Y coordinate.
neilt6 1:f7003ec66a51 84 * @param c The color of the pixel as a 32-bit ARGB value.
neilt6 1:f7003ec66a51 85 */
neilt6 1:f7003ec66a51 86 virtual void drawPixel(int x, int y, unsigned int c);
neilt6 1:f7003ec66a51 87
neilt6 1:f7003ec66a51 88 private:
neilt6 1:f7003ec66a51 89 //Commands
neilt6 1:f7003ec66a51 90 enum Command {
neilt6 1:f7003ec66a51 91 CMD_SETCONTRAST = 0x81,
neilt6 1:f7003ec66a51 92 CMD_DISPLAYALLON_RESUME = 0xA4,
neilt6 1:f7003ec66a51 93 CMD_DISPLAYALLON = 0xA5,
neilt6 1:f7003ec66a51 94 CMD_NORMALDISPLAY = 0xA6,
neilt6 1:f7003ec66a51 95 CMD_INVERTDISPLAY = 0xA7,
neilt6 1:f7003ec66a51 96 CMD_DISPLAYOFF = 0xAE,
neilt6 1:f7003ec66a51 97 CMD_DISPLAYON = 0xAF,
neilt6 1:f7003ec66a51 98 CMD_SETDISPLAYOFFSET = 0xD3,
neilt6 1:f7003ec66a51 99 CMD_SETCOMPINS = 0xDA,
neilt6 1:f7003ec66a51 100 CMD_SETVCOMDETECT = 0xDB,
neilt6 1:f7003ec66a51 101 CMD_SETDISPLAYCLOCKDIV = 0xD5,
neilt6 1:f7003ec66a51 102 CMD_SETPRECHARGE = 0xD9,
neilt6 1:f7003ec66a51 103 CMD_SETMULTIPLEX = 0xA8,
neilt6 1:f7003ec66a51 104 CMD_SETLOWCOLUMN = 0x00,
neilt6 1:f7003ec66a51 105 CMD_SETHIGHCOLUMN = 0x10,
neilt6 1:f7003ec66a51 106 CMD_SETSTARTLINE = 0x40,
neilt6 1:f7003ec66a51 107 CMD_MEMORYMODE = 0x20,
neilt6 1:f7003ec66a51 108 CMD_COMSCANINC = 0xC0,
neilt6 1:f7003ec66a51 109 CMD_COMSCANDEC = 0xC8,
neilt6 1:f7003ec66a51 110 CMD_SEGREMAP = 0xA0,
neilt6 1:f7003ec66a51 111 CMD_CHARGEPUMP = 0x8D,
neilt6 1:f7003ec66a51 112 CMD_CHARGEPUMPON = 0x14,
neilt6 1:f7003ec66a51 113 CMD_CHARGEPUMPOFF = 0x10,
neilt6 1:f7003ec66a51 114 CMD_ACTIVATE_SCROLL = 0x2F,
neilt6 1:f7003ec66a51 115 CMD_DEACTIVATE_SCROLL = 0x2E,
neilt6 1:f7003ec66a51 116 CMD_SET_VERTICAL_SCROLL_AREA = 0xA3,
neilt6 1:f7003ec66a51 117 CMD_RIGHT_HORIZONTAL_SCROLL = 0x26,
neilt6 1:f7003ec66a51 118 CMD_LEFT_HORIZONTAL_SCROLL = 0x27,
neilt6 1:f7003ec66a51 119 CMD_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL = 0x29,
neilt6 1:f7003ec66a51 120 CMD_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL = 0x2A
neilt6 1:f7003ec66a51 121 };
neilt6 1:f7003ec66a51 122
neilt6 1:f7003ec66a51 123 //Control bytes for the I2C interface
neilt6 1:f7003ec66a51 124 enum I2CControlByte {
neilt6 1:f7003ec66a51 125 CONTROL_COMMAND = 0x00,
neilt6 1:f7003ec66a51 126 CONTROL_DATA = 0x40
neilt6 1:f7003ec66a51 127 };
neilt6 1:f7003ec66a51 128
neilt6 1:f7003ec66a51 129 //I2C interface variables
neilt6 1:f7003ec66a51 130 I2C m_I2C;
neilt6 1:f7003ec66a51 131 const int m_ADDR;
neilt6 1:f7003ec66a51 132
neilt6 1:f7003ec66a51 133 //Back buffer
neilt6 1:f7003ec66a51 134 char m_Buffer[1025];
neilt6 1:f7003ec66a51 135
neilt6 1:f7003ec66a51 136 //Command and data helpers
neilt6 1:f7003ec66a51 137 void writeCommand(char command);
neilt6 1:f7003ec66a51 138 void writeData(char data);
neilt6 1:f7003ec66a51 139 };
neilt6 1:f7003ec66a51 140
neilt6 1:f7003ec66a51 141 #endif