summaryrefslogblamecommitdiff
path: root/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_exti.c
blob: ae674cf62786de54bd2d60156e9b53408e6c1655 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456







































































































































































































































































































































































































































































                                                                                                              
/**
  ******************************************************************************
  * @file    stm32h7xx_ll_exti.c
  * @author  MCD Application Team
  * @brief   EXTI LL module driver.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2017 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
#if defined(USE_FULL_LL_DRIVER)

/* Includes ------------------------------------------------------------------*/
#include "stm32h7xx_ll_exti.h"
#ifdef  USE_FULL_ASSERT
#include "stm32_assert.h"
#else
#define assert_param(expr) ((void)0U)
#endif

/** @addtogroup STM32H7xx_LL_Driver
  * @{
  */

#if defined (EXTI)

/** @defgroup EXTI_LL EXTI
  * @{
  */

/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private constants ---------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/** @addtogroup EXTI_LL_Private_Macros
  * @{
  */

#define IS_LL_EXTI_LINE_0_31(__VALUE__)              (((__VALUE__) & ~LL_EXTI_LINE_ALL_0_31)  == 0x00000000U)
#define IS_LL_EXTI_LINE_32_63(__VALUE__)             (((__VALUE__) & ~LL_EXTI_LINE_ALL_32_63) == 0x00000000U)
#define IS_LL_EXTI_LINE_64_95(__VALUE__)             (((__VALUE__) & ~LL_EXTI_LINE_ALL_64_95) == 0x00000000U)

#define IS_LL_EXTI_MODE(__VALUE__)                   (((__VALUE__) == LL_EXTI_MODE_IT)            \
                                                   || ((__VALUE__) == LL_EXTI_MODE_EVENT)         \
                                                   || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT))


#define IS_LL_EXTI_TRIGGER(__VALUE__)                (((__VALUE__) == LL_EXTI_TRIGGER_NONE)       \
                                                   || ((__VALUE__) == LL_EXTI_TRIGGER_RISING)     \
                                                   || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING)    \
                                                   || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING))

/**
  * @}
  */

/* Private function prototypes -----------------------------------------------*/

/* Exported functions --------------------------------------------------------*/
/** @addtogroup EXTI_LL_Exported_Functions
  * @{
  */

/** @addtogroup EXTI_LL_EF_Init
  * @{
  */

/**
  * @brief  De-initialize the EXTI registers to their default reset values.
  * @retval An ErrorStatus enumeration value:
  *          - SUCCESS: EXTI registers are de-initialized
  *          - ERROR: not applicable
  */
