Statistics
| Branch: | Tag: | Revision:

root / host / lib / transport / libusb1_control.cpp @ fe7df530

History | View | Annotate | Download (2.8 kB)

1
//
2
// Copyright 2010 Ettus Research LLC
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
//
17

    
18
#include "libusb1_base.hpp"
19
#include <uhd/transport/usb_control.hpp>
20

    
21
using namespace uhd::transport;
22

    
23
const int libusb_debug_level = 3;
24
const int libusb_timeout = 0;
25

    
26
/***********************************************************************
27
 * libusb-1.0 implementation of USB control transport
28
 **********************************************************************/
29
class libusb_control_impl : public usb_control {
30
public:
31
    libusb_control_impl(usb_device_handle::sptr handle);
32
    ~libusb_control_impl();
33

    
34
    size_t submit(boost::uint8_t request_type,
35
                  boost::uint8_t request,
36
                  boost::uint16_t value,
37
                  boost::uint16_t index,
38
                  unsigned char *buff,
39
                  boost::uint16_t length); 
40

    
41
private:
42
    libusb_context       *_ctx;
43
    libusb_device_handle *_dev_handle;
44
};
45

    
46

    
47
libusb_control_impl::libusb_control_impl(usb_device_handle::sptr handle)
48
{
49
    libusb::init(&_ctx, libusb_debug_level);
50

    
51
    _dev_handle = libusb::open_device(_ctx, handle);
52

    
53
    libusb::open_interface(_dev_handle, 0);
54
}
55

    
56

    
57
libusb_control_impl::~libusb_control_impl()
58
{
59
    libusb_close(_dev_handle);
60
    libusb_exit(_ctx);
61
}
62

    
63

    
64
size_t libusb_control_impl::submit(boost::uint8_t request_type,
65
                                   boost::uint8_t request,
66
                                   boost::uint16_t value,
67
                                   boost::uint16_t index, 
68
                                   unsigned char *buff,
69
                                   boost::uint16_t length) 
70
{
71
    return libusb_control_transfer(_dev_handle,
72
                                   request_type,
73
                                   request,
74
                                   value,
75
                                   index,
76
                                   buff, 
77
                                   length, 
78
                                   libusb_timeout);
79
}
80

    
81

    
82
/***********************************************************************
83
 * USB control public make functions
84
 **********************************************************************/
85
usb_control::sptr usb_control::make(usb_device_handle::sptr handle)
86
{
87
    return sptr(new libusb_control_impl(handle));
88
}