diff --git a/libraries/drivers/inc/at32f403a_407_gpio.h b/libraries/drivers/inc/at32f403a_407_gpio.h index 01d460c99517df996d75a21779946e37b1a3e61d..447f30a899c82197ab61cd1e60add3eda130ffb2 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 5aca62fbcbdc41bd0d28911a5b5290d62c4e43d8..b82158207ca12cf6de9b8c7d7beb41d5ab030109 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.