【先楫HPM6750测评】+LVGL修改触摸屏,但失败了,触摸出了点问题
[复制链接]
准备修改下触摸的,这样在原子的屏幕上就能使用了,修改了一天,最发现感觉是触摸屏坏了。先看下我修改的,准备修改的简单点。
#include "gt9147.h"
#include "hpm_gpio_drv.h"
static uint8_t g_i2c_addr;
const uint8_t GT9147_CFG_TBL[]=
{
0X65,0XE0,0X01,0X20,0X03,0X05,0X35,0X00,0X02,0X08,
0X1E,0X08,0X50,0X3C,0X0F,0X05,0X00,0X00,0XFF,0X67,
0X50,0X00,0X00,0X18,0X1A,0X1E,0X14,0X89,0X28,0X0A,
0X30,0X2E,0XBB,0X0A,0X03,0X00,0X00,0X02,0X33,0X1D,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X32,0X00,0X00,
0X2A,0X1C,0X5A,0X94,0XC5,0X02,0X07,0X00,0X00,0X00,
0XB5,0X1F,0X00,0X90,0X28,0X00,0X77,0X32,0X00,0X62,
0X3F,0X00,0X52,0X50,0X00,0X52,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X0F,
0X0F,0X03,0X06,0X10,0X42,0XF8,0X0F,0X14,0X00,0X00,
0X00,0X00,0X1A,0X18,0X16,0X14,0X12,0X10,0X0E,0X0C,
0X0A,0X08,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X29,0X28,0X24,0X22,0X20,0X1F,0X1E,0X1D,
0X0E,0X0C,0X0A,0X08,0X06,0X05,0X04,0X02,0X00,0XFF,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,
};
hpm_stat_t gt9147_read_data(I2C_Type *i2c_ptr, uint16_t addr, uint8_t *buf, uint32_t size)
{
uint8_t r[2];
r[0] = addr >> 8;
r[1] = addr & 0xFF;
//i2c_master_write(i2c_ptr, g_i2c_addr,r, sizeof(r));
//return i2c_master_read(i2c_ptr, g_i2c_addr, buf, size);
return i2c_master_address_read(i2c_ptr, g_i2c_addr, r, sizeof(r), buf, size);
}
hpm_stat_t gt9147_write_data(I2C_Type *i2c_ptr, uint16_t addr, uint8_t *buf, uint32_t size)
{
uint8_t r[2];
r[0] = addr >> 8;
r[1] = addr & 0xFF;
return i2c_master_address_write(i2c_ptr, g_i2c_addr, r, sizeof(r), buf, size);
}
hpm_stat_t gt9147_read_register(I2C_Type *i2c_ptr, uint16_t reg, uint8_t *buf)
{
return gt9147_read_data(i2c_ptr, reg, buf, 1);
}
hpm_stat_t gt9147_write_register(I2C_Type *i2c_ptr, uint16_t reg, uint8_t val)
{
return gt9147_write_data(i2c_ptr, reg, &val, 1);
}
//发送GT9147配置参数
//mode:0,参数不保存到flash
// 1,参数保存到flash
uint8_t GT9147_Send_Cfg(I2C_Type *i2c_ptr,uint8_t mode)
{
uint8_t buf[2];
uint8_t i=0;
buf[0]=0;
buf[1]=mode; //是否写入到GT9147 FLASH? 即是否掉电保存
for(i=0;i<sizeof(GT9147_CFG_TBL);i++)buf[0]+=GT9147_CFG_TBL[i];//计算校验和
buf[0]=(~buf[0])+1;
gt9147_write_data(i2c_ptr,GT_CFGS_REG,(uint8_t*)GT9147_CFG_TBL,sizeof(GT9147_CFG_TBL));//发送寄存器配置
gt9147_write_data(i2c_ptr,GT_CHECK_REG,buf,2);//写入校验和,和配置更新标记
return 0;
}
const uint16_t GT9147_TPX_TBL[5]={GT_TP1_REG,GT_TP2_REG,GT_TP3_REG,GT_TP4_REG,GT_TP5_REG};
hpm_stat_t gt9147_init(I2C_Type *i2c_ptr)
{
hpm_stat_t stat = status_success;
g_i2c_addr = GT_9147_ADDR;
uint8_t temp[5];
board_delay_ms(100);
stat = gt9147_read_data(i2c_ptr, GT_PID_REG, temp, 4);
temp[4]=0;
printf("CTP ID:%s\r\n",temp); //打印ID
if (stat != status_success) {
printf("Master read failed\n");
return stat;
}
if(strcmp((char*)temp,"9147")==0)//ID==9147
{
temp[0]=0X02;
gt9147_write_register(i2c_ptr,GT_CTRL_REG,temp);//软复位GT9147
gt9147_read_register(i2c_ptr,GT_CFGS_REG,temp);//读取GT_CFGS_REG寄存器
if(temp[0]<0X65)//默认版本比较低,需要更新flash配置
{
printf("Default Ver:%d\r\n",temp[0]);
GT9147_Send_Cfg(i2c_ptr,1);//更新并保存配置
}
printf("Default Ver:%d\r\n",temp[0]);
board_delay_ms(10);
temp[0]=0X00;
gt9147_write_register(i2c_ptr,GT_CTRL_REG,temp);//结束复位
return status_success;
}
return status_success;
}
_m_tp_dev tp_dev;
hpm_stat_t touch_get_gt9147_data()
{
uint8_t mode = 1;
uint8_t buf[4];
uint8_t i=0;
uint8_t res=0;
uint8_t temp;
uint8_t tempsta;
static uint8_t t=0;//控制查询间隔,从而降低CPU占用率
t++;
if((t%10)==0||t<10)//空闲时,每进入10次CTP_Scan函数才检测1次,从而节省CPU使用率
{
gt9147_read_register(BOARD_CAP_I2C_BASE,GT_GSTID_REG,&mode); //读取触摸点的状态
printf("mode:%d\r\n",mode);
//if(mode&0X80&&((mode&0XF)<6))
//{
// temp=0;
// gt9147_write_register(BOARD_CAP_I2C_BASE,GT_GSTID_REG,&temp);//清标志
//}
//if((mode&0XF)&&((mode&0XF)<6))
//{
temp=0XFF<<(mode&0XF); //将点的个数转换为1的位数,匹配tp_dev.sta定义
tempsta=tp_dev.sta; //保存当前的tp_dev.sta值
tp_dev.sta=(~temp)|TP_PRES_DOWN|TP_CATH_PRES;
tp_dev.x[4]=tp_dev.x[0]; //保存触点0的数据
tp_dev.y[4]=tp_dev.y[0];
for(i=0;i<5;i++)
{
//if(tp_dev.sta&(1<<i)) //触摸有效?
//{
gt9147_read_data(BOARD_CAP_I2C_BASE,GT9147_TPX_TBL[i],buf,4); //读取XY坐标值
//printf("buf:%d %d\r\n",buf[0],buf[1]);
//}else
//{
tp_dev.x[i]=(((uint16_t)buf[1]<<8)+buf[0]);
tp_dev.y[i]=(((uint16_t)buf[3]<<8)+buf[2]);
//}
//printf("x[%d]:%d,y[%d]:%d\r\n",i,tp_dev.x[i],i,tp_dev.y[i]);
}
//res=1;
//if(tp_dev.x[0]>800||tp_dev.y[0]>480)//非法数据(坐标超出了)
//{
// if((mode&0XF)>1) //有其他点有数据,则复第二个触点的数据到第一个触点.
// {
// tp_dev.x[0]=tp_dev.x[1];
// tp_dev.y[0]=tp_dev.y[1];
// //触发一次,则会最少连续监测10次,从而提高命中率
// }
// else //非法数据,则忽略此次数据(还原原来的)
// {
// tp_dev.x[0]=tp_dev.x[4];
// tp_dev.y[0]=tp_dev.y[4];
// mode=0X80;
// tp_dev.sta=tempsta; //恢复tp_dev.sta
// }
//}else
//{
//t=0; //触发一次,则会最少连续监测10次,从而提高命中率
//}
printf("tp_dev.x[0]:%d \r\n",tp_dev.x[0]);
printf("tp_dev.y[0]:%d \r\n",tp_dev.y[0]);
//}
}
if((mode&0X8F)==0X80)//无触摸点按下
{
if(tp_dev.sta&TP_PRES_DOWN) //之前是被按下的
{
tp_dev.sta&=~(1<<7); //标记按键松开
}else //之前就没有被按下
{
tp_dev.x[0]=0xffff;
tp_dev.y[0]=0xffff;
tp_dev.sta&=0XE0; //清除点有效标记
}
}
if(t>240)t=10;//重新从10开始计数
return status_success;
}
测试读ID是可以的。我把屏换回开发板上开发板也是读不到了。
到这里就不对了读取内部寄存器第一个值是0。然后我们发送配置表,读取坐标都是零,不对了。
所以当后面的读取时就都是0了,目前测试了两块,都是坏了,比较悲剧。
|