stm32: move ina219 initialization to common board logic directory
This commit is contained in:
parent
60d51f2907
commit
05e005c58e
80
boards/arm/stm32/common/include/stm32_ina219.h
Normal file
80
boards/arm/stm32/common/include/stm32_ina219.h
Normal file
@ -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
|
@ -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)
|
||||
|
@ -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) <juan@erlerobotics.com>
|
||||
@ -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 */
|
@ -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
|
||||
|
@ -308,24 +308,6 @@ int stm32_can_setup(void);
|
||||
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
|
||||
*
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user