i2c-context.h 606 B

1234567891011121314151617181920212223242526
  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. /* common data */
  14. uint8_t addr;
  15. int file;
  16. };
  17. /* the default I2C bus on RPi */
  18. #define I2C_BUS "/dev/i2c-1"
  19. extern struct i2c_ctx *i2c_slave_open(char *i2c_bus, uint8_t slave_addr);
  20. #endif /* I2C_CONTEXT_H */