Debian Codegraph @

src/ticables.h

raw symbols SCIP
1 /* Hey EMACS -*- linux-c -*- */
2 /* $Id$ */
3
4 /* libticables2 - link cable library, a part of the TiLP project
5 * Copyright (C) 1999-2005 Romain Lievin
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #ifndef __TICABLES__
23 #define __TICABLES__
24
25 #ifdef HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28
29 #include <stdint.h>
30 #include <string.h>
31 #include "export1.h"
32 #include "timeout.h"
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 /***********************/
39 /* Types & Definitions */
40 /***********************/
41
42 /* Versioning */
43
44 #ifdef __WIN32__
45 # define libticables2_VERSION "1.3.6"
46 #else
47 # define libticables2_VERSION VERSION
48 #endif
49
50 /* Types */
51
52 #define DFLT_TIMEOUT 15 /* 1.5 second */
53 #define DFLT_DELAY 10 /* 10 micro-seconds */
54
55 #define ERROR_READ_TIMEOUT 4 /* fixed in error.h */
56 #define ERROR_WRITE_TIMEOUT 6 /* fixed in error.h */
57
58 /**
59 * CableModel:
60 *
61 * An enumeration which contains the following cable types:
62 **/
63 typedef enum
64 {
65 CABLE_NUL = 0,
66 CABLE_GRY, CABLE_BLK, CABLE_PAR, CABLE_SLV, CABLE_USB,
67 CABLE_VTI, CABLE_TIE, CABLE_ILP, CABLE_DEV,
68 CABLE_TCPC, CABLE_TCPS,
69 CABLE_MAX
70 } CableModel;
71
72 /**
73 * CablePort:
74 *
75 * An enumeration which contains the following ports:
76 **/
77 typedef enum
78 {
79 PORT_0 = 0,
80 PORT_1, PORT_FIRST = PORT_1, PORT_2, PORT_3, PORT_4, PORT_MAX
81 } CablePort;
82
83 /**
84 * UsbPid:
85 *
86 * An enumeration which contains the following devices:
87 **/
88 typedef enum
89 {
90 PID_UNKNOWN = 0,
91 PID_TIGLUSB = 0xE001,
92 PID_TI89TM = 0xE004,
93 PID_TI84P = 0xE003,
94 PID_TI84P_SE = 0xE008,
95 PID_NSPIRE = 0xE012,
96 } UsbPid;
97
98 /**
99 * CableStatus:
100 *
101 * An enumeration which contains the following values:
102 **/
103 typedef enum
104 {
105 STATUS_NONE = 0,
106 STATUS_RX = 1,
107 STATUS_TX = 2,
108 } CableStatus;
109
110 /**
111 * ProbingMethod:
112 *
113 * Defines how to probe cables:
114 **/
115 typedef enum
116 {
117 PROBE_NONE = 0,
118 PROBE_FIRST = 1,
119 PROBE_USB = 2,
120 PROBE_DBUS = 4,
121 PROBE_ALL = 6,
122 } ProbingMethod;
123
124 /**
125 * CableFnctsIdx:
126 *
127 * Index of function in the #CableFncts structure:
128 **/
129 typedef enum
130 {
131 CABLE_FNCT_PREPARE=0,
132 CABLE_FNCT_OPEN,
133 CABLE_FNCT_CLOSE,
134 CABLE_FNCT_RESET,
135 CABLE_FNCT_PROBE,
136 CABLE_FNCT_TIMEOUT,
137 CABLE_FNCT_SEND,
138 CABLE_FNCT_RECV,
139 CABLE_FNCT_CHECK,
140 CABLE_FNCT_SET_D0,
141 CABLE_FNCT_SET_D1,
142 CABLE_FNCT_GET_D0,
143 CABLE_FNCT_GET_D1,
144 CABLE_FNCT_SET_RAW,
145 CABLE_FNCT_GET_RAW,
146 CABLE_FNCT_SET_DEVICE,
147 CABLE_FNCT_GET_DEVICE_INFO,
148 CABLE_FNCT_LAST // Keep this one last
149 } CableFnctsIdx;
150
151 /**
152 * CableFamily:
153 *
154 * Defines the various types of devices supported and which can be
155 * detected automatically; each family is generally incompatible with
156 * the others in terms of protocol, file formats, or both.
157 */
158 typedef enum
159 {
160 CABLE_FAMILY_UNKNOWN = 0,
161 CABLE_FAMILY_DBUS, /* Traditional TI link protocol */
162 CABLE_FAMILY_USB_TI8X, /* Direct USB for TI-84 Plus, CSE, CE, etc. */
163 CABLE_FAMILY_USB_TI9X, /* Direct USB for TI-89 Titanium */
164 CABLE_FAMILY_USB_NSPIRE /* Direct USB for TI-Nspire series */
165 } CableFamily;
166
167 /**
168 * CableVariant:
169 *
170 * Defines the various sub-types (for a given CableFamily) that are
171 * supported and can be detected automatically.
172 */
173 typedef enum
174 {
175 CABLE_VARIANT_UNKNOWN = 0,
176 CABLE_VARIANT_TIGLUSB, /* CABLE_FAMILY_DBUS */
177 CABLE_VARIANT_TI84P, /* CABLE_FAMILY_USB_TI8X */
178 CABLE_VARIANT_TI84PSE, /* CABLE_FAMILY_USB_TI8X */
179 CABLE_VARIANT_TI84PCSE, /* CABLE_FAMILY_USB_TI8X */
180 CABLE_VARIANT_TI84PCE, /* CABLE_FAMILY_USB_TI8X */
181 CABLE_VARIANT_TI83PCE, /* CABLE_FAMILY_USB_TI8X */
182 CABLE_VARIANT_TI82A, /* CABLE_FAMILY_USB_TI8X */
183 CABLE_VARIANT_TI89TM, /* CABLE_FAMILY_USB_TI9X */
184 CABLE_VARIANT_NSPIRE, /* CABLE_FAMILY_USB_NSPIRE */
185 CABLE_VARIANT_TI84PT /* CABLE_FAMILY_USB_TI8X */
186 } CableVariant;
187
188 /**
189 * CableDeviceInfo:
190 * @family: calculator family
191 * @variant: calculator variant
192 *
193 * Information returned for each cable by ticables_get_usb_device_info.
194 */
195 typedef struct
196 {
197 CableFamily family;
198 CableVariant variant;
199 } CableDeviceInfo;
200
201 /**
202 * DataRate:
203 * @count: number of bytes transferred
204 * @start: the time when transfer started
205 * @current: free of use
206 * @stop: the time when transfer finished
207 *
208 * A structure used for benchmarks.
209 * !!! This structure is for private use !!!
210 **/
211 typedef struct
212 {
213 int count;
214 tiTIME start;
215 tiTIME current;
216 tiTIME stop;
217 } DataRate;
218
219 typedef struct _CableFncts CableFncts;
220 typedef struct _CableHandle CableHandle;
221
222 /**
223 * Cable:
224 * @model: link cable model (CableModel).
225 * @name: name of cable like "SER"
226 * @fullname: complete name of cable like "BlackLink"
227 * @description: description of cable like "serial cable"
228 * @need_open: set if cable need to be 'open'/'close' before calling 'probe'
229 * @prepare: detect and map I/O
230 * @probe: check for cable presence
231 * @timeout: used to update timeout
232 * @open: open I/O port or device
233 * @close: close I/O port or device
234 * @reset: reset I/O port or device
235 * @send: send data onto the cable
236 * @recv: recv data from cable
237 * @check: check for data arrival
238 * @set_d0: set D0/red wire
239 * @set_d1: set D1/white wire
240 * @get_d0 get D0/red wire
241 * @get_d1 set D1/white wire
242 * @set_raw: set both wires
243 * @get_raw: read both wires
244 *
245 * A structure used for handling a link cable.
246 * !!! This structure is for private use !!!
247 **/
248 struct _CableFncts
249 {
250 const int model;
251 const char* name;
252 const char* fullname;
253 const char* description;
254
255 const int need_open;
256
257 int (*prepare) (CableHandle *);
258
259 int (*open) (CableHandle *);
260 int (*close) (CableHandle *);
261 int (*reset) (CableHandle *);
262 int (*probe) (CableHandle *);
263 int (*timeout) (CableHandle *);
264
265 int (*send) (CableHandle *, uint8_t *, uint32_t);
266 int (*recv) (CableHandle *, uint8_t *, uint32_t);
267 int (*check) (CableHandle *, int *);
268
269 int (*set_d0) (CableHandle *, int);
270 int (*set_d1) (CableHandle *, int);
271 int (*get_d0) (CableHandle *);
272 int (*get_d1) (CableHandle *);
273 int (*set_raw) (CableHandle *, int);
274 int (*get_raw) (CableHandle *, int *);
275 int (*set_device) (CableHandle*, const char*);
276 int (*get_device_info) (CableHandle *, CableDeviceInfo *);
277 };
278
279 typedef int (*ticables_pre_send_hook_type)(CableHandle * handle, uint8_t * data, uint32_t len);
280 typedef int (*ticables_post_send_hook_type)(CableHandle * handle, uint8_t * data, uint32_t len, int retval);
281 typedef int (*ticables_pre_recv_hook_type)(CableHandle * handle, uint8_t * data, uint32_t len);
282 typedef int (*ticables_post_recv_hook_type)(CableHandle * handle, uint8_t * data, uint32_t len, int retval);
283
284 /**
285 * CableEventType:
286 *
287 * Defines the various events fired by libticables into a registered event hook, if any.
288 */
289 typedef enum
290 {
291 CABLE_EVENT_TYPE_UNKNOWN = 0,
292 CABLE_EVENT_TYPE_BEFORE_OPEN,
293 CABLE_EVENT_TYPE_AFTER_OPEN,
294 CABLE_EVENT_TYPE_BEFORE_CLOSE,
295 CABLE_EVENT_TYPE_AFTER_CLOSE,
296 CABLE_EVENT_TYPE_BEFORE_RESET,
297 CABLE_EVENT_TYPE_AFTER_RESET,
298 CABLE_EVENT_TYPE_BEFORE_SEND = 16384,
299 CABLE_EVENT_TYPE_AFTER_SEND,
300 CABLE_EVENT_TYPE_BEFORE_RECV,
301 CABLE_EVENT_TYPE_AFTER_RECV,
302 CABLE_EVENT_TYPE_BEFORE_GENERIC_OPERATION = 32768,
303 CABLE_EVENT_TYPE_AFTER_GENERIC_OPERATION,
304 CABLE_EVENT_TYPE_USER = 49152
305 } CableEventType;
306
307 /**
308 * CableEventData:
309 * @version: event protocol version.
310 * @type: event type
311 * @retval: return value of the operation, for "after" events.
312 * @open: whether the cable is open.
313 * @operation: index (CalcFnctsIdx) of the generic operation invoked by the library user, if any.
314 * @data: data to be sent / received, if any - or user-specified data.
315 *
316 * Information returned for every event fired by the libticables library; only a subset of the fields is valid for some event types.
317 */
318 typedef struct
319 {
320 unsigned int version;
321 CableEventType type;
322 int retval;
323 int open;
324 CableFnctsIdx operation;
325 union
326 {
327 int intval;
328 void * ptrval;
329 const void * cptrval;
330 struct
331 {
332 uint8_t * data;
333 uint32_t len;
334 } data;
335 struct
336 {
337 uint8_t * data;
338 uint32_t len;
339 } user_data;
340 } data;
341 } CableEventData;
342
343 typedef int (*ticables_event_hook_type)(CableHandle * handle, uint32_t event_count, const CableEventData * event, void * user_pointer);
344
345 /**
346 * CableHandle:
347 * @model: cable model
348 * @port: generic port
349 * @timeout: timeout value in 0.1 seconds
350 * @delay: inter-bit delay for serial/parallel cable in us
351 * @device: device name like COMx or ttySx (if used)
352 * @address: I/O base address of device (if used)
353 * @cable: a Cable structure used by this handle
354 * @rate: data rate during transfers
355 * @priv: opaque data for internal/private use (static)
356 * @priv2: idem (allocated)
357 * @priv3: idem (static)
358 * @open: set if cable has been open
359 * @busy: set if cable is busy
360 * @pre_send_hook: callback fired before sending a block of data (deprecated).
361 * @post_send_hook: callback fired after sending a block of data (deprecated).
362 * @pre_recv_hook: callback fired before receiving a block of data (deprecated).
363 * @post_recv_hook: callback fired after receiving a block of data (deprecated).
364 * @event_hook: callback fired upon various events (replaces and expands on the deprecated callbacks).
365 * @user_pointer: user-set pointer passed to the event callbacks.
366 * @event_count: number of events sent since this handle was created.
367 *
368 * A structure used to store information as an handle.
369 * !!! This structure is for private use !!!
370 **/
371 struct _CableHandle
372 {
373 CableModel model;
374 CablePort port;
375 unsigned int timeout;
376 unsigned int delay;
377
378 char * device;
379 unsigned int address;
380
381 CableFncts* cable;
382 DataRate rate;
383
384 // TODO for next gen struct {
385 void* priv;
386 void* priv2;
387 void* priv3;
388 // } priv; and probably after open + busy.
389
390 int open;
391 int busy;
392
393 ticables_event_hook_type event_hook;
394 void * user_pointer;
395 uint32_t event_count;
396 };
397
398 /**
399 * CableOptions:
400 * @cable_model: model
401 * @cable_port: port
402 * @cable_timeout: timeout in tenth of seconds
403 * @cable_delay: inter-bit delay in us
404 * @calc_model: calculator model
405 *
406 * A convenient structure free of use by the user.
407 **/
408 typedef struct
409 {
410 CableModel model;
411 CablePort port;
412 unsigned int timeout;
413 unsigned int delay;
414
415 int calc; // unused
416 } CableOptions;
417
418 // namespace scheme: library_class_function like ticables_fext_get
419
420 /****************/
421 /* Entry points */
422 /****************/
423
424 TIEXPORT1 int TICALL ticables_library_init(void);
425 TIEXPORT1 int TICALL ticables_library_exit(void);
426
427 /*********************/
428 /* General functions */
429 /*********************/
430
431 // ticables.c
432 TIEXPORT1 const char * TICALL ticables_version_get(void);
433 TIEXPORT1 uint32_t TICALL ticables_supported_cables(void);
434 TIEXPORT1 uint32_t TICALL ticables_max_ports(void);
435
436 TIEXPORT1 CableHandle * TICALL ticables_handle_new(CableModel model, CablePort port);
437 TIEXPORT1 int TICALL ticables_handle_del(CableHandle *handle);
438
439 TIEXPORT1 unsigned int TICALL ticables_options_set_timeout(CableHandle *handle, unsigned int timeout);
440 TIEXPORT1 unsigned int TICALL ticables_options_set_delay(CableHandle *handle, unsigned int delay);
441
442 TIEXPORT1 CableModel TICALL ticables_get_model(CableHandle *handle);
443 TIEXPORT1 CablePort TICALL ticables_get_port(CableHandle *handle);
444 TIEXPORT1 const char * TICALL ticables_get_device(CableHandle *handle);
445 TIEXPORT1 unsigned int TICALL ticables_get_timeout(CableHandle *handle);
446 TIEXPORT1 unsigned int TICALL ticables_get_delay(CableHandle *handle);
447
448 TIEXPORT1 int TICALL ticables_handle_show(CableHandle *handle);
449
450 // error.c
451 TIEXPORT1 int TICALL ticables_error_get(int number, char **message);
452 TIEXPORT1 int TICALL ticables_error_free(char *message);
453
454 // link_xxx.c
455 TIEXPORT1 int TICALL ticables_cable_open(CableHandle *handle);
456 TIEXPORT1 int TICALL ticables_cable_close(CableHandle *handle);
457
458 TIEXPORT1 int TICALL ticables_cable_reset(CableHandle *handle);
459 TIEXPORT1 int TICALL ticables_cable_probe(CableHandle *handle, int *result);
460
461 TIEXPORT1 int TICALL ticables_cable_send(CableHandle *handle, uint8_t *data, uint32_t len);
462 TIEXPORT1 int TICALL ticables_cable_recv(CableHandle *handle, uint8_t *data, uint32_t len);
463
464 TIEXPORT1 int TICALL ticables_cable_check(CableHandle *handle, CableStatus *status);
465
466 TIEXPORT1 int TICALL ticables_cable_set_d0(CableHandle *handle, int state);
467 TIEXPORT1 int TICALL ticables_cable_set_d1(CableHandle *handle, int state);
468
469 TIEXPORT1 int TICALL ticables_cable_get_d0(CableHandle *handle);
470 TIEXPORT1 int TICALL ticables_cable_get_d1(CableHandle *handle);
471
472 TIEXPORT1 int TICALL ticables_cable_set_raw(CableHandle *handle, int state);
473 TIEXPORT1 int TICALL ticables_cable_get_raw(CableHandle *handle, int *state);
474
475 TIEXPORT1 int TICALL ticables_cable_set_device(CableHandle *handle, const char *device);
476
477 TIEXPORT1 int TICALL ticables_cable_get_device_info(CableHandle *handle, CableDeviceInfo *info);
478
479 TIEXPORT1 int TICALL ticables_progress_reset(CableHandle *handle);
480 TIEXPORT1 int TICALL ticables_progress_get(CableHandle *handle, int *count, int *msec, float *rate);
481
482 TIEXPORT1 int TICALL ticables_cable_put(CableHandle *handle, uint8_t data);
483 TIEXPORT1 int TICALL ticables_cable_get(CableHandle *handle, uint8_t *data);
484
485 TILIBS_DEPRECATED TIEXPORT1 ticables_pre_send_hook_type TICALL ticables_cable_get_pre_send_hook(CableHandle *handle);
486 TILIBS_DEPRECATED TIEXPORT1 ticables_pre_send_hook_type TICALL ticables_cable_set_pre_send_hook(CableHandle *handle, ticables_pre_send_hook_type hook);
487 TILIBS_DEPRECATED TIEXPORT1 ticables_post_send_hook_type TICALL ticables_cable_get_post_send_hook(CableHandle *handle);
488 TILIBS_DEPRECATED TIEXPORT1 ticables_post_send_hook_type TICALL ticables_cable_set_post_send_hook(CableHandle *handle, ticables_post_send_hook_type hook);
489
490 TILIBS_DEPRECATED TIEXPORT1 ticables_pre_recv_hook_type TICALL ticables_cable_get_pre_recv_hook(CableHandle *handle);
491 TILIBS_DEPRECATED TIEXPORT1 ticables_pre_recv_hook_type TICALL ticables_cable_set_pre_recv_hook(CableHandle *handle, ticables_pre_recv_hook_type hook);
492 TILIBS_DEPRECATED TIEXPORT1 ticables_post_recv_hook_type TICALL ticables_cable_get_post_recv_hook(CableHandle *handle);
493 TILIBS_DEPRECATED TIEXPORT1 ticables_post_recv_hook_type TICALL ticables_cable_set_post_recv_hook(CableHandle *handle, ticables_post_recv_hook_type hook);
494
495 TIEXPORT1 ticables_event_hook_type TICALL ticables_cable_get_event_hook(CableHandle *handle);
496 TIEXPORT1 ticables_event_hook_type TICALL ticables_cable_set_event_hook(CableHandle *handle, ticables_event_hook_type hook);
497 TIEXPORT1 void * ticables_cable_get_event_user_pointer(CableHandle *handle);
498 TIEXPORT1 void * ticables_cable_set_event_user_pointer(CableHandle *handle, void * user_pointer);
499 TIEXPORT1 uint32_t TICALL ticables_cable_get_event_count(CableHandle *handle);
500 TIEXPORT1 int TICALL ticables_cable_fire_user_event(CableHandle *handle, CableEventType type, int retval, void * user_data, uint32_t user_len);
501
502 // type2str.c
503 TIEXPORT1 const char * TICALL ticables_model_to_string(CableModel model);
504 TIEXPORT1 CableModel TICALL ticables_string_to_model (const char *str);
505
506 TIEXPORT1 const char * TICALL ticables_port_to_string(CablePort port);
507 TIEXPORT1 CablePort TICALL ticables_string_to_port(const char *str);
508
509 TIEXPORT1 const char * TICALL ticables_usbpid_to_string(UsbPid pid);
510 TIEXPORT1 UsbPid TICALL ticables_string_to_usbpid(const char *str);
511
512 // probe.c
513 TIEXPORT1 int TICALL ticables_probing_do(int ***result, unsigned int timeout, ProbingMethod method);
514 TIEXPORT1 int TICALL ticables_probing_finish(int ***result);
515 TIEXPORT1 void TICALL ticables_probing_show(int **array);
516 TIEXPORT1 int TICALL ticables_probing_found(int *array);
517
518 TIEXPORT1 int TICALL ticables_is_usb_enabled(void);
519
520 TIEXPORT1 int TICALL ticables_get_usb_device_info(CableDeviceInfo **array, int *len);
521 TIEXPORT1 int TICALL ticables_free_usb_device_info(CableDeviceInfo *array);
522
523 TIEXPORT1 int TICALL ticables_get_usb_devices(int **array, int *len);
524 TIEXPORT1 int TICALL ticables_free_usb_devices(int *array);
525
526 /************************/
527 /* Deprecated functions */
528 /************************/
529
530 #ifdef __cplusplus
531 }
532 #endif
533
534 #endif