Subversion Repositories EDIS_Ignition

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 18
Line 1... Line 1...
1
/**
1
/**
2
  ******************************************************************************
2
  ******************************************************************************
3
  * @file    stm32f1xx_hal_exti.c
3
  * @file    stm32f1xx_hal_exti.c
4
  * @author  MCD Application Team
4
  * @author  MCD Application Team
5
  * @brief   EXTI HAL module driver.
5
  * @brief   EXTI HAL module driver.
6
  *          This file provides firmware functions to manage the following
6
  *          This file provides firmware functions to manage the following
7
  *          functionalities of the Extended Interrupts and events controller (EXTI) peripheral:
7
  *          functionalities of the Extended Interrupts and events controller (EXTI) peripheral:
8
  *           + Initialization and de-initialization functions
8
  *           + Initialization and de-initialization functions
9
  *           + IO operation functions
9
  *           + IO operation functions
10
  *
10
  *
11
  @verbatim
11
  ******************************************************************************
12
  ==============================================================================
12
  * @attention
13
                    ##### EXTI Peripheral features #####
13
  *
14
  ==============================================================================
14
  * Copyright (c) 2019 STMicroelectronics.
15
  [..]
15
  * All rights reserved.
16
    (+) Each Exti line can be configured within this driver.
16
  *
17
 
17
  * This software is licensed under terms that can be found in the LICENSE file
18
    (+) Exti line can be configured in 3 different modes
18
  * in the root directory of this software component.
19
        (++) Interrupt
19
  * If no LICENSE file comes with this software, it is provided AS-IS.
20
        (++) Event
20
  *
21
        (++) Both of them
21
  ******************************************************************************
22
 
22
  @verbatim
23
    (+) Configurable Exti lines can be configured with 3 different triggers
23
  ==============================================================================
24
        (++) Rising
24
                    ##### EXTI Peripheral features #####
25
        (++) Falling
25
  ==============================================================================
26
        (++) Both of them
26
  [..]
27
 
27
    (+) Each Exti line can be configured within this driver.
28
    (+) When set in interrupt mode, configurable Exti lines have two different
28
 
29
        interrupts pending registers which allow to distinguish which transition
29
    (+) Exti line can be configured in 3 different modes
30
        occurs:
30
        (++) Interrupt
31
        (++) Rising edge pending interrupt
31
        (++) Event
32
        (++) Falling
32
        (++) Both of them
33
 
33
 
34
    (+) Exti lines 0 to 15 are linked to gpio pin number 0 to 15. Gpio port can
34
    (+) Configurable Exti lines can be configured with 3 different triggers
35
        be selected through multiplexer.
35
        (++) Rising
36
 
36
        (++) Falling
37
                     ##### How to use this driver #####
37
        (++) Both of them
38
  ==============================================================================
38
 
39
  [..]
39
    (+) When set in interrupt mode, configurable Exti lines have two different
40
 
40
        interrupts pending registers which allow to distinguish which transition
41
    (#) Configure the EXTI line using HAL_EXTI_SetConfigLine().
41
        occurs:
42
        (++) Choose the interrupt line number by setting "Line" member from
42
        (++) Rising edge pending interrupt
43
             EXTI_ConfigTypeDef structure.
43
        (++) Falling
44
        (++) Configure the interrupt and/or event mode using "Mode" member from
44
 
45
             EXTI_ConfigTypeDef structure.
45
    (+) Exti lines 0 to 15 are linked to gpio pin number 0 to 15. Gpio port can
46
        (++) For configurable lines, configure rising and/or falling trigger
46
        be selected through multiplexer.
47
             "Trigger" member from EXTI_ConfigTypeDef structure.
47
 
48
        (++) For Exti lines linked to gpio, choose gpio port using "GPIOSel"
48
                     ##### How to use this driver #####
49
             member from GPIO_InitTypeDef structure.
49
  ==============================================================================
50
 
50
  [..]
51
    (#) Get current Exti configuration of a dedicated line using
51
 
52
        HAL_EXTI_GetConfigLine().
52
    (#) Configure the EXTI line using HAL_EXTI_SetConfigLine().
53
        (++) Provide exiting handle as parameter.
53
        (++) Choose the interrupt line number by setting "Line" member from
54
        (++) Provide pointer on EXTI_ConfigTypeDef structure as second parameter.
54
             EXTI_ConfigTypeDef structure.
55
 
55
        (++) Configure the interrupt and/or event mode using "Mode" member from
56
    (#) Clear Exti configuration of a dedicated line using HAL_EXTI_GetConfigLine().
56
             EXTI_ConfigTypeDef structure.
57
        (++) Provide exiting handle as parameter.
57
        (++) For configurable lines, configure rising and/or falling trigger
58
 
58
             "Trigger" member from EXTI_ConfigTypeDef structure.
59
    (#) Register callback to treat Exti interrupts using HAL_EXTI_RegisterCallback().
59
        (++) For Exti lines linked to gpio, choose gpio port using "GPIOSel"
60
        (++) Provide exiting handle as first parameter.
60
             member from GPIO_InitTypeDef structure.
61
        (++) Provide which callback will be registered using one value from
61
 
62
             EXTI_CallbackIDTypeDef.
62
    (#) Get current Exti configuration of a dedicated line using
63
        (++) Provide callback function pointer.
63
        HAL_EXTI_GetConfigLine().
64
 
64
        (++) Provide exiting handle as parameter.
65
    (#) Get interrupt pending bit using HAL_EXTI_GetPending().
65
        (++) Provide pointer on EXTI_ConfigTypeDef structure as second parameter.
66
 
66
 
67
    (#) Clear interrupt pending bit using HAL_EXTI_GetPending().
67
    (#) Clear Exti configuration of a dedicated line using HAL_EXTI_ClearConfigLine().
68
 
68
        (++) Provide exiting handle as parameter.
69
    (#) Generate software interrupt using HAL_EXTI_GenerateSWI().
69
 
70
 
70
    (#) Register callback to treat Exti interrupts using HAL_EXTI_RegisterCallback().
71
  @endverbatim
71
        (++) Provide exiting handle as first parameter.
72
  ******************************************************************************
72
        (++) Provide which callback will be registered using one value from
73
  * @attention
73
             EXTI_CallbackIDTypeDef.
74
  *
74
        (++) Provide callback function pointer.
75
  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
75
 
76
  * All rights reserved.</center></h2>
76
    (#) Get interrupt pending bit using HAL_EXTI_GetPending().
77
  *
77
 
78
  * This software component is licensed by ST under BSD 3-Clause license,
78
    (#) Clear interrupt pending bit using HAL_EXTI_ClearPending().
79
  * the "License"; You may not use this file except in compliance with the
79
 
80
  * License. You may obtain a copy of the License at:
80
    (#) Generate software interrupt using HAL_EXTI_GenerateSWI().
81
  *                        opensource.org/licenses/BSD-3-Clause
81
 
82
  *
82
  @endverbatim
83
  ******************************************************************************
83
  */
