@@ -124,6 +124,7 @@ struct spi_cs_control {
124
124
/**
125
125
* @brief SPI controller configuration structure
126
126
*
127
+ * dev is a valid pointer to an actual SPI device
127
128
* frequency is the bus frequency in Hertz
128
129
* operation is a bit field with the following parts:
129
130
* operational mode [ 0 ] - master or slave.
@@ -139,9 +140,12 @@ struct spi_cs_control {
139
140
* emulated through a gpio line, or NULL otherwise.
140
141
*/
141
142
struct spi_config {
143
+ struct device * dev ;
144
+
142
145
u32_t frequency ;
143
146
u16_t operation ;
144
147
u16_t slave ;
148
+
145
149
struct spi_cs_control * cs ;
146
150
};
147
151
@@ -163,25 +167,36 @@ struct spi_buf {
163
167
* @brief Callback API for I/O
164
168
* See spi_transceive() for argument descriptions
165
169
*/
166
- typedef int (* spi_api_io )(struct device * dev ,
167
- struct spi_config * config ,
170
+ typedef int (* spi_api_io )(struct spi_config * config ,
168
171
const struct spi_buf * * tx_bufs ,
169
172
struct spi_buf * * rx_bufs );
170
173
174
+ /**
175
+ * @typedef spi_api_io
176
+ * @brief Callback API for asynchronous I/O
177
+ * See spi_transceive_async() for argument descriptions
178
+ */
179
+ typedef int (* spi_api_io_async )(struct spi_config * config ,
180
+ const struct spi_buf * * tx_bufs ,
181
+ struct spi_buf * * rx_bufs ,
182
+ struct k_poll_signal * async );
183
+
171
184
/**
172
185
* @brief SPI driver API
173
186
* This is the mandatory API any SPI driver needs to expose.
174
187
*/
175
188
struct spi_driver_api {
176
189
spi_api_io transceive ;
190
+ #ifdef CONFIG_POLL
191
+ spi_api_io_async transceive_async ;
192
+ #endif
177
193
};
178
194
179
195
/**
180
196
* @brief Read/write the specified amount of data from the SPI driver.
181
197
*
182
198
* Note: This function is synchronous.
183
199
*
184
- * @param dev is a valid pointer to an actual SPI device
185
200
* @param config Pointer to a valid spi_config structure instance.
186
201
* @param tx_bufs NULL terminated buffer array where data to be sent
187
202
* originates from, or NULL if none.
@@ -190,57 +205,129 @@ struct spi_driver_api {
190
205
*
191
206
* @retval 0 If successful, negative errno code otherwise.
192
207
*/
193
- static inline int spi_transceive (struct device * dev ,
194
- struct spi_config * config ,
208
+ static inline int spi_transceive (struct spi_config * config ,
195
209
const struct spi_buf * * tx_bufs ,
196
210
struct spi_buf * * rx_bufs )
197
211
{
198
- const struct spi_driver_api * api = dev -> driver_api ;
212
+ const struct spi_driver_api * api = config -> dev -> driver_api ;
199
213
200
- return api -> transceive (dev , config , tx_bufs , rx_bufs );
214
+ return api -> transceive (config , tx_bufs , rx_bufs );
201
215
}
202
216
203
217
/**
204
218
* @brief Read the specified amount of data from the SPI driver.
205
219
*
206
220
* Note: This function is synchronous.
207
221
*
208
- * @param dev is a valid pointer to an actual SPI device
209
222
* @param config Pointer to a valid spi_config structure instance.
210
223
* @param rx_bufs NULL terminated buffer array where data to be read
211
224
* will be written to.
212
225
*
213
226
* @retval 0 If successful, negative errno code otherwise.
214
227
*/
215
- static inline int spi_read (struct device * dev ,
216
- struct spi_config * config ,
228
+ static inline int spi_read (struct spi_config * config ,
217
229
struct spi_buf * * rx_bufs )
218
230
{
219
- const struct spi_driver_api * api = dev -> driver_api ;
231
+ const struct spi_driver_api * api = config -> dev -> driver_api ;
220
232
221
- return api -> transceive (dev , config , NULL , rx_bufs );
233
+ return api -> transceive (config , NULL , rx_bufs );
222
234
}
223
235
224
236
/**
225
237
* @brief Write the specified amount of data from the SPI driver.
226
238
*
227
239
* Note: This function is synchronous.
228
240
*
229
- * @param dev is a valid pointer to an actual SPI device
230
241
* @param config Pointer to a valid spi_config structure instance.
231
242
* @param tx_bufs NULL terminated buffer array where data to be sent
232
243
* originates from.
233
244
*
234
245
* @retval 0 If successful, negative errno code otherwise.
235
246
*/
236
- static inline int spi_write (struct device * dev ,
237
- struct spi_config * config ,
247
+ static inline int spi_write (struct spi_config * config ,
238
248
const struct spi_buf * * tx_bufs )
239
249
{
240
- const struct spi_driver_api * api = dev -> driver_api ;
250
+ const struct spi_driver_api * api = config -> dev -> driver_api ;
251
+
252
+ return api -> transceive (config , tx_bufs , NULL );
253
+ }
254
+
255
+ #ifdef CONFIG_POLL
256
+ /**
257
+ * @brief Read/write the specified amount of data from the SPI driver.
258
+ *
259
+ * Note: This function is asynchronous.
260
+ *
261
+ * @param config Pointer to a valid spi_config structure instance.
262
+ * @param tx_bufs NULL terminated buffer array where data to be sent
263
+ * originates from, or NULL if none.
264
+ * @param rx_bufs NULL terminated buffer array where data to be read
265
+ * will be written to, or NULL if none.
266
+ * @param async A pointer to a valid and ready to be signaled
267
+ * struct k_poll_signal. (Note: if NULL this function will not
268
+ * notify the end of the transaction, and whether it went
269
+ * successfully or not).
270
+ *
271
+ * @retval 0 If successful, negative errno code otherwise.
272
+ */
273
+ static inline int spi_transceive_async (struct spi_config * config ,
274
+ const struct spi_buf * * tx_bufs ,
275
+ struct spi_buf * * rx_bufs ,
276
+ struct k_poll_signal * async )
277
+ {
278
+ const struct spi_driver_api * api = config -> dev -> driver_api ;
279
+
280
+ return api -> transceive_async (config , tx_bufs , rx_bufs , async );
281
+ }
282
+
283
+ /**
284
+ * @brief Read the specified amount of data from the SPI driver.
285
+ *
286
+ * Note: This function is asynchronous.
287
+ *
288
+ * @param config Pointer to a valid spi_config structure instance.
289
+ * @param rx_bufs NULL terminated buffer array where data to be read
290
+ * will be written to.
291
+ * @param async A pointer to a valid and ready to be signaled
292
+ * struct k_poll_signal. (Note: if NULL this function will not
293
+ * notify the end of the transaction, and whether it went
294
+ * successfully or not).
295
+ *
296
+ * @retval 0 If successful, negative errno code otherwise.
297
+ */
298
+ static inline int spi_read_async (struct spi_config * config ,
299
+ struct spi_buf * * rx_bufs ,
300
+ struct k_poll_signal * async )
301
+ {
302
+ const struct spi_driver_api * api = config -> dev -> driver_api ;
303
+
304
+ return api -> transceive_async (config , NULL , rx_bufs , async );
305
+ }
306
+
307
+ /**
308
+ * @brief Write the specified amount of data from the SPI driver.
309
+ *
310
+ * Note: This function is asynchronous.
311
+ *
312
+ * @param config Pointer to a valid spi_config structure instance.
313
+ * @param tx_bufs NULL terminated buffer array where data to be sent
314
+ * originates from.
315
+ * @param async A pointer to a valid and ready to be signaled
316
+ * struct k_poll_signal. (Note: if NULL this function will not
317
+ * notify the end of the transaction, and whether it went
318
+ * successfully or not).
319
+ *
320
+ * @retval 0 If successful, negative errno code otherwise.
321
+ */
322
+ static inline int spi_write_async (struct spi_config * config ,
323
+ const struct spi_buf * * tx_bufs ,
324
+ struct k_poll_signal * async )
325
+ {
326
+ const struct spi_driver_api * api = config -> dev -> driver_api ;
241
327
242
- return api -> transceive ( dev , config , tx_bufs , NULL );
328
+ return api -> transceive_async ( config , tx_bufs , NULL , async );
243
329
}
330
+ #endif /* CONFIG_POLL */
244
331
245
332
#ifdef __cplusplus
246
333
}
0 commit comments