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 // SPI mode (bits 0-1: CPHA and CPOL, hardware specific)
85
86 // 26: virtual
88 // 18: SPI_CTRL2.HWCSOE(2)
90
91 // 20: SPI_CTRL2.TIEN(4)
93 VSF_SPI_TI_MODE = (1 << 20),
94#define VSF_SPI_MOTOROLA_MODE VSF_SPI_MOTOROLA_MODE
95#define VSF_SPI_TI_MODE VSF_SPI_TI_MODE
96#define VSF_SPI_MOTOROLA_TI_MASK (VSF_SPI_MOTOROLA_MODE | VSF_SPI_TI_MODE)
97
98 // 11: SPI_CTRL1.FBN(11)
101#define VSF_SPI_DATASIZE_16 VSF_SPI_DATASIZE_16
102 // 27: not support
104
106 // 10: SPI_CTRL1.ORA(10)
108 // 15: SPI_CTRL1.SLBEN(15)
110#define VSF_SPI_DATALINE_2_LINE_FULL_DUPLEX VSF_SPI_DATALINE_2_LINE_FULL_DUPLEX
111#define VSF_SPI_DATALINE_2_LINE_RX_ONLY VSF_SPI_DATALINE_2_LINE_RX_ONLY
112#define VSF_SPI_DATALINE_1_LINE_HALF_DUPLEX VSF_SPI_DATALINE_1_LINE_HALF_DUPLEX
113
114 // 13: SPI_CTRL1.CCEN(13)
117
118 // Standard Optional: only include these if hardware supports them
119 // 1: SPI_CTRL1.CLKPOL(1)
121 #define VSF_SPI_CPOL_LOW VSF_SPI_CPOL_LOW
123 #define VSF_SPI_CPOL_HIGH VSF_SPI_CPOL_HIGH
124 // 0: SPI_CTRL1.CLKPHA(0)
126 #define VSF_SPI_CPHA_LOW VSF_SPI_CPHA_LOW
128 #define VSF_SPI_CPHA_HIGH VSF_SPI_CPHA_HIGH
129
130 // more vendor specified modes can be added here
131
136#ifdef VSF_SPI_CPOL_LOW
139#endif
140#ifdef VSF_SPI_CPHA_LOW
143#endif
156#endif
157
158#if VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK == ENABLED
159typedef enum vsf_spi_irq_mask_t {
160 // 1: SPI_STS.TDBE(1)
162 // 0: SPI_STS.RDBF(0)
164 // 9: virtual, TODO: use DMA interrupt
166 // 10: virtual, TODO: use DMA interrupt
168 // 6: SPI_STS.ROERR(6)
170 // 4: SPI_STS.CCERR(4)
172
173 // more vendor specified irq_masks can be added here
175#endif
176
177// HW/IPCore end
178
179/*============================ INCLUDES ======================================*/
180
181#ifdef __cplusplus
182}
183#endif
184
185#endif // VSF_HAL_USE_SPI
186#endif // __HAL_DRIVER_ARTERY_AT32F402_405_SPI_H__
187/* EOF */
vsf_spi_mode_t
Definition spi.h:33
@ VSF_SPI_SLAVE
Definition spi.h:34
@ VSF_SPI_DATASIZE_16
Definition spi.h:57
@ VSF_SPI_MODE_1
Definition spi.h:41
@ VSF_SPI_DATASIZE_8
datasize is 8 bits
Definition spi.h:49
@ VSF_SPI_MASTER
Definition spi.h:35
@ VSF_SPI_DATASIZE_32
Definition spi.h:73
@ VSF_SPI_MODE_0
Definition spi.h:39
@ VSF_SPI_MODE_3
Definition spi.h:45
@ VSF_SPI_MODE_2
Definition spi.h:43
vsf_spi_irq_mask_t
Definition spi.h:159
@ VSF_SPI_IRQ_MASK_CRC_ERR
Definition spi.h:171
#define VSF_SPI_TI_MODE
Definition spi.h:95
#define VSF_SPI_DATALINE_2_LINE_FULL_DUPLEX
Definition spi.h:110
@ VSF_SPI_CRC_ENABLED
Definition spi.h:116
@ VSF_SPI_LSB_FIRST
Definition spi.h:78
@ __VSF_HW_SPI_CS_MASK
Definition spi.h:154
@ VSF_SPI_CRC_DISABLED
Definition spi.h:115
@ __VSF_HW_SPI_CTRL2_MASK
Definition spi.h:151
@ VSF_SPI_MSB_FIRST
Definition spi.h:77
@ __VSF_HW_SPI_CTRL1_MASK
Definition spi.h:132
@ VSF_SPI_CS_SOFTWARE_MODE
Definition spi.h:87
@ VSF_SPI_CS_HARDWARE_MODE
Definition spi.h:89
#define VSF_SPI_DATALINE_1_LINE_HALF_DUPLEX
Definition spi.h:112
#define VSF_SPI_DATALINE_2_LINE_RX_ONLY
Definition spi.h:111
#define VSF_SPI_MOTOROLA_MODE
Definition spi.h:94
#define VSF_SPI_CPOL_HIGH
Definition spi.h:101
@ VSF_SPI_IRQ_MASK_RX_OVERFLOW_ERR
Definition spi.h:117
@ VSF_SPI_IRQ_MASK_RX
Definition spi.h:114
@ VSF_SPI_IRQ_MASK_TX
Definition spi.h:113
#define VSF_SPI_CPHA_HIGH
Definition spi.h:105
vsf_spi_mode_t
Definition spi.h:79
#define VSF_SPI_CPHA_LOW
Definition spi.h:103
#define VSF_SPI_CPOL_LOW
Definition spi.h:99
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@b2e9e8a