ErrorStatus LL_EXTI_DeInit(void)
{
  /* Rising Trigger selection register set to default reset values */
  LL_EXTI_WriteReg(RTSR1,  0x00000000U);
  LL_EXTI_WriteReg(RTSR2,  0x00000000U);
  LL_EXTI_WriteReg(RTSR3,  0x00000000U);

  /* Falling Trigger selection register set to default reset values */
  LL_EXTI_WriteReg(FTSR1,  0x00000000U);
  LL_EXTI_WriteReg(FTSR2,  0x00000000U);
  LL_EXTI_WriteReg(FTSR3,  0x00000000U);

  /* Software interrupt event register set to default reset values */
  LL_EXTI_WriteReg(SWIER1, 0x00000000U);
  LL_EXTI_WriteReg(SWIER2, 0x00000000U);
  LL_EXTI_WriteReg(SWIER3, 0x00000000U);

  /* D3 Pending register set to default reset values */
  LL_EXTI_WriteReg(D3PMR1, 0x00000000U);
  LL_EXTI_WriteReg(D3PMR2, 0x00000000U);
  LL_EXTI_WriteReg(D3PMR3, 0x00000000U);

  /* D3 Pending clear selection register low to default reset values */
  LL_EXTI_WriteReg(D3PCR1L, 0x00000000U);
  LL_EXTI_WriteReg(D3PCR2L, 0x00000000U);
  LL_EXTI_WriteReg(D3PCR3L, 0x00000000U);

  /* D3 Pending clear selection register high to default reset values */
  LL_EXTI_WriteReg(D3PCR1H, 0x00000000U);
  LL_EXTI_WriteReg(D3PCR2H, 0x00000000U);
  LL_EXTI_WriteReg(D3PCR3H, 0x00000000U);

  /* Interrupt mask register reset */
  LL_EXTI_WriteReg(IMR1, 0x00000000U);
  LL_EXTI_WriteReg(IMR2, 0x00000000U);
  LL_EXTI_WriteReg(IMR3, 0x00000000U);

  /*  Event mask register reset */
  LL_EXTI_WriteReg(EMR1, 0x00000000U);
  LL_EXTI_WriteReg(EMR2, 0x00000000U);
  LL_EXTI_WriteReg(EMR3, 0x00000000U);

  /* Clear Pending requests */
  LL_EXTI_WriteReg(PR1, EXTI_PR1_PR_Msk);
  LL_EXTI_WriteReg(PR2, EXTI_PR2_PR_Msk);
  LL_EXTI_WriteReg(PR3, EXTI_PR3_PR_Msk);

#if defined(DUAL_CORE)
  /* Interrupt mask register set to default reset values  for Core 2 (Coretx-M4)*/
  LL_EXTI_WriteReg(C2IMR1, 0x00000000U);
  LL_EXTI_WriteReg(C2IMR2, 0x00000000U);
  LL_EXTI_WriteReg(C2IMR3, 0x00000000U);

  /*  Event mask register set to default reset values */
  LL_EXTI_WriteReg(C2EMR1, 0x00000000U);
  LL_EXTI_WriteReg(C2EMR2, 0x00000000U);
  LL_EXTI_WriteReg(C2EMR3, 0x00000000U);

  /* Clear Pending requests */
  LL_EXTI_WriteReg(C2PR1, EXTI_PR1_PR_Msk);
  LL_EXTI_WriteReg(C2PR2, EXTI_PR2_PR_Msk);
  LL_EXTI_WriteReg(C2PR3, EXTI_PR3_PR_Msk);

#endif /* DUAL_CORE*/
  return SUCCESS;
}

/**
  * @brief  Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
  * @param  EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
  * @retval An ErrorStatus enumeration value:
  *          - SUCCESS: EXTI registers are initialized
  *          - ERROR: not applicable
  */
