Latest libopenui updates
This commit is contained in:
@@ -17,29 +17,25 @@
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include "touch_driver.h"
|
||||
|
||||
enum ENUM_TOUCH_STATE
|
||||
{
|
||||
TOUCH_NONE,
|
||||
TOUCH_SLIDE,
|
||||
TOUCH_CLICK
|
||||
TOUCH_NONE,
|
||||
TOUCH_SLIDE,
|
||||
TOUCH_CLICK
|
||||
};
|
||||
signed int x;
|
||||
signed int y;
|
||||
|
||||
int x;
|
||||
int y;
|
||||
uint32_t TouchEvent;
|
||||
unsigned short Tx;
|
||||
unsigned short Ty;
|
||||
extern STRUCT_TOUCH touchState; //definition in mainwindow.cpp
|
||||
static unsigned char TouchState = TOUCH_NONE;
|
||||
static unsigned char TouchState = TOUCH_NONE;
|
||||
static unsigned short Txold;
|
||||
static unsigned short Tyold;
|
||||
static unsigned short TouchStartX;
|
||||
static unsigned short TouchStartY;
|
||||
|
||||
|
||||
#include "board.h"
|
||||
#include "touch_driver.h"
|
||||
|
||||
#define FT6x06_MAX_INSTANCE 1
|
||||
|
||||
@@ -57,61 +53,63 @@ static unsigned short TouchStartY;
|
||||
|
||||
#define TOUCH_FT6236_I2C_ADDRESS (0x70>>1)
|
||||
|
||||
uint8_t ft6x06[FT6x06_MAX_INSTANCE] = { 0 };
|
||||
static ft6x06_handle_TypeDef ft6x06_handle = { FT6206_I2C_NOT_INITIALIZED, 0, 0};
|
||||
uint8_t ft6x06[FT6x06_MAX_INSTANCE] = {0};
|
||||
static ft6x06_handle_TypeDef ft6x06_handle = {FT6206_I2C_NOT_INITIALIZED, 0, 0};
|
||||
|
||||
static void I2C_FreeBus(void) {
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
// reset i2c bus by setting clk as output and sending manual clock pulses
|
||||
GPIO_InitStructure.GPIO_Pin = I2C_TOUCH_SCL_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_Init(I2C_TOUCH_GPIO, &GPIO_InitStructure);
|
||||
void I2C_FreeBus()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
// reset i2c bus by setting clk as output and sending manual clock pulses
|
||||
GPIO_InitStructure.GPIO_Pin = I2C_TOUCH_SCL_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_Init(I2C_TOUCH_GPIO, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = I2C_TOUCH_SDA_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_Init(I2C_TOUCH_GPIO, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.GPIO_Pin = I2C_TOUCH_SDA_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_Init(I2C_TOUCH_GPIO, &GPIO_InitStructure);
|
||||
|
||||
//send 100khz clock train for some 100ms
|
||||
tmr10ms_t until = get_tmr10ms() + 11;
|
||||
while(get_tmr10ms() < until){
|
||||
if (GPIO_ReadInputDataBit(I2C_TOUCH_GPIO, I2C_TOUCH_SDA_GPIO_PIN) == 1){
|
||||
TRACE("touch: i2c free again\n");
|
||||
break;
|
||||
}
|
||||
TRACE("FREEEEE");
|
||||
I2C_TOUCH_GPIO->BSRRH = I2C_TOUCH_SCL_GPIO_PIN; //BSRRL
|
||||
delay_us(10);
|
||||
I2C_TOUCH_GPIO->BSRRL = I2C_TOUCH_SCL_GPIO_PIN;
|
||||
delay_us(10);
|
||||
//send 100khz clock train for some 100ms
|
||||
tmr10ms_t until = get_tmr10ms() + 11;
|
||||
while (get_tmr10ms() < until) {
|
||||
if (GPIO_ReadInputDataBit(I2C_TOUCH_GPIO, I2C_TOUCH_SDA_GPIO_PIN) == 1) {
|
||||
TRACE("touch: i2c free again\n");
|
||||
break;
|
||||
}
|
||||
TRACE("FREEEEE");
|
||||
I2C_TOUCH_GPIO->BSRRH = I2C_TOUCH_SCL_GPIO_PIN; //BSRRL
|
||||
delay_us(10);
|
||||
I2C_TOUCH_GPIO->BSRRL = I2C_TOUCH_SCL_GPIO_PIN;
|
||||
delay_us(10);
|
||||
}
|
||||
|
||||
//send stop condition:
|
||||
GPIO_InitStructure.GPIO_Pin = I2C_TOUCH_SDA_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_Init(I2C_TOUCH_GPIO, &GPIO_InitStructure);
|
||||
//send stop condition:
|
||||
GPIO_InitStructure.GPIO_Pin = I2C_TOUCH_SDA_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_Init(I2C_TOUCH_GPIO, &GPIO_InitStructure);
|
||||
|
||||
//clock is low
|
||||
I2C_TOUCH_GPIO->BSRRH = I2C_TOUCH_SCL_GPIO_PIN;
|
||||
delay_us(10);
|
||||
//sda = lo
|
||||
I2C_TOUCH_GPIO->BSRRL = I2C_TOUCH_SDA_GPIO_PIN;
|
||||
delay_us(10);
|
||||
//clock goes high
|
||||
I2C_TOUCH_GPIO->BSRRH = I2C_TOUCH_SCL_GPIO_PIN;
|
||||
delay_us(10);
|
||||
//sda = hi
|
||||
I2C_TOUCH_GPIO->BSRRL = I2C_TOUCH_SDA_GPIO_PIN;
|
||||
delay_us(10);
|
||||
TRACE("FREE BUS");
|
||||
//clock is low
|
||||
I2C_TOUCH_GPIO->BSRRH = I2C_TOUCH_SCL_GPIO_PIN;
|
||||
delay_us(10);
|
||||
//sda = lo
|
||||
I2C_TOUCH_GPIO->BSRRL = I2C_TOUCH_SDA_GPIO_PIN;
|
||||
delay_us(10);
|
||||
//clock goes high
|
||||
I2C_TOUCH_GPIO->BSRRH = I2C_TOUCH_SCL_GPIO_PIN;
|
||||
delay_us(10);
|
||||
//sda = hi
|
||||
I2C_TOUCH_GPIO->BSRRL = I2C_TOUCH_SDA_GPIO_PIN;
|
||||
delay_us(10);
|
||||
TRACE("FREE BUS");
|
||||
}
|
||||
static void Touch_DeInit(void)
|
||||
|
||||
void Touch_DeInit()
|
||||
{
|
||||
I2C_DeInit(I2C_TOUCH);
|
||||
(RCC->APB1RSTR |= (RCC_APB1RSTR_I2C1RST));
|
||||
@@ -119,80 +117,81 @@ static void Touch_DeInit(void)
|
||||
(RCC->APB1RSTR &= ~(RCC_APB1RSTR_I2C1RST));
|
||||
}
|
||||
|
||||
static void I2C_Init(void)
|
||||
void I2C_Init()
|
||||
{
|
||||
Touch_DeInit();
|
||||
Touch_DeInit();
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
EXTI_InitTypeDef EXTI_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
I2C_InitTypeDef I2C_InitStructure;
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
EXTI_InitTypeDef EXTI_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
I2C_InitTypeDef I2C_InitStructure;
|
||||
|
||||
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
|
||||
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE);
|
||||
|
||||
I2C_FreeBus();
|
||||
I2C_FreeBus();
|
||||
|
||||
GPIO_PinAFConfig(I2C_TOUCH_GPIO, GPIO_PinSource7, GPIO_AF_I2C1);
|
||||
GPIO_PinAFConfig(I2C_TOUCH_GPIO, GPIO_PinSource8, GPIO_AF_I2C1);
|
||||
GPIO_PinAFConfig(I2C_TOUCH_GPIO, GPIO_PinSource7, GPIO_AF_I2C1);
|
||||
GPIO_PinAFConfig(I2C_TOUCH_GPIO, GPIO_PinSource8, GPIO_AF_I2C1);
|
||||
|
||||
GPIO_StructInit(&GPIO_InitStructure);
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_InitStructure.GPIO_Pin = I2C_TOUCH_SCL_GPIO_PIN | I2C_TOUCH_SDA_GPIO_PIN;
|
||||
GPIO_Init(I2C_TOUCH_GPIO, &GPIO_InitStructure);
|
||||
GPIO_StructInit(&GPIO_InitStructure);
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_InitStructure.GPIO_Pin = I2C_TOUCH_SCL_GPIO_PIN | I2C_TOUCH_SDA_GPIO_PIN;
|
||||
GPIO_Init(I2C_TOUCH_GPIO, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = I2C_TOUCH_RESET_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//GPIO_PuPd_NOPULL; //
|
||||
GPIO_Init(I2C_TOUCH_RESET_GPIO, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.GPIO_Pin = I2C_TOUCH_RESET_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//GPIO_PuPd_NOPULL; //
|
||||
GPIO_Init(I2C_TOUCH_RESET_GPIO, &GPIO_InitStructure);
|
||||
|
||||
|
||||
//https://community.st.com/s/question/0D50X00009XkZ9FSAV/stm32f4-i2c-issues-solved
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
|
||||
I2C_StructInit(&I2C_InitStructure);
|
||||
I2C_InitStructure.I2C_ClockSpeed = 400000;
|
||||
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
|
||||
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
|
||||
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
|
||||
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
|
||||
I2C_Init(I2C_TOUCH, &I2C_InitStructure);
|
||||
//https://community.st.com/s/question/0D50X00009XkZ9FSAV/stm32f4-i2c-issues-solved
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
|
||||
I2C_StructInit(&I2C_InitStructure);
|
||||
I2C_InitStructure.I2C_ClockSpeed = 400000;
|
||||
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
|
||||
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
|
||||
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
|
||||
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
|
||||
I2C_Init(I2C_TOUCH, &I2C_InitStructure);
|
||||
|
||||
I2C_Init(I2C_TOUCH, &I2C_InitStructure);
|
||||
//I2C_StretchClockCmd(I2C_TOUCH, ENABLE);
|
||||
I2C_Cmd(I2C_TOUCH, ENABLE);
|
||||
I2C_Init(I2C_TOUCH, &I2C_InitStructure);
|
||||
//I2C_StretchClockCmd(I2C_TOUCH, ENABLE);
|
||||
I2C_Cmd(I2C_TOUCH, ENABLE);
|
||||
|
||||
//ext interupt
|
||||
GPIO_InitStructure.GPIO_Pin = I2C_TOUCH_INT_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(I2C_TOUCH_INT_GPIO, &GPIO_InitStructure);
|
||||
//ext interupt
|
||||
GPIO_InitStructure.GPIO_Pin = I2C_TOUCH_INT_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(I2C_TOUCH_INT_GPIO, &GPIO_InitStructure);
|
||||
|
||||
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource9);
|
||||
EXTI_InitStructure.EXTI_Line = EXTI_Line9;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init(&EXTI_InitStructure);
|
||||
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource9);
|
||||
EXTI_InitStructure.EXTI_Line = EXTI_Line9;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init(&EXTI_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 8;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 8;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
}
|
||||
|
||||
#define I2C_TIMEOUT_MAX 1000
|
||||
|
||||
bool I2C_WaitEvent(uint32_t event)
|
||||
{
|
||||
uint32_t timeout = I2C_TIMEOUT_MAX;
|
||||
@@ -211,23 +210,26 @@ bool I2C_WaitEventCleared(uint32_t event)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool I2C_Send7BitAddress(uint8_t address, uint16_t direction){
|
||||
bool I2C_Send7BitAddress(uint8_t address, uint16_t direction)
|
||||
{
|
||||
I2C_SendData(I2C_TOUCH, (address << 1) | ((direction == I2C_Direction_Receiver) ? 1 : 0));
|
||||
// check if slave acknowledged his address within timeout
|
||||
if(!I2C_WaitEvent(direction == I2C_Direction_Transmitter ? I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED : I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)) return false;
|
||||
if (!I2C_WaitEvent(direction == I2C_Direction_Transmitter ? I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED : I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool touch_i2c_read(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len){
|
||||
bool touch_i2c_read(uint8_t addr, uint8_t reg, uint8_t * data, uint8_t len)
|
||||
{
|
||||
if (!I2C_WaitEventCleared(I2C_FLAG_BUSY)) return false;
|
||||
I2C_GenerateSTART(I2C_TOUCH, ENABLE);
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_MODE_SELECT)) return false;
|
||||
if(!I2C_Send7BitAddress(addr, I2C_Direction_Transmitter)) return false;
|
||||
if (!I2C_Send7BitAddress(addr, I2C_Direction_Transmitter)) return false;
|
||||
I2C_SendData(I2C_TOUCH, reg);
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED)) return false;
|
||||
I2C_GenerateSTART(I2C_TOUCH, ENABLE);
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_MODE_SELECT)) return false;
|
||||
if(!I2C_Send7BitAddress(addr, I2C_Direction_Receiver)) return false;
|
||||
if (!I2C_Send7BitAddress(addr, I2C_Direction_Receiver)) return false;
|
||||
|
||||
if (len > 1) I2C_AcknowledgeConfig(I2C_TOUCH, ENABLE);
|
||||
|
||||
@@ -241,16 +243,16 @@ bool touch_i2c_read(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len){
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool touch_i2c_write(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len)
|
||||
static bool touch_i2c_write(uint8_t addr, uint8_t reg, uint8_t * data, uint8_t len)
|
||||
{
|
||||
if (!I2C_WaitEventCleared(I2C_FLAG_BUSY)) return false;
|
||||
I2C_GenerateSTART(I2C_TOUCH, ENABLE);
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_MODE_SELECT)) return false;
|
||||
|
||||
if(!I2C_Send7BitAddress(addr, I2C_Direction_Transmitter)) return false;
|
||||
I2C_SendData(I2C_TOUCH, (uint8_t)((reg & 0xFF00) >> 8));
|
||||
if (!I2C_Send7BitAddress(addr, I2C_Direction_Transmitter)) return false;
|
||||
I2C_SendData(I2C_TOUCH, (uint8_t) ((reg & 0xFF00) >> 8));
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING)) return false;
|
||||
I2C_SendData(I2C_TOUCH, (uint8_t)(reg & 0x00FF));
|
||||
I2C_SendData(I2C_TOUCH, (uint8_t) (reg & 0x00FF));
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING)) return false;
|
||||
while (len--) {
|
||||
I2C_SendData(I2C_TOUCH, *data);
|
||||
@@ -266,9 +268,9 @@ static bool touch_i2c_write(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t le
|
||||
static void TS_IO_Write(uint8_t addr, uint8_t reg, uint8_t data)
|
||||
{
|
||||
uint8_t tryCount = 3;
|
||||
while(!touch_i2c_write(addr, reg, &data, 1)) {
|
||||
if(--tryCount == 0) break;
|
||||
I2C_Init();
|
||||
while (!touch_i2c_write(addr, reg, &data, 1)) {
|
||||
if (--tryCount == 0) break;
|
||||
I2C_Init();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,36 +278,38 @@ static uint8_t TS_IO_Read(uint8_t addr, uint8_t reg)
|
||||
{
|
||||
uint8_t retult;
|
||||
uint8_t tryCount = 3;
|
||||
while(!touch_i2c_read(addr, reg, &retult, 1)) {
|
||||
if(--tryCount == 0) break;
|
||||
while (!touch_i2c_read(addr, reg, &retult, 1)) {
|
||||
if (--tryCount == 0) break;
|
||||
I2C_Init();
|
||||
}
|
||||
return retult;
|
||||
}
|
||||
|
||||
static uint16_t TS_IO_ReadMultiple(uint8_t addr, uint8_t reg, uint8_t *buffer, uint16_t length)
|
||||
static uint16_t TS_IO_ReadMultiple(uint8_t addr, uint8_t reg, uint8_t * buffer, uint16_t length)
|
||||
{
|
||||
uint8_t tryCount = 3;
|
||||
while(!touch_i2c_read(addr, reg, buffer, length)) {
|
||||
if(--tryCount == 0) break;
|
||||
while (!touch_i2c_read(addr, reg, buffer, length)) {
|
||||
if (--tryCount == 0) break;
|
||||
I2C_Init();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static uint8_t TS_IO_Read(uint8_t reg) {
|
||||
static uint8_t TS_IO_Read(uint8_t reg)
|
||||
{
|
||||
return TS_IO_Read(TOUCH_FT6236_I2C_ADDRESS, reg);
|
||||
}
|
||||
|
||||
static void touch_ft6236_debug_info(void) {
|
||||
static void touch_ft6236_debug_info(void)
|
||||
{
|
||||
#if defined(DEBUG)
|
||||
TRACE("ft6x36: thrhld = %d", TS_IO_Read(TOUCH_FT6236_REG_TH_GROUP) * 4);
|
||||
TRACE("ft6x36: rep rate=", TS_IO_Read(TOUCH_FT6236_REG_PERIODACTIVE) * 10);
|
||||
TRACE("ft6x36: fw lib 0x%02X %02X", TS_IO_Read(TOUCH_FT6236_REG_LIB_VER_H), TS_IO_Read(TOUCH_FT6236_REG_LIB_VER_L));
|
||||
TRACE("ft6x36: fw v 0x%02X", TS_IO_Read(TOUCH_FT6236_REG_FIRMID));
|
||||
TRACE("ft6x36: CHIP ID 0x%02X", TS_IO_Read(TOUCH_FT6236_REG_CIPHER));
|
||||
TRACE("ft6x36: CTPM ID 0x%02X", TS_IO_Read(TOUCH_FT6236_REG_FOCALTECH_ID));
|
||||
TRACE("ft6x36: rel code 0x%02X", TS_IO_Read(TOUCH_FT6236_REG_RELEASE_CODE_ID));
|
||||
TRACE("ft6x36: thrhld = %d", TS_IO_Read(TOUCH_FT6236_REG_TH_GROUP) * 4);
|
||||
TRACE("ft6x36: rep rate=", TS_IO_Read(TOUCH_FT6236_REG_PERIODACTIVE) * 10);
|
||||
TRACE("ft6x36: fw lib 0x%02X %02X", TS_IO_Read(TOUCH_FT6236_REG_LIB_VER_H), TS_IO_Read(TOUCH_FT6236_REG_LIB_VER_L));
|
||||
TRACE("ft6x36: fw v 0x%02X", TS_IO_Read(TOUCH_FT6236_REG_FIRMID));
|
||||
TRACE("ft6x36: CHIP ID 0x%02X", TS_IO_Read(TOUCH_FT6236_REG_CIPHER));
|
||||
TRACE("ft6x36: CTPM ID 0x%02X", TS_IO_Read(TOUCH_FT6236_REG_FOCALTECH_ID));
|
||||
TRACE("ft6x36: rel code 0x%02X", TS_IO_Read(TOUCH_FT6236_REG_RELEASE_CODE_ID));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -318,22 +322,21 @@ static void touch_ft6236_debug_info(void) {
|
||||
*/
|
||||
static uint8_t ft6x06_TS_DetectTouch(uint16_t DeviceAddr)
|
||||
{
|
||||
volatile uint8_t nbTouch = 0;
|
||||
volatile uint8_t nbTouch = 0;
|
||||
|
||||
/* Read register FT6206_TD_STAT_REG to check number of touches detection */
|
||||
nbTouch = TS_IO_Read(DeviceAddr, FT6206_TD_STAT_REG);
|
||||
nbTouch &= FT6206_TD_STAT_MASK;
|
||||
if(nbTouch > FT6206_MAX_DETECTABLE_TOUCH)
|
||||
{
|
||||
/* If invalid number of touch detected, set it to zero */
|
||||
nbTouch = 0;
|
||||
}
|
||||
/* Update ft6x06 driver internal global : current number of active touches */
|
||||
ft6x06_handle.currActiveTouchNb = nbTouch;
|
||||
/* Read register FT6206_TD_STAT_REG to check number of touches detection */
|
||||
nbTouch = TS_IO_Read(DeviceAddr, FT6206_TD_STAT_REG);
|
||||
nbTouch &= FT6206_TD_STAT_MASK;
|
||||
if (nbTouch > FT6206_MAX_DETECTABLE_TOUCH) {
|
||||
/* If invalid number of touch detected, set it to zero */
|
||||
nbTouch = 0;
|
||||
}
|
||||
/* Update ft6x06 driver internal global : current number of active touches */
|
||||
ft6x06_handle.currActiveTouchNb = nbTouch;
|
||||
|
||||
/* Reset current active touch index on which to work on */
|
||||
ft6x06_handle.currActiveTouchIdx = 0;
|
||||
return(nbTouch);
|
||||
/* Reset current active touch index on which to work on */
|
||||
ft6x06_handle.currActiveTouchIdx = 0;
|
||||
return (nbTouch);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -351,43 +354,41 @@ static uint8_t ft6x06_TS_DetectTouch(uint16_t DeviceAddr)
|
||||
|
||||
* @retval None.
|
||||
*/
|
||||
static void ft6x06_TS_GetTouchInfo(uint16_t DeviceAddr,
|
||||
uint32_t touchIdx,
|
||||
uint32_t * pWeight,
|
||||
uint32_t * pArea,
|
||||
uint32_t * pEvent)
|
||||
static void ft6x06_TS_GetTouchInfo(uint16_t DeviceAddr,
|
||||
uint32_t touchIdx,
|
||||
uint32_t * pWeight,
|
||||
uint32_t * pArea,
|
||||
uint32_t * pEvent)
|
||||
{
|
||||
uint8_t regAddress = 0;
|
||||
uint8_t dataxy[3];
|
||||
uint8_t regAddress = 0;
|
||||
uint8_t dataxy[3];
|
||||
|
||||
if(touchIdx < ft6x06_handle.currActiveTouchNb)
|
||||
{
|
||||
switch(touchIdx)
|
||||
{
|
||||
case 0 :
|
||||
regAddress = FT6206_P1_WEIGHT_REG;
|
||||
break;
|
||||
if (touchIdx < ft6x06_handle.currActiveTouchNb) {
|
||||
switch (touchIdx) {
|
||||
case 0 :
|
||||
regAddress = FT6206_P1_WEIGHT_REG;
|
||||
break;
|
||||
|
||||
case 1 :
|
||||
regAddress = FT6206_P2_WEIGHT_REG;
|
||||
break;
|
||||
case 1 :
|
||||
regAddress = FT6206_P2_WEIGHT_REG;
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
|
||||
} /* end switch(touchIdx) */
|
||||
} /* end switch(touchIdx) */
|
||||
|
||||
/* Read weight, area and Event Id of touch index */
|
||||
TS_IO_ReadMultiple(DeviceAddr, regAddress, dataxy, sizeof(dataxy));
|
||||
/* Read weight, area and Event Id of touch index */
|
||||
TS_IO_ReadMultiple(DeviceAddr, regAddress, dataxy, sizeof(dataxy));
|
||||
|
||||
/* Return weight of touch index */
|
||||
* pWeight = (dataxy[0] & FT6206_TOUCH_WEIGHT_MASK) >> FT6206_TOUCH_WEIGHT_SHIFT;
|
||||
/* Return area of touch index */
|
||||
* pArea = (dataxy[1] & FT6206_TOUCH_AREA_MASK) >> FT6206_TOUCH_AREA_SHIFT;
|
||||
/* Return Event Id of touch index */
|
||||
* pEvent = (dataxy[2] & FT6206_TOUCH_EVT_FLAG_MASK) >> FT6206_TOUCH_EVT_FLAG_SHIFT;
|
||||
/* Return weight of touch index */
|
||||
*pWeight = (dataxy[0] & FT6206_TOUCH_WEIGHT_MASK) >> FT6206_TOUCH_WEIGHT_SHIFT;
|
||||
/* Return area of touch index */
|
||||
*pArea = (dataxy[1] & FT6206_TOUCH_AREA_MASK) >> FT6206_TOUCH_AREA_SHIFT;
|
||||
/* Return Event Id of touch index */
|
||||
*pEvent = (dataxy[2] & FT6206_TOUCH_EVT_FLAG_MASK) >> FT6206_TOUCH_EVT_FLAG_SHIFT;
|
||||
|
||||
} /* of if(touchIdx < ft6x06_handle.currActiveTouchNb) */
|
||||
} /* of if(touchIdx < ft6x06_handle.currActiveTouchNb) */
|
||||
}
|
||||
|
||||
|
||||
@@ -400,56 +401,56 @@ static void ft6x06_TS_GetTouchInfo(uint16_t DeviceAddr,
|
||||
* @param Y: Pointer to Y position value
|
||||
* @retval None.
|
||||
*/
|
||||
static void ft6x06_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y, uint32_t *event)
|
||||
static void ft6x06_TS_GetXY(uint16_t DeviceAddr, uint16_t * X, uint16_t * Y, uint32_t * event)
|
||||
{
|
||||
uint8_t regAddress = 0;
|
||||
uint8_t dataxy[4];
|
||||
uint8_t regAddress = 0;
|
||||
uint8_t dataxy[4];
|
||||
|
||||
if(ft6x06_handle.currActiveTouchIdx < ft6x06_handle.currActiveTouchNb)
|
||||
{
|
||||
switch(ft6x06_handle.currActiveTouchIdx)
|
||||
{
|
||||
case 0 :
|
||||
regAddress = FT6206_P1_XH_REG;
|
||||
break;
|
||||
case 1 :
|
||||
regAddress = FT6206_P2_XH_REG;
|
||||
break;
|
||||
if (ft6x06_handle.currActiveTouchIdx < ft6x06_handle.currActiveTouchNb) {
|
||||
switch (ft6x06_handle.currActiveTouchIdx) {
|
||||
case 0 :
|
||||
regAddress = FT6206_P1_XH_REG;
|
||||
break;
|
||||
case 1 :
|
||||
regAddress = FT6206_P2_XH_REG;
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
|
||||
/* Read X and Y positions */
|
||||
TS_IO_ReadMultiple(DeviceAddr, regAddress, dataxy, sizeof(dataxy));
|
||||
/* Send back ready X position to caller */
|
||||
*X = ((dataxy[0] & FT6206_MSB_MASK) << 8) | (dataxy[1] & FT6206_LSB_MASK);
|
||||
/* Send back ready Y position to caller */
|
||||
*Y = ((dataxy[2] & FT6206_MSB_MASK) << 8) | (dataxy[3] & FT6206_LSB_MASK);
|
||||
|
||||
*event = (dataxy[0] & FT6206_TOUCH_EVT_FLAG_MASK) >> FT6206_TOUCH_EVT_FLAG_SHIFT;
|
||||
/*
|
||||
uint32_t weight;
|
||||
uint32_t area;
|
||||
ft6x06_TS_GetTouchInfo(DeviceAddr, ft6x06_handle.currActiveTouchIdx, &weight, &area, event);
|
||||
*/
|
||||
ft6x06_handle.currActiveTouchIdx++;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
|
||||
/* Read X and Y positions */
|
||||
TS_IO_ReadMultiple(DeviceAddr, regAddress, dataxy, sizeof(dataxy));
|
||||
/* Send back ready X position to caller */
|
||||
*X = ((dataxy[0] & FT6206_MSB_MASK) << 8) | (dataxy[1] & FT6206_LSB_MASK);
|
||||
/* Send back ready Y position to caller */
|
||||
*Y = ((dataxy[2] & FT6206_MSB_MASK) << 8) | (dataxy[3] & FT6206_LSB_MASK);
|
||||
|
||||
*event = (dataxy[0] & FT6206_TOUCH_EVT_FLAG_MASK) >> FT6206_TOUCH_EVT_FLAG_SHIFT;
|
||||
/*
|
||||
uint32_t weight;
|
||||
uint32_t area;
|
||||
ft6x06_TS_GetTouchInfo(DeviceAddr, ft6x06_handle.currActiveTouchIdx, &weight, &area, event);
|
||||
*/
|
||||
ft6x06_handle.currActiveTouchIdx++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void ft6x06_TS_GetGestureID(uint16_t DeviceAddr, uint32_t * pGestureId)
|
||||
{
|
||||
*pGestureId = TS_IO_Read(DeviceAddr, FT6206_GEST_ID_REG);
|
||||
*pGestureId = TS_IO_Read(DeviceAddr, FT6206_GEST_ID_REG);
|
||||
}
|
||||
|
||||
void TouchReset(){
|
||||
void TouchReset()
|
||||
{
|
||||
GPIO_ResetBits(I2C_TOUCH_RESET_GPIO, I2C_TOUCH_RESET_GPIO_PIN);
|
||||
delay_ms(20);
|
||||
GPIO_SetBits(I2C_TOUCH_RESET_GPIO, I2C_TOUCH_RESET_GPIO_PIN);
|
||||
delay_ms(300);
|
||||
}
|
||||
void TouchInit( void )
|
||||
|
||||
void TouchInit(void)
|
||||
{
|
||||
I2C_Init();
|
||||
TouchReset();
|
||||
@@ -488,68 +489,57 @@ void handleTouch()
|
||||
ft6x06_TS_GetXY(TOUCH_FT6236_I2C_ADDRESS, &Tx, &Ty, &TouchEvent);
|
||||
uint32_t gesture;
|
||||
ft6x06_TS_GetGestureID(TOUCH_FT6236_I2C_ADDRESS, &gesture);
|
||||
#if defined( LCD_DIRECTION ) && ( LCD_DIRECTION == LCD_VERTICAL )
|
||||
Tx=LCD_WIDTH-Tx;
|
||||
Ty=LCD_HEIGHT-Ty;
|
||||
#if defined( LCD_DIRECTION ) && (LCD_DIRECTION == LCD_VERTICAL)
|
||||
Tx = LCD_WIDTH - Tx;
|
||||
Ty = LCD_HEIGHT - Ty;
|
||||
#else
|
||||
x = ( LCD_WIDTH - 1 ) - Ty;
|
||||
Ty = Tx;
|
||||
Tx = x;
|
||||
#endif
|
||||
if(TouchEvent == FT6206_TOUCH_EVT_FLAG_CONTACT)
|
||||
{
|
||||
touchState.X = Tx;
|
||||
touchState.Y = Ty;
|
||||
if (TouchEvent == FT6206_TOUCH_EVT_FLAG_CONTACT) {
|
||||
touchState.x = Tx;
|
||||
touchState.y = Ty;
|
||||
|
||||
if( TOUCH_NONE == TouchState )
|
||||
{
|
||||
touchState.Event = TE_NONE;
|
||||
TouchState = TOUCH_CLICK;
|
||||
if (TOUCH_NONE == TouchState) {
|
||||
touchState.event = TE_NONE;
|
||||
TouchState = TOUCH_CLICK;
|
||||
if (g_eeGeneral.backlightMode & e_backlight_mode_keys)
|
||||
backlightOn(); // TODO is that the best place ?
|
||||
}
|
||||
else {
|
||||
if (TOUCH_CLICK == TouchState) {
|
||||
x = Tx - Txold;
|
||||
y = Ty - Tyold;
|
||||
|
||||
TouchStartX = Tx;
|
||||
TouchStartY = Ty;
|
||||
|
||||
if (g_eeGeneral.backlightMode & e_backlight_mode_keys)
|
||||
backlightOn(); // TODO is that the best place ?
|
||||
if ((x >= SLIDE_RANGE) || (x <= -SLIDE_RANGE) || (y >= SLIDE_RANGE) || (y <= -SLIDE_RANGE)) {
|
||||
TouchState = TOUCH_SLIDE;
|
||||
touchState.event = TE_SLIDE;
|
||||
}
|
||||
else {
|
||||
touchState.event = TE_DOWN;
|
||||
touchState.startX = touchState.lastX = touchState.x;
|
||||
touchState.startY = touchState.lastY = touchState.y;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( TOUCH_CLICK == TouchState )
|
||||
{
|
||||
x = Tx - Txold;
|
||||
y = Ty - Tyold;
|
||||
|
||||
if( ( x >= SLIDE_RANGE ) || ( x <= -SLIDE_RANGE ) || ( y >= SLIDE_RANGE ) || ( y <= -SLIDE_RANGE ) )
|
||||
{
|
||||
TouchState = TOUCH_SLIDE;
|
||||
touchState.Event = TE_SLIDE;
|
||||
}
|
||||
else
|
||||
{
|
||||
touchState.Event = TE_DOWN;
|
||||
touchState.startX = touchState.lastX = touchState.X;
|
||||
touchState.startY = touchState.lastY = touchState.Y;
|
||||
}
|
||||
}
|
||||
else if ( TOUCH_SLIDE == TouchState )
|
||||
{
|
||||
touchState.Event = TE_SLIDE;
|
||||
}
|
||||
else
|
||||
{
|
||||
TouchState = TOUCH_NONE;
|
||||
}
|
||||
else if (TOUCH_SLIDE == TouchState) {
|
||||
touchState.event = TE_SLIDE;
|
||||
}
|
||||
Txold = Tx;
|
||||
Tyold = Ty;
|
||||
else {
|
||||
TouchState = TOUCH_NONE;
|
||||
}
|
||||
}
|
||||
Txold = Tx;
|
||||
Tyold = Ty;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void EXTI9_5_IRQHandler(void) {
|
||||
extern "C" void EXTI9_5_IRQHandler(void)
|
||||
{
|
||||
|
||||
if(EXTI_GetITStatus(EXTI_Line9) != RESET) {
|
||||
if (EXTI_GetITStatus(EXTI_Line9) != RESET) {
|
||||
|
||||
if(ft6x06_TS_DetectTouch(TOUCH_FT6236_I2C_ADDRESS)){
|
||||
if (ft6x06_TS_DetectTouch(TOUCH_FT6236_I2C_ADDRESS)) {
|
||||
handleTouch();
|
||||
/*
|
||||
TRACE("X %d Y %d", x, y);
|
||||
@@ -560,20 +550,17 @@ extern "C" void EXTI9_5_IRQHandler(void) {
|
||||
if(gesture != TOUCH_FT6236_GESTURE_NONE) TRACE("gesture d3 %d", gesture);
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( TOUCH_CLICK == TouchState )
|
||||
{
|
||||
touchState.X = Txold;
|
||||
touchState.Y = Tyold;
|
||||
touchState.Event = TE_UP;
|
||||
touchState.Time = get_tmr10ms();
|
||||
else {
|
||||
if (TOUCH_CLICK == TouchState) {
|
||||
touchState.x = Txold;
|
||||
touchState.y = Tyold;
|
||||
touchState.event = TE_UP;
|
||||
touchState.time = get_tmr10ms();
|
||||
}
|
||||
else if (get_tmr10ms() > touchState.Time + 50)
|
||||
{
|
||||
touchState.X = LCD_WIDTH;
|
||||
touchState.Y = LCD_HEIGHT;
|
||||
touchState.Event = TE_NONE;
|
||||
else if (get_tmr10ms() > touchState.time + 50) {
|
||||
touchState.x = LCD_WIDTH;
|
||||
touchState.y = LCD_HEIGHT;
|
||||
touchState.event = TE_NONE;
|
||||
}
|
||||
TouchState = TOUCH_NONE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user