常规GPIO翻转切换输出,如果我们使用的是别人家的MCU,那么就是读改写的过程,比如下面这样子:- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] Toggle the specified GPIO pin.
- * @param GPIOx where x can be (A..F) to select the GPIO peripheral for STM32G0xx family
- * @param GPIO_Pin specifies the pin to be toggled.
- * This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
- * @retval None
- */
- void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
- {
- uint32_t odr;
- /* Check the parameters */
- assert_param(IS_GPIO_PIN(GPIO_Pin));
- /* get current Output Data Register value */
- odr = GPIOx->ODR;
- /* Set selected pins that were at low level, and reset ones that were high */
- GPIOx->BSRR = ((odr & GPIO_Pin) << GPIO_NUMBER) | (~odr & GPIO_Pin);
- }
但如果是MSPM0,那就是下面这个样子:
- __STATIC_INLINE void DL_GPIO_togglePins(GPIO_Regs* gpio, uint32_t pins)
- {
- gpio->DOUTTGL31_0 = pins;
- }
简简单单的一条寄存器操作搞定。因为GPIO的翻转专门有一个寄存器进行操作。
|