Skip to content

Commit 4497a86

Browse files
committed
Update readme
Signed-off-by: Alex Forencich <[email protected]>
1 parent a958c8e commit 4497a86

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![Regression Tests](https://github.com/alexforencich/cocotbext-i2c/actions/workflows/regression-tests.yml/badge.svg)](https://github.com/alexforencich/cocotbext-i2c/actions/workflows/regression-tests.yml)
44
[![codecov](https://codecov.io/gh/alexforencich/cocotbext-i2c/branch/master/graph/badge.svg)](https://codecov.io/gh/alexforencich/cocotbext-i2c)
55
[![PyPI version](https://badge.fury.io/py/cocotbext-i2c.svg)](https://pypi.org/project/cocotbext-i2c)
6+
[![Downloads](https://pepy.tech/badge/cocotbext-i2c)](https://pepy.tech/project/cocotbext-i2c)
67

78
GitHub repository: https://github.com/alexforencich/cocotbext-i2c
89

@@ -29,3 +30,72 @@ Installation for active development:
2930

3031
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.
3132

33+
### I2C Master
34+
35+
The `I2cMaster` class can be used to issue read and write operations on an I2C bus.
36+
37+
Example:
38+
39+
from cocotbext.i2c import I2cMaster
40+
41+
i2c_master = I2cMaster(dut.sda_i, dut.sda_o, dut.scl_i, dut.scl_o, 400e3)
42+
43+
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.
80+
81+
Example:
82+
83+
from cocotbext.i2c import I2cMemory
84+
85+
i2c_mem = I2cMemory(dut.sda_i, dut.sda_o, dut.scl_i, dut.scl_o, 0x50, 256)
86+
87+
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

Comments
 (0)