diff --git a/configs/teensy-3.x/include/board.h b/configs/teensy-3.x/include/board.h index 785ccf3c60..1d1d250227 100644 --- a/configs/teensy-3.x/include/board.h +++ b/configs/teensy-3.x/include/board.h @@ -42,8 +42,10 @@ ************************************************************************************/ #include + #ifndef __ASSEMBLY__ # include +# include #endif /************************************************************************************ @@ -135,12 +137,12 @@ * high will illuminate the LED. */ -/* LED index values for use with sam_setled() */ +/* LED index values for use with kinetis_setled() */ #define BOARD_LED 0 #define BOARD_NLEDS 1 -/* LED bits for use with sam_setleds() */ +/* LED bits for use with kinetis_setleds() */ #define BOARD_LED_BIT (1 << BOARD_LED) @@ -229,6 +231,22 @@ extern "C" void kinetis_boardinitialize(void); +/************************************************************************************ + * Name: kinetis_ledinit, kinetis_setled, and kinetis_setleds + * + * Description: + * If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board LED. If + * CONFIG_ARCH_LEDS is not defined, then the following interfaces are available to + * control the LEDs from user applications. + * + ************************************************************************************/ + +#ifndef CONFIG_ARCH_LEDS +void kinetis_ledinit(void); +void kinetis_setled(int led, bool ledon); +void kinetis_setleds(uint8_t ledset); +#endif + #undef EXTERN #if defined(__cplusplus) } diff --git a/configs/teensy-3.x/src/Makefile b/configs/teensy-3.x/src/Makefile index 99b549a8f9..4c7cee11ac 100644 --- a/configs/teensy-3.x/src/Makefile +++ b/configs/teensy-3.x/src/Makefile @@ -44,6 +44,8 @@ CSRCS = k20_boot.c k20_spi.c ifeq ($(CONFIG_ARCH_LEDS),y) CSRCS += k20_autoleds.c +else +CSRCS += k20_userleds.c endif ifeq ($(CONFIG_NSH_ARCHINIT),y) diff --git a/configs/teensy-3.x/src/k20_autoleds.c b/configs/teensy-3.x/src/k20_autoleds.c index 2fb385982f..2248ce7a01 100644 --- a/configs/teensy-3.x/src/k20_autoleds.c +++ b/configs/teensy-3.x/src/k20_autoleds.c @@ -46,22 +46,12 @@ #include "kinetis_internal.h" #include "teensy-3x.h" +#ifdef CONFIG_ARCH_LEDS + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -/* CONFIG_DEBUG_LEDS enables debug output from this file (needs CONFIG_DEBUG - * with CONFIG_DEBUG_VERBOSE too) - */ - -#ifdef CONFIG_DEBUG_LEDS -# define leddbg lldbg -# define ledvdbg llvdbg -#else -# define leddbg(x...) -# define ledvdbg(x...) -#endif - /**************************************************************************** * Private Data ****************************************************************************/ @@ -82,7 +72,6 @@ * ****************************************************************************/ -#ifdef CONFIG_ARCH_LEDS void board_led_initialize(void) { kinetis_pinconfig(GPIO_LED); diff --git a/configs/teensy-3.x/src/k20_userleds.c b/configs/teensy-3.x/src/k20_userleds.c new file mode 100644 index 0000000000..64b0cc2515 --- /dev/null +++ b/configs/teensy-3.x/src/k20_userleds.c @@ -0,0 +1,88 @@ +/**************************************************************************** + * configs/teensy-3.x/src/kinetis_userleds.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include "kinetis_internal.h" +#include "teensy-3x.h" + +#ifndef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: kinetis_ledinit + ****************************************************************************/ + +void kinetis_ledinit(void) +{ + kinetis_pinconfig(GPIO_LED); +} + +/**************************************************************************** + * Name: kinetis_setled + ****************************************************************************/ + +void kinetis_setled(int led, bool ledon) +{ + if (led == BOARD_LED) + { + kinetis_pinconfig(GPIO_LED); + } +} + +/**************************************************************************** + * Name: kinetis_setleds + ****************************************************************************/ + +void kinetis_setleds(uint8_t ledset) +{ + kinetis_pinconfig((ledset & BOARD_LED_BIT) != 0); +} + +#endif /* !CONFIG_ARCH_LEDS */