libftdi: (tomj) userspace URB processing (I'm hardcore...)
[libftdi] / ftdi / ftdi.h
... / ...
CommitLineData
1/***************************************************************************
2 ftdi.h - description
3 -------------------
4 begin : Fri Apr 4 2003
5 copyright : (C) 2003 by Intra2net AG
6 email : opensource@intra2net.com
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
20/* libusb header */
21#include <usb.h>
22
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
43enum ftdi_chip_type { TYPE_AM=0, TYPE_BM=1, TYPE_2232C=2 };
44
45struct ftdi_context {
46 // USB specific
47 struct usb_dev_handle *usb_dev;
48 int usb_read_timeout;
49 int usb_write_timeout;
50 struct usbdevfs_urb *urb;
51
52 // FTDI specific
53 enum ftdi_chip_type type;
54 int baudrate;
55 unsigned char bitbang_enabled;
56 unsigned char *readbuffer;
57 unsigned int readbuffer_offset;
58 unsigned int readbuffer_remaining;
59 unsigned int readbuffer_chunksize;
60 unsigned int writebuffer_chunksize;
61
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
68
69 /* 1: (default) Normal bitbang mode, 2: FT2232C SPI bitbang mode */
70 unsigned char bitbang_mode;
71
72 // misc
73 char *error_str;
74};
75
76struct ftdi_eeprom {
77 int vendor_id;
78 int product_id;
79
80 int self_powered;
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;
92
93 char *manufacturer;
94 char *product;
95 char *serial;
96};
97
98#ifdef __cplusplus
99extern "C" {
100#endif
101
102 int ftdi_init(struct ftdi_context *ftdi);
103 void ftdi_deinit(struct ftdi_context *ftdi);
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);
108 int ftdi_usb_purge_buffers(struct ftdi_context *ftdi);
109
110 int ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate);
111
112 int ftdi_read_data(struct ftdi_context *ftdi, unsigned char *buf, int size);
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);
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
127 /* init and build eeprom from ftdi_eeprom structure */
128 void ftdi_eeprom_initdefaults(struct ftdi_eeprom *eeprom);
129 int ftdi_eeprom_build(struct ftdi_eeprom *eeprom, unsigned char *output);
130
131 /* "eeprom" needs to be valid 128 byte eeprom (generated by the eeprom generator)
132 the checksum of the eeprom is valided */
133 int ftdi_read_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom);
134 int ftdi_write_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom);
135 int ftdi_erase_eeprom(struct ftdi_context *ftdi);
136
137#ifdef __cplusplus
138}
139#endif
140
141#endif /* __libftdi_h__ */