ErrorStatus LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
{
  ErrorStatus status = SUCCESS;
  /* Check the parameters */
  assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
  assert_param(IS_LL_EXTI_LINE_32_63(EXTI_InitStruct->Line_32_63));
  assert_param(IS_LL_EXTI_LINE_64_95(EXTI_InitStruct->Line_64_95));
  assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
  assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));

  /* ENABLE LineCommand */
  if (EXTI_InitStruct->LineCommand != DISABLE)
  {
    assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));

    /* Configure EXTI Lines in range from 0 to 31 */
    if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
    {
      if((EXTI_InitStruct->Mode & LL_EXTI_MODE_IT) == LL_EXTI_MODE_IT)
      {
        /* Enable IT on provided Lines for Cortex-M7*/
        LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
      }
      else
      {
        /* Disable IT on provided Lines for Cortex-M7*/
        LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
      }

      if((EXTI_InitStruct->Mode & LL_EXTI_MODE_EVENT) == LL_EXTI_MODE_EVENT)
      {
        /* Enable event on provided Lines for Cortex-M7 */
        LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
      }
      else
      {
        /* Disable event on provided Lines for Cortex-M7 */
        LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
      }
#if defined(DUAL_CORE)
      if((EXTI_InitStruct->Mode & LL_EXTI_MODE_C2_IT) == LL_EXTI_MODE_C2_IT)
      {
        /* Enable IT on provided Lines for Cortex-M4 */
        LL_C2_EXTI_EnableIT_0_31 (EXTI_InitStruct->Line_0_31);
      }
      else
      {
        /* Disable IT on provided Lines for Cortex-M4*/
        LL_C2_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
      }

      if((EXTI_InitStruct->Mode & LL_EXTI_MODE_C2_EVENT) == LL_EXTI_MODE_C2_EVENT)
      {
        /* Enable event on provided Lines for Cortex-M4 */
        LL_C2_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
      }
      else
      {
        /* Disable event on provided Lines for Cortex-M4*/
        LL_C2_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
      }
#endif /* DUAL_CORE */

      if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
      {
        switch (EXTI_InitStruct->Trigger)
        {
          case LL_EXTI_TRIGGER_RISING:
            /* First Disable Falling Trigger on provided Lines */
            LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
            /* Then Enable Rising Trigger on provided Lines */
            LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
            break;
          case LL_EXTI_TRIGGER_FALLING:
            /* First Disable Rising Trigger on provided Lines */
            LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
            /* Then Enable Falling Trigger on provided Lines */
            LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
            break;
          case LL_EXTI_TRIGGER_RISING_FALLING:
            LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
            LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
            break;
          default:
            status = ERROR;
            break;
        }
      }
    }
    /* Configure EXTI Lines in range from 32 to 63 */
    if (EXTI_InitStruct->Line_32_63 != LL_EXTI_LINE_NONE)
    {
      if((EXTI_InitStruct->Mode & LL_EXTI_MODE_IT) == LL_EXTI_MODE_IT)
      {
        /* Enable IT on provided Lines for Cortex-M7*/
        LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
      }
      else
      {
        /* Disable IT on provided Lines for Cortex-M7*/
        LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
      }

      if((EXTI_InitStruct->Mode & LL_EXTI_MODE_EVENT) == LL_EXTI_MODE_EVENT)
      {
        /* Enable event on provided Lines for Cortex-M7 */
        LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
      }
      else
      {
        /* Disable event on provided Lines for Cortex-M7 */
        LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
      }
#if defined(DUAL_CORE)
      if((EXTI_InitStruct->Mode & LL_EXTI_MODE_C2_IT) == LL_EXTI_MODE_C2_IT)
      {
        /* Enable IT on provided Lines for Cortex-M4 */
        LL_C2_EXTI_EnableIT_32_63 (EXTI_InitStruct->Line_32_63);
      }
      else
      {
        /* Disable IT on provided Lines for Cortex-M4 */
        LL_C2_EXTI_DisableIT_32_63 (EXTI_InitStruct->Line_32_63);
      }

      if((EXTI_InitStruct->Mode & LL_EXTI_MODE_C2_EVENT) == LL_EXTI_MODE_C2_EVENT)
      {
        /* Enable event on provided Lines for Cortex-M4 */
        LL_C2_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
      }
      else
      {
        /* Disable event on provided Lines for Cortex-M4 */
        LL_C2_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
      }
#endif /* DUAL_CORE */

      if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
      {
        switch (EXTI_InitStruct->Trigger)
        {
          case LL_EXTI_TRIGGER_RISING:
            /* First Disable Falling Trigger on provided Lines */
            LL_EXTI_DisableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
            /* Then Enable IT on provided Lines */
            LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
            break;
          case LL_EXTI_TRIGGER_FALLING:
            /* First Disable Rising Trigger on provided Lines */
            LL_EXTI_DisableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
            /* Then Enable Falling Trigger on provided Lines */
            LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
            break;
          case LL_EXTI_TRIGGER_RISING_FALLING:
            LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
            LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
            break;
          default:
            status = ERROR;
            break;
        }
      }
    }
    /* Configure EXTI Lines in range from 64 to 95 */
    if (EXTI_InitStruct->Line_64_95 != LL_EXTI_LINE_NONE)
    {
      if((EXTI_InitStruct->Mode & LL_EXTI_MODE_IT) == LL_EXTI_MODE_IT)
      {
        /* Enable IT on provided Lines for Cortex-M7*/
        LL_EXTI_EnableIT_64_95(EXTI_InitStruct->Line_64_95);
      }
      else
      {
        /* Disable IT on provided Lines for Cortex-M7*/
        LL_EXTI_DisableIT_64_95(EXTI_InitStruct->Line_64_95);
      }

      if((EXTI_InitStruct->Mode & LL_EXTI_MODE_EVENT) == LL_EXTI_MODE_EVENT)
      {
        /* Enable event on provided Lines for Cortex-M7 */
        LL_EXTI_EnableEvent_64_95(EXTI_InitStruct->Line_64_95);
      }
      else
      {
        /* Disable event on provided Lines for Cortex-M7 */
        LL_EXTI_DisableEvent_64_95(EXTI_InitStruct->Line_64_95);
      }

#if defined(DUAL_CORE)
      if((EXTI_InitStruct->Mode & LL_EXTI_MODE_C2_IT) == LL_EXTI_MODE_C2_IT)
      {
        /* Enable IT on provided Lines for Cortex-M4 */
        LL_C2_EXTI_EnableIT_64_95 (EXTI_InitStruct->Line_64_95);
      }
      else
      {
        /* Disable IT on provided Lines for Cortex-M4 */
        LL_C2_EXTI_DisableIT_64_95 (EXTI_InitStruct->Line_64_95);
      }

      if((EXTI_InitStruct->Mode & LL_EXTI_MODE_C2_EVENT) == LL_EXTI_MODE_C2_EVENT)
      {
        /* Enable event on provided Lines for Cortex-M4 */
        LL_C2_EXTI_EnableEvent_64_95(EXTI_InitStruct->Line_64_95);
      }
      else
      {
        /* Disable event on provided Lines for Cortex-M4 */
        LL_C2_EXTI_DisableEvent_64_95(EXTI_InitStruct->Line_64_95);
      }
#endif /* DUAL_CORE */

      if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
      {
        switch (EXTI_InitStruct->Trigger)
        {
          case LL_EXTI_TRIGGER_RISING:
            /* First Disable Falling Trigger on provided Lines */
            LL_EXTI_DisableFallingTrig_64_95(EXTI_InitStruct->Line_64_95);
            /* Then Enable IT on provided Lines */
            LL_EXTI_EnableRisingTrig_64_95(EXTI_InitStruct->Line_64_95);
            break;
          case LL_EXTI_TRIGGER_FALLING:
            /* First Disable Rising Trigger on provided Lines */
            LL_EXTI_DisableRisingTrig_64_95(EXTI_InitStruct->Line_64_95);
            /* Then Enable Falling Trigger on provided Lines */
            LL_EXTI_EnableFallingTrig_64_95(EXTI_InitStruct->Line_64_95);
            break;
          case LL_EXTI_TRIGGER_RISING_FALLING:
            LL_EXTI_EnableRisingTrig_64_95(EXTI_InitStruct->Line_64_95);
            LL_EXTI_EnableFallingTrig_64_95(EXTI_InitStruct->Line_64_95);
            break;
          default:
            status = ERROR;
            break;
        }
      }
    }
  }
  else /* DISABLE LineCommand */
  {
    /* Disable IT on provided Lines for Cortex-M7*/
    LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
    LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
    LL_EXTI_DisableIT_64_95(EXTI_InitStruct->Line_64_95);

    /* Disable event on provided Lines for Cortex-M7 */
    LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
    LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
    LL_EXTI_DisableEvent_64_95(EXTI_InitStruct->Line_64_95);

#if defined(DUAL_CORE)
    /* Disable IT on provided Lines for Cortex-M4*/
    LL_C2_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
    LL_C2_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
    LL_C2_EXTI_DisableIT_64_95(EXTI_InitStruct->Line_64_95);

    /* Disable event on provided Lines for Cortex-M4 */
    LL_C2_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
    LL_C2_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
    LL_C2_EXTI_DisableEvent_64_95(EXTI_InitStruct->Line_64_95);
#endif /* DUAL_CORE */
  }

  return status;
}

/**
  * @brief  Set each @ref LL_EXTI_InitTypeDef field to default value.
  * @param  EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
  * @retval None
  */
void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
{
  EXTI_InitStruct->Line_0_31      = LL_EXTI_LINE_NONE;
  EXTI_InitStruct->Line_32_63     = LL_EXTI_LINE_NONE;
  EXTI_InitStruct->Line_64_95     = LL_EXTI_LINE_NONE;
  EXTI_InitStruct->LineCommand    = DISABLE;
  EXTI_InitStruct->Mode           = LL_EXTI_MODE_IT;
  EXTI_InitStruct->Trigger        = LL_EXTI_TRIGGER_FALLING;
}

/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

#endif /* defined (EXTI) */

/**
  * @}
  */

#endif /* USE_FULL_LL_DRIVER */