https://github.com/firobe/i2c-unix
Modern bindings to the I2C user-space kernel interface
https://github.com/firobe/i2c-unix
Last synced: over 1 year ago
JSON representation
Modern bindings to the I2C user-space kernel interface
- Host: GitHub
- URL: https://github.com/firobe/i2c-unix
- Owner: Firobe
- License: mit
- Created: 2023-01-22T19:58:56.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-06T01:15:17.000Z (about 3 years ago)
- Last Synced: 2025-01-22T00:37:22.527Z (over 1 year ago)
- Language: OCaml
- Size: 8.79 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# i2c-unix
This library provides bindings to the `i2c-dev` module of the Linux kernel to
access the I2C bus from user space.
It is partly inspired by the older
[ocaml-i2c](https://github.com/mwweissmann/ocaml-i2c) library by Markus
Weissmann, aiming to use more modern tools (like `dune` and `ctypes`).
Its API is very straightforward and documented [online](FIXME).
## Installation
> Run `opam install i2c-unix`
You will have to have the SMBus i2c headers available on your system for the
package to build, provided by `i2c-tools` on Arch Linux or `libi2c-dev` on
Debian.
## Usage
For the library to work, ensure:
- the `i2c_dev` kernel module is loaded (`lsmod | grep i2c_dev`)
- you have an I2C bus attached to the system (`i2cdetect -l`)
Then you can use this library, with the name of the device returned by
`i2cdetect` (usually of the form `i2c-X`):
```ocaml
(* This snippet reads a byte from the bus at address 0x20 *)
let (let*) = Result.bind
let i2c =
let* t = I2c_unix.open_device "i2c-1" 0x20 in
let* b : Stdint.uint8 = I2c_unix.read_byte t in
(* do something with b *)
I2c_unix.close_device t;
Result.ok ()
```