config/sim: Add logic to set the simulated I/O expander for testing with apps/examples/gpio
This commit is contained in:
parent
c11473657c
commit
e9b604914c
@ -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
|
||||
|
@ -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 */
|
||||
|
89
configs/sim/src/sim_ioexpander.c
Normal file
89
configs/sim/src/sim_ioexpander.c
Normal file
@ -0,0 +1,89 @@
|
||||
/****************************************************************************
|
||||
* configs/sim/src/sim_ioexpander.c
|
||||
*
|
||||
* Copyright (C) 2016 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 <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/ioexpander/gpio.h>
|
||||
#include <nuttx/ioexpander/ioexpander.h>
|
||||
|
||||
#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 */
|
Loading…
x
Reference in New Issue
Block a user