tm4c123g-launchpad: Add board button interrupt logic. From Calvin Maguranis

This commit is contained in:
Gregory Nutt 2015-02-20 12:32:39 -06:00
parent abb6e41550
commit 9db37ff67d
2 changed files with 72 additions and 44 deletions

View File

@ -1,7 +1,7 @@
/************************************************************************************ /************************************************************************************
* configs/tm4c123g-launchpad/src/tm4c123g-launchpad.h * configs/tm4c123g-launchpad/src/tm4c123g-launchpad.h
* *
* Copyright (C) 2014 Gregory Nutt. All rights reserved. * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -42,6 +42,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <nuttx/compiler.h> #include <nuttx/compiler.h>
#include <nuttx/irq.h>
#include "chip.h" #include "chip.h"
#include "tiva_gpio.h" #include "tiva_gpio.h"
@ -163,8 +164,8 @@
/* The TM4C123G LaunchPad has a two buttons: /* The TM4C123G LaunchPad has a two buttons:
* *
* BOARD_SW1 -- Connected to PF4 * BOARD_SW1 -- Connected to PF0
* BOARD_SW2 -- Connected to PF0 * BOARD_SW2 -- Connected to PF4
*/ */
#define GPIO_SW1 (GPIO_FUNC_INTERRUPT | GPIO_INT_BOTHEDGES | \ #define GPIO_SW1 (GPIO_FUNC_INTERRUPT | GPIO_INT_BOTHEDGES | \
@ -263,4 +264,3 @@ int adc_devinit(void);
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
#endif /* __CONFIGS_TM4C123G_LAUNCHPAD_TM4C123G_LAUNCHPAD_H */ #endif /* __CONFIGS_TM4C123G_LAUNCHPAD_TM4C123G_LAUNCHPAD_H */

View File

@ -39,10 +39,11 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <debug.h> #include <nuttx/arch.h>
#include <arch/irq.h>
#include <arch/board/board.h> #include <arch/board/board.h>
#include "tiva_gpio.h"
#include "tm4c123g-launchpad.h" #include "tm4c123g-launchpad.h"
#ifdef CONFIG_ARCH_BUTTONS #ifdef CONFIG_ARCH_BUTTONS
@ -55,6 +56,10 @@
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_ARCH_IRQBUTTONS
static xcpt_t g_irquser;
#endif
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
@ -80,9 +85,7 @@ void board_button_initialize(void)
* and see table 10-10 in datasheet for pins with special considerations. * and see table 10-10 in datasheet for pins with special considerations.
*/ */
modifyreg32(TIVA_GPIOF_LOCK, 0, GPIO_LOCK_UNLOCK); tiva_gpio_lockport(GPIO_SW2, false);
modifyreg32(TIVA_GPIOF_CR, 0, 0x01);
modifyreg32(TIVA_GPIOF_LOCK, GPIO_LOCK_UNLOCK, GPIO_LOCK_LOCKED);
/* Configure the GPIO pins as inputs. NOTE that EXTI interrupts are /* Configure the GPIO pins as inputs. NOTE that EXTI interrupts are
* configured for some pins but NOT used in this file * configured for some pins but NOT used in this file
@ -90,10 +93,23 @@ void board_button_initialize(void)
tiva_configgpio(GPIO_SW1); tiva_configgpio(GPIO_SW1);
tiva_configgpio(GPIO_SW2); tiva_configgpio(GPIO_SW2);
/* Configure GPIO interrupts */
#ifdef CONFIG_ARCH_IRQBUTTONS
(void)tiva_gpioirqinitialize();
#endif
} }
/**************************************************************************** /****************************************************************************
* Name: board_buttons * Name: board_buttons
*
* Description:
* After board_button_initialize() has been called, board_buttons() may be
* called to collect the state of all buttons. board_buttons() returns an
* 8-bit bit set with each bit associated with a button. See the BUTTON*
* definitions above for the meaning of each bit in the returned value.
*
****************************************************************************/ ****************************************************************************/
uint8_t board_buttons(void) uint8_t board_buttons(void)
@ -117,51 +133,63 @@ uint8_t board_buttons(void)
return ret; return ret;
} }
/***************************************************************************** /****************************************************************************
* Button support. * Name: board_button_irq
* *
* Description: * Description:
* board_button_initialize() must be called to initialize button resources. * This function may be called to register an interrupt handler that will
* After that, board_buttons() may be called to collect the current state * be called when a button is depressed or released. The ID value is one
* of all buttons or board_button_irq() may be called to register button * of the BUTTON* definitions provided above. The previous interrupt
* interrupt handlers. * handler address is returned (so that it may restored, if so desired).
*
* After board_button_initialize() has been called, board_buttons() may be
* called to collect the state of all buttons. board_buttons() returns an
* 8-bit bit set with each bit associated with a button. See the
* BUTTON_*_BIT and JOYSTICK_*_BIT definitions in board.h for the meaning
* of each bit.
*
* board_button_irq() may be called to register an interrupt handler that
* will be called when a button is depressed or released. The ID value is
* a button enumeration value that uniquely identifies a button resource.
* See the BUTTON_* and JOYSTICK_* definitions in board.h for the meaning
* of enumeration values. The previous interrupt handler address is
* returned (so that it may restored, if so desired).
* *
****************************************************************************/ ****************************************************************************/
#if 0 # ifdef CONFIG_ARCH_IRQBUTTONS
#ifdef CONFIG_ARCH_IRQBUTTONS
xcpt_t board_button_irq(int id, xcpt_t irqhandler) xcpt_t board_button_irq(int id, xcpt_t irqhandler)
{ {
uint16_t gpio; xcpt_t oldhandler = NULL;
if (id == BUTTON_KEY1) if (id == BUTTON_SW1 ||
id == BUTTON_SW2)
{ {
gpio = GPIO_SW1; irqstate_t flags;
}
else if (id == BUTTON_KEY2) /* Disable interrupts until we are done. This guarantees that the
{ * following operations are atomic.
gpio = GPIO_SW2; */
}
else flags = irqsave();
{
return NULL; /* Get the old button interrupt handler and save the new one */
oldhandler = g_irquser;
g_irquser = irqhandler;
/* Are we attaching or detaching? */
if (irqhandler != NULL)
{
/* Configure the interrupt */
(void)tiva_gpioirqattach(CONFIG_TIVA_GPIOF_IRQS, irqhandler);
tiva_gpioirqenable(CONFIG_TIVA_GPIOF_IRQS);
}
else
{
/* Disable and detach the interrupt */
tiva_gpioirqdisable(CONFIG_TIVA_GPIOF_IRQS);
(void)tiva_gpioirqattach(CONFIG_TIVA_GPIOF_IRQS, NULL);
}
/* Configure the interrupt */
irqrestore(flags);
} }
return stm32_gpiosetevent(gpio, true, true, true, irqhandler); /* Return the old button handler (so that it can be restored) */
return oldhandler;
} }
#endif # endif
#endif // 0
#endif /* CONFIG_ARCH_BUTTONS */ #endif /* CONFIG_ARCH_BUTTONS */