2021-03-04 08:02:21 +01:00
|
|
|
/****************************************************************************
|
2016-09-16 20:45:53 +02:00
|
|
|
* drivers/sensors/xen1210.h
|
|
|
|
*
|
2021-03-13 10:55:07 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2016-09-16 20:45:53 +02:00
|
|
|
*
|
2021-03-13 10:55:07 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-09-16 20:45:53 +02:00
|
|
|
*
|
2021-03-13 10:55:07 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2016-09-16 20:45:53 +02:00
|
|
|
*
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
2016-09-16 20:45:53 +02:00
|
|
|
|
|
|
|
#ifndef __DRIVERS_SENSORS_XEN1210_H
|
|
|
|
#define __DRIVERS_SENSORS_XEN1210_H
|
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/****************************************************************************
|
2016-09-16 20:45:53 +02:00
|
|
|
* Included Files
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
2016-09-16 20:45:53 +02:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <nuttx/wdog.h>
|
|
|
|
#include <nuttx/clock.h>
|
|
|
|
#include <nuttx/wqueue.h>
|
2020-02-01 08:17:32 +01:00
|
|
|
#include <nuttx/semaphore.h>
|
2016-09-16 20:45:53 +02:00
|
|
|
#include <nuttx/sensors/xen1210.h>
|
|
|
|
|
2017-08-24 18:26:53 +02:00
|
|
|
#if defined(CONFIG_SENSORS_XEN1210)
|
2016-09-16 20:45:53 +02:00
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/****************************************************************************
|
2016-09-16 20:45:53 +02:00
|
|
|
* Pre-processor Definitions
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
2016-09-16 20:45:53 +02:00
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/* Driver support ***********************************************************/
|
|
|
|
|
|
|
|
/* This format is used to construct the /dev/mag[n] device driver path.
|
|
|
|
* It is defined here so that it will be used consistently in all places.
|
2016-09-16 20:45:53 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define DEV_FORMAT "/dev/mag%d"
|
|
|
|
#define DEV_NAMELEN 16
|
|
|
|
|
|
|
|
/* Driver flags */
|
|
|
|
|
|
|
|
#define XEN1210_STAT_INITIALIZED 1 /* Device has been initialized */
|
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/****************************************************************************
|
2016-09-16 20:45:53 +02:00
|
|
|
* Public Types
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
2016-09-16 20:45:53 +02:00
|
|
|
|
|
|
|
/* This structure describes the results of one XEN1210 sample */
|
|
|
|
|
|
|
|
struct xen1210_sample_s
|
|
|
|
{
|
|
|
|
uint32_t data_x; /* Measured X-axis magnetic field */
|
|
|
|
uint32_t data_y; /* Measured Y-axis magnetic field */
|
|
|
|
uint32_t data_z; /* Measured Z-axis magnetic filed */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* This structure represents the state of the XEN1210 driver */
|
|
|
|
|
|
|
|
struct xen1210_dev_s
|
|
|
|
{
|
|
|
|
/* Common fields */
|
|
|
|
|
|
|
|
FAR struct xen1210_config_s *config; /* Board configuration data */
|
|
|
|
sem_t exclsem; /* Manages exclusive access to this structure */
|
|
|
|
FAR struct spi_dev_s *spi; /* Saved SPI driver instance */
|
|
|
|
|
|
|
|
uint8_t status; /* See XEN1210_STAT_* definitions */
|
|
|
|
struct work_s work; /* Supports the interrupt handling "bottom half" */
|
|
|
|
|
|
|
|
uint8_t nwaiters; /* Number of threads waiting for XEN1210 data */
|
|
|
|
|
|
|
|
sem_t waitsem; /* Used to wait for the availability of data */
|
|
|
|
|
|
|
|
struct work_s timeout; /* Supports timeout work */
|
|
|
|
struct xen1210_sample_s sample; /* Last sampled accelerometer data */
|
|
|
|
};
|
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/****************************************************************************
|
2016-09-16 20:45:53 +02:00
|
|
|
* Public Function Prototypes
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
2016-09-16 20:45:53 +02:00
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/****************************************************************************
|
2016-09-16 20:45:53 +02:00
|
|
|
* Name: xen1210_getdata
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Read 24-bit from XEN1210 buffer, read three times (3 sensors)
|
|
|
|
*
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
2016-09-16 20:45:53 +02:00
|
|
|
|
|
|
|
void xen1210_getdata(FAR struct xen1210_dev_s *priv);
|
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/****************************************************************************
|
2016-09-16 20:45:53 +02:00
|
|
|
* Name: xen1210_putdata
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Write 24-bit to XEN1210 buffer, write three times (3 sensors)
|
|
|
|
*
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
2016-09-16 20:45:53 +02:00
|
|
|
|
|
|
|
void xen1210_putdata(FAR struct xen1210_dev_s *priv, uint32_t regval);
|
|
|
|
|
|
|
|
#endif /* CONFIG_SENSORS_XEN1210 */
|
|
|
|
#endif /* __DRIVERS_SENSORS_XEN1210_H */
|