"STMPE811 Touch Controller" Kullanımı..

Başlatan Mucit23, 20 Mart 2013, 19:48:10

Mucit23

Arkadaşlar Merhaba. Deney kiti üzerindeki TFT ekranın dokunmatiği ile uğraşıyorum. Dokunmatik ekran sürücüsü olarak STMPE811 kullanılmış. Datasheete baktımda çok karmaşık bir çip. Kullanıcıya hitap eden birçok register i var.

Ben örnek programlara bakarak Sensörü init edip X, Y, ve Z eksenlerini okudum. Bu arada I2C ile haberleşiyorum.

Normade Bu sensör Hem 12 bit hemde 10 bit ADC dönüşümü yapabiliyor. Bu seçimde ADC_CTRL1 Registerinin 3. biti ile yapılıyor.
images

Ben bu biti 10 bit ölçüm yapacak şekilde ayarlıyorum ama aldığım X ve Y değerleri hala 1024 den büyük oluyor. Yani ekranın  bir köşesinde X ve Y için 230 küsür bir değer, Ekranın diğer çapraz bir ucunda 3900 küsür bir değer alıyorum. Hiçbir zaman bu değerler 3900 den yukarı ve 200 den aşağı inmiyor. Hep bu aralıkta değer alıyorum.

Birde Z ekseni var. Normalde birde Z eksen bilgisi alınıyor. Sanırım buda ekrana uygulanan basıncı gösteriyor ve sadece 8 bitlik bir değer alıyor. Buradan aldığım değerlerde çok çok tutarsız. Normade ekrana uyguladığım basıncı arttırdıkça aldığım değer yükselmesi gerekir. Ama durum öyle değil malesef.

Daha önce dokunmatik ekranlarla hiç uğraşmadım. Bu yüzden aklımda soru işareti baya fazla.

Örneğin kullandığım ekranın çözünürlüğü 320X240, Ben aldığım X ve Y kordinatlarına göre Yani şuanda aldığım 200 ile 3900 arasındaki bir değere göre ekranda Ekranda o değere karşılık gelecek kordinata (0-320, 0-240) nokta gibi birşeyler koymak istiyorum.

Bunun için nasıl bir hesaplama yapabilirim?
Bu tür uygulamada kalibrasyon gibi olaylar vardı? 
Kalibrasyon dediğimiz işlem nedir. Çokmu zordur?

Yardımcı olursanız sevinirim. Özellikle yol ve yordam arıyorum.

Mucit23

#1
Kimsenin bi bilgisi yokmu.

Tamam aldığım 12 bit bilgiye razıyım. Sadece bu aldığım değerlere karşılık ekranın koordinatları nasıl hesaplayacağımı ögrensem yeter. Birde şu kalibrasyonu meselesini çözmem lazım

erhanmete

#2
ben o bulduğun değerlerden sabit hesaplıyorum çok ince olmayan işlerde iş görüyor.
kalibrasyon işi ise baktım matematiğini anlamadım ihtiyaç da olmadı bıraktım.

hesaplamaya gelince x i hesaplayalım.
driverden   0 noktası için 200 geliyor 320 noktası için 3900 geliyor. buna XD diyelim


X=(XD-200)*(320/(3900-200))

eğer kalemle çizim yapmayacaksan sadece butonların varsa bu iş görür.
kalibrasyon işini çözersen bende öğrenmek istiyorum.

touch screen

buzkırıcı

#3
Bende aynı firmanın stmp611 i kullanıyorum. Z değerini kapattım ben. çünkü her hangi bir baskı olmadğı zaman zaten x ve y yi 0 gönderiyor. Bir de bazen x ve y değerlerini negatif değer olarak da gönderiyor. okuduktan sonra ABS() kullanmanı tavsiye ederim.
0,0 noktası için 120,340 okuyorum x,y(lcd_xsize,lcd_ysize) içinse 3950,3950 okuyorum Bunları kalibre ediyorum.

#define ABS(x)                (((int16_t)(x)) < 0 ? (-x) : (x))
//Calibration uCGUI de böyle yapmışlar
static int _Log2Phys(int l, I32 l0, I32 l1, I32 p0, I32 p1) {
  return p0 + ((p1 - p0) * (l - l0)) / (l1 - l0);
}

static void _Calibrate(int Coord, int Log0, int Log1, int Phys0, int Phys1, int *p0, int *p1) {
  int l0 = 0;
  int l1 = (Coord == GUI_COORD_X) ? LCD_XSIZE - 1 : LCD_YSIZE - 1;
  *p0 = _Log2Phys(l0, Log0, Log1, Phys0, Phys1);
  *p1 = _Log2Phys(l1, Log0, Log1, Phys0, Phys1);
}
İmza Atmayı bilmem Parnak Bassam olur mu?

haydarpasamikro

Keil MCBSTM32F400 deneme board un kütüphanesinden alıntı..

/*-----------------------------------------------------------------------------
* Name:    TSC_STMPE811.c
* Purpose: Touchscreen controller routines for the STMPE811
* Note(s):
*-----------------------------------------------------------------------------
* This file is part of the uVision/ARM development tools.
* This software may only be used under the terms of a valid, current,
* end user licence from KEIL for a compatible version of KEIL software
* development tools. Nothing else gives you the right to use this software.
*
* This software is supplied "AS IS" without warranties of any kind.
*
* Copyright (c) 2011 Keil - An ARM Company. All rights reserved.
*----------------------------------------------------------------------------*/

