1 /***************************************************************************
5 copyright : (C) 2003 by Intra2net AG
6 email : opensource@intra2net.com
7 ***************************************************************************/
9 /***************************************************************************
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; *
15 ***************************************************************************/
22 #define ftdi_error_return(code, str) do { \
23 ftdi->error_str = str; \
28 /* ftdi_init return codes:
30 -1: couldn't allocate read buffer
32 int ftdi_init(struct ftdi_context *ftdi)
35 ftdi->usb_read_timeout = 5000;
36 ftdi->usb_write_timeout = 5000;
38 ftdi->type = TYPE_BM; /* chip type */
40 ftdi->bitbang_enabled = 0;
42 ftdi->readbuffer = NULL;
43 ftdi->readbuffer_offset = 0;
44 ftdi->readbuffer_remaining = 0;
45 ftdi->writebuffer_chunksize = 4096;
51 ftdi->bitbang_mode = 1; /* 1: Normal bitbang mode, 2: SPI bitbang mode */
53 ftdi->error_str = NULL;
55 /* All fine. Now allocate the readbuffer */
56 return ftdi_read_data_set_chunksize(ftdi, 4096);
60 Open selected channels on a chip, otherwise use first channel
64 int ftdi_set_interface(struct ftdi_context *ftdi, enum ftdi_interface interface)
69 /* ftdi_usb_open_desc cares to set the right index, depending on the found chip */
73 ftdi->index = INTERFACE_B;
78 ftdi_error_return(-1, "Unknown interface");
83 void ftdi_deinit(struct ftdi_context *ftdi)
85 if (ftdi->readbuffer != NULL) {
86 free(ftdi->readbuffer);
87 ftdi->readbuffer = NULL;
92 void ftdi_set_usbdev (struct ftdi_context *ftdi, usb_dev_handle *usb)
98 /* ftdi_usb_open return codes:
100 -1: usb_find_busses() failed
101 -2: usb_find_devices() failed
102 -3: usb device not found
103 -4: unable to open device
104 -5: unable to claim device
106 -7: set baudrate failed
107 -8: get product description failed
108 -9: get serial number failed
109 -10: unable to close device
111 int ftdi_usb_open(struct ftdi_context *ftdi, int vendor, int product)
113 return ftdi_usb_open_desc(ftdi, vendor, product, NULL, NULL);
116 int ftdi_usb_open_desc(struct ftdi_context *ftdi, int vendor, int product,
117 const char* description, const char* serial)
120 struct usb_device *dev;
125 if (usb_find_busses() < 0)
126 ftdi_error_return(-1, "usb_find_busses() failed");
128 if (usb_find_devices() < 0)
129 ftdi_error_return(-2,"usb_find_devices() failed");
131 for (bus = usb_busses; bus; bus = bus->next) {
132 for (dev = bus->devices; dev; dev = dev->next) {
133 if (dev->descriptor.idVendor == vendor
134 && dev->descriptor.idProduct == product) {
135 if (!(ftdi->usb_dev = usb_open(dev)))
136 ftdi_error_return(-4, "usb_open() failed");
138 if (description != NULL) {
139 if (usb_get_string_simple(ftdi->usb_dev, dev->descriptor.iProduct, string, sizeof(string)) <= 0) {
140 usb_close (ftdi->usb_dev);
141 ftdi_error_return(-8, "unable to fetch product description");
143 if (strncmp(string, description, sizeof(string)) != 0) {
144 if (usb_close (ftdi->usb_dev) < 0)
145 ftdi_error_return(-10, "product description not matching");
149 if (serial != NULL) {
150 if (usb_get_string_simple(ftdi->usb_dev, dev->descriptor.iSerialNumber, string, sizeof(string)) <= 0) {
151 usb_close (ftdi->usb_dev);
152 ftdi_error_return(-9, "unable to fetch serial number");
154 if (strncmp(string, serial, sizeof(string)) != 0) {
155 ftdi->error_str = "serial number not matching\n";
156 if (usb_close (ftdi->usb_dev) != 0)
157 ftdi_error_return(-10, "unable to fetch serial number");
162 if (usb_claim_interface(ftdi->usb_dev, ftdi->interface) != 0) {
163 usb_close (ftdi->usb_dev);
164 ftdi_error_return(-5, "unable to claim usb device. Make sure ftdi_sio is unloaded!");
167 if (ftdi_usb_reset (ftdi) != 0) {
168 usb_close (ftdi->usb_dev);
169 ftdi_error_return(-6, "ftdi_usb_reset failed");
172 if (ftdi_set_baudrate (ftdi, 9600) != 0) {
173 usb_close (ftdi->usb_dev);
174 ftdi_error_return(-7, "set baudrate failed");
177 // Try to guess chip type
178 // Bug in the BM type chips: bcdDevice is 0x200 for serial == 0
179 if (dev->descriptor.bcdDevice == 0x400 || (dev->descriptor.bcdDevice == 0x200
180 && dev->descriptor.iSerialNumber == 0))
181 ftdi->type = TYPE_BM;
182 else if (dev->descriptor.bcdDevice == 0x200)
183 ftdi->type = TYPE_AM;
184 else if (dev->descriptor.bcdDevice == 0x500) {
185 ftdi->type = TYPE_2232C;
187 ftdi->index = INTERFACE_A;
189 ftdi_error_return(0, "all fine");
195 ftdi_error_return(-3, "device not found");
199 int ftdi_usb_reset(struct ftdi_context *ftdi)
201 if (usb_control_msg(ftdi->usb_dev, 0x40, 0, 0, ftdi->index, NULL, 0, ftdi->usb_write_timeout) != 0)
202 ftdi_error_return(-1,"FTDI reset failed");
204 // Invalidate data in the readbuffer
205 ftdi->readbuffer_offset = 0;
206 ftdi->readbuffer_remaining = 0;
211 int ftdi_usb_purge_buffers(struct ftdi_context *ftdi)
213 if (usb_control_msg(ftdi->usb_dev, 0x40, 0, 1, ftdi->index, NULL, 0, ftdi->usb_write_timeout) != 0)
214 ftdi_error_return(-1, "FTDI purge of RX buffer failed");
216 // Invalidate data in the readbuffer
217 ftdi->readbuffer_offset = 0;
218 ftdi->readbuffer_remaining = 0;
220 if (usb_control_msg(ftdi->usb_dev, 0x40, 0, 2, ftdi->index, NULL, 0, ftdi->usb_write_timeout) != 0)
221 ftdi_error_return(-2, "FTDI purge of TX buffer failed");
226 /* ftdi_usb_close return codes
228 -1: usb_release failed
231 int ftdi_usb_close(struct ftdi_context *ftdi)
235 if (usb_release_interface(ftdi->usb_dev, ftdi->interface) != 0)
238 if (usb_close (ftdi->usb_dev) != 0)
246 ftdi_convert_baudrate returns nearest supported baud rate to that requested.
247 Function is only used internally
249 static int ftdi_convert_baudrate(int baudrate, struct ftdi_context *ftdi,
250 unsigned short *value, unsigned short *index)
252 static const char am_adjust_up[8] = {0, 0, 0, 1, 0, 3, 2, 1};
253 static const char am_adjust_dn[8] = {0, 0, 0, 1, 0, 1, 2, 3};
254 static const char frac_code[8] = {0, 3, 2, 4, 1, 5, 6, 7};
255 int divisor, best_divisor, best_baud, best_baud_diff;
256 unsigned long encoded_divisor;
264 divisor = 24000000 / baudrate;
266 if (ftdi->type == TYPE_AM) {
267 // Round down to supported fraction (AM only)
268 divisor -= am_adjust_dn[divisor & 7];
271 // Try this divisor and the one above it (because division rounds down)
275 for (i = 0; i < 2; i++) {
276 int try_divisor = divisor + i;
280 // Round up to supported divisor value
281 if (try_divisor <= 8) {
282 // Round up to minimum supported divisor
284 } else if (ftdi->type != TYPE_AM && try_divisor < 12) {
285 // BM doesn't support divisors 9 through 11 inclusive
287 } else if (divisor < 16) {
288 // AM doesn't support divisors 9 through 15 inclusive
291 if (ftdi->type == TYPE_AM) {
292 // Round up to supported fraction (AM only)
293 try_divisor += am_adjust_up[try_divisor & 7];
294 if (try_divisor > 0x1FFF8) {
295 // Round down to maximum supported divisor value (for AM)
296 try_divisor = 0x1FFF8;
299 if (try_divisor > 0x1FFFF) {
300 // Round down to maximum supported divisor value (for BM)
301 try_divisor = 0x1FFFF;
305 // Get estimated baud rate (to nearest integer)
306 baud_estimate = (24000000 + (try_divisor / 2)) / try_divisor;
307 // Get absolute difference from requested baud rate
308 if (baud_estimate < baudrate) {
309 baud_diff = baudrate - baud_estimate;
311 baud_diff = baud_estimate - baudrate;
313 if (i == 0 || baud_diff < best_baud_diff) {
314 // Closest to requested baud rate so far
315 best_divisor = try_divisor;
316 best_baud = baud_estimate;
317 best_baud_diff = baud_diff;
318 if (baud_diff == 0) {
319 // Spot on! No point trying
324 // Encode the best divisor value
325 encoded_divisor = (best_divisor >> 3) | (frac_code[best_divisor & 7] << 14);
326 // Deal with special cases for encoded value
327 if (encoded_divisor == 1) {
328 encoded_divisor = 0; // 3000000 baud
329 } else if (encoded_divisor == 0x4001) {
330 encoded_divisor = 1; // 2000000 baud (BM only)
332 // Split into "value" and "index" values
333 *value = (unsigned short)(encoded_divisor & 0xFFFF);
334 if(ftdi->type == TYPE_2232C) {
335 *index = (unsigned short)(encoded_divisor >> 8);
337 *index |= ftdi->interface;
340 *index = (unsigned short)(encoded_divisor >> 16);
342 // Return the nearest baud rate
347 ftdi_set_baudrate return codes:
350 -2: setting baudrate failed
352 int ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate)
354 unsigned short value, index;
357 if (ftdi->bitbang_enabled) {
358 baudrate = baudrate*4;
361 actual_baudrate = ftdi_convert_baudrate(baudrate, ftdi, &value, &index);
362 if (actual_baudrate <= 0)
363 ftdi_error_return (-1, "Silly baudrate <= 0.");
365 // Check within tolerance (about 5%)
366 if ((actual_baudrate * 2 < baudrate /* Catch overflows */ )
367 || ((actual_baudrate < baudrate)
368 ? (actual_baudrate * 21 < baudrate * 20)
369 : (baudrate * 21 < actual_baudrate * 20)))
370 ftdi_error_return (-1, "Unsupported baudrate. Note: bitbang baudrates are automatically multiplied by 4");
372 if (usb_control_msg(ftdi->usb_dev, 0x40, 3, value, index, NULL, 0, ftdi->usb_write_timeout) != 0)
373 ftdi_error_return (-2, "Setting new baudrate failed");
375 ftdi->baudrate = baudrate;
380 int ftdi_write_data(struct ftdi_context *ftdi, unsigned char *buf, int size)
384 int total_written = 0;
386 while (offset < size) {
387 int write_size = ftdi->writebuffer_chunksize;
389 if (offset+write_size > size)
390 write_size = size-offset;
392 ret = usb_bulk_write(ftdi->usb_dev, ftdi->in_ep, buf+offset, write_size, ftdi->usb_write_timeout);
394 ftdi_error_return(ret, "usb bulk write failed");
396 total_written += ret;
397 offset += write_size;
400 return total_written;
404 int ftdi_write_data_set_chunksize(struct ftdi_context *ftdi, unsigned int chunksize)
406 ftdi->writebuffer_chunksize = chunksize;
411 int ftdi_write_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize)
413 *chunksize = ftdi->writebuffer_chunksize;
418 int ftdi_read_data(struct ftdi_context *ftdi, unsigned char *buf, int size)
420 int offset = 0, ret = 1, i, num_of_chunks, chunk_remains;
422 // everything we want is still in the readbuffer?
423 if (size <= ftdi->readbuffer_remaining) {
424 memcpy (buf, ftdi->readbuffer+ftdi->readbuffer_offset, size);
427 ftdi->readbuffer_remaining -= size;
428 ftdi->readbuffer_offset += size;
430 /* printf("Returning bytes from buffer: %d - remaining: %d\n", size, ftdi->readbuffer_remaining); */
434 // something still in the readbuffer, but not enough to satisfy 'size'?
435 if (ftdi->readbuffer_remaining != 0) {
436 memcpy (buf, ftdi->readbuffer+ftdi->readbuffer_offset, ftdi->readbuffer_remaining);
439 offset += ftdi->readbuffer_remaining;
441 // do the actual USB read
442 while (offset < size && ret > 0) {
443 ftdi->readbuffer_remaining = 0;
444 ftdi->readbuffer_offset = 0;
445 /* returns how much received */
446 ret = usb_bulk_read (ftdi->usb_dev, ftdi->out_ep, ftdi->readbuffer, ftdi->readbuffer_chunksize, ftdi->usb_read_timeout);
448 ftdi_error_return(ret, "usb bulk read failed");
451 // skip FTDI status bytes.
452 // Maybe stored in the future to enable modem use
453 num_of_chunks = ret / 64;
454 chunk_remains = ret % 64;
455 //printf("ret = %X, num_of_chunks = %X, chunk_remains = %X, readbuffer_offset = %X\n", ret, num_of_chunks, chunk_remains, ftdi->readbuffer_offset);
457 ftdi->readbuffer_offset += 2;
461 for (i = 1; i < num_of_chunks; i++)
462 memmove (ftdi->readbuffer+ftdi->readbuffer_offset+62*i,
463 ftdi->readbuffer+ftdi->readbuffer_offset+64*i,
465 if (chunk_remains > 2) {
466 memmove (ftdi->readbuffer+ftdi->readbuffer_offset+62*i,
467 ftdi->readbuffer+ftdi->readbuffer_offset+64*i,
469 ret -= 2*num_of_chunks;
471 ret -= 2*(num_of_chunks-1)+chunk_remains;
473 } else if (ret <= 2) {
474 // no more data to read?
478 // data still fits in buf?
479 if (offset+ret <= size) {
480 memcpy (buf+offset, ftdi->readbuffer+ftdi->readbuffer_offset, ret);
481 //printf("buf[0] = %X, buf[1] = %X\n", buf[0], buf[1]);
484 /* Did we read exactly the right amount of bytes? */
486 //printf("read_data exact rem %d offset %d\n",
487 //ftdi->readbuffer_remaining, offset);
490 // only copy part of the data or size <= readbuffer_chunksize
491 int part_size = size-offset;
492 memcpy (buf+offset, ftdi->readbuffer+ftdi->readbuffer_offset, part_size);
494 ftdi->readbuffer_offset += part_size;
495 ftdi->readbuffer_remaining = ret-part_size;
498 /* printf("Returning part: %d - size: %d - offset: %d - ret: %d - remaining: %d\n",
499 part_size, size, offset, ret, ftdi->readbuffer_remaining); */
510 int ftdi_read_data_set_chunksize(struct ftdi_context *ftdi, unsigned int chunksize)
512 unsigned char *new_buf;
514 // Invalidate all remaining data
515 ftdi->readbuffer_offset = 0;
516 ftdi->readbuffer_remaining = 0;
518 if ((new_buf = (unsigned char *)realloc(ftdi->readbuffer, chunksize)) == NULL)
519 ftdi_error_return(-1, "out of memory for readbuffer");
521 ftdi->readbuffer = new_buf;
522 ftdi->readbuffer_chunksize = chunksize;
528 int ftdi_read_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize)
530 *chunksize = ftdi->readbuffer_chunksize;
536 int ftdi_enable_bitbang(struct ftdi_context *ftdi, unsigned char bitmask)
538 unsigned short usb_val;
540 usb_val = bitmask; // low byte: bitmask
541 /* FT2232C: Set bitbang_mode to 2 to enable SPI */
542 usb_val |= (ftdi->bitbang_mode << 8);
544 if (usb_control_msg(ftdi->usb_dev, 0x40, 0x0B, usb_val, ftdi->index, NULL, 0, ftdi->usb_write_timeout) != 0)
545 ftdi_error_return(-1, "unable to enter bitbang mode. Perhaps not a BM type chip?");
547 ftdi->bitbang_enabled = 1;
552 int ftdi_disable_bitbang(struct ftdi_context *ftdi)
554 if (usb_control_msg(ftdi->usb_dev, 0x40, 0x0B, 0, ftdi->index, NULL, 0, ftdi->usb_write_timeout) != 0)
555 ftdi_error_return(-1, "unable to leave bitbang mode. Perhaps not a BM type chip?");
557 ftdi->bitbang_enabled = 0;
562 int ftdi_set_bitmode(struct ftdi_context *ftdi, unsigned char bitmask, unsigned char mode)
564 unsigned short usb_val;
566 usb_val = bitmask; // low byte: bitmask
567 usb_val |= (mode << 8);
568 if (usb_control_msg(ftdi->usb_dev, 0x40, 0x0B, usb_val, ftdi->index, NULL, 0, ftdi->usb_write_timeout) != 0)
569 ftdi_error_return(-1, "unable to configure bitbang mode. Perhaps not a 2232C type chip?");
571 ftdi->bitbang_mode = mode;
572 ftdi->bitbang_enabled = (mode == BITMODE_BITBANG || mode == BITMODE_SYNCBB)?1:0;
576 int ftdi_read_pins(struct ftdi_context *ftdi, unsigned char *pins)
578 unsigned short usb_val;
579 if (usb_control_msg(ftdi->usb_dev, 0xC0, 0x0C, 0, ftdi->index, (char *)&usb_val, 1, ftdi->usb_read_timeout) != 1)
580 ftdi_error_return(-1, "read pins failed");
582 *pins = (unsigned char)usb_val;
587 int ftdi_set_latency_timer(struct ftdi_context *ftdi, unsigned char latency)
589 unsigned short usb_val;
592 ftdi_error_return(-1, "latency out of range. Only valid for 1-255");
595 if (usb_control_msg(ftdi->usb_dev, 0x40, 0x09, usb_val, ftdi->index, NULL, 0, ftdi->usb_write_timeout) != 0)
596 ftdi_error_return(-2, "unable to set latency timer");
602 int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char *latency)
604 unsigned short usb_val;
605 if (usb_control_msg(ftdi->usb_dev, 0xC0, 0x0A, 0, ftdi->index, (char *)&usb_val, 1, ftdi->usb_read_timeout) != 1)
606 ftdi_error_return(-1, "reading latency timer failed");
608 *latency = (unsigned char)usb_val;
613 void ftdi_eeprom_initdefaults(struct ftdi_eeprom *eeprom)
615 eeprom->vendor_id = 0x0403;
616 eeprom->product_id = 0x6001;
618 eeprom->self_powered = 1;
619 eeprom->remote_wakeup = 1;
620 eeprom->BM_type_chip = 1;
622 eeprom->in_is_isochronous = 0;
623 eeprom->out_is_isochronous = 0;
624 eeprom->suspend_pull_downs = 0;
626 eeprom->use_serial = 0;
627 eeprom->change_usb_version = 0;
628 eeprom->usb_version = 0x0200;
629 eeprom->max_power = 0;
631 eeprom->manufacturer = NULL;
632 eeprom->product = NULL;
633 eeprom->serial = NULL;
638 ftdi_eeprom_build return codes:
639 positive value: used eeprom size
640 -1: eeprom size (128 bytes) exceeded by custom strings
642 int ftdi_eeprom_build(struct ftdi_eeprom *eeprom, unsigned char *output)
645 unsigned short checksum, value;
646 unsigned char manufacturer_size = 0, product_size = 0, serial_size = 0;
649 if (eeprom->manufacturer != NULL)
650 manufacturer_size = strlen(eeprom->manufacturer);
651 if (eeprom->product != NULL)
652 product_size = strlen(eeprom->product);
653 if (eeprom->serial != NULL)
654 serial_size = strlen(eeprom->serial);
656 size_check = 128; // eeprom is 128 bytes
657 size_check -= 28; // 28 are always in use (fixed)
658 size_check -= manufacturer_size*2;
659 size_check -= product_size*2;
660 size_check -= serial_size*2;
662 // eeprom size exceeded?
667 memset (output, 0, 128);
669 // Addr 00: Stay 00 00
670 // Addr 02: Vendor ID
671 output[0x02] = eeprom->vendor_id;
672 output[0x03] = eeprom->vendor_id >> 8;
674 // Addr 04: Product ID
675 output[0x04] = eeprom->product_id;
676 output[0x05] = eeprom->product_id >> 8;
678 // Addr 06: Device release number (0400h for BM features)
681 if (eeprom->BM_type_chip == 1)
686 // Addr 08: Config descriptor
687 // Bit 1: remote wakeup if 1
688 // Bit 0: self powered if 1
691 if (eeprom->self_powered == 1)
693 if (eeprom->remote_wakeup == 1)
697 // Addr 09: Max power consumption: max power = value * 2 mA
698 output[0x09] = eeprom->max_power;
701 // Addr 0A: Chip configuration
702 // Bit 7: 0 - reserved
703 // Bit 6: 0 - reserved
704 // Bit 5: 0 - reserved
705 // Bit 4: 1 - Change USB version
706 // Bit 3: 1 - Use the serial number string
707 // Bit 2: 1 - Enable suspend pull downs for lower power
708 // Bit 1: 1 - Out EndPoint is Isochronous
709 // Bit 0: 1 - In EndPoint is Isochronous
712 if (eeprom->in_is_isochronous == 1)
714 if (eeprom->out_is_isochronous == 1)
716 if (eeprom->suspend_pull_downs == 1)
718 if (eeprom->use_serial == 1)
720 if (eeprom->change_usb_version == 1)
727 // Addr 0C: USB version low byte when 0x0A bit 4 is set
728 // Addr 0D: USB version high byte when 0x0A bit 4 is set
729 if (eeprom->change_usb_version == 1) {
730 output[0x0C] = eeprom->usb_version;
731 output[0x0D] = eeprom->usb_version >> 8;
735 // Addr 0E: Offset of the manufacturer string + 0x80
736 output[0x0E] = 0x14 + 0x80;
738 // Addr 0F: Length of manufacturer string
739 output[0x0F] = manufacturer_size*2 + 2;
741 // Addr 10: Offset of the product string + 0x80, calculated later
742 // Addr 11: Length of product string
743 output[0x11] = product_size*2 + 2;
745 // Addr 12: Offset of the serial string + 0x80, calculated later
746 // Addr 13: Length of serial string
747 output[0x13] = serial_size*2 + 2;
750 output[0x14] = manufacturer_size*2 + 2;
751 output[0x15] = 0x03; // type: string
755 // Output manufacturer
756 for (j = 0; j < manufacturer_size; j++) {
757 output[i] = eeprom->manufacturer[j], i++;
758 output[i] = 0x00, i++;
761 // Output product name
762 output[0x10] = i + 0x80; // calculate offset
763 output[i] = product_size*2 + 2, i++;
764 output[i] = 0x03, i++;
765 for (j = 0; j < product_size; j++) {
766 output[i] = eeprom->product[j], i++;
767 output[i] = 0x00, i++;
771 output[0x12] = i + 0x80; // calculate offset
772 output[i] = serial_size*2 + 2, i++;
773 output[i] = 0x03, i++;
774 for (j = 0; j < serial_size; j++) {
775 output[i] = eeprom->serial[j], i++;
776 output[i] = 0x00, i++;
779 // calculate checksum
782 for (i = 0; i < 63; i++) {
784 value += output[(i*2)+1] << 8;
786 checksum = value^checksum;
787 checksum = (checksum << 1) | (checksum >> 15);
790 output[0x7E] = checksum;
791 output[0x7F] = checksum >> 8;
797 int ftdi_read_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom)
801 for (i = 0; i < 64; i++) {
802 if (usb_control_msg(ftdi->usb_dev, 0xC0, 0x90, 0, i, eeprom+(i*2), 2, ftdi->usb_read_timeout) != 2)
803 ftdi_error_return(-1, "reading eeprom failed");
810 int ftdi_write_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom)
812 unsigned short usb_val;
815 for (i = 0; i < 64; i++) {
816 usb_val = eeprom[i*2];
817 usb_val += eeprom[(i*2)+1] << 8;
818 if (usb_control_msg(ftdi->usb_dev, 0x40, 0x91, usb_val, i, NULL, 0, ftdi->usb_write_timeout) != 0)
819 ftdi_error_return(-1, "unable to write eeprom");
826 int ftdi_erase_eeprom(struct ftdi_context *ftdi)
828 if (usb_control_msg(ftdi->usb_dev, 0x40, 0x92, 0, 0, NULL, 0, ftdi->usb_write_timeout) != 0)
829 ftdi_error_return(-1, "unable to erase eeprom");
835 char *ftdi_get_error_string (struct ftdi_context *ftdi)
837 return ftdi->error_str;