I'm moving from my EVK1104 to my custom PCB, and I'm having an odd LED/GPIO problem. The EVK1104 has 4 LEDs, my custom board has 3. I've copied and modified the EVK1104's led.c/h files, as well as made a custom header for my PCB. Everything else seems to be working fine, except one LED is backwards. LED2 appears to turn on when an "LED_Off(LED2)" command is issued, and the opposite for LED_On. Here's some of the relevant code:
In my custom PCB header:
/* LED Defines */ #define LED_COUNT 3 #define LED0_GPIO AVR32_PIN_PX41 #define LED1_GPIO AVR32_PIN_PX22 #define LED2_GPIO AVR32_PIN_PX20 #define LED_RED LED0 #define LED_GREEN LED1 #define LED_ORANGE LED2
In led.h:
/* Identifiers of LEDs to Use with LED Functions */ #define LED0 0x01 #define LED1 0x02 #define LED2 0x04
In led.c:
void LED_Off(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. Clr_bits(LED_State, leds); // While there are specified LEDs left to manage... while (leds) { // Select the next specified LED and turn it off. led_shift = 1 + ctz(leds); led_descriptor += led_shift; led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT]; led_gpio_port->ovrs = 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_On(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. Set_bits(LED_State, leds); // While there are specified LEDs left to manage... while (leds) { // Select the next specified LED and turn it on. led_shift = 1 + ctz(leds); led_descriptor += led_shift; led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT]; led_gpio_port->ovrc = 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; } }
I haven't changed anything in led.c, and I only removed LED3 in led.h. I did change the GPIO ports that are used for the LEDs, but that should be appropriately fixed in my custom header.
Any ideas?