Subversion Repositories FuelGauge

Rev

Rev 2 | Details | Compare with Previous | 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
      if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
197
      {
198
        /* Check Speed mode parameters */
199
        assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed));
200
 
201
        /* Speed mode configuration */
202
        LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
6 mjames 203
 
204
        /* Check Output mode parameters */
205
        assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
206
 
207
        /* Output mode configuration*/
208
        LL_GPIO_SetPinOutputType(GPIOx, GPIO_InitStruct->Pin, GPIO_InitStruct->OutputType);
2 mjames 209
      }
210
 
211
      /* Pull-up Pull down resistor configuration*/
212
      LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
213
 
214
      if (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE)
215
      {
216
        /* Check Alternate parameter */
217
        assert_param(IS_LL_GPIO_ALTERNATE(GPIO_InitStruct->Alternate));
218
 
219
        /* Speed mode configuration */
220
        if (currentpin < LL_GPIO_PIN_8)
221
        {
222
          LL_GPIO_SetAFPin_0_7(GPIOx, currentpin, GPIO_InitStruct->Alternate);
223
        }
224
        else
225
        {
226
          LL_GPIO_SetAFPin_8_15(GPIOx, currentpin, GPIO_InitStruct->Alternate);
227
        }
228
      }
6 mjames 229
 
230
      /* Pin Mode configuration */
231
      LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
2 mjames 232
    }
233
    pinpos++;
234
  }
235
 
236
  return (SUCCESS);
237
}
238
 
239
/**
240
  * @brief Set each @ref LL_GPIO_InitTypeDef field to default value.
241
  * @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure
242
  *                          whose fields will be set to default values.
243
  * @retval None
244
  */
245
 
246
void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct)
247
{
248
  /* Reset GPIO init structure parameters values */
249
  GPIO_InitStruct->Pin        = LL_GPIO_PIN_ALL;
250
  GPIO_InitStruct->Mode       = LL_GPIO_MODE_ANALOG;
251
  GPIO_InitStruct->Speed      = LL_GPIO_SPEED_FREQ_LOW;
252
  GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_PUSHPULL;
253
  GPIO_InitStruct->Pull       = LL_GPIO_PULL_NO;
254
  GPIO_InitStruct->Alternate  = LL_GPIO_AF_0;
255
}
256
 
257
/**
258
  * @}
259
  */
260
 
261
/**
262
  * @}
263
  */
264
 
265
/**
266
  * @}
267
  */
268
 
269
#endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) */
270
 
271
/**
272
  * @}
273
  */
274
 
275
#endif /* USE_FULL_LL_DRIVER */
276
 
277
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/