Giter Site home page Giter Site logo

pyftdi-bitbang's Introduction

pyftdi-bitbang

Bit-bang protocol support for PyFtdi.

This package adds SPI protocol support for FT232 devices without MPSSE (e.g. FT232RL) by using the bit-bang mode based on asynchronous or synchronous GPIO driver.

Usage

Refer to tests/ for code examples.

The library supports the following baud rates:

  • in async mode: 57600..921600; only standard baud rates can be used (115200, 230400, etc.)
  • in sync mode: 500..2000000; try to stick with "even" rates (aligned to thousands)

SPI

The library provides a subclass of SpiController called BitBangSpiController which can be used as a drop-in replacement. It doesn't support features like CPOL/CPHA but should be enough for most applications.

Creating the object requires a GPIO controller: GpioAsyncController for fully software-driven bit writing, or GpioSyncController to use a (much faster) transaction-based GPIO control.

Example of reading SPI flash ID:

from pyftdi.gpio import GpioSyncController
from pyftdibb.spi import BitBangSpiController

gpio = GpioSyncController()
spi = BitBangSpiController(gpio=gpio)
spi.configure("ftdi:///1", frequency=1_000_000)
port = spi.get_port(cs=0)
# half-duplex mode
flash_id = port.exchange(b"\x9F", readlen=3, duplex=False)
# full-duplex mode (no benefit here, just an example)
flash_id = port.exchange(b"\x9F", readlen=4, duplex=True)
flash_id = flash_id[1:]

Example usage with PySpiFlash:

from pyftdi.gpio import GpioSyncController
from pyftdibb.spi import BitBangSpiController
from spiflash.serialflash import SerialFlashManager

gpio = GpioSyncController()
spi = BitBangSpiController(gpio=gpio)
spi.configure("ftdi:///1", frequency=1_000_000)
flash = SerialFlashManager.get_from_controller(spi)
data = flash.read(0, 0x1000)

License

MIT

pyftdi-bitbang's People

Contributors

kuba2k2 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.