summaryrefslogtreecommitdiff
path: root/bsp/hc32/libraries/hc32_drivers/drv_i2c.h
blob: 402fe7ed254fe76932554db2b913f626d10fe7f7 (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
/*
 * 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_H__
#define __DRV_I2C_H__

#include <rtdevice.h>
#include "board_config.h"
#include "drv_irq.h"
#include "drv_dma.h"

#ifdef BSP_USING_I2C

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

/*******************************************************************************
 * Global type definitions ('typedef')
 ******************************************************************************/
struct hc32_i2c_config
{
    const char              *name;
    CM_I2C_TypeDef          *Instance;
    rt_uint32_t             clock;
    rt_uint32_t             baudrate;
    rt_uint32_t             timeout;
    struct dma_config       *i2c_tx_dma;
    struct dma_config       *i2c_rx_dma;
};

struct hc32_i2c
{
    struct hc32_i2c_config      *config;
    struct rt_i2c_bus_device    i2c_bus;
    rt_uint8_t                  i2c_dma_flag;
};

/*******************************************************************************
 * Global pre-processor symbols/macros ('#define')
 ******************************************************************************/
#define I2C_USING_TX_DMA_FLAG       (1U)
#define I2C_USING_RX_DMA_FLAG       (1U << 1)

#ifdef __cplusplus
}
#endif

#endif /* BSP_USING_I2C */

#endif /* __DRV_I2C_H__ */