Microchip® Advanced Software Framework

mxt_device_1.c File Reference

maXTouch component.

Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.

#include <twihs_master.h>
#include <ioport.h>
#include "mxt_device_1.h"

Macros

#define MXT_FAMILY_143E   0x81
 
#define MXT_ID_BLOCK_SIZE   7
 
#define MXT_MEM_ADDR   0x00
 
#define MXT_VARIANT_143E   0x07
 
#define OBJECT_TABLE_ELEMENT_SIZE   6
 
#define OBJECT_TABLE_START_ADDRESS   7
 

Functions

static status_code_t mxt_calculate_infoblock_crc (struct mxt_device *device, uint32_t *crc)
 Calculates the crc checksum of the data in the info block. More...
 
status_code_t mxt_close_device (struct mxt_device *device)
 Closes the twi connection and frees memory. More...
 
static uint32_t mxt_crc_24 (uint32_t crc, uint8_t byte1, uint8_t byte2)
 Calculates the next crc value of current crc value and the following two bytes. More...
 
static uint8_t mxt_crc_8 (uint8_t crc, uint8_t data)
 Calculates the next crc value of current crc value and the following byte. More...
 
static status_code_t mxt_create_report_id_map (struct mxt_device *device)
 Create report ID map from the object list in mxt_device. More...
 
static uint32_t mxt_get_crc_value (struct mxt_device *device)
 Reads out the crc value stored in the mxt-device. More...
 
int8_t mxt_get_message_count (struct mxt_device *device)
 Get pending message count. More...
 
uint16_t mxt_get_object_address (struct mxt_device *device, uint8_t object_id, uint8_t instance)
 Get memory address to object. More...
 
static uint8_t mxt_get_object_size (struct mxt_device *device, mxt_memory_adr mem_adr)
 Returns the object size by using the object address. More...
 
enum mxt_object_type mxt_get_object_type (struct mxt_device *device, struct mxt_conf_messageprocessor_t5 *message)
 Get object type from message. More...
 
static int8_t mxt_get_report_id_offset (struct mxt_device *device, enum mxt_object_type object_type)
 Returns the report id offset for a object. More...
 
static uint8_t mxt_get_tot_report_ids (struct mxt_device *device)
 Total number of report ids available in the maXTouch device. More...
 
static void mxt_info_le_to_cpu (struct mxt_device *device)
 Do any potential endian conversions in info block. More...
 
status_code_t mxt_init_device (struct mxt_device *device, twihs_master_t interface, uint8_t chip_adr, uint32_t chgpin)
 Initialize maXTouch device connected to TWIx module. More...
 
bool mxt_is_message_pending (struct mxt_device *device)
 Report if there is any pending messages in the queue. More...
 
status_code_t mxt_probe_device (twihs_master_t interface, uint8_t chip_adr)
 Probe for a maXTouch connected to a specific TWI line. More...
 
status_code_t mxt_process_messages (struct mxt_device *device)
 Process message queue on maXTouch device. More...
 
status_code_t mxt_read_config_object (struct mxt_device *device, mxt_memory_adr memory_adr, void *obj_data)
 Read object configuration. More...
 
status_code_t mxt_read_config_reg (struct mxt_device *device, mxt_memory_adr memory_adr, uint8_t *value)
 Read object register. More...
 
static status_code_t mxt_read_id_block (struct mxt_device *device)
 Read out the id information from the maXTouch device and put it into the info_object struct in the device instance. More...
 
static status_code_t mxt_read_info_block (struct mxt_device *device)
 Read info block from device. More...
 
status_code_t mxt_read_message (struct mxt_device *device, struct mxt_conf_messageprocessor_t5 *message)
 Get next message in queue. More...
 
static status_code_t mxt_read_object_table (struct mxt_device *device)
 Read out the object table from the maXTouch device and put it into the object_list structs in the device instance. More...
 
status_code_t mxt_read_touch_event (struct mxt_device *device, struct mxt_touch_event *touch_event)
 Read next touch event in queue, skip other events (other events are lost) More...
 
void mxt_set_message_handler (struct mxt_device *device, mxt_message_handler_t handler)
 Set message handler. More...
 
static status_code_t mxt_validate_info_block (struct mxt_device *device)
 Validates the info block by comparing the calculated Compares the calculated and stored crc value. More...
 
static status_code_t mxt_validate_message (twihs_package_t *packet)
 Validates the message received from the maXTouch device. More...
 
status_code_t mxt_write_config_object (struct mxt_device *device, mxt_memory_adr memory_adr, void *obj_data)
 Write object configuration. More...
 
status_code_t mxt_write_config_reg (struct mxt_device *device, mxt_memory_adr memory_adr, uint8_t value)
 Write object register. More...
 

#define MXT_FAMILY_143E   0x81

Referenced by mxt_probe_device().

#define MXT_ID_BLOCK_SIZE   7
#define MXT_MEM_ADDR   0x00
#define MXT_VARIANT_143E   0x07

Referenced by mxt_probe_device().

#define OBJECT_TABLE_ELEMENT_SIZE   6
#define OBJECT_TABLE_START_ADDRESS   7

Referenced by mxt_read_object_table().

static status_code_t mxt_calculate_infoblock_crc ( struct mxt_device device,
uint32_t *  crc 
)
static

Calculates the crc checksum of the data in the info block.

Parameters
*devicePointer to mxt_device instance
*crcPointer to the crc variable
Returns
Operation result status code

