From 1695b11c0e5b12ed930b00f791fe397e4362eeb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B9=94=E4=BF=8A=E8=B6=85?= <958092084@qq.com> Date: Tue, 14 Dec 2021 21:46:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0gpio=E7=BF=BB=E8=BD=AC?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libraries/drivers/inc/at32f403a_407_gpio.h | 1 + libraries/drivers/src/at32f403a_407_gpio.c | 34 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/libraries/drivers/inc/at32f403a_407_gpio.h b/libraries/drivers/inc/at32f403a_407_gpio.h index 01d460c9..447f30a8 100644 --- a/libraries/drivers/inc/at32f403a_407_gpio.h +++ b/libraries/drivers/inc/at32f403a_407_gpio.h @@ -913,6 +913,7 @@ flag_status gpio_output_data_bit_read(gpio_type *gpio_x, uint16_t pins); uint16_t gpio_output_data_read(gpio_type *gpio_x); void gpio_bits_set(gpio_type *gpio_x, uint16_t pins); void gpio_bits_reset(gpio_type *gpio_x, uint16_t pins); +void gpio_bits_toggle(gpio_type *gpio_x, uint16_t pins); void gpio_bits_write(gpio_type *gpio_x, uint16_t pins, confirm_state bit_state); void gpio_port_wirte(gpio_type *gpio_x, uint16_t port_value); void gpio_pin_wp_config(gpio_type *gpio_x, uint16_t pins); diff --git a/libraries/drivers/src/at32f403a_407_gpio.c b/libraries/drivers/src/at32f403a_407_gpio.c index 5aca62fb..b8215820 100644 --- a/libraries/drivers/src/at32f403a_407_gpio.c +++ b/libraries/drivers/src/at32f403a_407_gpio.c @@ -343,6 +343,40 @@ void gpio_bits_reset(gpio_type *gpio_x, uint16_t pins) gpio_x->clr = pins; } +/** + * @brief toggle the selected data port bits. + * @param gpio_x: to select the gpio peripheral. + * this parameter can be one of the following values: + * GPIOA, GPIOB, GPIOC, GPIOD, GPIOE. + * @param pins: gpio pin number + * parameter can be any combination of gpio_pin_x, gpio_pin_x as following values: + * - GPIO_PINS_0 + * - GPIO_PINS_1 + * - GPIO_PINS_2 + * - GPIO_PINS_3 + * - GPIO_PINS_4 + * - GPIO_PINS_5 + * - GPIO_PINS_6 + * - GPIO_PINS_7 + * - GPIO_PINS_8 + * - GPIO_PINS_9 + * - GPIO_PINS_10 + * - GPIO_PINS_11 + * - GPIO_PINS_12 + * - GPIO_PINS_13 + * - GPIO_PINS_14 + * - GPIO_PINS_15 + * - GPIO_PINS_ALL + * @retval none + */ +void gpio_bits_toggle(gpio_type *gpio_x, uint16_t pins) +{ + uint32_t odt; + odt = gpio_x->odt; + gpio_x->scr = ((odt & pins) << 16) | (~odt & pins); +} + + /** * @brief set or clear the selected data port bit. * @param gpio_x: to select the gpio peripheral. -- Gitee