1 /*
2  * Copyright (c) 2006-2022, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2022-10-19     Nations      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 #include "board.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /* n32 config class */
24 struct n32_soft_i2c_config
25 {
26     rt_uint8_t scl;
27     rt_uint8_t sda;
28     const char *bus_name;
29 };
30 
31 /* n32 i2c dirver class */
32 struct n32_i2c
33 {
34     struct rt_i2c_bit_ops ops;
35     struct rt_i2c_bus_device i2c_bus;
36 };
37 
38 #ifdef BSP_USING_I2C1
39 #define I2C1_BUS_CONFIG                                  \
40     {                                                    \
41         .scl = BSP_I2C1_SCL_PIN,                         \
42         .sda = BSP_I2C1_SDA_PIN,                         \
43         .bus_name = "i2c1",                              \
44     }
45 #endif
46 
47 #ifdef BSP_USING_I2C2
48 #define I2C2_BUS_CONFIG                                  \
49     {                                                    \
50         .scl = BSP_I2C2_SCL_PIN,                         \
51         .sda = BSP_I2C2_SDA_PIN,                         \
52         .bus_name = "i2c2",                              \
53     }
54 #endif
55 
56 #ifdef BSP_USING_I2C3
57 #define I2C3_BUS_CONFIG                                  \
58     {                                                    \
59         .scl = BSP_I2C3_SCL_PIN,                         \
60         .sda = BSP_I2C3_SDA_PIN,                         \
61         .bus_name = "i2c3",                              \
62     }
63 #endif
64 
65 #ifdef BSP_USING_I2C4
66 #define I2C4_BUS_CONFIG                                  \
67     {                                                    \
68         .scl = BSP_I2C4_SCL_PIN,                         \
69         .sda = BSP_I2C4_SDA_PIN,                         \
70         .bus_name = "i2c4",                              \
71     }
72 #endif
73 
74 struct rt_i2c_bus
75 {
76     struct rt_i2c_bus_device parent;
77     rt_uint32_t i2c_periph;
78 };
79 
80 int rt_hw_i2c_init(void);
81 
82 #ifdef __cplusplus
83 }
84 #endif
85 
86 #endif /* __DRV_I2C__ */
87