Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
EAQVGAOLED.h@0:ae3d20db48fc, 2011-02-09 (annotated)
- Committer:
- gbloice
- Date:
- Wed Feb 09 21:23:49 2011 +0000
- Revision:
- 0:ae3d20db48fc
- Child:
- 1:b23bfa1be0d9
Updated description
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| gbloice | 0:ae3d20db48fc | 1 | /* mbed library for driving the EA QVGA 2.8" OLED |
| gbloice | 0:ae3d20db48fc | 2 | * Copyright (c) Graham Bloice 2011 |
| gbloice | 0:ae3d20db48fc | 3 | * |
| gbloice | 0:ae3d20db48fc | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| gbloice | 0:ae3d20db48fc | 5 | * of this software and associated documentation files (the "Software"), to deal |
| gbloice | 0:ae3d20db48fc | 6 | * in the Software without restriction, including without limitation the rights |
| gbloice | 0:ae3d20db48fc | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| gbloice | 0:ae3d20db48fc | 8 | * copies of the Software, and to permit persons to whom the Software is |
| gbloice | 0:ae3d20db48fc | 9 | * furnished to do so, subject to the following conditions: |
| gbloice | 0:ae3d20db48fc | 10 | * |
| gbloice | 0:ae3d20db48fc | 11 | * The above copyright notice and this permission notice shall be included in |
| gbloice | 0:ae3d20db48fc | 12 | * all copies or substantial portions of the Software. |
| gbloice | 0:ae3d20db48fc | 13 | * |
| gbloice | 0:ae3d20db48fc | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| gbloice | 0:ae3d20db48fc | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| gbloice | 0:ae3d20db48fc | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| gbloice | 0:ae3d20db48fc | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| gbloice | 0:ae3d20db48fc | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| gbloice | 0:ae3d20db48fc | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| gbloice | 0:ae3d20db48fc | 20 | * THE SOFTWARE. |
| gbloice | 0:ae3d20db48fc | 21 | */ |
| gbloice | 0:ae3d20db48fc | 22 | |
| gbloice | 0:ae3d20db48fc | 23 | #ifndef MBED_EAQVGAOLED_H |
| gbloice | 0:ae3d20db48fc | 24 | #define MBED_EAQVGAOLED_H |
| gbloice | 0:ae3d20db48fc | 25 | |
| gbloice | 0:ae3d20db48fc | 26 | #include "mbed.h" |
| gbloice | 0:ae3d20db48fc | 27 | #include "GraphicsDisplay.h" |
| gbloice | 0:ae3d20db48fc | 28 | |
| gbloice | 0:ae3d20db48fc | 29 | #define BLACK 0x0000 /* 0, 0, 0 */ |
| gbloice | 0:ae3d20db48fc | 30 | #define NAVY 0x000F /* 0, 0, 128 */ |
| gbloice | 0:ae3d20db48fc | 31 | #define DARK_GREEN 0x03E0 /* 0, 128, 0 */ |
| gbloice | 0:ae3d20db48fc | 32 | #define DARK_CYAN 0x03EF /* 0, 128, 128 */ |
| gbloice | 0:ae3d20db48fc | 33 | #define MAROON 0x7800 /* 128, 0, 0 */ |
| gbloice | 0:ae3d20db48fc | 34 | #define PURPLE 0x780F /* 128, 0, 128 */ |
| gbloice | 0:ae3d20db48fc | 35 | #define OLIVE 0x7BE0 /* 128, 128, 0 */ |
| gbloice | 0:ae3d20db48fc | 36 | #define LIGHT_GRAY 0xC618 /* 192, 192, 192 */ |
| gbloice | 0:ae3d20db48fc | 37 | #define DARK_GRAY 0x7BEF /* 128, 128, 128 */ |
| gbloice | 0:ae3d20db48fc | 38 | #define BLUE 0x001F /* 0, 0, 255 */ |
| gbloice | 0:ae3d20db48fc | 39 | #define GREEN 0x07E0 /* 0, 255, 0 */ |
| gbloice | 0:ae3d20db48fc | 40 | #define CYAN 0x07FF /* 0, 255, 255 */ |
| gbloice | 0:ae3d20db48fc | 41 | #define RED 0xF800 /* 255, 0, 0 */ |
| gbloice | 0:ae3d20db48fc | 42 | #define MAGENTA 0xF81F /* 255, 0, 255 */ |
| gbloice | 0:ae3d20db48fc | 43 | #define YELLOW 0xFFE0 /* 255, 255, 0 */ |
| gbloice | 0:ae3d20db48fc | 44 | #define WHITE 0xFFFF /* 255, 255, 255 */ |
| gbloice | 0:ae3d20db48fc | 45 | |
| gbloice | 0:ae3d20db48fc | 46 | #define CURSOR_CLS 0 |
| gbloice | 0:ae3d20db48fc | 47 | #define CURSOR_UP 1 |
| gbloice | 0:ae3d20db48fc | 48 | #define CURSOR_DOWN 2 |
| gbloice | 0:ae3d20db48fc | 49 | #define CURSOR_LEFT 3 |
| gbloice | 0:ae3d20db48fc | 50 | #define CURSOR_RIGHT 4 |
| gbloice | 0:ae3d20db48fc | 51 | |
| gbloice | 0:ae3d20db48fc | 52 | /** EA QVGA OLED Display driver |
| gbloice | 0:ae3d20db48fc | 53 | * |
| gbloice | 0:ae3d20db48fc | 54 | * Uses SPI to drive the Embedded Artists 2.8" |
| gbloice | 0:ae3d20db48fc | 55 | * QVGA OLED panel |
| gbloice | 0:ae3d20db48fc | 56 | * |
| gbloice | 0:ae3d20db48fc | 57 | */ |
| gbloice | 0:ae3d20db48fc | 58 | class EAQVGAOLED : public GraphicsDisplay { |
| gbloice | 0:ae3d20db48fc | 59 | |
| gbloice | 0:ae3d20db48fc | 60 | public: |
| gbloice | 0:ae3d20db48fc | 61 | |
| gbloice | 0:ae3d20db48fc | 62 | // These are the functions required to support the base class |
| gbloice | 0:ae3d20db48fc | 63 | |
| gbloice | 0:ae3d20db48fc | 64 | /** Create an EA QVGA OLED object connected using |
| gbloice | 0:ae3d20db48fc | 65 | * the specified SPI port, and two output pins; |
| gbloice | 0:ae3d20db48fc | 66 | * the Chip Select pin and the Backlight pin. |
| gbloice | 0:ae3d20db48fc | 67 | * |
| gbloice | 0:ae3d20db48fc | 68 | * @param spiPort SPI port to use for data |
| gbloice | 0:ae3d20db48fc | 69 | * @param cs Pin to drive the display CS |
| gbloice | 0:ae3d20db48fc | 70 | * @param reset Pin to drive the display reset |
| gbloice | 0:ae3d20db48fc | 71 | * @param bl Pin to drive the display backlight |
| gbloice | 0:ae3d20db48fc | 72 | */ |
| gbloice | 0:ae3d20db48fc | 73 | EAQVGAOLED(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, PinName bl); |
| gbloice | 0:ae3d20db48fc | 74 | |
| gbloice | 0:ae3d20db48fc | 75 | /** Set a pixel to the specified colour |
| gbloice | 0:ae3d20db48fc | 76 | * |
| gbloice | 0:ae3d20db48fc | 77 | * @param x Pixel x position |
| gbloice | 0:ae3d20db48fc | 78 | * @param y Pixel y position |
| gbloice | 0:ae3d20db48fc | 79 | * @param colour Pixel colour |
| gbloice | 0:ae3d20db48fc | 80 | */ |
| gbloice | 0:ae3d20db48fc | 81 | virtual void pixel(int x, int y, int colour); |
| gbloice | 0:ae3d20db48fc | 82 | |
| gbloice | 0:ae3d20db48fc | 83 | /** Accessor to obtain the display width |
| gbloice | 0:ae3d20db48fc | 84 | * |
| gbloice | 0:ae3d20db48fc | 85 | * @return the width of the display in pixels |
| gbloice | 0:ae3d20db48fc | 86 | */ |
| gbloice | 0:ae3d20db48fc | 87 | virtual int width(void) { return 240; } |
| gbloice | 0:ae3d20db48fc | 88 | |
| gbloice | 0:ae3d20db48fc | 89 | /** Accessor to obtain the display height |
| gbloice | 0:ae3d20db48fc | 90 | * |
| gbloice | 0:ae3d20db48fc | 91 | * @return the height of the display in pixels |
| gbloice | 0:ae3d20db48fc | 92 | */ |
| gbloice | 0:ae3d20db48fc | 93 | virtual int height(void) { return 320; } |
| gbloice | 0:ae3d20db48fc | 94 | |
| gbloice | 0:ae3d20db48fc | 95 | /** Clear the screen |
| gbloice | 0:ae3d20db48fc | 96 | */ |
| gbloice | 0:ae3d20db48fc | 97 | virtual void cls() { fillRectangle(0, 0, width(), height(), _background); } |
| gbloice | 0:ae3d20db48fc | 98 | |
| gbloice | 0:ae3d20db48fc | 99 | /* No overrides for these functions |
| gbloice | 0:ae3d20db48fc | 100 | |
| gbloice | 0:ae3d20db48fc | 101 | virtual void window(int x, int y, int w, int h); |
| gbloice | 0:ae3d20db48fc | 102 | virtual void putp(int colour); |
| gbloice | 0:ae3d20db48fc | 103 | |
| gbloice | 0:ae3d20db48fc | 104 | virtual void fill(int x, int y, int w, int h, int colour); |
| gbloice | 0:ae3d20db48fc | 105 | virtual void blit(int x, int y, int w, int h, const int *colour); |
| gbloice | 0:ae3d20db48fc | 106 | virtual void blitbit(int x, int y, int w, int h, const char* colour); |
| gbloice | 0:ae3d20db48fc | 107 | |
| gbloice | 0:ae3d20db48fc | 108 | virtual void character(int column, int row, int c); |
| gbloice | 0:ae3d20db48fc | 109 | virtual int columns(); |
| gbloice | 0:ae3d20db48fc | 110 | virtual int rows(); |
| gbloice | 0:ae3d20db48fc | 111 | |
| gbloice | 0:ae3d20db48fc | 112 | */ |
| gbloice | 0:ae3d20db48fc | 113 | |
| gbloice | 0:ae3d20db48fc | 114 | // These are new functions for this class |
| gbloice | 0:ae3d20db48fc | 115 | |
| gbloice | 0:ae3d20db48fc | 116 | /** Draw a horizontal line |
| gbloice | 0:ae3d20db48fc | 117 | * |
| gbloice | 0:ae3d20db48fc | 118 | * @param x0 Starting x position |
| gbloice | 0:ae3d20db48fc | 119 | * @param y0 Starting y position |
| gbloice | 0:ae3d20db48fc | 120 | * @param x1 End x position |
| gbloice | 0:ae3d20db48fc | 121 | * @param colour Colour of line |
| gbloice | 0:ae3d20db48fc | 122 | */ |
| gbloice | 0:ae3d20db48fc | 123 | void hLine(const uint16_t x0, const uint16_t y0, const uint16_t x1, const uint16_t colour); |
| gbloice | 0:ae3d20db48fc | 124 | |
| gbloice | 0:ae3d20db48fc | 125 | /** Draw a vertical line |
| gbloice | 0:ae3d20db48fc | 126 | * |
| gbloice | 0:ae3d20db48fc | 127 | * @param x0 Starting x position |
| gbloice | 0:ae3d20db48fc | 128 | * @param y0 Starting y position |
| gbloice | 0:ae3d20db48fc | 129 | * @param y1 End y position |
| gbloice | 0:ae3d20db48fc | 130 | * @param colour Colour of line |
| gbloice | 0:ae3d20db48fc | 131 | */ |
| gbloice | 0:ae3d20db48fc | 132 | void vLine(const uint16_t x0, const uint16_t y0, const uint16_t y1, const uint16_t colour); |
| gbloice | 0:ae3d20db48fc | 133 | |
| gbloice | 0:ae3d20db48fc | 134 | /** Draw a rectangle in the specified colour |
| gbloice | 0:ae3d20db48fc | 135 | * |
| gbloice | 0:ae3d20db48fc | 136 | * @param x0 Starting x position |
| gbloice | 0:ae3d20db48fc | 137 | * @param y0 Starting y position |
| gbloice | 0:ae3d20db48fc | 138 | * @param x1 Ending x position |
| gbloice | 0:ae3d20db48fc | 139 | * @param y1 Ending y position |
| gbloice | 0:ae3d20db48fc | 140 | * @param colour Outline colour of rectangle |
| gbloice | 0:ae3d20db48fc | 141 | */ |
| gbloice | 0:ae3d20db48fc | 142 | void rectangle(const uint16_t x0, const uint16_t y0, const uint16_t x1, const uint16_t y1, uint16_t colour); |
| gbloice | 0:ae3d20db48fc | 143 | |
| gbloice | 0:ae3d20db48fc | 144 | /** Draw a filled rectangle in the specified colour |
| gbloice | 0:ae3d20db48fc | 145 | * |
| gbloice | 0:ae3d20db48fc | 146 | * @param x0 Starting x position |
| gbloice | 0:ae3d20db48fc | 147 | * @param y0 Starting y position |
| gbloice | 0:ae3d20db48fc | 148 | * @param x1 Ending x position |
| gbloice | 0:ae3d20db48fc | 149 | * @param y1 Ending y position |
| gbloice | 0:ae3d20db48fc | 150 | * @param colour Outline colour of rectangle |
| gbloice | 0:ae3d20db48fc | 151 | */ |
| gbloice | 0:ae3d20db48fc | 152 | void fillRectangle(const uint16_t x0, const uint16_t y0, const uint16_t x1, const uint16_t y1, uint16_t colour); |
| gbloice | 0:ae3d20db48fc | 153 | |
| gbloice | 0:ae3d20db48fc | 154 | /** Control the backlight |
| gbloice | 0:ae3d20db48fc | 155 | * |
| gbloice | 0:ae3d20db48fc | 156 | * @param on Enable the backlight |
| gbloice | 0:ae3d20db48fc | 157 | */ |
| gbloice | 0:ae3d20db48fc | 158 | void backlightControl(bool on) { |
| gbloice | 0:ae3d20db48fc | 159 | _bl = on ? 1 : 0; |
| gbloice | 0:ae3d20db48fc | 160 | } |
| gbloice | 0:ae3d20db48fc | 161 | |
| gbloice | 0:ae3d20db48fc | 162 | protected: |
| gbloice | 0:ae3d20db48fc | 163 | |
| gbloice | 0:ae3d20db48fc | 164 | /** Print a character |
| gbloice | 0:ae3d20db48fc | 165 | * |
| gbloice | 0:ae3d20db48fc | 166 | * Overridden to handle control characters |
| gbloice | 0:ae3d20db48fc | 167 | */ |
| gbloice | 0:ae3d20db48fc | 168 | virtual int _putc(int value); |
| gbloice | 0:ae3d20db48fc | 169 | |
| gbloice | 0:ae3d20db48fc | 170 | private: |
| gbloice | 0:ae3d20db48fc | 171 | bool resetDisplay(void); // Reset the display |
| gbloice | 0:ae3d20db48fc | 172 | void initHardware(void); // Initialise the hardware |
| gbloice | 0:ae3d20db48fc | 173 | inline void setRegisterIndex(const uint8_t reg); // Write register |
| gbloice | 0:ae3d20db48fc | 174 | inline void writeData(const uint16_t data); // Write data |
| gbloice | 0:ae3d20db48fc | 175 | uint16_t readDataRegister(const uint8_t reg); // Read from a register |
| gbloice | 0:ae3d20db48fc | 176 | void writeDataRegister(const uint8_t reg, const uint16_t data); // Write data to a register |
| gbloice | 0:ae3d20db48fc | 177 | void movePen(const uint16_t x, const uint16_t y); // Set the pen position |
| gbloice | 0:ae3d20db48fc | 178 | |
| gbloice | 0:ae3d20db48fc | 179 | SPI _spi; // The SPI Port to use for data I/O |
| gbloice | 0:ae3d20db48fc | 180 | DigitalOut _cs; // The I/O pin for the Chip Select |
| gbloice | 0:ae3d20db48fc | 181 | DigitalOut _reset; // The I/O pin for the reset |
| gbloice | 0:ae3d20db48fc | 182 | DigitalOut _bl; // The I/O pin for the blacklight |
| gbloice | 0:ae3d20db48fc | 183 | }; |
| gbloice | 0:ae3d20db48fc | 184 | |
| gbloice | 0:ae3d20db48fc | 185 | #endif |