Subversion Repositories LedShow

Rev

Go to most recent revision | 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</center></h2>
10
  *
11
  * Redistribution and use in source and binary forms, with or without modification,
12
  * are permitted provided that the following conditions are met:
13
  *   1. Redistributions of source code must retain the above copyright notice,
14
  *      this list of conditions and the following disclaimer.
15
  *   2. Redistributions in binary form must reproduce the above copyright notice,
16
  *      this list of conditions and the following disclaimer in the documentation
17
  *      and/or other materials provided with the distribution.
18
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
19
  *      may be used to endorse or promote products derived from this software
20
  *      without specific prior written permission.
21
  *
22
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
  *
33
  ******************************************************************************
34
  */
35
#if defined(USE_FULL_LL_DRIVER)
36
 
37
/* Includes ------------------------------------------------------------------*/
38
#include "stm32f1xx_ll_gpio.h"
39
#include "stm32f1xx_ll_bus.h"
40
#ifdef  USE_FULL_ASSERT
41
#include "stm32_assert.h"
42
#else
43
#define assert_param(expr) ((void)0U)
44
#endif
45
 
46
/** @addtogroup STM32F1xx_LL_Driver
47
  * @{
48
  */
49
 
50
#if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG)
51
 
52
/** @addtogroup GPIO_LL
53
  * @{
54
  */
55
 
56
/* Private types -------------------------------------------------------------*/
57
/* Private variables ---------------------------------------------------------*/
58
/* Private constants ---------------------------------------------------------*/
59
/* Private macros ------------------------------------------------------------*/
60
/** @addtogroup GPIO_LL_Private_Macros
61
  * @{
62
  */
63
 
64
#define IS_LL_GPIO_PIN(__VALUE__)          ((((__VALUE__) & LL_GPIO_PIN_ALL)!= 0U) &&\
65
                                            (((__VALUE__) & (~LL_GPIO_PIN_ALL))== 0U))
66
 
67
#define IS_LL_GPIO_MODE(__VALUE__)         (((__VALUE__) == LL_GPIO_MODE_ANALOG)       ||\
68
                                            ((__VALUE__) == LL_GPIO_MODE_FLOATING)     ||\
69
                                            ((__VALUE__) == LL_GPIO_MODE_INPUT)        ||\
70
                                            ((__VALUE__) == LL_GPIO_MODE_OUTPUT)       ||\
71
                                            ((__VALUE__) == LL_GPIO_MODE_ALTERNATE))
72
 
73
#define IS_LL_GPIO_SPEED(__VALUE__)        (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW)       ||\
74
                                            ((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM)    ||\
75
                                            ((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH))
76
 
77
#define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__)  (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL)  ||\
78
                                            ((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN))
79
 
80
#define IS_LL_GPIO_PULL(__VALUE__)         (((__VALUE__) == LL_GPIO_PULL_DOWN)   ||\
81
                                            ((__VALUE__) == LL_GPIO_PULL_UP))
82
 
83
/**
84
  * @}
85
  */
86
 
87
/* Private function prototypes -----------------------------------------------*/
88
 
89
/* Exported functions --------------------------------------------------------*/
90
/** @addtogroup GPIO_LL_Exported_Functions
91
  * @{
92
  */
93
 
94
/** @addtogroup GPIO_LL_EF_Init
95
  * @{
96
  */
97
 
98
/**
99
  * @brief  De-initialize GPIO registers (Registers restored to their default values).
100
  * @param  GPIOx GPIO Port
101
  * @retval An ErrorStatus enumeration value:
102
  *          - SUCCESS: GPIO registers are de-initialized
103
  *          - ERROR:   Wrong GPIO Port
104
  */
105
ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx)
106
{
107
  ErrorStatus status = SUCCESS;
108
 
109
  /* Check the parameters */
110
  assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
111
 
112
  /* Force and Release reset on clock of GPIOx Port */
113
  if (GPIOx == GPIOA)
114
  {
115
    LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOA);
116
    LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOA);
117
  }
118
  else if (GPIOx == GPIOB)
119
  {
120
    LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOB);
121
    LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOB);
122
  }
123
  else if (GPIOx == GPIOC)
124
  {
125
    LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOC);
