### Quickstart: UART Communication Example Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/uart.rst A quick example demonstrating how to enable the PyFtdi pyserial backend, open a serial port on a specific FTDI device interface at a given baud rate, send data, and receive data. ```python # Enable pyserial extensions import pyftdi.serialext # Open a serial port on the second FTDI device interface (IF/2) @ 3Mbaud port = pyftdi.serialext.serial_for_url('ftdi://ftdi:2232h/2', baudrate=3000000) # Send bytes port.write(b'Hello World') # Receive bytes data = port.read(1024) ``` -------------------------------- ### Install PyFTDI from Source Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/installation.rst Installs PyFTDI after cloning the repository and installing dependencies. Uses the setup.py script for installation. ```shell python3 setup.py install ``` -------------------------------- ### Install PyFtdi Dependencies and Documentation Tools Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/installation.rst Install necessary packages for building documentation and the RTD theme. Use the -e flag for editable installs. ```shell pip3 install setuptools wheel sphinx sphinx_autodoc_typehints # Shpinx Read the Doc theme seems to never get a release w/ fixed issues pip3 install -U -e git+https://github.com/readthedocs/sphinx_rtd_theme.git@2b8717a3647cc650625c566259e00305f7fb60aa#egg=sphinx_rtd_theme sphinx-build -b html pyftdi/doc . ``` -------------------------------- ### I2C Controller Setup and Basic Transactions Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/i2c.rst Instantiate an I2C controller, configure it for a specific FTDI device interface, and then get a port to an I2C slave device for basic read/write operations. ```python # Instantiate an I2C controller i2c = I2cController() # Configure the first interface (IF/1) of the FTDI device as an I2C master i2c.configure('ftdi://ftdi:2232h/1') # Get a port to an I2C slave device slave = i2c.get_port(0x21) # Send one byte, then receive one byte slave.exchange([0x04], 1) # Write a register to the I2C slave slave.write_to(0x06, b'\x00') # Read a register from the I2C slave slave.read_from(0x00, 1) ``` -------------------------------- ### Install ruamel.yaml and run mockusb.py Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/testing.rst Install the required ruamel.yaml package and then execute the mockusb.py script to run virtual tests. This command sets the PYTHONPATH and FTDI_LOGLEVEL environment variables. ```bash pip3 install ruamel.yaml PYTHONPATH=. FTDI_LOGLEVEL=info pyftdi/tests/mockusb.py ``` -------------------------------- ### Example FTDI Device Output Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/installation.rst This is an example output from the `Ftdi.show_devices()` command, illustrating how FTDI devices with and without serial numbers are listed. ```text Available interfaces: ftdi://ftdi:232h:FT1PWZ0Q/1 (C232HD-DDHSP-0) ftdi://ftdi:2232/1 (Dual RS232-HS) ftdi://ftdi:2232/2 (Dual RS232-HS) ``` -------------------------------- ### Install PyFTDI Dependencies from Requirements Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/installation.rst Installs all necessary Python dependencies for PyFTDI from the requirements.txt file after cloning the repository. ```shell # note: 'pip3' may simply be 'pip' on some hosts pip3 install -r requirements.txt ``` -------------------------------- ### Example FTDI URLs with Bus and Address Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/urlscheme.rst Demonstrates using bus and address (hexadecimal) to select an FTDI device. ```text ftdi://ftdi:232h:10:22/1 ``` ```text ftdi://ftdi:232h:10:22/1 ``` ```text ftdi://::10:22/1 ``` -------------------------------- ### List Supported EEPROM Configuration Parameters Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/eeprom.rst Query the device to get a list of all configurable EEPROM parameters. ```bash pyftdi/bin/ftconf.py ftdi:///1 -c ? ``` -------------------------------- ### Install PyFTDI with PIP Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/installation.rst Installs the PyFTDI package and its dependencies using pip, the Python package installer. Ensure pip3 is available or use 'pip'. ```shell pip3 install pyftdi ``` -------------------------------- ### SPI Full-Duplex Communication Example Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/spi.rst Illustrates full-duplex SPI communication, allowing simultaneous write and read operations. This example reserves two CS lines and configures SPI mode 2 at 10MHz. ```python # Instantiate a SPI controller # We need want to use A*BUS4 for /CS, so at least 2 /CS lines should be # reserved for SPI, the remaining IO are available as GPIOs. spi = SpiController(cs_count=2) # Configure the first interface (IF/1) of the FTDI device as a SPI master spi.configure('ftdi://ftdi:2232h/1') # Get a port to a SPI slave w/ /CS on A*BUS4 and SPI mode 2 @ 10MHz slave = spi.get_port(cs=1, freq=10E6, mode=2) # Synchronous exchange with the remote SPI slave write_buf = b'\x01\x02\x03' read_buf = slave.exchange(write_buf, duplex=True) ``` -------------------------------- ### Open FTDI and Configure CBUS Pins Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/gpio.rst Demonstrates opening an FTDI device, validating CBUS support, and configuring CBUS pins for input and output. It also shows how to set and get GPIO values. ```python ftdi = Ftdi() ftdi.open_from_url('ftdi:///1') # validate CBUS feature with the current device assert ftdi.has_cbus # validate CBUS EEPROM configuration with the current device eeprom = FtdiEeprom() eeprom.connect(ftdi) # here we use CBUS0 and CBUS3 (or CBUS5 and CBUS9 on FT232H) assert eeprom.cbus_mask & 0b1001 == 0b1001 # configure CBUS0 as output and CBUS3 as input ftdi.set_cbus_direction(0b1001, 0b0001) # set CBUS0 ftdi.set_cbus_gpio(0x1) # get CBUS3 cbus3 = ftdi.get_cbus_gpio() >> 3 ``` -------------------------------- ### Start New Group Session Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/installation.rst Starts a new shell session with the 'plugdev' group active, useful for testing PyFTDI without logging out. ```shell newgrp plugdev ``` -------------------------------- ### Start Serial Terminal Session Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/uart.rst Starts a serial terminal session using a specified FTDI port. The example uses the first interface of an FT2232H device. ```shell PYTHONPATH=$PWD pyftdi/bin/pyterm.py ftdi://ftdi:2232/1 ``` -------------------------------- ### Install libusb on macOS with Homebrew Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/installation.rst Installs the libusb-1.0 package using the Homebrew package manager on macOS. ```shell brew install libusb ``` -------------------------------- ### Example FTDI URLs with Serial Number Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/urlscheme.rst Illustrates how to specify a serial number in the FTDI URL for unique device identification. ```text ftdi://ftdi:232h:FT0FMF6V/1 ``` ```text ftdi://:232h:FT0FMF6V/1 ``` ```text ftdi://::FT0FMF6V/1 ``` -------------------------------- ### Install libusb on Debian/Ubuntu Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/installation.rst Installs the libusb-1.0 package required by PyUSB on Debian-based Linux distributions. ```shell apt-get install libusb-1.0 ``` -------------------------------- ### SPI Communication with Extra GPIO Example Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/spi.rst Shows how to integrate SPI communication with GPIO management. This example uses an extra GPIO pin (A*BUS4) as an output and another (A*BUS5) as an input, alongside SPI operations. ```python # Instantiate a SPI controller spi = SpiController() # Configure the first interface (IF/1) of the first FTDI device as a # SPI master spi.configure('ftdi://::/1') # Get a SPI port to a SPI slave w/ /CS on A*BUS3 and SPI mode 0 @ 12MHz slave = spi.get_port(cs=0, freq=12E6, mode=0) # Get GPIO port to manage extra pins, use A*BUS4 as GPO, A*BUS5 as GPI gpio = spi.get_gpio() gpio.set_direction(pins=0b0011_0000, direction=0b0001_0000) # Assert GPO pin gpio.write(0x10) # Write to SPI slace slave.write(b'hello world!') # Release GPO pin gpio.write(0x00) # Test GPI pin pin = bool(gpio.read() & 0x20) ``` -------------------------------- ### SPI Non-Byte Aligned Transfers Example Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/spi.rst Demonstrates how to manage SPI transfers that are not byte-aligned. This includes writing a partial byte and reading a specific number of bits, with options to control data alignment. ```python # Instantiate a SPI controller spi = SpiController() # Configure the first interface (IF/1) of the first FTDI device as a # SPI master spi.configure('ftdi://::/1') # Get a SPI port to a SPI slave w/ /CS on A*BUS3 slave = spi.get_port(cs=0) # write 6 first bits of a byte buffer slave.write(b'\xff', droptail=2) # read only 13 bits from a slave (13 clock cycles) # only the 5 MSBs of the last byte are valid, 3 LSBs are force to zero slave.read(2, droptail=3) ``` -------------------------------- ### SPI Half-Duplex Communication Example Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/spi.rst Demonstrates a basic half-duplex SPI communication to request a JEDEC ID from a SPI slave. Ensure the FTDI device is configured correctly for SPI master mode. ```python # Instantiate a SPI controller spi = SpiController() # Configure the first interface (IF/1) of the FTDI device as a SPI master spi.configure('ftdi://ftdi:2232h/1') # Get a port to a SPI slave w/ /CS on A*BUS3 and SPI mode 0 @ 12MHz slave = spi.get_port(cs=0, freq=12E6, mode=0) # Request the JEDEC ID from the SPI slave jedec_id = slave.exchange([0x9f], 3) ``` -------------------------------- ### Complex I2C Bus Mastering with PyFtdi Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/i2c.rst Demonstrates advanced I2C bus control, including emitting START sequences, writing data without START/STOP, and reading data while releasing the bus. Requires importing the 'sleep' function. ```python from time import sleep port = I2cController().get_port(0x56) # emit a START sequence is read address, but read no data and keep the bus # busy port.read(0, relax=False) # wait for ~1ms sleep(0.001) # write 4 bytes, without neither emitting the start or stop sequence port.write(b'\x00\x01', relax=False, start=False) # read 4 bytes, without emitting the start sequence, and release the bus port.read(4, start=False) ``` -------------------------------- ### Clone PyFTDI Repository Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/installation.rst Clones the PyFTDI source code from its GitHub repository to install from source. ```shell git clone https://github.com/eblot/pyftdi.git cd pyftdi ``` -------------------------------- ### Configure GPIO Port Direction Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/gpio.rst Configure an 8-bit GPIO port with a specific direction mask. The direction is represented as a hexadecimal value where '1' indicates output and '0' indicates input. This example also shows how to reconfigure specific pins using set_direction. ```python gpio = GpioAsyncController() gpio.configure('ftdi:///1', direction=0x76) # later, reconfigure BD2 as input and BD7 as output gpio.set_direction(0x84, 0x80) ``` -------------------------------- ### Write to GPIO Pins Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/gpio.rst Write to GPIO pins. The caller must mask out bits configured as input to avoid exceptions. Writing '0' to an input pin is ignored, while writing '1' to an input pin raises an IOError. This example demonstrates setting all outputs low, high, and applying a direction mask. ```python gpio = GpioAsyncController() gpio.configure('ftdi:///1', direction=0x76) # all output set low gpio.write(0x00) # all output set high gpio.write(0x76) # all output set high, apply direction mask gpio.write(0xFF & gpio.direction) # all output forced to high, writing to input pins is illegal gpio.write(0xFF) # raises an IOError gpio.close() ``` -------------------------------- ### SpiController Instantiation and Configuration Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/spi.rst Demonstrates how to instantiate a SpiController and configure an FTDI device interface for SPI communication. ```APIDOC ## SpiController ### Description Manages SPI communication through FTDI devices. It allows configuration of interfaces and retrieval of SPI ports for communication with slaves. ### Methods - **__init__(cs_count=1)**: Initializes the SPI controller. `cs_count` specifies the number of Chip Select lines to reserve for SPI. - **configure(url, port_width=8, **kwargs)**: Configures the FTDI device interface for SPI master mode. `url` specifies the FTDI device and interface. `port_width` defines the interface port width. - **get_port(cs, freq=5000000, mode=0, clk_idle_high=False, clk_phase2=False, bit_order='msb', **kwargs)**: Retrieves a SPI port object for a specific slave device. `cs` is the Chip Select line. `freq` is the SPI clock frequency. `mode` is the SPI mode (0, 1, 2, or 3). `clk_idle_high` and `clk_phase2` configure clock polarity and phase. `bit_order` specifies MSB or LSB first. - **get_gpio()**: Retrieves a GPIO port object for managing extra pins not used by SPI. ``` -------------------------------- ### I2C Controller Configuration and Usage Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/i2c.rst Demonstrates how to instantiate an I2C controller, configure it for a specific FTDI device interface, and interact with I2C slave devices. ```APIDOC ## I2cController ### Description Manages I2C communication over FTDI devices. ### Methods - `configure(url: str)`: Configures the I2C controller with the specified FTDI device URL. - `get_port(address: int, frequency: int = 100000)`: Gets an I2C port object for a slave device at the given address and frequency. ### Example ```python # Instantiate an I2C controller i2c = I2cController() # Configure the first interface (IF/1) of the FTDI device as an I2C master i2c.configure('ftdi://ftdi:2232h/1') # Get a port to an I2C slave device slave = i2c.get_port(0x21) # Send one byte, then receive one byte slave.exchange([0x04], 1) # Write a register to the I2C slave slave.write_to(0x06, b'\x00') # Read a register from the I2C slave slave.read_from(0x00, 1) ``` ``` -------------------------------- ### List Supported Values for a Configuration Parameter Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/eeprom.rst Check the available options for a specific configuration parameter, such as `cbus_func_0`. ```bash pyftdi/bin/ftconf.py ftdi:///1 -c cbus_func_0:? ``` -------------------------------- ### List Available FTDI Devices Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/installation.rst Perform a post-installation sanity check by listing all FTDI devices connected to the host. This can be done interactively in a Python shell. ```python from pyftdi.ftdi import Ftdi Ftdi.show_devices() ``` -------------------------------- ### FtdiEeprom.open Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/eeprom.rst Opens the EEPROM manager and selects the FTDI device to access. The interface string specifies the device and interface to use. ```APIDOC ## FtdiEeprom.open ### Description Opens the EEPROM manager and selects the FTDI device to access. The interface string specifies the device and interface to use. ### Method `open(self, url)` ### Parameters #### Path Parameters - **url** (str) - Required - The FTDI device URL (e.g., 'ftdi://ftdi:2232h/1'). ### Request Example ```python eeprom.open('ftdi://ftdi:2232h/1') ``` ``` -------------------------------- ### URL for Enumerating All FTDI Devices Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/urlscheme.rst Use this special URL syntax to enumerate all compatible FTDI devices. The '?' character may need escaping in some shells. ```text ftdi:///? ``` ```text ftdi:///? ``` -------------------------------- ### Dump EEPROM Content with pyftdi Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/eeprom.rst Instantiate an EEPROM manager, open a FTDI device, and display its EEPROM content in both configuration and raw hex format. ```python # Instantiate an EEPROM manager eeprom = FtdiEeprom() # Select the FTDI device to access (the interface is mandatory but any # valid interface for the device fits) eeprom.open('ftdi://ftdi:2232h/1') # Show the EEPROM content eeprom.dump_config() # Show the raw EEPROM content from pyftdi.misc import hexdump print(hexdump(eeprom.data)) ``` -------------------------------- ### Configure and Use I2C Feature with GPIO Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/gpio.rst Illustrates how to use the I2C controller, configuring it with a specific direction mask for GPIO pins. It demonstrates reading, modifying, and writing GPIO states, while accounting for pins reserved by the I2C feature. ```python # use I2C feature i2c = I2cController() # configure the I2C feature, and predefines the direction of the GPIO pins i2c.configure('ftdi:///1', direction=0x78) gpio = i2c.get_gpio() # read whole port pins = gpio.read() # clearing out I2C bits (SCL, SDAo, SDAi) pins &= 0x07 # set AD4 pins |= 1 << 4 # update GPIO output gpio.write(pins) ``` -------------------------------- ### Enable PyFtdi pyserial Backend Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/uart.rst Import the pyftdi.serialext module to enable PyFtdi as a backend for pyserial. ```python import pyftdi.serialext ``` -------------------------------- ### FtdiEeprom.dump_config Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/eeprom.rst Dumps the configuration of the EEPROM. ```APIDOC ## FtdiEeprom.dump_config ### Description Dumps the configuration of the EEPROM. ### Method `dump_config(self)` ### Request Example ```python eeprom.dump_config() ``` ``` -------------------------------- ### Run EEPROM Tests with pyftdi Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/eeprom.rst Execute EEPROM tests using Python. Optionally, specify an alternative FTDI device by setting the FTDI_DEVICE environment variable. ```shell # optional: specify an alternative FTDI device export FTDI_DEVICE=ftdi://ftdi:2232h/1 PYTHONPATH=. python3 pyftdi/tests/eeprom.py ``` -------------------------------- ### Open FTDI Connection from URL Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/urlscheme.rst Helper methods to open an FTDI connection using a URL. These methods abstract the connection details. ```python open_from_url() open_mpsse_from_url() open_bitbang_from_url() ``` -------------------------------- ### List FTDI Devices Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/uart.rst Lists all available FTDI device ports. Ensure PYTHONPATH is set if running from the archive directory. ```shell PYTHONPATH=. python3 pyftdi/bin/ftdi_urls.py ``` -------------------------------- ### Configure CBUS GPIO Pins Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/eeprom.rst Set specific CBUS pins to function as GPIOs and then display the updated device configuration. ```bash pyftdi/bin/ftconf.py ftdi:///1 -v -c cbus_func_0:GPIO -c cbus_func_3:GPIO ``` -------------------------------- ### ftconf.py Usage Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/eeprom.rst This is the command-line usage for the `ftconf.py` script, which helps manage FTDI EEPROM content. It outlines various options for input, output, device selection, EEPROM model and size specification, data formatting, configuration, and actions. ```bash usage: ftconf.py [-h] [-i INPUT] [-l {all,raw,values}] [-o OUTPUT] [-V VIRTUAL] [-P VIDPID] [-M EEPROM] [-S {128,256,1024}] [-x] [-X HEXBLOCK] [-s SERIAL_NUMBER] [-m MANUFACTURER] [-p PRODUCT] [-c CONFIG] [--vid VID] [--pid PID] [-e] [-E] [-u] [-v] [-d] [device] Simple FTDI EEPROM configurator. positional arguments: device serial port device name optional arguments: -h, --help show this help message and exit Files: -i INPUT, --input INPUT input ini file to load EEPROM content -l {all,raw,values}, --load {all,raw,values} section(s) to load from input file -o OUTPUT, --output OUTPUT output ini file to save EEPROM content -V VIRTUAL, --virtual VIRTUAL use a virtual device, specified as YaML Device: -P VIDPID, --vidpid VIDPID specify a custom VID:PID device ID (search for FTDI devices) -M EEPROM, --eeprom EEPROM force an EEPROM model -S {128,256,1024}, --size {128,256,1024} force an EEPROM size Format: -x, --hexdump dump EEPROM content as ASCII -X HEXBLOCK, --hexblock HEXBLOCK dump EEPROM as indented hexa blocks Configuration: -s SERIAL_NUMBER, --serial-number SERIAL_NUMBER set serial number -m MANUFACTURER, --manufacturer MANUFACTURER set manufacturer name -p PRODUCT, --product PRODUCT set product name -c CONFIG, --config CONFIG change/configure a property as key=value pair --vid VID shortcut to configure the USB vendor ID --pid PID shortcut to configure the USB product ID Action: -e, --erase erase the whole EEPROM content -E, --full-erase erase the whole EEPROM content, including the CRC -u, --update perform actual update, use w/ care Extras: -v, --verbose increase verbosity -d, --debug enable debug mode ``` -------------------------------- ### GpioMpsseController Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/gpio.rst Provides control over GPIO pins using the MPSSE interface. ```APIDOC class GpioMpsseController :members: ``` -------------------------------- ### Legacy FTDI Connection Methods Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/urlscheme.rst Deprecated methods for opening FTDI connections using VID, PID, and serial parameters directly, without a URL. ```python open() open_mpsse() open_bitbang() ``` -------------------------------- ### Add Custom Vendor/Product IDs with String Names Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/installation.rst You can specify custom vendor and product IDs using string names instead of numerical values. This is useful for creating more readable URLs for device connections. ```python from pyftdi.ftdi import Ftdi Ftdi.add_custom_vendor(0x1234, 'myvendor') Ftdi.add_custom_product(0x1234, 0x5678, 'myproduct') f1 = Ftdi.create_from_url('ftdi://0x1234:0x5678/1') f2 = Ftdi.create_from_url('ftdi://myvendor:myproduct/2') ``` -------------------------------- ### GpioSyncController Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/gpio.rst Provides synchronous control over GPIO pins. ```APIDOC class GpioSyncController :members: ``` -------------------------------- ### Add Custom Product ID Support Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/installation.rst Before opening an FTDI device, add support for a custom product ID by calling `Ftdi.add_custom_product()`. This is necessary for devices with customized EEPROM IDs. ```python from pyftdi.ftdi import Ftdi Ftdi.add_custom_product(Ftdi.DEFAULT_VENDOR, product_id) ``` -------------------------------- ### Synchronous GPIO Access with exchange() Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/gpio.rst Perform synchronous GPIO access using GpioSyncController. The exchange method sends a byte buffer of output states and receives a byte buffer of input states, with a configurable frequency. ```python gpio = GpioSyncController() gpio.configure('ftdi:///1', direction=0x0F, frequency=1e6) outs = bytes(range(16)) ins = gpio.exchange(outs) # ins contains as many bytes as outs gpio.close() ``` -------------------------------- ### GpioException Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/gpio.rst Base exception for GPIO related errors. ```APIDOC exception GpioException ``` -------------------------------- ### GpioAsyncController Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/gpio.rst Provides asynchronous control over GPIO pins. ```APIDOC class GpioAsyncController :members: ``` -------------------------------- ### Open FTDI from Serial Port Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/gpio.rst Shows how to obtain an FTDI object from an existing pyserial port instance, useful when pyftdi is used in conjunction with serial communication. ```python # it is possible to open the ftdi object from an existing serial connection: port = serial_for_url('ftdi:///1') ftdi = port.ftdi ftdi.has_cbus # etc... ``` -------------------------------- ### Open Serial Port with PyFtdi Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/uart.rst Use serial_for_url to open a pyserial serial port instance with PyFtdi as the backend. Specify the FTDI URL and any desired options. ```python pyftdi.serialext.serial_for_url(url, **options) ``` -------------------------------- ### Add Custom Vendor and Product ID Support Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/installation.rst To support devices with custom vendor and product IDs, call `Ftdi.add_custom_vendor()` and `Ftdi.add_custom_product()` before any FTDI `open()` calls. This allows PyFtdi to recognize these custom identifiers. ```python from pyftdi.ftdi import Ftdi Ftdi.add_custom_vendor(vendor_id) Ftdi.add_custom_product(vendor_id, product_id) ``` -------------------------------- ### Linux udev Rules for FTDI Devices Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/installation.rst Configuration file for udev to grant user-space access to FTDI USB devices. Ensure to reload rules after creation. ```shell # /etc/udev/rules.d/11-ftdi.rules # FT232AM/FT232BM/FT232R SUBSYSTEM=="usb", ATTR{idVendor}=="0403", ATTR{idProduct}=="6001", GROUP="plugdev", MODE="0664" # FT2232C/FT2232D/FT2232H SUBSYSTEM=="usb", ATTR{idVendor}=="0403", ATTR{idProduct}=="6010", GROUP="plugdev", MODE="0664" # FT4232/FT4232H SUBSYSTEM=="usb", ATTR{idVendor}=="0403", ATTR{idProduct}=="6011", GROUP="plugdev", MODE="0664" # FT232H SUBSYSTEM=="usb", ATTR{idVendor}=="0403", ATTR{idProduct}=="6014", GROUP="plugdev", MODE="0664" # FT230X/FT231X/FT234X SUBSYSTEM=="usb", ATTR{idVendor}=="0403", ATTR{idProduct}=="6015", GROUP="plugdev", MODE="0664" # FT4232HA SUBSYSTEM=="usb", ATTR{idVendor}=="0403", ATTR{idProduct}=="6048", GROUP="plugdev", MODE="0664" # FT4232HP SUBSYSTEM=="usb", ATTR{idVendor}=="0403", ATTR{idProduct}=="6043", GROUP="plugdev", MODE="0664" ``` -------------------------------- ### Ftdi Class Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/ftdi.rst Documentation for the Ftdi class, which offers low-level control over FTDI devices. Most users should utilize higher-level abstractions. ```APIDOC ## Class: Ftdi ### Description Provides low-level access to FTDI devices. Direct usage is generally not recommended; prefer higher-level APIs. ### Members (Members are documented separately via autoclass directive) ``` -------------------------------- ### Open FTDI Connection from PyUSB Device Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/urlscheme.rst Helper methods to open an FTDI connection from an existing PyUSB device object. ```python open_from_device() open_mpsse_from_device() open_bitbang_from_device() ``` -------------------------------- ### FtdiEeprom.data Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/eeprom.rst Provides access to the raw EEPROM data. ```APIDOC ## FtdiEeprom.data ### Description Provides access to the raw EEPROM data. ### Method `data` (property) ### Request Example ```python from pyftdi.misc import hexdump print(hexdump(eeprom.data)) ``` ``` -------------------------------- ### UsbToolsError Exception Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/usbtools.rst Custom exception for UsbTools related errors. ```APIDOC ## Exception: UsbToolsError ### Description Custom exception raised for errors encountered within the UsbTools module. ``` -------------------------------- ### Change Product Name and Serial Number Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/eeprom.rst Use this command to set a custom product name and serial number for the FTDI device's EEPROM. ```bash pyftdi/bin/ftconf.py ftdi:///1 -p UartBridge -s abcd1234 -u ``` -------------------------------- ### UsbTools Class Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/usbtools.rst The UsbTools class provides methods for managing and querying USB devices. ```APIDOC ## Class: UsbTools ### Description Provides methods for managing and querying USB devices. ### Methods (Members are documented separately in the source, but not exposed as specific callable API endpoints in this context.) ### Exceptions (Exceptions are documented separately in the source, but not exposed as specific callable API endpoints in this context.) ``` -------------------------------- ### Accessing UART GPIO Pins Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/uart.rst Demonstrates how to access UART GPIO pins through PySerial port attributes. Note the limitations on direction, atomicity, and potential conflicts with hardware flow control. ```python # Example of accessing RTS pin (Output) port.rts = state # Example of accessing CTS pin (Input) state = port.cts # Example of accessing DTR pin (Output) port.dtr = state # Example of accessing DSR pin (Input) state = port.dsr # Example of accessing DCD pin (Input) state = port.dcd # Example of accessing RI pin (Input) state = port.ri ``` -------------------------------- ### Reload and Trigger udev Rules Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/installation.rst Commands to apply new udev rules after modifying the configuration file. This ensures the system recognizes the updated rules for FTDI devices. ```shell sudo udevadm control --reload-rules sudo udevadm trigger ``` -------------------------------- ### Copy libusb0.dll on Windows with PyInstaller Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/troubleshooting.rst If using a PyInstaller executable on Windows, copy the libusb0.dll to the executable's directory. ```shell copy C:\\Windows\\System32\\libusb0.dll ``` -------------------------------- ### Set DYLD_LIBRARY_PATH on macOS Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/troubleshooting.rst On macOS, set the DYLD_LIBRARY_PATH environment variable to help the dynamic loader find the libusb library. ```shell export DYLD_LIBRARY_PATH=.../lib ``` -------------------------------- ### I2C Exceptions Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/i2c.rst Lists the custom exceptions raised during I2C operations. ```APIDOC ## I2C Exceptions ### Description Custom exceptions for handling I2C communication errors. ### Exceptions - `I2cIOError`: Raised for general I/O errors during I2C communication. - `I2cNackError`: Raised when an I2C NACK is received unexpectedly. - `I2cTimeoutError`: Raised when an I2C operation times out. ``` -------------------------------- ### Add User to plugdev Group Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/installation.rst Adds the current user to the 'plugdev' group, granting necessary permissions to access FTDI devices on Linux. Requires logout/login or newgrp. ```shell sudo adduser $USER plugdev ``` -------------------------------- ### URL Scheme Definition Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/urlscheme.rst Defines the structure of the ftdi:// URL for specifying FTDI device connection parameters. ```text ftdi://[vendor][:[product][:serial|:bus:address|:index]]/interface ``` -------------------------------- ### Recover Erased EEPROM Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/eeprom.rst Restore an erased EEPROM by providing valid VID/PID and other parameters. This is useful for recovering devices that have had their EEPROM erased. ```bash # for a FT4232 device # note that ffff matches an erased EEPROM, other corrupted values may # exist, such device can be identified with system tools such as lsusb pyftdi/bin/ftconf.py -P ffff:ffff ftdi://ffff:ffff/1 -e -u \ --vid 0403 --pid 6011 ``` -------------------------------- ### Set LD_LIBRARY_PATH on Linux Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/troubleshooting.rst On Linux, set the LD_LIBRARY_PATH environment variable to help the dynamic loader find the libusb library. ```shell export LD_LIBRARY_PATH= ``` -------------------------------- ### Ftdi Exceptions Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/ftdi.rst Details on exceptions raised by the FTDI driver module. ```APIDOC ## Exceptions ### FtdiError Base exception for FTDI related errors. ### FtdiMpsseError Exception specific to MPSSE related errors. ### FtdiFeatureError Exception raised when a requested FTDI feature is not supported. ``` -------------------------------- ### SpiPort Operations Source: https://github.com/eblot/pyftdi/blob/main/pyftdi/doc/api/spi.rst Details the operations available on a SpiPort object for interacting with SPI slave devices. ```APIDOC ## SpiPort ### Description Represents a SPI slave port, enabling communication with a specific SPI device. ### Methods - **exchange(txbuf, nbytes=None, duplex=False)**: Performs a synchronous SPI transfer. Sends `txbuf` and receives data. If `nbytes` is specified, it receives that many bytes. `duplex` enables full-duplex mode. - **write(txbuf, droptail=0)**: Writes data from `txbuf` to the SPI slave. `droptail` specifies the number of least significant bits to drop from the last byte. - **read(nbytes, droptail=0)**: Reads `nbytes` from the SPI slave. `droptail` specifies the number of least significant bits to force to zero in the last byte. - **close()**: Closes the SPI port. ```