/*
 * ________________________________________________________________________________________________________
 * Copyright (c) 2016-2016 InvenSense Inc. All rights reserved.
 *
 * This software, related documentation and any modifications thereto (collectively “Software”) is subject
 * to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
 * and other intellectual property rights laws.
 *
 * InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
 * and any use, reproduction, disclosure or distribution of the Software without an express license agreement
 * from InvenSense is strictly prohibited.
 *
 * EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
 * PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
 * INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
 * OF THE SOFTWARE.
 * ________________________________________________________________________________________________________
 */
#ifndef _EXAMPLE_SMD_H_
#define _EXAMPLE_SMD_H_

#include <stdint.h>
#include "imu/inv_imu_transport.h"
#include "imu/inv_imu_defs.h"
#include "imu/inv_imu_driver.h"
#include "imu/inv_imu_apex.h"

/*** Example configuration ***/

/* 
 * Select communication between SmartMotion and IMU by setting correct SERIF_TYPE 
 */
#define SERIF_TYPE UI_SPI4
//#define SERIF_TYPE           UI_I2C

/*
 * SMD power save mode
 * Use type APEX_CONFIG0_DMP_POWER_SAVE_t to define pedometer power save mode
 * These types are defined in inv_imu_defs.h.
 */
#define SMD_POWER_SAVE_MODE APEX_CONFIG0_DMP_POWER_SAVE_EN

/*
 * Default value for the WOM threshold
 * Resolution of the threshold is 3.9 mg (= 1g / 256)
 */
#define DEFAULT_WOM_THS 13 /* = 13 * 1000 / 256 = 50.8 mg */

/**
 * \brief This function is in charge of reseting and initializing IMU device. It should
 * be successfully executed before any access to IMU device.
 *
 * \return 0 on success, negative value on error.
 */
int setup_imu_device(const struct inv_imu_serif *icm_serif);

/**
 * \brief This function configures the device in order to output SMD.
 *
 * Then function sets full scale range and frequency for accel and it 
 * starts accel and SMD in the requested power mode with the requested configuration.
 *
 * \return 0 on success, negative value on error.
 */
int configure_imu_device();

/**
 * \brief This function extracts data from the IMU FIFO.
 *
 * The function just calls IMU driver function inv_imu_get_data_from_fifo.
 * But note that for each packet extracted from FIFO, a user defined function is called to 
 * allow custom handling of each packet.
 *
 * \return 0 on success, negative value on error.
 */
int get_imu_data(void);

#endif /* !_EXAMPLE_SMD_H_ */
