/****************************************************************************************************/
/**
Copyright (c) 2009 Freescale Semiconductor
Freescale Confidential Proprietary
\file       Accel.c
\brief      
\author     Freescale Semiconductor
\author     Applications Austin, Texas
\author     
\version    0.3
\date       Aug/2009
*/
/****************************************************************************************************/
/*                                                                                                  */
/* All software, source code, included documentation, and any implied know-how are property of      */
/* Freescale Semiconductor and therefore considered CONFIDENTIAL INFORMATION.                       */
/* This confidential information is disclosed FOR DEMONSTRATION PURPOSES ONLY.                      */
/*                                                                                                  */
/* All Confidential Information remains the property of Freescale Semiconductor and will not be     */
/* copied or reproduced without the express written permission of the Discloser, except for copies  */
/* that are absolutely necessary in order to fulfill the Purpose.                                   */
/*                                                                                                  */
/* Services performed by FREESCALE in this matter are performed AS IS and without any warranty.     */
/* CUSTOMER retains the final decision relative to the total design and functionality of the end    */
/* product.                                                                                         */
/* FREESCALE neither guarantees nor will be held liable by CUSTOMER for the success of this project.*/
/*                                                                                                  */
/* FREESCALE disclaims all warranties, express, implied or statutory including, but not limited to, */
/* implied warranty of merchantability or fitness for a particular purpose on any hardware,         */
/* software ore advise supplied to the project by FREESCALE, and or any product resulting from      */
/* FREESCALE services.                                                                              */
/* In no event shall FREESCALE be liable for incidental or consequential damages arising out of     */
/* this agreement. CUSTOMER agrees to hold FREESCALE harmless against any and all claims demands or */
/* actions by anyone on account of any damage,or injury, whether commercial, contractual, or        */
/* tortuous, rising directly or indirectly as a result of the advise or assistance supplied CUSTOMER*/ 
/* in connectionwith product, services or goods supplied under this Agreement.                      */
/*                                                                                                  */
/****************************************************************************************************/

#include "IO_Map.h"
#include "Accel.h"     
#include "LL64_ADC.h"  /* ADC defines */
#include "ACCEL_SLEEP_B.h"

/************************** variable Declarations ******************************/




  void Accel_WakeUp(void){
  
  /* PTB5 is tied to the Accelerometer Sleep bar       */
  ACCEL_SLEEP_B_SetDir(1);
  ACCEL_SLEEP_B_SetVal() ;
  
  }
  
unsigned int Accel_GetX(void){
    ADCCFG1 =(ADLPC_NORMAL|ADIV_8|ADLSMP_LONG|MODE_12|ADICLK_BUS);
    ADCSC3 = (ADCO_SINGLE);
    ADCSC1_ADCH = 5;       //ADP5 = X Axis
    
    do{
    }while (ADCSC2_ADACT == 1); /* Wait for conversion to complete */
    return(ADCR);
}
unsigned int Accel_GetY(void) {
   ADCCFG1 =(ADLPC_NORMAL|ADIV_8|ADLSMP_LONG|MODE_12|ADICLK_BUS);
   ADCSC3 = (ADCO_SINGLE);
   ADCSC1_ADCH = 6;       //ADP6
   do{
   }while (ADCSC2_ADACT == 1); /* Wait for conversion to complete */
   return(ADCR);

}

unsigned int Accel_GetZ(void) {
   ADCCFG1 =(ADLPC_NORMAL|ADIV_8|ADLSMP_LONG|MODE_12|ADICLK_BUS);
   ADCSC3 = (ADCO_SINGLE);
   ADCSC1_ADCH = 7;       //ADP6
   do{
   }while (ADCSC2_ADACT == 1); /* Wait for conversion to complete */
   return(ADCR);
}
  
void Accel_Sleep(void){
  ACCEL_SLEEP_B_ClrVal();
  }
void Accel_ZeroG(void){
  asm nop;
} 
