TA的每日心情 | 擦汗 2019-6-26 20:59 |
---|
签到天数: 235 天 连续签到: 1 天 [LV.7]常住居民III
|
本帖最后由 小马哥-1650185 于 2018-6-16 13:08 编辑
野火5寸电容屏采用了i2c电容屏驱动函数gt9157芯片,支持5点触控。
GT9157的iic接口
触摸芯片引脚定义
- #define TOUCH_PAD_SCL_IOMUXC IOMUXC_GPIO_AD_B1_00_LPI2C1_SCL
- #define TOUCH_PAD_SDA_IOMUXC IOMUXC_GPIO_AD_B1_01_LPI2C1_SDA
- #define TOUCH_PAD_RST_GPIO GPIO1
- #define TOUCH_PAD_RST_GPIO_PIN (2U)
- #define TOUCH_PAD_RST_IOMUXC IOMUXC_GPIO_AD_B0_02_GPIO1_IO02
- #define TOUCH_PAD_INT_GPIO GPIO1
- #define TOUCH_PAD_INT_GPIO_PIN (11U)
- #define TOUCH_PAD_INT_IOMUXC IOMUXC_GPIO_AD_B0_11_GPIO1_IO11
- #define TOUCH_PAD_INT_IRQ GPIO1_Combined_0_15_IRQn
- #define TOUCH_PAD_IRQHANDLER GPIO1_Combined_0_15_IRQHandler
复制代码
iic 初始化
触摸引脚及芯片初始化
- void I2C_Touch_Init(void)
- {
- /* 初始化各引脚IOMUXC相关 */
- I2C_GTP_IOMUXC_MUX_Config();
- I2C_GTP_IOMUXC_PAD_Config();
- /* 初始化I2C外设工作模式 */
- GTP_I2C_ModeInit();
-
- /* 复位触摸芯片,配置地址 */
- GTP_ResetChip();
- // I2C_GTP_IRQEnable();
- }
复制代码
5寸屏GT9157驱动配置- const 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
- };
复制代码
gtp初始化
- int32_t GTP_Init_Panel(void)
- {
- int32_t ret = -1;
- int32_t i = 0;
- uint8_t check_sum = 0;
- int32_t retry = 0;
- const uint8_t* cfg_info;
- uint8_t cfg_info_len ;
- uint8_t cfg_num =0x80FE-0x8047+1 ; //需要配置的寄存器个数
- GTP_DEBUG_FUNC();
- I2C_Touch_Init();
- ret = GTP_I2C_Test();
- if (ret < 0)
- {
- GTP_ERROR("I2C communication ERROR!");
- return ret;
- }
-
- //获取触摸IC的型号
- GTP_Read_Version();
-
- //根据IC的型号指向不同的配置
- if(touchIC == GT9157)
- {
- cfg_info = CTP_CFG_GT9157; //指向寄存器配置
- cfg_info_len = CFG_GROUP_LEN(CTP_CFG_GT9157);//计算配置表的大小
- }
- else
- {
- cfg_info = CTP_CFG_GT911;//指向寄存器配置
- cfg_info_len = CFG_GROUP_LEN(CTP_CFG_GT911) ;//计算配置表的大小
- }
- memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH);
- memcpy(&config[GTP_ADDR_LENGTH], cfg_info, cfg_info_len);
-
- //计算要写入checksum寄存器的值
- 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 配置更新标志
- //写入配置信息
- for (retry = 0; retry < 5; retry++)
- {
- ret = GTP_I2C_Write(GTP_ADDRESS, config , cfg_num + GTP_ADDR_LENGTH+2);
- if (ret > 0)
- {
- break;
- }
- }
- Delay(0xffffff); //延迟等待芯片更新
-
-
- #if 0 //读出写入的数据,检查是否正常写入
- //检验读出的数据与写入的是否相同
- {
- uint16_t i;
- uint8_t buf[200];
- buf[0] = config[0];
- buf[1] =config[1]; //寄存器地址
- GTP_DEBUG_FUNC();
- ret = GTP_I2C_Read(GTP_ADDRESS, buf, sizeof(buf));
- //版本号写入0x00后,会进行复位,复位为0x41
- config[GTP_ADDR_LENGTH] = 0x41;
- for(i=0;i<cfg_num+GTP_ADDR_LENGTH;i++)
- {
- if(config[i] != buf[i])
- {
- GTP_ERROR("Config fail ! i = %d ",i);
- return -1;
- }
- }
- if(i==cfg_num+GTP_ADDR_LENGTH)
- GTP_DEBUG("Config success ! i = %d ",i);
- }
- #endif
-
-
- /*使能中断,这样才能检测触摸数据*/
- GTP_IRQEnable();
-
- GTP_Get_Info();
- return 0;
- }
复制代码
Palette_Init 画板初始化
- void Palette_Init(void)
- {
-
- uint8_t i;
- /* 整屏清为白色 */
- LCD_Clear(CL_WHITE); /* 清屏,显示全黑 */
-
- /* 初始化按钮 */
- Touch_Button_Init();
-
- /* 描绘按钮 */
- for(i=0;i<BUTTON_NUM;i++)
- {
- button[i].draw_btn(&button[i]);
- }
-
-
- /* 初始化画笔 */
- brush.color = CL_BLACK;
- brush.shape = LINE_SINGLE_PIXCEL;
-
- LCD_SetTextColor(brush.color);
- }
复制代码
在画板区域描绘触摸轨迹- void Draw_Trail(int16_t pre_x,int16_t pre_y,int16_t x,int16_t y,Brush_Style* brush)
- {
- /*设置画板区域为活动窗口,bsp_lcd.c驱动还没有这样的函数,用于限制绘画窗口*/
- // RA8875_SetActiveWindow(PALETTE_START_X,PALETTE_START_Y,PALETTE_END_X,PALETTE_END_Y);
-
-
- /*触摸位置在画板区域*/
- if(x>PALETTE_START_X && pre_x>PALETTE_START_X )
- {
- switch(brush->shape) /*根据画刷参数描绘不同的轨迹*/
- {
- /* 描绘1像素宽度的轨迹线 */
- case LINE_SINGLE_PIXCEL:
- if(pre_x< 0 || pre_y < 0) //新的笔迹
- {
- PutPixel(x,y);
- }
- else //继续上一次的笔迹
- {
- LCD_DrawUniLine(pre_x,pre_y,x,y);
- }
-
- break;
-
- case LINE_2_PIXCEL:
-
- if(x-1<PALETTE_START_X||pre_x-1<PALETTE_START_X) //画板左边界
- break;
- /* 描绘2像素宽度的轨迹线 */
- LCD_DrawUniLineCircle(pre_x,pre_y,x,y,1);
-
- break;
-
- case LINE_4_PIXCEL:
-
- if(x-2<PALETTE_START_X||pre_x-2<PALETTE_START_X) //画板左边界
- break;
-
- LCD_DrawUniLineCircle(pre_x,pre_y,x,y,2);
- break;
-
- case LINE_6_PIXCEL:
-
- if(x-3<PALETTE_START_X||pre_x-3<PALETTE_START_X) //画板左边界
- break;
-
- LCD_DrawUniLineCircle(pre_x,pre_y,x,y,3);
-
- break;
-
- case LINE_8_PIXCEL:
-
- if(x-4<PALETTE_START_X||pre_x-4<PALETTE_START_X) //画板左边界
- break;
-
- LCD_DrawUniLineCircle(pre_x,pre_y,x,y,4);
- break;
-
- case LINE_16_PIXCEL:
-
- if(x-8<PALETTE_START_X||pre_x-8<PALETTE_START_X) //画板左边界
- break;
-
- LCD_DrawUniLineCircle(pre_x,pre_y,x,y,8);
- break;
-
- case LINE_20_PIXCEL:
-
- if(x-10<PALETTE_START_X ||pre_x-10<PALETTE_START_X) //画板左边界
- break;
-
- LCD_DrawUniLineCircle(pre_x,pre_y,x,y,10);
- break;
-
- /*描绘带珠子的单像素线*/
- case LINE_WITH_CIRCLE:
- if(x-3<PALETTE_START_X||pre_x-3<PALETTE_START_X) //画板左边界
- break;
-
- if(pre_x< 0 || pre_y< 0)//新的笔迹
- {
- PutPixel(x,y);
- }
- else //继续上一次的笔迹
- {
- LCD_DrawUniLine(pre_x,pre_y,x,y);
- LCD_DrawFullCircle(x,y,3);
- }
-
- break;
-
- /*橡皮功能*/
- case RUBBER:
-
- if(x-20<PALETTE_START_X || //画板左边界
- x+20>LCD_PIXEL_WIDTH || x-20<0 || //液晶左右边界
- y+20>LCD_PIXEL_HEIGHT || y-20<0) //液晶上下边界
- break;
-
- // if(x>PALETTE_START_X+20)
- {
- LCD_SetColors(CL_WHITE,CL_WHITE);
-
- LCD_DrawFullRect( x-40/2,
- y-40/2,
- 40,
- 40);
-
- }
- break;
- }
- }
-
- /*退出局限画板的绘图窗口,bsp_lcd.c驱动还没有这样的函数,用于限制绘画窗口*/
- // RA8875_SetActiveWindow(0,0,LCD_PIXEL_WIDTH,LCD_PIXEL_HEIGHT);
- }
复制代码
效果:
|
|