#include <stdint.h>
#include "TSC.h"
#include "I2C.h"

#define TSC_I2C_ADDR    0x41            /* Touchscreen 7-bit I2C address      */

/* Register addresses */

#define SYS_CTRL1       0x03
#define SYS_CTRL2       0x04
#define INT_CTRL        0x09
#define INT_EN          0x0A
#define INT_STA         0x0B
#define GPIO_ALT_FUNCT  0x17
#define ADC_CTRL1       0x20
#define ADC_CTRL2       0x21
#define TSC_CTRL        0x40
#define TSC_CFG         0x41
#define FIFO_TH         0x4A
#define FIFO_STA        0x4B
#define FIFO_SIZE       0x4C
#define DATA_X          0x4D
#define DATA_Y          0x4F
#define DATA_Z          0x51
#define TSC_FRACTION_Z  0x56
#define TSC_I_DRIVE     0x58
#define TSC_SHIELD      0x59
#define DATA_XYZ        0xD7

/* Prototypes */
static uint32_t TSC_WrReg (uint8_t reg, uint8_t  val);
static uint32_t TSC_RdReg (uint8_t reg, uint8_t *val);


/*-----------------------------------------------------------------------------
*      TSC_Init:  Initialize touchscreen controller
*
*  Parameter:  (none)
*  Return:     0 on success, nonzero on error
*----------------------------------------------------------------------------*/
uint32_t TSC_Init (void) {
  int i;

  TSC_WrReg (SYS_CTRL1,       0x02);    /* Reset Touch-screen controller      */
  for (i = 0; i < 180000; i++);         /* Wait a bit                         */
  TSC_WrReg (SYS_CTRL2,       0x0C);    /* Enable TSC and ADC                 */
  TSC_WrReg (INT_EN,          0x07);    /* Enable Touch detect, FIFO          */
  TSC_WrReg (ADC_CTRL1,       0x69);    /* Set sample time , 12-bit mode      */
  for (i = 0; i < 36000; i++);          /* Wait a bit                         */
  TSC_WrReg (ADC_CTRL2,       0x01);    /* ADC frequency 3.25 MHz             */
  TSC_WrReg (TSC_CFG,         0xC2);    /* Detect delay 10us Settle time 500us*/
  TSC_WrReg (FIFO_TH,         0x01);    /* Threshold for FIFO                 */
  TSC_WrReg (FIFO_STA,        0x01);    /* FIFO reset                         */
  TSC_WrReg (FIFO_STA,        0x00);    /* FIFO not reset                     */
  TSC_WrReg (TSC_FRACTION_Z,  0x07);    /* Fraction z                         */
  TSC_WrReg (TSC_I_DRIVE,     0x01);    /* Drive 50 mA typical                */
  TSC_WrReg (GPIO_ALT_FUNCT,  0x00);    /* Pins are used for touchscreen      */
  TSC_WrReg (TSC_CTRL,        0x01);    /* Enable TSC                         */
  TSC_WrReg (INT_STA,         0xFF);    /* Clear interrupt status             */
  return (0);
}

/*-----------------------------------------------------------------------------
*      TSC_TouchDet: Check if touch of the screen is detected
*
* Parameters: (none)
*
* Return:     0 if touch not detected, nonzero otherwise
*----------------------------------------------------------------------------*/
uint32_t TSC_TouchDet (void) {
  uint8_t  val;
  uint32_t rtv = 0;
 
  if (TSC_RdReg (TSC_CTRL, &val) == 0) {
    if (val & (1 << 7)) {
      rtv = 1;
    }
  }
  return (rtv);
}

/*-----------------------------------------------------------------------------
*      TSC_GetData: Read coordinates from registers and write them into
*                   TSC_DATA structure.
*
* Parameters: tscd - pointer to TSC_DATA structure
*
* Return:     0 on success, nonzero on error
*----------------------------------------------------------------------------*/
uint32_t TSC_GetData (TSC_DATA *tscd) {
  uint8_t  num, xyz[4];
  uint32_t rtv;

  /* If FIFO overflow, read all samples except the last one */
  TSC_RdReg (FIFO_SIZE, &num);
  while (--num) {
    if (I2C_RdData (TSC_I2C_ADDR, DATA_XYZ, xyz, 4)) {
      /* Registers cannot be read */
      return (1);
    }
  }

  /* Retreive last taken sample */
  rtv = I2C_RdData (TSC_I2C_ADDR, DATA_XYZ, xyz, 4);
  tscd->x = (xyz[0] << 4) | ((xyz[1] & 0xF0) >> 4);
  tscd->y = ((xyz[1] & 0x0F) << 8) | xyz[2];
  tscd->z =  xyz[3];

  /* Clear interrupt flags */
  TSC_WrReg (INT_STA, 0x1F);

  return (rtv);
}

/*-----------------------------------------------------------------------------
*      TSC_Write:  Write a value to the touchscreen controller register
*
* Parameters:  reg - register to write
*              val - value to write
*
* Return:      0 on success, nonzero on error
*----------------------------------------------------------------------------*/
uint32_t TSC_WrReg (uint8_t reg, uint8_t  val) {
  return I2C_WrData (TSC_I2C_ADDR, reg, &val, 1);
}


/*-----------------------------------------------------------------------------
*      TSC_Read:  Read a value from the touchscreen controller register
*
* Parameters:  reg - register to read
*              val - variable where value will be stored
*
* Return:      0 on success, nonzero on error
*----------------------------------------------------------------------------*/
uint32_t TSC_RdReg (uint8_t reg, uint8_t *val) {
  return I2C_RdData (TSC_I2C_ADDR, reg, val, 1);
}


