Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (3.1 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 = 0;
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
    // Find and open the libusb_device corresponding to the
52
    // given handle and return the libusb_device_handle
53
    // that can be used for I/O purposes.
54
    _dev_handle = libusb::open_device(_ctx, handle);
55

    
56
    // Open USB interfaces for control using magic value
57
    // IN interface:      2
58
    // OUT interface:     1
59
    // Control interface: 0
60
    libusb::open_interface(_dev_handle, 0);
61
}
62

    
63

    
64
libusb_control_impl::~libusb_control_impl()
65
{
66
    libusb_close(_dev_handle);
67
    libusb_exit(_ctx);
68
}
69

    
70

    
71
size_t libusb_control_impl::submit(boost::uint8_t request_type,
72
                                   boost::uint8_t request,
73
                                   boost::uint16_t value,
74
                                   boost::uint16_t index, 
75
                                   unsigned char *buff,
76
                                   boost::uint16_t length) 
77
{
78
    return libusb_control_transfer(_dev_handle,
79
                                   request_type,
80
                                   request,
81
                                   value,
82
                                   index,
83
                                   buff, 
84
                                   length, 
85
                                   libusb_timeout);
86
}
87

    
88

    
89
/***********************************************************************
90
 * USB control public make functions
91
 **********************************************************************/
92
usb_control::sptr usb_control::make(usb_device_handle::sptr handle)
93
{
94
    return sptr(new libusb_control_impl(handle));
95
}