-
Notifications
You must be signed in to change notification settings - Fork 12
/
bus.ex
61 lines (49 loc) · 1.97 KB
/
bus.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
defprotocol Circuits.I2C.Bus do
@moduledoc """
A bus is the connection to a real or virtual I2C controller
"""
@typedoc """
I2C controller flags
* `:supports_empty_write` - the controller supports sending empty binaries
to devices. These can be used for device detection.
"""
@type flag() :: :supports_empty_write
@doc """
"""
@spec flags(t()) :: [flag()]
def flags(bus)
@doc """
Read data over I2C
The controller should try to read the specified number of bytes over I2C.
If the retry option is passed and non-zero, the transaction only needs to
be retried if there's an error. This means that fewer that the requested
number of bytes may be returned.
See the implementation for options
"""
@spec read(t(), Circuits.I2C.address(), non_neg_integer(), keyword()) ::
{:ok, binary()} | {:error, term()}
def read(bus, address, count, options)
@doc """
Write data over I2C
The controller should write the passed in data to the specified I2C address.
"""
@spec write(t(), Circuits.I2C.address(), iodata(), keyword()) :: :ok | {:error, term()}
def write(bus, address, data, options)
@doc """
Write data and read a result in one I2C transaction
This function handles the common task of writing a register number
to a device and then reading its contents. The controller should perform it
as one transaction without a stop condition between the write and read.
"""
@spec write_read(t(), Circuits.I2C.address(), iodata(), non_neg_integer(), keyword()) ::
{:ok, binary()} | {:error, term()}
def write_read(bus, address, write_data, read_count, options)
@doc """
Free up resources associated with the bus
Well behaved backends free up their resources with the help of the Erlang garbage collector. However, it is good
practice for users to call `Circuits.I2C.close/1` (and hence this function) so that
limited resources are freed before they're needed again.
"""
@spec close(t()) :: :ok
def close(bus)
end