/*-----------------------------------------------------------------------------
* End of file
*----------------------------------------------------------------------------*/


/*-----------------------------------------------------------------------------
* Name:    TSC.h
* Purpose: Touchscreen controller definitions
*-----------------------------------------------------------------------------
* This file is part of the uVision/ARM development tools.
* This software may only be used under the terms of a valid, current,
* end user licence from KEIL for a compatible version of KEIL software
* development tools. Nothing else gives you the right to use this software.
*
* This software is supplied "AS IS" without warranties of any kind.
*
* Copyright (c) 2004-2011 Keil - An ARM Company. All rights reserved.
*----------------------------------------------------------------------------*/

#ifndef __TSC_H
#define __TSC_H

typedef struct {
  int16_t x;
  int16_t y;
  int16_t z; 
} TSC_DATA;

extern uint32_t TSC_Init      (void);
extern uint32_t TSC_TouchDet  (void);
extern uint32_t TSC_GetData   (TSC_DATA *tscd);

#endif /* __TSC_H */
Mikro Dünyası.Haydarpaşa Teknik ve Endüstri Meslek Lisesi Mikrodenetleyici Atl. Şefi

Mucit23

Hocam Keilin içindeki örnek çok iyiymiş. Haberleşmede sıkıntım yok ama yinede elimdeki kodlar atıp oradaki kodları kullanacağım. Veya mantığını kullanırım.

Erhan hocam kalibrasyon işin araştıracağım. İlk Önce kalibrasyon denilen mesele nedir? Onu öğrenmem lazım.

Amacım kalem kullanmak bakalım nekadar hassasiyet yakalayabileceğim.

Mucit23

#6
Hocam orjin noktası belirlemek sıkıntı olacak. Çünkü touch panelden alınan min. değer ile max değer çok değişken. normalde 200 civarındaydı ama şimdi 150 leri görüyorum.

Ekranın dokunmatik panelin max ve min noktalarını belirlemek için nasıl bir yöntem izleyebilirim.

Videolarda izliyorum genelde hep ekranın 3 noktasına bir işaret konuluyor. Sonrasında kullanıcının bu noktalara dokunması bekleniyor. Kullanıcı bu üç noktaya dokunduğu zaman kalibrasyon bitmiş oluyor.

Şimdi bu üç noktaya dokunularak ne gibi bilgiler elde ediliyor. Buna karşılık kalibrasyon nasıl yapılıyor bu konuda bilgili arkadaşların konuya bakmasını rica ediyorum.

Şöyle bir tahminim var.

Biz ekranın herhangi bir noktasına bir işaret koyalım. Normalde bu işaretin x,y kordinatlarını biliriz.  Biz bu noktaya dokunursak dokunmatik panelden bizim ekrana koyduğumuz noktanın kordinatına denk gelen bir bir kordinat bilgisi alırız.

Buraya kadar tamam bu kısmı hallederim.

Peki buradan sonra dokunmatik panelde basılan başka bir kordinata karşılık gelen ekran kordinatını nasıl belirlerim? Burada kafam duruyor...

@erhanmete burada anlatılıyor kalibrasyon işlemi

Hatta örnek kod vermişler.

calibrate.c
/*
 *
 *   Copyright (c) 2001, Carlos E. Vidales. All rights reserved.
 *
 *   This sample program was written and put in the public domain 
 *    by Carlos E. Vidales.  The program is provided "as is" 
 *    without warranty of any kind, either expressed or implied.
 *   If you choose to use the program within your own products
 *    you do so at your own risk, and assume the responsibility
 *    for servicing, repairing or correcting the program should
 *    it prove defective in any manner.
 *   You may copy and distribute the program's source code in any 
 *    medium, provided that you also include in each copy an
 *    appropriate copyright notice and disclaimer of warranty.
 *   You may also modify this program and distribute copies of
 *    it provided that you include prominent notices stating 
 *    that you changed the file(s) and the date of any change,
 *    and that you do not charge any royalties or licenses for 
 *    its use.
 * 
 *
 * 
 *   File Name:  calibrate.c
 *
 *
 *   This file contains functions that implement calculations 
 *    necessary to obtain calibration factors for a touch screen
 *    that suffers from multiple distortion effects: namely, 
 *    translation, scaling and rotation.
 *
 *   The following set of equations represent a valid display 
 *    point given a corresponding set of touch screen points:
 *
 *
 *                                              /-     -\
 *              /-    -\     /-            -\   |       |
 *              |      |     |              |   |   Xs  |
 *              |  Xd  |     | A    B    C  |   |       |
 *              |      |  =  |              | * |   Ys  |
 *              |  Yd  |     | D    E    F  |   |       |
 *              |      |     |              |   |   1   |
 *              \-    -/     \-            -/   |       |
 *                                              \-     -/
 *
 * 
 *    where:
 *
 *           (Xd,Yd) represents the desired display point 
 *                    coordinates,
 *
 *           (Xs,Ys) represents the available touch screen
 *                    coordinates, and the matrix
 *
 *           /-   -\
 *           |A,B,C|
 *           |D,E,F| represents the factors used to translate
 *           \-   -/  the available touch screen point values
 *                    into the corresponding display 
 *                    coordinates.
 *
 *
 *    Note that for practical considerations, the utilitities 
 *     within this file do not use the matrix coefficients as
 *     defined above, but instead use the following 
 *     equivalents, since floating point math is not used:
 *
 *            A = An/Divider 
 *            B = Bn/Divider 
 *            C = Cn/Divider 
 *            D = Dn/Divider 
 *            E = En/Divider 
 *            F = Fn/Divider 
 *
 *
 *
 *    The functions provided within this file are:
 *
 *          setCalibrationMatrix() - calculates the set of factors
 *                                    in the above equation, given
 *                                    three sets of test points.
 *               getDisplayPoint() - returns the actual display
 *                                    coordinates, given a set of
 *                                    touch screen coordinates.
 * translateRawScreenCoordinates() - helper function to transform
 *                                    raw screen points into values
 *                                    scaled to the desired display
 *                                    resolution.
 *
 *
 */


