This library can be used to control a low-cost Adafruit 358 TFT display. It has basic functionality but is a starting point for others trying to control this type of display using the FRDM-K64F.

Committer:
bmazzeo
Date:
Thu Aug 07 03:17:21 2014 +0000
Revision:
1:cd3c7c2e2746
Parent:
0:7cb96171f886
A few updates to clean up the code before publishing.

Who changed what in which revision?

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