void LED_Toggle(U32 leds) { // Use the LED descriptors to get the connections of a given LED to the MCU. tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1; volatile avr32_gpio_port_t *led_gpio_port; U8 led_shift; // Make sure only existing LEDs are specified. leds &= (1 << LED_COUNT) - 1; // Update the saved state of all LEDs with the requested changes. Tgl_bits(LED_State, leds); // While there are specified LEDs left to manage... while (leds) { // Select the next specified LED and toggle it. led_shift = 1 + ctz(leds); led_descriptor += led_shift; led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT]; led_gpio_port->ovrt = led_descriptor->GPIO.PIN_MASK; led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK; led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK; leds >>= led_shift; } }
void LED_Toggle(U32 leds) { tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1; volatile avr32_gpio_port_t *led_gpio_port; U8 led_shift; leds &= (1 << LED_COUNT) - 1; Tgl_bits(LED_State, leds); while (leds) { led_shift = 1 + ctz(leds); led_descriptor += led_shift; led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT]; led_gpio_port->ovrt = led_descriptor->GPIO.PIN_MASK; led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK; led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK; leds >>= led_shift; } }