通过STM32CubeMX移植TouchGFX

This commit is contained in:
wlk 2019-12-12 12:02:32 +08:00
parent 62aaa9c48d
commit 365ffdc28c
1642 changed files with 22585 additions and 10147 deletions

View File

@ -1,264 +0,0 @@
/**
******************************************************************************
* @file stm32f4xx_hal_exti.h
* @author MCD Application Team
* @brief Header file of EXTI HAL module.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2018 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32f4xx_HAL_EXTI_H
#define STM32f4xx_HAL_EXTI_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal_def.h"
/** @addtogroup STM32F4xx_HAL_Driver
* @{
*/
/** @defgroup EXTI EXTI
* @brief EXTI HAL module driver
* @{
*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup EXTI_Exported_Types EXTI Exported Types
* @{
*/
typedef enum
{
HAL_EXTI_COMMON_CB_ID = 0x00U,
HAL_EXTI_RISING_CB_ID = 0x01U,
HAL_EXTI_FALLING_CB_ID = 0x02U,
} EXTI_CallbackIDTypeDef;
/**
* @brief EXTI Handle structure definition
*/
typedef struct
{
uint32_t Line; /*!< Exti line number */
void (* RisingCallback)(void); /*!< Exti rising callback */
void (* FallingCallback)(void); /*!< Exti falling callback */
} EXTI_HandleTypeDef;
/**
* @brief EXTI Configuration structure definition
*/
typedef struct
{
uint32_t Line; /*!< The Exti line to be configured. This parameter
can be a value of @ref EXTI_Line */
uint32_t Mode; /*!< The Exit Mode to be configured for a core.
This parameter can be a combination of @ref EXTI_Mode */
uint32_t Trigger; /*!< The Exti Trigger to be configured. This parameter
can be a value of @ref EXTI_Trigger */
} EXTI_ConfigTypeDef;
/**
* @}
*/
/* Exported constants --------------------------------------------------------*/
/** @defgroup EXTI_Exported_Constants EXTI Exported Constants
* @{
*/
/** @defgroup EXTI_Line EXTI Line
* @{
*/
#define EXTI_LINE_0 EXTI_IMR_IM0 /*!< External interrupt line 0 */
#define EXTI_LINE_1 EXTI_IMR_IM1 /*!< External interrupt line 1 */
#define EXTI_LINE_2 EXTI_IMR_IM2 /*!< External interrupt line 2 */
#define EXTI_LINE_3 EXTI_IMR_IM3 /*!< External interrupt line 3 */
#define EXTI_LINE_4 EXTI_IMR_IM4 /*!< External interrupt line 4 */
#define EXTI_LINE_5 EXTI_IMR_IM5 /*!< External interrupt line 5 */
#define EXTI_LINE_6 EXTI_IMR_IM6 /*!< External interrupt line 6 */
#define EXTI_LINE_7 EXTI_IMR_IM7 /*!< External interrupt line 7 */
#define EXTI_LINE_8 EXTI_IMR_IM8 /*!< External interrupt line 8 */
#define EXTI_LINE_9 EXTI_IMR_IM9 /*!< External interrupt line 9 */
#define EXTI_LINE_10 EXTI_IMR_IM10 /*!< External interrupt line 10 */
#define EXTI_LINE_11 EXTI_IMR_IM11 /*!< External interrupt line 11 */
#define EXTI_LINE_12 EXTI_IMR_IM12 /*!< External interrupt line 12 */
#define EXTI_LINE_13 EXTI_IMR_IM13 /*!< External interrupt line 13 */
#define EXTI_LINE_14 EXTI_IMR_IM14 /*!< External interrupt line 14 */
#define EXTI_LINE_15 EXTI_IMR_IM15 /*!< External interrupt line 15 */
#define EXTI_LINE_16 EXTI_IMR_IM16 /*!< External interrupt line 16 Connected to the PVD Output */
#define EXTI_LINE_17 EXTI_IMR_IM17 /*!< External interrupt line 17 Connected to the RTC Alarm event */
#define EXTI_LINE_18 EXTI_IMR_IM18 /*!< External interrupt line 18 Connected to the USB OTG FS Wakeup from suspend event */
#define EXTI_LINE_19 EXTI_IMR_IM19 /*!< External interrupt line 19 Connected to the Ethernet Wakeup event */
#define EXTI_LINE_20 EXTI_IMR_IM20 /*!< External interrupt line 20 Connected to the USB OTG HS (configured in FS) Wakeup event */
#define EXTI_LINE_21 EXTI_IMR_IM21 /*!< External interrupt line 21 Connected to the RTC Tamper and Time Stamp events */
#define EXTI_LINE_22 EXTI_IMR_IM22 /*!< External interrupt line 22 Connected to the RTC Wakeup event */
/**
* @}
*/
/** @defgroup EXTI_Mode EXTI Mode
* @{
*/
#define EXTI_MODE_INTERRUPT 0x00000000U
#define EXTI_MODE_EVENT 0x00000004U
/**
* @}
*/
/** @defgroup EXTI_Trigger EXTI Trigger
* @{
*/
#define EXTI_TRIGGER_RISING 0x00000008U
#define EXTI_TRIGGER_FALLING 0x0000000CU
#define EXTI_TRIGGER_RISING_FALLING 0x00000010U
/**
* @}
*/
/**
* @}
*/
/* Exported macro ------------------------------------------------------------*/
/** @defgroup EXTI_Exported_Macros EXTI Exported Macros
* @{
*/
/**
* @}
*/
/* Private constants --------------------------------------------------------*/
/** @defgroup EXTI_Private_Constants EXTI Private Constants
* @{
*/
/**
* @brief EXTI Mask for interrupt & event mode
*/
#define EXTI_MODE_MASK (EXTI_MODE_EVENT | EXTI_MODE_INTERRUPT)
/**
* @brief EXTI Mask for trigger possibilities
*/
#define EXTI_TRIGGER_MASK (EXTI_TRIGGER_RISING | EXTI_TRIGGER_FALLING | EXTI_TRIGGER_RISING_FALLING)
/**
* @brief EXTI Line number
*/
#define EXTI_LINE_NB 23UL
/**
* @}
*/
/* Private macros ------------------------------------------------------------*/
/** @defgroup EXTI_Private_Macros EXTI Private Macros
* @{
*/
#define IS_EXTI_LINE(__LINE__) (((__LINE__) == EXTI_LINE_0) || \
((__LINE__) == EXTI_LINE_1) || \
((__LINE__) == EXTI_LINE_2) || \
((__LINE__) == EXTI_LINE_3) || \
((__LINE__) == EXTI_LINE_4) || \
((__LINE__) == EXTI_LINE_5) || \
((__LINE__) == EXTI_LINE_6) || \
((__LINE__) == EXTI_LINE_7) || \
((__LINE__) == EXTI_LINE_8) || \
((__LINE__) == EXTI_LINE_9) || \
((__LINE__) == EXTI_LINE_10) || \
((__LINE__) == EXTI_LINE_11) || \
((__LINE__) == EXTI_LINE_12) || \
((__LINE__) == EXTI_LINE_13) || \
((__LINE__) == EXTI_LINE_14) || \
((__LINE__) == EXTI_LINE_15) || \
((__LINE__) == EXTI_LINE_16) || \
((__LINE__) == EXTI_LINE_17) || \
((__LINE__) == EXTI_LINE_18) || \
((__LINE__) == EXTI_LINE_19) || \
((__LINE__) == EXTI_LINE_20) || \
((__LINE__) == EXTI_LINE_21) || \
((__LINE__) == EXTI_LINE_22))
#define IS_EXTI_MODE(__LINE__) ((((__LINE__) & ~EXTI_MODE_MASK) == 0x00U))
#define IS_EXTI_TRIGGER(__LINE__) (((__LINE__) & ~EXTI_TRIGGER_MASK) == 0x00U)
#define IS_EXTI_PENDING_EDGE(__LINE__) (((__LINE__) == EXTI_TRIGGER_FALLING) || \
((__LINE__) == EXTI_TRIGGER_RISING) || \
((__LINE__) == EXTI_TRIGGER_RISING_FALLING))
#define IS_EXTI_GPIO_PIN(__PIN__) ((__PIN__) < 16U)
/**
* @}
*/
/* Exported functions --------------------------------------------------------*/
/** @defgroup EXTI_Exported_Functions EXTI Exported Functions
* @brief EXTI Exported Functions
* @{
*/
/** @defgroup EXTI_Exported_Functions_Group1 Configuration functions
* @brief Configuration functions
* @{
*/
/* Configuration functions ****************************************************/
HAL_StatusTypeDef HAL_EXTI_SetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig);
HAL_StatusTypeDef HAL_EXTI_GetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig);
HAL_StatusTypeDef HAL_EXTI_ClearConfigLine(EXTI_HandleTypeDef *hexti);
HAL_StatusTypeDef HAL_EXTI_RegisterCallback(EXTI_HandleTypeDef *hexti, EXTI_CallbackIDTypeDef CallbackID, void (*pPendingCbfn)(void));
HAL_StatusTypeDef HAL_EXTI_GetHandle(EXTI_HandleTypeDef *hexti, uint32_t ExtiLine);
/**
* @}
*/
/** @defgroup EXTI_Exported_Functions_Group2 IO operation functions
* @brief IO operation functions
* @{
*/
/* IO operation functions *****************************************************/
void HAL_EXTI_IRQHandler(EXTI_HandleTypeDef *hexti);
uint32_t HAL_EXTI_GetPending(EXTI_HandleTypeDef *hexti, uint32_t Edge);
void HAL_EXTI_ClearPending(EXTI_HandleTypeDef *hexti, uint32_t Edge);
void HAL_EXTI_GenerateSWI(EXTI_HandleTypeDef *hexti);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* STM32f4xx_HAL_EXTI_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +0,0 @@
#include <touchgfx/Font.hpp>
FONT_KERNING_LOCATION_FLASH_PRAGMA
KEEP extern const touchgfx::KerningNode kerning_verdana_20_4bpp[] FONT_KERNING_LOCATION_FLASH_ATTRIBUTE =
{
{ 0, 0 }
};

