1 /**
2   ******************************************************************************
3   * @file    stm32u5xx_ll_lpgpio.c
4   * @author  MCD Application Team
5   * @brief   LPGPIO LL module driver.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2021 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 #if defined(USE_FULL_LL_DRIVER)
19 
20 /* Includes ------------------------------------------------------------------*/
21 #include "stm32u5xx_ll_lpgpio.h"
22 #include "stm32u5xx_ll_bus.h"
23 #ifdef  USE_FULL_ASSERT
24 #include "stm32_assert.h"
25 #else
26 #define assert_param(expr) ((void)0U)
27 #endif /* USE_FULL_ASSERT */
28 
29 /** @addtogroup STM32U5xx_LL_Driver
30   * @{
31   */
32 
33 #if defined (LPGPIO1)
34 
35 /** @addtogroup LPGPIO_LL
36   * @{
37   */
38 
39 /* Private types -------------------------------------------------------------*/
40 /* Private variables ---------------------------------------------------------*/
41 /* Private constants ---------------------------------------------------------*/
42 /* Private macros ------------------------------------------------------------*/
43 /** @addtogroup LPGPIO_LL_Private_Macros
44   * @{
45   */
46 #define IS_LL_LPGPIO_PIN(__VALUE__)          (((0x00000000U) < (__VALUE__)) && ((__VALUE__) <= (LL_LPGPIO_PIN_ALL)))
47 
48 #define IS_LL_LPGPIO_MODE(__VALUE__)         (((__VALUE__) == LL_LPGPIO_MODE_INPUT)     ||\
49                                               ((__VALUE__) == LL_LPGPIO_MODE_OUTPUT))
50 
51 /**
52   * @}
53   */
54 
55 /* Private function prototypes -----------------------------------------------*/
56 
57 /* Exported functions --------------------------------------------------------*/
58 /** @addtogroup LPGPIO_LL_Exported_Functions
59   * @{
60   */
61 
62 /** @addtogroup LPGPIO_LL_EF_Init
63   * @{
64   */
65 
66 /**
67   * @brief  De-initialize LPGPIO registers (Registers restored to their default values).
68   * @param  LPGPIOx LPGPIO Port
69   * @retval An ErrorStatus enumeration value:
70   *          - SUCCESS: LPGPIO registers are de-initialized
71   *          - ERROR:   Wrong LPGPIO Port
72   */
LL_LPGPIO_DeInit(const GPIO_TypeDef * LPGPIOx)73 ErrorStatus LL_LPGPIO_DeInit(const GPIO_TypeDef *LPGPIOx)
74 {
75   ErrorStatus status = SUCCESS;
76 
77   /* Check the parameters */
78   assert_param(IS_LPGPIO_ALL_INSTANCE(LPGPIOx));
79 
80   /* Force and Release reset on clock of LPGPIOx Port */
81   if (LPGPIOx == LPGPIO1)
82   {
83     LL_AHB3_GRP1_ForceReset(LL_AHB3_GRP1_PERIPH_LPGPIO1);
84     LL_AHB3_GRP1_ReleaseReset(LL_AHB3_GRP1_PERIPH_LPGPIO1);
85   }
86   else
87   {
88     status = ERROR;
89   }
90 
91   return (status);
92 }
93 
94 /**
95   * @brief  Initialize LPGPIO registers according to the specified parameters in LPGPIO_InitStruct.
96   * @param  LPGPIOx LPGPIO Port
97   * @param  LPGPIO_InitStruct: pointer to a @ref LL_LPGPIO_InitTypeDef structure
98   *         that contains the configuration information for the specified LPGPIO peripheral.
99   * @retval An ErrorStatus enumeration value:
100   *          - SUCCESS: LPGPIO registers are initialized according to LPGPIO_InitStruct content
101   *          - ERROR:   Not applicable
102   */
LL_LPGPIO_Init(GPIO_TypeDef * LPGPIOx,const LL_LPGPIO_InitTypeDef * const LPGPIO_InitStruct)103 ErrorStatus LL_LPGPIO_Init(GPIO_TypeDef *LPGPIOx, const LL_LPGPIO_InitTypeDef *const LPGPIO_InitStruct)
104 {
105   uint32_t pinpos;
106   uint32_t currentpin;
107 
108   /* Check the parameters */
109   assert_param(IS_LPGPIO_ALL_INSTANCE(LPGPIOx));
110   assert_param(IS_LL_LPGPIO_PIN(LPGPIO_InitStruct->Pin));
111   assert_param(IS_LL_LPGPIO_MODE(LPGPIO_InitStruct->Mode));
112 
113   /* ------------------------- Configure the port pins ---------------- */
114   /* Initialize  pinpos on first pin set */
115   pinpos = POSITION_VAL(LPGPIO_InitStruct->Pin);
116 
117   /* Configure the port pins */
118   while (((LPGPIO_InitStruct->Pin) >> pinpos) != 0U)
119   {
120     /* Get current io position */
121     currentpin = (LPGPIO_InitStruct->Pin) & (1UL << pinpos);
122 
123     if (currentpin != 0U)
124     {
125       /* Pin Mode configuration */
126       LL_LPGPIO_SetPinMode(LPGPIOx, currentpin, LPGPIO_InitStruct->Mode);
127     }
128     pinpos++;
129   }
130   return (SUCCESS);
131 }
132 
133 /**
134   * @brief Set each @ref LL_LPGPIO_InitTypeDef field to default value.
135   * @param LPGPIO_InitStruct: pointer to a @ref LL_LPGPIO_InitTypeDef structure
136   *                           whose fields will be set to default values.
137   * @retval None
138   */
139 
LL_LPGPIO_StructInit(LL_LPGPIO_InitTypeDef * LPGPIO_InitStruct)140 void LL_LPGPIO_StructInit(LL_LPGPIO_InitTypeDef *LPGPIO_InitStruct)
141 {
142   /* Reset LPGPIO init structure parameters values */
143   LPGPIO_InitStruct->Pin        = LL_LPGPIO_PIN_ALL;
144   LPGPIO_InitStruct->Mode       = LL_LPGPIO_MODE_INPUT;
145 }
146 
147 /**
148   * @}
149   */
150 
151 /**
152   * @}
153   */
154 
155 /**
156   * @}
157   */
158 
159 #endif /* defined (LPGPIO1) */
160 
161 /**
162   * @}
163   */
164 
165 #endif /* USE_FULL_LL_DRIVER */
166