### Sysfs and Debugfs Interface for ft5x06 Touchscreen Firmware Management (Shell) Source: https://context7.com/mycroft-dev/touchscreen-controller/llms.txt Provides user-space interfaces via sysfs and debugfs for managing the ft5x06 touchscreen firmware and debugging the driver. Allows setting firmware filenames, triggering updates, and accessing debug information. Requires appropriate permissions to write to sysfs and debugfs entries. ```shell /* Sysfs attributes for firmware management */ /* /sys/bus/i2c/devices/3-0038/fw_name - Set firmware filename */ echo "new_fw.bin" > /sys/bus/i2c/devices/3-0038/fw_name /* /sys/bus/i2c/devices/3-0038/update_fw - Trigger firmware update */ echo 1 > /sys/bus/i2c/devices/3-0038/update_fw /* /sys/bus/i2c/devices/3-0038/force_update_fw - Force update regardless of version */ echo 1 > /sys/bus/i2c/devices/3-0038/force_update_fw /* Debugfs interface at /sys/kernel/debug/ts_debug/ */ /* addr - Set register address for read/write */ echo 0xa6 > /sys/kernel/debug/ts_debug/addr /* data - Read/write register value */ cat /sys/kernel/debug/ts_debug/data /* Returns: 0x10 */ /* suspend - Force suspend/resume for testing */ echo 1 > /sys/kernel/debug/ts_debug/suspend /* Force suspend */ echo 0 > /sys/kernel/debug/ts_debug/suspend /* Force resume */ /* dump_info - Display driver and firmware information */ cat /sys/kernel/debug/ts_debug/dump_info /* Output: controller = focaltech model = 0x06 name = ft5x06 max_touches = 5 drv_ver = 0x02 fw_ver = 1.0.0 */ ``` -------------------------------- ### Parse Device Tree Bindings for ft5x06 Touchscreen (C) Source: https://context7.com/mycroft-dev/touchscreen-controller/llms.txt Parses device tree bindings to configure the ft5x06 touchscreen controller. It defines platform data structures populated from the device tree, specifying parameters like firmware name, GPIO pins, screen coordinates, and touch capabilities. Dependencies include kernel headers for device tree and platform data structures. ```c /* Example Device Tree binding */ /* &i2c_3 { focaltech@38 { compatible = "focaltech,5x06"; reg = <0x38>; interrupt-parent = <&msmgpio>; interrupts = <13 0x2008>; vdd-supply = <&pm8226_l19>; vcc_i2c-supply = <&pm8226_lvs1>; focaltech,name = "ft5x06"; focaltech,family-id = <0x06>; focaltech,reset-gpio = <&msmgpio 16 0x00>; focaltech,irq-gpio = <&msmgpio 13 0x2008>; focaltech,display-coords = <0 0 480 800>; focaltech,panel-coords = <0 0 480 800>; focaltech,num-max-touches = <5>; focaltech,hard-reset-delay-ms = <20>; focaltech,soft-reset-delay-ms = <200>; focaltech,fw-name = "ft_fw.bin"; focaltech,fw-delay-aa-ms = <30>; focaltech,fw-delay-55-ms = <30>; focaltech,fw-upgrade-id1 = <0x79>; focaltech,fw-upgrade-id2 = <0x08>; focaltech,fw-delay-readid-ms = <10>; focaltech,fw-delay-era-flsh-ms = <2000>; focaltech,fw-auto-cal; focaltech,i2c-pull-up; }; }; */ /* Platform data structure populated from DT */ struct ft5x06_ts_platform_data { const char *name; /* "ft5x06" */ const char *fw_name; /* "ft_fw.bin" */ u32 family_id; /* 0x06 for FT6x06 */ u32 irq_gpio; /* GPIO 13 */ u32 reset_gpio; /* GPIO 16 */ u32 x_min, y_min; /* 0, 0 */ u32 x_max, y_max; /* 480, 800 */ u32 num_max_touches; /* 5 */ u32 hard_rst_dly; /* 20ms */ u32 soft_rst_dly; /* 200ms */ struct fw_upgrade_info info; /* Firmware upgrade parameters */ }; ``` -------------------------------- ### Firmware Upgrade Functions Source: https://context7.com/mycroft-dev/touchscreen-controller/llms.txt Provides functions for upgrading the firmware of the touchscreen controller. ```APIDOC ## Firmware Upgrade Functions ### Description Functions for upgrading the firmware of the touchscreen controller. ### Method Not Applicable (C functions) ### Endpoint Not Applicable (C functions) ### Parameters None ### Request Example ```c // Firmware upgrade functions are not detailed in the provided text. // This section would typically include functions for: // - Initiating firmware update mode // - Sending firmware data chunks // - Verifying firmware integrity // - Committing the new firmware ``` ### Response None (modifies system state) ``` -------------------------------- ### Manage Power State Transitions Source: https://context7.com/mycroft-dev/touchscreen-controller/llms.txt Handles system suspend and resume operations for the touchscreen. Suspend disables interrupts, clears touch events, and enters hibernate mode, while resume restores power, resets the hardware, and re-enables interrupts. ```c /* Suspend handler */ static int ft5x06_ts_suspend(struct device *dev) { struct ft5x06_ts_data *data = dev_get_drvdata(dev); char txbuf[2]; int i; if (data->loading_fw || data->suspended) return 0; disable_irq(data->client->irq); /* Release all active touches */ for (i = 0; i < data->pdata->num_max_touches; i++) { input_mt_slot(data->input_dev, i); input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, 0); } input_mt_report_pointer_emulation(data->input_dev, false); input_sync(data->input_dev); /* Put controller in hibernate mode */ txbuf[0] = FT_REG_PMODE; txbuf[1] = FT_PMODE_HIBERNATE; ft5x06_i2c_write(data->client, txbuf, sizeof(txbuf)); /* Power off regulators */ ft5x06_power_on(data, false); /* Set pins to suspend state */ pinctrl_select_state(data->ts_pinctrl, data->pinctrl_state_suspend); data->suspended = true; return 0; } /* Resume handler */ static int ft5x06_ts_resume(struct device *dev) { struct ft5x06_ts_data *data = dev_get_drvdata(dev); if (!data->suspended) return 0; /* Power on and configure pins */ ft5x06_power_on(data, true); pinctrl_select_state(data->ts_pinctrl, data->pinctrl_state_active); /* Hardware reset sequence */ gpio_set_value_cansleep(data->pdata->reset_gpio, 0); msleep(data->pdata->hard_rst_dly); gpio_set_value_cansleep(data->pdata->reset_gpio, 1); msleep(data->pdata->soft_rst_dly); enable_irq(data->client->irq); data->suspended = false; return 0; } ``` -------------------------------- ### Read Data via I2C for FocalTech Controllers Source: https://context7.com/mycroft-dev/touchscreen-controller/llms.txt Demonstrates reading firmware versions and touch data buffers from the controller using the ft5x06_i2c_read function. It handles register addressing and buffer management for multi-touch event data. ```c struct i2c_client *client; u8 reg_addr = FT_REG_FW_VER; /* Register 0xA6 */ u8 fw_version; int ret; ret = ft5x06_i2c_read(client, ®_addr, 1, &fw_version, 1); if (ret < 0) { dev_err(&client->dev, "Failed to read firmware version\n"); } else { dev_info(&client->dev, "Firmware version: 0x%02x\n", fw_version); } #define POINT_READ_BUF 63 u8 touch_buf[POINT_READ_BUF] = {0}; u8 read_cmd = 0; ret = ft5x06_i2c_read(client, &read_cmd, 1, touch_buf, POINT_READ_BUF); if (ret < 0) { dev_err(&client->dev, "Failed to read touch data\n"); } ``` -------------------------------- ### Upgrade Controller Firmware via I2C Source: https://context7.com/mycroft-dev/touchscreen-controller/llms.txt Performs a multi-step firmware upgrade process for FT5x06 series controllers. The sequence includes resetting to bootloader mode, erasing flash, writing binary data in 128-byte packets with ECC verification, and resetting to normal operation. ```c /* Firmware upgrade sequence for FT5x06 series */ struct i2c_client *client; u8 *pbt_buf; /* Firmware binary data */ u32 dw_lenth; /* Firmware length */ u8 reg_val[2], auc_i2c_write_buf[10], packet_buf[FT_FW_PKT_LEN + 6]; u8 bt_ecc = 0; int i, j; /* Step 1: Reset to bootloader mode */ ft5x0x_write_reg(client, 0xfc, FT_UPGRADE_AA); /* 0xAA */ msleep(50); ft5x0x_write_reg(client, 0xfc, FT_UPGRADE_55); /* 0x55 */ msleep(30); /* Step 2: Enter upgrade mode */ auc_i2c_write_buf[0] = FT_UPGRADE_55; auc_i2c_write_buf[1] = FT_UPGRADE_AA; ft5x06_i2c_write(client, auc_i2c_write_buf, 2); msleep(10); /* Step 3: Verify bootloader ID */ auc_i2c_write_buf[0] = 0x90; auc_i2c_write_buf[1] = auc_i2c_write_buf[2] = auc_i2c_write_buf[3] = 0x00; ft5x06_i2c_read(client, auc_i2c_write_buf, 4, reg_val, 2); if (reg_val[0] != 0x79 || reg_val[1] != expected_id) { dev_err(&client->dev, "Bootloader ID mismatch\n"); return -EIO; } /* Step 4: Erase flash */ auc_i2c_write_buf[0] = 0x61; ft5x06_i2c_write(client, auc_i2c_write_buf, 1); msleep(2000); /* Step 5: Write firmware in 128-byte packets */ u32 packet_number = dw_lenth / FT_FW_PKT_LEN; packet_buf[0] = 0xbf; packet_buf[1] = 0x00; for (j = 0; j < packet_number; j++) { u32 temp = j * FT_FW_PKT_LEN; packet_buf[2] = (u8)(temp >> 8); packet_buf[3] = (u8)temp; packet_buf[4] = (u8)(FT_FW_PKT_LEN >> 8); packet_buf[5] = (u8)FT_FW_PKT_LEN; for (i = 0; i < FT_FW_PKT_LEN; i++) { packet_buf[6 + i] = pbt_buf[j * FT_FW_PKT_LEN + i]; bt_ecc ^= packet_buf[6 + i]; } ft5x06_i2c_write(client, packet_buf, FT_FW_PKT_LEN + 6); msleep(22); } /* Step 6: Verify checksum */ auc_i2c_write_buf[0] = 0xcc; ft5x06_i2c_read(client, auc_i2c_write_buf, 1, reg_val, 1); if (reg_val[0] != bt_ecc) { dev_err(&client->dev, "Checksum error: 0x%02x != 0x%02x\n", reg_val[0], bt_ecc); return -EIO; } /* Step 7: Reset to normal mode */ auc_i2c_write_buf[0] = 0x07; ft5x06_i2c_write(client, auc_i2c_write_buf, 1); msleep(300); ``` -------------------------------- ### Report Touch Events (C) Source: https://context7.com/mycroft-dev/touchscreen-controller/llms.txt Reports processed touch events to the Linux input subsystem using the MT Protocol B. It handles touch down, contact, and lift events, reporting coordinates and touch major information for each finger. This enables the system to receive and process touch input. ```c /* Report multi-touch events to input subsystem */ struct ft5x06_ts_data *data; struct ts_event *event = &data->event; int i, uppoint = 0; for (i = 0; i < event->touch_point; i++) { /* Select MT slot for this finger */ input_mt_slot(data->input_dev, event->au8_finger_id[i]); if (event->au8_touch_event[i] == FT_TOUCH_DOWN || /* 0 = down */ event->au8_touch_event[i] == FT_TOUCH_CONTACT) { /* 2 = contact */ /* Report finger present */ input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, true); input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, event->pressure); input_report_abs(data->input_dev, ABS_MT_POSITION_X, event->au16_x[i]); input_report_abs(data->input_dev, ABS_MT_POSITION_Y, event->au16_y[i]); } else { /* Finger lifted */ uppoint++; input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, false); } } /* Report BTN_TOUCH state and sync */ input_report_key(data->input_dev, BTN_TOUCH, event->touch_point > uppoint); input_sync(data->input_dev); ``` -------------------------------- ### Report Touch Events Source: https://context7.com/mycroft-dev/touchscreen-controller/llms.txt Reports touch events to the Linux input subsystem using MT Protocol B. ```APIDOC ## fts_report_value ### Description Reports touch events to the Linux input subsystem using MT Protocol B. ### Method Not Applicable (C function) ### Endpoint Not Applicable (C function) ### Parameters None ### Request Example ```c /* Report multi-touch events to input subsystem */ struct ft5x06_ts_data *data; struct ts_event *event = &data->event; int i, uppoint = 0; for (i = 0; i < event->touch_point; i++) { /* Select MT slot for this finger */ input_mt_slot(data->input_dev, event->au8_finger_id[i]); if (event->au8_touch_event[i] == FT_TOUCH_DOWN || /* 0 = down */ event->au8_touch_event[i] == FT_TOUCH_CONTACT) { /* 2 = contact */ /* Report finger present */ input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, true); input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, event->pressure); input_report_abs(data->input_dev, ABS_MT_POSITION_X, event->au16_x[i]); input_report_abs(data->input_dev, ABS_MT_POSITION_Y, event->au16_y[i]); } else { /* Finger lifted */ uppoint++; input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, false); } } /* Report BTN_TOUCH state and sync */ input_report_key(data->input_dev, BTN_TOUCH, event->touch_point > uppoint); input_sync(data->input_dev); ``` ### Response None (modifies system state) ``` -------------------------------- ### Write Data via I2C for FocalTech Controllers Source: https://context7.com/mycroft-dev/touchscreen-controller/llms.txt Demonstrates writing configuration data and firmware packets to the controller using the ft5x06_i2c_write function. This is essential for power management and firmware update procedures. ```c struct i2c_client *client; char txbuf[2]; int ret; txbuf[0] = FT_REG_PMODE; /* Register address 0xA5 */ txbuf[1] = FT_PMODE_HIBERNATE; /* Hibernate mode 0x03 */ ret = ft5x06_i2c_write(client, txbuf, sizeof(txbuf)); if (ret < 0) { dev_err(&client->dev, "Failed to set hibernate mode\n"); } u8 packet_buf[FT_FW_PKT_LEN + 6]; packet_buf[0] = 0xbf; /* Write firmware command */ packet_buf[1] = 0x00; packet_buf[2] = (u8)(addr >> 8); packet_buf[3] = (u8)addr; packet_buf[4] = (u8)(len >> 8); packet_buf[5] = (u8)len; memcpy(&packet_buf[6], fw_data, len); ret = ft5x06_i2c_write(client, packet_buf, len + 6); ``` -------------------------------- ### Read Touch Data (C) Source: https://context7.com/mycroft-dev/touchscreen-controller/llms.txt Reads and parses raw touch event data from the controller. It populates a ts_event structure with coordinates, event types, and finger IDs for up to 10 touch points. This function is crucial for capturing user input from the touchscreen. ```c /* Touch event structure */ struct ts_event { u16 au16_x[TPD_MAX_POINTS_10]; /* X coordinates */ u16 au16_y[TPD_MAX_POINTS_10]; /* Y coordinates */ u8 au8_touch_event[TPD_MAX_POINTS_10]; /* 0=down, 1=up, 2=contact */ u8 au8_finger_id[TPD_MAX_POINTS_10]; /* Finger tracking ID */ u16 pressure; u8 touch_point; /* Number of active touches */ u8 point_num; }; /* Reading touch data in interrupt handler */ struct ft5x06_ts_data *data; struct ts_event *event = &data->event; u8 buf[POINT_READ_BUF] = {0}; int i; ret = ft5x06_i2c_read(data->client, buf, 1, buf, POINT_READ_BUF); if (ret < 0) return ret; memset(event, 0, sizeof(struct ts_event)); event->touch_point = 0; /* Parse each touch point (up to 10) */ for (i = 0; i < CFG_MAX_TOUCH_POINTS; i++) { u8 pointid = (buf[FT_TOUCH_ID_POS + FT_ONE_TCH_LEN * i]) >> 4; if (pointid >= FT_MAX_ID) break; event->touch_point++; event->au16_x[i] = (buf[FT_TOUCH_X_H_POS + FT_ONE_TCH_LEN * i] & 0x0F) << 8 | buf[FT_TOUCH_X_L_POS + FT_ONE_TCH_LEN * i]; event->au16_y[i] = (buf[FT_TOUCH_Y_H_POS + FT_ONE_TCH_LEN * i] & 0x0F) << 8 | buf[FT_TOUCH_Y_L_POS + FT_ONE_TCH_LEN * i]; event->au8_touch_event[i] = buf[FT_TOUCH_EVENT_POS + FT_ONE_TCH_LEN * i] >> 6; event->au8_finger_id[i] = pointid; } event->pressure = FT_PRESS; /* 0x7F */ ``` -------------------------------- ### Check and Report Gestures (C) Source: https://context7.com/mycroft-dev/touchscreen-controller/llms.txt Detects and reports various gesture events, including directional swipes and double-taps, by mapping them to specific key events in the input subsystem. It reads gesture data from the controller and enables gesture mode for future events. ```c /* Supported gesture codes */ #define GESTURE_LEFT 0x20 #define GESTURE_RIGHT 0x21 #define GESTURE_UP 0x22 #define GESTURE_DOWN 0x23 #define GESTURE_DOUBLECLICK 0x24 #define GESTURE_O 0x30 #define GESTURE_W 0x31 #define GESTURE_M 0x32 #define GESTURE_E 0x33 #define GESTURE_L 0x44 #define GESTURE_S 0x46 #define GESTURE_V 0x54 #define GESTURE_Z 0x41 /* Read gesture data from controller */ u8 buf[FTS_GESTRUE_POINTS * 3] = {0}; int gesture_id, pointnum; buf[0] = 0xd3; /* Gesture output address */ ft5x06_i2c_read(client, buf, 1, buf, FTS_GESTRUE_POINTS_HEADER); gesture_id = buf[0]; pointnum = (short)(buf[1]) & 0xff; /* Report gesture as key event */ switch (gesture_id) { case GESTURE_LEFT: input_report_key(input_dev, KEY_LEFT, 1); input_sync(input_dev); input_report_key(input_dev, KEY_LEFT, 0); input_sync(input_dev); break; case GESTURE_DOUBLECLICK: input_report_key(input_dev, KEY_U, 1); input_sync(input_dev); input_report_key(input_dev, KEY_U, 0); input_sync(input_dev); break; /* Handle other gestures similarly */ } /* Enable gesture mode before suspend */ ft5x0x_write_reg(client, 0xd0, 0x01); ft5x0x_write_reg(client, 0xd1, 0xff); /* Enable all gestures */ ``` -------------------------------- ### Gesture Recognition API Source: https://context7.com/mycroft-dev/touchscreen-controller/llms.txt Detects and reports gesture events, including directional swipes, double-tap, and letter-shaped gestures. ```APIDOC ## check_gesture / fts_read_Gestruedata ### Description Detect and report gesture events. Supports directional swipes, double-tap, and letter-shaped gestures. ### Method Not Applicable (C function) ### Endpoint Not Applicable (C function) ### Parameters None ### Request Example ```c /* Supported gesture codes */ #define GESTURE_LEFT 0x20 #define GESTURE_RIGHT 0x21 #define GESTURE_UP 0x22 #define GESTURE_DOWN 0x23 #define GESTURE_DOUBLECLICK 0x24 #define GESTURE_O 0x30 #define GESTURE_W 0x31 #define GESTURE_M 0x32 #define GESTURE_E 0x33 #define GESTURE_L 0x44 #define GESTURE_S 0x46 #define GESTURE_V 0x54 #define GESTURE_Z 0x41 /* Read gesture data from controller */ u8 buf[FTS_GESTRUE_POINTS * 3] = {0}; int gesture_id, pointnum; buf[0] = 0xd3; /* Gesture output address */ ft5x06_i2c_read(client, buf, 1, buf, FTS_GESTRUE_POINTS_HEADER); gesture_id = buf[0]; pointnum = (short)(buf[1]) & 0xff; /* Report gesture as key event */ switch (gesture_id) { case GESTURE_LEFT: input_report_key(input_dev, KEY_LEFT, 1); input_sync(input_dev); input_report_key(input_dev, KEY_LEFT, 0); input_sync(input_dev); break; case GESTURE_DOUBLECLICK: input_report_key(input_dev, KEY_U, 1); input_sync(input_dev); input_report_key(input_dev, KEY_U, 0); input_sync(input_dev); break; /* Handle other gestures similarly */ } /* Enable gesture mode before suspend */ ft5x0x_write_reg(client, 0xd0, 0x01); ft5x0x_write_reg(client, 0xd1, 0xff); /* Enable all gestures */ ``` ### Response None (modifies system state) ``` -------------------------------- ### Perform Single Register I2C Operations Source: https://context7.com/mycroft-dev/touchscreen-controller/llms.txt Utilizes convenience functions ft5x0x_read_reg and ft5x0x_write_reg for simplified register access. These are used for device identification, threshold configuration, and enabling specific controller modes. ```c struct i2c_client *client; u8 chip_id; int ret; ret = ft5x0x_read_reg(client, FT_REG_ID, &chip_id); /* Register 0xA3 */ if (ret < 0) { dev_err(&client->dev, "Failed to read chip ID\n"); } else { switch (chip_id) { case FT5X06_ID: /* 0x55 */ printk("FT5x06 detected\n"); break; case FT6X06_ID: /* 0x06 */ printk("FT6x06 detected\n"); break; case FT6X36_ID: /* 0x36 */ printk("FT6x36 detected\n"); break; } } ret = ft5x0x_write_reg(client, FT_REG_THGROUP, 0x10); /* Register 0x80 */ ret = ft5x0x_write_reg(client, 0xd0, 0x01); ``` -------------------------------- ### Read Touch Data Source: https://context7.com/mycroft-dev/touchscreen-controller/llms.txt Reads and parses touch event data from the controller, returning coordinates, event type, and finger IDs. ```APIDOC ## fts_read_Touchdata ### Description Reads and parses touch event data from the controller. Returns touch coordinates, event type, and finger IDs. ### Method Not Applicable (C function) ### Endpoint Not Applicable (C function) ### Parameters None ### Request Example ```c /* Touch event structure */ struct ts_event { u16 au16_x[TPD_MAX_POINTS_10]; /* X coordinates */ u16 au16_y[TPD_MAX_POINTS_10]; /* Y coordinates */ u8 au8_touch_event[TPD_MAX_POINTS_10]; /* 0=down, 1=up, 2=contact */ u8 au8_finger_id[TPD_MAX_POINTS_10]; /* Finger tracking ID */ u16 pressure; u8 touch_point; /* Number of active touches */ u8 point_num; }; /* Reading touch data in interrupt handler */ struct ft5x06_ts_data *data; struct ts_event *event = &data->event; u8 buf[POINT_READ_BUF] = {0}; int i; ret = ft5x06_i2c_read(data->client, buf, 1, buf, POINT_READ_BUF); if (ret < 0) return ret; memset(event, 0, sizeof(struct ts_event)); event->touch_point = 0; /* Parse each touch point (up to 10) */ for (i = 0; i < CFG_MAX_TOUCH_POINTS; i++) { u8 pointid = (buf[FT_TOUCH_ID_POS + FT_ONE_TCH_LEN * i]) >> 4; if (pointid >= FT_MAX_ID) break; event->touch_point++; event->au16_x[i] = (buf[FT_TOUCH_X_H_POS + FT_ONE_TCH_LEN * i] & 0x0F) << 8 | buf[FT_TOUCH_X_L_POS + FT_ONE_TCH_LEN * i]; event->au16_y[i] = (buf[FT_TOUCH_Y_H_POS + FT_ONE_TCH_LEN * i] & 0x0F) << 8 | buf[FT_TOUCH_Y_L_POS + FT_ONE_TCH_LEN * i]; event->au8_touch_event[i] = buf[FT_TOUCH_EVENT_POS + FT_ONE_TCH_LEN * i] >> 6; event->au8_finger_id[i] = pointid; } event->pressure = FT_PRESS; /* 0x7F */ ``` ### Response #### Success Response (200) - **event** (struct ts_event) - Structure containing parsed touch data. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.