View File

@ -1,24 +0,0 @@
// Autogenerated, do not edit
#include <fonts/GeneratedFont.hpp>
FONT_TABLE_LOCATION_FLASH_PRAGMA
KEEP extern const touchgfx::GlyphNode glyphs_verdana_20_4bpp[] FONT_TABLE_LOCATION_FLASH_ATTRIBUTE =
{
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
// verdana_20_4bpp
extern const touchgfx::GlyphNode glyphs_verdana_20_4bpp[];
extern const uint8_t* const unicodes_verdana_20_4bpp[] =
{
0
};
extern const touchgfx::KerningNode kerning_verdana_20_4bpp[];
touchgfx::GeneratedFont& getFont_verdana_20_4bpp();
touchgfx::GeneratedFont& getFont_verdana_20_4bpp()
{
static touchgfx::GeneratedFont verdana_20_4bpp(glyphs_verdana_20_4bpp, 0, 20, 0, 4, 1, 0, 0, unicodes_verdana_20_4bpp, kerning_verdana_20_4bpp, 0, 0, 0);
return verdana_20_4bpp;
}

View File

@ -1,24 +0,0 @@
// Autogenerated, do not edit
#include <fonts/GeneratedFont.hpp>
FONT_TABLE_LOCATION_FLASH_PRAGMA
KEEP extern const touchgfx::GlyphNode glyphs_verdana_40_4bpp[] FONT_TABLE_LOCATION_FLASH_ATTRIBUTE =
{
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
// verdana_40_4bpp
extern const touchgfx::GlyphNode glyphs_verdana_40_4bpp[];
extern const uint8_t* const unicodes_verdana_40_4bpp[] =
{
0
};
extern const touchgfx::KerningNode kerning_verdana_40_4bpp[];
touchgfx::GeneratedFont& getFont_verdana_40_4bpp();
touchgfx::GeneratedFont& getFont_verdana_40_4bpp()
{
static touchgfx::GeneratedFont verdana_40_4bpp(glyphs_verdana_40_4bpp, 0, 40, 0, 4, 1, 0, 0, unicodes_verdana_40_4bpp, kerning_verdana_40_4bpp, 0, 0, 0);
return verdana_40_4bpp;
}

View File

@ -1,18 +0,0 @@
/*********************************************************************************/
/********** THIS FILE IS GENERATED BY TOUCHGFX DESIGNER, DO NOT MODIFY ***********/
/*********************************************************************************/
#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>
#include <touchgfx/Color.hpp>
Screen1ViewBase::Screen1ViewBase()
{
box1.setPosition(0, 0, 800, 480);
box1.setColor(touchgfx::Color::getColorFrom24BitRGB(255, 255, 255));
add(box1);
}
void Screen1ViewBase::setupScreen()
{
}

View File

@ -1 +0,0 @@
{"languages":[],"textids":[]}

View File

@ -1 +0,0 @@
{"remap":"yes","languages":[],"characters":[]}

View File

@ -1 +0,0 @@
{"databases":{"DEFAULT":[]},"database_list":[],"fonts":{"getFont_verdana_20_4bpp":0,"getFont_verdana_40_4bpp":1,"getFont_verdana_10_4bpp":2}}

View File

@ -1,71 +0,0 @@
{
"Application": {
"Screens": [
{
"Components": [
{
"Color": {
"Red": 255,
"Green": 255,
"Blue": 255
},
"Alpha": 255,
"Name": "box1",
"X": 0,
"Y": 0,
"Width": 800,
"Height": 480,
"Type": "Box",
"Visible": true,
"Draggable": false,
"Clickable": false,
"Fadeable": false,
"Moveable": false
}
],
"Interactions": [],
"Name": "Screen1",
"OverrideDefaultBufferSize": false,
"CanvasBufferSize": 0
}
],
"CustomContainerDefinitions": [],
"Name": "MyApplication",
"Resolution": {
"Width": 800,
"Height": 480
},
"SelectedColorDepth": 24,
"StartupScreenName": "Screen1",
"SelectedStartupLanguage": "GB",
"Skin": "Blue",
"TouchGfxPath": "../Middlewares/ST/TouchGFX/touchgfx/",
"UIPath": ".",
"ApplicationTemplate": {
"Name": "Simulator",
"Version": "1.0.0",
"Description": "STM32CubeMX Generated Simulator Application Template",
"AvailableColorDepths": [
24
],
"AvailableSections": [
"ExtFlashSection",
"IntFlashSection"
],
"AvailableResolutions": [],
"PhysicalButtons": [],
"GenerateAssetsCommand": "make -f simulator/gcc/Makefile assets -j10",
"PostGenerateCommand": "touchgfx update_project --project-file=..\\MDK-ARM\\hellotouchGFX_demo.uvprojx --gui-group-name=Application/User/TouchGFX/gui --generated-group-name=Application/User/TouchGFX/generated",
"CompileSimulatorCommand": "make -f simulator/gcc/Makefile -j10",
"RunSimulatorCommand": "build\\bin\\simulator.exe",
"CompileTargetCommand": "",
"FlashTargetCommand": ""
},
"LandscapeSkinX": 0,
"LandscapeSkinY": 0,
"PortraitSkinX": 0,
"PortraitSkinY": 0,
"DisplayOrientation": "Landscape"
},
"Version": "4.12.3"
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,435 @@
/**
******************************************************************************
* @file bsp_i2c_ee.c
* @author STMicroelectronics
* @version V1.0
* @date 2015-xx-xx
* @brief <EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ר<EFBFBD><EFBFBD>iic<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
******************************************************************************
* @attention
*
* ʵ<EFBFBD><EFBFBD>ƽ̨:Ұ<EFBFBD><EFBFBD> STM32 F429 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD>̳ :http://www.firebbs.cn
* <EFBFBD>Ա<EFBFBD> :https://fire-stm32.taobao.com
*
******************************************************************************
*/
#include "bsp_i2c_touch.h"
#include "gt9xx.h"
/* STM32 I2C <20><><EFBFBD><EFBFBD>ģʽ */
#define I2C_Speed 400000
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַֻҪ<D6BB><D2AA>STM32<33><32><EFBFBD>ҵ<EFBFBD>I2C<32><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define I2C_OWN_ADDRESS7 0x0A
static void Delay(__IO uint32_t nCount) //<2F>򵥵<EFBFBD><F2B5A5B5><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
{
for(; nCount != 0; nCount--);
}
/**
* @brief EXTI line detection callbacks.
* @param GPIO_Pin Specifies the pins connected EXTI line
* @retval None
*/
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == GPIO_PIN_13)
{
}
}
/**
* @brief ʹ<EFBFBD>ܴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
* @param <EFBFBD><EFBFBD>
* @retval <EFBFBD><EFBFBD>
*/
void I2C_GTP_IRQEnable(void)
{
}
/**
* @brief <EFBFBD>رմ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
* @param <EFBFBD><EFBFBD>
* @retval <EFBFBD><EFBFBD>
*/
void I2C_GTP_IRQDisable(void)
{
}
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> I/O<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param <EFBFBD><EFBFBD>
* @retval <EFBFBD><EFBFBD>
*/
static void I2C_GPIO_Config(void)
{
}
/**
* @brief <EFBFBD><EFBFBD>GT91xxоƬ<EFBFBD><EFBFBD><EFBFBD>и<EFBFBD>λ
* @param <EFBFBD><EFBFBD>
* @retval <EFBFBD><EFBFBD>
*/
void I2C_ResetChip(void)
{
/*<2A><>λΪ<CEBB>͵<EFBFBD>ƽ<EFBFBD><C6BD>Ϊ<EFBFBD><CEAA>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>׼<EFBFBD><D7BC>*/
HAL_GPIO_WritePin (GTP_RST_GPIO_PORT,CTP_RSTN_Pin,GPIO_PIN_RESET);
Delay(0x0FFFFF);
/*<2A><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʱ<EFBFBD><EFBFBD><E4A3AC><EFBFBD>г<EFBFBD>ʼ<EFBFBD><CABC>*/
HAL_GPIO_WritePin (GTP_RST_GPIO_PORT,CTP_RSTN_Pin,GPIO_PIN_SET);
Delay(0x0FFFFF);
}
/**
* @brief I2C <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param <EFBFBD><EFBFBD>
* @retval <EFBFBD><EFBFBD>
*/
/**
* @brief I2C <EFBFBD><EFBFBD><EFBFBD><EFBFBD>(GT91xx)<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
* @param <EFBFBD><EFBFBD>
* @retval <EFBFBD><EFBFBD>
*/
void I2C_Touch_Init(void)
{
I2C_GPIO_Config();
I2C_ResetChip();
I2C_GTP_IRQEnable();
}
/*
*********************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: i2c_Delay
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>: I2C<EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>ӳ٣<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>400KHz
* <EFBFBD><EFBFBD> <EFBFBD>Σ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> ֵ: <EFBFBD><EFBFBD>
*********************************************************************************************************
*/
static void i2c_Delay(void)
{
uint8_t i;
/*<2A><>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD>߼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD><EFBFBD>Եõ<EFBFBD><EFBFBD>ġ<EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CPU<EFBFBD><EFBFBD>Ƶ180MHz <EFBFBD><EFBFBD>MDK<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><EFBFBD><EFBFBD>Ż<EFBFBD>
ѭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ50ʱ<EFBFBD><EFBFBD>SCLƵ<EFBFBD><EFBFBD> = 333KHz
ѭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ30ʱ<EFBFBD><EFBFBD>SCLƵ<EFBFBD><EFBFBD> = 533KHz<EFBFBD><EFBFBD>
ѭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ20ʱ<EFBFBD><EFBFBD>SCLƵ<EFBFBD><EFBFBD> = 727KHz<EFBFBD><EFBFBD>
*/
for (i = 0; i < 10*5; i++);
}
/*
*********************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: i2c_Start
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>: CPU<EFBFBD><EFBFBD><EFBFBD><EFBFBD>I2C<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD>Σ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> ֵ: <EFBFBD><EFBFBD>
*********************************************************************************************************
*/
void i2c_Start(void)
{
SDA_OUT();
/* <20><>SCL<43>ߵ<EFBFBD>ƽʱ<C6BD><CAB1>SDA<44><41><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD>ʾI2C<32><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD> */
I2C_SDA_1();
I2C_SCL_1();
i2c_Delay();
I2C_SDA_0();
i2c_Delay();
I2C_SCL_0();
i2c_Delay();
}
/*
*********************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: i2c_Start
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>: CPU<EFBFBD><EFBFBD><EFBFBD><EFBFBD>I2C<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣ<EFBFBD>ź<EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD>Σ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> ֵ: <EFBFBD><EFBFBD>
*********************************************************************************************************
*/
void i2c_Stop(void)
{
SDA_OUT();
/* <20><>SCL<43>ߵ<EFBFBD>ƽʱ<C6BD><CAB1>SDA<44><41><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD>ʾI2C<32><43><EFBFBD><EFBFBD>ֹͣ<CDA3>ź<EFBFBD> */
I2C_SDA_0();
I2C_SCL_1();
i2c_Delay();
I2C_SDA_1();
}
/*
*********************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: i2c_SendByte
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>: CPU<EFBFBD><EFBFBD>I2C<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>8bit<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD>Σ<EFBFBD>_ucByte <EFBFBD><EFBFBD> <EFBFBD>ȴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD>ֽ<EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> ֵ: <EFBFBD><EFBFBD>
*********************************************************************************************************
*/
void i2c_SendByte(uint8_t _ucByte)
{
uint8_t i;
SDA_OUT();
/* <20>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>ֽڵĸ<DAB5>λbit7 */
for (i = 0; i < 8; i++)
{
if (_ucByte & 0x80)
{
I2C_SDA_1();
}
else
{
I2C_SDA_0();
}
i2c_Delay();
I2C_SCL_1();
i2c_Delay();
I2C_SCL_0();
if (i == 7)
{
I2C_SDA_1(); // <20>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD>
}
_ucByte <<= 1; /* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>bit */
i2c_Delay();
}
}
/*
*********************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: i2c_ReadByte
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>: CPU<EFBFBD><EFBFBD>I2C<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ8bit<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD>Σ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> ֵ: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*********************************************************************************************************
*/
uint8_t i2c_ReadByte(void)
{
uint8_t i;
uint8_t value;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31>bitΪ<74><CEAA><EFBFBD>ݵ<EFBFBD>bit7 */
value = 0;
for (i = 0; i < 8; i++)
{
value <<= 1;
SDA_IN();
I2C_SCL_1();
i2c_Delay();
if (I2C_SDA_READ())
{
value++;
}
I2C_SCL_0();
i2c_Delay();
}
return value;
}
/*
*********************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: i2c_WaitAck
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>: CPU<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>ʱ<EFBFBD>ӣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ACKӦ<EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD>Σ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> ֵ: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ȷӦ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ
*********************************************************************************************************
*/
uint8_t i2c_WaitAck(void)
{
uint8_t re;
SDA_IN();
I2C_SDA_1(); /* CPU<50>ͷ<EFBFBD>SDA<44><41><EFBFBD><EFBFBD> */
i2c_Delay();
I2C_SCL_1(); /* CPU<50><55><EFBFBD><EFBFBD>SCL = 1, <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1B7B5>ACKӦ<4B><D3A6> */
i2c_Delay();
if (I2C_SDA_READ()) /* CPU<50><55>ȡSDA<44><41><EFBFBD><EFBFBD>״̬ */
{
re = 1;
}
else
{
re = 0;
}
I2C_SCL_0();
i2c_Delay();
return re;
}
/*
*********************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: i2c_Ack
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>: CPU<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>ACK<EFBFBD>ź<EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD>Σ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> ֵ: <EFBFBD><EFBFBD>
*********************************************************************************************************
*/
void i2c_Ack(void)
{
SDA_OUT();
I2C_SDA_0(); /* CPU<50><55><EFBFBD><EFBFBD>SDA = 0 */
i2c_Delay();
I2C_SCL_1(); /* CPU<50><55><EFBFBD><EFBFBD>1<EFBFBD><31>ʱ<EFBFBD><CAB1> */
i2c_Delay();
I2C_SCL_0();
i2c_Delay();
I2C_SDA_1(); /* CPU<50>ͷ<EFBFBD>SDA<44><41><EFBFBD><EFBFBD> */
}
/*
*********************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: i2c_NAck
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>: CPU<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><EFBFBD>NACK<EFBFBD>ź<EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD>Σ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> ֵ: <EFBFBD><EFBFBD>
*********************************************************************************************************
*/
void i2c_NAck(void)
{
SDA_OUT();
I2C_SDA_1(); /* CPU<50><55><EFBFBD><EFBFBD>SDA = 1 */
i2c_Delay();
I2C_SCL_1(); /* CPU<50><55><EFBFBD><EFBFBD>1<EFBFBD><31>ʱ<EFBFBD><CAB1> */
i2c_Delay();
I2C_SCL_0();
i2c_Delay();
}
#define I2C_DIR_WR 0 /* д<><D0B4><EFBFBD><EFBFBD>bit */
#define I2C_DIR_RD 1 /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bit */
/**
* @brief ʹ<EFBFBD><EFBFBD>IIC<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param
* @arg ClientAddr:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
* @arg pBuffer:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɴӻ<EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @arg NumByteToRead:<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
* @retval <EFBFBD><EFBFBD>
*/
uint32_t I2C_ReadBytes(uint8_t ClientAddr,uint8_t* pBuffer, uint16_t NumByteToRead)
{
/* <20><>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>I2C<32><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD> */
i2c_Start();
/* <20><>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽڣ<D6BD><DAA3><EFBFBD>7bit<69>ǵ<EFBFBD>ַ<EFBFBD><D6B7>bit0<74>Ƕ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>0<EFBFBD><30>ʾд<CABE><D0B4>1<EFBFBD><31>ʾ<EFBFBD><CABE> */
i2c_SendByte(ClientAddr | I2C_DIR_RD); /* <20>˴<EFBFBD><CBB4>Ƕ<EFBFBD>ָ<EFBFBD><D6B8> */
/* <20><>3<EFBFBD><33><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD>ACK */
if (i2c_WaitAck() != 0)
{
goto cmd_fail; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6> */
}
while(NumByteToRead)
{
if(NumByteToRead == 1)
{
i2c_NAck(); /* <20><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD>ֽڶ<D6BD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CPU<50><55><EFBFBD><EFBFBD>NACK<43>ź<EFBFBD>(<28><><EFBFBD><EFBFBD>SDA = 1) */
/* <20><><EFBFBD><EFBFBD>I2C<32><43><EFBFBD><EFBFBD>ֹͣ<CDA3>ź<EFBFBD> */
i2c_Stop();
}
*pBuffer = i2c_ReadByte();
/* <20><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
pBuffer++;
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD> */
NumByteToRead--;
i2c_Ack(); /* <20>м<EFBFBD><D0BC>ֽڶ<D6BD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CPU<50><55><EFBFBD><EFBFBD>ACK<43>ź<EFBFBD>(<28><><EFBFBD><EFBFBD>SDA = 0) */
}
/* <20><><EFBFBD><EFBFBD>I2C<32><43><EFBFBD><EFBFBD>ֹͣ<CDA3>ź<EFBFBD> */
i2c_Stop();
return 0; /* ִ<>гɹ<D0B3> */
cmd_fail: /* <20><><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>ʧ<EFBFBD>ܺ<EFBFBD><DCBA><EFBFBD><EFBFBD>мǷ<D0BC><C7B7><EFBFBD>ֹͣ<CDA3>źţ<C5BA><C5A3><EFBFBD><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0>I2C<32><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸 */
/* <20><><EFBFBD><EFBFBD>I2C<32><43><EFBFBD><EFBFBD>ֹͣ<CDA3>ź<EFBFBD> */
i2c_Stop();
return 1;
}
/**
* @brief ʹ<EFBFBD><EFBFBD>IICд<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param
* @arg ClientAddr:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
* @arg pBuffer:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @arg NumByteToWrite:д<EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD>
* @retval <EFBFBD><EFBFBD>
*/
uint32_t I2C_WriteBytes(uint8_t ClientAddr,uint8_t* pBuffer, uint8_t NumByteToWrite)
{
uint16_t m;
/*<2A><><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣ<CDA3>źţ<C5BA><C5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
i2c_Stop();
/* ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD>ķ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ж<EFBFBD><D0B6>ڲ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>, һ<><D2BB>С<EFBFBD><D0A1> 10ms
CLKƵ<EFBFBD><EFBFBD>Ϊ200KHzʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ30<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
for (m = 0; m < 1000; m++)
{
/* <20><>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>I2C<32><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD> */
i2c_Start();
/* <20><>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽڣ<D6BD><DAA3><EFBFBD>7bit<69>ǵ<EFBFBD>ַ<EFBFBD><D6B7>bit0<74>Ƕ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>0<EFBFBD><30>ʾд<CABE><D0B4>1<EFBFBD><31>ʾ<EFBFBD><CABE> */
i2c_SendByte(ClientAddr | I2C_DIR_WR); /* <20>˴<EFBFBD><CBB4><EFBFBD>дָ<D0B4><D6B8> */
/* <20><>3<EFBFBD><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʱ<EFBFBD>ӣ<EFBFBD><D3A3>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ȷӦ<C8B7><D3A6> */
if (i2c_WaitAck() == 0)
{
break;
}
}
if (m == 1000)
{
goto cmd_fail; /* EEPROM<4F><4D><EFBFBD><EFBFBD>д<EFBFBD><D0B4>ʱ */
}
while(NumByteToWrite--)
{
/* <20><>4<EFBFBD><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼд<CABC><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
i2c_SendByte(*pBuffer);
/* <20><>5<EFBFBD><35><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ACK */
if (i2c_WaitAck() != 0)
{
goto cmd_fail; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6> */
}
pBuffer++; /* <20><>ַ<EFBFBD><D6B7>1 */
}
/* <20><><EFBFBD><EFBFBD>ִ<EFBFBD>гɹ<D0B3><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>I2C<32><43><EFBFBD><EFBFBD>ֹͣ<CDA3>ź<EFBFBD> */
i2c_Stop();
return 0;
cmd_fail: /* <20><><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>ʧ<EFBFBD>ܺ<EFBFBD><DCBA><EFBFBD><EFBFBD>мǷ<D0BC><C7B7><EFBFBD>ֹͣ<CDA3>źţ<C5BA><C5A3><EFBFBD><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0>I2C<32><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸 */
/* <20><><EFBFBD><EFBFBD>I2C<32><43><EFBFBD><EFBFBD>ֹͣ<CDA3>ź<EFBFBD> */
i2c_Stop();
return 1;
}
/*********************************************END OF FILE**********************/

