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 05e005c58ed486be158d80e1b87e1df450ac6cfe
Author: Matias Nitsche <[email protected]>
AuthorDate: Tue May 12 15:45:08 2020 -0300

    stm32: move ina219 initialization to common board logic directory
---
 boards/arm/stm32/common/include/stm32_ina219.h     | 80 ++++++++++++++++++++++
 boards/arm/stm32/common/src/Make.defs              |  4 ++
 .../src/stm32_ina219.c                             | 21 +++---
 boards/arm/stm32/olimex-stm32-e407/src/Make.defs   |  4 --
 .../olimex-stm32-e407/src/olimex-stm32-e407.h      | 18 -----
 .../stm32/olimex-stm32-e407/src/stm32_bringup.c    |  6 +-
 6 files changed, 98 insertions(+), 35 deletions(-)

diff --git a/boards/arm/stm32/common/include/stm32_ina219.h 
b/boards/arm/stm32/common/include/stm32_ina219.h
new file mode 100644
index 0000000..fbb9039
--- /dev/null
+++ b/boards/arm/stm32/common/include/stm32_ina219.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+ * boards/arm/stm32/common/include/stm32_ina219.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_INA219_H
+#define __STM32_INA219_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_ina219_initialize
+ *
+ * Description:
+ *   Initialize and register the INA219 voltage/current sensor.
+ *
+ * Input parameters:
+ *   devno - The device number, used to build the device path as /dev/inaN
+ *   busno - The I2C bus number
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int board_ina219_initialize(int devno, int busno);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif // __STM32_INA219_H
diff --git a/boards/arm/stm32/common/src/Make.defs 
b/boards/arm/stm32/common/src/Make.defs
index 1d8d75d..e195cc2 100644
--- a/boards/arm/stm32/common/src/Make.defs
+++ b/boards/arm/stm32/common/src/Make.defs
@@ -70,6 +70,10 @@ ifeq ($(CONFIG_SENSORS_QENCODER),y)
   CSRCS += stm32_qencoder.c
 endif
 
+ifeq ($(CONFIG_SENSORS_INA219),y)
+  CSRCS += stm32_ina219.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/olimex-stm32-e407/src/stm32_ina219.c 
b/boards/arm/stm32/common/src/stm32_ina219.c
similarity index 87%
rename from boards/arm/stm32/olimex-stm32-e407/src/stm32_ina219.c
rename to boards/arm/stm32/common/src/stm32_ina219.c
index d6dbc9a..2f5e1e2 100644
--- a/boards/arm/stm32/olimex-stm32-e407/src/stm32_ina219.c
+++ b/boards/arm/stm32/common/src/stm32_ina219.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * boards/arm/stm32/olimex-stm32-e407/src/stm32_ina219.c
+ * boards/arm/stm32/common/src/stm32_ina219.c
  *
  *   Copyright (C) 2018 Erle Robotics (Juan Flores Muñoz). All rights reserved.
  *   Author: Erle Robotics (Juan Flores Muñoz) <[email protected]>
@@ -42,50 +42,48 @@
 #include <errno.h>
 #include <syslog.h>
 #include <debug.h>
+#include <stdio.h>
 
 #include <nuttx/spi/spi.h>
 #include <nuttx/sensors/ina219.h>
 
 #include "stm32.h"
 #include "stm32_i2c.h"
-#include "olimex-stm32-e407.h"
-
-#if defined(CONFIG_I2C) && defined(CONFIG_SENSORS_INA219)
 
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
 
-#define INA219_I2C_PORTNO 1   /* On I2C1 */
-
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
 /****************************************************************************
- * Name: stm32_ina219initialize
+ * Name: board_ina219_initialize
  *
  * Description:
  *   Initialize and register the INA219 voltage/current sensor.
  *
  * Input parameters:
- *   devpath - The full path to the driver to register. E.g., "/dev/ina219"
+ *   devno - The device number, used to build the device path as /dev/inaN
+ *   busno - The I2C bus number
  *
  * Returned Value:
  *   Zero (OK) on success; a negated errno value on failure.
  *
  ****************************************************************************/
 
