summaryrefslogtreecommitdiff
path: root/bsp/hc32f4a0/drivers/drv_soft_i2c.h
blob: 64dec1184b43187d0d7f1647e36cf802ca983204 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * Copyright (C) 2020, Huada Semiconductor Co., Ltd.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020-10-30     CDT          first version
 */
 

#ifndef __DRV_I2C_H__
#define __DRV_I2C_H__

/*******************************************************************************
 * Include files
 ******************************************************************************/
#include <rtdevice.h>
#include "hc32_ddl.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;
};

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

#ifdef BSP_USING_I2C2
#define I2C2_BUS_CONFIG                                  \
    {                                                    \
        .scl = BSP_I2C2_SCL_PIN,                         \
        .sda = BSP_I2C2_SDA_PIN,                         \
        .bus_name = "i2c2",                              \
    }
#endif
    
#ifdef BSP_USING_I2C3
#define I2C3_BUS_CONFIG                                  \
    {                                                    \
        .scl = BSP_I2C3_SCL_PIN,                         \
        .sda = BSP_I2C3_SDA_PIN,                         \
        .bus_name = "i2c3",                              \
    }
#endif
		
#ifdef BSP_USING_I2C4
#define I2C4_BUS_CONFIG                                  \
    {                                                    \
        .scl = BSP_I2C4_SCL_PIN,                         \
        .sda = BSP_I2C4_SDA_PIN,                         \
        .bus_name = "i2c4",                              \
    }
#endif

#ifdef BSP_USING_I2C5
#define I2C5_BUS_CONFIG                                  \
    {                                                    \
        .scl = BSP_I2C5_SCL_PIN,                         \
        .sda = BSP_I2C5_SDA_PIN,                         \
        .bus_name = "i2c5",                              \
    }
#endif
		
#ifdef BSP_USING_I2C6
#define I2C6_BUS_CONFIG                                  \
    {                                                    \
        .scl = BSP_I2C6_SCL_PIN,                         \
        .sda = BSP_I2C6_SDA_PIN,                         \
        .bus_name = "i2c6",                              \
    }
#endif

/**
 *******************************************************************************
 ** \brief Open parameters.
 *******************************************************************************
 */
struct hc32_i2c_config
{
    rt_uint8_t scl;
    rt_uint8_t sda;
    const char *bus_name;
};

struct hc32_i2c
{
    struct rt_i2c_bit_ops ops;
    struct rt_i2c_bus_device i2c1_bus;
};


typedef struct hc32_i2c_instance
{
    rt_uint32_t id;
    void *handle;
    stc_i2c_init_t init;
} hc32_i2c_instance_t;


int hc32_hw_i2c_init(void);

#ifdef __cplusplus
}
#endif

#endif /* __DRV_I2C_H__ */

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