L3GD20H driver added

This commit is contained in:
Gunar Schorcht 2017-12-21 19:04:00 +01:00
parent c3ae04c93f
commit 60427cf383
8 changed files with 3218 additions and 0 deletions

1000
extras/l3gd20h/README.md Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,10 @@
# Component makefile for extras/l3gd20h
# expected anyone using L3GD20H driver includes it as 'l3gd20h/l3gd20h.h'
INC_DIRS += $(l3gd20h_ROOT)..
INC_DIRS += $(l3gd20h_ROOT)
# args for passing into compile rule generation
l3gd20h_SRC_DIR = $(l3gd20h_ROOT)
$(eval $(call component_compile_rules,l3gd20h))

1066
extras/l3gd20h/l3gd20h.c Normal file

File diff suppressed because it is too large Load diff

407
extras/l3gd20h/l3gd20h.h Normal file
View file

@ -0,0 +1,407 @@
/**
* Driver for L3GD20H 3-axes digital output gyroscope connected to I2C or SPI.
* It can also be used with L3GD20 and L3G4200D.
*
* This driver is for the usage with the ESP8266 and FreeRTOS (esp-open-rtos)
* [https://github.com/SuperHouse/esp-open-rtos]. It is also working with ESP32
* and ESP-IDF [https://github.com/espressif/esp-idf.git] as well as Linux
* based systems using a wrapper library for ESP8266 functions.
*
* ---------------------------------------------------------------------------
*
* The BSD License (3-clause license)
*
* Copyright (c) 2017 Gunar Schorcht (https://github.com/gschorcht)
* All rights reserved.
*
* 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 of the copyright holder 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 HOLDER 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 __L3GD20H_H__
#define __L3GD20H_H__
// Uncomment one of the following defines to enable debug output
// #define L3GD20H_DEBUG_LEVEL_1 // only error messages
// #define L3GD20H_DEBUG_LEVEL_2 // debug and error messages
// L3GD20H addresses
#define L3GD20H_I2C_ADDRESS_1 0x6a // SDO pin is low
#define L3GD20H_I2C_ADDRESS_2 0x6b // SDO pin is high
// L3GD20 addresses
#define L3GD20_I2C_ADDRESS_1 0x6a // SDO pin is low
#define L3GD20_I2C_ADDRESS_2 0x6b // SDO pin is high
// L3G4200D addresses
#define L3G4200D_I2C_ADDRESS_1 0x68 // SDO pin is low
#define L3G4200D_I2C_ADDRESS_2 0x69 // SDO pin is high
// L3GD20H chip id
#define L3GD20H_CHIP_ID 0xd7 // L3GD20H_REG_WHO_AM_I<7:0>
// L3GD20 chip id
#define L3GD20_CHIP_ID 0xd4 // L3GD20H_REG_WHO_AM_I<7:0>
// L3G4200D chip id
#define L3G4200D_CHIP_ID 0xd3 // L3GD20H_REG_WHO_AM_I<7:0>
// Definition of error codes
#define L3GD20H_OK 0
#define L3GD20H_NOK -1
#define L3GD20H_INT_ERROR_MASK 0x000f
#define L3GD20H_DRV_ERROR_MASK 0xfff0
// Error codes for I2C and SPI interfaces ORed with L3GD20H driver error codes
#define L3GD20H_I2C_READ_FAILED 1
#define L3GD20H_I2C_WRITE_FAILED 2
#define L3GD20H_I2C_BUSY 3
#define L3GD20H_SPI_WRITE_FAILED 4
#define L3GD20H_SPI_READ_FAILED 5
#define L3GD20H_SPI_BUFFER_OVERFLOW 6
#define L3GD20H_SPI_SET_PAGE_FAILED 7
// L3GD20H driver error codes ORed with error codes for I2C and SPI interfaces
#define L3GD20H_WRONG_CHIP_ID ( 1 << 8)
#define L3GD20H_WRONG_BANDWIDTH ( 2 << 8)
#define L3GD20H_GET_RAW_DATA_FAILED ( 3 << 8)
#define L3GD20H_GET_RAW_DATA_FIFO_FAILED ( 4 << 8)
#define L3GD20H_WRONG_INT_TYPE ( 5 << 8)
#define L3GD20H_CONFIG_INT_SIGNALS_FAILED ( 6 << 8)
#define L3GD20H_CONFIG_INT1_FAILED ( 7 << 8)
#define L3GD20H_CONFIG_INT2_FAILED ( 8 << 8)
#define L3GD20H_INT1_SOURCE_FAILED ( 9 << 8)
#define L3GD20H_INT2_SOURCE_FAILED (10 << 8)
#define L3GD20H_SEL_OUT_FILTER_FAILED (11 << 8)
#define L3GD20H_CONFIG_HPF_FAILED (12 << 8)
#define L3GD20H_ENABLE_HPF_FAILED (13 << 8)
#define L3GD20H_SENSOR_IN_BYPASS_MODE (14 << 8)
#define L3GD20H_SENSOR_IN_FIFO_MODE (15 << 8)
#define LG3GD20H_ODR_TOO_HIGH (16 << 8)
#include "l3gd20h_platform.h"
#include "l3gd20h_types.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
* @brief Initialize the sensor
*
* Reset the sensor and switch to power down mode. All registers are reset to
* default values. FIFO is cleared.
*
* @param bus I2C or SPI bus at which L3GD20H sensor is connected
* @param addr I2C addr of the L3GD20H sensor, 0 for using SPI
* @param cs SPI CS GPIO, ignored for I2C
* @return pointer to sensor data structure, or NULL on error
*/
l3gd20h_sensor_t* l3gd20h_init_sensor (uint8_t bus, uint8_t addr, uint8_t cs);
/**
* @brief Set sensor mode
*
* @param dev pointer to the sensor device data structure
* @param mode sensor mode with certain output data rate
* @param bw bandwidth
* @param x true enable x-axis, false disable x-axis
* @param y true enable y-axis, false disable y-axis
* @param z true enable z-axis, false disable z-axis
* @return true on success, false on error
*/
bool l3gd20h_set_mode (l3gd20h_sensor_t* dev, l3gd20h_mode_t mode, uint8_t bw,
bool x, bool y, bool z);
/**
* @brief Set scale (full range range)
*
* @param dev pointer to the sensor device data structure
* @param scale range setting
* @return true on success, false on error
*/
bool l3gd20h_set_scale (l3gd20h_sensor_t* dev, l3gd20h_scale_t sens);
/**
* @brief Set FIFO mode
*
* @param dev pointer to the sensor device data structure
* @param mode FIFO mode
* @param thresh FIFO watermark (ignored in bypass mode)
* @return true on success, false on error
*/
bool l3gd20h_set_fifo_mode (l3gd20h_sensor_t* dev,
l3gd20h_fifo_mode_t mode, uint8_t thresh);
/**
* @brief Filter selection for raw data output values
*
* High pass filter (HPF) is configured with function *l3gd20h_config_hpf*. If
* HPF is selected, it is enabled implicitly.
*
* @param dev pointer to the sensor device data structure
* @param filter selected filters for output values
* @return true on success, false on error
*/
bool l3gd20h_select_output_filter (l3gd20h_sensor_t* dev,
l3gd20h_filter_t filter);
/**
* @brief Test whether new sets of data are available
*
* @param dev pointer to the sensor device data structure
* @return true on new data, otherwise false
*/
bool l3gd20h_new_data (l3gd20h_sensor_t* dev);
/**
* @brief Get one sample of floating point sensor data (unit degree)
*
* Function works only in bypass mode and fails in FIFO modes. In FIFO modes,
* function *l3gd20h_get_float_data_fifo* has to be used instead to get data.
*
* @param dev pointer to the sensor device data structure
* @param data pointer to float data structure filled with values
* @return true on success, false on error
*/
bool l3gd20h_get_float_data (l3gd20h_sensor_t* dev,
l3gd20h_float_data_t* data);
/**
* @brief Get all samples of sensor data stored in the FIFO (unit dps)
*
* In bypass mode, it returns only one sensor data sample.
*
* @param dev pointer to the sensor device data structure
* @param data array of 32 float data structures
* @return number of data sets read from fifo on success or 0 on error
*/
uint8_t l3gd20h_get_float_data_fifo (l3gd20h_sensor_t* dev,
l3gd20h_float_data_fifo_t data);
/**
* @brief Get one sample of raw sensor data as 16 bit two's complements
*
* Function works only in bypass mode and fails in FIFO modes. In FIFO modes,
* function *l3gd20h_get_raw_data_fifo* has to be used instead to get data.
*
* @param dev pointer to the sensor device data structure
* @param raw pointer to raw data structure filled with values
* @return true on success, false on error
*/
bool l3gd20h_get_raw_data (l3gd20h_sensor_t* dev,
l3gd20h_raw_data_t* raw);
/**
* @brief Get all samples of raw sensor data stored in the FIFO
*
* In bypass mode, it returns only one raw data sample.
*
* @param dev pointer to the sensor device data structure
* @param raw array of 32 raw data structures
* @return number of data sets read from fifo on success or 0 on error
*/
uint8_t l3gd20h_get_raw_data_fifo (l3gd20h_sensor_t* dev,
l3gd20h_raw_data_fifo_t raw);
/**
* @brief Enable / disable data or event interrupts on signal INT1/INT2
*
* @param dev pointer to the sensor device data structure
* @param type type of the interrupt to be enabled/disabled
* @param value true to enable or false to disable the interrupt
* @return true on success, false on error
*/
bool l3gd20h_enable_int (l3gd20h_sensor_t* dev,
l3gd20h_int_types_t type, bool value);
/**
* @brief Set the configuration of the event interrupt generator
*
* The event interrupt generator produces interrupts (axis movement and wake up)
* on signal INT1 whenever the angular rate of one or more axes becomes higher
* or lower than defined thresholds.
*
* @param dev pointer to the sensor device data structure
* @param config pointer to the interrupt generator configuration
* @return true on success, false on error
*/
bool l3gd20h_set_int_event_config (l3gd20h_sensor_t* dev,
l3gd20h_int_event_config_t* config);
/**
* @brief Get the configuration of the event interrupt generator
*
* The event interrupt generator produces interrupts (axis movement and wake up)
* on signal INT1 whenever the angular rate of one or more axes becomes higher
* or lower than defined thresholds.
*
* @param dev pointer to the sensor device data structure
* @param config pointer to the interrupt generator configuration
* @return true on success, false on error
*/
bool l3gd20h_get_int_event_config (l3gd20h_sensor_t* dev,
l3gd20h_int_event_config_t* config);
/**
* @brief Get the source of an event interrupt (axis movement and wake up)
*
* @param dev pointer to the sensor device data structure
* @param type pointer to the interrupt source
* @return true on success, false on error
*/
bool l3gd20h_get_int_event_source (l3gd20h_sensor_t* dev,
l3gd20h_int_event_source_t* source);
/**
* @brief Get the source of a data interrupt (data ready or FIFO status)
*
* @param dev pointer to the sensor device data structure
* @param source pointer to the interrupt source
* @return true on success, false on error
*/
bool l3gd20h_get_int_data_source (l3gd20h_sensor_t* dev,
l3gd20h_int_data_source_t* source);
/**
* @brief Set signal configuration for INT1 and INT2 signals
*
* @param dev pointer to the sensor device data structure
* @param level define interrupt signal as low or high active
* @param type define interrupt signal as pushed/pulled or open drain
* @return true on success, false on error
*/
bool l3gd20h_config_int_signals (l3gd20h_sensor_t* dev,
l3gd20h_signal_level_t level,
l3gd20h_signal_type_t type);
/**
* @brief Config HPF (high pass filter)
*
* @param dev pointer to the sensor device data structure
* @param mode high pass filter mode
* @param cutoff cutoff frequency (depends on output data rate) [0 ... 15]
* @return true on success, false on error
*/
bool l3gd20h_config_hpf (l3gd20h_sensor_t* dev,
l3gd20h_hpf_mode_t mode, uint8_t cutoff);
/**
* @brief Set HPF (high pass filter) reference
*
* Used to set the reference of HPF in reference mode *l3gd20h_hpf_reference*.
* Used to reset the HPF in autoreset mode *l3gd20h_hpf_autoreset*.
* Reference is given as two's complement.
*
* @param dev pointer to the sensor device data structure
* @param ref reference *l3gd20h_hpf_reference* mode, otherwise ignored
* @return true on success, false on error
*/
bool l3gd20h_set_hpf_ref (l3gd20h_sensor_t* dev, int8_t ref);
/**
* @brief Get HPF (high pass filter) reference
*
* Used to reset the HPF in normal mode *l3gd20h_hpf_normal*.
*
* @param dev pointer to the sensor device data structure
* @return HPF reference as two's complement
*/
int8_t l3gd20h_get_hpf_ref (l3gd20h_sensor_t* dev);
/**
* @brief Get temperature
*
* @param dev pointer to the sensor device data structure
* @return temperature in degree as two's complement
*/
int8_t l3gd20h_get_temperature (l3gd20h_sensor_t* dev);
// ---- Low level interface functions -----------------------------
/**
* @brief Direct write to register
*
* PLEASE NOTE: This function should only be used to do something special that
* is not covered by the high level interface AND if you exactly know what you
* do and what effects it might have. Please be aware that it might affect the
* high level interface.
*
* @param dev pointer to the sensor device data structure
* @param reg address of the first register to be changed
* @param data pointer to the data to be written to the register
* @param len number of bytes to be written to the register
* @return true on success, false on error
*/
bool l3gd20h_reg_write (l3gd20h_sensor_t* dev,
uint8_t reg, uint8_t *data, uint16_t len);
/**
* @brief Direct read from register
*
* PLEASE NOTE: This function should only be used to do something special that
* is not covered by the high level interface AND if you exactly know what you
* do and what effects it might have. Please be aware that it might affect the
* high level interface.
*
* @param dev pointer to the sensor device data structure
* @param reg address of the first register to be read
* @param data pointer to the data to be read from the register
* @param len number of bytes to be read from the register
* @return true on success, false on error
*/
bool l3gd20h_reg_read (l3gd20h_sensor_t* dev,
uint8_t reg, uint8_t *data, uint16_t len);
#ifdef __cplusplus
}
#endif /* End of CPP guard */
#endif /* __L3GD20H_H__ */

