USB programming

独自空忆成欢 提交于 2019-12-02 15:54:27
J Edward Ellis

Well, although you can develop and write your own USB driver, the beauty of USB is that you don't need to write your own driver. the USB Implementers Forum has defined class specifications for all the standard device classes. If you can make your device fit into a standard device class the driver has already been written for you!

If you truly want to become familiar with USB development, you should start by reviewing the USB approved class specification documents.

If you are into framework for AVR microcontrollers with hardware USB then take a look into LUFA, and if you are into AVRs with software USB then look into V-USB. They have both implemented many USB classes so you don't have to do it on your own - just use them.

That sounds like a great project! I'd suggest starting off with something a little simpler since you're - as you say - a "total n00b". I'm not sure what hardware you currently have (or have in mind) but what I would suggest for the total beginner is the STK500. It's a development board that's very well supported in both Linux and Windows and will give you the most flexibility. It comes with LEDs and switches built in for your projects, but you will need to get a microcontroller. And for that I recommend the ATMega32, a great multi-purpose IC that's also well supported and has lots of documentation on the web.

Once you get those I suggest you do your development on Linux using avr-gcc (make sure to also install avr-libc). If you're using Ubuntu it's easy to get all the packages you need:

% sudo apt-get install gcc-avr avr-libc avrdude

Those should get you up and running. I'd suggest Googling around for help writing your first programs but another good resource is the online materials for this class at Cornell.

That's enough to get your feet wet with AVR microcontrollers and the development tools. The sky is the limit at that point but since you said you want to get into USB I'd suggest using the excellent V-USB framework to have your ATMega32 act as a USB device. After that, as they say, the steps to flipping LEDs are a piece of cake :).

avra

I wonder what to use to write your own drivers on the computer

  1. libusb (here, here and here)
  2. wdk
  3. WinDriver

For libusb variants info read this

You could us libusb. It's powerful and cross-platform.

But what you're trying to do is a rather simple control interface. You can sidestep most of the complexity by using HIDAPI, I think.

http://www.signal11.us/oss/hidapi/

HID devices often use generic drivers that come packaged into the OS. That way you don't actually have to write any drivers ever, you just make your device compliant with the generic driver and tailor the client software to it.

I think this is what's usually done in the hobbyist electronics field, which is what you're interested in here.

HIDAPI is even recommended for simple communications with HID devices in the libusb FAQ since its a bit more complicated to do it across platforms using libusb.

One good way to go is just to develop a HID device, since the driver is built in to most higher level OSes and pretty flexible for simple IO like you are talking about. Another good option is just using a USB RS232 device or software. I use PICs which have a number of nice devices with USB onboard.

I had built my own test bed based on the ARDUINO UNO and i was using the ionlabs programmer of type usbasp and it worked perfectly fine but it did not allow to convert the TTL back to Rs-232 and hence i couldn't use the features such as serial.print() and i had to install the ftdi cable which allowed me to do this. The drivers were the libusb 1.xx working just fine.

If you want to program the AVR you can use the ARDUINO software bundle or the stino to upload the programs. You need to know c(only basics).

I created a USB-keyboard adapter last year for my capstone. I did not do the host programming but used existing code that you can find on the web.But I did program the device side and for that I got a lot of help from this website Teensy Look into their "Code Library" which has code for Keyboard, Mouse and others. Also, the USB protocol handbook will always be useful and you should always consult it when you are doing stuff with USB.

I wonder whether your AVB acts as a host or device. I guess your board is a usb device and you need to light the leds on your board. So, it may be a good way to initialize your board as a HID device. To achieve this goal, you need a HID gadget software stack running on your board. References as follows:

  1. gadget framework in uboot
  2. HID specefication usb org
  3. debug tools such as USB Protocol Analyzer
  4. libusb running on Host PC to send packets
Orbling

The Microsoft documentation area of the WDK (Windows Development Kit) is recently available on MSDN. There is a section on USB, though you would be best to read the earlier sections first, in particular the "Getting Started" areas. They assume you'll be using C as the programming language for driver development.

For Linux, the Linux USB website should be able to point you in the right direction. In particular you'll want the Programming Guide for Linux USB Device Drivers.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!