EA OLED Hello World (Runs through the different possibilities with the OLED software

Dependencies:   mbed

Committer:
Lerche
Date:
Sun Oct 03 08:40:47 2010 +0000
Revision:
0:ff072ee9597c

        

Who changed what in which revision?

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