touch screen handler for the microchip AR1020

Committer:
hlipka
Date:
Thu Feb 24 22:05:04 2011 +0000
Revision:
6:a6971458d612
Parent:
4:510ea5b28a05
calibration works now

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 0:cf4dd04052e3 1 /*
hlipka 0:cf4dd04052e3 2 * mbed AR1020 library
hlipka 0:cf4dd04052e3 3 * Copyright (c) 2010 Hendrik Lipka
hlipka 0:cf4dd04052e3 4 *
hlipka 0:cf4dd04052e3 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
hlipka 0:cf4dd04052e3 6 * of this software and associated documentation files (the "Software"), to deal
hlipka 0:cf4dd04052e3 7 * in the Software without restriction, including without limitation the rights
hlipka 0:cf4dd04052e3 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hlipka 0:cf4dd04052e3 9 * copies of the Software, and to permit persons to whom the Software is
hlipka 0:cf4dd04052e3 10 * furnished to do so, subject to the following conditions:
hlipka 0:cf4dd04052e3 11 *
hlipka 0:cf4dd04052e3 12 * The above copyright notice and this permission notice shall be included in
hlipka 0:cf4dd04052e3 13 * all copies or substantial portions of the Software.
hlipka 0:cf4dd04052e3 14 *
hlipka 0:cf4dd04052e3 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hlipka 0:cf4dd04052e3 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hlipka 0:cf4dd04052e3 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
hlipka 0:cf4dd04052e3 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hlipka 0:cf4dd04052e3 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hlipka 0:cf4dd04052e3 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
hlipka 0:cf4dd04052e3 21 * THE SOFTWARE.
hlipka 0:cf4dd04052e3 22 */
hlipka 0:cf4dd04052e3 23
hlipka 0:cf4dd04052e3 24 #ifndef __AR1020_H_
hlipka 0:cf4dd04052e3 25 #define __AR1020_H_
hlipka 0:cf4dd04052e3 26
hlipka 0:cf4dd04052e3 27 #include "mbed.h"
hlipka 0:cf4dd04052e3 28
hlipka 0:cf4dd04052e3 29 #include "touchpanel.h"
hlipka 0:cf4dd04052e3 30 #include "touchevent.h"
hlipka 4:510ea5b28a05 31
hlipka 4:510ea5b28a05 32 /**
hlipka 4:510ea5b28a05 33 class handling all the connections to a AR1020 touch screen controller
hlipka 4:510ea5b28a05 34 SPI is handled by bit-banging, since the SPI-mode is non-standard. Therefore all pins can be used for the connection.
hlipka 4:510ea5b28a05 35 Since the AR1020 seems to be sensitive to the changing pin signals during reset and startup, this library controls the AR1020 power (so it's Vcc must be connected to an mbed pin)
hlipka 4:510ea5b28a05 36 */
hlipka 0:cf4dd04052e3 37 class AR1020: public TouchPanel
hlipka 0:cf4dd04052e3 38 {
hlipka 0:cf4dd04052e3 39 public:
hlipka 0:cf4dd04052e3 40 /**
hlipka 4:510ea5b28a05 41 @params mosi the MOSI pin name (SDI)
hlipka 4:510ea5b28a05 42 @params miso the MISO pin name (SDO)
hlipka 4:510ea5b28a05 43 @params clk the CLK pin (SCL)
hlipka 4:510ea5b28a05 44 @params enable the enable pin name (/CS)
hlipka 4:510ea5b28a05 45 @params siq the SIQ pin name (SIQ)
hlipka 4:510ea5b28a05 46 @params power the power pin name (connected to Vdd - this library does power handling for the AR1020)
hlipka 4:510ea5b28a05 47 */
hlipka 4:510ea5b28a05 48 AR1020(PinName mosi, PinName miso, PinName clk, PinName enable, PinName siq, PinName power);
hlipka 4:510ea5b28a05 49 ~AR1020();
hlipka 4:510ea5b28a05 50
hlipka 4:510ea5b28a05 51 /**
hlipka 4:510ea5b28a05 52 initialize the controller
hlipka 4:510ea5b28a05 53 */
hlipka 4:510ea5b28a05 54 virtual void init();
hlipka 4:510ea5b28a05 55
hlipka 4:510ea5b28a05 56 /**
hlipka 4:510ea5b28a05 57 read X coordinate (from last update)
hlipka 4:510ea5b28a05 58 @returns last known X coordinate
hlipka 0:cf4dd04052e3 59 */
hlipka 0:cf4dd04052e3 60 virtual int x();
hlipka 4:510ea5b28a05 61 /**
hlipka 4:510ea5b28a05 62 read Y coordinate (from last update)
hlipka 4:510ea5b28a05 63 @returns last known Y coordinate
hlipka 4:510ea5b28a05 64 */
hlipka 0:cf4dd04052e3 65 virtual int y();
hlipka 4:510ea5b28a05 66
hlipka 4:510ea5b28a05 67 /**
hlipka 4:510ea5b28a05 68 @return 0 if pen is up, 1 if pen is down
hlipka 4:510ea5b28a05 69 */
hlipka 0:cf4dd04052e3 70 virtual int pen();
hlipka 4:510ea5b28a05 71
hlipka 4:510ea5b28a05 72 /**
hlipka 4:510ea5b28a05 73 read coordinates on request
hlipka 4:510ea5b28a05 74 */
hlipka 0:cf4dd04052e3 75 virtual void read();
hlipka 4:510ea5b28a05 76
hlipka 4:510ea5b28a05 77 /**
hlipka 4:510ea5b28a05 78 execute touch screen calibration
hlipka 4:510ea5b28a05 79 */
hlipka 0:cf4dd04052e3 80 void calibrate();
hlipka 0:cf4dd04052e3 81 private:
hlipka 2:1a436d154c84 82 int cmd(char cmd,char* data, int len, bool doEnable=true);
hlipka 0:cf4dd04052e3 83 int readCalibResponse();
hlipka 0:cf4dd04052e3 84 int readByte();
hlipka 2:1a436d154c84 85 void writeByte(char bytee);
hlipka 0:cf4dd04052e3 86
hlipka 0:cf4dd04052e3 87 SPI *_spi;
hlipka 0:cf4dd04052e3 88 DigitalOut *_enable;
hlipka 0:cf4dd04052e3 89 InterruptIn *_irq;
hlipka 4:510ea5b28a05 90 DigitalIn *_siq;
hlipka 0:cf4dd04052e3 91 int _x, _y, _pen;
hlipka 0:cf4dd04052e3 92
hlipka 0:cf4dd04052e3 93 DigitalOut *_led;
hlipka 1:264ad2a00fd9 94 DigitalOut* _power;
hlipka 0:cf4dd04052e3 95
hlipka 0:cf4dd04052e3 96 DigitalOut *_mosi;
hlipka 0:cf4dd04052e3 97 DigitalIn *_miso;
hlipka 0:cf4dd04052e3 98 DigitalOut *_clk;
hlipka 0:cf4dd04052e3 99
hlipka 0:cf4dd04052e3 100 bool _oldPen;
hlipka 0:cf4dd04052e3 101 TouchEvent _event;
hlipka 0:cf4dd04052e3 102 };
hlipka 0:cf4dd04052e3 103
hlipka 0:cf4dd04052e3 104
hlipka 0:cf4dd04052e3 105
hlipka 0:cf4dd04052e3 106 #endif