drivers/analog/lmp92001.c: Add support for the TI LMP92001 device.

This commit is contained in:
Gregory Nutt 2018-12-21 09:46:33 -06:00
parent baab6dd1bd
commit ebbfb225f6
8 changed files with 1764 additions and 12 deletions

View File

@ -126,6 +126,7 @@ config PGA11X_MULTIPLE
devid=SPIDEV_MUX(n).
endif # if ADC_PGA11X
endif # ADC
config COMP
@ -166,3 +167,15 @@ config OPAMP
default n
---help---
Select to enable support for Operational Amplifiers (OPAMPs).
config LMP92001
bool "LMP92001 support"
default n
select I2C
---help---
Enable driver support for the Texas Instruments LMP92001.
config LMP92001_I2C_FREQUENCY
int "LMP92001 I2C frequency"
default 400000
depends on LMP92001

View File

@ -52,6 +52,7 @@ endif
ifeq ($(CONFIG_DAC7571),y)
CSRCS += dac7571.c
endif
endif
# Check for COMP devices
@ -103,6 +104,10 @@ ifeq ($(CONFIG_ADC_LTC1867L),y)
endif
endif
ifeq ($(CONFIG_LMP92001),y)
CSRCS += lmp92001.c
endif
# Add analog driver build support (the nested if-then-else implements an OR)
ifeq ($(CONFIG_DAC),y)

View File

@ -283,7 +283,7 @@ static ssize_t dac_write(FAR struct file *filep, FAR const char *buffer, size_t
int msglen;
int ret = 0;
/* Interrupts must disabled throughout the following */
/* Interrupts must be disabled throughout the following */
flags = enter_critical_section();
@ -381,7 +381,7 @@ static ssize_t dac_write(FAR struct file *filep, FAR const char *buffer, size_t
}
/* We get here if there is space at the end of the FIFO. Add the new
* CAN message at the tail of the FIFO.
* DAC message at the tail of the FIFO.
*/
if (msglen == 5)

1562
drivers/analog/lmp92001.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@
*
* Derived from include/nuttx/can/can.h
*
* Copyright (C) 2008, 2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2008, 2009, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -57,6 +57,7 @@
#include <semaphore.h>
#include <nuttx/fs/fs.h>
#include <nuttx/spi/spi.h>
#include <nuttx/i2c/i2c_master.h>
/************************************************************************************
* Pre-processor Definitions
@ -258,6 +259,24 @@ int adc_register(FAR const char *path, FAR struct adc_dev_s *dev);
FAR struct adc_dev_s *up_ads1255initialize(FAR struct spi_dev_s *spi,
unsigned int devno);
/****************************************************************************
* Name: lmp92001_adc_initialize
*
* Description:
* Initialize ADC
*
* Input Parameters:
* I2C Port number
* Device address
*
* Returned Value:
* Valid LM92001 device structure reference on success; a NULL on failure
*
****************************************************************************/
FAR struct adc_dev_s *lmp92001_adc_initialize(FAR struct i2c_master_s *i2c,
uint8_t addr);
#if defined(__cplusplus)
}
#endif

View File

@ -8,7 +8,7 @@
*
* Derived from include/nuttx/can/can.h
*
* Copyright (C) 2008, 2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2008, 2009, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -88,7 +88,7 @@ struct dac_fifo_s
sem_t af_sem; /* Counting semaphore */
uint8_t af_head; /* Index to the head [IN] index in the circular buffer */
uint8_t af_tail; /* Index to the tail [OUT] index in the circular buffer */
/* Circular buffer of CAN messages */
/* Circular buffer of DAC messages */
struct dac_msg_s af_buffer[CONFIG_DAC_FIFOSIZE];
};
@ -212,6 +212,24 @@ FAR struct dac_dev_s *up_ad5410initialize(FAR struct spi_dev_s *spi, unsigned in
FAR struct dac_dev_s *dac7571_initialize(FAR struct i2c_master_s *i2c, uint8_t addr);
/****************************************************************************
* Name: lmp92001_dac_initialize
*
* Description:
* Initialize DAC
*
* Input Parameters:
* I2C Port number
* Device address
*
* Returned Value:
* Valid LM92001 device structure reference on success; a NULL on failure
*
****************************************************************************/
FAR struct dac_dev_s *lmp92001_dac_initialize(FAR struct i2c_master_s *i2c,
uint8_t addr);
#if defined(__cplusplus)
}
#endif

View File

