This library is for Arduino TFT LCD Screen module.(for new LCD driver IC)

Dependents:   ArduinoTFTLCDScreenSample_SPI18TFT

Fork of ST7735_TFT by Jonne Valola

いきさつ

Arduino TFT LCD ScreenというLCD moduleをmbedで使用しました。(module詳細 switch science web)

/media/uploads/suupen/2014-09-21_10.39.18_-240x320-.jpg

このLCD moduleのLCD driver ICはST7735 ですが、複数のバージョンがあり、libraryとICのバージョンが合わないと正常に表示しません。

mbedにはこのICに対応したlibrary(ST7735_TFT)がありますが、私が入手したLCD moduleではICの種類が違うためか正常に動作しませんでした。幸い、switch scienceのwebにarduino用の対応libraryがあったので、これを元にmbedのlibrary(ST7735_TFT)に移植しました。

libraryの移植

移植元のArduino library

移植元はswitch science webにある置き換え用TFTライブラリ(Arduino IDE1.0.5用)を使用します。このファイルを解凍してできる、"Adfruit_ST7735.cpp"の230行目以降のGcmd[]配列が該当するdriver ICの設定データになります。

Adfruit_ST7735.cpp

・
・
・
  Gcmd[] = {                  // Initialization commands for 7735B screens
    19,                       // 18 commands in list:
    ST7735_SWRESET,   DELAY,  //  1: Software reset, no args, w/delay
      50,                     //     50 ms delay
    ST7735_SLPOUT ,   DELAY,  //  2: Out of sleep mode, no args, w/delay
      100,                    //     255 = 500 ms delay
    0x26 , 1,  			// 3: Set default gamma
      0x04,                     //     16-bit color
    0xb1, 2,              	// 4: Frame Rate
      0x0b,
      0x14,
    0xc0, 2,                    // 5: VRH1[4:0] & VC[2:0]
      0x08,
      0x00,
    0xc1, 1,                    // 6: BT[2:0]
      0x05,
    0xc5, 2,                    // 7: VMH[6:0] & VML[6:0]
      0x41,
      0x30,
    0xc7, 1,                    // 8: LCD Driving control
      0xc1,
    0xEC, 1,                    // 9: Set pumping color freq
      0x1b,
    0x3a , 1 + DELAY,  	        // 10: Set color format
      0x55,                     //     16-bit color
      100,
    0x2a, 4,                    // 11: Set Column Address
      0x00,
      0x00,
      0x00,
      0x7f,
    0x2b, 4,                    // 12: Set Page Address
      0x00,
      0x00,
      0x00,
      0x9f,
    0x36, 1,                    // 12+1: Set Scanning Direction
      0xc8,
    0xb7, 1,			// 14: Set Source Output Direciton
      0x00,
    0xf2, 1,			// 15: Enable Gamma bit
      0x00,
    0xe0, 15 + DELAY,		// 16: magic
      0x28, 0x24, 0x22, 0x31,
      0x2b, 0x0e, 0x53, 0xa5,
      0x42, 0x16, 0x18, 0x12,
      0x1a, 0x14, 0x03,
      50,
    0xe1, 15 + DELAY,		// 17: more magic
      0x17, 0x1b, 0x1d, 0x0e,
      0x14, 0x11, 0x2c, 0xa5,
      0x3d, 0x09, 0x27, 0x2d,
      0x25, 0x2b, 0x3c, 
      50, 
    ST7735_NORON  ,   DELAY,  // 17: Normal display on, no args, w/delay
      10,                     //     10 ms delay
    ST7735_DISPON ,   DELAY,  // 18: Main screen turn on, no args, w/delay
      255 };                  //     255 = 500 ms delay
・
・
・

移植先のmbed library

移植先となるmbed libraryはST7735_TFT libraryとなります。この中のST7735_TFT.cppのtft_reset() にIC設定データを追加します。追加したコードを区別するため"ST7735B"というdefine定義で条件コンパイルするようにしました。

追加したコードの最後にある"switch(orientation)"の節はarduinoのlibraryにはなく、mbedのlibraryから修正したものです。

ST7735_TFT.cpp

