An mbed library for the Embedded Artists QVGA OLED 2.8 inch panel

Committer:
gbloice
Date:
Wed Mar 09 19:45:23 2011 +0000
Revision:
5:b3f5d19945ff
Parent:
0:ae3d20db48fc
Fixed example with conditional compilation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gbloice 0:ae3d20db48fc 1 /* mbed GraphicsDisplay Display Library Base Class
gbloice 0:ae3d20db48fc 2 * Copyright (c) 2007-2009 sford
gbloice 0:ae3d20db48fc 3 * Released under the MIT License: http://mbed.org/license/mit
gbloice 0:ae3d20db48fc 4 */
gbloice 0:ae3d20db48fc 5
gbloice 0:ae3d20db48fc 6 #include "GraphicsDisplay.h"
gbloice 0:ae3d20db48fc 7
gbloice 0:ae3d20db48fc 8 const unsigned char FONT8x8[97][8] = {
gbloice 0:ae3d20db48fc 9 0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char
gbloice 0:ae3d20db48fc 10 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20
gbloice 0:ae3d20db48fc 11 0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00, // !
gbloice 0:ae3d20db48fc 12 0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00, // "
gbloice 0:ae3d20db48fc 13 0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00, // #
gbloice 0:ae3d20db48fc 14 0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00, // $
gbloice 0:ae3d20db48fc 15 0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00, // %
gbloice 0:ae3d20db48fc 16 0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00, // &
gbloice 0:ae3d20db48fc 17 0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00, // '
gbloice 0:ae3d20db48fc 18 0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00, // (
gbloice 0:ae3d20db48fc 19 0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00, // )
gbloice 0:ae3d20db48fc 20 0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, // *
gbloice 0:ae3d20db48fc 21 0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00, // +
gbloice 0:ae3d20db48fc 22 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30, // ,
gbloice 0:ae3d20db48fc 23 0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00, // -
gbloice 0:ae3d20db48fc 24 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00, // .
gbloice 0:ae3d20db48fc 25 0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, // / (forward slash)
gbloice 0:ae3d20db48fc 26 0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00, // 0 0x30
gbloice 0:ae3d20db48fc 27 0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00, // 1
gbloice 0:ae3d20db48fc 28 0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00, // 2
gbloice 0:ae3d20db48fc 29 0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00, // 3
gbloice 0:ae3d20db48fc 30 0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00, // 4
gbloice 0:ae3d20db48fc 31 0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00, // 5
gbloice 0:ae3d20db48fc 32 0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00, // 6
gbloice 0:ae3d20db48fc 33 0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00, // 7
gbloice 0:ae3d20db48fc 34 0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00, // 8
gbloice 0:ae3d20db48fc 35 0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00, // 9
gbloice 0:ae3d20db48fc 36 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00, // :
gbloice 0:ae3d20db48fc 37 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30, // ;
gbloice 0:ae3d20db48fc 38 0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00, // <
gbloice 0:ae3d20db48fc 39 0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00, // =
gbloice 0:ae3d20db48fc 40 0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00, // >
gbloice 0:ae3d20db48fc 41 0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00, // ?
gbloice 0:ae3d20db48fc 42 0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00, // @ 0x40
gbloice 0:ae3d20db48fc 43 0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00, // A
gbloice 0:ae3d20db48fc 44 0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00, // B
gbloice 0:ae3d20db48fc 45 0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00, // C
gbloice 0:ae3d20db48fc 46 0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00, // D
gbloice 0:ae3d20db48fc 47 0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00, // E
gbloice 0:ae3d20db48fc 48 0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00, // F
gbloice 0:ae3d20db48fc 49 0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00, // G
gbloice 0:ae3d20db48fc 50 0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00, // H
gbloice 0:ae3d20db48fc 51 0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // I
gbloice 0:ae3d20db48fc 52 0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00, // J
gbloice 0:ae3d20db48fc 53 0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00, // K
gbloice 0:ae3d20db48fc 54 0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00, // L
gbloice 0:ae3d20db48fc 55 0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00, // M
gbloice 0:ae3d20db48fc 56 0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00, // N
gbloice 0:ae3d20db48fc 57 0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00, // O
gbloice 0:ae3d20db48fc 58 0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00, // P 0x50
gbloice 0:ae3d20db48fc 59 0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00, // Q
gbloice 0:ae3d20db48fc 60 0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00, // R
gbloice 0:ae3d20db48fc 61 0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00, // S
gbloice 0:ae3d20db48fc 62 0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00, // T
gbloice 0:ae3d20db48fc 63 0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00, // U
gbloice 0:ae3d20db48fc 64 0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00, // V
gbloice 0:ae3d20db48fc 65 0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, // W
gbloice 0:ae3d20db48fc 66 0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00, // X
gbloice 0:ae3d20db48fc 67 0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00, // Y
gbloice 0:ae3d20db48fc 68 0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00, // Z
gbloice 0:ae3d20db48fc 69 0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, // [
gbloice 0:ae3d20db48fc 70 0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, // \ (back slash)
gbloice 0:ae3d20db48fc 71 0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, // ]
gbloice 0:ae3d20db48fc 72 0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // ^
gbloice 0:ae3d20db48fc 73 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, // _
gbloice 0:ae3d20db48fc 74 0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00, // ` 0x60
gbloice 0:ae3d20db48fc 75 0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00, // a
gbloice 0:ae3d20db48fc 76 0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00, // b
gbloice 0:ae3d20db48fc 77 0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00, // c
gbloice 0:ae3d20db48fc 78 0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00, // d
gbloice 0:ae3d20db48fc 79 0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00, // e
gbloice 0:ae3d20db48fc 80 0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00, // f
gbloice 0:ae3d20db48fc 81 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C, // g
gbloice 0:ae3d20db48fc 82 0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00, // h
gbloice 0:ae3d20db48fc 83 0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00, // i
gbloice 0:ae3d20db48fc 84 0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C, // j
gbloice 0:ae3d20db48fc 85 0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00, // k
gbloice 0:ae3d20db48fc 86 0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // l
gbloice 0:ae3d20db48fc 87 0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00, // m
gbloice 0:ae3d20db48fc 88 0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00, // n
gbloice 0:ae3d20db48fc 89 0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00, // o
gbloice 0:ae3d20db48fc 90 0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78, // p
gbloice 0:ae3d20db48fc 91 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F, // q
gbloice 0:ae3d20db48fc 92 0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00, // r
gbloice 0:ae3d20db48fc 93 0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00, // s
gbloice 0:ae3d20db48fc 94 0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00, // t
gbloice 0:ae3d20db48fc 95 0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00, // u
gbloice 0:ae3d20db48fc 96 0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00, // v
gbloice 0:ae3d20db48fc 97 0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00, // w
gbloice 0:ae3d20db48fc 98 0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00, // x
gbloice 0:ae3d20db48fc 99 0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C, // y
gbloice 0:ae3d20db48fc 100 0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00, // z
gbloice 0:ae3d20db48fc 101 0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00, // {
gbloice 0:ae3d20db48fc 102 0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00, // |
gbloice 0:ae3d20db48fc 103 0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // }
gbloice 0:ae3d20db48fc 104 0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~
gbloice 0:ae3d20db48fc 105 0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00}; // DEL
gbloice 0:ae3d20db48fc 106
gbloice 0:ae3d20db48fc 107 GraphicsDisplay::GraphicsDisplay() {
gbloice 0:ae3d20db48fc 108 foreground(0x00FFFFFF);
gbloice 0:ae3d20db48fc 109 background(0x00000000);
gbloice 0:ae3d20db48fc 110 }
gbloice 0:ae3d20db48fc 111
gbloice 0:ae3d20db48fc 112 void GraphicsDisplay::character(int column, int row, int value) {
gbloice 0:ae3d20db48fc 113 blitbit(column * 8, row * 8, 8, 8, (char*)&(FONT8x8[value - 0x1F][0]));
gbloice 0:ae3d20db48fc 114 }
gbloice 0:ae3d20db48fc 115
gbloice 0:ae3d20db48fc 116 void GraphicsDisplay::window(int x, int y, int w, int h) {
gbloice 0:ae3d20db48fc 117 // current pixel location
gbloice 0:ae3d20db48fc 118 _x = x;
gbloice 0:ae3d20db48fc 119 _y = y;
gbloice 0:ae3d20db48fc 120 // window settings
gbloice 0:ae3d20db48fc 121 _x1 = x;
gbloice 0:ae3d20db48fc 122 _x2 = x + w - 1;
gbloice 0:ae3d20db48fc 123 _y1 = y;
gbloice 0:ae3d20db48fc 124 _y2 = y + h - 1;
gbloice 0:ae3d20db48fc 125 }
gbloice 0:ae3d20db48fc 126
gbloice 0:ae3d20db48fc 127 void GraphicsDisplay::putp(int colour) {
gbloice 0:ae3d20db48fc 128 // put pixel at current pixel location
gbloice 0:ae3d20db48fc 129 pixel(_x, _y, colour);
gbloice 0:ae3d20db48fc 130 // update pixel location based on window settings
gbloice 0:ae3d20db48fc 131 _x++;
gbloice 0:ae3d20db48fc 132 if(_x > _x2) {
gbloice 0:ae3d20db48fc 133 _x = _x1;
gbloice 0:ae3d20db48fc 134 _y++;
gbloice 0:ae3d20db48fc 135 if(_y > _y2) {
gbloice 0:ae3d20db48fc 136 _y = _y1;
gbloice 0:ae3d20db48fc 137 }
gbloice 0:ae3d20db48fc 138 }
gbloice 0:ae3d20db48fc 139 }
gbloice 0:ae3d20db48fc 140
gbloice 0:ae3d20db48fc 141 void GraphicsDisplay::fill(int x, int y, int w, int h, int colour) {
gbloice 0:ae3d20db48fc 142 window(x, y, w, h);
gbloice 0:ae3d20db48fc 143 for(int i=0; i<w*h; i++) {
gbloice 0:ae3d20db48fc 144 putp(colour);
gbloice 0:ae3d20db48fc 145 }
gbloice 0:ae3d20db48fc 146 }
gbloice 0:ae3d20db48fc 147
gbloice 0:ae3d20db48fc 148 void GraphicsDisplay::cls() {
gbloice 0:ae3d20db48fc 149 fill(0, 0, width(), height(), _background);
gbloice 0:ae3d20db48fc 150 }
gbloice 0:ae3d20db48fc 151
gbloice 0:ae3d20db48fc 152 void GraphicsDisplay::blit(int x, int y, int w, int h, const int *colour) {
gbloice 0:ae3d20db48fc 153 window(x, y, w, h);
gbloice 0:ae3d20db48fc 154 for(int i=0; i<w*h; i++) {
gbloice 0:ae3d20db48fc 155 putp(colour[i]);
gbloice 0:ae3d20db48fc 156 }
gbloice 0:ae3d20db48fc 157 }
gbloice 0:ae3d20db48fc 158
gbloice 0:ae3d20db48fc 159 void GraphicsDisplay::blitbit(int x, int y, int w, int h, const char* colour) {
gbloice 0:ae3d20db48fc 160 window(x, y, w, h);
gbloice 0:ae3d20db48fc 161 for(int i = 0; i < w*h; i++) {
gbloice 0:ae3d20db48fc 162 char byte = colour[i >> 3];
gbloice 0:ae3d20db48fc 163 int offset = i & 0x7;
gbloice 0:ae3d20db48fc 164 int c = ((byte << offset) & 0x80) ? _foreground : _background;
gbloice 0:ae3d20db48fc 165 putp(c);
gbloice 0:ae3d20db48fc 166 }
gbloice 0:ae3d20db48fc 167 }
gbloice 0:ae3d20db48fc 168
gbloice 0:ae3d20db48fc 169 int GraphicsDisplay::columns() {
gbloice 0:ae3d20db48fc 170 return width() / 8;
gbloice 0:ae3d20db48fc 171 }
gbloice 0:ae3d20db48fc 172
gbloice 0:ae3d20db48fc 173 int GraphicsDisplay::rows() {
gbloice 0:ae3d20db48fc 174 return height() / 8;
gbloice 0:ae3d20db48fc 175 }