.
Diff: Protocols/PAR8.cpp
- Revision:
- 20:14daa48ffd4c
- Parent:
- 11:b842b8e332cb
- Child:
- 25:daacdcf34e52
--- a/Protocols/PAR8.cpp Mon Mar 02 10:52:26 2015 +0000 +++ b/Protocols/PAR8.cpp Mon Mar 23 14:08:04 2015 +0000 @@ -26,111 +26,63 @@ _WR=1; _RD=1; _CS=1; -#ifdef STMPORTDEBUG - findport(port); //on return, GPIO get disabled -#endif _port.mode(PullNone); _port.output(); // will re-enable our GPIO port hw_reset(); } -#ifdef STMPORTDEBUG -// create a port obj with STM HAL drivers, just to collect memorymapped regs -void PAR8::findport(PortName port) -{ - port_t tempport; - port_init(&tempport, port, 0xFF, PIN_INPUT); - outreg = tempport.reg_out; - inreg = tempport.reg_in; - // debug("out 0x%.8X in 0x%.8X\r\n", outreg, inreg); -} -#endif void PAR8::wr_cmd8(unsigned char cmd) -{ -#ifdef USE_CS - _CS = 0; -#endif +{ _DC = 0; // 0=cmd + _port.write(cmd); // write 8bit _WR=0; - _port.write(cmd); // write 8bit _WR=1; -#ifdef USE_CS - _CS = 1; -#endif + _DC = 1; // 1=data next } void PAR8::wr_data8(unsigned char data) { -#ifdef USE_CS - _CS = 0; -#endif - _DC = 1; // 1=data + _port.write(data); // write 8bit _WR=0; - _port.write(data); // write 8bit _WR=1; -#ifdef USE_CS - _CS = 1; -#endif } void PAR8::wr_cmd16(unsigned short cmd) -{ -#ifdef USE_CS - _CS = 0; -#endif +{ _DC = 0; // 0=cmd - _WR=0; _port.write(cmd>>8); // write 8bit - _WR=1; _WR=0; - _port.write(cmd&0xFF); // write 8bit _WR=1; -#ifdef USE_CS - _CS = 1; -#endif + _port.write(cmd&0xFF); // write 8bit + _WR=0; + _WR=1; + _DC = 1; // 1=data next } void PAR8::wr_data16(unsigned short data) { -#ifdef USE_CS - _CS = 0; -#endif - _DC = 1; // 1=data + _port.write(data>>8); // write 8bit _WR=0; - _port.write(data>>8); // write 8bit _WR=1; + _port.write(data&0xFF); // write 8bit _WR=0; - _port.write(data&0xFF); // write 8bit _WR=1; -#ifdef USE_CS - _CS = 1; -#endif } void PAR8::wr_gram(unsigned short data) { -#ifdef USE_CS - _CS = 0; -#endif - _DC = 1; // 1=data + _port.write(data>>8); // write 8bit _WR=0; - _port.write(data>>8); // write 8bit _WR=1; + _port.write(data&0xFF); // write 8bit _WR=0; - _port.write(data&0xFF); // write 8bit _WR=1; -#ifdef USE_CS - _CS = 1; -#endif } void PAR8::wr_gram(unsigned short data, unsigned int count) { -#ifdef USE_CS - _CS = 0; -#endif - _DC = 1; // 1=data if((data>>8)==(data&0xFF)) { count<<=1; - _port.write(data); // write 8bit + // _port.write(data); // write 8bit while(count) { + _port.write(data); // rewrite even if same data, otherwise too much fast _WR=0; _WR=1; count--; @@ -140,62 +92,49 @@ { while(count) { + _port.write(data>>8); // write 8bit _WR=0; - _port.write(data>>8); // write 8bit _WR=1; + _port.write(data&0xFF); // write 8bit _WR=0; - _port.write(data&0xFF); // write 8bit _WR=1; count--; } } -#ifdef USE_CS - _CS = 1; -#endif } void PAR8::wr_grambuf(unsigned short* data, unsigned int lenght) { -#ifdef USE_CS - _CS = 0; -#endif - _DC = 1; // 1=data while(lenght) { + _port.write((*data)>>8); // write 8bit _WR=0; - _port.write((*data)>>8); // write 8bit _WR=1; + _port.write((*data)&0xFF); // write 8bit _WR=0; - _port.write((*data)&0xFF); // write 8bit _WR=1; data++; lenght--; } -#ifdef USE_CS - _CS = 1; -#endif } unsigned short PAR8::rd_gram(bool convert) { -#ifdef USE_CS - _CS = 0; -#endif unsigned int r=0; - _DC = 1; // 1=data _port.input(); _RD = 0; + _RD = 0; // add wait _port.read(); //dummy read _RD = 1; _RD = 0; -// _RD = 0; // add wait - r |= (_port.read()&0xFF); + _RD = 0; // add wait + r |= _port.read(); + _RD = 1; r <<= 8; - _RD = 1; _RD = 0; -// _RD = 0; // add wait - r |= (_port.read()&0xFF); + _RD = 0; // add wait + r |= _port.read(); _RD = 1; if(convert) { @@ -208,20 +147,13 @@ // during reading, you read the raw 18bit gram r = RGB24to16((r&0xFF0000)>>16, (r&0xFF00)>>8, r&0xFF);// 18bit pixel padded to 24bits, rrrrrr00_gggggg00_bbbbbb00, converted to 16bit } -#ifdef USE_CS - _CS = 1; -#endif _port.output(); return (unsigned short)r; } unsigned int PAR8::rd_reg_data32(unsigned char reg) { -#ifdef USE_CS - _CS = 0; -#endif wr_cmd8(reg); unsigned int r=0; - _DC = 1; // 1=data _port.input(); _RD = 0; @@ -252,9 +184,7 @@ _RD = 1; _CS = 1; // force CS HIG to interupt the cmd in case was not supported -#ifndef USE_CS //if CS is not used, force fixed LOW again _CS = 0; -#endif _port.output(); return r; } @@ -263,6 +193,70 @@ { return rd_reg_data32(reg); } +// ILI932x specific +void PAR8::dummyread() +{ + _port.input(); + _RD=0; + _RD=0; // add wait + _port.read(); // dummy read + _RD=1; + // _port.output(); +} +// ILI932x specific +void PAR8::reg_select(unsigned char reg, bool forread) +{ + _DC = 0; + _port.write(0); // write MSB + _WR=0; + _WR=1; + _port.write(reg); // write LSB + _WR=0; + _WR=1; + _DC = 1; // 1=data next +} +// ILI932x specific +void PAR8::reg_write(unsigned char reg, unsigned short data) +{ + _DC = 0; + _port.write(0); // write MSB + _WR=0; + _WR=1; + _port.write(reg); // write MSB + _WR=0; + _WR=1; + _DC = 1; + _port.write(data>>8); + _WR=0; + _WR=1; + _port.write(data&0xFF); + _WR=0; + _WR=1; +} +// ILI932x specific +unsigned short PAR8::reg_read(unsigned char reg) +{ + unsigned short r=0; + _DC = 0; + _port.write(0); + _WR=0; + _WR=1; + _port.write(reg); + _WR=0; + _WR=1; + _DC = 1; + _port.input(); + _RD=0; + r |= _port.read(); // read 8bit + _RD=1; + r <<= 8; + _RD=0; + r |= _port.read(); // read 8bit + _RD=1; + _port.output(); + + return r; +} void PAR8::hw_reset() { wait_ms(15); @@ -271,12 +265,9 @@ _WR = 1; _RD = 1; _reset = 0; // display reset - wait_us(50); + wait_ms(2); _reset = 1; // end reset - wait_ms(15); -#ifndef USE_CS - _CS=0; // put CS low now and forever -#endif + wait_ms(100); } void PAR8::BusEnable(bool enable) {