G32R430 Device Driver Layer v1.0.4
G32R4xx Device Driver Layer API Reference
g32r4xx_ddl_gpio.c
Go to the documentation of this file.
1
43#if defined(USE_FULL_DDL_DRIVER)
44
45/* Includes ------------------------------------------------------------------*/
46#include "g32r4xx_ddl_gpio.h"
47#include "g32r4xx_ddl_rcm.h"
48#ifdef USE_FULL_ASSERT
49#include "g32_assert.h"
50#else
51#define ASSERT_PARAM(_PARAM_) ((void)0U)
52#endif
53
57
58#if defined (GPIO)
59
63
64/* Private types -------------------------------------------------------------*/
65/* Private variables ---------------------------------------------------------*/
66/* Private constants ---------------------------------------------------------*/
67/* Private macros ------------------------------------------------------------*/
71#define IS_DDL_GPIO_PORT(__VALUE__) ((__VALUE__) < (4U))
72
73#define IS_DDL_GPIO_PIN(__VALUE__) (((0x00000000U) < (__VALUE__)) && ((__VALUE__) <= (DDL_GPIO_PIN_ALL)))
74
75#define DDL_GPIO_PIN_0_5 (DDL_GPIO_PIN_0 | DDL_GPIO_PIN_1 | DDL_GPIO_PIN_2 | \
76 DDL_GPIO_PIN_3 | DDL_GPIO_PIN_4 | DDL_GPIO_PIN_5)
77
78#define IS_DDL_GPIO_PIN_FOR_PORT(__GPIO__, __PIN__) \
79 (((__GPIO__) == GPIOA) ? (((__PIN__) & ~DDL_GPIO_PIN_0_5) == 0U) : \
80 (((__PIN__) & ~DDL_GPIO_PIN_ALL) == 0U))
81
82#define IS_DDL_GPIO_MODE(__VALUE__) (((__VALUE__) == DDL_GPIO_MODE_INPUT) ||\
83 ((__VALUE__) == DDL_GPIO_MODE_OUTPUT) ||\
84 ((__VALUE__) == DDL_GPIO_MODE_ALTERNATE) ||\
85 ((__VALUE__) == DDL_GPIO_MODE_ANALOG))
86
87#define IS_DDL_GPIO_OUTPUT_TYPE(__VALUE__) (((__VALUE__) == DDL_GPIO_OUTPUT_PUSHPULL) ||\
88 ((__VALUE__) == DDL_GPIO_OUTPUT_OPENDRAIN))
89
90#define IS_DDL_GPIO_SPEED(__VALUE__) (((__VALUE__) == DDL_GPIO_SPEED_FREQ_LOW) ||\
91 ((__VALUE__) == DDL_GPIO_SPEED_FREQ_MEDIUM) ||\
92 ((__VALUE__) == DDL_GPIO_SPEED_FREQ_HIGH))
93
94#define IS_DDL_GPIO_PULL(__VALUE__) (((__VALUE__) == DDL_GPIO_PULL_NO) ||\
95 ((__VALUE__) == DDL_GPIO_PULL_UP) ||\
96 ((__VALUE__) == DDL_GPIO_PULL_DOWN))
97
98#define IS_DDL_GPIO_ALTERNATE(__VALUE__) (((__VALUE__) == DDL_GPIO_AF_0) ||\
99 ((__VALUE__) == DDL_GPIO_AF_1) ||\
100 ((__VALUE__) == DDL_GPIO_AF_2) ||\
101 ((__VALUE__) == DDL_GPIO_AF_3))
102
103#define IS_DDL_GPIO_SPECIAL_PIN_TYPE(__VALUE__) (((__VALUE__) == DDL_GPIO_SPECIAL_PIN_TYPE_DIGITAL_5V_INPUT) ||\
104 ((__VALUE__) == DDL_GPIO_SPECIAL_PIN_TYPE_ANALOG_3V3_INPUT_OUTPUT))
105
106#define IS_DDL_GPIO_SPECIAL_PIN(__GPIO__, __PIN__) ((((__GPIO__) == GPIOB) && (((__PIN__) == DDL_GPIO_PIN_4) || ((__PIN__) == DDL_GPIO_PIN_6))) ||\
107 (((__GPIO__) == GPIOC) && ((__PIN__) == DDL_GPIO_PIN_12)) ||\
108 (((__GPIO__) == GPIOD) && (((__PIN__) == DDL_GPIO_PIN_5) || ((__PIN__) == DDL_GPIO_PIN_12) || ((__PIN__) == DDL_GPIO_PIN_15))))
109
110#define DDL_GPIO_ADC3_SWR_PIN_B (DDL_GPIO_PIN_2 | DDL_GPIO_PIN_3 | DDL_GPIO_PIN_5)
111#define DDL_GPIO_ADC3_SWR_PIN_C (DDL_GPIO_PIN_3 | DDL_GPIO_PIN_4 | DDL_GPIO_PIN_5 | \
112 DDL_GPIO_PIN_6 | DDL_GPIO_PIN_9 | DDL_GPIO_PIN_10 | DDL_GPIO_PIN_11)
113#define DDL_GPIO_ADC3_SWR_PIN_D (DDL_GPIO_PIN_0 | DDL_GPIO_PIN_1 | DDL_GPIO_PIN_2)
114
115#define IS_DDL_GPIO_ADC3_ANALOG_SWITCH_PIN(__GPIO__, __PIN__) \
116 ( ((__PIN__) != 0U) && \
117 ( (((__GPIO__) == GPIOB) && (((__PIN__) & ~DDL_GPIO_ADC3_SWR_PIN_B) == 0U)) || \
118 (((__GPIO__) == GPIOC) && (((__PIN__) & ~DDL_GPIO_ADC3_SWR_PIN_C) == 0U)) || \
119 (((__GPIO__) == GPIOD) && (((__PIN__) & ~DDL_GPIO_ADC3_SWR_PIN_D) == 0U)) ) )
120
124
125/* Private function prototypes -----------------------------------------------*/
126
127/* Exported functions --------------------------------------------------------*/
131
135
143ErrorStatus DDL_GPIO_DeInit(GPIO_Type GPIOx)
144{
145 if(!IS_DDL_GPIO_PORT(GPIOx))
146 {
147 return (ERROR);
148 }
149
150 DDL_GPIO_InitTypeDef deInitStruct;
151 DDL_GPIO_StructInit(&deInitStruct);
152 DDL_GPIO_Init(GPIOx, &deInitStruct);
153
154 return (SUCCESS);
155}
156
166ErrorStatus DDL_GPIO_Init(GPIO_Type GPIOx, DDL_GPIO_InitTypeDef *GPIO_InitStruct)
167{
168 uint32_t pinpos = 0x00000000U;
169 uint32_t currentpin = 0x00000000U;
170
171 /* Check the parameters */
172 ASSERT_PARAM(IS_DDL_GPIO_PIN(GPIO_InitStruct->Pin));
173 ASSERT_PARAM(IS_DDL_GPIO_PIN_FOR_PORT(GPIOx, GPIO_InitStruct->Pin));
174 ASSERT_PARAM(IS_DDL_GPIO_MODE(GPIO_InitStruct->Mode));
175 ASSERT_PARAM(IS_DDL_GPIO_PULL(GPIO_InitStruct->Pull));
176
177 if (!IS_DDL_GPIO_PIN_FOR_PORT(GPIOx, GPIO_InitStruct->Pin))
178 {
179 return (ERROR);
180 }
181
182 /* ------------------------- Configure the port pins ---------------- */
183 /* Initialize pinpos on first pin set */
184 pinpos = POSITION_VAL(GPIO_InitStruct->Pin);
185
186 /* Configure the port pins */
187 while (((GPIO_InitStruct->Pin) >> pinpos) != 0x00000000U)
188 {
189 /* Get current io position */
190 currentpin = (GPIO_InitStruct->Pin) & (0x00000001U << pinpos);
191
192 if (currentpin)
193 {
194
195 if ((GPIO_InitStruct->Mode == DDL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == DDL_GPIO_MODE_ALTERNATE))
196 {
197 /* Check Speed mode parameters */
198 ASSERT_PARAM(IS_DDL_GPIO_SPEED(GPIO_InitStruct->Speed));
199
200 /* Speed mode configuration */
201 DDL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
202
203 /* Check Output mode parameters */
205
206 /* Output mode configuration*/
207 DDL_GPIO_SetPinOutputType(GPIOx, currentpin, GPIO_InitStruct->OutputType);
208 }
209
210 /* Pull-up Pull down resistor configuration*/
211 DDL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
212
213 if (GPIO_InitStruct->Mode == DDL_GPIO_MODE_ALTERNATE)
214 {
215 /* Check Alternate parameter */
217
218 /* Alternate function configuration */
219 DDL_GPIO_SetAFPin(GPIOx, currentpin, GPIO_InitStruct->Alternate);
220 }
221
222 /* Init always clears SWR. ADC3 channels use DDL_GPIO_EnableAdc3AnalogSwitchPin();
223 5 V-tolerant special pins use DDL_GPIO_SetSpecialPinType(). */
224 {
225 volatile uint16_t *swr = DDL_GPIO_Locate16BitReg((&GPIO->SWR1), GPIOx);
226 CLEAR_BIT16((swr), currentpin);
227 }
228
229 /* Pin Mode configuration */
230 DDL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
231 }
232 pinpos++;
233 }
234
235 return (SUCCESS);
236}
237
244
246{
247 /* Reset GPIO init structure parameters values */
248 GPIO_InitStruct->Pin = DDL_GPIO_PIN_ALL;
249 GPIO_InitStruct->Mode = DDL_GPIO_MODE_ANALOG;
250 GPIO_InitStruct->Speed = DDL_GPIO_SPEED_FREQ_LOW;
251 GPIO_InitStruct->OutputType = DDL_GPIO_OUTPUT_PUSHPULL;
252 GPIO_InitStruct->Pull = DDL_GPIO_PULL_NO;
253 GPIO_InitStruct->Alternate = DDL_GPIO_AF_0;
254}
255
263{
264 volatile uint16_t *reg;
265
267
268 reg = DDL_GPIO_Locate16BitReg((&GPIO->SWR1), GPIOx);
269 SET_BIT16((reg), PinMask);
270}
271
279{
280 volatile uint16_t *reg;
281
283
284 reg = DDL_GPIO_Locate16BitReg((&GPIO->SWR1), GPIOx);
285 CLEAR_BIT16((reg), PinMask);
286}
287
295void DDL_GPIO_SetSpecialPinType(GPIO_Type GPIOx, uint32_t PinMask, uint32_t PinType)
296{
297 volatile uint16_t *reg;
298
300 ASSERT_PARAM(IS_DDL_GPIO_SPECIAL_PIN(GPIOx, PinMask));
301
302 reg = DDL_GPIO_Locate16BitReg((&GPIO->SWR1), GPIOx);
303 MODIFY_REG16((reg), PinMask, (PinMask * PinType));
304}
305
312uint32_t DDL_GPIO_GetSpecialPinType(GPIO_Type GPIOx, uint32_t PinMask)
313{
314 volatile uint16_t *reg;
315
316 ASSERT_PARAM(IS_DDL_GPIO_SPECIAL_PIN(GPIOx, PinMask));
317
318 reg = DDL_GPIO_Locate16BitReg((&GPIO->SWR1), GPIOx);
319 return (uint32_t)(READ_BIT16((reg), PinMask) >> POSITION_VAL(PinMask));
320}
321
325
329
333
334#endif /* defined (GPIO) */
335
339
340#endif /* USE_FULL_DDL_DRIVER */
341
G32 assert template file. This file should be copied to the application folder and renamed to g32_ass...
#define ASSERT_PARAM(_PARAM_)
Definition g32_assert.h:58
Header file of GPIO DDL module.
Header file of RCM DDL module.
#define DDL_GPIO_AF_0
#define DDL_GPIO_MODE_ALTERNATE
#define DDL_GPIO_MODE_OUTPUT
#define DDL_GPIO_MODE_ANALOG
#define DDL_GPIO_OUTPUT_PUSHPULL
#define DDL_GPIO_PIN_ALL
#define DDL_GPIO_PULL_NO
#define DDL_GPIO_SPEED_FREQ_LOW
uint32_t DDL_GPIO_GetSpecialPinType(GPIO_Type GPIOx, uint32_t PinMask)
Return special pin type configuration for the dedicated special GPIO pin.
ErrorStatus DDL_GPIO_DeInit(GPIO_Type GPIOx)
De-initialize GPIO registers (Registers restored to their default values).
void DDL_GPIO_EnableAdc3AnalogSwitchPin(GPIO_Type GPIOx, uint32_t PinMask)
Enable ADC3 analog switch bits in SWR.
void DDL_GPIO_SetSpecialPinType(GPIO_Type GPIOx, uint32_t PinMask, uint32_t PinType)
Configure special pin type for the dedicated special GPIO pin.
void DDL_GPIO_DisableAdc3AnalogSwitchPin(GPIO_Type GPIOx, uint32_t PinMask)
Disable ADC3 analog switch bits in SWR.
void DDL_GPIO_StructInit(DDL_GPIO_InitTypeDef *GPIO_InitStruct)
Set each DDL_GPIO_InitTypeDef field to default value.
ErrorStatus DDL_GPIO_Init(GPIO_Type GPIOx, DDL_GPIO_InitTypeDef *GPIO_InitStruct)
Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
__STATIC_INLINE void DDL_GPIO_SetPinOutputType(GPIO_Type GPIOx, uint32_t PinMask, uint32_t OutputType)
Configure gpio output type for several pins on dedicated port.
__STATIC_INLINE void DDL_GPIO_SetPinPull(GPIO_Type GPIOx, uint32_t Pin, uint32_t Pull)
Configure gpio pull-up or pull-down for a dedicated pin on a dedicated port.
__STATIC_INLINE void DDL_GPIO_SetAFPin(GPIO_Type GPIOx, uint32_t Pin, uint32_t Alternate)
Configure gpio alternate function of a dedicated pin for a dedicated port.
__STATIC_INLINE void DDL_GPIO_SetPinMode(GPIO_Type GPIOx, uint32_t Pin, uint32_t Mode)
Configure gpio mode for a dedicated pin on a dedicated port.
__STATIC_INLINE void DDL_GPIO_SetPinSpeed(GPIO_Type GPIOx, uint32_t Pin, uint32_t Speed)
Configure gpio speed for a dedicated pin on a dedicated port.
#define DDL_GPIO_Locate16BitReg(__BASEADDR__, __GPIO__)
#define IS_DDL_GPIO_MODE(__VALUE__)
#define IS_DDL_GPIO_OUTPUT_TYPE(__VALUE__)
#define IS_DDL_GPIO_PULL(__VALUE__)
#define IS_DDL_GPIO_SPECIAL_PIN(__GPIO__, __PIN__)
#define IS_DDL_GPIO_PIN(__VALUE__)
#define IS_DDL_GPIO_SPECIAL_PIN_TYPE(__VALUE__)
#define IS_DDL_GPIO_PORT(__VALUE__)
#define IS_DDL_GPIO_ALTERNATE(__VALUE__)
#define IS_DDL_GPIO_ADC3_ANALOG_SWITCH_PIN(__GPIO__, __PIN__)
#define IS_DDL_GPIO_PIN_FOR_PORT(__GPIO__, __PIN__)
#define IS_DDL_GPIO_SPEED(__VALUE__)
GPIO_Type
G32R4XX GPIO port Definition, according to the selected device configuration in the CMSIS device head...
LL GPIO Init Structure definition.