Exemplo n.º 1
0
//******************************************************************************
/// \brief Read information block
/// \return #mxt_rc
int mxt_get_info(struct mxt_device *mxt)
{
  int ret;

  ret = mxt_read_info_block(mxt);
  if (ret)
    return ret;

  ret = mxt_calc_report_ids(mxt);
  if (ret) {
    mxt_err(mxt->ctx, "Failed to generate report ID look-up table");
    return ret;
  }

  mxt_display_chip_info(mxt);

  return MXT_SUCCESS;
}
Exemplo n.º 2
0
/**
 * \brief Probe for a maXTouch connected to a specific TWI line
 *
 * \param interface Pointer to TWI register set
 * \param *chip_adr I2C address to maXTouch device
 * \return Operation result status code
 */
status_code_t mxt_probe_device(twi_master_t interface, uint8_t chip_adr)
{
	struct mxt_info_object info;
	uint8_t status;

	/* Initializing the TWI packet to send to the slave */
	twi_package_t packet = {
		.addr[0]      = MXT_MEM_ADDR,
		.addr[1]      = MXT_MEM_ADDR >> 8,
		.addr_length  = sizeof(mxt_memory_adr),
		.chip         = chip_adr,
		.buffer       = &info,
		.length       = sizeof(info)
	};

	/* Read information from the slave */
	status = twi_master_read(interface, &packet);
	if (status != TWI_SUCCESS) {
		return (status_code_t)status;
	}

	if ((info.family_ID != MXT_FAMILY_143E)
			|| (info.variant_ID != MXT_VARIANT_143E)) {
		return ERR_BAD_ADDRESS;
	}

	return STATUS_OK;
}

/**
 * \brief Initialize maXTouch device connected to TWIx module
 *
 * \param *interface Pointer to TWI register set
 * \param *device Pointer to mxt_device instance
 * \param chip_adr I2C address to maXTouch device
 * \param chgpin IOPORT pin instance attached to the maXTouch device's /CHG pin
 * \return Operation result status code
 */
status_code_t mxt_init_device(struct mxt_device *device,
		twi_master_t interface, uint8_t chip_adr, uint32_t chgpin)
{
	int8_t status;

	/* Set TWI interface, TWI address and CHG-pin of the maXTouch device. */
	device->interface = interface;
	device->mxt_chip_adr = chip_adr;
	device->chgpin = chgpin;
	device->handler = NULL;

	/* Read the info block from the chip into the mxt_device struct */
	status = mxt_read_info_block(device);

	if (status != STATUS_OK) {
		return (status_code_t)status;
	}

	/* Validate the data read from the info block */
	status = mxt_validate_info_block(device);
	if (status != STATUS_OK) {
		return (status_code_t)status;
	}

	/* Fix possible endian issues between protocol and cpu */
	mxt_info_le_to_cpu(device);

	/* Create map of the report ID's and put it into mxt_device struct */
	status = mxt_create_report_id_map(device);
	if (status != STATUS_OK) {
		return (status_code_t)status;
	}

	/* Get the report id offset of the multi touch object*/
	status = mxt_get_report_id_offset(device,
			MXT_TOUCH_MULTITOUCHSCREEN_T9);
	if (status == -1) {
		return ERR_BAD_DATA;
	}

	device->multitouch_report_offset = status;

	return STATUS_OK;
}