stm32: move APDS9960 initialization to common board logic
This commit is contained in:
parent
beba7a8f0b
commit
562210a9bd
80
boards/arm/stm32/common/include/stm32_apds9960.h
Normal file
80
boards/arm/stm32/common/include/stm32_apds9960.h
Normal file
@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
* /home/v01d/coding/nuttx_latest/nuttx/boards/arm/stm32/common/include/stm32_apds9960.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __STM32_APDS9960_H
|
||||
#define __STM32_APDS9960_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Inline Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_apds9960_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register the APDS9960 gesture sensor.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devno - The device number, used to build the device path as /dev/gestN
|
||||
* busno - The I2C bus number
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_apds9960_initialize(int devno, int busno);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __STM32_APDS9960_H
|
@ -58,6 +58,10 @@ ifeq ($(CONFIG_SENSORS_HCSR04),y)
|
||||
CSRCS += stm32_hcsr04.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSORS_APDS9960),y)
|
||||
CSRCS += stm32_apds9960.c
|
||||
endif
|
||||
|
||||
DEPPATH += --dep-path src
|
||||
VPATH += :src
|
||||
CFLAGS += $(shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/stm32f103-minimum/src/stm32_apds9960.c
|
||||
* boards/arm/stm32/common/src/stm32_apds9960.c
|
||||
*
|
||||
* Copyright (C) 2017 Alan Carvalho de Assis. All rights reserved.
|
||||
* Author: Alan Carvalho de Assis <acassis@gmail.com>
|
||||
@ -41,22 +41,19 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <nuttx/sensors/apds9960.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "stm32.h"
|
||||
#include "stm32_i2c.h"
|
||||
#include "stm32f103_minimum.h"
|
||||
|
||||
#if defined(CONFIG_I2C) && defined(CONFIG_SENSORS_APDS9960)
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define APDS9960_I2C_PORTNO 1 /* On I2C1 */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@ -77,8 +74,8 @@ struct stm32_apds9960config_s
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static int apds9960_irq_attach(FAR struct apds9960_config_s *state, xcpt_t isr,
|
||||
FAR void *arg);
|
||||
static int apds9960_irq_attach(FAR struct apds9960_config_s *state,
|
||||
xcpt_t isr, FAR void *arg);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
@ -108,8 +105,8 @@ static struct stm32_apds9960config_s g_apds9960config =
|
||||
|
||||
/* Attach the APDS-9960 interrupt handler to the GPIO interrupt */
|
||||
|
||||
static int apds9960_irq_attach(FAR struct apds9960_config_s *state, xcpt_t isr,
|
||||
FAR void *arg)
|
||||
static int apds9960_irq_attach(FAR struct apds9960_config_s *state,
|
||||
xcpt_t isr, FAR void *arg)
|
||||
{
|
||||
irqstate_t flags;
|
||||
|
||||
@ -119,7 +116,7 @@ static int apds9960_irq_attach(FAR struct apds9960_config_s *state, xcpt_t isr,
|
||||
|
||||
/* Setup interrupt for Falling Edge */
|
||||
|
||||
stm32_gpiosetevent(GPIO_APDS9960_INT, false, true, true, isr, arg);
|
||||
stm32_gpiosetevent(BOARD_APDS9960_GPIO_INT, false, true, true, isr, arg);
|
||||
|
||||
leave_critical_section(flags);
|
||||
|
||||
@ -131,33 +128,35 @@ static int apds9960_irq_attach(FAR struct apds9960_config_s *state, xcpt_t isr,
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_apds9960initialize
|
||||
* Name: board_apds9960_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register the APDS9960 gesture sensor.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devpath - The full path to the driver to register. E.g., "/dev/gest0"
|
||||
* devno - The device number, used to build the device path as /dev/gestN
|
||||
* busno - The I2C bus number
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int stm32_apds9960initialize(FAR const char *devpath)
|
||||
int board_apds9960_initialize(int devno, int busno)
|
||||
{
|
||||
FAR struct i2c_master_s *i2c;
|
||||
char devpath[12];
|
||||
int ret;
|
||||
|
||||
sninfo("Initializing APDS9960!\n");
|
||||
|
||||
/* Configure the GPIO interrupt */
|
||||
|
||||
stm32_configgpio(GPIO_APDS9960_INT);
|
||||
stm32_configgpio(BOARD_APDS9960_GPIO_INT);
|
||||
|
||||
/* Initialize I2C */
|
||||
|
||||
i2c = stm32_i2cbus_initialize(APDS9960_I2C_PORTNO);
|
||||
i2c = stm32_i2cbus_initialize(busno);
|
||||
if (i2c == NULL)
|
||||
{
|
||||
return -ENODEV;
|
||||
@ -170,6 +169,7 @@ int stm32_apds9960initialize(FAR const char *devpath)
|
||||
|
||||
/* Then register the gesture sensor */
|
||||
|
||||
snprintf(devpath, 12, "/dev/gest%d", devno);
|
||||
ret = apds9960_register(devpath, &g_apds9960config.config);
|
||||
if (ret < 0)
|
||||
{
|
||||
@ -178,5 +178,3 @@ int stm32_apds9960initialize(FAR const char *devpath)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_I2C && CONFIG_SENSORS_APDS9960 && CONFIG_STM32_I2C1 */
|
@ -230,4 +230,10 @@
|
||||
#define BOARD_HCSR04_GPIO_TRIG GPIO_HCSR04_TRIG
|
||||
#define BOARD_HCSR04_FRTIMER 1 /* TIM1 as free running timer */
|
||||
|
||||
/* Pin for APDS-9960 sensor */
|
||||
|
||||
#define GPIO_APDS9960_INT (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_PORTA|GPIO_PIN0)
|
||||
|
||||
#define BOARD_APDS9960_GPIO_INT GPIO_APDS9960_INT
|
||||
|
||||
#endif /* __BOARDS_ARM_STM32_STM32F103_MINIMUM_INCLUDE_BOARD_H */
|
||||
|
@ -119,10 +119,6 @@ ifeq ($(CONFIG_LCD_PCD8544),y)
|
||||
CSRCS += stm32_pcd8544.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSORS_APDS9960),y)
|
||||
CSRCS += stm32_apds9960.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSORS_QENCODER),y)
|
||||
CSRCS += stm32_qencoder.c
|
||||
endif
|
||||
|
@ -121,6 +121,10 @@
|
||||
#include "stm32_hcsr04.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SENSORS_APDS9960
|
||||
#include "stm32_apds9960.h"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
@ -417,7 +421,7 @@ int stm32_bringup(void)
|
||||
#ifdef CONFIG_SENSORS_APDS9960
|
||||
/* Register the APDS-9960 gesture sensor */
|
||||
|
||||
ret = stm32_apds9960initialize("/dev/gest0");
|
||||
ret = board_apds9960_initialize(0, 1);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: stm32_apds9960initialize() failed: %d\n", ret);
|
||||
|
@ -137,10 +137,6 @@
|
||||
|
||||
#define GPIO_ZEROCROSS (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_PORTA|GPIO_PIN0)
|
||||
|
||||
/* Pin for APDS-9960 sensor */
|
||||
|
||||
#define GPIO_APDS9960_INT (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_PORTA|GPIO_PIN0)
|
||||
|
||||
/* SPI chip selects */
|
||||
|
||||
#define FLASH_SPI1_CS (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
|
||||
@ -267,18 +263,6 @@ int stm32_zerocross_initialize(void);
|
||||
int stm32_adc_setup(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_apds9960initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize APDS-9960 gesture sensor
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SENSORS_APDS9960
|
||||
int stm32_apds9960initialize(FAR const char *devpath);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_spidev_initialize
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user