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_MODE ENABLED
64#define VSF_I2C_CFG_REIMPLEMENT_TYPE_STATUS ENABLED
65#define VSF_I2C_CFG_REIMPLEMENT_TYPE_IRQ_MASK ENABLED
66#define VSF_I2C_CFG_REIMPLEMENT_TYPE_CMD ENABLED
67#define VSF_I2C_CFG_REIMPLEMENT_TYPE_CTRL ENABLED
68#define VSF_I2C_CFG_REIMPLEMENT_TYPE_CFG ENABLED
69#define VSF_I2C_CFG_REIMPLEMENT_TYPE_CAPABILITY ENABLED
70// HW end
71
72/*============================ TYPES =========================================*/
73
74// HW/IPCore, not for emulated drivers
75#if VSF_I2C_CFG_REIMPLEMENT_TYPE_MODE == ENABLED
76typedef enum vsf_i2c_mode_t {
77 VSF_I2C_MODE_MASTER = (0x1ul << 28),
78 VSF_I2C_MODE_SLAVE = (0x0ul << 28),
79
81 VSF_I2C_SPEED_FAST_MODE = (0x1ul << 29),
84
85 VSF_I2C_ADDR_7_BITS = (0x0ul << 31),
86 VSF_I2C_ADDR_10_BITS = (0x1ul << 31),
87
88 // more vendor specified irq_mask can be added here
90#endif
91
92#if VSF_I2C_CFG_REIMPLEMENT_TYPE_CMD == ENABLED
93typedef enum vsf_i2c_cmd_t {
94 VSF_I2C_CMD_WRITE = (0x00ul << 0),
95 VSF_I2C_CMD_READ = (0x01ul << 0),
96
97 VSF_I2C_CMD_START = (0x00ul << 28),
98 VSF_I2C_CMD_NO_START = (0x01ul << 28),
99
100 VSF_I2C_CMD_STOP = (0x00ul << 29),
101 VSF_I2C_CMD_RESTART = (0x01ul << 30),
103
104 VSF_I2C_CMD_7_BITS = (0x00ul << 31),
105 VSF_I2C_CMD_10_BITS = (0x01ul << 31),
106
107 // more vendor specified commands can be added here
109#endif
110
111#if VSF_I2C_CFG_REIMPLEMENT_TYPE_IRQ_MASK == ENABLED
112typedef enum vsf_i2c_irq_mask_t {
126
127 // more vendor specified irq_masks can be added here
129#endif
130
131#if VSF_I2C_CFG_REIMPLEMENT_TYPE_STATUS == ENABLED
132/*\note It's not obligated to inherit from vsf_peripheral_status_t.
133 * If not, there MUST be a is_busy bit in vsf_i2c_status_t.
134 */
135
136typedef struct vsf_i2c_status_t {
137 union {
139 struct {
140 uint32_t is_busy : 1;
141 };
143 };
145#endif
146
147#if VSF_I2C_CFG_REIMPLEMENT_TYPE_CTRL == ENABLED
148typedef enum vsf_i2c_ctrl_t {
151#endif
152
153#if VSF_I2C_CFG_REIMPLEMENT_TYPE_CFG == ENABLED
154typedef struct vsf_i2c_t vsf_i2c_t;
155typedef void vsf_i2c_isr_handler_t(void *target_ptr, vsf_i2c_t *i2c_ptr, vsf_i2c_irq_mask_t irq_mask);
156typedef struct vsf_i2c_isr_t {
161typedef struct vsf_i2c_cfg_t {
167#endif
168
169#if VSF_I2C_CFG_REIMPLEMENT_TYPE_CAPABILITY == ENABLED
170typedef struct vsf_i2c_capability_t {
171#if VSF_I2C_CFG_INHERIT_HAL_CAPABILITY == ENABLED
173#endif
180
181 // more vendor specified capability can be added here
183#endif
184// HW/IPCore end
185
186/*============================ GLOBAL VARIABLES ==============================*/
187/*============================ PROTOTYPES ====================================*/
188
189#ifdef __cplusplus
190}
191#endif
192
193#endif // VSF_HAL_USE_I2C
194#endif // __HAL_DRIVER_ARTERY_AT32F402_405_I2C_H__
195/* EOF */
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
struct vsf_i2c_cfg_t vsf_i2c_cfg_t
struct vsf_i2c_status_t vsf_i2c_status_t
vsf_i2c_mode_t
Definition i2c.h:76
@ VSF_I2C_MODE_MASTER
Definition i2c.h:77
@ VSF_I2C_SPEED_HIGH_SPEED_MODE
Definition i2c.h:83
@ VSF_I2C_MODE_SLAVE
Definition i2c.h:78
@ VSF_I2C_SPEED_STANDARD_MODE
Definition i2c.h:80
@ VSF_I2C_ADDR_7_BITS
Definition i2c.h:85
@ VSF_I2C_SPEED_FAST_MODE_PLUS
Definition i2c.h:82
@ VSF_I2C_SPEED_FAST_MODE
Definition i2c.h:81
@ VSF_I2C_ADDR_10_BITS
Definition i2c.h:86
struct vsf_i2c_capability_t vsf_i2c_capability_t
struct vsf_i2c_isr_t vsf_i2c_isr_t
vsf_i2c_ctrl_t
Definition i2c.h:148
@ __VSF_I2C_CTRL_DUMMP
Definition i2c.h:149
vsf_i2c_irq_mask_t
Definition i2c.h:112
@ VSF_I2C_IRQ_MASK_MASTER_STOP_DETECT
Definition i2c.h:120
@ VSF_I2C_IRQ_MASK_SLAVE_TX
Definition i2c.h:123
@ VSF_I2C_IRQ_MASK_MASTER_TRANSFER_COMPLETE
Definition i2c.h:115
@ VSF_I2C_IRQ_MASK_SLAVE_START_OR_RESTART_DETECT
Definition i2c.h:121
@ VSF_I2C_IRQ_MASK_MASTER_TX
Definition i2c.h:113
@ VSF_I2C_IRQ_MASK_MASTER_RX
Definition i2c.h:114
@ VSF_I2C_IRQ_MASK_SLAVE_TRANSFER_COMPLETE
Definition i2c.h:125
@ VSF_I2C_IRQ_MASK_MASTER_START_OR_RESTART_DETECT
Definition i2c.h:119
@ VSF_I2C_IRQ_MASK_MASTER_ADDRESS_NACK
Definition i2c.h:117
@ VSF_I2C_IRQ_MASK_SLAVE_STOP_DETECT
Definition i2c.h:122
@ VSF_I2C_IRQ_MASK_MASTER_ARBITRATION_LOST
Definition i2c.h:116
@ VSF_I2C_IRQ_MASK_MASTER_TX_NACK_DETECT
Definition i2c.h:118
@ VSF_I2C_IRQ_MASK_SLAVE_RX
Definition i2c.h:124
void vsf_i2c_isr_handler_t(void *target_ptr, vsf_i2c_t *i2c_ptr, vsf_i2c_irq_mask_t irq_mask)
Definition i2c.h:155
vsf_i2c_mode_t
Definition i2c.h:116
vsf_i2c_irq_mask_t
Definition i2c.h:152
void vsf_i2c_isr_handler_t(void *target_ptr, vsf_i2c_t *i2c_ptr, vsf_i2c_irq_mask_t irq_mask)
Definition i2c.h:195
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 i2c.h:170
uint8_t support_restart
Definition i2c.h:177
uint8_t support_no_stop
Definition i2c.h:176
inherit(vsf_peripheral_capability_t) vsf_i2c_irq_mask_t irq_mask
uint_fast16_t max_transfer_size
Definition i2c.h:178
uint_fast16_t min_transfer_size
Definition i2c.h:179
uint8_t support_no_start
Definition i2c.h:175
I2C configuration.
Definition i2c.h:161
vsf_i2c_mode_t mode
Definition i2c.h:162
uint_fast16_t slave_addr
Definition i2c.h:165
vsf_i2c_isr_t isr
Definition i2c.h:164
uint32_t clock_hz
Definition i2c.h:163
I2C interrupt configuration.
Definition i2c.h:156
vsf_i2c_isr_handler_t * handler_fn
Definition i2c.h:157
void * target_ptr
Definition i2c.h:158
vsf_arch_prio_t prio
Definition i2c.h:159
Predefined VSF I2C status that can be reimplemented in specific hal drivers.
Definition i2c.h:136
uint32_t value
Definition i2c.h:142
I2C instance structure for multi-class support.
Definition vsf_template_i2c.h:970
Definition vsf_template_hal_driver.h:203
Definition vsf_template_hal_driver.h:196
Generated from commit: vsfteam/vsf@368bfa6