-
Notifications
You must be signed in to change notification settings - Fork 0
/
i2c.h
34 lines (24 loc) · 1.06 KB
/
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
#ifndef _I2C_H_
#define _I2C_H_
#include <stdio.h>
#define I2C_READ_SUCCESS 0
#define I2C_READ_ERROR 1
typedef void (*i2c_data_ready_callback)(int status, int count);
void i2c_initialize();
int i2c_read(uint8_t slave, uint8_t reg, uint8_t *buffer, size_t n);
int i2c_write(uint8_t slave, uint8_t reg, uint8_t value);
int i2c_read_noblock(uint8_t slave, uint8_t reg, uint8_t *buffer, size_t n,
i2c_data_ready_callback callback);
#define i2c_is_busy() (I2C0_S & I2C_S_BUSY)
unsigned int i2c_bytes_read();
#define i2c_read_register_byte(slave, reg) \
({ \
uint8_t i; \
i2c_read(slave, reg, &i, 1) < 0 ? -1 : i; \
})
#define i2c_read_register_word(slave, reg) \
({ \
uint16_t i; \
(i2c_read(slave, reg, (uint8_t *)&i, 2) < 0 ? - 1 : i); \
})
#endif