TM STM32Fxxx HAL Libraries  v1.0.0
Libraries for STM32Fxxx (F0, F4 and F7 series) devices based on HAL drivers from ST from Tilen Majerle

GPIO Functions. More...

Macros

#define TM_GPIO_SetPinLow(GPIOx, GPIO_Pin)   ((GPIOx)->BSRR = (uint32_t)(((uint32_t)GPIO_Pin) << 16))
 Sets pin(s) low. More...
 
#define TM_GPIO_SetPinHigh(GPIOx, GPIO_Pin)   ((GPIOx)->BSRR = (uint32_t)(GPIO_Pin))
 Sets pin(s) high. More...
 
#define TM_GPIO_SetPinValue(GPIOx, GPIO_Pin, val)   ((val) ? TM_GPIO_SetPinHigh(GPIOx, GPIO_Pin) : TM_GPIO_SetPinLow(GPIOx, GPIO_Pin))
 Sets pin(s) value. More...
 
#define TM_GPIO_TogglePinValue(GPIOx, GPIO_Pin)   ((GPIOx)->ODR ^= (GPIO_Pin))
 Toggles pin(s) More...
 
#define TM_GPIO_SetPortValue(GPIOx, value)   ((GPIOx)->ODR = (value))
 Sets value to entire GPIO PORT. More...
 
#define TM_GPIO_GetInputPinValue(GPIOx, GPIO_Pin)   (((GPIOx)->IDR & (GPIO_Pin)) == 0 ? 0 : 1)
 Gets input data bit. More...
 
#define TM_GPIO_GetOutputPinValue(GPIOx, GPIO_Pin)   (((GPIOx)->ODR & (GPIO_Pin)) == 0 ? 0 : 1)
 Gets output data bit. More...
 
#define TM_GPIO_GetPortInputValue(GPIOx)   ((GPIOx)->IDR)
 Gets input value from entire GPIO PORT. More...
 
#define TM_GPIO_GetPortOutputValue(GPIOx)   ((GPIOx)->ODR)
 Gets output value from entire GPIO PORT. More...
 

Functions

void TM_GPIO_Init (GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, TM_GPIO_Mode_t GPIO_Mode, TM_GPIO_OType_t GPIO_OType, TM_GPIO_PuPd_t GPIO_PuPd, TM_GPIO_Speed_t GPIO_Speed)
 Initializes GPIO pins(s) More...
 
void TM_GPIO_InitAlternate (GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, TM_GPIO_OType_t GPIO_OType, TM_GPIO_PuPd_t GPIO_PuPd, TM_GPIO_Speed_t GPIO_Speed, uint8_t Alternate)
 Initializes GPIO pins(s) as alternate function. More...
 
