Chinese module HY-1.8 SPI TFT lcd Display library.
Dependents: KL25Z_DCF77_HY-1_8LCD
Fork of HY-1_8TFT_ST7735 by
GraphicsDisplay.cpp
00001 // ST7735 8 Bit SPI Library 00002 00003 #include "GraphicsDisplay.h" 00004 00005 const unsigned char FONT8x8[97][8] = { 00006 0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char 00007 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20 00008 0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00, // ! 00009 0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00, // " 00010 0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00, // # 00011 0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00, // $ 00012 0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00, // % 00013 0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00, // & 00014 0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00, // ' 00015 0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00, // ( 00016 0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00, // ) 00017 0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, // * 00018 0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00, // + 00019 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30, // , 00020 0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00, // - 00021 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00, // . 00022 0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, // / (forward slash) 00023 0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00, // 0 0x30 00024 0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00, // 1 00025 0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00, // 2 00026 0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00, // 3 00027 0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00, // 4 00028 0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00, // 5 00029 0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00, // 6 00030 0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00, // 7 00031 0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00, // 8 00032 0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00, // 9 00033 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00, // : 00034 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30, // ; 00035 0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00, // < 00036 0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00, // = 00037 0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00, // > 00038 0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00, // ? 00039 0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00, // @ 0x40 00040 0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00, // A 00041 0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00, // B 00042 0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00, // C 00043 0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00, // D 00044 0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00, // E 00045 0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00, // F 00046 0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00, // G 00047 0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00, // H 00048 0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // I 00049 0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00, // J 00050 0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00, // K 00051 0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00, // L 00052 0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00, // M 00053 0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00, // N 00054 0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00, // O 00055 0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00, // P 0x50 00056 0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00, // Q 00057 0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00, // R 00058 0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00, // S 00059 0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00, // T 00060 0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00, // U 00061 0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00, // V 00062 0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, // W 00063 0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00, // X 00064 0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00, // Y 00065 0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00, // Z 00066 0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, // [ 00067 0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, // \ (back slash) 00068 0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, // ] 00069 0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // ^ 00070 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, // _ 00071 0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00, // ` 0x60 00072 0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00, // a 00073 0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00, // b 00074 0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00, // c 00075 0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00, // d 00076 0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00, // e 00077 0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00, // f 00078 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C, // g 00079 0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00, // h 00080 0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00, // i 00081 0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C, // j 00082 0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00, // k 00083 0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // l 00084 0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00, // m 00085 0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00, // n 00086 0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00, // o 00087 0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78, // p 00088 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F, // q 00089 0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00, // r 00090 0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00, // s 00091 0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00, // t 00092 0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00, // u 00093 0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00, // v 00094 0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00, // w 00095 0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00, // x 00096 0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C, // y 00097 0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00, // z 00098 0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00, // { 00099 0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00, // | 00100 0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // } 00101 0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~ 00102 0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00}; // DEL 00103 00104 GraphicsDisplay::GraphicsDisplay(const char *name):TextDisplay(name) { 00105 foreground(0xFFFF); 00106 background(0x0000); 00107 } 00108 00109 void GraphicsDisplay::character(int column, int row, int value) { 00110 blitbit(column * 8, row * 8, 8, 8, (char*)&(FONT8x8[value - 0x1F][0])); 00111 } 00112 00113 void GraphicsDisplay::gwindow(int x, int y, int w, int h) { 00114 // current pixel location 00115 _x = x; 00116 _y = y; 00117 // window settings 00118 _x1 = x; 00119 _x2 = x + w - 1; 00120 _y1 = y; 00121 _y2 = y + h - 1; 00122 } 00123 00124 void GraphicsDisplay::putp(int colour) { 00125 // put pixel at current pixel location 00126 pixel(_x, _y, colour); 00127 // update pixel location based on window settings 00128 _x++; 00129 if(_x > _x2) { 00130 _x = _x1; 00131 _y++; 00132 if(_y > _y2) { 00133 _y = _y1; 00134 } 00135 } 00136 } 00137 00138 void GraphicsDisplay::fill(int x, int y, int w, int h, int colour) { 00139 gwindow(x, y, w, h); 00140 for(int i=0; i<w*h; i++) { 00141 putp(colour); 00142 } 00143 } 00144 00145 void GraphicsDisplay::cls() { 00146 fill(0, 0, width(), height(), _background); 00147 } 00148 00149 void GraphicsDisplay::blit(int x, int y, int w, int h, const int *colour) { 00150 gwindow(x, y, w, h); 00151 for(int i=0; i<w*h; i++) { 00152 putp(colour[i]); 00153 } 00154 } 00155 00156 void GraphicsDisplay::blitbit(int x, int y, int w, int h, const char* colour) { 00157 gwindow(x, y, w, h); 00158 for(int i = 0; i < w*h; i++) { 00159 char byte = colour[i >> 3]; 00160 int offset = i & 0x7; 00161 int c = ((byte << offset) & 0x80) ? _foreground : _background; 00162 putp(c); 00163 } 00164 } 00165 00166 int GraphicsDisplay::columns() { 00167 return width() / 8; 00168 } 00169 00170 int GraphicsDisplay::rows() { 00171 return height() / 8; 00172 } 00173
Generated on Sun Jul 17 2022 07:48:57 by 1.7.2