mirror of
https://github.com/apache/nuttx.git
synced 2026-09-27 18:58:27 +08:00
drivers/sensors: Add driver for the MLX90393 3 axis magnetometer.
This commit is contained in:
committed by
Gregory Nutt
parent
338bf8c9e3
commit
b29287b022
@@ -75,6 +75,13 @@ config MB7040_I2C_FREQUENCY
|
|||||||
range 1 400000
|
range 1 400000
|
||||||
depends on MB7040
|
depends on MB7040
|
||||||
|
|
||||||
|
config MLX90393
|
||||||
|
bool "MLX90393 3-Axis Magnetometer"
|
||||||
|
default n
|
||||||
|
select SPI
|
||||||
|
---help---
|
||||||
|
Enable driver support for the Melex MLX90393 3-Axis magnetometer.
|
||||||
|
|
||||||
config MCP9844
|
config MCP9844
|
||||||
bool "MCP9844 Temperature Sensor"
|
bool "MCP9844 Temperature Sensor"
|
||||||
default n
|
default n
|
||||||
|
|||||||
@@ -89,6 +89,10 @@ ifeq ($(CONFIG_MCP9844),y)
|
|||||||
CSRCS += mcp9844.c
|
CSRCS += mcp9844.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_MLX90393),y)
|
||||||
|
CSRCS += mlx90393.c
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_MS58XX),y)
|
ifeq ($(CONFIG_MS58XX),y)
|
||||||
CSRCS += ms58xx.c
|
CSRCS += ms58xx.c
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -352,10 +352,10 @@ static int lis3mdl_interrupt_handler(int irq, FAR void *context)
|
|||||||
|
|
||||||
DEBUGASSERT(priv->work.worker == NULL);
|
DEBUGASSERT(priv->work.worker == NULL);
|
||||||
ret = work_queue(HPWORK, &priv->work, lis3mdl_worker, priv, 0);
|
ret = work_queue(HPWORK, &priv->work, lis3mdl_worker, priv, 0);
|
||||||
if (ret != 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
snerr("Failed to queue work: %d\n", ret);
|
snerr("Failed to queue work: %d\n", ret);
|
||||||
return ERROR;
|
return ret;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -435,8 +435,9 @@ static int lis3mdl_open(FAR struct file *filep)
|
|||||||
/* Read back the content of all control registers for debug purposes */
|
/* Read back the content of all control registers for debug purposes */
|
||||||
|
|
||||||
reg_content = 0;
|
reg_content = 0;
|
||||||
eg_addr = LIS3MDL_CTRL_REG_1;
|
for (reg_addr = LIS3MDL_CTRL_REG_1;
|
||||||
for (; reg_addr <= LIS3MDL_CTRL_REG_5; reg_addr++)
|
reg_addr <= LIS3MDL_CTRL_REG_5;
|
||||||
|
reg_addr++)
|
||||||
{
|
{
|
||||||
lis3mdl_read_register(priv, reg_addr, ®_content);
|
lis3mdl_read_register(priv, reg_addr, ®_content);
|
||||||
snerr("R#%04x = %04x\n", reg_addr, reg_content);
|
snerr("R#%04x = %04x\n", reg_addr, reg_content);
|
||||||
@@ -469,6 +470,7 @@ static int lis3mdl_close(FAR struct file *filep)
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: lis3mdl_read
|
* Name: lis3mdl_read
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static ssize_t lis3mdl_read(FAR struct file *filep, FAR char *buffer,
|
static ssize_t lis3mdl_read(FAR struct file *filep, FAR char *buffer,
|
||||||
size_t buflen)
|
size_t buflen)
|
||||||
{
|
{
|
||||||
@@ -490,10 +492,10 @@ static ssize_t lis3mdl_read(FAR struct file *filep, FAR char *buffer,
|
|||||||
/* Aquire the semaphore before the data is copied */
|
/* Aquire the semaphore before the data is copied */
|
||||||
|
|
||||||
ret = sem_wait(&priv->datasem);
|
ret = sem_wait(&priv->datasem);
|
||||||
if (ret != OK)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
snerr("Could not aquire priv->datasem: %d\n", ret);
|
snerr("Could not aquire priv->datasem: %d\n", ret);
|
||||||
return ERROR;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the sensor data into the buffer */
|
/* Copy the sensor data into the buffer */
|
||||||
@@ -556,8 +558,10 @@ static int lis3mdl_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
|||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* devpath - The full path to the driver to register. E.g., "/dev/mag0"
|
* devpath - The full path to the driver to register. E.g., "/dev/mag0"
|
||||||
* spi - An instance of the SPI interface to use to communicate with LIS3MDL
|
* spi - An instance of the SPI interface to use to communicate with
|
||||||
* config - configuration for the LIS3MDL driver. For details see description above.
|
* LIS3MDL
|
||||||
|
* config - configuration for the LIS3MDL driver. For details see
|
||||||
|
* description above.
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Zero (OK) on success; a negated errno value on failure.
|
* Zero (OK) on success; a negated errno value on failure.
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -158,8 +158,10 @@ extern "C"
|
|||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* devpath - The full path to the driver to register. E.g., "/dev/mag0"
|
* devpath - The full path to the driver to register. E.g., "/dev/mag0"
|
||||||
* spi - An instance of the SPI interface to use to communicate with LIS3MDL
|
* spi - An instance of the SPI interface to use to communicate with
|
||||||
* config - configuration for the LIS3MDL driver. For details see description above.
|
* LIS3MDL
|
||||||
|
* config - configuration for the LIS3MDL driver. For details see
|
||||||
|
* description above.
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Zero (OK) on success; a negated errno value on failure.
|
* Zero (OK) on success; a negated errno value on failure.
|
||||||
|
|||||||
@@ -0,0 +1,153 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* include/nuttx/sensors/mlx90393.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2016 DS-Automotion GmbH. All rights reserved.
|
||||||
|
* Author: Alexander Entinger <a.entinger@ds-automotion.com>
|
||||||
|
*
|
||||||
|
* 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 NUTTX_INCLUDE_NUTTX_SENSORS_MLX90393_H_
|
||||||
|
#define NUTTX_INCLUDE_NUTTX_SENSORS_MLX90393_H_
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/irq.h>
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <nuttx/fs/ioctl.h>
|
||||||
|
#include <nuttx/spi/spi.h>
|
||||||
|
|
||||||
|
#if defined(CONFIG_SPI) && defined(CONFIG_MLX90393)
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* MLX90393 Command Definitions *********************************************/
|
||||||
|
|
||||||
|
#define MLX90393_SB (0x10) /* SB = Start Burst Mode */
|
||||||
|
#define MLX90393_SW (0x20) /* SW = Start Wake-up on Change Mode */
|
||||||
|
#define MLX90393_SM (0x30) /* SB = Start Single Measurement Mode */
|
||||||
|
#define MLX90393_RM (0x40) /* RM = Read Measurement */
|
||||||
|
#define MLX90393_RR (0x50) /* RR = Read Register */
|
||||||
|
#define MLX90393_WR (0x60) /* WR = Write Register */
|
||||||
|
#define MLX90393_EX (0x80) /* EX = Exit Mode */
|
||||||
|
#define MLX90393_HR (0xD0) /* HR = Memory Recall */
|
||||||
|
#define MLX90393_HS (0xE0) /* HS = Memory Store */
|
||||||
|
#define MLX90393_RT (0xF0) /* RT = Reset */
|
||||||
|
|
||||||
|
/* MLX90393 Sensor Selection Bit Definitions ********************************/
|
||||||
|
|
||||||
|
#define MLX90393_T_bm (1<<0) /* Temperature Sensor Bitmask */
|
||||||
|
#define MLX90393_X_bm (1<<1) /* Magnetometer X-Axis Bitmask */
|
||||||
|
#define MLX90393_Y_bm (1<<2) /* Magnetometer Y-Axis Bitmask */
|
||||||
|
#define MLX90393_Z_bm (1<<3) /* Magnetometer Z-Axis Bitmask */
|
||||||
|
#define MLX90393_ZYXT_bm (MLX90393_Z_bm | MLX90393_Y_bm | MLX90393_X_bm | MLX90393_T_bm)
|
||||||
|
|
||||||
|
/* SPI BUS PARAMETERS *******************************************************/
|
||||||
|
|
||||||
|
#define MLX90393_SPI_FREQUENCY (1000000) /* 1 MHz */
|
||||||
|
#define MLX90393_SPI_MODE (SPIDEV_MODE3) /* Device uses SPI Mode 3: CPOL=1, CPHA=1 */
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* A reference to a structure of this type must be passed to the MLX90393
|
||||||
|
* driver. This structure provides information about the configuration
|
||||||
|
* of the sensor and provides some board-specific hooks.
|
||||||
|
*
|
||||||
|
* Memory for this structure is provided by the caller. It is not copied
|
||||||
|
* by the driver and is presumed to persist while the driver is active.
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct mlx90393_config_s
|
||||||
|
{
|
||||||
|
/* Since multiple MLX90393 can be connected to the same SPI bus we need
|
||||||
|
* to use multiple spi device ids which are employed by NuttX to select/
|
||||||
|
* deselect the desired MLX90393 chip via their chip select inputs.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int spi_devid;
|
||||||
|
|
||||||
|
/* The IRQ number must be provided for each so MLX90393 device so that
|
||||||
|
* their interrupts can be distinguished.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int irq;
|
||||||
|
|
||||||
|
/* Attach the MLX90393 interrupt handler to the GPIO interrupt of the
|
||||||
|
* concrete MLX90393 instance.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int (*attach)(FAR struct mlx90393_config_s *, xcpt_t);
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: mlx90393_register
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Register the MLX90393 character device as 'devpath'
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* devpath - The full path to the driver to register. E.g., "/dev/mag0"
|
||||||
|
* spi - An instance of the SPI interface to use to communicate with
|
||||||
|
* MLX90393
|
||||||
|
* config - Describes the configuration of the MLX90393 part.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno value on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int mlx90393_register(FAR const char *devpath, FAR struct spi_dev_s *spi,
|
||||||
|
FAR struct mlx90393_config_s *config);
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CONFIG_SPI && CONFIG_MLX90393 */
|
||||||
|
|
||||||
|
#endif /* NUTTX_INCLUDE_NUTTX_SENSORS_MLX90393_H_ */
|
||||||
Reference in New Issue
Block a user