#include "include.h"

#if LE_APP_EN
#include "ab_link/ab_link.h"
#endif

#if LE_EN

const bool cfg_ble_security_en = LE_PAIR_EN;
const bool cfg_ble_mtu_request_en = true;

uint bsp_get_bat_level(void);

//This function can be redefined to modify the ble address
void ble_get_local_bd_addr(u8 *addr)
{
    u8 ack_Mac[6];
    bt_get_local_bd_addr(ack_Mac);
    ack_Mac[5] ^= 0x55;
    memcpy(addr,ack_Mac,6);
}

//This function can be redefined to modify the ble address
//u8 ble_get_local_addr_mode(void)
//{
//    return 1;   //0:public 1:random no resolvable 2:random resolvable
//}

static u8 clk_res;

//needs to exchange MTU before sending
void ble_enter_transmit(void)
{
    clk_res = get_cur_sysclk();

    set_sys_clk(SYS_160M);

    ble_update_conn_param(12, 0, 400);
}

void ble_exit_transmit(void)
{
    set_sys_clk(clk_res);

    ble_update_conn_param(80, 0, 400);
}

//----------------------------------------------------------------------------
// BLE callback function
//----------------------------------------------------------------------------
void ble_disconnect_callback(void)
{
    printf("--->ble_disconnect_callback\n");
#if LE_APP_FOT_EN
    fot_ble_disconnect_callback();
#endif
}
//u8 flag=0;
void ble_connect_callback(void)
{
    printf("--->ble_connect_callback\n");
#if LE_APP_FOT_EN
    fot_ble_connect_callback();
#endif
}

uint ble_get_bat_level(void)
{
    return bsp_get_bat_level();
}

void ble_init_att(void)
{
    ble_app_init();
}
#endif // LE_EN
