config/stm32f429i-disco: add support for the L3GD20 driver

This commit is contained in:
raiden00 2017-02-19 17:42:25 +01:00
parent 82cb38c824
commit d45b731fbd
5 changed files with 184 additions and 1 deletions

View File

@ -8,7 +8,7 @@ memory and 256kbytes. The board features:
- On-board ST-LINK/V2 for programming and debugging,
- On-board 64 Mbits (8 Mbytes) External SDRAM (1 Mbit x 16-bit x 4-bank)
- LIS302DL, ST MEMS motion sensor, 3-axis digital output accelerometer,
- L3GD20, ST MEMS motion sensor, 3-axis digital output gyroscope,
- TFT 2.4" LCD, 262K color RGB, 240 x 320 pixels
- Touchscreen controller
- Two user LEDs and two push-buttons,

View File

@ -72,6 +72,10 @@ ifeq ($(CONFIG_STM32F429I_DISCO_ILI9341),y)
CSRCS += stm32_ili93414ws.c
endif
ifeq ($(CONFIG_SENSORS_L3GD20),y)
CSRCS += stm32_l3gd20.c
endif
ifeq ($(and \
$(CONFIG_STM32F429I_DISCO_ILI9341_LCDIFACE), \
$(CONFIG_STM32F429I_DISCO_ILI9341_FBIFACE), \

View File

@ -165,6 +165,8 @@ int board_app_initialize(uintptr_t arg)
int ret;
#elif defined(HAVE_USBHOST) || defined(HAVE_USBMONITOR)
int ret;
#elif defined(CONFIG_SENSORS_L3GD20)
int ret;
#endif
/* Configure SPI-based devices */
@ -378,5 +380,14 @@ int board_app_initialize(uintptr_t arg)
}
#endif
#ifdef CONFIG_SENSORS_L3GD20
ret = stm32_l3gd20initialize("/dev/gyr0");
if (ret != OK)
{
syslog(LOG_ERR, "ERROR: Failed to initialize l3gd20 sensor: %d\n", ret);
}
#endif
return OK;
}

View File

@ -0,0 +1,144 @@
/****************************************************************************
* configs/stm32f429i-disco/src/stm32_l3gd20.c
*
* Authors: Mateusz Szafoni <raiden00@railab.me>
*
* 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/l3gd20.h>
#include "stm32.h"
#include "stm32_spi.h"
#include "stm32f429i-disco.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#if defined(CONFIG_SPI) & defined(CONFIG_SENSORS_L3GD20)
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
static int l3gd20_attach(FAR struct l3gd20_config_s * cfg, xcpt_t irq);
/****************************************************************************
* Private Data
****************************************************************************/
/* Only one L3GD20 device on board */
static struct l3gd20_config_s g_l3gd20_config =
{
.attach = l3gd20_attach,
.irq = L3GD20_IRQ,
.spi_devid = SPIDEV_ACCELEROMETER
};
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: l3gd20_attach()
*
* Description: Attach the l3gd20 interrupt handler to the GPIO interrupt
*
****************************************************************************/
static int l3gd20_attach(FAR struct l3gd20_config_s * cfg, xcpt_t irq)
{
stm32_gpiosetevent(GPIO_L3GD20_DREADY, true, false, true, irq);
return OK;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: stm32_l3gd20initialize()
*
* Description:
* Initialize and register the L3GD20 3 axis gyroscope sensor driver.
*
* Input parameters:
* devpath - The full path to the driver to register. E.g., "/dev/gyro0"
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
int stm32_l3gd20initialize(FAR const char *devpath)
{
int ret = 0;
struct spi_dev_s *spi;
/* Configure DREADY IRQ input */
stm32_configgpio(GPIO_L3GD20_DREADY);
/* Initialize SPI */
spi = stm32_spi5initialize();
if (!spi)
{
ret = -ENODEV;
goto errout;
}
/* Then register the gyro */
ret = l3gd20_register(devpath, spi, &g_l3gd20_config);
if (ret != OK)
{
goto errout;
}
errout:
return ret;
}
#endif /* CONFIG_SPI && CONFIG_SENSORS_L3GD20 */

View File

@ -114,6 +114,11 @@
#define GPIO_CS_SST25 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTE|GPIO_PIN4)
/* L3GD20 MEMS*/
#define GPIO_L3GD20_DREADY (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTA|GPIO_PIN2)
#define L3GD20_IRQ (2 + STM32_IRQ_EXTI0)
/* USB OTG HS
*
* PA9 OTG_HS_VBUS VBUS sensing (also connected to the green LED)
@ -275,6 +280,25 @@ FAR struct ili9341_lcd_s *stm32_ili93414ws_initialize(void);
FAR struct spi_dev_s *stm32_spi5initialize(void);
#endif
#if defined(CONFIG_SPI) & defined(CONFIG_SENSORS_L3GD20)
/****************************************************************************
* Name: stm32_l3gd20initialize()
*
* Description:
* Initialize and register the L3GD20 3 axis gyroscope sensor driver.
*
* Input parameters:
* devpath - The full path to the driver to register. E.g., "/dev/gyro0"
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
int stm32_l3gd20initialize(FAR const char *devpath);
#endif
#endif /* __ASSEMBLY__ */
#endif /* __CONFIGS_STM32F429I_DISCO_SRC_STM32F429I_DISCO_H */