Debian Codegraph @

spectro/usbio_nt.c

raw symbols SCIP
1
2 /* General USB I/O support for MSWin. */
3 /* This is a shim to allow usbio_w0 and usbio_dk to both be used. */
4 /* This file is conditionaly #included into usbio.c */
5
6 /*
7 * Argyll Color Management System
8 *
9 * Author: Graeme W. Gill
10 * Date: 2023/11/16
11 *
12 * Copyright 2006 - 2023 Graeme W. Gill
13 * All rights reserved.
14 *
15 * This material is licenced under the GNU GENERAL PUBLIC LICENSE Version 2 or later :-
16 * see the License2.txt file for licencing details.
17 */
18
19 /* Note that one of EN_LIBUSB0 or EN_USBDK both will be #defined... */
20
21 /* Add paths to USB connected device */
22 int usb_get_paths(
23 icompaths *p
24 ) {
25 int w0 = 0, dk;
26
27 #ifdef EN_LIBUSB0
28 w0 = usb_get_paths_w0(p);
29 # ifndef EN_USBDK
30 return w0;
31 # endif
32 #endif
33
34 #ifdef EN_USBDK
35 dk = usb_get_paths_dk(p);
36 # ifdef EN_LIBUSB0
37 if (dk != 0)
38 return w0;
39 # endif
40 return dk;
41 #endif
42 }
43
44 /* Copy usb_idevice contents from icompaths to icom */
45 int usb_copy_usb_idevice(icoms *d, icompath *s) {
46 if (s->usbd == NULL) {
47 d->usbd = NULL;
48 return ICOM_OK;
49 }
50 #ifdef EN_USBDK
51 if (s->usbd->is_dk)
52 return usb_copy_usb_idevice_dk(d, s);
53 #endif
54 #ifdef EN_LIBUSB0
55 return usb_copy_usb_idevice_w0(d, s);
56 #endif
57 }
58
59 /* Cleanup and then free a usb dev entry */
60 void usb_del_usb_idevice(struct usb_idevice *usbd) {
61 if (usbd == NULL)
62 return;
63 #ifdef EN_USBDK
64 if (usbd->is_dk) {
65 usb_del_usb_idevice_dk(usbd);
66 return;
67 }
68 #endif
69 #ifdef EN_LIBUSB0
70 usb_del_usb_idevice_w0(usbd);
71 #endif
72 }
73
74 /* Cleanup any USB specific icoms state */
75 void usb_del_usb(icoms *p) {
76 if (p->usbd == NULL)
77 return;
78 #ifdef EN_USBDK
79 if (p->usbd->is_dk) {
80 usb_del_usb_dk(p);
81 return;
82 }
83 #endif
84 #ifdef EN_LIBUSB0
85 usb_del_usb_w0(p);
86 #endif
87 }
88
89 /* Close an open USB port */
90 void usb_close_port(icoms *p) {
91 if (p->usbd == NULL)
92 return;
93 #ifdef EN_USBDK
94 if (p->usbd->is_dk) {
95 usb_close_port_dk(p);
96 return;
97 }
98 #endif
99 #ifdef EN_LIBUSB0
100 usb_close_port_w0(p);
101 #endif
102 }
103
104 /* Open a USB port for all our uses. */
105 static int usb_open_port(
106 icoms *p,
107 int config, /* Configuration number */
108 int wr_ep, /* Write end point */
109 int rd_ep, /* Read end point */
110 icomuflags usbflags,/* Any special handling flags */
111 int retries, /* > 0 if we should retry set_configuration (100msec) */
112 char **pnames /* List of process names to try and kill before opening */
113 ) {
114 #ifdef EN_USBDK
115 if (p->usbd->is_dk)
116 return usb_open_port_dk(p, config, wr_ep, rd_ep, usbflags, retries, pnames);
117 #endif
118 #ifdef EN_LIBUSB0
119 return usb_open_port_w0(p, config, wr_ep, rd_ep, usbflags, retries, pnames);
120 #endif
121 }
122
123 /* -------------------------------------------------------------- */
124
125 /* Universal (non-control pipe) USB transfer function, used for rd/wr. */
126 static int icoms_usb_transaction(
127 icoms *p,
128 usb_cancelt *cancelt, /* if !NULL, allows signalling another thread that op has started */
129 int *transferred,
130 icom_usb_trantype ttype, /* transfer type */
131 unsigned char endpoint, /* 0x80 for control write, 0x00 for control read */
132 unsigned char *buffer,
133 int length, /* Length to write/expected length to read */
134 unsigned int timeout /* In msec */
135 ) {
136 #ifdef EN_USBDK
137 if (p->usbd->is_dk)
138 return icoms_usb_transaction_dk(p, cancelt, transferred, ttype, endpoint, buffer, length, timeout);
139 #endif
140 #ifdef EN_LIBUSB0
141 return icoms_usb_transaction_w0(p, cancelt, transferred, ttype, endpoint, buffer, length, timeout);
142 #endif
143 }
144
145 /* Control message routine */
146 static int icoms_usb_control_msg(
147 icoms *p,
148 int *transferred,
149 int requesttype,
150 int request,
151 int value,
152 int index,
153 unsigned char *bytes,
154 int size,
155 int timeout
156 ) {
157 #ifdef EN_USBDK
158 if (p->usbd->is_dk)
159 return icoms_usb_control_msg_dk(p, transferred, requesttype, request, value, index, bytes, size, timeout);
160 #endif
161 #ifdef EN_LIBUSB0
162 return icoms_usb_control_msg_w0(p, transferred, requesttype, request, value, index, bytes, size, timeout);
163 #endif
164 }
165
166 /* Cancel i/o operation in another thread. */
167 int icoms_usb_cancel_io(
168 icoms *p,
169 usb_cancelt *cancelt
170 ) {
171 #ifdef EN_USBDK
172 if (p->usbd->is_dk)
173 return icoms_usb_cancel_io_dk(p, cancelt);
174 #endif
175 #ifdef EN_LIBUSB0
176 return icoms_usb_cancel_io_w0(p, cancelt);
177 #endif
178 }
179
180 /* Reset and end point data toggle to 0 */
181 int icoms_usb_resetep(
182 icoms *p,
183 int ep /* End point address */
184 ) {
185 #ifdef EN_USBDK
186 if (p->usbd->is_dk)
187 return icoms_usb_resetep_dk(p, ep);
188 #endif
189 #ifdef EN_LIBUSB0
190 return icoms_usb_resetep_w0(p, ep);
191 #endif
192 }
193
194 /* Clear a halt on an end point */
195 int icoms_usb_clearhalt(
196 icoms *p,
197 int ep /* End point address */
198 ) {
199 #ifdef EN_USBDK
200 if (p->usbd->is_dk)
201 return icoms_usb_clearhalt_dk(p, ep);
202 #endif
203 #ifdef EN_LIBUSB0
204 return icoms_usb_clearhalt_w0(p, ep);
205 #endif
206 }
207