CYPRESS TMA54X/CY8CTMA54X 驱动调试

TMA54X使用I2C通信,但是有别于其他TP芯片,TMA54X使用了一个叫PIP(Packet Interface Protocol)的协议。

至于PIP协议到底是一个什么玩意,不如看通信时序来得直观。

手册指示的操作流程如下:

1. 设备上电后会自动复位,并在COMM_INT引脚产生一个最大18ms的中断信号,逻辑分析仪下的信号如下SCL、SDA拉高,Channel2(COMM_INT)产生两个脉冲):

2.初始化程序中,需要读两个字节,返回值都为0x00,自此,COMM_INT被拉高,TP进入Application模式

3.当TP有触摸操作时,中断产生,COMM_INT拉低,这时Host开始读数据,数据包格式参考手册


硬件平台使用的是MT2503,初始化及读数据包代码如下:

 

 

kal_bool ctp_cy8cttma54x_init(void)
{
	ctp_i2c_start();
	ctp_i2c_send_byte(0x49);
	ctp_i2c_receive_byte(0);
	ctp_i2c_receive_byte(1);
	ctp_i2c_stop();

	CTP_delay_ms(400);

	ctp_i2c_start();

	ctp_i2c_send_byte(0x49);
	ctp_i2c_receive_byte(0);
	ctp_i2c_receive_byte(1);
	ctp_i2c_stop();

	return KAL_TRUE;
}

typedef __packed struct {
	uint16_t length;
	uint8_t report_id;
	uint16_t timestamp;
	uint8_t b5;
	uint8_t b6;
} touch_report_t;

typedef __packed struct {
	uint8_t r5_touch_type;
	uint8_t tip1_eventid2_touchid5;
	uint16_t x;
	uint16_t y;
	uint8_t pressure;
	uint8_t major_axis_len;
	uint8_t minor_axis_len;
	uint8_t orientation;
} touch_record_t;

kal_bool ctp_cy8cttma54x_get_data(TouchPanelMultipleEventStruct *tpes)
{
	struct {
		touch_report_t touch_report;
		touch_record_t touch_record[3];
	} recv_packet;

	kal_uint8 *p_recv = (kal_uint8 *)&recv_packet;
	kal_uint8 i;
	kal_bool ret = KAL_FALSE;
	
	ctp_i2c_start();
	ctp_i2c_send_byte(0x49);

	*p_recv++ = ctp_i2c_receive_byte(0);
	*p_recv++ = ctp_i2c_receive_byte(0);

	if (recv_packet.touch_report.length <= sizeof(recv_packet)) {
		i = recv_packet.touch_report.length - 3;
		while (i--) {
			*p_recv++ = ctp_i2c_receive_byte(0);
		}
		*p_recv = ctp_i2c_receive_byte(1);
	}

	ctp_i2c_stop();

	if (recv_packet.touch_report.report_id == 0x01) {
		kal_uint8 num_of_records = recv_packet.touch_report.b5 & 0x1F;
		
		if (num_of_records > 3) num_of_records = 3;
		for (i=0; i<num_of_records; i++) {
			kal_prompt_trace(MOD_TP_TASK, "------- record index = %d, (%d, %d)", i, recv_packet.touch_record[i].x, recv_packet.touch_record[i].y);
			tpes->points[i].x = recv_packet.touch_record[i].y;
			tpes->points[i].y = recv_packet.touch_record[i].x;
		}

		tpes->time_stamp = (kal_uint16)L1I_GetTimeStamp();
		tpes->padding = CTP_PATTERN;
		tpes->model = num_of_records;

		if (num_of_records) {
			if (recv_packet.touch_record[0].tip1_eventid2_touchid5 & 0x80) {
				ret = KAL_TRUE;
			}
		}
	}

	return ret;
}

  

 

原文地址:http://www.noblock.cn/?p=236

 

posted @ 2019-12-13 17:28  mez  阅读(626)  评论(0编辑  收藏  举报