Teensy-3.1: Add user LED support

This commit is contained in:
Gregory Nutt 2015-06-10 17:19:26 -06:00
parent 63226728b6
commit de254f6ac3
5 changed files with 112 additions and 17 deletions

View File

@ -390,8 +390,6 @@
/* Global Pin Control High Register */
#define PORT_GPCHR_
#define PORT_GPCHR_GPWD_SHIFT (0) /* Bits 0-15: Global Pin Write Data */
#define PORT_GPCHR_GPWD_MASK (0xffff << PORT_GPCHR_GPWD_SHIFT)
# define PORT_GPCHR_GPWD(n) ((1 << (n)) << PORT_GPCHR_GPWD_SHIFT)

View File

@ -42,8 +42,10 @@
************************************************************************************/
#include <nuttx/config.h>
#ifndef __ASSEMBLY__
# include <stdint.h>
# include <stdbool.h>
#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)
}

View File

@ -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)

View File

@ -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);

View File

@ -0,0 +1,88 @@
/****************************************************************************
* configs/teensy-3.x/src/kinetis_userleds.c
*
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <nuttx/config.h>
#include <stdbool.h>
#include <debug.h>
#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 */