#define _CALIBRATE_C_



/****************************************************/
/*                                                  */
/* Included files                                   */
/*                                                  */
/****************************************************/

#include "Calibrate.h"



/****************************************************/
/*                                                  */
/* Local Definitions and macros                     */
/*                                                  */
/****************************************************/



/****************************************************/
/*                                                  */
/* Global variables                                 */
/*                                                  */
/****************************************************/



/****************************************************/
/*                                                  */
/* Forward Declaration of local functions           */
/*                                                  */
/****************************************************/






/**********************************************************************
 *
 *     Function: setCalibrationMatrix()
 *
 *  Description: Calling this function with valid input data
 *                in the display and screen input arguments 
 *                causes the calibration factors between the
 *                screen and display points to be calculated,
 *                and the output argument - matrixPtr - to be 
 *                populated.
 *
 *               This function needs to be called only when new
 *                calibration factors are desired.
 *               
 *  
 *  Argument(s): displayPtr (input) - Pointer to an array of three 
 *                                     sample, reference points.
 *               screenPtr (input) - Pointer to the array of touch 
 *                                    screen points corresponding 
 *                                    to the reference display points.
 *               matrixPtr (output) - Pointer to the calibration 
 *                                     matrix computed for the set 
 *                                     of points being provided.
 *
 *
 *  From the article text, recall that the matrix coefficients are
 *   resolved to be the following:
 *
 *
 *      Divider =  (Xs0 - Xs2)*(Ys1 - Ys2) - (Xs1 - Xs2)*(Ys0 - Ys2)
 *
 *
 *
 *                 (Xd0 - Xd2)*(Ys1 - Ys2) - (Xd1 - Xd2)*(Ys0 - Ys2)
 *            A = ---------------------------------------------------
 *                                   Divider
 *
 *
 *                 (Xs0 - Xs2)*(Xd1 - Xd2) - (Xd0 - Xd2)*(Xs1 - Xs2)
 *            B = ---------------------------------------------------
 *                                   Divider
 *
 *
 *                 Ys0*(Xs2*Xd1 - Xs1*Xd2) + 
 *                             Ys1*(Xs0*Xd2 - Xs2*Xd0) + 
 *                                           Ys2*(Xs1*Xd0 - Xs0*Xd1)
 *            C = ---------------------------------------------------
 *                                   Divider
 *
 *
 *                 (Yd0 - Yd2)*(Ys1 - Ys2) - (Yd1 - Yd2)*(Ys0 - Ys2)
 *            D = ---------------------------------------------------
 *                                   Divider
 *
 *
 *                 (Xs0 - Xs2)*(Yd1 - Yd2) - (Yd0 - Yd2)*(Xs1 - Xs2)
 *            E = ---------------------------------------------------
 *                                   Divider
 *
 *
 *                 Ys0*(Xs2*Yd1 - Xs1*Yd2) + 
 *                             Ys1*(Xs0*Yd2 - Xs2*Yd0) + 
 *                                           Ys2*(Xs1*Yd0 - Xs0*Yd1)
 *            F = ---------------------------------------------------
 *                                   Divider
 *
 *
 *       Return: OK - the calibration matrix was correctly 
 *                     calculated and its value is in the 
 *                     output argument.
 *               NOT_OK - an error was detected and the 
 *                         function failed to return a valid
 *                         set of matrix values.
 *                        The only time this sample code returns
 *                        NOT_OK is when Divider == 0
 *
 *
 *
 *                 NOTE!    NOTE!    NOTE!
 *
 *  setCalibrationMatrix() and getDisplayPoint() will do fine
 *  for you as they are, provided that your digitizer         
 *  resolution does not exceed 10 bits (1024 values).  Higher
 *  resolutions may cause the integer operations to overflow
 *  and return incorrect values.  If you wish to use these   
 *  functions with digitizer resolutions of 12 bits (4096    
 *  values) you will either have to a) use 64-bit signed     
 *  integer variables and math, or b) judiciously modify the 
 *  operations to scale results by a factor of 2 or even 4.  
 *
 *
 */
