亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? tsd_com.c

?? tft and touch program for at91sam9263ek,編程環境為keil
?? C
字號:
/* ----------------------------------------------------------------------------
 *         ATMEL Microcontroller Software Support
 * ----------------------------------------------------------------------------
 * Copyright (c) 2008, Atmel Corporation
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the disclaimer below.
 *
 * Atmel's name may not be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * ----------------------------------------------------------------------------
 */

//------------------------------------------------------------------------------
//         Headers
//------------------------------------------------------------------------------

#include "tsd.h"
#include <board.h>
#include <aic/aic.h>
#include <pio/pio.h>
#include <drivers/lcd/lcdd.h>
#include <drivers/lcd/draw.h>
#include <drivers/lcd/font.h>
#include <drivers/lcd/color.h>
#include <string.h>

//------------------------------------------------------------------------------
//         Local definitions
//------------------------------------------------------------------------------

/// Size in pixels of calibration points.
#define POINTS_SIZE         4
/// Maximum difference in pixels between the test point and the measured point.
#define POINTS_MAX_ERROR    8

/// Delay at the end of calibartion for result display (positive or negative)
#define DELAY_RESULT_DISPLAY 4000000

//------------------------------------------------------------------------------
//         Local types
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
/// Point used during the touchscreen calibration process.
//------------------------------------------------------------------------------
typedef struct _CalibrationPoint {

    /// Coordinate of point along the X-axis of the screen.
    unsigned int x;
    /// Coordinate of point along the Y-axis of the screen.
    unsigned int y;
    /// Calibration data of point.
    unsigned int data[2];

} CalibrationPoint;

//------------------------------------------------------------------------------
//         Local variables
//------------------------------------------------------------------------------

/// indicates if the touch screen has been calibrated.
/// If not, Callback functions are not called
static volatile unsigned char bCalibrationOk = 0;
/// Slope for interpoling touchscreen measurements along the X-axis.
static signed int xSlope;
/// Slope for interpoling touchscreen measurements along the Y-axis.
static signed int ySlope;

/// Calibration points
static CalibrationPoint calibrationPoints[] = {

    // Top-left corner calibration point
    {
        BOARD_LCD_WIDTH / 10,
        BOARD_LCD_HEIGHT / 10,
        {0, 0}
    },
    // Top-right corner calibration point
    {
        BOARD_LCD_WIDTH - BOARD_LCD_WIDTH / 10,
        BOARD_LCD_HEIGHT / 10,
        {0, 0}
    },
    // Bottom-right corner calibration point
    {
        BOARD_LCD_WIDTH - BOARD_LCD_WIDTH / 10,
        BOARD_LCD_HEIGHT - BOARD_LCD_HEIGHT / 10,
        {0, 0}
    },
    // Bottom-left corner calibration point
    {
        BOARD_LCD_WIDTH / 10,
        BOARD_LCD_HEIGHT - BOARD_LCD_HEIGHT / 10,
        {0, 0}
    }
};

/// Test point
static const CalibrationPoint testPoint = {
    BOARD_LCD_WIDTH / 2,
    BOARD_LCD_HEIGHT / 2,
    {0, 0}
};

//------------------------------------------------------------------------------
//         External functions
//------------------------------------------------------------------------------

extern void TSD_GetRawMeasurement(unsigned int *pData);
extern void TSD_WaitPenPressed(void);
extern void TSD_WaitPenReleased(void);

//------------------------------------------------------------------------------
//         Local functions
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
/// Display a calibration point on the given buffer.
/// \param pLcdBuffer  LCD buffer to draw on.
/// \param pPoint  Calibration point to display.
//------------------------------------------------------------------------------
static void DrawCalibrationPoint(
    void *pLcdBuffer,
    const CalibrationPoint *pPoint)
{
    LCDD_DrawRectangle(pLcdBuffer,
                       pPoint->x - POINTS_SIZE / 2,
                       pPoint->y - POINTS_SIZE / 2,
                       POINTS_SIZE,
                       POINTS_SIZE,
                       COLOR_RED);
}

//------------------------------------------------------------------------------
/// Clears a calibration point from the given buffer.
/// \param pLcdBuffer  LCD buffer to draw on.
/// \param pPoint  Calibration point to clear.
//------------------------------------------------------------------------------
static void ClearCalibrationPoint(
    void *pLcdBuffer,
    const CalibrationPoint *pPoint)
{
    LCDD_DrawRectangle(pLcdBuffer,
                       pPoint->x - POINTS_SIZE / 2,
                       pPoint->y - POINTS_SIZE / 2,
                       POINTS_SIZE,
                       POINTS_SIZE,
                       COLOR_WHITE);
}