84
  */
84
 
85
 
85
/* Includes ------------------------------------------------------------------*/
86
/* Includes ------------------------------------------------------------------*/
86
#include "stm32f1xx_hal.h"
87
#include "stm32f1xx_hal.h"
87
 
88
 
88
/** @addtogroup STM32F1xx_HAL_Driver
89
/** @addtogroup STM32F1xx_HAL_Driver
89
  * @{
90
  * @{
90
  */
91
  */
91
 
92
 
92
/** @addtogroup EXTI
93
/** @addtogroup EXTI
93
  * @{
94
  * @{
94
  */
95
  */
95
/** MISRA C:2012 deviation rule has been granted for following rule:
96
/** MISRA C:2012 deviation rule has been granted for following rule:
96
  * Rule-18.1_b - Medium: Array `EXTICR' 1st subscript interval [0,7] may be out
97
  * Rule-18.1_b - Medium: Array `EXTICR' 1st subscript interval [0,7] may be out
97
  * of bounds [0,3] in following API :
98
  * of bounds [0,3] in following API :
98
  * HAL_EXTI_SetConfigLine
99
  * HAL_EXTI_SetConfigLine
99
  * HAL_EXTI_GetConfigLine
100
  * HAL_EXTI_GetConfigLine
100
  * HAL_EXTI_ClearConfigLine
101
  * HAL_EXTI_ClearConfigLine
101
  */
102
  */
102
 
103
 
103
#ifdef HAL_EXTI_MODULE_ENABLED
104
#ifdef HAL_EXTI_MODULE_ENABLED
104
 
105
 
105
/* Private typedef -----------------------------------------------------------*/
106
/* Private typedef -----------------------------------------------------------*/
106
/* Private defines -----------------------------------------------------------*/
107
/* Private defines -----------------------------------------------------------*/
107
/** @defgroup EXTI_Private_Constants EXTI Private Constants
108
/** @defgroup EXTI_Private_Constants EXTI Private Constants
108
  * @{
109
  * @{
109
  */
110
  */
110
 
111
 
111
/**
112
/**
112
  * @}
113
  * @}
113
  */
114
  */
114
 
115
 
115
/* Private macros ------------------------------------------------------------*/
116
/* Private macros ------------------------------------------------------------*/
116
/* Private variables ---------------------------------------------------------*/
117
/* Private variables ---------------------------------------------------------*/
117
/* Private function prototypes -----------------------------------------------*/
118
/* Private function prototypes -----------------------------------------------*/
118
/* Exported functions --------------------------------------------------------*/
119
/* Exported functions --------------------------------------------------------*/
119
 
120
 
120
/** @addtogroup EXTI_Exported_Functions
121
/** @addtogroup EXTI_Exported_Functions
121
  * @{
122
  * @{
122
  */
123
  */
123
 
124
 
124
/** @addtogroup EXTI_Exported_Functions_Group1
125
/** @addtogroup EXTI_Exported_Functions_Group1
125
  *  @brief    Configuration functions
126
  *  @brief    Configuration functions
126
  *
127
  *
127
@verbatim
128
@verbatim
128
 ===============================================================================
129
 ===============================================================================
129
              ##### Configuration functions #####
130
              ##### Configuration functions #####
130
 ===============================================================================
131
 ===============================================================================
131
 
132
 
132
@endverbatim
133
@endverbatim
133
  * @{
134
  * @{
134
  */
