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.
Diff: EAQVGAOLED.h
- Revision:
- 0:ae3d20db48fc
- Child:
- 1:b23bfa1be0d9
diff -r 000000000000 -r ae3d20db48fc EAQVGAOLED.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/EAQVGAOLED.h Wed Feb 09 21:23:49 2011 +0000
@@ -0,0 +1,185 @@
+/* mbed library for driving the EA QVGA 2.8" OLED
+ * Copyright (c) Graham Bloice 2011
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MBED_EAQVGAOLED_H
+#define MBED_EAQVGAOLED_H
+
+#include "mbed.h"
+#include "GraphicsDisplay.h"
+
+#define BLACK 0x0000 /* 0, 0, 0 */
+#define NAVY 0x000F /* 0, 0, 128 */
+#define DARK_GREEN 0x03E0 /* 0, 128, 0 */
+#define DARK_CYAN 0x03EF /* 0, 128, 128 */
+#define MAROON 0x7800 /* 128, 0, 0 */
+#define PURPLE 0x780F /* 128, 0, 128 */
+#define OLIVE 0x7BE0 /* 128, 128, 0 */
+#define LIGHT_GRAY 0xC618 /* 192, 192, 192 */
+#define DARK_GRAY 0x7BEF /* 128, 128, 128 */
+#define BLUE 0x001F /* 0, 0, 255 */
+#define GREEN 0x07E0 /* 0, 255, 0 */
+#define CYAN 0x07FF /* 0, 255, 255 */
+#define RED 0xF800 /* 255, 0, 0 */
+#define MAGENTA 0xF81F /* 255, 0, 255 */
+#define YELLOW 0xFFE0 /* 255, 255, 0 */
+#define WHITE 0xFFFF /* 255, 255, 255 */
+
+#define CURSOR_CLS 0
+#define CURSOR_UP 1
+#define CURSOR_DOWN 2
+#define CURSOR_LEFT 3
+#define CURSOR_RIGHT 4
+
+ /** EA QVGA OLED Display driver
+ *
+ * Uses SPI to drive the Embedded Artists 2.8"
+ * QVGA OLED panel
+ *
+ */
+class EAQVGAOLED : public GraphicsDisplay {
+
+public:
+
+ // These are the functions required to support the base class
+
+ /** Create an EA QVGA OLED object connected using
+ * the specified SPI port, and two output pins;
+ * the Chip Select pin and the Backlight pin.
+ *
+ * @param spiPort SPI port to use for data
+ * @param cs Pin to drive the display CS
+ * @param reset Pin to drive the display reset
+ * @param bl Pin to drive the display backlight
+ */
+ EAQVGAOLED(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, PinName bl);
+
+ /** Set a pixel to the specified colour
+ *
+ * @param x Pixel x position
+ * @param y Pixel y position
+ * @param colour Pixel colour
+ */
+ virtual void pixel(int x, int y, int colour);
+
+ /** Accessor to obtain the display width
+ *
+ * @return the width of the display in pixels
+ */
+ virtual int width(void) { return 240; }
+
+ /** Accessor to obtain the display height
+ *
+ * @return the height of the display in pixels
+ */
+ virtual int height(void) { return 320; }
+
+ /** Clear the screen
+ */
+ virtual void cls() { fillRectangle(0, 0, width(), height(), _background); }
+
+ /* No overrides for these functions
+
+ virtual void window(int x, int y, int w, int h);
+ virtual void putp(int colour);
+
+ virtual void fill(int x, int y, int w, int h, int colour);
+ virtual void blit(int x, int y, int w, int h, const int *colour);
+ virtual void blitbit(int x, int y, int w, int h, const char* colour);
+
+ virtual void character(int column, int row, int c);
+ virtual int columns();
+ virtual int rows();
+
+ */
+
+ // These are new functions for this class
+
+ /** Draw a horizontal line
+ *
+ * @param x0 Starting x position
+ * @param y0 Starting y position
+ * @param x1 End x position
+ * @param colour Colour of line
+ */
+ void hLine(const uint16_t x0, const uint16_t y0, const uint16_t x1, const uint16_t colour);
+
+ /** Draw a vertical line
+ *
+ * @param x0 Starting x position
+ * @param y0 Starting y position
+ * @param y1 End y position
+ * @param colour Colour of line
+ */
+ void vLine(const uint16_t x0, const uint16_t y0, const uint16_t y1, const uint16_t colour);
+
+ /** Draw a rectangle in the specified colour
+ *
+ * @param x0 Starting x position
+ * @param y0 Starting y position
+ * @param x1 Ending x position
+ * @param y1 Ending y position
+ * @param colour Outline colour of rectangle
+ */
+ void rectangle(const uint16_t x0, const uint16_t y0, const uint16_t x1, const uint16_t y1, uint16_t colour);
+
+ /** Draw a filled rectangle in the specified colour
+ *
+ * @param x0 Starting x position
+ * @param y0 Starting y position
+ * @param x1 Ending x position
+ * @param y1 Ending y position
+ * @param colour Outline colour of rectangle
+ */
+ void fillRectangle(const uint16_t x0, const uint16_t y0, const uint16_t x1, const uint16_t y1, uint16_t colour);
+
+ /** Control the backlight
+ *
+ * @param on Enable the backlight
+ */
+ void backlightControl(bool on) {
+ _bl = on ? 1 : 0;
+ }
+
+protected:
+
+ /** Print a character
+ *
+ * Overridden to handle control characters
+ */
+ virtual int _putc(int value);
+
+private:
+ bool resetDisplay(void); // Reset the display
+ void initHardware(void); // Initialise the hardware
+ inline void setRegisterIndex(const uint8_t reg); // Write register
+ inline void writeData(const uint16_t data); // Write data
+ uint16_t readDataRegister(const uint8_t reg); // Read from a register
+ void writeDataRegister(const uint8_t reg, const uint16_t data); // Write data to a register
+ void movePen(const uint16_t x, const uint16_t y); // Set the pen position
+
+ SPI _spi; // The SPI Port to use for data I/O
+ DigitalOut _cs; // The I/O pin for the Chip Select
+ DigitalOut _reset; // The I/O pin for the reset
+ DigitalOut _bl; // The I/O pin for the blacklight
+ };
+
+ #endif
\ No newline at end of file