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