diff --git a/drivers/sensors/Kconfig b/drivers/sensors/Kconfig index 19bdedae26d..fbb7118b853 100644 --- a/drivers/sensors/Kconfig +++ b/drivers/sensors/Kconfig @@ -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" diff --git a/drivers/sensors/adxl345_i2c.c b/drivers/sensors/adxl345_i2c.c index fb2c7861353..9b905b7b970 100644 --- a/drivers/sensors/adxl345_i2c.c +++ b/drivers/sensors/adxl345_i2c.c @@ -46,6 +46,7 @@ #include #include +#include #include #include "adxl345.h" diff --git a/drivers/sensors/adxl345_spi.c b/drivers/sensors/adxl345_spi.c index 2f3b4894fbc..a87765e8193 100644 --- a/drivers/sensors/adxl345_spi.c +++ b/drivers/sensors/adxl345_spi.c @@ -46,6 +46,7 @@ #include #include +#include #include #include "adxl345.h" diff --git a/drivers/sensors/lis331dl.c b/drivers/sensors/lis331dl.c index ec44a72868b..10cf8d360a8 100644 --- a/drivers/sensors/lis331dl.c +++ b/drivers/sensors/lis331dl.c @@ -46,8 +46,11 @@ #include #include +#include #include +#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 */ diff --git a/drivers/sensors/lm75.c b/drivers/sensors/lm75.c index e11e3f725fc..7c47f867102 100644 --- a/drivers/sensors/lm75.c +++ b/drivers/sensors/lm75.c @@ -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; diff --git a/drivers/sensors/lm92.c b/drivers/sensors/lm92.c index 618b3d32902..f2fa27f65b9 100644 --- a/drivers/sensors/lm92.c +++ b/drivers/sensors/lm92.c @@ -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; diff --git a/drivers/sensors/mpl115a.c b/drivers/sensors/mpl115a.c index a5b940ab7b4..f3d1bff907c 100644 --- a/drivers/sensors/mpl115a.c +++ b/drivers/sensors/mpl115a.c @@ -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)); diff --git a/include/nuttx/sensors/adxl345.h b/include/nuttx/sensors/adxl345.h index 4e806d5ea02..9655e84f69e 100644 --- a/include/nuttx/sensors/adxl345.h +++ b/include/nuttx/sensors/adxl345.h @@ -41,10 +41,6 @@ ********************************************************************************************/ #include - -#include -#include - #include #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 ********************************************************************************************/ diff --git a/include/nuttx/sensors/as5048b.h b/include/nuttx/sensors/as5048b.h index b28c86ae7ce..6a6de4eef02 100644 --- a/include/nuttx/sensors/as5048b.h +++ b/include/nuttx/sensors/as5048b.h @@ -41,8 +41,6 @@ ****************************************************************************/ #include -#include -#include #include #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 ****************************************************************************/ diff --git a/include/nuttx/sensors/bmp180.h b/include/nuttx/sensors/bmp180.h index 668ce62815f..505aa724888 100644 --- a/include/nuttx/sensors/bmp180.h +++ b/include/nuttx/sensors/bmp180.h @@ -36,7 +36,9 @@ #ifndef __DRIVERS_SENSORS_BMP180_H #define __DRIVERS_SENSORS_BMP180_H -#if defined(CONFIG_BMP180) +#include + +#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 */ diff --git a/include/nuttx/sensors/lis331dl.h b/include/nuttx/sensors/lis331dl.h index 2025e82952a..60062884636 100644 --- a/include/nuttx/sensors/lis331dl.h +++ b/include/nuttx/sensors/lis331dl.h @@ -38,9 +38,11 @@ #ifndef __INCLUDE_NUTTX_SENSORS_LIS331DL_H #define __INCLUDE_NUTTX_SENSORS_LIS331DL_H -#include +#include #include +#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 */ diff --git a/include/nuttx/sensors/lm75.h b/include/nuttx/sensors/lm75.h index 75f8d95f02e..a343a54874a 100644 --- a/include/nuttx/sensors/lm75.h +++ b/include/nuttx/sensors/lm75.h @@ -43,6 +43,8 @@ #include #include +#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 */ diff --git a/include/nuttx/sensors/lm92.h b/include/nuttx/sensors/lm92.h index d0fcea8fec4..16266568a88 100644 --- a/include/nuttx/sensors/lm92.h +++ b/include/nuttx/sensors/lm92.h @@ -45,6 +45,8 @@ #include #include +#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 */ diff --git a/include/nuttx/sensors/mpl115a.h b/include/nuttx/sensors/mpl115a.h index 9aa60495732..c958c8025df 100644 --- a/include/nuttx/sensors/mpl115a.h +++ b/include/nuttx/sensors/mpl115a.h @@ -36,7 +36,9 @@ #ifndef __DRIVERS_SENSORS_MPL115A_H #define __DRIVERS_SENSORS_MPL115A_H -#if defined(CONFIG_MPL115A) +#include + +#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 */