VSF Documented
spi.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_SPI_H__
19#define __HAL_DRIVER_ARTERY_AT32F402_405_SPI_H__
20
21/*============================ INCLUDES ======================================*/
22
23#include "hal/vsf_hal_cfg.h"
24
25#if VSF_HAL_USE_SPI == 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 SPI driver can reimplement following types:
51 * To enable reimplementation, please enable macro below:
52 * VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE for vsf_spi_mode_t
53 * VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS for vsf_spi_status_t
54 * VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK for vsf_spi_irq_mask_t
55 * VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL for vsf_spi_ctrl_t
56 * VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG for vsf_spi_cfg_t
57 * VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY for vsf_spi_capability_t
58 * Reimplementation is used for optimization hw/IPCore drivers, reimplement the bit mask according to hw registers.
59 * *** DO NOT reimplement these in emulated drivers. ***
60 */
61
62#define VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE ENABLED
63#define VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK ENABLED
64// HW end
65
66/*============================ MACROFIED FUNCTIONS ===========================*/
67/*============================ TYPES =========================================*/
68
69// HW/IPCore, not for emulated drivers
70#if VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE == ENABLED
71typedef enum vsf_spi_mode_t {
72 // 2: SPI_CTRL1.MSTEN(2)
74 VSF_SPI_SLAVE = 0 << 2,
75
76 // 7: SPI_CTRL1.LTF(7)
79
80 // 1: SPI_CTRL1.CLKPOL(1)
83 // 0: SPI_CTRL1.CLKPHA(0)
90
91 // 26: virtual
93 // 18: SPI_CTRL2.HWCSOE(2)
95
96 // 20: SPI_CTRL2.TIEN(4)
98 VSF_SPI_TI_MODE = (1 << 20),
99#define VSF_SPI_MOTOROLA_MODE VSF_SPI_MOTOROLA_MODE
100#define VSF_SPI_TI_MODE VSF_SPI_TI_MODE
101#define VSF_SPI_MOTOROLA_TI_MASK (VSF_SPI_MOTOROLA_MODE | VSF_SPI_TI_MODE)
102
103 // 11: SPI_CTRL1.FBN(11)
106#define VSF_SPI_DATASIZE_16 VSF_SPI_DATASIZE_16
107 // 27: not support
109
111 // 10: SPI_CTRL1.ORA(10)
113 // 15: SPI_CTRL1.SLBEN(15)
115#define VSF_SPI_DATALINE_2_LINE_FULL_DUPLEX VSF_SPI_DATALINE_2_LINE_FULL_DUPLEX
116#define VSF_SPI_DATALINE_2_LINE_RX_ONLY VSF_SPI_DATALINE_2_LINE_RX_ONLY
117#define VSF_SPI_DATALINE_1_LINE_HALF_DUPLEX VSF_SPI_DATALINE_1_LINE_HALF_DUPLEX
118
119 // 13: SPI_CTRL1.CCEN(13)
122
123 // more vendor specified modes can be added here
124
145#endif
146
147#if VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK == ENABLED
148typedef enum vsf_spi_irq_mask_t {
149 // 1: SPI_STS.TDBE(1)
151 // 0: SPI_STS.RDBF(0)
153 // 9: virtual, TODO: use DMA interrupt
155 // 10: virtual, TODO: use DMA interrupt
157 // 6: SPI_STS.ROERR(6)
159 // 4: SPI_STS.CCERR(4)
161
162 // more vendor specified irq_masks can be added here
164#endif
165
166// HW/IPCore end
167
168/*============================ INCLUDES ======================================*/
169
170#ifdef __cplusplus
171}
172#endif
173
174#endif // VSF_HAL_USE_SPI
175#endif // __HAL_DRIVER_ARTERY_AT32F402_405_SPI_H__
176/* EOF */
vsf_spi_mode_t
Definition spi.h:33
@ VSF_SPI_SLAVE
Definition spi.h:34
@ VSF_SPI_DATASIZE_16
Definition spi.h:52
@ VSF_SPI_MODE_1
Definition spi.h:38
@ VSF_SPI_DATASIZE_8
datasize is 8 bits
Definition spi.h:44
@ VSF_SPI_MASTER
Definition spi.h:35
@ VSF_SPI_DATASIZE_32
Definition spi.h:68
@ VSF_SPI_MODE_0
Definition spi.h:37
@ VSF_SPI_MODE_3
Definition spi.h:40
@ VSF_SPI_MODE_2
Definition spi.h:39
vsf_spi_irq_mask_t
Definition spi.h:148
@ VSF_SPI_IRQ_MASK_CRC_ERR
Definition spi.h:160
#define VSF_SPI_TI_MODE
Definition spi.h:100
#define VSF_SPI_DATALINE_2_LINE_FULL_DUPLEX
Definition spi.h:115
@ VSF_SPI_CPHA_LOW
Definition spi.h:84
@ VSF_SPI_CRC_ENABLED
Definition spi.h:121
@ VSF_SPI_LSB_FIRST
Definition spi.h:78
@ __VSF_HW_SPI_CS_MASK
Definition spi.h:143
@ VSF_SPI_CRC_DISABLED
Definition spi.h:120
@ VSF_SPI_CPHA_HIGH
Definition spi.h:85
@ __VSF_HW_SPI_CTRL2_MASK
Definition spi.h:140
@ VSF_SPI_MSB_FIRST
Definition spi.h:77
@ __VSF_HW_SPI_CTRL1_MASK
Definition spi.h:125
@ VSF_SPI_CS_SOFTWARE_MODE
Definition spi.h:92
@ VSF_SPI_CS_HARDWARE_MODE
Definition spi.h:94
#define VSF_SPI_DATALINE_1_LINE_HALF_DUPLEX
Definition spi.h:117
#define VSF_SPI_DATALINE_2_LINE_RX_ONLY
Definition spi.h:116
#define VSF_SPI_MOTOROLA_MODE
Definition spi.h:99
@ VSF_SPI_IRQ_MASK_RX_OVERFLOW_ERR
Definition spi.h:108
@ VSF_SPI_IRQ_MASK_RX
Definition spi.h:105
@ VSF_SPI_IRQ_MASK_TX
Definition spi.h:104
vsf_spi_mode_t
Definition spi.h:79
@ VSF_SPI_CPHA_LOW
Definition spi.h:86
@ VSF_SPI_LSB_FIRST
Definition spi.h:83
@ VSF_SPI_CPOL_HIGH
Definition spi.h:85
@ VSF_SPI_MSB_FIRST
Definition spi.h:82
@ VSF_SPI_CS_SOFTWARE_MODE
Definition spi.h:92
@ VSF_SPI_CS_HARDWARE_MODE
Definition spi.h:93
@ VSF_SPI_CPOL_LOW
Definition spi.h:84
vsf_spi_irq_mask_t
Definition spi.h:41
@ VSF_SPI_IRQ_MASK_RX_CPL
Definition spi.h:43
@ VSF_SPI_IRQ_MASK_TX_CPL
Definition spi.h:42
Generated from commit: vsfteam/vsf@f33b89f