From 7c7836d1d714c3980c62bbfbeb90cb7b63a9a0a2 Mon Sep 17 00:00:00 2001 From: Matias Nitsche Date: Fri, 8 May 2020 16:10:13 -0300 Subject: [PATCH] stm32: move lm75 handling into common board logic; delete unused lm75 file for stm3210e-eval --- boards/arm/stm32/common/include/stm32_lm75.h | 80 ++++++++++++ boards/arm/stm32/common/src/Make.defs | 4 + boards/arm/stm32/common/src/stm32_lm75.c | 103 +++++++++++++++ boards/arm/stm32/stm3210e-eval/src/Makefile | 4 - .../arm/stm32/stm3210e-eval/src/stm32_lm75.c | 122 ------------------ .../arm/stm32/stm32f103-minimum/src/Make.defs | 4 - .../stm32f103-minimum/src/stm32_bringup.c | 5 +- .../stm32/stm32f103-minimum/src/stm32_lm75.c | 122 ------------------ 8 files changed, 191 insertions(+), 253 deletions(-) create mode 100644 boards/arm/stm32/common/include/stm32_lm75.h create mode 100644 boards/arm/stm32/common/src/stm32_lm75.c delete mode 100644 boards/arm/stm32/stm3210e-eval/src/stm32_lm75.c delete mode 100644 boards/arm/stm32/stm32f103-minimum/src/stm32_lm75.c diff --git a/boards/arm/stm32/common/include/stm32_lm75.h b/boards/arm/stm32/common/include/stm32_lm75.h new file mode 100644 index 0000000000..a39bed226b --- /dev/null +++ b/boards/arm/stm32/common/include/stm32_lm75.h @@ -0,0 +1,80 @@ +/**************************************************************************** + * boards/arm/stm32/common/include/stm32_lm75.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_LM75_H +#define __STM32_LM75_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * 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_lm75_initialize + * + * Description: + * Initialize and register the LM-75 Temperature Sensor driver. + * + * Input Parameters: + * devno - The device number, used to build the device path as /dev/tempN + * busno - The I2C bus number + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int board_lm75_initialize(int devno, int busno); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif // __STM32_LM75_H diff --git a/boards/arm/stm32/common/src/Make.defs b/boards/arm/stm32/common/src/Make.defs index c308f1ac85..f3a6e9f1a2 100644 --- a/boards/arm/stm32/common/src/Make.defs +++ b/boards/arm/stm32/common/src/Make.defs @@ -46,6 +46,10 @@ ifeq ($(CONFIG_LCD_SSD1306),y) CSRCS += stm32_ssd1306.c endif +ifeq ($(CONFIG_SENSORS_LM75),y) + CSRCS += stm32_lm75.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_lm75.c b/boards/arm/stm32/common/src/stm32_lm75.c new file mode 100644 index 0000000000..408bfcdfe3 --- /dev/null +++ b/boards/arm/stm32/common/src/stm32_lm75.c @@ -0,0 +1,103 @@ +/**************************************************************************** + * boards/arm/stm32/common/src/stm32_lm75.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.h" +#include "stm32_i2c.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_lm75_initialize + * + * Description: + * Initialize and register the LM-75 Temperature Sensor driver. + * + * Input Parameters: + * devno - The device number, used to build the device path as /dev/tempN + * busno - The I2C bus number + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int board_lm75_initialize(int devno, int busno) +{ + FAR struct i2c_master_s *i2c; + char devpath[12]; + int ret; + + /* Get an instance of the I2C1 interface */ + + i2c = stm32_i2cbus_initialize(busno); + if (!i2c) + { + return -ENODEV; + } + + /* Then register the temperature sensor */ + + snprintf(devpath, 12, "/dev/temp%d", devno); + ret = lm75_register(devpath, i2c, 0x48); + if (ret < 0) + { + stm32_i2cbus_uninitialize(i2c); + } + + return ret; +} diff --git a/boards/arm/stm32/stm3210e-eval/src/Makefile b/boards/arm/stm32/stm3210e-eval/src/Makefile index 9a5294ba32..a98c744055 100644 --- a/boards/arm/stm32/stm3210e-eval/src/Makefile +++ b/boards/arm/stm32/stm3210e-eval/src/Makefile @@ -60,10 +60,6 @@ ifeq ($(CONFIG_USBDEV_COMPOSITE),y) CSRCS += stm32_composite.c endif -ifeq ($(CONFIG_LM75_I2C),y) -CSRCS += stm32_lm75.c -endif - ifeq ($(CONFIG_CAN),y) CSRCS += stm32_can.c endif diff --git a/boards/arm/stm32/stm3210e-eval/src/stm32_lm75.c b/boards/arm/stm32/stm3210e-eval/src/stm32_lm75.c deleted file mode 100644 index 3694884cbb..0000000000 --- a/boards/arm/stm32/stm3210e-eval/src/stm32_lm75.c +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** - * boards/arm/stm32/stm3210e-eval/src/stm32_lm75.c - * - * Copyright (C) 2011, 2016 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 "stm32.h" -#include "stm32_i2c.h" -#include "stm3210e-eval.h" - -#if defined(CONFIG_I2C) && defined(CONFIG_LM75_I2C) && defined(CONFIG_STM32_I2C1) - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: stm32_lm75initialize - * - * Description: - * Initialize and register the LM-75 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_lm75initialize(FAR const char *devpath) -{ - FAR struct i2c_master_s *i2c; - int ret; - - /* Configure PB.5 as Input pull-up. This pin can be used as a temperature - * sensor interrupt (not fully implemented). - */ - - stm32_configgpio(GPIO_LM75_OSINT); - - /* Get an instance of the I2C1 interface */ - - i2c = stm32_i2cbus_initialize(1); - if (!i2c) - { - return -ENODEV; - } - - /* Then register the temperature sensor */ - - ret = lm75_register(devpath, i2c, 0x48); - if (ret < 0) - { - stm32_i2cbus_uninitialize(i2c); - } - - return ret; -} - -/**************************************************************************** - * Name: stm32_lm75attach - * - * Description: - * Attach the LM-75 interrupt handler - * - * Input Parameters: - * irqhandler - the LM-75 interrupt handler - * arg - The argument that will accompany the interrupt - * - * Returned Value: - * Zero (OK) returned on success; a negated errno value is returned on failure. - * - ****************************************************************************/ - -int stm32_lm75attach(xcpt_t irqhandler, void *arg) -{ - stm32_gpiosetevent(GPIO_LM75_OSINT, true, true, true, irqhandler, arg); - return OK; -} - -#endif /* CONFIG_I2C && CONFIG_LM75_I2C && CONFIG_STM32_I2C1 */ diff --git a/boards/arm/stm32/stm32f103-minimum/src/Make.defs b/boards/arm/stm32/stm32f103-minimum/src/Make.defs index ee01d76fe9..25fd42434d 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_LM75_I2C),y) - CSRCS += stm32_lm75.c -endif - ifeq ($(CONFIG_RGBLED),y) CSRCS += stm32_rgbled.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 f9cacd33aa..587254484d 100644 --- a/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c +++ b/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c @@ -109,6 +109,9 @@ #include "stm32_tone.h" #endif +#ifdef CONFIG_SENSORS_LM75 +#include "stm32_lm75.h" +#endif /**************************************************************************** * Pre-processor Definitions @@ -308,7 +311,7 @@ int stm32_bringup(void) #ifdef CONFIG_LM75_I2C /* Configure and initialize the LM75 sensor */ - ret = stm32_lm75initialize("/dev/temp"); + ret = board_lm75_initialize(0, 1); if (ret < 0) { syslog(LOG_ERR, "ERROR: stm32_lm75initialize() failed: %d\n", ret); diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32_lm75.c b/boards/arm/stm32/stm32f103-minimum/src/stm32_lm75.c deleted file mode 100644 index 15c68edd85..0000000000 --- a/boards/arm/stm32/stm32f103-minimum/src/stm32_lm75.c +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** - * boards/arm/stm32/stm32f103-minimum/src/stm32_lm75.c - * - * Copyright (C) 2017 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 "stm32.h" -#include "stm32_i2c.h" -#include "stm32f103_minimum.h" - -#if defined(CONFIG_I2C) && defined(CONFIG_LM75_I2C) && defined(CONFIG_STM32_I2C1) - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: stm32_lm75initialize - * - * Description: - * Initialize and register the LM-75 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_lm75initialize(FAR const char *devpath) -{ - FAR struct i2c_master_s *i2c; - int ret; - - /* Configure PB.5 as Input pull-up. This pin can be used as a temperature - * sensor interrupt (not fully implemented). - */ - - stm32_configgpio(GPIO_LM75_OSINT); - - /* Get an instance of the I2C1 interface */ - - i2c = stm32_i2cbus_initialize(1); - if (!i2c) - { - return -ENODEV; - } - - /* Then register the temperature sensor */ - - ret = lm75_register(devpath, i2c, 0x48); - if (ret < 0) - { - stm32_i2cbus_uninitialize(i2c); - } - - return ret; -} - -/**************************************************************************** - * Name: stm32_lm75attach - * - * Description: - * Attach the LM-75 interrupt handler - * - * Input Parameters: - * irqhandler - the LM-75 interrupt handler - * arg - The argument that will accompany the interrupt - * - * Returned Value: - * Zero (OK) returned on success; a negated errno value is returned on failure. - * - ****************************************************************************/ - -int stm32_lm75attach(xcpt_t irqhandler, void *arg) -{ - stm32_gpiosetevent(GPIO_LM75_OSINT, true, true, true, irqhandler, arg); - return OK; -} - -#endif /* CONFIG_I2C && CONFIG_LM75_I2C && CONFIG_STM32_I2C1 */