When using just stdio_usb, the SDK configures, initialises and runs a TinyUSB instance 'behind the scenes'. If you want to use USB directly in your app, you need to take on the whole job yourself, providing one extra CDC instance on top of what you want in the configuration for the stuff you are doing directly (if you also want CDC instances yourself, stdio_usb will take the first one and you are free to use the rest).
So you can't add HID to the USB setup provided by a simple stdio_usb build, but you can add stdio_usb to an otherwise complete HID application.
This is not particularly hard. The CMakelists.txt just needs to add tinyusb_device to target_link_libraries and keep pico_enable_stdio_usb(). You need to add a tusb_config.h and a usb_descriptors.c and edit them to suit your requirements (you can either take the ones that the SDK uses for the standalone stdio_usb and add your stuff to them, or take a separate HID-only example and add a CDC instance):
pico-sdk/src/rp2_common/pico_stdio_usb/include/tusb_config.h
pico-sdk/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c
Then in your main code you need to do the setup:and arrange that tud_task() is called frequently in your main loop (the stdio-only version calls tud_task() from a timer, but that's tricky from a reentrancy point of view: TinyUSB assumes that its code all runs in foreground and the only interrupts it has to be concerned about are its own; all 'callback' functions are called via tud_task()).
The one fly in the ointment here is Windows. While the USB specification defines device descriptors which should be enough for any sensible operating system to associate device drivers with devices, Windows has decided to require devices to include extra Windows proprietary descriptors under some circumstances. Probably for just CDC + HID you can get away without this, but keep your USB version as 2.0 (.bcdUSB=0x200), because if you go to 2.1 than Windows insists on the extra descriptor even if it would not be otherwise needed.
The Windows documentation used to be at this link, but the link seems to have gone stale since I bookmarked it and now just takes you to the front page and I haven't gone searching to see where they've put the descriptor requirements.
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
So you can't add HID to the USB setup provided by a simple stdio_usb build, but you can add stdio_usb to an otherwise complete HID application.
This is not particularly hard. The CMakelists.txt just needs to add tinyusb_device to target_link_libraries and keep pico_enable_stdio_usb(). You need to add a tusb_config.h and a usb_descriptors.c and edit them to suit your requirements (you can either take the ones that the SDK uses for the standalone stdio_usb and add your stuff to them, or take a separate HID-only example and add a CDC instance):
pico-sdk/src/rp2_common/pico_stdio_usb/include/tusb_config.h
pico-sdk/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c
Then in your main code you need to do the setup:
Code:
tud_init(BOARD_TUD_RHPORT); stdio_usb_init();The one fly in the ointment here is Windows. While the USB specification defines device descriptors which should be enough for any sensible operating system to associate device drivers with devices, Windows has decided to require devices to include extra Windows proprietary descriptors under some circumstances. Probably for just CDC + HID you can get away without this, but keep your USB version as 2.0 (.bcdUSB=0x200), because if you go to 2.1 than Windows insists on the extra descriptor even if it would not be otherwise needed.
The Windows documentation used to be at this link, but the link seems to have gone stale since I bookmarked it and now just takes you to the front page and I haven't gone searching to see where they've put the descriptor requirements.
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
Statistics: Posted by arg001 — Tue Nov 12, 2024 1:16 pm