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