https://github.com/kopera/erlang-spi
An Erlang application for interfacing with SPI devices on Linux systems
https://github.com/kopera/erlang-spi
embedded erlang linux spi
Last synced: about 1 month ago
JSON representation
An Erlang application for interfacing with SPI devices on Linux systems
- Host: GitHub
- URL: https://github.com/kopera/erlang-spi
- Owner: kopera
- License: apache-2.0
- Created: 2023-03-21T16:16:39.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-21T23:08:22.000Z (over 3 years ago)
- Last Synced: 2025-02-23T12:18:22.513Z (over 1 year ago)
- Topics: embedded, erlang, linux, spi
- Language: Erlang
- Size: 17.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# spi
An Erlang application for interfacing with SPI devices on Linux systems.
# Setup
You need to add `spi` as a dependency to your project. If you are using
`rebar3`, you can add the following to your `rebar.config`:
```erlang
{deps, [
{spi, "0.5.0"}
]}.
```
Also ensure that `spi` is added as a dependency to your application, by
updating your `.app.src` file:
```erlang
{application, my_app, [
{applications, [
kernel,
stdlib,
spi % <- You need this in your applications list
]}
]}.
```
# Usage
The following will open /dev/spidev0.0 using mode 0, at 10MHz using 8 bits per word:
```erlang
> {ok, Device} = spi:open("/dev/spidev0.0", #{
mode => 0,
speed_hz => 10000000,
bits_per_word => 8
}).
{ok, #Ref<0.2893647232.3229876230.113792>}
```
Once the device is open you need to use `spi:transfer/2` to initiate a transfer.
Alternatively `spi:read/2`, `spi:read/3`, `spi:write/2` and `spi:write/3` can
also be used for simple transfers.