View File

@ -0,0 +1,69 @@
#ifndef __I2C_TOUCH_H
#define __I2C_TOUCH_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32f4xx_hal.h"
#include "main.h"
/*ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IIC<49><43><EFBFBD><EFBFBD>SOFT_IIC<49><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ1<CEAA><31>Ӳ<EFBFBD><D3B2>IIC<49><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ0
!!ʹ<EFBFBD><EFBFBD>Ӳ<EFBFBD><EFBFBD>IICʱ<EFBFBD>dz<EFBFBD><EFBFBD><EFBFBD><EFBFBD>׳<EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD>󣬲<EFBFBD><EFBFBD>Ƽ<EFBFBD>*/
#define SOFT_IIC 1
/*<2A>ʹ<E8B6A8>õĵ<C3B5><C4B5><EFBFBD><EFBFBD><EFBFBD>IIC<49><EFBFBD><E8B1B8>ַ*/
#define GTP_ADDRESS 0xBA
#define I2CT_FLAG_TIMEOUT ((uint32_t)0x1000)
#define I2CT_LONG_TIMEOUT ((uint32_t)(10 * I2CT_FLAG_TIMEOUT))
/*I2C<32><43><EFBFBD><EFBFBD>*/
#define GTP_I2C I2C2
#define GTP_I2C_CLK RCC_APB1Periph_I2C2
#define GTP_I2C_CLK_INIT RCC_APB1PeriphClockCmd
#define GTP_I2C_SCL_PIN GPIO_Pin_4
#define GTP_I2C_SCL_GPIO_PORT GPIOH
#define GTP_I2C_SCL_GPIO_CLK RCC_AHB1Periph_GPIOH
#define GTP_I2C_SCL_SOURCE GPIO_PinSource4
#define GTP_I2C_SCL_AF GPIO_AF_I2C2
#define GTP_I2C_SDA_PIN GPIO_Pin_5
#define GTP_I2C_SDA_GPIO_PORT GPIOH
#define GTP_I2C_SDA_GPIO_CLK RCC_AHB1Periph_GPIOH
#define GTP_I2C_SDA_SOURCE GPIO_PinSource5
#define GTP_I2C_SDA_AF GPIO_AF_I2C2
/*<2A><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>*/
#define GTP_RST_GPIO_PORT GPIOD
#define GTP_RST_GPIO_CLK RCC_AHB1Periph_GPIOD
#define GTP_RST_GPIO_PIN GPIO_Pin_11
/*<2A>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>*/
#define GTP_INT_GPIO_PORT GPIOD
#define GTP_INT_GPIO_CLK RCC_AHB1Periph_GPIOD
#define GTP_INT_GPIO_PIN GPIO_Pin_13
#define GTP_INT_EXTI_PORTSOURCE EXTI_PortSourceGPIOD
#define GTP_INT_EXTI_PINSOURCE EXTI_PinSource13
#define GTP_INT_EXTI_LINE EXTI_Line13
#define GTP_INT_EXTI_IRQ EXTI15_10_IRQn
//IO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define SDA_IN() {GPIOH->MODER&=~(3<<(5*2));GPIOH->MODER|=0<<5*2;} //PH5<48><35><EFBFBD><EFBFBD>ģʽ
#define SDA_OUT() {GPIOH->MODER&=~(3<<(5*2));GPIOH->MODER|=1<<5*2;} //PH5<48><35><EFBFBD><EFBFBD>ģʽ
//<2F><><EFBFBD><EFBFBD>IICʹ<43>õĺ<C3B5>
#define I2C_SCL_1() HAL_GPIO_WritePin(I2C_SCL_GPIO_Port, I2C_SCL_Pin, GPIO_PIN_SET) /* SCL = 1 */
#define I2C_SCL_0() HAL_GPIO_WritePin(I2C_SCL_GPIO_Port, I2C_SCL_Pin, GPIO_PIN_RESET) /* SCL = 0 */
#define I2C_SDA_1() HAL_GPIO_WritePin(I2C_SDA_GPIO_Port, I2C_SDA_Pin, GPIO_PIN_SET) /* SDA = 1 */
#define I2C_SDA_0() HAL_GPIO_WritePin(I2C_SDA_GPIO_Port, I2C_SDA_Pin, GPIO_PIN_RESET) /* SDA = 0 */
#define I2C_SDA_READ() HAL_GPIO_ReadPin(I2C_SDA_GPIO_Port, I2C_SDA_Pin) /* <20><>SDA<44><41><EFBFBD><EFBFBD>״̬ */
//<2F><><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
void I2C_Touch_Init(void);
uint32_t I2C_WriteBytes(uint8_t ClientAddr,uint8_t* pBuffer, uint8_t NumByteToWrite);
uint32_t I2C_ReadBytes(uint8_t ClientAddr,uint8_t* pBuffer, uint16_t NumByteToRead);
void I2C_ResetChip(void);
void I2C_GTP_IRQDisable(void);
void I2C_GTP_IRQEnable(void);
#ifdef __cplusplus
}
#endif
#endif /* __I2C_TOUCH_H */

