/*************************************************  
  File name     : hal_interface_gsensor.c
  Module        : hal gsensor library interface
  Author        : 
  Version       :
  Created on    : 2020-10-20
  Description   :
      Data structure and function definitions required by 
      the gsensor interface
    
  Modify History:   
  1. Date:        Author:         Modification:
  2020-10-20    amir.liang         create
*************************************************/
#include "pal.h"
#include "hal_product_config.h"
#include "hal_interface_gsensor.h"
#include "hal_interface.h"


#ifndef HAL_CFG_GSENSOR_TYPE
#error HAL_CFG_GSENSOR_TYPE undefined !!! Go to "hal_gernerate_product_config_h.sh" settings
#endif


#if (HAL_CFG_GSENSOR_TYPE == HAL_CFG_GSENSOR_TYPE_T31)

#elif (HAL_CFG_GSENSOR_TYPE == HAL_CFG_GSENSOR_TYPE_MCU)
#include "mcu_gsensor.h"
#elif (HAL_CFG_GSENSOR_TYPE == HAL_CFG_GSENSOR_TYPE_6441)
#include "atbm6441_gsensor.h"
#endif


ST_HAL_GSENSOR_INTERFACE gHalGSensorInterface[] = 
{
#if (HAL_CFG_GSENSOR_TYPE == HAL_CFG_GSENSOR_TYPE_MCU)
{
    .pfnInit            = Mcu_Gsensor_Init,
    .pfnDeinit          = Mcu_Gsensor_Deinit,
    .pfnSetSensitivity  = Mcu_Gsensor_SetSensitivity,
    .pfnGetSensitivity  = Mcu_Gsensor_GetSensitivity,
    .pfnSetSwitch       = Mcu_Gsensor_SetSwitch,
    .pfnGetSwitch       = Mcu_Gsensor_GetSwitch,
    .pfnGetValue        = Mcu_Gsensor_GetValue,
},
#elif (HAL_CFG_GSENSOR_TYPE == HAL_CFG_GSENSOR_TYPE_6441)
{
    .pfnInit            = Atbm6441_Gsensor_Init,
    .pfnDeinit          = Atbm6441_Gsensor_Deinit,
    .pfnSetSensitivity  = Atbm6441_Gsensor_SetSensitivity,
    .pfnGetSensitivity  = Atbm6441_Gsensor_GetSensitivity,
    .pfnSetSwitch       = Atbm6441_Gsensor_SetSwitch,
    .pfnGetSwitch       = Atbm6441_Gsensor_GetSwitch,
    .pfnGetValue        = Atbm6441_Gsensor_GetValue,
},
#endif
};


ST_HAL_GSENSOR_INTERFACE * HAL_GSensor_GetInterface(int32_t Channel)
{
#if (HAL_CFG_GSENSOR_TYPE == HAL_TYPE_NONE)
    return NULL;

#else
    HAL_ITF_INDEX idx = HAL_SELF;

    if ( Channel == HAL_CHANNEL_SELF )
    {
        idx = HAL_SELF;
    }
    else
    {
        // 需要从NV获取通道号Channel对应的设备类型对应的hal
        //idx = HAL_REMOTE_SUB1G;
        return NULL;
    }
    return &gHalGSensorInterface[idx];
#endif
}

