/**
 * @brief  Set L3GD20 Initialization.
 * @param  L3GD20_InitStruct: pointer to a L3GD20_InitTypeDef structure
 *         that contains the configuration setting for the L3GD20.
 * @retval None
 */
void L3GD20_Init(L3GD20_InitTypeDef *L3GD20_InitStruct) {
	uint8_t ctrl1 = 0x00, ctrl4 = 0x00, fifoCTRL = 0x00;

	/* Configure the low level interface ---------------------------------------*/
	L3GD20_LowLevel_Init();

	/* Configure MEMS: data rate, power mode, full scale and axes */
	ctrl1 |= (uint8_t)(
			L3GD20_InitStruct->Power_Mode | L3GD20_InitStruct->Output_DataRate
					| L3GD20_InitStruct->Axes_Enable
					| L3GD20_InitStruct->Band_Width);

	ctrl4 |= (uint8_t)(
			L3GD20_InitStruct->BlockData_Update | L3GD20_InitStruct->Endianness
					| L3GD20_InitStruct->Full_Scale);

	/* Write value to MEMS CTRL_REG1 regsister */
	L3GD20_Write(&ctrl1, L3GD20_CTRL_REG1_ADDR, 1);

	/* Write value to MEMS CTRL_REG4 regsister */
	L3GD20_Write(&ctrl4, L3GD20_CTRL_REG4_ADDR, 1);

	// configure fifo
	fifoCTRL |= (uint8_t)(
			L3GD20_InitStruct->FifoMode
					| (L3GD20_InitStruct->FifoThreshold & 0x0F));
	L3GD20_Write(&fifoCTRL, L3GD20_FIFO_CTRL_REG_ADDR, 1);

	// Enable fifo is necessary
	if (L3GD20_InitStruct->FifoMode != L3GD20_FIFO_BYPASS_MODE ) {
		uint8_t enableFifo = 0x40;
		L3GD20_Write(&enableFifo, L3GD20_CTRL_REG5_ADDR, 1);
	}
}
/**
  * @brief  Set L3GD20 Initialization.
  * @param  L3GD20_InitStruct: pointer to a L3GD20_InitTypeDef structure 
  *         that contains the configuration setting for the L3GD20.
  * @retval None
  */
void L3GD20_Init(L3GD20_InitTypeDef *L3GD20_InitStruct)
{  
  uint8_t ctrl1 = 0x00, ctrl4 = 0x00;
  
  /* Configure the low level interface ---------------------------------------*/
  L3GD20_LowLevel_Init();
  
  /* Configure MEMS: data rate, power mode, full scale and axes */
  ctrl1 |= (uint8_t) (L3GD20_InitStruct->Power_Mode | L3GD20_InitStruct->Output_DataRate | \
                    L3GD20_InitStruct->Axes_Enable | L3GD20_InitStruct->Band_Width);
  
  ctrl4 |= (uint8_t) (L3GD20_InitStruct->BlockData_Update | L3GD20_InitStruct->Endianness | \
                    L3GD20_InitStruct->Full_Scale);
                    
  /* Write value to MEMS CTRL_REG1 regsister */
  L3GD20_Write(&ctrl1, L3GD20_CTRL_REG1_ADDR, 1);
  
  /* Write value to MEMS CTRL_REG4 regsister */
  L3GD20_Write(&ctrl4, L3GD20_CTRL_REG4_ADDR, 1);
}