UniGraphics Library Fork to support mbed os 6.3 Release for ILI9341

Dependents:   TFT_ILI9341_UniGraphic TFT_ILI9341_os6

Committer:
amouroug
Date:
Thu Oct 08 18:11:03 2020 -0500
Revision:
2:59188908eb60
Parent:
1:6f267dbbafec
Added GraphicsDisplay GFX API to draw triangle.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
amouroug 0:bb2bda4f5846 1 /* mbed UniGraphic library - Device specific class
amouroug 0:bb2bda4f5846 2 * Copyright (c) 2015 Giuliano Dianda
amouroug 0:bb2bda4f5846 3 * Released under the MIT License: http://mbed.org/license/mit
amouroug 0:bb2bda4f5846 4 */
amouroug 0:bb2bda4f5846 5
amouroug 0:bb2bda4f5846 6 #include "Protocols.h"
amouroug 0:bb2bda4f5846 7 #include "ILI9341.h"
amouroug 0:bb2bda4f5846 8
amouroug 0:bb2bda4f5846 9 //////////////////////////////////////////////////////////////////////////////////
amouroug 0:bb2bda4f5846 10 // display settings ///////////////////////////////////////////////////////
amouroug 0:bb2bda4f5846 11 /////////////////////////////////////////////////////////////////////////
amouroug 0:bb2bda4f5846 12
amouroug 0:bb2bda4f5846 13 // put in constructor
amouroug 0:bb2bda4f5846 14 //#define LCDSIZE_X 240 // display X pixels, TFTs are usually portrait view
amouroug 0:bb2bda4f5846 15 //#define LCDSIZE_Y 320 // display Y pixels
amouroug 0:bb2bda4f5846 16
amouroug 0:bb2bda4f5846 17
amouroug 0:bb2bda4f5846 18
amouroug 0:bb2bda4f5846 19 ILI9341::ILI9341(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)
amouroug 0:bb2bda4f5846 20 : TFT(displayproto, port, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, name)
amouroug 0:bb2bda4f5846 21 {
amouroug 0:bb2bda4f5846 22 hw_reset();
amouroug 0:bb2bda4f5846 23 BusEnable(true);
amouroug 0:bb2bda4f5846 24 identify(); // will collect tftID and set mipistd flag
amouroug 0:bb2bda4f5846 25 init();
amouroug 0:bb2bda4f5846 26 auto_gram_read_format();
amouroug 0:bb2bda4f5846 27 set_orientation(0);
amouroug 0:bb2bda4f5846 28 cls();
amouroug 0:bb2bda4f5846 29 FastWindow(true); // most but not all controllers support this, even if datasheet tells they should.
amouroug 0:bb2bda4f5846 30 locate(0,0);
amouroug 0:bb2bda4f5846 31 }
amouroug 0:bb2bda4f5846 32 ILI9341::ILI9341(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)
amouroug 0:bb2bda4f5846 33 : TFT(displayproto, buspins, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, name)
amouroug 0:bb2bda4f5846 34 {
amouroug 0:bb2bda4f5846 35 hw_reset();
amouroug 0:bb2bda4f5846 36 BusEnable(true);
amouroug 0:bb2bda4f5846 37 identify(); // will collect tftID and set mipistd flag
amouroug 0:bb2bda4f5846 38 init();
amouroug 0:bb2bda4f5846 39 auto_gram_read_format();
amouroug 0:bb2bda4f5846 40 set_orientation(0);
amouroug 0:bb2bda4f5846 41 cls();
amouroug 0:bb2bda4f5846 42 FastWindow(true); // most but not all controllers support this, even if datasheet tells they should.
amouroug 0:bb2bda4f5846 43 locate(0,0);
amouroug 0:bb2bda4f5846 44 }
amouroug 0:bb2bda4f5846 45 ILI9341::ILI9341(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)
amouroug 0:bb2bda4f5846 46 : TFT(displayproto, Hz, mosi, miso, sclk, CS, reset, DC, LCDSIZE_X, LCDSIZE_Y, name)
amouroug 0:bb2bda4f5846 47 {
amouroug 0:bb2bda4f5846 48 hw_reset(); //TFT class forwards to Protocol class
amouroug 0:bb2bda4f5846 49 BusEnable(true); //TFT class forwards to Protocol class
amouroug 0:bb2bda4f5846 50 identify(); // will collect tftID and set mipistd flag
amouroug 0:bb2bda4f5846 51 init(); // per display custom init cmd sequence, implemented here
amouroug 0:bb2bda4f5846 52 auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
amouroug 0:bb2bda4f5846 53 set_orientation(0); //TFT class does for MIPI standard and some ILIxxx
amouroug 0:bb2bda4f5846 54 FastWindow(true); // most but not all controllers support this, even if datasheet tells they should.
amouroug 0:bb2bda4f5846 55 cls();
amouroug 0:bb2bda4f5846 56 locate(0,0);
amouroug 0:bb2bda4f5846 57 }
amouroug 0:bb2bda4f5846 58 // reset and init the lcd controller
amouroug 0:bb2bda4f5846 59 void ILI9341::init()
amouroug 0:bb2bda4f5846 60 {
amouroug 0:bb2bda4f5846 61 /* Start Initial Sequence ----------------------------------------------------*/
amouroug 0:bb2bda4f5846 62
amouroug 0:bb2bda4f5846 63 wr_cmd8(0xCB); // POWER_ON_SEQ_CONTROL
amouroug 0:bb2bda4f5846 64 wr_data8(0x39);
amouroug 0:bb2bda4f5846 65 wr_data8(0x2C);
amouroug 0:bb2bda4f5846 66 wr_data8(0x00);
amouroug 0:bb2bda4f5846 67 wr_data8(0x34);
amouroug 0:bb2bda4f5846 68 wr_data8(0x02);
amouroug 0:bb2bda4f5846 69
amouroug 0:bb2bda4f5846 70 wr_cmd8(0xCF); // POWER_CONTROL_B
amouroug 0:bb2bda4f5846 71 wr_data8(0x00);
amouroug 0:bb2bda4f5846 72 wr_data8(0xC1); // Applic Notes 81, was 83, C1 enables PCEQ: PC and EQ operation for power saving
amouroug 0:bb2bda4f5846 73 wr_data8(0x30);
amouroug 0:bb2bda4f5846 74
amouroug 0:bb2bda4f5846 75 wr_cmd8(0xE8); // DRIVER_TIMING_CONTROL_A
amouroug 0:bb2bda4f5846 76 wr_data8(0x85);
amouroug 0:bb2bda4f5846 77 wr_data8(0x00); // AN 10, was 01
amouroug 0:bb2bda4f5846 78 wr_data8(0x78); // AN 7A, was 79
amouroug 0:bb2bda4f5846 79
amouroug 0:bb2bda4f5846 80 wr_cmd8(0xEA); // DRIVER_TIMING_CONTROL_B
amouroug 0:bb2bda4f5846 81 wr_data8(0x00);
amouroug 0:bb2bda4f5846 82 wr_data8(0x00);
amouroug 0:bb2bda4f5846 83
amouroug 0:bb2bda4f5846 84 wr_cmd8(0xED);
amouroug 0:bb2bda4f5846 85 wr_data8(0x64);
amouroug 0:bb2bda4f5846 86 wr_data8(0x03);
amouroug 0:bb2bda4f5846 87 wr_data8(0x12);
amouroug 0:bb2bda4f5846 88 wr_data8(0x81);
amouroug 0:bb2bda4f5846 89
amouroug 0:bb2bda4f5846 90 wr_cmd8(0xF7); // PUMP_RATIO_CONTROL
amouroug 0:bb2bda4f5846 91 wr_data8(0x20);
amouroug 0:bb2bda4f5846 92
amouroug 0:bb2bda4f5846 93 wr_cmd8(0xC0); // POWER_CONTROL_1
amouroug 0:bb2bda4f5846 94 wr_data8(0x23); // AN 21, was 26
amouroug 0:bb2bda4f5846 95
amouroug 0:bb2bda4f5846 96 wr_cmd8(0xC1); // POWER_CONTROL_2
amouroug 0:bb2bda4f5846 97 wr_data8(0x10); // AN 11, was 11
amouroug 0:bb2bda4f5846 98
amouroug 0:bb2bda4f5846 99 wr_cmd8(0xC5); // VCOM_CONTROL_1
amouroug 0:bb2bda4f5846 100 wr_data8(0x3E); // AN 3F, was 35
amouroug 0:bb2bda4f5846 101 wr_data8(0x28); // AN 3C, was 3E
amouroug 0:bb2bda4f5846 102
amouroug 0:bb2bda4f5846 103 wr_cmd8(0xC7); // VCOM_CONTROL_2
amouroug 0:bb2bda4f5846 104 wr_data8(0x86); // AN A7, was BE
amouroug 0:bb2bda4f5846 105
amouroug 0:bb2bda4f5846 106
amouroug 0:bb2bda4f5846 107
amouroug 0:bb2bda4f5846 108 wr_cmd8(0xB1); // Frame Rate
amouroug 0:bb2bda4f5846 109 wr_data8(0x00);
amouroug 0:bb2bda4f5846 110 wr_data8(0x18); // AN 1B, was 1B 1B=70hz
amouroug 0:bb2bda4f5846 111
amouroug 0:bb2bda4f5846 112 wr_cmd8(0xB6); // display function control, INTERESTING
amouroug 0:bb2bda4f5846 113 wr_data8(0x08); // AN 0A, was 0A
amouroug 0:bb2bda4f5846 114 wr_data8(0x82); // AN A2
amouroug 0:bb2bda4f5846 115 wr_data8(0x27); // AN not present
amouroug 0:bb2bda4f5846 116 // wr_data8(0x00); // was present
amouroug 0:bb2bda4f5846 117
amouroug 0:bb2bda4f5846 118 wr_cmd8(0xF2); // Gamma Function Disable
amouroug 0:bb2bda4f5846 119 wr_data8(0x00); // AN 00, was 08
amouroug 0:bb2bda4f5846 120
amouroug 0:bb2bda4f5846 121 wr_cmd8(0x26);
amouroug 0:bb2bda4f5846 122 wr_data8(0x01); // gamma set for curve 01/2/04/08
amouroug 0:bb2bda4f5846 123
amouroug 0:bb2bda4f5846 124 wr_cmd8(0xE0); // positive gamma correction
amouroug 0:bb2bda4f5846 125 wr_data8(0x0F);
amouroug 0:bb2bda4f5846 126 wr_data8(0x31);
amouroug 0:bb2bda4f5846 127 wr_data8(0x2B);
amouroug 0:bb2bda4f5846 128 wr_data8(0x0C);
amouroug 0:bb2bda4f5846 129 wr_data8(0x0E);
amouroug 0:bb2bda4f5846 130 wr_data8(0x08);
amouroug 0:bb2bda4f5846 131 wr_data8(0x4E);
amouroug 0:bb2bda4f5846 132 wr_data8(0xF1);
amouroug 0:bb2bda4f5846 133 wr_data8(0x37);
amouroug 0:bb2bda4f5846 134 wr_data8(0x07);
amouroug 0:bb2bda4f5846 135 wr_data8(0x10);
amouroug 0:bb2bda4f5846 136 wr_data8(0x03);
amouroug 0:bb2bda4f5846 137 wr_data8(0x0E);
amouroug 0:bb2bda4f5846 138 wr_data8(0x09);
amouroug 0:bb2bda4f5846 139 wr_data8(0x00);
amouroug 0:bb2bda4f5846 140
amouroug 0:bb2bda4f5846 141 wr_cmd8(0xE1); // negativ gamma correction
amouroug 0:bb2bda4f5846 142 wr_data8(0x00);
amouroug 0:bb2bda4f5846 143 wr_data8(0x0E);
amouroug 0:bb2bda4f5846 144 wr_data8(0x14);
amouroug 0:bb2bda4f5846 145 wr_data8(0x03);
amouroug 0:bb2bda4f5846 146 wr_data8(0x11);
amouroug 0:bb2bda4f5846 147 wr_data8(0x07);
amouroug 0:bb2bda4f5846 148 wr_data8(0x31);
amouroug 0:bb2bda4f5846 149 wr_data8(0xC1);
amouroug 0:bb2bda4f5846 150 wr_data8(0x48);
amouroug 0:bb2bda4f5846 151 wr_data8(0x08);
amouroug 0:bb2bda4f5846 152 wr_data8(0x0F);
amouroug 0:bb2bda4f5846 153 wr_data8(0x0C);
amouroug 0:bb2bda4f5846 154 wr_data8(0x31);
amouroug 0:bb2bda4f5846 155 wr_data8(0x36);
amouroug 0:bb2bda4f5846 156 wr_data8(0x0F);
amouroug 0:bb2bda4f5846 157
amouroug 0:bb2bda4f5846 158 //wr_cmd8(0x34); // tearing effect off
amouroug 0:bb2bda4f5846 159
amouroug 0:bb2bda4f5846 160 //wr_cmd8(0x35); // tearing effect on
amouroug 0:bb2bda4f5846 161
amouroug 0:bb2bda4f5846 162 // wr_cmd8(0xB7); // ENTRY_MODE_SET
amouroug 0:bb2bda4f5846 163 // wr_data8(0x07);
amouroug 0:bb2bda4f5846 164
amouroug 0:bb2bda4f5846 165 wr_cmd8(0x36); // MEMORY_ACCESS_CONTROL (orientation stuff)
amouroug 0:bb2bda4f5846 166 wr_data8(0x48);
amouroug 0:bb2bda4f5846 167
amouroug 0:bb2bda4f5846 168 wr_cmd8(0x3A); // COLMOD_PIXEL_FORMAT_SET
amouroug 0:bb2bda4f5846 169 wr_data8(0x55); // 16 bit pixel
amouroug 0:bb2bda4f5846 170
amouroug 0:bb2bda4f5846 171 wr_cmd8(0x13); // Nomal Displaymode
amouroug 0:bb2bda4f5846 172
amouroug 0:bb2bda4f5846 173 wr_cmd8(0x11); // sleep out
amouroug 1:6f267dbbafec 174 ThisThread::sleep_for(150ms);
amouroug 0:bb2bda4f5846 175
amouroug 0:bb2bda4f5846 176 wr_cmd8(0x29); // display on
amouroug 1:6f267dbbafec 177 ThisThread::sleep_for(150ms);
amouroug 0:bb2bda4f5846 178
amouroug 0:bb2bda4f5846 179 }