This commit is contained in:
lmx
2025-10-29 13:10:02 +08:00
commit 49a07fa419
2284 changed files with 642060 additions and 0 deletions

View File

@ -0,0 +1,118 @@
#include "adapter_idev.h"
#include "adapter_idev_bt.h"
#include "adapter_idev_ble.h"
#include "list.h"
#include "os/os_api.h"
#include "circular_buf.h"
#include "app_config.h"
#include "adapter_process.h"
#include "bt_edr_fun.h"
#if TCFG_WIRELESS_MIC_ENABLE
#define LOG_TAG_CONST WIRELESSMIC
#define LOG_TAG "[IDEV_BT]"
#define LOG_ERROR_ENABLE
#define LOG_DEBUG_ENABLE
#define LOG_INFO_ENABLE
#define LOG_DUMP_ENABLE
#define LOG_CLI_ENABLE
#include "debug.h"
struct _idev_bt idev_bt;
#define __this (&idev_bt)
static int adapter_idev_bt_open(void *parm)
{
r_printf("adapter_idev_bt_open\n");
memset(__this, 0, sizeof(struct _idev_bt));
set_bt_dev_role(BT_AS_IDEV);
__this->parm = (struct _idev_bt_parm *)parm;
if (__this->parm->mode & BIT(IDEV_BLE)) {
adapter_idev_ble_open(&__this->parm->ble_parm);
}
bt_init();
__this->ble = &idev_ble;
return 0;
}
static int adapter_idev_bt_start(struct adapter_media *media)
{
printf("adapter_idev_bt_start\n");
if (__this->parm->mode & BIT(IDEV_BLE)) {
adapter_idev_ble_start(NULL);
}
return 0;
}
static int adapter_idev_bt_office(struct sys_event *event)
{
int ret = 0;
if ((u32)event->arg == SYS_BT_EVENT_TYPE_CON_STATUS) {
bt_connction_status_event_handler(&event->u.bt, __this);
} else if ((u32)event->arg == SYS_BT_EVENT_TYPE_HCI_STATUS) {
//bt_hci_event_handler(&event->u.bt, __this);
}
return ret;
}
static int adapter_idev_bt_event_deal(struct sys_event *event)
{
//r_printf("adapter_odev_bt_event_deal\n");
int ret = 0;
switch (event->type) {
case SYS_KEY_EVENT:
break;
case SYS_DEVICE_EVENT:
break;
case SYS_BT_EVENT:
adapter_idev_bt_office(event);
ret = 1;
break;
default:
break;
}
return ret;
}
static int adapter_idev_bt_close(void)
{
r_printf("adapter_idev_bt_close\n");
if (__this->parm->mode & BIT(IDEV_BLE)) {
adapter_idev_ble_close(NULL);
}
return 0;
}
static int adapter_idev_bt_stop(void *priv)
{
r_printf("adapter_idev_bt_stop\n");
if (__this->parm->mode & BIT(IDEV_BLE)) {
adapter_idev_ble_stop(NULL);
}
return 0;
}
REGISTER_ADAPTER_IDEV(adapter_idev_bt) = {
.id = ADAPTER_IDEV_BT,
.open = adapter_idev_bt_open,
.close = adapter_idev_bt_close,
.start = adapter_idev_bt_start,
.stop = adapter_idev_bt_stop,
.event_fun = adapter_idev_bt_event_deal,
};
#endif

View File

