Skip to main content

SPI

The SPI builtin package that exposes functions to read, write, transfer buffers over SPI. In particular, it exposes an SPI class and spi singleton instance (currently only one SPI interface is supported).

SPI.configure

The SPI.configure function is used to configure the SPI bus. It takes the pin configuration, frequency and mode.

import { spi } from "@devicescript/spi"
await spi.configure({})

SPI.read

The SPI.read function is used to read a buffer from the SPI bus.

import { spi } from "@devicescript/spi"
const res = await spi.read(8) // read 8 bytes

SPI.write

The SPI.write function is used to write a buffer to the SPI bus.

import { spi } from "@devicescript/spi"

await spi.write(hex`abcd`)

SPI.transfer

The SPI.transfer function is used to write and read buffers from and to the SPI bus. The read buffer has the same length as the write buffer.

import { spi } from "@devicescript/spi"

const res = await spi.transfer(hex`abcd`)