stm32g071b-disco: ina230 support

This commit is contained in:
raiden00pl 2022-07-12 16:10:18 +02:00 committed by Alan Carvalho de Assis
parent 0570704cdc
commit 0253f0ff66
4 changed files with 149 additions and 0 deletions

View File

@ -43,6 +43,10 @@ ifeq ($(CONFIG_LCD_SSD1306),y)
CSRCS += stm32_lcd_ssd1306.c
endif
ifeq ($(CONFIG_SENSORS_INA226),y)
CSRCS += stm32_ina226.c
endif
DEPPATH += --dep-path board
VPATH += :board
CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board)

View File

@ -89,6 +89,18 @@ int stm32_bringup(void)
board_lcd_initialize();
#endif
#ifdef CONFIG_SENSORS_INA226
/* Initialize and register the INA226 */
ret = stm32_ina226_initialization();
if (ret != OK)
{
syslog(LOG_ERR,
"ERROR: Failed to register the INA226 drivers: %d\n", ret);
return ret;
}
#endif
UNUSED(ret);
return OK;
}

View File

@ -0,0 +1,121 @@
/****************************************************************************
* boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_ina226.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 <nuttx/config.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/i2c/i2c_master.h>
#include <nuttx/sensors/ina226.h>
#include "stm32_i2c.h"
#include "stm32g071b-disco.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef CONFIG_STM32F0L0G0_I2C1
# error I2C1 must be enabled!
#endif
#define INA226_1_I2C_ADDR 0x40 /* VBUS */
#define INA226_2_I2C_ADDR 0x41 /* CC1 */
#define INA226_3_I2C_ADDR 0x42 /* CC2 */
#define INA226_I2C_BUS 1
#define INA226_SHUNT_VAL 15000
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: stm32_ina226_initialization
*
* Description:
* Initialize and configure the INA226
*
****************************************************************************/
int stm32_ina226_initialization(void)
{
struct i2c_master_s *i2c = NULL;
static bool initialized = false;
int ret = OK;
/* Have we already initialized? */
if (!initialized)
{
/* No.. Get the I2C bus driver */
i2c = stm32_i2cbus_initialize(INA226_I2C_BUS);
if (!i2c)
{
serr("ERROR: Failed to initialize I2C%d\n", INA226_I2C_BUS);
goto errout;
}
/* Now bind the I2C interface to the INA226 drivers */
ret = ina226_register("/dev/ina226_1",
i2c, INA226_1_I2C_ADDR,
INA226_SHUNT_VAL, 0);
if (ret < 0)
{
serr("ERROR: Failed to bind I2C%d to the INA226_1 driver\n",
INA226_I2C_BUS);
goto errout;
}
ret = ina226_register("/dev/ina226_2",
i2c, INA226_2_I2C_ADDR,
INA226_SHUNT_VAL, 0);
if (ret < 0)
{
serr("ERROR: Failed to bind I2C%d to the INA226_2 driver\n",
INA226_I2C_BUS);
goto errout;
}
ret = ina226_register("/dev/ina226_3",
i2c, INA226_3_I2C_ADDR,
INA226_SHUNT_VAL, 0);
if (ret < 0)
{
serr("ERROR: Failed to bind I2C%d to the INA226_3 driver\n",
INA226_I2C_BUS);
goto errout;
}
/* Now we are initialized */
initialized = true;
}
errout:
return ret;
}

View File

@ -114,4 +114,16 @@ void stm32_spidev_initialize(void);
int stm32_djoy_initialization(void);
#endif
/****************************************************************************
* Name: stm32_ina226_initialization
*
* Description:
* Initialize and configure the INA226
*
****************************************************************************/
#ifdef CONFIG_SENSORS_INA226
int stm32_ina226_initialization(void);
#endif
#endif /* __BOARDS_ARM_STM32F0L0G0_STM32G071B_DISCO_SRC_STM32G071B_DISCO_H */