126
    LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOC);
127
  }
128
  else if (GPIOx == GPIOD)
129
  {
130
    LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOD);
131
    LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOD);
132
  }
133
#if defined(GPIOE)
134
  else if (GPIOx == GPIOE)
135
  {
136
    LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOE);
137
    LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOE);
138
  }
139
#endif
140
#if defined(GPIOF)
141
  else if (GPIOx == GPIOF)
142
  {
143
    LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOF);
144
    LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOF);
145
  }
146
#endif
147
#if defined(GPIOG)
148
  else if (GPIOx == GPIOG)
149
  {
150
    LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOG);
151
    LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOG);
152
  }
153
#endif
154
  else
155
  {
156
    status = ERROR;
157
  }
158
 
159
  return (status);
160
}
161
 
162
/**
163
  * @brief  Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
164
  * @param  GPIOx GPIO Port
165
  * @param  GPIO_InitStruct: pointer to a @ref LL_GPIO_InitTypeDef structure
166
  *         that contains the configuration information for the specified GPIO peripheral.
167
  * @retval An ErrorStatus enumeration value:
168
  *          - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content
169
  *          - ERROR:   Not applicable
170
  */
171
ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
172
{
173
  uint32_t pinmask;
174
  uint32_t pinpos;
175
  uint32_t currentpin;
176
 
177
  /* Check the parameters */
178
  assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
179
  assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin));
180
 
181
  /* ------------------------- Configure the port pins ---------------- */
182
  /* Initialize  pinpos on first pin set */
183
 
184
  pinmask = ((GPIO_InitStruct->Pin) << GPIO_PIN_MASK_POS) >> GPIO_PIN_NB;
185
  pinpos = POSITION_VAL(pinmask);
186
 
187
  /* Configure the port pins */
188
  while ((pinmask  >> pinpos) != 0U)
189
  {
190
    /* skip if bit is not set */
191
    if ((pinmask & (1U << pinpos)) != 0U)
192
    {
193
      /* Get current io position */
194
      if (pinpos < GPIO_PIN_MASK_POS)
195
      {
196
        currentpin = (0x00000101U << pinpos);
197
      }
198
      else
199
      {
200
        currentpin = ((0x00010001U << (pinpos - GPIO_PIN_MASK_POS)) | 0x04000000U);
201
      }
202
 
203
      /* Check Pin Mode and Pin Pull parameters */
204
      assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode));
205
      assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull));
206
 
207
      /* Pin Mode configuration */
208
      LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
209
 
210
      /* Pull-up Pull-down resistor configuration*/
211
      LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
212
 
213
      if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
214
      {
215
        /* Check speed and Output mode parameters */
216
        assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed));
217
        assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
218
 
219
        /* Speed mode configuration */
220
        LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
221
 
222
        /* Output mode configuration*/
223
        LL_GPIO_SetPinOutputType(GPIOx, currentpin, GPIO_InitStruct->OutputType);
224
      }
225
    }
226
    pinpos++;
227
  }
228
  return (SUCCESS);
229
}
230
 
231
/**
232
  * @brief Set each @ref LL_GPIO_InitTypeDef field to default value.
233
  * @param GPIO_InitStruct: pointer to a @ref LL_GPIO_InitTypeDef structure
234
  *                          whose fields will be set to default values.
235
  * @retval None
236
  */
237
 
238
void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct)
239
{
240
  /* Reset GPIO init structure parameters values */
241
  GPIO_InitStruct->Pin        = LL_GPIO_PIN_ALL;
242
  GPIO_InitStruct->Mode       = LL_GPIO_MODE_FLOATING;
243
  GPIO_InitStruct->Speed      = LL_GPIO_SPEED_FREQ_LOW;
244
  GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
245
  GPIO_InitStruct->Pull       = LL_GPIO_PULL_DOWN;
246
}
247
 
248
/**
249
  * @}
250
  */
251
 
252
/**
253
  * @}
254
  */
255
 
256
/**
257
  * @}
258
  */
259
 
260
#endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) */
261
 
262
/**
263
  * @}
264
  */
265
 
266
#endif /* USE_FULL_LL_DRIVER */
267
 
268
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/