Firmware SDK
twr_i2c.h
1 #ifndef _TWR_I2C_H
2 #define _TWR_I2C_H
3 
4 #include <twr_common.h>
5 
9 
11 #define TWR_I2C_MEMORY_ADDRESS_16_BIT 0x80000000
12 
14 
15 typedef enum
16 {
19 
22 
24  TWR_I2C_I2C_1W = 2
25 
27 
29 
30 typedef enum
31 {
34 
37 
39 
41 
42 typedef struct
43 {
45  uint8_t device_address;
46 
48  void *buffer;
49 
51  size_t length;
52 
54 
56 
57 typedef struct
58 {
60  uint8_t device_address;
61 
63  uint32_t memory_address;
64 
66  void *buffer;
67 
69  size_t length;
70 
72 
76 
78 
81 
82 void twr_i2c_deinit(twr_i2c_channel_t channel);
83 
87 
89 
93 
95 
101 
102 bool twr_i2c_write(twr_i2c_channel_t channel, const twr_i2c_transfer_t *transfer);
103 
109 
110 bool twr_i2c_read(twr_i2c_channel_t channel, const twr_i2c_transfer_t *transfer);
111 
117 
119 
125 
127 
133 
134 bool twr_i2c_memory_write_8b(twr_i2c_channel_t channel, uint8_t device_address, uint32_t memory_address, uint8_t data);
135 
141 
142 bool twr_i2c_memory_write_16b(twr_i2c_channel_t channel, uint8_t device_address, uint32_t memory_address, uint16_t data);
143 
149 
150 bool twr_i2c_memory_read_8b(twr_i2c_channel_t channel, uint8_t device_address, uint32_t memory_address, uint8_t *data);
151 
157 
158 bool twr_i2c_memory_read_16b(twr_i2c_channel_t channel, uint8_t device_address, uint32_t memory_address, uint16_t *data);
159 
161 
162 #endif // _TWR_I2C_H
twr_i2c_speed_t
I2C communication speed.
Definition: twr_i2c.h:31
void twr_i2c_deinit(twr_i2c_channel_t channel)
Deitialize I2C channel.
Definition: twr_i2c.c:140
void twr_i2c_init(twr_i2c_channel_t channel, twr_i2c_speed_t speed)
Initialize I2C channel.
Definition: twr_i2c.c:57
bool twr_i2c_memory_write(twr_i2c_channel_t channel, const twr_i2c_memory_transfer_t *transfer)
Memory write to I2C channel.
Definition: twr_i2c.c:333
bool twr_i2c_memory_read(twr_i2c_channel_t channel, const twr_i2c_memory_transfer_t *transfer)
Memory read from I2C channel.
Definition: twr_i2c.c:371
void twr_i2c_set_speed(twr_i2c_channel_t channel, twr_i2c_speed_t speed)
Set I2C channel speed.
Definition: twr_i2c.c:200
bool twr_i2c_read(twr_i2c_channel_t channel, const twr_i2c_transfer_t *transfer)
Read from I2C channel.
Definition: twr_i2c.c:289
bool twr_i2c_memory_write_8b(twr_i2c_channel_t channel, uint8_t device_address, uint32_t memory_address, uint8_t data)
Memory write 1 byte to I2C channel.
Definition: twr_i2c.c:408
bool twr_i2c_memory_write_16b(twr_i2c_channel_t channel, uint8_t device_address, uint32_t memory_address, uint16_t data)
Memory write 2 bytes to I2C channel.
Definition: twr_i2c.c:420
bool twr_i2c_memory_read_16b(twr_i2c_channel_t channel, uint8_t device_address, uint32_t memory_address, uint16_t *data)
Memory read 2 bytes from I2C channel.
Definition: twr_i2c.c:449
twr_i2c_speed_t twr_i2c_get_speed(twr_i2c_channel_t channel)
Get speed I2C channel.
Definition: twr_i2c.c:195
bool twr_i2c_write(twr_i2c_channel_t channel, const twr_i2c_transfer_t *transfer)
Write to I2C channel.
Definition: twr_i2c.c:243
bool twr_i2c_memory_read_8b(twr_i2c_channel_t channel, uint8_t device_address, uint32_t memory_address, uint8_t *data)
Memory read 1 byte from I2C channel.
Definition: twr_i2c.c:437
twr_i2c_channel_t
I2C channels.
Definition: twr_i2c.h:16
@ TWR_I2C_SPEED_400_KHZ
I2C communication speed is 400 kHz.
Definition: twr_i2c.h:36
@ TWR_I2C_SPEED_100_KHZ
I2C communication speed is 100 kHz.
Definition: twr_i2c.h:33
@ TWR_I2C_I2C0
I2C channel I2C0.
Definition: twr_i2c.h:18
@ TWR_I2C_I2C_1W
I2C channel 1wire.
Definition: twr_i2c.h:24
@ TWR_I2C_I2C1
I2C channel I2C1.
Definition: twr_i2c.h:21
I2C memory transfer parameters.
Definition: twr_i2c.h:58
uint32_t memory_address
8-bit I2C memory address (it can be extended to 16-bit format if OR-ed with TWR_I2C_MEMORY_ADDRESS_16...
Definition: twr_i2c.h:63
uint8_t device_address
7-bit I2C device address
Definition: twr_i2c.h:60
size_t length
Length of buffer which is being written or read.
Definition: twr_i2c.h:69
void * buffer
Pointer to buffer which is being written or read.
Definition: twr_i2c.h:66
I2C transfer parameters.
Definition: twr_i2c.h:43
void * buffer
Pointer to buffer which is being written or read.
Definition: twr_i2c.h:48
uint8_t device_address
7-bit I2C device address
Definition: twr_i2c.h:45
size_t length
Length of buffer which is being written or read.
Definition: twr_i2c.h:51