• 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 i2c port template \n
16  *
17  * History: \n
18  * 2022-08-15, Create file. \n
19  */
20 #ifndef I2C_PORTING_H
21 #define I2C_PORTING_H
22 
23 #include <stdint.h>
24 #include <stdbool.h>
25 #include "platform_core.h"
26 
27 #ifdef __cplusplus
28 #if __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31 #endif /* __cplusplus */
32 
33 #define I2C_BUS_MAX_NUM I2C_BUS_MAX_NUMBER
34 
35 #define I2C_0_SCL_PIN_CTRL_REG 0x4400D048
36 #define I2C_0_SDA_PIN_CTRL_REG 0x4400D044
37 #define I2C_1_SCL_PIN_CTRL_REG 0x4400D040
38 #define I2C_1_SDA_PIN_CTRL_REG 0x4400D03C
39 #define PIN_CTRL_MODE_2 0x2
40 
41 /**
42  * @brief  Get the base address of a specified I2C.
43  * @param  [in]  bus The bus index of I2C.
44  * @return The base address of specified I2C.
45  */
46 uintptr_t i2c_porting_base_addr_get(i2c_bus_t bus);
47 
48 /**
49  * @brief  Set the bus clock of specified i2c.
50  * @param  [in]  bus The I2C bus. see @ref i2c_bus_t
51  * @param  [in]  clock The bus clock of specified I2C.
52  */
53 void i2c_port_set_clock_value(i2c_bus_t bus, uint32_t clock);
54 
55 /**
56  * @brief  Get the bus clock of specified i2c.
57  * @param  [in]  bus The I2C bus. see @ref i2c_bus_t
58  * @return The bus clock of specified I2C.
59  */
60 uint32_t i2c_port_get_clock_value(i2c_bus_t bus);
61 
62 /**
63  * @brief  Register the interrupt of I2C.
64  */
65 void i2c_port_register_irq(i2c_bus_t bus);
66 
67 /**
68  * @brief  Unregister the interrupt of I2C.
69  */
70 void i2c_port_unregister_irq(i2c_bus_t bus);
71 
72 /**
73  * @brief  I2C lock.
74  * @param [in]  bus The bus index of I2C.
75  * @return The irq lock number of I2C.
76  */
77 uint32_t i2c_porting_lock(i2c_bus_t bus);
78 
79 /**
80  * @brief  I2C unlock.
81  * @param [in]  bus The bus index of I2C.
82  * @param [in]  irq_sts The irq lock number of I2C.
83  */
84 void i2c_porting_unlock(i2c_bus_t bus, uint32_t irq_sts);
85 
86 #ifdef TEST_SUITE
87 /**
88  * @brief  Init i2c pin for test.
89  */
90 void i2c_port_test_i2c_init_pin(void);
91 #endif
92 
93 #ifdef __cplusplus
94 #if __cplusplus
95 }
96 #endif /* __cplusplus */
97 #endif /* __cplusplus */
98 
99 #endif
100