USB programming
Rick Murray (539) 13857 posts |
How easy/difficult is it to communicate with a USB device? Is it possible to ‘open’ the device using DeviceFS? I was considering poking around my graphics tablet, to see if I could pick up on its positioning and fake mouse moves/clicks accordingly. I don’t have a datasheet, but it looks like a rebadged mini Widcomm tablet; I was hoping it might just spew out information somewhat akin to a serial mouse. Thing is, how do I gain access to it? Additionally, if there are registers to set up, does this work as PTR# to the desired offset, or some sort of ioctl operation? In short – is there a crash course to the easiest way to talking to a USB device? |
Steffen Huber (91) 1954 posts |
Basically, you open the device via DeviceFS (usually after scanning for it or after getting triggered) and then read and write bytes via the usual FS SWIs. Really simple ;-) Castle USB doc is here: http://www.iyonix.com/32bit/USBDevFS.shtml A good look at the official USB spec is also a good idea (or buying one of the USB books from Jan Axelson) to get the grips on the USB basics like endpoints and transfer types. I have some BASIC code used as a testbed for my USB CD stuff, which shows how to scan for a device, how to discover device endpoints, and how to communicate with a mass storage device. I could make that available if you want, but it is restricted to “bulk transfers”. Dave Higton also has a large collection of code that controls several cute USB devices. See http://www.apts04.dsl.pipex.com/ for more info, most (all?) of it is in BASIC. There are also some notes available for more advanced stuff: http://www.riscos.info/index.php/DeviceFS_USB_technical |
Dave Higton (1515) 3535 posts |
It’s fairly involved. Please, take this as meaning: you will need to persevere; don’t take it as “it’s too hard, I won’t bother”.
You open the endpoints, rather than the device as a whole. But you do open them via DeviceFS, yes – assuming you are using the Castle USB stack. (The Simtec USB stack is utterly and completely different, but I regard it as moribund these days.)
Yes, been there, done that with a Nisis tablet. It works, within the limitation that it’s an application, and therefore subject to not being active when some other application needs mouse input. In fact I’d like to know how to use USB within a module and to do USB I/O without needing to be the currently paged in application. If I’m ever to get Bluetooth working, I’ll need to know that. Like Steffen says, there are several USB apps on my web site, and they are all in uncrunched BASIC, so I hope they will be useful to you. I have to point out that http://www.apts04.dsl.pipex.com will shortly cease to exist. The new site is at http://davehigton.me.uk
No, and, like I say, it will take some perseverance on your part, because it isn’t like communicating with serial devices, for instance. But please do try; if I can help, I will. Please consider writing up what you learn as you learn it, to help the next person. The biggest difficulties in communicating with any USB device are knowing what you have to say to it, how you have to say it, what it will say to you, and how you have to interpret what it says. |
Steve Pampling (1551) 8175 posts |
Someone needs to remind Frank deBruijn to update the URL in AntiSpam which refers to your original version. |
Frank de Bruijn (160) 228 posts |
That’s already been taken care of. The next release will have the new url (no, I don’t know when the next release will be…). |