VSF Documented
i2c.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __HAL_DRIVER_ARTERY_AT32F402_405_I2C_H__
19#define __HAL_DRIVER_ARTERY_AT32F402_405_I2C_H__
20
21/*============================ INCLUDES ======================================*/
22
23#include "hal/vsf_hal_cfg.h"
24
25#if VSF_HAL_USE_I2C == ENABLED
26
27// HW/IPCore
32// HW/IPCore end
33
34/*\note Refer to template/README.md for usage cases.
35 * For peripheral drivers, blackbox mode is recommended but not required, reimplementation part MUST be open.
36 * For IPCore drivers, class structure, MULTI_CLASS configuration, reimplementation and class APIs should be open to user.
37 * For emulated drivers, **** No reimplementation ****.
38 */
39
40/*\note Includes CAN ONLY be put here. */
41/*\note If current header is for a peripheral driver(hw driver), and inherit from an IPCore driver, include IPCore header here. */
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47/*============================ MACROS ========================================*/
48
49// HW
50/*\note hw I2C driver can reimplement following types:
51 * To enable reimplementation, please enable macro below:
52 * VSF_I2C_CFG_REIMPLEMENT_TYPE_MODE for vsf_i2c_mode_t
53 * VSF_I2C_CFG_REIMPLEMENT_TYPE_STATUS for vsf_i2c_status_t
54 * VSF_I2C_CFG_REIMPLEMENT_TYPE_IRQ_MASK for vsf_i2c_irq_mask_t
55 * VSF_I2C_CFG_REIMPLEMENT_TYPE_CMD for vsf_i2c_cmd_t
56 * VSF_I2C_CFG_REIMPLEMENT_TYPE_CTRL for vsf_i2c_ctrl_t
57 * VSF_I2C_CFG_REIMPLEMENT_TYPE_CFG for vsf_i2c_cfg_t
58 * VSF_I2C_CFG_REIMPLEMENT_TYPE_CAPABILITY for vsf_i2c_capability_t
59 * Reimplementation is used for optimization hw/IPCore drivers, reimplement the bit mask according to hw registers.
60 * *** DO NOT reimplement these in emulated drivers. ***
61 */
62
63#define VSF_I2C_CFG_REIMPLEMENT_TYPE_IRQ_MASK ENABLED
64#define VSF_I2C_CFG_REIMPLEMENT_TYPE_CMD ENABLED
65// HW end
66
67/*============================ TYPES =========================================*/
68
69// HW/IPCore, not for emulated drivers
70
71#if VSF_I2C_CFG_REIMPLEMENT_TYPE_CMD == ENABLED
72typedef enum vsf_i2c_cmd_t {
73 // 10: I2C_CTRL2.DIR(10)
74 VSF_I2C_CMD_WRITE = (0 << 10),
75 VSF_I2C_CMD_READ = (1 << 10),
76
77 // 13: I2C_CTRL2.GENSTART(13)
78 VSF_I2C_CMD_START = (1 << 13),
80 // 14: I2C_CTRL2.GENSTOP(14)
81 VSF_I2C_CMD_STOP = (1 << 14),
82
83 // 11: I2C_CTRL2.ADDR10(11)
84 VSF_I2C_CMD_7_BITS = (0 << 11),
86
87 // more vendor specified commands can be added here
88
97#endif
98
99#if VSF_I2C_CFG_REIMPLEMENT_TYPE_IRQ_MASK == ENABLED
100typedef enum vsf_i2c_irq_mask_t {
101 // 1: I2C_STS.TDIS(1)
103 // 2: I2C_STS.RDBF(2)
105 // 24: virtual
107 // 9: I2C_STS.ARLOST(9)
109 // 25: virtual, I2C_STS.ACKFAILF(4)|!I2C_STS.ADDRF(3)
111 // 26: virtual, I2C_STS.ACKFAILF(4)|I2C_STS.ADDRF(3)
113
114 // below 2 are not supported
117
118 // 27: virtual
120 // 5: I2C_STS.STOPF(5)
122 // 3: I2C_STS.ADDRF(3)
126 // 28: virtual
128
129 // more vendor specified irq_masks can be added here
130
139 | (1 << 4) // ACKFAIL
143#endif
144// HW/IPCore end
145
146/*============================ GLOBAL VARIABLES ==============================*/
147/*============================ PROTOTYPES ====================================*/
148
149#ifdef __cplusplus
150}
151#endif
152
153#endif // VSF_HAL_USE_I2C
154#endif // __HAL_DRIVER_ARTERY_AT32F402_405_I2C_H__
155/* EOF */
vsf_i2c_cmd_t
Definition i2c.h:32
@ VSF_I2C_CMD_10_BITS
Definition i2c.h:40
@ VSF_I2C_CMD_7_BITS
Definition i2c.h:39
@ VSF_I2C_CMD_STOP
Definition i2c.h:48
@ VSF_I2C_CMD_RESTART
Definition i2c.h:37
@ VSF_I2C_CMD_WRITE
Definition i2c.h:33
@ VSF_I2C_CMD_READ
Definition i2c.h:34
@ VSF_I2C_CMD_START
Definition i2c.h:36
@ __VSF_HW_I2C_CMD_MASK
Definition i2c.h:89
vsf_i2c_irq_mask_t
Definition i2c.h:100
@ __VSF_HW_I2C_VIRTUAL_MASK
Definition i2c.h:131
@ VSF_I2C_IRQ_MASK_MASTER_STOP_DETECT
Definition i2c.h:116
@ VSF_I2C_IRQ_MASK_SLAVE_TX
Definition i2c.h:124
@ VSF_I2C_IRQ_MASK_MASTER_TRANSFER_COMPLETE
Definition i2c.h:106
@ VSF_I2C_IRQ_MASK_SLAVE_START_OR_RESTART_DETECT
Definition i2c.h:119
@ VSF_I2C_IRQ_MASK_MASTER_TX
Definition i2c.h:102
@ __VSF_HW_I2C_REAL_MASK
Definition i2c.h:136
@ VSF_I2C_IRQ_MASK_SLAVE_ADDRESS_ACK
Definition i2c.h:123
@ VSF_I2C_IRQ_MASK_MASTER_RX
Definition i2c.h:104
@ VSF_I2C_IRQ_MASK_SLAVE_TRANSFER_COMPLETE
Definition i2c.h:127
@ VSF_I2C_IRQ_MASK_MASTER_START_OR_RESTART_DETECT
Definition i2c.h:115
@ VSF_I2C_IRQ_MASK_MASTER_ADDRESS_NACK
Definition i2c.h:110
@ VSF_I2C_IRQ_MASK_SLAVE_STOP_DETECT
Definition i2c.h:121
@ VSF_I2C_IRQ_MASK_MASTER_ARBITRATION_LOST
Definition i2c.h:108
@ VSF_I2C_IRQ_MASK_MASTER_TX_NACK_DETECT
Definition i2c.h:112
@ VSF_I2C_IRQ_MASK_SLAVE_RX
Definition i2c.h:125
Generated from commit: vsfteam/vsf@91f710a