@ -0,0 +1,155 @@
#include "adapter_idev.h"
#include "adapter_idev_bt.h"
#include "adapter_idev_ble.h"
#include "app_config.h"
#include "btstack/le/att.h"
#include "btstack/le/le_user.h"
#include "ble_user.h"
#include "btcontroller_modules.h"
#include "adapter_process.h"
#include "adapter_wireless_dec.h"
#if TCFG_WIRELESS_MIC_ENABLE
#define LOG_TAG_CONST WIRELESSMIC
#define LOG_TAG "[IDEV_BLE]"
#define LOG_ERROR_ENABLE
#define LOG_DEBUG_ENABLE
#define LOG_INFO_ENABLE
#define LOG_DUMP_ENABLE
#define LOG_CLI_ENABLE
#include "debug.h"
struct _idev_ble idev_ble;
#define __this (&idev_ble)
extern void bt_ble_adv_enable(u8 enable);
extern void bt_ble_init(void);
int adpter_ble_send_data(u8 *data, u16 len)
{
if (__this->ble_opt) {
u32 vaild_len = __this->ble_opt->get_buffer_vaild(0);
if (vaild_len >= len) {
return __this->ble_opt->send_data(NULL, data, len);
}
}
return 0;
}
static void adapter_ble_send_wakeup(void)
{
//putchar('W');
}
static void adapter_ble_status_callback(void *priv, ble_state_e status)
{
switch (status) {
case BLE_ST_IDLE:
break;
case BLE_ST_ADV:
break;
case BLE_ST_CONNECT:
break;
case BLE_ST_DISCONN:
case BLE_ST_SEND_DISCONN:
adapter_process_event_notify(ADAPTER_EVENT_IDEV_MEDIA_CLOSE, 0);
break;
case BLE_ST_NOTIFY_IDICATE:
break;
case BLE_ST_CONNECTION_UPDATE_OK:
adapter_process_event_notify(ADAPTER_EVENT_IDEV_MEDIA_OPEN, 0);
break;
default:
break;
}
}
static void adapter_ble_recieve_cbk(void *priv, u8 *buf, u16 len)
{
//r_printf("adapter --- ble_api_rx(%d) \n", len);
//printf_buf(buf, len);
adapter_wireless_dec_frame_write(buf, len);
}
int adapter_idev_ble_open(void *priv)
{
r_printf("adapter_idev_ble_open\n");
if (__this->status == IDEV_BLE_OPEN) {
g_printf("adapter_idev_ble_already_open\n");
return 0;
}
memset(__this, 0, sizeof(struct _idev_ble));
#if TRANS_DATA_EN || BLE_WIRELESS_MIC_SERVER_EN
ble_get_server_operation_table(&__this->ble_opt);
__this->ble_opt->regist_recieve_cbk(0, adapter_ble_recieve_cbk);
__this->ble_opt->regist_state_cbk(0, adapter_ble_status_callback);
__this->ble_opt->regist_wakeup_send(NULL, adapter_ble_send_wakeup);
#endif
__this->status = IDEV_BLE_OPEN;
return 0;
}
int adapter_idev_ble_start(void *priv)
{
r_printf("adapter_idev_ble_start\n");
if (__this->status == IDEV_BLE_START) {
r_printf("adapter_idev_ble_already_start\n");
return 0;
}
__this->status = IDEV_BLE_START;
#if TRANS_DATA_EN || BLE_WIRELESS_MIC_SERVER_EN
bt_ble_init();
#endif
return 0;
}
int adapter_idev_ble_stop(void *priv)
{
r_printf("adapter_idev_ble_stop\n");
if (__this->status == IDEV_BLE_STOP) {
r_printf("adapter_idev_ble_already_stop\n");
return 0;
}
__this->status = IDEV_BLE_STOP;
#if BLE_CLIENT_EN || TRANS_MULTI_BLE_EN || BLE_WIRELESS_MIC_SERVER_EN
ble_module_enable(0);
#endif
return 0;
}
int adapter_idev_ble_close(void *priv)
{
r_printf("adapter_idev_ble_close\n");
if (__this->status == IDEV_BLE_CLOSE) {
r_printf("adapter_idev_ble_already_close\n");
return 0;
}
__this->status = IDEV_BLE_CLOSE;
#if BLE_CLIENT_EN || TRANS_MULTI_BLE_EN || BLE_WIRELESS_MIC_SERVER_EN
ble_module_enable(0);
#endif
return 0;
}
int adapter_idev_ble_config(int cmd, void *parm)
{
switch (cmd) {
case 0:
break;
default:
break;
}
return 0;
}
#endif

View File

@ -0,0 +1,31 @@
#ifndef __ADAPTER_IDEV_BLE_H__
#define __ADAPTER_IDEV_BLE_H__
#include "generic/typedef.h"
enum {
IDEV_BLE_CLOSE,
IDEV_BLE_OPEN,
IDEV_BLE_START,
IDEV_BLE_STOP,
};
struct _idev_ble_parm {
};
struct _idev_ble {
u8 status;
struct ble_server_operation_t *ble_opt;
};
int adapter_idev_ble_open(void *priv);
int adapter_idev_ble_start(void *priv);
int adapter_idev_ble_stop(void *priv);
int adapter_idev_ble_close(void *priv);
int adapter_idev_ble_config(int cmd, void *parm);
extern struct _idev_ble idev_ble;
#endif//__ADAPTER_IDEV_BLE_H__

View File

@ -0,0 +1,24 @@
#ifndef __ADAPTER_IDEV_BT_H__
#define __ADAPTER_IDEV_BT_H__
#include "generic/typedef.h"
#include "adapter_idev_ble.h"
enum {
IDEV_EDR = 0x0,
IDEV_BLE,
};
struct _idev_bt_parm {
u8 mode;
struct _idev_ble_parm ble_parm;
};
struct _idev_bt {
struct _idev_bt_parm *parm;
struct _idev_ble *ble;
};
#endif//__ADAPTER_IDEV_BT_H__