touch screen handler for the microchip AR1020

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ar1020.h Source File

ar1020.h

00001 /*
00002 * mbed AR1020 library
00003 * Copyright (c) 2010 Hendrik Lipka
00004 *
00005 * Permission is hereby granted, free of charge, to any person obtaining a copy
00006 * of this software and associated documentation files (the "Software"), to deal
00007 * in the Software without restriction, including without limitation the rights
00008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 * copies of the Software, and to permit persons to whom the Software is
00010 * furnished to do so, subject to the following conditions:
00011 *
00012 * The above copyright notice and this permission notice shall be included in
00013 * all copies or substantial portions of the Software.
00014 *
00015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021 * THE SOFTWARE.
00022 */
00023 
00024 #ifndef __AR1020_H_
00025 #define __AR1020_H_
00026 
00027 #include "mbed.h"
00028     
00029 #include "touchpanel.h"
00030 #include "touchevent.h"
00031 
00032 /**
00033     class handling all the connections to a AR1020 touch screen controller
00034     SPI is handled by bit-banging, since the SPI-mode is non-standard. Therefore all pins can be used for the connection.
00035     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)   
00036 */    
00037 class AR1020: public TouchPanel
00038 {
00039     public:
00040         /**
00041             @params mosi the MOSI pin name (SDI)
00042             @params miso the MISO pin name (SDO)
00043             @params clk the CLK pin (SCL)
00044             @params enable the enable pin name (/CS)
00045             @params siq the SIQ pin name (SIQ)
00046             @params power the power pin name (connected to Vdd - this library does power handling for the AR1020)
00047         */
00048         AR1020(PinName mosi, PinName miso, PinName clk, PinName enable, PinName siq, PinName power);
00049         ~AR1020();
00050         
00051         /**
00052             initialize the controller
00053         */
00054         virtual void init();
00055         
00056         /**
00057             read X coordinate (from last update)
00058             @returns last known X coordinate
00059         */
00060         virtual int x();
00061         /**
00062             read Y coordinate (from last update)
00063             @returns last known Y coordinate
00064         */
00065         virtual int y();
00066         
00067         /**
00068             @return 0 if pen is up, 1 if pen is down
00069         */
00070         virtual int pen ();
00071         
00072         /**
00073             read coordinates on request
00074         */
00075         virtual void read();
00076         
00077         /**
00078             execute touch screen calibration
00079         */
00080         void calibrate();
00081     private:
00082         int cmd(char cmd,char* data, int len, bool doEnable=true);
00083         int readCalibResponse();
00084         int readByte();
00085         void writeByte(char bytee);
00086 
00087         SPI *_spi;
00088         DigitalOut *_enable;   
00089         InterruptIn *_irq;
00090         DigitalIn *_siq;
00091         int _x, _y, _pen; 
00092         
00093         DigitalOut *_led;
00094         DigitalOut* _power;
00095     
00096         DigitalOut *_mosi;
00097         DigitalIn *_miso;
00098         DigitalOut *_clk;
00099         
00100         bool _oldPen;
00101         TouchEvent _event;
00102 };
00103 
00104 
00105 
00106 #endif