View File

@ -0,0 +1,700 @@
/**
******************************************************************************
* @file gt9xx.c
* @author STMicroelectronics
* @version V1.0
* @date 2013-xx-xx
* @brief i2c<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
******************************************************************************
* @attention
*
* ʵ<EFBFBD><EFBFBD>ƽ̨:Ұ<EFBFBD><EFBFBD> iSO STM32 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD>̳ :http://www.firebbs.cn
* <EFBFBD>Ա<EFBFBD> :https://fire-stm32.taobao.com
*
******************************************************************************
*/
#include <stdio.h>
#include <string.h>
#include "bsp_i2c_touch.h"
#include "gt9xx.h"
// 5<><35><EFBFBD><EFBFBD>GT9157<35><37><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t CTP_CFG_GT9157[] ={
0x00,0x20,0x03,0xE0,0x01,0x05,0x3C,0x00,0x01,0x08,
0x28,0x0C,0x50,0x32,0x03,0x05,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x17,0x19,0x1E,0x14,0x8B,0x2B,0x0D,
0x33,0x35,0x0C,0x08,0x00,0x00,0x00,0x9A,0x03,0x11,
0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x32,0x00,0x00,
0x00,0x20,0x58,0x94,0xC5,0x02,0x00,0x00,0x00,0x04,
0xB0,0x23,0x00,0x93,0x2B,0x00,0x7B,0x35,0x00,0x69,
0x41,0x00,0x5B,0x4F,0x00,0x5B,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,0x10,
0x12,0x14,0x16,0x18,0x1A,0xFF,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0F,
0x10,0x12,0x13,0x16,0x18,0x1C,0x1D,0x1E,0x1F,0x20,
0x21,0x22,0x24,0x26,0xFF,0xFF,0xFF,0xFF,0x00,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0x48,0x01
};
// 7<><37><EFBFBD><EFBFBD>GT911<31><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t CTP_CFG_GT911[] = {
0x00,0x20,0x03,0xE0,0x01,0x05,0x0D,0x00,0x01,0x08,
0x28,0x0F,0x50,0x32,0x03,0x05,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x8A,0x2A,0x0C,
0x45,0x47,0x0C,0x08,0x00,0x00,0x00,0x02,0x02,0x2D,
0x00,0x00,0x00,0x00,0x00,0x03,0x64,0x32,0x00,0x00,
0x00,0x28,0x64,0x94,0xC5,0x02,0x07,0x00,0x00,0x04,
0x9C,0x2C,0x00,0x8F,0x34,0x00,0x84,0x3F,0x00,0x7C,
0x4C,0x00,0x77,0x5B,0x00,0x77,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x16,0x14,0x12,0x10,0x0E,0x0C,0x0A,
0x08,0x06,0x04,0x02,0xFF,0xFF,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x16,0x18,0x1C,0x1D,0x1E,0x1F,0x20,0x21,
0x22,0x24,0x13,0x12,0x10,0x0F,0x0A,0x08,0x06,0x04,
0x02,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x24,0x01
};
uint8_t config[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH]
= {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff};
TOUCH_IC touchIC;
static int8_t GTP_I2C_Test(void);
static void Delay(__IO uint32_t nCount) //<2F>򵥵<EFBFBD><F2B5A5B5><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
{
for(; nCount != 0; nCount--);
}
/**
* @brief ʹ<EFBFBD><EFBFBD>IIC<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><EFBFBD><EFBFBD>
* @param
* @arg i2c_msg:<EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @arg num:<EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>
* @retval <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵĴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0xff
*/
static int I2C_Transfer( struct i2c_msg *msgs,int num)
{
int im = 0;
int ret = 0;
GTP_DEBUG_FUNC();
for (im = 0; ret == 0 && im != num; im++)
{
if ((msgs[im].flags&I2C_M_RD)) //<2F><><EFBFBD><EFBFBD>flag<61>ж<EFBFBD><D0B6>Ƕ<EFBFBD><C7B6><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
{
ret = I2C_ReadBytes(msgs[im].addr, msgs[im].buf, msgs[im].len); //IIC<49><43>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
} else
{
ret = I2C_WriteBytes(msgs[im].addr, msgs[im].buf, msgs[im].len); //IICд<43><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
}
if(ret)
return ret;
return im; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵĴ<C9B5><C4B4><EFBFBD><EFBFBD><EFBFBD><E1B9B9><EFBFBD><EFBFBD>
}
/**
* @brief <EFBFBD><EFBFBD>IIC<EFBFBD><EFBFBD>ж<EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param
* @arg client_addr:<EFBFBD><EFBFBD><EFBFBD>ַ
* @arg buf[0~1]: <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>ݼĴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>ַ
* @arg buf[2~len-1]: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĻ<EFBFBD><EFBFBD><EFBFBD>buffer
* @arg len: GTP_ADDR_LENGTH + read bytes count<EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>+<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @retval i2c_msgs<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2Ϊ<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊʧ<EFBFBD><EFBFBD>
*/
static int32_t GTP_I2C_Read(uint8_t client_addr, uint8_t *buf, int32_t len)
{
struct i2c_msg msgs[2];
int32_t ret=-1;
int32_t retries = 0;
GTP_DEBUG_FUNC();
/*һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĹ<DDB5><C4B9>̿<EFBFBD><CCBF>Է<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
* 1. IIC д<EFBFBD><EFBFBD> Ҫ<EFBFBD><EFBFBD>ȡ<EFBFBD>ļĴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
* 2. IIC <EFBFBD><EFBFBD>ȡ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* */
msgs[0].flags = !I2C_M_RD; //д<><D0B4>
msgs[0].addr = client_addr; //IIC<49><EFBFBD><E8B1B8>ַ
msgs[0].len = GTP_ADDR_LENGTH; //<2F>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ַΪ2<CEAA>ֽ<EFBFBD>(<28><>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>ֽڵ<D6BD><DAB5><EFBFBD><EFBFBD><EFBFBD>)
msgs[0].buf = &buf[0]; //buf[0~1]<5D><EFBFBD><E6B4A2><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ȡ<EFBFBD>ļĴ<C4BC><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ
msgs[1].flags = I2C_M_RD; //<2F><>ȡ
msgs[1].addr = client_addr; //IIC<49><43><EFBFBD><EFBFBD><E8B1B8>ַ
msgs[1].len = len - GTP_ADDR_LENGTH; //Ҫ<><D2AA>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
msgs[1].buf = &buf[GTP_ADDR_LENGTH]; //buf[GTP_ADDR_LENGTH]֮<><D6AE><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
while(retries < 5)
{
ret = I2C_Transfer( msgs, 2); //<2F><><EFBFBD><EFBFBD>IIC<49><43><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD><CCBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(ret == 2)break;
retries++;
}
if((retries >= 5))
{
GTP_ERROR("I2C Read: 0x%04X, %d bytes failed, errcode: %d! Process reset.", (((uint16_t)(buf[0] << 8)) | buf[1]), len-2, ret);
}
return ret;
}
/**
* @brief <EFBFBD><EFBFBD>IIC<EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param
* @arg client_addr:<EFBFBD><EFBFBD><EFBFBD>ַ
* @arg buf[0~1]: Ҫд<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼĴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>ַ
* @arg buf[2~len-1]: Ҫд<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @arg len: GTP_ADDR_LENGTH + write bytes count<EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>+д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @retval i2c_msgs<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1Ϊ<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊʧ<EFBFBD><EFBFBD>
*/
static int32_t GTP_I2C_Write(uint8_t client_addr,uint8_t *buf,int32_t len)
{
struct i2c_msg msg;
int32_t ret = -1;
int32_t retries = 0;
GTP_DEBUG_FUNC();
/*һ<><D2BB>д<EFBFBD><D0B4><EFBFBD>ݵĹ<DDB5><C4B9><EFBFBD>ֻ<EFBFBD><D6BB>Ҫһ<D2AA><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
* 1. IIC<EFBFBD><EFBFBD><EFBFBD><EFBFBD> д<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>ݼĴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* */
msg.flags = !I2C_M_RD; //д<><D0B4>
msg.addr = client_addr; //<2F><><EFBFBD><EFBFBD><E8B1B8>ַ
msg.len = len; //<2F><><EFBFBD><EFBFBD>ֱ<EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD>(<28>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>)
msg.buf = buf; //ֱ<><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EBBBBA><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD>˼Ĵ<CBBC><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ)
while(retries < 5)
{
ret = I2C_Transfer(&msg, 1); //<2F><><EFBFBD><EFBFBD>IIC<49><43><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD><CCBA><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (ret == 1)break;
retries++;
}
if((retries >= 5))
{
GTP_ERROR("I2C Write: 0x%04X, %d bytes failed, errcode: %d! Process reset.", (((uint16_t)(buf[0] << 8)) | buf[1]), len-2, ret);
}
return ret;
}
/**
* @brief ʹ<EFBFBD><EFBFBD>IIC<EFBFBD><EFBFBD>ȡ<EFBFBD>ٴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param
* @arg client:<EFBFBD><EFBFBD><EFBFBD>ַ
* @arg addr: <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
* @arg rxbuf: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @arg len: <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD>
* @retval
* @arg FAIL
* @arg SUCCESS
*/
int32_t GTP_I2C_Read_dbl_check(uint8_t client_addr, uint16_t addr, uint8_t *rxbuf, int len)
{
uint8_t buf[16] = {0};
uint8_t confirm_buf[16] = {0};
uint8_t retry = 0;
GTP_DEBUG_FUNC();
while (retry++ < 3)
{
memset(buf, 0xAA, 16);
buf[0] = (uint8_t)(addr >> 8);
buf[1] = (uint8_t)(addr & 0xFF);
GTP_I2C_Read(client_addr, buf, len + 2);
memset(confirm_buf, 0xAB, 16);
confirm_buf[0] = (uint8_t)(addr >> 8);
confirm_buf[1] = (uint8_t)(addr & 0xFF);
GTP_I2C_Read(client_addr, confirm_buf, len + 2);
if (!memcmp(buf, confirm_buf, len+2))
{
memcpy(rxbuf, confirm_buf+2, len);
return SUCCESS;
}
}
GTP_ERROR("I2C read 0x%04X, %d bytes, double check failed!", addr, len);
return FAIL;
}
/*<2A><><EFBFBD>ڼ<EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ(<28><><EFBFBD><EFBFBD>)<29><><EFBFBD><EFBFBD>һ<EFBFBD>δ<EFBFBD><CEB4><EFBFBD>λ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>ʾ<EFBFBD><CABE>һ<EFBFBD><D2BB><EFBFBD>޴<EFBFBD><DEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
int16_t pre_x=-1;
int16_t pre_y=-1;
/**
* @brief <EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>򱨸<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param
* @arg id: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><EFBFBD>trackID
* @arg x: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> x <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @arg y: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> y <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @arg w: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>С
* @retval <EFBFBD><EFBFBD>
*/
static void GTP_Touch_Down(int32_t x,int32_t y,int32_t w)
{
GTP_DEBUG_FUNC();
/*ȡx<C8A1><78>y<EFBFBD><79>ʼֵ<CABC><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD>ֵ*/
GTP_DEBUG("X:%d, Y:%d, W:%d", x, y, w);
pre_x = x; pre_y=y;
}
/**
* @brief <EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>򱨸<EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>
* @param <EFBFBD>ͷŵ<EFBFBD><EFBFBD><EFBFBD>id<EFBFBD><EFBFBD>
* @retval <EFBFBD><EFBFBD>
*/
static void GTP_Touch_Up(void)
{
/*<2A><><EFBFBD><EFBFBD><EFBFBD>ͷţ<CDB7><C5A3><EFBFBD>pre xy <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>*/
pre_x = -1;
pre_y = -1;
GTP_DEBUG("Touch release!");
}
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϵ<EFBFBD><EFBFBD><EFBFBD>
* @param <EFBFBD><EFBFBD>
* @retval <EFBFBD><EFBFBD>
*/
static void Goodix_TS_Work_Func(void)
{
static uint8_t IsTouch=0;
uint8_t end_cmd[3] = {GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF, 0};
uint8_t point_data[2 + 1 + 8 * GTP_MAX_TOUCH + 1]={GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF};
uint8_t touch_num = 0;
uint8_t finger = 0;
uint8_t client_addr=GTP_ADDRESS;
int32_t input_x = 0;
int32_t input_y = 0;
int32_t input_w = 0;
int32_t ret = -1;
GTP_DEBUG_FUNC();
ret = GTP_I2C_Read(client_addr, point_data, 12);//10<31>ֽڼĴ<DABC><C4B4><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD>ֽڵ<D6BD>ַ
if (ret < 0)
{
GTP_ERROR("I2C transfer error. errno:%d\n ", ret);
return;
}
finger = point_data[GTP_ADDR_LENGTH];//״̬<D7B4>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GTP_DEBUG("I2C finger:%X",finger);
if(finger == 0x00) //û<><C3BB><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3>˳<EFBFBD>
{
if(IsTouch)
{
GTP_Touch_Up();
IsTouch=0;
}
return;
}
if((finger & 0x80) == 0)//<2F>ж<EFBFBD>buffer statusλ
{
goto exit_work_func;//<2F><><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч
}
touch_num = finger & 0x0f;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (touch_num > GTP_MAX_TOUCH)
{
goto exit_work_func;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD>
}
IsTouch=1;
input_x = point_data[4] | (point_data[5] << 8); //x<><78><EFBFBD><EFBFBD>
input_y = point_data[6] | (point_data[7] << 8); //y<><79><EFBFBD><EFBFBD>
input_w = point_data[8] | (point_data[9] << 8); //size
GTP_Touch_Down(input_x, input_y, input_w);//<2F><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>
exit_work_func:
{
ret = GTP_I2C_Write(client_addr, end_cmd, 3);
if (ret < 0)
{
GTP_INFO("I2C write end_cmd error!");
}
}
}
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>оƬ<EFBFBD><EFBFBD><EFBFBD>¸<EFBFBD>λ
* @param <EFBFBD><EFBFBD>
* @retval <EFBFBD><EFBFBD>
*/
int8_t GTP_Reset_Guitar(void)
{
GTP_DEBUG_FUNC();
#if 1
I2C_ResetChip();
return 0;
#else //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
int8_t ret = -1;
int8_t retry = 0;
uint8_t reset_command[3]={(uint8_t)GTP_REG_COMMAND>>8,(uint8_t)GTP_REG_COMMAND&0xFF,2};
//д<>븴λ<EBB8B4><CEBB><EFBFBD><EFBFBD>
while(retry++ < 5)
{
ret = GTP_I2C_Write(GTP_ADDRESS, reset_command, 3);
if (ret > 0)
{
GTP_INFO("GTP enter sleep!");
return ret;
}
}
GTP_ERROR("GTP send sleep cmd failed.");
return ret;
#endif
}
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˯<EFBFBD><EFBFBD>ģʽ
* @param <EFBFBD><EFBFBD>
* @retval 1Ϊ<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊʧ<EFBFBD><EFBFBD>
*/
//int8_t GTP_Enter_Sleep(void)
//{
// int8_t ret = -1;
// int8_t retry = 0;
// uint8_t reset_comment[3] = {(uint8_t)(GTP_REG_COMMENT >> 8), (uint8_t)GTP_REG_COMMENT&0xFF, 5};//5
//
// GTP_DEBUG_FUNC();
//
// while(retry++ < 5)
// {
// ret = GTP_I2C_Write(GTP_ADDRESS, reset_comment, 3);
// if (ret > 0)
// {
// GTP_INFO("GTP enter sleep!");
//
// return ret;
// }
//
// }
// GTP_ERROR("GTP send sleep cmd failed.");
// return ret;
//}
int8_t GTP_Send_Command(uint8_t command)
{
int8_t ret = -1;
int8_t retry = 0;
uint8_t command_buf[3] = {(uint8_t)(GTP_REG_COMMAND >> 8), (uint8_t)GTP_REG_COMMAND&0xFF, GTP_COMMAND_READSTATUS};
GTP_DEBUG_FUNC();
while(retry++ < 5)
{
ret = GTP_I2C_Write(GTP_ADDRESS, command_buf, 3);
if (ret > 0)
{
GTP_INFO("send command success!");
return ret;
}
}
GTP_ERROR("send command fail!");
return ret;
}
/**
* @brief <EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param <EFBFBD><EFBFBD>
* @retval 0Ϊ<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊʧ<EFBFBD><EFBFBD>
*/
int8_t GTP_WakeUp_Sleep(void)
{
uint8_t retry = 0;
int8_t ret = -1;
GTP_DEBUG_FUNC();
while(retry++ < 10)
{
ret = GTP_I2C_Test();
if (ret > 0)
{
GTP_INFO("GTP wakeup sleep.");
return ret;
}
GTP_Reset_Guitar();
}
GTP_ERROR("GTP wakeup sleep failed.");
return ret;
}
static int32_t GTP_Get_Info(void)
{
uint8_t opr_buf[6] = {0};
int32_t ret = 0;
uint16_t abs_x_max = GTP_MAX_WIDTH;
uint16_t abs_y_max = GTP_MAX_HEIGHT;
uint8_t int_trigger_type = GTP_INT_TRIGGER;
opr_buf[0] = (uint8_t)((GTP_REG_CONFIG_DATA+1) >> 8);
opr_buf[1] = (uint8_t)((GTP_REG_CONFIG_DATA+1) & 0xFF);
ret = GTP_I2C_Read(GTP_ADDRESS, opr_buf, 6);
if (ret < 0)
{
return FAIL;
}
abs_x_max = (opr_buf[3] << 8) + opr_buf[2];
abs_y_max = (opr_buf[5] << 8) + opr_buf[4];
opr_buf[0] = (uint8_t)((GTP_REG_CONFIG_DATA+6) >> 8);
opr_buf[1] = (uint8_t)((GTP_REG_CONFIG_DATA+6) & 0xFF);
ret = GTP_I2C_Read(GTP_ADDRESS, opr_buf, 3);
if (ret < 0)
{
return FAIL;
}
int_trigger_type = opr_buf[2] & 0x03;
GTP_INFO("X_MAX = %d, Y_MAX = %d, TRIGGER = 0x%02x",
abs_x_max,abs_y_max,int_trigger_type);
return SUCCESS;
}
/*******************************************************
Function:
Initialize gtp.
Input:
ts: goodix private data
Output:
Executive outcomes.
0: succeed, otherwise: failed
*******************************************************/
int32_t GTP_Init_Panel(void)
{
int32_t ret = -1;
int32_t i = 0;
uint8_t check_sum = 0;
int32_t retry = 0;
uint8_t* cfg_info;
uint8_t cfg_info_len ;
uint8_t cfg_num =0x80FE-0x8047+1 ; //<2F><>Ҫ<EFBFBD><D2AA><EFBFBD>õļĴ<C4BC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GTP_DEBUG_FUNC();
I2C_Touch_Init();
ret = GTP_I2C_Test();
if (ret < 0)
{
GTP_ERROR("I2C communication ERROR!");
}
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>IC<49><43><EFBFBD>ͺ<EFBFBD>
GTP_Read_Version();
//<2F><><EFBFBD><EFBFBD>IC<49><43><EFBFBD>ͺ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(touchIC == GT9157)
{
cfg_info = CTP_CFG_GT9157; //ָ<><D6B8><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cfg_info_len = CFG_GROUP_LEN(CTP_CFG_GT9157);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><C3B1>Ĵ<EFBFBD>С
}
else
{
cfg_info = CTP_CFG_GT911;//ָ<><D6B8><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cfg_info_len = CFG_GROUP_LEN(CTP_CFG_GT911) ;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><C3B1>Ĵ<EFBFBD>С
}
memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH);
memcpy(&config[GTP_ADDR_LENGTH], cfg_info, cfg_info_len);
//<2F><><EFBFBD><EFBFBD>Ҫд<D2AA><D0B4>checksum<75>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ֵ
check_sum = 0;
for (i = GTP_ADDR_LENGTH; i < cfg_num+GTP_ADDR_LENGTH; i++)
{
check_sum += config[i];
}
config[ cfg_num+GTP_ADDR_LENGTH] = (~check_sum) + 1; //checksum
config[ cfg_num+GTP_ADDR_LENGTH+1] = 1; //refresh <20><><EFBFBD>ø<EFBFBD><C3B8>±<EFBFBD>־
//д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
for (retry = 0; retry < 5; retry++)
{
ret = GTP_I2C_Write(GTP_ADDRESS, config , cfg_num + GTP_ADDR_LENGTH+2);
if (ret > 0)
{
break;
}
}
Delay(0xfffff); //<2F>ӳٵȴ<D9B5>оƬ<D0BE><C6AC><EFBFBD><EFBFBD>
#if 0 //<2F><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ͬ
{
uint16_t i;
uint8_t buf[200];
buf[0] = config[0];
buf[1] =config[1]; //<2F>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ
GTP_DEBUG_FUNC();
ret = GTP_I2C_Read(GTP_ADDRESS, buf, sizeof(buf));
//<2F><EFBFBD><E6B1BE>д<EFBFBD><D0B4>0x00<30>󣬻<EFBFBD><F3A3ACBB><EFBFBD><EFBFBD>и<EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>λΪ0x41
config[GTP_ADDR_LENGTH] = 0x41;
for(i=0;i<cfg_num+GTP_ADDR_LENGTH;i++)
{
if(config[i] != buf[i])
{
GTP_DEBUG("Config fail ! i = %d ",i);
break;
}
}
if(i==cfg_num+GTP_ADDR_LENGTH)
GTP_DEBUG("Config success ! i = %d ",i);
}
#endif
GTP_Get_Info();
// GT91xx_Config_Read_Proc();
// GTP_Send_Command(GTP_COMMAND_UPDATE);
// Delay(0xfffff); //<2F>ӳٵȴ<D9B5>оƬ<D0BE><C6AC><EFBFBD><EFBFBD>
//
// GTP_Send_Command(GTP_COMMAND_CALCULATE);
// Delay(0xfffff); //<2F>ӳٵȴ<D9B5>оƬ<D0BE><C6AC><EFBFBD><EFBFBD>
// GTP_Send_Command(GTP_COMMAND_UPDATE);
// Delay(0xfffff); //<2F>ӳٵȴ<D9B5>оƬ<D0BE><C6AC><EFBFBD><EFBFBD>
//
// GTP_Send_Command(GTP_COMMAND_DIFFERENCE);
// Delay(0xfffff); //<2F>ӳٵȴ<D9B5>оƬ<D0BE><C6AC><EFBFBD><EFBFBD>
return 0;
}
/*******************************************************
Function:
Read chip version.
Input:
client: i2c device
version: buffer to keep ic firmware version
Output:
read operation return.
2: succeed, otherwise: failed
*******************************************************/
int32_t GTP_Read_Version(void)
{
int32_t ret = -1;
uint8_t buf[8] = {GTP_REG_VERSION >> 8, GTP_REG_VERSION & 0xff}; //<2F>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ
GTP_DEBUG_FUNC();
ret = GTP_I2C_Read(GTP_ADDRESS, buf, sizeof(buf));
if (ret < 0)
{
GTP_ERROR("GTP read version failed");
return ret;
}
if (buf[5] == 0x00)
{
GTP_INFO("IC1 Version: %c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[7], buf[6]);
//GT911оƬ
if(buf[2] == '9' && buf[3] == '1' && buf[4] == '1')
touchIC = GT911;
}
else
{
GTP_INFO("IC2 Version: %c%c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[5], buf[7], buf[6]);
//GT9157оƬ
if(buf[2] == '9' && buf[3] == '1' && buf[4] == '5' && buf[5] == '7')
touchIC = GT9157;
}
return ret;
}
/*******************************************************
Function:
I2c test Function.
Input:
client:i2c client.
Output:
Executive outcomes.
2: succeed, otherwise failed.
*******************************************************/
static int8_t GTP_I2C_Test( void)
{
uint8_t test[3] = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff};
uint8_t retry = 0;
int8_t ret = -1;
GTP_DEBUG_FUNC();
while(retry++ < 5)
{
ret = GTP_I2C_Read(GTP_ADDRESS, test, 3);
if (ret > 0)
{
return ret;
}
GTP_ERROR("GTP i2c test failed time %d.",retry);
}
return ret;
}
void GT9xx_GetOnePiont(void)
{
GTP_DEBUG_FUNC();
Goodix_TS_Work_Func();
}
//MODULE_DESCRIPTION("GTP Series Driver");
//MODULE_LICENSE("GPL");

View File

@ -0,0 +1,266 @@
/* drivers/input/touchscreen/gt9xx.h
*
* 2010 - 2013 Goodix Technology.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be a reference
* to you, when you are integrating the GOODiX's CTP IC into your system,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
*/
#ifndef _GOODIX_GT9XX_H
#define _GOODIX_GT9XX_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32f4xx_hal.h"
#ifndef NULL
#define NULL 0
#endif
/**
* struct i2c_msg - an I2C transaction segment beginning with START
* @addr: Slave address, either seven or ten bits. When this is a ten
* bit address, I2C_M_TEN must be set in @flags and the adapter
* must support I2C_FUNC_10BIT_ADDR.
* @flags: I2C_M_RD is handled by all adapters. No other flags may be
* provided unless the adapter exported the relevant I2C_FUNC_*
* flags through i2c_check_functionality().
* @len: Number of data bytes in @buf being read from or written to the
* I2C slave address. For read transactions where I2C_M_RECV_LEN
* is set, the caller guarantees that this buffer can hold up to
* 32 bytes in addition to the initial length byte sent by the
* slave (plus, if used, the SMBus PEC); and this value will be
* incremented by the number of block data bytes received.
* @buf: The buffer into which data is read, or from which it's written.
*
* An i2c_msg is the low level representation of one segment of an I2C
* transaction. It is visible to drivers in the @i2c_transfer() procedure,
* to userspace from i2c-dev, and to I2C adapter drivers through the
* @i2c_adapter.@master_xfer() method.
*
* Except when I2C "protocol mangling" is used, all I2C adapters implement
* the standard rules for I2C transactions. Each transaction begins with a
* START. That is followed by the slave address, and a bit encoding read
* versus write. Then follow all the data bytes, possibly including a byte
* with SMBus PEC. The transfer terminates with a NAK, or when all those
* bytes have been transferred and ACKed. If this is the last message in a
* group, it is followed by a STOP. Otherwise it is followed by the next
* @i2c_msg transaction segment, beginning with a (repeated) START.
*
* Alternatively, when the adapter supports I2C_FUNC_PROTOCOL_MANGLING then
* passing certain @flags may have changed those standard protocol behaviors.
* Those flags are only for use with broken/nonconforming slaves, and with
* adapters which are known to support the specific mangling options they
* need (one or more of IGNORE_NAK, NO_RD_ACK, NOSTART, and REV_DIR_ADDR).
*/
struct i2c_msg {
uint8_t addr; /* slave address */
uint16_t flags;
#define I2C_M_TEN 0x0010 /* this is a ten bit chip address */
#define I2C_M_RD 0x0001 /* read data, from slave to master */
#define I2C_M_NOSTART 0x4000 /* if I2C_FUNC_PROTOCOL_MANGLING */
#define I2C_M_REV_DIR_ADDR 0x2000 /* if I2C_FUNC_PROTOCOL_MANGLING */
#define I2C_M_IGNORE_NAK 0x1000 /* if I2C_FUNC_PROTOCOL_MANGLING */
#define I2C_M_NO_RD_ACK 0x0800 /* if I2C_FUNC_PROTOCOL_MANGLING */
#define I2C_M_RECV_LEN 0x0400 /* length will be first received byte */
uint16_t len; /* msg length */
uint8_t *buf; /* pointer to msg data */
};
typedef enum
{
GT9157=0,
GT911=1,
}TOUCH_IC;
//***************************PART1:ON/OFF define*******************************
#define GTP_DEBUG_ON 0
#define GTP_DEBUG_ARRAY_ON 0
#define GTP_DEBUG_FUNC_ON 0
//*************************** PART2:TODO define **********************************
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѹij<D1B8><C4B3><EFBFBD><EFBFBD><EFBFBD><E9A3AC>c<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
//*************************** PART2:TODO define **********************************
// TODO: define your own default or for Sensor_ID == 0 config here.
// The predefined one is just a sample config, which is not suitable for your tp in most cases.
// 5<><35><EFBFBD><EFBFBD>GT9157<35><37><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//#define CTP_CFG_GT9157 {\
//0x00,0x20,0x03,0xE0,0x01,0x05,0x3C,0x00,0x01,0x08,\
//0x28,0x0C,0x50,0x32,0x03,0x05,0x00,0x00,0x00,0x00,\
//0x00,0x00,0x00,0x17,0x19,0x1E,0x14,0x8B,0x2B,0x0D,\
//0x33,0x35,0x0C,0x08,0x00,0x00,0x00,0x9A,0x03,0x11,\
//0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x32,0x00,0x00,\
//0x00,0x20,0x58,0x94,0xC5,0x02,0x00,0x00,0x00,0x04,\
//0xB0,0x23,0x00,0x93,0x2B,0x00,0x7B,0x35,0x00,0x69,\
//0x41,0x00,0x5B,0x4F,0x00,0x5B,0x00,0x00,0x00,0x00,\
//0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
//0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
//0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
//0x00,0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,0x10,\
//0x12,0x14,0x16,0x18,0x1A,0xFF,0x00,0x00,0x00,0x00,\
//0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
//0x00,0x00,0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0F,\
//0x10,0x12,0x13,0x16,0x18,0x1C,0x1D,0x1E,0x1F,0x20,\
//0x21,0x22,0x24,0x26,0xFF,0xFF,0xFF,0xFF,0x00,0x00,\
//0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,\
//0xFF,0xFF,0xFF,0xFF,0x48,0x01\
//}
// 7<><37><EFBFBD><EFBFBD>GT911<31><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//#define CTP_CFG_GT911 {\
//0x00,0x20,0x03,0xE0,0x01,0x05,0x3D,0x00,0x01,0x48,\
//0x28,0x08,0x6E,0x5A,0x03,0x05,0x00,0x00,0x00,0x00,\
//0x00,0x00,0x00,0x18,0x1A,0x1E,0x14,0x87,0x28,0x0A,\
//0x46,0x48,0x31,0x0D,0x00,0x00,0x02,0x18,0x03,0x1D,\
//0x00,0x01,0x00,0x00,0x00,0x03,0x64,0x32,0x00,0x00,\
//0x00,0x0F,0x4B,0x94,0x45,0x02,0x07,0x00,0x00,0x04,\
//0x9B,0x11,0x00,0x72,0x18,0x00,0x57,0x21,0x00,0x43,\
//0x2E,0x00,0x36,0x40,0x00,0x36,0x00,0x00,0x00,0x00,\
//0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
//0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
//0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
//0x00,0x00,0x14,0x12,0x10,0x0E,0x0C,0x0A,0x08,0x06,\
//0x04,0x02,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,\
//0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
//0x00,0x00,0x26,0x24,0x22,0x21,0x20,0x1F,0x1E,0x1D,\
//0x0C,0x0A,0x08,0x06,0x04,0x02,0x00,0xFF,0xFF,0xFF,\
//0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,\
//0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
//0x00,0x00,0x00,0x00,0xCD,0x01 \
//}
// STEP_3(optional): Specify your special config info if needed
#define GTP_MAX_HEIGHT 480
#define GTP_MAX_WIDTH 800
#define GTP_INT_TRIGGER 0
#define GTP_MAX_TOUCH 1
//***************************PART3:OTHER define*********************************
#define GTP_DRIVER_VERSION "V2.2<2014/01/14>"
#define GTP_I2C_NAME "Goodix-TS"
#define GT91XX_CONFIG_PROC_FILE "gt9xx_config"
#define GTP_POLL_TIME 10
#define GTP_ADDR_LENGTH 2
#define GTP_CONFIG_MIN_LENGTH 186
#define GTP_CONFIG_MAX_LENGTH 240
#define FAIL 0
#define SUCCESS 1
#define SWITCH_OFF 0
#define SWITCH_ON 1
//******************** For GT9XXF Start **********************//
#define GTP_REG_BAK_REF 0x99D0
#define GTP_REG_MAIN_CLK 0x8020
#define GTP_REG_CHIP_TYPE 0x8000
#define GTP_REG_HAVE_KEY 0x804E
#define GTP_REG_MATRIX_DRVNUM 0x8069
#define GTP_REG_MATRIX_SENNUM 0x806A
#define GTP_REG_COMMAND 0x8040
#define GTP_COMMAND_READSTATUS 0
#define GTP_COMMAND_DIFFERENCE 1
#define GTP_COMMAND_SOFTRESET 2
#define GTP_COMMAND_UPDATE 3
#define GTP_COMMAND_CALCULATE 4
#define GTP_COMMAND_TURNOFF 5
#define GTP_FL_FW_BURN 0x00
#define GTP_FL_ESD_RECOVERY 0x01
#define GTP_FL_READ_REPAIR 0x02
#define GTP_BAK_REF_SEND 0
#define GTP_BAK_REF_STORE 1
#define CFG_LOC_DRVA_NUM 29
#define CFG_LOC_DRVB_NUM 30
#define CFG_LOC_SENS_NUM 31
#define GTP_CHK_FW_MAX 40
#define GTP_CHK_FS_MNT_MAX 300
#define GTP_BAK_REF_PATH "/data/gtp_ref.bin"
#define GTP_MAIN_CLK_PATH "/data/gtp_clk.bin"
#define GTP_RQST_CONFIG 0x01
#define GTP_RQST_BAK_REF 0x02
#define GTP_RQST_RESET 0x03
#define GTP_RQST_MAIN_CLOCK 0x04
#define GTP_RQST_RESPONDED 0x00
#define GTP_RQST_IDLE 0xFF
//******************** For GT9XXF End **********************//
// Registers define
#define GTP_READ_COOR_ADDR 0x814E
#define GTP_REG_SLEEP 0x8040
#define GTP_REG_SENSOR_ID 0x814A
#define GTP_REG_CONFIG_DATA 0x8047
#define GTP_REG_VERSION 0x8140
#define RESOLUTION_LOC 3
#define TRIGGER_LOC 8
#define CFG_GROUP_LEN(p_cfg_grp) (sizeof(p_cfg_grp) / sizeof(p_cfg_grp[0]))
// Log define
#define GTP_INFO(fmt,arg...) printf("<<-GTP-INFO->> "fmt"\n",##arg)
#define GTP_ERROR(fmt,arg...) printf("<<-GTP-ERROR->> "fmt"\n",##arg)
#define GTP_DEBUG(fmt,arg...) do{\
if(GTP_DEBUG_ON)\
printf("<<-GTP-DEBUG->> [%d]"fmt"\n",__LINE__, ##arg);\
}while(0)
#define GTP_DEBUG_ARRAY(array, num) do{\
int32_t i;\
uint8_t* a = array;\
if(GTP_DEBUG_ARRAY_ON)\
{\
printf("<<-GTP-DEBUG-ARRAY->>\n");\
for (i = 0; i < (num); i++)\
{\
printf("%02x ", (a)[i]);\
if ((i + 1 ) %10 == 0)\
{\
printf("\n");\
}\
}\
printf("\n");\
}\
}while(0)
#define GTP_DEBUG_FUNC() do{\
if(GTP_DEBUG_FUNC_ON)\
printf("<<-GTP-FUNC->> Func:%s@Line:%d\n",__func__,__LINE__);\
}while(0)
#define GTP_SWAP(x, y) do{\
typeof(x) z = x;\
x = y;\
y = z;\
}while (0)
//*****************************End of Part III********************************
int8_t GTP_Reset_Guitar(void);
int32_t GTP_Read_Version(void);
int32_t GTP_Init_Panel(void);
int8_t GTP_Send_Command(uint8_t command);
void GT9xx_GetOnePiont(void);
#ifdef __cplusplus
}
#endif
#endif /* _GOODIX_GT9XX_H_ */

View File

@ -0,0 +1,30 @@
#include "main.h"
#include "stdio.h"
#pragma import(__use_no_semihosting)
//<2F><>׼<EFBFBD><D7BC><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>֧<EFBFBD>ֺ<EFBFBD><D6BA><EFBFBD>
struct __FILE
{
int handle;
};
FILE __stdout;
//<2F><><EFBFBD><EFBFBD>_sys_exit()<29>Ա<EFBFBD><D4B1><EFBFBD>ʹ<EFBFBD>ð<EFBFBD><C3B0><EFBFBD><EFBFBD><EFBFBD>ģʽ
void _sys_exit(int x)
{
x = x;
}
//__use_no_semihosting was requested, but _ttywrch was
void _ttywrch(int ch)
{
ch = ch;
}
//<2F>ض<EFBFBD><D8B6><EFBFBD>fputc<74><63><EFBFBD><EFBFBD>
int fputc(int ch, FILE *f)
{
while((USART1->SR&0X40)==0);//ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USART1->DR = (char) ch;
return ch;
}

Some files were not shown because too many files have changed in this diff Show More