View file

@ -0,0 +1,113 @@
/**
* Driver for L3GD20H 3-axes digital output gyroscope connected to I2C or SPI.
* It can also be used with L3GD20 and L3G4200D.
*
* This driver is for the usage with the ESP8266 and FreeRTOS (esp-open-rtos)
* [https://github.com/SuperHouse/esp-open-rtos]. It is also working with ESP32
* and ESP-IDF [https://github.com/espressif/esp-idf.git] as well as Linux
* based systems using a wrapper library for ESP8266 functions.
*
* ---------------------------------------------------------------------------
*
* The BSD License (3-clause license)
*
* Copyright (c) 2017 Gunar Schorcht (https://github.com/gschorcht)
* All rights reserved.
*
* 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 of the copyright holder 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 HOLDER 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.
*/
/**
* Platform file: platform specific definitions, includes and functions
*/
#ifndef __L3GD20H_PLATFORM_H__
#define __L3GD20H_PLATFORM_H__
#if !defined(ESP_OPEN_RTOS)
#define ESP_OPEN_RTOS 1
#endif
#ifdef ESP_OPEN_RTOS // ESP8266
// platform specific includes
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "espressif/esp_common.h"
#include "espressif/sdk_private.h"
#include "esp/uart.h"
#include "esp/spi.h"
#include "i2c/i2c.h"
// platform specific definitions
#define spi_semaphore_init()
#define spi_semaphore_take()
#define spi_semaphore_give()
// platform specific SPI functions
#define spi_bus_init(bus,sck,miso,mosi) // not needed on ESP8266
static const spi_settings_t bus_settings = {
.mode = SPI_MODE0,
.freq_divider = SPI_FREQ_DIV_1M,
.msb = true,
.minimal_pins = false,
.endianness = SPI_LITTLE_ENDIAN
};
inline static bool spi_device_init (uint8_t bus, uint8_t cs)
{
gpio_enable(cs, GPIO_OUTPUT);
gpio_write (cs, true);
return true;
}
inline static size_t spi_transfer_pf(uint8_t bus, uint8_t cs, const uint8_t *mosi, uint8_t *miso, uint16_t len)
{
spi_settings_t old_settings;
spi_get_settings(bus, &old_settings);
spi_set_settings(bus, &bus_settings);
gpio_write(cs, false);
size_t transfered = spi_transfer (bus, (const void*)mosi, (void*)miso, len, SPI_8BIT);
gpio_write(cs, true);
spi_set_settings(bus, &old_settings);
return transfered;
}
#endif // ESP_OPEN_RTOS
#endif // __L3GD20H_PLATFORM_H__

