HAL_GPIO_WritePin do extra work when pin state is known in avance
It would be helpfull to have couple of function in addition to
HAL_GPIO_WritePin( GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState )
for cases when pin state is known in advance (not result of calculation in runtime)
void HAL_GPIO_SetPin (GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
{
assert_param(IS_GPIO_PIN(GPIO_Pin));
GPIOx->BSRR = (uint32_t) GPIO_Pin;
}
void HAL_GPIO_ClearPin (GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
{
assert_param(IS_GPIO_PIN(GPIO_Pin));
GPIOx->BRR = (uint32_t) GPIO_Pin;
}Props:
1 One parameter less
2 One assert less
3 No condition check
4 Less typing
5 Less work in runtime
6 Better search. One can serach SetPin or ClearPin instead of all HAL_GPIO_WritePin at first and then see pin state value in common list.
7 Sense of command in one place instead of combination of command_name + parameter_value
8 More uniform with HAL_GPIO_TogglePin. Set, Clear, Toggle have the same signature
Edited to apply source code formatting - please see How to insert source code for future reference.
