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

Setting the board serial number explicitly in USB HID API #389

Open
abratchik opened this issue Jan 22, 2021 · 2 comments · May be fixed by #387
Open

Setting the board serial number explicitly in USB HID API #389

abratchik opened this issue Jan 22, 2021 · 2 comments · May be fixed by #387

Comments

@abratchik
Copy link

Current implementation of USB HID library generates the Serial No automatically by adding the descriptor size to the "HIDAA" string. This approach is ok as a default but in some use cases it is necessary to set a specific serial number to the board, which will not change when the USB HID descriptor is updated.
Besides, the serial number is utilized in the naming of the Arduino port so changing it dynamically may lead to the loss of connectivity to the board after the sketch upload.
Instead, a new method setSerial() is proposed, which can take any string stored in PROGMEM.

@matthijskooijman
Copy link
Collaborator

Sounds like a good feature, I've thought about this before (for a project where machines have an actual serial number written to EEPROM, where it would be good to actually use that serial on USB as well). However, I wonder: How is the timing of this? Typically, USB is initialized directly on startup, even before setup() runs. Won't a setSerial() method be called too late to still influence the USB descriptor?

@abratchik
Copy link
Author

abratchik commented Jan 22, 2021

Timing is fine since all the string descriptors can be overridden through PluggableUSB (it is called first in the USBCore). I already implemented and tested this feature in the associated pull request. You may check the code changes in HID.cpp. The idea is - string descriptors are implemented by the getDescriptor() method, which is called before setup whenever String is required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants