Coder Social home page Coder Social logo

spi-ftx232's Introduction

USB SPI + GPIO Linux driver for FTDI FT2232, FT232

Linux driver makes accessible SPI bus and GPIO pins through USB FTDI FT2232 even on your desktop! Two independent SPI controllers with maximal speed of 30 Mhz and 12 chip selects per channel. Each SPI device can be managed by existing kernel driver or userspace application through spidev. Unused chip selects are accessible as GPIOs with the maximal number of 24 pins.

Build & Run

Currently, the ftdi_sio driver should be unloaded or USB PID and VID should be changed in the FTDI and driver.

$ make
$ insmod ./spi-ftx232.ko

Configuring SPI slaves devices

Up to 12 SPI devices can be registered by writing to the export file of the SPI controller. The first argument is the SPI driver name followed by chip select in the range of 0 to 12. Chipselects starts from the fourth pin because the first three pins are CLK, MOSI and MISO. The third argument is the hexadecimal mode value. Supported mode options are SPI_CPHA(0x01), SPI_CPOL(0x02), SPI_CS_HIGH(0x04).

The following example registers the spidev driver for the CS2, SPI_CPOL | SPI_CS_HIGH and maximal speed of 100 khz:

echo spidev 2 6 100000 > /sys/devices/pci0000:00/0000:00:04.0/usb1/1-1/1-1:1.0/spi_master/spi0/export

Devices can be configured upon connecting to the USB via udev rules:

ACTION=="add", SUBSYSTEM=="spi_master", DEVPATH=="*usb*:1.0/spi_master*", RUN+="/bin/sh -c 'echo spidev 0 0 1000000 > /sys$DEVPATH/export'"
ACTION=="add", SUBSYSTEM=="spi_master", DEVPATH=="*usb*:1.0/spi_master*", RUN+="/bin/sh -c 'echo spidev 12 4 30000 > /sys$DEVPATH/export'"
ACTION=="add", SUBSYSTEM=="spi_master", DEVPATH=="*usb*:1.1/spi_master*", RUN+="/bin/sh -c 'echo spidev 0 3 1000000 > /sys$DEVPATH/export'"

Place them to the /etc/udev/rules.d/80-spi-ftx232.rules and reload udevadm control --reload-rules && udevadm trigger. After the USB reconnection all devices should appear in /dev/:

$ ls /dev/spidev*
/dev/spidev0.0  /dev/spidev0.12  /dev/spidev1.0

GPIO

Unused GPIO pins are available for general purposes like resetting the display etc.

$ gpioinfo
gpiochip0 - 13 lines:
        line   0:      unnamed "ftx232 chan 1 cs 0" output active-low [used]
        line   1:      unnamed       unused   input  active-high 
        line   2:      unnamed       unused   input  active-high 
        line   3:      unnamed       unused   input  active-high 
        line   4:      unnamed       unused   input  active-high 
        line   5:      unnamed       unused   input  active-high 
        line   6:      unnamed       unused   input  active-high 
        line   7:      unnamed       unused   input  active-high 
        line   8:      unnamed       unused   input  active-high 
        line   9:      unnamed       unused   input  active-high 
        line  10:      unnamed       unused   input  active-high 
        line  11:      unnamed       unused   input  active-high 
        line  12:      unnamed "ftx232 chan 1 cs 12" output active-high [used]
gpiochip1 - 13 lines:
        line   0:      unnamed "ftx232 chan 2 cs 0" output active-low [used]
        line   1:      unnamed       unused   input  active-high 
        line   2:      unnamed       unused   input  active-high 
        line   3:      unnamed       unused   input  active-high 
        line   4:      unnamed       unused   input  active-high 
        line   5:      unnamed       unused   input  active-high 
        line   6:      unnamed       unused   input  active-high 
        line   7:      unnamed       unused   input  active-high 
        line   8:      unnamed       unused   input  active-high 
        line   9:      unnamed       unused   input  active-high 
        line  10:      unnamed       unused   input  active-high 
        line  11:      unnamed       unused   input  active-high 
        line  12:      unnamed       unused   input  active-high 

spi-ftx232's People

Contributors

trnila avatar

Watchers

James Cloos avatar  avatar  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.