Subversion Repositories dashGPS

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/**
2
  ******************************************************************************
3
  * @file    stm32f1xx_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 "stm32f1xx_ll_gpio.h"
24
#include "stm32f1xx_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 STM32F1xx_LL_Driver
32
  * @{
33
  */
34
 
35
#if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG)
36
 
37
/** @addtogroup GPIO_LL
38
  * @{
39
  */
40
 
41
/* Private types -------------------------------------------------------------*/
42
/* Private variables ---------------------------------------------------------*/
43
/* Private constants ---------------------------------------------------------*/
44
/* Private macros ------------------------------------------------------------*/
45
/** @addtogroup GPIO_LL_Private_Macros
46
  * @{
47
  */
48
 
49
#define IS_LL_GPIO_PIN(__VALUE__)          ((((__VALUE__) & LL_GPIO_PIN_ALL)!= 0u) &&\
50
                                            (((__VALUE__) & (~LL_GPIO_PIN_ALL))== 0u))
51
 
52
#define IS_LL_GPIO_MODE(__VALUE__)         (((__VALUE__) == LL_GPIO_MODE_ANALOG)       ||\
53
                                            ((__VALUE__) == LL_GPIO_MODE_FLOATING)     ||\
54
                                            ((__VALUE__) == LL_GPIO_MODE_INPUT)        ||\
55
                                            ((__VALUE__) == LL_GPIO_MODE_OUTPUT)       ||\
56
                                            ((__VALUE__) == LL_GPIO_MODE_ALTERNATE))
57
 
58
#define IS_LL_GPIO_SPEED(__VALUE__)        (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW)       ||\
59
                                            ((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM)    ||\
60
                                            ((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH))
61
 
62
#define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__)  (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL)  ||\
63
                                            ((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN))
64
 
65
#define IS_LL_GPIO_PULL(__VALUE__)         (((__VALUE__) == LL_GPIO_PULL_DOWN)   ||\
66
                                            ((__VALUE__) == LL_GPIO_PULL_UP))
67
 
68
/**
69
  * @}
70
  */
71
 
72
/* Private function prototypes -----------------------------------------------*/
73
 
74
/* Exported functions --------------------------------------------------------*/
75
/** @addtogroup GPIO_LL_Exported_Functions
76
  * @{
77
  */
78
 
79
/** @addtogroup GPIO_LL_EF_Init
80
  * @{
81
  */
82
 
83
/**
84
  * @brief  De-initialize GPIO registers (Registers restored to their default values).
85
  * @param  GPIOx GPIO Port
86
  * @retval An ErrorStatus enumeration value:
87
  *          - SUCCESS: GPIO registers are de-initialized
88
  *          - ERROR:   Wrong GPIO Port
89
  */
90
ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx)
91
{
92
  ErrorStatus status = SUCCESS;
93
 
94
  /* Check the parameters */
95
  assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
96
 
97
  /* Force and Release reset on clock of GPIOx Port */
98
  if (GPIOx == GPIOA)
99
  {
100
    LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOA);
101
    LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOA);
102
  }
103
  else if (GPIOx == GPIOB)
104
  {
105
    LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOB);
106
    LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOB);
107
  }
108
  else if (GPIOx == GPIOC)
109
  {
110
    LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOC);
111
    LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOC);
112
  }
113
  else if (GPIOx == GPIOD)
114
  {
115
    LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOD);
116
    LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOD);
117
  }
118
#if defined(GPIOE)
119
  else if (GPIOx == GPIOE)
120
  {
121
    LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOE);
122
    LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOE);
123
  }
124
#endif
125
#if defined(GPIOF)
126
  else if (GPIOx == GPIOF)
127
  {
128
    LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOF);
129
    LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOF);
130
  }
131
#endif
132
#if defined(GPIOG)
133
  else if (GPIOx == GPIOG)
134
  {
135
    LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOG);
136
    LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOG);
137
  }
138
#endif
139
  else
140
  {
141
    status = ERROR;
142
  }
143
 
144
  return (status);
145
}
146
 
147
/**
148
  * @brief  Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
149
  * @param  GPIOx GPIO Port
150
  * @param  GPIO_InitStruct: pointer to a @ref LL_GPIO_InitTypeDef structure
151
  *         that contains the configuration information for the specified GPIO peripheral.
152
  * @retval An ErrorStatus enumeration value:
153
  *          - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content
154
  *          - ERROR:   Not applicable
155
  */
156
ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
157
{
158
  uint32_t pinmask;
159
  uint32_t pinpos;
160
  uint32_t currentpin;
161
 
162
  /* Check the parameters */
163
  assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
164
  assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin));
165
 
166
  /* ------------------------- Configure the port pins ---------------- */
167
  /* Initialize  pinpos on first pin set */
168
 
169
  pinmask = ((GPIO_InitStruct->Pin) << GPIO_PIN_MASK_POS) >> GPIO_PIN_NB;
170
  pinpos = POSITION_VAL(pinmask);
171
 
172
  /* Configure the port pins */
173
  while ((pinmask  >> pinpos) != 0u)
174
  {
175
    /* skip if bit is not set */
176
    if ((pinmask & (1u << pinpos)) != 0u)
177
    {
178
      /* Get current io position */
179
      if (pinpos < GPIO_PIN_MASK_POS)
180
      {
181
        currentpin = (0x00000101uL << pinpos);
182
      }
183
      else
184
      {
185
        currentpin = ((0x00010001u << (pinpos - GPIO_PIN_MASK_POS)) | 0x04000000u);
186
      }
187
 
188
      /* Check Pin Mode and Pin Pull parameters */
189
      assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode));
190
      assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull));
191
 
192
      /* Pin Mode configuration */
193
      LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
194
 
195
      /* Pull-up Pull-down resistor configuration*/
196
      LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
197
 
198
      if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
199
      {
200
        /* Check speed and Output mode parameters */
201
        assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed));
202
        assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
203
 
204
        /* Speed mode configuration */
205
        LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
206
 
207
        /* Output mode configuration*/
208
        LL_GPIO_SetPinOutputType(GPIOx, currentpin, GPIO_InitStruct->OutputType);
209
      }
210
    }
211
    pinpos++;
212
  }
213
  return (SUCCESS);
214
}
215
 
216
/**
217
  * @brief Set each @ref LL_GPIO_InitTypeDef field to default value.
218
  * @param GPIO_InitStruct: pointer to a @ref LL_GPIO_InitTypeDef structure
219
  *                          whose fields will be set to default values.
220
  * @retval None
221
  */
222
 
223
void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct)
224
{
225
  /* Reset GPIO init structure parameters values */
226
  GPIO_InitStruct->Pin        = LL_GPIO_PIN_ALL;
227
  GPIO_InitStruct->Mode       = LL_GPIO_MODE_FLOATING;
228
  GPIO_InitStruct->Speed      = LL_GPIO_SPEED_FREQ_LOW;
229
  GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
230
  GPIO_InitStruct->Pull       = LL_GPIO_PULL_DOWN;
231
}
232
 
233
/**
234
  * @}
235
  */
236
 
237
/**
238
  * @}
239
  */
240
 
241
/**
242
  * @}
243
  */
244
 
245
#endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) */
246
 
247
/**
248
  * @}
249
  */
250
 
251
#endif /* USE_FULL_LL_DRIVER */
252
 
253
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/