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


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

#if (HAL_CFG_BT_TYPE == HAL_CFG_BT_TYPE_BCM)
#include "ble_bcm_interface.h"
#endif

#if (HAL_CFG_BT_TYPE == HAL_CFG_BT_TYPE_NRF)
#include "nrf_ble_interface.h"
#endif

#if (HAL_CFG_BT_TYPE == HAL_CFG_BT_TYPE_BCM)
ST_HAL_BT_INTERFACE gHalBtInterface[] =
{
{
    .pfnInit	= bcm_bt_init,
    .pfnDeinit	= bcm_bt_deinit,
    .pfnOpen	= bcm_bt_open,
    .pfnClose	= bcm_bt_close,
    .pfnAdv		= bcm_bt_adv,
    .pfnGetState		= bcm_bt_get_state,
    .pfnSendData		= bcm_bt_send_data,
    .pfnEnterSleepMode	= bcm_bt_enter_sleep_mode,
    .pfnRegisterCB		= bcm_bt_register_callback,
    .pfnFactoryTest		= bcm_bt_factory_test,
}
};
#endif

#if (HAL_CFG_BT_TYPE == HAL_CFG_BT_TYPE_NRF)
ST_HAL_BT_INTERFACE_NRF gHalBtInterface[] =
{
{
	.pfnBleCInit			= User_BLE_Init,
	.pfnBleCDeInit			= User_BLE_DeInit,
	.pfnBleCReset           = User_BLE_Reset,
	.pfnBleCScan			= User_BLE_Scan,
    .pfnBleCConn			= User_BLE_Connect,
    .pfnBleCDisconn			= User_BLE_Disconnect,
    .pfnBleCDataSend        = User_BLE_SendData,
  	.pfnBleCDataRcv         = User_BLE_RcvData,
  	.pfnBleCEnterBoot       = User_BLE_Enter_Boot,
  	.pfnBleCOTAProcess      = User_BLE_OTA,
  	.pfnBleCGetSWVer        = User_BLE_GET_VER,
}
};
#endif

#if (HAL_CFG_BT_TYPE != HAL_CFG_BT_TYPE_NRF)

ST_HAL_BT_INTERFACE * HAL_Bt_GetInterface(int32_t channel)
{
#if (HAL_CFG_BT_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 &gHalBtInterface[idx];
#endif
}

#else

ST_HAL_BT_INTERFACE_NRF * HAL_Bt_GetInterface(int32_t channel)
{
#if (HAL_CFG_BT_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 &gHalBtInterface[idx];
#endif
}

#endif
