1 /*
2  * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /*******************************************************************************
8  * NOTICE
9  * The hal is not public api, don't use in application code.
10  * See readme.md in hal/include/hal/readme.md
11  ******************************************************************************/
12 
13 // The HAL layer for I2C
14 
15 #pragma once
16 
17 #include "hal/i2c_ll.h"
18 #include "hal/i2c_types.h"
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 /**
25  * @brief I2C hal Context definition
26  */
27 typedef struct {
28     i2c_dev_t *dev;
29 } i2c_hal_context_t;
30 
31 #if SOC_I2C_SUPPORT_SLAVE
32 
33 /**
34  * @brief  Init the I2C slave.
35  *
36  * @param  hal Context of the HAL layer
37  * @param  i2c_num I2C port number
38  *
39  * @return None
40  */
41 void i2c_hal_slave_init(i2c_hal_context_t *hal);
42 
43 #endif // SOC_I2C_SUPPORT_SLAVE
44 
45 /**
46  * @brief  Init the I2C master.
47  *
48  * @param  hal Context of the HAL layer
49  * @param  i2c_num I2C port number
50  *
51  * @return None
52  */
53 void i2c_hal_master_init(i2c_hal_context_t *hal);
54 
55 /**
56  * @brief  Set I2C bus timing with the given frequency
57  *
58  * @param  hal Context of the HAL layer
59  * @param  scl_freq The scl frequency to be set
60  * @param  src_clk The source clock of I2C
61  * @param  source_freq Source clock frequency of I2C
62  *
63  * @return None
64  */
65 void i2c_hal_set_bus_timing(i2c_hal_context_t *hal, int scl_freq, i2c_clock_source_t src_clk, int source_freq);
66 
67 /**
68  * @brief  I2C hardware FSM reset
69  *
70  * @param  hal Context of the HAL layer
71  *
72  * @return None
73  */
74 void i2c_hal_master_fsm_rst(i2c_hal_context_t *hal);
75 
76 /**
77  * @brief  I2C master handle tx interrupt event
78  *
79  * @param  hal Context of the HAL layer
80  * @param  event Pointer to accept the interrupt event
81  *
82  * @return None
83  */
84 void i2c_hal_master_handle_tx_event(i2c_hal_context_t *hal, i2c_intr_event_t *event);
85 
86 /**
87  * @brief  I2C master handle rx interrupt event
88  *
89  * @param  hal Context of the HAL layer
90  * @param  event Pointer to accept the interrupt event
91  *
92  * @return None
93  */
94 void i2c_hal_master_handle_rx_event(i2c_hal_context_t *hal, i2c_intr_event_t *event);
95 
96 /**
97  * @brief Init I2C hal layer
98  *
99  * @param hal Context of the HAL
100  * @param i2c_port I2C port number.
101  */
102 void i2c_hal_init(i2c_hal_context_t *hal, int i2c_port);
103 
104 /**
105  * @brief Deinit I2C hal layer
106  *
107  * @param hal Context of the HAL
108  */
109 void i2c_hal_deinit(i2c_hal_context_t *hal);
110 
111 /**
112  * @brief Start I2C master transaction
113  *
114  * @param hal Context of the HAL
115  */
116 void i2c_hal_master_trans_start(i2c_hal_context_t *hal);
117 
118 /**
119  * @brief Get timing configuration
120  *
121  * @param hal Context of the HAL
122  * @param timing_config Pointer to timing config structure.
123  */
124 void i2c_hal_get_timing_config(i2c_hal_context_t *hal, i2c_hal_timing_config_t *timing_config);
125 
126 /**
127  * @brief Set timing configuration
128  *
129  * @param hal Context of the HAL
130  * @param timing_config Timing config structure.
131  */
132 void i2c_hal_set_timing_config(i2c_hal_context_t *hal, i2c_hal_timing_config_t *timing_config);
133 
134 #ifdef __cplusplus
135 }
136 #endif
137