1 /*
2  * Copyright (c) 2017 Linaro Ltd.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @brief Functions for setting and getting the state of the I2C lines.
9  *
10  * These need to be implemented by the user of this library.
11  */
12 struct i2c_bitbang_io {
13 	/* Set the state of the SCL line (zero/non-zero value) */
14 	void (*set_scl)(void *io_context, int state);
15 	/* Set the state of the SDA line (zero/non-zero value) */
16 	void (*set_sda)(void *io_context, int state);
17 	/* Return the state of the SDA line (zero/non-zero value) */
18 	int (*get_sda)(void *io_context);
19 };
20 
21 /**
22  * @brief Instance data for i2c_bitbang
23  *
24  * A driver or other code wishing to use the i2c_bitbang library should
25  * create one of these structures then use it via the library APIs.
26  * Structure members are private, and shouldn't be accessed directly.
27  */
28 struct i2c_bitbang {
29 	const struct i2c_bitbang_io	*io;
30 	void				*io_context;
31 	uint32_t			delays[2];
32 	uint32_t			dev_config;
33 };
34 
35 /**
36  * @brief Initialize an i2c_bitbang instance
37  *
38  * @param bitbang	The instance to initialize
39  * @param io		Functions to use for controlling I2C bus lines
40  * @param io_context	Context pointer to pass to i/o functions when then are
41  *			called.
42  */
43 void i2c_bitbang_init(struct i2c_bitbang *bitbang,
44 			const struct i2c_bitbang_io *io, void *io_context);
45 
46 /**
47  * Implementation of the functionality required by the 'configure' function
48  * in struct i2c_driver_api.
49  */
50 int i2c_bitbang_configure(struct i2c_bitbang *bitbang, uint32_t dev_config);
51 
52 /**
53  * Implementation of the functionality required by the 'get_config' function
54  * in struct i2c_driver_api.
55  */
56 int i2c_bitbang_get_config(struct i2c_bitbang *context, uint32_t *config);
57 
58 /**
59  * Implementation of the functionality required by the 'recover_bus'
60  * function in struct i2c_driver_api.
61  */
62 int i2c_bitbang_recover_bus(struct i2c_bitbang *bitbang);
63 
64 /**
65  * Implementation of the functionality required by the 'transfer' function
66  * in struct i2c_driver_api.
67  */
68 int i2c_bitbang_transfer(struct i2c_bitbang *bitbang,
69 			   struct i2c_msg *msgs, uint8_t num_msgs,
70 			   uint16_t slave_address);
71