WB32L003 Standard Peripherals Firmware Library

wb32l003_spi.h
Go to the documentation of this file.
1
10 /* Define to prevent recursive inclusion -------------------------------------*/
11 #ifndef __WB32L003_SPI_H
12 #define __WB32L003_SPI_H
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18 /* Includes ------------------------------------------------------------------*/
19 #include "wb32l003.h"
20
29 /* Exported types ------------------------------------------------------------*/
30
34 typedef struct
35 {
36 uint8_t SPI_TransferMode;
37 uint8_t SPI_CPOL;
38 uint8_t SPI_CPHA;
39 uint8_t SPI_BaudRatePrescaler;
40 } SPI_InitTypeDef;
41
42 /* Exported constants --------------------------------------------------------*/
43
51 #define SPI_MODE_SLAVE ((uint8_t)0x00U)
52 #define SPI_MODE_MASTER ((uint8_t)SPI_CR_MSTR)
53
61 #define SPI_CPOL_Low ((uint8_t)0x00U)
62 #define SPI_CPOL_High ((uint8_t)SPI_CR_CPOL)
63
71 #define SPI_CPHA_1Edge ((uint8_t)0x00U)
72 #define SPI_CPHA_2Edge ((uint8_t)SPI_CR_CPHA)
73
81 #define SPI_NSS_MODE_HIGH ((uint8_t)SPI_SSN_SSN)
82 #define SPI_NSS_MODE_LOW ((uint8_t)0x00U)
83
91 #define SPI_BAUD_RATE_PRESCALER_2 ((uint8_t)0x00U)
92 #define SPI_BAUD_RATE_PRESCALER_4 ((uint8_t)SPI_CR_SPR0)
93 #define SPI_BAUD_RATE_PRESCALER_8 ((uint8_t)SPI_CR_SPR1)
94 #define SPI_BAUD_RATE_PRESCALER_16 ((uint8_t)(SPI_CR_SPR0 | SPI_CR_SPR1))
95 #define SPI_BAUD_RATE_PRESCALER_32 ((uint8_t)SPI_CR_SPR2)
96 #define SPI_BAUD_RATE_PRESCALER_64 ((uint8_t)(SPI_CR_SPR2 | SPI_CR_SPR0))
97 #define SPI_BAUD_RATE_PRESCALER_128 ((uint8_t)(SPI_CR_SPR2 | SPI_CR_SPR1))
98
106 #define SPI_FLAG_SPIF ((uint8_t)SPI_SR_SPIF) /* SPI status flag: Tx ok flag */
107 #define SPI_FLAG_WCOL ((uint8_t)SPI_SR_WCOL) /* SPI status flag: write conflict flag */
108 #define SPI_FLAG_SSERR ((uint8_t)SPI_SR_SSERR) /* SPI Error flag: Slave SSN flag */
109 #define SPI_FLAG_MDF ((uint8_t)SPI_SR_MDF) /* SPI Error flag: Master Mode error flag */
110
118 /* Exported macro ------------------------------------------------------------*/
119
120 #define IS_SPI_MODE(MODE) (((MODE) == SPI_MODE_SLAVE) || \
121 ((MODE) == SPI_MODE_MASTER))
122
123 #define IS_SPI_CPOL(CPOL) (((CPOL) == SPI_CPOL_Low) || \
124 ((CPOL) == SPI_CPOL_High))
125
126 #define IS_SPI_CPHA(CPHA) (((CPHA) == SPI_CPHA_1Edge) || \
127 ((CPHA) == SPI_CPHA_2Edge))
128
129 #define IS_SPI_NSS(NSS) (((NSS) == SPI_NSS_MODE_HIGH) || \
130 ((NSS) == SPI_NSS_MODE_LOW))
131
132 #define IS_SPI_BAUDRATE_PRESCALER(PRESCALER) (((PRESCALER) == SPI_BAUD_RATE_PRESCALER_2) || \
133 ((PRESCALER) == SPI_BAUD_RATE_PRESCALER_4) || \
134 ((PRESCALER) == SPI_BAUD_RATE_PRESCALER_8) || \
135 ((PRESCALER) == SPI_BAUD_RATE_PRESCALER_16) || \
136 ((PRESCALER) == SPI_BAUD_RATE_PRESCALER_32) || \
137 ((PRESCALER) == SPI_BAUD_RATE_PRESCALER_64) || \
138 ((PRESCALER) == SPI_BAUD_RATE_PRESCALER_128))
139
140 #define IS_SPI_ALL_PERIPH(PERIPH) ((PERIPH) == SPI)
141
142 /* Exported functions --------------------------------------------------------*/
143
144 void SPI_DeInit(SPI_TypeDef* SPIx);
145 void SPI_Init(SPI_TypeDef *SPIx, SPI_InitTypeDef *SPI_InitStruct);
146 void SPI_Cmd(SPI_TypeDef *SPIx, FunctionalState NewState);
147 void SPI_NSSConfig(SPI_TypeDef *SPIx, FunctionalState NewState);
148 uint8_t SPI_ReadData(SPI_TypeDef *SPIx);
149 void SPI_WriteData(SPI_TypeDef *SPIx, uint8_t Data);
150 FlagStatus SPI_GetFlagStatus(SPI_TypeDef *SPIx, uint8_t SPI_FLAG);
151
160 #ifdef __cplusplus
161 }
162 #endif
163
164 #endif /*__WB32L003_SPI_H */
SPI_TypeDef
Definition: wb32l003.h:309
SPI_WriteData
void SPI_WriteData(SPI_TypeDef *SPIx, uint8_t Data)
Write one data to DATA register.
Definition: wb32l003_spi.c:138
SPI_Init
void SPI_Init(SPI_TypeDef *SPIx, SPI_InitTypeDef *SPI_InitStruct)
Initializes the SPIx peripheral according to the specified parameters in the SPI_InitStruct.
Definition: wb32l003_spi.c:63
SPI_NSSConfig
void SPI_NSSConfig(SPI_TypeDef *SPIx, FunctionalState NewState)
Enables or disables the specified slave select line.
Definition: wb32l003_spi.c:108
SPI_DeInit
void SPI_DeInit(SPI_TypeDef *SPIx)
Deinitializes the SPIx peripheral registers to their default reset values.
Definition: wb32l003_spi.c:40
SPI_InitTypeDef
SPI Init structure definition.
Definition: wb32l003_spi.h:34
SPI_ReadData
uint8_t SPI_ReadData(SPI_TypeDef *SPIx)
Read one data from DATA register.
Definition: wb32l003_spi.c:125
SPI_GetFlagStatus
FlagStatus SPI_GetFlagStatus(SPI_TypeDef *SPIx, uint8_t SPI_FLAG)
Checks whether the specified SPIx flag is set or not.
Definition: wb32l003_spi.c:156
SPI_Cmd
void SPI_Cmd(SPI_TypeDef *SPIx, FunctionalState NewState)
Enables or disables the specified SPI peripheral.
Definition: wb32l003_spi.c:87