Skip to content

Commit

Permalink
libusb wrapper workaround for Clang constexpr fails
Browse files Browse the repository at this point in the history
  • Loading branch information
diablodale committed May 29, 2023
1 parent 9cabf73 commit e99a13f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
27 changes: 27 additions & 0 deletions src/pc/protocols/wrap_libusb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
dp::libusb - C++ wrapper for libusb-1.0 (focused on use with the XLink protocol)
Copyright 2023 Dale Phurrough
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "wrap_libusb.hpp"

std::mutex dp::libusb::device_list::mtx;

// definition outside class to workaround Clang constexpr failures
constexpr int dp::libusb::device_handle::DEFAULT_CHUNK_SIZE;
constexpr int dp::libusb::device_handle::DEFAULT_CHUNK_SIZE_USB1;
constexpr decltype(libusb_endpoint_descriptor::wMaxPacketSize) dp::libusb::device_handle::DEFAULT_MAX_PACKET_SIZE;
constexpr std::array<decltype(libusb_endpoint_descriptor::wMaxPacketSize), 32> dp::libusb::device_handle::DEFAULT_MAX_PACKET_ARRAY;
6 changes: 2 additions & 4 deletions src/pc/protocols/wrap_libusb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

// project
#define MVLOG_UNIT_NAME xLinkUsb
#include "XLink/XLinkLog.h"

// libraries
#ifdef XLINK_LIBUSB_LOCAL
Expand Down Expand Up @@ -273,9 +274,6 @@ class device_list {
pointer deviceList{};
};

// TODO move to dedicated cpp file to avoid multiple definitions
std::mutex device_list::mtx;

// wraps libusb_config_descriptor* and automatically libusb_free_config_descriptor() on destruction
class config_descriptor : public unique_resource_ptr<libusb_config_descriptor, libusb_free_config_descriptor> {
public:
Expand Down Expand Up @@ -534,7 +532,7 @@ class device_handle : public unique_resource_ptr<libusb_device_handle, libusb_cl
int control_transfer(uint8_t requestType, uint8_t request, uint16_t value, uint16_t index, void *data, uint16_t length, std::chrono::milliseconds timeout) const noexcept(!Throw) {
return call_log_throw<Loglevel, Throw>(__func__, __LINE__, libusb_control_transfer, get(), requestType, request, value, index, static_cast<unsigned char*>(data), length, static_cast<unsigned int>(timeout.count()));
}
};
};

class usb_device : public unique_resource_ptr<libusb_device, libusb_unref_device> {
private:
Expand Down

0 comments on commit e99a13f

Please sign in to comment.