・
・
・
void ST7735_TFT::tft_reset() {
    static unsigned short driverCode;
    
    // init SPI
    _spi.format(8,3);                 // 8 bit spi mode 3
    _spi.frequency(16000000);         // 16Mhz SPI clock ... 15Mhz is maximum for display, but it seems to work
    
    // reset exactly like in Arduino version
    _cs = 0;
    _reset = 1;                       // reset
    wait_ms(500);
    _reset = 0;                       // reset
    wait_ms(500);
    _reset = 1;                       // reset
    wait_ms(500);
 
 #ifdef ST7735B //@ss   
    /* Start Initial Sequence ----------------------------------------------------*/
    wr_cmd(ST7735_SWRESET);                         /* SW Reset                       */
    wait_ms(150);
    wr_cmd(ST7735_SLPOUT);                         /* Out of sleepmode               */
    wait_ms(500);
    
    wr_cmd(0x26);   // 3: Set default gamma
    wr_dat(0x04);   //      16-bit color
    
    wr_cmd(ST7735_FRMCTR1);                         /*4 Frame rate in normal mode            */
    wr_dat(0x0b);                              
    wr_dat(0x14);

    


    wr_cmd(0xc0);   // 5 POWER CONTROL 1   
    wr_dat(0x08); 
    wr_dat(0x00);
    
    wr_cmd(0xc1);   // 6 POWER CONTROL 2   
    wr_dat(0x05);

    wr_cmd(0xC5);   // POWER CONTROL 6   
    wr_dat(0x41);            // 
    wr_dat(0x30);

    wr_cmd(0xc7);   // 8:LCD Driving control
    wr_dat(0xc1);
    
    wr_cmd(0xec);   // 9:Set color format
    wr_dat(0x1b);   //      16-bit color
     
    wr_cmd(0x3A);   // COLOR MODE   
    wr_dat(0x55);            //      
    wait_ms(100);
    
    wr_cmd(0x2a);   // 11 COLUMN ADDR SET   
    wr_dat(0x00);   //
    wr_dat(0x00);   // xstart = 0
    wr_dat(0x00);   //
    wr_dat(0x7F);   // xend = 127
    
    wr_cmd(0x2b);   // ROW ADDR SET   
    wr_dat(0x00);   //
    wr_dat(0x00);   // ystart = 0
    wr_dat(0x00);   //
    wr_dat(0x9F);   // yend = 159            
    
    wr_cmd(0x36);   // 13 Set Scanning Direction
    wr_dat(0xc8);
    
    wr_cmd(0xb7);   // 14 Set Source Output Direction
    wr_dat(0x00);
    /* Gamma settings  -----------------------------------------------------------*/

  wr_cmd(0xE0); // GMCTRP1
  wr_dat(0x28);
  wr_dat(0x24);
  wr_dat(0x22);
  wr_dat(0x31);
  
  wr_dat(0x2b);
  wr_dat(0x0e);
  wr_dat(0x53);
  wr_dat(0xa5);
  
  wr_dat(0x42);
  wr_dat(0x16);
  wr_dat(0x18);
  wr_dat(0x12);
  
  wr_dat(0x1a);
  wr_dat(0x14);
  wr_dat(0x03);

    wait_ms(50);

  wr_cmd(0xE1); // GMCTRN1
  wr_dat(0x17); 
  wr_dat(0x1b); 
  wr_dat(0x1d); 
  wr_dat(0x0e);
   
  wr_dat(0x14); 
  wr_dat(0x11); 
  wr_dat(0x2c); 
  wr_dat(0xa5); 
  
  wr_dat(0x3d); 
  wr_dat(0x09); 
  wr_dat(0x27); 
  wr_dat(0x2d); 
  
  wr_dat(0x25); 
  wr_dat(0x2b); 
  wr_dat(0x3c); 

    wait_ms(50);
  
  wr_cmd(0x13); // 18 Normal display on no args.
  wait_ms(10);

  wr_cmd(0x29);  // 19 Main screen turn on, no args.normal display on
  wait_ms(500);
  
  switch (orientation) {
        case 0:
            wr_reg(0x36, 0x0008);   //originalでの0xc8は間違いで、ST7735_MADCTL(0x36)ではないか
            break;
        case 1:
            wr_reg(0x36, 0x0068);
            break;
        case 2:
            wr_reg(0x36, 0x00C8);
            break;
        case 3:
            wr_reg(0x36, 0x00A8);
            break;
    }

#else //@ss ~ST7735B (original)
   /* Start Initial Sequence ----------------------------------------------------*/
    wr_cmd(ST7735_SWRESET);                         /* SW Reset                       */
    wait_ms(150);
    wr_cmd(ST7735_SLPOUT);                         /* Out of sleepmode               */
    wait_ms(500);
・
・
・

mbed library自体の修正

上記のdriver IC設定値の修正だけでは、LCDの表示領域がずれるなどの不具合がありました。この修正も行います。この不具合の原因が、driver ICの種類の違いよるものなのか、コードそのものの不具合なのかはわかりません。
修正コードは"@ss"のコメントをつけた行になります。

1.driver ICへの画像データバッファアドレス指示の修正
pixel()関数で使用しているwindow()関数の引数が間違っています。元のコードは、終点のx,yが絶対座標形式のようになっていますが、視点からの相対座標を設定しないといけません。

ST7735_TFT.cpp

・
・
・
void ST7735_TFT::pixel(int x, int y, int color) {
  if ((x >= width()) || (y >= height())) return;

    window(x,y,1,1);    //@ss
//@ss  window(x,y,x+1,y+1);
  
  // setup for data
・
・
・


2.window()関数の座標原点のずれ
driver ICの仕様かもしれませんが、driver ICの画像データバッファの原点が、x=2, y=1となっています。このlibraryで使用される原点はx=0, y=0なので、offsetを追加します。

ST7735_TFT.cpp

・
・
・
void ST7735_TFT::window (unsigned int x, unsigned int y, unsigned int w, unsigned int h) {
    //@ss なぜか CASET(X軸)で2, RASET(Y軸)で1 が最小値になっており、これがLCDDisplayのx,y原点になっていない(LCDの原点を設定するためには(-2,-1)を指示する必要がある
    //@ss プログラム上はLCD原点を0,0にするために、この関数でoffsetをかける。
    x-=2;   //@ss
    y-=1;   //@ss
  wr_cmd(ST7735_CASET);  // column addr set
  wr_dat(0x00);
・
・
・


3.端子定義処理での"orientation"変数の初期値設定タイミングの変更

"ST7735_TFT()"関数内の"orientation"変数の初期値設定がtft_reset()の後になっていますが、tft_reset()内でこの変数を使用しているので、tft_reset()実行前に、変数値を設定する必要があります。

ST7735_TFT.cpp

・
・
・
ST7735_TFT::ST7735_TFT(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName rs, PinName reset, const char *name)
        : _spi(mosi, miso, sclk), _cs(cs), _rs(rs), _reset(reset),GraphicsDisplay(name) {
    orientation = 1;    //@ss
    tft_reset();
//@ss    orientation = 2;
    char_x = 0;
・
・
・

補足:LCD 表示原点の設定

今回使用したmoduleのLCDは160*128ピクセルのものです。画像データの送信によって、x,y軸を入れ替える(横長、縦長)ことができます。これを設定するのが、上記"3"のorientation変数になります。この変数は"set_orientation()"関数の引数として与えることで変更することができます。引数は0,1,2,3となります。

<縦横選択>
0,2 : 縦長(x=0-127, y=0-159)
1,3 : 横長(x=0-159, y=0-127)

<縦(y軸)座標値増加方向>
0,1を基準にした場合、2,3は上下が逆転する

<表示例>
orientation = 0
/media/uploads/suupen/orientation_0--_1_-320x240-.jpg

orientation = 1
/media/uploads/suupen/orientation_1--_2_-320x240-.jpg

orientation =2
/media/uploads/suupen/orientation_2-_3_-320x240-.jpg

orientation=3
/media/uploads/suupen/orientation_3--_4_-320x240-.jpg

以上

Committer:
suupen
Date:
Sat Sep 20 12:44:49 2014 +0000
Revision:
2:9a62e159e30c
Parent:
0:246f2fb5be59
This library is for Arduino TFT LCD Screen Module.(for new LCD driver)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
smultron1977 0:246f2fb5be59 1 /* mbed GraphicsDisplay Display Library Base Class
smultron1977 0:246f2fb5be59 2 * Copyright (c) 2007-2009 sford
smultron1977 0:246f2fb5be59 3 * Released under the MIT License: http://mbed.org/license/mit
smultron1977 0:246f2fb5be59 4 */
smultron1977 0:246f2fb5be59 5
smultron1977 0:246f2fb5be59 6 #include "GraphicsDisplay.h"
smultron1977 0:246f2fb5be59 7
smultron1977 0:246f2fb5be59 8 const unsigned char FONT8x8[97][8] = {
smultron1977 0:246f2fb5be59 9 0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char
smultron1977 0:246f2fb5be59 10 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20
smultron1977 0:246f2fb5be59 11 0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00, // !
smultron1977 0:246f2fb5be59 12 0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00, // "
smultron1977 0:246f2fb5be59 13 0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00, // #
smultron1977 0:246f2fb5be59 14 0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00, // $
smultron1977 0:246f2fb5be59 15 0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00, // %
smultron1977 0:246f2fb5be59 16 0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00, // &
smultron1977 0:246f2fb5be59 17 0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00, // '
smultron1977 0:246f2fb5be59 18 0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00, // (
smultron1977 0:246f2fb5be59 19 0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00, // )
smultron1977 0:246f2fb5be59 20 0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, // *
smultron1977 0:246f2fb5be59 21 0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00, // +
smultron1977 0:246f2fb5be59 22 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30, // ,
smultron1977 0:246f2fb5be59 23 0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00, // -
smultron1977 0:246f2fb5be59 24 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00, // .
smultron1977 0:246f2fb5be59 25 0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, // / (forward slash)
smultron1977 0:246f2fb5be59 26 0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00, // 0 0x30
smultron1977 0:246f2fb5be59 27 0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00, // 1
smultron1977 0:246f2fb5be59 28 0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00, // 2
smultron1977 0:246f2fb5be59 29 0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00, // 3
smultron1977 0:246f2fb5be59 30 0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00, // 4
smultron1977 0:246f2fb5be59 31 0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00, // 5
smultron1977 0:246f2fb5be59 32 0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00, // 6
smultron1977 0:246f2fb5be59 33 0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00, // 7
smultron1977 0:246f2fb5be59 34 0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00, // 8
smultron1977 0:246f2fb5be59 35 0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00, // 9
smultron1977 0:246f2fb5be59 36 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00, // :
smultron1977 0:246f2fb5be59 37 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30, // ;
smultron1977 0:246f2fb5be59 38 0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00, // <
smultron1977 0:246f2fb5be59 39 0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00, // =
smultron1977 0:246f2fb5be59 40 0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00, // >
smultron1977 0:246f2fb5be59 41 0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00, // ?
smultron1977 0:246f2fb5be59 42 0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00, // @ 0x40
smultron1977 0:246f2fb5be59 43 0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00, // A
smultron1977 0:246f2fb5be59 44 0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00, // B
smultron1977 0:246f2fb5be59 45 0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00, // C
smultron1977 0:246f2fb5be59 46 0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00, // D
smultron1977 0:246f2fb5be59 47 0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00, // E
smultron1977 0:246f2fb5be59 48 0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00, // F
smultron1977 0:246f2fb5be59 49 0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00, // G
smultron1977 0:246f2fb5be59 50 0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00, // H
smultron1977 0:246f2fb5be59 51 0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // I
smultron1977 0:246f2fb5be59 52 0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00, // J
smultron1977 0:246f2fb5be59 53 0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00, // K
smultron1977 0:246f2fb5be59 54 0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00, // L
smultron1977 0:246f2fb5be59 55 0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00, // M
smultron1977 0:246f2fb5be59 56 0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00, // N
smultron1977 0:246f2fb5be59 57 0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00, // O
smultron1977 0:246f2fb5be59 58 0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00, // P 0x50
smultron1977 0:246f2fb5be59 59 0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00, // Q
smultron1977 0:246f2fb5be59 60 0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00, // R
smultron1977 0:246f2fb5be59 61 0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00, // S
smultron1977 0:246f2fb5be59 62 0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00, // T
smultron1977 0:246f2fb5be59 63 0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00, // U
smultron1977 0:246f2fb5be59 64 0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00, // V
smultron1977 0:246f2fb5be59 65 0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, // W
smultron1977 0:246f2fb5be59 66 0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00, // X
smultron1977 0:246f2fb5be59 67 0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00, // Y
smultron1977 0:246f2fb5be59 68 0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00, // Z
smultron1977 0:246f2fb5be59 69 0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, // [
smultron1977 0:246f2fb5be59 70 0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, // \ (back slash)
smultron1977 0:246f2fb5be59 71 0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, // ]
smultron1977 0:246f2fb5be59 72 0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // ^
smultron1977 0:246f2fb5be59 73 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, // _
smultron1977 0:246f2fb5be59 74 0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00, // ` 0x60
smultron1977 0:246f2fb5be59 75 0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00, // a
smultron1977 0:246f2fb5be59 76 0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00, // b
smultron1977 0:246f2fb5be59 77 0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00, // c
smultron1977 0:246f2fb5be59 78 0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00, // d
smultron1977 0:246f2fb5be59 79 0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00, // e
smultron1977 0:246f2fb5be59 80 0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00, // f
smultron1977 0:246f2fb5be59 81 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C, // g
smultron1977 0:246f2fb5be59 82 0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00, // h
smultron1977 0:246f2fb5be59 83 0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00, // i
smultron1977 0:246f2fb5be59 84 0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C, // j
smultron1977 0:246f2fb5be59 85 0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00, // k
smultron1977 0:246f2fb5be59 86 0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // l
smultron1977 0:246f2fb5be59 87 0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00, // m
smultron1977 0:246f2fb5be59 88 0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00, // n
smultron1977 0:246f2fb5be59 89 0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00, // o
smultron1977 0:246f2fb5be59 90 0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78, // p
smultron1977 0:246f2fb5be59 91 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F, // q
smultron1977 0:246f2fb5be59 92 0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00, // r
smultron1977 0:246f2fb5be59 93 0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00, // s
smultron1977 0:246f2fb5be59 94 0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00, // t
smultron1977 0:246f2fb5be59 95 0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00, // u
smultron1977 0:246f2fb5be59 96 0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00, // v
smultron1977 0:246f2fb5be59 97 0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00, // w
smultron1977 0:246f2fb5be59 98 0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00, // x
smultron1977 0:246f2fb5be59 99 0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C, // y
smultron1977 0:246f2fb5be59 100 0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00, // z
smultron1977 0:246f2fb5be59 101 0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00, // {
smultron1977 0:246f2fb5be59 102 0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00, // |
smultron1977 0:246f2fb5be59 103 0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // }
smultron1977 0:246f2fb5be59 104 0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~
smultron1977 0:246f2fb5be59 105 0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00}; // DEL
smultron1977 0:246f2fb5be59 106
smultron1977 0:246f2fb5be59 107 GraphicsDisplay::GraphicsDisplay(const char *name):TextDisplay(name) {
smultron1977 0:246f2fb5be59 108 foreground(0xFFFF);
smultron1977 0:246f2fb5be59 109 background(0x0000);
smultron1977 0:246f2fb5be59 110 }
smultron1977 0:246f2fb5be59 111
smultron1977 0:246f2fb5be59 112 void GraphicsDisplay::character(int column, int row, int value) {
smultron1977 0:246f2fb5be59 113 blitbit(column * 8, row * 8, 8, 8, (char*)&(FONT8x8[value - 0x1F][0]));
smultron1977 0:246f2fb5be59 114 }
smultron1977 0:246f2fb5be59 115
smultron1977 0:246f2fb5be59 116 void GraphicsDisplay::window(int x, int y, int w, int h) {
smultron1977 0:246f2fb5be59 117 // current pixel location
smultron1977 0:246f2fb5be59 118 _x = x;
smultron1977 0:246f2fb5be59 119 _y = y;
smultron1977 0:246f2fb5be59 120 // window settings
smultron1977 0:246f2fb5be59 121 _x1 = x;
smultron1977 0:246f2fb5be59 122 _x2 = x + w - 1;
smultron1977 0:246f2fb5be59 123 _y1 = y;
smultron1977 0:246f2fb5be59 124 _y2 = y + h - 1;
smultron1977 0:246f2fb5be59 125 }
smultron1977 0:246f2fb5be59 126
smultron1977 0:246f2fb5be59 127 void GraphicsDisplay::putp(int colour) {
smultron1977 0:246f2fb5be59 128 // put pixel at current pixel location
smultron1977 0:246f2fb5be59 129 pixel(_x, _y, colour);
smultron1977 0:246f2fb5be59 130 // update pixel location based on window settings
smultron1977 0:246f2fb5be59 131 _x++;
smultron1977 0:246f2fb5be59 132 if(_x > _x2) {
smultron1977 0:246f2fb5be59 133 _x = _x1;
smultron1977 0:246f2fb5be59 134 _y++;
smultron1977 0:246f2fb5be59 135 if(_y > _y2) {
smultron1977 0:246f2fb5be59 136 _y = _y1;
smultron1977 0:246f2fb5be59 137 }
smultron1977 0:246f2fb5be59 138 }
smultron1977 0:246f2fb5be59 139 }
smultron1977 0:246f2fb5be59 140
smultron1977 0:246f2fb5be59 141 void GraphicsDisplay::fill(int x, int y, int w, int h, int colour) {
smultron1977 0:246f2fb5be59 142 window(x, y, w, h);
smultron1977 0:246f2fb5be59 143 for(int i=0; i<w*h; i++) {
smultron1977 0:246f2fb5be59 144 putp(colour);
smultron1977 0:246f2fb5be59 145 }
smultron1977 0:246f2fb5be59 146 }
smultron1977 0:246f2fb5be59 147
smultron1977 0:246f2fb5be59 148 void GraphicsDisplay::cls() {
smultron1977 0:246f2fb5be59 149 fill(0, 0, width(), height(), _background);
smultron1977 0:246f2fb5be59 150 }
smultron1977 0:246f2fb5be59 151
smultron1977 0:246f2fb5be59 152 void GraphicsDisplay::blit(int x, int y, int w, int h, const int *colour) {
smultron1977 0:246f2fb5be59 153 window(x, y, w, h);
smultron1977 0:246f2fb5be59 154 for(int i=0; i<w*h; i++) {
smultron1977 0:246f2fb5be59 155 putp(colour[i]);
smultron1977 0:246f2fb5be59 156 }
smultron1977 0:246f2fb5be59 157 }
smultron1977 0:246f2fb5be59 158
smultron1977 0:246f2fb5be59 159 void GraphicsDisplay::blitbit(int x, int y, int w, int h, const char* colour) {
smultron1977 0:246f2fb5be59 160 window(x, y, w, h);
smultron1977 0:246f2fb5be59 161 for(int i = 0; i < w*h; i++) {
smultron1977 0:246f2fb5be59 162 char byte = colour[i >> 3];
smultron1977 0:246f2fb5be59 163 int offset = i & 0x7;
smultron1977 0:246f2fb5be59 164 int c = ((byte << offset) & 0x80) ? _foreground : _background;
smultron1977 0:246f2fb5be59 165 putp(c);
smultron1977 0:246f2fb5be59 166 }
smultron1977 0:246f2fb5be59 167 }
smultron1977 0:246f2fb5be59 168
smultron1977 0:246f2fb5be59 169 int GraphicsDisplay::columns() {
smultron1977 0:246f2fb5be59 170 return width() / 8;
smultron1977 0:246f2fb5be59 171 }
smultron1977 0:246f2fb5be59 172
smultron1977 0:246f2fb5be59 173 int GraphicsDisplay::rows() {
smultron1977 0:246f2fb5be59 174 return height() / 8;
smultron1977 0:246f2fb5be59 175 }
smultron1977 0:246f2fb5be59 176