CARPLAY版本整理
This commit is contained in:
22
MXC_A27-PCB4.5-270T/lib/bt/fsc_bt/config.h
Normal file
22
MXC_A27-PCB4.5-270T/lib/bt/fsc_bt/config.h
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
#ifndef __CONFIG_H__
|
||||
#define __CONFIG_H__
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "FreeRTOS.h"
|
||||
#include "queue.h"
|
||||
#include "task.h"
|
||||
#include "fscbt_interface.h"
|
||||
|
||||
#define TEST_STACK_SIZE 500000
|
||||
|
||||
extern QueueHandle_t tx_queue;
|
||||
extern QueueHandle_t rx_queue;
|
||||
extern int initialize_timeout;
|
||||
|
||||
#endif
|
||||
|
124
MXC_A27-PCB4.5-270T/lib/bt/fsc_bt/console.c
Normal file
124
MXC_A27-PCB4.5-270T/lib/bt/fsc_bt/console.c
Normal file
@ -0,0 +1,124 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "console.h"
|
||||
|
||||
QueueHandle_t tx_queue = NULL;
|
||||
QueueHandle_t rx_queue = NULL;
|
||||
|
||||
int initialize_timeout = 0;
|
||||
bt_at_callback gCallback = NULL;
|
||||
static void* gCbContex = NULL;
|
||||
static TaskHandle_t console_task_handle = NULL;
|
||||
|
||||
/*
|
||||
example to demonstrate that:
|
||||
1. recv AT response/event from blueware and print out
|
||||
the application should parse these data according to "Feasycom BT90X AT Command interface_v4.1.pdf"
|
||||
2. send AT command to blueware for call/music/phonebook control
|
||||
note:
|
||||
the applicaton should process data as soon as possilbe (otherwise the queue may overflow)
|
||||
*/
|
||||
static void console_task(void* arg)
|
||||
{
|
||||
char buf[AT_CMD_PAYLOAD_LEN];
|
||||
|
||||
gCbContex = gCbContex;//make iar happy
|
||||
for (;;)
|
||||
{
|
||||
buf[0] = '\0';
|
||||
char *response = buf;
|
||||
if (xQueueReceive(rx_queue, response, portMAX_DELAY) == pdTRUE)
|
||||
{
|
||||
response[AT_CMD_PAYLOAD_LEN-1] = '\0';
|
||||
|
||||
int response_len = strlen(response);
|
||||
// response always start/end with \r\n
|
||||
if((response_len < 4) ||
|
||||
(response[0] != '\r' || response[1] != '\n') ||
|
||||
(response[response_len-2] != '\r' || response[response_len-1] != '\n'))
|
||||
{
|
||||
printf("invalid response format !!! \n");
|
||||
continue;
|
||||
}
|
||||
|
||||
// printf("###");
|
||||
// for(uint16_t i =0;i<response_len;i++){
|
||||
// printf("%c",response[i]);
|
||||
// }
|
||||
|
||||
response[response_len-2] = '\0';
|
||||
response += 2;
|
||||
|
||||
if (NULL != gCallback)
|
||||
{
|
||||
gCallback(response);
|
||||
}
|
||||
if(strlen(response) > 4 && !memcmp(response,"+VER",4))
|
||||
{
|
||||
console_send_atcmd("AT+NAME\r\n", strlen("AT+NAME\r\n"));
|
||||
}else{
|
||||
parseBtATCommand(response,response_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int console_init(bt_at_callback cb)
|
||||
{
|
||||
pthread_t task;
|
||||
pthread_attr_t attr;
|
||||
if (NULL == gCallback)
|
||||
{
|
||||
gCallback = cb;
|
||||
}
|
||||
|
||||
if (xTaskCreate(console_task, "console", 4096, NULL,
|
||||
configMAX_PRIORITIES / 3, &console_task_handle) != pdPASS) {
|
||||
printf("create console_task task fail.\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void console_register_cb(void *ctx, bt_at_callback cb)
|
||||
{
|
||||
gCbContex = ctx;
|
||||
gCallback = cb;
|
||||
}
|
||||
|
||||
int console_send_atcmd(char* cAtCmd, unsigned short length)
|
||||
{
|
||||
if (tx_queue == NULL)
|
||||
{
|
||||
printf("console_send_atcmd tx_queue NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
char buf[AT_CMD_PAYLOAD_LEN] = {0};
|
||||
char *command;
|
||||
|
||||
if (AT_CMD_PAYLOAD_LEN <= length)
|
||||
{
|
||||
printf("console_send_atcmd invalid length. %d\r\n", length);
|
||||
return -1;
|
||||
}
|
||||
command = buf;
|
||||
memcpy(command,cAtCmd, length);
|
||||
if (pdTRUE != xQueueSend(tx_queue,command,pdMS_TO_TICKS(200)))
|
||||
{
|
||||
printf("console_send_atcmd Send failed.\r\n");
|
||||
return -1;
|
||||
}
|
||||
fscbt_wakeup(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int console_deinit(void)
|
||||
{
|
||||
if(rx_queue) vQueueDelete(rx_queue);
|
||||
if(tx_queue) vQueueDelete(tx_queue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
13
MXC_A27-PCB4.5-270T/lib/bt/fsc_bt/console.h
Normal file
13
MXC_A27-PCB4.5-270T/lib/bt/fsc_bt/console.h
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
#ifndef __CONSOLE_H__
|
||||
#define __CONSOLE_H__
|
||||
|
||||
typedef void (* bt_at_callback)(char * cAtStr);
|
||||
|
||||
int console_init(bt_at_callback cb);
|
||||
void console_register_cb(void *ctx, bt_at_callback cb);
|
||||
int console_send_atcmd(char * cAtCmd, unsigned short length);
|
||||
int console_deinit(void);
|
||||
|
||||
#endif
|
||||
|
124
MXC_A27-PCB4.5-270T/lib/bt/fsc_bt/fsc_bt.c
Normal file
124
MXC_A27-PCB4.5-270T/lib/bt/fsc_bt/fsc_bt.c
Normal file
@ -0,0 +1,124 @@
|
||||
#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;
|
||||
}
|
||||
|
9
MXC_A27-PCB4.5-270T/lib/bt/fsc_bt/fsc_bt.h
Normal file
9
MXC_A27-PCB4.5-270T/lib/bt/fsc_bt/fsc_bt.h
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
#ifndef __FSC_BT_H__
|
||||
#define __FSC_BT_H__
|
||||
|
||||
int fsc_bt_main(void);
|
||||
void fsc_bt_register_pcm_interface(void *itfc);
|
||||
|
||||
#endif
|
||||
|
106
MXC_A27-PCB4.5-270T/lib/bt/fsc_bt/fscbt_interface.h
Normal file
106
MXC_A27-PCB4.5-270T/lib/bt/fsc_bt/fscbt_interface.h
Normal file
@ -0,0 +1,106 @@
|
||||
|
||||
#ifndef __FSCBT_INTERFACE_H__
|
||||
#define __FSCBT_INTERFACE_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define AT_CMD_TX_QUEUE_LEN 20
|
||||
#define AT_CMD_RX_QUEUE_LEN 100
|
||||
#define AT_CMD_PAYLOAD_LEN 4096
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BT_A2DP_PLAY_START = 0,
|
||||
BT_A2DP_PLAY_STOP = 1,
|
||||
BT_HFP_PLAY_START = 2,
|
||||
BT_HFP_PLAY_STOP = 3,
|
||||
BT_PLAY_STATE_END
|
||||
} BT_PLAY_STATE_E;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BLE_EASY_CONNECTION = 0, /* for EASYCONNECTION */
|
||||
BLE_ERYA_CONNECTION = 1, /* for ERYA CONNECTION */
|
||||
BLE_DEFAULT_CONNECTION = 2, /* for DEFAULT CONNECTION */
|
||||
BLE_DEFAULT1_CONNECTION = 3, /* for DEFAULT1 CONNECTION */
|
||||
BLE_CONNECTION_END
|
||||
} BLE_CONNECTION_TYPE_E;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BT_UART_PORT_1 = 1, /* Uart 1 */
|
||||
BT_UART_PORT_3 = 3, /* Uart 3 */
|
||||
BT_UART_PORT_END
|
||||
} BT_UART_PORT_E;
|
||||
|
||||
#define DB0_START_ADDR ((unsigned int)0x00036000)
|
||||
#define DB0_END_ADDR ((unsigned int)0x00036fff)
|
||||
#define DB1_START_ADDR ((unsigned int)0x00037000) /* for backup database */
|
||||
#define DB1_END_ADDR ((unsigned int)0x00037FFF)
|
||||
|
||||
typedef int (* bt_play_state_callback)(BT_PLAY_STATE_E state, unsigned short samplerate, unsigned char channel);
|
||||
typedef int (* bt_pcm_data_callback)(unsigned char* buffer, unsigned short length);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int bt_en_pin;
|
||||
unsigned int uartport;
|
||||
unsigned int flashaddr; /* Start Block Flash Address for Database. Default address is 0x00036000*/
|
||||
unsigned int flashaddr1; /* Start Block Flash Address for bakeup Database. Default address is 0x00037000 */
|
||||
}bt_hw_cfg_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void* tx_queue; /* AT-Command sent from upper layer application to blueware */
|
||||
void* rx_queue; /* AT-Response sent from blueware to upper layer application */
|
||||
int a2dp_resampler; /* not support.default 0 */
|
||||
int debug_mode; /* turn blueware debug log on/off */
|
||||
bt_play_state_callback play_state_cb; /* play state callback function */
|
||||
bt_pcm_data_callback a2dp_cb; /* a2dp pcm data callback function */
|
||||
bt_pcm_data_callback hfp_spk_cb; /* hfp spk pcm data callback function */
|
||||
unsigned char ble_connection_type; /* BLE_CONNECTION_TYPE_E */
|
||||
unsigned char ancs_enable; /* ancs on/off */
|
||||
unsigned char absvol_enable; /* abs vol on/off */
|
||||
}bt_sw_cfg_t;
|
||||
|
||||
/*!
|
||||
\brief: initialise bluetooth stack (blueware)
|
||||
\param hw_cfg: hardware configuration
|
||||
\param sw_cfg: software configuration
|
||||
*/
|
||||
int fscbt_init(const bt_hw_cfg_t *hw_cfg,const bt_sw_cfg_t *sw_cfg);
|
||||
|
||||
/*!
|
||||
\brief: blueware main loop , running in a standalone task
|
||||
*/
|
||||
void fscbt_run(void);
|
||||
|
||||
/*!
|
||||
\brief: wake up blueooth task from sleeping
|
||||
\param from_isr: set to 1 if call from isr, othewise set to 0
|
||||
*/
|
||||
void fscbt_wakeup(int from_isr);
|
||||
|
||||
/*!
|
||||
\brief: push mic data to bt send buffer.
|
||||
|
||||
\param *buffer: data to Send
|
||||
length: data length. 160 bytes default.
|
||||
\return: sent data length
|
||||
*/
|
||||
int fscbt_push_mic_data(unsigned char* buffer, unsigned short length);
|
||||
|
||||
/*!
|
||||
\brief: get avrcp coverart image data..
|
||||
|
||||
\param * pu32len: Image Data Length.
|
||||
0:No Data.
|
||||
\return:
|
||||
JPG Image Data Address:
|
||||
start data: 0xff, 0xd8
|
||||
end data:0xff,0xd9
|
||||
*/
|
||||
void fscbt_get_coverart_data(char** pImage,unsigned int* pu32len);
|
||||
|
||||
#endif
|
||||
|
BIN
MXC_A27-PCB4.5-270T/lib/bt/fsc_bt/lib/blueware.a
Normal file
BIN
MXC_A27-PCB4.5-270T/lib/bt/fsc_bt/lib/blueware.a
Normal file
Binary file not shown.
BIN
MXC_A27-PCB4.5-270T/lib/bt/fsc_bt/lib/blueware_bw2231.a
Normal file
BIN
MXC_A27-PCB4.5-270T/lib/bt/fsc_bt/lib/blueware_bw2231.a
Normal file
Binary file not shown.
BIN
MXC_A27-PCB4.5-270T/lib/bt/fsc_bt/lib/blueware_ec.a
Normal file
BIN
MXC_A27-PCB4.5-270T/lib/bt/fsc_bt/lib/blueware_ec.a
Normal file
Binary file not shown.
BIN
MXC_A27-PCB4.5-270T/lib/bt/fsc_bt/lib/blueware_ey.a
Normal file
BIN
MXC_A27-PCB4.5-270T/lib/bt/fsc_bt/lib/blueware_ey.a
Normal file
Binary file not shown.
Reference in New Issue
Block a user