1 /*
2  * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include "hal/i2c_hal.h"
8 
9 
10 //////////////////////////////////////////Deprecated Functions//////////////////////////////////////////////////////////
11 /////////////////////////////The following functions are only used by the legacy driver/////////////////////////////////
12 /////////////////////////////They might be removed in the next major release (ESP-IDF 6.0)//////////////////////////////
13 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
14 
i2c_hal_master_handle_tx_event(i2c_hal_context_t * hal,i2c_intr_event_t * event)15 void i2c_hal_master_handle_tx_event(i2c_hal_context_t *hal, i2c_intr_event_t *event)
16 {
17     uint32_t intr_status = 0;
18     i2c_ll_get_intr_mask(hal->dev, &intr_status);
19     if (intr_status != 0) {
20         // If intr status is 0, no need to handle it.
21         i2c_ll_master_get_event(hal->dev, event);
22         if ((*event < I2C_INTR_EVENT_END_DET) ||
23             (*event == I2C_INTR_EVENT_TRANS_DONE)) {
24             i2c_ll_master_disable_tx_it(hal->dev);
25             i2c_ll_clear_intr_mask(hal->dev, intr_status);
26         } else if (*event == I2C_INTR_EVENT_END_DET) {
27             i2c_ll_clear_intr_mask(hal->dev, intr_status);
28         }
29     }
30 }
31 
i2c_hal_master_handle_rx_event(i2c_hal_context_t * hal,i2c_intr_event_t * event)32 void i2c_hal_master_handle_rx_event(i2c_hal_context_t *hal, i2c_intr_event_t *event)
33 {
34     uint32_t intr_status = 0;
35     i2c_ll_get_intr_mask(hal->dev, &intr_status);
36     if (intr_status != 0) {
37         i2c_ll_master_get_event(hal->dev, event);
38         if ((*event < I2C_INTR_EVENT_END_DET) ||
39             (*event == I2C_INTR_EVENT_TRANS_DONE)) {
40             i2c_ll_master_disable_rx_it(hal->dev);
41             i2c_ll_clear_intr_mask(hal->dev, intr_status);
42         } else if (*event == I2C_INTR_EVENT_END_DET) {
43             i2c_ll_clear_intr_mask(hal->dev, intr_status);
44         }
45     }
46 }
47