1 /**
2   ******************************************************************************
3   * @file    stm32f4xx_spdifrx.h
4   * @author  MCD Application Team
5   * @version V1.5.1
6   * @date    22-May-2015
7   * @brief   This file contains all the functions prototypes for the SPDIFRX firmware
8   *          library.
9   ******************************************************************************
10   * @attention
11   *
12   * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
13   *
14   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
15   * You may not use this file except in compliance with the License.
16   * You may obtain a copy of the License at:
17   *
18   *        http://www.st.com/software_license_agreement_liberty_v2
19   *
20   * Unless required by applicable law or agreed to in writing, software
21   * distributed under the License is distributed on an "AS IS" BASIS,
22   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23   * See the License for the specific language governing permissions and
24   * limitations under the License.
25   *
26   ******************************************************************************
27   */
28 
29 /* Define to prevent recursive inclusion -------------------------------------*/
30 #ifndef __STM32F4xx_SPDIFRX_H
31 #define __STM32F4xx_SPDIFRX_H
32 
33 #ifdef __cplusplus
34  extern "C" {
35 #endif
36 
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f4xx.h"
39 
40 /** @addtogroup STM32F4xx_StdPeriph_Driver
41   * @{
42   */
43 
44 /** @addtogroup SPDIFRX
45   * @{
46   */
47 #if defined(STM32F446xx)
48 /* Exported types ------------------------------------------------------------*/
49 /**
50   * @brief  SPDIFRX Init structure definition
51   */
52 typedef struct
53 {
54   uint32_t SPDIFRX_InputSelection;           /*!< Specifies the SPDIFRX input selection.
55                                                 This parameter can be a value of @ref SPDIFRX_Input_Selection */
56 
57   uint32_t SPDIFRX_Retries;                  /*!< Specifies the Maximum allowed re-tries during synchronization phase.
58                                                 This parameter can be a value of @ref SPDIFRX_Max_Retries */
59 
60   uint32_t SPDIFRX_WaitForActivity;          /*!< Specifies the wait for activity on SPDIFRX selected input.
61                                                 This parameter can be a value of @ref SPDIFRX_Wait_For_Activity. */
62 
63   uint32_t SPDIFRX_ChannelSelection;         /*!< Specifies whether the control flow will take the channel status from channel A or B.
64                                                 This parameter can be a value of @ref SPDIFRX_Channel_Selection */
65 
66   uint32_t SPDIFRX_DataFormat;               /*!< Specifies the Data samples format (LSB, MSB, ...).
67                                                 This parameter can be a value of @ref SPDIFRX_Data_Format */
68 
69   uint32_t SPDIFRX_StereoMode;               /*!< Specifies whether the peripheral is in stereo or mono mode.
70                                                 This parameter can be a value of @ref SPDIFRX_Stereo_Mode */
71 }SPDIFRX_InitTypeDef;
72 
73 
74 /* Exported constants --------------------------------------------------------*/
75 
76 /** @defgroup SPDIFRX_Exported_Constants
77   * @{
78   */
79 #define IS_SPDIFRX_PERIPH(PERIPH) (((PERIPH) == SPDIFRX))
80 
81 /** @defgroup SPDIFRX_Input_Selection SPDIFRX Input Selection
82   * @{
83   */
84 #define SPDIFRX_Input_IN0               ((uint32_t)0x00000000)
85 #define SPDIFRX_Input_IN1               ((uint32_t)0x00010000)
86 #define SPDIFRX_Input_IN2               ((uint32_t)0x00020000)
87 #define SPDIFRX_Input_IN3               ((uint32_t)0x00030000)
88 #define IS_SPDIFRX_INPUT_SELECT(INPUT)  (((INPUT) == SPDIFRX_Input_IN1) || \
89                                          ((INPUT) == SPDIFRX_Input_IN2) || \
90                                          ((INPUT) == SPDIFRX_Input_IN3)  || \
91                                          ((INPUT) == SPDIFRX_Input_IN0))
92 /**
93   * @}
94   */
95 
96 /** @defgroup SPDIFRX_Max_Retries SPDIFRX Max Retries
97   * @{
98   */
99 #define SPDIFRX_1MAX_RETRIES               ((uint32_t)0x00000000)
100 #define SPDIFRX_4MAX_RETRIES               ((uint32_t)0x00001000)
101 #define SPDIFRX_16MAX_RETRIES              ((uint32_t)0x00002000)
102 #define SPDIFRX_64MAX_RETRIES              ((uint32_t)0x00003000)
103 #define IS_SPDIFRX_MAX_RETRIES(RET)   (((RET) == SPDIFRX_1MAX_RETRIES) || \
104                                        ((RET) == SPDIFRX_4MAX_RETRIES) || \
105                                        ((RET) == SPDIFRX_16MAX_RETRIES)  || \
106                                        ((RET) == SPDIFRX_64MAX_RETRIES))
107 /**
108   * @}
109   */
110 
111 /** @defgroup SPDIFRX_Wait_For_Activity SPDIFRX Wait For Activity
112   * @{
113   */
114 #define SPDIFRX_WaitForActivity_Off                 ((uint32_t)0x00000000)
115 #define SPDIFRX_WaitForActivity_On                  ((uint32_t)SPDIFRX_CR_WFA)
116 #define IS_SPDIFRX_WAIT_FOR_ACTIVITY(VAL)    (((VAL) == SPDIFRX_WaitForActivity_On) || \
117                                               ((VAL) == SPDIFRX_WaitForActivity_Off))
118 /**
119   * @}
120   */
121 
122 /** @defgroup SPDIFRX_ChannelSelection SPDIFRX Channel Selection
123   * @{
124   */
125 #define SPDIFRX_Select_Channel_A      ((uint32_t)0x00000000)
126 #define SPDIFRX_Select_Channel_B      ((uint32_t)SPDIFRX_CR_CHSEL)
127 #define IS_SPDIFRX_CHANNEL(CHANNEL)   (((CHANNEL) == SPDIFRX_Select_Channel_A) || \
128                                        ((CHANNEL) == SPDIFRX_Select_Channel_B))
129 /**
130   * @}
131   */
132 
133 /** @defgroup SPDIFRX_Block_Synchronization SPDIFRX Block Synchronization
134   * @{
135   */
136 #define SPDIFRX_LSB_DataFormat                   ((uint32_t)0x00000000)
137 #define SPDIFRX_MSB_DataFormat                   ((uint32_t)0x00000010)
138 #define SPDIFRX_32BITS_DataFormat                ((uint32_t)0x00000020)
139 #define IS_SPDIFRX_DATA_FORMAT(FORMAT)    (((FORMAT) == SPDIFRX_LSB_DataFormat) || \
140                                            ((FORMAT) == SPDIFRX_MSB_DataFormat) || \
141                                            ((FORMAT) == SPDIFRX_32BITS_DataFormat))
142 /**
143   * @}
144   */
145 
146 /** @defgroup SPDIFRX_StereoMode SPDIFRX StereoMode
147   * @{
148   */
149 #define SPDIFRX_StereoMode_Disabled          ((uint32_t)0x00000000)
150 #define SPDIFRX_StereoMode_Enabled           ((uint32_t)SPDIFRX_CR_RXSTEO)
151 #define IS_STEREO_MODE(MODE)  (((MODE) == SPDIFRX_StereoMode_Disabled) || \
152                                ((MODE) == SPDIFRX_StereoMode_Enabled))
153 /**
154   * @}
155   */
156 
157 /** @defgroup SPDIFRX_State SPDIFRX State
158   * @{
159   */
160 #define SPDIFRX_STATE_IDLE    ((uint32_t)0x00000000)
161 #define SPDIFRX_STATE_SYNC    ((uint32_t)0x00000001)
162 #define SPDIFRX_STATE_RCV     ((uint32_t)SPDIFRX_CR_SPDIFEN)
163 #define IS_SPDIFRX_STATE(STATE)    (((STATE) == SPDIFRX_STATE_IDLE) || \
164                                     ((STATE) == SPDIFRX_STATE_SYNC) || \
165                                     ((STATE) == SPDIFRX_STATE_RCV))
166 /**
167   * @}
168   */
169 
170 /** @defgroup SPDIFRX_Interrupts_Definition SPDIFRX Interrupts Definition
171   * @{
172   */
173 #define SPDIFRX_IT_RXNE                       ((uint32_t)SPDIFRX_IMR_RXNEIE)
174 #define SPDIFRX_IT_CSRNE                      ((uint32_t)SPDIFRX_IMR_CSRNEIE)
175 #define SPDIFRX_IT_PERRIE                     ((uint32_t)SPDIFRX_IMR_PERRIE)
176 #define SPDIFRX_IT_OVRIE                      ((uint32_t)SPDIFRX_IMR_OVRIE)
177 #define SPDIFRX_IT_SBLKIE                     ((uint32_t)SPDIFRX_IMR_SBLKIE)
178 #define SPDIFRX_IT_SYNCDIE                    ((uint32_t)SPDIFRX_IMR_SYNCDIE)
179 #define SPDIFRX_IT_IFEIE                      ((uint32_t)SPDIFRX_IMR_IFEIE )
180 #define IS_SPDIFRX_CONFIG_IT(IT)    (((IT) == SPDIFRX_IT_RXNE)   || \
181                                      ((IT) == SPDIFRX_IT_CSRNE)   || \
182                                      ((IT) == SPDIFRX_IT_PERRIE)  || \
183                                      ((IT) == SPDIFRX_IT_OVRIE)   || \
184                                      ((IT) == SPDIFRX_IT_SBLKIE)  || \
185                                      ((IT) == SPDIFRX_IT_SYNCDIE) || \
186                                      ((IT) == SPDIFRX_IT_IFEIE))
187 /**
188   * @}
189   */
190 
191 /** @defgroup SPDIFRX_Flags_Definition SPDIFRX Flags Definition
192   * @{
193   */
194 #define SPDIFRX_FLAG_RXNE                   ((uint32_t)SPDIFRX_SR_RXNE)
195 #define SPDIFRX_FLAG_CSRNE                  ((uint32_t)SPDIFRX_SR_CSRNE)
196 #define SPDIFRX_FLAG_PERR                   ((uint32_t)SPDIFRX_SR_PERR)
197 #define SPDIFRX_FLAG_OVR                    ((uint32_t)SPDIFRX_SR_OVR)
198 #define SPDIFRX_FLAG_SBD                    ((uint32_t)SPDIFRX_SR_SBD)
199 #define SPDIFRX_FLAG_SYNCD                  ((uint32_t)SPDIFRX_SR_SYNCD)
200 #define SPDIFRX_FLAG_FERR                   ((uint32_t)SPDIFRX_SR_FERR)
201 #define SPDIFRX_FLAG_SERR                   ((uint32_t)SPDIFRX_SR_SERR)
202 #define SPDIFRX_FLAG_TERR                   ((uint32_t)SPDIFRX_SR_TERR)
203 #define IS_SPDIFRX_FLAG(FLAG)    (((FLAG) == SPDIFRX_FLAG_RXNE) || ((FLAG) == SPDIFRX_FLAG_CSRNE) || \
204                                   ((FLAG) == SPDIFRX_FLAG_PERR) || ((FLAG) == SPDIFRX_FLAG_OVR) || \
205                                   ((FLAG) == SPDIFRX_SR_SBD) || ((FLAG) == SPDIFRX_SR_SYNCD) || \
206                                   ((FLAG) == SPDIFRX_SR_FERR) || ((FLAG) == SPDIFRX_SR_SERR) || \
207 				  ((FLAG) == SPDIFRX_SR_TERR))
208 #define IS_SPDIFRX_CLEAR_FLAG(FLAG)    (((FLAG) == SPDIFRX_FLAG_PERR) || ((FLAG) == SPDIFRX_FLAG_OVR)   || \
209                                         ((FLAG) == SPDIFRX_SR_SBD) || ((FLAG) == SPDIFRX_SR_SYNCD))
210 /**
211   * @}
212   */
213 
214 /**
215   * @}
216   */
217 
218 /* Exported macro ------------------------------------------------------------*/
219 /* Exported functions --------------------------------------------------------*/
220 
221 /*  Function used to set the SPDIFRX configuration to the default reset state *****/
222 void SPDIFRX_DeInit(void);
223 
224 /* Initialization and Configuration functions *********************************/
225 void SPDIFRX_Init(SPDIFRX_InitTypeDef* SPDIFRX_InitStruct);
226 void SPDIFRX_StructInit(SPDIFRX_InitTypeDef* SPDIFRX_InitStruct);
227 void SPDIFRX_Cmd(uint32_t SPDIFRX_State);
228 void SPDIFRX_SetPreambleTypeBit(FunctionalState NewState);
229 void SPDIFRX_SetUserDataChannelStatusBits(FunctionalState NewState);
230 void SPDIFRX_SetValidityBit(FunctionalState NewState);
231 void SPDIFRX_SetParityBit(FunctionalState NewState);
232 
233 /* Data transfers functions ***************************************************/
234 uint32_t SPDIFRX_ReceiveData(void);
235 
236 /* DMA transfers management functions *****************************************/
237 void SPDIFRX_RxDMACmd(FunctionalState NewState);
238 void SPDIFRX_CbDMACmd(FunctionalState NewState);
239 
240 /* Interrupts and flags management functions **********************************/
241 void SPDIFRX_ITConfig(uint32_t SPDIFRX_IT, FunctionalState NewState);
242 FlagStatus SPDIFRX_GetFlagStatus(uint32_t SPDIFRX_FLAG);
243 void SPDIFRX_ClearFlag(uint32_t SPDIFRX_FLAG);
244 ITStatus SPDIFRX_GetITStatus(uint32_t SPDIFRX_IT);
245 void SPDIFRX_ClearITPendingBit(uint32_t SPDIFRX_IT);
246 
247 #endif /* STM32F446xx */
248 /**
249   * @}
250   */
251 
252 /**
253   * @}
254   */
255 
256 #ifdef __cplusplus
257 }
258 #endif
259 
260 #endif /*__STM32F4xx_SPDIFRX_H */
261 
262 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
263