atomvm_gleam/spi
Types
SPI bus settings. Each field is one optional key of AtomVM bus_config.
None omits the key. pico is the newer name for MOSI, poci for MISO.
A present pin is the GPIO number; -1 means that line is not wired, which
is how the SK6812 chain marks its missing clock.
See bus_config().
pub type BusConfig {
BusConfig(
peripheral: option.Option(String),
sclk: option.Option(Int),
mosi: option.Option(Int),
miso: option.Option(Int),
pico: option.Option(Int),
poci: option.Option(Int),
)
}
Constructors
-
BusConfig( peripheral: option.Option(String), sclk: option.Option(Int), mosi: option.Option(Int), miso: option.Option(Int), pico: option.Option(Int), poci: option.Option(Int), )
Per-follower device settings. Maps to one entry in device_config.
name becomes the Erlang atom used with read_at / write / etc.
See device_config().
pub type DeviceConfig {
DeviceConfig(
name: String,
cs: Int,
clock_speed_hz: option.Option(Int),
mode: option.Option(Int),
address_len_bits: option.Option(Int),
command_len_bits: option.Option(Int),
)
}
Constructors
-
DeviceConfig( name: String, cs: Int, clock_speed_hz: option.Option(Int), mode: option.Option(Int), address_len_bits: option.Option(Int), command_len_bits: option.Option(Int), )
Errors from the AtomVM spi driver.
Known reason atoms are Gleam constructors (so {error, badarg} is
Error(Badarg)). Bare AtomVM error becomes Failed. Anything else
lands in Other as a string because AtomVM types reasons as open term().
See Module spi.
pub type Error {
Failed
NotSupported
Badarg
Timeout
Other(String)
}
Constructors
-
Failed -
NotSupported -
Badarg -
Timeout -
Other(String)
Full spi:open/1 parameters.
See params().
pub type Params {
Params(
bus_config: BusConfig,
device_config: List(DeviceConfig),
)
}
Constructors
-
Params(bus_config: BusConfig, device_config: List(DeviceConfig))
Opaque handle for an AtomVM SPI bus opened via spi:open/1.
See Module spi.
pub type Spi
SPI transaction map fields. All optional per the AtomVM docs.
See transaction().
pub type Transaction {
Transaction(
command: option.Option(Int),
address: option.Option(Int),
write_data: option.Option(BitArray),
write_bits: option.Option(Int),
read_bits: option.Option(Int),
)
}
Constructors
-
Transaction( command: option.Option(Int), address: option.Option(Int), write_data: option.Option(BitArray), write_bits: option.Option(Int), read_bits: option.Option(Int), )
Values
pub fn close(spi: Spi) -> Result(Nil, Error)
Close the SPI driver and free its resources.
See spi:close/1.
pub fn open(params: Params) -> Result(Spi, Error)
Open an SPI bus. Pass device_config: [] when AtomGL owns the device
(as on the badge display).
See spi:open/1.
pub fn read_at(
spi: Spi,
device_name: String,
address: Int,
len: Int,
) -> Result(Int, Error)
Read a value from an address on a named device.
See spi:read_at/4.
pub fn write(
spi: Spi,
device_name: String,
transaction: Transaction,
) -> Result(Nil, Error)
Write using a transaction map.
See spi:write/3.
pub fn write_at(
spi: Spi,
device_name: String,
address: Int,
len: Int,
data: Int,
) -> Result(Int, Error)
Write a value to an address on a named device.
See spi:write_at/5.
pub fn write_read(
spi: Spi,
device_name: String,
transaction: Transaction,
) -> Result(BitArray, Error)
Write and simultaneously read using a transaction map.
See spi:write_read/3.