135
  */
135
 
136
 
136
/**
137
/**
137
  * @brief  Set configuration of a dedicated Exti line.
138
  * @brief  Set configuration of a dedicated Exti line.
138
  * @param  hexti Exti handle.
139
  * @param  hexti Exti handle.
139
  * @param  pExtiConfig Pointer on EXTI configuration to be set.
140
  * @param  pExtiConfig Pointer on EXTI configuration to be set.
140
  * @retval HAL Status.
141
  * @retval HAL Status.
141
  */
142
  */
142
HAL_StatusTypeDef HAL_EXTI_SetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig)
143
HAL_StatusTypeDef HAL_EXTI_SetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig)
143
{
144
{
144
  uint32_t regval;
145
  uint32_t regval;
145
  uint32_t linepos;
146
  uint32_t linepos;
146
  uint32_t maskline;
147
  uint32_t maskline;
147
 
148
 
148
  /* Check null pointer */
149
  /* Check null pointer */
149
  if ((hexti == NULL) || (pExtiConfig == NULL))
150
  if ((hexti == NULL) || (pExtiConfig == NULL))
150
  {
151
  {
151
    return HAL_ERROR;
152
    return HAL_ERROR;
152
  }
153
  }
153
 
154
 
154
  /* Check parameters */
155
  /* Check parameters */
155
  assert_param(IS_EXTI_LINE(pExtiConfig->Line));
156
  assert_param(IS_EXTI_LINE(pExtiConfig->Line));
156
  assert_param(IS_EXTI_MODE(pExtiConfig->Mode));
157
  assert_param(IS_EXTI_MODE(pExtiConfig->Mode));
157
 
158
 
158
  /* Assign line number to handle */
159
  /* Assign line number to handle */
159
  hexti->Line = pExtiConfig->Line;
160
  hexti->Line = pExtiConfig->Line;
160
 
161
 
161
  /* Compute line mask */
162
  /* Compute line mask */
162
  linepos = (pExtiConfig->Line & EXTI_PIN_MASK);
163
  linepos = (pExtiConfig->Line & EXTI_PIN_MASK);
163
  maskline = (1uL << linepos);
164
  maskline = (1uL << linepos);
164
 
165
 
165
  /* Configure triggers for configurable lines */
166
  /* Configure triggers for configurable lines */
166
  if ((pExtiConfig->Line & EXTI_CONFIG) != 0x00u)
167
  if ((pExtiConfig->Line & EXTI_CONFIG) != 0x00u)
167
  {
168
  {
168
    assert_param(IS_EXTI_TRIGGER(pExtiConfig->Trigger));
169
    assert_param(IS_EXTI_TRIGGER(pExtiConfig->Trigger));
169
 
170
 
170
    /* Configure rising trigger */
171
    /* Configure rising trigger */
171
    /* Mask or set line */
172
    /* Mask or set line */
172
    if ((pExtiConfig->Trigger & EXTI_TRIGGER_RISING) != 0x00u)
173
    if ((pExtiConfig->Trigger & EXTI_TRIGGER_RISING) != 0x00u)
173
    {
174
    {
174
      EXTI->RTSR |= maskline;
175
      EXTI->RTSR |= maskline;
175
    }
176
    }
176
    else
177
    else
177
    {
178
    {
178
      EXTI->RTSR &= ~maskline;
179
      EXTI->RTSR &= ~maskline;
179
    }
180
    }
180
 
181
 
181
    /* Configure falling trigger */
182
    /* Configure falling trigger */
182
    /* Mask or set line */
183
    /* Mask or set line */
183
    if ((pExtiConfig->Trigger & EXTI_TRIGGER_FALLING) != 0x00u)
184
    if ((pExtiConfig->Trigger & EXTI_TRIGGER_FALLING) != 0x00u)
184
    {
185
    {
185
      EXTI->FTSR |= maskline;
186
      EXTI->FTSR |= maskline;
186
    }
187
    }
187
    else
188
    else
188
    {
189
    {
189
      EXTI->FTSR &= ~maskline;
190
      EXTI->FTSR &= ~maskline;
190
    }
191
    }
191
 
192
 
192
 
193
 
193
    /* Configure gpio port selection in case of gpio exti line */
194
    /* Configure gpio port selection in case of gpio exti line */
194
    if ((pExtiConfig->Line & EXTI_GPIO) == EXTI_GPIO)
195
    if ((pExtiConfig->Line & EXTI_GPIO) == EXTI_GPIO)
195
    {
196
    {
196
      assert_param(IS_EXTI_GPIO_PORT(pExtiConfig->GPIOSel));
197
      assert_param(IS_EXTI_GPIO_PORT(pExtiConfig->GPIOSel));
197
      assert_param(IS_EXTI_GPIO_PIN(linepos));
198
      assert_param(IS_EXTI_GPIO_PIN(linepos));
198
     
199
     
199
      regval = AFIO->EXTICR[linepos >> 2u];
200
      regval = AFIO->EXTICR[linepos >> 2u];
200
      regval &= ~(AFIO_EXTICR1_EXTI0 << (AFIO_EXTICR1_EXTI1_Pos * (linepos & 0x03u)));
201
      regval &= ~(AFIO_EXTICR1_EXTI0 << (AFIO_EXTICR1_EXTI1_Pos * (linepos & 0x03u)));
201
      regval |= (pExtiConfig->GPIOSel << (AFIO_EXTICR1_EXTI1_Pos * (linepos & 0x03u)));
202
      regval |= (pExtiConfig->GPIOSel << (AFIO_EXTICR1_EXTI1_Pos * (linepos & 0x03u)));
202
      AFIO->EXTICR[linepos >> 2u] = regval;
203
      AFIO->EXTICR[linepos >> 2u] = regval;
203
    }
204
    }
204
  }
205
  }
205
 
206
 
206
  /* Configure interrupt mode : read current mode */
207
  /* Configure interrupt mode : read current mode */
207
  /* Mask or set line */
208
  /* Mask or set line */
208
  if ((pExtiConfig->Mode & EXTI_MODE_INTERRUPT) != 0x00u)
209
  if ((pExtiConfig->Mode & EXTI_MODE_INTERRUPT) != 0x00u)
209
  {
210
  {
210
    EXTI->IMR |= maskline;
211
    EXTI->IMR |= maskline;
211
  }
212
  }
212
  else
213
  else
213
  {
214
  {
214
    EXTI->IMR &= ~maskline;
215
    EXTI->IMR &= ~maskline;
215
  }
216
  }
216
 
217
 
217
  /* Configure event mode : read current mode */
218
  /* Configure event mode : read current mode */
218
  /* Mask or set line */
219
  /* Mask or set line */
219
  if ((pExtiConfig->Mode & EXTI_MODE_EVENT) != 0x00u)
220
  if ((pExtiConfig->Mode & EXTI_MODE_EVENT) != 0x00u)
220
  {
221
  {
221
    EXTI->EMR |= maskline;
222
    EXTI->EMR |= maskline;
222
  }
223
  }
223
  else
224
  else
224
  {
225
  {
225
    EXTI->EMR &= ~maskline;
226
    EXTI->EMR &= ~maskline;
226
  }
227
  }
227
 
228
 
228
  return HAL_OK;
229
  return HAL_OK;
229
}
230
}
230
 
