SHARPメモリ液晶+つぼフォント(GT20L16J1Y) の表示サンプル。 半角カナ(JIS X 0201)と、2バイトUTF-8コード(顔文字に使用)に対応。
Dependencies: GT20L16J1Y_font TFT_fonts mbed sharp_mlcd
Fork of hello_GT20L16J1Y_FONT by
Diff: main.cpp
- Revision:
- 3:b095be7ec287
- Parent:
- 0:b468ef973095
- Child:
- 4:ad167108200d
--- a/main.cpp Wed Jan 15 07:05:48 2014 +0000
+++ b/main.cpp Thu Sep 04 06:55:37 2014 +0000
@@ -1,19 +1,31 @@
#include "mbed.h"
-#include "C12832_lcd.h"
+#include "C12832.h"
#include "GT20L16J1Y_font.h"
+#include "utf8_table.h"
+
+#include <stdlib.h>
/*
GT20L16J1Y library test program
- works with mbed application board
*/
-C12832_LCD lcd;
+DigitalOut led(LED1);
+
+#if defined(TARGET_LPC1768)
+C12832 lcd(p5, p7, p6, p8, p11);
GT20L16J1Y_FONT font(p11, p12, p13, p10);
+#elif defined(TARGET_LPC11U68)
+C12832 lcd(D11, D13, D12, D7, D10);
+GT20L16J1Y_FONT font(P0_21, P0_22, P1_20, P0_23);
+#endif
-void draw_kanji(int offset_x, int offset_y)
+#define numOfCharBuffer 40
+uint16_t kBuf[numOfCharBuffer];
+
+void draw_string(int offset_x, int offset_y, int width)
{
int color;
- for(int x=0; x<32; x++)
+ for(int x=0; x<width*2; x++)
{
for(int y=0; y<8; y++)
{
@@ -21,30 +33,83 @@
color = 1;
else
color = 0;
- lcd.pixel(x%16 + offset_x, y+(8*(x>>4)) + offset_y, color);
+ lcd.pixel(x%width + offset_x, y+(8*(x/width)) + offset_y, color);
}
}
lcd.copy_to_lcd();
}
+int int_compar(const uint16_t *a, const uint16_t *b)
+{
+ if (*a < *b)
+ return (-1);
+ else if (*a > *b)
+ return (1);
+ else
+ return (0);
+}
+
+int conv_utf8(char* utfBuffer, uint16_t* kutenBuffer)
+{
+ int ret;
+ uint16_t key, *index, *pBuf;
+ char *uBuf;
+
+ uBuf = utfBuffer;
+ pBuf = kutenBuffer;
+ ret = 0;
+
+ while (uBuf[0] != 0) {
+ if (uBuf[0] >= 0x20 && uBuf[0] < 0x80) {
+ // in case of ASCII
+ *pBuf++ = (uint16_t)uBuf[0];
+ uBuf += 1;
+ ret++;
+ continue;
+ }
+ else if ( (uBuf[0]&0xF0) != 0xE0) {
+ uBuf += 1;
+ continue;
+ }
+ // extract valid bits of UTF-8
+ key = ((uBuf[0] & 0x000F) << 12) | ((uBuf[1] & 0x003F) << 6) | (uBuf[2] & 0x003F);
+
+ // search UTF-8 code from utf8_key[] table to get index of Kuten table
+ index = (uint16_t *)bsearch(&key, utf8_key, (sizeof(utf8_key) / sizeof(utf8_key[0])), sizeof(uint16_t), (int (*)(const void *, const void *))int_compar);
+ if (index != 0) {
+ // get Kuten code
+ *pBuf = utf8_value[index - utf8_key];
+ }
+
+ uBuf += 3;
+ pBuf++;
+ ret++;
+ }
+ *pBuf = 0;
+
+ return ret;
+}
+
+void draw_utf8(int offset_x, int offset_y, char *buf_u)
+{
+ int len = conv_utf8(buf_u, kBuf);
+ int xpos = 0;
+
+ for(int i = 0; i < len; i++) {
+ int width = font.read_kuten(kBuf[i]);
+ draw_string(xpos + offset_x, offset_y, width);
+ xpos += width;
+ }
+}
+
int main()
{
- unsigned short kbuf[16] = {
- 0x9069,
- 0x92BB,
- 0x82C7,
- 0x82A4,
- 0x82C5,
- 0x82B7,
- 0x82A9,
- 0x8148
- };
-
+ led = 0;
lcd.cls();
-
- for(int i=0; i<8; i++) {
- font.read(kbuf[i]);
- draw_kanji(16*i, 0);
+ draw_utf8(0, 0, "進捗どうですか??");
+ draw_utf8(0, 16, "mbedで日本語表示");
+ while(1) {
+ led = !led;
+ wait(1.0);
}
-
}
ban4jp -
