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: afero_poc15_180216 afero_poc15_180223 afero_poc15_180302 afero_poc15_180403R ... more
Fork of UniGraphic by
UniGraphic for La Suno Version.
To go with La Suno, WatchDog Reset functions were added in ILI9341.
Protocols/PAR8.cpp@1:ff019d22b275, 2015-02-13 (annotated)
- Committer:
- Geremia
- Date:
- Fri Feb 13 15:25:10 2015 +0000
- Revision:
- 1:ff019d22b275
- Parent:
- 0:75ec1b3cde17
- Child:
- 4:12ba0ecc2c1f
Added SPI_16, LCD done
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Geremia | 0:75ec1b3cde17 | 1 | #include "PAR8.h" |
Geremia | 0:75ec1b3cde17 | 2 | |
Geremia | 0:75ec1b3cde17 | 3 | PAR8::PAR8(PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD) |
Geremia | 0:75ec1b3cde17 | 4 | : _port(port,0xFF), _CS(CS), _reset(reset), _DC(DC), _WR(WR), _RD(RD) |
Geremia | 0:75ec1b3cde17 | 5 | { |
Geremia | 0:75ec1b3cde17 | 6 | _reset = 1; |
Geremia | 0:75ec1b3cde17 | 7 | _DC=1; |
Geremia | 0:75ec1b3cde17 | 8 | _WR=1; |
Geremia | 0:75ec1b3cde17 | 9 | _RD=1; |
Geremia | 0:75ec1b3cde17 | 10 | _CS=1; |
Geremia | 0:75ec1b3cde17 | 11 | #ifdef STMPORTDEBUG |
Geremia | 0:75ec1b3cde17 | 12 | findport(port); //on return, GPIO get disabled |
Geremia | 0:75ec1b3cde17 | 13 | #endif |
Geremia | 0:75ec1b3cde17 | 14 | _port.mode(PullNone); |
Geremia | 0:75ec1b3cde17 | 15 | _port.output(); // will re-enable our GPIO port |
Geremia | 0:75ec1b3cde17 | 16 | hw_reset(); |
Geremia | 0:75ec1b3cde17 | 17 | } |
Geremia | 0:75ec1b3cde17 | 18 | |
Geremia | 0:75ec1b3cde17 | 19 | #ifdef STMPORTDEBUG |
Geremia | 0:75ec1b3cde17 | 20 | // create a port obj with STM HAL drivers, just to collect memorymapped regs |
Geremia | 0:75ec1b3cde17 | 21 | void PAR8::findport(PortName port) |
Geremia | 0:75ec1b3cde17 | 22 | { |
Geremia | 0:75ec1b3cde17 | 23 | port_t tempport; |
Geremia | 0:75ec1b3cde17 | 24 | port_init(&tempport, port, 0xFF, PIN_INPUT); |
Geremia | 0:75ec1b3cde17 | 25 | outreg = tempport.reg_out; |
Geremia | 0:75ec1b3cde17 | 26 | inreg = tempport.reg_in; |
Geremia | 0:75ec1b3cde17 | 27 | // debug("out 0x%.8X in 0x%.8X\r\n", outreg, inreg); |
Geremia | 0:75ec1b3cde17 | 28 | } |
Geremia | 0:75ec1b3cde17 | 29 | #endif |
Geremia | 1:ff019d22b275 | 30 | void PAR8::wr_cmd8(unsigned char cmd) |
Geremia | 0:75ec1b3cde17 | 31 | { |
Geremia | 0:75ec1b3cde17 | 32 | #ifdef USE_CS |
Geremia | 0:75ec1b3cde17 | 33 | _CS = 0; |
Geremia | 0:75ec1b3cde17 | 34 | #endif |
Geremia | 0:75ec1b3cde17 | 35 | _DC = 0; // 0=cmd |
Geremia | 0:75ec1b3cde17 | 36 | _WR=0; |
Geremia | 0:75ec1b3cde17 | 37 | _port.write(cmd); // write 8bit |
Geremia | 0:75ec1b3cde17 | 38 | _WR=1; |
Geremia | 0:75ec1b3cde17 | 39 | #ifdef USE_CS |
Geremia | 0:75ec1b3cde17 | 40 | _CS = 1; |
Geremia | 0:75ec1b3cde17 | 41 | #endif |
Geremia | 0:75ec1b3cde17 | 42 | } |
Geremia | 1:ff019d22b275 | 43 | void PAR8::wr_data8(unsigned char data) |
Geremia | 0:75ec1b3cde17 | 44 | { |
Geremia | 0:75ec1b3cde17 | 45 | #ifdef USE_CS |
Geremia | 0:75ec1b3cde17 | 46 | _CS = 0; |
Geremia | 0:75ec1b3cde17 | 47 | #endif |
Geremia | 0:75ec1b3cde17 | 48 | _DC = 1; // 1=data |
Geremia | 0:75ec1b3cde17 | 49 | _WR=0; |
Geremia | 1:ff019d22b275 | 50 | _port.write(data); // write 8bit |
Geremia | 0:75ec1b3cde17 | 51 | _WR=1; |
Geremia | 0:75ec1b3cde17 | 52 | #ifdef USE_CS |
Geremia | 0:75ec1b3cde17 | 53 | _CS = 1; |
Geremia | 0:75ec1b3cde17 | 54 | #endif |
Geremia | 0:75ec1b3cde17 | 55 | } |
Geremia | 1:ff019d22b275 | 56 | void PAR8::wr_data8(unsigned char data, unsigned int count) |
Geremia | 0:75ec1b3cde17 | 57 | { |
Geremia | 0:75ec1b3cde17 | 58 | #ifdef USE_CS |
Geremia | 0:75ec1b3cde17 | 59 | _CS = 0; |
Geremia | 0:75ec1b3cde17 | 60 | #endif |
Geremia | 0:75ec1b3cde17 | 61 | _DC = 1; // 1=data |
Geremia | 1:ff019d22b275 | 62 | _port.write(data); // write 8bit |
Geremia | 0:75ec1b3cde17 | 63 | while(count) |
Geremia | 0:75ec1b3cde17 | 64 | { |
Geremia | 0:75ec1b3cde17 | 65 | _WR=0; |
Geremia | 0:75ec1b3cde17 | 66 | // _WR=0; |
Geremia | 0:75ec1b3cde17 | 67 | _WR=1; |
Geremia | 0:75ec1b3cde17 | 68 | count--; |
Geremia | 0:75ec1b3cde17 | 69 | } |
Geremia | 0:75ec1b3cde17 | 70 | #ifdef USE_CS |
Geremia | 0:75ec1b3cde17 | 71 | _CS = 1; |
Geremia | 0:75ec1b3cde17 | 72 | #endif |
Geremia | 0:75ec1b3cde17 | 73 | } |
Geremia | 1:ff019d22b275 | 74 | void PAR8::wr_data8buf(unsigned char* data, unsigned int lenght) |
Geremia | 0:75ec1b3cde17 | 75 | { |
Geremia | 0:75ec1b3cde17 | 76 | #ifdef USE_CS |
Geremia | 0:75ec1b3cde17 | 77 | _CS = 0; |
Geremia | 0:75ec1b3cde17 | 78 | #endif |
Geremia | 0:75ec1b3cde17 | 79 | _DC = 1; // 1=data |
Geremia | 0:75ec1b3cde17 | 80 | while(lenght) |
Geremia | 0:75ec1b3cde17 | 81 | { |
Geremia | 0:75ec1b3cde17 | 82 | _WR=0; |
Geremia | 1:ff019d22b275 | 83 | _port.write(*data++); // write 8bit |
Geremia | 0:75ec1b3cde17 | 84 | _WR=1; |
Geremia | 0:75ec1b3cde17 | 85 | lenght--; |
Geremia | 0:75ec1b3cde17 | 86 | } |
Geremia | 0:75ec1b3cde17 | 87 | #ifdef USE_CS |
Geremia | 0:75ec1b3cde17 | 88 | _CS = 1; |
Geremia | 0:75ec1b3cde17 | 89 | #endif |
Geremia | 0:75ec1b3cde17 | 90 | } |
Geremia | 1:ff019d22b275 | 91 | void PAR8::wr_cmd16(unsigned short cmd) |
Geremia | 1:ff019d22b275 | 92 | { |
Geremia | 1:ff019d22b275 | 93 | #ifdef USE_CS |
Geremia | 1:ff019d22b275 | 94 | _CS = 0; |
Geremia | 1:ff019d22b275 | 95 | #endif |
Geremia | 1:ff019d22b275 | 96 | _DC = 0; // 0=cmd |
Geremia | 1:ff019d22b275 | 97 | _WR=0; |
Geremia | 1:ff019d22b275 | 98 | _port.write(cmd>>8); // write 8bit |
Geremia | 1:ff019d22b275 | 99 | _WR=1; |
Geremia | 1:ff019d22b275 | 100 | _WR=0; |
Geremia | 1:ff019d22b275 | 101 | _port.write(cmd&0xFF); // write 8bit |
Geremia | 1:ff019d22b275 | 102 | _WR=1; |
Geremia | 1:ff019d22b275 | 103 | #ifdef USE_CS |
Geremia | 1:ff019d22b275 | 104 | _CS = 1; |
Geremia | 1:ff019d22b275 | 105 | #endif |
Geremia | 1:ff019d22b275 | 106 | } |
Geremia | 1:ff019d22b275 | 107 | void PAR8::wr_data16(unsigned short data) |
Geremia | 1:ff019d22b275 | 108 | { |
Geremia | 1:ff019d22b275 | 109 | #ifdef USE_CS |
Geremia | 1:ff019d22b275 | 110 | _CS = 0; |
Geremia | 1:ff019d22b275 | 111 | #endif |
Geremia | 1:ff019d22b275 | 112 | _DC = 1; // 1=data |
Geremia | 1:ff019d22b275 | 113 | _WR=0; |
Geremia | 1:ff019d22b275 | 114 | _port.write(data>>8); // write 8bit |
Geremia | 1:ff019d22b275 | 115 | _WR=1; |
Geremia | 1:ff019d22b275 | 116 | _WR=0; |
Geremia | 1:ff019d22b275 | 117 | _port.write(data&0xFF); // write 8bit |
Geremia | 1:ff019d22b275 | 118 | _WR=1; |
Geremia | 1:ff019d22b275 | 119 | #ifdef USE_CS |
Geremia | 1:ff019d22b275 | 120 | _CS = 1; |
Geremia | 1:ff019d22b275 | 121 | #endif |
Geremia | 1:ff019d22b275 | 122 | } |
Geremia | 1:ff019d22b275 | 123 | void PAR8::wr_data16(unsigned short data, unsigned int count) |
Geremia | 1:ff019d22b275 | 124 | { |
Geremia | 1:ff019d22b275 | 125 | #ifdef USE_CS |
Geremia | 1:ff019d22b275 | 126 | _CS = 0; |
Geremia | 1:ff019d22b275 | 127 | #endif |
Geremia | 1:ff019d22b275 | 128 | _DC = 1; // 1=data |
Geremia | 1:ff019d22b275 | 129 | if((data>>8)==(data&0xFF)) |
Geremia | 1:ff019d22b275 | 130 | { |
Geremia | 1:ff019d22b275 | 131 | count<<=1; |
Geremia | 1:ff019d22b275 | 132 | _port.write(data); // write 8bit |
Geremia | 1:ff019d22b275 | 133 | while(count) |
Geremia | 1:ff019d22b275 | 134 | { |
Geremia | 1:ff019d22b275 | 135 | _WR=0; |
Geremia | 1:ff019d22b275 | 136 | _WR=1; |
Geremia | 1:ff019d22b275 | 137 | count--; |
Geremia | 1:ff019d22b275 | 138 | } |
Geremia | 1:ff019d22b275 | 139 | } |
Geremia | 1:ff019d22b275 | 140 | else |
Geremia | 1:ff019d22b275 | 141 | { |
Geremia | 1:ff019d22b275 | 142 | while(count) |
Geremia | 1:ff019d22b275 | 143 | { |
Geremia | 1:ff019d22b275 | 144 | _WR=0; |
Geremia | 1:ff019d22b275 | 145 | _port.write(data>>8); // write 8bit |
Geremia | 1:ff019d22b275 | 146 | _WR=1; |
Geremia | 1:ff019d22b275 | 147 | _WR=0; |
Geremia | 1:ff019d22b275 | 148 | _port.write(data&0xFF); // write 8bit |
Geremia | 1:ff019d22b275 | 149 | _WR=1; |
Geremia | 1:ff019d22b275 | 150 | count--; |
Geremia | 1:ff019d22b275 | 151 | } |
Geremia | 1:ff019d22b275 | 152 | } |
Geremia | 1:ff019d22b275 | 153 | #ifdef USE_CS |
Geremia | 1:ff019d22b275 | 154 | _CS = 1; |
Geremia | 1:ff019d22b275 | 155 | #endif |
Geremia | 1:ff019d22b275 | 156 | } |
Geremia | 1:ff019d22b275 | 157 | void PAR8::wr_data16buf(unsigned short* data, unsigned int lenght) |
Geremia | 1:ff019d22b275 | 158 | { |
Geremia | 1:ff019d22b275 | 159 | #ifdef USE_CS |
Geremia | 1:ff019d22b275 | 160 | _CS = 0; |
Geremia | 1:ff019d22b275 | 161 | #endif |
Geremia | 1:ff019d22b275 | 162 | _DC = 1; // 1=data |
Geremia | 1:ff019d22b275 | 163 | while(lenght) |
Geremia | 1:ff019d22b275 | 164 | { |
Geremia | 1:ff019d22b275 | 165 | _WR=0; |
Geremia | 1:ff019d22b275 | 166 | _port.write((*data)>>8); // write 8bit |
Geremia | 1:ff019d22b275 | 167 | _WR=1; |
Geremia | 1:ff019d22b275 | 168 | _WR=0; |
Geremia | 1:ff019d22b275 | 169 | _port.write((*data)&0xFF); // write 8bit |
Geremia | 1:ff019d22b275 | 170 | _WR=1; |
Geremia | 1:ff019d22b275 | 171 | data++; |
Geremia | 1:ff019d22b275 | 172 | lenght--; |
Geremia | 1:ff019d22b275 | 173 | } |
Geremia | 1:ff019d22b275 | 174 | #ifdef USE_CS |
Geremia | 1:ff019d22b275 | 175 | _CS = 1; |
Geremia | 1:ff019d22b275 | 176 | #endif |
Geremia | 1:ff019d22b275 | 177 | } |
Geremia | 0:75ec1b3cde17 | 178 | void PAR8::hw_reset() |
Geremia | 0:75ec1b3cde17 | 179 | { |
Geremia | 0:75ec1b3cde17 | 180 | wait_ms(15); |
Geremia | 0:75ec1b3cde17 | 181 | _DC = 1; |
Geremia | 0:75ec1b3cde17 | 182 | _CS = 1; |
Geremia | 0:75ec1b3cde17 | 183 | _WR = 1; |
Geremia | 0:75ec1b3cde17 | 184 | _RD = 1; |
Geremia | 0:75ec1b3cde17 | 185 | _reset = 0; // display reset |
Geremia | 0:75ec1b3cde17 | 186 | wait_us(50); |
Geremia | 0:75ec1b3cde17 | 187 | _reset = 1; // end reset |
Geremia | 0:75ec1b3cde17 | 188 | wait_ms(15); |
Geremia | 0:75ec1b3cde17 | 189 | #ifndef USE_CS |
Geremia | 0:75ec1b3cde17 | 190 | _CS=0; // put CS low now and forever |
Geremia | 0:75ec1b3cde17 | 191 | #endif |
Geremia | 0:75ec1b3cde17 | 192 | } |
Geremia | 0:75ec1b3cde17 | 193 | void PAR8::BusEnable(bool enable) |
Geremia | 0:75ec1b3cde17 | 194 | { |
Geremia | 0:75ec1b3cde17 | 195 | _CS = enable ? 0:1; |
Geremia | 0:75ec1b3cde17 | 196 | } |