-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathi_tiny_i2c.h
62 lines (51 loc) · 1.54 KB
/
i_tiny_i2c.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*!
* @file
* @brief Abstract synchronous I2C peripheral.
*/
#ifndef i_tiny_i2c_h
#define i_tiny_i2c_h
#include <stdint.h>
#include <stdbool.h>
struct i_tiny_i2c_api_t;
typedef struct {
const struct i_tiny_i2c_api_t* api;
} i_tiny_i2c_t;
typedef struct i_tiny_i2c_api_t {
/*!
* Writes bytes from a buffer to the specified address. The stop
* condition can be omitted in order to allow for a repeated start
* by setting prepare_for_restart.
*
* Returns true if the transaction succeeded and false otherwise.
*/
bool (*write)(
i_tiny_i2c_t* self,
uint8_t address,
bool prepare_for_restart,
const void* buffer,
uint16_t buffer_size);
/*!
* Read bytes into a buffer from the specified address. The stop
* condition can be omitted in order to allow for a repeated start
* by setting prepare_for_restart.
*
* Returns true if the transaction succeeded and false otherwise.
*/
bool (*read)(
i_tiny_i2c_t* self,
uint8_t address,
bool prepare_for_restart,
void* buffer,
uint16_t buffer_size);
/*!
* Resets the bus.
*/
void (*reset)(i_tiny_i2c_t* self);
} i_tiny_i2c_api_t;
#define tiny_i2c_write(self, address, prepare_for_restart, buffer, buffer_size) \
(self)->api->write((self), (address), (prepare_for_restart), (buffer), (buffer_size))
#define tiny_i2c_read(self, address, prepare_for_restart, buffer, buffer_size) \
(self)->api->read((self), (address), (prepare_for_restart), (buffer), (buffer_size))
#define tiny_i2c_reset(self) \
(self)->api->reset((self))
#endif