how to use zy-fgd1442701v1 with mbed

18
aitendoの正方形LCDをmbedで駆動させる ZY-FGD1442701V1(ST7735S搭載版) Kei Yoshimura (@9SQ)

Upload: kei-yoshimura

Post on 18-Jul-2015

190 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: how to use ZY-FGD1442701V1 with mbed

aitendoの正方形LCDをmbedで駆動させる !

ZY-FGD1442701V1(ST7735S搭載版)

Kei Yoshimura (@9SQ)

Page 2: how to use ZY-FGD1442701V1 with mbed

ZY-FGD1442701V1 (ST7735S)

• 1.44インチTFT液晶モジュール

• 解像度:128x128

• コントローラチップ:ST7735S

• 表示領域:26.496×25.4976mm

• 接続インターフェース:8bitパラレル

• 0.8mmピッチ27ピンFPC

• http://www.aitendo.com/product/1621→データシート、初期化コード あり!

!ST7735搭載版は販売終了! →非S版とS版でコマンドに変更あり

Page 3: how to use ZY-FGD1442701V1 with mbed
Page 4: how to use ZY-FGD1442701V1 with mbed

LCD_Write_CMD(0xE0); // Gamma Adjustment (+Polarity) LCD_Write_Data(0x03); LCD_Write_Data(0x1B); LCD_Write_Data(0x09); LCD_Write_Data(0x0E); LCD_Write_Data(0x32); LCD_Write_Data(0x2D); LCD_Write_Data(0x28); LCD_Write_Data(0x2C); LCD_Write_Data(0x2B); LCD_Write_Data(0x29); LCD_Write_Data(0x30); LCD_Write_Data(0x3B); LCD_Write_Data(0x00); LCD_Write_Data(0x01); LCD_Write_Data(0x02); LCD_Write_Data(0x10); LCD_Write_CMD(0xE1); // Gamma Adjustment (-Polarity) LCD_Write_Data(0x03); LCD_Write_Data(0x1B); LCD_Write_Data(0x09); LCD_Write_Data(0x0E); LCD_Write_Data(0x32); LCD_Write_Data(0x2E); LCD_Write_Data(0x28); LCD_Write_Data(0x2C); LCD_Write_Data(0x2B); LCD_Write_Data(0x28); LCD_Write_Data(0x31); LCD_Write_Data(0x3C); LCD_Write_Data(0x00); LCD_Write_Data(0x00); LCD_Write_Data(0x02); LCD_Write_Data(0x10); ! LCD_Write_CMD(0x3A); // Interface Pixel Format LCD_Write_Data(0x05); // 16-bit/pixel ! LCD_Write_CMD(0x2A); // Column Address Set LCD_Write_Data(0x00); LCD_Write_Data(0x02); LCD_Write_Data(0x00); LCD_Write_Data(0x81); LCD_Write_CMD(0x2B); // Row Address Set LCD_Write_Data(0x00); LCD_Write_Data(0x01); LCD_Write_Data(0x00); LCD_Write_Data(0x80); ! wait_ms(100); LCD_Write_CMD(0x2C); // Memory Write }

