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.
Fork of UniGraphic by
BUS8.cpp
00001 /* mbed UniGraphic library - BUS8 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 00019 #include "BUS8.h" 00020 00021 BUS8::BUS8(PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD) 00022 : _bus(buspins), _CS(CS), _reset(reset), _DC(DC), _WR(WR), _RD(RD) 00023 { 00024 _reset = 1; 00025 _DC=1; 00026 _WR=1; 00027 _RD=1; 00028 _CS=1; 00029 _bus.mode(PullNone); 00030 _bus.output(); // will re-enable our GPIO port 00031 hw_reset(); 00032 } 00033 00034 void BUS8::wr_cmd8(unsigned char cmd) 00035 { 00036 _DC = 0; // 0=cmd 00037 _bus.write(cmd); // write 8bit 00038 _WR=0; 00039 _WR=1; 00040 _DC = 1; // 1=data next 00041 } 00042 void BUS8::wr_data8(unsigned char data) 00043 { 00044 _bus.write(data); // write 8bit 00045 _WR=0; 00046 _WR=1; 00047 } 00048 void BUS8::wr_cmd16(unsigned short cmd) 00049 { 00050 _DC = 0; // 0=cmd 00051 _bus.write(cmd>>8); // write 8bit 00052 _WR=0; 00053 _WR=1; 00054 _bus.write(cmd&0xFF); // write 8bit 00055 _WR=0; 00056 _WR=1; 00057 _DC = 1; // 1=data next 00058 } 00059 void BUS8::wr_data16(unsigned short data) 00060 { 00061 _bus.write(data>>8); // write 8bit 00062 _WR=0; 00063 _WR=1; 00064 _bus.write(data&0xFF); // write 8bit 00065 _WR=0; 00066 _WR=1; 00067 } 00068 void BUS8::wr_gram(unsigned short data) 00069 { 00070 _bus.write(data>>8); // write 8bit 00071 _WR=0; 00072 _WR=1; 00073 _bus.write(data&0xFF); // write 8bit 00074 _WR=0; 00075 _WR=1; 00076 } 00077 void BUS8::wr_gram(unsigned short data, unsigned int count) 00078 { 00079 if((data>>8)==(data&0xFF)) 00080 { 00081 count<<=1; 00082 // _bus.write(data); // write 8bit 00083 while(count) 00084 { 00085 _bus.write(data); // rewrite even if same data, otherwise too much fast 00086 _WR=0; 00087 _WR=1; 00088 count--; 00089 } 00090 } 00091 else 00092 { 00093 while(count) 00094 { 00095 _bus.write(data>>8); // write 8bit 00096 _WR=0; 00097 _WR=1; 00098 _bus.write(data&0xFF); // write 8bit 00099 _WR=0; 00100 _WR=1; 00101 count--; 00102 } 00103 } 00104 } 00105 void BUS8::wr_grambuf(unsigned short* data, unsigned int lenght) 00106 { 00107 while(lenght) 00108 { 00109 _bus.write((*data)>>8); // write 8bit 00110 _WR=0; 00111 _WR=1; 00112 _bus.write((*data)&0xFF); // write 8bit 00113 _WR=0; 00114 _WR=1; 00115 data++; 00116 lenght--; 00117 } 00118 } 00119 unsigned short BUS8::rd_gram(bool convert) 00120 { 00121 unsigned int r=0; 00122 _bus.input(); 00123 00124 _RD = 0; 00125 _RD = 0; // add wait 00126 _bus.read(); //dummy read 00127 _RD = 1; 00128 00129 _RD = 0; 00130 _RD = 0; // add wait 00131 r |= _bus.read(); 00132 _RD = 1; 00133 r <<= 8; 00134 00135 _RD = 0; 00136 _RD = 0; // add wait 00137 r |= _bus.read(); 00138 _RD = 1; 00139 if(convert) 00140 { 00141 r <<= 8; 00142 _RD = 0; 00143 // _RD = 0; // add wait 00144 r |= _bus.read(); 00145 _RD = 1; 00146 // gram is 18bit/pixel, if you set 16bit/pixel (cmd 3A), during writing the 16bits are expanded to 18bit 00147 // during reading, you read the raw 18bit gram 00148 r = RGB24to16((r&0xFF0000)>>16, (r&0xFF00)>>8, r&0xFF);// 18bit pixel padded to 24bits, rrrrrr00_gggggg00_bbbbbb00, converted to 16bit 00149 } 00150 _bus.output(); 00151 return (unsigned short)r; 00152 } 00153 unsigned int BUS8::rd_reg_data32(unsigned char reg) 00154 { 00155 wr_cmd8(reg); 00156 unsigned int r=0; 00157 _bus.input(); 00158 00159 _RD = 0; 00160 _bus.read(); //dummy read 00161 _RD = 1; 00162 00163 _RD = 0; 00164 // _RD = 0; // add wait 00165 r |= (_bus.read()&0xFF); 00166 r <<= 8; 00167 _RD = 1; 00168 00169 _RD = 0; 00170 // _RD = 0; // add wait 00171 r |= (_bus.read()&0xFF); 00172 r <<= 8; 00173 _RD = 1; 00174 00175 _RD = 0; 00176 // _RD = 0; // add wait 00177 r |= (_bus.read()&0xFF); 00178 r <<= 8; 00179 _RD = 1; 00180 00181 _RD = 0; 00182 // _RD = 0; // add wait 00183 r |= (_bus.read()&0xFF); 00184 _RD = 1; 00185 00186 _CS = 1; // force CS HIG to interupt the cmd in case was not supported 00187 _CS = 0; 00188 _bus.output(); 00189 return r; 00190 } 00191 // in Par mode EXTC regs (0xB0-0xFF) can be directly read 00192 unsigned int BUS8::rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd) 00193 { 00194 return rd_reg_data32(reg); 00195 } 00196 // ILI932x specific 00197 void BUS8::dummyread() 00198 { 00199 _bus.input(); 00200 _RD=0; 00201 _RD=0; // add wait 00202 _bus.read(); // dummy read 00203 _RD=1; 00204 // _bus.output(); 00205 } 00206 // ILI932x specific 00207 void BUS8::reg_select(unsigned char reg, bool forread) 00208 { 00209 _DC = 0; 00210 _bus.write(0); // write MSB 00211 _WR=0; 00212 _WR=1; 00213 _bus.write(reg); // write LSB 00214 _WR=0; 00215 _WR=1; 00216 _DC = 1; // 1=data next 00217 } 00218 // ILI932x specific 00219 void BUS8::reg_write(unsigned char reg, unsigned short data) 00220 { 00221 _DC = 0; 00222 _bus.write(0); // write MSB 00223 _WR=0; 00224 _WR=1; 00225 _bus.write(reg); // write MSB 00226 _WR=0; 00227 _WR=1; 00228 _DC = 1; 00229 _bus.write(data>>8); 00230 _WR=0; 00231 _WR=1; 00232 _bus.write(data&0xFF); 00233 _WR=0; 00234 _WR=1; 00235 } 00236 // ILI932x specific 00237 unsigned short BUS8::reg_read(unsigned char reg) 00238 { 00239 unsigned short r=0; 00240 _DC = 0; 00241 _bus.write(0); 00242 _WR=0; 00243 _WR=1; 00244 _bus.write(reg); 00245 _WR=0; 00246 _WR=1; 00247 _DC = 1; 00248 _bus.input(); 00249 _RD=0; 00250 r |= _bus.read(); // read 8bit 00251 _RD=1; 00252 r <<= 8; 00253 _RD=0; 00254 r |= _bus.read(); // read 8bit 00255 _RD=1; 00256 _bus.output(); 00257 00258 return r; 00259 } 00260 void BUS8::hw_reset() 00261 { 00262 wait_ms(15); 00263 _DC = 1; 00264 _CS = 1; 00265 _WR = 1; 00266 _RD = 1; 00267 _reset = 0; // display reset 00268 wait_ms(2); 00269 _reset = 1; // end reset 00270 wait_ms(100); 00271 } 00272 void BUS8::BusEnable(bool enable) 00273 { 00274 _CS = enable ? 0:1; 00275 }
Generated on Wed Jul 13 2022 21:19:22 by 1.7.2