aitendo C128X64SPI-12P-M with FRDM KL25Z

Dependencies:   mbed

/media/uploads/masato/c128x64spi-12p_2.jpg

aitendo の FSTN液晶モジュール(128x64/SPI)[C128X64SPI-12P-M] を KL25Z につないでみました。今のところ、ドット、ライン操作までしか用意できていません。コントローラ仕様によるとデバイスからデータを取得することができるのですが、シリアル(SPI)ではできないことになっているため、フレームバッファは自前で持っています。テスト用にドラゴン曲線を表示させてみました。

ところで aitendo の商品説明ページ中の FPCケーブル取り付け例の写真は誤っていました(修正された模様)。また、キャリーボードでの LCD とバックライトの GND と電源は直結されているようです。ついでにサンプルのコードでのフレームバッファの使い方にも誤りがありますからドット単位で操作する場合には注意が必要です。

2014.03.12
q61.org さんの Chibimo 表示器として使えるようにしてみました。ドラゴン曲線を描いた後、ホストからの Chibimo データを処理します。KL05 とトラ技 ARM ライタ基板でも動作を確認していますが、Chibimo として使うには USB シリアルの使える KL* が良いでしょう。

/media/uploads/masato/12876787564_6915e1f553_z.jpg

Committer:
masato
Date:
Mon Mar 03 03:28:29 2014 +0000
Revision:
1:84b2d36d57f0
Parent:
0:b06afbefd350
Child:
2:f6b27ec62471
supports Chibimo; http://q61.org/chibimo/build/

Who changed what in which revision?

