STM32 Blue Pill Drivers
Drivers that could be used to interface and interact with STM32F103C8T6 Microcontroller
Loading...
Searching...
No Matches
GPIO_program.c File Reference

This file contains the implementation for the GPIO module. More...

+ Include dependency graph for GPIO_program.c:

Macros

#define IS_PIN_IN_LOW_REGISTER(GPIO_PIN)   (GPIO_PIN <= GPIO_Pins_7)
 Check if the pin is in the low register. More...
 

Functions

static void GPIO_vGetPortAddress (t_GPIO_Ports tPort, t_GPIOx_RegisterMap **ppu32PortBaseAddress)
 This function gets the base address of a GPIO port. More...
 
static t_u8 GPIO_vGetPinSpan (t_GPIO_Pins tPin)
 This function gets the pin span. More...
 
static void GPIO_vSetPinInputTypePullUpDown (t_GPIOx_RegisterMap *pu32PortBaseAddress, t_GPIO_Pins tPin, t_GPIO_Input_Type tInputType)
 This function is used to set the pin input type. More...
 
void GPIO_vSetPinDirection (t_GPIO_Ports tPort, t_GPIO_Pins tPin, t_GPIO_Direction tDirection)
 This function is used to set the direction of a GPIO pin. More...
 
void GPIO_vSetPinInputType (t_GPIO_Ports tPort, t_GPIO_Pins tPin, t_GPIO_Input_Type tInputType)
 This function is used to set the input type of a GPIO pin. More...
 
void GPIO_vSetPinOutputType (t_GPIO_Ports tPort, t_GPIO_Pins tPin, t_GPIO_Output_Type tOutputType)
 This function is used to set the output type of a GPIO pin. More...
 
void GPIO_vSetPinValue (t_GPIO_Ports tPort, t_GPIO_Pins tPin, t_GPIO_Value tValue)
 This function is used to set the value of a GPIO pin. More...
 
t_GPIO_Value GPIO_tGetPinValue (t_GPIO_Ports tPort, t_GPIO_Pins tPin)
 This function is used to get the value of a GPIO pin. More...
 

Detailed Description

This file contains the implementation for the GPIO module.

Author
Mohamed Alaa
Version
1.0.0

This file contains the implementation for the GPIO module.

Date
2023-06-25

Macro Definition Documentation

◆ IS_PIN_IN_LOW_REGISTER

#define IS_PIN_IN_LOW_REGISTER (   GPIO_PIN)    (GPIO_PIN <= GPIO_Pins_7)

Check if the pin is in the low register.

This macro checks if the pin is in the low register (CRL)

Parameters
[in]GPIO_PINThe pin to check if it is in the low register (CRL) or not

Function Documentation

◆ GPIO_vGetPortAddress()

static void GPIO_vGetPortAddress ( t_GPIO_Ports  tPort,
t_GPIOx_RegisterMap **  ppu32PortBaseAddress 
)
static

This function gets the base address of a GPIO port.

This function gets the base address of a GPIO port

Parameters
[in]tPortThe GPIO port to get its base address
[out]ppu32PortBaseAddressThe base address of the GPIO port
33{
35 pu32PortBaseAddress = (P2VAR(t_GPIOx_RegisterMap))NULL;
36
37 switch (tPort)
38 {
39 case GPIO_Ports_A:
40 pu32PortBaseAddress = &GPIO_A;
41 break;
42 case GPIO_Ports_B:
43 pu32PortBaseAddress = &GPIO_B;
44 break;
45 case GPIO_Ports_C:
46 pu32PortBaseAddress = &GPIO_C;
47 break;
48 case GPIO_Ports_D:
49 pu32PortBaseAddress = &GPIO_D;
50 break;
51 case GPIO_Ports_E:
52 pu32PortBaseAddress = &GPIO_E;
53 break;
54 case GPIO_Ports_F:
55 pu32PortBaseAddress = &GPIO_F;
56 break;
57 case GPIO_Ports_G:
58 pu32PortBaseAddress = &GPIO_G;
59 break;
60 default:
61 break;
62 }
63
64 *ppu32PortBaseAddress = (P2VAR(t_GPIOx_RegisterMap))pu32PortBaseAddress;
65}
#define P2VAR(ptrtype)
Declare a pointer-to-variable with the specified type.
Definition: LSTD_COMPILER.h:46
#define VOLATILE
Declare a standard volatile variable.
Definition: LSTD_COMPILER.h:39
#define NULL
Type definition for NULL.
Definition: LSTD_VALUES.h:42
@ GPIO_Ports_E
GPIO Port E.
Definition: GPIO_interface.h:49
@ GPIO_Ports_A
GPIO Port A.
Definition: GPIO_interface.h:33
@ GPIO_Ports_D
GPIO Port D.
Definition: GPIO_interface.h:45
@ GPIO_Ports_G
GPIO Port G.
Definition: GPIO_interface.h:57
@ GPIO_Ports_F
GPIO Port F.
Definition: GPIO_interface.h:53
@ GPIO_Ports_C
GPIO Port C.
Definition: GPIO_interface.h:41
@ GPIO_Ports_B
GPIO Port B.
Definition: GPIO_interface.h:37
#define GPIO_B
GPIO Port B.
Definition: GPIO_private.h:105
#define GPIO_C
GPIO Port C.
Definition: GPIO_private.h:117
#define GPIO_D
GPIO Port D.
Definition: GPIO_private.h:129
#define GPIO_A
GPIO Port A.
Definition: GPIO_private.h:93
#define GPIO_E
GPIO Port E.
Definition: GPIO_private.h:141
#define GPIO_F
GPIO Port F.
Definition: GPIO_private.h:153
#define GPIO_G
GPIO Port G.
Definition: GPIO_private.h:165
GPIO Register Map.
Definition: GPIO_private.h:46

