Modified version of the DmTftLibrary, optimized for the LPC4088 Experiment Base Board

Dependents:   lpc4088_ebb_dm_calc lpc4088_ebb_dm_bubbles

Fork of DmTftLibrary by Display Module

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DmTouch.h Source File

DmTouch.h

00001 /**********************************************************************************************
00002  Copyright (c) 2014 DisplayModule. All rights reserved.
00003 
00004  Redistribution and use of this source code, part of this source code or any compiled binary
00005  based on this source code is permitted as long as the above copyright notice and following
00006  disclaimer is retained.
00007 
00008  DISCLAIMER:
00009  THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES
00010  NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE.
00011  ********************************************************************************************/
00012 
00013 #ifndef DM_TOUCH_h
00014 #define DM_TOUCH_h
00015 
00016 #include "dm_platform.h"
00017 
00018 typedef struct calibrationMatrix {
00019   int32_t  a, b, c, d, e, f;
00020 } CalibrationMatrix;
00021 
00022 class DmTouch
00023 {
00024 public:
00025   enum Display {
00026     DM_TFT28_103 = 103,
00027     DM_TFT24_104 = 104,
00028     DM_TFT28_105 = 105,
00029     DM_TFT35_107 = 107
00030   };
00031 
00032   enum SpiMode {
00033     Auto,
00034     Software,
00035     Hardware
00036   };
00037 
00038 #if defined (DM_TOOLCHAIN_ARDUINO)
00039   DmTouch(Display disp, SpiMode spiMode=Auto, bool useIrq=true);
00040 #elif defined (DM_TOOLCHAIN_MBED)
00041   DmTouch(Display disp, SpiMode spiMode=Hardware);
00042 #endif
00043   void init();
00044   void readTouchData(uint16_t& posX, uint16_t& posY, bool& touching);
00045   bool isTouched();
00046   bool getMiddleXY(uint16_t &x, uint16_t &y); // Raw Touch Data, used for calibration
00047   void setCalibrationMatrix(CalibrationMatrix calibrationMatrix);
00048   void setPrecison(uint8_t samplesPerMeasurement);
00049   void waitForTouch();
00050   void waitForTouchRelease();
00051   uint32_t rescaleFactor() { return 1000000; };
00052   Display getDisplay() { return _disp; };
00053 
00054 private:
00055   void spiWrite(uint8_t data);
00056   uint8_t spiRead();
00057   uint16_t readData12(uint8_t command);
00058   void enableIrq();
00059   void readRawData(uint16_t &x, uint16_t &y);
00060   void getAverageXY(uint16_t &x, uint16_t &y);
00061   uint16_t getDisplayCoordinateX(uint16_t x_touch, uint16_t y_touch);
00062   uint16_t getDisplayCoordinateY(uint16_t x_touch, uint16_t y_touch);
00063   uint16_t calculateMiddleValue(uint16_t values[], uint8_t count);
00064   bool isSampleValid();
00065 
00066   Display _disp;
00067   uint16_t _width, _height;
00068   bool _hardwareSpi;
00069   uint8_t _samplesPerMeasurement;
00070   CalibrationMatrix _calibrationMatrix;
00071   uint8_t _cs, _clk, _mosi, _miso;
00072   int8_t _irq;
00073 
00074 #if defined (DM_TOOLCHAIN_ARDUINO)
00075   regtype *_pinDC, *_pinCS, *_pinCLK, *_pinMOSI, *_pinMISO, *_pinIrq;
00076   regsize _bitmaskDC, _bitmaskCS, _bitmaskCLK, _bitmaskMOSI, _bitmaskMISO, _bitmaskIrq;
00077   uint8_t _spiSettings;
00078 #elif defined (DM_TOOLCHAIN_MBED)
00079   DigitalOut *_pinDC, *_pinCS, *_pinCLK, *_pinMOSI, *_led;
00080   DigitalIn *_pinMISO;
00081   SPI *_spi;
00082 #endif
00083 
00084 };
00085 #endif