void TM_GPIO_DeInit (GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
 Deinitializes pin(s) More...
 
void TM_GPIO_SetPinAsInput (GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
 Sets pin(s) as input. More...
 
void TM_GPIO_SetPinAsOutput (GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
 Sets pin(s) as output. More...
 
void TM_GPIO_SetPinAsAnalog (GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
 Sets pin(s) as analog. More...
 
void TM_GPIO_SetPinAsAlternate (GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
 Sets pin(s) as alternate function. More...
 
void TM_GPIO_SetPullResistor (GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, TM_GPIO_PuPd_t GPIO_PuPd)
 Sets pull resistor settings to GPIO pin(s) More...
 
uint16_t TM_GPIO_GetPortSource (GPIO_TypeDef *GPIOx)
 Gets port source from desired GPIOx PORT. More...
 
uint16_t TM_GPIO_GetPinSource (uint16_t GPIO_Pin)
 Gets pin source from desired GPIO pin. More...
 
void TM_GPIO_Lock (GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
 Locks GPIOx register for future changes. More...
 
uint16_t TM_GPIO_GetUsedPins (GPIO_TypeDef *GPIOx)
 Gets bit separated pins which were used at least once in library and were not deinitialized. More...
 
uint16_t TM_GPIO_GetFreePins (GPIO_TypeDef *GPIOx)
 Gets bit separated pins which were not used at in library or were deinitialized. More...
 

Detailed Description

GPIO Functions.

TM_GPIO_Typedefs

Macro Definition Documentation

#define TM_GPIO_GetInputPinValue (   GPIOx,
  GPIO_Pin 
)    (((GPIOx)->IDR & (GPIO_Pin)) == 0 ? 0 : 1)

Gets input data bit.

Note
Defined as macro to get maximum speed using register access
Parameters
GPIOxGPIOx PORT where you want to read input bit value
GPIO_PinGPIO pin where you want to read value
Return values
1in case pin is high, or 0 if low
#define TM_GPIO_GetOutputPinValue (   GPIOx,
  GPIO_Pin 
)    (((GPIOx)->ODR & (GPIO_Pin)) == 0 ? 0 : 1)

Gets output data bit.

Note
Defined as macro to get maximum speed using register access
Parameters
GPIOxGPIOx PORT where you want to read output bit value
GPIO_PinGPIO pin where you want to read value
Return values
1in case pin is high, or 0 if low
#define TM_GPIO_GetPortInputValue (   GPIOx)    ((GPIOx)->IDR)

Gets input value from entire GPIO PORT.

Note
Defined as macro to get maximum speed using register access
Parameters
GPIOxGPIOx PORT where you want to read input data value
Return values
EntirePORT INPUT register
#define TM_GPIO_GetPortOutputValue (   GPIOx)    ((GPIOx)->ODR)

Gets output value from entire GPIO PORT.

Note
Defined as macro to get maximum speed using register access
Parameters
GPIOxGPIOx PORT where you want to read output data value
Return values
EntirePORT OUTPUT register
#define TM_GPIO_SetPinHigh (   GPIOx,
  GPIO_Pin 
)    ((GPIOx)->BSRR = (uint32_t)(GPIO_Pin))

Sets pin(s) high.

Note
Defined as macro to get maximum speed using register access
Parameters
GPIOxGPIOx PORT where you want to set pin high
GPIO_PinSelect GPIO pin(s). You can select more pins with | (OR) operator to set them high
Return values
None
#define TM_GPIO_SetPinLow (   GPIOx,
  GPIO_Pin 
)    ((GPIOx)->BSRR = (uint32_t)(((uint32_t)GPIO_Pin) << 16))

Sets pin(s) low.

Note
Defined as macro to get maximum speed using register access
Parameters
GPIOxGPIOx PORT where you want to set pin low
GPIO_PinSelect GPIO pin(s). You can select more pins with | (OR) operator to set them low
Return values
None
#define TM_GPIO_SetPinValue (   GPIOx,
  GPIO_Pin,
  val 
)    ((val) ? TM_GPIO_SetPinHigh(GPIOx, GPIO_Pin) : TM_GPIO_SetPinLow(GPIOx, GPIO_Pin))

Sets pin(s) value.

Note
Defined as macro to get maximum speed using register access
Parameters
GPIOxGPIOx PORT where you want to set pin value
GPIO_PinSelect GPIO pin(s). You can select more pins with | (OR) operator to set them value
valIf parameter is 0 then pin will be low, otherwise high
Return values
None
#define TM_GPIO_SetPortValue (   GPIOx,
  value 
)    ((GPIOx)->ODR = (value))

Sets value to entire GPIO PORT.

Note
Defined as macro to get maximum speed using register access
Parameters
GPIOxGPIOx PORT where you want to set value
valueValue for GPIO OUTPUT data
Return values
None
#define TM_GPIO_TogglePinValue (   GPIOx,
  GPIO_Pin 
)    ((GPIOx)->ODR ^= (GPIO_Pin))

Toggles pin(s)

Note
Defined as macro to get maximum speed using register access
Parameters
GPIOxGPIOx PORT where you want to toggle pin value
GPIO_PinSelect GPIO pin(s). You can select more pins with | (OR) operator to toggle them all at a time
Return values
None

Function Documentation

void TM_GPIO_DeInit ( GPIO_TypeDef *  GPIOx,
uint16_t  GPIO_Pin 
)

Deinitializes pin(s)

Note
Pins(s) will be set as analog mode to get low power consumption
Parameters
GPIOxGPIOx PORT where you want to set pin as input
GPIO_PinSelect GPIO pin(s). You can select more pins with | (OR) operator to set them as input
Return values
None
uint16_t TM_GPIO_GetFreePins ( GPIO_TypeDef *  GPIOx)

Gets bit separated pins which were not used at in library or were deinitialized.

Parameters
*GPIOxPointer to GPIOx peripheral where to check used GPIO pins
Return values
Bitvalues for free pins
uint16_t TM_GPIO_GetPinSource ( uint16_t  GPIO_Pin)

Gets pin source from desired GPIO pin.

Note
Meant for private use, unless you know what are you doing
Parameters
GPIO_PinGPIO pin for calculating port source
Return values
Calculatedpin source for GPIO pin
uint16_t TM_GPIO_GetPortSource ( GPIO_TypeDef *  GPIOx)

Gets port source from desired GPIOx PORT.

Note
Meant for private use, unless you know what are you doing
Parameters
GPIOxGPIO PORT for calculating port source
Return values
Calculatedport source for GPIO
uint16_t TM_GPIO_GetUsedPins ( GPIO_TypeDef *  GPIOx)

Gets bit separated pins which were used at least once in library and were not deinitialized.

Parameters
*GPIOxPointer to GPIOx peripheral where to check used GPIO pins
Return values
Bitvalues for used pins
void TM_GPIO_Init ( GPIO_TypeDef *  GPIOx,
uint16_t  GPIO_Pin,
TM_GPIO_Mode_t  GPIO_Mode,
TM_GPIO_OType_t  GPIO_OType,
TM_GPIO_PuPd_t  GPIO_PuPd,
TM_GPIO_Speed_t  GPIO_Speed 
)

