1# Copyright (C) 2009-2014 Wander Lairson Costa
2#
3# The following terms apply to all files associated
4# with the software unless explicitly disclaimed in individual files.
5#
6# The authors hereby grant permission to use, copy, modify, distribute,
7# and license this software and its documentation for any purpose, provided
8# that existing copyright notices are retained in all copies and that this
9# notice is included verbatim in any distributions. No written agreement,
10# license, or royalty fee is required for any of the authorized uses.
11# Modifications to this software may be copyrighted by their authors
12# and need not follow the licensing terms described here, provided that
13# the new terms are clearly indicated on the first page of each file where
14# they apply.
15#
16# IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
17# FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
18# ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
19# DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
20# POSSIBILITY OF SUCH DAMAGE.
21#
22# THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
23# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
24# FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE
25# IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
26# NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
27# MODIFICATIONS.
28
29import usb.util
30
31ID_VENDOR = 0x04d8
32ID_PRODUCT = 0xfa2e
33
34# transfer interfaces
35INTF_BULK = 0
36INTF_INTR = 1
37INTF_ISO = 2
38
39# endpoints address
40EP_BULK = 1
41EP_INTR = 2
42EP_ISO = 3
43
44# test type
45TEST_NONE = 0
46TEST_PCREAD = 1
47TEST_PCWRITE = 2
48TEST_LOOP = 3
49
50# Vendor requests
51PICFW_SET_TEST = 0x0e
52PICFW_SET_TEST = 0x0f
53PICFW_SET_VENDOR_BUFFER = 0x10
54PICFW_GET_VENDOR_BUFFER = 0x11
55
56def set_test_type(t, dev = None):
57    if dev is None:
58        dev = usb.core.find(idVendor = ID_VENDOR, idProduct = ID_PRODUCT)
59
60    bmRequestType = usb.util.build_request_type(
61                        usb.util.CTRL_OUT,
62                        usb.util.CTRL_TYPE_VENDOR,
63                        usb.util.CTRL_RECIPIENT_INTERFACE
64                    )
65
66    dev.ctrl_transfer(
67        bmRequestType = bmRequestType,
68        bRequest = PICFW_SET_TEST,
69        wValue = t,
70        wIndex = 0
71    )
72
73