repair the timeout problem of i2c interrupt for xidatong

This commit is contained in:
Wang_Weigen 2022-06-02 15:53:24 +08:00
parent c6c0a0f71b
commit d57d8e0a4d
5 changed files with 55 additions and 28 deletions

View File

@ -192,9 +192,12 @@ typedef struct
#define PRIV_SYSTICK_GET (CurrentTicksGain())
#define PRIV_LCD_DEV "/dev/lcd_dev"
#define PRIV_TOUCH_DEV "/dev/touch_dev"
#define MY_DISP_HOR_RES BSP_LCD_Y_MAX
#define MY_DISP_VER_RES BSP_LCD_X_MAX
#define PRIV_TOUCH_DEV "/dev/touch_dev"
#define MY_INDEV_X BSP_LCD_Y_MAX
#define MY_INDEV_Y BSP_LCD_X_MAX
/**********************mutex**************************/
int PrivMutexCreate(pthread_mutex_t *p_mutex, const pthread_mutexattr_t *attr);

View File

@ -226,7 +226,12 @@ void lv_port_indev_init(void)
static void touchpad_init(void)
{
touch_fd = PrivOpen(PRIV_TOUCH_DEV,O_RDWR);
printf("touch fd = %d\n",touch_fd);
if(touch_fd >= 0) {
printf("touch fd = %d\n",touch_fd);
} else {
printf("open %s touch fd = %d\n",PRIV_TOUCH_DEV,touch_fd);
}
/*Your code comes here*/
}
@ -256,8 +261,9 @@ static bool touchpad_is_pressed(void)
/*Your code comes here*/
memset(&touch_data, 0 ,sizeof(TouchDataParam));
ret = PrivRead(touch_fd, &touch_data, 1);
if(ret && touch_data.x >= 0 && touch_data.x <= 480 && touch_data.y >= 0 && touch_data.y <= 272)
if(ret && touch_data.x >= 0 && touch_data.x < MY_INDEV_X && touch_data.y >= 0 && touch_data.y < MY_INDEV_Y)
{
// printf("touch x %d touch y %d\n",touch_data.x,touch_data.y);
return true;
}

View File

@ -1396,7 +1396,7 @@ void LPI2C_MasterTransferHandleIRQ(LPI2C_Type *base, lpi2c_master_handle_t *hand
}
result = LPI2C_RunTransferStateMachine(base, handle, &isDone);
if (isDone || (result != kStatus_Success))
{
/* XXX need to handle data that may be in rx fifo below watermark level? */
@ -2113,7 +2113,9 @@ void LPI2C0_DriverIRQHandler(void)
/* Implementation of LPI2C1 handler named in startup code. */
void LPI2C1_DriverIRQHandler(int irqn, void *arg)
{
DisableIRQ(LPI2C1_IRQn);
LPI2C_CommonIRQHandler(LPI2C1, 1);
EnableIRQ(LPI2C1_IRQn);
}
DECLARE_HW_IRQ(LPI2C1_IRQn, LPI2C1_DriverIRQHandler, NONE);
#endif

View File

@ -106,7 +106,7 @@ static int32_t GtpI2cRead(uint8_t client_addr, uint8_t *buf, int32_t len)
}
if((retries >= 5))
{
KPrintf("I2C Read: 0x%04X, %d bytes failed, errcode: %d! Process reset.\n", (((uint16_t)(buf[0] << 8)) | buf[1]), len-2, ret);
KPrintf("I2C Read: 0x%04X, %d bytes %d times failed, errcode: %d! Process reset.\n", (((uint16_t)(buf[0] << 8)) | buf[1]), len-2, retries,ret);
ret = -1;
}
return ret;
@ -180,17 +180,20 @@ bool GetTouchEvent(POINT *touch_point,touch_event_t *touch_event)
if (finger == 0x00) //没有数据,退出
{
return 0;
ret = 0;
goto exit_work_func;
}
if((finger & 0x80) == 0)//判断buffer status位
{
ret = 0;
goto exit_work_func;//坐标未就绪,数据无效
}
touch_num = finger & 0x0f;//坐标点数
if (touch_num > GTP_MAX_TOUCH)
{
ret = 0;
goto exit_work_func;//大于最大支持点数,错误退出
}
@ -220,10 +223,11 @@ exit_work_func:
ret = GtpI2cWrite(client_addr, end_cmd, 3);
if (ret < 0)
{
KPrintf("I2C write end_cmd error!");
KPrintf("I2C write end_cmd error!\n");
ret = 0;
}
}
return 1;
return ret;
}
int32_t GtpReadVersion(void)
@ -251,6 +255,7 @@ int32_t GtpReadVersion(void)
static int32_t GtpGetInfo(void)
{
uint8_t end_cmd[3] = {GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF, 0};
uint8_t opr_buf[6] = {0};
int32_t ret = 0;
@ -285,7 +290,13 @@ static int32_t GtpGetInfo(void)
KPrintf("X_MAX = %d, Y_MAX = %d, TRIGGER = 0x%02x\n",
abs_x_max,abs_y_max,int_trigger_type);
ret = GtpI2cWrite(GTP_ADDRESS, end_cmd, 3);
if (ret < 0)
{
KPrintf("I2C write end_cmd error!\n");
ret = 0;
}
return 0;
}
@ -294,7 +305,6 @@ static uint32 TouchOpen(void *dev)
int32_t ret = -1;
I2C_Touch_Init();
ret = GtpReadVersion();
if(ret < 0)
{
@ -339,6 +349,7 @@ static uint32 TouchRead(void *dev, struct BusBlockReadParam *read_param)
touch_event_t touch_event;
struct TouchDataStandard *data = (struct TouchDataStandard*)read_param->buffer;
read_param->read_length = 0;
result = KSemaphoreObtain(touch_sem, 1000);
if (EOK == result)
{
@ -349,11 +360,11 @@ static uint32 TouchRead(void *dev, struct BusBlockReadParam *read_param)
data->x = touch_point.X;
data->y = touch_point.Y;
g_TouchPadInputSignal = 0;
SemReleaseFlag = 0;
read_param->read_length = read_param->size;
ret = EOK;
}
SemReleaseFlag = 0;
}
return ret;

