Subversion Repositories FuelGauge

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/**
2
  ******************************************************************************
3
  * @file    stm32f0xx_ll_gpio.c
4
  * @author  MCD Application Team
5
  * @brief   GPIO LL module driver.
6
  ******************************************************************************
7
  * @attention
8
  *
9
  *  <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
10
  * All rights reserved.</center></h2>
11
  *
12
  * This software component is licensed by ST under BSD 3-Clause license,
13
  * the "License"; You may not use this file except in compliance with the
14
  * License. You may obtain a copy of the License at:
15
  *                        opensource.org/licenses/BSD-3-Clause
16
  *
17
  ******************************************************************************
18
  */
19
 
20
#if defined(USE_FULL_LL_DRIVER)
21
 
22
/* Includes ------------------------------------------------------------------*/
23
#include "stm32f0xx_ll_gpio.h"
24
#include "stm32f0xx_ll_bus.h"
25
#ifdef  USE_FULL_ASSERT
26
#include "stm32_assert.h"
27
#else
28
#define assert_param(expr) ((void)0U)
29
#endif
30
 
31
/** @addtogroup STM32F0xx_LL_Driver
32
  * @{
33
  */
34
 
35
#if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF)
36
 
37
/** @addtogroup GPIO_LL
38
  * @{
39
  */
40
/** MISRA C:2012 deviation rule has been granted for following rules:
41
  * Rule-12.2 - Medium: RHS argument is in interval [0,INF] which is out of
42
  * range of the shift operator in following API :
43
  * LL_GPIO_Init
44
  * LL_GPIO_DeInit
45
  * LL_GPIO_SetPinMode
46
  * LL_GPIO_GetPinMode
47
  * LL_GPIO_SetPinSpeed
48
  * LL_GPIO_GetPinSpeed
49
  * LL_GPIO_SetPinPull
50
  * LL_GPIO_GetPinPull
51
  * LL_GPIO_GetAFPin_0_7
52
  * LL_GPIO_SetAFPin_0_7
53
  * LL_GPIO_SetAFPin_8_15
54
  * LL_GPIO_GetAFPin_8_15
55
  */
56
 
57
/* Private types -------------------------------------------------------------*/
58
/* Private variables ---------------------------------------------------------*/
59
/* Private constants ---------------------------------------------------------*/
60
/* Private macros ------------------------------------------------------------*/
61
/** @addtogroup GPIO_LL_Private_Macros
62
  * @{
63
  */
64
#define IS_LL_GPIO_PIN(__VALUE__)          (((0x00u) < (__VALUE__)) && ((__VALUE__) <= (LL_GPIO_PIN_ALL)))
65
 
66
#define IS_LL_GPIO_MODE(__VALUE__)         (((__VALUE__) == LL_GPIO_MODE_INPUT)     ||\
67
                                            ((__VALUE__) == LL_GPIO_MODE_OUTPUT)    ||\
68
                                            ((__VALUE__) == LL_GPIO_MODE_ALTERNATE) ||\
69
                                            ((__VALUE__) == LL_GPIO_MODE_ANALOG))
70
 
71
#define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__)  (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL)  ||\
72
                                            ((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN))
73
 
74
#define IS_LL_GPIO_SPEED(__VALUE__)        (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW)       ||\
75
                                            ((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM)    ||\
76
                                            ((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH))
77
 
78
#define IS_LL_GPIO_PULL(__VALUE__)         (((__VALUE__) == LL_GPIO_PULL_NO)   ||\
79
                                            ((__VALUE__) == LL_GPIO_PULL_UP)   ||\
80
                                            ((__VALUE__) == LL_GPIO_PULL_DOWN))
81
 
82
#define IS_LL_GPIO_ALTERNATE(__VALUE__)    (((__VALUE__) == LL_GPIO_AF_0  )   ||\
83
                                            ((__VALUE__) == LL_GPIO_AF_1  )   ||\
84
                                            ((__VALUE__) == LL_GPIO_AF_2  )   ||\
85
                                            ((__VALUE__) == LL_GPIO_AF_3  )   ||\
86
                                            ((__VALUE__) == LL_GPIO_AF_4  )   ||\
87
                                            ((__VALUE__) == LL_GPIO_AF_5  )   ||\
88
                                            ((__VALUE__) == LL_GPIO_AF_6  )   ||\
89
                                            ((__VALUE__) == LL_GPIO_AF_7 ))
90
/**
91
  * @}
92
  */
93
 
94
/* Private function prototypes -----------------------------------------------*/
95
 
96
/* Exported functions --------------------------------------------------------*/
97
/** @addtogroup GPIO_LL_Exported_Functions
98
  * @{
99
  */
100
 
101
/** @addtogroup GPIO_LL_EF_Init
102
  * @{
103
  */
104
 
105
/**
106
  * @brief  De-initialize GPIO registers (Registers restored to their default values).
107
  * @param  GPIOx GPIO Port
108
  * @retval An ErrorStatus enumeration value:
109
  *          - SUCCESS: GPIO registers are de-initialized
110
  *          - ERROR:   Wrong GPIO Port
111
  */