231
 
231
/**
232
/**
232
  * @brief  Get configuration of a dedicated Exti line.
233
  * @brief  Get configuration of a dedicated Exti line.
233
  * @param  hexti Exti handle.
234
  * @param  hexti Exti handle.
234
  * @param  pExtiConfig Pointer on structure to store Exti configuration.
235
  * @param  pExtiConfig Pointer on structure to store Exti configuration.
235
  * @retval HAL Status.
236
  * @retval HAL Status.
236
  */
237
  */
237
HAL_StatusTypeDef HAL_EXTI_GetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig)
238
HAL_StatusTypeDef HAL_EXTI_GetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig)
238
{
239
{
239
  uint32_t regval;
240
  uint32_t regval;
240
  uint32_t linepos;
241
  uint32_t linepos;
241
  uint32_t maskline;
242
  uint32_t maskline;
242
 
243
 
243
  /* Check null pointer */
244
  /* Check null pointer */
244
  if ((hexti == NULL) || (pExtiConfig == NULL))
245
  if ((hexti == NULL) || (pExtiConfig == NULL))
245
  {
246
  {
246
    return HAL_ERROR;
247
    return HAL_ERROR;
247
  }
248
  }
248
 
249
 
249
  /* Check the parameter */
250
  /* Check the parameter */
250
  assert_param(IS_EXTI_LINE(hexti->Line));
251
  assert_param(IS_EXTI_LINE(hexti->Line));
251
 
252
 
252
  /* Store handle line number to configuration structure */
253
  /* Store handle line number to configuration structure */
253
  pExtiConfig->Line = hexti->Line;
254
  pExtiConfig->Line = hexti->Line;
254
 
255
 
255
  /* Compute line mask */
256
  /* Compute line mask */
256
  linepos = (pExtiConfig->Line & EXTI_PIN_MASK);
257
  linepos = (pExtiConfig->Line & EXTI_PIN_MASK);
257
  maskline = (1uL << linepos);
258
  maskline = (1uL << linepos);
258
 
259
 
259
  /* 1] Get core mode : interrupt */
260
  /* 1] Get core mode : interrupt */
260
 
261
 
261
  /* Check if selected line is enable */
262
  /* Check if selected line is enable */
262
  if ((EXTI->IMR & maskline) != 0x00u)
263
  if ((EXTI->IMR & maskline) != 0x00u)
263
  {
264
  {
264
    pExtiConfig->Mode = EXTI_MODE_INTERRUPT;
265
    pExtiConfig->Mode = EXTI_MODE_INTERRUPT;
265
  }
266
  }
266
  else
267
  else
267
  {
268
  {
268
    pExtiConfig->Mode = EXTI_MODE_NONE;
269
    pExtiConfig->Mode = EXTI_MODE_NONE;
269
  }
270
  }
270
 
271
 
271
  /* Get event mode */
272
  /* Get event mode */
272
  /* Check if selected line is enable */
273
  /* Check if selected line is enable */
273
  if ((EXTI->EMR & maskline) != 0x00u)
274
  if ((EXTI->EMR & maskline) != 0x00u)
274
  {
275
  {
275
    pExtiConfig->Mode |= EXTI_MODE_EVENT;
276
    pExtiConfig->Mode |= EXTI_MODE_EVENT;
276
  }
277
  }
277
 
278
 
278
  /* Get default Trigger and GPIOSel configuration */
279
  /* Get default Trigger and GPIOSel configuration */
279
  pExtiConfig->Trigger = EXTI_TRIGGER_NONE;
280
  pExtiConfig->Trigger = EXTI_TRIGGER_NONE;
280
  pExtiConfig->GPIOSel = 0x00u;
281
  pExtiConfig->GPIOSel = 0x00u;
281
 
282
 
282
  /* 2] Get trigger for configurable lines : rising */
283
  /* 2] Get trigger for configurable lines : rising */
283
  if ((pExtiConfig->Line & EXTI_CONFIG) != 0x00u)
284
  if ((pExtiConfig->Line & EXTI_CONFIG) != 0x00u)
284
  {
285
  {
285
    /* Check if configuration of selected line is enable */
286
    /* Check if configuration of selected line is enable */
286
    if ((EXTI->RTSR & maskline) != 0x00u)
287
    if ((EXTI->RTSR & maskline) != 0x00u)
287
    {
288
    {
288
      pExtiConfig->Trigger = EXTI_TRIGGER_RISING;
289
      pExtiConfig->Trigger = EXTI_TRIGGER_RISING;
289
    }
290
    }
290
 
291
 
291
    /* Get falling configuration */
292
    /* Get falling configuration */
292
    /* Check if configuration of selected line is enable */
293
    /* Check if configuration of selected line is enable */
293
    if ((EXTI->FTSR & maskline) != 0x00u)
294
    if ((EXTI->FTSR & maskline) != 0x00u)
294
    {
295
    {
295
      pExtiConfig->Trigger |= EXTI_TRIGGER_FALLING;
296
      pExtiConfig->Trigger |= EXTI_TRIGGER_FALLING;
296
    }
297
    }
297
 
298
 
298
    /* Get Gpio port selection for gpio lines */
299
    /* Get Gpio port selection for gpio lines */
299
    if ((pExtiConfig->Line & EXTI_GPIO) == EXTI_GPIO)
300
    if ((pExtiConfig->Line & EXTI_GPIO) == EXTI_GPIO)
300
    {
301
    {
301
      assert_param(IS_EXTI_GPIO_PIN(linepos));
302
      assert_param(IS_EXTI_GPIO_PIN(linepos));
302
 
303
 
303
      regval = AFIO->EXTICR[linepos >> 2u];
304
      regval = AFIO->EXTICR[linepos >> 2u];
304
      pExtiConfig->GPIOSel = (regval >> (AFIO_EXTICR1_EXTI1_Pos * (linepos & 0x03u))) & AFIO_EXTICR1_EXTI0;
305
      pExtiConfig->GPIOSel = ((regval << (AFIO_EXTICR1_EXTI1_Pos * (3uL - (linepos & 0x03u)))) >> 24);
305
    }
306
    }
306
  }
307
  }
307
 
308
 
308
  return HAL_OK;
309
  return HAL_OK;
309
}
310
}
310
 
