Added forward declarations of structures to fix header inclusion

order bugs.
Removed an unused variable.
Added debug asserts to check for invalid I2C addresses.
This commit is contained in:
Paul A. Patience 2015-08-10 14:59:11 -04:00
parent c0964a17b4
commit 65792c5dbc
14 changed files with 91 additions and 27 deletions

View File

@ -7,6 +7,7 @@ config AS5048B
bool "AMS AS5048B Magnetic Rotary Encoder support"
default n
select I2C
select QENCODER
---help---
Enable driver support for the AMS AS5048B magnetic rotary encoder.
@ -21,6 +22,7 @@ config LIS331DL
bool "ST LIS331DL device support"
default n
select I2C
select I2C_TRANSFER
config MPL115A
bool "Freescale MPL115A Barometer Sensor support"

View File

@ -46,6 +46,7 @@
#include <debug.h>
#include <nuttx/kmalloc.h>
#include <nuttx/i2c.h>
#include <nuttx/sensors/adxl345.h>
#include "adxl345.h"

View File

@ -46,6 +46,7 @@
#include <debug.h>
#include <nuttx/kmalloc.h>
#include <nuttx/spi/spi.h>
#include <nuttx/sensors/adxl345.h>
#include "adxl345.h"

View File

@ -46,8 +46,11 @@
#include <stdio.h>
#include <nuttx/kmalloc.h>
#include <nuttx/i2c.h>
#include <nuttx/sensors/lis331dl.h>
#if defined(CONFIG_I2C) && defined(CONFIG_I2C_TRANSFER) && defined(CONFIG_LIS331DL)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@ -373,3 +376,5 @@ lis331dl_getreadings(FAR struct lis331dl_dev_s * dev)
return NULL;
}
#endif /* CONFIG_I2C && CONFIG_I2C_TRANSFER && CONFIG_LIS331DL */

View File