//------------------------------------------------------------------------------
//         Global functions
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
/// Indicates if the calibration of the touch screen is Ok
/// \return 1 calibration Ok, 0 if not
//------------------------------------------------------------------------------
unsigned char TSDCom_IsCalibrationOk(void)
{
    return bCalibrationOk;
}

//------------------------------------------------------------------------------
/// Interpolates the provided raw measurements using the previously calculated
/// slope. The resulting x and y coordinates are stored in an array.
/// \param pData  Raw measurement data, as returned by TSD_GetRawMeasurement().
/// \param pPoint  Array in which x and y will be stored.
//------------------------------------------------------------------------------
void TSDCom_InterpolateMeasurement(const unsigned int *pData, unsigned int *pPoint)
{
    pPoint[0] = calibrationPoints[0].x
                - (((signed int) calibrationPoints[0].data[0] - (signed int) pData[0]) * 1024)
                / xSlope;

    pPoint[1] = calibrationPoints[0].y
                - (((signed int) calibrationPoints[0].data[1] - (signed int) pData[1]) * 1024)
                / ySlope;

    if(pPoint[0] & 0x80000000) // Is pPoint[0] negative ?
    {
        pPoint[0] = 0;
    }

    if(pPoint[0] > BOARD_LCD_WIDTH) // Is pPoint[0] bigger than the LCD width ?
    {
        pPoint[0] = BOARD_LCD_WIDTH;
    }

    if(pPoint[1] & 0x80000000) // Is pPoint[1] negative ?
    {
        pPoint[1] = 0;
    }

    if(pPoint[1] > BOARD_LCD_HEIGHT) // Is pPoint[1] bigger than the LCD width ?
    {
        pPoint[1] = BOARD_LCD_HEIGHT;
    }
}

