i2c-context.h 816 B

123456789101112131415161718192021222324252627282930
  1. #ifndef I2C_CONTEXT_H
  2. #define I2C_CONTEXT_H
  3. #include <stdbool.h>
  4. #include <stdint.h>
  5. /* common i2c context */
  6. struct i2c_ctx {
  7. /* destructor */
  8. void (*exit)(struct i2c_ctx *ctx);
  9. /* write one byte to given register */
  10. bool (*write)(struct i2c_ctx *ctx, uint8_t reg, uint8_t val);
  11. /* read one byte from given register */
  12. bool (*read)(struct i2c_ctx *ctx, uint8_t reg, uint8_t *val);
  13. /* write multiple bytes to addr */
  14. bool (*write_raw)(struct i2c_ctx *ctx, uint8_t *buf, uint32_t len);
  15. /* read multiple bytes from addr */
  16. bool (*read_raw)(struct i2c_ctx *ctx, uint8_t *buf, uint32_t len);
  17. /* common data */
  18. uint8_t addr;
  19. int file;
  20. };
  21. /* the default I2C bus on RPi */
  22. #define I2C_BUS "/dev/i2c-1"
  23. extern struct i2c_ctx *i2c_slave_open(char *i2c_bus, uint8_t slave_addr);
  24. #endif /* I2C_CONTEXT_H */