Basically i glued Peter Drescher and Simon Ford libs in a GraphicsDisplay class, then derived TFT or LCD class (which inherits Protocols class), then the most derived ones (Inits), which are per-display and are the only part needed to be adapted to diff hw.

Dependents:   testUniGraphic_150217 maze_TFT_MMA8451Q TFT_test_frdm-kl25z TFT_test_NUCLEO-F411RE ... more

Committer:
Geremia
Date:
Tue Jan 25 17:57:55 2022 +0000
Revision:
34:c66986d80f72
Parent:
29:866213bb9bf0
align attribute fixed to gcc style, updated to OS6 then got bored

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Geremia 29:866213bb9bf0 1 /* mbed UniGraphic library - Device specific class
Geremia 29:866213bb9bf0 2 * Copyright (c) 2015 Giuliano Dianda
Geremia 29:866213bb9bf0 3 * Released under the MIT License: http://mbed.org/license/mit
Geremia 29:866213bb9bf0 4 */
Geremia 29:866213bb9bf0 5 #include "Protocols.h"
Geremia 29:866213bb9bf0 6 #include "ILI9327.h"
Geremia 29:866213bb9bf0 7
Geremia 29:866213bb9bf0 8 //////////////////////////////////////////////////////////////////////////////////
Geremia 29:866213bb9bf0 9 // display settings ///////////////////////////////////////////////////////
Geremia 29:866213bb9bf0 10 /////////////////////////////////////////////////////////////////////////
Geremia 29:866213bb9bf0 11
Geremia 29:866213bb9bf0 12 // put in constructor
Geremia 29:866213bb9bf0 13 //#define LCDSIZE_X 240 // display X pixels, TFTs are usually portrait view
Geremia 29:866213bb9bf0 14 //#define LCDSIZE_Y 400 // display Y pixels
Geremia 29:866213bb9bf0 15
Geremia 29:866213bb9bf0 16
Geremia 29:866213bb9bf0 17
Geremia 29:866213bb9bf0 18 ILI9327::ILI9327(proto_t displayproto, PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char *name , unsigned int LCDSIZE_X, unsigned int LCDSIZE_Y)
Geremia 29:866213bb9bf0 19 : TFT(displayproto, port, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, name)
Geremia 29:866213bb9bf0 20 {
Geremia 29:866213bb9bf0 21 hw_reset();
Geremia 29:866213bb9bf0 22 BusEnable(true);
Geremia 29:866213bb9bf0 23 identify(); // will collect tftID, set mipistd flag
Geremia 29:866213bb9bf0 24 init();
Geremia 29:866213bb9bf0 25 auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
Geremia 29:866213bb9bf0 26 // scrollbugfix=1; // when scrolling 1 line, the last line disappears, set to 1 to fix it, for ili9481 is set automatically in identify()
Geremia 29:866213bb9bf0 27 set_orientation(0);
Geremia 29:866213bb9bf0 28 FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. Give a try
Geremia 29:866213bb9bf0 29 cls();
Geremia 29:866213bb9bf0 30 locate(0,0);
Geremia 29:866213bb9bf0 31 }
Geremia 29:866213bb9bf0 32 ILI9327::ILI9327(proto_t displayproto, PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char *name , unsigned int LCDSIZE_X, unsigned int LCDSIZE_Y)
Geremia 29:866213bb9bf0 33 : TFT(displayproto, buspins, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, name)
Geremia 29:866213bb9bf0 34 {
Geremia 29:866213bb9bf0 35 hw_reset();
Geremia 29:866213bb9bf0 36 BusEnable(true);
Geremia 29:866213bb9bf0 37 identify(); // will collect tftID, set mipistd flag
Geremia 29:866213bb9bf0 38 init();
Geremia 29:866213bb9bf0 39 auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
Geremia 29:866213bb9bf0 40 // scrollbugfix=1; // when scrolling 1 line, the last line disappears, set to 1 to fix it, for ili9481 is set automatically in identify()
Geremia 29:866213bb9bf0 41 set_orientation(0);
Geremia 29:866213bb9bf0 42 FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. Give a try
Geremia 29:866213bb9bf0 43 cls();
Geremia 29:866213bb9bf0 44 locate(0,0);
Geremia 29:866213bb9bf0 45 }
Geremia 29:866213bb9bf0 46 ILI9327::ILI9327(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const char *name , unsigned int LCDSIZE_X , unsigned int LCDSIZE_Y )
Geremia 29:866213bb9bf0 47 : TFT(displayproto, Hz, mosi, miso, sclk, CS, reset, DC, LCDSIZE_X, LCDSIZE_Y, name)
Geremia 29:866213bb9bf0 48 {
Geremia 29:866213bb9bf0 49 hw_reset(); //TFT class forwards to Protocol class
Geremia 29:866213bb9bf0 50 BusEnable(true); //TFT class forwards to Protocol class
Geremia 29:866213bb9bf0 51 identify(); // will collect tftID and set mipistd flag
Geremia 29:866213bb9bf0 52 init(); // per display custom init cmd sequence, implemented here
Geremia 29:866213bb9bf0 53 auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
Geremia 29:866213bb9bf0 54 // scrollbugfix=1; // when scrolling 1 line, the last line disappears, set to 1 to fix it, for ili9481 is set automatically in identify()
Geremia 29:866213bb9bf0 55 set_orientation(0); //TFT class does for MIPI standard and some ILIxxx
Geremia 29:866213bb9bf0 56 FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. Give a try
Geremia 29:866213bb9bf0 57 cls();
Geremia 29:866213bb9bf0 58 locate(0,0);
Geremia 29:866213bb9bf0 59 }
Geremia 29:866213bb9bf0 60 // read display ID
Geremia 29:866213bb9bf0 61 void ILI9327::identify()
Geremia 29:866213bb9bf0 62 {
Geremia 29:866213bb9bf0 63 // ILI9327 custom cmd
Geremia 29:866213bb9bf0 64 tftID=rd_reg_data32(0xEF);
Geremia 29:866213bb9bf0 65 mipistd=true;
Geremia 29:866213bb9bf0 66 }
Geremia 29:866213bb9bf0 67 // reset and init the lcd controller
Geremia 29:866213bb9bf0 68 void ILI9327::init()
Geremia 29:866213bb9bf0 69 {
Geremia 29:866213bb9bf0 70 wr_cmd8(0x11);
Geremia 34:c66986d80f72 71 thread_sleep_for(150);
Geremia 29:866213bb9bf0 72
Geremia 29:866213bb9bf0 73 wr_cmd8(0xF3); //Set EQ
Geremia 29:866213bb9bf0 74 wr_data8(0x08);
Geremia 29:866213bb9bf0 75 wr_data8(0x20);
Geremia 29:866213bb9bf0 76 wr_data8(0x20);
Geremia 29:866213bb9bf0 77 wr_data8(0x08);
Geremia 29:866213bb9bf0 78
Geremia 29:866213bb9bf0 79 wr_cmd8(0xE7);
Geremia 29:866213bb9bf0 80 wr_data8(0x60); //OPON
Geremia 29:866213bb9bf0 81
Geremia 29:866213bb9bf0 82 wr_cmd8(0xD1); // Set VCOM
Geremia 29:866213bb9bf0 83 wr_data8(0x00);
Geremia 29:866213bb9bf0 84 wr_data8(0x5D);
Geremia 29:866213bb9bf0 85 wr_data8(0x15);
Geremia 29:866213bb9bf0 86
Geremia 29:866213bb9bf0 87 wr_cmd8(0xD0); //Set power related setting
Geremia 29:866213bb9bf0 88 wr_data8(0x07);
Geremia 29:866213bb9bf0 89 wr_data8(0x02); //VGH:15V,VGL:-7.16V (BOE LCD: VGH:12~18V,VGL:-6~10V)
Geremia 29:866213bb9bf0 90 wr_data8(0x8B);
Geremia 29:866213bb9bf0 91 wr_data8(0x03);
Geremia 29:866213bb9bf0 92 wr_data8(0xD4);
Geremia 29:866213bb9bf0 93
Geremia 29:866213bb9bf0 94 wr_cmd8(0x3A); // Set_pixel_format
Geremia 29:866213bb9bf0 95 wr_data8(0x55); //0x55:16bit/pixel,65k;0x66:18bit/pixel,262k;
Geremia 29:866213bb9bf0 96
Geremia 29:866213bb9bf0 97 wr_cmd8(0x36); //Set_address_mode
Geremia 29:866213bb9bf0 98 wr_data8(0x38);
Geremia 29:866213bb9bf0 99
Geremia 29:866213bb9bf0 100 wr_cmd8(0x20); //Exit_invert_mode
Geremia 29:866213bb9bf0 101
Geremia 29:866213bb9bf0 102 wr_cmd8(0xC1); //Set Normal/Partial mode display timing
Geremia 29:866213bb9bf0 103 wr_data8(0x10);
Geremia 29:866213bb9bf0 104 wr_data8(0x1A);
Geremia 29:866213bb9bf0 105 wr_data8(0x02);
Geremia 29:866213bb9bf0 106 wr_data8(0x02);
Geremia 29:866213bb9bf0 107
Geremia 29:866213bb9bf0 108 wr_cmd8(0xC0); //Set display related setting
Geremia 29:866213bb9bf0 109 wr_data8(0x10);
Geremia 29:866213bb9bf0 110 wr_data8(0x31);
Geremia 29:866213bb9bf0 111 wr_data8(0x00);
Geremia 29:866213bb9bf0 112 wr_data8(0x00);
Geremia 29:866213bb9bf0 113 wr_data8(0x01);
Geremia 29:866213bb9bf0 114 wr_data8(0x02);
Geremia 29:866213bb9bf0 115
Geremia 29:866213bb9bf0 116 wr_cmd8(0xC4); //Set waveform timing
Geremia 29:866213bb9bf0 117 wr_data8(0x01);
Geremia 29:866213bb9bf0 118
Geremia 29:866213bb9bf0 119 wr_cmd8(0xC5); //Set oscillator
Geremia 29:866213bb9bf0 120 wr_data8(0x04); //72Hz
Geremia 29:866213bb9bf0 121 wr_data8(0x01);
Geremia 29:866213bb9bf0 122
Geremia 29:866213bb9bf0 123 wr_cmd8(0xD2); //Set power for normal mode
Geremia 29:866213bb9bf0 124 wr_data8(0x01);
Geremia 29:866213bb9bf0 125 wr_data8(0x44);
Geremia 29:866213bb9bf0 126
Geremia 29:866213bb9bf0 127 wr_cmd8(0xC8); //Set gamma
Geremia 29:866213bb9bf0 128 wr_data8(0x00);
Geremia 29:866213bb9bf0 129 wr_data8(0x77);
Geremia 29:866213bb9bf0 130 wr_data8(0x77);
Geremia 29:866213bb9bf0 131 wr_data8(0x00);
Geremia 29:866213bb9bf0 132 wr_data8(0x04);
Geremia 29:866213bb9bf0 133 wr_data8(0x00);
Geremia 29:866213bb9bf0 134 wr_data8(0x00);
Geremia 29:866213bb9bf0 135 wr_data8(0x00);
Geremia 29:866213bb9bf0 136 wr_data8(0x77);
Geremia 29:866213bb9bf0 137 wr_data8(0x00);
Geremia 29:866213bb9bf0 138 wr_data8(0x00);
Geremia 29:866213bb9bf0 139 wr_data8(0x08);
Geremia 29:866213bb9bf0 140 wr_data8(0x00);
Geremia 29:866213bb9bf0 141 wr_data8(0x00);
Geremia 29:866213bb9bf0 142 wr_data8(0x00);
Geremia 29:866213bb9bf0 143
Geremia 29:866213bb9bf0 144 wr_cmd8(0xCA); //Set DGC LUT
Geremia 29:866213bb9bf0 145 wr_data8(0x00);
Geremia 29:866213bb9bf0 146
Geremia 29:866213bb9bf0 147 wr_cmd8(0xEA); //3-Gamma Function Control
Geremia 29:866213bb9bf0 148 wr_data8(0x80); // enable
Geremia 29:866213bb9bf0 149
Geremia 29:866213bb9bf0 150 wr_cmd8(0x29); // Set_display_on
Geremia 34:c66986d80f72 151 thread_sleep_for(150);
Geremia 29:866213bb9bf0 152
Geremia 29:866213bb9bf0 153 }