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 }; 33 34 /** 35 * @brief Initialize an i2c_bitbang instance 36 * 37 * @param bitbang The instance to initialize 38 * @param io Functions to use for controlling I2C bus lines 39 * @param io_context Context pointer to pass to i/o functions when then are 40 * called. 41 */ 42 void i2c_bitbang_init(struct i2c_bitbang *bitbang, 43 const struct i2c_bitbang_io *io, void *io_context); 44 45 /** 46 * Implementation of the functionality required by the 'configure' function 47 * in struct i2c_driver_api. 48 */ 49 int i2c_bitbang_configure(struct i2c_bitbang *bitbang, uint32_t dev_config); 50 51 /** 52 * Implementation of the functionality required by the 'recover_bus' 53 * function in struct i2c_driver_api. 54 */ 55 int i2c_bitbang_recover_bus(struct i2c_bitbang *bitbang); 56 57 /** 58 * Implementation of the functionality required by the 'transfer' function 59 * in struct i2c_driver_api. 60 */ 61 int i2c_bitbang_transfer(struct i2c_bitbang *bitbang, 62 struct i2c_msg *msgs, uint8_t num_msgs, 63 uint16_t slave_address); 64