source: trunk/firmware/Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_ll_gpio.c

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