void LCD_Init(void) { LCD_Reset(); ! LCD_Write_CMD(0xB1); // In Normal Mode(Full Colors) Frame rate 80Hz LCD_Write_Data(0x02); LCD_Write_Data(0x35); LCD_Write_Data(0x36); ! LCD_Write_CMD(0xB2); // In Idle Mode(8-colors) LCD_Write_Data(0x02); LCD_Write_Data(0x35); LCD_Write_Data(0x36); ! LCD_Write_CMD(0xB3); // In Partial Mode + Full Colors LCD_Write_Data(0x02); LCD_Write_Data(0x35); LCD_Write_Data(0x36); LCD_Write_Data(0x02); LCD_Write_Data(0x35); LCD_Write_Data(0x36); ! LCD_Write_CMD(0xB4); // Dot Inversion Control LCD_Write_Data(0x03); // Inversion setting in Idle mode and full Colors partial mode ! LCD_Write_CMD(0xC0); // Power Control Setting (GVDD Voltage) LCD_Write_Data(0xA2); // AVDD=5, GVDD=4.6 LCD_Write_Data(0x02); // VGCL=-4.6 LCD_Write_Data(0x84); // MODE=AUTO ! LCD_Write_CMD(0xC1); // Power Control Setting (VGH/VGL Voltage) LCD_Write_Data(0xC5); // VGH and VGL supply power level = 2.4, VGL=-10, VGH=3*AVDD-0.5 ! LCD_Write_CMD(0xC2); // In Normal Mode(Full Colors) APA/DCA LCD_Write_Data(0x0D); // SAP=Small, AP=Large LCD_Write_Data(0x00); // Clock frequency for Booster circuit/1,/3,/1,/1,/1 ! LCD_Write_CMD(0xC3); // In Idle Mode(8-colors) APA/DCA LCD_Write_Data(0x8D); LCD_Write_Data(0xEA); ! LCD_Write_CMD(0xC4); // In Partial Mode(Full Colors) APA/DCA LCD_Write_Data(0x8D); LCD_Write_Data(0xEE); ! LCD_Write_CMD(0xC5); // VCOM LCD_Write_Data(0x05); // -0.55 ! LCD_Write_CMD(0x36); // Memory Data Access Control LCD_Write_Data(0x48); // MX, RGB mode (Row Address Order, RGB color filter panel)

aitendoが公開している初期化コードを ベースに若干の変更・追加 (+コメント)初期化

Page 5: how to use ZY-FGD1442701V1 with mbed

void LCD_Write_CMD(unsigned char cmd) { CS0=0; RD=1; CD=0; P1=cmd; WR=0; WR=1; CS0=1; } !void LCD_Write_Data(unsigned char d) { CS0=0; RD=1; CD=1; P1=d; WR=0; WR=1; CS0=1; } !void LCD_Reset(void) { RSTB=1; wait_ms(1); RSTB=0; wait_ms(1); RSTB=1; wait_ms(120); LCD_Write_CMD(0x11); // Sleep Out and Booster On wait_ms(120); }

RSTB

CS0

CD

RD

WR

コマンド・データ送信、リセット

RSTB

Page 6: how to use ZY-FGD1442701V1 with mbed

8-bit Data Bus for 16-bit/Pixel!(RGB 5-6-5-bit Input)!65535色 (16bitカラー)

128px

128px

Page 7: how to use ZY-FGD1442701V1 with mbed

LCD_Write_CMD(0x3A); // Interface Pixel Format LCD_Write_Data(0x05); // 16-bit/pixel LCD_Write_CMD(0x2A); // Column Address Set LCD_Write_Data(0x00); LCD_Write_Data(0x02); LCD_Write_Data(0x00); LCD_Write_Data(0x81); LCD_Write_CMD(0x2B); // Row Address Set LCD_Write_Data(0x00); LCD_Write_Data(0x01); LCD_Write_Data(0x00); LCD_Write_Data(0x80);

Y:02h,81h = 128列!X:01h,80h = 128行

※図は132×132ドットの場合

Page 8: how to use ZY-FGD1442701V1 with mbed
Page 9: how to use ZY-FGD1442701V1 with mbed

main.cpp

BusOut P1(p17, p16, p15, p14, p13, p12, p11, p10); DigitalOut CS0(p21); DigitalOut CD(p22); DigitalOut RD(p23); DigitalOut WR(p24); DigitalOut RSTB(p25); !LocalFileSystem local("local");

描画速度:669ms → 遅い  →LocalFileSystem(内蔵Flash)からのfreadが遅い

• BusOut (pin10-17)

Page 10: how to use ZY-FGD1442701V1 with mbed

SD追加

SDHC 8GB (Class10)

Page 11: how to use ZY-FGD1442701V1 with mbed

MicroSDを買ったら付いてくる アダプタにL型ピンヘッダをはんだづけ

Page 12: how to use ZY-FGD1442701V1 with mbed

• BusOut (pin10-17)

main.cpp

BusOut P1(p17, p16, p15, p14, p13, p12, p11, p10); DigitalOut CS0(p21); DigitalOut CD(p22); DigitalOut RD(p23); DigitalOut WR(p24); DigitalOut RSTB(p25); !SDFileSystem sd(p5, p6, p7, p8, "sd");

!SDHCFileSystem.cpp #230

_spi.frequency(32000000); //32MHz

描画速度:230ms → 3倍くらい高速化  →SDFileSystem(SDカード)からのfreadが高速   (SPI 32MHz)

Page 13: how to use ZY-FGD1442701V1 with mbed

1. アクセス回数と処理を減らす

2. RAMに画像を全て展開して書き込み Bitmap画像のサイズ=32KBくらい mbed1768のRAMサイズ=32KB (USB/Ethernetの予約分まで拡張すると64KB)

3. ポートレジスタに直接アクセス

ちょっと 厳しい?

もっと高速に描画したい

Page 14: how to use ZY-FGD1442701V1 with mbed

unsigned short pixel; !for (i=0; i<128*128; i++) { fread(&pixel, 2, 1, fp); LCD_Write_Data((unsigned char)((pixel & 0xFFFF) >> 8)); LCD_Write_Data((unsigned char)pixel); }

unsigned short pixel[128]; !for (i=0; i<128; i++) { fread(&pixel, 2, 128, fp); for(j=0; j<128; j++) { LCD_Write_Data((unsigned char)((pixel & 0xFFFF) >> 8)); LCD_Write_Data((unsigned char)pixel); } }

185ms

215ms

・1pixel(16bit)ずつ bmp565形式 128×128=16384回アクセス

・1行(16bit×128=256Byte)ずつ bmp565形式 128回アクセス

アクセス回数と処理を減らして描画高速化

約86%

235ms・1Byte(8bit)ずつ bmp555形式 128×128×2=32768回アクセス

約91%↓コントローラの形式に合わせることで処理を減らす

Page 15: how to use ZY-FGD1442701V1 with mbed

• port0の使用!

PortOut P0(Port0, 0x00000FF0);

さらに高速化するために ポートレジスタを直接叩く※

8bit連続で出ている

01531

27 28 5 6 7 8 29 30

※厳密にはPortOutでも間に処理入ってるので“直接”ではない

http://developer.mbed.org/users/nxp_ip/notebook/parallel-bus-access/

• PortOut (pin30,29,8,7,6,5,28,27)

Page 16: how to use ZY-FGD1442701V1 with mbed

void LCD_Write_CMD(unsigned char a) { CS0=0; RD=1; CD=0; P0=(unsigned)a<<4; WR=0; WR=1; CS0=1; } !void LCD_Write_Data(unsigned char b) { CS0=0; RD=1; CD=1; P0=(unsigned)b<<4; WR=0; WR=1; CS0=1; }

01531

unsigned char(8bit)

unsigned(32bit)27 28 5 6 7 8 29 30

Page 17: how to use ZY-FGD1442701V1 with mbed
Page 18: how to use ZY-FGD1442701V1 with mbed

SPI 2 SPI 1

PortOut port0使用宣言  →2つのSPIがport0に存在   →SPIが使えない    →SDカード接続不可

• PortOut (pin30,29,8,7,6,5,28,27)

→LPCXpresso NXP LPC1769なら可能?!(Port0~2すべてのピンが表に出ている)