311
 
311
/**
312
/**
312
  * @brief  Clear whole configuration of a dedicated Exti line.
313
  * @brief  Clear whole configuration of a dedicated Exti line.
313
  * @param  hexti Exti handle.
314
  * @param  hexti Exti handle.
314
  * @retval HAL Status.
315
  * @retval HAL Status.
315
  */
316
  */
316
HAL_StatusTypeDef HAL_EXTI_ClearConfigLine(EXTI_HandleTypeDef *hexti)
317
HAL_StatusTypeDef HAL_EXTI_ClearConfigLine(EXTI_HandleTypeDef *hexti)
317
{
318
{
318
  uint32_t regval;
319
  uint32_t regval;
319
  uint32_t linepos;
320
  uint32_t linepos;
320
  uint32_t maskline;
321
  uint32_t maskline;
321
 
322
 
322
  /* Check null pointer */
323
  /* Check null pointer */
323
  if (hexti == NULL)
324
  if (hexti == NULL)
324
  {
325
  {
325
    return HAL_ERROR;
326
    return HAL_ERROR;
326
  }
327
  }
327
 
328
 
328
  /* Check the parameter */
329
  /* Check the parameter */
329
  assert_param(IS_EXTI_LINE(hexti->Line));
330
  assert_param(IS_EXTI_LINE(hexti->Line));
330
 
331
 
331
  /* compute line mask */
332
  /* compute line mask */
332
  linepos = (hexti->Line & EXTI_PIN_MASK);
333
  linepos = (hexti->Line & EXTI_PIN_MASK);
333
  maskline = (1uL << linepos);
334
  maskline = (1uL << linepos);
334
 
335
 
335
  /* 1] Clear interrupt mode */
336
  /* 1] Clear interrupt mode */
336
  EXTI->IMR = (EXTI->IMR & ~maskline);
337
  EXTI->IMR = (EXTI->IMR & ~maskline);
337
 
338
 
338
  /* 2] Clear event mode */
339
  /* 2] Clear event mode */
339
  EXTI->EMR = (EXTI->EMR & ~maskline);
340
  EXTI->EMR = (EXTI->EMR & ~maskline);
340
 
341
 
341
  /* 3] Clear triggers in case of configurable lines */
342
  /* 3] Clear triggers in case of configurable lines */
342
  if ((hexti->Line & EXTI_CONFIG) != 0x00u)
343
  if ((hexti->Line & EXTI_CONFIG) != 0x00u)
343
  {
344
  {
344
    EXTI->RTSR = (EXTI->RTSR & ~maskline);
345
    EXTI->RTSR = (EXTI->RTSR & ~maskline);
345
    EXTI->FTSR = (EXTI->FTSR & ~maskline);
346
    EXTI->FTSR = (EXTI->FTSR & ~maskline);
346
 
347
 
347
    /* Get Gpio port selection for gpio lines */
348
    /* Get Gpio port selection for gpio lines */
348
    if ((hexti->Line & EXTI_GPIO) == EXTI_GPIO)
349
    if ((hexti->Line & EXTI_GPIO) == EXTI_GPIO)
349
    {
350
    {
350
      assert_param(IS_EXTI_GPIO_PIN(linepos));
351
      assert_param(IS_EXTI_GPIO_PIN(linepos));
351
 
352
 
352
      regval = AFIO->EXTICR[linepos >> 2u];
353
      regval = AFIO->EXTICR[linepos >> 2u];
353
      regval &= ~(AFIO_EXTICR1_EXTI0 << (AFIO_EXTICR1_EXTI1_Pos * (linepos & 0x03u)));
354
      regval &= ~(AFIO_EXTICR1_EXTI0 << (AFIO_EXTICR1_EXTI1_Pos * (linepos & 0x03u)));
354
      AFIO->EXTICR[linepos >> 2u] = regval;
355
      AFIO->EXTICR[linepos >> 2u] = regval;
355
    }
356
    }
356
  }
357
  }
357
 
358
 
358
  return HAL_OK;
359
  return HAL_OK;
359
}
360
}
360
 
