Lib for the new LCD Display with ILI9341 controller

Dependents:   TFT_Test_ILI9341 touch_piirto TFT_banggood TFT_Test_ILI9341-a-fish ... more

Lib for 320*240 Pixel Color LCD with ILI9341 controller. Based on MI0283QT-9 datasheet. The lib is based on the http://mbed.org/cookbook/SPI-driven-QVGA-TFT code for the older LCD board.

The lib is using the 4 line serial data interface. The IM pins have to be set to 1110 (IM3-IM0) to use this mode. It use the SPI hardware.

I have started to speed up the lib with using DMA and direct SPI programming. To do this I have to split the code for the different platforms. To prevent unreadable code with a lot of #ifdef... I have create a new file. The #ifdef definition around is switching between the platforms. I will add the other Nucleo platforms. If you want to support others - see ..._NUCLEO.cpp , port and send me the code to add.

Display 1

If you use the TFT Proto from MikroElektronika http://www.mikroe.com/eng/products/view/474/tft-proto-board/ you have to connect : /media/uploads/dreschpe/tft_proto.png

MBEDDisplay
+ 3,3V3,3V
GNDGND
mosiSDI
misoSDO
sckRS
csCS
resetRST
dcWR/SCL
GNDIM0
+3,3VIM1 IM2 IM3
GNDDB0 - DB17
GNDRD

The backlite LED need a resistor to limit the current. You can use two 10R resistors parallel to get 5R driven by 3.3V.

Display 2

Watterott is also selling a ILI9341 based QVGA TFT : http://www.watterott.com/de/MI0283QT-2-Adapter

Unfortunately this adapter is set to 9 bit SPI mode via the mode pins IM0-IM3. If you want to patch this - like I have done - you have to desolder the TFT from the pcb to cut some traces. This is a flexible print. Only for people with soldering skills ! You also have to get access to pin 36 for the dc signal. Cut the GND connection. You can use the level converter used for the LCD_LED signal. Mosfet Q1 can be driven with a logic signal without converter. Watterott will change this in a future revision.

/media/uploads/dreschpe/mi0283qt_v12_patch.pdf

Display 3

There are inexpensive displays from china. You can get them at: http://www.banggood.com/2_2-Inch-Serial-TFT-SPI-LCD-Screen-Module-HD-240-X-320-5110-Compatible-p-912854.html The board has also a SD card connector at the backside, but no touch.

/media/uploads/dreschpe/tft3_1.jpg /media/uploads/dreschpe/tft3_2.jpg

The board can be used without modification. Connect VCC with 5V USB out. There is a voltage regulator on board. To use the SD card simply import the SDFileSystem and connect it to the second SPI.

Fonts

How to get nice looking fonts ?

To print characters to a graphic screen we need a font. To code a font by paper is ok for a small lcd, but for a 320*240 pixel display we need bigger fonts. A 12*12 pixel font is readable, but a lot of work to construct.

Fonts can be made with the GLCD Font Creator also from http://www.mikroe.com .

With this program you can load a window font and convert it into a c-array. To use this Font with my lib you have to add 4 parameter at the beginning of the font array. - the number of byte / char - the vertial size in pixel - the horizontal size in pixel - the number of byte per vertical line (it is vertical size / 8 ) You also have to change the array to char[]. After that you can switch between different fonts with set_font(unsigned char* font); The horizontal size of each character is also stored in the font. It look better if you use bigger fonts or italic. The letter M is wider than a l.

Here are some Fonts from me : http://mbed.org/users/dreschpe/code/TFT_fonts/

The small made for the mbed lab board : http://mbed.org/users/dreschpe/code/LCD_fonts/

And from Peter Holzleitner : http://mbed.org/users/pholzleitner/code/SourceCodePro31-SB/

Text commands :

You can use the claim() function to redirect the output to stdout or stderr to the TFT. After claim(stdout) you can simply use the printf function to print to the TFT.

  • locate(x,y); function is used to setup the cursor position. x,y are the pixel position. This was changed from row,column in older lib !

There are two parameter to setup the color of the text :

  • background(color);
  • foreground(color); All color are 16bit: R5 G6 B5.
  • set_orientation(); This command select one of the 4 directions to use the display. This command is also working on the graphical commands.

Graphics

Graphic commands :

  • cls(); Fill the screen with background color
  • pixel(x,y,color); set a single pixel at x,y with color
  • line(x0,y0,x1,y1,color); draw a line from x0,y0 to x1,y1 with color
  • rect(x0,y0,x1,y1,color); draw a rectangle x0,y0 to x1,y1 with color
  • fillrect(x0,y0,x1,y1,color); draw a filled rectangle
  • circle( x0,y0,radius ,color); draw a circle around x0,y0 with radius
  • fillcircle(x0,y0,radius ,color); draw a filled circle around x0,y0 with radius
  • Bitmap(x0,y0,w,h,*bitmap); paint a bitmap with width w and high h starting at x0,y0 (upper left corner)
  • BMP_16(x0,y0,*bmp); paint a bmp file out of the internal drive or a SD-card

How to transfer a grafic to the mbed ?

The hard way - but fast to load :

Load from mbed flash. It consume a lot of flash memory. To construct a bitmap array we can use gimp. http://www.gimp.org/ Load a image (edit and resize) and export it as BMP. You have to select the option 16 bit R5 G6 B5 !

