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