361
 
361
/**
362
/**
362
  * @brief  Register callback for a dedicated Exti line.
363
  * @brief  Register callback for a dedicated Exti line.
363
  * @param  hexti Exti handle.
364
  * @param  hexti Exti handle.
364
  * @param  CallbackID User callback identifier.
365
  * @param  CallbackID User callback identifier.
365
  *         This parameter can be one of @arg @ref EXTI_CallbackIDTypeDef values.
366
  *         This parameter can be one of @arg @ref EXTI_CallbackIDTypeDef values.
366
  * @param  pPendingCbfn function pointer to be stored as callback.
367
  * @param  pPendingCbfn function pointer to be stored as callback.
367
  * @retval HAL Status.
368
  * @retval HAL Status.
368
  */
369
  */
369
HAL_StatusTypeDef HAL_EXTI_RegisterCallback(EXTI_HandleTypeDef *hexti, EXTI_CallbackIDTypeDef CallbackID, void (*pPendingCbfn)(void))
370
HAL_StatusTypeDef HAL_EXTI_RegisterCallback(EXTI_HandleTypeDef *hexti, EXTI_CallbackIDTypeDef CallbackID, void (*pPendingCbfn)(void))
370
{
371
{
371
  HAL_StatusTypeDef status = HAL_OK;
372
  HAL_StatusTypeDef status = HAL_OK;
372
 
373
 
373
  switch (CallbackID)
374
  switch (CallbackID)
374
  {
375
  {
375
    case  HAL_EXTI_COMMON_CB_ID:
376
    case  HAL_EXTI_COMMON_CB_ID:
376
      hexti->PendingCallback = pPendingCbfn;
377
      hexti->PendingCallback = pPendingCbfn;
377
      break;
378
      break;
378
 
379
 
379
    default:
380
    default:
380
      status = HAL_ERROR;
381
      status = HAL_ERROR;
381
      break;
382
      break;
382
  }
383
  }
383
 
384
 
384
  return status;
385
  return status;
385
}
386
}
386
 
387
 
387
/**
388
/**
388
  * @brief  Store line number as handle private field.
389
  * @brief  Store line number as handle private field.
389
  * @param  hexti Exti handle.
390
  * @param  hexti Exti handle.
390
  * @param  ExtiLine Exti line number.
391
  * @param  ExtiLine Exti line number.
391
  *         This parameter can be from 0 to @ref EXTI_LINE_NB.
392
  *         This parameter can be from 0 to @ref EXTI_LINE_NB.
392
  * @retval HAL Status.
393
  * @retval HAL Status.
393
  */
394
  */
