1d718b747SBALATON Zoltan #ifndef BITBANG_I2C_H 2d718b747SBALATON Zoltan #define BITBANG_I2C_H 3d718b747SBALATON Zoltan 4d718b747SBALATON Zoltan #include "hw/i2c/i2c.h" 5d718b747SBALATON Zoltan 6*da8df26dSPhilippe Mathieu-Daudé #define TYPE_GPIO_I2C "gpio_i2c" 7*da8df26dSPhilippe Mathieu-Daudé 8d718b747SBALATON Zoltan typedef struct bitbang_i2c_interface bitbang_i2c_interface; 9d718b747SBALATON Zoltan 10d718b747SBALATON Zoltan #define BITBANG_I2C_SDA 0 11d718b747SBALATON Zoltan #define BITBANG_I2C_SCL 1 12d718b747SBALATON Zoltan 1341742927SPeter Maydell typedef enum bitbang_i2c_state { 1441742927SPeter Maydell STOPPED = 0, 1541742927SPeter Maydell SENDING_BIT7, 1641742927SPeter Maydell SENDING_BIT6, 1741742927SPeter Maydell SENDING_BIT5, 1841742927SPeter Maydell SENDING_BIT4, 1941742927SPeter Maydell SENDING_BIT3, 2041742927SPeter Maydell SENDING_BIT2, 2141742927SPeter Maydell SENDING_BIT1, 2241742927SPeter Maydell SENDING_BIT0, 2341742927SPeter Maydell WAITING_FOR_ACK, 2441742927SPeter Maydell RECEIVING_BIT7, 2541742927SPeter Maydell RECEIVING_BIT6, 2641742927SPeter Maydell RECEIVING_BIT5, 2741742927SPeter Maydell RECEIVING_BIT4, 2841742927SPeter Maydell RECEIVING_BIT3, 2941742927SPeter Maydell RECEIVING_BIT2, 3041742927SPeter Maydell RECEIVING_BIT1, 3141742927SPeter Maydell RECEIVING_BIT0, 3241742927SPeter Maydell SENDING_ACK, 3341742927SPeter Maydell SENT_NACK 3441742927SPeter Maydell } bitbang_i2c_state; 3541742927SPeter Maydell 3641742927SPeter Maydell struct bitbang_i2c_interface { 3741742927SPeter Maydell I2CBus *bus; 3841742927SPeter Maydell bitbang_i2c_state state; 3941742927SPeter Maydell int last_data; 4041742927SPeter Maydell int last_clock; 4141742927SPeter Maydell int device_out; 4241742927SPeter Maydell uint8_t buffer; 4341742927SPeter Maydell int current_addr; 4441742927SPeter Maydell }; 4541742927SPeter Maydell 4641742927SPeter Maydell /** 4741742927SPeter Maydell * bitbang_i2c_init: in-place initialize the bitbang_i2c_interface struct 4841742927SPeter Maydell */ 4941742927SPeter Maydell void bitbang_i2c_init(bitbang_i2c_interface *s, I2CBus *bus); 50d718b747SBALATON Zoltan int bitbang_i2c_set(bitbang_i2c_interface *i2c, int line, int level); 51d718b747SBALATON Zoltan 52d718b747SBALATON Zoltan #endif 53