for 522 mbed basic operate
Revision 15:70127e08ed27, committed 2019-12-21
- Comitter:
- UlricL
- Date:
- Sat Dec 21 06:43:26 2019 +0000
- Parent:
- 14:2db7065edbec
- Commit message:
- 522
Changed in this revision
diff -r 2db7065edbec -r 70127e08ed27 DmTftHX8353C.cpp --- a/DmTftHX8353C.cpp Mon Oct 12 08:35:35 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,251 +0,0 @@ -/********************************************************************************************** - Copyright (c) 2014 DisplayModule. All rights reserved. - - Redistribution and use of this source code, part of this source code or any compiled binary - based on this source code is permitted as long as the above copyright notice and following - disclaimer is retained. - - DISCLAIMER: - THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES - NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. - ********************************************************************************************/ - - //Tested on NUCLEO-F401RE, LPCXpresso11U68 platform. - -#include "DmTftHX8353C.h" -#if defined (DM_TOOLCHAIN_ARDUINO) -DmTftHX8353C::DmTftHX8353C(uint8_t mosi, uint8_t clk, uint8_t cs, uint8_t dc, uint8_t rst) : DmTftBase(128,160) -#elif defined (DM_TOOLCHAIN_MBED) -DmTftHX8353C::DmTftHX8353C(PinName mosi, PinName clk, PinName cs, PinName dc, PinName rst) : DmTftBase(128,160) -#endif -{ - _mosi = mosi; - _clk = clk; - _cs = cs; - _dc = dc; - _rst = rst; -} - -DmTftHX8353C::~DmTftHX8353C() { -#if defined (DM_TOOLCHAIN_MBED) - delete _pinMOSI; - delete _pinCLK; - delete _pinCS; - delete _pinDC; - delete _pinRST; - - _pinMOSI = NULL; - _pinCLK = NULL; - _pinCS = NULL; - _pinDC = NULL; - _pinRST = NULL; -#endif -} - -void DmTftHX8353C::writeBus(uint8_t data) { - if (data & 0x80) { - sbi(_pinMOSI, _bitmaskMOSI); - } - else { - cbi(_pinMOSI, _bitmaskMOSI); - } - pulse_low(_pinCLK, _bitmaskCLK); - - if (data & 0x40) { - sbi(_pinMOSI, _bitmaskMOSI); - } - else { - cbi(_pinMOSI, _bitmaskMOSI); - } - pulse_low(_pinCLK, _bitmaskCLK); - - if (data & 0x20) { - sbi(_pinMOSI, _bitmaskMOSI); - } - else { - cbi(_pinMOSI, _bitmaskMOSI); - } - pulse_low(_pinCLK, _bitmaskCLK); - - if (data & 0x10) { - sbi(_pinMOSI, _bitmaskMOSI); - } - else { - cbi(_pinMOSI, _bitmaskMOSI); - } - pulse_low(_pinCLK, _bitmaskCLK); - - if (data & 0x08) { - sbi(_pinMOSI, _bitmaskMOSI); - } - else { - cbi(_pinMOSI, _bitmaskMOSI); - } - pulse_low(_pinCLK, _bitmaskCLK); - - if (data & 0x04) { - sbi(_pinMOSI, _bitmaskMOSI); - } - else { - cbi(_pinMOSI, _bitmaskMOSI); - } - pulse_low(_pinCLK, _bitmaskCLK); - - if (data & 0x02) { - sbi(_pinMOSI, _bitmaskMOSI); - } - else { - cbi(_pinMOSI, _bitmaskMOSI); - } - pulse_low(_pinCLK, _bitmaskCLK); - - if (data & 0x01) { - sbi(_pinMOSI, _bitmaskMOSI); - } - else { - cbi(_pinMOSI, _bitmaskMOSI); - } - pulse_low(_pinCLK, _bitmaskCLK); -} - -void DmTftHX8353C::sendCommand(uint8_t index) { - cbi(_pinDC, _bitmaskDC); - writeBus(index); -} - -void DmTftHX8353C::send8BitData(uint8_t data) { - sbi(_pinDC, _bitmaskDC); - writeBus(data); -} - -void DmTftHX8353C::sendData(uint16_t data) { - sbi(_pinDC, _bitmaskDC); - writeBus(data>>8); - writeBus(data); -} - -void DmTftHX8353C::setAddress(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { - sendCommand(0x2A); // SetColumn - sendData(x0); - sendData(x1); - sendCommand(0x2B); // SetPage - sendData(y0); - sendData(y1); - - sendCommand(0x2c); -} - - -void DmTftHX8353C::init (void) { - setTextColor(BLACK, WHITE); -#if defined (DM_TOOLCHAIN_ARDUINO) - _pinMOSI= portOutputRegister(digitalPinToPort(_mosi)); - _bitmaskMOSI= digitalPinToBitMask(_mosi); - _pinCLK= portOutputRegister(digitalPinToPort(_clk)); - _bitmaskCLK= digitalPinToBitMask(_clk); - _pinCS = portOutputRegister(digitalPinToPort(_cs)); - _bitmaskCS = digitalPinToBitMask(_cs); - _pinDC = portOutputRegister(digitalPinToPort(_dc)); - _bitmaskDC = digitalPinToBitMask(_dc); - _pinRST = portOutputRegister(digitalPinToPort(_rst)); - _bitmaskRST = digitalPinToBitMask(_rst); - - pinMode(_mosi,OUTPUT); - pinMode(_clk,OUTPUT); - pinMode(_cs,OUTPUT); - pinMode(_dc,OUTPUT); - pinMode(_rst,OUTPUT); -#elif defined (DM_TOOLCHAIN_MBED) - _pinMOSI = new DigitalOut(_mosi); - _pinCLK = new DigitalOut(_clk); - _pinCS = new DigitalOut(_cs); - _pinDC = new DigitalOut(_dc); - _pinRST = new DigitalOut(_rst); -#endif - - sbi(_pinRST, _bitmaskRST); - delay(5); - cbi(_pinRST, _bitmaskRST); - delay(15); - sbi(_pinRST, _bitmaskRST); - delay(15); - cbi(_pinCS, _bitmaskCS); - - sendCommand(0xB9); // HX8353C INIT - send8BitData(0xFF); - send8BitData(0x83); - send8BitData(0x53); - - sendCommand(0xB0); - send8BitData(0x3C); - send8BitData(0X01); - - sendCommand(0xB6); - send8BitData(0x94); - send8BitData(0x6C); - send8BitData(0x50); - - sendCommand(0xB1); - send8BitData(0x00); - send8BitData(0x01); - send8BitData(0x1B); - send8BitData(0x03); - send8BitData(0X01); - send8BitData(0X08); - send8BitData(0x77); - send8BitData(0x89); - - sendCommand(0xE0); - send8BitData(0x50); - send8BitData(0x77); - send8BitData(0X40); - send8BitData(0X08); - send8BitData(0xBE); - send8BitData(0x00); - send8BitData(0x03); - send8BitData(0x0F); - send8BitData(0x00); - send8BitData(0x01); - send8BitData(0x73); - send8BitData(0x00); - send8BitData(0x72); - send8BitData(0x03); - send8BitData(0xB0); - send8BitData(0x0F); - send8BitData(0x08); - send8BitData(0x00); - send8BitData(0x0F); - sendCommand(0x3A); - send8BitData(0x05); - sendCommand(0x36); - send8BitData(0xC0); - sendCommand(0x11); - delay(150); - sendCommand(0x29); - delay(150); - sendCommand(0x2D); - uint8_t i=0; - - for(i=0;i<32;i++) { - send8BitData(2*i); - } //Red - - for(i=0;i<64;i++) { - send8BitData(1*i); - } //Green - - for(i=0;i<32;i++) - { - send8BitData(2*i); - } //Blue - sendCommand(0x2C); - - delay(150); - clearScreen(); -} - -/********************************************************************************************************* - END FILE -*********************************************************************************************************/ - -
diff -r 2db7065edbec -r 70127e08ed27 DmTftHX8353C.h --- a/DmTftHX8353C.h Mon Oct 12 08:35:35 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/********************************************************************************************** - Copyright (c) 2014 DisplayModule. All rights reserved. - - Redistribution and use of this source code, part of this source code or any compiled binary - based on this source code is permitted as long as the above copyright notice and following - disclaimer is retained. - - DISCLAIMER: - THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES - NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. - ********************************************************************************************/ - -#ifndef DM_TFT_HX8353C_h -#define DM_TFT_HX8353C_h - -#include "DmTftBase.h" - -class DmTftHX8353C : public DmTftBase -{ -public: -#if defined (DM_TOOLCHAIN_ARDUINO) - DmTftHX8353C(uint8_t mosi=D2, uint8_t clk=D3, uint8_t cs=D4, uint8_t dc=D5, uint8_t rst=D6); -#elif defined (DM_TOOLCHAIN_MBED) - DmTftHX8353C(PinName mosi, PinName clk, PinName cs, PinName dc, PinName rst); -#endif - virtual ~DmTftHX8353C(); - virtual void init(void); -private: - void send8BitData(uint8_t data); - void writeBus(uint8_t data); - - virtual void setAddress(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2); - virtual void sendCommand(uint8_t index); - virtual void sendData(uint16_t data); - - - static const uint16_t _width; - static const uint16_t _height; -#if defined (DM_TOOLCHAIN_ARDUINO) - uint8_t _mosi, _clk, _cs, _dc, _rst; - regtype *_pinDC, *_pinRST, *_pinMOSI, *_pinCLK; - regsize _bitmaskDC, _bitmaskRST, _bitmaskMOSI, _bitmaskCLK; -#elif defined (DM_TOOLCHAIN_MBED) - PinName _mosi, _clk, _cs, _dc, _rst; - DigitalOut* _pinDC, *_pinRST, *_pinMOSI, *_pinCLK; -#endif -}; -#endif - - -
diff -r 2db7065edbec -r 70127e08ed27 DmTftIli9325.cpp --- a/DmTftIli9325.cpp Mon Oct 12 08:35:35 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,209 +0,0 @@ -/********************************************************************************************** - Copyright (c) 2014 DisplayModule. All rights reserved. - - Redistribution and use of this source code, part of this source code or any compiled binary - based on this source code is permitted as long as the above copyright notice and following - disclaimer is retained. - - DISCLAIMER: - THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES - NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. - ********************************************************************************************/ - - //Tested on NUCLEO-F401RE, LPCXpresso11U68 platform. - -#include "DmTftIli9325.h" - -#if defined (DM_TOOLCHAIN_ARDUINO) -DmTftIli9325::DmTftIli9325(uint8_t wr, uint8_t cs, uint8_t dc, uint8_t rst) : DmTftBase(240, 320) -#elif defined (DM_TOOLCHAIN_MBED) -DmTftIli9325::DmTftIli9325(PinName wr, PinName cs, PinName dc, PinName rst) : DmTftBase(240, 320) -#endif -{ - _wr = wr; - _cs = cs; - _dc = dc; - _rst = rst; -} - -DmTftIli9325::~DmTftIli9325() { -#if defined (DM_TOOLCHAIN_MBED) - delete _pinRST; - delete _pinCS; - delete _pinWR; - delete _pinDC; - delete _virtualPortD; - _pinRST = NULL; - _pinCS = NULL; - _pinWR = NULL; - _pinDC = NULL; - _virtualPortD = NULL; -#endif -} - -void DmTftIli9325::writeBus(uint8_t data) { -#if defined (DM_TOOLCHAIN_ARDUINO) - PORTD = data; -#elif defined (DM_TOOLCHAIN_MBED) - *_virtualPortD = data; - //if(data & 0x10) -#endif - pulse_low(_pinWR, _bitmaskWR); -} - -void DmTftIli9325::sendCommand(uint8_t index) { - cbi(_pinDC, _bitmaskDC); - writeBus(0x00); - writeBus(index); -} - -void DmTftIli9325::sendData(uint16_t data) { - sbi(_pinDC, _bitmaskDC); - writeBus(data>>8); - writeBus(data); -} - -void DmTftIli9325::setAddress(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { - sendCommand(0x50); // Set Column - sendData(x0); - sendCommand(0x51); - sendData(x1); - - sendCommand(0x52); // Set Page - sendData(y0); - sendCommand(0x53); - sendData(y1); - - sendCommand(0x20); - sendData(x0); - sendCommand(0x21); - sendData(y0); - sendCommand(0x22); -} - -void DmTftIli9325::init(void) { - setTextColor(BLACK, WHITE); -#if defined (DM_TOOLCHAIN_ARDUINO) -/************************************** - DM-DmTftIli932522-102 Arduino UNO NUM - - RST A2 16 - CS A3 17 - WR A4 18 - RS A5 19 - - DB8 0 0 - DB9 1 1 - DB10 2 2 - DB11 3 3 - DB12 4 4 - DB13 5 5 - DB14 6 6 - DB15 7 7 - -***************************************/ - DDRD = DDRD | B11111111; // SET PORT D AS OUTPUT - - _pinRST = portOutputRegister(digitalPinToPort(_rst)); - _bitmaskRST = digitalPinToBitMask(_rst); - _pinCS = portOutputRegister(digitalPinToPort(_cs)); - _bitmaskCS = digitalPinToBitMask(_cs); - _pinWR = portOutputRegister(digitalPinToPort(_wr)); - _bitmaskWR = digitalPinToBitMask(_wr); - _pinDC = portOutputRegister(digitalPinToPort(_dc)); - _bitmaskDC = digitalPinToBitMask(_dc); - - pinMode(_rst, OUTPUT); - pinMode(_cs, OUTPUT); - pinMode(_wr, OUTPUT); - pinMode(_dc,OUTPUT); -#elif defined (DM_TOOLCHAIN_MBED) - _pinRST = new DigitalOut(_rst); - _pinCS = new DigitalOut(_cs); - _pinWR = new DigitalOut(_wr); - _pinDC = new DigitalOut(_dc); - _virtualPortD = new BusOut(D0, D1, D2, D3, D4, SPECIAL_D5, D6, D7); // LPC15XX_H -#endif - - sbi(_pinRST, _bitmaskRST); - - delay(5); - cbi(_pinRST, _bitmaskRST); - - delay(15); - sbi(_pinRST, _bitmaskRST); - sbi(_pinCS, _bitmaskCS); - sbi(_pinWR, _bitmaskWR); - - delay(15); - cbi(_pinCS, _bitmaskCS); - - - - sendCommand(0xE5); sendData(0x78F0); - sendCommand(0x01); sendData(0x0100); - sendCommand(0x02); sendData(0x0700); - sendCommand(0x03); sendData(0x1030); - sendCommand(0x04); sendData(0x0000); - sendCommand(0x08); sendData(0x0207); - sendCommand(0x09); sendData(0x0000); - sendCommand(0x0A); sendData(0x0000); - sendCommand(0x0C); sendData(0x0000); - sendCommand(0x0D); sendData(0x0000); - sendCommand(0x0F); sendData(0x0000); - - sendCommand(0x10); sendData(0x0000); - sendCommand(0x11); sendData(0x0007); - sendCommand(0x12); sendData(0x0000); - sendCommand(0x13); sendData(0x0000); - - sendCommand(0x10); sendData(0x1290); - sendCommand(0x11); sendData(0x0227); - sendCommand(0x12); sendData(0x001D); - sendCommand(0x13); sendData(0x1500); - - sendCommand(0x29); sendData(0x0018); - sendCommand(0x2B); sendData(0x000D); - - sendCommand(0x30); sendData(0x0004); - sendCommand(0x31); sendData(0x0307); - sendCommand(0x32); sendData(0x0002); - sendCommand(0x35); sendData(0x0206); - sendCommand(0x36); sendData(0x0408); - sendCommand(0x37); sendData(0x0507); - sendCommand(0x38); sendData(0x0204); - sendCommand(0x39); sendData(0x0707); - sendCommand(0x3C); sendData(0x0405); - sendCommand(0x3D); sendData(0x0f02); - - sendCommand(0x50); sendData(0x0000); - sendCommand(0x51); sendData(0x00EF); - sendCommand(0x52); sendData(0x0000); - sendCommand(0x53); sendData(0x013F); - sendCommand(0x60); sendData(0xA700); - sendCommand(0x61); sendData(0x0001); - sendCommand(0x6A); sendData(0x0000); - - sendCommand(0x80); sendData(0x0000); - sendCommand(0x81); sendData(0x0000); - sendCommand(0x82); sendData(0x0000); - sendCommand(0x83); sendData(0x0000); - sendCommand(0x84); sendData(0x0000); - sendCommand(0x85); sendData(0x0000); - - sendCommand(0x90); sendData(0x0010); - sendCommand(0x92); sendData(0x0600); - sendCommand(0x93); sendData(0x0003); - sendCommand(0x95); sendData(0x0110); - sendCommand(0x97); sendData(0x0000); - sendCommand(0x98); sendData(0x0000); - sendCommand(0x07); sendData(0x0133); - sbi(_pinCS, _bitmaskCS); - delay(500); - clearScreen(); -} - -/********************************************************************************************************* - END FILE -*********************************************************************************************************/ -
diff -r 2db7065edbec -r 70127e08ed27 DmTftIli9325.h --- a/DmTftIli9325.h Mon Oct 12 08:35:35 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/********************************************************************************************** - Copyright (c) 2014 DisplayModule. All rights reserved. - - Redistribution and use of this source code, part of this source code or any compiled binary - based on this source code is permitted as long as the above copyright notice and following - disclaimer is retained. - - DISCLAIMER: - THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES - NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. - ********************************************************************************************/ - -#ifndef DM_TFT_ILI9325_h -#define DM_TFT_ILI9325_h - -#include "DmTftBase.h" - -class DmTftIli9325 : public DmTftBase -{ -public: -#if defined (DM_TOOLCHAIN_ARDUINO) - DmTftIli9325(uint8_t wr=A4, uint8_t cs=A3, uint8_t dc=A5, uint8_t rst=A2); -#elif defined (DM_TOOLCHAIN_MBED) - DmTftIli9325(PinName wr, PinName cs, PinName dc, PinName rst); -#endif - virtual ~DmTftIli9325(); - virtual void init(void); -private: - void send8BitData(uint8_t data); - void writeBus(uint8_t data); - - virtual void setAddress(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1); - virtual void sendCommand(uint8_t index); - virtual void sendData(uint16_t data); - - - static const uint16_t _width; - static const uint16_t _height; -#if defined (DM_TOOLCHAIN_ARDUINO) - uint8_t _wr, _cs, _dc, _rst; - regtype *_pinDC, *_pinRST, *_pinWR; - regsize _bitmaskDC, _bitmaskRST, _bitmaskWR; -#elif defined (DM_TOOLCHAIN_MBED) - PinName _wr, _cs, _dc, _rst; - DigitalOut* _pinDC, *_pinRST, *_pinWR; - BusOut * _virtualPortD; -#endif -}; -#endif - - -
diff -r 2db7065edbec -r 70127e08ed27 DmTftRa8875.cpp --- a/DmTftRa8875.cpp Mon Oct 12 08:35:35 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,902 +0,0 @@ -/********************************************************************************************** - Copyright (c) 2014 DisplayModule. All rights reserved. - - Redistribution and use of this source code, part of this source code or any compiled binary - based on this source code is permitted as long as the above copyright notice and following - disclaimer is retained. - - DISCLAIMER: - THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES - NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. - ********************************************************************************************/ - -/* Notice: - The panel resolution should be config in DmTftRa8875::init() function. - RA8875Size size = RA8875_480x272 or RA8875Size size = RA8875_800x480; - - Tested on NUCLEO-F401RE, LPCXpresso11U68, LPCXpresso824-MAX platform. -*/ - -#include "DmTftRa8875.h" -#if defined (DM_TOOLCHAIN_ARDUINO) -DmTftRa8875::DmTftRa8875(uint8_t cs, uint8_t sel) -: DmTftBase(480, 272) -#elif defined (DM_TOOLCHAIN_MBED) -DmTftRa8875::DmTftRa8875(PinName cs, PinName sel, PinName mosi, PinName miso, PinName clk) -: DmTftBase(480, 272), spi(mosi, miso, clk) -#endif -{ - _cs = cs; - _sel = sel; -} - -DmTftRa8875::~DmTftRa8875() -{ -#if defined (DM_TOOLCHAIN_MBED) - delete _pinCS; - delete _pinSEL; - - _pinCS = NULL; - _pinSEL = NULL; -#endif -} - -uint16_t DmTftRa8875::width(void) -{ - return _width; -} - -uint16_t DmTftRa8875::height(void) -{ - return _height; -} - -void DmTftRa8875::writeBus(uint8_t data) -{ -#if defined (DM_TOOLCHAIN_ARDUINO) - //SPCR = _spiSettings; // SPI Control Register - SPDR = data; // SPI Data Register - while(!(SPSR & _BV(SPIF))); // SPI Status Register Wait for transmission to finish -#elif defined (DM_TOOLCHAIN_MBED) - spi.write(data); -#endif -} - -uint8_t DmTftRa8875::readBus(void) -{ -#if defined (DM_TOOLCHAIN_ARDUINO) - //SPCR = _spiSettings; // SPI Control Register - SPDR = 0; // SPI Data Register - while(!(SPSR & _BV(SPIF))); // SPI Status Register Wait for transmission to finish - return SPDR; -#elif defined (DM_TOOLCHAIN_MBED) - return spi.write(0x00); // dummy byte to read -#endif -} - -void DmTftRa8875::sendCommand(uint8_t index) -{ - cbi(_pinCS, _bitmaskCS); - - writeBus(0x80); - writeBus(index); - - sbi(_pinCS, _bitmaskCS); -} - -uint8_t DmTftRa8875::readStatus(void) -{ - cbi(_pinCS, _bitmaskCS); - - writeBus(0xC0); - uint8_t data = readBus(); - - sbi(_pinCS, _bitmaskCS); - - return data; -} - -void DmTftRa8875::sendData(uint16_t data) -{ - - uint8_t dh = data>>8; - uint8_t dl = data&0xff; - - cbi(_pinCS, _bitmaskCS); - - writeBus(0x00); - writeBus(dh); - writeBus(dl); - - sbi(_pinCS, _bitmaskCS); - -} - -void DmTftRa8875::send8BitData(uint8_t data) -{ - cbi(_pinCS, _bitmaskCS); - - writeBus(0x00); - writeBus(data); - - sbi(_pinCS, _bitmaskCS); -} - -uint8_t DmTftRa8875::readData(void) -{ - cbi(_pinCS, _bitmaskCS); - - writeBus(0x40); - uint8_t data = readBus(); - - sbi(_pinCS, _bitmaskCS); - - return data; -} - -void DmTftRa8875::writeReg(uint8_t reg, uint8_t val) -{ - sendCommand(reg); - send8BitData(val); -} - -uint8_t DmTftRa8875::readReg(uint8_t reg) -{ - sendCommand(reg); - return readData(); -} - -void DmTftRa8875::setAddress(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) -{ - /* Set active window X */ - writeReg(0x30, x0); // horizontal start point - writeReg(0x31, x0 >> 8); - writeReg(0x34, (uint16_t)(x1) & 0xFF); // horizontal end point - writeReg(0x35, (uint16_t)(x1) >> 8); - - /* Set active window Y */ - writeReg(0x32, y0); // vertical start point - writeReg(0x33, y0 >> 8); - writeReg(0x36, (uint16_t)(y1) & 0xFF); // vertical end point - writeReg(0x37, (uint16_t)(y1) >> 8); - - writeReg(0x46, x0); - writeReg(0x47, x0 >> 8); - writeReg(0x48, y0); - writeReg(0x49, y0 >> 8); - sendCommand(0x02); -} - -void DmTftRa8875::softReset(void) -{ - //softreset - sendCommand(0x01); - send8BitData(0x01); - delay(10); - sendCommand(0x01); - send8BitData(0x00); - delay(100); // This much delay needed?? -} - -void DmTftRa8875::init(void) -{ - // DM_TFT43_108 = RA8875_480x272; DM_TFT50_111 = RA8875_800x480 - RA8875Size size = RA8875_480x272; - - setTextColor(BLACK, WHITE); -#if defined (DM_TOOLCHAIN_ARDUINO) - _pinCS = portOutputRegister(digitalPinToPort(_cs)); - _bitmaskCS = digitalPinToBitMask(_cs); - _pinSEL = portOutputRegister(digitalPinToPort(_sel)); - _bitmaskSEL = digitalPinToBitMask(_sel); - pinMode(_cs,OUTPUT); - pinMode(_sel,OUTPUT); - digitalWrite(_sel, LOW); // w25 control by MCU - - sbi(_pinCS, _bitmaskCS); - - SPI.begin(); - SPI.setClockDivider(SPI_CLOCK_DIV2); // 8 MHz (full! speed!) - SPI.setBitOrder(MSBFIRST); - SPI.setDataMode(SPI_MODE0); - _spiSettings = SPCR; -#elif defined (DM_TOOLCHAIN_MBED) - _pinCS = new DigitalOut(_cs); - _pinSEL = new DigitalOut(_sel); - sbi(_pinSEL, _bitmaskSEL); // w25 control by MCU - - sbi(_pinCS, _bitmaskCS); - - -#ifdef TARGET_LPC824 // for LPCXpresso824-MAX - spi.format(8,3); - spi.frequency(8000000); -#elif TARGET_LPC11U6X // for LPCXpresso11U68 - spi.format(8,3); - spi.frequency(2000000); -#elif TARGET_NUCLEO_F401RE // for NUCLEO-F401RE - spi.format(8,0); - spi.frequency(8000000); -#else - spi.format(8,3); - spi.frequency(2000000); // Max SPI speed for display is 10 and for 17 for LPC15xx -#endif - softReset(); -#endif - - cbi(_pinCS, _bitmaskCS); - - /* Timing values */ - uint8_t pixclk; - uint8_t hsync_start; - uint8_t hsync_pw; - uint8_t hsync_finetune; - uint8_t hsync_nondisp; - uint8_t vsync_pw; - uint16_t vsync_nondisp; - uint16_t vsync_start; - - if(size == RA8875_480x272) { - _width = 480; - _height = 272; - setWidth(_width); - setHeight(_height); - // PLL init - // 20MHz*(10+1)/((RA8875_PLLC1_PLLDIV1 +1) * 2^RA8875_PLLC2_DIV4)) - writeReg(0x88, 0x00 + 10); - delay(1); - writeReg(0x89, 0x02); - delay(1); - - pixclk = 0x80 | 0x02; - hsync_nondisp = 10; - hsync_start = 8; - hsync_pw = 48; - hsync_finetune = 0; - vsync_nondisp = 3; - vsync_start = 8; - vsync_pw = 10; - } - - if(size == RA8875_800x480) { - _width = 800; - _height = 480; - setWidth(_width); - setHeight(_height); - // PLL init - // 20MHz*(10+1)/((RA8875_PLLC1_PLLDIV1 +1) * 2^RA8875_PLLC2_DIV4)) - writeReg(0x88, 0x00 + 10); - delay(1); - writeReg(0x89, 0x02); - delay(1); - - pixclk = 0x80 | 0x01; - hsync_nondisp = 26; - hsync_start = 32; - hsync_pw = 96; - hsync_finetune = 0; - vsync_nondisp = 32; - vsync_start = 23; - vsync_pw = 2; - } - - writeReg(0x10, 0x0C | 0x00); - - writeReg(0x04, pixclk); - delay(1); - - /* Horizontal settings registers */ - writeReg(0x14, (_width / 8) - 1); // H width: (HDWR + 1) * 8 = 480 - writeReg(0x15, 0x00 + hsync_finetune); - writeReg(0x16, (hsync_nondisp - hsync_finetune - 2)/8); // H non-display: HNDR * 8 + HNDFTR + 2 = 10 - writeReg(0x17, hsync_start/8 - 1); // Hsync start: (HSTR + 1)*8 - writeReg(0x18, 0x00 + (hsync_pw/8 - 1)); // HSync pulse width = (HPWR+1) * 8 - - /* Vertical settings registers */ - writeReg(0x19, (uint16_t)(_height - 1) & 0xFF); - writeReg(0x1A, (uint16_t)(_height - 1) >> 8); - writeReg(0x1B, vsync_nondisp-1); // V non-display period = VNDR + 1 - writeReg(0x1C, vsync_nondisp >> 8); - writeReg(0x1D, vsync_start-1); // Vsync start position = VSTR + 1 - writeReg(0x1E, vsync_start >> 8); - writeReg(0x1F, 0x00 + vsync_pw - 1); // Vsync pulse width = VPWR + 1 - - /* Set active window X */ - writeReg(0x30, 0); // horizontal start point - writeReg(0x31, 0); - writeReg(0x34, (uint16_t)(_width - 1) & 0xFF); // horizontal end point - writeReg(0x35, (uint16_t)(_width - 1) >> 8); - - /* Set active window Y */ - writeReg(0x32, 0); // vertical start point - writeReg(0x33, 0); - writeReg(0x36, (uint16_t)(_height - 1) & 0xFF); // vertical end point - writeReg(0x37, (uint16_t)(_height - 1) >> 8); - /* Clear the entire window */ - writeReg(0x8E, 0x80 | 0x00); - /* Wait for the command to finish */ - while (readReg(0x8E) & 0x80); - //delay(100); - // display on - writeReg(0x01, 0x00 | 0x80); - // GPIOX on - writeReg(0xC7, 1); - sbi(_pinCS, _bitmaskCS); - - //clearScreen(); - setFontColor(BLACK, WHITE); - //setFontZoom(0, 0); - - // spi flash control by MCU - w25CtrlByMCU(); - - //backlight on - backlightOn(true); - backlightAdjust(255); // max luminance - -} - -void DmTftRa8875::eableKeyScan(bool on) -{ - if(on) { - writeReg(0xC0, (1 << 7) | (0 << 4 ) | 1 ); // enable key scan - } else { - writeReg(0xC0, (0 << 7)); - } -} - -uint8_t DmTftRa8875::getKeyValue(void) -{ - uint8_t data = 0xFF; - sendCommand(0xC2); - data = readData(); - - // Clear key interrupt status - writeReg(0xF1,readReg(0xF1) | 0x10); - delay(1); - return data; - -} - -bool DmTftRa8875::isKeyPress(void) -{ - uint8_t temp; - temp = readReg(0xF1); - - if(temp & 0x10) { - return true; - } else { - return false; - } -} - -void DmTftRa8875::backlightOn(bool on) -{ - if(on) { - writeReg(0x8A, (1 << 7) | (10 << 0 )); // enable PWM1 - } else { - writeReg(0x8A, (0 << 7) | (10 << 0 )); - } -} - -void DmTftRa8875::backlightAdjust(uint8_t value) -{ - writeReg(0x8B, value); -} - -void DmTftRa8875::w25CtrlByMCU(void) -{ -#if defined (DM_TOOLCHAIN_ARDUINO) - digitalWrite(_sel, LOW); -#elif defined (DM_TOOLCHAIN_MBED) - cbi(_pinSEL, _bitmaskSEL); -#endif -} - -void DmTftRa8875::w25CtrlByRa8875(void) -{ -#if defined (DM_TOOLCHAIN_ARDUINO) - digitalWrite(_sel, HIGH); -#elif defined (DM_TOOLCHAIN_MBED) - sbi(_pinSEL, _bitmaskSEL); -#endif - -} - -void DmTftRa8875::drawImageContinuous(uint32_t startaddress,uint32_t count,uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1) -{ - w25CtrlByRa8875(); - - setAddress(x0, y0, x1-1, y1-1); - - writeReg(0xE0, 0x00); - - writeReg(0x05, (0 << 7) | (0 << 6) | (1 << 5) | (0 << 3) | (1 << 2) | (3 << 1)); - writeReg(0x06, (0 << 0)); // set serial flash frequency - - writeReg(0xB0,startaddress & 0xFF); // DMA Source Start Address - writeReg(0xB1,startaddress >> 8); - writeReg(0xB2,startaddress >> 16); - - writeReg(0xB4, count & 0xFF); // DMA Transfer Number - writeReg(0xB6, (count & 0xFF00) >> 8 ); - writeReg(0xB8, (count & 0xFF0000) >> 16); - - - writeReg(0xBF, 0x00); // Continuous mode - writeReg(0xBF, readReg(0xBF) | 0x01); //start DMA - - /* Wait for the DMA Transfer to finish */ - while (readReg(0xBF) & 0x01); - - w25CtrlByMCU(); - -} - -void DmTftRa8875::drawImageBlock(uint32_t startaddress, uint32_t count, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,uint16_t pic_width, uint16_t block_width, uint16_t block_height) -{ - w25CtrlByRa8875(); - - setAddress(x0, y0, x1-1, y1-1); - - writeReg(0xE0, 0x00); - - writeReg(0x05, (0 << 7) | (0 << 6) | (1 << 5) | (0 << 3) | (1 << 2) | (3 << 1)); - writeReg(0x06, (0 << 0)); // set serial flash frequency - - writeReg(0xB0,startaddress & 0xFF); // DMA Source Start Address - writeReg(0xB1,startaddress >> 8); - writeReg(0xB2,startaddress >> 16); - - writeReg(0xB4, block_width & 0xFF); // DMA block width - writeReg(0xB5, block_width >> 8 ); - writeReg(0xB6, block_height & 0xFF); // DMA block height - writeReg(0xB7, block_height >> 8 ); - - writeReg(0xB8, pic_width & 0xFF); // DMA soruce picture width - writeReg(0xB9, pic_width >> 8 ); - - writeReg(0xBF, 0x02); // block mode - writeReg(0xBF, readReg(0xBF) | 0x01); //start DMA - - /* Wait for the DMA Transfer to finish */ - while (readReg(0xBF) & 0x01); - - w25CtrlByMCU(); - -} - -void DmTftRa8875::drawPoint(uint16_t x, uint16_t y, uint16_t radius) -{ - if (radius == 0) { - cbi(_pinCS, _bitmaskCS); - - setAddress(x,y,x,y); - sendData(_fgColor); - - sbi(_pinCS, _bitmaskCS); - } else { - fillRectangle(x-radius,y-radius,x+radius,y+radius, _fgColor); - } -} - - -void DmTftRa8875::setFontColor(uint16_t background,uint16_t foreground) -{ - /* Set Background Color */ - _bgColor = background; - writeReg(0x60, (background & 0xf800) >> 11); - writeReg(0x61, (background & 0x07e0) >> 5); - writeReg(0x62, (background & 0x001f)); - - /* Set Fore Color */ - _fgColor = foreground; - writeReg(0x63, (foreground & 0xf800) >> 11); - writeReg(0x64, (foreground & 0x07e0) >> 5); - writeReg(0x65, (foreground & 0x001f)); -} - - -void DmTftRa8875::setFontZoom(uint8_t Hsize,uint8_t Vsize) -{ - writeReg(0x22, ((Hsize & 0x03) <<2 | (Vsize & 0x03))); -} - -void DmTftRa8875::int2str(int n, char *str) -{ - char buf[10] = ""; - int i = 0; - int len = 0; - int temp = n < 0 ? -n: n; - - if (str == NULL) { - return; - } - while(temp) { - buf[i++] = (temp % 10) + '0'; - temp = temp / 10; - } - - len = n < 0 ? ++i: i; - str[i] = 0; - while(1) { - i--; - if (buf[len-i-1] ==0) { - break; - } - str[i] = buf[len-i-1]; - } - if (i == 0 ) { - str[i] = '-'; - } -} - -void DmTftRa8875::drawNumber(uint16_t x, uint16_t y, int num, int digitsToShow, bool leadingZeros) -{ - char p[10]; - int2str(num, p); - - // clear the last number on the screen; default font width is 8. - for(int i=0; i<digitsToShow; i++) - drawString(x+i*8, y," "); - - drawString(x, y, p); -} - - -void DmTftRa8875::drawString(uint16_t x, uint16_t y, const char *p) -{ - setAddress(0, 0, _width-1, _height-1); - - writeReg(0x40, (1 << 7) | (1 << 0)); // enter text mode - writeReg(0x2A, x); - writeReg(0x2B, x >> 8); - writeReg(0x2C, y); - writeReg(0x2D, y >> 8); - - writeReg(0x2F, 0x00); - writeReg(0x21, (0 << 7) | (0 << 5) | (0 << 1) | (0 << 0)); - sendCommand(0x02); - - while (*p != '\0') { - send8BitData(*p); - while ((readStatus() & 0x80) == 0x80); // wait finish - p++; - } - writeReg(0x40, (0 << 7)); // enter graphics mode -} - -void DmTftRa8875::drawStringCentered(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const char *p) -{ - - int len = strlen(p); - uint16_t tmp = len * 8; - if (tmp <= width) { - x += (width - tmp)/2; - } - if (16 <= height) { - y += (height - 16)/2; - } - - drawString(x, y, p); -} - -void DmTftRa8875::clearScreen(uint16_t color) -{ - rectangle(0, 0, _width-1, _height-1, color, true); -} - -void DmTftRa8875::rectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color, bool filled) -{ - setAddress(0, 0, _width-1, _height-1); - - /* Set x0 */ - writeReg(0x91, x0); - writeReg(0x92, x0 >> 8); - - /* Set y0 */ - writeReg(0x93, y0); - writeReg(0x94, y0 >> 8); - - /* Set x1 */ - writeReg(0x95, x1); - writeReg(0x96, x1 >> 8); - - /* Set y1 */ - writeReg(0x97, y1); - writeReg(0x98, y1 >> 8); - - /* Set Color */ - writeReg(0x63, (color & 0xf800) >> 11); - writeReg(0x64, (color & 0x07e0) >> 5); - writeReg(0x65, (color & 0x001f)); - - /* Draw! */ - if (filled) { - writeReg(0x90, 0xB0); - } else { - writeReg(0x90, 0x90); - } - - /* Wait for the command to finish */ - while (readReg(0x90) & 0x80); -} - -void DmTftRa8875::drawRectangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) -{ - rectangle(x0, y0, x1, y1, color, false); -} -void DmTftRa8875::fillRectangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) -{ - rectangle(x0, y0, x1, y1, color, true); -} - -void DmTftRa8875::drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) -{ - setAddress(0, 0, _width-1, _height-1); - - /* Set x0 */ - writeReg(0x91, x0); - writeReg(0x92, x0 >> 8); - - /* Set y0 */ - writeReg(0x93, y0); - writeReg(0x94, y0 >> 8); - - /* Set x1 */ - writeReg(0x95, x1); - writeReg(0x96, x1 >> 8); - - /* Set y1 */ - writeReg(0x97, y1); - writeReg(0x98, y1 >> 8); - - /* Set Color */ - writeReg(0x63, (color & 0xf800) >> 11); - writeReg(0x64, (color & 0x07e0) >> 5); - writeReg(0x65, (color & 0x001f)); - - /* Draw! */ - writeReg(0x90, 0x80); - - /* Wait for the command to finish */ - while (readReg(0x90) & 0x80); -} - -void DmTftRa8875::drawVerticalLine(uint16_t x, uint16_t y, uint16_t length, uint16_t color) -{ - drawLine(x, y, x, y+length, color); -} - -void DmTftRa8875::drawHorizontalLine(uint16_t x, uint16_t y, uint16_t length, uint16_t color) -{ - drawLine(x, y, x+length, y, color); -} - -void DmTftRa8875::circle(int16_t x, int16_t y, int16_t r, uint16_t color, bool filled) -{ - setAddress(0, 0, _width-1, _height-1); - - /* Set x */ - writeReg(0x99, x); - writeReg(0x9A, x >> 8); - - /* Set y */ - writeReg(0x9B, y); - writeReg(0x9C, y >> 8); - - /* Set Radius */ - writeReg(0x9D, r); - - /* Set Color */ - writeReg(0x63, (color & 0xf800) >> 11); - writeReg(0x64, (color & 0x07e0) >> 5); - writeReg(0x65, (color & 0x001f)); - - /* Draw! */ - if (filled) { - writeReg(0x90, 0x40 | 0x20); - } else { - writeReg(0x90, 0x40 | 0x00); - } - - /* Wait for the command to finish */ - while (readReg(0x90) & 0x40); -} - -void DmTftRa8875::drawCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color) -{ - circle(x0, y0, r, color, false); -} -void DmTftRa8875::fillCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color) -{ - circle(x0, y0, r, color, true); -} - -void DmTftRa8875::triangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color, bool filled) -{ - setAddress(0, 0, _width-1, _height-1); - - /* Set Point 0 */ - writeReg(0x91, x0); - writeReg(0x92, (x0 >> 8)); - writeReg(0x93, y0); - writeReg(0x94, (y0 >> 8)); - - /* Set Point 1 */ - writeReg(0x95, x1); - writeReg(0x96, (x1 >> 8)); - writeReg(0x97, y1); - writeReg(0x98, (y1 >> 8)); - - /* Set Point 2 */ - writeReg(0xA9, x2); - writeReg(0xAA, (x2 >> 8)); - writeReg(0xAB, y2); - writeReg(0xAC, (y2 >> 8)); - - /* Set Color */ - writeReg(0x63, (color & 0xf800) >> 11); - writeReg(0x64, (color & 0x07e0) >> 5); - writeReg(0x65, (color & 0x001f)); - - /* Draw! */ - if (filled) { - writeReg(0x90, 0xA1); - } else { - writeReg(0x90, 0x81); - } - - /* Wait for the command to finish */ - while (readReg(0x90) & 0x80); -} - -void DmTftRa8875::drawTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) -{ - triangle(x0, y0, x1, y1, x2, y2, color, false); -} - -void DmTftRa8875::fillTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) -{ - triangle(x0, y0, x1, y1, x2, y2, color, true); -} - -void DmTftRa8875::ellipse(int16_t x0, int16_t y0, int16_t longAxis, int16_t shortAxis, uint16_t color, bool filled) -{ - setAddress(0, 0, _width-1, _height-1); - - /* Set Center Point */ - writeReg(0xA5, x0); - writeReg(0xA6, (x0 >> 8)); - writeReg(0xA7, y0); - writeReg(0xA8, (y0 >> 8)); - - /* Set Long and Short Axis */ - writeReg(0xA1, longAxis); - writeReg(0xA2, (longAxis >> 8)); - writeReg(0xA3, shortAxis); - writeReg(0xA4, (shortAxis >> 8)); - - /* Set Color */ - writeReg(0x63, (color & 0xf800) >> 11); - writeReg(0x64, (color & 0x07e0) >> 5); - writeReg(0x65, (color & 0x001f)); - - /* Draw! */ - if (filled) { - writeReg(0xA0, 0xC0); - } else { - writeReg(0xA0, 0x80); - } - - /* Wait for the command to finish */ - while (readReg(0xA0) & 0x80); - -} - -void DmTftRa8875::drawEllipse(int16_t x0, int16_t y0, int16_t longAxis, int16_t shortAxis, uint16_t color) -{ - ellipse(x0, y0, longAxis, shortAxis, color, false); -} - -void DmTftRa8875::fillEllipse(int16_t x0, int16_t y0, int16_t longAxis, int16_t shortAxis, uint16_t color) -{ - ellipse(x0, y0, longAxis, shortAxis, color, true); -} - -void DmTftRa8875::curve(int16_t x0, int16_t y0, int16_t longAxis, int16_t shortAxis, uint8_t curvePart, uint16_t color, bool filled) -{ - setAddress(0, 0, _width-1, _height-1); - - /* Set Center Point */ - writeReg(0xA5, x0); - writeReg(0xA6, (x0 >> 8)); - writeReg(0xA7, y0); - writeReg(0xA8, (y0 >> 8)); - - /* Set Long and Short Axis */ - writeReg(0xA1, longAxis); - writeReg(0xA2, (longAxis >> 8)); - writeReg(0xA3, shortAxis); - writeReg(0xA4, (shortAxis >> 8)); - - /* Set Color */ - writeReg(0x63, (color & 0xf800) >> 11); - writeReg(0x64, (color & 0x07e0) >> 5); - writeReg(0x65, (color & 0x001f)); - - /* Draw! */ - if (filled) { - writeReg(0xA0, 0xD0 | (curvePart & 0x03)); - } else { - writeReg(0xA0, 0x90 | (curvePart & 0x03)); - } - - /* Wait for the command to finish */ - while (readReg(0xA0) & 0x80); - -} - -void DmTftRa8875::drawCurve(int16_t x0, int16_t y0, int16_t longAxis, int16_t shortAxis, uint8_t curvePart, uint16_t color) -{ - curve(x0, y0, longAxis, shortAxis, curvePart, color, false); -} - -void DmTftRa8875::fillCurve(int16_t x0, int16_t y0, int16_t longAxis, int16_t shortAxis, uint8_t curvePart, uint16_t color) -{ - curve(x0, y0, longAxis, shortAxis, curvePart, color, true); -} - -void DmTftRa8875::roundrectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t r1, uint16_t r2, uint16_t color, bool filled) -{ - setAddress(0, 0, _width-1, _height-1); - - /* Set x0 */ - writeReg(0x91, x0); - writeReg(0x92, x0 >> 8); - - /* Set y0 */ - writeReg(0x93, y0); - writeReg(0x94, y0 >> 8); - - /* Set x1 */ - writeReg(0x95, x1); - writeReg(0x96, x1 >> 8); - - /* Set y1 */ - writeReg(0x97, y1); - writeReg(0x98, y1 >> 8); - - /* Set Radius */ - writeReg(0xA1, r1); - writeReg(0xA2, r1 >> 8); - writeReg(0xA3, r2); - writeReg(0xA4, r2 >> 8); - - /* Set Color */ - writeReg(0x63, (color & 0xf800) >> 11); - writeReg(0x64, (color & 0x07e0) >> 5); - writeReg(0x65, (color & 0x001f)); - - /* Draw! */ - if (filled) { - writeReg(0xA0, 0xE0); - } else { - writeReg(0xA0, 0xA0); - } - - /* Wait for the command to finish */ - while (readReg(0xA0) & 0x80); -} - -void DmTftRa8875::drawRoundRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t r1, uint16_t r2, uint16_t color) -{ - roundrectangle(x0, y0, x1, y1, r1, r2, color, false); -} -void DmTftRa8875::fillRoundRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t r1, uint16_t r2, uint16_t color) -{ - roundrectangle(x0, y0, x1, y1, r1, r2, color, true); -} -/********************************************************************************************************* - END FILE -*********************************************************************************************************/
diff -r 2db7065edbec -r 70127e08ed27 DmTftRa8875.h --- a/DmTftRa8875.h Mon Oct 12 08:35:35 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,115 +0,0 @@ -/********************************************************************************************** - Copyright (c) 2014 DisplayModule. All rights reserved. - - Redistribution and use of this source code, part of this source code or any compiled binary - based on this source code is permitted as long as the above copyright notice and following - disclaimer is retained. - - DISCLAIMER: - THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES - NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. - ********************************************************************************************/ - -#ifndef DM_TFT_RA8875_h -#define DM_TFT_RA8875_h - -#include "DmTftBase.h" - -enum RA8875Size { - RA8875_480x272, - RA8875_800x480 -}; - -class DmTftRa8875 : public DmTftBase -{ -public: -#if defined (DM_TOOLCHAIN_ARDUINO) - DmTftRa8875(uint8_t cs=D10, uint8_t sel=D9); -#elif defined (DM_TOOLCHAIN_MBED) - DmTftRa8875(PinName cs, PinName sel, PinName mosi, PinName miso, PinName clk); -#endif - virtual ~DmTftRa8875(); - virtual void init(); - void w25CtrlByRa8875(void); - void w25CtrlByMCU(void); - void clearScreen(uint16_t color = BLACK); - - void setFontColor(uint16_t background,uint16_t foreground); - void setFontZoom(uint8_t Hsize, uint8_t Vsize); - void eableKeyScan(bool on); - bool isKeyPress(void); - uint8_t getKeyValue(void); - void backlightOn(bool on); - void backlightAdjust(uint8_t value); - void drawImageContinuous(uint32_t startaddress, uint32_t count, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1); - void drawImageBlock(uint32_t startaddress, uint32_t count, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,uint16_t pic_width, uint16_t block_width, uint16_t block_height); - uint16_t width(void); - uint16_t height(void); - void softReset(void); - - void drawPoint(uint16_t x, uint16_t y, uint16_t radius=0); - void drawNumber(uint16_t x, uint16_t y, int num, int digitsToShow, bool leadingZeros=false); - void drawString(uint16_t x, uint16_t y, const char *p); - void drawStringCentered(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const char *p); - - void drawRectangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color); - void fillRectangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color); - - void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color); - void drawVerticalLine(uint16_t x, uint16_t y, uint16_t length, uint16_t color); - void drawHorizontalLine(uint16_t x, uint16_t y, uint16_t length, uint16_t color); - - void drawCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color); - void fillCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color); - - void drawTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); - void fillTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); - - void drawEllipse(int16_t x0, int16_t y0, int16_t longAxis, int16_t shortAxis, uint16_t color); - void fillEllipse(int16_t x0, int16_t y0, int16_t longAxis, int16_t shortAxis, uint16_t color); - - void drawCurve(int16_t x0, int16_t y0, int16_t longAxis, int16_t shortAxis, uint8_t curvePart, uint16_t color); - void fillCurve(int16_t x0, int16_t y0, int16_t longAxis, int16_t shortAxis, uint8_t curvePart, uint16_t color); - - void drawRoundRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t r1, uint16_t r2, uint16_t color); - void fillRoundRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t r1, uint16_t r2, uint16_t color); -private: - void writeBus(uint8_t data); - uint8_t readBus(void); - virtual void sendCommand(uint8_t index); - uint8_t readStatus(void); - virtual void sendData(uint16_t data); - void send8BitData(uint8_t data); - uint8_t readData(void); - virtual void writeReg(uint8_t reg, uint8_t val); - uint8_t readReg(uint8_t reg); - - void rectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color, bool filled); - void circle(int16_t x, int16_t y, int16_t r, uint16_t color, bool filled); - void triangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color, bool filled); - void ellipse(int16_t x0, int16_t y0, int16_t longAxis, int16_t shortAxis, uint16_t color, bool filled); - void curve(int16_t x0, int16_t y0, int16_t longAxis, int16_t shortAxis, uint8_t curvePart, uint16_t color, bool filled); - void roundrectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t r1, uint16_t r2, uint16_t color, bool filled); - - virtual void setAddress(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1); - void int2str(int n, char *str); - uint16_t _width; - uint16_t _height; - uint16_t _bgColor; - uint16_t _fgColor; - enum RA8875Size _size; - - -#if defined (DM_TOOLCHAIN_ARDUINO) - uint8_t _cs, _sel; - regtype *_pinSEL; - regsize _bitmaskSEL; - uint8_t _spiSettings; -#elif defined (DM_TOOLCHAIN_MBED) - PinName _cs, _sel; - DigitalOut *_pinSEL; - SPI spi; -#endif -}; - -#endif
diff -r 2db7065edbec -r 70127e08ed27 DmTftS6D0164.cpp --- a/DmTftS6D0164.cpp Mon Oct 12 08:35:35 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,198 +0,0 @@ -/********************************************************************************************** - Copyright (c) 2014 DisplayModule. All rights reserved. - - Redistribution and use of this source code, part of this source code or any compiled binary - based on this source code is permitted as long as the above copyright notice and following - disclaimer is retained. - - DISCLAIMER: - THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES - NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. - ********************************************************************************************/ - - //Tested on NUCLEO-F401RE, LPCXpresso11U68 platform. - -#include "DmTftS6D0164.h" - -#if defined (DM_TOOLCHAIN_ARDUINO) -DmTftS6D0164::DmTftS6D0164(uint8_t wr, uint8_t cs, uint8_t dc, uint8_t rst) : DmTftBase(176, 220) -#elif defined (DM_TOOLCHAIN_MBED) -DmTftS6D0164::DmTftS6D0164(PinName wr, PinName cs, PinName dc, PinName rst) : DmTftBase(176, 220) -#endif -{ - _wr = wr; - _cs = cs; - _dc = dc; - _rst = rst; -} - -DmTftS6D0164::~DmTftS6D0164() { -#if defined (DM_TOOLCHAIN_MBED) - delete _pinRST; - delete _pinCS; - delete _pinWR; - delete _pinDC; - delete _virtualPortD; - _pinRST = NULL; - _pinCS = NULL; - _pinWR = NULL; - _pinDC = NULL; - _virtualPortD = NULL; -#endif -} - -void DmTftS6D0164::writeBus(uint8_t data) { -#if defined (DM_TOOLCHAIN_ARDUINO) - PORTD = data; -#elif defined (DM_TOOLCHAIN_MBED) - *_virtualPortD = data; -#endif - pulse_low(_pinWR, _bitmaskWR); -} - -void DmTftS6D0164::sendCommand(uint8_t index) { - cbi(_pinDC, _bitmaskDC); - writeBus(index); -} - -void DmTftS6D0164::sendData(uint16_t data) { - sbi(_pinDC, _bitmaskDC); - writeBus(data>>8); - writeBus(data); -} - -void DmTftS6D0164::setAddress(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { - sendCommand(0x37); // Set Column - sendData(x0); - sendCommand(0x36); - sendData(x1); - - - sendCommand(0x39); // Set Page - sendData(y0); - sendCommand(0x38); - sendData(y1); - - sendCommand(0x20); - sendData(x0); - sendCommand(0x21); - sendData(y0); - sendCommand(0x22); -} - -void DmTftS6D0164::init(void) { - setTextColor(BLACK, WHITE); -#if defined (DM_TOOLCHAIN_ARDUINO) -/************************************** - DM-DmTftS6D016422-102 Arduino UNO NUM - - RST A2 16 - CS A3 17 - WR A4 18 - RS A5 19 - - DB8 0 0 - DB9 1 1 - DB10 2 2 - DB11 3 3 - DB12 4 4 - DB13 5 5 - DB14 6 6 - DB15 7 7 - -***************************************/ - DDRD = DDRD | B11111111; // SET PORT D AS OUTPUT - - _pinRST = portOutputRegister(digitalPinToPort(_rst)); - _bitmaskRST = digitalPinToBitMask(_rst); - _pinCS = portOutputRegister(digitalPinToPort(_cs)); - _bitmaskCS = digitalPinToBitMask(_cs); - _pinWR = portOutputRegister(digitalPinToPort(_wr)); - _bitmaskWR = digitalPinToBitMask(_wr); - _pinDC = portOutputRegister(digitalPinToPort(_dc)); - _bitmaskDC = digitalPinToBitMask(_dc); - - pinMode(_rst, OUTPUT); - pinMode(_cs, OUTPUT); - pinMode(_wr, OUTPUT); - pinMode(_dc,OUTPUT); -#elif defined (DM_TOOLCHAIN_MBED) - _pinRST = new DigitalOut(_rst); - _pinCS = new DigitalOut(_cs); - _pinWR = new DigitalOut(_wr); - _pinDC = new DigitalOut(_dc); - _virtualPortD = new BusOut(D0, D1, D2, D3, D4, SPECIAL_D5, D6, D7); -#endif - - sbi(_pinRST, _bitmaskRST); - delay(5); - cbi(_pinRST, _bitmaskRST); - delay(15); - sbi(_pinRST, _bitmaskRST); - sbi(_pinCS, _bitmaskCS); - sbi(_pinWR, _bitmaskWR); - delay(15); - cbi(_pinCS, _bitmaskCS); - - // Power up sequence - sendCommand(0x11); sendData(0x001A); // S6D0164 INIT - sendCommand(0x12); sendData(0x3121); - sendCommand(0x13); sendData(0x006C); - sendCommand(0x14); sendData(0x4249); - sendCommand(0x10); sendData(0x0800); - delay(10); - sendCommand(0x11); sendData(0x011A); - delay(10); - sendCommand(0x11); sendData(0x031A); - delay(10); - sendCommand(0x11); sendData(0x071A); - delay(10); - sendCommand(0x11); sendData(0x0F1A); - delay(20); - sendCommand(0x11); sendData(0x0F3A); - delay(30); - // Initialization set sequence - sendCommand(0x01); sendData(0x011C); - sendCommand(0x02); sendData(0x0100); - sendCommand(0x03); sendData(0x1030); - sendCommand(0x07); sendData(0x0000); - sendCommand(0x08); sendData(0x0808); - sendCommand(0x0B); sendData(0x1100); - sendCommand(0x0C); sendData(0x0000); - sendCommand(0x0F); sendData(0x1401); - sendCommand(0x15); sendData(0x0000); - sendCommand(0x20); sendData(0x0000); - sendCommand(0x21); sendData(0x0000); - - sendCommand(0x38); sendData(0x00DB); - sendCommand(0x39); sendData(0x0000); - sendCommand(0x50); sendData(0x0001); - sendCommand(0x51); sendData(0x020B); - sendCommand(0x52); sendData(0x0805); - sendCommand(0x53); sendData(0x0404); - sendCommand(0x54); sendData(0x0C0C); - sendCommand(0x55); sendData(0x000C); - sendCommand(0x56); sendData(0x0101); - sendCommand(0x57); sendData(0x0400); - sendCommand(0x58); sendData(0x1108); - sendCommand(0x59); sendData(0x050C); - sendCommand(0x36); sendData(0x00AF); - sendCommand(0x37); sendData(0x0000); - sendCommand(0x38); sendData(0x00DB); - sendCommand(0x39); sendData(0x0000); - sendCommand(0x0F); sendData(0x0B01); - sendCommand(0x07); sendData(0x0016); - delay(2); - sendCommand(0x07); sendData(0x0017); - sendCommand(0x22); - delay(10); - sbi(_pinCS, _bitmaskCS); - - clearScreen(); -} - -/********************************************************************************************************* - END FILE -*********************************************************************************************************/ - -
diff -r 2db7065edbec -r 70127e08ed27 DmTftS6D0164.h --- a/DmTftS6D0164.h Mon Oct 12 08:35:35 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/********************************************************************************************** - Copyright (c) 2014 DisplayModule. All rights reserved. - - Redistribution and use of this source code, part of this source code or any compiled binary - based on this source code is permitted as long as the above copyright notice and following - disclaimer is retained. - - DISCLAIMER: - THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES - NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. - ********************************************************************************************/ - -#ifndef DM_TFT_S6D0164_h -#define DM_TFT_S6D0164_h - -#include "DmTftBase.h" - -class DmTftS6D0164 : public DmTftBase -{ -public: -#if defined (DM_TOOLCHAIN_ARDUINO) - DmTftS6D0164(uint8_t wr=A4, uint8_t cs=A3, uint8_t dc=A5, uint8_t rst=A2); -#elif defined (DM_TOOLCHAIN_MBED) - DmTftS6D0164(PinName wr=A4, PinName cs=A3, PinName dc=A5, PinName rst=A2); -#endif - virtual ~DmTftS6D0164(); - virtual void init(void); -private: - void send8BitData(uint8_t data); - void writeBus(uint8_t data); - - virtual void setAddress(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1); - virtual void sendCommand(uint8_t index); - virtual void sendData(uint16_t data); - - static const uint16_t _width; - static const uint16_t _height; -#if defined (DM_TOOLCHAIN_ARDUINO) - uint8_t _wr, _cs, _dc, _rst; - regtype *_pinDC, *_pinRST, *_pinWR; - regsize _bitmaskDC, _bitmaskRST, _bitmaskWR; -#elif defined (DM_TOOLCHAIN_MBED) - PinName _wr, _cs, _dc, _rst; - DigitalOut* _pinDC, *_pinRST, *_pinWR; - BusOut *_virtualPortD; -#endif -}; -#endif - - -
diff -r 2db7065edbec -r 70127e08ed27 DmTftSsd2119.cpp --- a/DmTftSsd2119.cpp Mon Oct 12 08:35:35 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,251 +0,0 @@ -/********************************************************************************************** - Copyright (c) 2014 DisplayModule. All rights reserved. - - Redistribution and use of this source code, part of this source code or any compiled binary - based on this source code is permitted as long as the above copyright notice and following - disclaimer is retained. - - DISCLAIMER: - THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES - NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. - ********************************************************************************************/ - -//Tested on NUCLEO-F401RE, LPCXpresso11U68, LPCXpresso824-MAX platform. - -#include "DmTftSsd2119.h" -#if defined (DM_TOOLCHAIN_ARDUINO) -DmTftSsd2119::DmTftSsd2119(uint8_t cs, uint8_t dc) -:DmTftBase(320, 240) -#elif defined (DM_TOOLCHAIN_MBED) -DmTftSsd2119::DmTftSsd2119(PinName cs, PinName dc, PinName mosi, PinName miso, PinName clk) -:DmTftBase(320, 240), spi(mosi, miso, clk) -#endif -{ - _cs = cs; - _dc = dc; -} - -DmTftSsd2119::~DmTftSsd2119() { -#if defined (DM_TOOLCHAIN_MBED) -delete _pinCS; -delete _pinDC; - -_pinCS = NULL; -_pinDC = NULL; -#endif -} - -void DmTftSsd2119::writeBus(uint8_t data) { -#if defined (DM_TOOLCHAIN_ARDUINO) - SPCR = _spiSettings; // SPI Control Register - SPDR = data; // SPI Data Register - while(!(SPSR & _BV(SPIF))); // SPI Status Register Wait for transmission to finish -#elif defined (DM_TOOLCHAIN_MBED) - spi.write(data); -#endif -} - -void DmTftSsd2119::sendCommand(uint8_t index) { - cbi(_pinDC, _bitmaskDC); - writeBus(0x00); - writeBus(index); -} - -void DmTftSsd2119::send8BitData(uint8_t data) { - sbi(_pinDC, _bitmaskDC); - writeBus(data); -} - -void DmTftSsd2119::sendData(uint16_t data) { - uint8_t dh = data>>8; - uint8_t dl = data&0xff; - - sbi(_pinDC, _bitmaskDC); - writeBus(dh); - writeBus(dl); -} - -void DmTftSsd2119::setAddress(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { - // Set Start and End Vertical RAM address position - uint16_t verticalStartEndAddress; - verticalStartEndAddress = y0&0xff; // Start vertical RAM address - verticalStartEndAddress += (y1&0xff)<<8; // End vertical RAM address - - sendCommand(0x44); - sendData(verticalStartEndAddress); - - sendCommand(0x45); // Set Start Horizontal RAM address position - sendData(x0); - - sendCommand(0x46); // Set End Horizontal RAM address position - sendData(x1); - - // Set start position - sendCommand(0x4e); // Set Column, RAM address X (max 320) - sendData(x0); - sendCommand(0x4f); // Set Page, RAM address Y (max 240) - sendData(y0); - sendCommand(0x22); // RAM data write -} - -// Separate setPixel, because setAddress is to many instructions -void DmTftSsd2119::setPixel(uint16_t x, uint16_t y, uint16_t color) { - cbi(_pinCS, _bitmaskCS); - - // setAddress(x, y, x, y); - sendCommand(0x4e); // Set Column, RAM address X (max 320) - sendData(x); - - sendCommand(0x4f); // Set Page, RAM address Y (max 240) - sendData(y); - - sendCommand(0x22); - sendData(color); - - sbi(_pinCS, _bitmaskCS); -} - -void DmTftSsd2119::init(void) { - setTextColor(BLACK, WHITE); -#if defined (DM_TOOLCHAIN_ARDUINO) - _pinCS = portOutputRegister(digitalPinToPort(_cs)); - _bitmaskCS = digitalPinToBitMask(_cs); - _pinDC = portOutputRegister(digitalPinToPort(_dc)); - _bitmaskDC = digitalPinToBitMask(_dc); - pinMode(_cs,OUTPUT); - pinMode(_dc,OUTPUT); - - sbi(_pinCS, _bitmaskCS); - - SPI.begin(); - SPI.setClockDivider(SPI_CLOCK_DIV2); // 8 MHz (full! speed!) - SPI.setBitOrder(MSBFIRST); - SPI.setDataMode(SPI_MODE0); - _spiSettings = SPCR; -#elif defined (DM_TOOLCHAIN_MBED) - _pinCS = new DigitalOut(_cs); - _pinDC = new DigitalOut(_dc); - sbi(_pinCS, _bitmaskCS); - - spi.format(8,0); - spi.frequency(6000000); -#endif - cbi(_pinCS, _bitmaskCS); - delay(135); // This much delay needed?? - - delay(120); - - sendCommand(0x28); // VCOM OTP - sendData(0x0006); - - sendCommand(0x00); // Start Oscillator - sendData(0x0001); - - sendCommand(0x10); // Set Sleep mode - sendData(0x0000); // Sleep out - delay(30); - - sendCommand(0x11); // Entry Mode ,SET LCM interface Mode. - sendData(0x6870); // SET 65K colors,MCU interface Mode.TypeB ,ID=11 AM=0 the address counter is updated in the horizontal direction. - - sendCommand(0x15); // Generic Interface Control. DOCLK,HSYNC,VSYNC,DE - sendData(0x0000); - - sendCommand(0x01); // Driver Output Control - sendData(0x72EF); // Set REV,GD,BGR,SM,RL,TB - - sendCommand(0x02); // LCD Driving Waveform Control,LCD - sendData(0x0600); - - sendCommand(0x08); // Set the scanning starting position of the gate driver. - sendData(0x0000); // The valid range is from 1 to 240 - - // LCD POWER CONTROL - sendCommand(0x03); // Power Control 1, VGH,VGL - sendData(0x6A38); // Set dct=fline*4, VGH=2 x VCIX2 + VCI,VGL=-(VGH) + VCix2, DC=Fline × 8, AP=Medium to large - - sendCommand(0X0B); // Frame Cycle Control. - sendData(0x5308); // SET NO SDT=1 clock cycle (POR) ,Sets the equalizing period, - - sendCommand(0x0C); // Power Control 2 VCIX2 - sendData(0x0003); // Adjust VCIX2 output voltage=5.7V - - sendCommand(0x0D); // Set amplitude magnification of VLCD63 - sendData(0x000A); // vlcd63=VREF(2.0V)* 2.335V - - sendCommand(0x0E); // SET VCOMG VDV .VCOM - sendData(0x2B00); // SET VCOMG=1,VCOM=VLCD63* //2A - - sendCommand(0X0F); // Gate Scan Position. - sendData(0x0000); // The valid range is from 1 to 240. - - sendCommand(0x1E); // SET nOTP VCOMH ,VCOMH - sendData(0x00B7); // SET nOTP=0, VCOMH=VLCD63* //B8 - - sendCommand(0x25); // Frame Frequency Control - sendData(0x8000); // SET OSC 65Hz //0A-70hz - - sendCommand(0x26); // Analog setting - sendData(0x3800); - - sendCommand(0x27); // Analog setting - sendData(0x0078); - -//sendCommand(0x12); // Sleep mode -//sendData(0xD999); - - // SET WINDOW - sendCommand(0x4E); // Ram Address Set - sendData(0x0000); - - sendCommand(0x4F); // Ram Address Set - sendData(0x0000); - - // Gamma Control - sendCommand(0x30); - sendData(0x0000);//1 - - sendCommand(0x31); - sendData(0x0104);//2 - - sendCommand(0x32); - sendData(0x0100);//3 - - sendCommand(0x33); - sendData(0x0305);//4 - - sendCommand(0x34); - sendData(0x0505);//4 - - sendCommand(0x35); - sendData(0x0305);//5 - - sendCommand(0x36); - sendData(0x0707);//6 - - sendCommand(0x37); - sendData(0x0300);//7 - - sendCommand(0x3A); - sendData(0x1200);//8 - - sendCommand(0x3B); - sendData(0x0800);//9 - - // Final init - delay(300); - sendCommand(0x07); // Display Control - - sendData(0x0033); // Display on - delay(100); - - sendCommand(0x22); // RAM data write/read - - delay(50); - sbi(_pinCS, _bitmaskCS); - clearScreen(); -} - -/********************************************************************************************************* - END FILE -*********************************************************************************************************/
diff -r 2db7065edbec -r 70127e08ed27 DmTftSsd2119.h --- a/DmTftSsd2119.h Mon Oct 12 08:35:35 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/********************************************************************************************** - Copyright (c) 2014 DisplayModule. All rights reserved. - - Redistribution and use of this source code, part of this source code or any compiled binary - based on this source code is permitted as long as the above copyright notice and following - disclaimer is retained. - - DISCLAIMER: - THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES - NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. - ********************************************************************************************/ - -#ifndef DM_TFT_SSD2119_h -#define DM_TFT_SSD2119_h - -#include "DmTftBase.h" - -class DmTftSsd2119 : public DmTftBase -{ -public: -#if defined (DM_TOOLCHAIN_ARDUINO) - DmTftSsd2119(uint8_t cs, uint8_t dc); -#elif defined (DM_TOOLCHAIN_MBED) - DmTftSsd2119(PinName cs, PinName dc, PinName mosi, PinName miso, PinName clk); -#endif - virtual ~DmTftSsd2119(); - virtual void init(void); - virtual void setPixel(uint16_t x, uint16_t y, uint16_t color); - - virtual void setAddress(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1); - virtual void sendData(uint16_t data); - -private: - void send8BitData(uint8_t data); - void writeBus(uint8_t data); - - virtual void sendCommand(uint8_t index); - - - static const uint16_t _width; - static const uint16_t _height; -#if defined (DM_TOOLCHAIN_ARDUINO) - uint8_t _cs, _dc; - regtype *_pinDC; - regsize _bitmaskDC; - uint8_t _spiSettings; -#elif defined (DM_TOOLCHAIN_MBED) - PinName _cs, _dc; - DigitalOut *_pinDC; - SPI spi; -#endif -}; - - -#endif - - -
diff -r 2db7065edbec -r 70127e08ed27 DmTpFt6x06.cpp --- a/DmTpFt6x06.cpp Mon Oct 12 08:35:35 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,215 +0,0 @@ -/********************************************************************************************** - Copyright (c) 2015 DisplayModule. All rights reserved. - - Redistribution and use of this source code, part of this source code or any compiled binary - based on this source code is permitted as long as the above copyright notice and following - disclaimer is retained. - - DISCLAIMER: - THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES - NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. - ********************************************************************************************/ -// Tested with FT6X06 - -#include "DmTpFt6x06.h" -//#define log(...) Serial.println(__VA_ARGS__) -#define log(...) - -#if defined(DM_TOOLCHAIN_ARDUINO) -// disp - which display is used -// useIrq - Enable IRQ or disable IRQ -DmTpFt6x06::DmTpFt6x06(Display disp, bool useIrq) -#elif defined (DM_TOOLCHAIN_MBED) -// disp - which display is used -// &i2c - I2C class -// useIrq - Enable IRQ or disable IRQ -DmTpFt6x06::DmTpFt6x06(Display disp, I2C &i2c, bool useIrq) -#endif -{ - switch (disp) { - case DmTpFt6x06::DM_TFT28_116: - _irq = D2; - break; - default: - _irq = D2; - break; - } - - if (!useIrq) { - _irq = NC; - } -#if defined (DM_TOOLCHAIN_MBED) - _i2c = &i2c; -#endif -} - -void DmTpFt6x06::init() { - log("enter init()"); - -#if defined (DM_TOOLCHAIN_ARDUINO) - Wire.begin(); - Serial.print("Panel ID: "); Serial.println(readRegister8(FT6x06_FOCALTECH_ID)); - Serial.print("Chip ID: "); Serial.println(readRegister8(FT6x06_CHIPER)); - Serial.print("Firmware V: "); Serial.println(readRegister8(FT6x06_FIRMID)); - Serial.print("Point Rate Hz: "); Serial.println(readRegister8(FT6x06_PERIODACTIVE)); - Serial.print("Threshold: "); Serial.println(readRegister8(FT6x06_TH_GROUP)); -#elif defined (DM_TOOLCHAIN_MBED) - _i2c->frequency(400000); -#endif - if (_irq != -1) { // We will use Touch IRQ - enableIrq(); - } - - - log("exit init()"); -} - -void DmTpFt6x06::enableIrq() { - log("enter enableIrq()"); - -#if defined (DM_TOOLCHAIN_ARDUINO) - pinMode(_irq, INPUT); - _pinIrq = portInputRegister(digitalPinToPort(_irq)); - _bitmaskIrq = digitalPinToBitMask(_irq); -#elif defined (DM_TOOLCHAIN_MBED) - _pinIrq = new DigitalIn((PinName)_irq); - _pinIrq->mode(PullUp); -#endif - - log("exit enableIrq()"); -} - -uint8_t DmTpFt6x06::readRegister8(uint8_t reg) { -#if defined (DM_TOOLCHAIN_ARDUINO) - uint8_t x ; - Wire.beginTransmission(FT6x06_ADDR); - Wire.write((byte)reg); - Wire.endTransmission(); - Wire.beginTransmission(FT6x06_ADDR); - Wire.requestFrom((byte)FT6x06_ADDR, (byte)1); - x = Wire.read(); - Wire.endTransmission(); - return x; -#elif defined (DM_TOOLCHAIN_MBED) - char buf[1] = {reg}, data = 0; - _i2c->write(FT6x06_ADDR, buf, 1, true); - _i2c->read(FT6x06_ADDR, &data, 1); - return data; -#endif -} - -void DmTpFt6x06::writeRegister8(uint8_t reg, uint8_t val) { -#if defined (DM_TOOLCHAIN_ARDUINO) - Wire.beginTransmission(FT6x06_ADDR); - Wire.write((byte)reg); - Wire.write((byte)val); - Wire.endTransmission(); -#elif defined (DM_TOOLCHAIN_MBED) - char buf[2] = {reg, val}; - _i2c->write(FT6x06_ADDR, buf, 2); -#endif -} - - -bool DmTpFt6x06::isTouched() { - if (_irq == -1) { - uint8_t val; - val = readRegister8(FT6x06_TD_STATUS); - if ((val == 1) || (val == 2)) return true; - return false; - } - -#if defined (DM_TOOLCHAIN_ARDUINO) - if ( !gbi(_pinIrq, _bitmaskIrq) ) { - return true; - } - return false; -#elif defined (DM_TOOLCHAIN_MBED) - if (!_pinIrq->read()) { - return true; - } - return false; -#endif -} - - -void DmTpFt6x06::readTouchData(uint16_t& posX, uint16_t& posY, bool& touching) { -#if defined (DM_TOOLCHAIN_ARDUINO) - uint8_t buf[16]; - Wire.beginTransmission(FT6x06_ADDR); - Wire.write((byte)0); - Wire.endTransmission(); - Wire.beginTransmission(FT6x06_ADDR); - Wire.requestFrom((byte)FT6x06_ADDR, (byte)16); - for (uint8_t i=0; i<16; i++) - buf[i] = Wire.read(); - Wire.endTransmission(); - - posX = buf[3] & 0x0F; - posX <<= 8; - posX |= buf[4]; - posY = buf[5] & 0x0F; - posY <<= 8; - posY |= buf[6]; -#elif defined (DM_TOOLCHAIN_MBED) - posX = readRegister8(0x03) & 0x0F; - posX <<= 8; - posX |= readRegister8(0x04); - posY = readRegister8(0x05) & 0x0F; - posY <<= 8; - posY |= readRegister8(0x06); - - posX = map(posX, 0, 240, 240, 0); - posY = map(posY, 0, 320, 320, 0); -#endif - touching = isTouched(); -} - -bool DmTpFt6x06::readTouchData(uint16_t& posX, uint16_t& posY) { -#if defined (DM_TOOLCHAIN_ARDUINO) - uint8_t buf[16]; - Wire.beginTransmission(FT6x06_ADDR); - Wire.write((byte)0); - Wire.endTransmission(); - Wire.beginTransmission(FT6x06_ADDR); - Wire.requestFrom((byte)FT6x06_ADDR, (byte)16); - for (uint8_t i=0; i<16; i++) - buf[i] = Wire.read(); - Wire.endTransmission(); - - if(buf[2] > 2){ - posX = 0; - posY = 0; - return false; - } - posX = buf[3] & 0x0F; - posX <<= 8; - posX |= buf[4]; - posY = buf[5] & 0x0F; - posY <<= 8; - posY |= buf[6]; - return true; -#elif defined (DM_TOOLCHAIN_MBED) - if(readRegister8(0x03) > 2){ - posX = 0; - posY = 0; - return false; - } - - posX = readRegister8(0x03) & 0x0F; - posX <<= 8; - posX |= readRegister8(0x04); - posY = readRegister8(0x05) & 0x0F; - posY <<= 8; - posY |= readRegister8(0x06); - - posX = map(posX, 0, 240, 240, 0); - posY = map(posY, 0, 320, 320, 0); - return true; -#endif -} - -long DmTpFt6x06::map(long x, long in_min, long in_max, long out_min, long out_max) -{ - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; -}
diff -r 2db7065edbec -r 70127e08ed27 DmTpFt6x06.h --- a/DmTpFt6x06.h Mon Oct 12 08:35:35 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -/********************************************************************************************** - Copyright (c) 2015 DisplayModule. All rights reserved. - - Redistribution and use of this source code, part of this source code or any compiled binary - based on this source code is permitted as long as the above copyright notice and following - disclaimer is retained. - - DISCLAIMER: - THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES - NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. - ********************************************************************************************/ - -#ifndef DM_TPFT6X06_h -#define DM_TPFT6X06_h - -#include "dm_platform.h" -#if defined (DM_TOOLCHAIN_ARDUINO) -#include <Wire.h> -#elif defined (DM_TOOLCHAIN_MBED) -#include "mbed.h" -#endif - -#if defined (DM_TOOLCHAIN_ARDUINO) -#define FT6x06_ADDR 0x38 -#elif defined (DM_TOOLCHAIN_MBED) -#define FT6x06_ADDR 0x70 -#endif - -#define FT6x06_DEV_MODE 0x00 -#define FT6x06_GEST_ID 0x01 -#define FT6x06_TD_STATUS 0x02 -#define FT6x06_TH_GROUP 0x80 -#define FT6x06_PERIODACTIVE 0x88 -#define FT6x06_CHIPER 0xA3 -#define FT6x06_G_MODE 0xA4 -#define FT6x06_FIRMID 0xA6 -#define FT6x06_FOCALTECH_ID 0xA8 -#define FT6x06_RELEASE_CODE_ID 0xAF - -#define WAIT_ACK_TIMEOUT 100 -#define COM_OK 0 -#define ACK_ERROR 1 - -class DmTpFt6x06 -{ -public: - enum Display { - DM_TFT28_116 = 116, - }; - -#if defined (DM_TOOLCHAIN_ARDUINO) - DmTpFt6x06(Display disp, bool useIrq=true); -#elif defined (DM_TOOLCHAIN_MBED) - DmTpFt6x06(Display disp, I2C &i2c, bool useIrq=true); -#endif - void init(); - void readTouchData(uint16_t& posX, uint16_t& posY, bool& touching); - bool readTouchData(uint16_t& posX, uint16_t& posY); - bool isTouched(); - -private: - uint8_t readRegister8(uint8_t reg); - void writeRegister8(uint8_t reg, uint8_t val); - void enableIrq(); -#if defined (DM_TOOLCHAIN_ARDUINO) - int8_t _irq; - regtype *_pinIrq; - regsize _bitmaskIrq; -#elif defined (DM_TOOLCHAIN_MBED) - PinName _irq; - long map(long x, long in_min, long in_max, long out_min, long out_max); - DigitalIn *_pinIrq; - I2C *_i2c; -#endif -}; -#endif