394
HAL_StatusTypeDef HAL_EXTI_GetHandle(EXTI_HandleTypeDef *hexti, uint32_t ExtiLine)
395
HAL_StatusTypeDef HAL_EXTI_GetHandle(EXTI_HandleTypeDef *hexti, uint32_t ExtiLine)
395
{
396
{
396
  /* Check the parameters */
397
  /* Check the parameters */
397
  assert_param(IS_EXTI_LINE(ExtiLine));
398
  assert_param(IS_EXTI_LINE(ExtiLine));
398
 
399
 
399
  /* Check null pointer */
400
  /* Check null pointer */
400
  if (hexti == NULL)
401
  if (hexti == NULL)
401
  {
402
  {
402
    return HAL_ERROR;
403
    return HAL_ERROR;
403
  }
404
  }
404
  else
405
  else
405
  {
406
  {
406
    /* Store line number as handle private field */
407
    /* Store line number as handle private field */
407
    hexti->Line = ExtiLine;
408
    hexti->Line = ExtiLine;
408
 
409
 
409
    return HAL_OK;
410
    return HAL_OK;
410
  }
411
  }
411
}
412
}
412
 
413
 
413
/**
414
/**
414
  * @}
415
  * @}
415
  */
416
  */
416
 
417
 
417
/** @addtogroup EXTI_Exported_Functions_Group2
418
/** @addtogroup EXTI_Exported_Functions_Group2
418
  *  @brief EXTI IO functions.
419
  *  @brief EXTI IO functions.
419
  *
420
  *
420
@verbatim
421
@verbatim
421
 ===============================================================================
422
 ===============================================================================
422
                       ##### IO operation functions #####
423
                       ##### IO operation functions #####
423
 ===============================================================================
424
 ===============================================================================
424
 
425
 
425
@endverbatim
426
@endverbatim
426
  * @{
427
  * @{
427
  */
428
  */
428
 
429
 
429
/**
430
/**
430
  * @brief  Handle EXTI interrupt request.
431
  * @brief  Handle EXTI interrupt request.
431
  * @param  hexti Exti handle.
432
  * @param  hexti Exti handle.
432
  * @retval none.
433
  * @retval none.
433
  */
434
  */
434
void HAL_EXTI_IRQHandler(EXTI_HandleTypeDef *hexti)
435
void HAL_EXTI_IRQHandler(EXTI_HandleTypeDef *hexti)
435
{
436
{
436
  uint32_t regval;
437
  uint32_t regval;
437
  uint32_t maskline;
438
  uint32_t maskline;
438
 
439
 
439
  /* Compute line mask */
440
  /* Compute line mask */
440
  maskline = (1uL << (hexti->Line & EXTI_PIN_MASK));
441
  maskline = (1uL << (hexti->Line & EXTI_PIN_MASK));
441
 
442
 
442
  /* Get pending bit  */
443
  /* Get pending bit  */
443
  regval = (EXTI->PR & maskline);
444
  regval = (EXTI->PR & maskline);
444
  if (regval != 0x00u)
445
  if (regval != 0x00u)
445
  {
446
  {
446
    /* Clear pending bit */
447
    /* Clear pending bit */
447
    EXTI->PR = maskline;
448
    EXTI->PR = maskline;
448
 
449
 
449
    /* Call callback */
450
    /* Call callback */
450
    if (hexti->PendingCallback != NULL)
451
    if (hexti->PendingCallback != NULL)
451
    {
452
    {
452
      hexti->PendingCallback();
453
      hexti->PendingCallback();
453
    }
454
    }
454
  }
455
  }
455
}
456
}
456
 
457
 
457
/**
458
/**
458
  * @brief  Get interrupt pending bit of a dedicated line.
459
  * @brief  Get interrupt pending bit of a dedicated line.
459
  * @param  hexti Exti handle.
460
  * @param  hexti Exti handle.
460
  * @param  Edge Specify which pending edge as to be checked.
461
  * @param  Edge Specify which pending edge as to be checked.
461
  *         This parameter can be one of the following values:
462
  *         This parameter can be one of the following values:
462
  *           @arg @ref EXTI_TRIGGER_RISING_FALLING
463
  *           @arg @ref EXTI_TRIGGER_RISING_FALLING
463
  *         This parameter is kept for compatibility with other series.
464
  *         This parameter is kept for compatibility with other series.
464
  * @retval 1 if interrupt is pending else 0.
465
  * @retval 1 if interrupt is pending else 0.
465
  */
466
  */
466
uint32_t HAL_EXTI_GetPending(EXTI_HandleTypeDef *hexti, uint32_t Edge)
467
uint32_t HAL_EXTI_GetPending(EXTI_HandleTypeDef *hexti, uint32_t Edge)
467
{
468
{
468
  uint32_t regval;
469
  uint32_t regval;
469
  uint32_t maskline;
470
  uint32_t maskline;
470
  uint32_t linepos;
471
  uint32_t linepos;
471
 
472
 
472
  /* Check parameters */
473
  /* Check parameters */
473
  assert_param(IS_EXTI_LINE(hexti->Line));
474
  assert_param(IS_EXTI_LINE(hexti->Line));
474
  assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));
475
  assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));
