Creating a project for TT_Mxx

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GraphicsDisplay.cpp Source File

GraphicsDisplay.cpp

00001 /* mbed GraphicsDisplay Display Library Base Class
00002  * Copyright (c) 2007-2009 sford
00003  * Released under the MIT License: http://mbed.org/license/mit
00004  */
00005  
00006 #include "GraphicsDisplay.h"
00007 extern uint8_t font[];
00008 
00009 const unsigned char FONT8x8[97][8] = {
00010 0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char
00011 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20
00012 0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00, // !
00013 0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00, // "
00014 0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00, // #
00015 0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00, // $
00016 0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00, // %
00017 0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00, // &
00018 0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00, // '
00019 0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00, // (
00020 0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00, // )
00021 0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, // *
00022 0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00, // +
00023 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30, // ,
00024 0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00, // -
00025 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00, // .
00026 0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, // / (forward slash)
00027 0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00, // 0 0x30
00028 0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00, // 1
00029 0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00, // 2
00030 0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00, // 3
00031 0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00, // 4
00032 0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00, // 5
00033 0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00, // 6
00034 0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00, // 7
00035 0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00, // 8
00036 0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00, // 9
00037 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00, // :
00038 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30, // ;
00039 0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00, // <
00040 0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00, // =
00041 0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00, // >
00042 0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00, // ?
00043 0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00, // @ 0x40
00044 0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00, // A
00045 0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00, // B
00046 0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00, // C
00047 0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00, // D
00048 0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00, // E
00049 0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00, // F
00050 0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00, // G
00051 0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00, // H
00052 0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // I
00053 0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00, // J
00054 0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00, // K
00055 0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00, // L
00056 0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00, // M
00057 0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00, // N
00058 0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00, // O
00059 0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00, // P 0x50
00060 0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00, // Q
00061 0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00, // R
00062 0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00, // S
00063 0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00, // T
00064 0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00, // U
00065 0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00, // V
00066 0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, // W
00067 0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00, // X
00068 0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00, // Y
00069 0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00, // Z
00070 0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, // [
00071 0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, // \ (back slash)
00072 0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, // ]
00073 0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // ^
00074 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, // _
00075 0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00, // ` 0x60
00076 0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00, // a
00077 0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00, // b
00078 0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00, // c
00079 0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00, // d
00080 0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00, // e
00081 0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00, // f
00082 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C, // g
00083 0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00, // h
00084 0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00, // i
00085 0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C, // j
00086 0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00, // k
00087 0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // l
00088 0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00, // m
00089 0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00, // n
00090 0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00, // o
00091 0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78, // p
00092 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F, // q
00093 0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00, // r
00094 0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00, // s
00095 0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00, // t
00096 0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00, // u
00097 0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00, // v
00098 0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00, // w
00099 0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00, // x
00100 0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C, // y
00101 0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00, // z
00102 0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00, // {
00103 0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00, // |
00104 0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // }
00105 0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~
00106 0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00}; // DEL
00107 #define read_font_line(__char, __line)  font[((uint16_t)(__char)) * FONT_CHAR_HEIGHT+(__line)]
00108     
00109 GraphicsDisplay::GraphicsDisplay(const char *name):TextDisplay(name) {
00110     foreground(WHITE);
00111     background(BLACK);
00112 }
00113     
00114 void GraphicsDisplay::character(int column, int row, int value)
00115 {
00116     blitbit(column * 8, row * 8, 8, 8, (char*)&(FONT8x8[value - 0x1F][0]));
00117 }
00118 
00119 void GraphicsDisplay::character_(int x, int y, char ch,int colour) { 
00120   uint8_t temp;
00121   uint8_t pos,t;
00122     //blitbit(column * 8, row * 8, 8, 8, (char*)&(FONT8x8[value - 0x1F][0]));
00123   if ((x > (width() - FONT_CHAR_WIDTH)) || (y > (height() - FONT_CHAR_HEIGHT))) {
00124     return;
00125   }
00126    
00127    for(pos=0;pos<FONT_CHAR_HEIGHT;pos++) {
00128       temp = read_font_line(ch, pos);
00129       for(t=0;t<FONT_CHAR_WIDTH;t++) {
00130         if (temp & 0x01) {
00131           //setAddress(x + t, y + pos, x + t, y + pos);
00132           pixel(x + t,y + pos,colour);
00133           //sendData(colour);
00134           //drawPoint(x + t, y + pos);
00135         }
00136         temp>>=1;
00137       }
00138     }
00139 
00140 }
00141 
00142 void GraphicsDisplay::window(unsigned int x,unsigned  int y,unsigned  int w,unsigned  int h) {
00143     // current pixel location
00144     _x = x;
00145     _y = y;
00146     // window settings
00147     _x1 = x;
00148     _x2 = x + w - 1;
00149     _y1 = y;
00150     _y2 = y + h - 1;
00151 }
00152     
00153 void GraphicsDisplay::putp(int colour) {
00154     // put pixel at current pixel location
00155     pixel(_x, _y, colour);
00156     // update pixel location based on window settings
00157     _x++;
00158     if(_x > _x2) {
00159         _x = _x1;
00160         _y++;
00161         if(_y > _y2) {
00162             _y = _y1;
00163         }
00164     }
00165 }
00166 
00167 void GraphicsDisplay::fill(int x, int y, int w, int h, int colour) { 
00168     window(x, y, w, h);
00169     for(int i=0; i<w*h; i++) {
00170         putp(colour);
00171     }
00172 }
00173     
00174 void GraphicsDisplay::cls() {
00175     fill(0, 0, width(), height(), _background);
00176 }
00177     
00178 void GraphicsDisplay::blit(int x, int y, int w, int h, const int *colour) { 
00179     window(x, y, w, h);
00180     for(int i=0; i<w*h; i++) {
00181         putp(colour[i]);
00182     }
00183 }
00184     
00185 void GraphicsDisplay::lcd_display_char(uint16_t hwXpos, //specify x position.
00186                          uint16_t hwYpos, //specify y position.
00187                          uint8_t chChr,   //a char is display.
00188                          uint8_t chSize,  //specify the size of the char
00189                          uint16_t hwColor)
00190 {
00191     uint8_t i, j, chTemp;
00192     uint16_t hwYpos0 = hwYpos, hwColorVal = 0;
00193 
00194     if (hwXpos >= width() || hwYpos >= height()) {
00195         return;
00196     }
00197 
00198                        
00199     for (i = 0; i < chSize; i ++) {   
00200         // if (FONT_1206 == chSize) {
00201         //     chTemp = FONT8x8[chChr - 0x20][i];  
00202         // } else if (FONT_1608 == chSize) { 
00203         //     chTemp = FONT8x8[chChr - 0x20][i];
00204         // }
00205         chTemp = FONT8x8[chChr - 0x20][i];
00206         
00207         for (j = 0; j < 8; j ++) {
00208             if (chTemp & 0x80) {
00209                 hwColorVal = hwColor;
00210                 //lcd_draw_point(hwXpos, hwYpos, hwColorVal);
00211                 pixel(hwXpos,hwYpos,hwColor);
00212             }           
00213             chTemp <<= 1;
00214             hwYpos ++;
00215             if ((hwYpos - hwYpos0) == chSize) {
00216                 hwYpos = hwYpos0;
00217                 hwXpos ++;
00218                 break;
00219             }
00220         }    
00221     } 
00222 }
00223 
00224 void GraphicsDisplay::blitbit(int x, int y, int w, int h, const char* colour) {
00225     window(x, y, w, h);
00226     for(int i = 0; i < w*h; i++) {
00227         char byte = colour[i >> 3];
00228         int offset = i & 0x7;
00229         int c = ((byte << offset) & 0x80) ? _foreground : _background;
00230         putp(c);
00231     }
00232 }
00233     
00234 int GraphicsDisplay::columns() { 
00235     return width() / 8; 
00236 }
00237 
00238 int GraphicsDisplay::rows() { 
00239     return height() / 8; 
00240 }
00241 
00242