diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index fa327b3d9..8d3466d49 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -1,5 +1,9 @@ name: Build Android +permissions: + contents: read + pull-requests: write + on: workflow_dispatch: workflow_call: @@ -14,14 +18,14 @@ jobs: - name: Install Qt uses: jurplel/install-qt-action@v4 with: - aqtversion: '==3.1.*' - version: '5.12.12' + aqtversion: '==3.3.*' + version: '5.14.2' host: 'linux' target: 'android' - arch: 'android_armv7' + arch: 'android' - name: Install SDK - run: ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --install 'platforms;android-28' 'build-tools;28.0.3' 'ndk;21.3.6528147' + run: ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --install 'platforms;android-31' 'build-tools;31.0.0' 'ndk;21.3.6528147' # Secrets should be the base64 portion of the PEM format # (i.e. the stuff between the BEGIN/END lines): @@ -60,20 +64,28 @@ jobs: qmake -config release make -j$(nproc) make INSTALL_ROOT=android-build install - JAVA_HOME=${JAVA_HOME_8_X64} androiddeployqt --input android-libLabrador.so-deployment-settings.json --output android-build --android-platform android-28 --verbose --gradle --release - ${ANDROID_SDK_ROOT}/build-tools/28.0.3/apksigner sign --in android-build/build/outputs/apk/release/android-build-release-unsigned.apk --out ${APK_BASENAME}-release-signed.apk --key cert.p8 --cert cert.cer --verbose + JAVA_HOME=${JAVA_HOME_8_X64} androiddeployqt --input android-Labrador-deployment-settings.json --output android-build --aab --android-platform android-31 --verbose --gradle --release + ${ANDROID_SDK_ROOT}/build-tools/31.0.0/apksigner sign --in android-build/build/outputs/apk/release/android-build-release-unsigned.apk --out ${APK_BASENAME}-release-signed.apk --key cert.p8 --cert cert.cer --verbose else qmake -config debug make -j$(nproc) make INSTALL_ROOT=android-build install - JAVA_HOME=${JAVA_HOME_8_X64} androiddeployqt --input android-libLabrador.so-deployment-settings.json --output android-build --android-platform android-28 --verbose --gradle + JAVA_HOME=${JAVA_HOME_8_X64} androiddeployqt --input android-Labrador-deployment-settings.json --output android-build --aab --android-platform android-31 --verbose --gradle cp android-build/build/outputs/apk/debug/android-build-debug.apk ${APK_BASENAME}-debug.apk fi + cp android-build/build/outputs/bundle/release/android-build-release.aab ${APK_BASENAME}-release-unsigned.aab - - name: Upload artifacts + - name: Upload apk artifacts uses: actions/upload-artifact@v4 with: name: asset-apk path: Desktop_Interface/Labrador*.apk compression-level: 0 if-no-files-found: error + - name: Upload aab artifacts + uses: actions/upload-artifact@v4 + with: + name: asset-aab + path: Desktop_Interface/Labrador*.aab + compression-level: 0 + if-no-files-found: error diff --git a/Desktop_Interface/Labrador.pro b/Desktop_Interface/Labrador.pro index 78c6e05d2..fc6d1b480 100644 --- a/Desktop_Interface/Labrador.pro +++ b/Desktop_Interface/Labrador.pro @@ -279,6 +279,7 @@ android { QT += androidextras CONFIG += mobility + CONFIG += android_app_bundle MOBILITY = DEFINES += PLATFORM_ANDROID @@ -287,13 +288,13 @@ android { INCLUDEPATH += build_android/libusb-242 ANDROID_PACKAGE_SOURCE_DIR = build_android/package_source - #ANDROID_MIN_SDK_VERSION = 21 - #ANDROID_TARGET_SDK_VERSION = 28 - ANDROID_SDK_BUILD_TOOLS_REVISION = 28.0.3 + ANDROID_MIN_SDK_VERSION = 21 + ANDROID_TARGET_SDK_VERSION = 31 + ANDROID_SDK_BUILD_TOOLS_REVISION = 31.0.0 # These are used in the AndroidManifest.xml template - ANDROID_VERSION_NAME = 1.3 - ANDROID_VERSION_CODE = 8 + ANDROID_VERSION_NAME = 1.4 + ANDROID_VERSION_CODE = 9 ANDROID_PERMISSIONS += android.permission.INTERNET ANDROID_PERMISSIONS += android.permission.WRITE_EXTERNAL_STORAGE ANDROID_PERMISSIONS += android.permission.READ_EXTERNAL_STORAGE @@ -307,13 +308,7 @@ android { INSTALLS += firmware waveforms #libdfuprog include - LIBS += -L$$PWD/build_android/libdfuprog/lib -ldfuprog-0.9 INCLUDEPATH += build_android/libdfuprog/include - ANDROID_EXTRA_LIBS += $${PWD}/build_android/libdfuprog/lib/libdfuprog-0.9.so - - #liblog include - LIBS += -L$$PWD/build_android/liblog/lib -llog - ANDROID_EXTRA_LIBS += $${PWD}/build_android/liblog/lib/liblog.so # Frequency spectrum/response disabled for now, needs UI and supporting libraries DEFINES += DISABLE_SPECTRUM @@ -321,12 +316,20 @@ android { HEADERS -= asyncdft.h # Library dependencies are only compiled for this ABI currently - ANDROID_ABIS = armeabi-v7a + ANDROID_ABIS = armeabi-v7a arm64-v8a # Doing the following inside one equals() failed. qmake bug? https://forum.qt.io/topic/113836/dynamic-libs-on-android-with-qt5-14-2/4 for(abi, ANDROID_ABIS): message("Building for Android ($${abi})") for(abi, ANDROID_ABIS): LIBS += -L$${PWD}/build_android/libusb-242/android/$${abi} -lusb1.0 for(abi, ANDROID_ABIS): ANDROID_EXTRA_LIBS += $${PWD}/build_android/libusb-242/android/$${abi}/libusb1.0.so + + #libdfuprog library + for(abi, ANDROID_ABIS): LIBS += -L$$PWD/build_android/libdfuprog/lib/$${abi} -ldfuprog-0.9 + for(abi, ANDROID_ABIS): ANDROID_EXTRA_LIBS += $${PWD}/build_android/libdfuprog/lib/$${abi}/libdfuprog-0.9.so + + #liblog library + for(abi, ANDROID_ABIS): LIBS += -L$$PWD/build_android/liblog/lib/$${abi} -llog + for(abi, ANDROID_ABIS): ANDROID_EXTRA_LIBS += $${PWD}/build_android/liblog/lib/$${abi}/liblog.so } DISTFILES += \ diff --git a/Desktop_Interface/androidusbdriver.cpp b/Desktop_Interface/androidusbdriver.cpp index e665cbb87..bef8ab13c 100644 --- a/Desktop_Interface/androidusbdriver.cpp +++ b/Desktop_Interface/androidusbdriver.cpp @@ -49,9 +49,10 @@ unsigned char androidUsbDriver::usbInit(unsigned long VIDin, unsigned long PIDin return E_BOARD_IN_BOOTLOADER; } + libusb_set_option(ctx, LIBUSB_OPTION_NO_DEVICE_DISCOVERY); int error = libusb_init(&ctx); if(error){ - qDebug() << "libusb_init FAILED"; + qDebug() << "libusb_init FAILED with error" << error; return error; } else qDebug() << "Libusb context initialised"; @@ -60,7 +61,7 @@ unsigned char androidUsbDriver::usbInit(unsigned long VIDin, unsigned long PIDin qDebug() << "Opening Device!"; //libusb_device * device_ptr = libusb_get_device2(ctx, usbfs_path); //error = libusb_open2(device_ptr, &handle, file_descriptor); - error = libusb_wrap_fd(ctx, file_descriptor, &handle); + error = libusb_wrap_sys_device(ctx, file_descriptor, &handle); if(error){ qDebug() << "ERROR OPENING DEVICE"; return error; @@ -121,7 +122,7 @@ int androidUsbDriver::get_new_bootloader_ctx(libusb_device **device_ptr, libusb_ //*(device_ptr) = libusb_get_device2(*(ctx), usbfs_path); //error = libusb_open2(*(device_ptr), handle, file_descriptor); - error = libusb_wrap_fd(*(ctx), file_descriptor, handle); + error = libusb_wrap_sys_device(*(ctx), file_descriptor, handle); if(error){ qDebug() << "ERROR OPENING DEVICE"; return error; diff --git a/Desktop_Interface/build_android/libdfuprog/lib/arm64-v8a/libdfuprog-0.9.so b/Desktop_Interface/build_android/libdfuprog/lib/arm64-v8a/libdfuprog-0.9.so new file mode 100755 index 000000000..30ed1c881 Binary files /dev/null and b/Desktop_Interface/build_android/libdfuprog/lib/arm64-v8a/libdfuprog-0.9.so differ diff --git a/Desktop_Interface/build_android/libdfuprog/lib/armeabi-v7a/libdfuprog-0.9.so b/Desktop_Interface/build_android/libdfuprog/lib/armeabi-v7a/libdfuprog-0.9.so new file mode 100755 index 000000000..f26cc9815 Binary files /dev/null and b/Desktop_Interface/build_android/libdfuprog/lib/armeabi-v7a/libdfuprog-0.9.so differ diff --git a/Desktop_Interface/build_android/liblog/lib/arm64-v8a/liblog.so b/Desktop_Interface/build_android/liblog/lib/arm64-v8a/liblog.so new file mode 100755 index 000000000..36cc24af2 Binary files /dev/null and b/Desktop_Interface/build_android/liblog/lib/arm64-v8a/liblog.so differ diff --git a/Desktop_Interface/build_android/liblog/lib/armeabi-v7a/liblog.so b/Desktop_Interface/build_android/liblog/lib/armeabi-v7a/liblog.so new file mode 100755 index 000000000..1f34f47d0 Binary files /dev/null and b/Desktop_Interface/build_android/liblog/lib/armeabi-v7a/liblog.so differ diff --git a/Desktop_Interface/build_android/libusb-242/android/arm64-v8a/libusb1.0.so b/Desktop_Interface/build_android/libusb-242/android/arm64-v8a/libusb1.0.so new file mode 100644 index 000000000..f7c15b2c9 Binary files /dev/null and b/Desktop_Interface/build_android/libusb-242/android/arm64-v8a/libusb1.0.so differ diff --git a/Desktop_Interface/build_android/libusb-242/android/armeabi-v7a/libusb1.0.so b/Desktop_Interface/build_android/libusb-242/android/armeabi-v7a/libusb1.0.so index 4236a9888..dc3df24b0 100755 Binary files a/Desktop_Interface/build_android/libusb-242/android/armeabi-v7a/libusb1.0.so and b/Desktop_Interface/build_android/libusb-242/android/armeabi-v7a/libusb1.0.so differ diff --git a/Desktop_Interface/build_android/libusb-242/libusb.h b/Desktop_Interface/build_android/libusb-242/libusb.h index 2294ef8bd..8542c6ac7 100644 --- a/Desktop_Interface/build_android/libusb-242/libusb.h +++ b/Desktop_Interface/build_android/libusb-242/libusb.h @@ -3,8 +3,9 @@ * Copyright © 2001 Johannes Erdfelt * Copyright © 2007-2008 Daniel Drake * Copyright © 2012 Pete Batard - * Copyright © 2012 Nathan Hjelm - * For more information, please visit: http://libusb.info + * Copyright © 2012-2023 Nathan Hjelm + * Copyright © 2014-2020 Chris Dickens + * For more information, please visit: https://libusb.info * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -24,65 +25,64 @@ #ifndef LIBUSB_H #define LIBUSB_H -#ifdef _MSC_VER +#if defined(_MSC_VER) +#pragma warning(push) +/* Disable: warning C4200: nonstandard extension used : zero-sized array in struct/union */ +#pragma warning(disable:4200) /* on MS environments, the inline keyword is available in C++ only */ #if !defined(__cplusplus) #define inline __inline #endif -/* ssize_t is also not available (copy/paste from MinGW) */ +/* ssize_t is also not available */ #ifndef _SSIZE_T_DEFINED #define _SSIZE_T_DEFINED -#undef ssize_t -#ifdef _WIN64 - typedef __int64 ssize_t; -#else - typedef int ssize_t; -#endif /* _WIN64 */ +#include +typedef SSIZE_T ssize_t; #endif /* _SSIZE_T_DEFINED */ #endif /* _MSC_VER */ -/* stdint.h is not available on older MSVC */ -#if defined(_MSC_VER) && (_MSC_VER < 1600) && (!defined(_STDINT)) && (!defined(_STDINT_H)) -typedef unsigned __int8 uint8_t; -typedef unsigned __int16 uint16_t; -typedef unsigned __int32 uint32_t; -#else +#include #include -#endif - -#if !defined(_WIN32_WCE) #include -#endif - -#if defined(__linux) || defined(__APPLE__) || defined(__CYGWIN__) || defined(__HAIKU__) +#if !defined(_MSC_VER) #include #endif - #include -#include + +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +#define LIBUSB_FLEXIBLE_ARRAY /* [] - valid C99 code */ +#else +#define LIBUSB_FLEXIBLE_ARRAY 0 /* [0] - non-standard, but usually working code */ +#endif /* __STDC_VERSION__ */ /* 'interface' might be defined as a macro on Windows, so we need to * undefine it so as not to break the current libusb API, because * libusb_config_descriptor has an 'interface' member * As this can be problematic if you include windows.h after libusb.h * in your sources, we force windows.h to be included first. */ -#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE) +#if defined(_WIN32) || defined(__CYGWIN__) #include #if defined(interface) #undef interface #endif -#if !defined(__CYGWIN__) -#include -#endif -#endif - -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) -#define LIBUSB_DEPRECATED_FOR(f) \ - __attribute__((deprecated("Use " #f " instead"))) +#endif /* _WIN32 || __CYGWIN__ */ + +#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) +#define LIBUSB_DEPRECATED_FOR(f) __attribute__ ((deprecated ("Use " #f " instead"))) +#elif defined(__GNUC__) && (__GNUC__ >= 3) +#define LIBUSB_DEPRECATED_FOR(f) __attribute__ ((deprecated)) +#elif defined(_MSC_VER) +#define LIBUSB_DEPRECATED_FOR(f) __declspec(deprecated("Use " #f " instead")) #else #define LIBUSB_DEPRECATED_FOR(f) #endif /* __GNUC__ */ +#if defined(__GNUC__) +#define LIBUSB_PACKED __attribute__ ((packed)) +#else +#define LIBUSB_PACKED +#endif /* __GNUC__ */ + /** \def LIBUSB_CALL * \ingroup libusb_misc * libusb's Windows calling convention. @@ -115,22 +115,27 @@ typedef unsigned __int32 uint32_t; * return type, before the function name. See internal documentation for * API_EXPORTED. */ -#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE) +#if defined(_WIN32) || defined(__CYGWIN__) #define LIBUSB_CALL WINAPI +#define LIBUSB_CALLV WINAPIV #else #define LIBUSB_CALL -#endif +#define LIBUSB_CALLV +#endif /* _WIN32 || __CYGWIN__ */ /** \def LIBUSB_API_VERSION * \ingroup libusb_misc * libusb's API version. * - * Since version 1.0.13, to help with feature detection, libusb defines + * Since version 1.0.18, to help with feature detection, libusb defines * a LIBUSB_API_VERSION macro that gets increased every time there is a * significant change to the API, such as the introduction of a new call, * the definition of a new macro/enum member, or any other element that * libusb applications may want to detect at compilation time. * + * Between versions 1.0.13 and 1.0.17 (inclusive) the older spelling of + * LIBUSBX_API_VERSION was used. + * * The macro is typically used in an application as follows: * \code * #if defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x01001234) @@ -140,13 +145,40 @@ typedef unsigned __int32 uint32_t; * * Internally, LIBUSB_API_VERSION is defined as follows: * (libusb major << 24) | (libusb minor << 16) | (16 bit incremental) + * + * The incremental component has changed as follows: + *
    + *
  • libusbx version 1.0.13: LIBUSBX_API_VERSION = 0x01000100 + *
  • libusbx version 1.0.14: LIBUSBX_API_VERSION = 0x010000FF + *
  • libusbx version 1.0.15: LIBUSBX_API_VERSION = 0x01000101 + *
  • libusbx version 1.0.16: LIBUSBX_API_VERSION = 0x01000102 + *
  • libusbx version 1.0.17: LIBUSBX_API_VERSION = 0x01000102 + *
  • libusb version 1.0.18: LIBUSB_API_VERSION = 0x01000102 + *
  • libusb version 1.0.19: LIBUSB_API_VERSION = 0x01000103 + *
  • libusb version 1.0.20: LIBUSB_API_VERSION = 0x01000104 + *
  • libusb version 1.0.21: LIBUSB_API_VERSION = 0x01000105 + *
  • libusb version 1.0.22: LIBUSB_API_VERSION = 0x01000106 + *
  • libusb version 1.0.23: LIBUSB_API_VERSION = 0x01000107 + *
  • libusb version 1.0.24: LIBUSB_API_VERSION = 0x01000108 + *
  • libusb version 1.0.25: LIBUSB_API_VERSION = 0x01000109 + *
  • libusb version 1.0.26: LIBUSB_API_VERSION = 0x01000109 + *
  • libusb version 1.0.27: LIBUSB_API_VERSION = 0x0100010A + *
  • libusb version 1.0.28: LIBUSB_API_VERSION = 0x0100010A + *
  • libusb version 1.0.29: LIBUSB_API_VERSION = 0x0100010B + *
  • libusb version 1.0.30: LIBUSB_API_VERSION = 0x0100010C + *
