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
@@ -105,69 +110,71 @@ class SPI : private NonCopyable<SPI> {
105
110
*/
106
111
voidformat(int bits, int mode = 0);
107
112
108
-
/** Set the spi bus clock frequency
113
+
/** Set the SPI bus clock frequency.
109
114
*
110
-
* @param hz SCLK frequency in hz (default = 1MHz)
115
+
* @param hz Clock frequency in Hz (default = 1MHz).
111
116
*/
112
117
voidfrequency(int hz = 1000000);
113
118
114
-
/** Write to the SPI Slave and return the response
119
+
/** Write to the SPI Slave and return the response.
115
120
*
116
-
* @param value Data to be sent to the SPI slave
121
+
* @param value Data to be sent to the SPI slave.
117
122
*
118
-
* @returns
119
-
* Response from the SPI slave
123
+
* @return Response from the SPI slave.
120
124
*/
121
125
virtualintwrite(int value);
122
126
123
-
/** Write to the SPI Slave and obtain the response
127
+
/** Write to the SPI Slave and obtain the response.
124
128
*
125
129
* The total number of bytes sent and received will be the maximum of
126
130
* tx_length and rx_length. The bytes written will be padded with the
127
131
* value 0xff.
128
132
*
129
-
* @param tx_buffer Pointer to the byte-array of data to write to the device
130
-
* @param tx_length Number of bytes to write, may be zero
131
-
* @param rx_buffer Pointer to the byte-array of data to read from the device
132
-
* @param rx_length Number of bytes to read, may be zero
133
-
* @returns
133
+
* @param tx_buffer Pointer to the byte-array of data to write to the device.
134
+
* @param tx_length Number of bytes to write, may be zero.
135
+
* @param rx_buffer Pointer to the byte-array of data to read from the device.
136
+
* @param rx_length Number of bytes to read, may be zero.
137
+
* @return
134
138
* The number of bytes written and read from the device. This is
135
139
* maximum of tx_length and rx_length.
136
140
*/
137
141
virtualintwrite(constchar *tx_buffer, int tx_length, char *rx_buffer, int rx_length);
138
142
139
-
/** Acquire exclusive access to this SPI bus
143
+
/** Acquire exclusive access to this SPI bus.
140
144
*/
141
145
virtualvoidlock(void);
142
146
143
-
/** Release exclusive access to this SPI bus
147
+
/** Release exclusive access to this SPI bus.
144
148
*/
145
149
virtualvoidunlock(void);
146
150
147
-
/** Set default write data
151
+
/** Set default write data.
148
152
* SPI requires the master to send some data during a read operation.
149
153
* Different devices may require different default byte values.
150
154
* For example: A SD Card requires default bytes to be 0xFF.
151
155
*
152
-
* @param data Default character to be transmitted while read operation
156
+
* @param data Default character to be transmitted during a read operation.
153
157
*/
154
158
voidset_default_write_value(char data);
155
159
156
160
#if DEVICE_SPI_ASYNCH
157
161
158
162
/** Start non-blocking SPI transfer using 8bit buffers.
159
163
*
160
-
* This function locks the deep sleep until any event has occurred
164
+
* This function locks the deep sleep until any event has occurred.
161
165
*
162
166
* @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
163
-
* the default SPI value is sent
164
-
* @param tx_length The length of TX buffer in bytes
167
+
* the default SPI value is sent.
168
+
* @param tx_length The length of TX buffer in bytes.
165
169
* @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
166
-
* received data are ignored
167
-
* @param rx_length The length of RX buffer in bytes
168
-
* @param callback The event callback function
169
-
* @param event The logical OR of events to modify. Look at spi hal header file for SPI events.
170
-
* @return Zero if the transfer has started, or -1 if SPI peripheral is busy
170
+
* received data are ignored.
171
+
* @param rx_length The length of RX buffer in bytes.
172
+
* @param callback The event callback function.
173
+
* @param event The event mask of events to modify. @see spi_api.h for SPI events.
174
+
*
175
+
* @return Operation result.
176
+
* @retval 0 If the transfer has started.
177
+
* @retval -1 If SPI peripheral is busy.
171
178
*/
172
179
template<typename Type>
173
180
inttransfer(const Type *tx_buffer, int tx_length, Type *rx_buffer, int rx_length, constevent_callback_t &callback, int event = SPI_EVENT_COMPLETE)
@@ -179,75 +186,85 @@ class SPI : private NonCopyable<SPI> {
179
186
return0;
180
187
}
181
188
182
-
/** Abort the on-going SPI transfer, and continue with transfer's in the queue if any.
189
+
/** Abort the on-going SPI transfer, and continue with transfers in the queue, if any.
183
190
*/
184
191
voidabort_transfer();
185
192
186
-
/** Clear the transaction buffer
193
+
/** Clear the queue of transfers.
187
194
*/
188
195
voidclear_transfer_buffer();
189
196
190
-
/** Clear the transaction buffer and abort on-going transfer.
197
+
/** Clear the queue of transfers and abort the on-going transfer.
191
198
*/
192
199
voidabort_all_transfers();
193
200
194
-
/** Configure DMA usage suggestion for non-blocking transfers
201
+
/** Configure DMA usage suggestion for non-blocking transfers.
195
202
*
196
-
* @param usage The usage DMA hint for peripheral
197
-
* @return Zero if the usage was set, -1 if a transaction is on-going
198
-
*/
203
+
* @param usage The usage DMA hint for peripheral.
204
+
*
205
+
* @return Result of the operation.
206
+
* @retval 0 The usage was set.
207
+
* @retval -1 Usage cannot be set as there is an ongoing transaction.
208
+
*/
199
209
intset_dma_usage(DMAUsage usage);
200
210
201
211
protected:
202
-
/** SPI IRQ handler
203
-
*
204
-
*/
212
+
/** SPI interrupt handler.
213
+
*/
205
214
voidirq_handler_asynch(void);
206
215
207
-
/** Common transfer method
216
+
/** Start the transfer or put it on the queue.
208
217
*
209
218
* @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
210
219
* the default SPI value is sent
211
-
* @param tx_length The length of TX buffer in bytes
220
+
* @param tx_length The length of TX buffer in bytes.
212
221
* @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
213
-
* received data are ignored
214
-
* @param rx_length The length of RX buffer in bytes
215
-
* @param bit_width The buffers element width
216
-
* @param callback The event callback function
217
-
* @param event The logical OR of events to modify
218
-
* @return Zero if the transfer has started or was added to the queue, or -1 if SPI peripheral is busy/buffer is full
219
-
*/
222
+
* received data are ignored.
223
+
* @param rx_length The length of RX buffer in bytes.
224
+
* @param bit_width The buffers element width in bits.
225
+
* @param callback The event callback function.
226
+
* @param event The event mask of events to modify.
227
+
*
228
+
* @return Operation success.
229
+
* @retval 0 A transfer was started or added to the queue.
230
+
* @retval -1 Transfer can't be added because queue is full.
231
+
*/
220
232
inttransfer(constvoid *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsignedchar bit_width, constevent_callback_t &callback, int event);
221
233
222
-
/**
234
+
/** Put a transfer on the transfer queue.
223
235
*
224
236
* @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
225
-
* the default SPI value is sent
226
-
* @param tx_length The length of TX buffer in bytes
237
+
* the default SPI value is sent.
238
+
* @param tx_length The length of TX buffer in bytes.
227
239
* @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
228
-
* received data are ignored
229
-
* @param rx_length The length of RX buffer in bytes
230
-
* @param bit_width The buffers element width
231
-
* @param callback The event callback function
232
-
* @param event The logical OR of events to modify
233
-
* @return Zero if a transfer was added to the queue, or -1 if the queue is full
234
-
*/
240
+
* received data are ignored.
241
+
* @param rx_length The length of RX buffer in bytes.
242
+
* @param bit_width The buffers element width in bits.
243
+
* @param callback The event callback function.
244
+
* @param event The event mask of events to modify.
245
+
*
246
+
* @return Operation success.
247
+
* @retval 0 A transfer was added to the queue.
248
+
* @retval -1 Transfer can't be added because queue is full.
249
+
*/
235
250
intqueue_transfer(constvoid *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsignedchar bit_width, constevent_callback_t &callback, int event);
236
251
237
-
/** Configures a callback, spi peripheral and initiate a new transfer
252
+
/** Configure a callback, SPI peripheral, and initiate a new transfer.
238
253
*
239
254
* @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
240
-
* the default SPI value is sent
241
-
* @param tx_length The length of TX buffer in bytes
255
+
* the default SPI value is sent.
256
+
* @param tx_length The length of TX buffer in bytes.
242
257
* @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
243
-
* received data are ignored
244
-
* @param rx_length The length of RX buffer in bytes
245
-
* @param bit_width The buffers element width
246
-
* @param callback The event callback function
247
-
* @param event The logical OR of events to modify
248
-
*/
258
+
* received data are ignored.
259
+
* @param rx_length The length of RX buffer in bytes.
260
+
* @param bit_width The buffers element width.
261
+
* @param callback The event callback function.
262
+
* @param event The event mask of events to modify.
263
+
*/
249
264
voidstart_transfer(constvoid *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsignedchar bit_width, constevent_callback_t &callback, int event);
250
265
266
+
#if !defined(DOXYGEN_ONLY)
267
+
251
268
private:
252
269
/** Lock deep sleep only if it is not yet locked */
253
270
voidlock_deep_sleep();
@@ -258,44 +275,63 @@ class SPI : private NonCopyable<SPI> {
258
275
259
276
#if TRANSACTION_QUEUE_SIZE_SPI
260
277
261
-
/** Start a new transaction
278
+
/** Start a new transaction.
262
279
*
263
-
* @param data Transaction data
264
-
*/
280
+
* @param data Transaction data.
281
+
*/
265
282
voidstart_transaction(transaction_t *data);
266
283
267
-
/** Dequeue a transaction
268
-
*
269
-
*/
284
+
/** Dequeue a transaction and start the transfer if there was one pending.
0 commit comments