-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathi_tiny_async_spi.h
40 lines (32 loc) · 1.03 KB
/
i_tiny_async_spi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*!
* @file
* @brief Abstraction for performing an asynchronous SPI transfer.
*
* Assumes chip select is managed by the client.
*/
#ifndef i_tiny_async_spi_h
#define i_tiny_async_spi_h
#include <stdint.h>
typedef void (*tiny_async_spi_callback_t)(void* context);
struct i_tiny_async_spi_api_t;
typedef struct {
const struct i_tiny_async_spi_api_t* api;
} i_tiny_async_spi_t;
typedef struct i_tiny_async_spi_api_t {
/*!
* Performs a simultaneous write/read. If not reading or writing, the corresponding
* buffer can be left NULL.
*
* Clients should assume that the callback is raised from an interrupt.
*/
void (*transfer)(
i_tiny_async_spi_t* self,
const void* write_buffer,
void* read_buffer,
uint16_t buffer_size,
void* context,
tiny_async_spi_callback_t callback);
} i_tiny_async_spi_api_t;
#define tiny_async_spi_transfer(self, write_buffer, read_buffer, buffer_size, context, callback) \
(self)->api->transfer((self), (write_buffer), (read_buffer), (buffer_size), (context), (callback))
#endif