| 1 | /*************************************************************************** |
| 2 | ftdi.h - description |
| 3 | ------------------- |
| 4 | begin : Fri Apr 4 2003 |
| 5 | copyright : (C) 2003 by Intra2net AG |
| 6 | email : info@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 | |
| 67 | int ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate); |
| 68 | int ftdi_write_data(struct ftdi_context *ftdi, char *buf, int size); |
| 69 | int ftdi_read_data(struct ftdi_context *ftdi, char *buf, int size); |
| 70 | |
| 71 | int ftdi_enable_bitbang(struct ftdi_context *ftdi, unsigned char bitmask); |
| 72 | int ftdi_disable_bitbang(struct ftdi_context *ftdi); |
| 73 | int ftdi_read_pins(struct ftdi_context *ftdi, unsigned char *pins); |
| 74 | |
| 75 | int ftdi_set_latency_timer(struct ftdi_context *ftdi, unsigned char latency); |
| 76 | int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char *latency); |
| 77 | |
| 78 | // init and build eeprom from ftdi_eeprom structure |
| 79 | void ftdi_eeprom_initdefaults(struct ftdi_eeprom *eeprom); |
| 80 | int ftdi_eeprom_build(struct ftdi_eeprom *eeprom, unsigned char *output); |
| 81 | |
| 82 | // "eeprom" needs to be valid 128 byte eeprom (generated by the eeprom generator) |
| 83 | // the checksum of the eeprom is valided |
| 84 | int ftdi_read_eeprom(struct ftdi_context *ftdi, char *eeprom); |
| 85 | int ftdi_write_eeprom(struct ftdi_context *ftdi, char *eeprom); |
| 86 | int ftdi_erase_eeprom(struct ftdi_context *ftdi); |
| 87 | |
| 88 | #ifdef __cplusplus |
| 89 | } |
| 90 | #endif |
| 91 | |
| 92 | #endif /* __libftdi_h__ */ |