int setCalibrationMatrix( POINT * displayPtr,
                          POINT * screenPtr,
                          MATRIX * matrixPtr)
{

    int  retValue = OK ;


    
    matrixPtr->Divider = ((screenPtr[0].x - screenPtr[2].x) * (screenPtr[1].y - screenPtr[2].y)) - 
                         ((screenPtr[1].x - screenPtr[2].x) * (screenPtr[0].y - screenPtr[2].y)) ;

    if( matrixPtr->Divider == 0 )
    {
        retValue = NOT_OK ;
    }
    else
    {
        matrixPtr->An = ((displayPtr[0].x - displayPtr[2].x) * (screenPtr[1].y - screenPtr[2].y)) - 
                        ((displayPtr[1].x - displayPtr[2].x) * (screenPtr[0].y - screenPtr[2].y)) ;

        matrixPtr->Bn = ((screenPtr[0].x - screenPtr[2].x) * (displayPtr[1].x - displayPtr[2].x)) - 
                        ((displayPtr[0].x - displayPtr[2].x) * (screenPtr[1].x - screenPtr[2].x)) ;

        matrixPtr->Cn = (screenPtr[2].x * displayPtr[1].x - screenPtr[1].x * displayPtr[2].x) * screenPtr[0].y +
                        (screenPtr[0].x * displayPtr[2].x - screenPtr[2].x * displayPtr[0].x) * screenPtr[1].y +
                        (screenPtr[1].x * displayPtr[0].x - screenPtr[0].x * displayPtr[1].x) * screenPtr[2].y ;

        matrixPtr->Dn = ((displayPtr[0].y - displayPtr[2].y) * (screenPtr[1].y - screenPtr[2].y)) - 
                        ((displayPtr[1].y - displayPtr[2].y) * (screenPtr[0].y - screenPtr[2].y)) ;
    
        matrixPtr->En = ((screenPtr[0].x - screenPtr[2].x) * (displayPtr[1].y - displayPtr[2].y)) - 
                        ((displayPtr[0].y - displayPtr[2].y) * (screenPtr[1].x - screenPtr[2].x)) ;

        matrixPtr->Fn = (screenPtr[2].x * displayPtr[1].y - screenPtr[1].x * displayPtr[2].y) * screenPtr[0].y +
                        (screenPtr[0].x * displayPtr[2].y - screenPtr[2].x * displayPtr[0].y) * screenPtr[1].y +
                        (screenPtr[1].x * displayPtr[0].y - screenPtr[0].x * displayPtr[1].y) * screenPtr[2].y ;
    }
 
    return( retValue ) ;

} /* end of setCalibrationMatrix() */



/**********************************************************************
 *
 *     Function: getDisplayPoint()
 *
 *  Description: Given a valid set of calibration factors and a point
 *                value reported by the touch screen, this function
 *                calculates and returns the true (or closest to true)
 *                display point below the spot where the touch screen 
 *                was touched.
 * 
 *
 * 
 *  Argument(s): displayPtr (output) - Pointer to the calculated
 *                                      (true) display point.
 *               screenPtr (input) - Pointer to the reported touch
 *                                    screen point.
 *               matrixPtr (input) - Pointer to calibration factors
 *                                    matrix previously calculated
 *                                    from a call to 
 *                                    setCalibrationMatrix()
 * 
 *
 *  The function simply solves for Xd and Yd by implementing the 
 *   computations required by the translation matrix.  
 * 
 *                                              /-     -\
 *              /-    -\     /-            -\   |       |
 *              |      |     |              |   |   Xs  |
 *              |  Xd  |     | A    B    C  |   |       |
 *              |      |  =  |              | * |   Ys  |
 *              |  Yd  |     | D    E    F  |   |       |
 *              |      |     |              |   |   1   |
 *              \-    -/     \-            -/   |       |
 *                                              \-     -/
 * 
 *  It must be kept brief to avoid consuming CPU cycles.
 * 
 *
 *       Return: OK - the display point was correctly calculated 
 *                     and its value is in the output argument.
 *               NOT_OK - an error was detected and the function
 *                         failed to return a valid point.
 *
 *
 *
 *                 NOTE!    NOTE!    NOTE!
 *
 *  setCalibrationMatrix() and getDisplayPoint() will do fine
 *  for you as they are, provided that your digitizer         
 *  resolution does not exceed 10 bits (1024 values).  Higher
 *  resolutions may cause the integer operations to overflow
 *  and return incorrect values.  If you wish to use these   
 *  functions with digitizer resolutions of 12 bits (4096    
 *  values) you will either have to a) use 64-bit signed     
 *  integer variables and math, or b) judiciously modify the 
 *  operations to scale results by a factor of 2 or even 4.  
 *
 *
 */
int getDisplayPoint( POINT * displayPtr,
                     POINT * screenPtr,
                     MATRIX * matrixPtr )
{
    int  retValue = OK ;


    if( matrixPtr->Divider != 0 )
    {

            /* Operation order is important since we are doing integer */
            /*  math. Make sure you add all terms together before      */
            /*  dividing, so that the remainder is not rounded off     */
            /*  prematurely.                                           */

        displayPtr->x = ( (matrixPtr->An * screenPtr->x) + 
                          (matrixPtr->Bn * screenPtr->y) + 
                           matrixPtr->Cn 
                        ) / matrixPtr->Divider ;

        displayPtr->y = ( (matrixPtr->Dn * screenPtr->x) + 
                          (matrixPtr->En * screenPtr->y) + 
                           matrixPtr->Fn 
                        ) / matrixPtr->Divider ;
    }
    else
    {
        retValue = NOT_OK ;
    }

    return( retValue ) ;

} /* end of getDisplayPoint() */


calibrate.h

