Lines Matching +full:i2c +full:- +full:errors

4  * SPDX-License-Identifier: Apache-2.0
13 #include <zephyr/drivers/i2c.h>
22 #include <driverlib/i2c.h>
29 #include "i2c-priv.h"
44 (((const struct i2c_cc32xx_config *const)(dev)->config)->base)
53 * I2C API without having to re-read I2C registers.
56 /* I2C was primed for a write operation */
58 /* I2C was primed for a read operation */
60 /* I2C error occurred */
91 return -EINVAL; in i2c_cc32xx_configure()
95 return -EINVAL; in i2c_cc32xx_configure()
106 return -EINVAL; in i2c_cc32xx_configure()
118 struct i2c_cc32xx_data *data = dev->data; in i2c_cc32xx_prime_transfer()
122 data->msg = *msg; in i2c_cc32xx_prime_transfer()
123 data->slave_addr = addr; in i2c_cc32xx_prime_transfer()
126 if (IS_I2C_MSG_WRITE(data->msg.flags)) { in i2c_cc32xx_prime_transfer()
128 /* Specify the I2C slave address */ in i2c_cc32xx_prime_transfer()
131 /* Update the I2C state */ in i2c_cc32xx_prime_transfer()
132 data->state = I2C_CC32XX_WRITE_MODE; in i2c_cc32xx_prime_transfer()
135 MAP_I2CMasterDataPut(base, *((data->msg.buf)++)); in i2c_cc32xx_prime_transfer()
137 /* Start the I2C transfer in master transmit mode */ in i2c_cc32xx_prime_transfer()
142 /* Specify the I2C slave address */ in i2c_cc32xx_prime_transfer()
145 /* Update the I2C mode */ in i2c_cc32xx_prime_transfer()
146 data->state = I2C_CC32XX_READ_MODE; in i2c_cc32xx_prime_transfer()
148 if (data->msg.len < 2) { in i2c_cc32xx_prime_transfer()
149 /* Start the I2C transfer in master receive mode */ in i2c_cc32xx_prime_transfer()
153 /* Start the I2C transfer in burst receive mode */ in i2c_cc32xx_prime_transfer()
163 struct i2c_cc32xx_data *data = dev->data; in i2c_cc32xx_transfer()
167 k_sem_take(&data->mutex, K_FOREVER); in i2c_cc32xx_transfer()
176 k_sem_take(&data->transfer_complete, K_FOREVER); in i2c_cc32xx_transfer()
179 if (data->state == I2C_CC32XX_ERROR) { in i2c_cc32xx_transfer()
180 retval = -EIO; in i2c_cc32xx_transfer()
189 k_sem_give(&data->mutex); in i2c_cc32xx_transfer()
198 data->msg.len--; in i2c_cc32xx_isr_handle_write()
201 if (data->msg.len) { in i2c_cc32xx_isr_handle_write()
204 MAP_I2CMasterDataPut(base, *(data->msg.buf)); in i2c_cc32xx_isr_handle_write()
205 data->msg.buf++; in i2c_cc32xx_isr_handle_write()
207 if (data->msg.len < 2) { in i2c_cc32xx_isr_handle_write()
236 *(data->msg.buf) = MAP_I2CMasterDataGet(base); in i2c_cc32xx_isr_handle_read()
237 data->msg.buf++; in i2c_cc32xx_isr_handle_read()
240 data->msg.len--; in i2c_cc32xx_isr_handle_read()
241 if (data->msg.len) { in i2c_cc32xx_isr_handle_read()
242 if (data->msg.len > 1) { in i2c_cc32xx_isr_handle_read()
266 struct i2c_cc32xx_data *data = dev->data; in i2c_cc32xx_isr()
270 /* Get the error status of the I2C controller */ in i2c_cc32xx_isr()
280 data->state, err_status, int_status); in i2c_cc32xx_isr()
282 /* Handle errors: */ in i2c_cc32xx_isr()
288 data->state = I2C_CC32XX_ERROR; in i2c_cc32xx_isr()
292 /* Send a STOP bit to end I2C communications */ in i2c_cc32xx_isr()
294 * I2C_MASTER_CMD_BURST_SEND_ERROR_STOP -and- in i2c_cc32xx_isr()
302 k_sem_give(&data->transfer_complete); in i2c_cc32xx_isr()
307 k_sem_give(&data->transfer_complete); in i2c_cc32xx_isr()
311 if (data->state == I2C_CC32XX_WRITE_MODE) { in i2c_cc32xx_isr()
314 if (data->state == I2C_CC32XX_READ_MODE) { in i2c_cc32xx_isr()
319 __ASSERT(1, "Unanticipated I2C Interrupt!"); in i2c_cc32xx_isr()
320 data->state = I2C_CC32XX_ERROR; in i2c_cc32xx_isr()
321 k_sem_give(&data->transfer_complete); in i2c_cc32xx_isr()
328 const struct i2c_cc32xx_config *config = dev->config; in i2c_cc32xx_init()
329 struct i2c_cc32xx_data *data = dev->data; in i2c_cc32xx_init()
334 /* Enable the I2C module clocks and wait for completion:*/ in i2c_cc32xx_init()
341 error = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); in i2c_cc32xx_init()
346 k_sem_init(&data->mutex, 1, K_SEM_MAX_LIMIT); in i2c_cc32xx_init()
347 k_sem_init(&data->transfer_complete, 0, K_SEM_MAX_LIMIT); in i2c_cc32xx_init()
349 /* In case of app restart: disable I2C module, clear NVIC interrupt */ in i2c_cc32xx_init()
354 MAP_IntPendClear((unsigned long)(config->irq_no + 16)); in i2c_cc32xx_init()
358 /* Take I2C hardware semaphore. */ in i2c_cc32xx_init()
364 bitrate_cfg = i2c_map_dt_bitrate(config->bitrate); in i2c_cc32xx_init()
373 /* Enable the I2C Master for operation */ in i2c_cc32xx_init()
376 /* Unmask I2C interrupts */ in i2c_cc32xx_init()
382 static DEVICE_API(i2c, i2c_cc32xx_driver_api) = {
412 irq_enable(config->irq_no); in configure_i2c_irq()