1 /**
2   ******************************************************************************
3   * @file    stm32g4xx_ll_cordic.h
4   * @author  MCD Application Team
5   * @brief   Header file of CORDIC LL 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_LL_CORDIC_H
21 #define STM32G4xx_LL_CORDIC_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32g4xx.h"
29 
30 /** @addtogroup STM32G4xx_LL_Driver
31   * @{
32   */
33 
34 #if defined(CORDIC)
35 
36 /** @defgroup CORDIC_LL CORDIC
37   * @{
38   */
39 
40 /* Private variables ---------------------------------------------------------*/
41 
42 /* Private constants ---------------------------------------------------------*/
43 
44 /* Private macros ------------------------------------------------------------*/
45 
46 /* Exported types ------------------------------------------------------------*/
47 
48 /* Exported constants --------------------------------------------------------*/
49 /** @defgroup CORDIC_LL_Exported_Constants CORDIC Exported Constants
50   * @{
51   */
52 
53 /** @defgroup CORDIC_LL_EC_GET_FLAG Get Flags Defines
54   * @brief    Flags defines which can be used with LL_CORDIC_ReadReg function.
55   * @{
56   */
57 #define LL_CORDIC_FLAG_RRDY                CORDIC_CSR_RRDY
58 /**
59   * @}
60   */
61 
62 /** @defgroup CORDIC_LL_EC_IT IT Defines
63   * @brief    IT defines which can be used with LL_CORDIC_ReadReg and LL_CORDIC_WriteReg functions.
64   * @{
65   */
66 #define LL_CORDIC_IT_IEN                   CORDIC_CSR_IEN            /*!< Result Ready interrupt enable */
67 /**
68   * @}
69   */
70 
71 /** @defgroup CORDIC_LL_EC_FUNCTION FUNCTION
72   * @{
73   */
74 #define LL_CORDIC_FUNCTION_COSINE          (0x00000000U)                                                          /*!< Cosine */
75 #define LL_CORDIC_FUNCTION_SINE            ((uint32_t)(CORDIC_CSR_FUNC_0))                                        /*!< Sine */
76 #define LL_CORDIC_FUNCTION_PHASE           ((uint32_t)(CORDIC_CSR_FUNC_1))                                        /*!< Phase */
77 #define LL_CORDIC_FUNCTION_MODULUS         ((uint32_t)(CORDIC_CSR_FUNC_1 | CORDIC_CSR_FUNC_0))                    /*!< Modulus */
78 #define LL_CORDIC_FUNCTION_ARCTANGENT      ((uint32_t)(CORDIC_CSR_FUNC_2))                                        /*!< Arctangent */
79 #define LL_CORDIC_FUNCTION_HCOSINE         ((uint32_t)(CORDIC_CSR_FUNC_2 | CORDIC_CSR_FUNC_0))                    /*!< Hyperbolic Cosine */
80 #define LL_CORDIC_FUNCTION_HSINE           ((uint32_t)(CORDIC_CSR_FUNC_2 | CORDIC_CSR_FUNC_1))                    /*!< Hyperbolic Sine */
81 #define LL_CORDIC_FUNCTION_HARCTANGENT     ((uint32_t)(CORDIC_CSR_FUNC_2 | CORDIC_CSR_FUNC_1 | CORDIC_CSR_FUNC_0))/*!< Hyperbolic Arctangent */
82 #define LL_CORDIC_FUNCTION_NATURALLOG      ((uint32_t)(CORDIC_CSR_FUNC_3))                                        /*!< Natural Logarithm */
83 #define LL_CORDIC_FUNCTION_SQUAREROOT      ((uint32_t)(CORDIC_CSR_FUNC_3 | CORDIC_CSR_FUNC_0))                    /*!< Square Root */
84 /**
85   * @}
86   */
87 
88 /** @defgroup CORDIC_LL_EC_PRECISION PRECISION
89   * @{
90   */
91 #define LL_CORDIC_PRECISION_1CYCLE         ((uint32_t)(CORDIC_CSR_PRECISION_0))
92 #define LL_CORDIC_PRECISION_2CYCLES        ((uint32_t)(CORDIC_CSR_PRECISION_1))
93 #define LL_CORDIC_PRECISION_3CYCLES        ((uint32_t)(CORDIC_CSR_PRECISION_1 | CORDIC_CSR_PRECISION_0))
94 #define LL_CORDIC_PRECISION_4CYCLES        ((uint32_t)(CORDIC_CSR_PRECISION_2))
95 #define LL_CORDIC_PRECISION_5CYCLES        ((uint32_t)(CORDIC_CSR_PRECISION_2 | CORDIC_CSR_PRECISION_0))
96 #define LL_CORDIC_PRECISION_6CYCLES        ((uint32_t)(CORDIC_CSR_PRECISION_2 | CORDIC_CSR_PRECISION_1))
97 #define LL_CORDIC_PRECISION_7CYCLES        ((uint32_t)(CORDIC_CSR_PRECISION_2\
98                                                        | CORDIC_CSR_PRECISION_1 | CORDIC_CSR_PRECISION_0))
99 #define LL_CORDIC_PRECISION_8CYCLES        ((uint32_t)(CORDIC_CSR_PRECISION_3))
100 #define LL_CORDIC_PRECISION_9CYCLES        ((uint32_t)(CORDIC_CSR_PRECISION_3 | CORDIC_CSR_PRECISION_0))
101 #define LL_CORDIC_PRECISION_10CYCLES       ((uint32_t)(CORDIC_CSR_PRECISION_3 | CORDIC_CSR_PRECISION_1))
102 #define LL_CORDIC_PRECISION_11CYCLES       ((uint32_t)(CORDIC_CSR_PRECISION_3\
103                                                        | CORDIC_CSR_PRECISION_1 | CORDIC_CSR_PRECISION_0))
104 #define LL_CORDIC_PRECISION_12CYCLES       ((uint32_t)(CORDIC_CSR_PRECISION_3 | CORDIC_CSR_PRECISION_2))
105 #define LL_CORDIC_PRECISION_13CYCLES       ((uint32_t)(CORDIC_CSR_PRECISION_3\
106                                                        | CORDIC_CSR_PRECISION_2 | CORDIC_CSR_PRECISION_0))
107 #define LL_CORDIC_PRECISION_14CYCLES       ((uint32_t)(CORDIC_CSR_PRECISION_3\
108                                                        | CORDIC_CSR_PRECISION_2 | CORDIC_CSR_PRECISION_1))
109 #define LL_CORDIC_PRECISION_15CYCLES       ((uint32_t)(CORDIC_CSR_PRECISION_3\
110                                                        | CORDIC_CSR_PRECISION_2 | CORDIC_CSR_PRECISION_1\
111                                                        | CORDIC_CSR_PRECISION_0))
112 /**
113   * @}
114   */
115 
116 /** @defgroup CORDIC_LL_EC_SCALE SCALE
117   * @{
118   */
119 #define LL_CORDIC_SCALE_0                  (0x00000000U)
120 #define LL_CORDIC_SCALE_1                  ((uint32_t)(CORDIC_CSR_SCALE_0))
121 #define LL_CORDIC_SCALE_2                  ((uint32_t)(CORDIC_CSR_SCALE_1))
122 #define LL_CORDIC_SCALE_3                  ((uint32_t)(CORDIC_CSR_SCALE_1 | CORDIC_CSR_SCALE_0))
123 #define LL_CORDIC_SCALE_4                  ((uint32_t)(CORDIC_CSR_SCALE_2))
124 #define LL_CORDIC_SCALE_5                  ((uint32_t)(CORDIC_CSR_SCALE_2 | CORDIC_CSR_SCALE_0))
125 #define LL_CORDIC_SCALE_6                  ((uint32_t)(CORDIC_CSR_SCALE_2 | CORDIC_CSR_SCALE_1))
126 #define LL_CORDIC_SCALE_7                  ((uint32_t)(CORDIC_CSR_SCALE_2 | CORDIC_CSR_SCALE_1 | CORDIC_CSR_SCALE_0))
127 /**
128   * @}
129   */
130 
131 /** @defgroup CORDIC_LL_EC_NBWRITE NBWRITE
132   * @{
133   */
134 #define LL_CORDIC_NBWRITE_1                (0x00000000U)         /*!< One 32-bits write containing either only one
135                                                                       32-bits data input (Q1.31 format), or two
136                                                                       16-bits data input (Q1.15 format) packed
137                                                                       in one 32 bits Data */
138 #define LL_CORDIC_NBWRITE_2                CORDIC_CSR_NARGS      /*!< Two 32-bit write containing two 32-bits data input
139                                                                       (Q1.31 format) */
140 /**
141   * @}
142   */
143 
144 /** @defgroup CORDIC_LL_EC_NBREAD NBREAD
145   * @{
146   */
147 #define LL_CORDIC_NBREAD_1                 (0x00000000U)          /*!< One 32-bits read containing either only one
148                                                                       32-bits data output (Q1.31 format), or two
149                                                                       16-bits data output (Q1.15 format) packed
150                                                                       in one 32 bits Data */
151 #define LL_CORDIC_NBREAD_2                 CORDIC_CSR_NRES       /*!< Two 32-bit Data containing two 32-bits data output
152                                                                       (Q1.31 format) */
153 /**
154   * @}
155   */
156 
157 /** @defgroup CORDIC_LL_EC_INSIZE INSIZE
158   * @{
159   */
160 #define LL_CORDIC_INSIZE_32BITS            (0x00000000U)             /*!< 32 bits input data size (Q1.31 format) */
161 #define LL_CORDIC_INSIZE_16BITS            CORDIC_CSR_ARGSIZE        /*!< 16 bits input data size (Q1.15 format) */
162 /**
163   * @}
164   */
165 
166 /** @defgroup CORDIC_LL_EC_OUTSIZE OUTSIZE
167   * @{
168   */
169 #define LL_CORDIC_OUTSIZE_32BITS           (0x00000000U)             /*!< 32 bits output data size (Q1.31 format) */
170 #define LL_CORDIC_OUTSIZE_16BITS           CORDIC_CSR_RESSIZE        /*!< 16 bits output data size (Q1.15 format) */
171 /**
172   * @}
173   */
174 
175 /** @defgroup CORDIC_LL_EC_DMA_REG_DATA DMA register data
176   * @{
177   */
178 #define LL_CORDIC_DMA_REG_DATA_IN          (0x00000000U)             /*!< Get address of input data register */
179 #define LL_CORDIC_DMA_REG_DATA_OUT         (0x00000001U)             /*!< Get address of output data register */
180 /**
181   * @}
182   */
183 
184 /**
185   * @}
186   */
187 
188 /* Exported macro ------------------------------------------------------------*/
189 /** @defgroup CORDIC_LL_Exported_Macros CORDIC Exported Macros
190   * @{
191   */
192 
193 /** @defgroup CORDIC_LL_EM_WRITE_READ Common Write and read registers Macros
194   * @{
195   */
196 
197 /**
198   * @brief  Write a value in CORDIC register.
199   * @param  __INSTANCE__ CORDIC Instance
200   * @param  __REG__ Register to be written
201   * @param  __VALUE__ Value to be written in the register
202   * @retval None
203   */
204 #define LL_CORDIC_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
205 
206 /**
207   * @brief  Read a value in CORDIC register.
208   * @param  __INSTANCE__ CORDIC Instance
209   * @param  __REG__ Register to be read
210   * @retval Register value
211   */
212 #define LL_CORDIC_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
213 /**
214   * @}
215   */
216 
217 /**
218   * @}
219   */
220 
221 /* Exported functions --------------------------------------------------------*/
222 /** @defgroup CORDIC_LL_Exported_Functions CORDIC Exported Functions
223   * @{
224   */
225 
226 /** @defgroup CORDIC_LL_EF_Configuration CORDIC Configuration functions
227   * @{
228   */
229 
230 /**
231   * @brief  Configure the CORDIC processing.
232   * @note   This function set all parameters of CORDIC processing.
233   *         These parameters can also be set individually using
234   *         dedicated functions:
235   *         - @ref LL_CORDIC_SetFunction()
236   *         - @ref LL_CORDIC_SetPrecision()
237   *         - @ref LL_CORDIC_SetScale()
238   *         - @ref LL_CORDIC_SetNbWrite()
239   *         - @ref LL_CORDIC_SetNbRead()
240   *         - @ref LL_CORDIC_SetInSize()
241   *         - @ref LL_CORDIC_SetOutSize()
242   * @rmtoll CSR          FUNC          LL_CORDIC_Config\n
243   *         CSR          PRECISION     LL_CORDIC_Config\n
244   *         CSR          SCALE         LL_CORDIC_Config\n
245   *         CSR          NARGS         LL_CORDIC_Config\n
246   *         CSR          NRES          LL_CORDIC_Config\n
247   *         CSR          ARGSIZE       LL_CORDIC_Config\n
248   *         CSR          RESIZE        LL_CORDIC_Config
249   * @param  CORDICx CORDIC instance
250   * @param  Function parameter can be one of the following values:
251   *         @arg @ref LL_CORDIC_FUNCTION_COSINE
252   *         @arg @ref LL_CORDIC_FUNCTION_SINE
253   *         @arg @ref LL_CORDIC_FUNCTION_PHASE
254   *         @arg @ref LL_CORDIC_FUNCTION_MODULUS
255   *         @arg @ref LL_CORDIC_FUNCTION_ARCTANGENT
256   *         @arg @ref LL_CORDIC_FUNCTION_HCOSINE
257   *         @arg @ref LL_CORDIC_FUNCTION_HSINE
258   *         @arg @ref LL_CORDIC_FUNCTION_HARCTANGENT
259   *         @arg @ref LL_CORDIC_FUNCTION_NATURALLOG
260   *         @arg @ref LL_CORDIC_FUNCTION_SQUAREROOT
261   * @param  Precision parameter can be one of the following values:
262   *         @arg @ref LL_CORDIC_PRECISION_1CYCLE
263   *         @arg @ref LL_CORDIC_PRECISION_2CYCLES
264   *         @arg @ref LL_CORDIC_PRECISION_3CYCLES
265   *         @arg @ref LL_CORDIC_PRECISION_4CYCLES
266   *         @arg @ref LL_CORDIC_PRECISION_5CYCLES
267   *         @arg @ref LL_CORDIC_PRECISION_6CYCLES
268   *         @arg @ref LL_CORDIC_PRECISION_7CYCLES
269   *         @arg @ref LL_CORDIC_PRECISION_8CYCLES
270   *         @arg @ref LL_CORDIC_PRECISION_9CYCLES
271   *         @arg @ref LL_CORDIC_PRECISION_10CYCLES
272   *         @arg @ref LL_CORDIC_PRECISION_11CYCLES
273   *         @arg @ref LL_CORDIC_PRECISION_12CYCLES
274   *         @arg @ref LL_CORDIC_PRECISION_13CYCLES
275   *         @arg @ref LL_CORDIC_PRECISION_14CYCLES
276   *         @arg @ref LL_CORDIC_PRECISION_15CYCLES
277   * @param  Scale parameter can be one of the following values:
278   *         @arg @ref LL_CORDIC_SCALE_0
279   *         @arg @ref LL_CORDIC_SCALE_1
280   *         @arg @ref LL_CORDIC_SCALE_2
281   *         @arg @ref LL_CORDIC_SCALE_3
282   *         @arg @ref LL_CORDIC_SCALE_4
283   *         @arg @ref LL_CORDIC_SCALE_5
284   *         @arg @ref LL_CORDIC_SCALE_6
285   *         @arg @ref LL_CORDIC_SCALE_7
286   * @param  NbWrite parameter can be one of the following values:
287   *         @arg @ref LL_CORDIC_NBWRITE_1
288   *         @arg @ref LL_CORDIC_NBWRITE_2
289   * @param  NbRead parameter can be one of the following values:
290   *         @arg @ref LL_CORDIC_NBREAD_1
291   *         @arg @ref LL_CORDIC_NBREAD_2
292   * @param  InSize parameter can be one of the following values:
293   *         @arg @ref LL_CORDIC_INSIZE_32BITS
294   *         @arg @ref LL_CORDIC_INSIZE_16BITS
295   * @param  OutSize parameter can be one of the following values:
296   *         @arg @ref LL_CORDIC_OUTSIZE_32BITS
297   *         @arg @ref LL_CORDIC_OUTSIZE_16BITS
298   * @retval None
299   */
LL_CORDIC_Config(CORDIC_TypeDef * CORDICx,uint32_t Function,uint32_t Precision,uint32_t Scale,uint32_t NbWrite,uint32_t NbRead,uint32_t InSize,uint32_t OutSize)300 __STATIC_INLINE void LL_CORDIC_Config(CORDIC_TypeDef *CORDICx, uint32_t Function, uint32_t Precision, uint32_t Scale,
301                                       uint32_t NbWrite, uint32_t NbRead, uint32_t InSize, uint32_t OutSize)
302 {
303   MODIFY_REG(CORDICx->CSR,
304              CORDIC_CSR_FUNC | CORDIC_CSR_PRECISION | CORDIC_CSR_SCALE |
305              CORDIC_CSR_NARGS | CORDIC_CSR_NRES | CORDIC_CSR_ARGSIZE | CORDIC_CSR_RESSIZE,
306              Function | Precision | Scale |
307              NbWrite | NbRead | InSize | OutSize);
308 }
309 
310 /**
311   * @brief  Configure function.
312   * @rmtoll CSR          FUNC          LL_CORDIC_SetFunction
313   * @param  CORDICx CORDIC Instance
314   * @param  Function parameter can be one of the following values:
315   *         @arg @ref LL_CORDIC_FUNCTION_COSINE
316   *         @arg @ref LL_CORDIC_FUNCTION_SINE
317   *         @arg @ref LL_CORDIC_FUNCTION_PHASE
318   *         @arg @ref LL_CORDIC_FUNCTION_MODULUS
319   *         @arg @ref LL_CORDIC_FUNCTION_ARCTANGENT
320   *         @arg @ref LL_CORDIC_FUNCTION_HCOSINE
321   *         @arg @ref LL_CORDIC_FUNCTION_HSINE
322   *         @arg @ref LL_CORDIC_FUNCTION_HARCTANGENT
323   *         @arg @ref LL_CORDIC_FUNCTION_NATURALLOG
324   *         @arg @ref LL_CORDIC_FUNCTION_SQUAREROOT
325   * @retval None
326   */
LL_CORDIC_SetFunction(CORDIC_TypeDef * CORDICx,uint32_t Function)327 __STATIC_INLINE void LL_CORDIC_SetFunction(CORDIC_TypeDef *CORDICx, uint32_t Function)
328 {
329   MODIFY_REG(CORDICx->CSR, CORDIC_CSR_FUNC, Function);
330 }
331 
332 /**
333   * @brief  Return function.
334   * @rmtoll CSR          FUNC          LL_CORDIC_GetFunction
335   * @param  CORDICx CORDIC Instance
336   * @retval Returned value can be one of the following values:
337   *         @arg @ref LL_CORDIC_FUNCTION_COSINE
338   *         @arg @ref LL_CORDIC_FUNCTION_SINE
339   *         @arg @ref LL_CORDIC_FUNCTION_PHASE
340   *         @arg @ref LL_CORDIC_FUNCTION_MODULUS
341   *         @arg @ref LL_CORDIC_FUNCTION_ARCTANGENT
342   *         @arg @ref LL_CORDIC_FUNCTION_HCOSINE
343   *         @arg @ref LL_CORDIC_FUNCTION_HSINE
344   *         @arg @ref LL_CORDIC_FUNCTION_HARCTANGENT
345   *         @arg @ref LL_CORDIC_FUNCTION_NATURALLOG
346   *         @arg @ref LL_CORDIC_FUNCTION_SQUAREROOT
347   */
LL_CORDIC_GetFunction(const CORDIC_TypeDef * CORDICx)348 __STATIC_INLINE uint32_t LL_CORDIC_GetFunction(const CORDIC_TypeDef *CORDICx)
349 {
350   return (uint32_t)(READ_BIT(CORDICx->CSR, CORDIC_CSR_FUNC));
351 }
352 
353 /**
354   * @brief  Configure precision in cycles number.
355   * @rmtoll CSR          PRECISION     LL_CORDIC_SetPrecision
356   * @param  CORDICx CORDIC Instance
357   * @param  Precision parameter can be one of the following values:
358   *         @arg @ref LL_CORDIC_PRECISION_1CYCLE
359   *         @arg @ref LL_CORDIC_PRECISION_2CYCLES
360   *         @arg @ref LL_CORDIC_PRECISION_3CYCLES
361   *         @arg @ref LL_CORDIC_PRECISION_4CYCLES
362   *         @arg @ref LL_CORDIC_PRECISION_5CYCLES
363   *         @arg @ref LL_CORDIC_PRECISION_6CYCLES
364   *         @arg @ref LL_CORDIC_PRECISION_7CYCLES
365   *         @arg @ref LL_CORDIC_PRECISION_8CYCLES
366   *         @arg @ref LL_CORDIC_PRECISION_9CYCLES
367   *         @arg @ref LL_CORDIC_PRECISION_10CYCLES
368   *         @arg @ref LL_CORDIC_PRECISION_11CYCLES
369   *         @arg @ref LL_CORDIC_PRECISION_12CYCLES
370   *         @arg @ref LL_CORDIC_PRECISION_13CYCLES
371   *         @arg @ref LL_CORDIC_PRECISION_14CYCLES
372   *         @arg @ref LL_CORDIC_PRECISION_15CYCLES
373   * @retval None
374   */
LL_CORDIC_SetPrecision(CORDIC_TypeDef * CORDICx,uint32_t Precision)375 __STATIC_INLINE void LL_CORDIC_SetPrecision(CORDIC_TypeDef *CORDICx, uint32_t Precision)
376 {
377   MODIFY_REG(CORDICx->CSR, CORDIC_CSR_PRECISION, Precision);
378 }
379 
380 /**
381   * @brief  Return precision in cycles number.
382   * @rmtoll CSR          PRECISION     LL_CORDIC_GetPrecision
383   * @param  CORDICx CORDIC Instance
384   * @retval Returned value can be one of the following values:
385   *         @arg @ref LL_CORDIC_PRECISION_1CYCLE
386   *         @arg @ref LL_CORDIC_PRECISION_2CYCLES
387   *         @arg @ref LL_CORDIC_PRECISION_3CYCLES
388   *         @arg @ref LL_CORDIC_PRECISION_4CYCLES
389   *         @arg @ref LL_CORDIC_PRECISION_5CYCLES
390   *         @arg @ref LL_CORDIC_PRECISION_6CYCLES
391   *         @arg @ref LL_CORDIC_PRECISION_7CYCLES
392   *         @arg @ref LL_CORDIC_PRECISION_8CYCLES
393   *         @arg @ref LL_CORDIC_PRECISION_9CYCLES
394   *         @arg @ref LL_CORDIC_PRECISION_10CYCLES
395   *         @arg @ref LL_CORDIC_PRECISION_11CYCLES
396   *         @arg @ref LL_CORDIC_PRECISION_12CYCLES
397   *         @arg @ref LL_CORDIC_PRECISION_13CYCLES
398   *         @arg @ref LL_CORDIC_PRECISION_14CYCLES
399   *         @arg @ref LL_CORDIC_PRECISION_15CYCLES
400   */
LL_CORDIC_GetPrecision(const CORDIC_TypeDef * CORDICx)401 __STATIC_INLINE uint32_t LL_CORDIC_GetPrecision(const CORDIC_TypeDef *CORDICx)
402 {
403   return (uint32_t)(READ_BIT(CORDICx->CSR, CORDIC_CSR_PRECISION));
404 }
405 
406 /**
407   * @brief  Configure scaling factor.
408   * @rmtoll CSR          SCALE         LL_CORDIC_SetScale
409   * @param  CORDICx CORDIC Instance
410   * @param  Scale parameter can be one of the following values:
411   *         @arg @ref LL_CORDIC_SCALE_0
412   *         @arg @ref LL_CORDIC_SCALE_1
413   *         @arg @ref LL_CORDIC_SCALE_2
414   *         @arg @ref LL_CORDIC_SCALE_3
415   *         @arg @ref LL_CORDIC_SCALE_4
416   *         @arg @ref LL_CORDIC_SCALE_5
417   *         @arg @ref LL_CORDIC_SCALE_6
418   *         @arg @ref LL_CORDIC_SCALE_7
419   * @retval None
420   */
LL_CORDIC_SetScale(CORDIC_TypeDef * CORDICx,uint32_t Scale)421 __STATIC_INLINE void LL_CORDIC_SetScale(CORDIC_TypeDef *CORDICx, uint32_t Scale)
422 {
423   MODIFY_REG(CORDICx->CSR, CORDIC_CSR_SCALE, Scale);
424 }
425 
426 /**
427   * @brief  Return scaling factor.
428   * @rmtoll CSR          SCALE         LL_CORDIC_GetScale
429   * @param  CORDICx CORDIC Instance
430   * @retval Returned value can be one of the following values:
431   *         @arg @ref LL_CORDIC_SCALE_0
432   *         @arg @ref LL_CORDIC_SCALE_1
433   *         @arg @ref LL_CORDIC_SCALE_2
434   *         @arg @ref LL_CORDIC_SCALE_3
435   *         @arg @ref LL_CORDIC_SCALE_4
436   *         @arg @ref LL_CORDIC_SCALE_5
437   *         @arg @ref LL_CORDIC_SCALE_6
438   *         @arg @ref LL_CORDIC_SCALE_7
439   */
LL_CORDIC_GetScale(const CORDIC_TypeDef * CORDICx)440 __STATIC_INLINE uint32_t LL_CORDIC_GetScale(const CORDIC_TypeDef *CORDICx)
441 {
442   return (uint32_t)(READ_BIT(CORDICx->CSR, CORDIC_CSR_SCALE));
443 }
444 
445 /**
446   * @brief  Configure number of 32-bit write expected for one calculation.
447   * @rmtoll CSR          NARGS         LL_CORDIC_SetNbWrite
448   * @param  CORDICx CORDIC Instance
449   * @param  NbWrite parameter can be one of the following values:
450   *         @arg @ref LL_CORDIC_NBWRITE_1
451   *         @arg @ref LL_CORDIC_NBWRITE_2
452   * @retval None
453   */
LL_CORDIC_SetNbWrite(CORDIC_TypeDef * CORDICx,uint32_t NbWrite)454 __STATIC_INLINE void LL_CORDIC_SetNbWrite(CORDIC_TypeDef *CORDICx, uint32_t NbWrite)
455 {
456   MODIFY_REG(CORDICx->CSR, CORDIC_CSR_NARGS, NbWrite);
457 }
458 
459 /**
460   * @brief  Return number of 32-bit write expected for one calculation.
461   * @rmtoll CSR          NARGS         LL_CORDIC_GetNbWrite
462   * @param  CORDICx CORDIC Instance
463   * @retval Returned value can be one of the following values:
464   *         @arg @ref LL_CORDIC_NBWRITE_1
465   *         @arg @ref LL_CORDIC_NBWRITE_2
466   */
LL_CORDIC_GetNbWrite(const CORDIC_TypeDef * CORDICx)467 __STATIC_INLINE uint32_t LL_CORDIC_GetNbWrite(const CORDIC_TypeDef *CORDICx)
468 {
469   return (uint32_t)(READ_BIT(CORDICx->CSR, CORDIC_CSR_NARGS));
470 }
471 
472 /**
473   * @brief  Configure number of 32-bit read expected after one calculation.
474   * @rmtoll CSR          NRES          LL_CORDIC_SetNbRead
475   * @param  CORDICx CORDIC Instance
476   * @param  NbRead parameter can be one of the following values:
477   *         @arg @ref LL_CORDIC_NBREAD_1
478   *         @arg @ref LL_CORDIC_NBREAD_2
479   * @retval None
480   */
LL_CORDIC_SetNbRead(CORDIC_TypeDef * CORDICx,uint32_t NbRead)481 __STATIC_INLINE void LL_CORDIC_SetNbRead(CORDIC_TypeDef *CORDICx, uint32_t NbRead)
482 {
483   MODIFY_REG(CORDICx->CSR, CORDIC_CSR_NRES, NbRead);
484 }
485 
486 /**
487   * @brief  Return number of 32-bit read expected after one calculation.
488   * @rmtoll CSR          NRES          LL_CORDIC_GetNbRead
489   * @param  CORDICx CORDIC Instance
490   * @retval Returned value can be one of the following values:
491   *         @arg @ref LL_CORDIC_NBREAD_1
492   *         @arg @ref LL_CORDIC_NBREAD_2
493   */
LL_CORDIC_GetNbRead(const CORDIC_TypeDef * CORDICx)494 __STATIC_INLINE uint32_t LL_CORDIC_GetNbRead(const CORDIC_TypeDef *CORDICx)
495 {
496   return (uint32_t)(READ_BIT(CORDICx->CSR, CORDIC_CSR_NRES));
497 }
498 
499 /**
500   * @brief  Configure width of input data.
501   * @rmtoll CSR          ARGSIZE       LL_CORDIC_SetInSize
502   * @param  CORDICx CORDIC Instance
503   * @param  InSize parameter can be one of the following values:
504   *         @arg @ref LL_CORDIC_INSIZE_32BITS
505   *         @arg @ref LL_CORDIC_INSIZE_16BITS
506   * @retval None
507   */
LL_CORDIC_SetInSize(CORDIC_TypeDef * CORDICx,uint32_t InSize)508 __STATIC_INLINE void LL_CORDIC_SetInSize(CORDIC_TypeDef *CORDICx, uint32_t InSize)
509 {
510   MODIFY_REG(CORDICx->CSR, CORDIC_CSR_ARGSIZE, InSize);
511 }
512 
513 /**
514   * @brief  Return width of input data.
515   * @rmtoll CSR          ARGSIZE       LL_CORDIC_GetInSize
516   * @param  CORDICx CORDIC Instance
517   * @retval Returned value can be one of the following values:
518   *         @arg @ref LL_CORDIC_INSIZE_32BITS
519   *         @arg @ref LL_CORDIC_INSIZE_16BITS
520   */
LL_CORDIC_GetInSize(const CORDIC_TypeDef * CORDICx)521 __STATIC_INLINE uint32_t LL_CORDIC_GetInSize(const CORDIC_TypeDef *CORDICx)
522 {
523   return (uint32_t)(READ_BIT(CORDICx->CSR, CORDIC_CSR_ARGSIZE));
524 }
525 
526 /**
527   * @brief  Configure width of output data.
528   * @rmtoll CSR          RESIZE       LL_CORDIC_SetOutSize
529   * @param  CORDICx CORDIC Instance
530   * @param  OutSize parameter can be one of the following values:
531   *         @arg @ref LL_CORDIC_OUTSIZE_32BITS
532   *         @arg @ref LL_CORDIC_OUTSIZE_16BITS
533   * @retval None
534   */
LL_CORDIC_SetOutSize(CORDIC_TypeDef * CORDICx,uint32_t OutSize)535 __STATIC_INLINE void LL_CORDIC_SetOutSize(CORDIC_TypeDef *CORDICx, uint32_t OutSize)
536 {
537   MODIFY_REG(CORDICx->CSR, CORDIC_CSR_RESSIZE, OutSize);
538 }
539 
540 /**
541   * @brief  Return width of output data.
542   * @rmtoll CSR          RESIZE       LL_CORDIC_GetOutSize
543   * @param  CORDICx CORDIC Instance
544   * @retval Returned value can be one of the following values:
545   *         @arg @ref LL_CORDIC_OUTSIZE_32BITS
546   *         @arg @ref LL_CORDIC_OUTSIZE_16BITS
547   */
LL_CORDIC_GetOutSize(const CORDIC_TypeDef * CORDICx)548 __STATIC_INLINE uint32_t LL_CORDIC_GetOutSize(const CORDIC_TypeDef *CORDICx)
549 {
550   return (uint32_t)(READ_BIT(CORDICx->CSR, CORDIC_CSR_RESSIZE));
551 }
552 
553 /**
554   * @}
555   */
556 
557 /** @defgroup CORDIC_LL_EF_IT_Management IT_Management
558   * @{
559   */
560 
561 /**
562   * @brief  Enable CORDIC result ready interrupt
563   * @rmtoll CSR          IEN           LL_CORDIC_EnableIT
564   * @param  CORDICx CORDIC Instance
565   * @retval None
566   */
LL_CORDIC_EnableIT(CORDIC_TypeDef * CORDICx)567 __STATIC_INLINE void LL_CORDIC_EnableIT(CORDIC_TypeDef *CORDICx)
568 {
569   SET_BIT(CORDICx->CSR, CORDIC_CSR_IEN);
570 }
571 
572 /**
573   * @brief  Disable CORDIC result ready interrupt
574   * @rmtoll CSR          IEN           LL_CORDIC_DisableIT
575   * @param  CORDICx CORDIC Instance
576   * @retval None
577   */
LL_CORDIC_DisableIT(CORDIC_TypeDef * CORDICx)578 __STATIC_INLINE void LL_CORDIC_DisableIT(CORDIC_TypeDef *CORDICx)
579 {
580   CLEAR_BIT(CORDICx->CSR, CORDIC_CSR_IEN);
581 }
582 
583 /**
584   * @brief  Check CORDIC result ready interrupt state.
585   * @rmtoll CSR          IEN           LL_CORDIC_IsEnabledIT
586   * @param  CORDICx CORDIC Instance
587   * @retval State of bit (1 or 0).
588   */
LL_CORDIC_IsEnabledIT(const CORDIC_TypeDef * CORDICx)589 __STATIC_INLINE uint32_t LL_CORDIC_IsEnabledIT(const CORDIC_TypeDef *CORDICx)
590 {
591   return ((READ_BIT(CORDICx->CSR, CORDIC_CSR_IEN) == (CORDIC_CSR_IEN)) ? 1U : 0U);
592 }
593 
594 /**
595   * @}
596   */
597 
598 /** @defgroup CORDIC_LL_EF_DMA_Management DMA_Management
599   * @{
600   */
601 
602 /**
603   * @brief  Enable CORDIC DMA read channel request.
604   * @rmtoll CSR          DMAREN        LL_CORDIC_EnableDMAReq_RD
605   * @param  CORDICx CORDIC Instance
606   * @retval None
607   */
LL_CORDIC_EnableDMAReq_RD(CORDIC_TypeDef * CORDICx)608 __STATIC_INLINE void LL_CORDIC_EnableDMAReq_RD(CORDIC_TypeDef *CORDICx)
609 {
610   SET_BIT(CORDICx->CSR, CORDIC_CSR_DMAREN);
611 }
612 
613 /**
614   * @brief  Disable CORDIC DMA read channel request.
615   * @rmtoll CSR          DMAREN        LL_CORDIC_DisableDMAReq_RD
616   * @param  CORDICx CORDIC Instance
617   * @retval None
618   */
LL_CORDIC_DisableDMAReq_RD(CORDIC_TypeDef * CORDICx)619 __STATIC_INLINE void LL_CORDIC_DisableDMAReq_RD(CORDIC_TypeDef *CORDICx)
620 {
621   CLEAR_BIT(CORDICx->CSR, CORDIC_CSR_DMAREN);
622 }
623 
624 /**
625   * @brief  Check CORDIC DMA read channel request state.
626   * @rmtoll CSR          DMAREN        LL_CORDIC_IsEnabledDMAReq_RD
627   * @param  CORDICx CORDIC Instance
628   * @retval State of bit (1 or 0).
629   */
LL_CORDIC_IsEnabledDMAReq_RD(const CORDIC_TypeDef * CORDICx)630 __STATIC_INLINE uint32_t LL_CORDIC_IsEnabledDMAReq_RD(const CORDIC_TypeDef *CORDICx)
631 {
632   return ((READ_BIT(CORDICx->CSR, CORDIC_CSR_DMAREN) == (CORDIC_CSR_DMAREN)) ? 1U : 0U);
633 }
634 
635 /**
636   * @brief  Enable CORDIC DMA write channel request.
637   * @rmtoll CSR          DMAWEN        LL_CORDIC_EnableDMAReq_WR
638   * @param  CORDICx CORDIC Instance
639   * @retval None
640   */
LL_CORDIC_EnableDMAReq_WR(CORDIC_TypeDef * CORDICx)641 __STATIC_INLINE void LL_CORDIC_EnableDMAReq_WR(CORDIC_TypeDef *CORDICx)
642 {
643   SET_BIT(CORDICx->CSR, CORDIC_CSR_DMAWEN);
644 }
645 
646 /**
647   * @brief  Disable CORDIC DMA write channel request.
648   * @rmtoll CSR          DMAWEN        LL_CORDIC_DisableDMAReq_WR
649   * @param  CORDICx CORDIC Instance
650   * @retval None
651   */
LL_CORDIC_DisableDMAReq_WR(CORDIC_TypeDef * CORDICx)652 __STATIC_INLINE void LL_CORDIC_DisableDMAReq_WR(CORDIC_TypeDef *CORDICx)
653 {
654   CLEAR_BIT(CORDICx->CSR, CORDIC_CSR_DMAWEN);
655 }
656 
657 /**
658   * @brief  Check CORDIC DMA write channel request state.
659   * @rmtoll CSR          DMAWEN        LL_CORDIC_IsEnabledDMAReq_WR
660   * @param  CORDICx CORDIC Instance
661   * @retval State of bit (1 or 0).
662   */
LL_CORDIC_IsEnabledDMAReq_WR(const CORDIC_TypeDef * CORDICx)663 __STATIC_INLINE uint32_t LL_CORDIC_IsEnabledDMAReq_WR(const CORDIC_TypeDef *CORDICx)
664 {
665   return ((READ_BIT(CORDICx->CSR, CORDIC_CSR_DMAWEN) == (CORDIC_CSR_DMAWEN)) ? 1U : 0U);
666 }
667 
668 /**
669   * @brief  Get the CORDIC data register address used for DMA transfer.
670   * @rmtoll RDATA        RES           LL_CORDIC_DMA_GetRegAddr\n
671   * @rmtoll WDATA        ARG           LL_CORDIC_DMA_GetRegAddr
672   * @param  CORDICx CORDIC Instance
673   * @param  Direction parameter can be one of the following values:
674   *         @arg @ref LL_CORDIC_DMA_REG_DATA_IN
675   *         @arg @ref LL_CORDIC_DMA_REG_DATA_OUT
676   * @retval Address of data register
677   */
LL_CORDIC_DMA_GetRegAddr(const CORDIC_TypeDef * CORDICx,uint32_t Direction)678 __STATIC_INLINE uint32_t LL_CORDIC_DMA_GetRegAddr(const CORDIC_TypeDef *CORDICx, uint32_t Direction)
679 {
680   uint32_t data_reg_addr;
681 
682   if (Direction == LL_CORDIC_DMA_REG_DATA_OUT)
683   {
684     /* return address of RDATA register */
685     data_reg_addr = (uint32_t) &(CORDICx->RDATA);
686   }
687   else
688   {
689     /* return address of WDATA register */
690     data_reg_addr = (uint32_t) &(CORDICx->WDATA);
691   }
692 
693   return data_reg_addr;
694 }
695 
696 /**
697   * @}
698   */
699 
700 /** @defgroup CORDIC_LL_EF_FLAG_Management FLAG_Management
701   * @{
702   */
703 
704 /**
705   * @brief  Check CORDIC result ready flag state.
706   * @rmtoll CSR          RRDY          LL_CORDIC_IsActiveFlag_RRDY
707   * @param  CORDICx CORDIC Instance
708   * @retval State of bit (1 or 0).
709   */
LL_CORDIC_IsActiveFlag_RRDY(const CORDIC_TypeDef * CORDICx)710 __STATIC_INLINE uint32_t LL_CORDIC_IsActiveFlag_RRDY(const CORDIC_TypeDef *CORDICx)
711 {
712   return ((READ_BIT(CORDICx->CSR, CORDIC_CSR_RRDY) == (CORDIC_CSR_RRDY)) ? 1U : 0U);
713 }
714 
715 /**
716   * @}
717   */
718 
719 /** @defgroup CORDIC_LL_EF_Data_Management Data_Management
720   * @{
721   */
722 
723 /**
724   * @brief  Write 32-bit input data for the CORDIC processing.
725   * @rmtoll WDATA        ARG           LL_CORDIC_WriteData
726   * @param  CORDICx CORDIC Instance
727   * @param  InData 0 .. 0xFFFFFFFF : 32-bit value to be provided as input data for CORDIC processing.
728   * @retval None
729   */
LL_CORDIC_WriteData(CORDIC_TypeDef * CORDICx,uint32_t InData)730 __STATIC_INLINE void LL_CORDIC_WriteData(CORDIC_TypeDef *CORDICx, uint32_t InData)
731 {
732   WRITE_REG(CORDICx->WDATA, InData);
733 }
734 
735 /**
736   * @brief  Return 32-bit output data of CORDIC processing.
737   * @rmtoll RDATA        RES           LL_CORDIC_ReadData
738   * @param  CORDICx CORDIC Instance
739   * @retval 32-bit output data of CORDIC processing.
740   */
LL_CORDIC_ReadData(const CORDIC_TypeDef * CORDICx)741 __STATIC_INLINE uint32_t LL_CORDIC_ReadData(const CORDIC_TypeDef *CORDICx)
742 {
743   return (uint32_t)(READ_REG(CORDICx->RDATA));
744 }
745 
746 /**
747   * @}
748   */
749 
750 #if defined(USE_FULL_LL_DRIVER)
751 /** @defgroup CORDIC_LL_EF_Init Initialization and de-initialization functions
752   * @{
753   */
754 ErrorStatus LL_CORDIC_DeInit(const CORDIC_TypeDef *CORDICx);
755 
756 /**
757   * @}
758   */
759 #endif /* USE_FULL_LL_DRIVER */
760 
761 /**
762   * @}
763   */
764 
765 /**
766   * @}
767   */
768 
769 #endif /* defined(CORDIC) */
770 
771 /**
772   * @}
773   */
774 
775 #ifdef __cplusplus
776 }
777 #endif
778 
779 #endif /* STM32G4xx_LL_CORDIC_H */
780