Customising support for USB drivers at compile-time #482
SteveSpencer
started this conversation in
Ideas
Replies: 2 comments 2 replies
-
I could image to add the following system options as #ifndef's to usbdevicefactory.cpp (all not defined by default):
|
Beta Was this translation helpful? Give feedback.
2 replies
-
I added the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
While looking at the code listing and map for a built kernel, I realised that there are many code-blocks in it that are not necessary for my particular case. This particularly applies to USB functionality.
Having also run into a couple of cases where the USB device discovery/configuration needed some minor tweaking, a few things occurred to me.
Firstly, in usbdevice.cpp CUSBDevice::Initialize, there are some special cases where retrieval of the default configuration descriptor has to be adjusted for certain devices (known for specific VID/PID combinations).
Secondly, in usbdevicefactory.cpp CUSBDeviceFactory::GetDevice, there are again, special cases matching interfaces, where, again, they are for specific VID/PID combinations.
Finally, again in usbdevicefactory.cpp CUSBDeviceFactory::GetDevice, there are device constructors being called for specific VID/PIDS.
It occurred to me that for the first and third situations, these could be dealt with using relatively simple data structures.
A data structure containing a vid, pid, configuration index, potentially an interface name, and a 'factory' function would mean that usbdevice.cpp and usbdevicefactory.cpp no longer need to be modified when adding in USB support for new devices.
I believe something along these lines this is being done for various CDC serial devices, which could be adapted into this system.
In addition, it would be possible in many cases, where it is known in advance that support for particular USB devices is NOT needed (for example, USB Midi, or gamepad devices), then by omitting rows from the table (via preprocessor definitions, eg OMIT_USB_MIDI), the built image would be smaller (at the cost of USB initialisation generating additional messages if unsupported devices are connected).
My suggestion would be to have a default table in lib/usb, which is NOT part of the libusb target, but is intended to be copied and modified in the app (and obviously, added as a Make dependency for kernel.img).
I would be interested to see what everyone else thinks about this, particularly as it would mean not just a rewrite of the relevant code, but it would also be a breaking change, meanin extra work modiying sample, app and addon Makefiles to make it all work.
Beta Was this translation helpful? Give feedback.
All reactions