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