References mxt_device::info_object, mxt_crc_24(), MXT_ID_BLOCK_SIZE, mxt_info_object::obj_count, mxt_device::object_list, OBJECT_TABLE_ELEMENT_SIZE, and STATUS_OK.

Referenced by mxt_validate_info_block().

static uint32_t mxt_crc_24 ( uint32_t  crc,
uint8_t  byte1,
uint8_t  byte2 
)
inlinestatic

Calculates the next crc value of current crc value and the following two bytes.

Parameters
crc
byte1
byte2
Returns
crc

Referenced by mxt_calculate_infoblock_crc().

static uint8_t mxt_crc_8 ( uint8_t  crc,
uint8_t  data 
)
inlinestatic

Calculates the next crc value of current crc value and the following byte.

Parameters
crc
data
Returns
crc

Referenced by mxt_validate_message().

static status_code_t mxt_create_report_id_map ( struct mxt_device device)
static
static uint32_t mxt_get_crc_value ( struct mxt_device device)
static

Reads out the crc value stored in the mxt-device.

Parameters
*devicePointer to mxt_device instance
Returns
crc_value 24-bit value representing the crc.

References twihs_packet::addr, ERR_IO_ERROR, mxt_device::info_object, mxt_device::interface, mxt_device::mxt_chip_adr, MXT_ID_BLOCK_SIZE, mxt_info_object::obj_count, OBJECT_TABLE_ELEMENT_SIZE, STATUS_OK, and twihs_master_read().

Referenced by mxt_validate_info_block().

static uint8_t mxt_get_object_size ( struct mxt_device device,
mxt_memory_adr  mem_adr 
)
static

Returns the object size by using the object address.

Parameters
*devicePointer to mxt_device instance
mem_adrAddress of the object
Returns
uint8_t Size of the object

References mxt_device::info_object, mxt_info_object::obj_count, mxt_device::object_list, mxt_object::size, and mxt_object::start_address.

Referenced by mxt_read_config_object(), and mxt_write_config_object().

static int8_t mxt_get_report_id_offset ( struct mxt_device device,
enum mxt_object_type  object_type 
)
static

Returns the report id offset for a object.

Parameters
*devicePointer to mxt_device instance
object_typeID of the object
Returns
int8_t Report ID offset

References mxt_get_tot_report_ids(), mxt_report_id_map::object_type, and mxt_device::report_id_map.

Referenced by mxt_init_device().

static uint8_t mxt_get_tot_report_ids ( struct mxt_device device)
static

Total number of report ids available in the maXTouch device.

Parameters
*devicePointer to mxt_device instance
Returns
Total number of report ids

References mxt_device::info_object, mxt_object::num_report_ids, mxt_info_object::obj_count, and mxt_device::object_list.

Referenced by mxt_create_report_id_map(), and mxt_get_report_id_offset().

static void mxt_info_le_to_cpu ( struct mxt_device device)
static

Do any potential endian conversions in info block.

Parameters
*devicePointer to mxt_device instance

References mxt_device::info_object, le16_to_cpu, mxt_info_object::obj_count, mxt_device::object_list, and mxt_object::start_address.

Referenced by mxt_init_device().

static status_code_t mxt_read_id_block ( struct mxt_device device)
static

Read out the id information from the maXTouch device and put it into the info_object struct in the device instance.

Parameters
*devicePointer to mxt_device instance
Returns
Operation result status code

References twihs_packet::addr, ERR_IO_ERROR, mxt_device::info_object, mxt_device::interface, mxt_device::mxt_chip_adr, MXT_ID_BLOCK_SIZE, MXT_MEM_ADDR, STATUS_OK, and twihs_master_read().

Referenced by mxt_read_info_block().

static status_code_t mxt_read_info_block ( struct mxt_device device)
inlinestatic

Read info block from device.

Parameters
*devicePointer to mxt_device instance
Returns
Operation result status code

References mxt_read_id_block(), mxt_read_object_table(), and STATUS_OK.

Referenced by mxt_init_device().

static status_code_t mxt_read_object_table ( struct mxt_device device)
static

Read out the object table from the maXTouch device and put it into the object_list structs in the device instance.

Parameters
*devicePointer to mxt_device instance
Returns
Operation result status code

References twihs_packet::addr, ERR_IO_ERROR, mxt_device::info_object, mxt_device::interface, mxt_device::mxt_chip_adr, mxt_info_object::obj_count, mxt_device::object_list, OBJECT_TABLE_START_ADDRESS, STATUS_OK, and twihs_master_read().

Referenced by mxt_read_info_block().

static status_code_t mxt_validate_info_block ( struct mxt_device device)
static

Validates the info block by comparing the calculated Compares the calculated and stored crc value.

Parameters
*devicePointer to mxt_device instance
Returns
Operation result status code.

References ERR_BAD_DATA, mxt_calculate_infoblock_crc(), mxt_get_crc_value(), and STATUS_OK.

Referenced by mxt_init_device().

static status_code_t mxt_validate_message ( twihs_package_t packet)
inlinestatic

Validates the message received from the maXTouch device.

Parameters
packetMessage received from the maXTouch device
Returns
Operation result status code.

References twihs_packet::buffer, ERR_BAD_DATA, mxt_crc_8(), MXT_TWI_MSG_SIZE_T5, and STATUS_OK.

Referenced by mxt_read_message().