static VM_DRV_TP_BOOL ctp_goodix_gt9xx_get_data(
		vm_drv_tp_multiple_event_t *tpes) {
	VMUINT8 lvalue = 0;
	VMUINT32 model = 0;
	VMUINT8 buf_status;
	VM_DRV_TP_BOOL ret = VM_DRV_TP_TRUE;
	VMUINT8 rst_char = 0;

	tpes->time_stamp = (VMUINT16) vm_drv_tp_get_time_stamp();
	tpes->padding = VM_DRV_TP_PATTERN;

	CTP_I2C_read(CTP_TOUCH_INFO_REG_BASE, &lvalue, 1);

	model = (VMUINT32) (lvalue & CTP_STAT_NUMBER_TOUCH);
	buf_status = lvalue & 0xF0;

	//vm_log_info( "model:%d buf_status:%d", model,buf_status);

	if (model > 5) //goodix only support 5 fingers
			{
		ret = VM_DRV_TP_FALSE;
		goto exit_get_data;
	}

	tpes->model = (VMUINT16) model;  //read out all touch points coordinates.

	if (model == 0) {
		ret = VM_DRV_TP_FALSE;
		CTP_I2C_read(CTP_POINT_INFO_REG_BASE + 1, &lvalue, 1);
		goto exit_get_data;
	}

	if (model <= 10) {
		if ((buf_status & 0x80) != 0) {
			ctp_read_all_point(tpes, model);
		} else {
			goto exit_get_data;
		}
	} else {
		if (model == 0x0d) {
			//TODO: check this event
		} else if (model == 0x0e) {
			//TODO: check this event
		} else {
			//TODO: check this event
		}

		goto exit_get_data;
	}

	exit_get_data:

	CTP_I2C_send(CTP_TOUCH_INFO_REG_BASE, &rst_char, 1);

	return ret;

}
static VM_DRV_TP_BOOL ctp_goodix_gt9xx_get_information(ctp_info_t *ctp_info) {
	VM_DRV_TP_BOOL ret;
	VMUINT8 cfg;

	ret = CTP_I2C_read(CTP_VERSION_INFO_REG, (VMUINT8 * )ctp_info,
			sizeof(ctp_info_t));
	ret = CTP_I2C_read(CTP_CONFIG_REG_BASE, &cfg, 1);

	return ret;
}
//If controller has the register store these informations
//Read out the informations from controller through I2C
void ctp_cypress_cy8ctma340_get_information()
{
	kal_uint8 value[4];
	kal_bool i2c_ret;

	i2c_ret = CTP_I2C_read(CID_0, value, 3);
	kal_prompt_trace(MOD_TP_TASK, "ctp_cypress_cy8ctma340_get_information i2c_ret=%d CID_0=%x CID_1=%x CID_2=%x", i2c_ret,  value[0], value[1], value[2]);
	i2c_ret = CTP_I2C_read(UID_0, value, 4);
	kal_prompt_trace(MOD_TP_TASK, "ctp_cypress_cy8ctma340_get_information i2c_ret=%d UID_0=%x UID_1=%x UID_2=%x UID_3=%x", i2c_ret,  value[0], value[1], value[2], value[3]);
	i2c_ret = CTP_I2C_read(UID_4, value, 4);
	kal_prompt_trace(MOD_TP_TASK, "ctp_cypress_cy8ctma340_get_information i2c_ret=%d UID_4=%x UID_5=%x UID_6=%x UID_7=%x", i2c_ret,  value[0], value[1], value[2], value[3]);
	i2c_ret = CTP_I2C_read(BL_VERH, value, 4);
	kal_prompt_trace(MOD_TP_TASK, "ctp_cypress_cy8ctma340_get_information i2c_ret=%d BL_VERH=%x BL_VERL=%x TTS_VERH=%x TTS_VERL=%x", i2c_ret,  value[0], value[1], value[2], value[3]);
	i2c_ret = CTP_I2C_read(APP_IDH, value, 4);
	kal_prompt_trace(MOD_TP_TASK, "ctp_cypress_cy8ctma340_get_information i2c_ret=%d APP_IDH=%x APP_IDL=%x APP_VERH=%x APP_VERL=%x", i2c_ret,  value[0], value[1], value[2], value[3]);
}
static VM_DRV_TP_BOOL ctp_goodix_gt9xx_set_device_mode(
		VM_DRV_TP_DEVICE_MODE mode) {
	VMUINT8 suspend_command = 0x05;
	VM_DCL_HANDLE eint_handle;
	ctp_info_t ctp_info;
	VMUINT8 ctp_buffer[2] = { 0 };

	if (mode == VM_DRV_TP_ACTIVE_MODE) {
		eint_handle = vm_dcl_open(VM_DCL_GPIO, gpio_ctp_eint_pin);
		vm_dcl_control(eint_handle, VM_DCL_GPIO_COMMAND_SET_MODE_0, NULL);
		vm_dcl_control(eint_handle, VM_DCL_GPIO_COMMAND_SET_DIRECTION_OUT,
				NULL);
		vm_dcl_control(eint_handle, VM_DCL_GPIO_COMMAND_WRITE_HIGH, NULL);
		delay_ms(15);
		vm_dcl_control(eint_handle, VM_DCL_GPIO_COMMAND_SET_MODE_2, NULL);
		vm_dcl_control(eint_handle, VM_DCL_GPIO_COMMAND_SET_DIRECTION_IN, NULL);
		vm_dcl_close(eint_handle);
	} else if ((mode == VM_DRV_TP_SLEEP_MODE)) {
		eint_handle = vm_dcl_open(VM_DCL_GPIO, gpio_ctp_eint_pin);
		vm_dcl_control(eint_handle, VM_DCL_GPIO_COMMAND_SET_MODE_0, NULL);
		vm_dcl_control(eint_handle, VM_DCL_GPIO_COMMAND_SET_DIRECTION_OUT,
				NULL);
		vm_dcl_control(eint_handle, VM_DCL_GPIO_COMMAND_WRITE_LOW, NULL);
		delay_ms(5);
		CTP_I2C_send(CTP_POWER_MODE_REG, &suspend_command, 1);
		CTP_I2C_read(CTP_POWER_MODE_REG, ctp_buffer, 1);
		vm_dcl_close(eint_handle);
	} else if (mode == VM_DRV_TP_FIRMWARE_UPDATE) {
		// need wdt
	}

	return VM_DRV_TP_FALSE;

}
static VM_DRV_TP_PEN_STATE ctp_goodix_gt9xx_hisr(void) {
	VMUINT8 lvalue;

	CTP_I2C_read(CTP_TOUCH_INFO_REG_BASE, &lvalue, 1);

	if (lvalue & CTP_STAT_NUMBER_TOUCH) {
		return VM_DRV_TP_DOWN;
	} else {
		return VM_DRV_TP_UP;
	}
}
kal_bool ctp_read_one_point(kal_uint32 x_base, TP_SINGLE_EVENT_T *event)
{
	kal_uint8 value[5];
	kal_bool i2c_ret;

	i2c_ret = CTP_I2C_read(x_base, value, 5);
	if(i2c_ret == KAL_FALSE)
		return KAL_FALSE;
	event->x = (value[0] << 8) | value[1];
	event->y = (value[2] << 8) | value[3];
	event->z = value[4];
	return KAL_TRUE;
}
static VM_DRV_TP_BOOL ctp_read_one_point(VMUINT32 x_base,
		vm_drv_tp_single_event_t *event) {
	VMUINT8 point_info[CTP_POINT_INFO_LEN];
	CTP_I2C_read(x_base, point_info, CTP_POINT_INFO_LEN);

	event->x = point_info[1] + (point_info[2] << 8);
	event->y = point_info[3] + (point_info[4] << 8);
	event->z = 32;
	//vm_log_info( "id:%d", point_info[0]);

	return VM_DRV_TP_TRUE;

}
Touch_Panel_PenState_enum ctp_cypress_cy8ctma340_hisr(void)
{
	kal_uint8 lvalue;
	kal_bool i2c_ret;

	
	i2c_ret = CTP_I2C_read(TT_STAT_ADDR, &lvalue, 1);
	if(i2c_ret == KAL_FALSE)
		return UP;
		

	if(lvalue & TT_STAT_NUMBER_TOUCH)
		return DOWN;
	else
		return UP;
}
kal_bool ctp_cypress_cy8ctma340_get_data(TouchPanelMultipleEventStruct *tpes)
{
	kal_bool i2c_ret;
	kal_uint8 reg[2];
	kal_uint32 model = 0;

	ASSERT(tpes);
		
	tpes->time_stamp = (kal_uint16)L1I_GetTimeStamp();
	tpes->padding = CTP_PATTERN;
	
	i2c_ret = CTP_I2C_read(TT_MODE_ADDR, reg, 2);
	if(i2c_ret == KAL_FALSE)
	{
		ctp_cypress_cy8ctma340_toggle();
		return KAL_FALSE;
	}	
	if(reg[0] & TT_MODE_BUFFER_INVALID)
	{
		drv_trace0(TRACE_GROUP_10, CTP_CAPACITIVE_GET_DATA_INVALID);
		ctp_cypress_cy8ctma340_toggle();
		return KAL_FALSE;
	}

	model = (kal_uint32)(reg[1] & TT_STAT_NUMBER_TOUCH);
		
	drv_trace1(TRACE_GROUP_10, CTP_CAPACITIVE_MODEL, model);
	if(model > 4) //cypress only support 4 fingers
	{
		ctp_cypress_cy8ctma340_toggle();
		return KAL_FALSE;
	}

	tpes->model = (kal_uint16)model;  //read out all touch points coordinates.
	if(model == 0)
	{
		ctp_cypress_cy8ctma340_toggle();
		return KAL_FALSE;
	}

	ctp_read_all_point(tpes, model);
	ctp_cypress_cy8ctma340_toggle();
	return KAL_TRUE;
}
Esempio n. 10
0
static VMUINT32 ctp_goodix_gt9xx_command(VMUINT32 cmd, void* p1, void* p2) // p1: input p2: output
{
#define TPD_SYNC_REG                  0x711
#define TPD_DIFF_DATA_REG             0xD80
#define TPD_CHANNEL_CONFIG_REG        0x6D5
#define TPD_RAW_DATA_1_REG            0x880
#define TPD_RAW_DATA_2_REG            0x9C0

#define MAX_DRIVING_CHANNEL 16
#define MAX_SENSING_CHANNLE 10
#define MAX_DIFF_DATA_SIZE   (MAX_DRIVING_CHANNEL*MAX_SENSING_CHANNLE*2)
#define MAX_RAW_DATA_SIZE    MAX_DIFF_DATA_SIZE

	char **dst = (char **) p2;
	ctp_info_t ctp_info;
	VM_DRV_TP_BOOL ret = VM_DRV_TP_TRUE;
	VMUINT8 *cfg = (VMUINT8 *) p1;
	VMUINT8 mode;
	VMUINT8 *tpd_raw_data;
	VMUINT8 tmp[MAX_DIFF_DATA_SIZE];
	VMUINT8 *ptr;
	VMUINT8 row;
	VMUINT8 illegal = 0;

	if (dst != NULL)
		*dst = NULL;

	switch (cmd) {
	case VM_DRV_TP_COMMAND_GET_VERSION: // get firmware version
		if (ctp_goodix_gt9xx_get_information(&ctp_info)) {
			memcpy(tpd_raw_data, (VMUINT8 *) &ctp_info, sizeof(ctp_info_t));
			*dst = (char *) tpd_raw_data;
		} else {
			ret = VM_DRV_TP_FALSE;
		}
		break;

	case VM_DRV_TP_COMMAND_GET_CONFIG:
		if (CTP_I2C_read(CTP_CONFIG_REG_BASE, tpd_raw_data,
				VM_DRV_TP_CONFIG_LENGTH)) {
			*dst = (char *) tpd_raw_data;
		} else {
			ret = VM_DRV_TP_FALSE;
		}
		break;

	case VM_DRV_TP_COMMAND_LOAD_INT_CONFIG:
		ctp_goodix_gt9xx_set_configuration();
		break;

	case VM_DRV_TP_COMMAND_LOAD_EXT_CONFIG:
		cfg[105] = 1;
		CTP_I2C_send(CTP_CONFIG_REG_BASE, cfg, VM_DRV_TP_CONFIG_LENGTH);
		break;

	case VM_DRV_TP_COMMAND_GET_DIFF_DATA:
		break;

	case VM_DRV_TP_COMMAND_GET_FW_BUFFER:
		break;

	case VM_DRV_TP_COMMAND_DO_FW_UPDATE:
		break;
	case 8:
		CTP_I2C_read(CTP_TOUCH_INFO_REG_BASE, &illegal, 1);
		if ((illegal & 0x80) == 0)
			ret = 1;
		else
			ret = 0;
		break;
	default:
		ret = VM_DRV_TP_FALSE;
	}

	return ret;

}