Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB-HOST-HID connect scanner STALL (IEC-146) #55

Open
3 tasks done
Sentaku1129 opened this issue Aug 2, 2024 · 6 comments
Open
3 tasks done

USB-HOST-HID connect scanner STALL (IEC-146) #55

Sentaku1129 opened this issue Aug 2, 2024 · 6 comments
Labels
Type: Bug Bug in esp-usb

Comments

@Sentaku1129
Copy link

Answers checklist.

  • I have read the component documentation ESP-IDF Components and the issue is not addressed there.
  • I am using target and esp-idf version as defined in component's idf_component.yml
  • I have searched the issue tracker for a similar issue and not found any related issue.

Which component are you using? If you choose Other, provide details in More Information.

host/hid

ESP-IDF version.

v5.3.0

Development Kit.

ESP32-S3-WROOM-1

Used Component version.

1.0.2

More Information.

I used the development board to connect the scanner gun and the STALL sign appeared. Use "https://github.com/espressif/esp-idf/tree/master/examples/peripherals/usb/host/hid" template modification, use the version number is component 1.0.2, I will attach the data collected by connecting the scanner to the S3 and connecting the computer to the USB logic analyzer
logic.zip

@Sentaku1129 Sentaku1129 added the Type: Bug Bug in esp-usb label Aug 2, 2024
@github-actions github-actions bot changed the title USB-HOST-HID connect scanner STALL USB-HOST-HID connect scanner STALL (IEC-146) Aug 2, 2024
@roma-jam
Copy link
Collaborator

roma-jam commented Aug 2, 2024

Hi @Sentaku1129 ,

Could you please update the *.csv log file format or let me know which software could be used to open the *.usmn format.

Thanks.

@Sentaku1129
Copy link
Author

Sentaku1129 commented Aug 2, 2024 via email

@Sentaku1129
Copy link
Author

Some devices will respond to data requests that interrupt IN only if they have sent OUT information about the system's numeric keypad area and case lock status

@roma-jam
Copy link
Collaborator

roma-jam commented Aug 8, 2024

Hi @Sentaku1129 ,

Sorry for such a delay, I have checked the log file and I was that the STALL'ed transfer is IN transfer with data length = 0.

Current implementation of HID Host Class Driver is working only with HID devices which are able to work in the BOOT mode (This is specific simplified protocol for devices to be able to work in BIOS e.t.c.).
Any device, which is a bit complicated (such as Gamepads or some scanners) requires more complicated protocol, therefore more complicated structure of input reports.

The example forces the device to change the protocol to BOOT after opening and call SetIdle(0) class specific request to disable notification from the device, even without any events (refer to the code here).
After these lines, the device will send the BOOT report via IN transfer only when some event has happened, (like key pressing).

You could try to disable this configuration and simplify the logic by removing these lines (hid_host_example.c, function hid_host_device_event()):

        ESP_ERROR_CHECK(hid_host_device_open(hid_device_handle, &dev_config));
        // Comment out start
        // if (HID_SUBCLASS_BOOT_INTERFACE == dev_params.sub_class) {
        //     ESP_ERROR_CHECK(hid_class_request_set_protocol(hid_device_handle, HID_REPORT_PROTOCOL_BOOT));
        //     if (HID_PROTOCOL_KEYBOARD == dev_params.proto) {
        //         ESP_ERROR_CHECK(hid_class_request_set_idle(hid_device_handle, 0, 0));
        //     }
        // }
        // Comment out stop
        ESP_ERROR_CHECK(hid_host_device_start(hid_device_handle));

But in this case, the input reports will be not compatible with current parsing logic, so you need to disable the parsing as well.
To verify the Scanner again, you can add the debug for the incoming report (hid_host_example.c, function hid_host_interface_callback(), event HID_HOST_INTERFACE_EVENT_INPUT_REPORT).

So, something like this:

    case HID_HOST_INTERFACE_EVENT_INPUT_REPORT:
        ESP_ERROR_CHECK(hid_host_device_get_raw_input_report_data(hid_device_handle,
                                                                  data,
                                                                  64,
                                                                  &data_length));

        ESP_LOG_BUFFER_HEX("Input Report", data, data_length); // Display the input report data 
        // Comment out start
        // if (HID_SUBCLASS_BOOT_INTERFACE == dev_params.sub_class) {
        //     if (HID_PROTOCOL_KEYBOARD == dev_params.proto) {
        //         hid_host_keyboard_report_callback(data, data_length);
        //     } else if (HID_PROTOCOL_MOUSE == dev_params.proto) {
        //         hid_host_mouse_report_callback(data, data_length);
        //     }
        // } else {
        //     hid_host_generic_report_callback(data, data_length);
        // }
        // Comment out stop
        break;

After the verification, please share the log with the result.
Thanks

@Sentaku1129
Copy link
Author

I've already tried to remove these lines of code and run them on the ESP32-S3 development board. I found that there was indeed no "STALL" error, but I still couldn't get the data from the scanner. My guess is that the scanner needs to receive the status of "NUM LOCK" and "CAPS LOCK" from the host before uploading the data, and it needs to send it to the OUT endpoint of the scanner via interrupt OUT.
I have tried to send a "set report" to endpoint 0, and the transmission error appears to be that only interrupt OUT data can be sent to endpoint OUT. What can I do? Send an interrupt OUT.

@roma-jam
Copy link
Collaborator

Hi @Sentaku1129 ,

Usually, the Host driver notifies all the devices about NUM/CAPS/SCROLL lock state changes by using the Control Endpoint and the specific class request Set Output Report.

Current version of the HID Host class driver doesn't provide any mechanisms to send interrupt data by OUT EP, or any other data via OUT EP.

To have possibility to send the interrupt OUT data, the device should have such EP available. Not all devices have that and it is better to refer the manual or some kind of documentation for any particular device you would like to use, because the specific configuration can be vary.

In any case, if the device requires some proprietary or specific logic, it is always possible to achieve the goal with using the public USB Host library API.
To check, how proprietary class driver could be designed, please refer to the usb_host_lib example from esp-idf (here).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bug in esp-usb
Projects
None yet
Development

No branches or pull requests

2 participants