libftdi: (tomj) improved write performance and configurable chunksize,
[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;
25 int usb_timeout;
26
27 // FTDI specific
28 int baudrate;
29 unsigned char bitbang_enabled;
948f9ada
TJ
30 unsigned char *readbuffer;
31 unsigned char readbuffer_offset;
32 unsigned char readbuffer_remaining;
33 unsigned int readbuffer_chunksize;
34 unsigned int writebuffer_chunksize;
35
a3da1d95
GE
36 // misc
37 char *error_str;
38};
39
b8aa7b35
TJ
40struct ftdi_eeprom {
41 int vendor_id;
42 int product_id;
43
44 int self_powered;
45 int remote_wakeup;
46 int BM_type_chip;
47
48 int in_is_isochronous;
49 int out_is_isochronous;
50 int suspend_pull_downs;
51
52 int use_serial;
53 int change_usb_version;
54 int usb_version;
55 int max_power;
56
57 char *manufacturer;
58 char *product;
59 char *serial;
60};
61
a3da1d95
GE
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66 int ftdi_init(struct ftdi_context *ftdi);
948f9ada 67 void ftdi_deinit(struct ftdi_context *ftdi);
a3da1d95
GE
68 void ftdi_set_usbdev (struct ftdi_context *ftdi, usb_dev_handle *usbdev);
69 int ftdi_usb_open(struct ftdi_context *ftdi, int vendor, int product);
70 int ftdi_usb_close(struct ftdi_context *ftdi);
71 int ftdi_usb_reset(struct ftdi_context *ftdi);
a60be878 72 int ftdi_usb_purge_buffers(struct ftdi_context *ftdi);
a3da1d95
GE
73
74 int ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate);
948f9ada 75
be5d7eec 76 int ftdi_read_data(struct ftdi_context *ftdi, unsigned char *buf, int size);
948f9ada
TJ
77 int ftdi_read_data_set_chunksize(struct ftdi_context *ftdi, unsigned int chunksize);
78 int ftdi_read_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize);
79
80 int ftdi_write_data(struct ftdi_context *ftdi, unsigned char *buf, int size);
81 int ftdi_write_data_set_chunksize(struct ftdi_context *ftdi, unsigned int chunksize);
82 int ftdi_write_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize);
a3da1d95
GE
83
84 int ftdi_enable_bitbang(struct ftdi_context *ftdi, unsigned char bitmask);
85 int ftdi_disable_bitbang(struct ftdi_context *ftdi);
86 int ftdi_read_pins(struct ftdi_context *ftdi, unsigned char *pins);
87
88 int ftdi_set_latency_timer(struct ftdi_context *ftdi, unsigned char latency);
89 int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char *latency);
90
b8aa7b35
TJ
91 // init and build eeprom from ftdi_eeprom structure
92 void ftdi_eeprom_initdefaults(struct ftdi_eeprom *eeprom);
93 int ftdi_eeprom_build(struct ftdi_eeprom *eeprom, unsigned char *output);
94
a3da1d95
GE
95 // "eeprom" needs to be valid 128 byte eeprom (generated by the eeprom generator)
96 // the checksum of the eeprom is valided
be5d7eec
TJ
97 int ftdi_read_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom);
98 int ftdi_write_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom);
b8aa7b35 99 int ftdi_erase_eeprom(struct ftdi_context *ftdi);
a3da1d95
GE
100
101#ifdef __cplusplus
102}
103#endif
104
105#endif /* __libftdi_h__ */