低功耗蓝牙ble开发随笔

1.使能广播 GAPROLE_ADVERT_ENABLED 查找与之相关函数即可

param = TRUE;
GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &param );

2.gap状态

蓝牙连接状态,可通过对状态的判断来实现相关操作,共有一下几种状态

GAPROLE_INIT = 0,                       //!< Waiting to be started 等待启动
GAPROLE_STARTED,                        //!< Started but not advertising 启动但是没有在广播
GAPROLE_ADVERTISING,                    //!< Currently Advertising 处于广播状态
GAPROLE_WAITING,  //设备启动但是没处于广播状态,处于再次广播之前的等待期间,比如关闭了广播等待再次打开广播             
//!< Device is started but not advertising, is in waiting period before advertising again
GAPROLE_WAITING_AFTER_TIMEOUT,    // 设备仅仅是从连接中超时但是未广播,在再次广播之前处于等待期间   
//!< Device just timed out from a connection but is not yet advertising, is in waiting period before advertising again
GAPROLE_CONNECTED,                      //!< In a connection 处于连接状态
GAPROLE_ERROR                           //!< Error occurred - invalid state 错误发生,无效的状态

 3.常用OSAL指令

osal_set_event( uint8 task_id, uint16 event_flag)//用于向一个 Task 发送事件,之后 Task 的事件处理函数会响应该事件。
osal_clear_event( uint8 task_id, uint16 event_flag ) //清除事件
osal_msg_send( uint8 task_id, uint8 *msg_ptr)//向一个 Task 发送消息
osal_start_timerEx(uint8 task_id, uint16 event_id, uint32 timeout_value)//开始一个应用 Timer,到达超时时间系统会向指定的 task 发送一个事件,该 timer 完成一次事件之后自动关闭,不再重发。
osal_memcpy( void *dst, const void GENERIC *src, unsigned int len)//将 len 个字节的数据从 src 拷贝到 dst 所在的地址处。

4.adc配置相关

结构体adc_Cfg_t可以配置adc的通道、模式等参数。
typedef struct _adc_Cfg_t{
uint8_t channel;
bool is_continue_mode;
uint8_t is_differential_mode;
uint8_t is_high_resolution;
}adc_Cfg_t;
channel:用于配置通道, 单端模式支持多个通道,差分模式支持一组通道。每个bit对应一个单端通道或一组差分通道。
is_continue_mode:adc工作方式,一直打开还是间隔打开。TRUE一直打着,FALSE采集一次关闭,下次需要重新打开。
is_differential_mode:是否是差分模式,全0单端模式,否则差分模式
is_high_resolution:bypass模式和attenuation模式,每个bit代表一个单端通道或一组差分通道。0代表attenuation模式,1代表bypass模式。

5.Voice声音相关

有结构体 voice_Cfg_t 可以灵活配置 Voice。数据处理则通过配置回调函数实现。
typedef struct _voice_Cfg_t{
bool voiceSelAmicDmic;
gpio_pin_e dmicDataPin;
gpio_pin_e dmicClkPin;
uint8_t amicGain;
uint8_t voiceGain;
VOICE_ENCODE_t voiceEncodeMode;
VOICE_RATE_t voiceRate;
bool voiceAutoMuteOnOff;
}voice_Cfg_t;
voiceSelAmicDmic:选择AMIC还是DMIC,选择AMIC时dmicDataPin和dmicClkPin有效,否则无效。
amicGain:用于AMIC PGA放大系数,共有两级参数可配。
voiceGain:用于VOICE放大系数,[-20dB,+20dB],每个step为0.5dB。
voiceEncodeMode:数据编码方式
voiceRate:采样率,支持8K、16K、32K、64K。
voiceAutoMuteOnOff:是否自动静音,默认0,支持。
volatile int voiceConfigStatus = hal_voice_config(cfg, voice_evt_handler_adpcm);配置Voice的参数和回调函数
6.目前问题汇总
 hidDevSendReport( uint8 id, uint8 type, uint8 len, uint8* pData )  HID蓝牙数据发送中 id 与 type的作业
ENABLE_SLAVE_LATENCY_EVENT  任务的作业
gap与gatt消息处理机制工作流程,如START_ADVERTISING_EVT事件仅在gapRole_ProcessGAPMsg( gapEventHdr_t* pMsg )消息处理函数中调用,但不知道消息在哪里发送
蓝牙名称修改后无反应,需再尝试
代码改写后开启蓝牙,蓝牙仅能在手机上扫描到,电脑上无法扫描。猜测与role角色设置有关
    if( events &  BSP_SOFT_POLLING_EVT )
    {
        keyboard_io_read();
        return ( events ^ BSP_SOFT_POLLING_EVT );
    }
    #endif
    
    // ! bsp button polling check events
    if ( events & BSP_BTN_EVT_SYSTICK )
    {
        ucKeyCode = bsp_KeyPro();//这个也对按键进行了扫描是否和上面的冲突

GATT协议层...

 学习资料:

https://e2echina.ti.com/support/wireless-connectivity/bluetooth/f/bluetooth-forum/69222/cc2540-cc2541-4-0ble TI CC2540/CC2541蓝牙4.0BLE协议栈开发(连载

https://www.ti.com/cn/lit/ml/zhcaa30/zhcaa30.pdf?ts=1684737157086 无线蓝牙开发手册

 

posted on 2023-05-11 15:37  foorun  阅读(508)  评论(0编辑  收藏  举报