You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -29,3 +30,72 @@ Installation for active development:
29
30
30
31
See the `tests` directory, [taxi](https://github.com/fpganinja/taxi), and [verilog-i2c](https://github.com/alexforencich/verilog-i2c) for complete testbenches using these modules.
31
32
33
+
### I2C Master
34
+
35
+
The `I2cMaster` class can be used to issue read and write operations on an I2C bus.
To issue I2C operations with an `I2cMaster`, call `read()` or `write()`. These are the preferred methods, as they will manage the bus state automatically. Lower-level methods must be called in the appropriate order. The `read()` and `write()` methods will leave the bus active, so call `send_stop()` to release the bus.
44
+
45
+
#### Constructor parameters:
46
+
47
+
*_sda_: serial data in/out
48
+
*_sda_o_: serial data output
49
+
*_scl_: clock in/out
50
+
*_scl_o_: clock output
51
+
*_speed_: nominal data rate in bits per second (default `400e3`)
52
+
53
+
#### Attributes:
54
+
55
+
*_speed_: nominal data rate in bits per second
56
+
57
+
#### Methods
58
+
59
+
*`write(addr, data)`: send _data_ to device at address `addr` (blocking)
60
+
*`read(addr, count)`: read _count_ bytes from device at address `addr` (blocking)
61
+
*`send_start()`: send a start condition on the bus
62
+
*`send_stop()`: send a stop condition and release the bus
63
+
*`send_byte()`: send a byte on the bus
64
+
*`recv_byte()`: read a byte from the bus
65
+
66
+
### I2C Device
67
+
68
+
The `I2cDevice` class emulates an I2C device. This class cannot be used directly, instead it should extended and the methods `handle_start()`, `handle_write()`, `handle_read()`, and `handle_stop()` implemented appropriately. See `I2cMem` for an example.
69
+
70
+
#### Constructor parameters:
71
+
72
+
*_sda_: serial data in/out
73
+
*_sda_o_: serial data output
74
+
*_scl_: clock in/out
75
+
*_scl_o_: clock output
76
+
77
+
### I2C Memory
78
+
79
+
The `I2cMemory` class emulates a simple memory like an I2C EEPROM.
The memory can then be read/written via I2C operations on the bus, with the first bytes written after a start bit setting the address, and subsequent reads/writes advancing the internal address and reading/writing the memory. The memory can also be accessed via `read_mem()` and `write_mem()`.
88
+
89
+
#### Constructor parameters:
90
+
91
+
*_sda_: serial data in/out
92
+
*_sda_o_: serial data output
93
+
*_scl_: clock in/out
94
+
*_scl_o_: clock output
95
+
*_addr_: device address (default `0x50`)
96
+
*_size_: size in bytes (default `256`)
97
+
98
+
#### Methods
99
+
100
+
*`read_mem(addr, count)`: read _count_ bytes from memory, starting at `addr`
101
+
*`write_mem(addr, data)`: write _data_ to memory, starting at `addr`
0 commit comments