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