Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

SPI

SPI is a faster, clocked bus used for displays, storage, and similar devices. Final’s type is SpiPeriph. Instances: spi0 (usual default), spi1, spi5. See the Pin Map.

Each SPI device on a shared bus needs its own chip-select (CS / CE). By default a SpiPeriph claims CE0 only. Set numCS before enabling if you need more (e.g. 2 for CE0+CE1). Extra CE lines are optional pins; unused ones stay available as GPIO.

Host OS: enable SPI (e.g. dtparam=spi=on) and be in the spi group (or root).

Set mode / word size / speed / numCS before enabled!.

  SpiPeriph.mode0 spi0.mode!
  SpiPeriph.bitsPerWord8 spi0.bitsPerWord!
  1000000 spi0.maxHz!
  1 spi0.numCS!
  0 spi0.selCS!
  true spi0.enabled!

API

PropertyR/WValues / defaultDescription
enabledR/Wboolclaim the bus (and CE0..numCS-1)
pathRstringCE0 device path, e.g. /dev/spidev0.0
modeR/WSpiPeriph.mode0..mode3 (def 0)SPI mode; set before enable
bitsPerWordR/WbitsPerWord8 or bitsPerWord16 (def 8)set before enable
maxHzR/W> 0 (def 1_000_000)clock rate; set before enable
numCSR/W1..max for that bus (def 1)how many CE lines; set before enable
selCSR/W0..numCS-1 (def 0)which CE the next transfer uses
MethodStackDescription
write( data:ByteList -- )clock out bytes (RX discarded)
read( n:i -- data:ByteList )clock in n bytes (TX zeros)
transfer( tx:ByteList -- rx:ByteList )full-duplex transfer

Many panels also need plain GPIO for DC, RST, BUSY, and so on. Those are normal GpioPins, not part of SpiPeriph.

Template

  // adj pins (example numbers — match your wiring)
  GpioPin.out gpio23.direction!   // DC
  false gpio23.value!
  true gpio23.enabled!

  GpioPin.out gpio24.direction!   // RST
  true gpio24.value!
  true gpio24.enabled!

  SpiPeriph.mode0 spi0.mode!
  SpiPeriph.bitsPerWord8 spi0.bitsPerWord!
  1000000 spi0.maxHz!
  true spi0.enabled!

  // command byte (DC low)
  false gpio23.value!
  ByteList.new^ >xs
  0x10 x:.append^
  xs> spi0.write^

  // data (DC high)
  true gpio23.value!
  myBytes spi0.write^

Drivers and demos

RoleFile
JD79661 e-ink driverexamples/pi/jd79661.fnl
Stripe paint demoexamples/pi/spi-jd79661-eink.fnl

The driver binds SpiPeriph plus DC/RST/BUSY pins (Jd79661.connect^), then uses spi.write^ with DC selecting command vs data. Start from that pair when adding another SPI panel.