#include <stdint.h>
#include <drivers/spi.h>

// SPI PINS
#define SPIM_CS_PIN    16 

// SPI Master Instance
void ADXL345_SPI_init();

/**@brief Function for reading to the ADXL375 registers over SPI.
 *
 * @param[in] address   ADXL375 Register adress    
 * @param[in] p_data    Pointer to rx buffer 
 * @param[in] bytes     Number of bytes to be read 
 *
 */

void ADXL345_SPI_readRegister(uint8_t address, uint8_t * p_data, uint8_t bytes);

/**@brief Function for writing to the ADXL375 registers over SPI.
 *
 * @param[in] address   ADXL375 Register adress    
 * @param[in] p_data    Pointer to tx buffer 
 * @param[in] bytes     Number of bytes to be written
 *
 */

void ADXL345_SPI_writeRegister(uint8_t reg_addr, uint8_t * p_data, uint8_t bytes);

/**@brief Function for setting the data rate of the ADXL375 .
 *
 * @param[in] rate      Data rate in hex (refer the ADXL375 datasheet for available rates)   
 *
 */

void ADXL345_SPI_setDataRate(uint8_t rate);

/**@brief Function for setting the POWER_CTL register of the ADXL375 .
 *
 * @param[in] reg_val       Value to be written the register   
 *
 */

void ADXL345_SPI_setPowerReg(uint8_t reg_val);


/**@brief Function for reading the data registers of the ADXL375 .
 *
 * @param[in] rx_buffer     Pointer to rx buffer 
 * @param[in] rx_buf_size   Size of rx buffer  
 * @param[in] x_val         Pointer to x value  
 * @param[in] y_val         Pointer to y value    
 * @param[in] z_val         Pointer to z value    
 *
 */
 
void ADXL345_SPI_readAccelerometerData( uint8_t * rx_buffer, uint8_t rx_buf_size, int16_t *x_val, int16_t *y_val, int16_t *z_val);

/**@brief Function for setting the OFSn register of the ADXL375, n = [X,Y,Z] .
 *
 * @param[in] x_offset       X-axis offset
 * @param[in] y_offset       Y-axis offset
 * @param[in] z_offset       Z-axis offset
 *
 */

void ADXL345_SPI_setOffsets(uint8_t x_offset, uint8_t y_offset, uint8_t z_offset );