@ -80,6 +80,11 @@
#define AN_ADS2142_FIRST (AN_FIRST + AN_NCMDS)
#define AN_ADS2142_NCMDS 6
/* See include/nuttx/analog/lm92001.h */
#define AN_LMP92001_FIRST (AN_FIRST + AN_NCMDS + AN_ADS2142_NCMDS)
#define AN_LMP92001_NCMDS 7
/****************************************************************************
* Public Function Prototypes
****************************************************************************/

View File

@ -0,0 +1,130 @@
/****************************************************************************
* include/nuttx/analog/lmp92001.h
*
* Copyright (C) 2018 Abdelatif Guettouche. All rights reserved.
* Author: Abdelatif Guettouche <abdelatif.guettouche@gmail.com>
*
* This file is a part of NuttX:
*
* Copyright (C) 2010 Gregory Nutt. All rights reserved.
*
* 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.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_ANALOG_LMP92001_H
#define __INCLUDE_NUTTX_ANALOG_LMP92001_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/analog/ioctl.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* IOCTL Commands ***********************************************************/
/* Cmd: ANIOC_LMP92001_DAC_SET_REF Arg: bool value
* Cmd: ANIOC_LMP92001_DAC_UPDATEALL Arg: uint16_t value
* Cmd: ANIOC_LMP92001_ADC_SET_REF Arg: bool value
* Cmd: ANIOC_LMP92001_ADC_ENABLE Arg: lmp92001_adc_enable_e channel
* Cmd: ANIOC_LMP92001_ADC_SINGLESHOT_CONV Arg: none
* Cmd: ANIOC_LMP92001_ADC_CONTINUOUS_CONV Arg: none
* Cmd: ANIOC_LMP92001_ADC_READ_CHANNEL Arg: struct adc_msg_s *channel
*/
#define ANIOC_LMP92001_DAC_SET_REF _ANIOC(AN_LMP92001_FIRST + 0)
#define ANIOC_LMP92001_DAC_UPDATEALL _ANIOC(AN_LMP92001_FIRST + 1)
#define ANIOC_LMP92001_ADC_SET_REF _ANIOC(AN_LMP92001_FIRST + 2)
#define ANIOC_LMP92001_ADC_ENABLE _ANIOC(AN_LMP92001_FIRST + 3)
#define ANIOC_LMP92001_ADC_SINGLESHOT_CONV _ANIOC(AN_LMP92001_FIRST + 4)
#define ANIOC_LMP92001_ADC_CONTINUOUS_CONV _ANIOC(AN_LMP92001_FIRST + 5)
#define ANIOC_LMP92001_ADC_READ_CHANNEL _ANIOC(AN_LMP92001_FIRST + 6)
/****************************************************************************
* Public Types
****************************************************************************/
enum lmp92001_ref_e
{
LMP92001_REF_INTERNAL = 0U,
LMP92001_REF_EXTERNAL
};
enum lmp92001_adc_enable_e
{
LMP92001_ADC_EN_CH1 = 1 << 0U,
LMP92001_ADC_EN_CH2 = 1 << 1U,
LMP92001_ADC_EN_CH3 = 1 << 2U,
LMP92001_ADC_EN_CH4 = 1 << 3U,
LMP92001_ADC_EN_CH5 = 1 << 4U,
LMP92001_ADC_EN_CH6 = 1 << 5U,
LMP92001_ADC_EN_CH7 = 1 << 6U,
LMP92001_ADC_EN_CH8 = 1 << 7U,
LMP92001_ADC_EN_CH9 = 1 << 8U,
LMP92001_ADC_EN_CH10 = 1 << 9U,
LMP92001_ADC_EN_CH11 = 1 << 10U,
LMP92001_ADC_EN_CH12 = 1 << 11U,
LMP92001_ADC_EN_CH13 = 1 << 12U,
LMP92001_ADC_EN_CH14 = 1 << 13U,
LMP92001_ADC_EN_CH15 = 1 << 14U,
LMP92001_ADC_EN_CH16 = 1 << 15U,
LMP92001_ADC_EN_CH17 = 1 << 16U,
LMP92001_ADC_EN_ALL = 0x1FFFFU
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: lmp92001_gpio_initialize
*
* Description:
* Instantiate and configure the LMP92001 device driver to use the provided
* I2C device instance.
*
* Input Parameters:
* i2c - An I2C driver instance
* minor - The device i2c address
*
* Returned Value:
* An ioexpander_dev_s instance on success, NULL on failure.
*
****************************************************************************/
struct i2c_master_s; /* Forward reference */
struct ioexpander_dev_s; /* Forward reference */
FAR struct ioexpander_dev_s *
lmp92001_gpio_initialize(FAR struct i2c_master_s *i2c, uint8_t addr);
#endif /* __INCLUDE_NUTTX_ANALOG_LMP92001_H */