• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
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  * Description: Provides V150 HAL i2c \n
16  *
17  * History: \n
18  * 2023-03-06, Create file. \n
19  */
20 
21 #ifndef HAL_I2C_V150_COMM_H
22 #define HAL_I2C_V150_COMM_H
23 
24 #include <stdint.h>
25 #include "common_def.h"
26 #include "soc_osal.h"
27 #include "hal_i2c.h"
28 #include "hal_i2c_v150_regs_op.h"
29 
30 #ifdef __cplusplus
31 #if __cplusplus
32 extern "C" {
33 #endif /* __cplusplus */
34 #endif /* __cplusplus */
35 
36 /**
37  * @defgroup drivers_hal_i2c_v150_comm I2C_V150 Common
38  * @ingroup  drivers_hal_i2c
39  * @{
40  */
41 
42 #define I2C_TRUE 1
43 #define I2C_FALSE 0
44 
45 #define I2C_V150_DEFAULT_WRITE_NUM 0xFFFFFFFF
46 #define I2C_V150_DEFAULT_READ_NUM 0xFFFFFFFF
47 
48 #define I2C_CFG_SCL_H_DEFAULT_VAL 1
49 #define I2C_CFG_SCL_L_DEFAULT_VAL 1
50 
51 /**
52  * @if Eng
53  * @brief  Definition of I2C trans mode.
54  * @else
55  * @brief  I2C读写模式定义
56  * @endif
57  */
58 typedef enum hal_i2c_trans_mode {
59     I2C_TRANS_MODE_INVALID = 0,
60     I2C_TRANS_MODE_WRITE = 1,
61     I2C_TRANS_MODE_READ = 2,
62     I2C_TRANS_MODE_WRITE_BEFORE_READ = 3,
63     I2C_TRANS_MODE_STOP_AFTER_WRITE = 4,
64     I2C_TRANS_TYPE_MAX_NUM
65 } hal_i2c_trans_mode_t;
66 
67 /**
68  * @if Eng
69  * @brief  Definition of I2C work type.
70  * @else
71  * @brief  I2C工作模式定义
72  * @endif
73  */
74 typedef enum hal_i2c_work_type {
75     I2C_WORK_TYPE_POLL_NOFIFO = 0,
76     I2C_WORK_TYPE_POLL_FIFO = 1,
77     I2C_WORK_TYPE_INT_NOFIFO = 2,
78     I2C_WORK_TYPE_INT_FIFO = 3,
79     I2C_WORK_TYPE_MAX_NUM
80 } hal_i2c_work_type_t;
81 
82 /**
83  * @if Eng
84  * @brief  Definition of I2C addr width.
85  * @else
86  * @brief  I2C地址位宽定义
87  * @endif
88  */
89 typedef enum hal_i2c_addr_width {
90     I2C_7_BITS_ADDR,                /*!< @if Eng I2C start transfers in 7-bit addressing mode.
91                                          @else   I2C以7位寻址模式开始传输。 @endif */
92     I2C_10_BITS_ADDR,               /*!< @if Eng I2C start transfers in 10-bit addressing mode.
93                                          @else   I2C以10位寻址模式开始传输。 @endif */
94     I2C_INVALID_BITS_ADDR
95 } hal_i2c_addr_width_t;
96 
97 /**
98  * @if Eng
99  * @brief  Definition of hal I2C transport information.
100  * @else
101  * @brief  HAL层I2C的传输信息数据结构定义
102  * @endif
103  */
104 typedef struct hal_i2c_trans_info {
105     uint8_t trans_mode;
106     uint32_t trans_cnt;
107     uint32_t total_len;
108 } hal_i2c_trans_info_t;
109 
110 /**
111  * @if Eng
112  * @brief  Definition of hal I2C ctrl information.
113  * @else
114  * @brief  HAL层I2C的控制信息数据结构定义
115  * @endif
116  */
117 typedef struct hal_i2c_ctrl_info {
118     uint8_t init;
119     uint8_t cfg_scl_h;
120     uint8_t cfg_scl_l;
121     uint8_t work_type;
122     uint32_t timeout_us;
123     uint32_t baudrate;
124     uint8_t *ext;
125 } hal_i2c_ctrl_info_t;
126 
127 /**
128  * @if Eng
129  * @brief  Control interface for hal I2C.
130  * @param  [in]  bus The I2C bus. see @ref i2c_bus_t
131  * @param  [in]  param Parameter pointer for callback.
132  * @retval ERRCODE_SUCC Success.
133  * @retval Other        Failure. For details, see @ref errcode_t
134  * @else
135  * @brief  HAL层I2C控制接口。
136  * @param  [in]  bus I2C索引。参考 @ref i2c_bus_t
137  * @param  [in]  param 传递给控制回调的参数指针。
138  * @retval ERRCODE_SUCC 成功。
139  * @retval Other        失败。参考 @ref errcode_t
140  * @endif
141  */
142 typedef errcode_t (*hal_i2c_inner_ctrl_t)(i2c_bus_t bus, uintptr_t param);
143 
144 hal_i2c_ctrl_info_t *hal_i2c_v150_get_ctrl_info(i2c_bus_t bus);
145 void hal_i2c_v150_load_ctrl_func(i2c_bus_t bus, hal_i2c_inner_ctrl_t *func_table);
146 void hal_i2c_v150_unload_ctrl_func(i2c_bus_t bus);
147 void hal_i2c_v150_register_callback(hal_i2c_callback_t callback);
148 hal_i2c_trans_info_t *hal_i2c_v150_get_trans_info(i2c_bus_t bus);
149 errcode_t hal_i2c_v150_ctrl_check_default(i2c_bus_t bus, uintptr_t param);
150 errcode_t hal_i2c_v150_ctrl_check_default_false(i2c_bus_t bus, uintptr_t param);
151 errcode_t hal_i2c_v150_ctrl_proc_default(i2c_bus_t bus, uintptr_t param);
152 errcode_t hal_i2c_v150_get_write_num(i2c_bus_t bus, uintptr_t param);
153 errcode_t hal_i2c_v150_get_read_num(i2c_bus_t bus, uintptr_t param);
154 errcode_t hal_i2c_v150_send_byte(i2c_bus_t bus, uint8_t data, uint8_t should_start);
155 errcode_t hal_i2c_v150_receive_byte(i2c_bus_t bus, uint8_t *data, uint32_t remain_len);
156 errcode_t hal_i2c_v150_write(i2c_bus_t bus, hal_i2c_buffer_wrap_t *data);
157 errcode_t hal_i2c_v150_read(i2c_bus_t bus, hal_i2c_buffer_wrap_t *data);
158 errcode_t hal_i2c_v150_deinit(i2c_bus_t bus);
159 void hal_i2c_v150_cfg_clk(i2c_bus_t bus, uint32_t baudrate, uint8_t scl_h, uint8_t scl_l);
160 void hal_i2c_v150_init_comp_param(i2c_bus_t bus);
161 errcode_t hal_i2c_v150_ctrl(i2c_bus_t bus, hal_i2c_ctrl_id_t id, uintptr_t param);
162 void hal_i2c_v150_irq_handler(i2c_bus_t bus);
163 
164 /**
165  * @}
166  */
167 
168 #ifdef __cplusplus
169 #if __cplusplus
170 }
171 #endif /* __cplusplus */
172 #endif /* __cplusplus */
173 
174 #endif
175 
176