1 /*
2  * Copyright (c) 2020-2021, Bluetrum Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author            Notes
8  * 2021-01-07     greedyhao         first version
9  */
10 
11 #ifndef __DRV_I2C__
12 #define __DRV_I2C__
13 
14 #include <rtthread.h>
15 #include <rthw.h>
16 #include <rtdevice.h>
17 
18 /* ab32 config class */
19 struct ab32_soft_i2c_config
20 {
21     rt_uint8_t scl;
22     rt_uint8_t sda;
23     rt_uint8_t sda_mode;
24     rt_uint8_t scl_mode;
25     const char *bus_name;
26 };
27 
28 /* ab32 i2c dirver class */
29 struct ab32_i2c
30 {
31     struct rt_i2c_bit_ops ops;
32     struct rt_i2c_bus_device i2c_bus;
33 };
34 
35 #ifdef BSP_USING_I2C1
36 #define I2C1_BUS_CONFIG                                  \
37     {                                                    \
38         .scl = BSP_I2C1_SCL_PIN,                         \
39         .sda = BSP_I2C1_SDA_PIN,                         \
40         .bus_name = "i2c1",                              \
41     }
42 #endif
43 
44 #ifdef BSP_USING_I2C2
45 #define I2C2_BUS_CONFIG                                  \
46     {                                                    \
47         .scl = BSP_I2C2_SCL_PIN,                         \
48         .sda = BSP_I2C2_SDA_PIN,                         \
49         .bus_name = "i2c2",                              \
50     }
51 #endif
52 
53 #ifdef BSP_USING_I2C3
54 #define I2C3_BUS_CONFIG                                  \
55     {                                                    \
56         .scl = BSP_I2C3_SCL_PIN,                         \
57         .sda = BSP_I2C3_SDA_PIN,                         \
58         .bus_name = "i2c3",                              \
59     }
60 #endif
61 
62 #ifdef BSP_USING_I2C4
63 #define I2C4_BUS_CONFIG                                  \
64     {                                                    \
65         .scl = BSP_I2C4_SCL_PIN,                         \
66         .sda = BSP_I2C4_SDA_PIN,                         \
67         .bus_name = "i2c4",                              \
68     }
69 #endif
70 int rt_hw_i2c_init(void);
71 
72 #endif
73