2011-04-03 22:26:05 +08:00
|
|
|
/****************************************************************************
|
2011-05-08 03:22:15 +08:00
|
|
|
* include/nuttx/sensors/lis331dl.h
|
2011-04-03 22:26:05 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Uros Platise. All rights reserved.
|
|
|
|
*
|
|
|
|
* Authors: Uros Platise <uros.platise@isotel.eu>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* \author Uros Platise
|
|
|
|
* \brief ST LIS331DL I2C Device Driver
|
|
|
|
**/
|
|
|
|
|
2011-05-08 03:22:15 +08:00
|
|
|
#ifndef __INCLUDE_NUTTX_SENSORS_LIS331DL_H
|
|
|
|
#define __INCLUDE_NUTTX_SENSORS_LIS331DL_H
|
2011-04-03 22:26:05 +08:00
|
|
|
|
2011-04-20 02:51:02 +08:00
|
|
|
#include <nuttx/i2c.h>
|
2011-04-03 22:26:05 +08:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
/************************************************************************************
|
|
|
|
* Pre-Processor Declarations
|
|
|
|
************************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define EXTERN extern "C"
|
|
|
|
extern "C" {
|
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************************
|
|
|
|
* Public Data Types
|
|
|
|
************************************************************************************/
|
|
|
|
|
2011-05-08 03:22:15 +08:00
|
|
|
struct lis331dl_dev_s;
|
2011-04-03 22:26:05 +08:00
|
|
|
|
2011-05-08 03:22:15 +08:00
|
|
|
struct lis331dl_vector_s {
|
2011-04-03 22:26:05 +08:00
|
|
|
int8_t x, y, z;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************************
|
|
|
|
* Public Function Prototypes
|
|
|
|
************************************************************************************/
|
|
|
|
|
|
|
|
/** Initialize ST LIS331DL Chip
|
|
|
|
*
|
|
|
|
* \param i2c I2C Device Structure
|
|
|
|
* \param address I2C Address of the proposed device
|
|
|
|
* \return Pointer to newly allocated ST LIS331DL structure or NULL on error with errno set.
|
|
|
|
*
|
|
|
|
* Possible errno as set by this function on error:
|
|
|
|
* - ENODEV: When device addressed on given address is not compatible or it is not a LIS331DL
|
|
|
|
* - EFAULT: When there is no device at given address.
|
|
|
|
* - EBUSY: When device is already addressed by other device driver (not yet supported by low-level driver)
|
|
|
|
**/
|
2011-05-08 03:22:15 +08:00
|
|
|
EXTERN struct lis331dl_dev_s * lis331dl_init(struct i2c_dev_s * i2c, uint16_t address);
|
2011-04-03 22:26:05 +08:00
|
|
|
|
|
|
|
/** Deinitialize ST LIS331DL Chip
|
|
|
|
*
|
2011-05-08 03:22:15 +08:00
|
|
|
* \param dev Device to LIS331DL device structure, as returned by the lis331dl_init()
|
2011-04-03 22:26:05 +08:00
|
|
|
* \return OK On success
|
|
|
|
*
|
|
|
|
**/
|
2011-05-08 03:22:15 +08:00
|
|
|
EXTERN int lis331dl_deinit(struct lis331dl_dev_s * dev);
|
2011-04-03 22:26:05 +08:00
|
|
|
|
|
|
|
/** Power up device, start conversion */
|
2011-05-08 03:22:15 +08:00
|
|
|
EXTERN int lis331dl_powerup(struct lis331dl_dev_s * dev);
|
2011-04-03 22:26:05 +08:00
|
|
|
|
|
|
|
/** Power down device, stop conversion */
|
2011-05-08 03:22:15 +08:00
|
|
|
EXTERN int lis331dl_powerdown(struct lis331dl_dev_s * dev);
|
2011-04-03 22:26:05 +08:00
|
|
|
|
|
|
|
/** Configure conversion
|
|
|
|
*
|
|
|
|
* \param dev Device to LIS331DL device structure
|
|
|
|
* \param full When set, range of [-9g, 9g] is selected, otherwise [-2g, +2g]
|
|
|
|
* \param fast When set, conversion operates at 400 Hz, otherwise at 100 Hz
|
|
|
|
* \return OK on success or errno is set
|
|
|
|
**/
|
2011-05-08 03:22:15 +08:00
|
|
|
EXTERN int lis331dl_setconversion(struct lis331dl_dev_s * dev, bool full, bool fast);
|
2011-04-03 22:26:05 +08:00
|
|
|
|
|
|
|
/** Get precision
|
|
|
|
*
|
2011-04-06 00:25:04 +08:00
|
|
|
* \return Precision of 1 LSB in terms of unit [mg]
|
2011-04-03 22:26:05 +08:00
|
|
|
**/
|
2011-05-08 03:22:15 +08:00
|
|
|
EXTERN int lis331dl_getprecision(struct lis331dl_dev_s * dev);
|
2011-04-03 22:26:05 +08:00
|
|
|
|
|
|
|
/** Get sample rate
|
|
|
|
*
|
|
|
|
* \return Sample rate in unit of [Hz]
|
|
|
|
**/
|
2011-05-08 03:22:15 +08:00
|
|
|
EXTERN int lis331dl_getsamplerate(struct lis331dl_dev_s * dev);
|
2011-04-03 22:26:05 +08:00
|
|
|
|
|
|
|
/** Get readings, updates internal data structure
|
|
|
|
*
|
|
|
|
* \param dev Device to LIS331DL device structure
|
2011-04-06 00:25:04 +08:00
|
|
|
* \return Ptr to vector acceleration [x,y,z] on success, or NULL on error with errno set.
|
|
|
|
* If data is not yet ready to be read from the LIS331 then errno is set to EAGAIN otherwise
|
|
|
|
* errno is set by I2C_TRANSFER().
|
2011-04-03 22:26:05 +08:00
|
|
|
*/
|
2011-05-08 03:22:15 +08:00
|
|
|
EXTERN const struct lis331dl_vector_s * lis331dl_getreadings(struct lis331dl_dev_s * dev);
|
2011-04-03 22:26:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __ASSEMBLY__ */
|
2011-05-08 03:22:15 +08:00
|
|
|
#endif /* __INCLUDE_NUTTX_SENSORS_LIS331DL_H */
|