@ -103,10 +103,10 @@ static const struct file_operations g_lm75fops =
lm75_close,
lm75_read,
lm75_write,
0,
NULL,
lm75_ioctl
#ifndef CONFIG_DISABLE_POLL
, 0
, NULL
#endif
};
@ -377,6 +377,7 @@ static int lm75_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
case SNIOC_READCONF:
{
FAR uint8_t *ptr = (FAR uint8_t *)((uintptr_t)arg);
DEBUGASSERT(ptr != NULL);
ret = lm75_readconf(priv, ptr);
sndbg("conf: %02x ret: %d\n", *ptr, ret);
}
@ -438,6 +439,7 @@ static int lm75_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
case SNIOC_READTHYS:
{
FAR b16_t *ptr = (FAR b16_t *)((uintptr_t)arg);
DEBUGASSERT(ptr != NULL);
ret = lm75_readb16(priv, LM75_THYS_REG, ptr);
sndbg("THYS: %08x ret: %d\n", *ptr, ret);
}
@ -455,6 +457,7 @@ static int lm75_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
case SNIOC_READTOS:
{
FAR b16_t *ptr = (FAR b16_t *)((uintptr_t)arg);
DEBUGASSERT(ptr != NULL);
ret = lm75_readb16(priv, LM75_TOS_REG, ptr);
sndbg("TOS: %08x ret: %d\n", *ptr, ret);
}
@ -503,10 +506,18 @@ int lm75_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, uint8_t ad
FAR struct lm75_dev_s *priv;
int ret;
/* Sanity check */
DEBUGASSERT(i2c != NULL);
DEBUGASSERT(addr == CONFIG_LM75_ADDR0 || addr == CONFIG_LM75_ADDR1 ||
addr == CONFIG_LM75_ADDR2 || addr == CONFIG_LM75_ADDR3 ||
addr == CONFIG_LM75_ADDR4 || addr == CONFIG_LM75_ADDR5 ||
addr == CONFIG_LM75_ADDR6 || addr == CONFIG_LM75_ADDR7);
/* Initialize the LM-75 device structure */
priv = (FAR struct lm75_dev_s *)kmm_malloc(sizeof(struct lm75_dev_s));
if (!priv)
if (priv == NULL)
{
sndbg("Failed to allocate instance\n");
return -ENOMEM;

View File

@ -107,10 +107,10 @@ static const struct file_operations g_lm92fops =
lm92_close,
lm92_read,
lm92_write,
0,
NULL,
lm92_ioctl
#ifndef CONFIG_DISABLE_POLL
, 0
, NULL
#endif
};
@ -423,6 +423,7 @@ static int lm92_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
case SNIOC_READCONF:
{
FAR uint8_t *ptr = (FAR uint8_t *)((uintptr_t)arg);
DEBUGASSERT(ptr != NULL);
ret = lm92_readconf(priv, ptr);
sndbg("conf: %02x ret: %d\n", *ptr, ret);
}
@ -484,6 +485,7 @@ static int lm92_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
case SNIOC_READTHYS:
{
FAR b16_t *ptr = (FAR b16_t *)((uintptr_t)arg);
DEBUGASSERT(ptr != NULL);
ret = lm92_readb16(priv, LM92_THYS_REG, ptr);
sndbg("THYS: %08x ret: %d\n", *ptr, ret);
}
@ -501,6 +503,7 @@ static int lm92_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
case SNIOC_READTCRIT:
{
FAR b16_t *ptr = (FAR b16_t *)((uintptr_t)arg);
DEBUGASSERT(ptr != NULL);
ret = lm92_readb16(priv, LM92_TCRIT_REG, ptr);
sndbg("TCRIT: %08x ret: %d\n", *ptr, ret);
}
@ -518,6 +521,7 @@ static int lm92_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
case SNIOC_READTLOW:
{
FAR b16_t *ptr = (FAR b16_t *)((uintptr_t)arg);
DEBUGASSERT(ptr != NULL);
ret = lm92_readb16(priv, LM92_TLOW_REG, ptr);
sndbg("TLOW: %08x ret: %d\n", *ptr, ret);
}
@ -535,6 +539,7 @@ static int lm92_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
case SNIOC_READTHIGH:
{
FAR b16_t *ptr = (FAR b16_t *)((uintptr_t)arg);
DEBUGASSERT(ptr != NULL);
ret = lm92_readb16(priv, LM92_THIGH_REG, ptr);
sndbg("THIGH: %08x ret: %d\n", *ptr, ret);
}
@ -552,6 +557,7 @@ static int lm92_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
case SNIOC_READID:
{
FAR uint16_t *ptr = (FAR uint16_t *)((uintptr_t)arg);
DEBUGASSERT(ptr != NULL);
ret = lm92_readid(priv, ptr);
sndbg("id: %04x ret: %d\n", *ptr, ret);
}
@ -595,10 +601,16 @@ int lm92_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c,
FAR struct lm92_dev_s *priv;
int ret;
/* Sanity check */
DEBUGASSERT(i2c != NULL);
DEBUGASSERT(addr == CONFIG_LM92_ADDR0 || addr == CONFIG_LM92_ADDR1 ||
addr == CONFIG_LM92_ADDR2 || addr == CONFIG_LM92_ADDR3);
/* Initialize the LM92 device structure */
priv = (FAR struct lm92_dev_s *)kmm_malloc(sizeof(struct lm92_dev_s));
if (!priv)
if (priv == NULL)
{
sndbg("Failed to allocate instance\n");
return -ENOMEM;

View File

@ -212,8 +212,6 @@ static void mpl115a_updatecaldata(FAR struct mpl115a_dev_s *priv)
static void mpl115a_read_press_temp(FAR struct mpl115a_dev_s *priv)
{
uint16_t pressure;
/* Start a new conversion */
mpl115a_getreg8(priv, (MPL115A_CONVERT << 1));

View File

@ -41,10 +41,6 @@
********************************************************************************************/
#include <nuttx/config.h>
#include <nuttx/i2c.h>
#include <nuttx/spi/spi.h>
#include <nuttx/irq.h>
#if defined(CONFIG_SENSORS_ADXL345)
@ -329,6 +325,9 @@ struct adxl345_config_s
typedef FAR void *ADXL345_HANDLE;
struct i2c_dev_s;
struct spi_dev_s;
/********************************************************************************************
* Public Function Prototypes
********************************************************************************************/

View File

@ -41,8 +41,6 @@
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/i2c.h>
#include <nuttx/sensors/qencoder.h>
#if defined(CONFIG_I2C) && defined(CONFIG_QENCODER) && defined(CONFIG_AS5048B)
@ -97,6 +95,12 @@
#define AS5048B_DIAG_COMPLOW (1 << 2) /* High Magnetic Field */
#define AS5048B_DIAG_COMPHIGH (1 << 3) /* Low Magnetic Field */
/****************************************************************************
* Public Types
****************************************************************************/
struct i2c_dev_s;
/****************************************************************************
* Public Function Prototypes
****************************************************************************/

View File

@ -36,7 +36,9 @@
#ifndef __DRIVERS_SENSORS_BMP180_H
#define __DRIVERS_SENSORS_BMP180_H
#if defined(CONFIG_BMP180)
#include <nuttx/config.h>
#if defined(CONFIG_I2C) && defined(CONFIG_BMP180)
/********************************************************************************************
* Pre-processor Definitions
@ -53,6 +55,12 @@
* Enable very low register-level debug output. Requires CONFIG_DEBUG.
*/
/****************************************************************************
* Public Types
****************************************************************************/
struct i2c_dev_s;
/********************************************************************************************
* Public Function Prototypes
********************************************************************************************/
@ -88,5 +96,5 @@ int bmp180_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c);
}
#endif
#endif /* CONFIG_BMP180 */
#endif /* CONFIG_I2C && CONFIG_BMP180 */
#endif /* __DRIVERS_BMP180_H */

