How to use gamepad by STM32? - stm32f4

I'm a very beginner of using STM32 and now I'm trying to move a robot by using STM32F4.
Now I can move a robot by controlling a device such as motor, encoder and other devices.
However, I don't have any idea about reading gamepad (HID device of USB).
I'm trying this because I want to control a robot by gamepad.
Is it possible to read gamepad which use USB by STM32F4?
If there are a page which write about this problem, I'm afraid you tell me the URL.
Thank you.

It is possible if your uC has the USB interface which can be configured as a host device. Check with your micro DS. but you have to remember - it is not an easy task, you will have to learn USB deeply, and implement the host stack.

Related

Emulate an HID device on windows?

I am trying to write a program that emulates a gamepad in such a way that windows recognizes it as a gamepad, but it is actually controlled by my own code.
I have tried to create a virtual COM port and try to make windows recognize it as a gamepad, but without much luck.
Does anyone know a way to do something like this, or could maybe give me some pointers on what might be worth trying?
The HIDUSBFX2 sample driver (hidusbfx2.sys) demonstrates how to map a non-HID USB device to a HID device.
On Windows 10 there is new Virtual HID Framework (VHF) that is intended for same purpose.

Writing device driver?

I wonder if I understand correctly...
Say, if I want to control how my mouse work, i.e Left Button open window, Right Button send keystroke 'A' etc.
But I am not talking about writting something like follows in an application:
void MouseDown(xxxxEventArgs e, sender object)
{
}
I want to completely controls how the device work, then I will need to write a driver for it? From what I learn in assembly before, controlling a device I should need to know their port to communicate with the device. But say if I buy a Logitech mouse, is it possible to write a mouse driver myself to use it?
Because I saw some project that they buy a usb web cam from store, and they could able to control the web came to rotate, recevie the image from the web cam, I wonder if that's because the web cam has API provided them?
Thanks in advance.
If you want to control the device in it's entirety, then you need to write a device driver indeed. This is a non-trivial task and you should read up on it. There is a tutorial on it here and there a book for windows driver development here.
If you want to write device drivers, you should be very well versed with C and/or C++.
You do not need to write a device driver for what you are trying to do.The device driver has nothing but as per the data sheet of the device address of registers where it can read,write,do IOMMU etc or some other stuff.What you will need is some kind of hacking the application programming part of the thing which you are trying to achieve.
Because device driver code just reads the data from device and writes back it is the application which is concerned for it.Though in some case device driver programmer provide a method (function) to application programmer so that they can write their application and invoke those methods.In your case you need to just understand how the application code is talking to device driver.
In case you want to write a device driver check this
http://www.freesoftwaremagazine.com/articles/drivers_linux?page=0%2C0
In such kind of cases you can proceed with writing your own device driver by C++ and assemb
lyem

How to read from USB without any driver?

We are creating small system which has GPS receiver and PC. We want to test my GPS receiver, We do not want to go for a driver on the first go. First I would like to test my circuit works or nor. GPS IC has been set to output NMEA sentence. We want a program which just reads data from USB port and print it on the screen.
Can we write something like this easily ? Do we have any open source tool which will achieve this purpose ?
Platform : Windows 7
All devices need a driver, so I'm going to interpret your question as "how can I read NMEA data from my GPS using only drivers provided by the OS, so I don't have to write my own?"
If the GPS chip has a USB interface, then you should have gotten a driver with it. But most GPS chips have a UART interface which in your case sounds like it is connected to a separate USB-UART conversion chip. That conversion chip most likely came with a driver as well, but if not, you could jumper the reset pin of the converter chip, disabling it, and then attach a TTL/RS-232 level converter (available off-the-shelf) to the UART traces and then to your computer's serial port.
Unless you suspect that the driver for the USB-UART converter is causing problems, I wouldn't bother.
Anything connected via USB is a device. Devices require a device driver, period.
You might be able to get away with an existing driver built into Windows. This is how USB memory keys work for example - they present a generic device that looks like a removable disk, and Windows already includes the drivers for generic removable disks.
You would need to check the documentation for your device to see if it can emulate a device which already has drivers. Otherwise you must install the company's drivers, or you're out of luck.
Have a look at libusb. You should be able to read the data with that and a little code. (Yes, it's a driver. I take the question to mean "without writing a driver".)
You need a device driver for your device. Unless Windows already have a class driver for the device.
For USB devices on Windows 7 you can write a user-mode driver, see UMDF.

Using HID USB in Visual Basic 6.0

im trying to interface a Gramin usb GPS to get the coordinates in a visual basic project, but i dont have an idea how to accomplish this, anyone point me out in the right direction please?
If the Garmin unit uses an RS-232 (standard serial) interface, then its USB driver probably implements a virtual serial port that you can open using the MSCOMM control.
Check that by opening the Hardware Manager and see if there's an extra port, maybe even labeled 'Garmin', while it's plugged in.
There are simple, standard text protocols used by GPS units. As long as no other app has the port open, you should be able to open it in VB and capture the output with a little experimenting for baud rate, etc. 4800,8,N,1 is a good place to start.

Communicating with USB device

I am working on building a USB Video Class camera, which is supposed to work well with various flavours of Windows. The camera needs firmware upgrade support to upload new software images into it. There are two ways to do it, as far as I know.
Use DFU.
Use control endpoint of the UVC Class device to transfer bytes into the device.
To use the second option, it looks like, one needs to write a Filter Driver. Is this correct? Is there any other way to accomplish this task?
There are several ways to do what you want.
The standard UVC Class driver supports a user mode interface, from which you can send USB packets to the device. This interface is called: USB Video Class Extension Units.
Another way is to use WinUSB, where you install the WinUSB driver for your device. After that you can send USB packets through the WinUSB interface.
The most involved solution would be, to write a complete USB driver. Just see the samples in the WDK.

Resources