Subversion Repositories CharLCD

Rev

Details | 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
      if (GPIO_InitStruct->Mode == LL_GPIO_MODE_INPUT)
189
      {
190
        /* Check The Pull parameter */
191
        assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull));
192
 
193
        /* Pull-up Pull-down resistor configuration*/
194
        LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
195
      }
196
 
197
      /* Check Pin Mode parameters */
198
      assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode));
199
 
200
      /* Pin Mode configuration */
201
      LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
202
 
203
      if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
204
      {
205
        /* Check speed and Output mode parameters */
206
        assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed));
207
        assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
208
 
209
        /* Speed mode configuration */
210
        LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
211
 
212
        /* Output mode configuration*/
213
        LL_GPIO_SetPinOutputType(GPIOx, currentpin, GPIO_InitStruct->OutputType);
214
      }
215
    }
216
    pinpos++;
217
  }
218
  return (SUCCESS);
219
}
220
 
221
/**
222
  * @brief Set each @ref LL_GPIO_InitTypeDef field to default value.
223
  * @param GPIO_InitStruct: pointer to a @ref LL_GPIO_InitTypeDef structure
224
  *                          whose fields will be set to default values.
225
  * @retval None
226
  */
227
 
228
void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct)
229
{
230
  /* Reset GPIO init structure parameters values */
231
  GPIO_InitStruct->Pin        = LL_GPIO_PIN_ALL;
232
  GPIO_InitStruct->Mode       = LL_GPIO_MODE_FLOATING;
233
  GPIO_InitStruct->Speed      = LL_GPIO_SPEED_FREQ_LOW;
234
  GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
235
  GPIO_InitStruct->Pull       = LL_GPIO_PULL_DOWN;
236
}
237
 
238
/**
239
  * @}
240
  */
241
 
242
/**
243
  * @}
244
  */
245
 
246
/**
247
  * @}
248
  */
249
 
250
#endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) */
251
 
252
/**
253
  * @}
254
  */
255
 
256
#endif /* USE_FULL_LL_DRIVER */
257
 
258
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/