From d336bb29585b0fe8d531e61b878e7dc733093b4f Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 14 Nov 2011 14:45:30 +0000 Subject: [PATCH] Button test can now be built as an NSH command git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4091 42af7a65-404d-4744-a932-0658087f49c3 --- ChangeLog.txt | 5 ++- examples/buttons/Makefile | 16 +++++++-- examples/buttons/main.c | 68 ++++++++++++++++++++++++++++++++--- examples/touchscreen/Makefile | 2 +- 4 files changed, 83 insertions(+), 8 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index d8c796a67..b808df67a 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -127,6 +127,9 @@ 6.11 2011-11-12 Gregory Nutt - (No major changes from 6.10) + (No major changes from 6.10) 6.12 2011-xx-xx Gregory Nutt + + * apps/examples/buttons: The button test can now be executed as an NSH + built in command. diff --git a/examples/buttons/Makefile b/examples/buttons/Makefile index 89db5cec1..9c0587199 100644 --- a/examples/buttons/Makefile +++ b/examples/buttons/Makefile @@ -56,12 +56,18 @@ endif ROOTDEPPATH = --dep-path . +# Buttons built-in application info + +APPNAME = buttons +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = 2048 + # Common build VPATH = all: .built -.PHONY: clean depend distclean +.PHONY: context clean depend distclean $(AOBJS): %$(OBJEXT): %.S $(call ASSEMBLE, $<, $@) @@ -75,7 +81,13 @@ $(COBJS): %$(OBJEXT): %.c done ; ) @touch .built -context: +.context: +ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) + $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) + @touch $@ +endif + +context: .context .depend: Makefile $(SRCS) @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep diff --git a/examples/buttons/main.c b/examples/buttons/main.c index 43999bc1a..b0d06e48a 100644 --- a/examples/buttons/main.c +++ b/examples/buttons/main.c @@ -48,6 +48,7 @@ #include #include +#include #include #include @@ -129,6 +130,16 @@ #define NUM_BUTTONS (MAX_BUTTON - MIN_BUTTON + 1) #define BUTTON_INDEX(b) ((b)-MIN_BUTTON) +/* Is this being built as an NSH built-in application? */ + +#ifdef CONFIG_NSH_BUILTIN_APPS +# define MAIN_NAME buttons_main +# define MAIN_STRING "buttons_main: " +#else +# define MAIN_NAME user_start +# define MAIN_STRING "user_start: " +#endif + /**************************************************************************** * Private Types ****************************************************************************/ @@ -254,8 +265,14 @@ static const struct button_info_s g_buttoninfo[NUM_BUTTONS] = static uint8_t g_oldset; +/* Used to limit the number of button presses */ + +#ifdef CONFIG_NSH_BUILTIN_APPS +static volatile long g_nbuttons; +#endif + /**************************************************************************** - * Public Functions + * Private Functions ****************************************************************************/ static void show_buttons(uint8_t oldset, uint8_t newset) @@ -263,6 +280,17 @@ static void show_buttons(uint8_t oldset, uint8_t newset) uint8_t chgset = oldset ^ newset; int i; + /* Update the count of button presses shown */ + +#ifdef CONFIG_NSH_BUILTIN_APPS + if ((chgset & newset) != 0) + { + g_nbuttons++; + } +#endif + + /* Show each button state change */ + for (i = MIN_BUTTON; i <= MAX_BUTTON; i++) { uint8_t mask = (1 << i); @@ -295,7 +323,7 @@ static void button_handler(int id, int irq) { uint8_t newset = up_buttons(); - lib_lowprintf("IRQ:%d Button %d:%s IRQ:%d SET:%02x:\n", + lib_lowprintf("IRQ:%d Button %d:%s SET:%02x:\n", irq, id, g_buttoninfo[BUTTON_INDEX(id)].name, newset); show_buttons(g_oldset, newset); g_oldset = newset; @@ -367,15 +395,33 @@ static int button7_handler(int irq, FAR void *context) #endif /* CONFIG_ARCH_IRQBUTTONS */ /**************************************************************************** - * user_start + * Public Functions ****************************************************************************/ -int user_start(int argc, char *argv[]) +/**************************************************************************** + * user_start/buttons_main + ****************************************************************************/ + +int MAIN_NAME(int argc, char *argv[]) { uint8_t newset; irqstate_t flags; int i; + /* If this example is configured as an NX add-on, then limit the number of + * samples that we collect before returning. Otherwise, we never return + */ + +#ifdef CONFIG_NSH_BUILTIN_APPS + long maxbuttons = 1; + g_nbuttons = 0; + if (argc > 1) + { + maxbuttons = strtol(argv[1], NULL, 10); + } + lib_lowprintf("maxbuttons: %d\n", maxbuttons); +#endif + /* Register to recieve button interrupts */ #ifdef CONFIG_ARCH_IRQBUTTONS @@ -408,7 +454,11 @@ int user_start(int argc, char *argv[]) /* Poll button state */ g_oldset = up_buttons(); +#ifdef CONFIG_NSH_BUILTIN_APPS + while (g_nbuttons < maxbuttons) +#else for (;;) +#endif { /* Get the set of pressed and release buttons. */ @@ -440,6 +490,16 @@ int user_start(int argc, char *argv[]) usleep(150000); /* 150 Milliseconds */ } + + /* Un-register button handlers */ + +#if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_NSH_BUILTIN_APPS) + for (i = CONFIG_EXAMPLE_IRQBUTTONS_MIN; i <= CONFIG_EXAMPLE_IRQBUTTONS_MAX; i++) + { + (void)up_irqbutton(i, NULL); + } +#endif + return 0; } diff --git a/examples/touchscreen/Makefile b/examples/touchscreen/Makefile index 264a54916..e53a52cf9 100644 --- a/examples/touchscreen/Makefile +++ b/examples/touchscreen/Makefile @@ -56,7 +56,7 @@ endif ROOTDEPPATH = --dep-path . -# NXHELLO built-in application info +# Touchscreen built-in application info APPNAME = tc PRIORITY = SCHED_PRIORITY_DEFAULT