libftdi, ftdi_eeprom: (tomj) changed all email addresses to opensource@intra2net.com
[libftdi] / ftdi / ftdi.h
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 #include <usb.h>
21
22 struct 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;
30
31     // misc
32     char *error_str;
33 };
34
35 struct ftdi_eeprom {
36     int vendor_id;
37     int product_id;
38
39     int self_powered;
40     int remote_wakeup;
41     int BM_type_chip;
42
43     int in_is_isochronous;
44     int out_is_isochronous;
45     int suspend_pull_downs;
46
47     int use_serial;
48     int change_usb_version;
49     int usb_version;
50     int max_power;
51     
52     char *manufacturer;
53     char *product;
54     char *serial;
55 };
56
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60
61     int ftdi_init(struct ftdi_context *ftdi);
62     void ftdi_set_usbdev (struct ftdi_context *ftdi, usb_dev_handle *usbdev);
63     int ftdi_usb_open(struct ftdi_context *ftdi, int vendor, int product);
64     int ftdi_usb_close(struct ftdi_context *ftdi);
65     int ftdi_usb_reset(struct ftdi_context *ftdi);
66     int ftdi_usb_purge_buffers(struct ftdi_context *ftdi);
67
68     int ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate);
69     int ftdi_write_data(struct ftdi_context *ftdi, unsigned char *buf, int size);
70     int ftdi_read_data(struct ftdi_context *ftdi, unsigned char *buf, int size);
71
72     int ftdi_enable_bitbang(struct ftdi_context *ftdi, unsigned char bitmask);
73     int ftdi_disable_bitbang(struct ftdi_context *ftdi);
74     int ftdi_read_pins(struct ftdi_context *ftdi, unsigned char *pins);
75
76     int ftdi_set_latency_timer(struct ftdi_context *ftdi, unsigned char latency);
77     int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char *latency);
78
79     // init and build eeprom from ftdi_eeprom structure
80     void ftdi_eeprom_initdefaults(struct ftdi_eeprom *eeprom);
81     int  ftdi_eeprom_build(struct ftdi_eeprom *eeprom, unsigned char *output);
82
83     // "eeprom" needs to be valid 128 byte eeprom (generated by the eeprom generator)
84     // the checksum of the eeprom is valided
85     int ftdi_read_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom);
86     int ftdi_write_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom);
87     int ftdi_erase_eeprom(struct ftdi_context *ftdi);
88
89 #ifdef __cplusplus
90 }
91 #endif
92
93 #endif /* __libftdi_h__ */