### Basic libftdi Usage Example Source: https://www.intra2net.com/en/developer/libftdi/documentation/index.html This example demonstrates the basic usage of libftdi, including initialization, opening a device, reading chip information, closing the device, and freeing resources. It requires the ftdi.h header and links against the libftdi library. ```c #include #include #include int main(void) { int ret; struct ftdi_context *ftdi; struct ftdi_version_info version; if ((ftdi = ftdi_new()) == 0) { fprintf(stderr, "ftdi_new failed\n"); return EXIT_FAILURE; } version = ftdi_get_library_version(); printf("Initialized libftdi %s (major: %d, minor: %d, micro: %d, snapshot ver: %s)\n", version.version_str, version.major, version.minor, version.micro, version.snapshot_str); if ((ret = ftdi_usb_open(ftdi, 0x0403, 0x6001)) < 0) { fprintf(stderr, "unable to open ftdi device: %d (%s)\n", ret, ftdi_get_error_string(ftdi)); ftdi_free(ftdi); return EXIT_FAILURE; } // Read out FTDIChip-ID of R type chips if (ftdi->type == TYPE_R) { unsigned int chipid; printf("ftdi_read_chipid: %d\n", ftdi_read_chipid(ftdi, &chipid)); printf("FTDI chipid: %X\n", chipid); } if ((ret = ftdi_usb_close(ftdi)) < 0) { fprintf(stderr, "unable to close ftdi device: %d (%s)\n", ret, ftdi_get_error_string(ftdi)); ftdi_free(ftdi); return EXIT_FAILURE; } ftdi_free(ftdi); return EXIT_SUCCESS; } ``` -------------------------------- ### Example Code for Async Mode in libFTDI Source: https://www.intra2net.com/en/developer/libftdi This snippet is an example demonstrating the asynchronous mode of operation within the libFTDI library. It is intended to showcase how to implement non-blocking data transfers. ```c /* Add example code for async mode */ ``` -------------------------------- ### Initialize and Start FTDI Stream Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi__stream_8c_source.html Sets up and initiates a data stream from an FTDI device in synchronous FIFO mode. It configures USB transfers, handles device mode switching, and starts the event loop for data reception. Ensure the device supports synchronous FIFO mode before calling. ```c int ftdi_readstream(struct ftdi_context *ftdi, FTDIStreamCallback *callback, void *userdata, int packetsPerTransfer, int numTransfers) { struct libusb_transfer **transfers; FTDIStreamState state = { callback, userdata, ftdi->max_packet_size, 1 }; int bufferSize = packetsPerTransfer * ftdi->max_packet_size; int xferIndex; int err = 0; /* Only FT2232H and FT232H know about the synchronous FIFO Mode*/ if ((ftdi->type != TYPE_2232H) && (ftdi->type != TYPE_232H)) { fprintf(stderr,"Device doesn't support synchronous FIFO mode\n"); return 1; } /* We don't know in what state we are, switch to reset*/ if (ftdi_set_bitmode(ftdi, 0xff, BITMODE_RESET) < 0) { fprintf(stderr,"Can't reset mode\n"); return 1; } /* Purge anything remaining in the buffers*/ if (ftdi_tcioflush(ftdi) < 0) { fprintf(stderr,"Can't flush FIFOs & buffers\n"); return 1; } /* * Set up all transfers */ transfers = calloc(numTransfers, sizeof *transfers); if (!transfers) { err = LIBUSB_ERROR_NO_MEM; goto cleanup; } for (xferIndex = 0; xferIndex < numTransfers; xferIndex++) { struct libusb_transfer *transfer; transfer = libusb_alloc_transfer(0); transfers[xferIndex] = transfer; if (!transfer) { err = LIBUSB_ERROR_NO_MEM; goto cleanup; } libusb_fill_bulk_transfer(transfer, ftdi->usb_dev, ftdi->out_ep, malloc(bufferSize), bufferSize, ftdi_readstream_cb, &state, 0); if (!transfer->buffer) { err = LIBUSB_ERROR_NO_MEM; goto cleanup; } transfer->status = -1; err = libusb_submit_transfer(transfer); if (err) goto cleanup; } /* Start the transfers only when everything has been set up. * Otherwise the transfers start stuttering and the PC not * fetching data for several to several ten milliseconds * and we skip blocks */ if (ftdi_set_bitmode(ftdi, 0xff, BITMODE_SYNCFF) < 0) { fprintf(stderr,"Can't set synchronous fifo mode: %s\n", ftdi_get_error_string(ftdi)); goto cleanup; } /* * Run the transfers, and periodically assess progress. */ gettimeofday(&state.progress.first.time, NULL); do { FTDIProgressInfo *progress = &state.progress; const double progressInterval = 1.0; struct timeval timeout = { 0, ftdi->usb_read_timeout * 1000}; struct timeval now; int err = libusb_handle_events_timeout(ftdi->usb_ctx, &timeout); if (err == LIBUSB_ERROR_INTERRUPTED) /* restart interrupted events */ err = libusb_handle_events_timeout(ftdi->usb_ctx, &timeout); if (!state.result) { state.result = err; } if (state.activity == 0) state.result = 1; else state.activity = 0; // If enough time has elapsed, update the progress gettimeofday(&now, NULL); if (TimevalDiff(&now, &progress->current.time) >= progressInterval) { progress->current.time = now; progress->totalTime = TimevalDiff(&progress->current.time, &progress->first.time); if (progress->prev.totalBytes) { // We have enough information to calculate rates double currentTime; currentTime = TimevalDiff(&progress->current.time, &progress->prev.time); progress->totalRate = progress->current.totalBytes /progress->totalTime; progress->currentRate = (progress->current.totalBytes - progress->prev.totalBytes) / currentTime; } state.callback(NULL, 0, progress, state.userdata); progress->prev = progress->current; } } while (!state.result); /* * Cancel any outstanding transfers, and free memory. */ cleanup: fprintf(stderr, "cleanup\n"); if (transfers) free(transfers); if (err) return err; else return state.result; } ``` -------------------------------- ### Ftdi::Context::description() Source: https://www.intra2net.com/en/developer/libftdi/documentation/classFtdi_1_1Context.html Gets the description string of the FTDI device. ```APIDOC const std::string & Ftdi::Context::description(); ``` -------------------------------- ### Basic libftdi Usage Example Source: https://www.intra2net.com/en/developer/libftdi/documentation This C code demonstrates the fundamental steps of initializing libftdi, opening an FTDI device by vendor and product ID, reading the chip ID for 'R' type chips, and then closing the device. Ensure you have the necessary headers and link against the libftdi library. ```c #include #include #include int main(void) { int ret; struct ftdi_context *ftdi; struct ftdi_version_info version; if ((ftdi = ftdi_new()) == 0) { fprintf(stderr, "ftdi_new failed\n"); return EXIT_FAILURE; } version = ftdi_get_library_version(); printf("Initialized libftdi %s (major: %d, minor: %d, micro: %d, snapshot ver: %s)\n", version.version_str, version.major, version.minor, version.micro, version.snapshot_str); if ((ret = ftdi_usb_open(ftdi, 0x0403, 0x6001)) < 0) { fprintf(stderr, "unable to open ftdi device: %d (%s)\n", ret, ftdi_get_error_string(ftdi)); ftdi_free(ftdi); return EXIT_FAILURE; } // Read out FTDIChip-ID of R type chips if (ftdi->type == TYPE_R) { unsigned int chipid; printf("ftdi_read_chipid: %d\n", ftdi_read_chipid(ftdi, &chipid)); printf("FTDI chipid: %X\n", chipid); } if ((ret = ftdi_usb_close(ftdi)) < 0) { fprintf(stderr, "unable to close ftdi device: %d (%s)\n", ret, ftdi_get_error_string(ftdi)); ftdi_free(ftdi); return EXIT_FAILURE; } ftdi_free(ftdi); return EXIT_SUCCESS; } ``` -------------------------------- ### Get Description String Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8cpp_source.html Returns the description string for the FTDI device. If not already retrieved, it calls get_strings_and_reopen to fetch it. ```cpp const std::string& Context::description() { if(d->description.empty()) get_strings_and_reopen(false,true,false); return d->description; } ``` -------------------------------- ### Loopback Definitions Source: https://www.intra2net.com/en/developer/libftdi/documentation/globals_l.html These macros define the start and end points for loopback operations within the libftdi library. ```APIDOC ## Macros ### LOOPBACK_END * **Description**: Defines the end of the loopback sequence. * **File**: ftdi.h ### LOOPBACK_START * **Description**: Defines the start of the loopback sequence. * **File**: ftdi.h ``` -------------------------------- ### Get List Size Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8cpp_source.html Returns the number of FTDI contexts currently in the list. This indicates how many devices were found. ```cpp List::ListType::size_type List::size() const { return d->list.size(); } ``` -------------------------------- ### Get Vendor String Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8cpp_source.html Returns the vendor string for the FTDI device. If not already retrieved, it calls get_strings_and_reopen to fetch it. ```cpp const std::string& Context::vendor() { if(d->vendor.empty()) get_strings_and_reopen(true,false,false); return d->vendor; } ``` -------------------------------- ### Get FTDI Device Strings Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8cpp_source.html Retrieves vendor, description, and serial strings for the FTDI device. Buffers are prepared internally. Ensure sufficient buffer sizes are allocated. ```cpp int Context::get_strings(bool vendor, bool description, bool serial) { // Prepare buffers char ivendor[512], idesc[512], iserial[512]; int ret = ftdi_usb_get_strings(d->ftdi, d->dev, vendor?ivendor:NULL, 512, description?idesc:NULL, 512, serial?iserial:NULL, 512); if (ret < 0) return -1; d->vendor = ivendor; d->description = idesc; d->serial = iserial; return 1; } ``` -------------------------------- ### Get FTDI Device Strings Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8cpp_source.html Retrieves vendor, description, and serial number strings from the FTDI device. Specify which strings to retrieve. ```cpp int Ftdi::Context::get_strings(bool vendor=true, bool description=true, bool serial=true) { return get_strings(vendor, description, serial); } ``` -------------------------------- ### Get Strings and Reopen Device Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8cpp_source.html Retrieves device strings and reopens the FTDI device. This is necessary after getting strings, as the operation can close the device. ```cpp int Context::get_strings_and_reopen(bool vendor, bool description, bool serial) { int ret = 0; if(vendor || description || serial) { if (d->dev == 0) { d->dev = libusb_get_device(d->ftdi->usb_dev); } // Get device strings (closes device) ret=get_strings(vendor, description, serial); if (ret < 0) { d->open = 0; return ret; } // Reattach device ret = ftdi_usb_open_dev(d->ftdi, d->dev); d->open = (ret >= 0); } return ret; } ``` -------------------------------- ### CBUS Python Example Code Source: https://www.intra2net.com/en/developer/libftdi This snippet refers to the inclusion of example code for utilizing the CBUS (Common Bus) functionality with Python wrappers for libFTDI. ```python /* cbus python example code (Rodney Sinclair) */ ``` -------------------------------- ### Import GPG Key Source: https://www.intra2net.com/en/developer/libftdi/download.php Import the GPG public key for verifying signatures. Ensure the key file is downloaded first. ```bash gpg --import opensource-intra2net.asc ``` -------------------------------- ### Context::open(int vendor, int product, const std::string& description, const std::string& serial, unsigned int index) Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8cpp_source.html Opens an FTDI device using vendor ID, product ID, and optional description, serial number, and index. This allows for more specific device selection. ```APIDOC ## Context::open(int vendor, int product, const std::string& description, const std::string& serial, unsigned int index) ### Description Opens an FTDI device using vendor ID, product ID, and optional description, serial number, and index. This allows for more specific device selection. ### Method ```cpp int Context::open(int vendor, int product, const std::string& description, const std::string& serial, unsigned int index) ``` ### Parameters * **vendor** (int) - The vendor ID of the FTDI device. * **product** (int) - The product ID of the FTDI device. * **description** (const std::string&) - An optional description string for device matching. * **serial** (const std::string&) - An optional serial number string for device matching. * **index** (unsigned int) - The index of the device to open if multiple devices match the criteria. ### Returns Returns 0 on success, or a negative error code on failure. ``` -------------------------------- ### Ftdi::Context Class Members - Functions starting with 'g' Source: https://www.intra2net.com/en/developer/libftdi/documentation/functions_g.html This section lists functions within the Ftdi::Context class whose names start with the letter 'g'. These functions are related to retrieving information about the FTDI device, such as strings and USB timeouts. ```APIDOC ## get_strings() ### Description Retrieves strings associated with the FTDI context. ### Method (Not specified, likely a C function call) ### Endpoint N/A ### Parameters None explicitly mentioned. ### Request Example N/A ### Response - strings (array of strings) - Description not specified. ### Response Example N/A ``` ```APIDOC ## get_strings_and_reopen() ### Description Retrieves strings and reopens the FTDI context. ### Method (Not specified, likely a C function call) ### Endpoint N/A ### Parameters None explicitly mentioned. ### Request Example N/A ### Response - strings (array of strings) - Description not specified. ### Response Example N/A ``` ```APIDOC ## get_usb_read_timeout() ### Description Retrieves the USB read timeout value for the FTDI context. ### Method (Not specified, likely a C function call) ### Endpoint N/A ### Parameters None explicitly mentioned. ### Request Example N/A ### Response - timeout (integer) - The USB read timeout value. Description not specified. ### Response Example N/A ``` ```APIDOC ## get_usb_write_timeout() ### Description Retrieves the USB write timeout value for the FTDI context. ### Method (Not specified, likely a C function call) ### Endpoint N/A ### Parameters None explicitly mentioned. ### Request Example N/A ### Response - timeout (integer) - The USB write timeout value. Description not specified. ### Response Example N/A ``` -------------------------------- ### init_defaults Source: https://www.intra2net.com/en/developer/libftdi/documentation/classFtdi_1_1Eeprom.html Initializes EEPROM with default values for manufacturer, product, and serial number. ```APIDOC ## init_defaults() ### Description Initializes the EEPROM with default values for the manufacturer, product, and serial number. ### Parameters - **manufacturer** (char *) - The manufacturer string. - **product** (char *) - The product string. - **serial** (char *) - The serial number string. ### Returns An integer status code. 0 on success, negative on error. ``` -------------------------------- ### Error String Function Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8h_source.html Function to get the last error string. ```APIDOC ## ftdi_get_error_string ### Description Returns a string describing the last error that occurred. ### Signature ```c const char *ftdi_get_error_string(struct ftdi_context *ftdi); ``` ``` -------------------------------- ### Context::open(int vendor, int product) Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8cpp_source.html Opens an FTDI device using its vendor and product IDs. This is a basic method to establish a connection. ```APIDOC ## Context::open(int vendor, int product) ### Description Opens an FTDI device using its vendor and product IDs. This is a basic method to establish a connection. ### Method ```cpp int Context::open(int vendor, int product) ``` ### Parameters * **vendor** (int) - The vendor ID of the FTDI device. * **product** (int) - The product ID of the FTDI device. ### Returns Returns 0 on success, or a negative error code on failure. ``` -------------------------------- ### Context::open Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8cpp_source.html Opens the FTDI device context. It takes a libusb_device pointer and initializes the internal device structure. ```APIDOC ## Context::open ### Description Opens the FTDI device context by associating it with a given libusb_device. ### Method `int open(struct libusb_device *dev)` ### Parameters * **dev** (`struct libusb_device *`) - A pointer to the libusb_device to be opened. ### Return Value Returns 0 on success, or -1 if the device is null or an error occurs. ``` -------------------------------- ### Ftdi::Context::get_usb_write_timeout Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8hpp_source.html Gets the USB write timeout value. ```APIDOC ## get_usb_write_timeout ### Description Gets the USB write timeout value. ### Method int ### Endpoint N/A (C++ function) ### Parameters None ### Request Example N/A ### Response #### Success Response (int) Returns the current USB write timeout value. #### Response Example ``` 1000 ``` ``` -------------------------------- ### Ftdi::Context::open() [2/4] Source: https://www.intra2net.com/en/developer/libftdi/documentation/classFtdi_1_1Context.html Opens the FTDI device using vendor and product IDs. ```APIDOC int Ftdi::Context::open(int _vendor_, int _product_); ``` -------------------------------- ### Ftdi::Context::get_usb_read_timeout Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8hpp_source.html Gets the USB read timeout value. ```APIDOC ## get_usb_read_timeout ### Description Gets the USB read timeout value. ### Method int ### Endpoint N/A (C++ function) ### Parameters None ### Request Example N/A ### Response #### Success Response (int) Returns the current USB read timeout value. #### Response Example ``` 1000 ``` ``` -------------------------------- ### Latency Timer Source: https://www.intra2net.com/en/developer/libftdi/documentation/classFtdi_1_1Context.html Get or set the latency timer for the FTDI device. ```APIDOC ## set_latency() ### Description Sets the latency timer for the FTDI device. ### Method `int Ftdi::Context::set_latency(unsigned char _latency)` ### Parameters * `_latency` (unsigned char) - The desired latency timer value in milliseconds. ### Returns On success, 0. On error, a negative value. ``` ```APIDOC ## latency() ### Description Retrieves the current latency timer value. ### Method `unsigned Ftdi::Context::latency()` ### Parameters None ### Returns An unsigned integer representing the current latency timer value in milliseconds. ``` -------------------------------- ### Ftdi::Context::open() [3/4] Source: https://www.intra2net.com/en/developer/libftdi/documentation/classFtdi_1_1Context.html Opens the FTDI device using vendor ID, product ID, description, serial number, and index. ```APIDOC int Ftdi::Context::open(int _vendor_, int _product_, const std::string & _description_, const std::string & _serial_ = std::string(), unsigned int _index_ = 0); ``` -------------------------------- ### Ftdi::Context::vendor Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8hpp_source.html Gets the vendor string of the FTDI device. ```APIDOC ## Ftdi::Context::vendor ### Description Gets the vendor string of the FTDI device. ### Method const std::string & vendor() ### Parameters None ### Return Value Returns a constant reference to the vendor string. ``` -------------------------------- ### Initialize EEPROM Defaults Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8cpp_source.html Initializes the EEPROM structure with default values for manufacturer, product, and serial number. This prepares the EEPROM for writing. ```cpp int Eeprom::init_defaults(char* manufacturer, char *product, char * serial) { return ftdi_eeprom_initdefaults(d->context, manufacturer, product, serial); } ``` -------------------------------- ### EEPROM Initialization Functions Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8h_source.html Functions for initializing and building the EEPROM content. ```APIDOC ## ftdi_eeprom_initdefaults ### Description Initializes EEPROM with default values for manufacturer, product, and serial. ### Signature ```c int ftdi_eeprom_initdefaults(struct ftdi_context *ftdi, char * manufacturer, char *product, char * serial); ``` ## ftdi_eeprom_build ### Description Builds the EEPROM content based on the current settings. ### Signature ```c int ftdi_eeprom_build(struct ftdi_context *ftdi); ``` ## ftdi_eeprom_decode ### Description Decodes the EEPROM content. If verbose is non-zero, it prints the decoded content. ### Signature ```c int ftdi_eeprom_decode(struct ftdi_context *ftdi, int verbose); ``` ``` -------------------------------- ### Ftdi::Context::open() [4/4] Source: https://www.intra2net.com/en/developer/libftdi/documentation/classFtdi_1_1Context.html Opens the FTDI device using a description string. ```APIDOC int Ftdi::Context::open(const std::string & _description_); ``` -------------------------------- ### Ftdi::Context::vendor() Source: https://www.intra2net.com/en/developer/libftdi/documentation/classFtdi_1_1Context.html Gets the vendor string of the FTDI device. ```APIDOC const std::string & Ftdi::Context::vendor(); ``` -------------------------------- ### ftdi_eeprom_initdefaults Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8c_source.html Initializes the EEPROM with default values. ```APIDOC ## ftdi_eeprom_initdefaults ### Description Initializes the EEPROM with default values. ### Signature ```c int ftdi_eeprom_initdefaults(struct ftdi_context *ftdi, char *manufacturer, char *product, char *serial) ``` ### Parameters - **ftdi** (*struct ftdi_context*) - **manufacturer** (char *) - The manufacturer string. - **product** (char *) - The product string. - **serial** (char *) - The serial number string. ### Return Value Returns 0 on success, or a negative error code on failure. ``` -------------------------------- ### Create and initialize a new ftdi_context Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8c_source.html Allocates memory for a new ftdi_context and initializes it by calling ftdi_init. Returns NULL if memory allocation fails or if ftdi_init returns an error. ```c struct ftdi_context *ftdi_new(void) { struct ftdi_context * ftdi = (struct ftdi_context *)malloc(sizeof(struct ftdi_context)); if (ftdi == NULL) { return NULL; } if (ftdi_init(ftdi) != 0) { ``` -------------------------------- ### Ftdi::Context::write_chunk_size Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8cpp_source.html Gets the current chunk size for write operations. ```APIDOC ## int write_chunk_size() ### Description Retrieves the current size of data chunks used for write operations. ### Signature int write_chunk_size() ### Returns The current chunk size in bytes. ``` -------------------------------- ### Ftdi::List::begin Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8hpp_source.html Returns an iterator to the beginning of the device list. ```APIDOC ## Ftdi::List::begin ### Description Returns an iterator to the beginning of the device list. ### Method iterator begin() ### Parameters None ### Return Value Returns an iterator pointing to the first element in the list. ``` -------------------------------- ### Ftdi::Context::read_chunk_size Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8cpp_source.html Gets the current chunk size for read operations. ```APIDOC ## int read_chunk_size() ### Description Retrieves the current size of data chunks used for read operations. ### Signature int read_chunk_size() ### Returns The current chunk size in bytes. ``` -------------------------------- ### Latency Timer Functions Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8h_source.html Functions for setting and getting the latency timer value. ```APIDOC ## ftdi_set_latency_timer ### Description Sets the latency timer for the FTDI device. ### Signature ```c int ftdi_set_latency_timer(struct ftdi_context *ftdi, unsigned char latency); ``` ## ftdi_get_latency_timer ### Description Gets the current latency timer value of the FTDI device. ### Signature ```c int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char *latency); ``` ``` -------------------------------- ### Error String Source: https://www.intra2net.com/en/developer/libftdi/documentation/classFtdi_1_1Context.html Get a human-readable string describing the last FTDI error. ```APIDOC ## error_string() ### Description Returns a string describing the last error that occurred. ### Method `const char * Ftdi::Context::error_string()` ### Parameters None ### Returns A pointer to a null-terminated string describing the last error. Returns `NULL` if no error has occurred. ``` -------------------------------- ### List Class Methods Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8cpp_source.html Methods for listing and iterating over available FTDI devices. ```APIDOC ## List Constructor ### Description Constructs a List object from a `ftdi_device_list`. ### Method `List(struct ftdi_device_list* devlist)` ### Parameters - **devlist** (struct ftdi_device_list*) - A pointer to the list of FTDI devices. ### Returns None ``` ```APIDOC ## begin ### Description Returns an iterator to the beginning of the device list. ### Method `iterator begin()` ### Parameters None ### Returns An iterator to the beginning of the list. ``` ```APIDOC ## end ### Description Returns an iterator to the end of the device list. ### Method `iterator end()` ### Parameters None ### Returns An iterator to the end of the list. ``` ```APIDOC ## begin (const) ### Description Returns a const iterator to the beginning of the device list. ### Method `const_iterator begin() const` ### Parameters None ### Returns A const iterator to the beginning of the list. ``` ```APIDOC ## end (const) ### Description Returns a const iterator to the end of the device list. ### Method `const_iterator end() const` ### Parameters None ### Returns A const iterator to the end of the list. ``` ```APIDOC ## rbegin ### Description Returns a reverse iterator to the beginning of the reversed device list. ### Method `reverse_iterator rbegin()` ### Parameters None ### Returns A reverse iterator to the beginning of the reversed list. ``` ```APIDOC ## rend ### Description Returns a reverse iterator to the end of the reversed device list. ### Method `reverse_iterator rend()` ### Parameters None ### Returns A reverse iterator to the end of the reversed list. ``` ```APIDOC ## rbegin (const) ### Description Returns a const reverse iterator to the beginning of the reversed device list. ### Method `const_reverse_iterator rbegin() const` ### Parameters None ### Returns A const reverse iterator to the beginning of the reversed list. ``` ```APIDOC ## rend (const) ### Description Returns a const reverse iterator to the end of the reversed device list. ### Method `const_reverse_iterator rend() const` ### Parameters None ### Returns A const reverse iterator to the end of the reversed list. ``` ```APIDOC ## size ### Description Returns the number of devices in the list. ### Method `ListType::size_type size() const` ### Parameters None ### Returns The number of devices. ``` ```APIDOC ## empty ### Description Checks if the device list is empty. ### Method `bool empty() const` ### Parameters None ### Returns `true` if the list is empty, `false` otherwise. ``` ```APIDOC ## clear ### Description Clears the device list and frees associated resources. ### Method `void clear()` ### Parameters None ### Returns None ``` -------------------------------- ### Ftdi::Context::serial Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8hpp_source.html Gets the serial number string of the FTDI device. ```APIDOC ## Ftdi::Context::serial ### Description Gets the serial number string of the FTDI device. ### Method const std::string & serial() ### Parameters None ### Return Value Returns a constant reference to the serial number string. ``` -------------------------------- ### Ftdi::Eeprom::init_defaults Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8hpp_source.html Initializes the EEPROM with default values. ```APIDOC ## Ftdi::Eeprom::init_defaults ### Description Initializes the EEPROM with default values. ### Method int init_defaults(char *manufacturer, char *product, char *serial) ### Parameters - **manufacturer** (char *) - The manufacturer string. - **product** (char *) - The product string. - **serial** (char *) - The serial number string. ### Return Value Returns 0 on success, or a negative error code on failure. ``` -------------------------------- ### Ftdi::Context::serial() Source: https://www.intra2net.com/en/developer/libftdi/documentation/classFtdi_1_1Context.html Gets the serial number string of the FTDI device. ```APIDOC const std::string & Ftdi::Context::serial(); ``` -------------------------------- ### EEPROM Value Access Functions Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8h_source.html Functions for getting and setting specific EEPROM values. ```APIDOC ## ftdi_get_eeprom_value ### Description Retrieves a specific EEPROM value by its name. ### Signature ```c int ftdi_get_eeprom_value(struct ftdi_context *ftdi, enum ftdi_eeprom_value value_name, int* value); ``` ## ftdi_set_eeprom_value ### Description Sets a specific EEPROM value by its name. ### Signature ```c int ftdi_set_eeprom_value(struct ftdi_context *ftdi, enum ftdi_eeprom_value value_name, int value); ``` ``` -------------------------------- ### Ftdi::Context::open Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8hpp_source.html Opens an FTDI device connection. ```APIDOC ## Ftdi::Context::open ### Description Opens an FTDI device connection. ### Method int open(struct libusb_device *dev=0) ### Parameters - **dev** (struct libusb_device *) - Optional: A pointer to a libusb_device structure to open. If null, the first available device is opened. ### Return Value Returns 0 on success, or a negative error code on failure. ``` -------------------------------- ### Write Chunk Size Source: https://www.intra2net.com/en/developer/libftdi/documentation/classFtdi_1_1Context.html Get or set the write chunk size for data transfers. ```APIDOC ## set_write_chunk_size() ### Description Sets the chunk size for write operations. ### Method `int Ftdi::Context::set_write_chunk_size(unsigned int _chunksize)` ### Parameters * `_chunksize` (unsigned int) - The desired chunk size in bytes. ### Returns On success, 0. On error, a negative value. ``` ```APIDOC ## write_chunk_size() ### Description Retrieves the current chunk size used for write operations. ### Method `int Ftdi::Context::write_chunk_size()` ### Parameters None ### Returns An integer representing the current write chunk size in bytes. ``` -------------------------------- ### Include Headers for libftdi1 Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8c.html Includes necessary headers for using libftdi1 and libusb. ```c #include #include #include #include #include #include "ftdi_i.h" #include "ftdi.h" #include "ftdi_version_i.h" ``` -------------------------------- ### Read Chunk Size Source: https://www.intra2net.com/en/developer/libftdi/documentation/classFtdi_1_1Context.html Get or set the read chunk size for data transfers. ```APIDOC ## set_read_chunk_size() ### Description Sets the chunk size for read operations. ### Method `int Ftdi::Context::set_read_chunk_size(unsigned int _chunksize)` ### Parameters * `_chunksize` (unsigned int) - The desired chunk size in bytes. ### Returns On success, 0. On error, a negative value. ``` ```APIDOC ## read_chunk_size() ### Description Retrieves the current chunk size used for read operations. ### Method `int Ftdi::Context::read_chunk_size()` ### Parameters None ### Returns An integer representing the current read chunk size in bytes. ``` -------------------------------- ### USB Write Timeout Source: https://www.intra2net.com/en/developer/libftdi/documentation/classFtdi_1_1Context.html Get or set the USB write timeout for FTDI operations. ```APIDOC ## get_usb_write_timeout() ### Description Retrieves the current USB write timeout value. ### Method `int Ftdi::Context::get_usb_write_timeout() const` ### Parameters None ### Returns An integer representing the USB write timeout in milliseconds. ``` ```APIDOC ## set_usb_write_timeout() ### Description Sets the USB write timeout value. ### Method `void Ftdi::Context::set_usb_write_timeout(int _usb_write_timeout)` ### Parameters * `_usb_write_timeout` (int) - The desired USB write timeout in milliseconds. ### Returns None ``` -------------------------------- ### Initialization and Context Management Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8h.html Functions for initializing, creating, and freeing FTDI context structures. ```APIDOC ## ftdi_init ### Description Initializes an FTDI context. ### Signature int ftdi_init (struct ftdi_context *ftdi) ``` ```APIDOC ## ftdi_new ### Description Creates a new FTDI context. ### Signature struct ftdi_context * ftdi_new (void) ``` ```APIDOC ## ftdi_deinit ### Description Deinitializes an FTDI context. ### Signature void ftdi_deinit (struct ftdi_context *ftdi) ``` ```APIDOC ## ftdi_free ### Description Frees an FTDI context. ### Signature void ftdi_free (struct ftdi_context *ftdi) ``` -------------------------------- ### USB Read Timeout Source: https://www.intra2net.com/en/developer/libftdi/documentation/classFtdi_1_1Context.html Get or set the USB read timeout for FTDI operations. ```APIDOC ## get_usb_read_timeout() ### Description Retrieves the current USB read timeout value. ### Method `int Ftdi::Context::get_usb_read_timeout() const` ### Parameters None ### Returns An integer representing the USB read timeout in milliseconds. ``` ```APIDOC ## set_usb_read_timeout() ### Description Sets the USB read timeout value. ### Method `void Ftdi::Context::set_usb_read_timeout(int _usb_read_timeout)` ### Parameters * `_usb_read_timeout` (int) - The desired USB read timeout in milliseconds. ### Returns None ``` -------------------------------- ### FTDI Initialization and Deinitialization Source: https://www.intra2net.com/en/developer/libftdi/documentation/globals_f.html Functions for initializing and deinitializing FTDI devices. ```APIDOC ## ftdi_init() ### Description Initializes an FTDI device structure. ### Method `ftdi_init(struct ftdi_context *ftdi)` ### Endpoint N/A (Library Function) ## ftdi_deinit() ### Description Deinitializes an FTDI device structure and frees associated resources. ### Method `ftdi_deinit(struct ftdi_context *ftdi)` ### Endpoint N/A (Library Function) ## ftdi_new() ### Description Allocates and initializes a new FTDI context. ### Method `struct ftdi_context *ftdi_new()` ### Endpoint N/A (Library Function) ``` -------------------------------- ### Class Members - o Source: https://www.intra2net.com/en/developer/libftdi/documentation/functions_o.html This section lists class members starting with 'o', including their associated classes. ```APIDOC ## Class Members - o ### offset - **Class**: ftdi_transfer_control ### open() - **Classes**: Ftdi::Context, Ftdi::Context::Private ### out_ep - **Class**: ftdi_context ### out_is_isochronous - **Class**: ftdi_eeprom ### Output - **Class**: Ftdi::Context ``` -------------------------------- ### Context::open(const std::string& description) Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8cpp_source.html Opens an FTDI device using a string description. This method is useful when the device can be uniquely identified by its description. ```APIDOC ## Context::open(const std::string& description) ### Description Opens an FTDI device using a string description. This method is useful when the device can be uniquely identified by its description. ### Method ```cpp int Context::open(const std::string& description) ``` ### Parameters * **description** (const std::string&) - The description string of the FTDI device. ### Returns Returns 0 on success, or a negative error code on failure. ``` -------------------------------- ### Ftdi::Eeprom Constructor Source: https://www.intra2net.com/en/developer/libftdi/documentation/classFtdi_1_1Eeprom.html Initializes a new instance of the Eeprom class. ```APIDOC ## Eeprom() ### Description Initializes a new instance of the Ftdi::Eeprom class. ### Parameters - **parent** (Context *) - Pointer to the parent Context object. ``` -------------------------------- ### Get FTDI Latency Timer Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8c_source.html Retrieves the current latency timer value from an FTDI device. ```c int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char *latency) { unsigned short usb_val; if (ftdi == NULL || ftdi->usb_dev == NULL) ftdi_error_return(-2, "USB device unavailable"); if (libusb_control_transfer(ftdi->usb_dev, FTDI_DEVICE_IN_REQTYPE, SIO_GET_LATENCY_TIMER_REQUEST, 0, ftdi->index, (unsigned char *)&usb_val, 1, ftdi->usb_read_timeout) != 1) ftdi_error_return(-1, "reading latency timer failed"); *latency = (unsigned char)usb_val; return 0; } ``` -------------------------------- ### Initialize FTDI Context Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8cpp_source.html Creates and initializes a new FTDI context. Ensure to free the context using ftdi_free() when done. ```c struct ftdi_context * ftdi_new(void) { return ftdi_new(); } ``` -------------------------------- ### Latency and Modem Status Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8c.html Functions for setting and getting the latency timer and polling modem status. ```APIDOC ## ftdi_set_latency_timer ### Description Sets the latency timer for the FTDI device. ### Signature int ftdi_set_latency_timer (struct ftdi_context *ftdi, unsigned char latency) ``` ```APIDOC ## ftdi_get_latency_timer ### Description Gets the current latency timer value. ### Signature int ftdi_get_latency_timer (struct ftdi_context *ftdi, unsigned char *latency) ``` ```APIDOC ## ftdi_poll_modem_status ### Description Polls the modem status lines. ### Signature int ftdi_poll_modem_status (struct ftdi_context *ftdi, unsigned short *status) ``` -------------------------------- ### Ftdi::Context::Context Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8hpp_source.html Constructor for the Ftdi::Context class. Initializes a new FTDI device context. ```APIDOC ## Ftdi::Context::Context ### Description Constructor for the Ftdi::Context class. Represents a single FTDI device context. ### Method Ftdi::Context::Context() ### Parameters None ``` -------------------------------- ### Chunk Size Configuration Source: https://www.intra2net.com/en/developer/libftdi/documentation/classFtdi_1_1Context.html Sets and gets the read and write chunk sizes for data transfer. ```APIDOC ## set_read_chunk_size(unsigned int chunksize) ### Description Sets the size of chunks for reading data. ### Method set_read_chunk_size ### Parameters #### Path Parameters - **chunksize** (unsigned int) - Required - The size of read chunks. ### Returns int ## set_write_chunk_size(unsigned int chunksize) ### Description Sets the size of chunks for writing data. ### Method set_write_chunk_size ### Parameters #### Path Parameters - **chunksize** (unsigned int) - Required - The size of write chunks. ### Returns int ## read_chunk_size() ### Description Gets the current read chunk size. ### Method read_chunk_size ### Returns int ## write_chunk_size() ### Description Gets the current write chunk size. ### Method write_chunk_size ### Returns int ``` -------------------------------- ### USB Timeout Configuration Source: https://www.intra2net.com/en/developer/libftdi/documentation/classFtdi_1_1Context.html Gets and sets the USB read and write timeouts for the FTDI device. ```APIDOC ## get_usb_read_timeout() const ### Description Gets the USB read timeout value. ### Method get_usb_read_timeout ### Returns int ## set_usb_read_timeout(int usb_read_timeout) ### Description Sets the USB read timeout value. ### Method set_usb_read_timeout ### Parameters #### Path Parameters - **usb_read_timeout** (int) - Required - The USB read timeout value. ## get_usb_write_timeout() const ### Description Gets the USB write timeout value. ### Method get_usb_write_timeout ### Returns int ## set_usb_write_timeout(int usb_write_timeout) ### Description Sets the USB write timeout value. ### Method set_usb_write_timeout ### Parameters #### Path Parameters - **usb_write_timeout** (int) - Required - The USB write timeout value. ``` -------------------------------- ### Ftdi::Context::open() [1/4] Source: https://www.intra2net.com/en/developer/libftdi/documentation/classFtdi_1_1Context.html Opens the FTDI device using a libusb_device pointer. ```APIDOC int Ftdi::Context::open(struct libusb_device * _dev_ = 0); ``` -------------------------------- ### ftdi_eeprom_initdefaults Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8h.html Initializes the EEPROM structure with default values. This function sets up the basic configuration for the EEPROM, allowing for custom manufacturer, product, and serial number strings. ```APIDOC ## ftdi_eeprom_initdefaults ### Description Initializes the EEPROM structure with default values. This function sets up the basic configuration for the EEPROM, allowing for custom manufacturer, product, and serial number strings. ### Signature `int ftdi_eeprom_initdefaults (struct ftdi_context *ftdi, char *manufacturer, char *product, char *serial)` ### Parameters * **ftdi** (struct ftdi_context *) - Pointer to the FTDI context structure. * **manufacturer** (char *) - String for the manufacturer's name. * **product** (char *) - String for the product's name. * **serial** (char *) - String for the serial number. ``` -------------------------------- ### Ftdi::Context::write_chunk_size() Source: https://www.intra2net.com/en/developer/libftdi/documentation/functions_w.html Gets or sets the chunk size for writing operations in Ftdi::Context. ```APIDOC ## Ftdi::Context::write_chunk_size() ### Description Gets or sets the chunk size for writing operations. ### Method (Not specified in source, likely a C function call) ### Endpoint (Not applicable for C library functions) ### Parameters (Parameters not specified in source) ### Request Example (Not applicable for C library functions) ### Response (Response details not specified in source) ``` -------------------------------- ### List Begin Iterator Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8cpp_source.html Returns a begin iterator for the list of FTDI contexts. Used for iterating through the discovered devices. ```cpp List::iterator List::begin() { return d->list.begin(); } ``` -------------------------------- ### File Members - w Source: https://www.intra2net.com/en/developer/libftdi/documentation/globals_w.html This section lists members starting with 'w' found in the ftdi.h file. ```APIDOC ## File Members - w ### Description This section lists members starting with 'w' found in the ftdi.h file. ### Variables - **WAIT_ON_HIGH** : ftdi.h - **WAIT_ON_LOW** : ftdi.h - **WRITE_EXTENDED** : ftdi.h - **WRITE_SHORT** : ftdi.h ``` -------------------------------- ### Ftdi::List::Private Constructor Source: https://www.intra2net.com/en/developer/libftdi/documentation/classFtdi_1_1List_1_1Private.html Initializes a new instance of the Private class, taking a pointer to an ftdi_device_list. ```APIDOC ## Ftdi::List::Private::Private() ### Description Constructor for the Private class. It initializes the internal state with a provided `ftdi_device_list`. ### Signature `Private(struct ftdi_device_list * __devlist_)` ### Definition Defined in `ftdi.cpp`, line 514. ``` -------------------------------- ### FTDI Utility Functions Source: https://www.intra2net.com/en/developer/libftdi/documentation/globals_func.html Utility functions for error handling, listing devices, and getting library information. ```APIDOC ## ftdi_get_error_string() ### Description Returns a string describing the last error that occurred. ### Method (Not specified, typically C function call) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## ftdi_get_library_version() ### Description Returns the version of the libftdi library. ### Method (Not specified, typically C function call) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## ftdi_list_free() ### Description Frees the memory allocated for a list of FTDI devices. ### Method (Not specified, typically C function call) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## ftdi_list_free2() ### Description Frees the memory allocated for a list of FTDI devices (alternative version). ### Method (Not specified, typically C function call) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## ftdi_poll_modem_status() ### Description Polls the modem status lines of the FTDI device. ### Method (Not specified, typically C function call) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## ftdi_set_usbdev() ### Description Sets the USB device context for the FTDI device. ### Method (Not specified, typically C function call) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Initialize and Free FTDI Context Source: https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8cpp_source.html Demonstrates the constructor and destructor for the Ftdi::Context class, which handles the initialization and cleanup of the underlying ftdi_context. Ensure proper cleanup to avoid resource leaks. ```cpp namespace Ftdi { class Context::Private { public: Private() : open(false), ftdi(0), dev(0) { ftdi = ftdi_new(); } ~Private() { if (open) ftdi_usb_close(ftdi); ftdi_free(ftdi); } bool open; struct ftdi_context* ftdi; struct libusb_device* dev; std::string vendor; std::string description; std::string serial; }; Context::Context() : d( new Private() ) { } Context::~Context() { } bool Context::is_open() { return d->open; } ```