ILI9341_SPI

Dependencies:   fonts

Dependents:   ov7670_dma_nucleo_f4 NUCLEO-F446RE_testDCMI

Revision:
1:2446b5e1a4fb
Parent:
0:2d4605aef62f
--- a/ILI9341.cpp	Fri Apr 29 13:36:39 2016 +0000
+++ b/ILI9341.cpp	Sun Nov 20 11:08:39 2016 +0000
@@ -1,6 +1,7 @@
 
 #include <mbed.h>
 #include "ILI9341.h"
+#include "font6x12.h"
 
 ili9341_spi::ili9341_spi(SPI& _spi, PinName _cs,PinName _dc,PinName _rs) : spi(_spi), cs(_cs),dc(_dc),rs(_rs) {}
 
@@ -204,14 +205,14 @@
     spi.write(0);
     spi.write(0);
     spi.write(0);
-    spi.write(0x95);
+    spi.write(0x95);//95
     
     cs = 1;
     wr_cmd(0x2B);
     spi.write(0);
     spi.write(0);
     spi.write(0x00);
-    spi.write(0x90);
+    spi.write(0x90);//90
     cs = 1;
      
      //wr_cmd(0x34);                     // tearing effect off
@@ -310,7 +311,7 @@
     int h = y1 - y0 + 1;
     int w = x1 - x0 + 1;
     int pixel = h * w;
-    //window(x0,y0,w,h);
+    window(x0,y0,w,h);
     wr_cmd(0x2C);  // send pixel 
     //#if defined TARGET_KL25Z  // 8 Bit SPI
     for (int p=0; p<pixel; p++) {
@@ -328,11 +329,61 @@
     //WindowMax();
     return;
 }    
+
+void ili9341_spi::draw_str(const char* str,uint8_t line)
+{
+    uint8_t len = strlen(str);
+
+    for (int i = 0; i < len; i++)
+    {
+        if(i==0){draw_char(str[i],1,line);}
+     else   draw_char(str[i],0,line);
+    }
+}
+
+void ili9341_spi::draw_char(char ch,uint8_t rs,uint8_t line)
+{
+static ushort col=0,row=0;
+static ushort pos_x = LEFT_PADDING, pos_y = TOP_PADDING;
+    // 画面の右側に達したら改行する
+    if(rs){pos_x=2;}
+    pos_y = line*(FONT_6x12_HEIGHT + 2);
+    if(pos_y==0){pos_y=2;}
+    if (/*(col > 240 - 1) ||*/ ch == 10) 
+    {
+        col = 0; row++;
+        pos_x = LEFT_PADDING; pos_y += FONT_6x12_HEIGHT + 2;
+    }
+    if (ch == 10) return;
+  // 文字の出力範囲を設定
+    window(pos_x,pos_y, FONT_6x12_WIDTH+1,FONT_6x12_HEIGHT+1);
+  // 文字がASCII表にある位置を探す
+    const byte* fc = fc_tab[(ushort)ch];
+    if (fc != 0)
+    {
+        wr_cmd(0x2C);
+        
+        for (int y = 0; y < FONT_6x12_HEIGHT; y++)
+        {
+            for (int x = 0; x <= FONT_6x12_WIDTH; x++)
+            {
+                ushort k = (*fc) & (1 << (FONT_6x12_WIDTH - x));
+           // フォントのピクセルを出力する
+                spi.write(k ? /*(fcolor >> 8)*/0xff : /*(bcolor >> 8)*/0xf8);
+                spi.write(k ? /*fcolor*/0xff : /*bcolor*/0x00);
+            }
+            fc++;
+        }
+    }
+    col++;
+    pos_x += FONT_6x12_WIDTH + 2;
+}
+
 void ili9341_spi::select() {
     //Set CS low to start transmission (interrupts conversion)
-    cs = 0;
+    cs = 0;   spi.frequency(60000000);
 }
 void ili9341_spi::deselect() {
     //Set CS high to stop transmission (restarts conversion)
-    cs = 1;
+    cs = 1;   spi.frequency(20000000);
 }
\ No newline at end of file