/*
 *
 *   Copyright (c) 2001, Carlos E. Vidales. All rights reserved.
 *
 *   This sample program was written and put in the public domain 
 *    by Carlos E. Vidales.  The program is provided "as is" 
 *    without warranty of any kind, either expressed or implied.
 *   If you choose to use the program within your own products
 *    you do so at your own risk, and assume the responsibility
 *    for servicing, repairing or correcting the program should
 *    it prove defective in any manner.
 *   You may copy and distribute the program's source code in any 
 *    medium, provided that you also include in each copy an
 *    appropriate copyright notice and disclaimer of warranty.
 *   You may also modify this program and distribute copies of
 *    it provided that you include prominent notices stating 
 *    that you changed the file(s) and the date of any change,
 *    and that you do not charge any royalties or licenses for 
 *    its use.
 * 
 *
 *   File Name:  calibrate.h
 *
 *
 *   Definition of constants and structures, and declaration of functions 
 *    in Calibrate.c
 *
 */

#ifndef _CALIBRATE_H_

#define _CALIBRATE_H_

/****************************************************/
/*                                                  */
/* Included files                                   */
/*                                                  */
/****************************************************/

#include <math.h>


/****************************************************/
/*                                                  */
/* Definitions                                      */
/*                                                  */
/****************************************************/

#ifndef		_CALIBRATE_C_
	#define		EXTERN         extern
#else
	#define		EXTERN
#endif



#ifndef		OK
	#define		OK		        0
	#define		NOT_OK		   -1
#endif



#define			INT32				long




/****************************************************/
/*                                                  */
/* Structures                                       */
/*                                                  */
/****************************************************/


typedef struct Point {
                        INT32    x,
                                 y ;
                     } POINT ;



typedef struct Matrix {
							/* This arrangement of values facilitates 
							 *  calculations within getDisplayPoint() 
							 */
                        INT32    An,     /* A = An/Divider */
                                 Bn,     /* B = Bn/Divider */
                                 Cn,     /* C = Cn/Divider */
                                 Dn,     /* D = Dn/Divider */
                                 En,     /* E = En/Divider */
                                 Fn,     /* F = Fn/Divider */
                                 Divider ;
                     } MATRIX ;




/****************************************************/
/*                                                  */
/* Function declarations                            */
/*                                                  */
/****************************************************/


EXTERN int setCalibrationMatrix( POINT * display,
                                 POINT * screen,
                                 MATRIX * matrix) ;


EXTERN int getDisplayPoint( POINT * display,
                            POINT * screen,
                            MATRIX * matrix ) ;


#endif  /* _CALIBRATE_H_ */


son olarak sample.c

/*
 *
 *   Copyright (c) 2001, Carlos E. Vidales. All rights reserved.
 * 
 *   This sample program was written and put in the public domain 
 *    by Carlos E. Vidales.  The program is provided "as is" 
 *    without warranty of any kind, either expressed or implied.
 *   If you choose to use the program within your own products
 *    you do so at your own risk, and assume the responsibility
 *    for servicing, repairing or correcting the program should
 *    it prove defective in any manner.
 *   You may copy and distribute the program's source code in any 
 *    medium, provided that you also include in each copy an
 *    appropriate copyright notice and disclaimer of warranty.
 *   You may also modify this program and distribute copies of
 *    it provided that you include prominent notices stating 
 *    that you changed the file(s) and the date of any change,
 *    and that you do not charge any royalties or licenses for 
 *    its use.
 *    
 *
 *   File Name:  sample.c
 *
 *
 */


#define _SAMPLE_C_



/****************************************************/
/*                                                  */
/* Included files                                   */
/*                                                  */
/****************************************************/

#include <stdio.h>

#include "Calibrate.h"



/****************************************************/
/*                                                  */
/* Local Definitions                                */
/*                                                  */
/****************************************************/

#define		MAX_SAMPLES		    8


/****************************************************/
/*                                                  */
/* Local Variables                                  */
/*                                                  */
/****************************************************/

        /* NOTE: Even though the validity of the calibration/translation method  */
        /*        proposed has been verified with empirical data from several    */
        /*        actual touch screen enabled displays, for the convenience of   */
        /*        this exercise, the raw and expected data used and presented    */
        /*        below are artificial.  When used with actual data the          */
        /*        functions presented yield results that may be off by a larger  */
        /*        but still small percentage (~1-3%) due to electrical noise and */
        /*        human error (i.e., the hand touching a screen target and       */
        /*        missing by a small amount.)                                    */


		/* The array of input points.  The first three are used for calibration. */
        /* These set of points assume that the touchscreen has vertical and      */
        /*  horizontal resolutions of 1024 pixels (10-bit digitizer.)            */ 

POINT screenSample[MAX_SAMPLES] =	{
                                            {  73, 154 },
											{ 891, 516 },
											{ 512, 939 },
											{ 265, 414 },
											{ 606, 171 },
											{ 768, 700 },
											{ 111, 956 },
                                            { 448, 580 }
									} ;



		/* The array of expected "right answers."  The values selected assume a  */
        /*  vertical and horizontal display resolution of 240 pixels.            */

POINT displaySample[MAX_SAMPLES] =	{
                                            {  30,  30 },
											{ 210, 120 },
											{ 120, 210 },
                                            {  70,  90 },
											{ 150,  40 },
											{ 180, 160 },
                                            {  30, 210 },
											{ 110, 130 }
									} ;


		/* An array of perfect input screen points used to obtain a first pass   */
        /*  calibration matrix good enough to collect calibration samples.       */

POINT perfectScreenSample[3] =	{
                                            { 100, 100 },
											{ 900, 500 },
                                            { 500, 900 }
                                } ;



		/* An array of perfect display points used to obtain a first pass        */
        /*  calibration matrix good enough to collect calibration samples.       */