//------------------------------------------------------------------------------
/// Performs the calibration process using the provided buffer to display
/// information.
/// \param pLcdBuffer  LCD buffer to display.
/// \return True if calibration was successful; otherwise false.
//------------------------------------------------------------------------------
unsigned char TSDCom_Calibrate(void *pLcdBuffer)
{
    void *pOldLcdBuffer;
    volatile unsigned int i; // to keep the tempo with gcc code optimisation
    signed int slope1, slope2;
    CalibrationPoint measuredPoint;
    unsigned char xOk, yOk;
    signed int xDiff, yDiff;

    // Calibration setup
    LCDD_Fill(pLcdBuffer, COLOR_WHITE);
    LCDD_DrawString(pLcdBuffer, 30, 50, "LCD calibration", COLOR_BLACK);
    LCDD_DrawString(pLcdBuffer, 1, 100, " Touch the dots to\ncalibrate the screen", COLOR_DARKBLUE);
    pOldLcdBuffer = LCDD_DisplayBuffer(pLcdBuffer);

    // Calibration points
    for (i=0; i < 4; i++) {

        DrawCalibrationPoint(pLcdBuffer, &calibrationPoints[i]);

        // Wait for touch & end of conversion
        TSD_WaitPenPressed();
        TSD_GetRawMeasurement(calibrationPoints[i].data);
        ClearCalibrationPoint(pLcdBuffer, &calibrationPoints[i]);

        // Wait for contact loss
        TSD_WaitPenReleased();
    }

    // Calculate slopes using the calibration data
    // Theory behind those calculations:
    //   - We suppose the touchscreen measurements are linear, so the following equations are true (simple
    //     linear regression) for any two 'a' and 'b' points of the screen:
    //       dx = (a.data[0] - b.data[0]) / (a.x - b.x)
    //       dy = (a.data[1] - b.data[1]) / (a.y - b.y)
    //
    //   - We calculate dx and dy (called xslope and yslope here) using the calibration points.
    //
    //   - We can then use dx and dy to infer the position of a point 'p' given the measurements performed
    //     by the touchscreen ('c' is any of the calibration points):
    //       dx = (p.data[0] - c.data[0]) / (p.x - c.x)
    //       dy = (p.data[1] - c.data[1]) / (p.y - c.y)
    //     Thus:
    //       p.x = c.x - (p.data[0] - c.data[0]) / dx
    //       p.y = c.y - (p.data[1] - c.data[1]) / dy
    //
    //   - Since there are four calibration points, dx and dy can be calculated twice, so we average
    //     the two values.
    slope1 = ((signed int) calibrationPoints[0].data[0]) - ((signed int) calibrationPoints[1].data[0]);
    slope1 *= 1024;
    slope1 /= ((signed int) calibrationPoints[0].x) - ((signed int) calibrationPoints[1].x);
    slope2 = ((signed int) calibrationPoints[2].data[0]) - ((signed int) calibrationPoints[3].data[0]);
    slope2 *= 1024;
    slope2 /= ((signed int) calibrationPoints[2].x) - ((signed int) calibrationPoints[3].x);
    xSlope = (slope1 + slope2) / 2;

    slope1 = ((signed int) calibrationPoints[0].data[1]) - ((signed int) calibrationPoints[2].data[1]);
    slope1 *= 1024;
    slope1 /= ((signed int) calibrationPoints[0].y) - ((signed int) calibrationPoints[2].y);
    slope2 = ((signed int) calibrationPoints[1].data[1]) - ((signed int) calibrationPoints[3].data[1]);
    slope2 *= 1024;
    slope2 /= ((signed int) calibrationPoints[1].y) - ((signed int) calibrationPoints[3].y);
    ySlope = (slope1 + slope2) / 2;

    // Test point
    LCDD_Fill(pLcdBuffer, 0xFFFFFF);
    LCDD_DrawString(pLcdBuffer, 30, 50, "LCD calibration", COLOR_BLACK);
    LCDD_DrawString(pLcdBuffer, 1, 100, " Touch the point to\nvalidate calibration", COLOR_DARKBLUE);
    DrawCalibrationPoint(pLcdBuffer, &testPoint);

    // Wait for touch & end of conversion
    TSD_WaitPenPressed();

    TSD_GetRawMeasurement(measuredPoint.data);
    TSDCom_InterpolateMeasurement(measuredPoint.data, (unsigned int *) &measuredPoint);
    DrawCalibrationPoint(pLcdBuffer, &measuredPoint);

    // Check resulting x and y
    xDiff = (signed int) measuredPoint.x - (signed int) testPoint.x;
    yDiff = (signed int) measuredPoint.y - (signed int) testPoint.y;
    xOk = (xDiff >= -POINTS_MAX_ERROR) && (xDiff <= POINTS_MAX_ERROR);
    yOk = (yDiff >= -POINTS_MAX_ERROR) && (yDiff <= POINTS_MAX_ERROR);

    // Wait for contact loss
    TSD_WaitPenReleased();

    // Check calibration result
    if (xOk && yOk) {

        bCalibrationOk = 1;
        LCDD_Fill(pLcdBuffer, COLOR_WHITE);
        LCDD_DrawString(pLcdBuffer, 30, 50, "LCD calibration", COLOR_BLACK);
        LCDD_DrawString(pLcdBuffer, 80, 100, "Success !", COLOR_GREEN);

    }
    else {

        bCalibrationOk = 0;
        LCDD_Fill(pLcdBuffer, COLOR_WHITE);
        LCDD_DrawString(pLcdBuffer, 30, 50, "LCD calibration", COLOR_BLACK);
        LCDD_DrawString(pLcdBuffer, 40, 100, "Error too big", COLOR_RED);
    }

    // Slight delay
    for (i = 0; i < DELAY_RESULT_DISPLAY; i++);

    // Restore old LCD buffer
    LCDD_DisplayBuffer(pOldLcdBuffer);

    return (xOk && yOk);
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色噜噜夜夜夜综合网| 久久久.com| 久久久美女艺术照精彩视频福利播放| 亚洲欧美综合网| 韩国视频一区二区| 在线精品视频小说1| 欧美国产一区二区在线观看| 日本女优在线视频一区二区| 91黄视频在线观看| 国产精品美女久久久久久2018 | zzijzzij亚洲日本少妇熟睡| 欧美电视剧免费观看| 亚洲成人动漫精品| 色爱区综合激月婷婷| 中文字幕一区二区三区四区不卡| 久久97超碰国产精品超碰| 欧美剧情片在线观看| 伊人色综合久久天天| 一本大道久久a久久综合婷婷| 日本一区二区三区四区| 国产精品一区二区男女羞羞无遮挡 | 欧美一区二区福利在线| 五月综合激情日本mⅴ| 在线中文字幕不卡| 一区二区三区四区亚洲| 色播五月激情综合网| 日韩一区在线看| 色悠悠亚洲一区二区| 一区二区三区四区中文字幕| 色综合中文综合网| 欧美日本一区二区在线观看| 亚洲资源在线观看| 欧美性高清videossexo| 亚洲国产裸拍裸体视频在线观看乱了| 色综合天天性综合| 亚洲综合清纯丝袜自拍| 91国偷自产一区二区三区观看| 综合亚洲深深色噜噜狠狠网站| 99久久国产免费看| 亚洲一区二区精品3399| 欧美日韩午夜在线视频| 午夜天堂影视香蕉久久| 日韩一区二区高清| 国产做a爰片久久毛片| 久久久www成人免费无遮挡大片| 国产精品一二三四区| 亚洲丝袜另类动漫二区| 欧美性色欧美a在线播放| 日本不卡在线视频| 亚洲精品一区二区三区四区高清| 懂色一区二区三区免费观看| 亚洲视频一区在线| 91麻豆精品国产91久久久使用方法| 狂野欧美性猛交blacked| 国产亚洲午夜高清国产拍精品| 91麻豆精品视频| 另类小说视频一区二区| 中文字幕在线一区免费| 欧美视频一区二| 国产在线播放一区三区四| 最好看的中文字幕久久| 欧美一区二区三区色| 国产成人日日夜夜| 亚洲一区二区三区三| 久久综合视频网| 色欧美乱欧美15图片| 久久国产乱子精品免费女| 18涩涩午夜精品.www| 日韩免费高清av| 色综合色综合色综合色综合色综合| 婷婷国产v国产偷v亚洲高清| 亚洲国产电影在线观看| 日韩一区二区三区在线| 色婷婷激情一区二区三区| 精品在线一区二区三区| 亚洲在线观看免费| 欧美激情一区二区三区不卡| 日韩欧美国产综合| 欧美在线观看一区| 成人一区二区在线观看| 奇米四色…亚洲| 亚洲第一精品在线| 国产精品久久久久影院亚瑟| 日韩欧美成人一区二区| 欧美色综合网站| 99久久伊人网影院| 国产乱子轮精品视频| 日本欧美久久久久免费播放网| 亚洲人成精品久久久久久 | 91精品国产乱码| 一本到不卡精品视频在线观看| 国产a视频精品免费观看| 日本一道高清亚洲日美韩| 亚洲国产成人va在线观看天堂| 国产精品福利一区| 亚洲国产精品二十页| 久久亚洲精品小早川怜子| 欧美精品第1页| 欧美视频一区二区在线观看| 一本久道久久综合中文字幕| av激情亚洲男人天堂| 成人黄色片在线观看| 国产精品一区二区三区四区 | 久久精品欧美日韩| 91精品国产黑色紧身裤美女| 欧美人与z0zoxxxx视频| 欧美午夜电影网| 欧美三级在线看| 欧美性色欧美a在线播放| 欧美影院一区二区三区| 欧美午夜在线一二页| 色综合天天性综合| 91久久精品一区二区三| 日本韩国欧美三级| 欧美亚洲一区二区三区四区| 欧美系列亚洲系列| 欧美精品日日鲁夜夜添| 日韩欧美一二区| 久久久影院官网| 国产精品电影一区二区| 最新日韩在线视频| 一区二区三区四区高清精品免费观看 | 人禽交欧美网站| 另类的小说在线视频另类成人小视频在线| 日韩电影一区二区三区| 精品一二三四区| 国产99久久久久久免费看农村| 成人综合激情网| 91麻豆免费看片| 欧美福利电影网| 欧美精品一区二区三区高清aⅴ| 久久精品网站免费观看| 国产精品三级电影| 亚洲综合成人在线视频| 美女视频黄a大片欧美| 国产成人免费视频网站| 色综合久久久久久久| 欧美一区午夜视频在线观看| 久久精品亚洲精品国产欧美kt∨| 亚洲欧美日韩在线播放| 日韩成人一区二区三区在线观看| 国产成人亚洲综合a∨婷婷| 91丨porny丨首页| 欧美一卡二卡在线| 国产欧美精品区一区二区三区| 一区二区三区蜜桃| 韩国三级电影一区二区| 在线观看免费亚洲| 日韩一区二区三区在线| 国产精品国产三级国产专播品爱网 | 欧美一级片免费看| 欧美国产精品一区| 日韩黄色免费电影| 高清shemale亚洲人妖| 欧美日韩免费一区二区三区视频| 精品国产不卡一区二区三区| 亚洲欧美激情在线| 黄色小说综合网站| 欧美性受xxxx| 国产精品三级av| 青青青爽久久午夜综合久久午夜| 91一区二区在线观看| 久久久久久久久久久黄色| 亚洲成人动漫一区| 不卡视频一二三| 亚洲精品在线观看网站| 五月天国产精品| 色综合久久99| 国产精品美女视频| 韩国毛片一区二区三区| 91.成人天堂一区| 亚洲日本电影在线| 成人久久视频在线观看| 精品日韩99亚洲| 性做久久久久久久免费看| 92国产精品观看| 中文字幕乱码亚洲精品一区| 国产乱子伦视频一区二区三区| 911精品国产一区二区在线| 亚洲一区在线观看网站| 9i在线看片成人免费| 国产无一区二区| 国产综合色精品一区二区三区| 欧美一区二区免费| 午夜精品久久一牛影视| 欧美视频一区二区三区四区 | 亚洲一区二区精品视频| 成人av资源网站| 国产女主播视频一区二区| 国内成+人亚洲+欧美+综合在线| 欧美一区二区大片| 免费观看久久久4p| 日韩一级高清毛片| 日本va欧美va欧美va精品| 欧美裸体bbwbbwbbw| 丝袜亚洲另类欧美| 欧美一区二区三级| 青青草91视频| 欧美成人伊人久久综合网| 久久99精品一区二区三区|