tested on STM32 Nucleo L152RE
Dependencies: aqm1248a_lcd mbed GT20L16J1Y_font
main.cpp
00001 #include "mbed.h" 00002 #include "aqm1248a_lcd.h" 00003 #include "GT20L16J1Y_font.h" 00004 #include "utf8_table.h" 00005 00006 #include <stdlib.h> 00007 00008 aqm1248a_lcd lcd; 00009 00010 const static 00011 char mbedlogo128x48[768] 00012 = { 00013 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00014 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00015 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00016 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00017 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00018 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00019 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00020 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00021 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00022 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00023 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00024 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00, 00025 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00, 00026 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00, 00027 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00, 00028 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00, 00029 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00, 00030 0x00,0x00,0x03,0xc7,0x83,0xe0,0x3c,0x7c,0x00,0x7e,0x00,0x3e,0x3c,0x00,0x00,0x00, 00031 0x00,0x00,0x03,0xdf,0xef,0xf8,0x3d,0xfe,0x01,0xff,0x80,0x7f,0xbc,0x00,0x00,0x00, 00032 0x00,0x00,0x03,0xff,0xff,0xf8,0x3f,0xff,0x03,0xff,0xc0,0xff,0xfc,0x00,0x00,0x00, 00033 0x00,0x00,0x03,0xf1,0xfc,0x7c,0x3f,0x0f,0x87,0xc3,0xe1,0xf0,0xfc,0x00,0x00,0x00, 00034 0x00,0x00,0x03,0xe0,0xf8,0x3c,0x3e,0x07,0x87,0x81,0xe1,0xe0,0x7c,0x00,0x00,0x00, 00035 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0x00,0xe3,0xc0,0x3c,0x00,0x00,0x00, 00036 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0x00,0xf3,0xc0,0x3c,0x00,0x00,0x00, 00037 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0xff,0xf3,0xc0,0x3c,0x00,0x00,0x00, 00038 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0xff,0xf3,0xc0,0x3c,0x00,0x00,0x00, 00039 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0xff,0xf3,0xc0,0x3c,0x00,0x00,0x00, 00040 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0x00,0x03,0xc0,0x3c,0x00,0x00,0x00, 00041 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3e,0x03,0xcf,0x00,0x03,0xc0,0x7c,0x00,0x00,0x00, 00042 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3e,0x07,0x87,0x80,0x01,0xe0,0x7c,0x00,0x00,0x00, 00043 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3f,0x0f,0x87,0xc1,0xc1,0xf0,0xfc,0x00,0x00,0x00, 00044 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3f,0xff,0x03,0xff,0xf0,0xff,0xfc,0x00,0x00,0x00, 00045 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3d,0xfe,0x01,0xff,0xe0,0x7f,0xbc,0x00,0x00,0x00, 00046 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0xfc,0x00,0x7f,0x00,0x3f,0x3c,0x00,0x00,0x00, 00047 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00048 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00049 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00050 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00051 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00052 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00053 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00054 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00055 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00056 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00057 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00058 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00059 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00060 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 00061 }; 00062 00063 00064 const static struct Bitmap logo = { 00065 128, 00066 48, 00067 16, 00068 (char*)mbedlogo128x48, 00069 }; 00070 00071 const char target[] = 00072 #if defined(TARGET_NUCLEO_L152RE) 00073 "STM32 Nucleo L152RE" 00074 #elif defined(TARGET_KL05Z) 00075 "Freescale FRDM-KL05Z" 00076 #else 00077 "????" 00078 #endif 00079 ; 00080 00081 #if defined(TARGET_NUCLEO_L152RE) 00082 GT20L16J1Y_FONT font(D4, D5, D3, D2); 00083 #else 00084 GT20L16J1Y_FONT font(p11, p12, p13, p10); 00085 #endif 00086 00087 #define numOfCharBuffer 40 00088 uint16_t kBuf[numOfCharBuffer]; 00089 00090 void draw_string(int offset_x, int offset_y, int width) 00091 { 00092 int color; 00093 for(int x=0; x<width*2; x++) 00094 { 00095 for(int y=0; y<8; y++) 00096 { 00097 if (font.bitmap[x] & (1<<y)) 00098 color = 1; 00099 else 00100 color = 0; 00101 lcd.pixel(x%width + offset_x, y+(8*(x/width)) + offset_y, color); 00102 } 00103 } 00104 lcd.copy_to_lcd(); 00105 } 00106 00107 int int_compar(const uint16_t *a, const uint16_t *b) 00108 { 00109 if (*a < *b) 00110 return (-1); 00111 else if (*a > *b) 00112 return (1); 00113 else 00114 return (0); 00115 } 00116 00117 int conv_utf8(char* utfBuffer, uint16_t* kutenBuffer) 00118 { 00119 int ret; 00120 uint16_t key, *index, *pBuf; 00121 char *uBuf; 00122 00123 uBuf = utfBuffer; 00124 pBuf = kutenBuffer; 00125 ret = 0; 00126 00127 while (uBuf[0] != 0) { 00128 if (uBuf[0] >= 0x20 && uBuf[0] < 0x80) { 00129 // in case of ASCII 00130 *pBuf++ = (uint16_t)uBuf[0]; 00131 uBuf += 1; 00132 ret++; 00133 continue; 00134 } 00135 else if ( (uBuf[0]&0xF0) != 0xE0) { 00136 uBuf += 1; 00137 continue; 00138 } 00139 // extract valid bits of UTF-8 00140 key = ((uBuf[0] & 0x000F) << 12) | ((uBuf[1] & 0x003F) << 6) | (uBuf[2] & 0x003F); 00141 00142 // search UTF-8 code from utf8_key[] table to get index of Kuten table 00143 index = (uint16_t *)bsearch(&key, utf8_key, (sizeof(utf8_key) / sizeof(utf8_key[0])), sizeof(uint16_t), (int (*)(const void *, const void *))int_compar); 00144 if (index != 0) { 00145 // get Kuten code 00146 *pBuf = utf8_value[index - utf8_key]; 00147 } 00148 00149 uBuf += 3; 00150 pBuf++; 00151 ret++; 00152 } 00153 *pBuf = 0; 00154 00155 return ret; 00156 } 00157 00158 void draw_utf8(int offset_x, int offset_y, char *buf_u) 00159 { 00160 int len = conv_utf8(buf_u, kBuf); 00161 int xpos = 0; 00162 00163 for(int i = 0; i < len; i++) { 00164 int width = font.read_kuten(kBuf[i]); 00165 draw_string(xpos + offset_x, offset_y, width); 00166 xpos += width; 00167 } 00168 } 00169 00170 00171 int main() { 00172 unsigned short kbuf[16] = {0x93fa, 0x967b, 0x8cea, 0x955c, 0x8ea6}; 00173 00174 printf("%s\r\n", target); 00175 lcd.setmode(NORMAL); 00176 // lcd.set_font((unsigned char*) Arial_9); 00177 lcd.set_contrast(25); 00178 while (1) { 00179 lcd.cls(); 00180 lcd.locate(0,0); 00181 lcd.printf("\r\n %s!\r\n This is AQM1248A demo.", target); 00182 00183 wait(1); 00184 lcd.cls(); 00185 draw_utf8(0, 0, "進捗どうですか??"); 00186 draw_utf8(0, 16, "mbedで日本語表示"); 00187 wait(5); 00188 // continue; 00189 00190 // wait(1); 00191 lcd.cls(); 00192 lcd.line(0, 0, lcd.width()-1, 0, 1); 00193 lcd.line(0, 0, lcd.width()-1, lcd.height()-1, 1); 00194 lcd.line(0, 0, 0, lcd.height()-1, 1); 00195 wait(1); 00196 lcd.circle(12, 32, 10, 1); 00197 lcd.fillcircle(24, 32, 10, 1); 00198 lcd.rect(36, 32, 48, 44, 1); 00199 lcd.fillrect(60, 32, 72, 44, 1); 00200 wait(1); 00201 lcd.print_bm(logo, 0, 0); 00202 // lcd.copy_to_lcd(); 00203 lcd.printf("\r\n\r\n %s", target); 00204 00205 wait(12); 00206 } 00207 }
Generated on Sat Jul 16 2022 04:57:53 by 1.7.2