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 - PAR16 protocol 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 * Derived work of:
amouroug 0:bb2bda4f5846 6 *
amouroug 0:bb2bda4f5846 7 * mbed library for 240*320 pixel display TFT based on ILI9341 LCD Controller
amouroug 0:bb2bda4f5846 8 * Copyright (c) 2013 Peter Drescher - DC2PD
amouroug 0:bb2bda4f5846 9 *
amouroug 0:bb2bda4f5846 10 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
amouroug 0:bb2bda4f5846 11 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
amouroug 0:bb2bda4f5846 12 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
amouroug 0:bb2bda4f5846 13 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
amouroug 0:bb2bda4f5846 14 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
amouroug 0:bb2bda4f5846 15 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
amouroug 0:bb2bda4f5846 16 * THE SOFTWARE.
amouroug 0:bb2bda4f5846 17 */
amouroug 0:bb2bda4f5846 18 #include "platform.h"
amouroug 0:bb2bda4f5846 19 #if DEVICE_PORTINOUT
amouroug 0:bb2bda4f5846 20
amouroug 0:bb2bda4f5846 21 #include "PAR16.h"
amouroug 0:bb2bda4f5846 22
amouroug 0:bb2bda4f5846 23 PAR16::PAR16(PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD)
amouroug 0:bb2bda4f5846 24 : _port(port,0xFFFF), _CS(CS), _reset(reset), _DC(DC), _WR(WR), _RD(RD)
amouroug 0:bb2bda4f5846 25 {
amouroug 0:bb2bda4f5846 26 _reset = 1;
amouroug 0:bb2bda4f5846 27 _DC=1;
amouroug 0:bb2bda4f5846 28 _WR=1;
amouroug 0:bb2bda4f5846 29 _RD=1;
amouroug 0:bb2bda4f5846 30 _CS=1;
amouroug 0:bb2bda4f5846 31 _port.mode(PullNone);
amouroug 0:bb2bda4f5846 32 _port.output(); // will re-enable our GPIO port
amouroug 0:bb2bda4f5846 33 hw_reset();
amouroug 0:bb2bda4f5846 34 }
amouroug 0:bb2bda4f5846 35
amouroug 0:bb2bda4f5846 36 void PAR16::wr_cmd8(unsigned char cmd)
amouroug 0:bb2bda4f5846 37 {
amouroug 0:bb2bda4f5846 38 _DC = 0; // 0=cmd
amouroug 0:bb2bda4f5846 39 _port.write(cmd); // write 8bit
amouroug 0:bb2bda4f5846 40 _WR=0;
amouroug 0:bb2bda4f5846 41 _WR=1;
amouroug 0:bb2bda4f5846 42 _DC = 1; // 1=data next
amouroug 0:bb2bda4f5846 43 }
amouroug 0:bb2bda4f5846 44 void PAR16::wr_data8(unsigned char data)
amouroug 0:bb2bda4f5846 45 {
amouroug 0:bb2bda4f5846 46 _port.write(data); // write 8bit
amouroug 0:bb2bda4f5846 47 _WR=0;
amouroug 0:bb2bda4f5846 48 _WR=1;
amouroug 0:bb2bda4f5846 49 }
amouroug 0:bb2bda4f5846 50 void PAR16::wr_cmd16(unsigned short cmd)
amouroug 0:bb2bda4f5846 51 {
amouroug 0:bb2bda4f5846 52 _DC = 0; // 0=cmd
amouroug 0:bb2bda4f5846 53 _port.write(cmd>>8); // write 8bit
amouroug 0:bb2bda4f5846 54 _WR=0;
amouroug 0:bb2bda4f5846 55 _WR=1;
amouroug 0:bb2bda4f5846 56 _port.write(cmd&0xFF); // write 8bit
amouroug 0:bb2bda4f5846 57 _WR=0;
amouroug 0:bb2bda4f5846 58 _WR=1;
amouroug 0:bb2bda4f5846 59 _DC = 1; // 1=data next
amouroug 0:bb2bda4f5846 60 }
amouroug 0:bb2bda4f5846 61 void PAR16::wr_data16(unsigned short data)
amouroug 0:bb2bda4f5846 62 {
amouroug 0:bb2bda4f5846 63 _port.write(data>>8); // write 8bit
amouroug 0:bb2bda4f5846 64 _WR=0;
amouroug 0:bb2bda4f5846 65 _WR=1;
amouroug 0:bb2bda4f5846 66 _port.write(data&0xFF); // write 8bit
amouroug 0:bb2bda4f5846 67 _WR=0;
amouroug 0:bb2bda4f5846 68 _WR=1;
amouroug 0:bb2bda4f5846 69 }
amouroug 0:bb2bda4f5846 70 void PAR16::wr_gram(unsigned short data)
amouroug 0:bb2bda4f5846 71 {
amouroug 0:bb2bda4f5846 72 _port.write(data); // write 16bit
amouroug 0:bb2bda4f5846 73 _WR=0;
amouroug 0:bb2bda4f5846 74 _WR=1;
amouroug 0:bb2bda4f5846 75 }
amouroug 0:bb2bda4f5846 76 void PAR16::wr_gram(unsigned short data, unsigned int count)
amouroug 0:bb2bda4f5846 77 {
amouroug 0:bb2bda4f5846 78 while(count)
amouroug 0:bb2bda4f5846 79 {
amouroug 0:bb2bda4f5846 80 _port.write(data); // rewrite even if same data, otherwise too much fast
amouroug 0:bb2bda4f5846 81 _WR=0;
amouroug 0:bb2bda4f5846 82 _WR=1;
amouroug 0:bb2bda4f5846 83 count--;
amouroug 0:bb2bda4f5846 84 }
amouroug 0:bb2bda4f5846 85 }
amouroug 0:bb2bda4f5846 86 void PAR16::wr_grambuf(unsigned short* data, unsigned int lenght)
amouroug 0:bb2bda4f5846 87 {
amouroug 0:bb2bda4f5846 88 while(lenght)
amouroug 0:bb2bda4f5846 89 {
amouroug 0:bb2bda4f5846 90 _port.write(*data); // write 16bit
amouroug 0:bb2bda4f5846 91 _WR=0;
amouroug 0:bb2bda4f5846 92 _WR=1;
amouroug 0:bb2bda4f5846 93 data++;
amouroug 0:bb2bda4f5846 94 lenght--;
amouroug 0:bb2bda4f5846 95 }
amouroug 0:bb2bda4f5846 96 }
amouroug 0:bb2bda4f5846 97 unsigned short PAR16::rd_gram(bool convert)
amouroug 0:bb2bda4f5846 98 {
amouroug 0:bb2bda4f5846 99 unsigned int r=0;
amouroug 0:bb2bda4f5846 100 _port.input();
amouroug 0:bb2bda4f5846 101
amouroug 0:bb2bda4f5846 102 _RD = 0;
amouroug 0:bb2bda4f5846 103 _port.read(); //dummy read
amouroug 0:bb2bda4f5846 104 _RD = 1;
amouroug 0:bb2bda4f5846 105
amouroug 0:bb2bda4f5846 106 _RD = 0;
amouroug 0:bb2bda4f5846 107 // _RD = 0; // add wait
amouroug 0:bb2bda4f5846 108 r |= _port.read();
amouroug 0:bb2bda4f5846 109 _RD = 1;
amouroug 0:bb2bda4f5846 110 if(convert)
amouroug 0:bb2bda4f5846 111 {
amouroug 0:bb2bda4f5846 112 r <<= 8;
amouroug 0:bb2bda4f5846 113 _RD = 0;
amouroug 0:bb2bda4f5846 114 // _RD = 0; // add wait
amouroug 0:bb2bda4f5846 115 r |= _port.read()>>8; //MSB of port read is blue, LSB is red of next pixel
amouroug 0:bb2bda4f5846 116 _RD = 1;
amouroug 0:bb2bda4f5846 117 // gram is 18bit/pixel, if you set 16bit/pixel (cmd 3A), during writing the 16bits are expanded to 18bit
amouroug 0:bb2bda4f5846 118 // during reading, you read the raw 18bit gram
amouroug 0:bb2bda4f5846 119 r = RGB24to16((r&0xFF0000)>>16, (r&0xFF00)>>8, r&0xFF);// 18bit pixel padded to 24bits, rrrrrr00_gggggg00_bbbbbb00, converted to 16bit
amouroug 0:bb2bda4f5846 120 }
amouroug 0:bb2bda4f5846 121 _port.output();
amouroug 0:bb2bda4f5846 122 return (unsigned short)r;
amouroug 0:bb2bda4f5846 123 }
amouroug 0:bb2bda4f5846 124 unsigned int PAR16::rd_reg_data32(unsigned char reg)
amouroug 0:bb2bda4f5846 125 {
amouroug 0:bb2bda4f5846 126 wr_cmd8(reg);
amouroug 0:bb2bda4f5846 127 unsigned int r=0;
amouroug 0:bb2bda4f5846 128 // _DC = 1; // 1=data
amouroug 0:bb2bda4f5846 129 _port.input();
amouroug 0:bb2bda4f5846 130
amouroug 0:bb2bda4f5846 131 _RD = 0;
amouroug 0:bb2bda4f5846 132 _port.read(); //dummy read
amouroug 0:bb2bda4f5846 133 _RD = 1;
amouroug 0:bb2bda4f5846 134
amouroug 0:bb2bda4f5846 135 _RD = 0;
amouroug 0:bb2bda4f5846 136 // _RD = 0; // add wait
amouroug 0:bb2bda4f5846 137 r |= (_port.read()&0xFF);
amouroug 0:bb2bda4f5846 138 r <<= 8;
amouroug 0:bb2bda4f5846 139 _RD = 1;
amouroug 0:bb2bda4f5846 140
amouroug 0:bb2bda4f5846 141 _RD = 0;
amouroug 0:bb2bda4f5846 142 // _RD = 0; // add wait
amouroug 0:bb2bda4f5846 143 r |= (_port.read()&0xFF);
amouroug 0:bb2bda4f5846 144 r <<= 8;
amouroug 0:bb2bda4f5846 145 _RD = 1;
amouroug 0:bb2bda4f5846 146
amouroug 0:bb2bda4f5846 147 _RD = 0;
amouroug 0:bb2bda4f5846 148 // _RD = 0; // add wait
amouroug 0:bb2bda4f5846 149 r |= (_port.read()&0xFF);
amouroug 0:bb2bda4f5846 150 r <<= 8;
amouroug 0:bb2bda4f5846 151 _RD = 1;
amouroug 0:bb2bda4f5846 152
amouroug 0:bb2bda4f5846 153 _RD = 0;
amouroug 0:bb2bda4f5846 154 // _RD = 0; // add wait
amouroug 0:bb2bda4f5846 155 r |= (_port.read()&0xFF);
amouroug 0:bb2bda4f5846 156 _RD = 1;
amouroug 0:bb2bda4f5846 157
amouroug 0:bb2bda4f5846 158 _CS = 1; // toggle CS to interupt the cmd in case was not supported
amouroug 0:bb2bda4f5846 159 _CS = 0;
amouroug 0:bb2bda4f5846 160
amouroug 0:bb2bda4f5846 161 _port.output();
amouroug 0:bb2bda4f5846 162 return r;
amouroug 0:bb2bda4f5846 163 }
amouroug 0:bb2bda4f5846 164 // in Par mode EXTC regs (0xB0-0xFF) can be directly read
amouroug 0:bb2bda4f5846 165 unsigned int PAR16::rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd)
amouroug 0:bb2bda4f5846 166 {
amouroug 0:bb2bda4f5846 167 return rd_reg_data32(reg);
amouroug 0:bb2bda4f5846 168 }
amouroug 0:bb2bda4f5846 169 // ILI932x specific
amouroug 0:bb2bda4f5846 170 void PAR16::dummyread()
amouroug 0:bb2bda4f5846 171 {
amouroug 0:bb2bda4f5846 172 _port.input();
amouroug 0:bb2bda4f5846 173 _RD = 0;
amouroug 0:bb2bda4f5846 174 _port.read(); // dummy read
amouroug 0:bb2bda4f5846 175 _RD=1;
amouroug 0:bb2bda4f5846 176 // _port.output();
amouroug 0:bb2bda4f5846 177 }
amouroug 0:bb2bda4f5846 178 // ILI932x specific
amouroug 0:bb2bda4f5846 179 void PAR16::reg_select(unsigned char reg, bool forread)
amouroug 0:bb2bda4f5846 180 {
amouroug 0:bb2bda4f5846 181 _DC = 0;
amouroug 0:bb2bda4f5846 182 _port.write(reg); // write 16bit
amouroug 0:bb2bda4f5846 183 _WR=0;
amouroug 0:bb2bda4f5846 184 _WR=1;
amouroug 0:bb2bda4f5846 185 _DC = 1; // 1=data next
amouroug 0:bb2bda4f5846 186 }
amouroug 0:bb2bda4f5846 187 // ILI932x specific
amouroug 0:bb2bda4f5846 188 void PAR16::reg_write(unsigned char reg, unsigned short data)
amouroug 0:bb2bda4f5846 189 {
amouroug 0:bb2bda4f5846 190 _DC = 0;
amouroug 0:bb2bda4f5846 191 _port.write(reg); // write 16bit
amouroug 0:bb2bda4f5846 192 _WR=0;
amouroug 0:bb2bda4f5846 193 _WR=1;
amouroug 0:bb2bda4f5846 194 _DC = 1;
amouroug 0:bb2bda4f5846 195 _port.write(data); // write 16bit
amouroug 0:bb2bda4f5846 196 _WR=0;
amouroug 0:bb2bda4f5846 197 _WR=1;
amouroug 0:bb2bda4f5846 198 }
amouroug 0:bb2bda4f5846 199 // ILI932x specific
amouroug 0:bb2bda4f5846 200 unsigned short PAR16::reg_read(unsigned char reg)
amouroug 0:bb2bda4f5846 201 {
amouroug 0:bb2bda4f5846 202 unsigned short r=0;
amouroug 0:bb2bda4f5846 203 _DC = 0;
amouroug 0:bb2bda4f5846 204 _port.write(reg); // write 16bit
amouroug 0:bb2bda4f5846 205 _WR=0;
amouroug 0:bb2bda4f5846 206 _WR=1;
amouroug 0:bb2bda4f5846 207 _DC = 1;
amouroug 0:bb2bda4f5846 208 _port.input();
amouroug 0:bb2bda4f5846 209 _RD=0;
amouroug 0:bb2bda4f5846 210 r |= _port.read(); // read 16bit
amouroug 0:bb2bda4f5846 211 _RD=1;
amouroug 0:bb2bda4f5846 212 _port.output();
amouroug 0:bb2bda4f5846 213 return r;
amouroug 0:bb2bda4f5846 214 }
amouroug 0:bb2bda4f5846 215 void PAR16::hw_reset()
amouroug 0:bb2bda4f5846 216 {
amouroug 1:6f267dbbafec 217 ThisThread::sleep_for(15ms);
amouroug 0:bb2bda4f5846 218 _DC = 1;
amouroug 0:bb2bda4f5846 219 _CS = 1;
amouroug 0:bb2bda4f5846 220 _WR = 1;
amouroug 0:bb2bda4f5846 221 _RD = 1;
amouroug 0:bb2bda4f5846 222 _reset = 0; // display reset
amouroug 1:6f267dbbafec 223 ThisThread::sleep_for(2ms);
amouroug 0:bb2bda4f5846 224 _reset = 1; // end reset
amouroug 1:6f267dbbafec 225 ThisThread::sleep_for(100ms);
amouroug 0:bb2bda4f5846 226 }
amouroug 0:bb2bda4f5846 227 void PAR16::BusEnable(bool enable)
amouroug 0:bb2bda4f5846 228 {
amouroug 0:bb2bda4f5846 229 _CS = enable ? 0:1;
amouroug 0:bb2bda4f5846 230 }
amouroug 0:bb2bda4f5846 231
amouroug 0:bb2bda4f5846 232 #endif