mbed-os

Fork of mbed-os by erkin yucel

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

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