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_${SERIES/I2C_IP}_I2C_H__
19#define __HAL_DRIVER_${SERIES/I2C_IP}_I2C_H__
20
21/*============================ INCLUDES ======================================*/
22
23#include "hal/vsf_hal_cfg.h"
24
25#if VSF_HAL_USE_I2C == ENABLED
26
27#include "../../__device.h"
28
29/*\note Refer to template/README.md for usage cases.
30 * For peripheral drivers, blackbox mode is recommended but not required, reimplementation part MUST be open.
31 * For IPCore drivers, class structure, MULTI_CLASS configuration, reimplementation and class APIs should be open to user.
32 * For emulated drivers, **** No reimplementation ****.
33 */
34
35/*\note Includes CAN ONLY be put here. */
36/*\note If current header is for a peripheral driver(hw driver), and inherit from an IPCore driver, include IPCore header here. */
37
38// IPCore
39#if defined(__VSF_HAL_${I2C_IP}_I2C_CLASS_IMPLEMENT)
40# define __VSF_CLASS_IMPLEMENT__
41#elif defined(__VSF_HAL_${I2C_IP}_I2C_CLASS_INHERIT__)
42# define __VSF_CLASS_INHERIT__
43#endif
44
45#include "utilities/ooc_class.h"
46// IPCore end
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52/*============================ MACROS ========================================*/
53
54/*\note VSF_${I2C_IP}_I2C_CFG_MULTI_CLASS should be implemented for IP drives and open to user,
55 * while VSF_HW_I2C_CFG_MULTI_CLASS should be in i2c.c.
56 */
57
58// IPCore
59#ifndef VSF_${I2C_IP}_I2C_CFG_MULTI_CLASS
60# define VSF_${I2C_IP}_I2C_CFG_MULTI_CLASS VSF_I2C_CFG_MULTI_CLASS
61#endif
62// IPCore end
63
64// HW
65/*\note hw I2C driver can reimplement vsf_i2c_mode_t/vsf_i2c_cmd_t/vsf_i2c_irq_mask_t/vsf_i2c_status_t.
66 * To enable reimplementation, please enable macro below:
67 * VSF_I2C_CFG_REIMPLEMENT_TYPE_MODE for vsf_i2c_mode_t
68 * VSF_I2C_CFG_REIMPLEMENT_TYPE_CMD for vsf_i2c_cmd_t
69 * VSF_I2C_CFG_REIMPLEMENT_TYPE_STATUS for vsf_i2c_status_t
70 * VSF_I2C_CFG_REIMPLEMENT_TYPE_IRQ_MASK for vsf_i2c_irq_mask_t
71 * Reimplementation is used for optimization hw/IPCore drivers, reimplement the bit mask according to hw registers.
72 * *** DO NOT reimplement these in emulated drivers. ***
73 */
74
75#define VSF_I2C_CFG_REIMPLEMENT_TYPE_MODE ENABLED
76#define VSF_I2C_CFG_REIMPLEMENT_TYPE_CMD ENABLED
77#define VSF_I2C_CFG_REIMPLEMENT_TYPE_STATUS ENABLED
78#define VSF_I2C_CFG_REIMPLEMENT_TYPE_IRQ_MASK ENABLED
79// HW end
80
81/*============================ TYPES =========================================*/
82
83// IPCore
84vsf_class(vsf_${i2c_ip}_i2c_t) {
85#if VSF_${I2C_IP}_CFG_MULTI_CLASS == ENABLED
86 public_member(
87 vsf_i2c_t vsf_i2c;
88 )
89#endif
90
91/*\note You can add more member in vsf_${i2c_ip}_i2c_t instance.
92 * For members accessible from child, put in protected_member.
93 * Else, put in private_member.
94 */
95
96 protected_member(
97 vsf_${i2c_ip}_iwc_reg_t *reg;
99 )
100};
101// IPCore end
102
103// HW/IPCore, not for emulated drivers
104typedef enum vsf_i2c_mode_t {
105 VSF_I2C_MODE_MASTER = (0x1ul << 28),
106 VSF_I2C_MODE_SLAVE = (0x0ul << 28),
107
109 VSF_I2C_SPEED_FAST_MODE = (0x1ul << 29),
112
113 VSF_I2C_ADDR_7_BITS = (0x0ul << 31),
114 VSF_I2C_ADDR_10_BITS = (0x1ul << 31),
115
116 // more vendor specified irq_mask can be added here
118
119typedef enum vsf_i2c_cmd_t {
120 VSF_I2C_CMD_WRITE = (0x00ul << 0),
121 VSF_I2C_CMD_READ = (0x01ul << 0),
122
123 VSF_I2C_CMD_START = (0x00ul << 28),
124 VSF_I2C_CMD_NO_START = (0x01ul << 28),
125
126 VSF_I2C_CMD_STOP = (0x00ul << 29),
127 VSF_I2C_CMD_RESTART = (0x01ul << 30),
129
130 VSF_I2C_CMD_7_BITS = (0x00ul << 31),
131 VSF_I2C_CMD_10_BITS = (0x01ul << 31),
132
133 // more vendor specified commands can be added here
135
136typedef enum vsf_i2c_irq_mask_t {
139 VSF_I2C_IRQ_MASK_MASTER_STOP_DETECT = (0x1ul << 2), // for multi master
144
147
148 // more vendor specified irq_masks can be added here
150
151/*\note It's not obligated to inherit from vsf_peripheral_status_t.
152 * If not, there MUST be a is_busy bit in vsf_i2c_status_t.
153 */
154
155typedef struct vsf_i2c_status_t {
156 union {
159 };
161// HW/IPCore end
162
163/*============================ GLOBAL VARIABLES ==============================*/
164/*============================ PROTOTYPES ====================================*/
165
166// IPCore
167/*\note Extern APIs for ip core diriver.
168 * There is no requirement about how APIs of IPCore drivers should be implemented.
169 * Just consider the simplicity for actual peripheral drivers.
170 */
171// IPCore end
172
173#ifdef __cplusplus
174}
175#endif
176
177// IPCore
178#undef __VSF_HAL_${I2C_IP}_I2C_CLASS_IMPLEMENT
179#undef __VSF_HAL_${I2C_IP}_I2C_CLASS_INHERIT__
180// IPCore end
181
182#endif // VSF_HAL_USE_I2C
183#endif // __HAL_DRIVER_${SERIES/I2C_IP}_I2C_H__
184/* EOF */
Definition adc.h:68
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_NO_START
Definition i2c.h:47
@ VSF_I2C_CMD_STOP
Definition i2c.h:48
@ VSF_I2C_CMD_NO_STOP_RESTART
Definition i2c.h:49
@ 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_i2c_mode_t
Definition i2c.h:104
@ VSF_I2C_MODE_MASTER
Definition i2c.h:105
@ VSF_I2C_SPEED_HIGH_SPEED_MODE
Definition i2c.h:111
@ VSF_I2C_MODE_SLAVE
Definition i2c.h:106
@ VSF_I2C_SPEED_STANDARD_MODE
Definition i2c.h:108
@ VSF_I2C_ADDR_7_BITS
Definition i2c.h:113
@ VSF_I2C_SPEED_FAST_MODE_PLUS
Definition i2c.h:110
@ VSF_I2C_SPEED_FAST_MODE
Definition i2c.h:109
@ VSF_I2C_ADDR_10_BITS
Definition i2c.h:114
class vsf_$ * reg
vsf_i2c_isr_t isr
Definition i2c.h:99
vsf_i2c_irq_mask_t
Definition i2c.h:136
@ VSF_I2C_IRQ_MASK_MASTER_STOP_DETECT
Definition i2c.h:139
@ VSF_I2C_IRQ_MASK_MASTER_ERROR
Definition i2c.h:143
@ VSF_I2C_IRQ_MASK_MASTER_TRANSFER_COMPLETE
Definition i2c.h:145
@ VSF_I2C_IRQ_MASK_MASTER_TX_EMPTY
Definition i2c.h:142
@ VSF_I2C_IRQ_MASK_MASTER_NACK_DETECT
Definition i2c.h:140
@ VSF_I2C_IRQ_MASK_MASTER_STOPPED
Definition i2c.h:138
@ VSF_I2C_IRQ_MASK_MASTER_ADDRESS_NACK
Definition i2c.h:146
@ VSF_I2C_IRQ_MASK_MASTER_ARBITRATION_LOST
Definition i2c.h:141
@ VSF_I2C_IRQ_MASK_MASTER_STARTED
Definition i2c.h:137
#define vsf_class(__name)
Definition ooc_class.h:48
unsigned uint32_t
Definition stdint.h:9
i2c interrupt configuration
Definition vsf_template_i2c.h:298
Definition vsf_template_i2c.h:222
Definition vsf_template_i2c.h:334
Definition vsf_template_hal_driver.h:196
vk_av_control_value_t value
Definition vsf_audio.h:171
vsf_i2c_mode_t
Definition vsf_template_i2c.h:116
vsf_i2c_irq_mask_t
Definition vsf_template_i2c.h:194