View File

@ -154,7 +154,7 @@ uint32_t I2C_ReadBytes(uint8_t ClientAddr,uint8_t* pBuffer, uint16_t NumByteToRe
{
lpi2c_master_transfer_t masterXfer = {0};
status_t reVal = kStatus_Fail;
uint32_t i2c_timeout = I2CT_LONG_TIMEOUT;
uint32_t i2c_timeout = I2CT_LONG_TIMEOUT;
/* subAddress = 0x00, data = pBuffer 自从机处接收
@ -169,20 +169,22 @@ uint32_t I2C_ReadBytes(uint8_t ClientAddr,uint8_t* pBuffer, uint16_t NumByteToRe
masterXfer.dataSize = NumByteToRead;
masterXfer.flags = kLPI2C_TransferDefaultFlag;
reVal = LPI2C_MasterTransferNonBlocking(GTP_I2C_MASTER, &g_m_handle, &masterXfer);
if (reVal != kStatus_Success)
{
return 1;
}
/* 复位传输完成标志 */
g_MasterCompletionFlag = false;
reVal = LPI2C_MasterTransferNonBlocking(GTP_I2C_MASTER, &g_m_handle, &masterXfer);
if (reVal != kStatus_Success)
{
return 1;
}
/* 等待传输完成 */
while (!g_MasterCompletionFlag)
{
if((i2c_timeout--) == 0) return I2C_Timeout_Callback(0);
if((i2c_timeout--) == 0)
return I2C_Timeout_Callback(0);
}
g_MasterCompletionFlag = false;
return 0;
@ -200,7 +202,7 @@ uint32_t I2C_WriteBytes(uint8_t ClientAddr,uint8_t* pBuffer, uint8_t NumByteToW
{
lpi2c_master_transfer_t masterXfer = {0};
status_t reVal = kStatus_Fail;
uint32_t i2c_timeout = I2CT_LONG_TIMEOUT;
uint32_t i2c_timeout = I2CT_LONG_TIMEOUT;
/* subAddress = 0x00, data = pBuffer 发送至从机
@ -215,18 +217,20 @@ uint32_t I2C_WriteBytes(uint8_t ClientAddr,uint8_t* pBuffer, uint8_t NumByteToW
masterXfer.dataSize = NumByteToWrite;
masterXfer.flags = kLPI2C_TransferDefaultFlag;
/* ¸´Î»´«ÊäÍê³É±êÖ¾ */
g_MasterCompletionFlag = false;
reVal = LPI2C_MasterTransferNonBlocking(GTP_I2C_MASTER, &g_m_handle, &masterXfer);
if (reVal != kStatus_Success)
{
return 1;
return 1;
}
/* ¸´Î»´«ÊäÍê³É±êÖ¾ */
g_MasterCompletionFlag = false;
/* 等待传输完成 */
while (!g_MasterCompletionFlag)
{
if((i2c_timeout--) == 0) return I2C_Timeout_Callback(1);
if((i2c_timeout--) == 0)
return I2C_Timeout_Callback(1);
}
g_MasterCompletionFlag = false;
@ -241,10 +245,10 @@ uint32_t I2C_WriteBytes(uint8_t ClientAddr,uint8_t* pBuffer, uint8_t NumByteToW
*/
static uint32_t I2C_Timeout_Callback(uint8_t errorCode)
{
/* Block communication and all processes */
KPrintf("I2C timeout!errorCode = %d",errorCode);
return 0xFF;
/* Block communication and all processes */
KPrintf("I2C timeout!errorCode = %d\n",errorCode);
return 0xFF;
}
/**
@ -300,6 +304,7 @@ void GT9xx_PEN_IRQHandler(int irqn, void *arg)
g_TouchPadInputSignal = true;
if(!SemReleaseFlag)
{
KPrintf("touch irq in release sem\n");
KSemaphoreAbandon(touch_sem);
SemReleaseFlag = true;
}