2
0

bitbang_i2c.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef BITBANG_I2C_H
  2. #define BITBANG_I2C_H
  3. #include "hw/i2c/i2c.h"
  4. #define TYPE_GPIO_I2C "gpio_i2c"
  5. typedef struct bitbang_i2c_interface bitbang_i2c_interface;
  6. #define BITBANG_I2C_SDA 0
  7. #define BITBANG_I2C_SCL 1
  8. typedef enum bitbang_i2c_state {
  9. STOPPED = 0,
  10. SENDING_BIT7,
  11. SENDING_BIT6,
  12. SENDING_BIT5,
  13. SENDING_BIT4,
  14. SENDING_BIT3,
  15. SENDING_BIT2,
  16. SENDING_BIT1,
  17. SENDING_BIT0,
  18. WAITING_FOR_ACK,
  19. RECEIVING_BIT7,
  20. RECEIVING_BIT6,
  21. RECEIVING_BIT5,
  22. RECEIVING_BIT4,
  23. RECEIVING_BIT3,
  24. RECEIVING_BIT2,
  25. RECEIVING_BIT1,
  26. RECEIVING_BIT0,
  27. SENDING_ACK,
  28. SENT_NACK
  29. } bitbang_i2c_state;
  30. struct bitbang_i2c_interface {
  31. I2CBus *bus;
  32. bitbang_i2c_state state;
  33. int last_data;
  34. int last_clock;
  35. int device_out;
  36. uint8_t buffer;
  37. int current_addr;
  38. };
  39. /**
  40. * bitbang_i2c_init: in-place initialize the bitbang_i2c_interface struct
  41. */
  42. void bitbang_i2c_init(bitbang_i2c_interface *s, I2CBus *bus);
  43. int bitbang_i2c_set(bitbang_i2c_interface *i2c, int line, int level);
  44. #endif