UserRevisionLine numberNew contents of line
masato 1:84b2d36d57f0 1 /* ---
masato 1:84b2d36d57f0 2 aitendo C128X64SPI-12P-M with FRDM-KL25Z, KL05Z and TRAGI-ARM Writer
masato 1:84b2d36d57f0 3
masato 1:84b2d36d57f0 4 * supports Chibimo
masato 1:84b2d36d57f0 5 --- */
masato 1:84b2d36d57f0 6
masato 0:b06afbefd350 7 #include "mbed.h"
masato 0:b06afbefd350 8 #include "c128x64spi.h"
masato 0:b06afbefd350 9
masato 1:84b2d36d57f0 10 // -- for KL25Z
masato 1:84b2d36d57f0 11 // c128x64spi fstn(PTD2, PTD3, PTD1, PTD0, PTD5, PTA13); // mosi, miso, sclk, cs, rs, reset
masato 1:84b2d36d57f0 12 // Serial pc(USBTX, USBRX);
masato 1:84b2d36d57f0 13 // -- for KL05Z
masato 1:84b2d36d57f0 14 c128x64spi fstn(PTA7, PTA6, PTB0, PTA5, PTB11, PTB10); // mosi, miso, sclk, cs, rs, reset
masato 0:b06afbefd350 15 Serial pc(USBTX, USBRX);
masato 1:84b2d36d57f0 16 // -- for TORA-GI U35
masato 1:84b2d36d57f0 17 // c128x64spi fstn(P0_21, P0_22, P1_15, P0_6, P0_11, P0_12); // mosi, miso, sclk, cs, rs, reset
masato 1:84b2d36d57f0 18 // Serial pc(P0_19, P0_18);
masato 1:84b2d36d57f0 19
masato 0:b06afbefd350 20 #define COLOR 1
masato 0:b06afbefd350 21 #define BG_COLOR 0
masato 0:b06afbefd350 22
masato 0:b06afbefd350 23 void Dragon(int x1,int y1,int x2,int y2,int lv)
masato 0:b06afbefd350 24 {
masato 0:b06afbefd350 25 // pc.printf("Enter Dragon(%d,%d,%d,%d,%d)\r\n", x1, y1, x2, y2, lv);
masato 0:b06afbefd350 26 int h,x3,y3;
masato 0:b06afbefd350 27 if (x1 == x2) {
masato 0:b06afbefd350 28 h = abs(y1 - y2) / 2;
masato 0:b06afbefd350 29 if (h * lv == 0) {
masato 0:b06afbefd350 30 fstn.line(x1, y1, x2, y2, COLOR); //ここで(x1,y1)から(x2,y2)まで線を描く
masato 0:b06afbefd350 31 } else {
masato 0:b06afbefd350 32 if (y1 < y2) {
masato 0:b06afbefd350 33 x3 = x1 + h;
masato 0:b06afbefd350 34 y3 = y1 + h;
masato 0:b06afbefd350 35 } else {
masato 0:b06afbefd350 36 x3 = x1 - h;
masato 0:b06afbefd350 37 y3 = y1 - h;
masato 0:b06afbefd350 38 }
masato 0:b06afbefd350 39 Dragon(x1, y1, x3, y3, lv - 1);
masato 0:b06afbefd350 40 Dragon(x2, y2, x3, y3, lv - 1);
masato 0:b06afbefd350 41 }
masato 0:b06afbefd350 42 } else if (y1 == y2) {
masato 0:b06afbefd350 43 h = abs(x1 - x2) / 2;
masato 0:b06afbefd350 44 if (h * lv == 0) {
masato 0:b06afbefd350 45 fstn.line(x1, y1, x2, y2, COLOR);//ここで(x1,y1)から(x2,y2)まで線を描く
masato 0:b06afbefd350 46 } else {
masato 0:b06afbefd350 47 if (x1 < x2) {
masato 0:b06afbefd350 48 x3 = x1 + h;
masato 0:b06afbefd350 49 y3 = y1 - h;
masato 0:b06afbefd350 50 } else {
masato 0:b06afbefd350 51 x3 = x1 - h;
masato 0:b06afbefd350 52 y3 = y1 + h;
masato 0:b06afbefd350 53 }
masato 0:b06afbefd350 54 Dragon(x1,y1,x3,y3,lv - 1);
masato 0:b06afbefd350 55 Dragon(x2,y2,x3,y3,lv - 1);
masato 0:b06afbefd350 56 }
masato 0:b06afbefd350 57 } else {
masato 0:b06afbefd350 58 if (lv == 0) {
masato 0:b06afbefd350 59 fstn.line(x1, y1, x2, y2, COLOR);//ここで(x1,y1)から(x2,y2)まで線を描く
masato 0:b06afbefd350 60 } else if (x1 < x2) {
masato 0:b06afbefd350 61 if (y1 < y2) {
masato 0:b06afbefd350 62 Dragon(x1,y1,x2,y1,lv - 1);
masato 0:b06afbefd350 63 Dragon(x2,y2,x2,y1,lv - 1);
masato 0:b06afbefd350 64 } else {
masato 0:b06afbefd350 65 Dragon(x1,y1,x1,y2,lv - 1);
masato 0:b06afbefd350 66 Dragon(x2,y2,x1,y2,lv - 1);
masato 0:b06afbefd350 67 }
masato 0:b06afbefd350 68 } else {
masato 0:b06afbefd350 69 if (y1 < y2) {
masato 0:b06afbefd350 70 Dragon(x1,y1,x1,y2,lv - 1);
masato 0:b06afbefd350 71 Dragon(x2,y2,x1,y2,lv - 1);
masato 0:b06afbefd350 72 } else {
masato 0:b06afbefd350 73 Dragon(x1,y1,x2,y1,lv - 1);
masato 0:b06afbefd350 74 Dragon(x2,y2,x2,y1,lv - 1);
masato 0:b06afbefd350 75 }
masato 0:b06afbefd350 76 }
masato 0:b06afbefd350 77 }
masato 0:b06afbefd350 78 // pc.printf("Leave Dragon(%d,%d,%d,%d,%d)\r\n", x1, y1, x2, y2, lv);
masato 0:b06afbefd350 79 }
masato 0:b06afbefd350 80
masato 0:b06afbefd350 81 int main() {
masato 0:b06afbefd350 82 int i, x, y;
masato 0:b06afbefd350 83
masato 1:84b2d36d57f0 84 pc.baud(115200);
masato 1:84b2d36d57f0 85 // pc.printf("start\r\n");
masato 0:b06afbefd350 86 #if 0
masato 0:b06afbefd350 87 for (y = 0; y < 64; y++)
masato 0:b06afbefd350 88 for (x = 0; x < 128; x++)
masato 0:b06afbefd350 89 fstn.pixel(x, y, 1);
masato 0:b06afbefd350 90 wait(1);
masato 0:b06afbefd350 91 for (y = 0; y < 64; y++)
masato 0:b06afbefd350 92 for (x = 0; x < 128; x++)
masato 0:b06afbefd350 93 fstn.pixel(x, y, 0);
masato 0:b06afbefd350 94 wait(1);
masato 0:b06afbefd350 95
masato 0:b06afbefd350 96 fstn.clr(0);
masato 0:b06afbefd350 97 for (x = 0; x < 64; x++)
masato 0:b06afbefd350 98 fstn.pixel(x, x, 1);
masato 0:b06afbefd350 99 wait(1);
masato 0:b06afbefd350 100
masato 0:b06afbefd350 101 fstn.clr(0);
masato 0:b06afbefd350 102 fstn.hline(0, 127, 32, 1);
masato 0:b06afbefd350 103 wait(1);
masato 0:b06afbefd350 104
masato 0:b06afbefd350 105 fstn.clr(0);
masato 0:b06afbefd350 106 fstn.vline(63, 0, 63, 1);
masato 0:b06afbefd350 107 wait(1);
masato 0:b06afbefd350 108
masato 0:b06afbefd350 109 fstn.clr(0);
masato 0:b06afbefd350 110 fstn.line(0, 0, 127, 63, 1);
masato 0:b06afbefd350 111 fstn.line(127, 0, 0, 63, 1);
masato 0:b06afbefd350 112 wait(1);
masato 0:b06afbefd350 113 #endif
masato 0:b06afbefd350 114 // Dragon
masato 1:84b2d36d57f0 115 // while (1)
masato 1:84b2d36d57f0 116 {
masato 0:b06afbefd350 117 for (i = 0; i < 12; i++) {
masato 1:84b2d36d57f0 118 // pc.printf("dragon %d\r\n", i);
masato 0:b06afbefd350 119 fstn.clr(BG_COLOR);
masato 0:b06afbefd350 120 Dragon(32, 42, 96, 42, i);
masato 0:b06afbefd350 121 wait(0.5);
masato 0:b06afbefd350 122 }
masato 0:b06afbefd350 123 wait(20);
masato 0:b06afbefd350 124 }
masato 1:84b2d36d57f0 125
masato 1:84b2d36d57f0 126 unsigned char ph = 0; // state
masato 1:84b2d36d57f0 127 unsigned char pxdt[20]; // buffer
masato 1:84b2d36d57f0 128 unsigned char dt;
masato 1:84b2d36d57f0 129 while (1) {
masato 1:84b2d36d57f0 130 if (pc.readable()) {
masato 1:84b2d36d57f0 131 dt = pc.getc();
masato 1:84b2d36d57f0 132 switch (ph++) {
masato 1:84b2d36d57f0 133 case 0: // reset state - get locate Y
masato 1:84b2d36d57f0 134 if (dt & 0xC0) {
masato 1:84b2d36d57f0 135 ph = 0; // invalid address, reset state
masato 1:84b2d36d57f0 136 } else {
masato 1:84b2d36d57f0 137 // lcd locate Y
masato 1:84b2d36d57f0 138 y = dt >> 3;
masato 1:84b2d36d57f0 139 x = dt & 0x07;
masato 1:84b2d36d57f0 140 fstn.locate_y(y);
masato 1:84b2d36d57f0 141 x <<= 4;
masato 1:84b2d36d57f0 142 }
masato 1:84b2d36d57f0 143 break;
masato 1:84b2d36d57f0 144 case 1: // get pxdt[1]
masato 1:84b2d36d57f0 145 // delayMicroseconds(5);
masato 1:84b2d36d57f0 146 fstn.locate_x(x);
masato 1:84b2d36d57f0 147 pxdt[ph] = dt;
masato 1:84b2d36d57f0 148 break;
masato 1:84b2d36d57f0 149 case 2: case 3: case 4: case 5: case 6: case 7:
masato 1:84b2d36d57f0 150 case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: //
masato 1:84b2d36d57f0 151 fstn.wr_dat(pxdt[ph - 1]);
masato 1:84b2d36d57f0 152 pxdt[ph] = dt;
masato 1:84b2d36d57f0 153 break;
masato 1:84b2d36d57f0 154 case 16:
masato 1:84b2d36d57f0 155 fstn.wr_dat(pxdt[ph - 1]);
masato 1:84b2d36d57f0 156 // delayMicroseconds(5);
masato 1:84b2d36d57f0 157 fstn.wr_dat(dt);
masato 1:84b2d36d57f0 158 ph = 0;
masato 1:84b2d36d57f0 159 break;
masato 1:84b2d36d57f0 160 default:
masato 1:84b2d36d57f0 161 ph = 0;
masato 1:84b2d36d57f0 162 break;
masato 1:84b2d36d57f0 163 }
masato 1:84b2d36d57f0 164 }
masato 1:84b2d36d57f0 165 }
masato 0:b06afbefd350 166 }