mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 01:21:26 +08:00
Add i2c support for the i.MX8MP
Enable INA219 on the Verdin board
This commit is contained in:
committed by
Alan Carvalho de Assis
parent
779741d1d9
commit
98e998b934
@@ -604,6 +604,7 @@ config ARCH_CHIP_MX8MP
|
|||||||
select ARCH_HAVE_MPU
|
select ARCH_HAVE_MPU
|
||||||
select ARCH_HAVE_FETCHADD
|
select ARCH_HAVE_FETCHADD
|
||||||
select ARCH_HAVE_RAMFUNCS
|
select ARCH_HAVE_RAMFUNCS
|
||||||
|
select ARCH_HAVE_I2CRESET
|
||||||
select ARM_HAVE_MPU_UNIFIED
|
select ARM_HAVE_MPU_UNIFIED
|
||||||
select ARMV7M_HAVE_ICACHE
|
select ARMV7M_HAVE_ICACHE
|
||||||
select ARMV7M_HAVE_DCACHE
|
select ARMV7M_HAVE_DCACHE
|
||||||
|
|||||||
@@ -31,6 +31,59 @@ config MX8MP_UART4
|
|||||||
select UART4_SERIALDRIVER
|
select UART4_SERIALDRIVER
|
||||||
select ARCH_HAVE_SERIAL_TERMIOS
|
select ARCH_HAVE_SERIAL_TERMIOS
|
||||||
|
|
||||||
|
#####################################################################
|
||||||
|
# I2C Configuration (Master)
|
||||||
|
#####################################################################
|
||||||
|
|
||||||
|
config MX8MP_I2C
|
||||||
|
bool "I2C Master"
|
||||||
|
select I2C
|
||||||
|
---help---
|
||||||
|
Build in support for I2C master mode.
|
||||||
|
|
||||||
|
if MX8MP_I2C
|
||||||
|
|
||||||
|
config MX8MP_I2C1
|
||||||
|
bool "I2C1"
|
||||||
|
default n
|
||||||
|
select I2C
|
||||||
|
|
||||||
|
config MX8MP_I2C2
|
||||||
|
bool "I2C2"
|
||||||
|
default n
|
||||||
|
select I2C
|
||||||
|
|
||||||
|
config MX8MP_I2C3
|
||||||
|
bool "I2C3"
|
||||||
|
default n
|
||||||
|
select I2C
|
||||||
|
|
||||||
|
config MX8MP_I2C4
|
||||||
|
bool "I2C4"
|
||||||
|
default n
|
||||||
|
select I2C
|
||||||
|
|
||||||
|
config MX8MP_I2C5
|
||||||
|
bool "I2C5"
|
||||||
|
default n
|
||||||
|
select I2C
|
||||||
|
|
||||||
|
config MX8MP_I2C6
|
||||||
|
bool "I2C6"
|
||||||
|
default n
|
||||||
|
select I2C
|
||||||
|
|
||||||
|
config MX8MP_I2C_DRIVER
|
||||||
|
bool "I2C character driver"
|
||||||
|
default n
|
||||||
|
select I2C_DRIVER
|
||||||
|
---help---
|
||||||
|
Build in support for a character driver at /dev/i2c[N] that may be
|
||||||
|
used to perform I2C bus transfers from applications. The intent of
|
||||||
|
this driver is to support I2C testing. It is not suitable for use
|
||||||
|
in any real driver application.
|
||||||
|
|
||||||
|
endif # MX8MP_I2C
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
# These "hidden" settings determine whether a peripheral option is available
|
# These "hidden" settings determine whether a peripheral option is available
|
||||||
|
|||||||
@@ -35,3 +35,7 @@ endif
|
|||||||
ifneq ($(CONFIG_SCHED_TICKLESS),y)
|
ifneq ($(CONFIG_SCHED_TICKLESS),y)
|
||||||
CHIP_CSRCS += mx8mp_timerisr.c
|
CHIP_CSRCS += mx8mp_timerisr.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_I2C),y)
|
||||||
|
CHIP_CSRCS += mx8mp_i2c.c
|
||||||
|
endif
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* arch/arm/src/mx8mp/hardware/mx8mp_i2c.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 __ARCH_ARM_SRC_MX8MP_HARDWARE_MX8MP_I2C_H
|
||||||
|
#define __ARCH_ARM_SRC_MX8MP_HARDWARE_MX8MP_I2C_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* I2C Register Offsets *****************************************************/
|
||||||
|
|
||||||
|
#define IADR_OFFSET 0x0000
|
||||||
|
#define IFDR_OFFSET 0x0004
|
||||||
|
#define I2CR_OFFSET 0x0008
|
||||||
|
#define I2SR_OFFSET 0x000c
|
||||||
|
#define I2DR_OFFSET 0x0010
|
||||||
|
|
||||||
|
/* I2C Register Bit Definitions *********************************************/
|
||||||
|
|
||||||
|
#define IADR_SHIFT 1
|
||||||
|
#define IADR_MASK (0x7f << IADR_SHIFT)
|
||||||
|
|
||||||
|
#define IFDR_SHIFT 0
|
||||||
|
#define IFDR_MASK (0x3f << IFDR_SHIFT)
|
||||||
|
|
||||||
|
#define I2CR_IEN (1 << 7) /* enable */
|
||||||
|
#define I2CR_IIEN (1 << 6) /* interrupt enable */
|
||||||
|
#define I2CR_MSTA (1 << 5) /* master/start */
|
||||||
|
#define I2CR_MTX (1 << 4) /* transmit */
|
||||||
|
#define I2CR_TXAK (1 << 3) /* ACK/NACK on reception */
|
||||||
|
#define I2CR_RSTA (1 << 2) /* repeated start */
|
||||||
|
|
||||||
|
#define I2SR_ICF (1 << 7) /* transfer in progress */
|
||||||
|
#define I2SR_IAAS (1 << 6) /* addressed as a slave */
|
||||||
|
#define I2SR_IBB (1 << 5) /* is busy */
|
||||||
|
#define I2SR_IAL (1 << 4) /* arbitration lost */
|
||||||
|
#define I2SR_SRW (1 << 2) /* slave read/write (if in slave mode) */
|
||||||
|
#define I2SR_IIF (1 << 1) /* interrupt is pending */
|
||||||
|
#define I2SR_RXAK (1 << 0) /* no ack detected */
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Inline Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#endif /* __ARCH_ARM_SRC_MX8MP_HARDWARE_MX8MP_I2C_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,72 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* arch/arm/src/mx8mp/mx8mp_i2c.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 __ARCH_ARM_SRC_MX8MP_MX8MP_I2C_H
|
||||||
|
#define __ARCH_ARM_SRC_MX8MP_MX8MP_I2C_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <nuttx/i2c/i2c_master.h>
|
||||||
|
#include "hardware/mx8mp_i2c.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: mx8mp_i2cbus_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the selected I2C port. And return a unique instance of struct
|
||||||
|
* struct i2c_master_s. This function may be called to obtain multiple
|
||||||
|
* instances of the interface, each of which may be set up with a
|
||||||
|
* different frequency and slave address.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* Port number (for hardware that has multiple I2C interfaces)
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Valid I2C device structure reference on success; a NULL on failure
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
struct i2c_master_s *mx8mp_i2cbus_initialize(int port);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: mx8mp_i2cbus_uninitialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* De-initialize the selected I2C port, and power down the device.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* Device structure as returned by the lpc43_i2cbus_initialize()
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* OK on success, ERROR when internal reference count mismatch or dev
|
||||||
|
* points to invalid hardware device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int mx8mp_i2cbus_uninitialize(struct i2c_master_s *dev);
|
||||||
|
|
||||||
|
#endif /* __ARCH_ARM_SRC_MX8MP_MX8MP_I2C_H */
|
||||||
@@ -23,7 +23,16 @@ include $(TOPDIR)/Make.defs
|
|||||||
CSRCS = mx8mp_boot.c mx8mp_bringup.c
|
CSRCS = mx8mp_boot.c mx8mp_bringup.c
|
||||||
|
|
||||||
ifeq ($(CONFIG_BOARDCTL),y)
|
ifeq ($(CONFIG_BOARDCTL),y)
|
||||||
CSRCS += mx8mp_appinit.c
|
CSRCS += mx8mp_appinit.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_SENSORS_INA219),y)
|
||||||
|
CSRCS += mx8mp_ina219.c
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_MX8MP_I2C_DRIVER),y)
|
||||||
|
CSRCS += mx8mp_i2cdev.c
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
include $(TOPDIR)/boards/Board.mk
|
include $(TOPDIR)/boards/Board.mk
|
||||||
|
|||||||
@@ -28,10 +28,16 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "verdin-mx8mp.h"
|
||||||
|
|
||||||
#ifdef CONFIG_USERLED
|
#ifdef CONFIG_USERLED
|
||||||
# include <nuttx/leds/userled.h>
|
# include <nuttx/leds/userled.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_SENSORS_INA219
|
||||||
|
# include "mx8mp_ina219.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -58,5 +64,35 @@ int mx8mp_bringup(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_FS_PROCFS
|
||||||
|
/* Mount the procfs file system */
|
||||||
|
|
||||||
|
ret = nx_mount(NULL, "/proc", "procfs", 0, NULL);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: Failed to mount procfs at /proc: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_MX8MP_I2C_DRIVER
|
||||||
|
/* Initialize I2C buses */
|
||||||
|
|
||||||
|
ret = mx8mp_i2cdev_initialize();
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: mx8mp_i2cdev_initialize() failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_SENSORS_INA219
|
||||||
|
/* Configure and initialize the INA219 sensor in I2C4 */
|
||||||
|
|
||||||
|
ret = board_ina219_initialize(4);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: mx8mp_ina219_initialize() failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,147 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* boards/arm/mx8mp/verdin-mx8mp/src/mx8mp_i2cdev.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 <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/i2c/i2c_master.h>
|
||||||
|
|
||||||
|
#include "arm_internal.h"
|
||||||
|
#include "chip.h"
|
||||||
|
#include "mx8mp_i2c.h"
|
||||||
|
|
||||||
|
#include <arch/board/board.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: board_i2cdev_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize and register i2c driver for the specified i2c port
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int board_i2cdev_initialize(int port)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
struct i2c_master_s *i2c;
|
||||||
|
|
||||||
|
i2cinfo("Initializing /dev/i2c%d..\n", port);
|
||||||
|
|
||||||
|
/* Initialize i2c device */
|
||||||
|
|
||||||
|
i2c = mx8mp_i2cbus_initialize(port);
|
||||||
|
if (!i2c)
|
||||||
|
{
|
||||||
|
i2cerr("ERROR: Failed to initialize i2c%d.\n", port);
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = i2c_register(i2c, port);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
i2cerr("ERROR: Failed to register i2c%d: %d\n", port, ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: mx8mp_i2cdev_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Called to configure all i2c drivers
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int mx8mp_i2cdev_initialize(void)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
#ifdef CONFIG_MX8MP_I2C1
|
||||||
|
ret = board_i2cdev_initialize(1);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "Failed to initialize I2C1.\n");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_MX8MP_I2C2
|
||||||
|
ret = board_i2cdev_initialize(2);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "Failed to initialize I2C2.\n");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_MX8MP_I2C3
|
||||||
|
ret = board_i2cdev_initialize(3);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "Failed to initialize I2C3.\n");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_MX8MP_I2C4
|
||||||
|
ret = board_i2cdev_initialize(4);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "Failed to initialize I2C4.\n");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_MX8MP_I2C5
|
||||||
|
ret = board_i2cdev_initialize(5);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "Failed to initialize I2C5.\n");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_MX8MP_I2C6
|
||||||
|
ret = board_i2cdev_initialize(6);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "Failed to initialize I2C6.\n");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* boards/arm/mx8mp/verdin-mx8mp/src/mx8mp_ina219.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 <syslog.h>
|
||||||
|
#include <debug.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <nuttx/spi/spi.h>
|
||||||
|
#include <nuttx/sensors/ina219.h>
|
||||||
|
|
||||||
|
#include "mx8mp_i2c.h"
|
||||||
|
#include "mx8mp_ina219.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* 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 busno)
|
||||||
|
{
|
||||||
|
struct i2c_master_s *i2c;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
sninfo("Initializing INA219!\n");
|
||||||
|
|
||||||
|
/* Initialize I2C */
|
||||||
|
|
||||||
|
i2c = mx8mp_i2cbus_initialize(busno);
|
||||||
|
if (!i2c)
|
||||||
|
{
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Then register the sensor */
|
||||||
|
|
||||||
|
ret = ina219_register("/dev/ina219", i2c, 0x40, 10000, 0x00);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: Error registering INA219\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* boards/arm/mx8mp/verdin-mx8mp/src/mx8mp_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 __BOARDS_ARM_MX8MP_MX8MP_VERDIN_INCLUDE_BOARD_H
|
||||||
|
#define __BOARDS_ARM_MX8MP_MX8MP_VERDIN_INCLUDE_BOARD_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:
|
||||||
|
* busno - The I2C bus number
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno value on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int board_ina219_initialize(int busno);
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __BOARDS_ARM_MX8MP_MX8MP_VERDIN_INCLUDE_BOARD_H */
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: xmc4_bringup
|
* Name: mx8mp_bringup
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Bring up board features
|
* Bring up board features
|
||||||
@@ -55,5 +55,15 @@
|
|||||||
|
|
||||||
int mx8mp_bringup(void);
|
int mx8mp_bringup(void);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: mx8mp_i2cdev_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Called to configure all i2c
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int mx8mp_i2cdev_initialize(void);
|
||||||
|
|
||||||
#endif /* __ASSEMBLY__ */
|
#endif /* __ASSEMBLY__ */
|
||||||
#endif /* __BOARDS_ARM_MX8MP_MX8MP_VERDIN_SRC_VERDIN_MX8MP_H */
|
#endif /* __BOARDS_ARM_MX8MP_MX8MP_VERDIN_SRC_VERDIN_MX8MP_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user