475
  assert_param(IS_EXTI_PENDING_EDGE(Edge));
476
  assert_param(IS_EXTI_PENDING_EDGE(Edge));
476
 
477
 
477
  /* Prevent unused argument compilation warning */
478
  /* Prevent unused argument compilation warning */
478
  UNUSED(Edge);
479
  UNUSED(Edge);
479
 
480
 
480
  /* Compute line mask */
481
  /* Compute line mask */
481
  linepos = (hexti->Line & EXTI_PIN_MASK);
482
  linepos = (hexti->Line & EXTI_PIN_MASK);
482
  maskline = (1uL << linepos);
483
  maskline = (1uL << linepos);
483
 
484
 
484
  /* return 1 if bit is set else 0 */
485
  /* return 1 if bit is set else 0 */
485
  regval = ((EXTI->PR & maskline) >> linepos);
486
  regval = ((EXTI->PR & maskline) >> linepos);
486
  return regval;
487
  return regval;
487
}
488
}
488
 
489
 
489
/**
490
/**
490
  * @brief  Clear interrupt pending bit of a dedicated line.
491
  * @brief  Clear interrupt pending bit of a dedicated line.
491
  * @param  hexti Exti handle.
492
  * @param  hexti Exti handle.
492
  * @param  Edge Specify which pending edge as to be clear.
493
  * @param  Edge Specify which pending edge as to be clear.
493
  *         This parameter can be one of the following values:
494
  *         This parameter can be one of the following values:
494
  *           @arg @ref EXTI_TRIGGER_RISING_FALLING
495
  *           @arg @ref EXTI_TRIGGER_RISING_FALLING
495
  *         This parameter is kept for compatibility with other series.
496
  *         This parameter is kept for compatibility with other series.
496
  * @retval None.
497
  * @retval None.
497
  */
498
  */
498
void HAL_EXTI_ClearPending(EXTI_HandleTypeDef *hexti, uint32_t Edge)
499
void HAL_EXTI_ClearPending(EXTI_HandleTypeDef *hexti, uint32_t Edge)
499
{
500
{
500
  uint32_t maskline;
501
  uint32_t maskline;
501
 
502
 
502
  /* Check parameters */
503
  /* Check parameters */
503
  assert_param(IS_EXTI_LINE(hexti->Line));
504
  assert_param(IS_EXTI_LINE(hexti->Line));
504
  assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));
505
  assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));
505
  assert_param(IS_EXTI_PENDING_EDGE(Edge));
506
  assert_param(IS_EXTI_PENDING_EDGE(Edge));
506
 
507
 
507
  /* Prevent unused argument compilation warning */
508
  /* Prevent unused argument compilation warning */
508
  UNUSED(Edge);
509
  UNUSED(Edge);
509
 
510
 
510
  /* Compute line mask */
511
  /* Compute line mask */
511
  maskline = (1uL << (hexti->Line & EXTI_PIN_MASK));
512
  maskline = (1uL << (hexti->Line & EXTI_PIN_MASK));
512
 
513
 
513
  /* Clear Pending bit */
514
  /* Clear Pending bit */
514
  EXTI->PR =  maskline;
515
  EXTI->PR =  maskline;
515
}
516
}
516
 
517
 
517
/**
518
/**
518
  * @brief  Generate a software interrupt for a dedicated line.
519
  * @brief  Generate a software interrupt for a dedicated line.
519
  * @param  hexti Exti handle.
520
  * @param  hexti Exti handle.
520
  * @retval None.
521
  * @retval None.
521
  */
522
  */
522
void HAL_EXTI_GenerateSWI(EXTI_HandleTypeDef *hexti)
523
void HAL_EXTI_GenerateSWI(EXTI_HandleTypeDef *hexti)
523
{
524
{
524
  uint32_t maskline;
525
  uint32_t maskline;
525
 
526
 
526
  /* Check parameters */
527
  /* Check parameters */
527
  assert_param(IS_EXTI_LINE(hexti->Line));
528
  assert_param(IS_EXTI_LINE(hexti->Line));
528
  assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));
529
  assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));
529
 
530
 
530
  /* Compute line mask */
531
  /* Compute line mask */
531
  maskline = (1uL << (hexti->Line & EXTI_PIN_MASK));
532
  maskline = (1uL << (hexti->Line & EXTI_PIN_MASK));
532
 
533
 
533
  /* Generate Software interrupt */
534
  /* Generate Software interrupt */
534
  EXTI->SWIER = maskline;
535
  EXTI->SWIER = maskline;
535
}
536
}
536
 
537
 
537
/**
538
/**
538
  * @}
539
  * @}
539
  */
540
  */
540
 
541
 
541
/**
542
/**
542
  * @}
543
  * @}
543
  */
544
  */
544
 
545
 
545
#endif /* HAL_EXTI_MODULE_ENABLED */
546
#endif /* HAL_EXTI_MODULE_ENABLED */
546
/**
547
/**
547
  * @}
548
  * @}
548
  */
549
  */
549
 
550
 
550
/**
551
/**
551
  * @}
552
  * @}
552
  */
553
  */
553
 
554
 
-
 
555
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-