How can I write a driver for a custom device?

Hi at all! I was wondering a thing. Let's pretend I make a electronical device, like a gamepad, which generate a sequence of bits (so I have a memory buffer) with a frequency of 125 Hz (so, every 1/125 seconds I have the above-mentioned buffer filled with different values). This device sends these bits to a USB adapter.
Now, I don't have much knowledge about electronics, but I do know that USB has four pins: VCC, Ground, Data+ and Data-.

THE SHORT QUESTION:
If we take a OS like Windows, how can I write a driver?

THE LONG QUESTION:
If we take a OS like Windows, I know that we can access individual COM ports by doing something like:
file("COM1", "r")
So, I read the sequence like a binary file... But:
1) If my device has a update frequency of 125 Hz, how can I synchronize reading and writing between the OS and my device?
2) How do I know which port is my device connected on? I think I must use the Windows API to get all the avaliable COM ports and scan them and search for my device. But how to recognize it?
3) I have made some thoughts about drivers. Once the OS recognize my device, how does it tells the port on which my device is connected? Is it passed in the main function of my driver?

Please, before linking any official documentation, I want you to give me every help you can.
Thanks in advance!
Last edited on
Drivers are based on the chips, such a video, network, serial port, you need to write the driver based on the mfg and model.

*hint* There is probably public domain linux drivers for most popular devices you can buy. Figure out what chips are used in which devices and you can probably find a generic driver. Maybe even one that would work with minor changes.
Topic archived. No new replies allowed.