Skip to content

Mode Switching between PTP & Mouse

Barryblueice edited this page Jan 2, 2026 · 1 revision

I use a simple but "violance" way to solve this problem.

Basic principle is getting Feature Report ID (ptp_input_mode) when tud_mounted is trueL

  • 0x03: PTP Mode
  • 0x00 (Default): Mouse Mode
void usb_mount_task(void *arg) {
    while (1) {
        if (tud_mounted()) {
            if (ptp_input_mode != last_ptp_input_mode) {
                switch (ptp_input_mode) {
                case 0x03:
                    ESP_LOGI(TAG, "Mode 0x03 detected: Activating ELAN PTP");
                    current_mode = PTP_MODE;
                    elan_activate_ptp();
                    break;
                case 0x00:
                    ESP_LOGI(TAG, "Mode 0x01 detected: Activating ELAN MOUSE");
                    current_mode = MOUSE_MODE;
                    elan_activate_mouse();
                    break;
                default:
                    break;
                }
                last_ptp_input_mode = ptp_input_mode;
            }
        } else {
            ptp_input_mode = 0x00;
        }
        vTaskDelay(100);
    }
}

Although it's not an elegent way, it can work perfectly.

Clone this wiki locally