Driver Library for our displays
Dependents: dm_bubbles dm_calc dm_paint dm_sdcard_with_adapter ... more
Revision 0:d6ff5fa503e8, committed 2014-05-13
- Comitter:
- displaymodule
- Date:
- Tue May 13 09:31:24 2014 +0000
- Child:
- 1:eab9854e0710
- Commit message:
- First version
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DmTftBase.cpp Tue May 13 09:31:24 2014 +0000 @@ -0,0 +1,334 @@ +/********************************************************************************************** + 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. + ********************************************************************************************/ + +#include "DmTftBase.h" + +#define FONT_CHAR_WIDTH 8 +#define FONT_CHAR_HEIGHT 16 +extern uint8_t font[]; + +/* + * Macro to read the 8 bits representing one line of a character. + * The macro is needed as the reading is handled differently on + * Arduino and Mbed platforms. + */ +#if defined (DM_TOOLCHAIN_ARDUINO) + #define read_font_line(__char, __line) \ + pgm_read_byte(&font[((uint16_t)(__char))*FONT_CHAR_HEIGHT+(__line)]) +#elif defined (DM_TOOLCHAIN_MBED) + #define read_font_line(__char, __line) \ + font[((uint16_t)(__char))*FONT_CHAR_HEIGHT+(__line)] +#endif + + +void DmTftBase::setPixel(uint16_t x, uint16_t y, uint16_t color) { + cbi(_pinCS, _bitmaskCS); + + setAddress(x, y, x, y); + + sendData(color); + sbi(_pinCS, _bitmaskCS); +} + +void DmTftBase::clearScreen(uint16_t color) { + cbi(_pinCS, _bitmaskCS); + + setAddress(0,0,_width-1, _height-1); + + for(uint16_t i=0; i<_height; i++) { + for(uint16_t j=0; j<_width; j++) { + sendData(color); + } + } + + sbi(_pinCS, _bitmaskCS); +} + +void DmTftBase::drawHorizontalLine(uint16_t x, uint16_t y, uint16_t length, uint16_t color) { + cbi(_pinCS, _bitmaskCS); + + setAddress(x, y, x + length, y); + + for (int i = 0; i <= length; i++) { + sendData(color); + } + + sbi(_pinCS, _bitmaskCS); +} + +void DmTftBase::drawVerticalLine(uint16_t x, uint16_t y, uint16_t length, uint16_t color) { + cbi(_pinCS, _bitmaskCS); + + setAddress(x, y, x, y + length); + + for (int i = 0; i <= length; i++) { + sendData(color); + } + + sbi(_pinCS, _bitmaskCS); +} + +void DmTftBase::drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) { + int x = x1-x0; + int y = y1-y0; + int dx = abs(x), sx = x0<x1 ? 1 : -1; + int dy = -abs(y), sy = y0<y1 ? 1 : -1; + int err = dx+dy, e2; /* error value e_xy */ + for (;;) { + setPixel(x0,y0,color); + e2 = 2*err; + if (e2 >= dy) { /* e_xy+e_x > 0 */ + if (x0 == x1) { + break; + } + err += dy; x0 += sx; + } + if (e2 <= dx) { /* e_xy+e_y < 0 */ + if (y0 == y1) { + break; + } + err += dx; y0 += sy; + } + } +} + +void DmTftBase::drawRectangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) { + // Make sure x0,y0 are in the top left corner + if(x0 > x1) { + x0 = x0^x1; + x1 = x0^x1; + x0 = x0^x1; + } + if(y0 > y1) { + y0 = y0^y1; + y1 = y0^y1; + y0 = y0^y1; + } + + drawHorizontalLine(x0, y0, x1-x0, color); + drawHorizontalLine(x0, y1, x1-x0, color); + drawVerticalLine(x0, y0, y1-y0, color); + drawVerticalLine(x1, y0, y1-y0, color); +} + +void DmTftBase::fillRectangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) { + unsigned long numPixels=0; + unsigned long i=0; + + // Make sure x0,y0 are in the top left corner + if(x0 > x1) { + x0 = x0^x1; + x1 = x0^x1; + x0 = x0^x1; + } + if(y0 > y1) { + y0 = y0^y1; + y1 = y0^y1; + y0 = y0^y1; + } + + x0 = constrain(x0, 0, _width-1); + x1 = constrain(x1, 0, _width-1); + y0 = constrain(y0, 0, _height-1); + y1 = constrain(y1, 0, _height-1); + + numPixels = (x1-x0+1); + numPixels = numPixels*(y1-y0+1); + + cbi(_pinCS, _bitmaskCS); + setAddress(x0,y0,x1,y1);/* start to write to display ra */ + + for(i=0; i < numPixels; i++) { + sendData(color); + } + + sbi(_pinCS, _bitmaskCS); +} + +void DmTftBase::drawCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color) { + int x = -r, y = 0, err = 2-2*r, e2; + do { + setPixel(x0-x, y0+y, color); + setPixel(x0+x, y0+y, color); + setPixel(x0+x, y0-y, color); + setPixel(x0-x, y0-y, color); + e2 = err; + if (e2 <= y) { + err += ++y*2+1; + if (-x == y && e2 <= x) { + e2 = 0; + } + } + if (e2 > x) { + err += ++x * 2 + 1; + } + } while (x <= 0); +} + +void DmTftBase::fillCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color) { + int x = -r, y = 0, err = 2-2*r, e2; + do { + drawVerticalLine(x0-x, y0-y, 2*y, color); + drawVerticalLine(x0+x, y0-y, 2*y, color); + + e2 = err; + if (e2 <= y) { + err += ++y * 2 + 1; + if (-x == y && e2 <= x) { + e2 = 0; + } + } + if (e2 > x) { + err += ++x*2+1; + } + } while (x <= 0); +} + +void DmTftBase::drawTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) { + drawLine(x0, y0, x1, y1, color); + drawLine(x0, y0, x2, y2, color); + drawLine(x1, y1, x2, y2, color); +} + +void DmTftBase::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 DmTftBase::drawChar(uint16_t x, uint16_t y, char ch, bool transparent) { + cbi(_pinCS, _bitmaskCS); + + uint8_t temp; + uint8_t pos,t; + + if ((x > (_width - FONT_CHAR_WIDTH)) || (y > (_height - FONT_CHAR_HEIGHT))) { + return; + } + + ch=ch-' '; + if (!transparent) { // Clear background + setAddress(x,y,x+FONT_CHAR_WIDTH-1,y+FONT_CHAR_HEIGHT-1); + for(pos=0;pos<FONT_CHAR_HEIGHT;pos++) { + temp = read_font_line(ch, pos); + for(t=0;t<FONT_CHAR_WIDTH;t++) { + if (temp & 0x01) { + sendData(_fgColor); + } + else { + sendData(_bgColor); + } + temp>>=1; + } + y++; + } + } + else { //Draw directly without clearing background + for(pos=0;pos<FONT_CHAR_HEIGHT;pos++) { + temp = read_font_line(ch, pos); + for(t=0;t<FONT_CHAR_WIDTH;t++) { + if (temp & 0x01) { + setAddress(x + t, y + pos, x + t, y + pos); + sendData(_fgColor); + //drawPoint(x + t, y + pos); + } + temp>>=1; + } + } + } + + sbi(_pinCS, _bitmaskCS); +} + +void DmTftBase::drawNumber(uint16_t x, uint16_t y, int num, int digitsToShow, bool leadingZeros) { + bool minus = false; + if (num < 0) { + num = -num; + minus = true; + } + for (int i = 0; i < digitsToShow; i++) { + char c = ' '; + if ((num == 0) && (i > 0)) { + if (leadingZeros) { + c = '0'; + if (minus && (i == (digitsToShow-1))) { + c = '-'; + } + } else if (minus) { + c = '-'; + minus = false; + } + } else { + c = '0' + (num % 10); + } + drawChar(x + FONT_CHAR_WIDTH*(digitsToShow - i - 1), y, c, false); + num = num / 10; + } +} + +void DmTftBase::drawString(uint16_t x, uint16_t y, const char *p) { + while(*p!='\0') + { + if(x > (_width - FONT_CHAR_WIDTH)) { + x = 0; + y += FONT_CHAR_HEIGHT; + } + if(y > (_height - FONT_CHAR_HEIGHT)) { + y = x = 0; + } + drawChar(x, y, *p, false); + x += FONT_CHAR_WIDTH; + p++; + } +} + +void DmTftBase::drawStringCentered(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const char *p) { + int len = strlen(p); + uint16_t tmp = len * FONT_CHAR_WIDTH; + if (tmp <= width) { + x += (width - tmp)/2; + } + if (FONT_CHAR_HEIGHT <= height) { + y += (height - FONT_CHAR_HEIGHT)/2; + } + drawString(x, y, p); +} + +void DmTftBase::drawImage(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t* data) { + const uint16_t* p = data; + + cbi(_pinCS, _bitmaskCS); + + setAddress(x,y,x+width-1,y+height-1); + for (int i = width*height; i > 0; i--) { + sendData(*p); + p++; + } + + sbi(_pinCS, _bitmaskCS); +} + +void DmTftBase::select(){ + cbi(_pinCS, _bitmaskCS); +} + +void DmTftBase::unSelect() { + sbi(_pinCS, _bitmaskCS); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DmTftBase.h Tue May 13 09:31:24 2014 +0000 @@ -0,0 +1,95 @@ +/********************************************************************************************** + 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 DMTFTBASE_h +#define DMTFTBASE_h + +#include "dm_platform.h" + + +//Basic Colors +#define RED 0xf800 +#define GREEN 0x07e0 +#define BLUE 0x001f +#define BLACK 0x0000 +#define YELLOW 0xffe0 +#define WHITE 0xffff + +//Other Colors +#define CYAN 0x07ff +#define BRIGHT_RED 0xf810 +#define GRAY1 0x8410 +#define GRAY2 0x4208 + + +class DmTftBase { +public: + DmTftBase(const uint16_t width, const uint16_t height) : _width(width), _height(height){}; + virtual ~DmTftBase() { }; + + uint16_t width() { return _width; } + uint16_t height() { return _height; } + + void setTextColor(uint16_t background, uint16_t foreground) { _bgColor = background; _fgColor = foreground; } + + 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) = 0; + virtual void sendData(uint16_t data) = 0; + + void clearScreen(uint16_t color = BLACK); + + 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 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 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 drawPoint(uint16_t x, uint16_t y, uint16_t radius=0); + + void drawChar(uint16_t x, uint16_t y, char ch, bool transparent); + 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 drawImage(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t* data); + + void select(); + void unSelect(); +protected: + virtual void sendCommand(uint8_t index) = 0; + +#if defined (DM_TOOLCHAIN_ARDUINO) + regtype *_pinCS; + regsize _bitmaskCS; +#elif defined (DM_TOOLCHAIN_MBED) + DigitalOut* _pinCS; + uint8_t _bitmaskCS; +#endif + +private: + const uint16_t _width; + const uint16_t _height; + + uint16_t _bgColor; + uint16_t _fgColor; +}; +#endif + + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DmTftHX8353C.cpp Tue May 13 09:31:24 2014 +0000 @@ -0,0 +1,245 @@ +/********************************************************************************************** + 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. + ********************************************************************************************/ + +#include "DmTftHX8353C.h" + +DmTftHX8353C::DmTftHX8353C(uint8_t mosi, uint8_t clk, uint8_t cs, uint8_t dc, uint8_t rst) : DmTftBase(128,160) { + _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((PinName)_mosi); + _pinCLK = new DigitalOut((PinName)_clk); + _pinCS = new DigitalOut((PinName)_cs); + _pinDC = new DigitalOut((PinName)_dc); + _pinRST = new DigitalOut((PinName)_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 +*********************************************************************************************************/ + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DmTftHX8353C.h Tue May 13 09:31:24 2014 +0000 @@ -0,0 +1,45 @@ +/********************************************************************************************** + 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: + DmTftHX8353C(uint8_t mosi=D2, uint8_t clk=D3, uint8_t cs=D4, uint8_t dc=D5, uint8_t rst=D6); + virtual ~DmTftHX8353C(); + 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); + + uint8_t _mosi, _clk, _cs, _dc, _rst; + static const uint16_t _width; + static const uint16_t _height; +#if defined (DM_TOOLCHAIN_ARDUINO) + regtype *_pinDC, *_pinRST, *_pinMOSI, *_pinCLK; + regsize _bitmaskDC, _bitmaskRST, _bitmaskMOSI, _bitmaskCLK; +#elif defined (DM_TOOLCHAIN_MBED) + DigitalOut* _pinDC, *_pinRST, *_pinMOSI, *_pinCLK; +#endif +}; +#endif + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DmTftIli9325.cpp Tue May 13 09:31:24 2014 +0000 @@ -0,0 +1,199 @@ +/********************************************************************************************** + 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. + ********************************************************************************************/ +#include "DmTftIli9325.h" + +DmTftIli9325::DmTftIli9325(uint8_t wr, uint8_t cs, uint8_t dc, uint8_t rst) : DmTftBase(240, 320) { + _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; +#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((PinName)_rst); + _pinCS = new DigitalOut((PinName)_cs); + _pinWR = new DigitalOut((PinName)_wr); + _pinDC = new DigitalOut((PinName)_dc); + #ifdef LPC15XX_H + _virtualPortD = new BusOut(D0, D1, D2, D3, D4, P0_11, D6, D7); + #else + _virtualPortD = new BusOut(D0, D1, D2, D3, D4, D5, D6, D7); + #endif +#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); + + clearScreen(); +} + +/********************************************************************************************************* + END FILE +*********************************************************************************************************/ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DmTftIli9325.h Tue May 13 09:31:24 2014 +0000 @@ -0,0 +1,46 @@ +/********************************************************************************************** + 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: + DmTftIli9325(uint8_t wr=A4, uint8_t cs=A3, uint8_t dc=A5, uint8_t rst=A2); + virtual ~DmTftIli9325(); + 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); + + uint8_t _wr, _cs, _dc, _rst; + static const uint16_t _width; + static const uint16_t _height; +#if defined (DM_TOOLCHAIN_ARDUINO) + regtype *_pinDC, *_pinRST, *_pinWR; + regsize _bitmaskDC, _bitmaskRST, _bitmaskWR; +#elif defined (DM_TOOLCHAIN_MBED) + DigitalOut* _pinDC, *_pinRST, *_pinWR; + BusOut *_virtualPortD; +#endif +}; +#endif + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DmTftIli9341.cpp Tue May 13 09:31:24 2014 +0000 @@ -0,0 +1,236 @@ +/********************************************************************************************** + 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. + ********************************************************************************************/ + +#include "DmTftIli9341.h" +#if defined (DM_TOOLCHAIN_ARDUINO) +DmTftIli9341::DmTftIli9341(uint8_t cs, uint8_t dc) +#elif defined (DM_TOOLCHAIN_MBED) +DmTftIli9341::DmTftIli9341(uint8_t cs, uint8_t dc, uint8_t miso, uint8_t mosi, uint8_t clk) +#endif +: DmTftBase(240, 320){ + _cs = cs; + _dc = dc; +#if defined (DM_TOOLCHAIN_MBED) + _miso = miso; + _mosi = mosi; + _clk = clk; +#endif +} + +DmTftIli9341::~DmTftIli9341() { +#if defined (DM_TOOLCHAIN_MBED) +delete _pinCS; +delete _pinDC; +delete _spi; + +_pinCS = NULL; +_pinDC = NULL; +_spi = NULL; +#endif +} + +void DmTftIli9341::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 DmTftIli9341::sendCommand(uint8_t index) { + // cbi(_pinCS, _bitmaskCS); + cbi(_pinDC, _bitmaskDC); + + writeBus(index); + // sbi(_pinCS, _bitmaskCS); +} + +void DmTftIli9341::send8BitData(uint8_t data) { + //cbi(_pinCS, _bitmaskCS); + sbi(_pinDC, _bitmaskDC); + writeBus(data); + //sbi(_pinCS, _bitmaskCS); +} + +void DmTftIli9341::sendData(uint16_t data) { + uint8_t dh = data>>8; + uint8_t dl = data&0xff; + + //cbi(_pinCS, _bitmaskCS); + sbi(_pinDC, _bitmaskDC); + writeBus(dh); + writeBus(dl); + //sbi(_pinCS, _bitmaskCS); +} + +void DmTftIli9341::setAddress(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { + sendCommand(0x2A); // Set Column + sendData(x0); + sendData(x1); + + sendCommand(0x2B); // Set Page + sendData(y0); + sendData(y1); + + sendCommand(0x2c); +} + +void DmTftIli9341::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((PinName)_cs); + _pinDC = new DigitalOut((PinName)_dc); + sbi(_pinCS, _bitmaskCS); + + _spi = new SPI((PinName)_mosi, (PinName)_miso, (PinName)_clk); + _spi->format(8,0); + _spi->frequency(8000000); // Max SPI speed for display is 10 and for 17 for LPC15xx +#endif + cbi(_pinCS, _bitmaskCS); + delay(135); // This much delay needed?? + + // ILI9341 init + sendCommand(0x11); + delay(120); + + sendCommand(0xCF); + send8BitData(0x00); + send8BitData(0xc3); + send8BitData(0X30); + + sendCommand(0xED); + send8BitData(0x64); + send8BitData(0x03); + send8BitData(0X12); + send8BitData(0X81); + + sendCommand(0xE8); + send8BitData(0x85); + send8BitData(0x10); + send8BitData(0x79); + + sendCommand(0xCB); + send8BitData(0x39); + send8BitData(0x2C); + send8BitData(0x00); + send8BitData(0x34); + send8BitData(0x02); + + sendCommand(0xF7); + send8BitData(0x20); + + sendCommand(0xEA); + send8BitData(0x00); + send8BitData(0x00); + + sendCommand(0xC0); //Power control + send8BitData(0x22); //VRH[5:0] + + sendCommand(0xC1); //Power control + send8BitData(0x11); //SAP[2:0];BT[3:0] + + sendCommand(0xC5); //VCM control + send8BitData(0x3d); + send8BitData(0x20); + + sendCommand(0xC7); //VCM control2 + send8BitData(0xAA); //0xB0 + + sendCommand(0x36); // Memory Access Control + send8BitData(0x08); + + sendCommand(0x3A); + send8BitData(0x55); + + sendCommand(0xB1); + send8BitData(0x00); + send8BitData(0x13); + + sendCommand(0xB6); // Display Function Control + send8BitData(0x0A); + send8BitData(0xA2); + + sendCommand(0xF6); + send8BitData(0x01); + send8BitData(0x30); + + sendCommand(0xF2); // 3Gamma Function Disable + send8BitData(0x00); + + sendCommand(0x26); //Gamma curve selected + send8BitData(0x01); + + sendCommand(0xE0); //Set Gamma + send8BitData(0x0F); + send8BitData(0x3F); + send8BitData(0x2F); + send8BitData(0x0C); + send8BitData(0x10); + send8BitData(0x0A); + send8BitData(0x53); + send8BitData(0XD5); + send8BitData(0x40); + send8BitData(0x0A); + send8BitData(0x13); + send8BitData(0x03); + send8BitData(0x08); + send8BitData(0x03); + send8BitData(0x00); + + sendCommand(0XE1); //Set Gamma + send8BitData(0x00); + send8BitData(0x00); + + send8BitData(0x10); + send8BitData(0x03); + send8BitData(0x0F); + send8BitData(0x05); + send8BitData(0x2C); + send8BitData(0xA2); + send8BitData(0x3F); + send8BitData(0x05); + send8BitData(0x0E); + send8BitData(0x0C); + send8BitData(0x37); + send8BitData(0x3C); + send8BitData(0x0F); + + sendCommand(0x11); //Exit Sleep + delay(120); + sendCommand(0x29); //Display on + delay(50); + sbi(_pinCS, _bitmaskCS); + clearScreen(); +} + +/********************************************************************************************************* + END FILE +*********************************************************************************************************/ + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DmTftIli9341.h Tue May 13 09:31:24 2014 +0000 @@ -0,0 +1,54 @@ +/********************************************************************************************** + 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_ILI9341_h +#define DM_TFT_ILI9341_h + +#include "DmTftBase.h" + +class DmTftIli9341 : public DmTftBase +{ +public: +#if defined (DM_TOOLCHAIN_ARDUINO) + DmTftIli9341(uint8_t cs, uint8_t dc); +#elif defined (DM_TOOLCHAIN_MBED) + DmTftIli9341(uint8_t cs=D10, uint8_t dc=D9, uint8_t miso=D12, uint8_t mosi=D11, uint8_t clk=D13); +#endif + virtual ~DmTftIli9341(); + 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); + + uint8_t _cs, _dc; + static const uint16_t _width; + static const uint16_t _height; +#if defined (DM_TOOLCHAIN_ARDUINO) + regtype *_pinDC; + regsize _bitmaskDC; + uint8_t _spiSettings; +#elif defined (DM_TOOLCHAIN_MBED) + uint8_t _miso, _mosi, _clk; + DigitalOut *_pinDC; + SPI *_spi; +#endif +}; + + +#endif + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DmTftS6D0164.cpp Tue May 13 09:31:24 2014 +0000 @@ -0,0 +1,195 @@ +/********************************************************************************************** + 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. + ********************************************************************************************/ + +#include "DmTftS6D0164.h" + +DmTftS6D0164::DmTftS6D0164(uint8_t wr, uint8_t cs, uint8_t dc, uint8_t rst) : DmTftBase(176, 220) { + _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((PinName)_rst); + _pinCS = new DigitalOut((PinName)_cs); + _pinWR = new DigitalOut((PinName)_wr); + _pinDC = new DigitalOut((PinName)_dc); + #ifdef LPC15XX_H + _virtualPortD = new BusOut(D0, D1, D2, D3, D4, P0_11, D6, D7); + #else + _virtualPortD = new BusOut(D0, D1, D2, D3, D4, D5, D6, D7); + #endif +#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 +*********************************************************************************************************/ + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DmTftS6D0164.h Tue May 13 09:31:24 2014 +0000 @@ -0,0 +1,46 @@ +/********************************************************************************************** + 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: + DmTftS6D0164(uint8_t wr=A4, uint8_t cs=A3, uint8_t dc=A5, uint8_t rst=A2); + virtual ~DmTftS6D0164(); + 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); + + uint8_t _wr, _cs, _dc, _rst; + static const uint16_t _width; + static const uint16_t _height; +#if defined (DM_TOOLCHAIN_ARDUINO) + regtype *_pinDC, *_pinRST, *_pinWR; + regsize _bitmaskDC, _bitmaskRST, _bitmaskWR; +#elif defined (DM_TOOLCHAIN_MBED) + DigitalOut* _pinDC, *_pinRST, *_pinWR; + BusOut *_virtualPortD; +#endif +}; +#endif + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DmTftSsd2119.cpp Tue May 13 09:31:24 2014 +0000 @@ -0,0 +1,267 @@ +/********************************************************************************************** + 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. + ********************************************************************************************/ + +#include "DmTftSsd2119.h" +#if defined (DM_TOOLCHAIN_ARDUINO) +DmTftSsd2119::DmTftSsd2119(uint8_t cs, uint8_t dc) +#elif defined (DM_TOOLCHAIN_MBED) +DmTftSsd2119::DmTftSsd2119(uint8_t cs, uint8_t dc, uint8_t miso, uint8_t mosi, uint8_t clk) +#endif +: DmTftBase(320, 240){ // Display is in landscape mode by default width: 320, height: 240 + _cs = cs; + _dc = dc; +#if defined (DM_TOOLCHAIN_MBED) + _miso = miso; + _mosi = mosi; + _clk = clk; +#endif +} + +DmTftSsd2119::~DmTftSsd2119() { +#if defined (DM_TOOLCHAIN_MBED) +delete _pinCS; +delete _pinDC; +delete _spi; + +_pinCS = NULL; +_pinDC = NULL; +_spi = 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(_pinCS, _bitmaskCS); + cbi(_pinDC, _bitmaskDC); + + writeBus(0x00); // Temp + writeBus(index); + // sbi(_pinCS, _bitmaskCS); +} + +void DmTftSsd2119::send8BitData(uint8_t data) { + //cbi(_pinCS, _bitmaskCS); + sbi(_pinDC, _bitmaskDC); + writeBus(data); + //sbi(_pinCS, _bitmaskCS); +} + +void DmTftSsd2119::sendData(uint16_t data) { + uint8_t dh = data>>8; + uint8_t dl = data&0xff; + + //cbi(_pinCS, _bitmaskCS); + sbi(_pinDC, _bitmaskDC); + writeBus(dh); + writeBus(dl); + //sbi(_pinCS, _bitmaskCS); +} + +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((PinName)_cs); + _pinDC = new DigitalOut((PinName)_dc); + sbi(_pinCS, _bitmaskCS); + + _spi = new SPI((PinName)_mosi, (PinName)_miso, (PinName)_clk); + _spi->format(8,0); + _spi->frequency(8000000); // Max SPI speed for display is 10 and for 17 for LPC15xx +#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 +*********************************************************************************************************/ + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DmTftSsd2119.h Tue May 13 09:31:24 2014 +0000 @@ -0,0 +1,57 @@ +/********************************************************************************************** + 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 (__AVR__) + DmTftSsd2119(uint8_t cs, uint8_t dc); +#elif defined (TOOLCHAIN_ARM_MICRO) + DmTftSsd2119(uint8_t cs=D10, uint8_t dc=D9, uint8_t miso=D12, uint8_t mosi=D11, uint8_t clk=D13); +#endif + virtual ~DmTftSsd2119(); + 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); + + uint8_t _cs, _dc; + static const uint16_t _width; + static const uint16_t _height; +#if defined (DM_TOOLCHAIN_ARDUINO) + regtype *_pinDC; + regsize _bitmaskDC; + uint8_t _spiSettings; +#elif defined (DM_TOOLCHAIN_MBED) + uint8_t _miso, _mosi, _clk; + DigitalOut *_pinDC; + SPI *_spi; +#endif +}; + + +#endif + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DmTouch.cpp Tue May 13 09:31:24 2014 +0000 @@ -0,0 +1,349 @@ +/********************************************************************************************** + 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 with Xpt2046 + +#include "DmTouch.h" + +#if defined(DM_TOOLCHAIN_ARDUINO) +// disp - which display is used +// cs - pin number CS (Chip Select, SS) +// irq - pin number IRQ (set to -1 if you don't want to use) +// hardwareSpi - set to 1 if you want to use hardware Spi, 0 otherwise +// (note, if you use hardware Spi on arduino, clk, mosi and miso will be disregarded) +// clk - pin number CLK (SLK) +// mosi - pin number MOSI +// miso - pin number MISO +// width - width of display (default 240) +// height - height of display (default 320) +DmTouch::DmTouch(Display disp, int8_t cs, int8_t irq, int8_t hardwareSpi, int8_t clk, int8_t mosi, int8_t miso, uint16_t width, uint16_t height) : _width(width), _height(height) +{ + _hardwareSpi = hardwareSpi; + _cs = cs; + _irq = irq; + _clk = clk; + _mosi = mosi; + _miso = miso; + +#elif defined (DM_TOOLCHAIN_MBED) +// disp - which display is used +DmTouch::DmTouch(Display disp, bool hardwareSPI) +{ + _hardwareSpi = hardwareSPI; + switch (disp) { + // Display with 40-pin connector on top of adapter board + case DmTouch::DM_TFT28_103: + case DmTouch::DM_TFT24_104: + _cs = D8; + _irq = D10; + _clk = A1; + _mosi = A0; + _miso = D9; + _width = 240; + _height = 320; + break; + + case DmTouch::DM_TFT28_105: + _cs = D4; + _irq = D2; + _clk = D13; + _mosi = D11; + _miso = D12; + _width = 240; + _height = 320; + break; + + case DmTouch::DM_TFT35_107: + default: + _cs = D4; + _irq = D2; + _clk = D13; + _mosi = D11; + _miso = D12; + _width = 320; + _height = 240; + break; + } +#endif + + // Calibration data for the different displays + switch (disp) { + case DmTouch::DM_TFT28_103: + _calibLowX = 220; + _calibLowY = 220; + _calibModifierX = 15.25; + _calibModifierY = 11.16; + _calibInvertedTouch = false; + break; + + case DmTouch::DM_TFT24_104: + _calibLowX = 210; + _calibLowY = 280; + _calibModifierX = 15; + _calibModifierY = 11.24; + _calibInvertedTouch = true; + break; + + case DmTouch::DM_TFT35_107: + _calibLowX = 912; + _calibLowY = 422 ; + _calibModifierX = 3.25; + _calibModifierY = 1.175; + _calibInvertedTouch = false; + break; + + case DmTouch::DM_TFT28_105: + default: + _calibLowX = 260; + _calibLowY = 220; + _calibModifierX = 14.42; + _calibModifierY = 10.78; + _calibInvertedTouch = false; + break; + } +} + +void DmTouch::init() { +#if defined (DM_TOOLCHAIN_ARDUINO) + pinMode(_cs, OUTPUT); + _pinCS = portOutputRegister(digitalPinToPort(_cs)); + _bitmaskCS = digitalPinToBitMask(_cs); + + if (_hardwareSpi) { + SPI.begin(); + SPI.setClockDivider(SPI_CLOCK_DIV2); + SPI.setBitOrder(MSBFIRST); + SPI.setDataMode(SPI_MODE0); + _spiSettings = SPCR; + } + else { + pinMode(_clk, OUTPUT); + pinMode(_mosi, OUTPUT); + pinMode(_miso, INPUT); + _pinCLK = portOutputRegister(digitalPinToPort(_clk)); + _bitmaskCLK = digitalPinToBitMask(_clk); + _pinMOSI = portOutputRegister(digitalPinToPort(_mosi)); + _bitmaskMOSI = digitalPinToBitMask(_mosi); + _pinMISO = portInputRegister(digitalPinToPort(_miso)); + _bitmaskMISO = digitalPinToBitMask(_miso); + } +#elif defined (DM_TOOLCHAIN_MBED) + _pinCS = new DigitalOut((PinName)_cs); + if (_hardwareSpi) { + sbi(_pinCS, _bitmaskCS); + _spi = new SPI((PinName)_mosi, (PinName)_miso, (PinName)_clk); + _spi->format(8,0); + _spi->frequency(2000000); // Max SPI speed + //cbi(_pinCS, _bitmaskCS); + } else { + _pinCLK = new DigitalOut((PinName)_clk); + _pinMISO = new DigitalOut((PinName)_miso); + _pinMOSI = new DigitalOut((PinName)_mosi); + } +#endif + + if (_irq != -1) { // We will use Touch IRQ + enableIrq(); + } +} + +void DmTouch::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 + + cbi(_pinCS, _bitmaskCS); + spiWrite(0x80); // Enable PENIRQ + sbi(_pinCS, _bitmaskCS); +} + +void DmTouch::spiWrite(uint8_t data) { +#if defined (DM_TOOLCHAIN_ARDUINO) + if (_hardwareSpi) { + SPCR = _spiSettings; // SPI Control Register + SPDR = data; // SPI Data Register + while(!(SPSR & _BV(SPIF))); // SPI Status Register Wait for transmission to finish + } + else { + uint8_t count=0; + uint8_t temp; + unsigned nop; + temp=data; // really needed? + cbi(_pinCLK, _bitmaskCLK); + for(count=0;count<8;count++) { + if(temp&0x80) { + sbi(_pinMOSI, _bitmaskMOSI); + } + else { + cbi(_pinMOSI, _bitmaskMOSI); + } + + temp=temp<<1; + + pulse_low(_pinCLK, _bitmaskCLK); + } + } +#elif defined (DM_TOOLCHAIN_MBED) + if (_hardwareSpi) { + _spi->write(data); + } + else { + uint8_t count=0; + uint8_t temp = data; + cbi(_pinCLK, _bitmaskCLK); + for(count=0;count<8;count++) { + if(temp&0x80) { + sbi(_pinMOSI, _bitmaskMOSI); + } + else { + cbi(_pinMOSI, _bitmaskMOSI); + } + + temp=temp<<1; + + pulse_low(_pinCLK, _bitmaskCLK); + } + } +#endif +} + +uint8_t DmTouch::spiRead() {// Only used for Hardware SPI +#if defined (DM_TOOLCHAIN_ARDUINO) + uint8_t data; + SPCR = _spiSettings; + spiWrite(0x00); + data = SPDR; + + return data; +#elif defined (DM_TOOLCHAIN_MBED) + if (_hardwareSpi) { + return _spi->write(0x00); // dummy byte to read + } else { + uint8_t count=0; + uint8_t temp=0; + cbi(_pinCLK, _bitmaskCLK); + cbi(_pinMOSI, _bitmaskMOSI); + for(count=0;count<8;count++) { + + pulse_low(_pinCLK, _bitmaskCLK); + temp = temp<<1; + temp |= _pinMISO->read(); + } + return temp; + } +#endif +} + +uint16_t DmTouch::readData12(uint8_t command) { + uint8_t temp = 0; + uint16_t value = 0; + + spiWrite(command); // Send command +//-------------- +#if defined (DM_TOOLCHAIN_ARDUINO) + if (_hardwareSpi) { + // We use 7-bits from the first byte and 5-bit from the second byte + temp = spiRead(); + value = temp<<8; + temp = spiRead(); + value |= temp; + value >>=3; + value &= 0xFFF; + } + else { + pulse_high(_pinCLK, _bitmaskCLK); + unsigned nop; + uint8_t count=0; + for(count=0;count<12;count++) { + value<<=1; + pulse_high(_pinCLK, _bitmaskCLK); + if ( gbi(_pinMISO, _bitmaskMISO) ) { + value++; + } + } + } +#elif defined (DM_TOOLCHAIN_MBED) + // We use 7-bits from the first byte and 5-bit from the second byte + temp = spiRead(); + value = temp<<8; + temp = spiRead(); + value |= temp; + value >>=3; + value &= 0xFFF; +#endif + return value; +} + +void DmTouch::readTouchData(uint16_t& posX, uint16_t& posY, bool& touching) { +#if defined (DM_TOOLCHAIN_MBED) + if (!isTouched()) { + touching = false; + return; + } + //touching = true; +#endif + unsigned int TP_X, TP_Y; + cbi(_pinCS, _bitmaskCS); + + TP_X = readData12(0xD0); + TP_Y = readData12(0x90); + + sbi(_pinCS, _bitmaskCS); + +// Serial.print("Raw X: "); +// Serial.println(TP_X); +// Serial.print("Raw Y: "); +// Serial.println(TP_Y); + + // Convert raw data to screen positions + if (_calibInvertedTouch) { + posX=_width-((TP_X-_calibLowX)/_calibModifierX); + posY=_height-((TP_Y-_calibLowY)/_calibModifierY); + } else { + posX=((TP_X-_calibLowX)/_calibModifierX); + posY=((TP_Y-_calibLowY)/_calibModifierY); + } + +//#if defined (DM_TOOLCHAIN_ARDUINO) + if (posX >= 0 && posX <= _width && posY >= 0 && posY <= _height) { + touching = true; + } else { + touching = false; + } +//#endif +} + +uint8_t DmTouch::isTouched() { +#if defined (DM_TOOLCHAIN_ARDUINO) + if (_irq == -1) { + uint16_t posX, posY; + bool touched; + readTouchData(posX, posY, touched); + return touched; + } + + if ( !gbi(_pinIrq, _bitmaskIrq) ) { + return true; + } + + return false; +#elif defined (DM_TOOLCHAIN_MBED) + return (*_pinIrq == 0); +#endif +} + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DmTouch.h Tue May 13 09:31:24 2014 +0000 @@ -0,0 +1,66 @@ +/********************************************************************************************** + 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_TOUCH_h +#define DM_TOUCH_h + +#include "dm_platform.h" + +class DmTouch +{ +public: + enum Display { + DM_TFT28_103, + DM_TFT24_104, + DM_TFT28_105, + DM_TFT35_107, + }; + +#if defined (DM_TOOLCHAIN_ARDUINO) + DmTouch(Display disp, uint8_t cs, int8_t tIrq = -1, uint8_t hardwareSpi = 1, uint8_t clk = -1, uint8_t mosi = -1, uint8_t miso = -1, uint16_t width = 240, uint16_t height = 320); +#elif defined (DM_TOOLCHAIN_MBED) + DmTouch(Display disp, bool hardwareSPI=true); +#endif + void init(); + void readTouchData(uint16_t& posX, uint16_t& posY, bool& touching); + uint8_t isTouched(); +private: + void spiWrite(uint8_t data); + uint8_t spiRead(); + uint16_t readData12(uint8_t command); + void enableIrq(); + + uint16_t _width, _height; + uint8_t _cs, _clk, _mosi, _miso; + uint8_t _irq; + + int _calibLowX, _calibLowY; + float _calibModifierX, _calibModifierY; + bool _calibInvertedTouch; + bool _hardwareSpi; + +#if defined (DM_TOOLCHAIN_ARDUINO) + regtype *_pinDC, *_pinCS, *_pinCLK, *_pinMOSI, *_pinMISO, *_pinIrq; + regsize _bitmaskDC, _bitmaskCS, _bitmaskCLK, _bitmaskMOSI, _bitmaskMISO, _bitmaskIrq; + uint8_t _spiSettings; +#elif defined (DM_TOOLCHAIN_MBED) + DigitalOut *_pinDC, *_pinCS, *_pinCLK, *_pinMOSI, *_pinMISO, *_led; + DigitalIn *_pinIrq; + SPI *_spi; +#endif + +}; +#endif + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dm_platform.h Tue May 13 09:31:24 2014 +0000 @@ -0,0 +1,99 @@ +#ifndef DM_PLATFORM_h +#define DM_PLATFORM_h + +// Determine type of system +#if defined (__AVR__) + #define DM_TOOLCHAIN_ARDUINO +#elif defined(TOOLCHAIN_ARM) || defined(TOOLCHAIN_ARM_MICRO) + #define DM_TOOLCHAIN_MBED +#else + #error Only Arduino and Mbed toolchains are supported +#endif + +// Arduino +#if defined (DM_TOOLCHAIN_ARDUINO) + + // Mandatory includes for Arduino + #include <Arduino.h> + #include <avr/pgmspace.h> + #include <SPI.h> + + // Clear bit, Set bit, High pulse and Low pulse macros + #define cbi(reg, _bitmask) *reg &= ~_bitmask + #define sbi(reg, _bitmask) *reg |= _bitmask + #define pulse_high(reg, _bitmask) sbi(reg, _bitmask); cbi(reg, _bitmask); + #define pulse_low(reg, _bitmask) cbi(reg, _bitmask); sbi(reg, _bitmask); + + // Map of mandatory pin names, from Arduino names to D* and A* + #define D2 2 + #define D3 3 + #define D4 4 + #define D5 5 + #define D6 6 + #define D9 9 + #define D10 10 + #define A2 16 + #define A3 17 + #define A4 18 + #define A5 19 + + // Needed typedefs, not normally present in the Arduino environment + #ifndef uint8_t + #define uint8_t unsigned char + #endif + #ifndef int8_t + #define int8_t signed char + #endif + #ifndef uint16_t + #define uint16_t unsigned short + #endif + #ifndef uint32_t + #define uint32_t unsigned long + #endif + +// Mbed +#elif defined(DM_TOOLCHAIN_MBED) + + // Mandatory includes for Mbed + #include "mbed.h" + + // Clear bit, Set bit, High pulse, Low pulse, Boundary limits and Delay macros + #define sbi(reg, _bitmask) (*(reg) = 1) + #define cbi(reg, _bitmask) (*(reg) = 0) + #define pulse_high(reg, _bitmask) do { *(reg) = 1; *(reg) = 0; } while(0) + #define pulse_low(reg, _bitmask) do { *(reg) = 0; *(reg) = 1; } while(0) + #define constrain(amt,low,high) ((amt)<=(low)?(low):((amt)>(high)?(high):(amt))) + #define delay(ms) wait_ms(ms) + + // Map of mandatory pin names, from Arduino names to D* and A* + #if defined(__LPC407x_8x_177x_8x_H__) + #define D0 p10 + #define D1 p9 + #define D2 p31 + #define D3 p32 + #define D4 p33 + #define D5 p37 + #define D6 p38 + #define D7 p34 + #define D8 p8 + #define D9 p39 + #define D10 p14 + #define D11 p11 + #define D12 p12 + #define D13 p13 + + #define A0 p15 + #define A1 p16 + #define A2 p17 + #define A3 p18 + #define A4 p19 + #define A5 p20 + #endif + // Special handling for the LPC1549 LPCXpresso board +#ifdef LPC15XX_H + #define D5 P0_11 +#endif +#endif + +#endif /* DM_PLATFORM_h */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/font.c Tue May 13 09:31:24 2014 +0000 @@ -0,0 +1,107 @@ + +#if defined (DM_TOOLCHAIN_ARDUINO) + #include <avr/pgmspace.h> +const unsigned char font[1520] PROGMEM= +#else +const unsigned char font[1520] = +#endif +{ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x18,0x18,0x00,0x00, +0x00,0x48,0x6C,0x24,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x24,0x24,0x24,0x7F,0x12,0x12,0x12,0x7F,0x12,0x12,0x12,0x00,0x00, +0x00,0x00,0x08,0x1C,0x2A,0x2A,0x0A,0x0C,0x18,0x28,0x28,0x2A,0x2A,0x1C,0x08,0x08, +0x00,0x00,0x00,0x22,0x25,0x15,0x15,0x15,0x2A,0x58,0x54,0x54,0x54,0x22,0x00,0x00, +0x00,0x00,0x00,0x0C,0x12,0x12,0x12,0x0A,0x76,0x25,0x29,0x11,0x91,0x6E,0x00,0x00, +0x00,0x06,0x06,0x04,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x40,0x20,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x10,0x10,0x20,0x40,0x00, +0x00,0x02,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x08,0x04,0x02,0x00, +0x00,0x00,0x00,0x00,0x08,0x08,0x6B,0x1C,0x1C,0x6B,0x08,0x08,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x7F,0x08,0x08,0x08,0x08,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x04,0x03, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x00,0x00, +0x00,0x00,0x80,0x40,0x40,0x20,0x20,0x10,0x10,0x08,0x08,0x04,0x04,0x02,0x02,0x00, +0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00, +0x00,0x00,0x00,0x08,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00, +0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x20,0x20,0x10,0x08,0x04,0x42,0x7E,0x00,0x00, +0x00,0x00,0x00,0x3C,0x42,0x42,0x20,0x18,0x20,0x40,0x40,0x42,0x22,0x1C,0x00,0x00, +0x00,0x00,0x00,0x20,0x30,0x28,0x24,0x24,0x22,0x22,0x7E,0x20,0x20,0x78,0x00,0x00, +0x00,0x00,0x00,0x7E,0x02,0x02,0x02,0x1A,0x26,0x40,0x40,0x42,0x22,0x1C,0x00,0x00, +0x00,0x00,0x00,0x38,0x24,0x02,0x02,0x1A,0x26,0x42,0x42,0x42,0x24,0x18,0x00,0x00, +0x00,0x00,0x00,0x7E,0x22,0x22,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00, +0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00, +0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x64,0x58,0x40,0x40,0x24,0x1C,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x04, +0x00,0x00,0x00,0x40,0x20,0x10,0x08,0x04,0x02,0x04,0x08,0x10,0x20,0x40,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x02,0x04,0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x04,0x02,0x00,0x00, +0x00,0x00,0x00,0x3C,0x42,0x42,0x46,0x40,0x20,0x10,0x10,0x00,0x18,0x18,0x00,0x00, +0x00,0x00,0x00,0x1C,0x22,0x5A,0x55,0x55,0x55,0x55,0x2D,0x42,0x22,0x1C,0x00,0x00, +0x00,0x00,0x00,0x08,0x08,0x18,0x14,0x14,0x24,0x3C,0x22,0x42,0x42,0xE7,0x00,0x00, +0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x1E,0x22,0x42,0x42,0x42,0x22,0x1F,0x00,0x00, +0x00,0x00,0x00,0x7C,0x42,0x42,0x01,0x01,0x01,0x01,0x01,0x42,0x22,0x1C,0x00,0x00, +0x00,0x00,0x00,0x1F,0x22,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x22,0x1F,0x00,0x00, +0x00,0x00,0x00,0x3F,0x42,0x12,0x12,0x1E,0x12,0x12,0x02,0x42,0x42,0x3F,0x00,0x00, +0x00,0x00,0x00,0x3F,0x42,0x12,0x12,0x1E,0x12,0x12,0x02,0x02,0x02,0x07,0x00,0x00, +0x00,0x00,0x00,0x3C,0x22,0x22,0x01,0x01,0x01,0x71,0x21,0x22,0x22,0x1C,0x00,0x00, +0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x42,0xE7,0x00,0x00, +0x00,0x00,0x00,0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00, +0x00,0x00,0x00,0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x11,0x0F, +0x00,0x00,0x00,0x77,0x22,0x12,0x0A,0x0E,0x0A,0x12,0x12,0x22,0x22,0x77,0x00,0x00, +0x00,0x00,0x00,0x07,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x42,0x7F,0x00,0x00, +0x00,0x00,0x00,0x77,0x36,0x36,0x36,0x36,0x2A,0x2A,0x2A,0x2A,0x2A,0x6B,0x00,0x00, +0x00,0x00,0x00,0xE3,0x46,0x46,0x4A,0x4A,0x52,0x52,0x52,0x62,0x62,0x47,0x00,0x00, +0x00,0x00,0x00,0x1C,0x22,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x22,0x1C,0x00,0x00, +0x00,0x00,0x00,0x3F,0x42,0x42,0x42,0x42,0x3E,0x02,0x02,0x02,0x02,0x07,0x00,0x00, +0x00,0x00,0x00,0x1C,0x22,0x41,0x41,0x41,0x41,0x41,0x4D,0x53,0x32,0x1C,0x60,0x00, +0x00,0x00,0x00,0x3F,0x42,0x42,0x42,0x3E,0x12,0x12,0x22,0x22,0x42,0xC7,0x00,0x00, +0x00,0x00,0x00,0x7C,0x42,0x42,0x02,0x04,0x18,0x20,0x40,0x42,0x42,0x3E,0x00,0x00, +0x00,0x00,0x00,0x7F,0x49,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x1C,0x00,0x00, +0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00, +0x00,0x00,0x00,0xE7,0x42,0x42,0x22,0x24,0x24,0x14,0x14,0x18,0x08,0x08,0x00,0x00, +0x00,0x00,0x00,0x6B,0x49,0x49,0x49,0x49,0x55,0x55,0x36,0x22,0x22,0x22,0x00,0x00, +0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x18,0x18,0x18,0x24,0x24,0x42,0xE7,0x00,0x00, +0x00,0x00,0x00,0x77,0x22,0x22,0x14,0x14,0x08,0x08,0x08,0x08,0x08,0x1C,0x00,0x00, +0x00,0x00,0x00,0x7E,0x21,0x20,0x10,0x10,0x08,0x04,0x04,0x42,0x42,0x3F,0x00,0x00, +0x00,0x78,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x78,0x00, +0x00,0x00,0x02,0x02,0x04,0x04,0x08,0x08,0x08,0x10,0x10,0x20,0x20,0x20,0x40,0x40, +0x00,0x1E,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1E,0x00, +0x00,0x38,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, +0x00,0x06,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x78,0x44,0x42,0x42,0xFC,0x00,0x00, +0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x1A,0x26,0x42,0x42,0x42,0x26,0x1A,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x44,0x02,0x02,0x02,0x44,0x38,0x00,0x00, +0x00,0x00,0x00,0x60,0x40,0x40,0x40,0x78,0x44,0x42,0x42,0x42,0x64,0xD8,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x7E,0x02,0x02,0x42,0x3C,0x00,0x00, +0x00,0x00,0x00,0xF0,0x88,0x08,0x08,0x7E,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x22,0x22,0x1C,0x02,0x3C,0x42,0x42,0x3C, +0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x3A,0x46,0x42,0x42,0x42,0x42,0xE7,0x00,0x00, +0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x0E,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00, +0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x38,0x20,0x20,0x20,0x20,0x20,0x20,0x22,0x1E, +0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x72,0x12,0x0A,0x16,0x12,0x22,0x77,0x00,0x00, +0x00,0x00,0x00,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x92,0x92,0x92,0x92,0x92,0xB7,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3B,0x46,0x42,0x42,0x42,0x42,0xE7,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1B,0x26,0x42,0x42,0x42,0x22,0x1E,0x02,0x07, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x44,0x42,0x42,0x42,0x44,0x78,0x40,0xE0, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x77,0x4C,0x04,0x04,0x04,0x04,0x1F,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x42,0x02,0x3C,0x40,0x42,0x3E,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x3E,0x08,0x08,0x08,0x08,0x08,0x30,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x63,0x42,0x42,0x42,0x42,0x62,0xDC,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x14,0x08,0x08,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xEB,0x49,0x49,0x55,0x55,0x22,0x22,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x24,0x18,0x18,0x18,0x24,0x6E,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x14,0x18,0x08,0x08,0x07, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x22,0x10,0x08,0x08,0x44,0x7E,0x00,0x00, +0x00,0xC0,0x20,0x20,0x20,0x20,0x20,0x10,0x20,0x20,0x20,0x20,0x20,0x20,0xC0,0x00, +0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, +0x00,0x06,0x08,0x08,0x08,0x08,0x08,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x06,0x00, +0x0C,0x32,0xC2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; + + +