This is a simple Qt app that can do transfers over USB.
Prerequisites
1. Download Qt from http://qt-project.org/downloads. Make sure to
specifically download
Qt x.y.z for Windows (MinGW 4.8.2, OpenGL)
2. The installer comes with MinGW but if it doesn’t, then download it from
http://www.mingw.org/
3. The SuperSpeed USB Suite from Cypress. You will also need the source
code for CyAPI.lib as we’ll need to recompile it
Compiling CyAPI
The C++ USB API from Cypress needs to be recompiled with MinGW before we
use it to build our project. Extract the source code to a folder and then run the
following in a command prompt:
set PATH=%PATH%;C:\Qt\Tools\mingw482_32\bin
mingw32-make %
And this requires a Makefile with the following contents:
all:
del CyAPI.*
g++ src/CyAPI.cpp -lsetupapi -I inc -c -o CyAPI.o -Wno-
conversion-null
ar rcs CyAPI.a CyAPI.o
This generates the CyAPI.a static library which we’ll link against in our project.
Creating the project
Open Qt Creator and create a new project. We’ll need to link against the CyAPI
library and the header files for the new project to compile correctly.
Open the .pro file in the project’s folder and add these lines at the end:
# Include the CyAPI library for USB accesses
LIBS += -L"..\CyAPI_lib_cpp" -lcyapi
LIBS += -lsetupapi
And in the mainwindow.h file, include the CyAPI.h file. For e.g,
#include "../CyAPI_lib_cpp/inc/CyAPI.h"
Page 1 of 2
You can now call use any CyAPI APIs and they’ll work as intended.
The Project
It displays a GUI shown below:
The mainwindow.cpp file has the code that handles all UI events and USB
transfers. Specifically, the MainWindow constructor does these
1. get a handle to all UI elements and attach all event handlers to them
2.
3. update the list view
initialize the USB device list
When you select a device, the listItemClicked handler is fired which then
updates the combo box with the selected device’s endpoints.
Now when the “Transfer Data” box is clicked, one packet of data is transferred
across the device in the transferButtonClicked handler.
Page 2 of 2