1 /**
2   ******************************************************************************
3   * @file    stm32g0xx_hal_dma_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of DMA HAL extension module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2018 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 STM32G0xx_HAL_DMA_EX_H
21 #define STM32G0xx_HAL_DMA_EX_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32g0xx_hal_def.h"
29 #include "stm32g0xx_ll_dmamux.h"
30 
31 /** @addtogroup STM32G0xx_HAL_Driver
32   * @{
33   */
34 
35 /** @addtogroup DMAEx
36   * @{
37   */
38 
39 /* Exported types ------------------------------------------------------------*/
40 /** @defgroup DMAEx_Exported_Types DMAEx Exported Types
41   * @{
42   */
43 
44 /**
45   * @brief  HAL DMAMUX Synchronization configuration structure definition
46   */
47 typedef struct
48 {
49   uint32_t SyncSignalID;        /*!< Specifies the synchronization signal gating the DMA request in periodic mode.
50                                   This parameter can be a value of @ref DMAEx_DMAMUX_SyncSignalID_selection */
51 
52   uint32_t SyncPolarity;        /*!< Specifies the polarity of the signal on which the DMA request is synchronized.
53                                   This parameter can be a value of @ref DMAEx_DMAMUX_SyncPolarity_selection */
54 
55   FunctionalState SyncEnable;   /*!< Specifies if the synchronization shall be enabled or disabled
56                                   This parameter can take the value ENABLE or DISABLE */
57 
58   FunctionalState EventEnable;  /*!< Specifies if an event shall be generated once the RequestNumber is reached.
59                                   This parameter can take the value ENABLE or DISABLE */
60 
61   uint32_t RequestNumber;       /*!< Specifies the number of DMA request that will be authorized after a sync event
62                                   This parameter must be a number between Min_Data = 1 and Max_Data = 32 */
63 
64 
65 } HAL_DMA_MuxSyncConfigTypeDef;
66 
67 
68 /**
69   * @brief  HAL DMAMUX request generator parameters structure definition
70   */
71 typedef struct
72 {
73   uint32_t SignalID;            /*!< Specifies the ID of the signal used for DMAMUX request generator
74                                   This parameter can be a value of @ref DMAEx_DMAMUX_SignalGeneratorID_selection */
75 
76   uint32_t Polarity;            /*!< Specifies the polarity of the signal on which the request is generated.
77                                   This parameter can be a value of @ref DMAEx_DMAMUX_RequestGeneneratorPolarity_selection */
78 
79   uint32_t RequestNumber;       /*!< Specifies the number of DMA request that will be generated after a signal event
80                                   This parameter must be a number between Min_Data = 1 and Max_Data = 32 */
81 
82 } HAL_DMA_MuxRequestGeneratorConfigTypeDef;
83 
84 /**
85   * @}
86   */
87 
88 /* Exported constants --------------------------------------------------------*/
89 /** @defgroup DMAEx_Exported_Constants DMAEx Exported Constants
90   * @{
91   */
92 
93 /** @defgroup DMAEx_DMAMUX_SyncSignalID_selection DMAMUX SyncSignalID selection
94   * @{
95   */
96 #define HAL_DMAMUX1_SYNC_EXTI0            LL_DMAMUX_SYNC_EXTI_LINE0      /*!< Synchronization signal from EXTI Line0  */
97 #define HAL_DMAMUX1_SYNC_EXTI1            LL_DMAMUX_SYNC_EXTI_LINE1      /*!< Synchronization signal from EXTI Line1  */
98 #define HAL_DMAMUX1_SYNC_EXTI2            LL_DMAMUX_SYNC_EXTI_LINE2      /*!< Synchronization signal from EXTI Line2  */
99 #define HAL_DMAMUX1_SYNC_EXTI3            LL_DMAMUX_SYNC_EXTI_LINE3      /*!< Synchronization signal from EXTI Line3  */
100 #define HAL_DMAMUX1_SYNC_EXTI4            LL_DMAMUX_SYNC_EXTI_LINE4      /*!< Synchronization signal from EXTI Line4  */
101 #define HAL_DMAMUX1_SYNC_EXTI5            LL_DMAMUX_SYNC_EXTI_LINE5      /*!< Synchronization signal from EXTI Line5  */
102 #define HAL_DMAMUX1_SYNC_EXTI6            LL_DMAMUX_SYNC_EXTI_LINE6      /*!< Synchronization signal from EXTI Line6  */
103 #define HAL_DMAMUX1_SYNC_EXTI7            LL_DMAMUX_SYNC_EXTI_LINE7      /*!< Synchronization signal from EXTI Line7  */
104 #define HAL_DMAMUX1_SYNC_EXTI8            LL_DMAMUX_SYNC_EXTI_LINE8      /*!< Synchronization signal from EXTI Line8  */
105 #define HAL_DMAMUX1_SYNC_EXTI9            LL_DMAMUX_SYNC_EXTI_LINE9      /*!< Synchronization signal from EXTI Line9  */
106 #define HAL_DMAMUX1_SYNC_EXTI10           LL_DMAMUX_SYNC_EXTI_LINE10     /*!< Synchronization signal from EXTI Line10  */
107 #define HAL_DMAMUX1_SYNC_EXTI11           LL_DMAMUX_SYNC_EXTI_LINE11     /*!< Synchronization signal from EXTI Line11  */
108 #define HAL_DMAMUX1_SYNC_EXTI12           LL_DMAMUX_SYNC_EXTI_LINE12     /*!< Synchronization signal from EXTI Line12  */
109 #define HAL_DMAMUX1_SYNC_EXTI13           LL_DMAMUX_SYNC_EXTI_LINE13     /*!< Synchronization signal from EXTI Line1 3 */
110 #define HAL_DMAMUX1_SYNC_EXTI14           LL_DMAMUX_SYNC_EXTI_LINE14     /*!< Synchronization signal from EXTI Line1 4 */
111 #define HAL_DMAMUX1_SYNC_EXTI15           LL_DMAMUX_SYNC_EXTI_LINE15     /*!< Synchronization signal from EXTI Line1 5 */
112 #define HAL_DMAMUX1_SYNC_DMAMUX1_CH0_EVT  LL_DMAMUX_SYNC_DMAMUX_CH0      /*!< Synchronization signal from DMAMUX channel0 Event */
113 #define HAL_DMAMUX1_SYNC_DMAMUX1_CH1_EVT  LL_DMAMUX_SYNC_DMAMUX_CH1      /*!< Synchronization signal from DMAMUX channel1 Event */
114 #define HAL_DMAMUX1_SYNC_DMAMUX1_CH2_EVT  LL_DMAMUX_SYNC_DMAMUX_CH2      /*!< Synchronization signal from DMAMUX channel2 Event */
115 #define HAL_DMAMUX1_SYNC_DMAMUX1_CH3_EVT  LL_DMAMUX_SYNC_DMAMUX_CH3      /*!< Synchronization signal from DMAMUX channel3 Event */
116 #if defined(LPTIM1)
117 #define HAL_DMAMUX1_SYNC_LPTIM1_OUT       LL_DMAMUX_SYNC_LPTIM1_OUT      /*!< Synchronization signal from LPTIM1 Output */
118 #endif /* LPTIM1 */
119 #if defined(LPTIM2)
120 #define HAL_DMAMUX1_SYNC_LPTIM2_OUT       LL_DMAMUX_SYNC_LPTIM2_OUT      /*!< Synchronization signal from LPTIM2 Output */
121 #endif /* LPTIM2 */
122 #define HAL_DMAMUX1_SYNC_TIM14_OC         LL_DMAMUX_SYNC_TIM14_OC        /*!< Synchronization signal from TIM14 OC */
123 
124 #define HAL_DMAMUX1_MAX_SYNC              HAL_DMAMUX1_SYNC_TIM14_OC
125 /**
126   * @}
127   */
128 
129 /** @defgroup DMAEx_DMAMUX_SyncPolarity_selection DMAMUX SyncPolarity selection
130   * @{
131   */
132 #define HAL_DMAMUX_SYNC_NO_EVENT          LL_DMAMUX_SYNC_NO_EVENT               /*!< block synchronization events                       */
133 #define HAL_DMAMUX_SYNC_RISING            LL_DMAMUX_SYNC_POL_RISING             /*!< synchronize with rising edge events                */
134 #define HAL_DMAMUX_SYNC_FALLING           LL_DMAMUX_SYNC_POL_FALLING            /*!< synchronize with falling edge events               */
135 #define HAL_DMAMUX_SYNC_RISING_FALLING    LL_DMAMUX_SYNC_POL_RISING_FALLING     /*!< synchronize with rising and falling edge events    */
136 
137 /**
138   * @}
139   */
140 
141 /** @defgroup DMAEx_DMAMUX_SignalGeneratorID_selection DMAMUX SignalGeneratorID selection
142   * @{
143   */
144 #define HAL_DMAMUX1_REQ_GEN_EXTI0            LL_DMAMUX_REQ_GEN_EXTI_LINE0    /*!< Request signal generation from EXTI Line0  */
145 #define HAL_DMAMUX1_REQ_GEN_EXTI1            LL_DMAMUX_REQ_GEN_EXTI_LINE1    /*!< Request signal generation from EXTI Line1  */
146 #define HAL_DMAMUX1_REQ_GEN_EXTI2            LL_DMAMUX_REQ_GEN_EXTI_LINE2    /*!< Request signal generation from EXTI Line2  */
147 #define HAL_DMAMUX1_REQ_GEN_EXTI3            LL_DMAMUX_REQ_GEN_EXTI_LINE3    /*!< Request signal generation from EXTI Line3  */
148 #define HAL_DMAMUX1_REQ_GEN_EXTI4            LL_DMAMUX_REQ_GEN_EXTI_LINE4    /*!< Request signal generation from EXTI Line4  */
149 #define HAL_DMAMUX1_REQ_GEN_EXTI5            LL_DMAMUX_REQ_GEN_EXTI_LINE5    /*!< Request signal generation from EXTI Line5  */
150 #define HAL_DMAMUX1_REQ_GEN_EXTI6            LL_DMAMUX_REQ_GEN_EXTI_LINE6    /*!< Request signal generation from EXTI Line6  */
151 #define HAL_DMAMUX1_REQ_GEN_EXTI7            LL_DMAMUX_REQ_GEN_EXTI_LINE7    /*!< Request signal generation from EXTI Line7  */
152 #define HAL_DMAMUX1_REQ_GEN_EXTI8            LL_DMAMUX_REQ_GEN_EXTI_LINE8    /*!< Request signal generation from EXTI Line8  */
153 #define HAL_DMAMUX1_REQ_GEN_EXTI9            LL_DMAMUX_REQ_GEN_EXTI_LINE9    /*!< Request signal generation from EXTI Line9  */
154 #define HAL_DMAMUX1_REQ_GEN_EXTI10           LL_DMAMUX_REQ_GEN_EXTI_LINE10   /*!< Request signal generation from EXTI Line10 */
155 #define HAL_DMAMUX1_REQ_GEN_EXTI11           LL_DMAMUX_REQ_GEN_EXTI_LINE11   /*!< Request signal generation from EXTI Line11 */
156 #define HAL_DMAMUX1_REQ_GEN_EXTI12           LL_DMAMUX_REQ_GEN_EXTI_LINE12   /*!< Request signal generation from EXTI Line12 */
157 #define HAL_DMAMUX1_REQ_GEN_EXTI13           LL_DMAMUX_REQ_GEN_EXTI_LINE13   /*!< Request signal generation from EXTI Line13 */
158 #define HAL_DMAMUX1_REQ_GEN_EXTI14           LL_DMAMUX_REQ_GEN_EXTI_LINE14   /*!< Request signal generation from EXTI Line14 */
159 #define HAL_DMAMUX1_REQ_GEN_EXTI15           LL_DMAMUX_REQ_GEN_EXTI_LINE15   /*!< Request signal generation from EXTI Line15 */
160 #define HAL_DMAMUX1_REQ_GEN_DMAMUX1_CH0_EVT  LL_DMAMUX_REQ_GEN_DMAMUX_CH0    /*!< Request signal generation from DMAMUX channel0 Event */
161 #define HAL_DMAMUX1_REQ_GEN_DMAMUX1_CH1_EVT  LL_DMAMUX_REQ_GEN_DMAMUX_CH1    /*!< Request signal generation from DMAMUX channel1 Event */
162 #define HAL_DMAMUX1_REQ_GEN_DMAMUX1_CH2_EVT  LL_DMAMUX_REQ_GEN_DMAMUX_CH2    /*!< Request signal generation from DMAMUX channel2 Event */
163 #define HAL_DMAMUX1_REQ_GEN_DMAMUX1_CH3_EVT  LL_DMAMUX_REQ_GEN_DMAMUX_CH3    /*!< Request signal generation from DMAMUX channel3 Event */
164 #if defined(LPTIM1)
165 #define HAL_DMAMUX1_REQ_GEN_LPTIM1_OUT       LL_DMAMUX_REQ_GEN_LPTIM1_OUT    /*!< Request signal generation from LPTIM1 Output */
166 #endif /* LPTIM1 */
167 #if defined(LPTIM2)
168 #define HAL_DMAMUX1_REQ_GEN_LPTIM2_OUT       LL_DMAMUX_REQ_GEN_LPTIM2_OUT    /*!< Request signal generation from LPTIM2 Output */
169 #endif /* LPTIM2 */
170 #define HAL_DMAMUX1_REQ_GEN_TIM14_OC         LL_DMAMUX_REQ_GEN_TIM14_OC      /*!< Request signal generation from TIM14 OC */
171 
172 #define HAL_DMAMUX1_MAX_REQ_GEN              HAL_DMAMUX1_REQ_GEN_TIM14_OC
173 /**
174   * @}
175   */
176 
177 /** @defgroup DMAEx_DMAMUX_RequestGeneneratorPolarity_selection DMAMUX RequestGeneneratorPolarity selection
178   * @{
179   */
180 #define HAL_DMAMUX_REQ_GEN_NO_EVENT       LL_DMAMUX_REQ_GEN_NO_EVENT            /*!< block request generator events                     */
181 #define HAL_DMAMUX_REQ_GEN_RISING         LL_DMAMUX_REQ_GEN_POL_RISING          /*!< generate request on rising edge events             */
182 #define HAL_DMAMUX_REQ_GEN_FALLING        LL_DMAMUX_REQ_GEN_POL_FALLING         /*!< generate request on falling edge events            */
183 #define HAL_DMAMUX_REQ_GEN_RISING_FALLING LL_DMAMUX_REQ_GEN_POL_RISING_FALLING  /*!< generate request on rising and falling edge events */
184 
185 /**
186   * @}
187   */
188 
189 /**
190   * @}
191   */
192 
193 /* Exported macro ------------------------------------------------------------*/
194 
195 /* Exported functions --------------------------------------------------------*/
196 /** @addtogroup DMAEx_Exported_Functions
197   * @{
198   */
199 
200 /* IO operation functions *****************************************************/
201 /** @addtogroup DMAEx_Exported_Functions_Group1
202   * @{
203   */
204 
205 /* ------------------------- REQUEST -----------------------------------------*/
206 HAL_StatusTypeDef HAL_DMAEx_ConfigMuxRequestGenerator(DMA_HandleTypeDef *hdma,
207                                                       HAL_DMA_MuxRequestGeneratorConfigTypeDef *pRequestGeneratorConfig);
208 HAL_StatusTypeDef HAL_DMAEx_EnableMuxRequestGenerator(DMA_HandleTypeDef *hdma);
209 HAL_StatusTypeDef HAL_DMAEx_DisableMuxRequestGenerator(DMA_HandleTypeDef *hdma);
210 /* -------------------------------------------------------------------------- */
211 
212 /* ------------------------- SYNCHRO -----------------------------------------*/
213 HAL_StatusTypeDef HAL_DMAEx_ConfigMuxSync(DMA_HandleTypeDef *hdma, HAL_DMA_MuxSyncConfigTypeDef *pSyncConfig);
214 /* -------------------------------------------------------------------------- */
215 
216 void              HAL_DMAEx_MUX_IRQHandler(DMA_HandleTypeDef *hdma);
217 
218 /**
219   * @}
220   */
221 
222 /**
223   * @}
224   */
225 
226 
227 /* Private macros ------------------------------------------------------------*/
228 /** @defgroup DMAEx_Private_Macros DMAEx Private Macros
229   * @brief    DMAEx private macros
230   * @{
231   */
232 
233 #define IS_DMAMUX_SYNC_SIGNAL_ID(SIGNAL_ID)             (((SIGNAL_ID) == HAL_DMAMUX1_SYNC_EXTI0) || \
234                                                          (((SIGNAL_ID) >= HAL_DMAMUX1_SYNC_EXTI1) && \
235                                                           ((SIGNAL_ID) <= HAL_DMAMUX1_MAX_SYNC)))
236 
237 #define IS_DMAMUX_SYNC_REQUEST_NUMBER(REQUEST_NUMBER)   (((REQUEST_NUMBER) > 0U) && ((REQUEST_NUMBER) <= 32U))
238 
239 #define IS_DMAMUX_SYNC_POLARITY(POLARITY)               (((POLARITY) == HAL_DMAMUX_SYNC_NO_EVENT) || \
240                                                          ((POLARITY) == HAL_DMAMUX_SYNC_RISING)   || \
241                                                          ((POLARITY) == HAL_DMAMUX_SYNC_FALLING)  || \
242                                                          ((POLARITY) == HAL_DMAMUX_SYNC_RISING_FALLING))
243 
244 #define IS_DMAMUX_SYNC_STATE(SYNC)                      (((SYNC) == DISABLE)   || ((SYNC) == ENABLE))
245 
246 #define IS_DMAMUX_SYNC_EVENT(EVENT)                     (((EVENT) == DISABLE)   || \
247                                                          ((EVENT) == ENABLE))
248 
249 #define IS_DMAMUX_REQUEST_GEN_SIGNAL_ID(SIGNAL_ID)      (((SIGNAL_ID) == HAL_DMAMUX1_REQ_GEN_EXTI0) || \
250                                                          (((SIGNAL_ID) >= HAL_DMAMUX1_REQ_GEN_EXTI1) && \
251                                                           ((SIGNAL_ID) <= HAL_DMAMUX1_MAX_REQ_GEN)))
252 
253 #define IS_DMAMUX_REQUEST_GEN_REQUEST_NUMBER(REQUEST_NUMBER) (((REQUEST_NUMBER) > 0U) && ((REQUEST_NUMBER) <= 32U))
254 
255 #define IS_DMAMUX_REQUEST_GEN_POLARITY(POLARITY)        (((POLARITY) == HAL_DMAMUX_REQ_GEN_NO_EVENT)|| \
256                                                          ((POLARITY) == HAL_DMAMUX_REQ_GEN_RISING)  || \
257                                                          ((POLARITY) == HAL_DMAMUX_REQ_GEN_FALLING) || \
258                                                          ((POLARITY) == HAL_DMAMUX_REQ_GEN_RISING_FALLING))
259 
260 /**
261   * @}
262   */
263 
264 
265 /**
266   * @}
267   */
268 
269 /**
270   * @}
271   */
272 
273 #ifdef __cplusplus
274 }
275 #endif
276 
277 #endif /* STM32G0xx_HAL_DMA_EX_H */
278 
279