To convert this file into a c-array you can use the hex-editor winhex. (http://www.x-ways.net/winhex/index-m.html) The eval version can handle the small files. We don`t need the bmp header. Mark the data starting at offset 0x46 to the end of file. Use "edit -> copy block -> C Source" to export this data as C array. Paste the data into a C file into the mbed compiler. The editor will generate a array of char[]. To use 16 bit DMA on this we have to put a __align(2) in front of the definition. To put it into Flash we change it to static const unsigned char bmp[]{...}

__align(2)
static const unsigned char bmp[]{
      0xCB, 0x5A, 0x5C, 0xE7,....

};

The easy way - but slower to load:

With the BMP_16 command we can load a picture out of the internal drive or a SD-card to the display.

  • BMP_16(x0,y0,"/local/test.bmp"); paint test.bmp out of the internal drive to x0, y0
  • BMP_16(x0,y0,"/sd/test.bmp"); paint test.bmp out of a external SD-card to x0, y0

simply copy test.bmp to the mbed usb drive or the SD-card. The bmp has to be saved with the options 16 bit R5 G6 B5 ! You can use the program gimp to convert pictures into the 16 bit bmp format.

sample code

http://mbed.org/users/dreschpe/code/TFT_Test_ILI9341/

// example to test the TFT Display
// Thanks to the GraphicsDisplay and TextDisplay classes
// test2.bmp has to be on the mbed file system

#include "stdio.h"
#include "mbed.h"
#include "SPI_TFT_ILI9341.h"
#include "string"
#include "Arial12x12.h"
#include "Arial24x23.h"
#include "Arial28x28.h"
#include "font_big.h"

extern unsigned char p1[];  // the mbed logo

DigitalOut LCD_LED(p21); // the Watterott display has a backlight switch
DigitalOut CS_Touch(p15); // disable the touch controller on the Watterott display

// the TFT is connected to SPI pin 5-7
SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc

int main()
{
    int i;
    LCD_LED = 1;  // backlight on
    CS_Touch = 1; 
   
    TFT.claim(stdout);      // send stdout to the TFT display
    //TFT.claim(stderr);      // send stderr to the TFT display
    TFT.set_orientation(1);
    TFT.background(Black);    // set background to black
    TFT.foreground(White);    // set chars to white
    TFT.cls();                // clear the screen

    //first show the 4 directions
    TFT.set_orientation(0);
    TFT.background(Black);
    TFT.cls();

    TFT.set_font((unsigned char*) Arial12x12);
    TFT.locate(0,0);
    printf("  Hello Mbed 0");

    TFT.set_orientation(1);
    TFT.locate(0,0);
    printf("  Hello Mbed 1");
    TFT.set_orientation(2);
    TFT.locate(0,0);
    printf("  Hello Mbed 2");
    TFT.set_orientation(3);
    TFT.locate(0,0);
    printf("  Hello Mbed 3");
    TFT.set_orientation(1);
    TFT.set_font((unsigned char*) Arial24x23);
    TFT.locate(50,100);
    TFT.printf("TFT orientation");

/media/uploads/dreschpe/orient.jpg

// draw some graphics
    TFT.cls();
    TFT.set_font((unsigned char*) Arial24x23);
    TFT.locate(100,100);
    TFT.printf("Graphic");

    TFT.line(0,0,100,0,Green);
    TFT.line(0,0,0,200,Green);
    TFT.line(0,0,100,200,Green);

    TFT.rect(100,50,150,100,Red);
    TFT.fillrect(180,25,220,70,Blue);

    TFT.circle(80,150,33,White);
    TFT.fillcircle(160,190,20,Yellow);

    double s;

    for (i=0; i<320; i++) {
        s =20 * sin((long double) i / 10 );
        TFT.pixel(i,100 + (int)s ,Red);
    }

/media/uploads/dreschpe/grafik.jpg

   // bigger text
    TFT.foreground(White);
    TFT.background(Blue);
    TFT.cls();
    TFT.set_font((unsigned char*) Arial24x23);
    TFT.locate(0,0);
    TFT.printf("Different Fonts :");

    TFT.set_font((unsigned char*) Neu42x35);
    TFT.locate(0,30);
    TFT.printf("Hello Mbed 1");
    TFT.set_font((unsigned char*) Arial24x23);
    TFT.locate(20,80);
    TFT.printf("Hello Mbed 2");
    TFT.set_font((unsigned char*) Arial12x12);
    TFT.locate(35,120);
    TFT.printf("Hello Mbed 3");

/media/uploads/dreschpe/fonts2.jpg

    // mbed logo from flash
    // defined in graphics.c
    //__align(4)
    //unsigned char p1[18920] = {
    //0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, ....
    // 
    TFT.background(Black);
    TFT.cls();

    TFT.locate(10,10);
    TFT.printf("Graphic from Flash");

    TFT.Bitmap(90,90,172,55,p1);

/media/uploads/dreschpe/mbed.jpg

  
  #include "SDFileSystem.h"
  // connect a sd-card to the second spi or use the local filesystem of the LPC   
  SDFileSystem sd(p11, p12, p13, p14, "sd"); // mosi,miso,sck,cs
  TFT.cls();
  TFT.locate(10,110);
  TFT.printf("Graphic from external SD-card");
  int err = TFT.BMP_16(1,140,"/sd/test.bmp");  // load test.bmp from external SD-card
  TFT.locate(10,120);
  if (err != 1) TFT.printf(" - Err: %d",err);

/media/uploads/dreschpe/bmp16.jpg

Committer:
dreschpe
Date:
Wed Jun 25 16:51:27 2014 +0000
Revision:
13:b2b3e5430f81
Parent:
0:da1bf437cbc1
add fast LPC1768 version

Who changed what in which revision?

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