Initializes GPIO pins(s)

Note
This function also enables clock for GPIO port
Parameters
GPIOxPointer to GPIOx port you will use for initialization
GPIO_PinGPIO pin(s) you will use for initialization
GPIO_ModeSelect GPIO mode. This parameter can be a value of TM_GPIO_Mode_t enumeration
GPIO_OTypeSelect GPIO Output type. This parameter can be a value of TM_GPIO_OType_t enumeration
GPIO_PuPdSelect GPIO pull resistor. This parameter can be a value of TM_GPIO_PuPd_t enumeration
GPIO_SpeedSelect GPIO speed. This parameter can be a value of TM_GPIO_Speed_t enumeration
Return values
None
void TM_GPIO_InitAlternate ( GPIO_TypeDef *  GPIOx,
uint16_t  GPIO_Pin,
TM_GPIO_OType_t  GPIO_OType,
TM_GPIO_PuPd_t  GPIO_PuPd,
TM_GPIO_Speed_t  GPIO_Speed,
uint8_t  Alternate 
)

Initializes GPIO pins(s) as alternate function.

Note
This function also enables clock for GPIO port
Parameters
GPIOxPointer to GPIOx port you will use for initialization
GPIO_PinGPIO pin(s) you will use for initialization
GPIO_OTypeSelect GPIO Output type. This parameter can be a value of TM_GPIO_OType_t enumeration
GPIO_PuPdSelect GPIO pull resistor. This parameter can be a value of TM_GPIO_PuPd_t enumeration
GPIO_SpeedSelect GPIO speed. This parameter can be a value of TM_GPIO_Speed_t enumeration
AlternateAlternate function you will use
Return values
None
void TM_GPIO_Lock ( GPIO_TypeDef *  GPIOx,
uint16_t  GPIO_Pin 
)

Locks GPIOx register for future changes.

Note
You are not able to config GPIO registers until new MCU reset occurs
Parameters
*GPIOxGPIOx PORT where you want to lock config registers
GPIO_PinGPIO pin(s) where you want to lock config registers
Return values
None
void TM_GPIO_SetPinAsAlternate ( GPIO_TypeDef *  GPIOx,
uint16_t  GPIO_Pin 
)

Sets pin(s) as alternate function.

Note
For proper alternate function, you should first init pin using TM_GPIO_InitAlternate() function. This functions is only used for changing GPIO mode
Parameters
GPIOxGPIOx PORT where you want to set pin as alternate
GPIO_PinSelect GPIO pin(s). You can select more pins with | (OR) operator to set them as alternate
Return values
None
void TM_GPIO_SetPinAsAnalog ( GPIO_TypeDef *  GPIOx,
uint16_t  GPIO_Pin 
)

Sets pin(s) as analog.

Note
Pins HAVE to be initialized first using TM_GPIO_Init() or TM_GPIO_InitAlternate() function
This is just an option for fast analog mode
Parameters
GPIOxGPIOx PORT where you want to set pin as analog
GPIO_PinSelect GPIO pin(s). You can select more pins with | (OR) operator to set them as analog
Return values
None
void TM_GPIO_SetPinAsInput ( GPIO_TypeDef *  GPIOx,
uint16_t  GPIO_Pin 
)

Sets pin(s) as input.

Note
Pins HAVE to be initialized first using TM_GPIO_Init() or TM_GPIO_InitAlternate() function
This is just an option for fast input mode
Parameters
GPIOxGPIOx PORT where you want to set pin as input
GPIO_PinSelect GPIO pin(s). You can select more pins with | (OR) operator to set them as input
Return values
None
void TM_GPIO_SetPinAsOutput ( GPIO_TypeDef *  GPIOx,
uint16_t  GPIO_Pin 
)

Sets pin(s) as output.

Note
Pins HAVE to be initialized first using TM_GPIO_Init() or TM_GPIO_InitAlternate() function
This is just an option for fast output mode
Parameters
GPIOxGPIOx PORT where you want to set pin as output
GPIO_PinSelect GPIO pin(s). You can select more pins with | (OR) operator to set them as output
Return values
None
void TM_GPIO_SetPullResistor ( GPIO_TypeDef *  GPIOx,
uint16_t  GPIO_Pin,
TM_GPIO_PuPd_t  GPIO_PuPd 
)

Sets pull resistor settings to GPIO pin(s)

Note
Pins HAVE to be initialized first using TM_GPIO_Init() or TM_GPIO_InitAlternate() function
Parameters
*GPIOxGPIOx PORT where you want to select pull resistor
GPIO_PinSelect GPIO pin(s). You can select more pins with | (OR) operator to set them as output
GPIO_PuPdPull resistor option. This parameter can be a value of TM_GPIO_PuPd_t enumeration
Return values
None