112
ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx)
113
{
114
  ErrorStatus status = SUCCESS;
115
 
116
  /* Check the parameters */
117
  assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
118
 
119
  /* Force and Release reset on clock of GPIOx Port */
120
  if (GPIOx == GPIOA)
121
  {
122
    LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOA);
123
    LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOA);
124
  }
125
  else if (GPIOx == GPIOB)
126
  {
127
    LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOB);
128
    LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOB);
129
  }
130
  else if (GPIOx == GPIOC)
131
  {
132
    LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOC);
133
    LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOC);
134
  }
135
#if defined(GPIOD)
136
  else if (GPIOx == GPIOD)
137
  {
138
    LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOD);
139
    LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOD);
140
  }
141
#endif /* GPIOD */
142
#if defined(GPIOE)
143
  else if (GPIOx == GPIOE)
144
  {
145
    LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOE);
146
    LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOE);
147
  }
148
#endif /* GPIOE */
149
#if defined(GPIOF)
150
  else if (GPIOx == GPIOF)
151
  {
152
    LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOF);
153
    LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOF);
154
  }
155
#endif /* GPIOF */
156
  else
157
  {
158
    status = ERROR;
159
  }
160
 
161
  return (status);
162
}
163
 
164
/**
165
  * @brief  Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
166
  * @param  GPIOx GPIO Port
167
  * @param  GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure
168
  *         that contains the configuration information for the specified GPIO peripheral.
169
  * @retval An ErrorStatus enumeration value:
170
  *          - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content
171
  *          - ERROR:   Not applicable
172
  */
173
ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
174
{
175
  uint32_t pinpos;
176
  uint32_t currentpin;
177
 
178
  /* Check the parameters */
179
  assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
180
  assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin));
181
  assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode));
182
  assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull));
183
 
184
  /* ------------------------- Configure the port pins ---------------- */
185
  /* Initialize  pinpos on first pin set */
186
  pinpos = 0;
187
 
188
  /* Configure the port pins */
189
  while (((GPIO_InitStruct->Pin) >> pinpos) != 0x00u)
190
  {
191
    /* Get current io position */
192
    currentpin = (GPIO_InitStruct->Pin) & (0x00000001uL << pinpos);
193
 
194
    if (currentpin != 0x00u)
195
    {
196
      /* Pin Mode configuration */
197
      LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
198
 
199
      if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
200
      {
201
        /* Check Speed mode parameters */
202
        assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed));
203
 
204
        /* Speed mode configuration */
205
        LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
206
      }
207
 
208
      /* Pull-up Pull down resistor configuration*/
209
      LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
210
 
211
      if (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE)
212
      {
213
        /* Check Alternate parameter */
214
        assert_param(IS_LL_GPIO_ALTERNATE(GPIO_InitStruct->Alternate));
215
 
216
        /* Speed mode configuration */
217
        if (currentpin < LL_GPIO_PIN_8)
218
        {
219
          LL_GPIO_SetAFPin_0_7(GPIOx, currentpin, GPIO_InitStruct->Alternate);
220
        }
221
        else
222
        {
223
          LL_GPIO_SetAFPin_8_15(GPIOx, currentpin, GPIO_InitStruct->Alternate);
224
        }
225
      }
226
    }
227
    pinpos++;
228
  }
229
 
230
  if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
231
  {
232
    /* Check Output mode parameters */
233
    assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
234
 
235
    /* Output mode configuration*/
236
    LL_GPIO_SetPinOutputType(GPIOx, GPIO_InitStruct->Pin, GPIO_InitStruct->OutputType);
237
 
238
  }
239
  return (SUCCESS);
240
}
241
 
242
/**
243
  * @brief Set each @ref LL_GPIO_InitTypeDef field to default value.
244
  * @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure
245
  *                          whose fields will be set to default values.
246
  * @retval None
247
  */
248
 
249
void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct)
250
{
251
  /* Reset GPIO init structure parameters values */
252
  GPIO_InitStruct->Pin        = LL_GPIO_PIN_ALL;
253
  GPIO_InitStruct->Mode       = LL_GPIO_MODE_ANALOG;
254
  GPIO_InitStruct->Speed      = LL_GPIO_SPEED_FREQ_LOW;
255
  GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_PUSHPULL;
256
  GPIO_InitStruct->Pull       = LL_GPIO_PULL_NO;
257
  GPIO_InitStruct->Alternate  = LL_GPIO_AF_0;
258
}
259
 
260
/**
261
  * @}
262
  */
263
 
264
/**
265
  * @}
266
  */
267
 
268
/**
269
  * @}
270
  */
271
 
272
#endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) */
273
 
274
/**
275
  * @}
276
  */
277
 
278
#endif /* USE_FULL_LL_DRIVER */
279
 
280
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/