POINT perfectDisplaySample[3] = {
                                            { 100, 100 },
											{ 900, 500 },
                                            { 500, 900 }
	                            } ;


/****************************************************/
/*                                                  */
/* Forward Declaration of local functions           */
/*                                                  */
/****************************************************/

int   main( int argCount, char ** argValue ) ;
void  greeting( void ) ;





/**********************************************************************
 *
 *     Function: main()
 *
 *  Description: Entry point into console version of sample
 *                program that exercises the calibration 
 *                functions.
 * 
 *  Argument(s): argCount - the number of arguments provided
 *               argValue - pointer to the list of char strings 
 *                           representing the command line arguments.
 * 
 *       Return: void
 *
 */
int main( int argCount, char ** argValue )
{

    int retValue = OK ;

    MATRIX  matrix ;
    POINT   display ;
    
    
    int     n ;


      
    greeting() ;


        /* The following call calculates the translation matrix that   */
        /*  results when the three consecutive points in the sample    */
        /*  set are used.  Such points are assumed to be properly      */
        /*  spaced within the screen surface.                          */
        /* Note that we call the function twice as we would normally   */
        /*  do within a calibration routine.  The first time we call   */
        /*  it using a perfect set of display and screen arguments.    */
        /* Such a call is made to obtain a calibration matrix that is  */
        /*  just good enough to collect samples to do the real         */
        /*  calibration.                                               */
        /*                                                             */
        /*                                                             */
        /*                                                             */
        /*                 NOTE!    NOTE!    NOTE!                     */
        /*                                                             */
        /*  setCalibrationMatrix() and getDisplayPoint() will do fine  */
        /*  for you as they are, provided that your digitizer          */
        /*  resolution does not exceed 10 bits (1024 values).  Higher  */
        /*  resolutions may cause the integer operations to overflow   */
        /*  and return incorrect values.  If you wish to use these     */
        /*  functions with digitizer resolutions of 12 bits (4096      */
        /*  values) you will either have to a) use 64-bit signed       */
        /*  integer variables and math, or b) judiciously modify the   */
        /*  operations to scale results by a factor of 2 or even 4.    */
        /*                                                             */


    setCalibrationMatrix( &perfectDisplaySample[0], 
						  &perfectScreenSample[0], 
						  &matrix ) ;

        /* Look at the matrix values when we use a perfect sample set. */
        /* The result is a unity matrix.                               */
    printf("\n\nLook at the unity matrix:\n\n"
           "matrix.An = % 8ld  matrix.Bn = % 8ld  matrix.Cn = % 8ld\n"
           "matrix.Dn = % 8ld  matrix.En = % 8ld  matrix.Fn = % 8ld\n"
           "matrix.Divider = % 8ld\n",
           matrix.An,matrix.Bn,matrix.Cn,
           matrix.Dn,matrix.En,matrix.Fn,
           matrix.Divider ) ;





        /* Now is when we need to do the work to collect a real set of */
        /*  calibration data.                                          */

        /* Draw three targets on your display. Drawing one at time is  */
        /*  probably a simpler implementation. These targets should be */
        /*  widely separated but also avoid the areas too near the     */
        /*  edges where digitizer output tends to become non-linear.   */
        /*  The recommended set of points is (in display resolution    */
        /*   percentages):                                             */
        /*                                                             */
        /*                  ( 15, 15)                                  */
        /*                  ( 50, 85)                                  */
        /*                  ( 85, 50)                                  */
        /*                                                             */
        /* Each time save the display and screen set (returned by the  */
        /*  digitizer when the user touches each calibration target    */
        /*  into the corresponding array).                             */ 
        /* Since you normalized your calibration matrix above, you     */
        /*  should be able to use touch screen data as it would be     */
        /*  provided by the digitizer driver.  When the matrix equals  */
        /*  unity, getDisplayPoint() returns the same raw input data   */
        /*  as output.                                                 */



    


        /* Call the function once more to obtain the calibration       */
        /*  factors you will use until you calibrate again.            */
    setCalibrationMatrix( &displaySample[0], &screenSample[0], &matrix ) ;

        /* Let's see the matrix values for no particular reason.       */
    printf("\n\nThis is the actual calibration matrix that we will use\n"
           "for all points (until we calibrate again):\n\n"
           "matrix.An = % 8d  matrix.Bn = % 8d  matrix.Cn = % 8d\n"
           "matrix.Dn = % 8d  matrix.En = % 8d  matrix.Fn = % 8d\n"
           "matrix.Divider = % 8d\n",
           matrix.An,matrix.Bn,matrix.Cn,
           matrix.Dn,matrix.En,matrix.Fn,
           matrix.Divider ) ;



        /* Now, lets use the complete set of screen samples to verify  */
        /*  that the calculated calibration matrix does its job as     */
        /*  expected.                                                  */
    printf("\n\nShow the results of our work:\n\n"
           "  Screen Sample    Translated Sample    Display Sample\n\n" ) ;


        /* In a real application, your digitizer driver interrupt      */
        /*  would probably do the following:                           */
        /*      1) collect raw digitizer data,                         */
        /*      2) filter the raw data which would probably contain    */
        /*          position jitter,                                   */
        /*      3) filter out repeated values (a touch screen          */
        /*          controller normally continues causing interrupts   */
        /*          and collecting data as long as the user is         */
        /*          pressing on the screen), and                       */
        /*      4) call the function getDisplayPoint() to obtain       */
        /*          the display coordinates that the user meant to     */
        /*          input as he touched the screen.                    */
        /*                                                             */
        /* This code sample, of course, only uses sample data.  So we  */
        /*  simply run through all the available sample points.        */

    for( n = 0 ; n < MAX_SAMPLES ; ++n )
    {
        getDisplayPoint( &display, &screenSample[n], &matrix ) ;
        printf("  % 6d,%-6d      % 6d,%-6d       % 6d,%-6d\n", 
                screenSample[n].x,  screenSample[n].y,
                display.x,          display.y,
                displaySample[n].x, displaySample[n].y ) ;
    }


    return( retValue ) ;

} // end of main() 



