Commit | Line | Data |
---|---|---|
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 | ||
a97980ad TJ |
20 | #include <sys/types.h> |
21 | #include <limits.h> | |
a3da1d95 | 22 | |
0e302db6 TJ |
23 | /* Kernel USB headers */ |
24 | #include <linux/usb.h> | |
25 | #include <linux/usbdevice_fs.h> | |
26 | ||
de22df10 | 27 | enum ftdi_chip_type { TYPE_AM=0, TYPE_BM=1, TYPE_2232C=2 }; |
53ad271d | 28 | |
a3da1d95 GE |
29 | struct ftdi_context { |
30 | // USB specific | |
a97980ad | 31 | int usb_fd; |
545820ce TJ |
32 | int usb_read_timeout; |
33 | int usb_write_timeout; | |
0e302db6 | 34 | struct usbdevfs_urb *urb; |
a3da1d95 GE |
35 | |
36 | // FTDI specific | |
53ad271d | 37 | enum ftdi_chip_type type; |
a3da1d95 GE |
38 | int baudrate; |
39 | unsigned char bitbang_enabled; | |
948f9ada | 40 | unsigned char *readbuffer; |
4ece2c24 TJ |
41 | unsigned int readbuffer_offset; |
42 | unsigned int readbuffer_remaining; | |
948f9ada TJ |
43 | unsigned int readbuffer_chunksize; |
44 | unsigned int writebuffer_chunksize; | |
d9f0cce7 | 45 | |
545820ce TJ |
46 | // FTDI FT2232C requirecments |
47 | int interface; // 0 or 1 | |
48 | int index; // 1 or 2 | |
49 | // Endpoints | |
50 | int in_ep; | |
51 | int out_ep; // 1 or 2 | |
3119537f TJ |
52 | |
53 | /* 1: (default) Normal bitbang mode, 2: FT2232C SPI bitbang mode */ | |
54 | unsigned char bitbang_mode; | |
545820ce | 55 | |
a3da1d95 GE |
56 | // misc |
57 | char *error_str; | |
58 | }; | |
59 | ||
b8aa7b35 | 60 | struct ftdi_eeprom { |
d9f0cce7 | 61 | int vendor_id; |
b8aa7b35 TJ |
62 | int product_id; |
63 | ||
d9f0cce7 | 64 | int self_powered; |
b8aa7b35 TJ |
65 | int remote_wakeup; |
66 | int BM_type_chip; | |
67 | ||
68 | int in_is_isochronous; | |
69 | int out_is_isochronous; | |
70 | int suspend_pull_downs; | |
71 | ||
72 | int use_serial; | |
73 | int change_usb_version; | |
74 | int usb_version; | |
75 | int max_power; | |
d9f0cce7 | 76 | |
b8aa7b35 TJ |
77 | char *manufacturer; |
78 | char *product; | |
79 | char *serial; | |
80 | }; | |
81 | ||
a3da1d95 GE |
82 | #ifdef __cplusplus |
83 | extern "C" { | |
84 | #endif | |
85 | ||
86 | int ftdi_init(struct ftdi_context *ftdi); | |
948f9ada | 87 | void ftdi_deinit(struct ftdi_context *ftdi); |
a3da1d95 GE |
88 | int ftdi_usb_open(struct ftdi_context *ftdi, int vendor, int product); |
89 | int ftdi_usb_close(struct ftdi_context *ftdi); | |
90 | int ftdi_usb_reset(struct ftdi_context *ftdi); | |
a60be878 | 91 | int ftdi_usb_purge_buffers(struct ftdi_context *ftdi); |
a3da1d95 GE |
92 | |
93 | int ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate); | |
948f9ada | 94 | |
be5d7eec | 95 | int ftdi_read_data(struct ftdi_context *ftdi, unsigned char *buf, int size); |
948f9ada TJ |
96 | int ftdi_read_data_set_chunksize(struct ftdi_context *ftdi, unsigned int chunksize); |
97 | int ftdi_read_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize); | |
98 | ||
99 | int ftdi_write_data(struct ftdi_context *ftdi, unsigned char *buf, int size); | |
100 | int ftdi_write_data_set_chunksize(struct ftdi_context *ftdi, unsigned int chunksize); | |
101 | int ftdi_write_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize); | |
a3da1d95 GE |
102 | |
103 | int ftdi_enable_bitbang(struct ftdi_context *ftdi, unsigned char bitmask); | |
104 | int ftdi_disable_bitbang(struct ftdi_context *ftdi); | |
105 | int ftdi_read_pins(struct ftdi_context *ftdi, unsigned char *pins); | |
106 | ||
107 | int ftdi_set_latency_timer(struct ftdi_context *ftdi, unsigned char latency); | |
108 | int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char *latency); | |
109 | ||
0e302db6 | 110 | /* init and build eeprom from ftdi_eeprom structure */ |
b8aa7b35 TJ |
111 | void ftdi_eeprom_initdefaults(struct ftdi_eeprom *eeprom); |
112 | int ftdi_eeprom_build(struct ftdi_eeprom *eeprom, unsigned char *output); | |
113 | ||
0e302db6 TJ |
114 | /* "eeprom" needs to be valid 128 byte eeprom (generated by the eeprom generator) |
115 | the checksum of the eeprom is valided */ | |
be5d7eec TJ |
116 | int ftdi_read_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom); |
117 | int ftdi_write_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom); | |
b8aa7b35 | 118 | int ftdi_erase_eeprom(struct ftdi_context *ftdi); |
a3da1d95 GE |
119 | |
120 | #ifdef __cplusplus | |
121 | } | |
122 | #endif | |
123 | ||
124 | #endif /* __libftdi_h__ */ |