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