125 lines
3.9 KiB
C
125 lines
3.9 KiB
C
#include "config.h"
|
||
#include "console.h"
|
||
#include "board.h"
|
||
|
||
static bt_sw_cfg_t g_bt_cfg;
|
||
static TaskHandle_t fsc_bt_task_handle = NULL;
|
||
|
||
void fsc_bt_register_pcm_interface(void *itfc)
|
||
{
|
||
memcpy((void*)&g_bt_cfg, itfc, sizeof(bt_sw_cfg_t));
|
||
}
|
||
|
||
static void fsc_bt_callback(char * cAtStr)
|
||
{
|
||
char* cmd = NULL;
|
||
//printf("fsc_bt_callback %s\r\n", cAtStr);
|
||
if (0) {
|
||
} else if (0 == strncmp(cAtStr, "+VER", 4)) {
|
||
cmd = "AT+ADDR\r\n";
|
||
console_send_atcmd(cmd, strlen(cmd));//get mac addr
|
||
} else if (0 == strncmp(cAtStr, "+ADDR=", 6)) {
|
||
char cmd_str[64] = {0};
|
||
sprintf(cmd_str, "AT+NAME=EY_%s\r\n", (cAtStr + 6));
|
||
console_send_atcmd(cmd_str, strlen(cmd_str));//get mac addr
|
||
}
|
||
}
|
||
static int fsc_bt_play_state_callback(BT_PLAY_STATE_E state, unsigned short samplerate, unsigned char channel)
|
||
{
|
||
printf("fsc_bt_play_state_callback state %d samplerate %d channel %d\r\n", state, samplerate, channel);
|
||
return 0;
|
||
}
|
||
|
||
static int fsc_bt_a2dp_pcm_data_callback(unsigned char* buffer, unsigned short length)
|
||
{
|
||
/* 蓝牙音乐播放数据 采样率为44100或48000,2 channel 16bit,直接输出到I2S设备 */
|
||
//printf("a2dp length %d 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x \r\n", length, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]);
|
||
return 0;
|
||
}
|
||
|
||
static int fsc_bt_hfp_spk_pcm_data_callback(unsigned char* buffer, unsigned short length)
|
||
{
|
||
/* 蓝牙电话下行数据 采样率为8000或16000,1 channel 16bit,直接输出到I2S设备 */
|
||
//if (buffer[0] || buffer[1] || buffer[2] || buffer[3])
|
||
//printf("spk length %d 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x \r\n", length, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]);
|
||
return 0;
|
||
}
|
||
|
||
static void bt_task(void* arg)
|
||
{
|
||
// bluetooth stack require none volatile storage to store configuration (e.g. device name) and paired record link key and etc.
|
||
// the file name is "bw_conf0.db" and "bw_conf1.db"
|
||
// do not setup uart in itpInit , as blueware will do this job.
|
||
bt_hw_cfg_t bt_hw_cfg = {BT_RESET_IO, BT_UART_PORT};
|
||
bt_sw_cfg_t bt_sw_cfg;
|
||
// for AT-Command sent from upper layer application to blueware
|
||
tx_queue = xQueueCreate(AT_CMD_TX_QUEUE_LEN, (unsigned portBASE_TYPE) sizeof(char)*AT_CMD_PAYLOAD_LEN);
|
||
// for AT-Response sent from blueware to upper layer application
|
||
rx_queue = xQueueCreate(AT_CMD_RX_QUEUE_LEN, (unsigned portBASE_TYPE) sizeof(char)*AT_CMD_PAYLOAD_LEN);
|
||
|
||
if(!tx_queue || !rx_queue)
|
||
{
|
||
goto die;
|
||
}
|
||
|
||
console_init(fsc_bt_callback);
|
||
|
||
bt_hw_cfg.bt_en_pin = BT_RESET_IO;
|
||
bt_hw_cfg.uartport = BT_UART_PORT;
|
||
bt_hw_cfg.flashaddr = DB0_START_ADDR;
|
||
bt_hw_cfg.flashaddr1 = DB1_START_ADDR;
|
||
|
||
bt_sw_cfg.rx_queue = rx_queue;
|
||
bt_sw_cfg.tx_queue = tx_queue;
|
||
bt_sw_cfg.a2dp_resampler = 0;
|
||
bt_sw_cfg.debug_mode = 0; // debug toggle
|
||
#if CARLINK_EC
|
||
bt_sw_cfg.ble_connection_type = BLE_EASY_CONNECTION;
|
||
#else
|
||
bt_sw_cfg.ble_connection_type = BLE_ERYA_CONNECTION;
|
||
#endif
|
||
bt_sw_cfg.ancs_enable = 0;
|
||
bt_sw_cfg.absvol_enable = 0;
|
||
|
||
if (g_bt_cfg.play_state_cb)
|
||
bt_sw_cfg.play_state_cb = g_bt_cfg.play_state_cb;
|
||
else
|
||
bt_sw_cfg.play_state_cb = fsc_bt_play_state_callback;
|
||
|
||
if (g_bt_cfg.a2dp_cb)
|
||
bt_sw_cfg.a2dp_cb = g_bt_cfg.a2dp_cb;
|
||
else
|
||
bt_sw_cfg.a2dp_cb = fsc_bt_a2dp_pcm_data_callback;
|
||
|
||
if (g_bt_cfg.hfp_spk_cb)
|
||
bt_sw_cfg.hfp_spk_cb = g_bt_cfg.hfp_spk_cb;
|
||
else
|
||
bt_sw_cfg.hfp_spk_cb = fsc_bt_hfp_spk_pcm_data_callback;
|
||
|
||
fscbt_init(&bt_hw_cfg, &bt_sw_cfg);
|
||
|
||
while(!initialize_timeout)
|
||
{
|
||
// do nothing else here
|
||
fscbt_run();
|
||
}
|
||
|
||
die:
|
||
console_deinit();
|
||
}
|
||
|
||
int fsc_bt_main(void)
|
||
{
|
||
if (fsc_bt_task_handle)
|
||
return 0;
|
||
/* Create a task to process uart rx data */
|
||
if (xTaskCreate(bt_task, "bt_main", 4096, NULL,
|
||
configMAX_PRIORITIES / 3, &fsc_bt_task_handle) != pdPASS) {
|
||
printf("create fsc_bt_thread task fail.\n");
|
||
return -1;
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
|