Music Player for ARCH-PRO

Dependencies:   GT20L16J1Y_font TinyJpgDec mbed

SeeedStudio Arch Pro + aitendo TFT-LCD w/Touch panel => .wav File Player
LPC1768 + aitendo TFT-LCD w/Touch panel => .wav File Player
http://goji2100.com/
/media/uploads/Goji/017s.png

Committer:
Goji
Date:
Mon Sep 08 16:07:05 2014 +0000
Revision:
0:6fa19738f62e
Music Player for ARCH-PRO

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Goji 0:6fa19738f62e 1 // --------------------------------------------------------
Goji 0:6fa19738f62e 2 // mGTFT.c (c) CopYright 2013-2014 Goji.
Goji 0:6fa19738f62e 3 // --------------------------------------------------------
Goji 0:6fa19738f62e 4
Goji 0:6fa19738f62e 5 #include "mbed.h"
Goji 0:6fa19738f62e 6 #include "mainconf.h"
Goji 0:6fa19738f62e 7
Goji 0:6fa19738f62e 8 #include "mGTFT.h"
Goji 0:6fa19738f62e 9 #include "mGTP.h"
Goji 0:6fa19738f62e 10 #include "font8x12A.h"
Goji 0:6fa19738f62e 11
Goji 0:6fa19738f62e 12 #define WW 1234
Goji 0:6fa19738f62e 13 #include "mGTFTini.h"
Goji 0:6fa19738f62e 14
Goji 0:6fa19738f62e 15
Goji 0:6fa19738f62e 16 void TFT_wr_reg(uint16_t regv)
Goji 0:6fa19738f62e 17 {
Goji 0:6fa19738f62e 18 TFT_WR_0;
Goji 0:6fa19738f62e 19 TFT_wr_regs(regv >> 8);
Goji 0:6fa19738f62e 20 TFT_WR_1;
Goji 0:6fa19738f62e 21 TFT_WR_0;
Goji 0:6fa19738f62e 22 TFT_wr_regs(regv);
Goji 0:6fa19738f62e 23 TFT_WR_1;
Goji 0:6fa19738f62e 24 }
Goji 0:6fa19738f62e 25
Goji 0:6fa19738f62e 26
Goji 0:6fa19738f62e 27 void TFT_wr_index(uint16_t index)
Goji 0:6fa19738f62e 28 {
Goji 0:6fa19738f62e 29 // TFT_CS_0;
Goji 0:6fa19738f62e 30 TFT_RS_0;
Goji 0:6fa19738f62e 31 TFT_wr_reg(index);
Goji 0:6fa19738f62e 32 TFT_RS_1;
Goji 0:6fa19738f62e 33 // TFT_CS_1;
Goji 0:6fa19738f62e 34 }
Goji 0:6fa19738f62e 35
Goji 0:6fa19738f62e 36
Goji 0:6fa19738f62e 37 void TFT_wr_data(uint16_t data)
Goji 0:6fa19738f62e 38 {
Goji 0:6fa19738f62e 39 // TFT_CS_0;
Goji 0:6fa19738f62e 40 // TFT_RS_1;
Goji 0:6fa19738f62e 41 TFT_wr_reg(data);
Goji 0:6fa19738f62e 42 // TFT_CS_1;
Goji 0:6fa19738f62e 43 }
Goji 0:6fa19738f62e 44
Goji 0:6fa19738f62e 45
Goji 0:6fa19738f62e 46 void TFT_wr_index_data(uint16_t index, uint16_t data)
Goji 0:6fa19738f62e 47 {
Goji 0:6fa19738f62e 48 // TFT_CS_0;
Goji 0:6fa19738f62e 49 TFT_RS_0;
Goji 0:6fa19738f62e 50 TFT_wr_reg(index);
Goji 0:6fa19738f62e 51 TFT_RS_1;
Goji 0:6fa19738f62e 52 TFT_wr_reg(data);
Goji 0:6fa19738f62e 53 // TFT_CS_1;
Goji 0:6fa19738f62e 54 }
Goji 0:6fa19738f62e 55
Goji 0:6fa19738f62e 56 void TFT_setOrientation(uint16_t am)
Goji 0:6fa19738f62e 57 {
Goji 0:6fa19738f62e 58 mTFT_SET_ORENTATION(am);
Goji 0:6fa19738f62e 59 }
Goji 0:6fa19738f62e 60
Goji 0:6fa19738f62e 61
Goji 0:6fa19738f62e 62 void TFT_setWindow(int16_t x1, int16_t y1, int16_t x2, int16_t y2)
Goji 0:6fa19738f62e 63 {
Goji 0:6fa19738f62e 64 TFT_wr_index_data(0x50, y1);
Goji 0:6fa19738f62e 65 TFT_wr_index_data(0x51, y2 - 1);
Goji 0:6fa19738f62e 66 TFT_wr_index_data(0x52, x1);
Goji 0:6fa19738f62e 67 TFT_wr_index_data(0x53, x2 - 1);
Goji 0:6fa19738f62e 68 TFT_setOrientation(TFT_HV_HORZ);
Goji 0:6fa19738f62e 69 TFT_setXY(x1, y1);
Goji 0:6fa19738f62e 70 }
Goji 0:6fa19738f62e 71
Goji 0:6fa19738f62e 72
Goji 0:6fa19738f62e 73 void TFT_setXY(int16_t x1, int16_t y1)
Goji 0:6fa19738f62e 74 {
Goji 0:6fa19738f62e 75 TFT_wr_index_data(0x20, y1);
Goji 0:6fa19738f62e 76 TFT_wr_index_data(0x21, x1);
Goji 0:6fa19738f62e 77 TFT_wr_index(0x22);
Goji 0:6fa19738f62e 78 }
Goji 0:6fa19738f62e 79
Goji 0:6fa19738f62e 80
Goji 0:6fa19738f62e 81 void TFT_clearScreen(uint16_t ccode)
Goji 0:6fa19738f62e 82 {
Goji 0:6fa19738f62e 83 TFT_setXY(0, 0);
Goji 0:6fa19738f62e 84 for (int y = 0; y < TFT_info.yMAX; y++)
Goji 0:6fa19738f62e 85 for (int x = 0; x < TFT_info.xMAX; x++)
Goji 0:6fa19738f62e 86 TFT_wr_reg(ccode);
Goji 0:6fa19738f62e 87 }
Goji 0:6fa19738f62e 88
Goji 0:6fa19738f62e 89
Goji 0:6fa19738f62e 90 void TFT_setPixels(int16_t x1, int16_t y1, uint16_t ccode)
Goji 0:6fa19738f62e 91 {
Goji 0:6fa19738f62e 92 if ((x1 >= TFT_info.xMIN) && (x1 < TFT_info.xMAX) &&
Goji 0:6fa19738f62e 93 (y1 >= TFT_info.yMIN) && (y1 < TFT_info.yMAX)) {
Goji 0:6fa19738f62e 94 TFT_setPixel(x1, y1, ccode);
Goji 0:6fa19738f62e 95 }
Goji 0:6fa19738f62e 96 }
Goji 0:6fa19738f62e 97
Goji 0:6fa19738f62e 98
Goji 0:6fa19738f62e 99 void TFT_setPixel(int16_t x1, int16_t y1, uint16_t ccode)
Goji 0:6fa19738f62e 100 {
Goji 0:6fa19738f62e 101 TFT_setXY(x1, y1);
Goji 0:6fa19738f62e 102 TFT_wr_data(ccode);
Goji 0:6fa19738f62e 103 }
Goji 0:6fa19738f62e 104
Goji 0:6fa19738f62e 105 void TFT_drawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t ccode)
Goji 0:6fa19738f62e 106 {
Goji 0:6fa19738f62e 107 if (x1 == x2) {
Goji 0:6fa19738f62e 108 TFT_drawVerticalLine (x1, y1, y2, ccode);
Goji 0:6fa19738f62e 109 } else
Goji 0:6fa19738f62e 110 if (y1 == y2) {
Goji 0:6fa19738f62e 111 TFT_drawHorizontalLine(x1, y1, x2, ccode);
Goji 0:6fa19738f62e 112 } else {
Goji 0:6fa19738f62e 113 int16_t dx = TFT_abs(x1, x2);
Goji 0:6fa19738f62e 114 int16_t dy = TFT_abs(y1, y2);
Goji 0:6fa19738f62e 115 int16_t sx = (x1 < x2) ? 1 : -1;
Goji 0:6fa19738f62e 116 int16_t sy = (y1 < y2) ? 1 : -1;
Goji 0:6fa19738f62e 117 int16_t er = dx - dy, e2;
Goji 0:6fa19738f62e 118
Goji 0:6fa19738f62e 119 while (1) {
Goji 0:6fa19738f62e 120 TFT_setPixels(x1, y1, ccode);
Goji 0:6fa19738f62e 121 if ((x1 == x2) && (y1 == y2)) break;
Goji 0:6fa19738f62e 122 e2 = er * 2;
Goji 0:6fa19738f62e 123 if (e2 > -dx) { er -= dy; x1 += sx; }
Goji 0:6fa19738f62e 124 if (e2 < dx) { er += dx; y1 += sy; }
Goji 0:6fa19738f62e 125 }
Goji 0:6fa19738f62e 126 }
Goji 0:6fa19738f62e 127 }
Goji 0:6fa19738f62e 128
Goji 0:6fa19738f62e 129
Goji 0:6fa19738f62e 130 void TFT_drawVerticalLine(int16_t x1, int16_t y1, int16_t y2, uint16_t ccode)
Goji 0:6fa19738f62e 131 {
Goji 0:6fa19738f62e 132 if ((x1 < TFT_info.xMIN) ||
Goji 0:6fa19738f62e 133 (x1 >= TFT_info.xMAX)) return;
Goji 0:6fa19738f62e 134
Goji 0:6fa19738f62e 135 if (y1 > y2) TFT_swap(y1, y2);
Goji 0:6fa19738f62e 136
Goji 0:6fa19738f62e 137 if (y1 < TFT_info.yMIN) y1 = TFT_info.yMIN;
Goji 0:6fa19738f62e 138 if (y1 >= TFT_info.yMAX) y1 = TFT_info.yMAX - 1;
Goji 0:6fa19738f62e 139 if (y2 < TFT_info.yMIN) y2 = TFT_info.yMIN;
Goji 0:6fa19738f62e 140 if (y2 >= TFT_info.yMAX) y2 = TFT_info.yMAX - 1;
Goji 0:6fa19738f62e 141
Goji 0:6fa19738f62e 142 mTFT_SET_ORENTATION(TFT_HV_VERT);
Goji 0:6fa19738f62e 143 TFT_setXY(x1, y1);
Goji 0:6fa19738f62e 144 while (y1++ <= y2)
Goji 0:6fa19738f62e 145 TFT_wr_data(ccode);
Goji 0:6fa19738f62e 146 mTFT_SET_ORENTATION(TFT_HV_HORZ);
Goji 0:6fa19738f62e 147 }
Goji 0:6fa19738f62e 148
Goji 0:6fa19738f62e 149
Goji 0:6fa19738f62e 150 void TFT_drawHorizontalLine(int16_t x1, int16_t y1, int16_t x2, uint16_t ccode)
Goji 0:6fa19738f62e 151 {
Goji 0:6fa19738f62e 152 if ((y1 < TFT_info.yMIN) ||
Goji 0:6fa19738f62e 153 (y1 >= TFT_info.yMAX)) return;
Goji 0:6fa19738f62e 154
Goji 0:6fa19738f62e 155 if (x1 > x2) TFT_swap(x1, x2);
Goji 0:6fa19738f62e 156
Goji 0:6fa19738f62e 157 if (x1 < TFT_info.xMIN) x1 = TFT_info.xMIN;
Goji 0:6fa19738f62e 158 if (x1 >= TFT_info.xMAX) x1 = TFT_info.xMAX - 1;
Goji 0:6fa19738f62e 159 if (x2 < TFT_info.xMIN) x2 = TFT_info.xMIN;
Goji 0:6fa19738f62e 160 if (x2 >= TFT_info.xMAX) x2 = TFT_info.xMAX - 1;
Goji 0:6fa19738f62e 161
Goji 0:6fa19738f62e 162 TFT_setXY(x1, y1);
Goji 0:6fa19738f62e 163 while (x1++ <= x2)
Goji 0:6fa19738f62e 164 TFT_wr_data(ccode);
Goji 0:6fa19738f62e 165 }
Goji 0:6fa19738f62e 166
Goji 0:6fa19738f62e 167
Goji 0:6fa19738f62e 168 void TFT_drawRectangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t ccode)
Goji 0:6fa19738f62e 169 {
Goji 0:6fa19738f62e 170 TFT_drawLine(x1, y1, x1, y2, ccode);
Goji 0:6fa19738f62e 171 TFT_drawLine(x1, y1, x2, y1, ccode);
Goji 0:6fa19738f62e 172 TFT_drawLine(x1, y2, x2, y2, ccode);
Goji 0:6fa19738f62e 173 TFT_drawLine(x2, y1, x2, y2, ccode);
Goji 0:6fa19738f62e 174 }
Goji 0:6fa19738f62e 175
Goji 0:6fa19738f62e 176
Goji 0:6fa19738f62e 177 void TFT_fillRectangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t lccode, uint16_t fccode)
Goji 0:6fa19738f62e 178 {
Goji 0:6fa19738f62e 179 if (y1 > y2) TFT_swap(y1, y2);
Goji 0:6fa19738f62e 180
Goji 0:6fa19738f62e 181 TFT_drawRectangle(x1++, y1++, x2--, y2--, lccode);
Goji 0:6fa19738f62e 182 #if (1)
Goji 0:6fa19738f62e 183 while (y1 <= y2)
Goji 0:6fa19738f62e 184 TFT_drawHorizontalLine(x1, y1++, x2, fccode);
Goji 0:6fa19738f62e 185 #else
Goji 0:6fa19738f62e 186 if (x1 < TFT_info.xMIN) x1 = TFT_info.xMIN;
Goji 0:6fa19738f62e 187 if (x1 >= TFT_info.xMAX) x1 = TFT_info.xMAX - 1;
Goji 0:6fa19738f62e 188 if (x2 < TFT_info.xMIN) x2 = TFT_info.xMIN;
Goji 0:6fa19738f62e 189 if (x2 >= TFT_info.xMAX) x2 = TFT_info.xMAX - 1;
Goji 0:6fa19738f62e 190
Goji 0:6fa19738f62e 191 while (y1 <= y2) {
Goji 0:6fa19738f62e 192 TFT_setXY(x1, y1++);
Goji 0:6fa19738f62e 193 for (int wx = x1; wx < x2; wx++)
Goji 0:6fa19738f62e 194 wr_data(fccode);
Goji 0:6fa19738f62e 195 }
Goji 0:6fa19738f62e 196 #endif
Goji 0:6fa19738f62e 197 }
Goji 0:6fa19738f62e 198
Goji 0:6fa19738f62e 199
Goji 0:6fa19738f62e 200 void TFT_drawCircle(int16_t x1, int16_t y1, int16_t r, uint16_t lccode, uint16_t fccode)
Goji 0:6fa19738f62e 201 {
Goji 0:6fa19738f62e 202 // http://fussy.web.fc2.com/algo/algo2-1.htm
Goji 0:6fa19738f62e 203 int32_t wx = r, wy = 0, lx = r, fx, fy;
Goji 0:6fa19738f62e 204 int32_t xy = (r * -2) + 3;
Goji 0:6fa19738f62e 205
Goji 0:6fa19738f62e 206 if (r < 1) return;
Goji 0:6fa19738f62e 207 while (wx >= wy) {
Goji 0:6fa19738f62e 208 TFT_setPixels(x1 - wx, y1 + wy, lccode);
Goji 0:6fa19738f62e 209 TFT_setPixels(x1 + wx, y1 + wy, lccode);
Goji 0:6fa19738f62e 210 TFT_setPixels(x1 - wx, y1 - wy, lccode);
Goji 0:6fa19738f62e 211 TFT_setPixels(x1 + wx, y1 - wy, lccode);
Goji 0:6fa19738f62e 212 TFT_setPixels(x1 - wy, y1 + wx, lccode);
Goji 0:6fa19738f62e 213 TFT_setPixels(x1 + wy, y1 + wx, lccode);
Goji 0:6fa19738f62e 214 TFT_setPixels(x1 - wy, y1 - wx, lccode);
Goji 0:6fa19738f62e 215 TFT_setPixels(x1 + wy, y1 - wx, lccode);
Goji 0:6fa19738f62e 216 if (fccode != BLACK1) {
Goji 0:6fa19738f62e 217 fx = wx + wx - 1;
Goji 0:6fa19738f62e 218 fy = wy + wy - 1;
Goji 0:6fa19738f62e 219 TFT_drawHorizontalLine((x1 - wx) + 1, y1 + wy, (x1 - wx) + 1 + fx, fccode);
Goji 0:6fa19738f62e 220 TFT_drawHorizontalLine((x1 - wx) + 1, y1 - wy, (x1 - wx) + 1 + fx, fccode);
Goji 0:6fa19738f62e 221 if (lx != wx) {
Goji 0:6fa19738f62e 222 lx = wx;
Goji 0:6fa19738f62e 223 TFT_drawHorizontalLine((x1 - wy) + 1, y1 + wx, (x1 - wy) + 1 + fy, fccode);
Goji 0:6fa19738f62e 224 TFT_drawHorizontalLine((x1 - wy) + 1, y1 - wx, (x1 - wy) + 1 + fy, fccode);
Goji 0:6fa19738f62e 225 }
Goji 0:6fa19738f62e 226 }
Goji 0:6fa19738f62e 227 if (xy >= 0) {
Goji 0:6fa19738f62e 228 wx--;
Goji 0:6fa19738f62e 229 xy -= wx << 2;
Goji 0:6fa19738f62e 230 }
Goji 0:6fa19738f62e 231 wy++;
Goji 0:6fa19738f62e 232 xy += ((wy << 2) + 2);
Goji 0:6fa19738f62e 233 }
Goji 0:6fa19738f62e 234 }
Goji 0:6fa19738f62e 235
Goji 0:6fa19738f62e 236
Goji 0:6fa19738f62e 237 uint32_t TFT_getFont(uint8_t *font, int16_t width, int16_t line)
Goji 0:6fa19738f62e 238 {
Goji 0:6fa19738f62e 239 if (width <= 8) {
Goji 0:6fa19738f62e 240 return (*(font + line) << (32 - 8));
Goji 0:6fa19738f62e 241 } else {
Goji 0:6fa19738f62e 242 if (width <= 12) {
Goji 0:6fa19738f62e 243 uint16_t n = line + (line >> 1); // n = line * 1.5
Goji 0:6fa19738f62e 244 if (line & 1) {
Goji 0:6fa19738f62e 245 return ((*(font + n) << (32 - 12)) | (*(font + n + 1) << (32 - 4)));
Goji 0:6fa19738f62e 246 } else {
Goji 0:6fa19738f62e 247 return ((*(font + n) << (32 - 16)) | (*(font + n + 1) << (32 - 8)));
Goji 0:6fa19738f62e 248 }
Goji 0:6fa19738f62e 249 } else {
Goji 0:6fa19738f62e 250 return (*(uint32_t *)((uint8_t *)font + ((width / 8) * line)));
Goji 0:6fa19738f62e 251 }
Goji 0:6fa19738f62e 252 }
Goji 0:6fa19738f62e 253 }
Goji 0:6fa19738f62e 254
Goji 0:6fa19738f62e 255
Goji 0:6fa19738f62e 256 void TFT_drawFont(int16_t x1, int16_t y1, int16_t width, int16_t line, uint8_t *font, uint16_t fccode, uint16_t bccode)
Goji 0:6fa19738f62e 257 {
Goji 0:6fa19738f62e 258 int j;
Goji 0:6fa19738f62e 259 uint32_t k;
Goji 0:6fa19738f62e 260
Goji 0:6fa19738f62e 261 if (((x1 + width) < TFT_info.xMIN) || (x1 >= TFT_info.xMAX) ||
Goji 0:6fa19738f62e 262 ((y1 + line ) < TFT_info.yMIN) || (y1 >= TFT_info.yMAX)) return;
Goji 0:6fa19738f62e 263
Goji 0:6fa19738f62e 264 for (int i = 0; i < line; i++) {
Goji 0:6fa19738f62e 265 uint32_t p = TFT_getFont(font, width, i);
Goji 0:6fa19738f62e 266 for (j = 0, k = 0x80000000; j < width; j++, k >>= 1) {
Goji 0:6fa19738f62e 267 if (p & k)
Goji 0:6fa19738f62e 268 TFT_setPixels(x1 + j, y1 + i, fccode);
Goji 0:6fa19738f62e 269 else
Goji 0:6fa19738f62e 270 if (bccode != BLACK1)
Goji 0:6fa19738f62e 271 TFT_setPixels(x1 + j, y1 + i, bccode);
Goji 0:6fa19738f62e 272 }
Goji 0:6fa19738f62e 273 }
Goji 0:6fa19738f62e 274 }
Goji 0:6fa19738f62e 275
Goji 0:6fa19738f62e 276
Goji 0:6fa19738f62e 277 int16_t TFT_drawText(int16_t x1, int16_t y1, uint8_t *s, uint16_t fccode, uint16_t bccode)
Goji 0:6fa19738f62e 278 {
Goji 0:6fa19738f62e 279 uint8_t cc;
Goji 0:6fa19738f62e 280
Goji 0:6fa19738f62e 281 while ((cc = *s++) != '\0') {
Goji 0:6fa19738f62e 282 if (cc > 0x7F) cc = ' ';
Goji 0:6fa19738f62e 283 TFT_drawFont(x1, y1, 8, 12, (uint8_t*)&font8x12A[cc][0], fccode, bccode);
Goji 0:6fa19738f62e 284 x1 += 8;
Goji 0:6fa19738f62e 285 }
Goji 0:6fa19738f62e 286 return x1;
Goji 0:6fa19738f62e 287 }