References GPIO_A, GPIO_B, GPIO_C, GPIO_D, GPIO_E, GPIO_F, GPIO_G, GPIO_Ports_A, GPIO_Ports_B, GPIO_Ports_C, GPIO_Ports_D, GPIO_Ports_E, GPIO_Ports_F, GPIO_Ports_G, NULL, P2VAR, and VOLATILE.

Referenced by GPIO_tGetPinValue(), GPIO_vSetPinDirection(), GPIO_vSetPinInputType(), GPIO_vSetPinOutputType(), and GPIO_vSetPinValue().

+ Here is the caller graph for this function:

◆ GPIO_vGetPinSpan()

static t_u8 GPIO_vGetPinSpan ( t_GPIO_Pins  tPin)
static

This function gets the pin span.

This function gets the pin span, which is the number of bits to shift to reach the target pin mode and configuration bits

Parameters
[in]tPinThe target pin
Returns
t_u8 The pin span
74{
75 /* Get the pin span (the number of bits to shift to reach the target pin mode and configuration bits) */
76 return (t_u8)(((tPin <= GPIO_Pins_7) ? tPin : (tPin - GPIO_Pins_8)) * PIN_SHIFT_VALUE);
77}
unsigned char t_u8
Type definition for 8-bit unsigned INT.
Definition: LSTD_TYPES.h:34
@ GPIO_Pins_8
GPIO Pin 8.
Definition: GPIO_interface.h:102
@ GPIO_Pins_7
GPIO Pin 7.
Definition: GPIO_interface.h:98
#define PIN_SHIFT_VALUE
Pin Shift Value.
Definition: GPIO_private.h:180

References GPIO_Pins_7, GPIO_Pins_8, and PIN_SHIFT_VALUE.

Referenced by GPIO_vSetPinDirection(), GPIO_vSetPinInputType(), and GPIO_vSetPinOutputType().

+ Here is the caller graph for this function:

◆ GPIO_vSetPinInputTypePullUpDown()

static void GPIO_vSetPinInputTypePullUpDown ( t_GPIOx_RegisterMap pu32PortBaseAddress,
t_GPIO_Pins  tPin,
t_GPIO_Input_Type  tInputType 
)
static

This function is used to set the pin input type.

This function is used to set the pin input type in case of it is pull-up or pull-down in the ODR register

Parameters
[in]pu32PortBaseAddressThe base address of the GPIO port
[in]tPinThe target pin
[in]tInputTypeThe input type of the target pin (pull-up or pull-down)
See also
t_GPIO_Input_Type
88{
89 if (tInputType >= GPIO_Input_Type_Pull_Down)
90 {
91 /* Get the pin input type (pull-up or pull-down) */
92 t_u8 u8PinInputType = GET_BIT(tInputType, 0);
93
94 /* Set the pull-up/pull-down resistor */
95 pu32PortBaseAddress->ODR = (pu32PortBaseAddress->ODR & PIN_RESET_ODR_MASK(tPin)) | (t_u32)(u8PinInputType << tPin);
96 }
97 else
98 {
99 /* Do nothing */
100 }
101}
#define GET_BIT(REG, BITNUM)
Return the value of the bit whether it's 1 or 0
Definition: LSTD_BITMATH.h:53
unsigned int t_u32
Type definition for 32-bit unsigned int.
Definition: LSTD_TYPES.h:64
@ GPIO_Input_Type_Pull_Down
GPIO Pin Input Type: Pull-Down.
Definition: GPIO_interface.h:201
#define PIN_RESET_ODR_MASK(GPIO_PIN_SPAN)
Pin Reset ODR Mask.
Definition: GPIO_private.h:239
t_u32 ODR
Port Output Data Register.
Definition: GPIO_private.h:63

References GET_BIT, GPIO_Input_Type_Pull_Down, t_GPIOx_RegisterMap::ODR, and PIN_RESET_ODR_MASK.

Referenced by GPIO_vSetPinInputType().

+ Here is the caller graph for this function: