/**
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* 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.
*
* @file bmg250_defs.h
* @date 10/01/2020
* @version 1.1.2
*
*//*! @file bmg250_defs.h
* @brief Sensor driver for BMG250 sensor
*//*!
* @defgroup BMG250 SENSOR API
* @brief
* @{
*/#ifndefBMG250_DEFS_H_#defineBMG250_DEFS_H_/********************************************************//* header includes */#ifdef__KERNEL__#include<linux/types.h>#include<linux/kernel.h>#else#include<stdint.h>#include<stdio.h>#endif#ifdef__KERNEL__#if(LONG_MAX)>0x7fffffff#define__have_long641#elif(LONG_MAX)==0x7fffffff#define__have_long321#endif#if!defined(UINT8_C)#defineINT8_C(x) x#if(INT_MAX)>0x7f#defineUINT8_C(x) x#else#defineUINT8_C(x) x##U#endif#endif#if!defined(UINT16_C)#defineINT16_C(x) x#if(INT_MAX)>0x7fff#defineUINT16_C(x) x#else#defineUINT16_C(x) x##U#endif#endif#if!defined(INT32_C)&&!defined(UINT32_C)#ifdef__have_long32#defineINT32_C(x) x##L#defineUINT32_C(x) x##UL#else#defineINT32_C(x) x#defineUINT32_C(x) x##U#endif#endif#if!defined(INT64_C)&&!defined(UINT64_C)#ifdef__have_long64#defineINT64_C(x) x##L#defineUINT64_C(x) x##UL#else#defineINT64_C(x) x##LL#defineUINT64_C(x) x##ULL#endif#endif#endif/**@}*//**\name C standard macros */#ifndefNULL#ifdef__cplusplus#defineNULL0#else#defineNULL((void*)0)#endif#endif#defineTRUEUINT8_C(1)#defineFALSEUINT8_C(0)/**\name API success code */#defineBMG250_OKINT8_C(0)/**\name API warning codes */#defineBMG250_W_SELF_TEST_FAILINT8_C(1)/**\name API error codes */#defineBMG250_E_NULL_PTRINT8_C(-1)#defineBMG250_E_COM_FAILINT8_C(-2)#defineBMG250_E_DEV_NOT_FOUNDINT8_C(-3)#defineBMG250_E_OUT_OF_RANGEINT8_C(-4)#defineBMG250_E_INVALID_INPUTINT8_C(-5)#defineBMG250_E_ODR_BW_INVALIDINT8_C(-6)#defineBMG250_E_INVALID_TEMPERATUREINT8_C(-7)/**\name BMG250 Settings selection macros */#defineBMG250_ODR_SELUINT8_C(0x01)#defineBMG250_BW_SELUINT8_C(0x02)#defineBMG250_RANGE_SELUINT8_C(0x04)/**\name Data select macros for reading sensor data */#defineBMG250_DATA_SELUINT8_C(0x01)#defineBMG250_DATA_TIME_SELUINT8_C(0x02)/**\name ODR Settings */#defineBMG250_ODR_25HZUINT8_C(0x06)#defineBMG250_ODR_50HZUINT8_C(0x07)#defineBMG250_ODR_100HZUINT8_C(0x08)#defineBMG250_ODR_200HZUINT8_C(0x09)#defineBMG250_ODR_400HZUINT8_C(0x0A)#defineBMG250_ODR_800HZUINT8_C(0x0B)#defineBMG250_ODR_1600HZUINT8_C(0x0C)#defineBMG250_ODR_3200HZUINT8_C(0x0D)/**\name BW Settings */#defineBMG250_BW_OSR4_MODEUINT8_C(0x00)#defineBMG250_BW_OSR2_MODEUINT8_C(0x01)#defineBMG250_BW_NORMAL_MODEUINT8_C(0x02)/**\name Range Settings */#defineBMG250_RANGE_2000_DPSUINT8_C(0x00)#defineBMG250_RANGE_1000_DPSUINT8_C(0x01)#defineBMG250_RANGE_500_DPSUINT8_C(0x02)#defineBMG250_RANGE_250_DPSUINT8_C(0x03)#defineBMG250_RANGE_125_DPSUINT8_C(0x04)/**\name Interface settings */#defineBMG250_SPI_RD_MASKUINT8_C(0x80)#defineBMG250_SPI_WR_MASKUINT8_C(0x7F)/**\name Interface settings */#defineBMG250_SPI_COMM_TEST_ADDRUINT8_C(0x7F)/**\name BMG250 Chip ID */#defineBMG250_CHIP_IDUINT8_C(0XD5)/**\name BMG250 I2C address *//**\name I2C address when SDO pulled to GND */#defineBMG250_I2C_ADDRUINT8_C(0x68)/**\name address when SDO pulled to VDDIO */#defineBMG250_SEC_I2C_ADDRUINT8_C(0x69)/**\name BMG250 Register map */#defineBMG250_CHIP_ID_ADDRUINT8_C(0x00)#defineBMG250_ERROR_REG_ADDRUINT8_C(0x02)#defineBMG250_PMU_STATUS_ADDRUINT8_C(0x03)#defineBMG250_DATA_ADDRUINT8_C(0x12)#defineBMG250_STATUS_ADDRUINT8_C(0x1B)#defineBMG250_INT_STATUS_ADDRUINT8_C(0x1D)#defineBMG250_TEMPERATURE_ADDRUINT8_C(0x20)#defineBMG250_FIFO_LENGTH_ADDRUINT8_C(0x22)#defineBMG250_FIFO_DATA_ADDRUINT8_C(0x24)#defineBMG250_GYRO_CONFIG_ADDRUINT8_C(0x42)#defineBMG250_GYRO_RANGE_ADDRUINT8_C(0x43)#defineBMG250_FIFO_DOWN_ADDRUINT8_C(0x45)#defineBMG250_FIFO_CONFIG0_ADDRUINT8_C(0x46)#defineBMG250_FIFO_CONFIG1_ADDRUINT8_C(0x47)#defineBMG250_INT_EN_ADDRUINT8_C(0x51)#defineBMG250_IN_OUT_CNTRL_ADDRUINT8_C(0x53)#defineBMG250_INT_IN_CTRL_ADDRUINT8_C(0x54)#defineBMG250_INT_MAP_ADDRUINT8_C(0x56)#defineBMG250_IF_CONF_ADDRUINT8_C(0x6B)#defineBMG250_SELF_TEST_ADDRUINT8_C(0x6D)#defineBMG250_NV_CONF_ADDRUINT8_C(0x70)#defineBMG250_OFFSET_X_ADDRUINT8_C(0x74)#defineBMG250_OFFSET_Y_ADDRUINT8_C(0x75)#defineBMG250_OFFSET_Z_ADDRUINT8_C(0x76)#defineBMG250_OFFSET_EN_ADDRUINT8_C(0x77)#defineBMG250_COMMAND_REG_ADDRUINT8_C(0x7E)/**\name BMG250 Command register */#defineBMG250_FIFO_FLUSH_CMDUINT8_C(0xB0)#defineBMG250_SOFT_RESET_CMDUINT8_C(0xB6)#defineBMG250_FOC_ENABLE_CMDUINT8_C(0x03)/**\name BMG250 Self test trigger */#defineBMG250_SELF_TEST_TRIGGERUINT8_C(0x10)#defineBMG250_SELF_TEST_SUCCESSUINT8_C(0x01)#defineBMG250_SELF_TEST_FAILUINT8_C(0x00)/**\name BMG250 Delay definitions */#defineBMG250_GYRO_DELAY_MSUINT8_C(81)#defineBMG250_SOFT_RESET_DELAY_MSUINT8_C(15)#defineBMG250_GYRO_FSU_DELAY_MSUINT8_C(10)#defineBMG250_FOC_DELAY_MSUINT8_C(500)/**\name Gyro power mode */#defineBMG250_GYRO_SUSPEND_MODEUINT8_C(0x14)#defineBMG250_GYRO_NORMAL_MODEUINT8_C(0x15)#defineBMG250_GYRO_FASTSTARTUP_MODEUINT8_C(0x17)/**\name Gyro power mode status macros */#defineBMG250_PMU_STATUS_SUSPENDUINT8_C(0x00)#defineBMG250_PMU_STATUS_FSUUINT8_C(0x03)/**\name Maximum limits definition */#defineBMG250_GYRO_ODR_MAXUINT8_C(13)#defineBMG250_GYRO_BW_MAXUINT8_C(2)#defineBMG250_GYRO_RANGE_MAXUINT8_C(4)/**\name Mask definitions for FIFO_CONFIG register */#defineBMG250_FIFO_GYROUINT8_C(0x80)#defineBMG250_FIFO_HEADERUINT8_C(0x10)#defineBMG250_FIFO_TAG_INT1UINT8_C(0x08)#defineBMG250_FIFO_TAG_INT2UINT8_C(0x04)#defineBMG250_FIFO_TIMEUINT8_C(0x02)#defineBMG250_FIFO_STOP_ON_FULLUINT8_C(0x01)#defineBMG250_FIFO_ALL_SETTINGUINT8_C(0x9F)/**\name BMG250 FIFO down sampling Settings */#defineBMG250_GYRO_FIFO_FILT_ENUINT8_C(0x08)#defineBMG250_GYRO_FIFO_DOWN_ZEROUINT8_C(0x00)#defineBMG250_GYRO_FIFO_DOWN_ONEUINT8_C(0x01)#defineBMG250_GYRO_FIFO_DOWN_TWOUINT8_C(0x02)#defineBMG250_GYRO_FIFO_DOWN_THREEUINT8_C(0x03)#defineBMG250_GYRO_FIFO_DOWN_FOURUINT8_C(0x04)#defineBMG250_GYRO_FIFO_DOWN_FIVEUINT8_C(0x05)#defineBMG250_GYRO_FIFO_DOWN_SIXUINT8_C(0x06)#defineBMG250_GYRO_FIFO_DOWN_SEVENUINT8_C(0x07)/**\name BMG250 FIFO Definitions */#defineBMG250_SENSOR_TIME_LENGTHUINT8_C(3)#defineBMG250_FIFO_G_HEADER_LENGTHUINT8_C(7)#defineBMG250_FIFO_G_LENGTHUINT8_C(6)#defineBMG250_FIFO_BYTE_COUNTER_MASKUINT8_C(0x07)/** Mask definition for FIFO Header Data Tag */#defineBMG250_FIFO_TAG_INTR_MASKUINT8_C(0xFC)/** FIFO Header Data definitions */#defineBMG250_FIFO_HEAD_GUINT8_C(0x88)#defineBMG250_FIFO_HEAD_SKIP_FRAMEUINT8_C(0x40)#defineBMG250_FIFO_HEAD_SENSOR_TIMEUINT8_C(0x44)#defineBMG250_FIFO_HEAD_INPUT_CONFIGUINT8_C(0x48)#defineBMG250_FIFO_HEAD_OVER_READUINT8_C(0x80)/** Definitions to check validity of FIFO frames */#defineFIFO_CONFIG_MSB_CHECKUINT8_C(0x80)#defineFIFO_CONFIG_LSB_CHECKUINT8_C(0x00)/**\name BMG250 interrupt setting macros */#defineBMG250_DISABLEUINT8_C(0)#defineBMG250_ENABLEUINT8_C(1)#defineBMG250_PUSH_PULLUINT8_C(0)#defineBMG250_OPEN_DRAINUINT8_C(1)#defineBMG250_ACTIVE_LOWUINT8_C(0)#defineBMG250_ACTIVE_HIGHUINT8_C(1)#defineBMG250_LEVEL_TRIGGERUINT8_C(0)#defineBMG250_EDGE_TRIGGERUINT8_C(1)/**\name BMG250 interrupt status macros */#defineDRDY_INT_ASSERTEDUINT8_C(0x10)#defineFIFO_FULL_INT_ASSERTEDUINT8_C(0x20)#defineFIFO_WM_INT_ASSERTEDUINT8_C(0x40)/**\name BMG250 Status macros */#defineBMG250_FOC_READYUINT8_C(0x08)/**\name BMG250 if_mode configurations */#defineBMG250_IF_AUTO_CONFIGUINT8_C(0)#defineBMG250_IF_I2C_OISUINT8_C(1)/**\name BMG250 Watch-dog timer configurations */#defineBMG250_I2C_WDT_1_MSUINT8_C(0)#defineBMG250_I2C_WDT_50_MSUINT8_C(1)/**\name BMG250 position and mask macros */#defineBMG250_GYRO_ODR_MSKUINT8_C(0x0F)#defineBMG250_GYRO_BW_MSKUINT8_C(0x30)#defineBMG250_GYRO_BW_POSUINT8_C(4)#defineBMG250_GYRO_RANGE_MSKUINT8_C(0x07)#defineBMG250_ERR_REG_MASKUINT8_C(0x0F)#defineBMG250_GYRO_PMU_STATUS_MSKUINT8_C(0x0C)#defineBMG250_GYRO_PMU_STATUS_POSUINT8_C(2)#defineBMG250_DATA_READY_EN_MSKUINT8_C(0x10)#defineBMG250_DATA_READY_EN_POSUINT8_C(4)#defineBMG250_FIFO_FULL_EN_MSKUINT8_C(0x20)#defineBMG250_FIFO_FULL_EN_POSUINT8_C(5)#defineBMG250_FIFO_WM_EN_MSKUINT8_C(0x40)#defineBMG250_FIFO_WM_EN_POSUINT8_C(6)#defineBMG250_INT1_EN_MSKUINT8_C(0x08)#defineBMG250_INT1_EN_POSUINT8_C(3)#defineBMG250_INT1_OD_MSKUINT8_C(0x04)#defineBMG250_INT1_OD_POSUINT8_C(2)#defineBMG250_INT1_LVL_MSKUINT8_C(0x02)#defineBMG250_INT1_LVL_POSUINT8_C(1)#defineBMG250_INT1_EDGE_MSKUINT8_C(0x01)#defineBMG250_INT2_EN_MSKUINT8_C(0x80)#defineBMG250_INT2_EN_POSUINT8_C(7)#defineBMG250_INT2_OD_MSKUINT8_C(0x40)#defineBMG250_INT2_OD_POSUINT8_C(6)#defineBMG250_INT2_LVL_MSKUINT8_C(0x20)#defineBMG250_INT2_LVL_POSUINT8_C(5)#defineBMG250_INT2_EDGE_MSKUINT8_C(0x10)#defineBMG250_INT2_EDGE_POSUINT8_C(4)#defineBMG250_INT1_INPUT_EN_MSKUINT8_C(0x10)#defineBMG250_INT1_INPUT_EN_POSUINT8_C(4)#defineBMG250_INT2_INPUT_EN_MSKUINT8_C(0x20)#defineBMG250_INT2_INPUT_EN_POSUINT8_C(5)#defineBMG250_INT1_DATA_READY_MSKUINT8_C(0x80)#defineBMG250_INT1_DATA_READY_POSUINT8_C(7)#defineBMG250_INT2_DATA_READY_MSKUINT8_C(0x08)#defineBMG250_INT2_DATA_READY_POSUINT8_C(3)#defineBMG250_INT1_FIFO_FULL_MSKUINT8_C(0x20)#defineBMG250_INT1_FIFO_FULL_POSUINT8_C(5)#defineBMG250_INT2_FIFO_FULL_MSKUINT8_C(0x02)#defineBMG250_INT2_FIFO_FULL_POSUINT8_C(1)#defineBMG250_INT1_FIFO_WM_MSKUINT8_C(0x40)#defineBMG250_INT1_FIFO_WM_POSUINT8_C(6)#defineBMG250_INT2_FIFO_WM_MSKUINT8_C(0x04)#defineBMG250_INT2_FIFO_WM_POSUINT8_C(2)#defineBMG250_FIFO_HEADER_EN_MSKUINT8_C(0x10)#defineBMG250_FIFO_HEADER_EN_POSUINT8_C(4)#defineBMG250_FIFO_TIME_EN_MSKUINT8_C(0x02)#defineBMG250_FIFO_TIME_EN_POSUINT8_C(1)#defineBMG250_FIFO_DATA_EN_MSKUINT8_C(0x80)#defineBMG250_FIFO_DATA_EN_POSUINT8_C(7)#defineBMG250_SELF_TEST_RSLT_MSKUINT8_C(0x02)#defineBMG250_SELF_TEST_RSLT_POSUINT8_C(1)#defineBMG250_OFFSET_ENABLE_MSKUINT8_C(0x80)#defineBMG250_OFFSET_ENABLE_POSUINT8_C(7)#defineBMG250_GYRO_OFFSET_MSB_MSKUINT16_C(0x0300)#defineBMG250_GYRO_OFFSET_MSB_POSUINT16_C(8)#defineBMG250_GYRO_OFFSET_LSB_MSKUINT16_C(0x00FF)#defineBMG250_FOC_READY_MSKUINT8_C(0x08)#defineBMG250_FOC_READY_POSUINT8_C(3)#defineBMG250_WDT_EN_MSKUINT8_C(0x04)#defineBMG250_WDT_EN_POSUINT8_C(2)#defineBMG250_WDT_SEL_MSKUINT8_C(0x02)#defineBMG250_WDT_SEL_POSUINT8_C(1)#defineBMG250_IF_CONFIG_MSKUINT8_C(0x10)#defineBMG250_IF_CONFIG_POSUINT8_C(4)#defineBMG250_SPI_EN_MSKUINT8_C(0x01)#defineBMG250_FIFO_DOWN_SAMPLING_MSKUINT8_C(0x0F)/**\name BIT SLICE GET AND SET FUNCTIONS */#defineBMG250_GET_BITS(regvar, bitname)\((regvar & bitname##_MSK)>> bitname##_POS)#defineBMG250_SET_BITS(regvar, bitname, val)\((regvar &~bitname##_MSK)|\((val << bitname##_POS)& bitname##_MSK))#defineBMG250_SET_BITS_POS_0(reg_data, bitname, data)\((reg_data &~(bitname##_MSK))|\(data & bitname##_MSK))#defineBMG250_GET_BITS_POS_0(reg_data, bitname)(reg_data &(bitname##_MSK))/********************************************************//*!
* @brief Interface selection Enums
*/enumbmg250_intf{/*! SPI interface */
BMG250_SPI_INTF,/*! I2C interface */
BMG250_I2C_INTF
};/********************************************************//*!
* @brief Type definitions
*/typedefint8_t(*bmg250_com_fptr_t)(uint8_t dev_id,uint8_t reg_addr,uint8_t*data,uint16_t len);typedefvoid(*bmg250_delay_fptr_t)(uint32_t period);/********************************************************//*!
* @brief bmg250 sensor configuration structure
*/structbmg250_cfg{/*! output data rate */uint8_t odr;/*! range */uint8_t range;/*! bandwidth */uint8_t bw;};/*!
* @brief bmg250 sensor data structure which has gyro data
*/structbmg250_sensor_data{/*! X-axis sensor data */int16_t x;/*! Y-axis sensor data */int16_t y;/*! Z-axis sensor data */int16_t z;/*! sensor time */uint32_t sensortime;};/*!
* @brief bmg250 interrupt channel selection enum
*/enumbmg250_int_channel{/*! interrupt Channel 1 */
BMG250_INT_CHANNEL_1,/*! interrupt Channel 2 */
BMG250_INT_CHANNEL_2
};/*!
* @brief bmg250 interrupt type selection enum
*/enumbmg250_int_types{/*! data ready interrupt */
BMG250_DATA_RDY_INT,/*! fifo full interrupt */
BMG250_FIFO_FULL_INT,/*! fifo watermark interrupt */
BMG250_FIFO_WATERMARK_INT
};/*!
* @brief bmg250 interrupt pin setting
*/structbmg250_int_pin_settg{/*! To enable either INT1 or INT2 pin as output.
* 0- output disabled ,1- output enabled
*/uint8_t output_en;/*! 0 - push-pull 1- open drain,only valid if output_en is set 1 */uint8_t output_mode;/*! 0 - active low , 1 - active high level.
* if output_en is 1,this applies to interrupts,else PMU_trigger
*/uint8_t output_type;/*! 0 - level trigger , 1 - edge trigger */uint8_t edge_ctrl;/*! To enable either INT1 or INT2 pin as input.
* 0 - input disabled ,1 - input enabled
*/uint8_t input_en;};/*!
* @brief bmg250 interrupt setting
*/structbmg250_int_settg{/*! Interrupt channel */enumbmg250_int_channel int_channel;/*! Select Interrupt */enumbmg250_int_types int_type;/*! Structure configuring Interrupt pins */structbmg250_int_pin_settg int_pin_settg;/*! FIFO FULL INT 1-enable, 0-disable */uint8_t fifo_full_int_en;/*! FIFO WTM INT 1-enable, 0-disable */uint8_t fifo_wtm_int_en;};/*!
* @brief This structure holds the information for usage of
* FIFO by the user.
*/structbmg250_fifo_frame{/*! Data buffer of user defined length is to be mapped here */uint8_t*data;/*! While calling the API "bmg250_get_fifo_data" , length stores
* number of bytes in FIFO to be read (specified by user as input)
* and after execution of the API ,number of FIFO data bytes
* available is provided as an output to user
*/uint16_t length;/*! FIFO time enable */uint8_t fifo_time_enable;/*! Enabling of the FIFO header to stream in header mode */uint8_t fifo_header_enable;/*! Streaming of the data in FIFO */uint8_t fifo_data_enable;/*! Will be equal to length when no more frames are there to parse */uint16_t gyro_byte_start_idx;/*! Value of FIFO sensor time time */uint32_t sensor_time;/*! Value of Skipped frame counts */uint8_t skipped_frame_count;/*! Value to select FIFO downsampling and
* filtered/unfiltered data in FIFO
*/uint8_t fifo_down;};/*!
* @brief bmg250 offset structure
*/structbmg250_offset{/*XYZ offset */uint16_t x_offset;uint16_t y_offset;uint16_t z_offset;};/*!
* @brief bmg250 device structure
*/structbmg250_dev{/*! Chip Id */uint8_t chip_id;/*! Device Id */uint8_t dev_id;/*! SPI/I2C interface */enumbmg250_intf intf;/*! Read function pointer */bmg250_com_fptr_t read;/*! Write function pointer */bmg250_com_fptr_t write;/*! Delay function pointer */bmg250_delay_fptr_t delay_ms;/*! FIFO related configurations */structbmg250_fifo_frame*fifo;/* Power mode of sensor */uint8_t power_mode;};#endif/* BMG250_DEFS_H_ *//** @}*//** @}*/