/**********************************************************************
 *
 *     Function: greeting()
 *
 *  Description: Provides the sample program's welcome message.
 * 
 *  Argument(s): None
 * 
 *       Return: void
 *
 */
void greeting( void ) 
{
    printf("\n"
           "Touch Screen Calibration Sample Code,\n"
           " by Carlos E. Vidales, Copyright 2001.\n"
           "\n" ) ;
}


İndirdiğim dosyaların içinde bunlar var..

Kodların çalışmasını anlamaya çalışıyorum...

erhanmete

bu kodları ben çalıştıramadım dediğim gibi matematiğini de anlamamıştım zaten.

haydarpasamikro

öğrenciler hep şikayet eder, bu matrix, mantis,  analitik geometri, kartezyen,vs.. ne işime yarayacak ki diye:)
Mikro Dünyası.Haydarpaşa Teknik ve Endüstri Meslek Lisesi Mikrodenetleyici Atl. Şefi

Mucit23

Alıntı yapılan: haydarpasamikro - 22 Mart 2013, 10:41:43
öğrenciler hep şikayet eder, bu matrix, mantis,  analitik geometri, kartezyen,vs.. ne işime yarayacak ki diye:)

Hocam şimdiye kadar işime yaramayacak dediğim hiçbir dersim olmadı :)

erhanmete nin dediği yöntem ile aldığım X,Y touch kordinatlarını grafik LCD de ona karşılık gelen kordinatlara çevirdim.

Sonrasında o noktalara karşılık gelen kordinatlara daire çizdim.

Fazla bir kod yazmadım. Yaptıklarım bunlar.
if(TSC_TouchDet()){
			
					tch_x=Touch_Read(0x4F,2);
					tch_y=Touch_Read(0x4D,2);
					tch_z=Touch_Read(0x51,1);
			
					if(tch_x>touch_max_value) tch_x=3900;
					if(tch_x<touch_min_value) tch_x=200;
					if(tch_y>touch_max_value) tch_y=3900;
					if(tch_y<touch_min_value) tch_y=200;
			
					tch_xd=floor((tch_x-200) * xmult);
					tch_yd=(240-floor((tch_y-200) * ymult));
			
		}else{
			tch_x=0;
			tch_y=0;
			tch_z=0; 
		}
		
	if((tch_xd!=tch_xd_) | (tch_yd!=tch_yd_))
	{
     GLCD_Circle(tch_xd,tch_yd,2,1);
     tch_xd_=tch_xd;tch_yd_=tch_yd;		
  }


Yalnız bununla birlikte bir problem oluştu. Normalde işlemcinin çok hızlı çalışması lazım. Ekrana bir kalemledokunup çizgi çizdiğim zaman noktalar kesik kesik oluyor. Yani işlemci hızı veya verilerin güncellenme hızı bizim ekran üzerindeki yer değiştirme hızımıza yetişemiyor. Dolayısıyla yeni bir kordinat geldiğinde eski kordinatla birlikte arada çok mesafe olmuş oluyor.

İşlemciyi çalıştırabileceğim max hızda çalıştırıyorum.

Bu sorunu nasıl çözerim. Acaba STMPE811 en fazla nekadar hızda çalışır. Saniyede en az 50 veriye ihtiyacım var.

muhittin_kaplan

Takipteyim Mucit.
Şu Büyük Font işini çözdüm mü sırada TP var.

Mucit23

#11
Hocam bende paint yapıyorum  8)

Kordinat işini hallettim. Kesik çizgi işinide hallettim. Şimdi arayüz hazırlıyorum.

buzkırıcı

Hocam @Mucit23

Siz TFT ekrana yazı,pencere vs gibi graphic user interface olarak ne kullanıyorsunuz? Kendiniz mi yazıyorsunuz bunları?
İmza Atmayı bilmem Parnak Bassam olur mu?

Mucit23

Çoğunu ben yazmadım.

Kullandığım LCD nin Driver Çipi SPFD5408,

Elimde bulunan MCBSTM32C deney kitinin örnek kodlarını kullanıyorum. Orada kütüphane var. Keil içerisinde bulabilirsiniz. Yalnız ben birkaç ekleme yaptım.

Normalde Circle, Rectangle, Line gibi fonksiyonlar yok. Bunları ben ekledim.

buzkırıcı

Seggerin emWin adlı GUI si mevcut lpcware.com dan buna bedavaya ulaşabilirsin, Bir incele istersen.  SPFD5408 adlı LCD driver çipinide destekliyor sanırsam(benim baktığım kadar).

http://www.lpcware.com/content/nxpfile/segger-emwin-518-documentation

emWin ile yapılmış Bir örnek olarak:



Sadece öneride bulunmak istedim. Haddimi aşmışsam affola..
İmza Atmayı bilmem Parnak Bassam olur mu?