Lines Matching +full:bit +full:- +full:banging
4 * SPDX-License-Identifier: Apache-2.0
9 * @brief Software driven 'bit-banging' library for I2C
13 * the Standard-mode and Fast-mode speeds and doesn't support optional
14 * protocol feature like 10-bit addresses or clock stretching.
17 * https://www.nxp.com/docs/en/user-guide/UM10204.pdf
46 return -ENOTSUP; in i2c_bitbang_configure()
52 context->delays[T_LOW] = NS_TO_SYS_CLOCK_HW_CYCLES(4700); in i2c_bitbang_configure()
53 context->delays[T_HIGH] = NS_TO_SYS_CLOCK_HW_CYCLES(4000); in i2c_bitbang_configure()
56 context->delays[T_LOW] = NS_TO_SYS_CLOCK_HW_CYCLES(1300); in i2c_bitbang_configure()
57 context->delays[T_HIGH] = NS_TO_SYS_CLOCK_HW_CYCLES(600); in i2c_bitbang_configure()
60 return -ENOTSUP; in i2c_bitbang_configure()
63 context->dev_config = dev_config; in i2c_bitbang_configure()
70 if (context->dev_config == 0) { in i2c_bitbang_get_config()
71 return -EIO; in i2c_bitbang_get_config()
74 *config = context->dev_config; in i2c_bitbang_get_config()
81 context->io->set_scl(context->io_context, state); in i2c_set_scl()
86 context->io->set_sda(context->io_context, state); in i2c_set_sda()
91 return context->io->get_sda(context->io_context); in i2c_get_sda()
99 while (k_cycle_get_32() - start < cycles_to_wait) { in i2c_delay()
111 i2c_delay(context->delays[T_LOW]); in i2c_start()
113 i2c_delay(context->delays[T_SU_STA]); in i2c_start()
116 i2c_delay(context->delays[T_HD_STA]); in i2c_start()
119 i2c_delay(context->delays[T_LOW]); in i2c_start()
126 i2c_delay(context->delays[T_HIGH]); in i2c_repeated_start()
128 i2c_delay(context->delays[T_SU_STA]); in i2c_repeated_start()
135 i2c_delay(context->delays[T_LOW]); in i2c_stop()
138 i2c_delay(context->delays[T_HIGH]); in i2c_stop()
140 i2c_delay(context->delays[T_SU_STP]); in i2c_stop()
142 i2c_delay(context->delays[T_BUF]); /* In case we start again too soon */ in i2c_stop()
145 static void i2c_write_bit(struct i2c_bitbang *context, int bit) in i2c_write_bit() argument
148 i2c_set_sda(context, bit); in i2c_write_bit()
150 i2c_delay(context->delays[T_HIGH]); in i2c_write_bit()
152 i2c_delay(context->delays[T_LOW]); in i2c_write_bit()
157 bool bit; in i2c_read_bit() local
163 i2c_delay(context->delays[T_HIGH]); in i2c_read_bit()
165 bit = i2c_get_sda(context); in i2c_read_bit()
168 i2c_delay(context->delays[T_LOW]); in i2c_read_bit()
169 return bit; in i2c_read_bit()
180 /* Return inverted ACK bit, i.e. 'true' for ACK, 'false' for NACK */ in i2c_write_byte()
202 int result = -EIO; in i2c_bitbang_transfer()
227 } else if (msgs->flags & I2C_MSG_RESTART) { in i2c_bitbang_transfer()
232 flags |= msgs->flags; in i2c_bitbang_transfer()
246 buf = msgs->buf; in i2c_bitbang_transfer()
247 buf_end = buf + msgs->len; in i2c_bitbang_transfer()
266 num_msgs--; in i2c_bitbang_transfer()
282 * The I2C-bus specification and user manual (NXP UM10204 in i2c_bitbang_recover_bus()
313 return -EBUSY; in i2c_bitbang_recover_bus()
320 context->io = io; in i2c_bitbang_init()
321 context->io_context = io_context; in i2c_bitbang_init()