From e9b604914c76d86cc2e4bb86bc5b8051e127f5c1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 3 Aug 2016 12:45:16 -0600 Subject: [PATCH] config/sim: Add logic to set the simulated I/O expander for testing with apps/examples/gpio --- configs/sim/src/Makefile | 5 ++ configs/sim/src/sim_gpio.c | 4 +- configs/sim/src/sim_ioexpander.c | 89 ++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 configs/sim/src/sim_ioexpander.c diff --git a/configs/sim/src/Makefile b/configs/sim/src/Makefile index 63fcbca040..e56c82ae36 100644 --- a/configs/sim/src/Makefile +++ b/configs/sim/src/Makefile @@ -65,7 +65,12 @@ endif endif ifeq ($(CONFIG_EXAMPLES_GPIO),y) +ifeq ($(CONFIG_GPIO_LOWER_HALF),y) + CSRCS += sim_ioexpander.c +else CSRCS += sim_gpio.c endif +endif + include $(TOPDIR)/configs/Board.mk diff --git a/configs/sim/src/sim_gpio.c b/configs/sim/src/sim_gpio.c index 6dba310bba..bd9c499457 100644 --- a/configs/sim/src/sim_gpio.c +++ b/configs/sim/src/sim_gpio.c @@ -49,7 +49,7 @@ #include "sim.h" -#ifdef CONFIG_EXAMPLES_GPIO +#if defined(CONFIG_EXAMPLES_GPIO) && !defined(CONFIG_GPIO_LOWER_HALF) /**************************************************************************** * Private Types @@ -231,4 +231,4 @@ int sim_gpio_initialize(void) (void)gpio_pin_register(&g_gpint.simgpio.gpio, 2); return 0; } -#endif /* CONFIG_EXAMPLES_GPIO */ +#endif /* CONFIG_EXAMPLES_GPIO && !CONFIG_GPIO_LOWER_HALF */ diff --git a/configs/sim/src/sim_ioexpander.c b/configs/sim/src/sim_ioexpander.c new file mode 100644 index 0000000000..01cdb77ddf --- /dev/null +++ b/configs/sim/src/sim_ioexpander.c @@ -0,0 +1,89 @@ +/**************************************************************************** + * configs/sim/src/sim_ioexpander.c + * + * Copyright (C) 2016 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 +#include + +#include "up_internal.h" +#include "sim.h" + +#if defined(CONFIG_EXAMPLES_GPIO) && defined(CONFIG_GPIO_LOWER_HALF) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sim_gpio_initialize + * + * Description: + * Initialize simulated GPIO expander for use with /apps/examples/gpio + * + ****************************************************************************/ + +int sim_gpio_initialize(void) +{ + /* Get an instance of the simulated I/O expander */ + + FAR struct ioexpander_dev_s *ioe = sim_ioexpander_initialize(); + if (ioe == NULL) + { + gpioerr("ERROR: sim_ioexpander_initialize failed\n"); + return -ENOMEM; + } + + /* Register three pin drivers */ + + (void)IOEXP_SETDIRECTION(ioe, 0, IOEXPANDER_DIRECTION_IN); + (void)gpio_lower_half(ioe, 0, GPIO_INPUT_PIN, 0); + + (void)IOEXP_SETDIRECTION(ioe, 1, IOEXPANDER_DIRECTION_OUT); + (void)gpio_lower_half(ioe, 1, GPIO_OUTPUT_PIN, 1); + + (void)IOEXP_SETDIRECTION(ioe, 2, IOEXPANDER_DIRECTION_IN); + (void)gpio_lower_half(ioe, 2, GPIO_INTERRUPT_PIN, 2); + + return 0; +} +#endif /* CONFIG_EXAMPLES_GPIO && CONFIG_GPIO_LOWER_HALF */