简体   繁体   中英

Writing a Windows driver for Pro Micro

First off I have very very little experience with how USB functions let alone writing a driver; essentially trying to make this project a learning experience.

My setup consists of the SparkFun Pro Micro board and a Windows machine. I have a potentiometer wired up to the Pro Micro and my end goal is to send the value of the potentiometer to the host machine and use the value to change things like system volume etc...

The Arduino library came with a Serial library and I can send things over USB using that. I currently have a working Arduino program that sends 1 byte every 1 second, and a C program on the windows machine that "connects" to the COM port and reads the byte coming through (this part I have working fine).

The issue is that when the Pro Micro is connected to the computer it appears on a randomly selected COM port and I don't think you can tell which COM ports hold which device (not sure about this bit).

My end goal is when the Pro Micro is connected to the PC the host program should automatically recognize the Pro Micro and start processing the data that is coming from it. Setting it up as a HID device and making it appear in Device Manager as my own custom device is something I'd be interested in doing, especially for the learning experience but I feel that it might overcomplicate things.

Can anyone point me in the right direction as to what I should do/look into?

maybe use windows internal tools like the COM port database ( https://msdn.microsoft.com/en-us/library/ff546481.aspx ) or re-assign COM ports using windows registry , see

if you want to know the backgrounds: the arduino implements the USB CDC ACM class (Communication Device Class - Abstract Control Model https://en.wikipedia.org/wiki/USB_communications_device_class ) and emulates a COM port. Windows recognizes this class and loads the apropriate driver which is usbser.sys ( https://msdn.microsoft.com/de-de/library/windows/hardware/dn707976%28v=vs.85%29.aspx ) when the driver is loaded the new (virtual) COM port is accessible

the best sources are How does windows map the virtual com port to a device , https://superuser.com/questions/851192/change-com-port-number-programmatically and http://www.ftdichip.com/Support/Documents/AppNotes/AN_132_Re-Assigning_COM_Port_Numbers_Using_Registry.pdf

I would suggest using libusbp, a C library that can be used to find the name of a COM port, given the USB vendor ID and product ID. There is even an example in the "examples" folder that does just that:

https://github.com/pololu/libusbp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM