@@ -111,40 +111,108 @@ def elaborate(self, platform):
111111
112112
113113class SPIPeripheral (wiring .Component ):
114+ """
115+ A custom, minimal SPI controller
116+
117+ Transfers up to a width of 32 bits are supported, as are all SPI modes.
118+ """
119+
114120 class Config (csr .Register , access = "rw" ):
115- """
116- sck_idle: idle state of sck, '1' to invert sck
117- sck_edge:
118- 1 to latch output on rising sck edge, read input on falling sck edge
119- 0 to read input on rising sck edge, latch output on falling sck edge
120- chip_select: write '1' to assert (bring low) chip select output
121- width: width of transfer, minus 1
121+ """Config register.
122+
123+ This :class:`Register` is written to in order to configure the SPI mode and transaction.
124+
125+ It has the following fields:
126+
127+ .. bitfield::
128+ :bits: 8
129+
130+ [
131+ { "name": "sck_idle", "bits": 1, "attr": "RW" },
132+ { "name": "sck_edge", "bits": 1, "attr": "RW" },
133+ { "name": "chip_select", "bits": 1, "attr": "RW" },
134+ { "name": "width", "bits": 5, "attr": "RW" },
135+ ]
136+
137+ - The ``sck_idle`` field is used to invert the SCK polarity, ``0b0`` for an idle low SCK, ``0b1`` for an idle high SCK
138+ - The ``sck_edge`` field selects which edge is used for input and output data.
139+ - ``0b0`` to read input on rising SCK edge, latch output on falling SCK edge
140+ - ``0b1`` to latch output on rising SCK edge, read input on falling SCK edge
141+ - The ``chip_select`` field controls the CS pin; setting it to ``0b1`` asserts (brings low) chip select.
142+ - The ``width`` field configures the width of the transfer. It is set to the width of the transfer minus 1,
143+ ``31`` gives the maximum width of 32.
122144 """
123145 sck_idle : csr .Field (csr .action .RW , unsigned (1 ))
124146 sck_edge : csr .Field (csr .action .RW , unsigned (1 ))
125147 chip_select : csr .Field (csr .action .RW , unsigned (1 ))
126148 width : csr .Field (csr .action .RW , unsigned (5 ))
127149
128150 class Divider (csr .Register , access = "rw" ):
129- """SPI SCK clock divider, 1 = divide by 4"""
151+ """Divider register.
152+
153+ This :class:`Register` is used to configure the clock frequency of the I2C peripheral.
154+
155+ The SCK frequency is the input clock frequency divided by 4 times the value in this register.
156+ For example, for a SCK of 1/12 the system clock, this register would be set to 3.
157+ """
130158 val : csr .Field (csr .action .RW , unsigned (8 ))
131159
132160 class SendData (csr .Register , access = "w" ):
133- """data to transmit, must be left justified (bits [31..32-N] used)"""
161+ """SendData register.
162+
163+ Writing to this :class:`Register` starts a read/write transfer on the SPI bus, the width of which is configured in `Config`.
164+
165+ It has the following fields:
166+
167+ .. bitfield::
168+ :bits: 32
169+
170+ [
171+ { "name": "val", "bits": 32, "attr": "W" },
172+ ]
173+
174+ - The `val` field must be left-justified, so for a transfer of ``N`` bits, bits ``[31..32-N]`` are used.
175+ """
176+
134177 val : csr .Field (csr .action .W , unsigned (32 ))
135178
136179 class ReceiveData (csr .Register , access = "r" ):
137- """data received, is right justified (bits [N-1..0] used)"""
180+ """ReceiveData register.
181+
182+ This :class:`Register` contains the read data of the last transfer started with a write to ``SendData``.
183+
184+ It has the following fields:
185+
186+ .. bitfield::
187+ :bits: 8
188+
189+ [
190+ { "name": "val", "bits": 32, "attr": "R" },
191+ ]
192+
193+ - The `val` field is right-justified, so for a transfer of ``N`` bits, bits ``[N-1..0]`` are used.
194+ """
138195 val : csr .Field (csr .action .R , unsigned (32 ))
139196
140197 class Status (csr .Register , access = "r" ):
141- """recv_full is 1 when transfer has been completed. reset to zero by reading receive_data"""
142- recv_full : csr .Field (csr .action .R , unsigned (1 ))
198+ """Status register.
143199
200+ This :class:`Register` contains the status of the peripheral.
201+
202+ It has the following fields:
203+
204+ .. bitfield::
205+ :bits: 8
206+
207+ [
208+ { "name": "recv_full", "bits": 1, "attr": "R" },
209+ { "bits": 7, "attr": "ResR0" },
210+ ]
211+
212+ - The ``recv_full`` field is set to ``0b1`` when a transfer is completed. It is reset to zero by reading ``ReceiveData``.
213+ """
214+ recv_full : csr .Field (csr .action .R , unsigned (1 ))
144215
145- """
146- A custom, minimal SPI controller
147- """
148216 def __init__ (self ):
149217 regs = csr .Builder (addr_width = 5 , data_width = 8 )
150218
0 commit comments