#ifndef ACC_LIS2_H__
#define ACC_LIS2_H__

#include <stdint.h>
#include <stdbool.h>

#define IG_CFG1_6D		0x40
#define IG_CFG1_ZHIE	0x20
#define IG_CFG1_ZLIE	0x10
#define IG_CFG1_XHIE	0x02
#define IG_CFG1_XLIE	0x01

/**@brief Function for initializing the module 
 *
 * Sets up the GPIO's (and power cycle the accelerometer)
 */
void acc_init(void);


/**@brief Function for setting up the accelerometer to generate interrupt at 100Hz with 400Hz sampling
 *
 * Init the LIS2DH acc chip with 400Hz and FIFO
 */
void xacc_init_fifo_400Hz(void);


/**@brief Function for setting up the accelerometer to generate interrupt when moved (rotated)
 *
 * Initialization
 */
void acc_init_w_int(bool up, uint8_t x, uint8_t y, uint8_t z, uint8_t ig_cfg1);


/**@brief Function for reading X/Y/Z from accelerometer
 *
 * Reads 4 values in 12bit mode from the FIFO and averages them
 *
 * @return If any data is ready
 */
uint8_t acc_get_xyz(int16_t *x, int16_t *y, int16_t *z);

/**@brief Function for reading X/Y/Z from accelerometer
 *
 * start the Reading of 4 values in 12bit mode from the FIFO and averages them
 *
 */
void acc_start_xyz(void);


/**@brief Function for reading X/Y/Z from accelerometer
 *
 * Reads all available values in 12bit mode from the FIFO return a 8 bit values
 *
 * @return x, y, z values (32 = 1G)
 */
void acc_get_xyz8(int8_t *x, int8_t *y, int8_t *z);


/**@brief Function for reading X+Y from accelerometer
 *
 * Reads one set of values in 8bit mode
 *
 * @return x, y values (32 = 1G)
 */
void acc_get_xy(int8_t *x, int8_t *y);


/**@brief Set up accelerometer for 100Hz low power 8 bit updates
 *
 * Enable X + Y (but may use Z as X/Y for those hardware orientations)
 */
void acc_set_100Hz_lp_mode(void);


/**@brief Set up accelerometer for 400Hz low power 8 bit updates
 *
 * Enable X + Y (but may use Z as X/Y for those hardware orientations)
 */
void acc_set_400Hz_lp_mode(void);


/**@brief Function for reading X-acceleration
 *
 * @return X-acceleration (8 bit)
 */
int8_t acc_get_x8(void);


/**@brief Function for reading Y-acceleration
 *
 * @return Y-acceleration (8 bit)
 */
int8_t acc_get_y8(void);


/**@brief Function for reading Z-acceleration
 *
 * @return Z-acceleration (8 bit)
 */
int8_t acc_get_z8(void);


/**@brief Function for clearing the FIFO
 *
 * Empty the FIFO
 */
void acc_reset_fifo(void);


/**@brief Function for reading status register in accelerometer
 *
 * @return Status register
 */
int8_t acc_get_status(void);

int8_t acc_get_who_am_i(void);


/**@brief Function for reading interrupt 1 source register in accelerometer
 *
 * Read interrupt source (and clear interrupt)
 *
 * @return INT1_SRC register
 */
int8_t acc_get_int1_src(void);


/**@brief Function for reading interrupt 1 configuration register in accelerometer
 *
 * @return INT1_CFG register
 */
int8_t acc_get_int1_cfg(void);


/**@brief Function for reading the FIFO interrupt source register in accelerometer
 *
 * @return FIFO_SRC_REG register
 */
int8_t acc_get_fifo_src(void);


/**@brief Function for reading the FIFO watermark flag in accelerometer
 *
 * @return True if the FIFO watermark flag is set
 */
bool acc_get_fifo_wtm(void);


#endif
