library for Sharp memory LCD (LS027B4DH01)

Dependents:   Sharp_Memory_LCD_Test Sharp_Memory_LCD_Test

Committer:
masato
Date:
Sun May 11 14:03:39 2014 +0000
Revision:
1:f8ba3b236d12
Parent:
0:c99dda90f834
RC1

Who changed what in which revision?

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