diff --git a/configs/xmc4500-relax/src/xmc4500-relax.h b/configs/xmc4500-relax/src/xmc4500-relax.h index 7934462b70..156d6f8c17 100644 --- a/configs/xmc4500-relax/src/xmc4500-relax.h +++ b/configs/xmc4500-relax/src/xmc4500-relax.h @@ -42,6 +42,8 @@ #include +#include "xmc4_gpio.h" + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -50,18 +52,30 @@ * * The XMC4500 Relax Lite v1 board has two LEDs: * - * LED1 P1.1 High output illuminates - * LED2 P1.0 High output illuminates + * LED1 P1.1, Pad type A1+, High output illuminates + * LED2 P1.0, Pad type A1+ High output illuminates */ +#define GPIO_LED1 (GPIO_OUTPUT | GPIO_OUTPUT_PUSHPULL | \ + GPIO_PADA1P_STRONGSOFT | GPIO_PINCTRL_SOFTWARE | \ + GPIO_OUTPUT_CLEAR | GPIO_PORT1 | GPIO_PIN1) +#define GPIO_LED2 (GPIO_OUTPUT | GPIO_OUTPUT_PUSHPULL | \ + GPIO_PADA1P_STRONGSOFT | GPIO_PINCTRL_SOFTWARE | \ + GPIO_OUTPUT_CLEAR | GPIO_PORT1 | GPIO_PIN0) + /* BUTTONS * * The XMC4500 Relax Lite v1 board has two buttons: * - * BUTTON1 P1.14 Low input sensed when button pressed - * BUTTON2 P1.15 Low input sensed when button pressed + * BUTTON1 P1.14, Pad type A2, Low input sensed when button pressed + * BUTTON2 P1.15, Pad type A2, Low input sensed when button pressed */ +#define GPIO_BUTTON1 (GPIO_INPUT | GPIO_PINCTRL_SOFTWARE | \ + GPIO_PORT1 | GPIO_PIN14) +#define GPIO_BUTTON2 (GPIO_INPUT | GPIO_PINCTRL_SOFTWARE | \ + GPIO_PORT1 | GPIO_PIN15) + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/configs/xmc4500-relax/src/xmc4_autoleds.c b/configs/xmc4500-relax/src/xmc4_autoleds.c index 7fd88f7866..694007c5e5 100644 --- a/configs/xmc4500-relax/src/xmc4_autoleds.c +++ b/configs/xmc4500-relax/src/xmc4_autoleds.c @@ -33,6 +33,30 @@ * ****************************************************************************/ +/* The XMC4500 Relax Lite v1 board has two LEDs: + * + * LED1 P1.1 High output illuminates + * LED2 P1.0 High output illuminates + * + * These LEDs are not used by the board port unless CONFIG_ARCH_LEDS is + * defined. In that case, the usage by the board port is defined in + * include/board.h and src/sam_autoleds.c. The LEDs are used to encode + * OS-related events as follows: + * + * SYMBOL Meaning LED state + * LED2 LED1 + * --------------------- -------------------------- ------ ------ */ + +#define LED_STARTED 0 /* NuttX has been started OFF OFF */ +#define LED_HEAPALLOCATE 0 /* Heap has been allocated OFF OFF */ +#define LED_IRQSENABLED 0 /* Interrupts enabled OFF OFF */ +#define LED_STACKCREATED 1 /* Idle stack created ON OFF */ +#define LED_INIRQ 2 /* In an interrupt No change */ +#define LED_SIGNAL 2 /* In a signal handler No change */ +#define LED_ASSERTION 2 /* An assertion failed No change */ +#define LED_PANIC 3 /* The system has crashed N/C Blinking */ +#undef LED_IDLE /* MCU is is sleep mode Not used */ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -42,10 +66,93 @@ #include #include +#include "xmc4_gpio.h" #include "xmc4500-relax.h" #ifdef CONFIG_ARCH_LEDS +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static void board_led1_on(int led) +{ + bool ledon = false; + + switch (led) + { + case 0: /* LED1=OFF */ + break; + + case 1: /* LED1=ON */ + ledon = true; + break; + + case 2: /* LED1=N/C */ + case 3: /* LED1=N/C */ + default: + return; + } + + xmc4_gpio_write(GPIO_LED1, ledon); +} + +static void board_led2_on(int led) +{ + bool ledon = false; + + switch (led) + { + case 0: /* LED2=OFF */ + case 1: /* LED2=OFF */ + break; + + case 3: /* LED2=ON */ + ledon = true; + break; + + case 2: /* LED2=N/C */ + default: + return; + } + + xmc4_gpio_write(GPIO_LED2, ledon); +} + +void board_led1_off(int led) +{ + switch (led) + { + case 0: /* LED1=OFF */ + case 1: /* LED1=OFF */ + break; + + case 2: /* LED1=N/C */ + case 3: /* LED1=N/C */ + default: + return; + } + + xmc4_gpio_write(GPIO_LED1, false); +} + +void board_led2_off(int led) +{ + switch (led) + { + case 0: /* LED2=OFF */ + case 1: /* LED2=OFF */ + case 3: /* LED2=OFF */ + break; + + case 2: /* LED2=N/C */ + default: + return; + } + + xmc4_gpio_write(GPIO_LED2, false); +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -56,7 +163,10 @@ void board_autoled_initialize(void) { -#warning Missing logic + /* Configure LED1-2 GPIOs for output */ + + (void)xmc4_gpio_config(GPIO_LED1); + (void)xmc4_gpio_config(GPIO_LED2); } /**************************************************************************** @@ -65,7 +175,8 @@ void board_autoled_initialize(void) void board_autoled_on(int led) { -#warning Missing logic + board_led1_on(led); + board_led2_on(led); } /**************************************************************************** @@ -74,7 +185,8 @@ void board_autoled_on(int led) void board_autoled_off(int led) { -#warning Missing logic + board_led1_off(led); + board_led2_off(led); } #endif /* CONFIG_ARCH_LEDS */ diff --git a/configs/xmc4500-relax/src/xmc4_userleds.c b/configs/xmc4500-relax/src/xmc4_userleds.c index 8bb69336f7..4d9d0cb090 100644 --- a/configs/xmc4500-relax/src/xmc4_userleds.c +++ b/configs/xmc4500-relax/src/xmc4_userleds.c @@ -41,6 +41,8 @@ #include #include + +#include "xmc4_gpio.h" #include "xmc4500-relax.h" /**************************************************************************** @@ -53,7 +55,10 @@ void board_userled_initialize(void) { -#warning Missing logic + /* Configure LED1-2 GPIOs for output */ + + (void)xmc4_gpio_config(GPIO_LED1); + (void)xmc4_gpio_config(GPIO_LED2); } /**************************************************************************** @@ -62,7 +67,22 @@ void board_userled_initialize(void) void board_userled(int led, bool ledon) { -#warning Missing logic + gpioconfig_t ledcfg; + + if (led == BOARD_LED1) + { + ledcfg = GPIO_LED1; + } + else if (led == BOARD_LED2) + { + ledcfg = GPIO_LED2; + } + else + { + return; + } + + xmc4_gpio_write(ledcfg, ledon); } /**************************************************************************** @@ -71,5 +91,11 @@ void board_userled(int led, bool ledon) void board_userled_all(uint8_t ledset) { -#warning Missing logic + bool ledon; + + ledon = ((ledset & BOARD_LED1_BIT) != 0); + xmc4_gpio_write(GPIO_LED1, ledon); + + ledon = ((ledset & BOARD_LED2_BIT) != 0); + xmc4_gpio_write(GPIO_LED2, ledon); }