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:
27:acb2594b8aa4
align attribute fixed to gcc style, updated to OS6 then got bored

Who changed what in which revision?

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