View file

@ -0,0 +1,297 @@
/**
* Driver for L3GD20H 3-axes digital output gyroscope connected to I2C or SPI.
* It can also be used with L3GD20 and L3G4200D.
*
* This driver is for the usage with the ESP8266 and FreeRTOS (esp-open-rtos)
* [https://github.com/SuperHouse/esp-open-rtos]. It is also working with ESP32
* and ESP-IDF [https://github.com/espressif/esp-idf.git] as well as Linux
* based systems using a wrapper library for ESP8266 functions.
*
* ---------------------------------------------------------------------------
*
* The BSD License (3-clause license)
*
* Copyright (c) 2017 Gunar Schorcht (https://github.com/gschorcht)
* All rights reserved.
*
* 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 of the copyright holder 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 HOLDER 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 __L3GD20H_TYPES_H__
#define __L3GD20H_TYPES_H__
#include "stdint.h"
#include "stdbool.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
* @brief Output data rates (ODR)
*/
typedef enum
{
l3gd20h_power_down = 0, // power down mode
l3gd20h_normal_odr_12_5, // normal mode with low output data rate 12.5 Hz
l3gd20h_normal_odr_25, // normal mode with low output data rate 25 Hz
l3gd20h_normal_odr_50, // normal mode with low output data rate 50 Hz
l3gd20h_normal_odr_100, // normal mode with high output data rate 100 Hz
l3gd20h_normal_odr_200, // normal mode with high output data rate 200 Hz
l3gd20h_normal_odr_400, // normal mode with high output data rate 400 Hz
l3gd20h_normal_odr_800, // normal mode with high output data rate 800 Hz
} l3gd20h_mode_t;
/**
* @brief Sensitivity level
*/
typedef enum
{
l3gd20h_scale_245dps = 0, // default
l3gd20h_scale_500dps,
l3gd20h_scale_2000dps
} l3gd20h_scale_t;
/**
* @brief FIFO mode
*/
typedef enum
{
l3gd20h_bypass = 0, // default
l3gd20h_fifo = 1,
l3gd20h_stream = 2,
l3gd20h_stream_to_fifo = 3,
l3gd20h_bypass_to_stream = 5,
l3gd20h_dynamic_stream = 6,
l3gd20h_bypass_to_fifo = 7
} l3gd20h_fifo_mode_t;
/**
* @brief High pass filter (HPF) and low pass filter 2 (LPF2) modes
*/
typedef enum
{
l3gd20h_no_filter = 0, // HPF not used, LPF2 not used
l3gd20h_hpf_only, // HPF used, LPF2 not used
l3gd20h_lpf2_only, // HPF not used, LPF2 used
l3gd20h_hpf_and_lpf2 // HPF used, LPF2 used
} l3gd20h_filter_t;
/**
* @brief Interrupt types
*/
typedef enum {
l3gd20h_int_data_ready, // data are ready to read (INT2)
l3gd20h_int_fifo_threshold, // FIFO filling exceds FTH level (INT2)
l3gd20h_int_fifo_overrun, // FIFO is completely filled (INT2)
l3gd20h_int_fifo_empty, // FIFO becomes empty (INT2)
l3gd20h_int_event // angular rate of one or more axes becomes
// lower or higher than threshold (INT1)
} l3gd20h_int_types_t;
/**
* @brief Event interrupt generator configuration (axis movement and wake up)
*
* memset to 0 to disable all interrupt conditions (default)
*/
typedef struct
{
bool x_low_enabled; // x lower than threshold interrupt enabled
bool x_high_enabled; // x higher than threshold interrupt enabled
uint16_t x_threshold; // x threshold value
bool y_low_enabled; // y lower than threshold interrupt enabled
bool y_high_enabled; // y higher than threshold interrupt enabled
uint16_t y_threshold; // y threshold value
bool z_low_enabled; // z lower than threshold interrupt enabled
bool z_high_enabled; // z higher than threshold interrupt enabled
uint16_t z_threshold; // z threshold value
l3gd20h_filter_t filter; // HPF and LPF2 mode used for threshold comparison
bool and_or; // interrupt combination true - AND, false - OR
// AND - all enabled axes passed the treshold
// OR - at least one axes passed the threshold
bool latch; // latch the interrupt when true until the
// interrupt source has been read
uint8_t duration; // duration in 1/ODR an interrupt condition has
// to be given before the interrupt is generated
bool wait; // when true, duration is also used when interrupt
// condition in no longer given before interrupt
// signal is reset
bool counter_mode; // DCRM is not documented and not used therefore
} l3gd20h_int_event_config_t;
/**
* @brief Event interrupt source (axis movement and wake up)
*/
typedef struct {
bool x_low :1; // true - x is lower event occured
bool x_high:1; // true - x is higher event occured
bool y_low :1; // true - z is lower event occured
bool y_high:1; // true - z is higher event occured
bool z_low :1; // true - z is lower event occured
bool z_high:1; // true - z is higher event occured
bool active:1; // true - one ore more have been generated
} l3gd20h_int_event_source_t;
/**
* @brief Data interrupt source type (data ready and FIFO status)
*/
typedef struct {
bool data_ready; // true when data are ready to read
bool fifo_threshold; // true when FIFO filling >= FTH level
bool fifo_overrun; // true when FIFO is completely filled
bool fifo_empty; // true when FIFO is empty
} l3gd20h_int_data_source_t;
/**
* @brief INT1, INT2 signal activity level
*/
typedef enum {
l3gd20h_high_active = 0,
l3gd20h_low_active
} l3gd20h_signal_level_t;
/**
* @brief INT1, INT2 signal type
*/
typedef enum {
l3gd20h_push_pull = 0,
l3gd20h_open_drain
} l3gd20h_signal_type_t;
/**
* @brief Raw data set as two complements
*/
typedef struct {
int16_t x;
int16_t y;
int16_t z;
} l3gd20h_raw_data_t;
/**
* @brief Raw data FIFO type
*/
typedef l3gd20h_raw_data_t l3gd20h_raw_data_fifo_t[32];
/**
* @brief Floating point output value set in degree
*/
typedef struct {
float x;
float y;
float z;
} l3gd20h_float_data_t;
/**
* @brief Floating point output value FIFO type
*/
typedef l3gd20h_float_data_t l3gd20h_float_data_fifo_t[32];
/**
* @brief HPF (high pass filter) modes
*/
typedef enum {
l3gd20h_hpf_normal = 0,
l3gd20h_hpf_reference,
l3gd20h_hpf_normal_x,
l3gd20h_hpf_autoreset
} l3gd20h_hpf_mode_t;
/**
* @brief L3GD20H sensor device data structure type
*/
typedef struct {
int error_code; // contains the error code of last operation
uint8_t bus; // I2C = x, SPI = 1
uint8_t addr; // I2C = slave address, SPI = 0
uint8_t cs; // ESP8266, ESP32: GPIO used as SPI CS
// __linux__: device index
l3gd20h_scale_t scale; // fill range scale (default 245 dps)
l3gd20h_fifo_mode_t fifo_mode; // FIFO operation mode (default bypass)
} l3gd20h_sensor_t;
#ifdef __cplusplus
}
#endif /* End of CPP guard */
#endif /* __L3GD20H_TYPES_H__ */