| 
									
										
										
										
											2009-11-20 23:37:15 +00:00
										 |  |  | #ifndef BITBANG_I2C_H
 | 
					
						
							|  |  |  | #define BITBANG_I2C_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-05 17:06:20 +01:00
										 |  |  | #include "hw/i2c/i2c.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-20 23:37:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-11 09:50:12 +01:00
										 |  |  | #define TYPE_GPIO_I2C "gpio_i2c"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-20 12:55:23 +02:00
										 |  |  | typedef struct bitbang_i2c_interface bitbang_i2c_interface; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 23:37:15 +00:00
										 |  |  | #define BITBANG_I2C_SDA 0
 | 
					
						
							|  |  |  | #define BITBANG_I2C_SCL 1
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-02 17:38:44 +01:00
										 |  |  | typedef enum bitbang_i2c_state { | 
					
						
							|  |  |  |     STOPPED = 0, | 
					
						
							|  |  |  |     SENDING_BIT7, | 
					
						
							|  |  |  |     SENDING_BIT6, | 
					
						
							|  |  |  |     SENDING_BIT5, | 
					
						
							|  |  |  |     SENDING_BIT4, | 
					
						
							|  |  |  |     SENDING_BIT3, | 
					
						
							|  |  |  |     SENDING_BIT2, | 
					
						
							|  |  |  |     SENDING_BIT1, | 
					
						
							|  |  |  |     SENDING_BIT0, | 
					
						
							|  |  |  |     WAITING_FOR_ACK, | 
					
						
							|  |  |  |     RECEIVING_BIT7, | 
					
						
							|  |  |  |     RECEIVING_BIT6, | 
					
						
							|  |  |  |     RECEIVING_BIT5, | 
					
						
							|  |  |  |     RECEIVING_BIT4, | 
					
						
							|  |  |  |     RECEIVING_BIT3, | 
					
						
							|  |  |  |     RECEIVING_BIT2, | 
					
						
							|  |  |  |     RECEIVING_BIT1, | 
					
						
							|  |  |  |     RECEIVING_BIT0, | 
					
						
							|  |  |  |     SENDING_ACK, | 
					
						
							|  |  |  |     SENT_NACK | 
					
						
							|  |  |  | } bitbang_i2c_state; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct bitbang_i2c_interface { | 
					
						
							|  |  |  |     I2CBus *bus; | 
					
						
							|  |  |  |     bitbang_i2c_state state; | 
					
						
							|  |  |  |     int last_data; | 
					
						
							|  |  |  |     int last_clock; | 
					
						
							|  |  |  |     int device_out; | 
					
						
							|  |  |  |     uint8_t buffer; | 
					
						
							|  |  |  |     int current_addr; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * bitbang_i2c_init: in-place initialize the bitbang_i2c_interface struct | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void bitbang_i2c_init(bitbang_i2c_interface *s, I2CBus *bus); | 
					
						
							| 
									
										
										
										
											2009-11-20 23:37:15 +00:00
										 |  |  | int bitbang_i2c_set(bitbang_i2c_interface *i2c, int line, int level); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 |