mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 05:16:47 +08:00
Added initialization code and Kconfig entries to set up the LIS3DSH accelerometer
driver on STM32F4Discovery rev. C boards and attach the associated interrupt callback. Added the argument parameter (FAR void *arg) to the interrupt handler provided by the LIS3DSH driver to fit the definition for ISRs in xcpt_t. Changed the check for working queue availability in lis3dsh interrupt handler to use work_available() and not crash in case of an overrun.
This commit is contained in:
@@ -27,6 +27,18 @@ config STM32F4DISCO_QETIMER
|
|||||||
default 2
|
default 2
|
||||||
depends on QENCODER
|
depends on QENCODER
|
||||||
|
|
||||||
|
config STM32F4DISCO_LIS3DSH
|
||||||
|
bool "Enable LIS3DSH driver for the IMU on STM32F4Discovery (rev. MB997C)"
|
||||||
|
default n
|
||||||
|
depends on SPI
|
||||||
|
depends on LIS3DSH
|
||||||
|
default n
|
||||||
|
---help---
|
||||||
|
Select to create a LIS3DSH driver instance for the builtin accelerometer of
|
||||||
|
STM32F4Discovery. Provides /dev/acc0 device file.
|
||||||
|
Also see apps/examples/lis3dsh_reader.
|
||||||
|
The LIS3DSH is available on the STM32F4Discovery rev. MB997C (see the board manual).
|
||||||
|
|
||||||
config PM_BUTTONS
|
config PM_BUTTONS
|
||||||
bool "PM button support"
|
bool "PM button support"
|
||||||
default n
|
default n
|
||||||
|
|||||||
@@ -72,6 +72,10 @@ ifeq ($(CONFIG_SENSORS_MAX31855),y)
|
|||||||
CSRCS += stm32_max31855.c
|
CSRCS += stm32_max31855.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_STM32F4DISCO_LIS3DSH),y)
|
||||||
|
CSRCS += stm32_lis3dsh.c
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_SENSORS_MAX6675),y)
|
ifeq ($(CONFIG_SENSORS_MAX6675),y)
|
||||||
CSRCS += stm32_max6675.c
|
CSRCS += stm32_max6675.c
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -287,5 +287,17 @@ int stm32_bringup(void)
|
|||||||
ret = xen1210_archinitialize(0);
|
ret = xen1210_archinitialize(0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef CONFIG_STM32F4DISCO_LIS3DSH
|
||||||
|
/* Create a lis3dsh driver instance fitting the chip built into stm32f4discovery */
|
||||||
|
|
||||||
|
ret = stm32_lis3dshinitialize("/dev/acc0");
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
serr("ERROR: Failed to initialize LIS3DSH driver: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,125 @@
|
|||||||
|
/************************************************************************************
|
||||||
|
* configs/stm32f4discovery/src/stm32_lis3dsh.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017 Florian Olbrich. All rights reserved.
|
||||||
|
* Author: Florian Olbrich <flox@posteo.de>
|
||||||
|
*
|
||||||
|
* 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/spi/spi.h>
|
||||||
|
#include <nuttx/sensors/lis3dsh.h>
|
||||||
|
|
||||||
|
#include "stm32.h"
|
||||||
|
#include "stm32f4discovery.h"
|
||||||
|
#include <stm32_gpio.h>
|
||||||
|
#include <nuttx/sensors/lis3dsh.h>
|
||||||
|
|
||||||
|
#if defined(CONFIG_STM32F4DISCO_LIS3DSH) && defined(CONFIG_LIS3DSH)
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#define GPIO_STM32F4DISCO_LIS3DSH_EXT0 (GPIO_INPUT|GPIO_FLOAT|GPIO_AF0|GPIO_SPEED_50MHz|GPIO_PORTE|GPIO_PIN0)
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Name: attach_disc_lis3dsh
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Attach the lis3dsh interrupt handler to PE0/EXT0 on the STM32F4 as wired on STM32F4Discovery
|
||||||
|
*
|
||||||
|
* Input parameters:
|
||||||
|
* *config - The lis3dsh instance configuration data containing the IRQ number, device ID and interrupt handler
|
||||||
|
* interrupt_handler - The interrupt handler to attach
|
||||||
|
* arg -
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno value on failure.
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
int attach_disc_lis3dsh(FAR struct lis3dsh_config_s *config, xcpt_t interrupt_handler) {
|
||||||
|
return stm32_gpiosetevent(GPIO_STM32F4DISCO_LIS3DSH_EXT0, true, false, false, interrupt_handler, NULL );
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Name: stm32_lis3dshinitialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize and register the LIS3DSH 3-axis accelerometer.
|
||||||
|
*
|
||||||
|
* Input parameters:
|
||||||
|
* devpath - The full path to the driver to register. E.g., "/dev/acc0"
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno value on failure.
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
int stm32_lis3dshinitialize(FAR const char *devpath)
|
||||||
|
{
|
||||||
|
static struct lis3dsh_config_s acc0_config;
|
||||||
|
struct spi_dev_s *spi;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
sninfo("Initializing LIS3DSH\n");
|
||||||
|
|
||||||
|
acc0_config.irq=22; // Interrupt no. for PE0 (INT1 on LIS3DSH)
|
||||||
|
acc0_config.spi_devid=0;
|
||||||
|
acc0_config.attach = &attach_disc_lis3dsh;
|
||||||
|
|
||||||
|
spi = stm32_spibus_initialize(1);
|
||||||
|
if( !spi ) {
|
||||||
|
spiinfo("Failed to initialize SPI port\n");
|
||||||
|
ret = -ENODEV;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ret = lis3dsh_register(devpath, spi, &acc0_config);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_STM32F4DISCO_LIS3DSH && CONFIG_LIS3DSH */
|
||||||
@@ -429,6 +429,19 @@ int stm32_bh1750initialize(FAR const char *devpath);
|
|||||||
int stm32_bmp180initialize(FAR const char *devpath);
|
int stm32_bmp180initialize(FAR const char *devpath);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: stm32_lis3dshinitialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Called to configure SPI 1, and to register LIS3DSH and its external interrupt
|
||||||
|
* for the stm32f4discovery board.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_STM32F4DISCO_LIS3DSH
|
||||||
|
int stm32_lis3dshinitialize(FAR const char *devpath);
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: stm32_bringup
|
* Name: stm32_bringup
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
* Copyright (C) 2016 DS-Automotion GmbH. All rights reserved.
|
* Copyright (C) 2016 DS-Automotion GmbH. All rights reserved.
|
||||||
* Author: Alexander Entinger <a.entinger@ds-automotion.com>
|
* Author: Alexander Entinger <a.entinger@ds-automotion.com>
|
||||||
* Thomas Ilk
|
* Thomas Ilk
|
||||||
|
* Florian Olbrich <flox@posteo.de>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -309,8 +310,7 @@ static int lis3dsh_interrupt_handler(int irq, FAR void *context)
|
|||||||
|
|
||||||
/* Find out which device caused the interrupt */
|
/* Find out which device caused the interrupt */
|
||||||
|
|
||||||
for (priv = g_lis3dsh_list; priv && priv->config->irq != irq;
|
for (priv = g_lis3dsh_list; priv && priv->config->irq != irq; priv = priv->flink);
|
||||||
priv = priv->flink);
|
|
||||||
DEBUGASSERT(priv != NULL);
|
DEBUGASSERT(priv != NULL);
|
||||||
|
|
||||||
/* Task the worker with retrieving the latest sensor data. We should not do
|
/* Task the worker with retrieving the latest sensor data. We should not do
|
||||||
@@ -318,13 +318,13 @@ static int lis3dsh_interrupt_handler(int irq, FAR void *context)
|
|||||||
* SPI bus from within an interrupt.
|
* SPI bus from within an interrupt.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
DEBUGASSERT(priv->work.worker == NULL);
|
if(work_available(&priv->work)) {
|
||||||
ret = work_queue(HPWORK, &priv->work, lis3dsh_worker, priv, 0);
|
ret = work_queue(HPWORK, &priv->work, lis3dsh_worker, priv, 0);
|
||||||
if (ret < 0)
|
if (ret < 0) {
|
||||||
{
|
snerr("ERROR: Failed to queue work: %d\n", ret);
|
||||||
snerr("ERROR: Failed to queue work: %d\n", ret);
|
return ret;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user