forked from ckolivas/cgminer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi2c-context.h
30 lines (24 loc) · 816 Bytes
/
i2c-context.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
#ifndef I2C_CONTEXT_H
#define I2C_CONTEXT_H
#include <stdbool.h>
#include <stdint.h>
/* common i2c context */
struct i2c_ctx {
/* destructor */
void (*exit)(struct i2c_ctx *ctx);
/* write one byte to given register */
bool (*write)(struct i2c_ctx *ctx, uint8_t reg, uint8_t val);
/* read one byte from given register */
bool (*read)(struct i2c_ctx *ctx, uint8_t reg, uint8_t *val);
/* write multiple bytes to addr */
bool (*write_raw)(struct i2c_ctx *ctx, uint8_t *buf, uint32_t len);
/* read multiple bytes from addr */
bool (*read_raw)(struct i2c_ctx *ctx, uint8_t *buf, uint32_t len);
/* common data */
uint8_t addr;
int file;
};
/* the default I2C bus on RPi */
#define I2C_BUS "/dev/i2c-1"
extern struct i2c_ctx *i2c_slave_open(char *i2c_bus, uint8_t slave_addr);
#endif /* I2C_CONTEXT_H */