打印

VSFBoard + CSR8510 USB蓝牙

[复制链接]
1100|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 vsfopen 于 2018-9-6 14:06 编辑

协议栈使用btstack,实例代码位于usrapp/bluetooth下,测试demo使用了btstack自带的gap_inquiry。CSR8510应该是目前最常见的USB蓝牙狗了:


下载btstack的最新代码到vsf/component/3rd下,btstack需要做一下修改:
1. hci.c文件中,修改HCI_RESET_RESEND_TIMEOUT_MS参数为2000,以前的延时时间太短,不够复位后,USB设备重新枚举
2. gap_inquiry.c中,把printf修改为vsfdbg_printf

下载运行后,打开串口,插入CSR8510的USB蓝牙狗,显示如下:




VSF中已经提供了btstack的framework移植代码,包括h2和h4的HCI接口驱动。
应用层可以简单调用对应的btstack_main:
#include "btstack_event.h"
#include "btstack_run_loop.h"
#include "btstack_memory.h"
#include "hci.h"
#include "btstack_chipset_csr.h"
#include "btstack_run_loop_vsf.h"

int btstack_main(int argc, const char * argv[]);
static void usrapp_on_new_bthci(void *dev, struct vsfusbh_device_id_t *id)
{
        if ((id->idVendor == 0x0A12) && (id->idProduct == 0x0001))
        {
                btstack_memory_init();
                btstack_run_loop_init(btstack_run_loop_vsf_get_instance());
                hci_init(hci_transport_usb_instance(), dev);
                hci_set_chipset(btstack_chipset_csr_instance());
                btstack_main(0, NULL);
        }
}

static void usrapp_usbd_conn(void *p)
{
        struct usrapp_t *app = (struct usrapp_t *)p;

        vsfusbd_device_init(&app->usbd.device);
        vsfusbd_connect(&app->usbd.device);
        if (app_hwcfg.usbd.pullup.port != VSFHAL_DUMMY_PORT)
                vsfhal_gpio_set(app_hwcfg.usbd.pullup.port, 1 << app_hwcfg.usbd.pullup.pin);

        vsfusbh_init(&usrapp.usbh.usbh);
        vsfusbh_register_driver(&usrapp.usbh.usbh, &vsfusbh_hub_drv);
        vsfusbh_bthci_config_cb(usrapp_on_new_bthci, NULL, NULL);
        vsfusbh_register_driver(&usrapp.usbh.usbh, &vsfusbh_bthci_drv);
}
在检测到USB蓝牙狗的时候,驱动回调应用层的usrapp_on_new_bthci函数,然后简单启动btstack,最后调用btstack_main。
由于btstack本身就是事件驱动的状态机,所以可以和VSF其他功能同时运行,互不干扰。

使用特权

评论回复

相关帖子

沙发
jxyfree| | 2020-2-22 19:57 | 只看该作者
不错,看看。

使用特权

评论回复
发新帖
您需要登录后才可以回帖 登录 | 注册

本版积分规则

89

主题

324

帖子

8

粉丝