libftdi: (tomj) userspace URB processing (I'm hardcore...)
[libftdi] / ftdi / ftdi.h
CommitLineData
a3da1d95
GE
1/***************************************************************************
2 ftdi.h - description
3 -------------------
4 begin : Fri Apr 4 2003
5 copyright : (C) 2003 by Intra2net AG
5fdb1cb1 6 email : opensource@intra2net.com
a3da1d95
GE
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU Lesser General Public License *
13 * version 2.1 as published by the Free Software Foundation; *
14 * *
15 ***************************************************************************/
16
17#ifndef __libftdi_h__
18#define __libftdi_h__
19
0e302db6 20/* libusb header */
1d1c9d80 21#include <usb.h>
a3da1d95 22
0e302db6
TJ
23/* Kernel USB headers */
24#include <linux/usb.h>
25#include <linux/usbdevice_fs.h>
26
27/* Keep this in sync with libusb */
28struct usb_dev_handle {
29 int fd;
30
31 struct usb_bus *bus;
32 struct usb_device *device;
33
34 int config;
35 int interface;
36 int altsetting;
37
38 /* Added by RMT so implementations can store other per-open-device data */
39 void *impl_info;
40};
41
42
de22df10 43enum ftdi_chip_type { TYPE_AM=0, TYPE_BM=1, TYPE_2232C=2 };
53ad271d 44
a3da1d95
GE
45struct ftdi_context {
46 // USB specific
47 struct usb_dev_handle *usb_dev;
545820ce
TJ
48 int usb_read_timeout;
49 int usb_write_timeout;
0e302db6 50 struct usbdevfs_urb *urb;
a3da1d95
GE
51
52 // FTDI specific
53ad271d 53 enum ftdi_chip_type type;
a3da1d95
GE
54 int baudrate;
55 unsigned char bitbang_enabled;
948f9ada 56 unsigned char *readbuffer;
4ece2c24
TJ
57 unsigned int readbuffer_offset;
58 unsigned int readbuffer_remaining;
948f9ada
TJ
59 unsigned int readbuffer_chunksize;
60 unsigned int writebuffer_chunksize;
d9f0cce7 61
545820ce
TJ
62 // FTDI FT2232C requirecments
63 int interface; // 0 or 1
64 int index; // 1 or 2
65 // Endpoints
66 int in_ep;
67 int out_ep; // 1 or 2
3119537f
TJ
68
69 /* 1: (default) Normal bitbang mode, 2: FT2232C SPI bitbang mode */
70 unsigned char bitbang_mode;
545820ce 71
a3da1d95
GE
72 // misc
73 char *error_str;
74};
75
b8aa7b35 76struct ftdi_eeprom {
d9f0cce7 77 int vendor_id;
b8aa7b35
TJ
78 int product_id;
79
d9f0cce7 80 int self_powered;
b8aa7b35
TJ
81 int remote_wakeup;
82 int BM_type_chip;
83
84 int in_is_isochronous;
85 int out_is_isochronous;
86 int suspend_pull_downs;
87
88 int use_serial;
89 int change_usb_version;
90 int usb_version;
91 int max_power;
d9f0cce7 92
b8aa7b35
TJ
93 char *manufacturer;
94 char *product;
95 char *serial;
96};
97
a3da1d95
GE
98#ifdef __cplusplus
99extern "C" {
100#endif
101
102 int ftdi_init(struct ftdi_context *ftdi);
948f9ada 103 void ftdi_deinit(struct ftdi_context *ftdi);
a3da1d95
GE
104 void ftdi_set_usbdev (struct ftdi_context *ftdi, usb_dev_handle *usbdev);
105 int ftdi_usb_open(struct ftdi_context *ftdi, int vendor, int product);
106 int ftdi_usb_close(struct ftdi_context *ftdi);
107 int ftdi_usb_reset(struct ftdi_context *ftdi);
a60be878 108 int ftdi_usb_purge_buffers(struct ftdi_context *ftdi);
a3da1d95
GE
109
110 int ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate);
948f9ada 111
be5d7eec 112 int ftdi_read_data(struct ftdi_context *ftdi, unsigned char *buf, int size);
948f9ada
TJ
113 int ftdi_read_data_set_chunksize(struct ftdi_context *ftdi, unsigned int chunksize);
114 int ftdi_read_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize);
115
116 int ftdi_write_data(struct ftdi_context *ftdi, unsigned char *buf, int size);
117 int ftdi_write_data_set_chunksize(struct ftdi_context *ftdi, unsigned int chunksize);
118 int ftdi_write_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize);
a3da1d95
GE
119
120 int ftdi_enable_bitbang(struct ftdi_context *ftdi, unsigned char bitmask);
121 int ftdi_disable_bitbang(struct ftdi_context *ftdi);
122 int ftdi_read_pins(struct ftdi_context *ftdi, unsigned char *pins);
123
124 int ftdi_set_latency_timer(struct ftdi_context *ftdi, unsigned char latency);
125 int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char *latency);
126
0e302db6 127 /* init and build eeprom from ftdi_eeprom structure */
b8aa7b35
TJ
128 void ftdi_eeprom_initdefaults(struct ftdi_eeprom *eeprom);
129 int ftdi_eeprom_build(struct ftdi_eeprom *eeprom, unsigned char *output);
130
0e302db6
TJ
131 /* "eeprom" needs to be valid 128 byte eeprom (generated by the eeprom generator)
132 the checksum of the eeprom is valided */
be5d7eec
TJ
133 int ftdi_read_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom);
134 int ftdi_write_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom);
b8aa7b35 135 int ftdi_erase_eeprom(struct ftdi_context *ftdi);
a3da1d95
GE
136
137#ifdef __cplusplus
138}
139#endif
140
141#endif /* __libftdi_h__ */