Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Bicycl_Computer_NUCLEO-F411RE Bicycl_Computer_NUCLEO-L476RG
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 00019 #include "PAR8.h" 00020 00021 PAR8::PAR8(PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD) 00022 : _port(port,0xFF), _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 #ifdef STMPORTDEBUG 00030 findport(port); //on return, GPIO get disabled 00031 #endif 00032 _port.mode(PullNone); 00033 _port.output(); // will re-enable our GPIO port 00034 hw_reset(); 00035 } 00036 00037 #ifdef STMPORTDEBUG 00038 // create a port obj with STM HAL drivers, just to collect memorymapped regs 00039 void PAR8::findport(PortName port) 00040 { 00041 port_t tempport; 00042 port_init(&tempport, port, 0xFF, PIN_INPUT); 00043 outreg = tempport.reg_out; 00044 inreg = tempport.reg_in; 00045 // debug("out 0x%.8X in 0x%.8X\r\n", outreg, inreg); 00046 } 00047 #endif 00048 void PAR8::wr_cmd8(unsigned char cmd) 00049 { 00050 #ifdef USE_CS 00051 _CS = 0; 00052 #endif 00053 _DC = 0; // 0=cmd 00054 _WR=0; 00055 _port.write(cmd); // write 8bit 00056 _WR=1; 00057 #ifdef USE_CS 00058 _CS = 1; 00059 #endif 00060 } 00061 void PAR8::wr_data8(unsigned char data) 00062 { 00063 #ifdef USE_CS 00064 _CS = 0; 00065 #endif 00066 _DC = 1; // 1=data 00067 _WR=0; 00068 _port.write(data); // write 8bit 00069 _WR=1; 00070 #ifdef USE_CS 00071 _CS = 1; 00072 #endif 00073 } 00074 void PAR8::wr_cmd16(unsigned short cmd) 00075 { 00076 #ifdef USE_CS 00077 _CS = 0; 00078 #endif 00079 _DC = 0; // 0=cmd 00080 _WR=0; 00081 _port.write(cmd>>8); // write 8bit 00082 _WR=1; 00083 _WR=0; 00084 _port.write(cmd&0xFF); // write 8bit 00085 _WR=1; 00086 #ifdef USE_CS 00087 _CS = 1; 00088 #endif 00089 } 00090 void PAR8::wr_data16(unsigned short data) 00091 { 00092 #ifdef USE_CS 00093 _CS = 0; 00094 #endif 00095 _DC = 1; // 1=data 00096 _WR=0; 00097 _port.write(data>>8); // write 8bit 00098 _WR=1; 00099 _WR=0; 00100 _port.write(data&0xFF); // write 8bit 00101 _WR=1; 00102 #ifdef USE_CS 00103 _CS = 1; 00104 #endif 00105 } 00106 void PAR8::wr_gram(unsigned short data) 00107 { 00108 #ifdef USE_CS 00109 _CS = 0; 00110 #endif 00111 _DC = 1; // 1=data 00112 _WR=0; 00113 _port.write(data>>8); // write 8bit 00114 _WR=1; 00115 _WR=0; 00116 _port.write(data&0xFF); // write 8bit 00117 _WR=1; 00118 #ifdef USE_CS 00119 _CS = 1; 00120 #endif 00121 } 00122 void PAR8::wr_gram(unsigned short data, unsigned int count) 00123 { 00124 #ifdef USE_CS 00125 _CS = 0; 00126 #endif 00127 _DC = 1; // 1=data 00128 if((data>>8)==(data&0xFF)) 00129 { 00130 count<<=1; 00131 _port.write(data); // write 8bit 00132 while(count) 00133 { 00134 _WR=0; 00135 _WR=1; 00136 count--; 00137 } 00138 } 00139 else 00140 { 00141 while(count) 00142 { 00143 _WR=0; 00144 _port.write(data>>8); // write 8bit 00145 _WR=1; 00146 _WR=0; 00147 _port.write(data&0xFF); // write 8bit 00148 _WR=1; 00149 count--; 00150 } 00151 } 00152 #ifdef USE_CS 00153 _CS = 1; 00154 #endif 00155 } 00156 void PAR8::wr_grambuf(unsigned short* data, unsigned int lenght) 00157 { 00158 #ifdef USE_CS 00159 _CS = 0; 00160 #endif 00161 _DC = 1; // 1=data 00162 while(lenght) 00163 { 00164 _WR=0; 00165 _port.write((*data)>>8); // write 8bit 00166 _WR=1; 00167 _WR=0; 00168 _port.write((*data)&0xFF); // write 8bit 00169 _WR=1; 00170 data++; 00171 lenght--; 00172 } 00173 #ifdef USE_CS 00174 _CS = 1; 00175 #endif 00176 } 00177 unsigned short PAR8::rd_gram(bool convert) 00178 { 00179 #ifdef USE_CS 00180 _CS = 0; 00181 #endif 00182 unsigned int r=0; 00183 _DC = 1; // 1=data 00184 _port.input(); 00185 00186 _RD = 0; 00187 _port.read(); //dummy read 00188 _RD = 1; 00189 00190 _RD = 0; 00191 // _RD = 0; // add wait 00192 r |= (_port.read()&0xFF); 00193 r <<= 8; 00194 _RD = 1; 00195 00196 _RD = 0; 00197 // _RD = 0; // add wait 00198 r |= (_port.read()&0xFF); 00199 _RD = 1; 00200 if(convert) 00201 { 00202 r <<= 8; 00203 _RD = 0; 00204 // _RD = 0; // add wait 00205 r |= _port.read(); 00206 _RD = 1; 00207 // gram is 18bit/pixel, if you set 16bit/pixel (cmd 3A), during writing the 16bits are expanded to 18bit 00208 // during reading, you read the raw 18bit gram 00209 r = RGB24to16((r&0xFF0000)>>16, (r&0xFF00)>>8, r&0xFF);// 18bit pixel padded to 24bits, rrrrrr00_gggggg00_bbbbbb00, converted to 16bit 00210 } 00211 #ifdef USE_CS 00212 _CS = 1; 00213 #endif 00214 _port.output(); 00215 return (unsigned short)r; 00216 } 00217 unsigned int PAR8::rd_reg_data32(unsigned char reg) 00218 { 00219 #ifdef USE_CS 00220 _CS = 0; 00221 #endif 00222 wr_cmd8(reg); 00223 unsigned int r=0; 00224 _DC = 1; // 1=data 00225 _port.input(); 00226 00227 _RD = 0; 00228 _port.read(); //dummy read 00229 _RD = 1; 00230 00231 _RD = 0; 00232 // _RD = 0; // add wait 00233 r |= (_port.read()&0xFF); 00234 r <<= 8; 00235 _RD = 1; 00236 00237 _RD = 0; 00238 // _RD = 0; // add wait 00239 r |= (_port.read()&0xFF); 00240 r <<= 8; 00241 _RD = 1; 00242 00243 _RD = 0; 00244 // _RD = 0; // add wait 00245 r |= (_port.read()&0xFF); 00246 r <<= 8; 00247 _RD = 1; 00248 00249 _RD = 0; 00250 // _RD = 0; // add wait 00251 r |= (_port.read()&0xFF); 00252 _RD = 1; 00253 00254 _CS = 1; // force CS HIG to interupt the cmd in case was not supported 00255 #ifndef USE_CS //if CS is not used, force fixed LOW again 00256 _CS = 0; 00257 #endif 00258 _port.output(); 00259 return r; 00260 } 00261 // in Par mode EXTC regs (0xB0-0xFF) can be directly read 00262 unsigned int PAR8::rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd) 00263 { 00264 return rd_reg_data32(reg); 00265 } 00266 void PAR8::hw_reset() 00267 { 00268 wait_ms(15); 00269 _DC = 1; 00270 _CS = 1; 00271 _WR = 1; 00272 _RD = 1; 00273 _reset = 0; // display reset 00274 wait_us(50); 00275 _reset = 1; // end reset 00276 wait_ms(15); 00277 #ifndef USE_CS 00278 _CS=0; // put CS low now and forever 00279 #endif 00280 } 00281 void PAR8::BusEnable(bool enable) 00282 { 00283 _CS = enable ? 0:1; 00284 }
Generated on Wed Jul 13 2022 20:11:30 by
1.7.2
