From d444df59af7d9866dc464e14b0ce33b2552022d1 Mon Sep 17 00:00:00 2001 From: Matias Nitsche Date: Fri, 8 May 2020 13:17:28 -0300 Subject: [PATCH] stm32: move APA102, VEML6070 and MAX6675 initialization to board common logic --- .../arm/stm32/common/include/stm32_apa102.h | 84 +++++++++++++ .../arm/stm32/common/include/stm32_max6675.h | 84 +++++++++++++ .../arm/stm32/common/include/stm32_veml6070.h | 85 +++++++++++++ boards/arm/stm32/common/src/Make.defs | 12 ++ boards/arm/stm32/common/src/stm32_apa102.c | 108 +++++++++++++++++ boards/arm/stm32/common/src/stm32_max6675.c | 102 ++++++++++++++++ boards/arm/stm32/common/src/stm32_veml6070.c | 112 ++++++++++++++++++ .../arm/stm32/stm32f103-minimum/src/Make.defs | 12 -- .../stm32f103-minimum/src/stm32_apa102.c | 103 ---------------- .../stm32f103-minimum/src/stm32_bringup.c | 18 ++- .../stm32f103-minimum/src/stm32_max6675.c | 101 ---------------- .../stm32f103-minimum/src/stm32_veml6070.c | 105 ---------------- .../arm/stm32/stm32f4discovery/src/Make.defs | 4 - .../stm32f4discovery/src/stm32_bringup.c | 6 +- .../stm32f4discovery/src/stm32_max6675.c | 101 ---------------- 15 files changed, 607 insertions(+), 430 deletions(-) create mode 100644 boards/arm/stm32/common/include/stm32_apa102.h create mode 100644 boards/arm/stm32/common/include/stm32_max6675.h create mode 100644 boards/arm/stm32/common/include/stm32_veml6070.h create mode 100644 boards/arm/stm32/common/src/stm32_apa102.c create mode 100644 boards/arm/stm32/common/src/stm32_max6675.c create mode 100644 boards/arm/stm32/common/src/stm32_veml6070.c delete mode 100644 boards/arm/stm32/stm32f103-minimum/src/stm32_apa102.c delete mode 100644 boards/arm/stm32/stm32f103-minimum/src/stm32_max6675.c delete mode 100644 boards/arm/stm32/stm32f103-minimum/src/stm32_veml6070.c delete mode 100644 boards/arm/stm32/stm32f4discovery/src/stm32_max6675.c diff --git a/boards/arm/stm32/common/include/stm32_apa102.h b/boards/arm/stm32/common/include/stm32_apa102.h new file mode 100644 index 0000000000..4d7516ff9e --- /dev/null +++ b/boards/arm/stm32/common/include/stm32_apa102.h @@ -0,0 +1,84 @@ +/**************************************************************************** + * boards/arm/stm32/common/include/stm32_apa102.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_APA102_H +#define __STM32_APA102_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Type 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_apa102_initialize + * + * Description: + * Initialize and register the APA102 LED Strip driver. + * + * Input Parameters: + * devno - The device number, used to build the device path as /dev/leddrvN + * spino - SPI port number + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int board_apa102_initialize(int devno, int spino); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif // __STM32_APA102_H diff --git a/boards/arm/stm32/common/include/stm32_max6675.h b/boards/arm/stm32/common/include/stm32_max6675.h new file mode 100644 index 0000000000..d96f5f1bce --- /dev/null +++ b/boards/arm/stm32/common/include/stm32_max6675.h @@ -0,0 +1,84 @@ +/**************************************************************************** + * boards/arm/stm32/common/include/stm32_max6675.c + * + * 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_MAX6675_C +#define __STM32_MAX6675_C + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Type 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_max6675_initialize + * + * Description: + * Initialize and register the MAX6675 Temperature Sensor driver. + * + * Input Parameters: + * devno - The device number, used to build the device path as /dev/tempN + * busno - The SPI bus number + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int board_max6675_initialize(int devno, int busno); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif // __STM32_MAX6675_C diff --git a/boards/arm/stm32/common/include/stm32_veml6070.h b/boards/arm/stm32/common/include/stm32_veml6070.h new file mode 100644 index 0000000000..77ca033d5d --- /dev/null +++ b/boards/arm/stm32/common/include/stm32_veml6070.h @@ -0,0 +1,85 @@ +/**************************************************************************** + * boards/arm/stm32/common/include/stm32_veml6070.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_VEML6070_H +#define __STM32_VEML6070_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Type 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_veml6070_initialize + * + * Description: + * Initialize and register the VEML6070 UV-A Light sensor. + * + * Input Parameters: + * devno - The device number, used to build the device path as + * /dev/uvlightN + * busno - The I2C bus number + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int board_veml6070_initialize(int devno, int busno); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif // __STM32_VEML6070_H diff --git a/boards/arm/stm32/common/src/Make.defs b/boards/arm/stm32/common/src/Make.defs index 592055bd73..77377438c4 100644 --- a/boards/arm/stm32/common/src/Make.defs +++ b/boards/arm/stm32/common/src/Make.defs @@ -22,6 +22,18 @@ ifeq ($(CONFIG_SENSORS_BMP180),y) CSRCS += stm32_bmp180.c endif +ifeq ($(CONFIG_LEDS_APA102),y) + CSRCS += stm32_apa102.c +endif + +ifeq ($(CONFIG_SENSORS_MAX6675),y) + CSRCS += stm32_max6675.c +endif + +ifeq ($(CONFIG_SENSORS_VEML6070),y) + CSRCS += stm32_veml6070.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/common/src/stm32_apa102.c b/boards/arm/stm32/common/src/stm32_apa102.c new file mode 100644 index 0000000000..37f0bd1721 --- /dev/null +++ b/boards/arm/stm32/common/src/stm32_apa102.c @@ -0,0 +1,108 @@ +/**************************************************************************** + * boards/arm/stm32/common/src/stm32_apa102.c + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include "stm32.h" +#include "stm32_spi.h" + +#ifdef CONFIG_LEDS_APA102 + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_apa102_initialize + * + * Description: + * Initialize and register the APA102 LED Strip driver. + * + * Input Parameters: + * devno - The device number, used to build the device path as /dev/leddrvN + * spino - SPI port number + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int board_apa102_initialize(int devno, int spino) +{ + FAR struct spi_dev_s *spi; + char devpath[12]; + int ret; + + spi = stm32_spibus_initialize(spino); + if (spi == NULL) + { + return -ENODEV; + } + + /* Register the APA102 Driver at the specified location. */ + + snprintf(devpath, 12, "/dev/leddrv%d", devno); + ret = apa102_register(devpath, spi); + if (ret < 0) + { + lederr("ERROR: apa102_register(%s) failed: %d\n", + devpath, ret); + return ret; + } + + return OK; +} + +#endif diff --git a/boards/arm/stm32/common/src/stm32_max6675.c b/boards/arm/stm32/common/src/stm32_max6675.c new file mode 100644 index 0000000000..fe3987902a --- /dev/null +++ b/boards/arm/stm32/common/src/stm32_max6675.c @@ -0,0 +1,102 @@ +/**************************************************************************** + * boards/arm/stm32/common/src/stm32_max6675.c + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include "stm32_spi.h" + +#ifdef CONFIG_SENSORS_MAX6675 + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_max6675_initialize + * + * Description: + * Initialize and register the MAX6675 Temperature Sensor driver. + * + * Input Parameters: + * devno - The device number, used to build the device path as /dev/tempN + * busno - The SPI bus number + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int board_max6675_initialize(int devno, int busno) +{ + FAR struct spi_dev_s *spi; + char devpath[12]; + int ret; + + spi = stm32_spibus_initialize(busno); + + if (!spi) + { + return -ENODEV; + } + + /* Then register the barometer sensor */ + + snprintf(devpath, 12, "/dev/temp%d", devno); + ret = max6675_register(devpath, spi); + if (ret < 0) + { + snerr("ERROR: Error registering MAX6675\n"); + } + + return ret; +} + +#endif diff --git a/boards/arm/stm32/common/src/stm32_veml6070.c b/boards/arm/stm32/common/src/stm32_veml6070.c new file mode 100644 index 0000000000..a2850f1042 --- /dev/null +++ b/boards/arm/stm32/common/src/stm32_veml6070.c @@ -0,0 +1,112 @@ +/**************************************************************************** + * boards/arm/stm32/common/src/stm32_veml6070.c + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include "stm32.h" +#include "stm32_i2c.h" + +#ifdef CONFIG_SENSORS_VEML6070 + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_veml6070_initialize + * + * Description: + * Initialize and register the VEML6070 UV-A Light sensor. + * + * Input Parameters: + * devno - The device number, used to build the device path as + * /dev/uvlightN + * busno - The I2C bus number + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int board_veml6070_initialize(int devno, int busno) +{ + FAR struct i2c_master_s *i2c; + char devpath[13]; + int ret; + + sninfo("Initializing VEML6070!\n"); + + /* Initialize I2C */ + + i2c = stm32_i2cbus_initialize(busno); + + if (!i2c) + { + return -ENODEV; + } + + /* Then register the light sensor */ + + snprintf(devpath, 13, "/dev/uvlight%d", devno); + ret = veml6070_register(devpath, i2c, VEML6070_I2C_DATA_LSB_CMD_ADDR); + if (ret < 0) + { + snerr("ERROR: Error registering VEML6070\n"); + } + + return ret; +} + +#endif diff --git a/boards/arm/stm32/stm32f103-minimum/src/Make.defs b/boards/arm/stm32/stm32f103-minimum/src/Make.defs index c4bb6dfd9b..b4bf184b7a 100644 --- a/boards/arm/stm32/stm32f103-minimum/src/Make.defs +++ b/boards/arm/stm32/stm32f103-minimum/src/Make.defs @@ -73,10 +73,6 @@ ifeq ($(CONFIG_LCD_BACKPACK),y) CSRCS += stm32_lcd_backpack.c endif -ifeq ($(CONFIG_LEDS_APA102),y) - CSRCS += stm32_apa102.c -endif - ifeq ($(CONFIG_LM75_I2C),y) CSRCS += stm32_lm75.c endif @@ -115,10 +111,6 @@ ifeq ($(CONFIG_SENSORS_HCSR04),y) CSRCS += stm32_hcsr04.c endif -ifeq ($(CONFIG_SENSORS_MAX6675),y) - CSRCS += stm32_max6675.c -endif - ifeq ($(CONFIG_LCD_MAX7219),y) CSRCS += stm32_max7219.c endif @@ -147,10 +139,6 @@ ifeq ($(CONFIG_SENSORS_QENCODER),y) CSRCS += stm32_qencoder.c endif -ifeq ($(CONFIG_SENSORS_VEML6070),y) - CSRCS += stm32_veml6070.c -endif - ifeq ($(CONFIG_WL_NRF24L01),y) CSRCS += stm32_nrf24l01.c endif diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32_apa102.c b/boards/arm/stm32/stm32f103-minimum/src/stm32_apa102.c deleted file mode 100644 index f14f00cd1d..0000000000 --- a/boards/arm/stm32/stm32f103-minimum/src/stm32_apa102.c +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** - * boards/arm/stm32/stm32f103-minium/src/stm32_apa102.c - * - * Copyright (C) 2017 Alan Carvalho de Assis. All rights reserved. - * Author: Alan Carvalho de Assis - * - * 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 - -#include -#include - -#include -#include - -#include "stm32.h" -#include "stm32_spi.h" -#include "stm32f103_minimum.h" - -#if defined(CONFIG_SPI) && defined(CONFIG_STM32_SPI1) && \ - defined(CONFIG_LEDS_APA102) - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define APA102_SPI_PORTNO 1 /* On SPI1 */ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: stm32_apa102init - * - * Description: - * Initialize and register the APA102 LED Strip driver. - * - * Input Parameters: - * devpath - The full path to the driver to register. E.g., "/dev/leddrv0" - * - * Returned Value: - * Zero (OK) on success; a negated errno value on failure. - * - ****************************************************************************/ - -int stm32_apa102init(FAR const char *devpath) -{ - FAR struct spi_dev_s *spi; - int ret; - - spi = stm32_spibus_initialize(APA102_SPI_PORTNO); - if (spi == NULL) - { - return -ENODEV; - } - - /* Register the APA102 Driver at the specified location. */ - - ret = apa102_register(devpath, spi); - if (ret < 0) - { - lederr("ERROR: apa102_register(%s) failed: %d\n", - devpath, ret); - return ret; - } - - return OK; -} - -#endif /* CONFIG_SPI && CONFIG_CAN_APA102 */ diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c b/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c index 03bfa35ea7..8312d3681a 100644 --- a/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c +++ b/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c @@ -89,6 +89,18 @@ #include "stm32_bmp180.h" #endif +#ifdef CONFIG_LEDS_APA102 +#include "stm32_apa102.h" +#endif + +#ifdef CONFIG_SENSORS_MAX6675 +#include "stm32_max6675.h" +#endif + +#ifdef CONFIG_SENSORS_VEML6070 +#include "stm32_veml6070.h" +#endif + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -264,7 +276,7 @@ int stm32_bringup(void) #ifdef CONFIG_LEDS_APA102 /* Configure and initialize the APA102 LED Strip. */ - ret = stm32_apa102init("/dev/leddrv0"); + ret = board_apa102_initialize(0, 1); if (ret < 0) { syslog(LOG_ERR, "ERROR: stm32_apa102init() failed: %d\n", ret); @@ -302,7 +314,7 @@ int stm32_bringup(void) #endif #ifdef CONFIG_SENSORS_MAX6675 - ret = stm32_max6675initialize("/dev/temp0"); + ret = board_max6675_initialize(0, 1); if (ret < 0) { serr("ERROR: stm32_max6675initialize failed: %d\n", ret); @@ -391,7 +403,7 @@ int stm32_bringup(void) #ifdef CONFIG_SENSORS_VEML6070 /* Register the UV-A light sensor */ - ret = stm32_veml6070initialize("/dev/uvlight0"); + ret = board_veml6070_initialize(0, 1); if (ret < 0) { syslog(LOG_ERR, "ERROR: stm32_veml6070initialize() failed: %d\n", ret); diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32_max6675.c b/boards/arm/stm32/stm32f103-minimum/src/stm32_max6675.c deleted file mode 100644 index 23b79e3464..0000000000 --- a/boards/arm/stm32/stm32f103-minimum/src/stm32_max6675.c +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** - * boards/arm/stm32/stm32f4discovery/src/stm32_max6675.c - * - * Copyright (C) 2018 Alan Carvalho de Assis. All rights reserved. - * Author: Alan Carvalho de Assis - * - * 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 - -#include -#include - -#include -#include - -#include "stm32.h" -#include "stm32_spi.h" -#include "stm32f103_minimum.h" - -#if defined(CONFIG_SPI) && defined(CONFIG_SENSORS_MAX6675) && defined(CONFIG_STM32_SPI1) - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MAX6675_SPI_PORTNO 1 /* On SPI1 */ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: stm32_max6675initialize - * - * Description: - * Initialize and register the MAX6675 Temperature Sensor driver. - * - * Input Parameters: - * devpath - The full path to the driver to register. E.g., "/dev/temp0" - * - * Returned Value: - * Zero (OK) on success; a negated errno value on failure. - * - ****************************************************************************/ - -int stm32_max6675initialize(FAR const char *devpath) -{ - FAR struct spi_dev_s *spi; - int ret; - - spi = stm32_spibus_initialize(MAX6675_SPI_PORTNO); - - if (!spi) - { - return -ENODEV; - } - - /* Then register the barometer sensor */ - - ret = max6675_register(devpath, spi); - if (ret < 0) - { - snerr("ERROR: Error registering MAX6675\n"); - } - - return ret; -} - -#endif /* CONFIG_SPI && CONFIG_SENSORS_MAX6675 */ diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32_veml6070.c b/boards/arm/stm32/stm32f103-minimum/src/stm32_veml6070.c deleted file mode 100644 index c7dd4ae9d2..0000000000 --- a/boards/arm/stm32/stm32f103-minimum/src/stm32_veml6070.c +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** - * boards/arm/stm32/stm32f103-minimum/src/stm32_veml6070.c - * - * Copyright (C) 2016 Alan Carvalho de Assis. All rights reserved. - * Author: Alan Carvalho de Assis - * - * 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 - -#include -#include - -#include -#include - -#include "stm32.h" -#include "stm32_i2c.h" -#include "stm32f103_minimum.h" - -#if defined(CONFIG_I2C) && defined(CONFIG_SENSORS_VEML6070) - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define VEML6070_I2C_PORTNO 1 /* On I2C1 */ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: stm32_veml6070initialize - * - * Description: - * Initialize and register the VEML6070 UV-A Light sensor. - * - * Input Parameters: - * devpath - The full path to the driver to register. E.g., "/dev/uvlight0" - * - * Returned Value: - * Zero (OK) on success; a negated errno value on failure. - * - ****************************************************************************/ - -int stm32_veml6070initialize(FAR const char *devpath) -{ - FAR struct i2c_master_s *i2c; - int ret; - - sninfo("Initializing VEML6070!\n"); - - /* Initialize I2C */ - - i2c = stm32_i2cbus_initialize(VEML6070_I2C_PORTNO); - - if (!i2c) - { - return -ENODEV; - } - - /* Then register the light sensor */ - - ret = veml6070_register(devpath, i2c, VEML6070_I2C_DATA_LSB_CMD_ADDR); - if (ret < 0) - { - snerr("ERROR: Error registering VEML6070\n"); - } - - return ret; -} - -#endif /* CONFIG_I2C && CONFIG_SENSORS_VEML6070 && CONFIG_STM32_I2C1 */ diff --git a/boards/arm/stm32/stm32f4discovery/src/Make.defs b/boards/arm/stm32/stm32f4discovery/src/Make.defs index eefa4a43bb..6c12413bfd 100644 --- a/boards/arm/stm32/stm32f4discovery/src/Make.defs +++ b/boards/arm/stm32/stm32f4discovery/src/Make.defs @@ -97,10 +97,6 @@ ifeq ($(CONFIG_STM32F4DISCO_LIS3DSH),y) CSRCS += stm32_lis3dsh.c endif -ifeq ($(CONFIG_SENSORS_MAX6675),y) -CSRCS += stm32_max6675.c -endif - ifeq ($(CONFIG_LCD_MAX7219),y) CSRCS += stm32_max7219.c endif diff --git a/boards/arm/stm32/stm32f4discovery/src/stm32_bringup.c b/boards/arm/stm32/stm32f4discovery/src/stm32_bringup.c index 98903cc44b..8e4aebbb5e 100644 --- a/boards/arm/stm32/stm32f4discovery/src/stm32_bringup.c +++ b/boards/arm/stm32/stm32f4discovery/src/stm32_bringup.c @@ -86,6 +86,10 @@ #include "stm32_bmp180.h" #endif +#ifdef CONFIG_SENSORS_MAX6675 +#include "stm32_max6675.h" +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -407,7 +411,7 @@ int stm32_bringup(void) #endif #ifdef CONFIG_SENSORS_MAX6675 - ret = stm32_max6675initialize("/dev/temp0"); + ret = board_max6675_initialize(0, 2); if (ret < 0) { serr("ERROR: stm32_max6675initialize failed: %d\n", ret); diff --git a/boards/arm/stm32/stm32f4discovery/src/stm32_max6675.c b/boards/arm/stm32/stm32f4discovery/src/stm32_max6675.c deleted file mode 100644 index 4e30c2cfd6..0000000000 --- a/boards/arm/stm32/stm32f4discovery/src/stm32_max6675.c +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** - * boards/arm/stm32/stm32f4discovery/src/stm32_max6675.c - * - * Copyright (C) 2015 Alan Carvalho de Assis. All rights reserved. - * Author: Alan Carvalho de Assis - * - * 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 - -#include -#include - -#include -#include - -#include "stm32.h" -#include "stm32_spi.h" -#include "stm32f4discovery.h" - -#if defined(CONFIG_SPI) && defined(CONFIG_SENSORS_MAX6675) && defined(CONFIG_STM32_SPI2) - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MAX6675_SPI_PORTNO 2 /* On SPI2 */ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: stm32_max6675initialize - * - * Description: - * Initialize and register the MAX6675 Temperature Sensor driver. - * - * Input Parameters: - * devpath - The full path to the driver to register. E.g., "/dev/temp0" - * - * Returned Value: - * Zero (OK) on success; a negated errno value on failure. - * - ****************************************************************************/ - -int stm32_max6675initialize(FAR const char *devpath) -{ - FAR struct spi_dev_s *spi; - int ret; - - spi = stm32_spibus_initialize(MAX6675_SPI_PORTNO); - - if (!spi) - { - return -ENODEV; - } - - /* Then register the barometer sensor */ - - ret = max6675_register(devpath, spi); - if (ret < 0) - { - snerr("ERROR: Error registering MAX6675\n"); - } - - return ret; -} - -#endif /* CONFIG_SPI && CONFIG_SENSORS_MAX6675 */