summaryrefslogtreecommitdiff
path: root/bsp/hc32/libraries/hc32_drivers/drv_soft_i2c.h
blob: a16b9d0d37fca07ed602272da88fd52d1cfed12a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 * Copyright (C) 2022-2024, Xiaohua Semiconductor Co., Ltd.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-04-28     CDT          first version
 */

#ifndef __DRV_I2C_SOFT_H__
#define __DRV_I2C_SOFT_H__

/*******************************************************************************
 * Include files
 ******************************************************************************/
#include <rtdevice.h>

/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif

/*******************************************************************************
 * Global type definitions ('typedef')
 ******************************************************************************/
struct hc32_soft_i2c_config
{
    rt_uint16_t scl_pin;
    rt_uint16_t sda_pin;
    const char  *bus_name;
};

struct hc32_soft_i2c
{
    struct rt_i2c_bit_ops    ops;
    struct rt_i2c_bus_device i2c_bus;
};

#ifdef BSP_USING_I2C1_SW
#define I2C1_BUS_CONFIG                                     \
    {                                                       \
        .scl_pin  = BSP_I2C1_SCL_PIN,                       \
        .sda_pin  = BSP_I2C1_SDA_PIN,                       \
        .bus_name = "i2c1_sw",                              \
    }
#endif

#ifdef BSP_USING_I2C2_SW
#define I2C2_BUS_CONFIG                                     \
    {                                                       \
        .scl_pin = BSP_I2C2_SCL_PIN,                        \
        .sda_pin = BSP_I2C2_SDA_PIN,                        \
        .bus_name = "i2c2_sw",                              \
    }
#endif

#ifdef BSP_USING_I2C3_SW
#define I2C3_BUS_CONFIG                                     \
    {                                                       \
        .scl_pin = BSP_I2C3_SCL_PIN,                        \
        .sda_pin = BSP_I2C3_SDA_PIN,                        \
        .bus_name = "i2c3_sw",                              \
    }
#endif

#ifdef BSP_USING_I2C4_SW
#define I2C4_BUS_CONFIG                                     \
    {                                                       \
        .scl_pin = BSP_I2C4_SCL_PIN,                        \
        .sda_pin = BSP_I2C4_SDA_PIN,                        \
        .bus_name = "i2c4_sw",                              \
    }
#endif

#ifdef BSP_USING_I2C5_SW
#define I2C5_BUS_CONFIG                                     \
    {                                                       \
        .scl_pin = BSP_I2C5_SCL_PIN,                        \
        .sda_pin = BSP_I2C5_SDA_PIN,                        \
        .bus_name = "i2c5_sw",                              \
    }
#endif

#ifdef BSP_USING_I2C6_SW
#define I2C6_BUS_CONFIG                                     \
    {                                                       \
        .scl_pin = BSP_I2C6_SCL_PIN,                        \
        .sda_pin = BSP_I2C6_SDA_PIN,                        \
        .bus_name = "i2c6_sw",                              \
    }
#endif

#ifdef __cplusplus
}
#endif

#endif /* __DRV_SOFT_I2C_H__ */

/*******************************************************************************
 * EOF (not truncated)
 ******************************************************************************/