2010-08-13 20:40:13 +00:00
|
|
|
//
|
2014-08-13 15:44:31 +00:00
|
|
|
// Copyright 2010,2014 Ettus Research LLC
|
2010-08-13 20:40:13 +00:00
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
|
2010-08-26 19:21:50 +00:00
|
|
|
#include "libusb1_base.hpp"
|
2010-08-13 20:40:13 +00:00
|
|
|
#include <uhd/transport/usb_control.hpp>
|
2011-07-03 02:35:33 +00:00
|
|
|
#include <boost/thread/mutex.hpp>
|
2010-08-13 20:40:13 +00:00
|
|
|
|
|
|
|
|
using namespace uhd::transport;
|
|
|
|
|
|
2014-08-13 15:44:31 +00:00
|
|
|
usb_control::~usb_control(void){
|
|
|
|
|
/* NOP */
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-13 20:40:13 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* libusb-1.0 implementation of USB control transport
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
class libusb_control_impl : public usb_control {
|
|
|
|
|
public:
|
2016-06-24 20:48:12 +00:00
|
|
|
libusb_control_impl(libusb::device_handle::sptr handle, const int interface):
|
2010-09-26 04:07:15 +00:00
|
|
|
_handle(handle)
|
|
|
|
|
{
|
2011-09-19 23:14:12 +00:00
|
|
|
_handle->claim_interface(interface);
|
2010-09-26 04:07:15 +00:00
|
|
|
}
|
2010-08-13 20:40:13 +00:00
|
|
|
|
2016-06-24 20:48:32 +00:00
|
|
|
virtual ~libusb_control_impl(void);
|
|
|
|
|
|
2016-10-31 21:30:52 +00:00
|
|
|
int submit(uint8_t request_type,
|
|
|
|
|
uint8_t request,
|
|
|
|
|
uint16_t value,
|
|
|
|
|
uint16_t index,
|
2016-06-24 20:47:05 +00:00
|
|
|
unsigned char *buff,
|
2016-10-31 21:30:52 +00:00
|
|
|
uint16_t length,
|
|
|
|
|
uint32_t libusb_timeout = 0
|
2010-09-26 04:07:15 +00:00
|
|
|
){
|
2011-07-03 02:35:33 +00:00
|
|
|
boost::mutex::scoped_lock lock(_mutex);
|
2010-09-26 04:07:15 +00:00
|
|
|
return libusb_control_transfer(_handle->get(),
|
|
|
|
|
request_type,
|
|
|
|
|
request,
|
|
|
|
|
value,
|
|
|
|
|
index,
|
|
|
|
|
buff,
|
|
|
|
|
length,
|
|
|
|
|
libusb_timeout);
|
|
|
|
|
}
|
2010-08-13 20:40:13 +00:00
|
|
|
|
|
|
|
|
private:
|
2010-09-26 04:07:15 +00:00
|
|
|
libusb::device_handle::sptr _handle;
|
2011-07-03 02:35:33 +00:00
|
|
|
boost::mutex _mutex;
|
2010-08-13 20:40:13 +00:00
|
|
|
};
|
|
|
|
|
|
2016-06-24 20:48:32 +00:00
|
|
|
libusb_control_impl::~libusb_control_impl(void) {
|
|
|
|
|
/* NOP */
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-13 20:40:13 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* USB control public make functions
|
|
|
|
|
**********************************************************************/
|
2016-06-24 20:48:12 +00:00
|
|
|
usb_control::sptr usb_control::make(usb_device_handle::sptr handle, const int interface){
|
2010-09-26 04:07:15 +00:00
|
|
|
return sptr(new libusb_control_impl(libusb::device_handle::get_cached_handle(
|
|
|
|
|
boost::static_pointer_cast<libusb::special_handle>(handle)->get_device()
|
2011-09-19 23:14:12 +00:00
|
|
|
), interface));
|
2010-08-13 20:40:13 +00:00
|
|
|
}
|