1 // Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "hal/i2c_hal.h"
16 
i2c_hal_master_handle_tx_event(i2c_hal_context_t * hal,i2c_intr_event_t * event)17 void i2c_hal_master_handle_tx_event(i2c_hal_context_t *hal, i2c_intr_event_t *event)
18 {
19     if (i2c_ll_get_intsts_mask(hal->dev) != 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_master_clr_tx_it(hal->dev);
26         } else if (*event == I2C_INTR_EVENT_END_DET) {
27             i2c_ll_master_clr_tx_it(hal->dev);
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     if (i2c_ll_get_intsts_mask(hal->dev) != 0) {
35         i2c_ll_master_get_event(hal->dev, event);
36         if ((*event < I2C_INTR_EVENT_END_DET) ||
37             (*event == I2C_INTR_EVENT_TRANS_DONE)) {
38             i2c_ll_master_disable_rx_it(hal->dev);
39             i2c_ll_master_clr_rx_it(hal->dev);
40         } else if (*event == I2C_INTR_EVENT_END_DET) {
41             i2c_ll_master_clr_rx_it(hal->dev);
42         }
43     }
44 }
45 
i2c_hal_slave_handle_event(i2c_hal_context_t * hal,i2c_intr_event_t * event)46 void i2c_hal_slave_handle_event(i2c_hal_context_t *hal, i2c_intr_event_t *event)
47 {
48     i2c_ll_slave_get_event(hal->dev, event);
49 }
50