1 /**
2   ******************************************************************************
3   * @file    stm32g4xx_hal_fmac.h
4   * @author  MCD Application Team
5   * @brief   Header for stm32g4xx_hal_fmac.c module
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2019 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32G4xx_HAL_FMAC_H
21 #define STM32G4xx_HAL_FMAC_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32g4xx_hal_def.h"
29 
30 #if defined(FMAC)
31 /** @addtogroup STM32G4xx_HAL_Driver
32   * @{
33   */
34 
35 /** @addtogroup FMAC
36   * @{
37   */
38 
39 /* Exported types ------------------------------------------------------------*/
40 /** @defgroup FMAC_Exported_Types FMAC Exported Types
41   * @{
42   */
43 
44 /**
45   * @brief  FMAC HAL State Structure definition
46   */
47 typedef enum
48 {
49   HAL_FMAC_STATE_RESET       = 0x00U,            /*!< FMAC not yet initialized or disabled                           */
50   HAL_FMAC_STATE_READY       = 0x20U,            /*!< FMAC initialized and ready for use                             */
51   HAL_FMAC_STATE_BUSY        = 0x24U,            /*!< FMAC internal process is ongoing                               */
52   HAL_FMAC_STATE_BUSY_RD     = 0x25U,            /*!< FMAC reading configuration is ongoing                          */
53   HAL_FMAC_STATE_BUSY_WR     = 0x26U,            /*!< FMAC writing configuration is ongoing                          */
54   HAL_FMAC_STATE_TIMEOUT     = 0xA0U,            /*!< FMAC in Timeout state                                          */
55   HAL_FMAC_STATE_ERROR       = 0xE0U             /*!< FMAC in Error state                                            */
56 } HAL_FMAC_StateTypeDef;
57 
58 /**
59   * @brief  FMAC Handle Structure definition
60   */
61 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
62 typedef struct __FMAC_HandleTypeDef
63 #else
64 typedef struct
65 #endif  /* USE_HAL_FMAC_REGISTER_CALLBACKS */
66 {
67   FMAC_TypeDef               *Instance;          /*!< Register base address */
68 
69   uint32_t                   FilterParam;        /*!< Filter configuration (operation and parameters).
70                                                       Set to 0 if no valid configuration was applied. */
71 
72   uint8_t                    InputAccess;       /*!< Access to the input buffer (internal memory area): DMA, IT, Polling, None.
73                                                      This parameter can be a value of @ref FMAC_Buffer_Access. */
74 
75   uint8_t                    OutputAccess;      /*!< Access to the output buffer (internal memory area): DMA, IT, Polling, None.
76                                                      This parameter can be a value of @ref FMAC_Buffer_Access. */
77 
78   int16_t                    *pInput;            /*!< Pointer to FMAC input data buffer */
79 
80   uint16_t                   InputCurrentSize;   /*!< Number of the input elements already written into FMAC */
81 
82   uint16_t                   *pInputSize;        /*!< Number of input elements to write (memory allocated to pInput).
83                                                       In case of early interruption of the filter operation,
84                                                       its value will be updated. */
85 
86   int16_t                    *pOutput;           /*!< Pointer to FMAC output data buffer */
87 
88   uint16_t                   OutputCurrentSize;  /*!< Number of the output elements already read from FMAC */
89 
90   uint16_t                   *pOutputSize;       /*!< Number of output elements to read (memory allocated to pOutput).
91                                                       In case of early interruption of the filter operation,
92                                                       its value will be updated. */
93 
94   DMA_HandleTypeDef          *hdmaIn;            /*!< FMAC peripheral input data DMA handle parameters */
95 
96   DMA_HandleTypeDef          *hdmaOut;           /*!< FMAC peripheral output data DMA handle parameters */
97 
98   DMA_HandleTypeDef          *hdmaPreload;       /*!< FMAC peripheral preloaded data (X1, X2 and Y) DMA handle parameters */
99 
100 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
101   void (* ErrorCallback)(struct __FMAC_HandleTypeDef *hfmac);               /*!< FMAC error callback                  */
102 
103   void (* HalfGetDataCallback)(struct __FMAC_HandleTypeDef *hfmac);         /*!< FMAC get half data callback          */
104 
105   void (* GetDataCallback)(struct __FMAC_HandleTypeDef *hfmac);             /*!< FMAC get data callback               */
106 
107   void (* HalfOutputDataReadyCallback)(struct __FMAC_HandleTypeDef *hfmac); /*!< FMAC half output data ready callback */
108 
109   void (* OutputDataReadyCallback)(struct __FMAC_HandleTypeDef *hfmac);     /*!< FMAC output data ready callback      */
110 
111   void (* FilterConfigCallback)(struct __FMAC_HandleTypeDef *hfmac);        /*!< FMAC filter configuration callback   */
112 
113   void (* FilterPreloadCallback)(struct __FMAC_HandleTypeDef *hfmac);       /*!< FMAC filter preload callback         */
114 
115   void (* MspInitCallback)(struct __FMAC_HandleTypeDef *hfmac);             /*!< FMAC Msp Init callback               */
116 
117   void (* MspDeInitCallback)(struct __FMAC_HandleTypeDef *hfmac);           /*!< FMAC Msp DeInit callback             */
118 
119 #endif /* (USE_HAL_FMAC_REGISTER_CALLBACKS) */
120 
121   HAL_LockTypeDef            Lock;               /*!< FMAC locking object */
122 
123   __IO HAL_FMAC_StateTypeDef State;              /*!< FMAC state related to global handle management
124                                                       This parameter can be a value of @ref HAL_FMAC_StateTypeDef */
125 
126   __IO HAL_FMAC_StateTypeDef RdState;            /*!< FMAC state related to read operations (access to Y buffer)
127                                                       This parameter can be a value of @ref HAL_FMAC_StateTypeDef */
128 
129   __IO HAL_FMAC_StateTypeDef WrState;            /*!< FMAC state related to write operations (access to X1 buffer)
130                                                       This parameter can be a value of @ref HAL_FMAC_StateTypeDef */
131 
132   __IO uint32_t              ErrorCode;          /*!< FMAC peripheral error code
133                                                       This parameter can be a value of @ref FMAC_Error_Code */
134 
135 } FMAC_HandleTypeDef;
136 
137 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
138 /**
139   * @brief  FMAC Callback ID enumeration definition
140   */
141 typedef enum
142 {
143   HAL_FMAC_ERROR_CB_ID                  = 0x00U, /*!< FMAC error callback ID                  */
144   HAL_FMAC_HALF_GET_DATA_CB_ID          = 0x01U, /*!< FMAC get half data callback ID          */
145   HAL_FMAC_GET_DATA_CB_ID               = 0x02U, /*!< FMAC get data callback ID               */
146   HAL_FMAC_HALF_OUTPUT_DATA_READY_CB_ID = 0x03U, /*!< FMAC half output data ready callback ID */
147   HAL_FMAC_OUTPUT_DATA_READY_CB_ID      = 0x04U, /*!< FMAC output data ready callback ID      */
148   HAL_FMAC_FILTER_CONFIG_CB_ID          = 0x05U, /*!< FMAC filter configuration callback ID   */
149   HAL_FMAC_FILTER_PRELOAD_CB_ID         = 0x06U, /*!< FMAC filter preload callback ID         */
150 
151   HAL_FMAC_MSPINIT_CB_ID                = 0x07U, /*!< FMAC MspInit callback ID                */
152   HAL_FMAC_MSPDEINIT_CB_ID              = 0x08U, /*!< FMAC MspDeInit callback ID              */
153 } HAL_FMAC_CallbackIDTypeDef;
154 
155 /**
156   * @brief  HAL FMAC Callback pointer definition
157   */
158 typedef  void (*pFMAC_CallbackTypeDef)(FMAC_HandleTypeDef *hfmac);  /*!< pointer to an FMAC callback function */
159 
160 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
161 
162 /**
163   * @brief  FMAC Filter Configuration Structure definition
164   */
165 typedef struct
166 {
167   uint8_t                    InputBaseAddress;  /*!< Base address of the input buffer (X1) within the internal memory (0x00 to 0xFF).
168                                                      Ignored if InputBufferSize is set to 0
169                                                      (previous configuration kept).
170                                                      Note: the buffers can overlap or even coincide exactly. */
171 
172   uint8_t                    InputBufferSize;   /*!< Number of 16-bit words allocated to the input buffer (including the optional "headroom").
173                                                      0 if a previous configuration should be kept. */
174 
175   uint32_t                   InputThreshold;    /*!< Input threshold: the buffer full flag will be set if the number of free spaces
176                                                      in the buffer is lower than this threshold.
177                                                      This parameter can be a value
178                                                      of @ref FMAC_Data_Buffer_Threshold. */
179 
180   uint8_t                    CoeffBaseAddress;  /*!< Base address of the coefficient buffer (X2) within the internal memory (0x00 to 0xFF).
181                                                      Ignored if CoeffBufferSize is set to 0
182                                                      (previous configuration kept).
183                                                      Note: the buffers can overlap or even coincide exactly. */
184 
185   uint8_t                    CoeffBufferSize;   /*!< Number of 16-bit words allocated to the coefficient buffer.
186                                                      0 if a previous configuration should be kept. */
187 
188   uint8_t                    OutputBaseAddress; /*!< Base address of the output buffer (Y) within the internal memory (0x00 to 0xFF).
189                                                      Ignored if OuputBufferSize is set to 0
190                                                      (previous configuration kept).
191                                                      Note: the buffers can overlap or even coincide exactly. */
192 
193   uint8_t                    OutputBufferSize;  /*!< Number of 16-bit words allocated to the output buffer (including the optional "headroom").
194                                                      0 if a previous configuration should be kept. */
195 
196   uint32_t                   OutputThreshold;   /*!< Output threshold: the buffer empty flag will be set if the number of unread values
197                                                      in the buffer is lower than this threshold.
198                                                      This parameter can be a value
199                                                      of @ref FMAC_Data_Buffer_Threshold. */
200 
201   int16_t                    *pCoeffA;          /*!< [IIR only] Initialization of the coefficient vector A.
202                                                      If not needed, it should be set to NULL. */
203 
204   uint8_t                    CoeffASize;        /*!< Size of the coefficient vector A. */
205 
206   int16_t                    *pCoeffB;          /*!< Initialization of the coefficient vector B.
207                                                      If not needed (re-use of a previously loaded buffer),
208                                                      it should be set to NULL. */
209 
210   uint8_t                    CoeffBSize;        /*!< Size of the coefficient vector B. */
211 
212   uint8_t                    InputAccess;       /*!< Access to the input buffer (internal memory area): DMA, IT, Polling, None.
213                                                      This parameter can be a value of @ref FMAC_Buffer_Access. */
214 
215   uint8_t                    OutputAccess;      /*!< Access to the output buffer (internal memory area): DMA, IT, Polling, None.
216                                                      This parameter can be a value of @ref FMAC_Buffer_Access. */
217 
218   uint32_t                   Clip;              /*!< Enable or disable the clipping feature. If the q1.15 range is exceeded, wrapping
219                                                      is done when the clipping feature is disabled
220                                                      and saturation is done when the clipping feature is enabled.
221                                                      This parameter can be a value of @ref FMAC_Clip_State. */
222 
223   uint32_t                   Filter;            /*!< Filter type.
224                                                      This parameter can be a value
225                                                      of @ref FMAC_Functions (filter related values). */
226 
227   uint8_t                    P;                 /*!< Parameter P (vector length, number of filter taps, etc.). */
228 
229   uint8_t                    Q;                 /*!< Parameter Q (vector length, etc.). Ignored if not needed. */
230 
231   uint8_t                    R;                 /*!< Parameter R (gain, etc.). Ignored if not needed. */
232 
233 } FMAC_FilterConfigTypeDef;
234 
235 /**
236   * @}
237   */
238 
239 
240 /* Exported constants --------------------------------------------------------*/
241 
242 
243 /** @defgroup FMAC_Exported_Constants FMAC Exported Constants
244   * @{
245   */
246 
247 /** @defgroup FMAC_Error_Code FMAC Error code
248   * @{
249   */
250 #define HAL_FMAC_ERROR_NONE                0x00000000U /*!< No error               */
251 #define HAL_FMAC_ERROR_SAT                 0x00000001U /*!< Saturation error       */
252 #define HAL_FMAC_ERROR_UNFL                0x00000002U /*!< Underflow error        */
253 #define HAL_FMAC_ERROR_OVFL                0x00000004U /*!< Overflow error         */
254 #define HAL_FMAC_ERROR_DMA                 0x00000008U /*!< DMA error              */
255 #define HAL_FMAC_ERROR_RESET               0x00000010U /*!< Reset error            */
256 #define HAL_FMAC_ERROR_PARAM               0x00000020U /*!< Parameter error        */
257 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
258 #define HAL_FMAC_ERROR_INVALID_CALLBACK    0x00000040U /*!< Invalid Callback error */
259 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
260 #define HAL_FMAC_ERROR_TIMEOUT             0x00000080U /*!< Timeout error          */
261 
262 /**
263   * @}
264   */
265 
266 /** @defgroup FMAC_Functions FMAC Functions
267   * @{
268   */
269 #define FMAC_FUNC_LOAD_X1                  (FMAC_PARAM_FUNC_0)                                        /*!< Load X1 buffer                            */
270 #define FMAC_FUNC_LOAD_X2                  (FMAC_PARAM_FUNC_1)                                        /*!< Load X2 buffer                            */
271 #define FMAC_FUNC_LOAD_Y                   (FMAC_PARAM_FUNC_1 | FMAC_PARAM_FUNC_0)                    /*!< Load Y buffer                             */
272 #define FMAC_FUNC_CONVO_FIR                (FMAC_PARAM_FUNC_3)                                        /*!< Convolution (FIR filter)                  */
273 #define FMAC_FUNC_IIR_DIRECT_FORM_1        (FMAC_PARAM_FUNC_3 | FMAC_PARAM_FUNC_0)                    /*!< IIR filter (direct form 1)                */
274 /**
275   * @}
276   */
277 
278 /** @defgroup FMAC_Data_Buffer_Threshold FMAC Data Buffer Threshold
279   * @{
280   * @note     This parameter sets a watermark for buffer full (input) or buffer empty (output).
281   */
282 #define FMAC_THRESHOLD_1                   0x00000000U    /*!< Input: Buffer full flag set if the number of free spaces in the buffer is less than 1.
283                                                                 Output: Buffer empty flag set if the number
284                                                                 of unread values in the buffer is less than 1. */
285 #define FMAC_THRESHOLD_2                   0x01000000U    /*!< Input: Buffer full flag set if the number of free spaces in the buffer is less than 2.
286                                                                 Output: Buffer empty flag set if the number
287                                                                 of unread values in the buffer is less than 2. */
288 #define FMAC_THRESHOLD_4                   0x02000000U    /*!< Input: Buffer full flag set if the number of free spaces in the buffer is less than 4.
289                                                                 Output: Buffer empty flag set if the number
290                                                                 of unread values in the buffer is less than 4. */
291 #define FMAC_THRESHOLD_8                   0x03000000U    /*!< Input: Buffer full flag set if the number of free spaces in the buffer is less than 8.
292                                                                 Output: Buffer empty flag set if the number
293                                                                 of unread values in the buffer is less than 8. */
294 #define FMAC_THRESHOLD_NO_VALUE            0xFFFFFFFFU    /*!< The configured threshold value shouldn't be changed */
295 /**
296   * @}
297   */
298 
299 /** @defgroup FMAC_Buffer_Access FMAC Buffer Access
300   * @{
301   */
302 #define FMAC_BUFFER_ACCESS_NONE            0x00U           /*!< Buffer handled by an external IP (ADC for instance) */
303 #define FMAC_BUFFER_ACCESS_DMA             0x01U           /*!< Buffer accessed through DMA */
304 #define FMAC_BUFFER_ACCESS_POLLING         0x02U           /*!< Buffer accessed through polling */
305 #define FMAC_BUFFER_ACCESS_IT              0x03U           /*!< Buffer accessed through interruptions */
306 /**
307   * @}
308   */
309 
310 /** @defgroup FMAC_Clip_State FMAC Clip State
311   * @{
312   */
313 #define FMAC_CLIP_DISABLED                 0x00000000U     /*!< Clipping disabled */
314 #define FMAC_CLIP_ENABLED                  FMAC_CR_CLIPEN  /*!< Clipping enabled */
315 /**
316   * @}
317   */
318 
319 /** @defgroup FMAC_Flags  FMAC status flags
320   * @{
321   */
322 #define FMAC_FLAG_YEMPTY                   FMAC_SR_YEMPTY  /*!< Y Buffer Empty Flag */
323 #define FMAC_FLAG_X1FULL                   FMAC_SR_X1FULL  /*!< X1 Buffer Full Flag */
324 #define FMAC_FLAG_OVFL                     FMAC_SR_OVFL    /*!< Overflow Error Flag */
325 #define FMAC_FLAG_UNFL                     FMAC_SR_UNFL    /*!< Underflow Error Flag */
326 #define FMAC_FLAG_SAT                      FMAC_SR_SAT     /*!< Saturation Error Flag (this helps in debugging a filter) */
327 /**
328   * @}
329   */
330 
331 /** @defgroup FMAC_Interrupts_Enable FMAC Interrupts Enable bit
332   * @{
333   */
334 #define FMAC_IT_RIEN                       FMAC_CR_RIEN    /*!< Read Interrupt Enable */
335 #define FMAC_IT_WIEN                       FMAC_CR_WIEN    /*!< Write Interrupt Enable */
336 #define FMAC_IT_OVFLIEN                    FMAC_CR_OVFLIEN /*!< Overflow Error Interrupt Enable */
337 #define FMAC_IT_UNFLIEN                    FMAC_CR_UNFLIEN /*!< Underflow Error Interrupt Enable */
338 #define FMAC_IT_SATIEN                     FMAC_CR_SATIEN  /*!< Saturation Error Interrupt Enable (this helps in debugging a filter) */
339 /**
340   * @}
341   */
342 
343 /**
344   * @}
345   */
346 
347 
348 /* External variables --------------------------------------------------------*/
349 /** @defgroup FMAC_External_variables FMAC External variables
350   * @{
351   */
352 /**
353   * @}
354   */
355 
356 /* Exported macros -----------------------------------------------------------*/
357 /** @defgroup FMAC_Exported_Macros FMAC Exported Macros
358   * @{
359   */
360 
361 /** @brief  Reset FMAC handle state.
362   * @param  __HANDLE__ FMAC handle.
363   * @retval None
364   */
365 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
366 #define __HAL_FMAC_RESET_HANDLE_STATE(__HANDLE__) do{                                           \
367                                                       (__HANDLE__)->State = HAL_FMAC_STATE_RESET; \
368                                                       (__HANDLE__)->MspInitCallback = NULL;       \
369                                                       (__HANDLE__)->MspDeInitCallback = NULL;     \
370                                                     } while(0U)
371 #else
372 #define __HAL_FMAC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_FMAC_STATE_RESET)
373 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
374 
375 /**
376   * @brief  Enable the specified FMAC interrupt
377   * @param  __HANDLE__ FMAC handle.
378   * @param  __INTERRUPT__ FMAC Interrupt.
379   *         This parameter can be any combination of the following values:
380   *            @arg @ref FMAC_IT_RIEN    Read interrupt enable
381   *            @arg @ref FMAC_IT_WIEN    Write interrupt enable
382   *            @arg @ref FMAC_IT_OVFLIEN Overflow error interrupt enable
383   *            @arg @ref FMAC_IT_UNFLIEN Underflow error interrupt enable
384   *            @arg @ref FMAC_IT_SATIEN  Saturation error interrupt enable (this helps in debugging a filter)
385   * @retval None
386   */
387 #define __HAL_FMAC_ENABLE_IT(__HANDLE__, __INTERRUPT__) \
388   (((__HANDLE__)->Instance->CR) |= (__INTERRUPT__))
389 
390 /**
391   * @brief  Disable the FMAC interrupt
392   * @param  __HANDLE__ FMAC handle.
393   * @param  __INTERRUPT__ FMAC Interrupt.
394   *         This parameter can be any combination of the following values:
395   *            @arg @ref FMAC_IT_RIEN    Read interrupt enable
396   *            @arg @ref FMAC_IT_WIEN    Write interrupt enable
397   *            @arg @ref FMAC_IT_OVFLIEN Overflow error interrupt enable
398   *            @arg @ref FMAC_IT_UNFLIEN Underflow error interrupt enable
399   *            @arg @ref FMAC_IT_SATIEN  Saturation error interrupt enable (this helps in debugging a filter)
400   * @retval None
401   */
402 #define __HAL_FMAC_DISABLE_IT(__HANDLE__, __INTERRUPT__) \
403   (((__HANDLE__)->Instance->CR) &= ~(__INTERRUPT__))
404 
405 /** @brief  Check whether the specified FMAC interrupt occurred or not.
406   * @param  __HANDLE__ FMAC handle.
407   * @param  __INTERRUPT__ FMAC interrupt to check.
408   *         This parameter can be any combination of the following values:
409   *            @arg @ref FMAC_FLAG_YEMPTY Y Buffer Empty Flag
410   *            @arg @ref FMAC_FLAG_X1FULL X1 Buffer Full Flag
411   *            @arg @ref FMAC_FLAG_OVFL   Overflow Error Flag
412   *            @arg @ref FMAC_FLAG_UNFL   Underflow Error Flag
413   *            @arg @ref FMAC_FLAG_SAT    Saturation Error Flag
414   * @retval SET (interrupt occurred) or RESET (interrupt did not occurred)
415   */
416 #define __HAL_FMAC_GET_IT(__HANDLE__, __INTERRUPT__) \
417   (((__HANDLE__)->Instance->SR) &= ~(__INTERRUPT__))
418 
419 /** @brief  Clear specified FMAC interrupt status. Dummy macro as the
420             interrupt status flags are read-only.
421   * @param  __HANDLE__ FMAC handle.
422   * @param  __INTERRUPT__ FMAC interrupt to clear.
423   * @retval None
424   */
425 #define __HAL_FMAC_CLEAR_IT(__HANDLE__, __INTERRUPT__)   /* Dummy macro */
426 
427 /** @brief  Check whether the specified FMAC status flag is set or not.
428   * @param  __HANDLE__ FMAC handle.
429   * @param  __FLAG__ FMAC flag to check.
430   *         This parameter can be any combination of the following values:
431   *            @arg @ref FMAC_FLAG_YEMPTY Y Buffer Empty Flag
432   *            @arg @ref FMAC_FLAG_X1FULL X1 Buffer Full Flag
433   *            @arg @ref FMAC_FLAG_OVFL   Overflow Error Flag
434   *            @arg @ref FMAC_FLAG_UNFL   Underflow Error Flag
435   *            @arg @ref FMAC_FLAG_SAT    Saturation error Flag
436   * @retval SET (flag is set) or RESET (flag is reset)
437   */
438 #define __HAL_FMAC_GET_FLAG(__HANDLE__, __FLAG__) \
439   ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
440 
441 /** @brief  Clear specified FMAC status flag. Dummy macro as no
442             flag can be cleared.
443   * @param  __HANDLE__ FMAC handle.
444   * @param  __FLAG__ FMAC flag to clear.
445   * @retval None
446   */
447 #define __HAL_FMAC_CLEAR_FLAG(__HANDLE__, __FLAG__)     /* Dummy macro */
448 
449 /** @brief  Check whether the specified FMAC interrupt is enabled or not.
450   * @param  __HANDLE__ FMAC handle.
451   * @param  __INTERRUPT__ FMAC interrupt to check.
452   *         This parameter can be one of the following values:
453   *            @arg @ref FMAC_IT_RIEN    Read interrupt enable
454   *            @arg @ref FMAC_IT_WIEN    Write interrupt enable
455   *            @arg @ref FMAC_IT_OVFLIEN Overflow error interrupt enable
456   *            @arg @ref FMAC_IT_UNFLIEN Underflow error interrupt enable
457   *            @arg @ref FMAC_IT_SATIEN  Saturation error interrupt enable (this helps in debugging a filter)
458   * @retval FlagStatus
459   */
460 #define __HAL_FMAC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) \
461   (((__HANDLE__)->Instance->CR) & (__INTERRUPT__))
462 
463 /**
464   * @}
465   */
466 
467 /* Private Macros-----------------------------------------------------------*/
468 /** @addtogroup  FMAC_Private_Macros FMAC Private Macros
469   * @{
470   */
471 
472 /**
473   * @brief  Verify the FMAC function.
474   * @param  __FUNCTION__ ID of the function.
475   * @retval SET (__FUNCTION__ is a valid value) or RESET (__FUNCTION__ is invalid)
476   */
477 #define IS_FMAC_FUNCTION(__FUNCTION__) (((__FUNCTION__) == FMAC_FUNC_LOAD_X1)                         || \
478                                         ((__FUNCTION__) == FMAC_FUNC_LOAD_X2)                         || \
479                                         ((__FUNCTION__) == FMAC_FUNC_LOAD_Y)                          || \
480                                         ((__FUNCTION__) == FMAC_FUNC_CONVO_FIR)                       || \
481                                         ((__FUNCTION__) == FMAC_FUNC_IIR_DIRECT_FORM_1))
482 
483 /**
484   * @brief  Verify the FMAC load function used for input data, output data or coefficients.
485   * @param  __FUNCTION__ ID of the load function.
486   * @retval SET (__FUNCTION__ is a valid value) or RESET (__FUNCTION__ is invalid)
487   */
488 #define IS_FMAC_LOAD_FUNCTION(__FUNCTION__) (((__FUNCTION__) == FMAC_FUNC_LOAD_X1)                    || \
489                                              ((__FUNCTION__) == FMAC_FUNC_LOAD_X2)                    || \
490                                              ((__FUNCTION__) == FMAC_FUNC_LOAD_Y))
491 
492 /**
493   * @brief  Verify the FMAC load function used with N values as input or output data.
494   * @param  __FUNCTION__ ID of the load function.
495   * @retval SET (__FUNCTION__ is a valid value) or RESET (__FUNCTION__ is invalid)
496   */
497 #define IS_FMAC_N_LOAD_FUNCTION(__FUNCTION__) (((__FUNCTION__) == FMAC_FUNC_LOAD_X1)                  || \
498                                                ((__FUNCTION__) == FMAC_FUNC_LOAD_Y))
499 
500 /**
501   * @brief  Verify the FMAC load function used with N + M values as coefficients.
502   * @param  __FUNCTION__ ID of the load function.
503   * @retval SET (__FUNCTION__ is a valid value) or RESET (__FUNCTION__ is invalid)
504   */
505 #define IS_FMAC_N_M_LOAD_FUNCTION(__FUNCTION__) ((__FUNCTION__) == FMAC_FUNC_LOAD_X2)
506 
507 /**
508   * @brief  Verify the FMAC filter function.
509   * @param  __FUNCTION__ ID of the filter function.
510   * @retval SET (__FUNCTION__ is a valid value) or RESET (__FUNCTION__ is invalid)
511   */
512 #define IS_FMAC_FILTER_FUNCTION(__FUNCTION__) (((__FUNCTION__) == FMAC_FUNC_CONVO_FIR)                || \
513                                                ((__FUNCTION__) == FMAC_FUNC_IIR_DIRECT_FORM_1))
514 
515 
516 /**
517   * @brief  Verify the FMAC threshold.
518   * @param  __THRESHOLD__ Value of the threshold.
519   * @retval SET (__THRESHOLD__ is a valid value) or RESET (__THRESHOLD__ is invalid)
520   */
521 #define IS_FMAC_THRESHOLD(__THRESHOLD__) (((__THRESHOLD__) == FMAC_THRESHOLD_1)                       || \
522                                           ((__THRESHOLD__) == FMAC_THRESHOLD_2)                       || \
523                                           ((__THRESHOLD__) == FMAC_THRESHOLD_4)                       || \
524                                           ((__THRESHOLD__) == FMAC_THRESHOLD_NO_VALUE)                || \
525                                           ((__THRESHOLD__) == FMAC_THRESHOLD_8))
526 
527 /**
528   * @brief  Verify the FMAC filter parameter P.
529   * @param  __P__ Value of the filter parameter P.
530   * @param  __FUNCTION__ ID of the filter function.
531   * @retval SET (__P__ is a valid value) or RESET (__P__ is invalid)
532   */
533 #define IS_FMAC_PARAM_P(__FUNCTION__, __P__) ( (((__FUNCTION__) == FMAC_FUNC_CONVO_FIR)               && \
534                                                 (((__P__) >= 2U) && ((__P__) <= 127U)))               || \
535                                                (((__FUNCTION__) == FMAC_FUNC_IIR_DIRECT_FORM_1)       && \
536                                                 (((__P__) >= 2U) && ((__P__) <= 64U))) )
537 
538 /**
539   * @brief  Verify the FMAC filter parameter Q.
540   * @param  __Q__ Value of the filter parameter Q.
541   * @param  __FUNCTION__ ID of the filter function.
542   * @retval SET (__Q__ is a valid value) or RESET (__Q__ is invalid)
543   */
544 #define IS_FMAC_PARAM_Q(__FUNCTION__, __Q__) ( ((__FUNCTION__) == FMAC_FUNC_CONVO_FIR)                || \
545                                                (((__FUNCTION__) == FMAC_FUNC_IIR_DIRECT_FORM_1)       && \
546                                                 (((__Q__) >= 1U) && ((__Q__) <= 63U))) )
547 
548 /**
549   * @brief  Verify the FMAC filter parameter R.
550   * @param  __R__ Value of the filter parameter.
551   * @param  __FUNCTION__ ID of the filter function.
552   * @retval SET (__R__ is a valid value) or RESET (__R__ is invalid)
553   */
554 #define IS_FMAC_PARAM_R(__FUNCTION__, __R__) ( (((__FUNCTION__) == FMAC_FUNC_CONVO_FIR)               || \
555                                                 ((__FUNCTION__) == FMAC_FUNC_IIR_DIRECT_FORM_1))      && \
556                                                ((__R__) <= 7U))
557 
558 /**
559   * @brief  Verify the FMAC buffer access.
560   * @param  __BUFFER_ACCESS__ Type of access.
561   * @retval SET (__BUFFER_ACCESS__ is a valid value) or RESET (__BUFFER_ACCESS__ is invalid)
562   */
563 #define IS_FMAC_BUFFER_ACCESS(__BUFFER_ACCESS__) (((__BUFFER_ACCESS__) == FMAC_BUFFER_ACCESS_NONE)    || \
564                                                   ((__BUFFER_ACCESS__) == FMAC_BUFFER_ACCESS_DMA)     || \
565                                                   ((__BUFFER_ACCESS__) == FMAC_BUFFER_ACCESS_POLLING) || \
566                                                   ((__BUFFER_ACCESS__) == FMAC_BUFFER_ACCESS_IT))
567 
568 /**
569   * @brief  Verify the FMAC clip feature.
570   * @param  __CLIP_STATE__ Clip state.
571   * @retval SET (__CLIP_STATE__ is a valid value) or RESET (__CLIP_STATE__ is invalid)
572   */
573 #define IS_FMAC_CLIP_STATE(__CLIP_STATE__) (((__CLIP_STATE__) == FMAC_CLIP_DISABLED)                  || \
574                                             ((__CLIP_STATE__) == FMAC_CLIP_ENABLED))
575 
576 /**
577   * @brief  Check whether the threshold is applicable.
578   * @param  __SIZE__ Size of the matching buffer.
579   * @param  __WM__ Watermark value.
580   * @param  __ACCESS__ Access to the buffer (polling, it, dma, none).
581   * @retval THRESHOLD
582   */
583 #define IS_FMAC_THRESHOLD_APPLICABLE(__SIZE__, __WM__, __ACCESS__) \
584   (( (__SIZE__) >= (((__WM__) == FMAC_THRESHOLD_1)? 1U: \
585                     ((__WM__) == FMAC_THRESHOLD_2)? 2U: \
586                     ((__WM__) == FMAC_THRESHOLD_4)? 4U:8U))&& \
587    ((((__ACCESS__) == FMAC_BUFFER_ACCESS_DMA)&& \
588      ((__WM__) == FMAC_THRESHOLD_1))|| \
589     ((__ACCESS__ )!= FMAC_BUFFER_ACCESS_DMA)))
590 
591 /**
592   * @}
593   */
594 
595 /* Exported functions ------------------------------------------------------- */
596 /** @addtogroup FMAC_Exported_Functions
597   * @{
598   */
599 
600 /** @addtogroup FMAC_Exported_Functions_Group1
601   * @{
602   */
603 /* Initialization and de-initialization functions  ****************************/
604 HAL_StatusTypeDef HAL_FMAC_Init(FMAC_HandleTypeDef *hfmac);
605 HAL_StatusTypeDef HAL_FMAC_DeInit(FMAC_HandleTypeDef *hfmac);
606 void HAL_FMAC_MspInit(FMAC_HandleTypeDef *hfmac);
607 void HAL_FMAC_MspDeInit(FMAC_HandleTypeDef *hfmac);
608 
609 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
610 /* Callbacks Register/UnRegister functions  ***********************************/
611 HAL_StatusTypeDef HAL_FMAC_RegisterCallback(FMAC_HandleTypeDef *hfmac, HAL_FMAC_CallbackIDTypeDef CallbackID,
612                                             pFMAC_CallbackTypeDef pCallback);
613 HAL_StatusTypeDef HAL_FMAC_UnRegisterCallback(FMAC_HandleTypeDef *hfmac, HAL_FMAC_CallbackIDTypeDef CallbackID);
614 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
615 /**
616   * @}
617   */
618 
619 /** @addtogroup FMAC_Exported_Functions_Group2
620   * @{
621   */
622 /* Peripheral Control functions ***********************************************/
623 HAL_StatusTypeDef HAL_FMAC_FilterConfig(FMAC_HandleTypeDef *hfmac, FMAC_FilterConfigTypeDef *pConfig);
624 HAL_StatusTypeDef HAL_FMAC_FilterConfig_DMA(FMAC_HandleTypeDef *hfmac, FMAC_FilterConfigTypeDef *pConfig);
625 HAL_StatusTypeDef HAL_FMAC_FilterPreload(FMAC_HandleTypeDef *hfmac, int16_t *pInput, uint8_t InputSize,
626                                          int16_t *pOutput, uint8_t OutputSize);
627 HAL_StatusTypeDef HAL_FMAC_FilterPreload_DMA(FMAC_HandleTypeDef *hfmac, int16_t *pInput, uint8_t InputSize,
628                                              int16_t *pOutput, uint8_t OutputSize);
629 HAL_StatusTypeDef HAL_FMAC_FilterStart(FMAC_HandleTypeDef *hfmac, int16_t *pOutput, uint16_t *pOutputSize);
630 HAL_StatusTypeDef HAL_FMAC_AppendFilterData(FMAC_HandleTypeDef *hfmac, int16_t *pInput, uint16_t *pInputSize);
631 HAL_StatusTypeDef HAL_FMAC_ConfigFilterOutputBuffer(FMAC_HandleTypeDef *hfmac, int16_t *pOutput, uint16_t *pOutputSize);
632 HAL_StatusTypeDef HAL_FMAC_PollFilterData(FMAC_HandleTypeDef *hfmac, uint32_t Timeout);
633 HAL_StatusTypeDef HAL_FMAC_FilterStop(FMAC_HandleTypeDef  *hfmac);
634 /**
635   * @}
636   */
637 
638 /** @addtogroup FMAC_Exported_Functions_Group3
639   * @{
640   */
641 /* Callback functions *********************************************************/
642 void HAL_FMAC_ErrorCallback(FMAC_HandleTypeDef *hfmac);
643 void HAL_FMAC_HalfGetDataCallback(FMAC_HandleTypeDef *hfmac);
644 void HAL_FMAC_GetDataCallback(FMAC_HandleTypeDef *hfmac);
645 void HAL_FMAC_HalfOutputDataReadyCallback(FMAC_HandleTypeDef *hfmac);
646 void HAL_FMAC_OutputDataReadyCallback(FMAC_HandleTypeDef *hfmac);
647 void HAL_FMAC_FilterConfigCallback(FMAC_HandleTypeDef *hfmac);
648 void HAL_FMAC_FilterPreloadCallback(FMAC_HandleTypeDef *hfmac);
649 /**
650   * @}
651   */
652 
653 /** @addtogroup FMAC_Exported_Functions_Group4
654   * @{
655   */
656 /* IRQ handler management *****************************************************/
657 void HAL_FMAC_IRQHandler(FMAC_HandleTypeDef *hfmac);
658 /**
659   * @}
660   */
661 
662 /** @addtogroup FMAC_Exported_Functions_Group5
663   * @{
664   */
665 /* Peripheral State functions *************************************************/
666 HAL_FMAC_StateTypeDef HAL_FMAC_GetState(FMAC_HandleTypeDef *hfmac);
667 uint32_t HAL_FMAC_GetError(FMAC_HandleTypeDef *hfmac);
668 /**
669   * @}
670   */
671 
672 /**
673   * @}
674   */
675 
676 /**
677   * @}
678   */
679 
680 /**
681   * @}
682   */
683 
684 #endif /* FMAC */
685 
686 #ifdef __cplusplus
687 }
688 #endif
689 
690 #endif /* STM32G4xx_HAL_FMAC_H */
691