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
PAR16.cpp
00001 /* mbed UniGraphic library - PAR16 protocol class 00002 * Copyright (c) 2015 Giuliano Dianda 00003 * Released under the MIT License: http://mbed.org/license/mit 00004 * 00005 * Derived work of: 00006 * 00007 * mbed library for 240*320 pixel display TFT based on ILI9341 LCD Controller 00008 * Copyright (c) 2013 Peter Drescher - DC2PD 00009 * 00010 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00011 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00012 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00013 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00014 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00015 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00016 * THE SOFTWARE. 00017 */ 00018 #include "platform.h" 00019 #if DEVICE_PORTINOUT 00020 00021 #include "PAR16.h" 00022 00023 PAR16::PAR16(PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD) 00024 : _port(port,0xFFFF), _CS(CS), _reset(reset), _DC(DC), _WR(WR), _RD(RD) 00025 { 00026 _reset = 1; 00027 _DC=1; 00028 _WR=1; 00029 _RD=1; 00030 _CS=1; 00031 _port.mode(PullNone); 00032 _port.output(); // will re-enable our GPIO port 00033 hw_reset(); 00034 } 00035 00036 void PAR16::wr_cmd8(unsigned char cmd) 00037 { 00038 _DC = 0; // 0=cmd 00039 _port.write(cmd); // write 8bit 00040 _WR=0; 00041 _WR=1; 00042 _DC = 1; // 1=data next 00043 } 00044 void PAR16::wr_data8(unsigned char data) 00045 { 00046 _port.write(data); // write 8bit 00047 _WR=0; 00048 _WR=1; 00049 } 00050 void PAR16::wr_cmd16(unsigned short cmd) 00051 { 00052 _DC = 0; // 0=cmd 00053 _port.write(cmd>>8); // write 8bit 00054 _WR=0; 00055 _WR=1; 00056 _port.write(cmd&0xFF); // write 8bit 00057 _WR=0; 00058 _WR=1; 00059 _DC = 1; // 1=data next 00060 } 00061 void PAR16::wr_data16(unsigned short data) 00062 { 00063 _port.write(data>>8); // write 8bit 00064 _WR=0; 00065 _WR=1; 00066 _port.write(data&0xFF); // write 8bit 00067 _WR=0; 00068 _WR=1; 00069 } 00070 void PAR16::wr_gram(unsigned short data) 00071 { 00072 _port.write(data); // write 16bit 00073 _WR=0; 00074 _WR=1; 00075 } 00076 void PAR16::wr_gram(unsigned short data, unsigned int count) 00077 { 00078 while(count) 00079 { 00080 _port.write(data); // rewrite even if same data, otherwise too much fast 00081 _WR=0; 00082 _WR=1; 00083 count--; 00084 } 00085 } 00086 void PAR16::wr_grambuf(unsigned short* data, unsigned int lenght) 00087 { 00088 while(lenght) 00089 { 00090 _port.write(*data); // write 16bit 00091 _WR=0; 00092 _WR=1; 00093 data++; 00094 lenght--; 00095 } 00096 } 00097 unsigned short PAR16::rd_gram(bool convert) 00098 { 00099 unsigned int r=0; 00100 _port.input(); 00101 00102 _RD = 0; 00103 _port.read(); //dummy read 00104 _RD = 1; 00105 00106 _RD = 0; 00107 // _RD = 0; // add wait 00108 r |= _port.read(); 00109 _RD = 1; 00110 if(convert) 00111 { 00112 r <<= 8; 00113 _RD = 0; 00114 // _RD = 0; // add wait 00115 r |= _port.read()>>8; //MSB of port read is blue, LSB is red of next pixel 00116 _RD = 1; 00117 // gram is 18bit/pixel, if you set 16bit/pixel (cmd 3A), during writing the 16bits are expanded to 18bit 00118 // during reading, you read the raw 18bit gram 00119 r = RGB24to16((r&0xFF0000)>>16, (r&0xFF00)>>8, r&0xFF);// 18bit pixel padded to 24bits, rrrrrr00_gggggg00_bbbbbb00, converted to 16bit 00120 } 00121 _port.output(); 00122 return (unsigned short)r; 00123 } 00124 unsigned int PAR16::rd_reg_data32(unsigned char reg) 00125 { 00126 wr_cmd8(reg); 00127 unsigned int r=0; 00128 // _DC = 1; // 1=data 00129 _port.input(); 00130 00131 _RD = 0; 00132 _port.read(); //dummy read 00133 _RD = 1; 00134 00135 _RD = 0; 00136 // _RD = 0; // add wait 00137 r |= (_port.read()&0xFF); 00138 r <<= 8; 00139 _RD = 1; 00140 00141 _RD = 0; 00142 // _RD = 0; // add wait 00143 r |= (_port.read()&0xFF); 00144 r <<= 8; 00145 _RD = 1; 00146 00147 _RD = 0; 00148 // _RD = 0; // add wait 00149 r |= (_port.read()&0xFF); 00150 r <<= 8; 00151 _RD = 1; 00152 00153 _RD = 0; 00154 // _RD = 0; // add wait 00155 r |= (_port.read()&0xFF); 00156 _RD = 1; 00157 00158 _CS = 1; // toggle CS to interupt the cmd in case was not supported 00159 _CS = 0; 00160 00161 _port.output(); 00162 return r; 00163 } 00164 // in Par mode EXTC regs (0xB0-0xFF) can be directly read 00165 unsigned int PAR16::rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd) 00166 { 00167 return rd_reg_data32(reg); 00168 } 00169 // ILI932x specific 00170 void PAR16::dummyread() 00171 { 00172 _port.input(); 00173 _RD = 0; 00174 _port.read(); // dummy read 00175 _RD=1; 00176 // _port.output(); 00177 } 00178 // ILI932x specific 00179 void PAR16::reg_select(unsigned char reg, bool forread) 00180 { 00181 _DC = 0; 00182 _port.write(reg); // write 16bit 00183 _WR=0; 00184 _WR=1; 00185 _DC = 1; // 1=data next 00186 } 00187 // ILI932x specific 00188 void PAR16::reg_write(unsigned char reg, unsigned short data) 00189 { 00190 _DC = 0; 00191 _port.write(reg); // write 16bit 00192 _WR=0; 00193 _WR=1; 00194 _DC = 1; 00195 _port.write(data); // write 16bit 00196 _WR=0; 00197 _WR=1; 00198 } 00199 // ILI932x specific 00200 unsigned short PAR16::reg_read(unsigned char reg) 00201 { 00202 unsigned short r=0; 00203 _DC = 0; 00204 _port.write(reg); // write 16bit 00205 _WR=0; 00206 _WR=1; 00207 _DC = 1; 00208 _port.input(); 00209 _RD=0; 00210 r |= _port.read(); // read 16bit 00211 _RD=1; 00212 _port.output(); 00213 return r; 00214 } 00215 void PAR16::hw_reset() 00216 { 00217 thread_sleep_for(15); 00218 _DC = 1; 00219 _CS = 1; 00220 _WR = 1; 00221 _RD = 1; 00222 _reset = 0; // display reset 00223 thread_sleep_for(2); 00224 _reset = 1; // end reset 00225 thread_sleep_for(100); 00226 } 00227 void PAR16::BusEnable(bool enable) 00228 { 00229 _CS = enable ? 0:1; 00230 } 00231 00232 #endif
Generated on Tue Jul 12 2022 13:49:07 by
![doxygen](doxygen.png)