*/ -#define LIBUSB_API_VERSION 0x01000105 +#define LIBUSB_API_VERSION 0x0100010C -/* The following is kept for compatibility, but will be deprecated in the future */ +/** \def LIBUSBX_API_VERSION + * \ingroup libusb_misc + * + * This is the older spelling, kept for backwards compatibility of code + * needing to test for older library versions where the newer spelling + * did not exist. */ #define LIBUSBX_API_VERSION LIBUSB_API_VERSION -#ifdef __cplusplus +#if defined(__cplusplus) extern "C" { #endif @@ -158,7 +190,7 @@ extern "C" { * \param x the host-endian value to convert * \returns the value in little-endian byte order */ -static inline uint16_t libusb_cpu_to_le16(const uint16_t x) +static inline uint16_t libusb_cpu_to_le16(uint16_t x) { union { uint8_t b8[2]; @@ -188,35 +220,35 @@ enum libusb_class_code { * this bDeviceClass value indicates that each interface specifies its * own class information and all interfaces operate independently. */ - LIBUSB_CLASS_PER_INTERFACE = 0, + LIBUSB_CLASS_PER_INTERFACE = 0x00, /** Audio class */ - LIBUSB_CLASS_AUDIO = 1, + LIBUSB_CLASS_AUDIO = 0x01, /** Communications class */ - LIBUSB_CLASS_COMM = 2, + LIBUSB_CLASS_COMM = 0x02, /** Human Interface Device class */ - LIBUSB_CLASS_HID = 3, + LIBUSB_CLASS_HID = 0x03, /** Physical */ - LIBUSB_CLASS_PHYSICAL = 5, - - /** Printer class */ - LIBUSB_CLASS_PRINTER = 7, + LIBUSB_CLASS_PHYSICAL = 0x05, /** Image class */ - LIBUSB_CLASS_PTP = 6, /* legacy name from libusb-0.1 usb.h */ - LIBUSB_CLASS_IMAGE = 6, + LIBUSB_CLASS_IMAGE = 0x06, + LIBUSB_CLASS_PTP = 0x06, /* legacy name from libusb-0.1 usb.h */ + + /** Printer class */ + LIBUSB_CLASS_PRINTER = 0x07, /** Mass storage class */ - LIBUSB_CLASS_MASS_STORAGE = 8, + LIBUSB_CLASS_MASS_STORAGE = 0x08, /** Hub class */ - LIBUSB_CLASS_HUB = 9, + LIBUSB_CLASS_HUB = 0x09, /** Data class */ - LIBUSB_CLASS_DATA = 10, + LIBUSB_CLASS_DATA = 0x0a, /** Smart Card */ LIBUSB_CLASS_SMART_CARD = 0x0b, @@ -236,6 +268,9 @@ enum libusb_class_code { /** Wireless class */ LIBUSB_CLASS_WIRELESS = 0xe0, + /** Miscellaneous class */ + LIBUSB_CLASS_MISCELLANEOUS = 0xef, + /** Application class */ LIBUSB_CLASS_APPLICATION = 0xfe, @@ -261,6 +296,10 @@ enum libusb_descriptor_type { /** Endpoint descriptor. See libusb_endpoint_descriptor. */ LIBUSB_DT_ENDPOINT = 0x05, + /** Interface Association Descriptor. + * See libusb_interface_association_descriptor */ + LIBUSB_DT_INTERFACE_ASSOCIATION = 0x0b, + /** BOS descriptor */ LIBUSB_DT_BOS = 0x0f, @@ -296,19 +335,23 @@ enum libusb_descriptor_type { #define LIBUSB_DT_SS_ENDPOINT_COMPANION_SIZE 6 #define LIBUSB_DT_BOS_SIZE 5 #define LIBUSB_DT_DEVICE_CAPABILITY_SIZE 3 +#define LIBUSB_DT_INTERFACE_ASSOCIATION_SIZE 8 /* BOS descriptor sizes */ #define LIBUSB_BT_USB_2_0_EXTENSION_SIZE 7 #define LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE 10 +#define LIBUSB_BT_SSPLUS_USB_DEVICE_CAPABILITY_SIZE 12 #define LIBUSB_BT_CONTAINER_ID_SIZE 20 +#define LIBUSB_BT_PLATFORM_DESCRIPTOR_MIN_SIZE 20 /* We unwrap the BOS => define its max size */ -#define LIBUSB_DT_BOS_MAX_SIZE ((LIBUSB_DT_BOS_SIZE) +\ - (LIBUSB_BT_USB_2_0_EXTENSION_SIZE) +\ - (LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE) +\ - (LIBUSB_BT_CONTAINER_ID_SIZE)) +#define LIBUSB_DT_BOS_MAX_SIZE \ + (LIBUSB_DT_BOS_SIZE + \ + LIBUSB_BT_USB_2_0_EXTENSION_SIZE + \ + LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE + \ + LIBUSB_BT_CONTAINER_ID_SIZE) -#define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */ +#define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */ #define LIBUSB_ENDPOINT_DIR_MASK 0x80 /** \ingroup libusb_desc @@ -316,34 +359,31 @@ enum libusb_descriptor_type { * \ref libusb_endpoint_descriptor::bEndpointAddress "endpoint address" scheme. */ enum libusb_endpoint_direction { - /** In: device-to-host */ - LIBUSB_ENDPOINT_IN = 0x80, - /** Out: host-to-device */ - LIBUSB_ENDPOINT_OUT = 0x00 + LIBUSB_ENDPOINT_OUT = 0x00, + + /** In: device-to-host */ + LIBUSB_ENDPOINT_IN = 0x80 }; -#define LIBUSB_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */ +#define LIBUSB_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */ /** \ingroup libusb_desc * Endpoint transfer type. Values for bits 0:1 of the * \ref libusb_endpoint_descriptor::bmAttributes "endpoint attributes" field. */ -enum libusb_transfer_type { +enum libusb_endpoint_transfer_type { /** Control endpoint */ - LIBUSB_TRANSFER_TYPE_CONTROL = 0, + LIBUSB_ENDPOINT_TRANSFER_TYPE_CONTROL = 0x0, /** Isochronous endpoint */ - LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1, + LIBUSB_ENDPOINT_TRANSFER_TYPE_ISOCHRONOUS = 0x1, /** Bulk endpoint */ - LIBUSB_TRANSFER_TYPE_BULK = 2, + LIBUSB_ENDPOINT_TRANSFER_TYPE_BULK = 0x2, /** Interrupt endpoint */ - LIBUSB_TRANSFER_TYPE_INTERRUPT = 3, - - /** Stream endpoint */ - LIBUSB_TRANSFER_TYPE_BULK_STREAM = 4, + LIBUSB_ENDPOINT_TRANSFER_TYPE_INTERRUPT = 0x3 }; /** \ingroup libusb_misc @@ -378,20 +418,20 @@ enum libusb_standard_request { LIBUSB_REQUEST_SET_CONFIGURATION = 0x09, /** Return the selected alternate setting for the specified interface */ - LIBUSB_REQUEST_GET_INTERFACE = 0x0A, + LIBUSB_REQUEST_GET_INTERFACE = 0x0a, /** Select an alternate interface for the specified interface */ - LIBUSB_REQUEST_SET_INTERFACE = 0x0B, + LIBUSB_REQUEST_SET_INTERFACE = 0x0b, /** Set then report an endpoint's synchronization frame */ - LIBUSB_REQUEST_SYNCH_FRAME = 0x0C, + LIBUSB_REQUEST_SYNCH_FRAME = 0x0c, /** Sets both the U1 and U2 Exit Latency */ LIBUSB_REQUEST_SET_SEL = 0x30, /** Delay from the time a host transmits a packet to the time it is * received by the device. */ - LIBUSB_SET_ISOCH_DELAY = 0x31, + LIBUSB_SET_ISOCH_DELAY = 0x31 }; /** \ingroup libusb_misc @@ -427,10 +467,10 @@ enum libusb_request_recipient { LIBUSB_RECIPIENT_ENDPOINT = 0x02, /** Other */ - LIBUSB_RECIPIENT_OTHER = 0x03, + LIBUSB_RECIPIENT_OTHER = 0x03 }; -#define LIBUSB_ISO_SYNC_TYPE_MASK 0x0C +#define LIBUSB_ISO_SYNC_TYPE_MASK 0x0c /** \ingroup libusb_desc * Synchronization type for isochronous endpoints. Values for bits 2:3 of the @@ -439,19 +479,19 @@ enum libusb_request_recipient { */ enum libusb_iso_sync_type { /** No synchronization */ - LIBUSB_ISO_SYNC_TYPE_NONE = 0, + LIBUSB_ISO_SYNC_TYPE_NONE = 0x0, /** Asynchronous */ - LIBUSB_ISO_SYNC_TYPE_ASYNC = 1, + LIBUSB_ISO_SYNC_TYPE_ASYNC = 0x1, /** Adaptive */ - LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2, + LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 0x2, /** Synchronous */ - LIBUSB_ISO_SYNC_TYPE_SYNC = 3 + LIBUSB_ISO_SYNC_TYPE_SYNC = 0x3 }; -#define LIBUSB_ISO_USAGE_TYPE_MASK 0x30 +#define LIBUSB_ISO_USAGE_TYPE_MASK 0x30 /** \ingroup libusb_desc * Usage type for isochronous endpoints. Values for bits 4:5 of the @@ -460,13 +500,74 @@ enum libusb_iso_sync_type { */ enum libusb_iso_usage_type { /** Data endpoint */ - LIBUSB_ISO_USAGE_TYPE_DATA = 0, + LIBUSB_ISO_USAGE_TYPE_DATA = 0x0, /** Feedback endpoint */ - LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1, + LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 0x1, /** Implicit feedback Data endpoint */ - LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2, + LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 0x2 +}; + +/** \ingroup libusb_desc + * Supported speeds (wSpeedSupported) bitfield. Indicates what + * speeds the device supports. + */ +enum libusb_supported_speed { + /** Low speed operation supported (1.5MBit/s). */ + LIBUSB_LOW_SPEED_OPERATION = (1 << 0), + + /** Full speed operation supported (12MBit/s). */ + LIBUSB_FULL_SPEED_OPERATION = (1 << 1), + + /** High speed operation supported (480MBit/s). */ + LIBUSB_HIGH_SPEED_OPERATION = (1 << 2), + + /** Superspeed operation supported (5000MBit/s). */ + LIBUSB_SUPER_SPEED_OPERATION = (1 << 3) +}; + +/** \ingroup libusb_desc + * Masks for the bits of the + * \ref libusb_usb_2_0_extension_descriptor::bmAttributes "bmAttributes" field + * of the USB 2.0 Extension descriptor. + */ +enum libusb_usb_2_0_extension_attributes { + /** Supports Link Power Management (LPM) */ + LIBUSB_BM_LPM_SUPPORT = (1 << 1) +}; + +/** \ingroup libusb_desc + * Masks for the bits of the + * \ref libusb_ss_usb_device_capability_descriptor::bmAttributes "bmAttributes" field + * field of the SuperSpeed USB Device Capability descriptor. + */ +enum libusb_ss_usb_device_capability_attributes { + /** Supports Latency Tolerance Messages (LTM) */ + LIBUSB_BM_LTM_SUPPORT = (1 << 1) +}; + +/** \ingroup libusb_desc + * USB capability types + */ +enum libusb_bos_type { + /** Wireless USB device capability */ + LIBUSB_BT_WIRELESS_USB_DEVICE_CAPABILITY = 0x01, + + /** USB 2.0 extensions */ + LIBUSB_BT_USB_2_0_EXTENSION = 0x02, + + /** SuperSpeed USB device capability */ + LIBUSB_BT_SS_USB_DEVICE_CAPABILITY = 0x03, + + /** Container ID type */ + LIBUSB_BT_CONTAINER_ID = 0x04, + + /** Platform descriptor */ + LIBUSB_BT_PLATFORM_DESCRIPTOR = 0x05, + + /** SuperSpeedPlus device capability */ + LIBUSB_BT_SUPERSPEED_PLUS_CAPABILITY = 0x0A, }; /** \ingroup libusb_desc @@ -539,17 +640,15 @@ struct libusb_endpoint_descriptor { /** The address of the endpoint described by this descriptor. Bits 0:3 are * the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction, - * see \ref libusb_endpoint_direction. - */ + * see \ref libusb_endpoint_direction. */ uint8_t bEndpointAddress; /** Attributes which apply to the endpoint when it is configured using * the bConfigurationValue. Bits 0:1 determine the transfer type and - * correspond to \ref libusb_transfer_type. Bits 2:3 are only used for - * isochronous endpoints and correspond to \ref libusb_iso_sync_type. + * correspond to \ref libusb_endpoint_transfer_type. Bits 2:3 are only used + * for isochronous endpoints and correspond to \ref libusb_iso_sync_type. * Bits 4:5 are also only used for isochronous endpoints and correspond to - * \ref libusb_iso_usage_type. Bits 6:7 are reserved. - */ + * \ref libusb_iso_usage_type. Bits 6:7 are reserved. */ uint8_t bmAttributes; /** Maximum packet size this endpoint is capable of sending/receiving. */ @@ -569,10 +668,69 @@ struct libusb_endpoint_descriptor { * it will store them here, should you wish to parse them. */ const unsigned char *extra; - /** Length of the extra descriptors, in bytes. */ + /** Length of the extra descriptors, in bytes. Must be non-negative. */ int extra_length; }; +/** \ingroup libusb_desc + * A structure representing the standard USB interface association descriptor. + * This descriptor is documented in section 9.6.4 of the USB 3.0 specification. + * All multiple-byte fields are represented in host-endian format. + */ +struct libusb_interface_association_descriptor { + /** Size of this descriptor (in bytes) */ + uint8_t bLength; + + /** Descriptor type. Will have value + * \ref libusb_descriptor_type::LIBUSB_DT_INTERFACE_ASSOCIATION + * LIBUSB_DT_INTERFACE_ASSOCIATION in this context. */ + uint8_t bDescriptorType; + + /** Interface number of the first interface that is associated + * with this function */ + uint8_t bFirstInterface; + + /** Number of contiguous interfaces that are associated with + * this function */ + uint8_t bInterfaceCount; + + /** USB-IF class code for this function. + * A value of zero is not allowed in this descriptor. + * If this field is 0xff, the function class is vendor-specific. + * All other values are reserved for assignment by the USB-IF. + */ + uint8_t bFunctionClass; + + /** USB-IF subclass code for this function. + * If this field is not set to 0xff, all values are reserved + * for assignment by the USB-IF + */ + uint8_t bFunctionSubClass; + + /** USB-IF protocol code for this function. + * These codes are qualified by the values of the bFunctionClass + * and bFunctionSubClass fields. + */ + uint8_t bFunctionProtocol; + + /** Index of string descriptor describing this function */ + uint8_t iFunction; +}; + +/** \ingroup libusb_desc + * Structure containing an array of 0 or more interface association + * descriptors + */ +struct libusb_interface_association_descriptor_array { + /** Array of interface association descriptors. The size of this array + * is determined by the length field. + */ + const struct libusb_interface_association_descriptor *iad; + + /** Number of interface association descriptors contained. Read-only. */ + int length; +}; + /** \ingroup libusb_desc * A structure representing the standard USB interface descriptor. This * descriptor is documented in section 9.6.5 of the USB 3.0 specification. @@ -619,7 +777,7 @@ struct libusb_interface_descriptor { * it will store them here, should you wish to parse them. */ const unsigned char *extra; - /** Length of the extra descriptors, in bytes. */ + /** Length of the extra descriptors, in bytes. Must be non-negative. */ int extra_length; }; @@ -631,7 +789,8 @@ struct libusb_interface { * by the num_altsetting field. */ const struct libusb_interface_descriptor *altsetting; - /** The number of alternate settings that belong to this interface */ + /** The number of alternate settings that belong to this interface. + * Must be non-negative. */ int num_altsetting; }; @@ -678,7 +837,7 @@ struct libusb_config_descriptor { * descriptors, it will store them here, should you wish to parse them. */ const unsigned char *extra; - /** Length of the extra descriptors, in bytes. */ + /** Length of the extra descriptors, in bytes. Must be non-negative. */ int extra_length; }; @@ -689,7 +848,6 @@ struct libusb_config_descriptor { * host-endian format. */ struct libusb_ss_endpoint_companion_descriptor { - /** Size of this descriptor (in bytes) */ uint8_t bLength; @@ -698,19 +856,18 @@ struct libusb_ss_endpoint_companion_descriptor { * this context. */ uint8_t bDescriptorType; - /** The maximum number of packets the endpoint can send or * receive as part of a burst. */ uint8_t bMaxBurst; - /** In bulk EP: bits 4:0 represents the maximum number of - * streams the EP supports. In isochronous EP: bits 1:0 - * represents the Mult - a zero based value that determines - * the maximum number of packets within a service interval */ + /** In bulk EP: bits 4:0 represents the maximum number of + * streams the EP supports. In isochronous EP: bits 1:0 + * represents the Mult - a zero based value that determines + * the maximum number of packets within a service interval */ uint8_t bmAttributes; - /** The total number of bytes this EP will transfer every - * service interval. valid only for periodic EPs. */ + /** The total number of bytes this EP will transfer every + * service interval. Valid only for periodic EPs. */ uint16_t wBytesPerInterval; }; @@ -721,21 +878,18 @@ struct libusb_ss_endpoint_companion_descriptor { */ struct libusb_bos_dev_capability_descriptor { /** Size of this descriptor (in bytes) */ - uint8_t bLength; + uint8_t bLength; + /** Descriptor type. Will have value * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY * LIBUSB_DT_DEVICE_CAPABILITY in this context. */ - uint8_t bDescriptorType; + uint8_t bDescriptorType; + /** Device Capability type */ - uint8_t bDevCapabilityType; + uint8_t bDevCapabilityType; + /** Device Capability data (bLength - 3 bytes) */ - uint8_t dev_capability_data -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) - [] /* valid C99 code */ -#else - [0] /* non-standard, but usually working code */ -#endif - ; + uint8_t dev_capability_data[LIBUSB_FLEXIBLE_ARRAY]; }; /** \ingroup libusb_desc @@ -760,13 +914,7 @@ struct libusb_bos_descriptor { uint8_t bNumDeviceCaps; /** bNumDeviceCap Device Capability Descriptors */ - struct libusb_bos_dev_capability_descriptor *dev_capability -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) - [] /* valid C99 code */ -#else - [0] /* non-standard, but usually working code */ -#endif - ; + struct libusb_bos_dev_capability_descriptor *dev_capability[LIBUSB_FLEXIBLE_ARRAY]; }; /** \ingroup libusb_desc @@ -784,7 +932,7 @@ struct libusb_usb_2_0_extension_descriptor { uint8_t bDescriptorType; /** Capability type. Will have value - * \ref libusb_capability_type::LIBUSB_BT_USB_2_0_EXTENSION + * \ref libusb_bos_type::LIBUSB_BT_USB_2_0_EXTENSION * LIBUSB_BT_USB_2_0_EXTENSION in this context. */ uint8_t bDevCapabilityType; @@ -792,7 +940,7 @@ struct libusb_usb_2_0_extension_descriptor { * A value of one in a bit location indicates a feature is * supported; a value of zero indicates it is not supported. * See \ref libusb_usb_2_0_extension_attributes. */ - uint32_t bmAttributes; + uint32_t bmAttributes; }; /** \ingroup libusb_desc @@ -810,7 +958,7 @@ struct libusb_ss_usb_device_capability_descriptor { uint8_t bDescriptorType; /** Capability type. Will have value - * \ref libusb_capability_type::LIBUSB_BT_SS_USB_DEVICE_CAPABILITY + * \ref libusb_bos_type::LIBUSB_BT_SS_USB_DEVICE_CAPABILITY * LIBUSB_BT_SS_USB_DEVICE_CAPABILITY in this context. */ uint8_t bDevCapabilityType; @@ -837,6 +985,100 @@ struct libusb_ss_usb_device_capability_descriptor { uint16_t bU2DevExitLat; }; +/** \ingroup libusb_desc + * enum used in \ref libusb_ssplus_sublink_attribute + */ +enum libusb_superspeedplus_sublink_attribute_sublink_type { + LIBUSB_SSPLUS_ATTR_TYPE_SYM = 0, + LIBUSB_SSPLUS_ATTR_TYPE_ASYM = 1, +}; + +/** \ingroup libusb_desc + * enum used in \ref libusb_ssplus_sublink_attribute + */ +enum libusb_superspeedplus_sublink_attribute_sublink_direction { + LIBUSB_SSPLUS_ATTR_DIR_RX = 0, + LIBUSB_SSPLUS_ATTR_DIR_TX = 1, +}; + +/** \ingroup libusb_desc + * enum used in \ref libusb_ssplus_sublink_attribute + * Bit = Bits per second + * Kb = Kbps + * Mb = Mbps + * Gb = Gbps + */ +enum libusb_superspeedplus_sublink_attribute_exponent { + LIBUSB_SSPLUS_ATTR_EXP_BPS = 0, + LIBUSB_SSPLUS_ATTR_EXP_KBS = 1, + LIBUSB_SSPLUS_ATTR_EXP_MBS = 2, + LIBUSB_SSPLUS_ATTR_EXP_GBS = 3, +}; + +/** \ingroup libusb_desc + * enum used in \ref libusb_ssplus_sublink_attribute + */ +enum libusb_superspeedplus_sublink_attribute_link_protocol { + LIBUSB_SSPLUS_ATTR_PROT_SS = 0, + LIBUSB_SSPLUS_ATTR_PROT_SSPLUS = 1, +}; + +/** \ingroup libusb_desc + * Expose \ref libusb_ssplus_usb_device_capability_descriptor.sublinkSpeedAttributes + */ +struct libusb_ssplus_sublink_attribute { + /** Sublink Speed Attribute ID (SSID). + This field is an ID that uniquely identifies the speed of this sublink */ + uint8_t ssid; + + /** This field defines the + base 10 exponent times 3, that shall be applied to the + mantissa. */ + enum libusb_superspeedplus_sublink_attribute_exponent exponent; + + /** This field identifies whether the + Sublink Speed Attribute defines a symmetric or + asymmetric bit rate.*/ + enum libusb_superspeedplus_sublink_attribute_sublink_type type; + + /** This field indicates if this + Sublink Speed Attribute defines the receive or + transmit bit rate. */ + enum libusb_superspeedplus_sublink_attribute_sublink_direction direction; + + /** This field identifies the protocol + supported by the link. */ + enum libusb_superspeedplus_sublink_attribute_link_protocol protocol; + + /** This field defines the mantissa that shall be applied to the exponent when + calculating the maximum bit rate. */ + uint16_t mantissa; +}; + +/** \ingroup libusb_desc + * A structure representing the SuperSpeedPlus descriptor + * This descriptor is documented in section 9.6.2.5 of the USB 3.1 specification. + */ +struct libusb_ssplus_usb_device_capability_descriptor { + /** Sublink Speed Attribute Count */ + uint8_t numSublinkSpeedAttributes; + + /** Sublink Speed ID Count */ + uint8_t numSublinkSpeedIDs; + + /** Unique ID to indicates the minimum lane speed */ + uint8_t ssid; + + /** This field indicates the minimum receive lane count.*/ + uint8_t minRxLaneCount; + + /** This field indicates the minimum transmit lane count*/ + uint8_t minTxLaneCount; + + /** Array size is \ref libusb_ssplus_usb_device_capability_descriptor.numSublinkSpeedAttributes */ + struct libusb_ssplus_sublink_attribute sublinkSpeedAttributes[]; +}; + /** \ingroup libusb_desc * A structure representing the Container ID descriptor. * This descriptor is documented in section 9.6.2.3 of the USB 3.0 specification. @@ -852,19 +1094,50 @@ struct libusb_container_id_descriptor { uint8_t bDescriptorType; /** Capability type. Will have value - * \ref libusb_capability_type::LIBUSB_BT_CONTAINER_ID + * \ref libusb_bos_type::LIBUSB_BT_CONTAINER_ID * LIBUSB_BT_CONTAINER_ID in this context. */ uint8_t bDevCapabilityType; /** Reserved field */ - uint8_t bReserved; + uint8_t bReserved; /** 128 bit UUID */ uint8_t ContainerID[16]; }; +/** \ingroup libusb_desc + * A structure representing a Platform descriptor. + * This descriptor is documented in section 9.6.2.4 of the USB 3.2 specification. + */ +struct libusb_platform_descriptor { + /** Size of this descriptor (in bytes) */ + uint8_t bLength; + + /** Descriptor type. Will have value + * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY + * LIBUSB_DT_DEVICE_CAPABILITY in this context. */ + uint8_t bDescriptorType; + + /** Capability type. Will have value + * \ref libusb_bos_type::LIBUSB_BT_PLATFORM_DESCRIPTOR + * LIBUSB_BT_CONTAINER_ID in this context. */ + uint8_t bDevCapabilityType; + + /** Reserved field */ + uint8_t bReserved; + + /** 128 bit UUID */ + uint8_t PlatformCapabilityUUID[16]; + + /** Capability data (bLength - 20) */ + uint8_t CapabilityData[LIBUSB_FLEXIBLE_ARRAY]; +}; + /** \ingroup libusb_asyncio * Setup packet for control transfers. */ +#if defined(_MSC_VER) || defined(__WATCOMC__) +#pragma pack(push, 1) +#endif struct libusb_control_setup { /** Request type. Bits 0:4 determine recipient, see * \ref libusb_request_recipient. Bits 5:6 determine type, see @@ -889,7 +1162,10 @@ struct libusb_control_setup { /** Number of bytes to transfer */ uint16_t wLength; -}; +} LIBUSB_PACKED; +#if defined(_MSC_VER) || defined(__WATCOMC__) +#pragma pack(pop) +#endif #define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup)) @@ -904,22 +1180,22 @@ struct libusb_device_handle; */ struct libusb_version { /** Library major version. */ - const uint16_t major; + uint16_t major; /** Library minor version. */ - const uint16_t minor; + uint16_t minor; /** Library micro version. */ - const uint16_t micro; + uint16_t micro; /** Library nano version. */ - const uint16_t nano; + uint16_t nano; /** Library release candidate suffix string, e.g. "-rc4". */ const char *rc; /** For ABI compatibility only. */ - const char* describe; + const char *describe; }; /** \ingroup libusb_lib @@ -927,15 +1203,16 @@ struct libusb_version { * sessions allows for your program to use two libraries (or dynamically * load two modules) which both independently use libusb. This will prevent * interference between the individual libusb users - for example - * libusb_set_debug() will not affect the other user of the library, and + * libusb_set_option() will not affect the other user of the library, and * libusb_exit() will not destroy resources that the other user is still * using. * - * Sessions are created by libusb_init() and destroyed through libusb_exit(). + * Sessions are created by libusb_init_context() and destroyed through libusb_exit(). * If your application is guaranteed to only ever include a single libusb * user (i.e. you), you do not have to worry about contexts: pass NULL in - * every function call where a context is required. The default context - * will be used. + * every function call where a context is required, and the default context + * will be used. Note that libusb_set_option(NULL, ...) is special, and adds + * an option to a list of default options for new contexts. * * For more information, see \ref libusb_contexts. */ @@ -944,7 +1221,7 @@ typedef struct libusb_context libusb_context; /** \ingroup libusb_dev * Structure representing a USB device detected on the system. This is an * opaque type for which you are only ever provided with a pointer, usually - * originating from libusb_get_device_list(). + * originating from libusb_get_device_list() or libusb_hotplug_register_callback(). * * Certain operations can be performed on a device, but in order to do any * I/O you will have to first obtain a device handle using libusb_open(). @@ -987,61 +1264,12 @@ enum libusb_speed { /** The device is operating at super speed (5000MBit/s). */ LIBUSB_SPEED_SUPER = 4, -}; - -/** \ingroup libusb_dev - * Supported speeds (wSpeedSupported) bitfield. Indicates what - * speeds the device supports. - */ -enum libusb_supported_speed { - /** Low speed operation supported (1.5MBit/s). */ - LIBUSB_LOW_SPEED_OPERATION = 1, - /** Full speed operation supported (12MBit/s). */ - LIBUSB_FULL_SPEED_OPERATION = 2, - - /** High speed operation supported (480MBit/s). */ - LIBUSB_HIGH_SPEED_OPERATION = 4, - - /** Superspeed operation supported (5000MBit/s). */ - LIBUSB_SUPER_SPEED_OPERATION = 8, -}; + /** The device is operating at super speed plus (10000MBit/s). */ + LIBUSB_SPEED_SUPER_PLUS = 5, -/** \ingroup libusb_dev - * Masks for the bits of the - * \ref libusb_usb_2_0_extension_descriptor::bmAttributes "bmAttributes" field - * of the USB 2.0 Extension descriptor. - */ -enum libusb_usb_2_0_extension_attributes { - /** Supports Link Power Management (LPM) */ - LIBUSB_BM_LPM_SUPPORT = 2, -}; - -/** \ingroup libusb_dev - * Masks for the bits of the - * \ref libusb_ss_usb_device_capability_descriptor::bmAttributes "bmAttributes" field - * field of the SuperSpeed USB Device Capability descriptor. - */ -enum libusb_ss_usb_device_capability_attributes { - /** Supports Latency Tolerance Messages (LTM) */ - LIBUSB_BM_LTM_SUPPORT = 2, -}; - -/** \ingroup libusb_dev - * USB capability types - */ -enum libusb_bos_type { - /** Wireless USB device capability */ - LIBUSB_BT_WIRELESS_USB_DEVICE_CAPABILITY = 1, - - /** USB 2.0 extensions */ - LIBUSB_BT_USB_2_0_EXTENSION = 2, - - /** SuperSpeed USB device capability */ - LIBUSB_BT_SS_USB_DEVICE_CAPABILITY = 3, - - /** Container ID type */ - LIBUSB_BT_CONTAINER_ID = 4, + /** The device is operating at super speed plus x2 (20000MBit/s). */ + LIBUSB_SPEED_SUPER_PLUS_X2 = 6, }; /** \ingroup libusb_misc @@ -1095,12 +1323,31 @@ enum libusb_error { message strings in strerror.c when adding new error codes here. */ /** Other error */ - LIBUSB_ERROR_OTHER = -99, + LIBUSB_ERROR_OTHER = -99 }; /* Total number of error codes in enum libusb_error */ #define LIBUSB_ERROR_COUNT 14 +/** \ingroup libusb_asyncio + * Transfer type */ +enum libusb_transfer_type { + /** Control transfer */ + LIBUSB_TRANSFER_TYPE_CONTROL = 0U, + + /** Isochronous transfer */ + LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1U, + + /** Bulk transfer */ + LIBUSB_TRANSFER_TYPE_BULK = 2U, + + /** Interrupt transfer */ + LIBUSB_TRANSFER_TYPE_INTERRUPT = 3U, + + /** Bulk stream transfer */ + LIBUSB_TRANSFER_TYPE_BULK_STREAM = 4U +}; + /** \ingroup libusb_asyncio * Transfer status codes */ enum libusb_transfer_status { @@ -1125,7 +1372,7 @@ enum libusb_transfer_status { LIBUSB_TRANSFER_NO_DEVICE, /** Device sent more data than requested */ - LIBUSB_TRANSFER_OVERFLOW, + LIBUSB_TRANSFER_OVERFLOW /* NB! Remember to update libusb_error_name() when adding new status codes here. */ @@ -1135,19 +1382,19 @@ enum libusb_transfer_status { * libusb_transfer.flags values */ enum libusb_transfer_flags { /** Report short frames as errors */ - LIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0, + LIBUSB_TRANSFER_SHORT_NOT_OK = (1U << 0), /** Automatically free() transfer buffer during libusb_free_transfer(). * Note that buffers allocated with libusb_dev_mem_alloc() should not * be attempted freed in this way, since free() is not an appropriate * way to release such memory. */ - LIBUSB_TRANSFER_FREE_BUFFER = 1<<1, + LIBUSB_TRANSFER_FREE_BUFFER = (1U << 1), /** Automatically call libusb_free_transfer() after callback returns. * If this flag is set, it is illegal to call libusb_free_transfer() * from your transfer callback, as this will result in a double-free * when this flag is acted upon. */ - LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2, + LIBUSB_TRANSFER_FREE_TRANSFER = (1U << 2), /** Terminate transfers that are a multiple of the endpoint's * wMaxPacketSize with an extra zero length packet. This is useful @@ -1168,11 +1415,12 @@ enum libusb_transfer_flags { * * This flag is currently only supported on Linux. * On other systems, libusb_submit_transfer() will return - * LIBUSB_ERROR_NOT_SUPPORTED for every transfer where this flag is set. + * \ref LIBUSB_ERROR_NOT_SUPPORTED for every transfer where this + * flag is set. * * Available since libusb-1.0.9. */ - LIBUSB_TRANSFER_ADD_ZERO_PACKET = 1 << 3, + LIBUSB_TRANSFER_ADD_ZERO_PACKET = (1U << 3) }; /** \ingroup libusb_asyncio @@ -1217,10 +1465,10 @@ struct libusb_transfer { /** Address of the endpoint where this transfer will be sent. */ unsigned char endpoint; - /** Type of the endpoint from \ref libusb_transfer_type */ + /** Type of the transfer from \ref libusb_transfer_type */ unsigned char type; - /** Timeout for this transfer in millseconds. A value of 0 indicates no + /** Timeout for this transfer in milliseconds. A value of 0 indicates no * timeout. */ unsigned int timeout; @@ -1233,7 +1481,7 @@ struct libusb_transfer { * to determine if errors occurred. */ enum libusb_transfer_status status; - /** Length of the data buffer */ + /** Length of the data buffer. Must be non-negative. */ int length; /** Actual length of data that was transferred. Read-only, and only for @@ -1245,24 +1493,27 @@ struct libusb_transfer { * fails, or is cancelled. */ libusb_transfer_cb_fn callback; - /** User context data to pass to the callback function. */ + /** User context data. Useful for associating specific data to a transfer + * that can be accessed from within the callback function. + * + * This field may be set manually or is taken as the `user_data` parameter + * of the following functions: + * - libusb_fill_bulk_transfer() + * - libusb_fill_bulk_stream_transfer() + * - libusb_fill_control_transfer() + * - libusb_fill_interrupt_transfer() + * - libusb_fill_iso_transfer() */ void *user_data; /** Data buffer */ unsigned char *buffer; /** Number of isochronous packets. Only used for I/O with isochronous - * endpoints. */ + * endpoints. Must be non-negative. */ int num_iso_packets; /** Isochronous packet descriptors, for isochronous transfers only. */ - struct libusb_iso_packet_descriptor iso_packet_desc -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) - [] /* valid C99 code */ -#else - [0] /* non-standard, but usually working code */ -#endif - ; + struct libusb_iso_packet_descriptor iso_packet_desc[LIBUSB_FLEXIBLE_ARRAY]; }; /** \ingroup libusb_misc @@ -1272,45 +1523,192 @@ struct libusb_transfer { */ enum libusb_capability { /** The libusb_has_capability() API is available. */ - LIBUSB_CAP_HAS_CAPABILITY = 0x0000, + LIBUSB_CAP_HAS_CAPABILITY = 0x0000U, + /** Hotplug support is available on this platform. */ - LIBUSB_CAP_HAS_HOTPLUG = 0x0001, + LIBUSB_CAP_HAS_HOTPLUG = 0x0001U, + /** The library can access HID devices without requiring user intervention. * Note that before being able to actually access an HID device, you may * still have to call additional libusb functions such as * \ref libusb_detach_kernel_driver(). */ - LIBUSB_CAP_HAS_HID_ACCESS = 0x0100, - /** The library supports detaching of the default USB driver, using + LIBUSB_CAP_HAS_HID_ACCESS = 0x0100U, + + /** The library supports detaching of the default USB driver, using * \ref libusb_detach_kernel_driver(), if one is set by the OS kernel */ - LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER = 0x0101 + LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER = 0x0101U }; /** \ingroup libusb_lib * Log message levels. - * - LIBUSB_LOG_LEVEL_NONE (0) : no messages ever printed by the library (default) - * - LIBUSB_LOG_LEVEL_ERROR (1) : error messages are printed to stderr - * - LIBUSB_LOG_LEVEL_WARNING (2) : warning and error messages are printed to stderr - * - LIBUSB_LOG_LEVEL_INFO (3) : informational messages are printed to stdout, warning - * and error messages are printed to stderr - * - LIBUSB_LOG_LEVEL_DEBUG (4) : debug and informational messages are printed to stdout, - * warnings and errors to stderr */ enum libusb_log_level { + /** (0) : No messages ever emitted by the library (default) */ LIBUSB_LOG_LEVEL_NONE = 0, - LIBUSB_LOG_LEVEL_ERROR, - LIBUSB_LOG_LEVEL_WARNING, - LIBUSB_LOG_LEVEL_INFO, - LIBUSB_LOG_LEVEL_DEBUG, + + /** (1) : Error messages are emitted */ + LIBUSB_LOG_LEVEL_ERROR = 1, + + /** (2) : Warning and error messages are emitted */ + LIBUSB_LOG_LEVEL_WARNING = 2, + + /** (3) : Informational, warning and error messages are emitted */ + LIBUSB_LOG_LEVEL_INFO = 3, + + /** (4) : All messages are emitted */ + LIBUSB_LOG_LEVEL_DEBUG = 4 +}; + +/** \ingroup libusb_lib + * Log callback mode. + * + * Since version 1.0.23, \ref LIBUSB_API_VERSION >= 0x01000107 + * + * \see libusb_set_log_cb() + */ +enum libusb_log_cb_mode { + /** Callback function handling all log messages. */ + LIBUSB_LOG_CB_GLOBAL = (1 << 0), + + /** Callback function handling context related log messages. */ + LIBUSB_LOG_CB_CONTEXT = (1 << 1) +}; + +/** \ingroup libusb_lib + * Available option values for libusb_set_option() and libusb_init_context(). + */ +enum libusb_option { + /** Set the log message verbosity. + * + * This option must be provided an argument of type \ref libusb_log_level. + * The default level is LIBUSB_LOG_LEVEL_NONE, which means no messages are ever + * printed. If you choose to increase the message verbosity level, ensure + * that your application does not close the stderr file descriptor. + * + * You are advised to use level LIBUSB_LOG_LEVEL_WARNING. libusb is conservative + * with its message logging and most of the time, will only log messages that + * explain error conditions and other oddities. This will help you debug + * your software. + * + * If the LIBUSB_DEBUG environment variable was set when libusb was + * initialized, this option does nothing: the message verbosity is fixed + * to the value in the environment variable. + * + * If libusb was compiled without any message logging, this option does + * nothing: you'll never get any messages. + * + * If libusb was compiled with verbose debug message logging, this option + * does nothing: you'll always get messages from all levels. + */ + LIBUSB_OPTION_LOG_LEVEL = 0, + + /** Use the UsbDk backend for a specific context, if available. + * + * This option should be set at initialization with libusb_init_context() + * otherwise unspecified behavior may occur. + * + * Only valid on Windows. Ignored on all other platforms. + */ + LIBUSB_OPTION_USE_USBDK = 1, + + /** Do not scan for devices + * + * With this option set, libusb will skip scanning devices in + * libusb_init_context(). + * + * Hotplug functionality will also be deactivated. + * + * The option is useful in combination with libusb_wrap_sys_device(), + * which can access a device directly without prior device scanning. + * + * This is typically needed on Android, where access to USB devices + * is limited. + * + * This option should only be used with libusb_init_context() + * otherwise unspecified behavior may occur. + * + * Only valid on Linux. Ignored on all other platforms. + */ + LIBUSB_OPTION_NO_DEVICE_DISCOVERY = 2, + +#define LIBUSB_OPTION_WEAK_AUTHORITY LIBUSB_OPTION_NO_DEVICE_DISCOVERY + + /** Set the context log callback function. + * + * Set the log callback function either on a context or globally. This + * option must be provided an argument of type \ref libusb_log_cb. + * Using this option with a NULL context is equivalent to calling + * libusb_set_log_cb() with mode \ref LIBUSB_LOG_CB_GLOBAL. + * Using it with a non-NULL context is equivalent to calling + * libusb_set_log_cb() with mode \ref LIBUSB_LOG_CB_CONTEXT. + */ + LIBUSB_OPTION_LOG_CB = 3, + + LIBUSB_OPTION_MAX = 4 +}; + +/** \ingroup libusb_desc + * The device string type. + */ +enum libusb_device_string_type { + LIBUSB_DEVICE_STRING_MANUFACTURER, + LIBUSB_DEVICE_STRING_PRODUCT, + LIBUSB_DEVICE_STRING_SERIAL_NUMBER, + LIBUSB_DEVICE_STRING_COUNT /* The total number of string types. */ +}; + +/** \ingroup libusb_desc + * The maximum length for a device string descriptor in UTF-8. + * + * 255 max descriptor length with 2 byte header + * => 253 bytes UTF-16LE, no null termination (USB 2.0 9.6.7) + * => 126.5 codepoints + * => 126 * 3 + 1 + * => 382 bytes + * + * Stay with 256 * 2/3 = 384 to be safe. + */ +#define LIBUSB_DEVICE_STRING_BYTES_MAX (384U) + +/** \ingroup libusb_lib + * Callback function for handling log messages. + * \param ctx the context which is related to the log message, or NULL if it + * is a global log message + * \param level the log level, see \ref libusb_log_level for a description + * \param str the log message + * + * Since version 1.0.23, \ref LIBUSB_API_VERSION >= 0x01000107 + * + * \see libusb_set_log_cb() + */ +typedef void (LIBUSB_CALL *libusb_log_cb)(libusb_context *ctx, + enum libusb_log_level level, const char *str); + +/** \ingroup libusb_lib + * Structure used for setting options through \ref libusb_init_context. + * + */ +struct libusb_init_option { + /** Which option to set */ + enum libusb_option option; + /** An integer value used by the option (if applicable). */ + union { + int ival; + libusb_log_cb log_cbval; + } value; }; int LIBUSB_CALL libusb_init(libusb_context **ctx); +int LIBUSB_CALL libusb_init_context(libusb_context **ctx, const struct libusb_init_option options[], int num_options); void LIBUSB_CALL libusb_exit(libusb_context *ctx); void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level); +/* may be deprecated in the future in favor of lubusb_init_context()+libusb_set_option() */ +void LIBUSB_CALL libusb_set_log_cb(libusb_context *ctx, libusb_log_cb cb, int mode); const struct libusb_version * LIBUSB_CALL libusb_get_version(void); int LIBUSB_CALL libusb_has_capability(uint32_t capability); -const char * LIBUSB_CALL libusb_error_name(int errcode); +const char * LIBUSB_CALL libusb_error_name(int error_code); int LIBUSB_CALL libusb_setlocale(const char *locale); -const char * LIBUSB_CALL libusb_strerror(enum libusb_error errcode); +const char * LIBUSB_CALL libusb_strerror(int errcode); ssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx, libusb_device ***list); @@ -1319,6 +1717,8 @@ void LIBUSB_CALL libusb_free_device_list(libusb_device **list, libusb_device * LIBUSB_CALL libusb_ref_device(libusb_device *dev); void LIBUSB_CALL libusb_unref_device(libusb_device *dev); +int LIBUSB_CALL libusb_get_device_string(libusb_device *dev, + enum libusb_device_string_type string_type, char *data, int length); int LIBUSB_CALL libusb_get_configuration(libusb_device_handle *dev, int *config); int LIBUSB_CALL libusb_get_device_descriptor(libusb_device *dev, @@ -1332,7 +1732,7 @@ int LIBUSB_CALL libusb_get_config_descriptor_by_value(libusb_device *dev, void LIBUSB_CALL libusb_free_config_descriptor( struct libusb_config_descriptor *config); int LIBUSB_CALL libusb_get_ss_endpoint_companion_descriptor( - struct libusb_context *ctx, + libusb_context *ctx, const struct libusb_endpoint_descriptor *endpoint, struct libusb_ss_endpoint_companion_descriptor **ep_comp); void LIBUSB_CALL libusb_free_ss_endpoint_companion_descriptor( @@ -1341,27 +1741,39 @@ int LIBUSB_CALL libusb_get_bos_descriptor(libusb_device_handle *dev_handle, struct libusb_bos_descriptor **bos); void LIBUSB_CALL libusb_free_bos_descriptor(struct libusb_bos_descriptor *bos); int LIBUSB_CALL libusb_get_usb_2_0_extension_descriptor( - struct libusb_context *ctx, + libusb_context *ctx, struct libusb_bos_dev_capability_descriptor *dev_cap, struct libusb_usb_2_0_extension_descriptor **usb_2_0_extension); void LIBUSB_CALL libusb_free_usb_2_0_extension_descriptor( struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension); int LIBUSB_CALL libusb_get_ss_usb_device_capability_descriptor( - struct libusb_context *ctx, + libusb_context *ctx, struct libusb_bos_dev_capability_descriptor *dev_cap, struct libusb_ss_usb_device_capability_descriptor **ss_usb_device_cap); void LIBUSB_CALL libusb_free_ss_usb_device_capability_descriptor( struct libusb_ss_usb_device_capability_descriptor *ss_usb_device_cap); -int LIBUSB_CALL libusb_get_container_id_descriptor(struct libusb_context *ctx, +int LIBUSB_CALL libusb_get_ssplus_usb_device_capability_descriptor( + libusb_context *ctx, + struct libusb_bos_dev_capability_descriptor *dev_cap, + struct libusb_ssplus_usb_device_capability_descriptor **ssplus_usb_device_cap); +void LIBUSB_CALL libusb_free_ssplus_usb_device_capability_descriptor( + struct libusb_ssplus_usb_device_capability_descriptor *ssplus_usb_device_cap); +int LIBUSB_CALL libusb_get_container_id_descriptor(libusb_context *ctx, struct libusb_bos_dev_capability_descriptor *dev_cap, struct libusb_container_id_descriptor **container_id); void LIBUSB_CALL libusb_free_container_id_descriptor( struct libusb_container_id_descriptor *container_id); +int LIBUSB_CALL libusb_get_platform_descriptor(libusb_context *ctx, + struct libusb_bos_dev_capability_descriptor *dev_cap, + struct libusb_platform_descriptor **platform_descriptor); +void LIBUSB_CALL libusb_free_platform_descriptor( + struct libusb_platform_descriptor *platform_descriptor); +unsigned long LIBUSB_CALL libusb_get_session_data(libusb_device *dev); uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev); uint8_t LIBUSB_CALL libusb_get_port_number(libusb_device *dev); -int LIBUSB_CALL libusb_get_port_numbers(libusb_device *dev, uint8_t* port_numbers, int port_numbers_len); +int LIBUSB_CALL libusb_get_port_numbers(libusb_device *dev, uint8_t *port_numbers, int port_numbers_len); LIBUSB_DEPRECATED_FOR(libusb_get_port_numbers) -int LIBUSB_CALL libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t* path, uint8_t path_length); +int LIBUSB_CALL libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t *path, uint8_t path_length); libusb_device * LIBUSB_CALL libusb_get_parent(libusb_device *dev); uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev); int LIBUSB_CALL libusb_get_device_speed(libusb_device *dev); @@ -1369,8 +1781,17 @@ int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev, unsigned char endpoint); int LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev, unsigned char endpoint); +int LIBUSB_CALL libusb_get_max_alt_packet_size(libusb_device *dev, + int interface_number, int alternate_setting, unsigned char endpoint); -int LIBUSB_CALL libusb_wrap_fd(libusb_context *ctx, int fd, libusb_device_handle **dev_handle); +int LIBUSB_CALL libusb_get_interface_association_descriptors(libusb_device *dev, + uint8_t config_index, struct libusb_interface_association_descriptor_array **iad_array); +int LIBUSB_CALL libusb_get_active_interface_association_descriptors(libusb_device *dev, + struct libusb_interface_association_descriptor_array **iad_array); +void LIBUSB_CALL libusb_free_interface_association_descriptors( + struct libusb_interface_association_descriptor_array *iad_array); + +int LIBUSB_CALL libusb_wrap_sys_device(libusb_context *ctx, intptr_t sys_dev, libusb_device_handle **dev_handle); int LIBUSB_CALL libusb_open(libusb_device *dev, libusb_device_handle **dev_handle); void LIBUSB_CALL libusb_close(libusb_device_handle *dev_handle); libusb_device * LIBUSB_CALL libusb_get_device(libusb_device_handle *dev_handle); @@ -1410,6 +1831,14 @@ int LIBUSB_CALL libusb_attach_kernel_driver(libusb_device_handle *dev_handle, int LIBUSB_CALL libusb_set_auto_detach_kernel_driver( libusb_device_handle *dev_handle, int enable); +int LIBUSB_CALL libusb_endpoint_supports_raw_io(libusb_device_handle* dev_handle, + uint8_t endpoint); +int LIBUSB_CALL libusb_endpoint_set_raw_io(libusb_device_handle *dev_handle, + uint8_t endpoint, int enable); +int LIBUSB_CALL libusb_get_max_raw_io_transfer_size( + libusb_device_handle *dev_handle, + uint8_t endpoint); + /* async I/O */ /** \ingroup libusb_asyncio @@ -1445,7 +1874,7 @@ static inline unsigned char *libusb_control_transfer_get_data( static inline struct libusb_control_setup *libusb_control_transfer_get_setup( struct libusb_transfer *transfer) { - return (struct libusb_control_setup *)(void *) transfer->buffer; + return (struct libusb_control_setup *)(void *)transfer->buffer; } /** \ingroup libusb_asyncio @@ -1475,7 +1904,7 @@ static inline void libusb_fill_control_setup(unsigned char *buffer, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint16_t wLength) { - struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *) buffer; + struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *)buffer; setup->bmRequestType = bmRequestType; setup->bRequest = bRequest; setup->wValue = libusb_cpu_to_le16(wValue); @@ -1525,7 +1954,7 @@ static inline void libusb_fill_control_transfer( unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout) { - struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *) buffer; + struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *)buffer; transfer->dev_handle = dev_handle; transfer->endpoint = 0; transfer->type = LIBUSB_TRANSFER_TYPE_CONTROL; @@ -1664,6 +2093,7 @@ static inline void libusb_set_iso_packet_lengths( struct libusb_transfer *transfer, unsigned int length) { int i; + for (i = 0; i < transfer->num_iso_packets; i++) transfer->iso_packet_desc[i].length = length; } @@ -1747,16 +2177,16 @@ static inline unsigned char *libusb_get_iso_packet_buffer_simple( /* sync I/O */ int LIBUSB_CALL libusb_control_transfer(libusb_device_handle *dev_handle, - uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, + uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, unsigned char *data, uint16_t wLength, unsigned int timeout); int LIBUSB_CALL libusb_bulk_transfer(libusb_device_handle *dev_handle, unsigned char endpoint, unsigned char *data, int length, - int *actual_length, unsigned int timeout); + int *transferred, unsigned int timeout); int LIBUSB_CALL libusb_interrupt_transfer(libusb_device_handle *dev_handle, unsigned char endpoint, unsigned char *data, int length, - int *actual_length, unsigned int timeout); + int *transferred, unsigned int timeout); /** \ingroup libusb_desc * Retrieve a descriptor from the default control pipe. @@ -1878,7 +2308,7 @@ void LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx, * Callbacks handles are generated by libusb_hotplug_register_callback() * and can be used to deregister callbacks. Callback handles are unique * per libusb_context and it is safe to call libusb_hotplug_deregister_callback() - * on an already deregisted callback. + * on an already deregistered callback. * * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 * @@ -1890,29 +2320,30 @@ typedef int libusb_hotplug_callback_handle; * * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 * - * Flags for hotplug events */ + * Hotplug events */ typedef enum { - /** Default value when not using any flags. */ - LIBUSB_HOTPLUG_NO_FLAGS = 0, + /** A device has been plugged in and is ready to use */ + LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = (1 << 0), - /** Arm the callback and fire it for all matching currently attached devices. */ - LIBUSB_HOTPLUG_ENUMERATE = 1<<0, -} libusb_hotplug_flag; + /** A device has left and is no longer available. + * It is the user's responsibility to call libusb_close on any handle associated with a disconnected device. + * It is safe to call libusb_get_device_descriptor on a device that has left */ + LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = (1 << 1) +} libusb_hotplug_event; /** \ingroup libusb_hotplug * * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 * - * Hotplug events */ + * Hotplug flags */ typedef enum { - /** A device has been plugged in and is ready to use */ - LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = 0x01, + /** Arm the callback and fire it for all matching currently attached devices. */ + LIBUSB_HOTPLUG_ENUMERATE = (1 << 0) +} libusb_hotplug_flag; - /** A device has left and is no longer available. - * It is the user's responsibility to call libusb_close on any handle associated with a disconnected device. - * It is safe to call libusb_get_device_descriptor on a device that has left */ - LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = 0x02, -} libusb_hotplug_event; +/** \ingroup libusb_hotplug + * Convenience macro when not using any flags */ +#define LIBUSB_HOTPLUG_NO_FLAGS 0 /** \ingroup libusb_hotplug * Wildcard matching for hotplug events */ @@ -1941,9 +2372,7 @@ typedef enum { * returning 1 will cause this callback to be deregistered */ typedef int (LIBUSB_CALL *libusb_hotplug_callback_fn)(libusb_context *ctx, - libusb_device *device, - libusb_hotplug_event event, - void *user_data); + libusb_device *device, libusb_hotplug_event event, void *user_data); /** \ingroup libusb_hotplug * Register a hotplug callback function @@ -1968,25 +2397,23 @@ typedef int (LIBUSB_CALL *libusb_hotplug_callback_fn)(libusb_context *ctx, * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 * * \param[in] ctx context to register this callback with - * \param[in] events bitwise or of events that will trigger this callback. See \ref - * libusb_hotplug_event - * \param[in] flags hotplug callback flags. See \ref libusb_hotplug_flag + * \param[in] events bitwise or of hotplug events that will trigger this callback. + * See \ref libusb_hotplug_event + * \param[in] flags bitwise or of hotplug flags that affect registration. + * See \ref libusb_hotplug_flag * \param[in] vendor_id the vendor id to match or \ref LIBUSB_HOTPLUG_MATCH_ANY * \param[in] product_id the product id to match or \ref LIBUSB_HOTPLUG_MATCH_ANY * \param[in] dev_class the device class to match or \ref LIBUSB_HOTPLUG_MATCH_ANY * \param[in] cb_fn the function to be invoked on a matching event/device * \param[in] user_data user data to pass to the callback function * \param[out] callback_handle pointer to store the handle of the allocated callback (can be NULL) - * \returns LIBUSB_SUCCESS on success LIBUSB_ERROR code on failure + * \returns \ref LIBUSB_SUCCESS on success LIBUSB_ERROR code on failure */ int LIBUSB_CALL libusb_hotplug_register_callback(libusb_context *ctx, - libusb_hotplug_event events, - libusb_hotplug_flag flags, - int vendor_id, int product_id, - int dev_class, - libusb_hotplug_callback_fn cb_fn, - void *user_data, - libusb_hotplug_callback_handle *callback_handle); + int events, int flags, + int vendor_id, int product_id, int dev_class, + libusb_hotplug_callback_fn cb_fn, void *user_data, + libusb_hotplug_callback_handle *callback_handle); /** \ingroup libusb_hotplug * Deregisters a hotplug callback. @@ -2000,9 +2427,26 @@ int LIBUSB_CALL libusb_hotplug_register_callback(libusb_context *ctx, * \param[in] callback_handle the handle of the callback to deregister */ void LIBUSB_CALL libusb_hotplug_deregister_callback(libusb_context *ctx, - libusb_hotplug_callback_handle callback_handle); + libusb_hotplug_callback_handle callback_handle); + +/** \ingroup libusb_hotplug + * Gets the user_data associated with a hotplug callback. + * + * Since version v1.0.24 \ref LIBUSB_API_VERSION >= 0x01000108 + * + * \param[in] ctx context this callback is registered with + * \param[in] callback_handle the handle of the callback to get the user_data of + */ +void * LIBUSB_CALL libusb_hotplug_get_user_data(libusb_context *ctx, + libusb_hotplug_callback_handle callback_handle); + +int LIBUSB_CALLV libusb_set_option(libusb_context *ctx, enum libusb_option option, ...); + +#ifdef _MSC_VER +#pragma warning(pop) +#endif -#ifdef __cplusplus +#if defined(__cplusplus) } #endif diff --git a/Desktop_Interface/build_android/package_source/AndroidManifest.xml b/Desktop_Interface/build_android/package_source/AndroidManifest.xml index 68a61264d..358807d69 100644 --- a/Desktop_Interface/build_android/package_source/AndroidManifest.xml +++ b/Desktop_Interface/build_android/package_source/AndroidManifest.xml @@ -1,6 +1,6 @@ - + @@ -12,13 +12,14 @@ - + + android:icon="@mipmap/ic_launcher" + android:exported="true"> @@ -37,12 +38,10 @@ - - - + diff --git a/Desktop_Interface/build_android/package_source/src/androidInterface.java b/Desktop_Interface/build_android/package_source/src/androidInterface.java index 9935cf84d..fb7e84b10 100644 --- a/Desktop_Interface/build_android/package_source/src/androidInterface.java +++ b/Desktop_Interface/build_android/package_source/src/androidInterface.java @@ -5,6 +5,8 @@ import android.util.Log; +import android.os.Build; + import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbManager; import android.hardware.usb.UsbDeviceConnection; @@ -42,7 +44,12 @@ public void nonStaticTest() public void findDevice() { Log.d(QtApplication.QtTAG, "findDevice"); - PendingIntent mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); //??? + PendingIntent mPermissionIntent; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_MUTABLE); //??? + } else { + mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); //??? + } UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); //Handle to system USB service? HashMap deviceList = manager.getDeviceList(); Iterator deviceIterator = deviceList.values().iterator(); @@ -89,7 +96,12 @@ public void findDevice() public void findDevice_bootloader() { Log.d(QtApplication.QtTAG, "findDevice_bootloader"); - PendingIntent mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); //??? + PendingIntent mPermissionIntent; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_MUTABLE); + } else { + mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); + } UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); //Handle to system USB service? HashMap deviceList = manager.getDeviceList(); Iterator deviceIterator = deviceList.values().iterator(); diff --git a/Desktop_Interface/genericusbdriver.cpp b/Desktop_Interface/genericusbdriver.cpp index 1f1d42933..1d864eda4 100644 --- a/Desktop_Interface/genericusbdriver.cpp +++ b/Desktop_Interface/genericusbdriver.cpp @@ -253,6 +253,7 @@ void genericUsbDriver::sendFunctionGenData(functionGen::ChannelID channelID) usbSendControl(0x40, 0xb2, timerPeriod, clkSetting, channelData.samples.size(), channelData.samples.data()); } + this->sigGenFreqUpdated(channelID, clkSetting, timerPeriod, channelData.samples.size()); return; } diff --git a/Desktop_Interface/genericusbdriver.h b/Desktop_Interface/genericusbdriver.h index 95dcc7a57..a3807b99d 100644 --- a/Desktop_Interface/genericusbdriver.h +++ b/Desktop_Interface/genericusbdriver.h @@ -121,6 +121,7 @@ class genericUsbDriver : public QLabel void initialConnectComplete(void); void signalFirmwareFlash(void); void calibrateMe(void); + void sigGenFreqUpdated(functionGen::ChannelID channelID, int newClkSetting, int newTimerPeriod, int wfSize); public slots: void setPsu(double voltage); void setFunctionGen(functionGen::ChannelID channelID, functionGen::SingleChannelController *fGenControl); diff --git a/Desktop_Interface/isobuffer.cpp b/Desktop_Interface/isobuffer.cpp index 2243f7444..0f0bd6e54 100644 --- a/Desktop_Interface/isobuffer.cpp +++ b/Desktop_Interface/isobuffer.cpp @@ -426,8 +426,10 @@ void isoBuffer::serialManage(double baudRate, UartParity parity, bool hexDisplay void isoBuffer::setTriggerType(TriggerType newType) { qDebug() << "Trigger Type: " << (uint8_t)newType; - m_triggerType = newType; - m_lastTriggerDetlaT = 0; + if(newType != m_triggerType){ + m_triggerType = newType; + m_lastTriggerDeltaT = 0; + } } void isoBuffer::setTriggerLevel(double voltageLevel, uint16_t top, bool acCoupled) @@ -436,29 +438,63 @@ void isoBuffer::setTriggerLevel(double voltageLevel, uint16_t top, bool acCouple m_triggerSensitivity = static_cast(1 + abs(voltageLevel * kTriggerSensitivityMultiplier * static_cast(top) / 128.)); qDebug() << "Trigger Level: " << m_triggerLevel; qDebug() << "Trigger sensitivity:" << m_triggerSensitivity; - m_lastTriggerDetlaT = 0; + m_lastTriggerDeltaT = 0; +} + +void isoBuffer::setSigGenTriggerFreq(functionGen::ChannelID channelID, int clkSetting, int timerPeriod, int wfSize) +{ + int validClockDivs[7] = {1, 2, 4, 8, 64, 256, 1024}; + + double freq_ratio = ((double) (CLOCK_FREQ/m_samplesPerSecond))/validClockDivs[clkSetting-1]; // a power 2**n, n possibly < 0 + + double bufferSamplesPerWfCycle = wfSize * (timerPeriod+1) / freq_ratio; + + if(channelID==functionGen::ChannelID::CH1) + bufferSamplesPerCH1WfCycle = bufferSamplesPerWfCycle; + else if (channelID==functionGen::ChannelID::CH2) + bufferSamplesPerCH2WfCycle = bufferSamplesPerWfCycle; } // TODO: Clear trigger // FIXME: AC changes will not be reflected here void isoBuffer::checkTriggered() { + static uint32_t s_lastPosition = 0; if (m_triggerType == TriggerType::Disabled) return; - if ((bufferAt(0) >= (m_triggerLevel + m_triggerSensitivity)) && (m_triggerSeekState == TriggerSeekState::BelowTriggerLevel)) - { - // Rising Edge - m_triggerSeekState = TriggerSeekState::AboveTriggerLevel; - if (m_triggerType == TriggerType::Rising) - addTriggerPosition(m_back - 1); - } - else if ((bufferAt(0) < (m_triggerLevel - m_triggerSensitivity)) && (m_triggerSeekState == TriggerSeekState::AboveTriggerLevel)) + if((m_triggerType == TriggerType::CH1SigGen)||(m_triggerType == TriggerType::CH2SigGen)) { - // Falling Edge - m_triggerSeekState = TriggerSeekState::BelowTriggerLevel; - if (m_triggerType == TriggerType::Falling) - addTriggerPosition(m_back - 1); + float bufferSamplesPerWfCycle = m_triggerType == TriggerType::CH1SigGen ? bufferSamplesPerCH1WfCycle : bufferSamplesPerCH2WfCycle; + int32_t diff = m_back-s_lastPosition; + if(diff < 0) { + diff += m_bufferLen; + } + int n_cycles = diff/bufferSamplesPerWfCycle; + if( (m_triggerPositionList.size()==0) || (diff-n_cycles*bufferSamplesPerWfCycle == 0) ) { + addTriggerPosition(m_back, s_lastPosition, n_cycles); + s_lastPosition=m_back; + } + + } else { + if ((bufferAt(0) >= (m_triggerLevel + m_triggerSensitivity)) && (m_triggerSeekState == TriggerSeekState::BelowTriggerLevel)) + { + // Rising Edge + m_triggerSeekState = TriggerSeekState::AboveTriggerLevel; + if (m_triggerType == TriggerType::Rising){ + addTriggerPosition(m_back, s_lastPosition, 1); + s_lastPosition=m_back; + } + } + else if ((bufferAt(0) < (m_triggerLevel - m_triggerSensitivity)) && (m_triggerSeekState == TriggerSeekState::AboveTriggerLevel)) + { + // Falling Edge + m_triggerSeekState = TriggerSeekState::BelowTriggerLevel; + if (m_triggerType == TriggerType::Falling){ + addTriggerPosition(m_back, s_lastPosition, 1); + s_lastPosition=m_back; + } + } } } @@ -515,16 +551,14 @@ double isoBuffer::getDelayedTriggerPoint(double delay) double isoBuffer::getTriggerFrequencyHz() { - return (m_lastTriggerDetlaT == 0) ? -1. : static_cast(m_samplesPerSecond) / static_cast(m_lastTriggerDetlaT); + return (m_lastTriggerDeltaT == 0) ? -1. : 1. / (m_lastTriggerDeltaT); } -void isoBuffer::addTriggerPosition(uint32_t position) +void isoBuffer::addTriggerPosition(uint32_t position, uint32_t s_lastPosition, int n_cycles) { - static uint32_t s_lastPosition = 0; m_triggerPositionList.push_back(m_back - 1); - m_lastTriggerDetlaT = (position > s_lastPosition) ? (position - s_lastPosition) : position + m_bufferLen - s_lastPosition; - - s_lastPosition = position; + uint32_t delta_samples = (position > s_lastPosition) ? (position - s_lastPosition) : position + m_bufferLen - s_lastPosition; + m_lastTriggerDeltaT = delta_samples / static_cast(m_samplesPerSecond) / n_cycles; - //qDebug() << position << s_lastPosition << static_cast(m_samplesPerSecond) / static_cast(m_lastTriggerDetlaT) << "Hz"; + //qDebug() << position << s_lastPosition << static_cast(m_samplesPerSecond) / static_cast(m_lastTriggerDeltaT) << "Hz"; } diff --git a/Desktop_Interface/isobuffer.h b/Desktop_Interface/isobuffer.h index 4950dae77..a3baa202d 100644 --- a/Desktop_Interface/isobuffer.h +++ b/Desktop_Interface/isobuffer.h @@ -27,7 +27,9 @@ enum class TriggerType : uint8_t { Disabled, Rising, - Falling + Falling, + CH1SigGen, + CH2SigGen }; enum class TriggerSeekState : uint8_t @@ -99,6 +101,7 @@ class isoBuffer : public QWidget void setTriggerLevel(double voltageLevel, uint16_t top, bool acCoupled); double getDelayedTriggerPoint(double delay); double getTriggerFrequencyHz(); + void setSigGenTriggerFreq(functionGen::ChannelID channelID, int clkSetting, int timerPeriod, int wfSize); // ---- MEMBER VARIABLES ---- @@ -154,11 +157,13 @@ class isoBuffer : public QWidget qulonglong m_fileIO_maxFileSize; qulonglong m_fileIO_numBytesWritten; unsigned int m_currentColumn = 0; - uint32_t m_lastTriggerDetlaT = 0; + double m_lastTriggerDeltaT = 0.0; + float bufferSamplesPerCH1WfCycle; + float bufferSamplesPerCH2WfCycle; isoDriver* m_virtualParent; - void addTriggerPosition(uint32_t position); + void addTriggerPosition(uint32_t m_back, uint32_t position, int n_cycles); signals: void fileIOinternalDisable(); public slots: diff --git a/Desktop_Interface/isodriver.cpp b/Desktop_Interface/isodriver.cpp index 6e8ceb17c..256e06e4a 100644 --- a/Desktop_Interface/isodriver.cpp +++ b/Desktop_Interface/isodriver.cpp @@ -806,6 +806,13 @@ void isoDriver::setTriggerLevel(double level) triggerStateChanged(); } +// channel ID here refers to the wf gen channels +void isoDriver::newSigGenTriggerFreq(functionGen::ChannelID channelID, int clkSetting, int timerPeriod, int wfSize) { + internalBuffer375_CH1->setSigGenTriggerFreq(channelID, clkSetting, timerPeriod, wfSize); + internalBuffer750->setSigGenTriggerFreq(channelID, clkSetting, timerPeriod, wfSize); +} + + void isoDriver::setSingleShotEnabled(bool enabled) { singleShotEnabled = enabled; @@ -868,8 +875,10 @@ void isoDriver::frameActionGeneric(char CH1_mode, char CH2_mode) double triggerDelay = 0; if (triggerEnabled) { - triggerDelay = (triggerMode < 2) ? internalBuffer_CH1->getDelayedTriggerPoint(display->window) - display->window - : internalBuffer_CH2->getDelayedTriggerPoint(display->window) - display->window; + if((triggerMode<2)||(triggerMode>=4)) + triggerDelay = internalBuffer_CH1->getDelayedTriggerPoint(display->window) - display->window; + else + triggerDelay = internalBuffer_CH2->getDelayedTriggerPoint(display->window) - display->window; if (triggerDelay < 0) triggerDelay = 0; @@ -1728,7 +1737,7 @@ void isoDriver::slowTimerTick(){ update_CH1 = true; update_CH2 = true; - bool frequencyLabelVisible = false; + bool frequencyLabelValid = false; if (triggerEnabled) { @@ -1744,11 +1753,15 @@ void isoDriver::slowTimerTick(){ case 3: triggerFrequency = internalBuffer375_CH2->getTriggerFrequencyHz(); break; + case 4: + case 5: + triggerFrequency = (driver->deviceMode == 6) ? internalBuffer750->getTriggerFrequencyHz() : internalBuffer375_CH1->getTriggerFrequencyHz(); + break; } if (triggerFrequency > 0.) { - frequencyLabelVisible = true; + frequencyLabelValid = true; siprint triggerFreqSiprint("Hz", triggerFrequency); siprint periodSiprint("s", 1. / triggerFrequency); @@ -1758,7 +1771,7 @@ void isoDriver::slowTimerTick(){ qDebug() << triggerFrequency << "Hz"; } - triggerFrequencyLabel->setVisible(frequencyLabelVisible); + triggerFrequencyLabel->setVisible(showTriggerFrequencyLabel&&frequencyLabelValid); } void isoDriver::setTopRange(double newTop) @@ -2047,6 +2060,7 @@ void isoDriver::triggerStateChanged() { if (!triggerEnabled) { + internalBuffer375_CH1->setTriggerType(TriggerType::Disabled); internalBuffer375_CH2->setTriggerType(TriggerType::Disabled); internalBuffer750->setTriggerType(TriggerType::Disabled); @@ -2085,6 +2099,23 @@ void isoDriver::triggerStateChanged() internalBuffer750->setTriggerType(TriggerType::Disabled); break; } + // use the CH1 buffer to do the sig gen trigger timekeeping. If there were a Ch. 2-only mode for the device, + // this practice could be problematic, but at present there is no Ch. 2-only mode. + // Also, in CH#SigGen below, the channel number refers to the sig gen channel + case 4: + { + internalBuffer375_CH1->setTriggerType(TriggerType::CH1SigGen); + internalBuffer375_CH2->setTriggerType(TriggerType::Disabled); + internalBuffer750->setTriggerType(TriggerType::CH1SigGen); + break; + } + case 5: + { + internalBuffer375_CH1->setTriggerType(TriggerType::CH2SigGen); + internalBuffer375_CH2->setTriggerType(TriggerType::Disabled); + internalBuffer750->setTriggerType(TriggerType::CH2SigGen); + } + } } diff --git a/Desktop_Interface/isodriver.h b/Desktop_Interface/isodriver.h index 1cce763c6..e706a841e 100644 --- a/Desktop_Interface/isodriver.h +++ b/Desktop_Interface/isodriver.h @@ -7,6 +7,7 @@ #include #include "qcustomplot.h" #include "genericusbdriver.h" +#include "functiongencontrol.h" #include "desktop_settings.h" #include "siprint.h" #include "i2cdecoder.h" @@ -54,6 +55,7 @@ class DisplayControl : public QObject void botRangeUpdated(double); void timeWindowUpdated(double); void delayUpdated(double); + }; class isoDriver : public QLabel @@ -71,6 +73,7 @@ class isoDriver : public QLabel QCPItemText *cursorLabel; QCPItemText *fSpaceLabel; QCPItemText *triggerFrequencyLabel; + bool showTriggerFrequencyLabel = true; #endif genericUsbDriver *driver; bool doNotTouchGraph = true; @@ -154,7 +157,6 @@ class isoDriver : public QLabel bool hexDisplay_CH1 = false; bool hexDisplay_CH2 = false; - //Generic Functions QVector analogConvert(std::vector &in, int TOP, bool AC, int channel); QVector digitalConvert(std::vector &in); @@ -330,6 +332,8 @@ public slots: void attenuationChanged_CH2(int attenuationIndex); void setHexDisplay_CH1(bool enabled); void setHexDisplay_CH2(bool enabled); + + void newSigGenTriggerFreq(functionGen::ChannelID channelID, int clkSetting, int timerPeriod, int wfSize); #ifndef DISABLE_SPECTRUM void setWindowingType(int windowing); void setMinFreqResp(double minFreqResp); diff --git a/Desktop_Interface/mainwindow.cpp b/Desktop_Interface/mainwindow.cpp index d1b473655..a7fcf2071 100644 --- a/Desktop_Interface/mainwindow.cpp +++ b/Desktop_Interface/mainwindow.cpp @@ -167,6 +167,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->psuSlider, SIGNAL(voltageChanged(double)), ui->controller_iso->driver, SLOT(setPsu(double))); connect(ui->controller_iso, SIGNAL(setGain(double)), ui->controller_iso->driver, SLOT(setGain(double))); connect(ui->controller_fg, &functionGenControl::functionGenToUpdate, ui->controller_iso->driver, &genericUsbDriver::setFunctionGen); + connect(ui->controller_iso->driver, &genericUsbDriver::sigGenFreqUpdated, ui->controller_iso, &isoDriver::newSigGenTriggerFreq); connect(ui->bufferDisplay, SIGNAL(modeChange(int)), ui->controller_iso->driver, SLOT(setDeviceMode(int))); connect(ui->bufferDisplay, &bufferControl::modeChange, this, [this](){ // Force a trigger refresh @@ -1514,6 +1515,7 @@ void MainWindow::reinitUsbStage2(void){ connect(ui->psuSlider, SIGNAL(voltageChanged(double)), ui->controller_iso->driver, SLOT(setPsu(double))); connect(ui->controller_iso, SIGNAL(setGain(double)), ui->controller_iso->driver, SLOT(setGain(double))); connect(ui->controller_fg, &functionGenControl::functionGenToUpdate, ui->controller_iso->driver, &genericUsbDriver::setFunctionGen); + connect(ui->controller_iso->driver, &genericUsbDriver::sigGenFreqUpdated, ui->controller_iso, &isoDriver::newSigGenTriggerFreq); connect(ui->bufferDisplay, SIGNAL(modeChange(int)), ui->controller_iso->driver, SLOT(setDeviceMode(int))); connect(ui->bufferDisplay, &bufferControl::modeChange, this, [this](){ // Force a trigger refresh @@ -2728,10 +2730,13 @@ void MainWindow::on_actionFrequency_Spectrum_triggered(bool checked) ui->scopeAxes->xAxis->setNumberFormat(defaultNumberFormat); } - if (checked == true) + if (checked == true) { MAX_WINDOW_SIZE = 1<<17; - else + ui->controller_iso->showTriggerFrequencyLabel = false; + } else { MAX_WINDOW_SIZE = 10; + ui->controller_iso->showTriggerFrequencyLabel = true; + } } void MainWindow::on_actionFrequency_Response_triggered(bool checked) @@ -2765,6 +2770,8 @@ void MainWindow::on_actionFrequency_Response_triggered(bool checked) ui->cursorHoriCheck->setChecked(ui->controller_iso->horiCursorEnabled2); ui->cursorVertCheck->setChecked(ui->controller_iso->vertCursorEnabled2); ui->controller_iso->retickXAxis(); + + ui->controller_iso->showTriggerFrequencyLabel = false; }else{ ui->cursorHoriCheck->setChecked(ui->controller_iso->horiCursorEnabled0); ui->cursorVertCheck->setChecked(ui->controller_iso->vertCursorEnabled0); @@ -2774,6 +2781,8 @@ void MainWindow::on_actionFrequency_Response_triggered(bool checked) ui->scopeAxes->xAxis->setNumberPrecision(defaultNumberPrecision); ui->scopeAxes->xAxis->setAutoTickCount(defaultAutoTickCount); ui->scopeAxes->xAxis->setNumberFormat(defaultNumberFormat); + + ui->controller_iso->showTriggerFrequencyLabel = true; } } @@ -2804,9 +2813,11 @@ void MainWindow::on_actionEye_Diagram_triggered(bool checked) if(checked){ ui->cursorHoriCheck->setChecked(ui->controller_iso->horiCursorEnabled3); ui->cursorVertCheck->setChecked(ui->controller_iso->vertCursorEnabled3); + ui->controller_iso->showTriggerFrequencyLabel = false; }else{ ui->cursorHoriCheck->setChecked(ui->controller_iso->horiCursorEnabled0); ui->cursorVertCheck->setChecked(ui->controller_iso->vertCursorEnabled0); + ui->controller_iso->showTriggerFrequencyLabel = true; } } #endif @@ -2903,6 +2914,24 @@ void MainWindow::on_serialEncodingCheck_CH1_toggled(bool checked) } } +void MainWindow::triggerChannelChanged(int newTriggerChannel){ + if((newTriggerChannel==4)||(newTriggerChannel==5)) { + ui->triggerLevelValue->setEnabled(false); + ui->singleShotCheckBox->setEnabled(false); + ui->singleShotCheckBox->setChecked(false); +#ifndef PLATFORM_ANDROID + ui->label_6->setEnabled(false); +#endif + } else { + ui->triggerLevelValue->setEnabled(true); + ui->singleShotCheckBox->setEnabled(true); +#ifndef PLATFORM_ANDROID + ui->label_6->setEnabled(true); +#endif + } +} + + void MainWindow::on_txuart_textChanged() { QString text, new_char; diff --git a/Desktop_Interface/mainwindow.h b/Desktop_Interface/mainwindow.h index fcd36233e..9121a28f7 100644 --- a/Desktop_Interface/mainwindow.h +++ b/Desktop_Interface/mainwindow.h @@ -66,6 +66,8 @@ private slots: void on_actionSnap_to_Cursors_triggered(); void on_actionEnter_Manually_triggered(); + void triggerChannelChanged(int newTriggerChannel); + void connectDisplaySignals(); void calibrateStage2(); void calibrateStage3(); diff --git a/Desktop_Interface/ui_files_desktop/mainwindow.ui b/Desktop_Interface/ui_files_desktop/mainwindow.ui index 300b70155..9ed885377 100644 --- a/Desktop_Interface/ui_files_desktop/mainwindow.ui +++ b/Desktop_Interface/ui_files_desktop/mainwindow.ui @@ -691,6 +691,16 @@ CH2 (Falling) + + + Sig. Gen. CH1 + + + + + Sig. Gen. CH2 + + @@ -3643,6 +3653,12 @@ + + triggerChannelSelect + currentIndexChanged(int) + MainWindow + triggerChannelChanged(int) + acCoupledLabel_CH1 toggled(bool) diff --git a/Desktop_Interface/ui_files_mobile/mainwindow.ui b/Desktop_Interface/ui_files_mobile/mainwindow.ui index 1b6224adf..9c3e46671 100644 --- a/Desktop_Interface/ui_files_mobile/mainwindow.ui +++ b/Desktop_Interface/ui_files_mobile/mainwindow.ui @@ -576,6 +576,16 @@ CH2 (Falling) + + + Sig. Gen. CH1 + + + + + Sig. Gen. CH2 + + @@ -3627,6 +3637,12 @@ + + triggerChannelSelect + currentIndexChanged(int) + MainWindow + triggerChannelChanged(int) + acCoupledLabel_CH1 toggled(bool)