A simple 128x32 graphical LCD program to quickstart with LCD on ARM mbed IoT Starter Kit. This requires mbed Applciation Shield with FRDM-K64F platform.

Dependencies:   C12832

Committer:
tushki7
Date:
Sun Apr 12 15:45:52 2015 +0000
Revision:
1:eb68c94a8ee5
Parent:
0:60d829a0353a
A simple 128x32 LCD program with ARM mbed IoT Starter Kit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tushki7 0:60d829a0353a 1 /**
tushki7 0:60d829a0353a 2 ******************************************************************************
tushki7 0:60d829a0353a 3 * @file stm32f4xx_hal_spi.h
tushki7 0:60d829a0353a 4 * @author MCD Application Team
tushki7 0:60d829a0353a 5 * @version V1.1.0
tushki7 0:60d829a0353a 6 * @date 19-June-2014
tushki7 0:60d829a0353a 7 * @brief Header file of SPI HAL module.
tushki7 0:60d829a0353a 8 ******************************************************************************
tushki7 0:60d829a0353a 9 * @attention
tushki7 0:60d829a0353a 10 *
tushki7 0:60d829a0353a 11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
tushki7 0:60d829a0353a 12 *
tushki7 0:60d829a0353a 13 * Redistribution and use in source and binary forms, with or without modification,
tushki7 0:60d829a0353a 14 * are permitted provided that the following conditions are met:
tushki7 0:60d829a0353a 15 * 1. Redistributions of source code must retain the above copyright notice,
tushki7 0:60d829a0353a 16 * this list of conditions and the following disclaimer.
tushki7 0:60d829a0353a 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
tushki7 0:60d829a0353a 18 * this list of conditions and the following disclaimer in the documentation
tushki7 0:60d829a0353a 19 * and/or other materials provided with the distribution.
tushki7 0:60d829a0353a 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
tushki7 0:60d829a0353a 21 * may be used to endorse or promote products derived from this software
tushki7 0:60d829a0353a 22 * without specific prior written permission.
tushki7 0:60d829a0353a 23 *
tushki7 0:60d829a0353a 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
tushki7 0:60d829a0353a 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
tushki7 0:60d829a0353a 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
tushki7 0:60d829a0353a 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
tushki7 0:60d829a0353a 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
tushki7 0:60d829a0353a 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
tushki7 0:60d829a0353a 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
tushki7 0:60d829a0353a 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
tushki7 0:60d829a0353a 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
tushki7 0:60d829a0353a 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
tushki7 0:60d829a0353a 34 *
tushki7 0:60d829a0353a 35 ******************************************************************************
tushki7 0:60d829a0353a 36 */
tushki7 0:60d829a0353a 37
tushki7 0:60d829a0353a 38 /* Define to prevent recursive inclusion -------------------------------------*/
tushki7 0:60d829a0353a 39 #ifndef __STM32F4xx_HAL_SPI_H
tushki7 0:60d829a0353a 40 #define __STM32F4xx_HAL_SPI_H
tushki7 0:60d829a0353a 41
tushki7 0:60d829a0353a 42 #ifdef __cplusplus
tushki7 0:60d829a0353a 43 extern "C" {
tushki7 0:60d829a0353a 44 #endif
tushki7 0:60d829a0353a 45
tushki7 0:60d829a0353a 46 /* Includes ------------------------------------------------------------------*/
tushki7 0:60d829a0353a 47 #include "stm32f4xx_hal_def.h"
tushki7 0:60d829a0353a 48
tushki7 0:60d829a0353a 49 /** @addtogroup STM32F4xx_HAL_Driver
tushki7 0:60d829a0353a 50 * @{
tushki7 0:60d829a0353a 51 */
tushki7 0:60d829a0353a 52
tushki7 0:60d829a0353a 53 /** @addtogroup SPI
tushki7 0:60d829a0353a 54 * @{
tushki7 0:60d829a0353a 55 */
tushki7 0:60d829a0353a 56
tushki7 0:60d829a0353a 57 /* Exported types ------------------------------------------------------------*/
tushki7 0:60d829a0353a 58
tushki7 0:60d829a0353a 59 /**
tushki7 0:60d829a0353a 60 * @brief SPI Configuration Structure definition
tushki7 0:60d829a0353a 61 */
tushki7 0:60d829a0353a 62 typedef struct
tushki7 0:60d829a0353a 63 {
tushki7 0:60d829a0353a 64 uint32_t Mode; /*!< Specifies the SPI operating mode.
tushki7 0:60d829a0353a 65 This parameter can be a value of @ref SPI_mode */
tushki7 0:60d829a0353a 66
tushki7 0:60d829a0353a 67 uint32_t Direction; /*!< Specifies the SPI Directional mode state.
tushki7 0:60d829a0353a 68 This parameter can be a value of @ref SPI_Direction_mode */
tushki7 0:60d829a0353a 69
tushki7 0:60d829a0353a 70 uint32_t DataSize; /*!< Specifies the SPI data size.
tushki7 0:60d829a0353a 71 This parameter can be a value of @ref SPI_data_size */
tushki7 0:60d829a0353a 72
tushki7 0:60d829a0353a 73 uint32_t CLKPolarity; /*!< Specifies the serial clock steady state.
tushki7 0:60d829a0353a 74 This parameter can be a value of @ref SPI_Clock_Polarity */
tushki7 0:60d829a0353a 75
tushki7 0:60d829a0353a 76 uint32_t CLKPhase; /*!< Specifies the clock active edge for the bit capture.
tushki7 0:60d829a0353a 77 This parameter can be a value of @ref SPI_Clock_Phase */
tushki7 0:60d829a0353a 78
tushki7 0:60d829a0353a 79 uint32_t NSS; /*!< Specifies whether the NSS signal is managed by
tushki7 0:60d829a0353a 80 hardware (NSS pin) or by software using the SSI bit.
tushki7 0:60d829a0353a 81 This parameter can be a value of @ref SPI_Slave_Select_management */
tushki7 0:60d829a0353a 82
tushki7 0:60d829a0353a 83 uint32_t BaudRatePrescaler; /*!< Specifies the Baud Rate prescaler value which will be
tushki7 0:60d829a0353a 84 used to configure the transmit and receive SCK clock.
tushki7 0:60d829a0353a 85 This parameter can be a value of @ref SPI_BaudRate_Prescaler
tushki7 0:60d829a0353a 86 @note The communication clock is derived from the master
tushki7 0:60d829a0353a 87 clock. The slave clock does not need to be set */
tushki7 0:60d829a0353a 88
tushki7 0:60d829a0353a 89 uint32_t FirstBit; /*!< Specifies whether data transfers start from MSB or LSB bit.
tushki7 0:60d829a0353a 90 This parameter can be a value of @ref SPI_MSB_LSB_transmission */
tushki7 0:60d829a0353a 91
tushki7 0:60d829a0353a 92 uint32_t TIMode; /*!< Specifies if the TI mode is enabled or not.
tushki7 0:60d829a0353a 93 This parameter can be a value of @ref SPI_TI_mode */
tushki7 0:60d829a0353a 94
tushki7 0:60d829a0353a 95 uint32_t CRCCalculation; /*!< Specifies if the CRC calculation is enabled or not.
tushki7 0:60d829a0353a 96 This parameter can be a value of @ref SPI_CRC_Calculation */
tushki7 0:60d829a0353a 97
tushki7 0:60d829a0353a 98 uint32_t CRCPolynomial; /*!< Specifies the polynomial used for the CRC calculation.
tushki7 0:60d829a0353a 99 This parameter must be a number between Min_Data = 0 and Max_Data = 65535 */
tushki7 0:60d829a0353a 100
tushki7 0:60d829a0353a 101 }SPI_InitTypeDef;
tushki7 0:60d829a0353a 102
tushki7 0:60d829a0353a 103 /**
tushki7 0:60d829a0353a 104 * @brief HAL SPI State structure definition
tushki7 0:60d829a0353a 105 */
tushki7 0:60d829a0353a 106 typedef enum
tushki7 0:60d829a0353a 107 {
tushki7 0:60d829a0353a 108 HAL_SPI_STATE_RESET = 0x00, /*!< SPI not yet initialized or disabled */
tushki7 0:60d829a0353a 109 HAL_SPI_STATE_READY = 0x01, /*!< SPI initialized and ready for use */
tushki7 0:60d829a0353a 110 HAL_SPI_STATE_BUSY = 0x02, /*!< SPI process is ongoing */
tushki7 0:60d829a0353a 111 HAL_SPI_STATE_BUSY_TX = 0x12, /*!< Data Transmission process is ongoing */
tushki7 0:60d829a0353a 112 HAL_SPI_STATE_BUSY_RX = 0x22, /*!< Data Reception process is ongoing */
tushki7 0:60d829a0353a 113 HAL_SPI_STATE_BUSY_TX_RX = 0x32, /*!< Data Transmission and Reception process is ongoing */
tushki7 0:60d829a0353a 114 HAL_SPI_STATE_ERROR = 0x03 /*!< SPI error state */
tushki7 0:60d829a0353a 115
tushki7 0:60d829a0353a 116 }HAL_SPI_StateTypeDef;
tushki7 0:60d829a0353a 117
tushki7 0:60d829a0353a 118 /**
tushki7 0:60d829a0353a 119 * @brief HAL SPI Error Code structure definition
tushki7 0:60d829a0353a 120 */
tushki7 0:60d829a0353a 121 typedef enum
tushki7 0:60d829a0353a 122 {
tushki7 0:60d829a0353a 123 HAL_SPI_ERROR_NONE = 0x00, /*!< No error */
tushki7 0:60d829a0353a 124 HAL_SPI_ERROR_MODF = 0x01, /*!< MODF error */
tushki7 0:60d829a0353a 125 HAL_SPI_ERROR_CRC = 0x02, /*!< CRC error */
tushki7 0:60d829a0353a 126 HAL_SPI_ERROR_OVR = 0x04, /*!< OVR error */
tushki7 0:60d829a0353a 127 HAL_SPI_ERROR_FRE = 0x08, /*!< FRE error */
tushki7 0:60d829a0353a 128 HAL_SPI_ERROR_DMA = 0x10, /*!< DMA transfer error */
tushki7 0:60d829a0353a 129 HAL_SPI_ERROR_FLAG = 0x20 /*!< Flag: RXNE,TXE, BSY */
tushki7 0:60d829a0353a 130
tushki7 0:60d829a0353a 131 }HAL_SPI_ErrorTypeDef;
tushki7 0:60d829a0353a 132
tushki7 0:60d829a0353a 133 /**
tushki7 0:60d829a0353a 134 * @brief SPI handle Structure definition
tushki7 0:60d829a0353a 135 */
tushki7 0:60d829a0353a 136 typedef struct __SPI_HandleTypeDef
tushki7 0:60d829a0353a 137 {
tushki7 0:60d829a0353a 138 SPI_TypeDef *Instance; /* SPI registers base address */
tushki7 0:60d829a0353a 139
tushki7 0:60d829a0353a 140 SPI_InitTypeDef Init; /* SPI communication parameters */
tushki7 0:60d829a0353a 141
tushki7 0:60d829a0353a 142 uint8_t *pTxBuffPtr; /* Pointer to SPI Tx transfer Buffer */
tushki7 0:60d829a0353a 143
tushki7 0:60d829a0353a 144 uint16_t TxXferSize; /* SPI Tx transfer size */
tushki7 0:60d829a0353a 145
tushki7 0:60d829a0353a 146 uint16_t TxXferCount; /* SPI Tx Transfer Counter */
tushki7 0:60d829a0353a 147
tushki7 0:60d829a0353a 148 uint8_t *pRxBuffPtr; /* Pointer to SPI Rx transfer Buffer */
tushki7 0:60d829a0353a 149
tushki7 0:60d829a0353a 150 uint16_t RxXferSize; /* SPI Rx transfer size */
tushki7 0:60d829a0353a 151
tushki7 0:60d829a0353a 152 uint16_t RxXferCount; /* SPI Rx Transfer Counter */
tushki7 0:60d829a0353a 153
tushki7 0:60d829a0353a 154 DMA_HandleTypeDef *hdmatx; /* SPI Tx DMA handle parameters */
tushki7 0:60d829a0353a 155
tushki7 0:60d829a0353a 156 DMA_HandleTypeDef *hdmarx; /* SPI Rx DMA handle parameters */
tushki7 0:60d829a0353a 157
tushki7 0:60d829a0353a 158 void (*RxISR)(struct __SPI_HandleTypeDef * hspi); /* function pointer on Rx ISR */
tushki7 0:60d829a0353a 159
tushki7 0:60d829a0353a 160 void (*TxISR)(struct __SPI_HandleTypeDef * hspi); /* function pointer on Tx ISR */
tushki7 0:60d829a0353a 161
tushki7 0:60d829a0353a 162 HAL_LockTypeDef Lock; /* SPI locking object */
tushki7 0:60d829a0353a 163
tushki7 0:60d829a0353a 164 __IO HAL_SPI_StateTypeDef State; /* SPI communication state */
tushki7 0:60d829a0353a 165
tushki7 0:60d829a0353a 166 __IO HAL_SPI_ErrorTypeDef ErrorCode; /* SPI Error code */
tushki7 0:60d829a0353a 167
tushki7 0:60d829a0353a 168 }SPI_HandleTypeDef;
tushki7 0:60d829a0353a 169
tushki7 0:60d829a0353a 170 /* Exported constants --------------------------------------------------------*/
tushki7 0:60d829a0353a 171
tushki7 0:60d829a0353a 172 /** @defgroup SPI_Exported_Constants
tushki7 0:60d829a0353a 173 * @{
tushki7 0:60d829a0353a 174 */
tushki7 0:60d829a0353a 175
tushki7 0:60d829a0353a 176 /** @defgroup SPI_mode
tushki7 0:60d829a0353a 177 * @{
tushki7 0:60d829a0353a 178 */
tushki7 0:60d829a0353a 179 #define SPI_MODE_SLAVE ((uint32_t)0x00000000)
tushki7 0:60d829a0353a 180 #define SPI_MODE_MASTER (SPI_CR1_MSTR | SPI_CR1_SSI)
tushki7 0:60d829a0353a 181
tushki7 0:60d829a0353a 182 #define IS_SPI_MODE(MODE) (((MODE) == SPI_MODE_SLAVE) || \
tushki7 0:60d829a0353a 183 ((MODE) == SPI_MODE_MASTER))
tushki7 0:60d829a0353a 184 /**
tushki7 0:60d829a0353a 185 * @}
tushki7 0:60d829a0353a 186 */
tushki7 0:60d829a0353a 187
tushki7 0:60d829a0353a 188 /** @defgroup SPI_Direction_mode
tushki7 0:60d829a0353a 189 * @{
tushki7 0:60d829a0353a 190 */
tushki7 0:60d829a0353a 191 #define SPI_DIRECTION_2LINES ((uint32_t)0x00000000)
tushki7 0:60d829a0353a 192 #define SPI_DIRECTION_2LINES_RXONLY SPI_CR1_RXONLY
tushki7 0:60d829a0353a 193 #define SPI_DIRECTION_1LINE SPI_CR1_BIDIMODE
tushki7 0:60d829a0353a 194
tushki7 0:60d829a0353a 195 #define IS_SPI_DIRECTION_MODE(MODE) (((MODE) == SPI_DIRECTION_2LINES) || \
tushki7 0:60d829a0353a 196 ((MODE) == SPI_DIRECTION_2LINES_RXONLY) || \
tushki7 0:60d829a0353a 197 ((MODE) == SPI_DIRECTION_1LINE))
tushki7 0:60d829a0353a 198
tushki7 0:60d829a0353a 199 #define IS_SPI_DIRECTION_2LINES_OR_1LINE(MODE) (((MODE) == SPI_DIRECTION_2LINES) || \
tushki7 0:60d829a0353a 200 ((MODE) == SPI_DIRECTION_1LINE))
tushki7 0:60d829a0353a 201
tushki7 0:60d829a0353a 202 #define IS_SPI_DIRECTION_2LINES(MODE) ((MODE) == SPI_DIRECTION_2LINES)
tushki7 0:60d829a0353a 203
tushki7 0:60d829a0353a 204 /**
tushki7 0:60d829a0353a 205 * @}
tushki7 0:60d829a0353a 206 */
tushki7 0:60d829a0353a 207
tushki7 0:60d829a0353a 208 /** @defgroup SPI_data_size
tushki7 0:60d829a0353a 209 * @{
tushki7 0:60d829a0353a 210 */
tushki7 0:60d829a0353a 211 #define SPI_DATASIZE_8BIT ((uint32_t)0x00000000)
tushki7 0:60d829a0353a 212 #define SPI_DATASIZE_16BIT SPI_CR1_DFF
tushki7 0:60d829a0353a 213
tushki7 0:60d829a0353a 214 #define IS_SPI_DATASIZE(DATASIZE) (((DATASIZE) == SPI_DATASIZE_16BIT) || \
tushki7 0:60d829a0353a 215 ((DATASIZE) == SPI_DATASIZE_8BIT))
tushki7 0:60d829a0353a 216 /**
tushki7 0:60d829a0353a 217 * @}
tushki7 0:60d829a0353a 218 */
tushki7 0:60d829a0353a 219
tushki7 0:60d829a0353a 220 /** @defgroup SPI_Clock_Polarity
tushki7 0:60d829a0353a 221 * @{
tushki7 0:60d829a0353a 222 */
tushki7 0:60d829a0353a 223 #define SPI_POLARITY_LOW ((uint32_t)0x00000000)
tushki7 0:60d829a0353a 224 #define SPI_POLARITY_HIGH SPI_CR1_CPOL
tushki7 0:60d829a0353a 225
tushki7 0:60d829a0353a 226 #define IS_SPI_CPOL(CPOL) (((CPOL) == SPI_POLARITY_LOW) || \
tushki7 0:60d829a0353a 227 ((CPOL) == SPI_POLARITY_HIGH))
tushki7 0:60d829a0353a 228 /**
tushki7 0:60d829a0353a 229 * @}
tushki7 0:60d829a0353a 230 */
tushki7 0:60d829a0353a 231
tushki7 0:60d829a0353a 232 /** @defgroup SPI_Clock_Phase
tushki7 0:60d829a0353a 233 * @{
tushki7 0:60d829a0353a 234 */
tushki7 0:60d829a0353a 235 #define SPI_PHASE_1EDGE ((uint32_t)0x00000000)
tushki7 0:60d829a0353a 236 #define SPI_PHASE_2EDGE SPI_CR1_CPHA
tushki7 0:60d829a0353a 237
tushki7 0:60d829a0353a 238 #define IS_SPI_CPHA(CPHA) (((CPHA) == SPI_PHASE_1EDGE) || \
tushki7 0:60d829a0353a 239 ((CPHA) == SPI_PHASE_2EDGE))
tushki7 0:60d829a0353a 240 /**
tushki7 0:60d829a0353a 241 * @}
tushki7 0:60d829a0353a 242 */
tushki7 0:60d829a0353a 243
tushki7 0:60d829a0353a 244 /** @defgroup SPI_Slave_Select_management
tushki7 0:60d829a0353a 245 * @{
tushki7 0:60d829a0353a 246 */
tushki7 0:60d829a0353a 247 #define SPI_NSS_SOFT SPI_CR1_SSM
tushki7 0:60d829a0353a 248 #define SPI_NSS_HARD_INPUT ((uint32_t)0x00000000)
tushki7 0:60d829a0353a 249 #define SPI_NSS_HARD_OUTPUT ((uint32_t)0x00040000)
tushki7 0:60d829a0353a 250
tushki7 0:60d829a0353a 251 #define IS_SPI_NSS(NSS) (((NSS) == SPI_NSS_SOFT) || \
tushki7 0:60d829a0353a 252 ((NSS) == SPI_NSS_HARD_INPUT) || \
tushki7 0:60d829a0353a 253 ((NSS) == SPI_NSS_HARD_OUTPUT))
tushki7 0:60d829a0353a 254 /**
tushki7 0:60d829a0353a 255 * @}
tushki7 0:60d829a0353a 256 */
tushki7 0:60d829a0353a 257
tushki7 0:60d829a0353a 258 /** @defgroup SPI_BaudRate_Prescaler
tushki7 0:60d829a0353a 259 * @{
tushki7 0:60d829a0353a 260 */
tushki7 0:60d829a0353a 261 #define SPI_BAUDRATEPRESCALER_2 ((uint32_t)0x00000000)
tushki7 0:60d829a0353a 262 #define SPI_BAUDRATEPRESCALER_4 ((uint32_t)0x00000008)
tushki7 0:60d829a0353a 263 #define SPI_BAUDRATEPRESCALER_8 ((uint32_t)0x00000010)
tushki7 0:60d829a0353a 264 #define SPI_BAUDRATEPRESCALER_16 ((uint32_t)0x00000018)
tushki7 0:60d829a0353a 265 #define SPI_BAUDRATEPRESCALER_32 ((uint32_t)0x00000020)
tushki7 0:60d829a0353a 266 #define SPI_BAUDRATEPRESCALER_64 ((uint32_t)0x00000028)
tushki7 0:60d829a0353a 267 #define SPI_BAUDRATEPRESCALER_128 ((uint32_t)0x00000030)
tushki7 0:60d829a0353a 268 #define SPI_BAUDRATEPRESCALER_256 ((uint32_t)0x00000038)
tushki7 0:60d829a0353a 269
tushki7 0:60d829a0353a 270 #define IS_SPI_BAUDRATE_PRESCALER(PRESCALER) (((PRESCALER) == SPI_BAUDRATEPRESCALER_2) || \
tushki7 0:60d829a0353a 271 ((PRESCALER) == SPI_BAUDRATEPRESCALER_4) || \
tushki7 0:60d829a0353a 272 ((PRESCALER) == SPI_BAUDRATEPRESCALER_8) || \
tushki7 0:60d829a0353a 273 ((PRESCALER) == SPI_BAUDRATEPRESCALER_16) || \
tushki7 0:60d829a0353a 274 ((PRESCALER) == SPI_BAUDRATEPRESCALER_32) || \
tushki7 0:60d829a0353a 275 ((PRESCALER) == SPI_BAUDRATEPRESCALER_64) || \
tushki7 0:60d829a0353a 276 ((PRESCALER) == SPI_BAUDRATEPRESCALER_128) || \
tushki7 0:60d829a0353a 277 ((PRESCALER) == SPI_BAUDRATEPRESCALER_256))
tushki7 0:60d829a0353a 278 /**
tushki7 0:60d829a0353a 279 * @}
tushki7 0:60d829a0353a 280 */
tushki7 0:60d829a0353a 281
tushki7 0:60d829a0353a 282 /** @defgroup SPI_MSB_LSB_transmission
tushki7 0:60d829a0353a 283 * @{
tushki7 0:60d829a0353a 284 */
tushki7 0:60d829a0353a 285 #define SPI_FIRSTBIT_MSB ((uint32_t)0x00000000)
tushki7 0:60d829a0353a 286 #define SPI_FIRSTBIT_LSB SPI_CR1_LSBFIRST
tushki7 0:60d829a0353a 287
tushki7 0:60d829a0353a 288 #define IS_SPI_FIRST_BIT(BIT) (((BIT) == SPI_FIRSTBIT_MSB) || \
tushki7 0:60d829a0353a 289 ((BIT) == SPI_FIRSTBIT_LSB))
tushki7 0:60d829a0353a 290 /**
tushki7 0:60d829a0353a 291 * @}
tushki7 0:60d829a0353a 292 */
tushki7 0:60d829a0353a 293
tushki7 0:60d829a0353a 294 /** @defgroup SPI_TI_mode
tushki7 0:60d829a0353a 295 * @{
tushki7 0:60d829a0353a 296 */
tushki7 0:60d829a0353a 297 #define SPI_TIMODE_DISABLED ((uint32_t)0x00000000)
tushki7 0:60d829a0353a 298 #define SPI_TIMODE_ENABLED SPI_CR2_FRF
tushki7 0:60d829a0353a 299
tushki7 0:60d829a0353a 300 #define IS_SPI_TIMODE(MODE) (((MODE) == SPI_TIMODE_DISABLED) || \
tushki7 0:60d829a0353a 301 ((MODE) == SPI_TIMODE_ENABLED))
tushki7 0:60d829a0353a 302 /**
tushki7 0:60d829a0353a 303 * @}
tushki7 0:60d829a0353a 304 */
tushki7 0:60d829a0353a 305
tushki7 0:60d829a0353a 306 /** @defgroup SPI_CRC_Calculation
tushki7 0:60d829a0353a 307 * @{
tushki7 0:60d829a0353a 308 */
tushki7 0:60d829a0353a 309 #define SPI_CRCCALCULATION_DISABLED ((uint32_t)0x00000000)
tushki7 0:60d829a0353a 310 #define SPI_CRCCALCULATION_ENABLED SPI_CR1_CRCEN
tushki7 0:60d829a0353a 311
tushki7 0:60d829a0353a 312 #define IS_SPI_CRC_CALCULATION(CALCULATION) (((CALCULATION) == SPI_CRCCALCULATION_DISABLED) || \
tushki7 0:60d829a0353a 313 ((CALCULATION) == SPI_CRCCALCULATION_ENABLED))
tushki7 0:60d829a0353a 314 /**
tushki7 0:60d829a0353a 315 * @}
tushki7 0:60d829a0353a 316 */
tushki7 0:60d829a0353a 317
tushki7 0:60d829a0353a 318 /** @defgroup SPI_Interrupt_configuration_definition
tushki7 0:60d829a0353a 319 * @{
tushki7 0:60d829a0353a 320 */
tushki7 0:60d829a0353a 321 #define SPI_IT_TXE SPI_CR2_TXEIE
tushki7 0:60d829a0353a 322 #define SPI_IT_RXNE SPI_CR2_RXNEIE
tushki7 0:60d829a0353a 323 #define SPI_IT_ERR SPI_CR2_ERRIE
tushki7 0:60d829a0353a 324 /**
tushki7 0:60d829a0353a 325 * @}
tushki7 0:60d829a0353a 326 */
tushki7 0:60d829a0353a 327
tushki7 0:60d829a0353a 328 /** @defgroup SPI_Flag_definition
tushki7 0:60d829a0353a 329 * @{
tushki7 0:60d829a0353a 330 */
tushki7 0:60d829a0353a 331 #define SPI_FLAG_RXNE SPI_SR_RXNE
tushki7 0:60d829a0353a 332 #define SPI_FLAG_TXE SPI_SR_TXE
tushki7 0:60d829a0353a 333 #define SPI_FLAG_CRCERR SPI_SR_CRCERR
tushki7 0:60d829a0353a 334 #define SPI_FLAG_MODF SPI_SR_MODF
tushki7 0:60d829a0353a 335 #define SPI_FLAG_OVR SPI_SR_OVR
tushki7 0:60d829a0353a 336 #define SPI_FLAG_BSY SPI_SR_BSY
tushki7 0:60d829a0353a 337 #define SPI_FLAG_FRE SPI_SR_FRE
tushki7 0:60d829a0353a 338
tushki7 0:60d829a0353a 339 /**
tushki7 0:60d829a0353a 340 * @}
tushki7 0:60d829a0353a 341 */
tushki7 0:60d829a0353a 342
tushki7 0:60d829a0353a 343 /**
tushki7 0:60d829a0353a 344 * @}
tushki7 0:60d829a0353a 345 */
tushki7 0:60d829a0353a 346
tushki7 0:60d829a0353a 347 /* Exported macro ------------------------------------------------------------*/
tushki7 0:60d829a0353a 348
tushki7 0:60d829a0353a 349 /** @brief Reset SPI handle state
tushki7 0:60d829a0353a 350 * @param __HANDLE__: specifies the SPI handle.
tushki7 0:60d829a0353a 351 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
tushki7 0:60d829a0353a 352 * @retval None
tushki7 0:60d829a0353a 353 */
tushki7 0:60d829a0353a 354 #define __HAL_SPI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SPI_STATE_RESET)
tushki7 0:60d829a0353a 355
tushki7 0:60d829a0353a 356 /** @brief Enable or disable the specified SPI interrupts.
tushki7 0:60d829a0353a 357 * @param __HANDLE__: specifies the SPI handle.
tushki7 0:60d829a0353a 358 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
tushki7 0:60d829a0353a 359 * @param __INTERRUPT__: specifies the interrupt source to enable or disable.
tushki7 0:60d829a0353a 360 * This parameter can be one of the following values:
tushki7 0:60d829a0353a 361 * @arg SPI_IT_TXE: Tx buffer empty interrupt enable
tushki7 0:60d829a0353a 362 * @arg SPI_IT_RXNE: RX buffer not empty interrupt enable
tushki7 0:60d829a0353a 363 * @arg SPI_IT_ERR: Error interrupt enable
tushki7 0:60d829a0353a 364 * @retval None
tushki7 0:60d829a0353a 365 */
tushki7 0:60d829a0353a 366 #define __HAL_SPI_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 |= (__INTERRUPT__))
tushki7 0:60d829a0353a 367 #define __HAL_SPI_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 &= (~(__INTERRUPT__)))
tushki7 0:60d829a0353a 368
tushki7 0:60d829a0353a 369 /** @brief Check if the specified SPI interrupt source is enabled or disabled.
tushki7 0:60d829a0353a 370 * @param __HANDLE__: specifies the SPI handle.
tushki7 0:60d829a0353a 371 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
tushki7 0:60d829a0353a 372 * @param __INTERRUPT__: specifies the SPI interrupt source to check.
tushki7 0:60d829a0353a 373 * This parameter can be one of the following values:
tushki7 0:60d829a0353a 374 * @arg SPI_IT_TXE: Tx buffer empty interrupt enable
tushki7 0:60d829a0353a 375 * @arg SPI_IT_RXNE: RX buffer not empty interrupt enable
tushki7 0:60d829a0353a 376 * @arg SPI_IT_ERR: Error interrupt enable
tushki7 0:60d829a0353a 377 * @retval The new state of __IT__ (TRUE or FALSE).
tushki7 0:60d829a0353a 378 */
tushki7 0:60d829a0353a 379 #define __HAL_SPI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
tushki7 0:60d829a0353a 380
tushki7 0:60d829a0353a 381 /** @brief Check whether the specified SPI flag is set or not.
tushki7 0:60d829a0353a 382 * @param __HANDLE__: specifies the SPI handle.
tushki7 0:60d829a0353a 383 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
tushki7 0:60d829a0353a 384 * @param __FLAG__: specifies the flag to check.
tushki7 0:60d829a0353a 385 * This parameter can be one of the following values:
tushki7 0:60d829a0353a 386 * @arg SPI_FLAG_RXNE: Receive buffer not empty flag
tushki7 0:60d829a0353a 387 * @arg SPI_FLAG_TXE: Transmit buffer empty flag
tushki7 0:60d829a0353a 388 * @arg SPI_FLAG_CRCERR: CRC error flag
tushki7 0:60d829a0353a 389 * @arg SPI_FLAG_MODF: Mode fault flag
tushki7 0:60d829a0353a 390 * @arg SPI_FLAG_OVR: Overrun flag
tushki7 0:60d829a0353a 391 * @arg SPI_FLAG_BSY: Busy flag
tushki7 0:60d829a0353a 392 * @arg SPI_FLAG_FRE: Frame format error flag
tushki7 0:60d829a0353a 393 * @retval The new state of __FLAG__ (TRUE or FALSE).
tushki7 0:60d829a0353a 394 */
tushki7 0:60d829a0353a 395 #define __HAL_SPI_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
tushki7 0:60d829a0353a 396
tushki7 0:60d829a0353a 397 /** @brief Clear the SPI CRCERR pending flag.
tushki7 0:60d829a0353a 398 * @param __HANDLE__: specifies the SPI handle.
tushki7 0:60d829a0353a 399 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
tushki7 0:60d829a0353a 400 * @retval None
tushki7 0:60d829a0353a 401 */
tushki7 0:60d829a0353a 402 #define __HAL_SPI_CLEAR_CRCERRFLAG(__HANDLE__) ((__HANDLE__)->Instance->SR = ~(SPI_FLAG_CRCERR))
tushki7 0:60d829a0353a 403
tushki7 0:60d829a0353a 404 /** @brief Clear the SPI MODF pending flag.
tushki7 0:60d829a0353a 405 * @param __HANDLE__: specifies the SPI handle.
tushki7 0:60d829a0353a 406 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
tushki7 0:60d829a0353a 407 * @retval None
tushki7 0:60d829a0353a 408 */
tushki7 0:60d829a0353a 409 #define __HAL_SPI_CLEAR_MODFFLAG(__HANDLE__) do{(__HANDLE__)->Instance->SR;\
tushki7 0:60d829a0353a 410 (__HANDLE__)->Instance->CR1 &= (~SPI_CR1_SPE);}while(0)
tushki7 0:60d829a0353a 411
tushki7 0:60d829a0353a 412 /** @brief Clear the SPI OVR pending flag.
tushki7 0:60d829a0353a 413 * @param __HANDLE__: specifies the SPI handle.
tushki7 0:60d829a0353a 414 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
tushki7 0:60d829a0353a 415 * @retval None
tushki7 0:60d829a0353a 416 */
tushki7 0:60d829a0353a 417 #define __HAL_SPI_CLEAR_OVRFLAG(__HANDLE__) do{(__HANDLE__)->Instance->DR;\
tushki7 0:60d829a0353a 418 (__HANDLE__)->Instance->SR;}while(0)
tushki7 0:60d829a0353a 419
tushki7 0:60d829a0353a 420 /** @brief Clear the SPI FRE pending flag.
tushki7 0:60d829a0353a 421 * @param __HANDLE__: specifies the SPI handle.
tushki7 0:60d829a0353a 422 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
tushki7 0:60d829a0353a 423 * @retval None
tushki7 0:60d829a0353a 424 */
tushki7 0:60d829a0353a 425 #define __HAL_SPI_CLEAR_FREFLAG(__HANDLE__) ((__HANDLE__)->Instance->SR)
tushki7 0:60d829a0353a 426
tushki7 0:60d829a0353a 427 #define __HAL_SPI_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= SPI_CR1_SPE)
tushki7 0:60d829a0353a 428 #define __HAL_SPI_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~SPI_CR1_SPE)
tushki7 0:60d829a0353a 429
tushki7 0:60d829a0353a 430 #define IS_SPI_CRC_POLYNOMIAL(POLYNOMIAL) (((POLYNOMIAL) >= 0x1) && ((POLYNOMIAL) <= 0xFFFF))
tushki7 0:60d829a0353a 431
tushki7 0:60d829a0353a 432 #define __HAL_SPI_1LINE_TX(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= SPI_CR1_BIDIOE)
tushki7 0:60d829a0353a 433
tushki7 0:60d829a0353a 434 #define __HAL_SPI_1LINE_RX(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~SPI_CR1_BIDIOE)
tushki7 0:60d829a0353a 435
tushki7 0:60d829a0353a 436 #define __HAL_SPI_RESET_CRC(__HANDLE__) do{(__HANDLE__)->Instance->CR1 &= (~SPI_CR1_CRCEN);\
tushki7 0:60d829a0353a 437 (__HANDLE__)->Instance->CR1 |= SPI_CR1_CRCEN;}while(0)
tushki7 0:60d829a0353a 438
tushki7 0:60d829a0353a 439 /* Exported functions --------------------------------------------------------*/
tushki7 0:60d829a0353a 440
tushki7 0:60d829a0353a 441 /* Initialization/de-initialization functions **********************************/
tushki7 0:60d829a0353a 442 HAL_StatusTypeDef HAL_SPI_Init(SPI_HandleTypeDef *hspi);
tushki7 0:60d829a0353a 443 HAL_StatusTypeDef HAL_SPI_DeInit (SPI_HandleTypeDef *hspi);
tushki7 0:60d829a0353a 444 void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi);
tushki7 0:60d829a0353a 445 void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi);
tushki7 0:60d829a0353a 446
tushki7 0:60d829a0353a 447 /* I/O operation functions *****************************************************/
tushki7 0:60d829a0353a 448 HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout);
tushki7 0:60d829a0353a 449 HAL_StatusTypeDef HAL_SPI_Receive(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout);
tushki7 0:60d829a0353a 450 HAL_StatusTypeDef HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
tushki7 0:60d829a0353a 451 HAL_StatusTypeDef HAL_SPI_Transmit_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size);
tushki7 0:60d829a0353a 452 HAL_StatusTypeDef HAL_SPI_Receive_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size);
tushki7 0:60d829a0353a 453 HAL_StatusTypeDef HAL_SPI_TransmitReceive_IT(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
tushki7 0:60d829a0353a 454 HAL_StatusTypeDef HAL_SPI_Transmit_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size);
tushki7 0:60d829a0353a 455 HAL_StatusTypeDef HAL_SPI_Receive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size);
tushki7 0:60d829a0353a 456 HAL_StatusTypeDef HAL_SPI_TransmitReceive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
tushki7 0:60d829a0353a 457 HAL_StatusTypeDef HAL_SPI_DMAPause(SPI_HandleTypeDef *hspi);
tushki7 0:60d829a0353a 458 HAL_StatusTypeDef HAL_SPI_DMAResume(SPI_HandleTypeDef *hspi);
tushki7 0:60d829a0353a 459 HAL_StatusTypeDef HAL_SPI_DMAStop(SPI_HandleTypeDef *hspi);
tushki7 0:60d829a0353a 460
tushki7 0:60d829a0353a 461 void HAL_SPI_IRQHandler(SPI_HandleTypeDef *hspi);
tushki7 0:60d829a0353a 462 void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi);
tushki7 0:60d829a0353a 463 void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi);
tushki7 0:60d829a0353a 464 void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi);
tushki7 0:60d829a0353a 465 void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi);
tushki7 0:60d829a0353a 466 void HAL_SPI_TxHalfCpltCallback(SPI_HandleTypeDef *hspi);
tushki7 0:60d829a0353a 467 void HAL_SPI_RxHalfCpltCallback(SPI_HandleTypeDef *hspi);
tushki7 0:60d829a0353a 468 void HAL_SPI_TxRxHalfCpltCallback(SPI_HandleTypeDef *hspi);
tushki7 0:60d829a0353a 469
tushki7 0:60d829a0353a 470 /* Peripheral State and Control functions **************************************/
tushki7 0:60d829a0353a 471 HAL_SPI_StateTypeDef HAL_SPI_GetState(SPI_HandleTypeDef *hspi);
tushki7 0:60d829a0353a 472 HAL_SPI_ErrorTypeDef HAL_SPI_GetError(SPI_HandleTypeDef *hspi);
tushki7 0:60d829a0353a 473
tushki7 0:60d829a0353a 474 /**
tushki7 0:60d829a0353a 475 * @}
tushki7 0:60d829a0353a 476 */
tushki7 0:60d829a0353a 477
tushki7 0:60d829a0353a 478 /**
tushki7 0:60d829a0353a 479 * @}
tushki7 0:60d829a0353a 480 */
tushki7 0:60d829a0353a 481
tushki7 0:60d829a0353a 482 #ifdef __cplusplus
tushki7 0:60d829a0353a 483 }
tushki7 0:60d829a0353a 484 #endif
tushki7 0:60d829a0353a 485
tushki7 0:60d829a0353a 486 #endif /* __STM32F4xx_HAL_SPI_H */
tushki7 0:60d829a0353a 487
tushki7 0:60d829a0353a 488 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/