View File

@ -38,9 +38,11 @@
#ifndef __INCLUDE_NUTTX_SENSORS_LIS331DL_H
#define __INCLUDE_NUTTX_SENSORS_LIS331DL_H
#include <nuttx/i2c.h>
#include <nuttx/config.h>
#include <stdbool.h>
#if defined(CONFIG_I2C) && defined(CONFIG_I2C_TRANSFER) && defined(CONFIG_LIS331DL)
/************************************************************************************
* Pre-Processor Declarations
************************************************************************************/
@ -69,6 +71,8 @@ struct lis331dl_vector_s
int8_t z;
};
struct i2c_dev_s;
/************************************************************************************
* Public Function Prototypes
************************************************************************************/
@ -204,4 +208,5 @@ FAR const struct lis331dl_vector_s *
#endif
#endif /* __ASSEMBLY__ */
#endif /* CONFIG_I2C && CONFIG_I2C_TRANSFER && CONFIG_LIS331DL */
#endif /* __INCLUDE_NUTTX_SENSORS_LIS331DL_H */

View File

@ -43,6 +43,8 @@
#include <nuttx/config.h>
#include <nuttx/fs/ioctl.h>
#if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@ -52,6 +54,14 @@
*/
#define CONFIG_LM75_BASEADDR 0x48
#define CONFIG_LM75_ADDR0 (CONFIG_LM75_BASEADDR + 0)
#define CONFIG_LM75_ADDR1 (CONFIG_LM75_BASEADDR + 1)
#define CONFIG_LM75_ADDR2 (CONFIG_LM75_BASEADDR + 2)
#define CONFIG_LM75_ADDR3 (CONFIG_LM75_BASEADDR + 3)
#define CONFIG_LM75_ADDR4 (CONFIG_LM75_BASEADDR + 4)
#define CONFIG_LM75_ADDR5 (CONFIG_LM75_BASEADDR + 5)
#define CONFIG_LM75_ADDR6 (CONFIG_LM75_BASEADDR + 6)
#define CONFIG_LM75_ADDR7 (CONFIG_LM75_BASEADDR + 7)
/* IOCTL Commands ***********************************************************/
@ -86,12 +96,10 @@
*/
/****************************************************************************
* Public Data
* Public Types
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
struct i2c_dev_s;
/****************************************************************************
* Public Function Prototypes
@ -131,4 +139,5 @@ int lm75_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c,
}
#endif
#endif /* CONFIG_I2C && CONFIG_I2C_LM75 */
#endif /* __INCLUDE_NUTTX_SENSORS_LM75_H */

View File

@ -45,6 +45,8 @@
#include <nuttx/config.h>
#include <nuttx/fs/ioctl.h>
#if defined(CONFIG_I2C) && defined(CONFIG_LM92)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@ -101,12 +103,10 @@
*/
/****************************************************************************
* Public Data
* Public Types
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
struct i2c_dev_s;
/****************************************************************************
* Public Function Prototypes
@ -147,4 +147,5 @@ int lm92_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c,
}
#endif
#endif /* CONFIG_I2C && CONFIG_LM92 */
#endif /* __INCLUDE_NUTTX_SENSORS_LM92_H */

View File

@ -36,7 +36,9 @@
#ifndef __DRIVERS_SENSORS_MPL115A_H
#define __DRIVERS_SENSORS_MPL115A_H
#if defined(CONFIG_MPL115A)
#include <nuttx/config.h>
#if defined(CONFIG_SPI) && defined(CONFIG_MPL115A)
/********************************************************************************************
* Pre-processor Definitions
@ -83,6 +85,12 @@
/* 0x0c - 0x11 are reserved */
#define MPL115A_CONVERT 0x12 /* Start Pressure and Temperature Conversion */
/********************************************************************************************
* Public Types
********************************************************************************************/
struct spi_dev_s;
/********************************************************************************************
* Public Function Prototypes
********************************************************************************************/
@ -118,5 +126,5 @@ int mpl115a_register(FAR const char *devpath, FAR struct spi_dev_s *spi);
}
#endif
#endif /* CONFIG_SENSORS_MPL115A */
#endif /* CONFIG_SPI && CONFIG_MPL115A */
#endif /* __DRIVERS_SENSORS_MPL115A_H */