-int stm32_ina219initialize(FAR const char *devpath)
+int board_ina219_initialize(int devno, int busno)
 {
   FAR struct i2c_master_s *i2c;
+  char devpath[12];
   int ret;
 
   sninfo("Initializing INA219!\n");
 
   /* Initialize I2C */
 
-  i2c = stm32_i2cbus_initialize(INA219_I2C_PORTNO);
+  i2c = stm32_i2cbus_initialize(busno);
 
   if (!i2c)
     {
@@ -94,6 +92,7 @@ int stm32_ina219initialize(FAR const char *devpath)
 
   /* Then register the sensor */
 
+  snprintf(devpath, 12, "/dev/ina%d", devno);
   ret = ina219_register(devpath, i2c, 0x40, 100000, 0x00);
   if (ret < 0)
     {
@@ -102,5 +101,3 @@ int stm32_ina219initialize(FAR const char *devpath)
 
   return ret;
 }
-
-#endif /* CONFIG_I2C && CONFIG_SENSORS_INA219 */
diff --git a/boards/arm/stm32/olimex-stm32-e407/src/Make.defs 
b/boards/arm/stm32/olimex-stm32-e407/src/Make.defs
index e6d7c94..e50f4e8 100644
--- a/boards/arm/stm32/olimex-stm32-e407/src/Make.defs
+++ b/boards/arm/stm32/olimex-stm32-e407/src/Make.defs
@@ -84,10 +84,6 @@ ifeq ($(CONFIG_DAC),y)
 CSRCS += stm32_dac.c
 endif
 
-ifeq ($(CONFIG_SENSORS_INA219),y)
-CSRCS += stm32_ina219.c
-endif
-
 ifeq ($(CONFIG_TIMER),y)
 CSRCS += stm32_timer.c
 endif
diff --git a/boards/arm/stm32/olimex-stm32-e407/src/olimex-stm32-e407.h 
b/boards/arm/stm32/olimex-stm32-e407/src/olimex-stm32-e407.h
index 512cdd9..e3e3af3 100644
--- a/boards/arm/stm32/olimex-stm32-e407/src/olimex-stm32-e407.h
+++ b/boards/arm/stm32/olimex-stm32-e407/src/olimex-stm32-e407.h
@@ -309,24 +309,6 @@ int stm32_dac_setup(void);
 #endif
 
 /****************************************************************************
- * Name: stm32_ina219initialize
- *
- * Description:
- *   Initialize and register the INA219 voltage/current sensor.
- *
- * Input parameters:
- *   devpath - The full path to the driver to register. E.g., "/dev/ina219"
- *
- * Returned Value:
- *   Zero (OK) on success; a negated errno value on failure.
- *
- ****************************************************************************/
-
-#if defined(CONFIG_I2C) && defined(CONFIG_SENSORS_INA219)
-int stm32_ina219initialize(FAR const char *devpath);
-#endif
-
-/****************************************************************************
  * Name: stm32_timer_driver_setup
  *
  * Description:
diff --git a/boards/arm/stm32/olimex-stm32-e407/src/stm32_bringup.c 
b/boards/arm/stm32/olimex-stm32-e407/src/stm32_bringup.c
index 16e6453..063dd06 100644
--- a/boards/arm/stm32/olimex-stm32-e407/src/stm32_bringup.c
+++ b/boards/arm/stm32/olimex-stm32-e407/src/stm32_bringup.c
@@ -63,6 +63,10 @@
 #include "stm32_bmp180.h"
 #endif
 
+#ifdef CONFIG_SENSORS_INA219
+#include "stm32_ina219.h"
+#endif
+
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
@@ -248,7 +252,7 @@ int stm32_bringup(void)
 #ifdef CONFIG_SENSORS_INA219
   /* Configure and initialize the INA219 sensor */
 
-  ret = stm32_ina219initialize("/dev/ina219");
+  ret = board_ina219_initialize(0, 1);
   if (ret < 0)
     {
       syslog(LOG_ERR, "ERROR: stm32_ina219initialize() failed: %d\n", ret);

Reply via email to