前面我们完成了开发环境的搭建,界面的设计,这一篇正式开始业务部分开发。我们基于libusb来实现usb相关的操作。所以这一篇先添加libusb库到工程中,为了方便调试我们以添加源码的方式而不是添加库的方式。Libusb开发环境搭建还可以参考以下文章:
《Windows下基于MSVC搭建libusb开发环境》https://mp.weixin.qq.com/s/fYLEeHXhKQ96zKCMFCrphQ
《libusb开发之一-Linux下开发环境搭建》https://mp.weixin.qq.com/s/i9QOBc9hprwg6VGexh_Bhw
《libusb开发之二-Linux下使用vscode开发》https://mp.weixin.qq.com/s/kxtcLUZKAS8DeVEGHx3bHw
《libusb开发之三-Windows下使用vscode+MinGW开发》https://mp.weixin.qq.com/s/7TqixduB6nTUM_k9Su75HA
git clone https://github.com/libusb/libusb.git
修改.pro文件,添加源码,
SOURCES += \
......
libusb/libusb/core.c\
libusb/libusb/descriptor.c\
libusb/libusb/hotplug.c\
libusb/libusb/io.c\
libusb/libusb/sync.c\
libusb/libusb/strerror.c\
libusb/libusb/os/events_windows.c\
libusb/libusb/os/threads_windows.c\
libusb/libusb/os/windows_common.c\
libusb/libusb/os/windows_usbdk.c\
libusb/libusb/os/windows_winusb.c
添加头文件
HEADERS += \
......
config.h\
libusb/libusb/libusb.h\
libusb/libusb/libusbi.h\
libusb/libusb/version.h\
libusb/libusb/version_nano.h\
libusb/libusb/os/events_windows.h\
libusb/libusb/os/threads_windows.h\
libusb/libusb/os/windows_common.h\
libusb/libusb/os/windows_usbdk.h\
libusb/libusb/os/windows_winusb.h
配置头文件包含路径
INCLUDEPATH += $$PWD/libusb/libusb
INCLUDEPATH += $$PWD/libusb/libusb/os
INCLUDEPATH += $$PWD/
复制msvc/config.h到工程目录下
添加后文件如下
此时编译会有问题
修改config.h删除预处理语句变为
/* Define to the attribute for default visibility. */
/* Define to 1 to start with debug message logging enabled. */
/* #undef ENABLE_DEBUG_LOGGING */
/* Define to 1 to enable message logging. */
/* Define to 1 if compiling for a Windows platform. */
/* Define to the attribute for enabling parameter checks on printf-like
functions. */
/* Define to 1 to output logging messages to the systemwide log. */
/* #undef USE_SYSTEM_LOGGING_FACILITY */
此时只有一些告警
复制examples下的listdevs.c到工程目录下
.pro中添加源文件
SOURCES += \
......
listdevs.c\
构建运行
运行如下
也能进入源码级调试
以上完成了libusb源码的添加,并进行了测试,后面就开始进行usb相关的业务开发了。我们按照设备相关,接口相关,端点相关等层级来进行。