USB编程

发布于 2024-10-04 04:17:15 字数 480 浏览 0 评论 0原文

我想对微控制器 (AVR) 进行编程,以通过 USB 控制一些 LED。它只是出于对如何构建和编程 USB 设备的兴趣。 有一些 AVR 微控制器支持 USB 协议,或者我可以自己在另一个微控制器中实现 USB 协议,但我想知道用什么来在计算机上编写自己的驱动程序。

我的系统编程水平:完全菜鸟(因此有这个问题)

那么,你们会建议哪些文献来获得 USB 技术的良好知识以及如何编写自己的驱动程序等?

PS:我知道:

  • C(这里可能需要它)

  • Java(这里可能不需要它)

  • Python(希望可以在这里使用它)

  • 汇编器(希望这里不需要它XD)。

  • ...

PPS:不同操作系统的驱动程序开发有所不同。我使用 Linux 和 Windows,因此欢迎任何与这些系统中的一个或两个系统相关的材料。

I want to program a microcontroller (AVR) to control some leds through USB. It's just out of interest in how to build and program USB devices.
There are some AVR microcontrollers that support the USB protocol or I could implement the USB protocol in an another microcontroller myself, but I wonder what to use to write your own drivers on the computer.

My level in system programming: total noob (hence the question)

So what is the literature you people would advice to get good knowledge of the USB technology and how to write your own drivers and beyond?

P.S.: I know:

  • C (probably will need it here)

  • Java (probably won't need it here)

  • Python (hope can use it here)

  • assembler (hopefully won't need it here XD).

  • ...

P.P.S: driver development differs for different OS's. I use Linux and Windows, so any material related to one or both of these systems is welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

得不到的就毁灭 2024-10-11 04:17:15

好吧,虽然您可以开发和编写自己的 USB 驱动程序,但 USB 的美妙之处在于您不需要编写自己的驱动程序。 USB 实施者论坛 已为所有标准设备类定义了类规范。如果您可以使您的设备适合标准设备类,那么驱动程序已经为您编写好了!

如果您确实想熟悉 USB 开发,您应该首先查看 USB 批准的类规范文档

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.

李白 2024-10-11 04:17:15

如果您对带有硬件 USB 的 AVR 微控制器框架感兴趣,请查看 LUFA,如果您喜欢带有软件 USB 的 AVR,然后查看 V-USB。它们都实现了许多 USB 类,因此您不必自己执行 - 只需使用它们即可。

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.

萌吟 2024-10-11 04:17:15

这听起来是一个很棒的项目!我建议从更简单的事情开始,因为正如你所说,你是一个“十足的n00b”。我不确定您目前拥有(或想要)什么硬件,但我建议初学者的是 STK500。它是一款在 Linux 和 Windows 中都得到很好支持的开发板,将为您提供最大的灵活性。它配备了针对您的项目内置的 LED 和开关,但您需要一个微控制器。为此,我推荐 ATMega32,这是一款出色的多用途产品IC 也得到了很好的支持,并且在网络上有大量文档。

一旦你获得这些,我建议你使用 avr-gcc 在 Linux 上进行开发(确保还安装 avr-libc)。如果您使用 Ubuntu,则可以轻松获取所需的所有软件包:

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

这些软件包应该可以帮助您启动并运行。我建议在谷歌上搜索帮助编写您的第一个程序,但另一个很好的资源是 康奈尔大学的这门课

这足以让您熟悉 AVR 微控制器和开发工具。那时天空是极限,但既然你说你想进入 USB,我建议使用优秀的 V-USB 框架让您的 ATMega32 充当 USB 设备。之后,正如他们所说,翻转 LED 的步骤就是小菜一碟:)。

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 :).

债姬 2024-10-11 04:17:15

我想知道用什么来写你自己的
计算机上的驱动程序

  1. libusb 上的驱动程序(此处此处此处)
  2. wdk
  3. wdk jungo.com/st/wdusb.html" rel="nofollow noreferrer">WinDriver

对于 libusb 变体信息,请阅读 这个

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

咽泪装欢 2024-10-11 04:17:15

你可以使用libusb。它功能强大且跨平台。

但您想要做的是一个相当简单的控制界面。我认为,您可以通过使用 HIDAPI 来避免大部分复杂性。

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

HID 设备通常使用通用驱动程序打包到操作系统中。这样,您实际上不必编写任何驱动程序,只需使您的设备与通用驱动程序兼容并为其定制客户端软件即可。

我认为这是电子爱好者领域通常所做的事情,也是您在这里感兴趣的事情。

libusb 常见问题解答中甚至建议使用 HIDAPI 与 HID 设备进行简单通信,因为使用 libusb 跨平台进行通信要复杂一些。

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.

我一直都在从未离去 2024-10-11 04:17:15

一种好的方法是开发 HID 设备,因为驱动程序内置于大多数更高级别的操作系统中,并且对于您所说的简单 IO 非常灵活。另一个不错的选择是仅使用 USB RS232 设备或软件。我使用的 PIC 具有许多带有 USB 板载的好设备。

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.

孤云独去闲 2024-10-11 04:17:15

我基于 ARDUINO UNO 构建了自己的测试台,并且使用了 usbasp 类型的 ionlabs 编程器,它工作得很好,但它不允许将 TTL 转换回 Rs-232,因此我无法使用这些功能例如serial.print(),我必须安装ftdi电缆才能做到这一点。
驱动程序是 libusb 1.xx,工作得很好。

如果您想对 AVR 进行编程,您可以使用 ARDUINO 软件包或 stino 上传程序。
你需要了解c(仅基础知识)。

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).

○愚か者の日 2024-10-11 04:17:15

去年,我为我的顶点课程创建了一个 USB 键盘适配器。我没有进行主机编程,而是使用了您可以在网络上找到的现有代码。但我确实对设备端进行了编程,为此我从该网站获得了很多帮助 Teensy 查看他们的“代码库”,其中包含键盘、鼠标和其他代码。此外,USB 协议手册始终很有用,在使用 USB 进行操作时应始终查阅它。

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.

雨的味道风的声音 2024-10-11 04:17:15

我想知道你的AVB是充当主机还是设备。我猜你的主板是一个 USB 设备,你需要点亮主板上的 LED。因此,这可能是将您的板初始化为 HID 设备的好方法。为了实现这一目标,您需要在主板上运行 HID 小工具软件堆栈。参考资料如下:

  1. uboot 中的 gadget 框架
  2. HID 规范 usb org
  3. USB 协议分析器 libusb 等调试工具
  4. 运行在 Host PC 上的 发送数据包

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
勿挽旧人 2024-10-11 04:17:15

WDK(Windows 开发工具包)的 Microsoft 文档区域最近在 MSDN 上可用。有一个关于 USB 的部分,不过您最好先阅读前面的部分,特别是“入门”部分。他们假设您将使用 C 作为驱动程序开发的编程语言。

对于 Linux,Linux USB 网站应该能够为您指明正确的方向。特别是,您需要编程指南Linux USB 设备驱动程序

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文