tested on STM32 Nucleo L152RE
Dependencies: aqm1248a_lcd mbed GT20L16J1Y_font
STM32 Nucleo L152RE/mbed と Freescale FRDM-KL05Z で秋月 AQM1248A グラフィック LCD をドライブ。AQM1248A 用 LCD ライブラリは http://mbed.org/users/dreschpe/code/C12832_lcd/ をベースに変更しました。mbed LPC1768 でも動く筈です(未確認)。
ピン配置はライブラリの aqm1248a_lcd.cpp 内で指定しており、Nucleo L152RE では次のようにしています。LPC1768 mbed ではオリジナルのままです。
Nucleo | LPC1768 | name |
---|---|---|
D11 | p5 | SPI MOSI |
D13 | p7 | SPI Clock |
D10 | p11 | SPI chip select |
D9 | p6 | reset |
D8 | p8 | A0 |
条件コンパイルの TARGET_NUCLEO_L152RE の部分に追加すれば、ほとんどそのままで他の Nucleo ボードなどで動くと思います。
- 2014.04.27 mbed ライブラリを更新でテキスト描画が随分と高速化されました。Freescale FRDM-KL05Z でも動作確認しました。同じ配線で動きます。
Diff: main.cpp
- Revision:
- 3:93270b9f6a01
- Parent:
- 2:862f6ab24cfc
--- a/main.cpp Sun Apr 27 14:38:57 2014 +0000 +++ b/main.cpp Tue Jun 02 12:25:13 2015 +0000 @@ -1,5 +1,9 @@ #include "mbed.h" #include "aqm1248a_lcd.h" +#include "GT20L16J1Y_font.h" +#include "utf8_table.h" + +#include <stdlib.h> aqm1248a_lcd lcd; @@ -74,7 +78,99 @@ #endif ; +#if defined(TARGET_NUCLEO_L152RE) +GT20L16J1Y_FONT font(D4, D5, D3, D2); +#else +GT20L16J1Y_FONT font(p11, p12, p13, p10); +#endif + +#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<width*2; x++) + { + for(int y=0; y<8; y++) + { + if (font.bitmap[x] & (1<<y)) + color = 1; + else + color = 0; + 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] = {0x93fa, 0x967b, 0x8cea, 0x955c, 0x8ea6}; + printf("%s\r\n", target); lcd.setmode(NORMAL); // lcd.set_font((unsigned char*) Arial_9); @@ -82,9 +178,17 @@ while (1) { lcd.cls(); lcd.locate(0,0); - lcd.printf("\r\n %s!\r\n This is AQM1248A demo.", target); + lcd.printf("\r\n %s!\r\n This is AQM1248A demo.", target); + + wait(1); + lcd.cls(); + draw_utf8(0, 0, "進捗どうですか??"); + draw_utf8(0, 16, "mbedで日本語表示"); + wait(5); + // continue; - wait(1); + // wait(1); + lcd.cls(); lcd.line(0, 0, lcd.width()-1, 0, 1); lcd.line(0, 0, lcd.width()-1, lcd.height()-1, 1); lcd.line(0, 0, 0, lcd.height()-1, 1);