G32R430 Device Driver Layer v1.0.4
G32R4xx Device Driver Layer API Reference
g32r4xx_ddl_gpio.h
Go to the documentation of this file.
1
42
43/* Define to prevent recursive inclusion -------------------------------------*/
44#ifndef G32R4xx_DDL_GPIO_H
45#define G32R4xx_DDL_GPIO_H
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/* Includes ------------------------------------------------------------------*/
52#include "g32r4xx.h"
53
57
58#if defined (GPIO)
59
63
64/* Private types -------------------------------------------------------------*/
65
70typedef enum
71{
72 GPIOA = 0,
73 GPIOB = 1,
74 GPIOC = 2,
75 GPIOD = 3
76} GPIO_Type;
77
78/* Private variables ---------------------------------------------------------*/
79/* Private constants ---------------------------------------------------------*/
80/* Private macros ------------------------------------------------------------*/
81#if defined(USE_FULL_DDL_DRIVER)
85
89#endif /*USE_FULL_DDL_DRIVER*/
90
91/* Exported types ------------------------------------------------------------*/
92#if defined(USE_FULL_DDL_DRIVER)
96
100typedef struct
101{
102 uint32_t Pin;
104
105 uint32_t Mode;
109
110 uint32_t Speed;
114
115 uint32_t OutputType;
119
120 uint32_t Pull;
124
125 uint32_t Alternate;
130
134#endif /* USE_FULL_DDL_DRIVER */
135
136/* Exported constants --------------------------------------------------------*/
140
144#define DDL_GPIO_PIN_0 GPIO_PIN0
145#define DDL_GPIO_PIN_1 GPIO_PIN1
146#define DDL_GPIO_PIN_2 GPIO_PIN2
147#define DDL_GPIO_PIN_3 GPIO_PIN3
148#define DDL_GPIO_PIN_4 GPIO_PIN4
149#define DDL_GPIO_PIN_5 GPIO_PIN5
150#define DDL_GPIO_PIN_6 GPIO_PIN6
151#define DDL_GPIO_PIN_7 GPIO_PIN7
152#define DDL_GPIO_PIN_8 GPIO_PIN8
153#define DDL_GPIO_PIN_9 GPIO_PIN9
154#define DDL_GPIO_PIN_10 GPIO_PIN10
155#define DDL_GPIO_PIN_11 GPIO_PIN11
156#define DDL_GPIO_PIN_12 GPIO_PIN12
157#define DDL_GPIO_PIN_13 GPIO_PIN13
158#define DDL_GPIO_PIN_14 GPIO_PIN14
159#define DDL_GPIO_PIN_15 GPIO_PIN15
160#define DDL_GPIO_PIN_ALL (GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | \
161 GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | \
162 GPIO_PIN6 | GPIO_PIN7 | GPIO_PIN8 | \
163 GPIO_PIN9 | GPIO_PIN10 | GPIO_PIN11 | \
164 GPIO_PIN12 | GPIO_PIN13 | GPIO_PIN14 | \
165 GPIO_PIN15)
166
169
173#define DDL_GPIO_MODE_ANALOG (0x00000000U)
174#define DDL_GPIO_MODE_INPUT GPIO_MODE_MODE0_0
175#define DDL_GPIO_MODE_OUTPUT GPIO_MODE_MODE0_1
176#define DDL_GPIO_MODE_ALTERNATE GPIO_MODE_MODE0
180
184#define DDL_GPIO_OUTPUT_PUSHPULL (0x00000000U)
185#define DDL_GPIO_OUTPUT_OPENDRAIN GPIO_OMODE_OT_0
189
193#define DDL_GPIO_SPEED_FREQ_LOW GPIO_OSPEEDER_OSPEEDR0_0
194#define DDL_GPIO_SPEED_FREQ_MEDIUM GPIO_OSPEEDER_OSPEEDR0_1
195#define DDL_GPIO_SPEED_FREQ_HIGH GPIO_OSPEEDER_OSPEEDR0
199
203#define DDL_GPIO_PULL_NO (0x00000000U)
204#define DDL_GPIO_PULL_UP GPIO_PUPD_PUPDR0_0
205#define DDL_GPIO_PULL_DOWN GPIO_PUPD_PUPDR0
209
213#define DDL_GPIO_AF_0 (0x0000000U)
214#define DDL_GPIO_AF_1 (0x0000001U)
215#define DDL_GPIO_AF_2 (0x0000002U)
216#define DDL_GPIO_AF_3 (0x0000003U)
220
224#define DDL_GPIO_SPECIAL_PIN_TYPE_DIGITAL_5V_INPUT (0x00000000U)
225#define DDL_GPIO_SPECIAL_PIN_TYPE_ANALOG_3V3_INPUT_OUTPUT (0x00000001U)
229
233
234/* Exported macro ------------------------------------------------------------*/
238
242#define DDL_GPIO_Locate32BitReg(__BASEADDR__, __GPIO__) ((__BASEADDR__) + (__GPIO__ << 2))
243
244#define DDL_GPIO_Locate16BitReg(__BASEADDR__, __GPIO__) \
245 ((volatile uint16_t *)(((volatile uint8_t *)(__BASEADDR__)) + (((uint32_t)(__GPIO__)) << 1)))
246
254#define DDL_GPIO_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
255
262#define DDL_GPIO_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
266
270
271/* Exported functions --------------------------------------------------------*/
275
279
309__STATIC_INLINE void DDL_GPIO_SetPinMode(GPIO_Type GPIOx, uint32_t Pin, uint32_t Mode)
310{
311 volatile uint32_t *reg = (volatile uint32_t*)DDL_GPIO_Locate32BitReg((uint32_t)(&GPIO->MODER1), GPIOx);
312 MODIFY_REG((*reg), (GPIO_MODE_MODE0 << (POSITION_VAL(Pin) * 2U)), (Mode << (POSITION_VAL(Pin) * 2U)));
313}
314
343__STATIC_INLINE uint32_t DDL_GPIO_GetPinMode(GPIO_Type GPIOx, uint32_t Pin)
344{
345 volatile uint32_t *reg = (volatile uint32_t*)DDL_GPIO_Locate32BitReg((uint32_t)(&GPIO->MODER1), GPIOx);
346 return (uint32_t)(READ_BIT((*reg),
347 (GPIO_MODE_MODE0 << (POSITION_VAL(Pin) * 2U))) >> (POSITION_VAL(Pin) * 2U));
348}
349
378__STATIC_INLINE void DDL_GPIO_SetPinOutputType(GPIO_Type GPIOx, uint32_t PinMask, uint32_t OutputType)
379{
380 volatile uint16_t *reg = DDL_GPIO_Locate16BitReg((&GPIO->OTYPER1), GPIOx);
381 MODIFY_REG16((reg), PinMask, (PinMask * OutputType));
382}
383
412__STATIC_INLINE uint32_t DDL_GPIO_GetPinOutputType(GPIO_Type GPIOx, uint32_t Pin)
413{
414 volatile uint16_t *reg = DDL_GPIO_Locate16BitReg((&GPIO->OTYPER1), GPIOx);
415 return (uint32_t)(READ_BIT16((reg), Pin) >> POSITION_VAL(Pin));
416}
417
448__STATIC_INLINE void DDL_GPIO_SetPinSpeed(GPIO_Type GPIOx, uint32_t Pin, uint32_t Speed)
449{
450 volatile uint32_t *reg = (volatile uint32_t*)DDL_GPIO_Locate32BitReg((uint32_t)(&GPIO->OSPEEDR1), GPIOx);
451 MODIFY_REG((*reg), (GPIO_OSPEEDER_OSPEEDR0 << (POSITION_VAL(Pin) * 2U)),
452 (Speed << (POSITION_VAL(Pin) * 2U)));
453}
454
484__STATIC_INLINE uint32_t DDL_GPIO_GetPinSpeed(GPIO_Type GPIOx, uint32_t Pin)
485{
486 volatile uint32_t *reg = (volatile uint32_t*)DDL_GPIO_Locate32BitReg((uint32_t)(&GPIO->OSPEEDR1), GPIOx);
487 return (uint32_t)(READ_BIT((*reg),
488 (GPIO_OSPEEDER_OSPEEDR0 << (POSITION_VAL(Pin) * 2U))) >> (POSITION_VAL(Pin) * 2U));
489}
490
518__STATIC_INLINE void DDL_GPIO_SetPinPull(GPIO_Type GPIOx, uint32_t Pin, uint32_t Pull)
519{
520 volatile uint32_t *reg = (volatile uint32_t*)DDL_GPIO_Locate32BitReg((uint32_t)(&GPIO->PUPDR1), GPIOx);
521 MODIFY_REG((*reg), (GPIO_PUPD_PUPDR0 << (POSITION_VAL(Pin) * 2U)), (Pull << (POSITION_VAL(Pin) * 2U)));
522}
523
550__STATIC_INLINE uint32_t DDL_GPIO_GetPinPull(GPIO_Type GPIOx, uint32_t Pin)
551{
552 volatile uint32_t *reg = (volatile uint32_t*)DDL_GPIO_Locate32BitReg((uint32_t)(&GPIO->PUPDR1), GPIOx);
553 return (uint32_t)(READ_BIT((*reg),
554 (GPIO_PUPD_PUPDR0 << (POSITION_VAL(Pin) * 2U))) >> (POSITION_VAL(Pin) * 2U));
555}
556
586__STATIC_INLINE void DDL_GPIO_SetAFPin(GPIO_Type GPIOx, uint32_t Pin, uint32_t Alternate)
587{
588 volatile uint32_t *reg = (volatile uint32_t*)DDL_GPIO_Locate32BitReg((uint32_t)(&GPIO->AFSELR1), GPIOx);
589 MODIFY_REG((*reg), (GPIO_ALF_ALFSEL0 << (POSITION_VAL(Pin) * 2U)),
590 (Alternate << (POSITION_VAL(Pin) * 2U)));
591}
592
618__STATIC_INLINE uint32_t DDL_GPIO_GetAFPin(GPIO_Type GPIOx, uint32_t Pin)
619{
620 volatile uint32_t *reg = (volatile uint32_t*)DDL_GPIO_Locate32BitReg((uint32_t)(&GPIO->AFSELR1) ,GPIOx);
621 return (uint32_t)(READ_BIT((*reg),
622 (GPIO_ALF_ALFSEL0 << (POSITION_VAL(Pin) * 2U))) >> (POSITION_VAL(Pin) * 2U));
623}
624
650__STATIC_INLINE void DDL_GPIO_EnablePinFilter(GPIO_Type GPIOx, uint32_t Pin)
651{
652 volatile uint16_t *reg = DDL_GPIO_Locate16BitReg((&GPIO->FILTERR1), GPIOx);
653 SET_BIT16((reg), (Pin & DDL_GPIO_PIN_ALL));
654}
655
681__STATIC_INLINE void DDL_GPIO_DisablePinFilter(GPIO_Type GPIOx, uint32_t Pin)
682{
683 volatile uint16_t *reg = DDL_GPIO_Locate16BitReg((&GPIO->FILTERR1), GPIOx);
684 CLEAR_BIT16((reg), (Pin & DDL_GPIO_PIN_ALL));
685}
686
712__STATIC_INLINE uint32_t DDL_GPIO_IsEnabledPinFilter(GPIO_Type GPIOx, uint32_t Pin)
713{
714 volatile uint16_t *reg = DDL_GPIO_Locate16BitReg((&GPIO->FILTERR1), GPIOx);
715 uint32_t pinMask = (Pin & DDL_GPIO_PIN_ALL);
716 return (uint32_t)(READ_BIT16((reg), pinMask) == pinMask);
717}
718
722
726
732__STATIC_INLINE uint32_t DDL_GPIO_ReadInputPort(GPIO_Type GPIOx)
733{
734 volatile uint16_t *reg = DDL_GPIO_Locate16BitReg((&GPIO->IDR1), GPIOx);
735 return (uint32_t)(READ_REG16(reg));
736}
737
761__STATIC_INLINE uint32_t DDL_GPIO_IsInputPinSet(GPIO_Type GPIOx, uint32_t PinMask)
762{
763 volatile uint16_t *reg = DDL_GPIO_Locate16BitReg((&GPIO->IDR1), GPIOx);
764 return ((READ_BIT16((reg), PinMask) == (PinMask)) ? 1UL : 0UL);
765}
766
773__STATIC_INLINE void DDL_GPIO_WriteOutputPort(GPIO_Type GPIOx, uint32_t PortValue)
774{
775 volatile uint16_t *reg = DDL_GPIO_Locate16BitReg((&GPIO->ODR1), GPIOx);
776 WRITE_REG16((reg), PortValue);
777}
778
784__STATIC_INLINE uint32_t DDL_GPIO_ReadOutputPort(GPIO_Type GPIOx)
785{
786 volatile uint16_t *reg = DDL_GPIO_Locate16BitReg((&GPIO->ODR1), GPIOx);
787 return (uint32_t)(READ_REG16((reg)));
788}
789
813__STATIC_INLINE uint32_t DDL_GPIO_IsOutputPinSet(GPIO_Type GPIOx, uint32_t PinMask)
814{
815 volatile uint16_t *reg = DDL_GPIO_Locate16BitReg((&GPIO->ODR1), GPIOx);
816 return ((READ_BIT16((reg), PinMask) == (PinMask)) ? 1UL : 0UL);
817}
818
842__STATIC_INLINE void DDL_GPIO_SetOutputPin(GPIO_Type GPIOx, uint32_t PinMask)
843{
844 volatile uint32_t *reg = (volatile uint32_t*)DDL_GPIO_Locate32BitReg((uint32_t)(&GPIO->BSRR1), GPIOx);
845 SET_BIT((*reg), (PinMask));
846}
847
871__STATIC_INLINE void DDL_GPIO_ResetOutputPin(GPIO_Type GPIOx, uint32_t PinMask)
872{
873 volatile uint32_t *reg = (volatile uint32_t*)DDL_GPIO_Locate32BitReg((uint32_t)(&GPIO->BSRR1), GPIOx);
874 SET_BIT((*reg), (PinMask << 16));
875}
876
900__STATIC_INLINE void DDL_GPIO_TogglePin(GPIO_Type GPIOx, uint32_t PinMask)
901{
902 uint32_t odr = 0;
903 volatile uint16_t *reg = DDL_GPIO_Locate16BitReg((&GPIO->ODR1), GPIOx);
904 odr = READ_REG16((reg));
905 MODIFY_REG16((reg), (odr & PinMask), (~odr & PinMask));
906}
907
929void DDL_GPIO_EnableAdc3AnalogSwitchPin(GPIO_Type GPIOx, uint32_t PinMask);
930
938void DDL_GPIO_DisableAdc3AnalogSwitchPin(GPIO_Type GPIOx, uint32_t PinMask);
939
968void DDL_GPIO_SetSpecialPinType(GPIO_Type GPIOx, uint32_t PinMask, uint32_t PinType);
969
991uint32_t DDL_GPIO_GetSpecialPinType(GPIO_Type GPIOx, uint32_t PinMask);
992
996
997#if defined(USE_FULL_DDL_DRIVER)
1001
1002ErrorStatus DDL_GPIO_DeInit(GPIO_Type GPIOx);
1003ErrorStatus DDL_GPIO_Init(GPIO_Type GPIOx, DDL_GPIO_InitTypeDef *GPIO_InitStruct);
1004void DDL_GPIO_StructInit(DDL_GPIO_InitTypeDef *GPIO_InitStruct);
1005
1009#endif /* USE_FULL_DDL_DRIVER */
1010
1014
1018
1019#endif /* defined (GPIO) */
1023
1024#ifdef __cplusplus
1025}
1026#endif
1027
1028#endif /* G32R4xx_DDL_GPIO_H */
1029
#define DDL_GPIO_PIN_ALL
__STATIC_INLINE uint32_t DDL_GPIO_IsOutputPinSet(GPIO_Type GPIOx, uint32_t PinMask)
Return if input data level for several pins of dedicated port is high or low.
__STATIC_INLINE uint32_t DDL_GPIO_IsInputPinSet(GPIO_Type GPIOx, uint32_t PinMask)
Return if input data level for several pins of a dedicated port is high or low.
__STATIC_INLINE uint32_t DDL_GPIO_ReadInputPort(GPIO_Type GPIOx)
Return full input data register value for a dedicated port.
__STATIC_INLINE uint32_t DDL_GPIO_ReadOutputPort(GPIO_Type GPIOx)
Return full output data register value for a dedicated port.
uint32_t DDL_GPIO_GetSpecialPinType(GPIO_Type GPIOx, uint32_t PinMask)
Return special pin type configuration for the dedicated special GPIO pin.
__STATIC_INLINE void DDL_GPIO_WriteOutputPort(GPIO_Type GPIOx, uint32_t PortValue)
Write output data register for the port.
__STATIC_INLINE void DDL_GPIO_SetOutputPin(GPIO_Type GPIOx, uint32_t PinMask)
Set several pins to high level on dedicated gpio port.
void DDL_GPIO_EnableAdc3AnalogSwitchPin(GPIO_Type GPIOx, uint32_t PinMask)
Enable ADC3 analog switch bits in SWR for the given GPIO port.
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 for the given GPIO port.
__STATIC_INLINE void DDL_GPIO_TogglePin(GPIO_Type GPIOx, uint32_t PinMask)
Toggle data value for several pin of dedicated port.
__STATIC_INLINE void DDL_GPIO_ResetOutputPin(GPIO_Type GPIOx, uint32_t PinMask)
Set several pins to low level on dedicated gpio port.
ErrorStatus DDL_GPIO_DeInit(GPIO_Type GPIOx)
De-initialize GPIO registers (Registers restored to their default values).
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 uint32_t DDL_GPIO_GetPinMode(GPIO_Type GPIOx, uint32_t Pin)
Return gpio mode for a dedicated pin on a dedicated port.
__STATIC_INLINE void DDL_GPIO_DisablePinFilter(GPIO_Type GPIOx, uint32_t Pin)
Disable the wave filter for a certain pin of the specified GPIO port.
__STATIC_INLINE void DDL_GPIO_EnablePinFilter(GPIO_Type GPIOx, uint32_t Pin)
Enable the wave filter for a certain pin of the specified GPIO port.
__STATIC_INLINE uint32_t DDL_GPIO_GetPinOutputType(GPIO_Type GPIOx, uint32_t Pin)
Return gpio output type for several pins on 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 uint32_t DDL_GPIO_GetPinPull(GPIO_Type GPIOx, uint32_t Pin)
Return gpio pull-up or pull-down for a dedicated pin on 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 uint32_t DDL_GPIO_GetPinSpeed(GPIO_Type GPIOx, uint32_t Pin)
Return gpio speed for a dedicated pin on dedicated port.
__STATIC_INLINE uint32_t DDL_GPIO_IsEnabledPinFilter(GPIO_Type GPIOx, uint32_t Pin)
Check whether the wave filter for a certain pin is enabled or disabled.
__STATIC_INLINE uint32_t DDL_GPIO_GetAFPin(GPIO_Type GPIOx, uint32_t Pin)
Return gpio alternate function of a dedicated pin for 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_Locate32BitReg(__BASEADDR__, __GPIO__)
#define DDL_GPIO_Locate16BitReg(__BASEADDR__, __GPIO__)
GPIO_Type
G32R4XX GPIO port Definition, according to the selected device configuration in the CMSIS device head...
@ GPIOB
@ GPIOC
@ GPIOA
@ GPIOD
LL GPIO Init Structure definition.