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