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// HW/IPCore
32// HW/IPCore end
33
34#include "../../__device.h"
35
36/*\note Refer to template/README.md for usage cases.
37 * For peripheral drivers, blackbox mode is recommended but not required, reimplementation part MUST be open.
38 * For IPCore drivers, class structure, MULTI_CLASS configuration, reimplementation and class APIs should be open to user.
39 * For emulated drivers, **** No reimplementation ****.
40 */
41
42/*\note Includes CAN ONLY be put here. */
43/*\note If current header is for a peripheral driver(hw driver), and inherit from an IPCore driver, include IPCore header here. */
44
45// IPCore
46#if defined(__VSF_HAL_${I2C_IP}_I2C_CLASS_IMPLEMENT)
47# define __VSF_CLASS_IMPLEMENT__
48#elif defined(__VSF_HAL_${I2C_IP}_I2C_CLASS_INHERIT__)
49# define __VSF_CLASS_INHERIT__
50#endif
51
52#include "utilities/ooc_class.h"
53// IPCore end
54
55#ifdef __cplusplus
56extern "C" {
57#endif
58
59/*============================ MACROS ========================================*/
60
61/*\note VSF_${I2C_IP}_I2C_CFG_MULTI_CLASS should be implemented for IP drives and open to user,
62 * while VSF_HW_I2C_CFG_MULTI_CLASS should be in i2c.c.
63 */
64
65// IPCore
66#ifndef VSF_${I2C_IP}_I2C_CFG_MULTI_CLASS
67# define VSF_${I2C_IP}_I2C_CFG_MULTI_CLASS VSF_I2C_CFG_MULTI_CLASS
68#endif
69// IPCore end
70
71// HW
72/*\note hw I2C driver can reimplement following types:
73 * To enable reimplementation, please enable macro below:
74 * VSF_I2C_CFG_REIMPLEMENT_TYPE_MODE for vsf_i2c_mode_t
75 * VSF_I2C_CFG_REIMPLEMENT_TYPE_STATUS for vsf_i2c_status_t
76 * VSF_I2C_CFG_REIMPLEMENT_TYPE_IRQ_MASK for vsf_i2c_irq_mask_t
77 * VSF_I2C_CFG_REIMPLEMENT_TYPE_CMD for vsf_i2c_cmd_t
78 * VSF_I2C_CFG_REIMPLEMENT_TYPE_CTRL for vsf_i2c_ctrl_t
79 * VSF_I2C_CFG_REIMPLEMENT_TYPE_CFG for vsf_i2c_cfg_t
80 * VSF_I2C_CFG_REIMPLEMENT_TYPE_CAPABILITY for vsf_i2c_capability_t
81 * Reimplementation is used for optimization hw/IPCore drivers, reimplement the bit mask according to hw registers.
82 * *** DO NOT reimplement these in emulated drivers. ***
83 */
84
85#define VSF_I2C_CFG_REIMPLEMENT_TYPE_MODE ENABLED
86#define VSF_I2C_CFG_REIMPLEMENT_TYPE_STATUS ENABLED
87#define VSF_I2C_CFG_REIMPLEMENT_TYPE_IRQ_MASK ENABLED
88#define VSF_I2C_CFG_REIMPLEMENT_TYPE_CMD ENABLED
89#define VSF_I2C_CFG_REIMPLEMENT_TYPE_CTRL ENABLED
90#define VSF_I2C_CFG_REIMPLEMENT_TYPE_CFG ENABLED
91#define VSF_I2C_CFG_REIMPLEMENT_TYPE_CAPABILITY ENABLED
92// HW end
93
94/*============================ TYPES =========================================*/
95
96// IPCore
97vsf_class(vsf_${i2c_ip}_i2c_t) {
98#if VSF_${I2C_IP}_CFG_MULTI_CLASS == ENABLED
99 public_member(
100 vsf_i2c_t vsf_i2c;
101 )
102#endif
103
104/*\note You can add more member in vsf_${i2c_ip}_i2c_t instance.
105 * For members accessible from child, put in protected_member.
106 * Else, put in private_member.
107 */
108
109 protected_member(
110 vsf_${i2c_ip}_iwc_reg_t *reg;
113};
114// IPCore end
115
116// HW/IPCore, not for emulated drivers
117#if VSF_I2C_CFG_REIMPLEMENT_TYPE_MODE == ENABLED
118typedef enum vsf_i2c_mode_t {
119 VSF_I2C_MODE_MASTER = (0x1ul << 28),
120 VSF_I2C_MODE_SLAVE = (0x0ul << 28),
121
123 VSF_I2C_SPEED_FAST_MODE = (0x1ul << 29),
126
127 VSF_I2C_ADDR_7_BITS = (0x0ul << 31),
128 VSF_I2C_ADDR_10_BITS = (0x1ul << 31),
129
130 // more vendor specified irq_mask can be added here
132#endif
133
134#if VSF_I2C_CFG_REIMPLEMENT_TYPE_CMD == ENABLED
135typedef enum vsf_i2c_cmd_t {
136 VSF_I2C_CMD_WRITE = (0x00ul << 0),
137 VSF_I2C_CMD_READ = (0x01ul << 0),
138
139 VSF_I2C_CMD_START = (0x00ul << 28),
140 VSF_I2C_CMD_NO_START = (0x01ul << 28),
141
142 VSF_I2C_CMD_STOP = (0x00ul << 29),
143 VSF_I2C_CMD_RESTART = (0x01ul << 30),
145
146 VSF_I2C_CMD_7_BITS = (0x00ul << 31),
147 VSF_I2C_CMD_10_BITS = (0x01ul << 31),
148
149 // more vendor specified commands can be added here
151#endif
152
153#if VSF_I2C_CFG_REIMPLEMENT_TYPE_IRQ_MASK == ENABLED
154typedef enum vsf_i2c_irq_mask_t {
170
171 // more vendor specified irq_masks can be added here
173#endif
174
175#if VSF_I2C_CFG_REIMPLEMENT_TYPE_STATUS == ENABLED
176/*\note It's not obligated to inherit from vsf_peripheral_status_t.
177 * If not, there MUST be a is_busy bit in vsf_i2c_status_t.
178 */
179
180typedef struct vsf_i2c_status_t {
181 union {
183 struct {
184 uint32_t is_busy : 1;
185 };
187 };
189#endif
190
191#if VSF_I2C_CFG_REIMPLEMENT_TYPE_CTRL == ENABLED
192typedef enum vsf_i2c_ctrl_t {
195#endif
196
197#if VSF_I2C_CFG_REIMPLEMENT_TYPE_CFG == ENABLED
198typedef struct vsf_i2c_t vsf_i2c_t;
199typedef void vsf_i2c_isr_handler_t(void *target_ptr, vsf_i2c_t *i2c_ptr, vsf_i2c_irq_mask_t irq_mask);
200typedef struct vsf_i2c_isr_t {
202 void *target_ptr;
205typedef struct vsf_i2c_cfg_t {
211#endif
212
213#if VSF_I2C_CFG_REIMPLEMENT_TYPE_CAPABILITY == ENABLED
214typedef struct vsf_i2c_capability_t {
215#if VSF_I2C_CFG_INHERIT_HAL_CAPABILITY == ENABLED
217#endif
224
225 // more vendor specified capability can be added here
227#endif
228// HW/IPCore end
229
230/*============================ GLOBAL VARIABLES ==============================*/
231/*============================ PROTOTYPES ====================================*/
232
233// IPCore
234/*\note Extern APIs for ip core diriver.
235 * There is no requirement about how APIs of IPCore drivers should be implemented.
236 * Just consider the simplicity for actual peripheral drivers.
237 */
238// IPCore end
239
240#ifdef __cplusplus
241}
242#endif
243
244// IPCore
245#undef __VSF_HAL_${I2C_IP}_I2C_CLASS_IMPLEMENT
246#undef __VSF_HAL_${I2C_IP}_I2C_CLASS_INHERIT__
247// IPCore end
248
249#endif // VSF_HAL_USE_I2C
250#endif // __HAL_DRIVER_${SERIES/I2C_IP}_I2C_H__
251/* EOF */
Definition adc.h:94
vsf_arch_prio_t
Definition cortex_a_generic.h:88
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:118
@ VSF_I2C_MODE_MASTER
Definition i2c.h:119
@ VSF_I2C_SPEED_HIGH_SPEED_MODE
Definition i2c.h:125
@ VSF_I2C_MODE_SLAVE
Definition i2c.h:120
@ VSF_I2C_SPEED_STANDARD_MODE
Definition i2c.h:122
@ VSF_I2C_ADDR_7_BITS
Definition i2c.h:127
@ VSF_I2C_SPEED_FAST_MODE_PLUS
Definition i2c.h:124
@ VSF_I2C_SPEED_FAST_MODE
Definition i2c.h:123
@ VSF_I2C_ADDR_10_BITS
Definition i2c.h:128
class vsf_$ * reg
vsf_i2c_isr_t isr
Definition i2c.h:112
vsf_i2c_ctrl_t
Definition i2c.h:192
@ __VSF_I2C_CTRL_DUMMP
Definition i2c.h:193
vsf_i2c_irq_mask_t
Definition i2c.h:154
@ VSF_I2C_IRQ_MASK_MASTER_STOP_DETECT
Definition i2c.h:163
@ VSF_I2C_IRQ_MASK_SLAVE_TX
Definition i2c.h:166
@ VSF_I2C_IRQ_MASK_MASTER_TRANSFER_COMPLETE
Definition i2c.h:157
@ VSF_I2C_IRQ_MASK_SLAVE_START_OR_RESTART_DETECT
Definition i2c.h:164
@ VSF_I2C_IRQ_MASK_MASTER_TX
Definition i2c.h:155
@ VSF_I2C_IRQ_MASK_MASTER_ERR
Definition i2c.h:161
@ VSF_I2C_IRQ_MASK_MASTER_RX
Definition i2c.h:156
@ VSF_I2C_IRQ_MASK_SLAVE_TRANSFER_COMPLETE
Definition i2c.h:168
@ VSF_I2C_IRQ_MASK_MASTER_START_OR_RESTART_DETECT
Definition i2c.h:162
@ VSF_I2C_IRQ_MASK_MASTER_ADDRESS_NACK
Definition i2c.h:159
@ VSF_I2C_IRQ_MASK_SLAVE_ERR
Definition i2c.h:169
@ VSF_I2C_IRQ_MASK_SLAVE_STOP_DETECT
Definition i2c.h:165
@ VSF_I2C_IRQ_MASK_MASTER_ARBITRATION_LOST
Definition i2c.h:158
@ VSF_I2C_IRQ_MASK_MASTER_TX_NACK_DETECT
Definition i2c.h:160
@ VSF_I2C_IRQ_MASK_SLAVE_RX
Definition i2c.h:167
void vsf_i2c_isr_handler_t(void *target_ptr, vsf_i2c_t *i2c_ptr, vsf_i2c_irq_mask_t irq_mask)
Definition i2c.h:199
#define vsf_class(__name)
Definition ooc_class.h:48
const i_spi_t vsf_spi_irq_mask_t irq_mask
Definition spi_interface.h:38
unsigned uint32_t
Definition stdint.h:9
unsigned short uint_fast16_t
Definition stdint.h:25
unsigned char uint8_t
Definition stdint.h:5
Predefined I2C capability structure that can be reimplemented in specific HAL drivers.
Definition vsf_template_i2c.h:777
uint8_t support_restart
Definition vsf_template_i2c.h:795
uint8_t support_no_stop
Definition vsf_template_i2c.h:791
inherit(vsf_peripheral_capability_t) vsf_i2c_irq_mask_t irq_mask
uint_fast16_t max_transfer_size
Definition vsf_template_i2c.h:799
uint_fast16_t min_transfer_size
Definition vsf_template_i2c.h:803
uint8_t support_no_start
Definition vsf_template_i2c.h:787
I2C configuration.
Definition vsf_template_i2c.h:881
vsf_i2c_mode_t mode
Definition vsf_template_i2c.h:884
uint_fast16_t slave_addr
Definition vsf_template_i2c.h:896
vsf_i2c_isr_t isr
Definition vsf_template_i2c.h:892
uint32_t clock_hz
Definition vsf_template_i2c.h:888
I2C interrupt configuration.
Definition vsf_template_i2c.h:860
vsf_i2c_isr_handler_t * handler_fn
Definition vsf_template_i2c.h:863
void * target_ptr
Definition vsf_template_i2c.h:867
vsf_arch_prio_t prio
Definition vsf_template_i2c.h:871
Predefined VSF I2C status that can be reimplemented in specific hal drivers.
Definition vsf_template_i2c.h:757
uint32_t value
Definition vsf_template_i2c.h:763
I2C instance structure for multi-class support.
Definition vsf_template_i2c.h:976
Definition vsf_template_hal_driver.h:203
Definition vsf_template_hal_driver.h:196
vsf_i2c_mode_t
Predefined VSF I2C modes that can be reimplemented in specific HAL drivers.If we want to add optional...
Definition vsf_template_i2c.h:237
vsf_i2c_ctrl_t
I2C control commands for hardware-specific operations.
Definition vsf_template_i2c.h:909
vsf_i2c_irq_mask_t
Predefined VSF I2C interrupt masks that can be reimplemented in specific HAL drivers....
Definition vsf_template_i2c.h:537
Generated from commit: vsfteam/vsf@2b286be