The Linux kernel provides a standard interface for performing I2C operations.
This library exposes this interface in a clojure idiomatic way.
Each IO operation might throw if something fails.
Essentially, IO can be performed by directly reading and writing arbitrary bytes, doing transactions (uninterrupted sequence of messages) and using standard SMBus operations.
Not everything is supported by your driver, refer to [[]]. Furthermore, slave devices are often buggy and imperfect.
The Linux kernel provides a standard interface for performing I2C operations. This library exposes this interface in a clojure idiomatic way. Each IO operation might throw if something fails. Essentially, IO can be performed by directly reading and writing arbitrary bytes, doing transactions (uninterrupted sequence of messages) and using standard SMBus operations. Not everything is supported by your driver, refer to [[]]. Furthermore, slave devices are often buggy and imperfect.
(bus bus-path)
Opens an I2C bus by providing the number of the bus or a direct path.
(with-open [my-bus (bus "/dev/i2c-1")]
...)
Opens an I2C bus by providing the number of the bus or a direct path. ```clojure (with-open [my-bus (bus "/dev/i2c-1")] ...) ```
(capability+ bus)
Retrieves the I2C of the given bus.
Not every driver is capable of doing everything this library offers, specially when it comes to SMBus operations.
Even then, support can be unperfect. For instance, sometimes transactions are supported but fail when they contain more than 1 message, which makes them quite useless.
Furthermore, a lot also depends on the slave device.
Functions from this library document what need to be checked.
Retrieves the I2C of the given bus. Not every driver is capable of doing everything this library offers, specially when it comes to SMBus operations. Even then, support can be unperfect. For instance, sometimes transactions are supported but fail when they contain more than 1 message, which makes them quite useless. Furthermore, a lot also depends on the slave device. Functions from this library document what need to be checked.
Defaults values for options used throughout this library.
Defaults values for options used throughout this library.
(read bus length)
Reads an arbitrary amount of bytes.
Reads an arbitrary amount of bytes.
(select-slave bus slave-address)
(select-slave bus slave-address slave-options)
Selects an I2C slave device.
Affects every IO operations besides transactions where the slave address is given for each message.
Returns the given I2C bus.
See [[]] for :bit-10-addressing.
(select-slave my-bus
0x42
{:i2c/bit-10? false
:i2c/force? false})
Selects an I2C slave device. Affects every IO operations besides transactions where the slave address is given for each message. Returns the given I2C bus. See [[]] for :bit-10-addressing. ```clojure (select-slave my-bus 0x42 {:i2c/bit-10? false :i2c/force? false}) ```
(set-retries bus retries)
Sets the number of retries when communication fails.
Does not always produce an effect depending on the underlying driver.
Returns the given I2C bus.
Sets the number of retries when communication fails. Does not always produce an effect depending on the underlying driver. Returns the given I2C bus.
(set-timeout bus timeout-ms)
Sets the timeout in milliseconds for slave responses.
Does not always produce an effect depending on the underlying driver.
Returns the given I2C bus.
Sets the timeout in milliseconds for slave responses. Does not always produce an effect depending on the underlying driver. Returns the given I2C bus.
(transaction bus messages)
A transaction represents a sequence of messages, reads and writes, meant to be carried out without interruption.
Not every device supports this feature, or sometimes only supports 1 message per transaction with defeats their purpose.
Each message specifies if it is a read or a write and consists of options :
:i2c/bit-10? Should the 10-bit addressing mode be used ? :i2c/ignore-nak? Should "not-acknowledge" be ignored ? :i2c/no-read-ack? Should read-acks be ignored ? :i2c/no-start? Should not issue any more START/address after the initial one. :i2c/revise-wr-bit? Should send a read flag for writes and vice-versa (for broken slave) ? :i2c/slave-address Which slave. :i2c/tag Any value associated with the message, important for reads (the number of the message by default).
After the transaction is carried out, a map of tag -> bytes is returned for reads.
See capability+
for 10-bit addressing as well as other booleans flags under the :protocol-mangling capability.
(transaction some-bus
[{:i2c/slave-address 0x42
:i2c/write [24 1 2 3]}
{:i2c/slave-address 0x42
:i2c/read 3
:i2c/tag :my-read}])
;; => {:my-read [...]}
A transaction represents a sequence of messages, reads and writes, meant to be carried out without interruption. Not every device supports this feature, or sometimes only supports 1 message per transaction with defeats their purpose. Each message specifies if it is a read or a write and consists of options : :i2c/bit-10? Should the 10-bit addressing mode be used ? :i2c/ignore-nak? Should "not-acknowledge" be ignored ? :i2c/no-read-ack? Should read-acks be ignored ? :i2c/no-start? Should not issue any more START/address after the initial one. :i2c/revise-wr-bit? Should send a read flag for writes and vice-versa (for broken slave) ? :i2c/slave-address Which slave. :i2c/tag Any value associated with the message, important for reads (the number of the message by default). After the transaction is carried out, a map of tag -> bytes is returned for reads. See [[capability+]] for 10-bit addressing as well as other booleans flags under the :protocol-mangling capability. ```clojure (transaction some-bus [{:i2c/slave-address 0x42 :i2c/write [24 1 2 3]} {:i2c/slave-address 0x42 :i2c/read 3 :i2c/tag :my-read}]) ;; => {:my-read [...]} ```
(write bus bs)
Writes a sequence of bytes.
Returns the given I2C bus.
Writes a sequence of bytes. Returns the given I2C bus.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close