This is an automated email from the ASF dual-hosted git repository. jerpelea pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 562210a9bd834365b74935754af89d9724f43267 Author: Matias Nitsche <mnits...@dc.uba.ar> AuthorDate: Mon May 11 18:28:24 2020 -0300 stm32: move APDS9960 initialization to common board logic --- boards/arm/stm32/common/include/stm32_apds9960.h | 80 ++++++++++++++++++++++ boards/arm/stm32/common/src/Make.defs | 4 ++ .../src/stm32_apds9960.c | 34 +++++---- boards/arm/stm32/stm32f103-minimum/include/board.h | 6 ++ boards/arm/stm32/stm32f103-minimum/src/Make.defs | 4 -- .../stm32/stm32f103-minimum/src/stm32_bringup.c | 6 +- .../stm32f103-minimum/src/stm32f103_minimum.h | 16 ----- 7 files changed, 111 insertions(+), 39 deletions(-) diff --git a/boards/arm/stm32/common/include/stm32_apds9960.h b/boards/arm/stm32/common/include/stm32_apds9960.h new file mode 100644 index 0000000..eed7cf5 --- /dev/null +++ b/boards/arm/stm32/common/include/stm32_apds9960.h @@ -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 diff --git a/boards/arm/stm32/common/src/Make.defs b/boards/arm/stm32/common/src/Make.defs index 53b9345..9a0ab30 100644 --- a/boards/arm/stm32/common/src/Make.defs +++ b/boards/arm/stm32/common/src/Make.defs @@ -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) diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32_apds9960.c b/boards/arm/stm32/common/src/stm32_apds9960.c similarity index 88% rename from boards/arm/stm32/stm32f103-minimum/src/stm32_apds9960.c rename to boards/arm/stm32/common/src/stm32_apds9960.c index 2c225fa..efd31a7 100644 --- a/boards/arm/stm32/stm32f103-minimum/src/stm32_apds9960.c +++ b/boards/arm/stm32/common/src/stm32_apds9960.c @@ -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 <acas...@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 */ diff --git a/boards/arm/stm32/stm32f103-minimum/include/board.h b/boards/arm/stm32/stm32f103-minimum/include/board.h index ced5bcf..3852016 100644 --- a/boards/arm/stm32/stm32f103-minimum/include/board.h +++ b/boards/arm/stm32/stm32f103-minimum/include/board.h @@ -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 */ diff --git a/boards/arm/stm32/stm32f103-minimum/src/Make.defs b/boards/arm/stm32/stm32f103-minimum/src/Make.defs index 595056c..bc32755 100644 --- a/boards/arm/stm32/stm32f103-minimum/src/Make.defs +++ b/boards/arm/stm32/stm32f103-minimum/src/Make.defs @@ -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 diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c b/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c index fc6c0ac..1a7272a 100644 --- a/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c +++ b/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c @@ -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); diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32f103_minimum.h b/boards/arm/stm32/stm32f103-minimum/src/stm32f103_minimum.h index 0a28f83..ad0ed38 100644 --- a/boards/arm/stm32/stm32f103-minimum/src/stm32f103_minimum.h +++ b/boards/arm/stm32/stm32f103-minimum/src/stm32f103_minimum.h @@ -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|\ @@ -268,18 +264,6 @@ 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 * * Description: