Android4.2关于bluetooth在HAL层的分析

1.一些常用的数据结构
hardware/libhardware/include/hardware.h中
定义了三个重要的结构:
struct hw_module_t; //模块类型
struct hw_module_methods_t;   //模块方法
struct hw_device_t;   //设备类型

hw_module_t中包含结构hw_module_methods_t
hw_module_methods_t只有一个唯一的Open方法,如下:
 
int (*open)(const struct hw_module_t* module, const char* id,struct hw_device_t** device);
struct hw_device_t中包含hw_module_t结构和一个close方法如下:
 
int (*close)(struct hw_device_t* device);
这几个结构十分关键,是HAL层向上暴露的接口。

2.定义蓝牙HAL层结构
在hardware/libhardware/include/bluetooth.h中定义以下关键结构
首先是定义的蓝牙模块ID
#define BT_HARDWARE_MODULE_ID "bluetooth"
#define BT_STACK_MODULE_ID "bluetooth"
#define BT_STACK_TEST_MODULE_ID "bluetooth_test"

其次是定义的蓝牙硬件设备接口
//要求自定义xxx_device_t的第一个成员必须是hw_device_t类型,其次才是其它的一些接口信息.   
typedef struct {
    struct hw_device_t common;
    const bt_interface_t* (*get_bluetooth_interface)();
} bluetooth_device_t;

除了这个结构,还必须定义关hw_module_t类型的实例HAL_MODULE_INFO_SYM。这个结构在Bluedroid的bluetooth.c中定义。
//变量名必须为HAL_MODULE_INFO_SYM,这是强制要求的,你要写Android的HAL就得遵循这个游戏规则
struct hw_module_t HAL_MODULE_INFO_SYM = {
    .tag = HARDWARE_MODULE_TAG,
    .version_major = 1,
    .version_minor = 0,
    .id = BT_HARDWARE_MODULE_ID,
    .name = "Bluetooth Stack",
    .author = "The Android Open Source Project",
    .methods = &bt_stack_module_methods 
};
定义的bt_stack_module_methods如下:
static int open_bluetooth_stack (const struct hw_module_t* module, char const* name, struct hw_device_t** abstraction)
{
    bluetooth_device_t *stack = malloc(sizeof(bluetooth_device_t) ); 
    memset(stack, 0, sizeof(bluetooth_device_t) );
    stack->common.tag = HARDWARE_DEVICE_TAG;
    stack->common.version = 0;
    stack->common.module = (struct hw_module_t*)module;
    stack->common.close = close_bluetooth_stack;
    stack->get_bluetooth_interface = bluetooth__get_bluetooth_interface; 
    *abstraction = (struct hw_device_t*)stack;  //GJ:强制转换,bluetooth_device_t的第一个成员为hw_device_t,传到上层
    return 0;
}
static struct hw_module_methods_t bt_stack_module_methods = {
    .open = open_bluetooth_stack,
};

/packages/apps/Bluetooth/jni/com_android_bluetooth_btservice_AdapterService.cpp中实现的是bluetooth的JNI代码,是上层Java与下层Bluedroid的接口。
在static void classInitNative(JNIEnv* env, jclass clazz)函数中有以下部分code:
    char value[PROPERTY_VALUE_MAX];
    property_get("bluetooth.mock_stack", value, ""); //
    const char *id = (strcmp(value, "1")? BT_STACK_MODULE_ID : BT_STACK_TEST_MODULE_ID);
    //JNI获取HAL层模块的通用方式,根据模块ID获得hw_module_t对象
    err = hw_get_module(id, (hw_module_t const**)&module); 
    if (err == 0) 
    {
        hw_device_t* abstraction;
        err = module->methods->open(module, id, &abstraction);
        if (err == 0)
       
    //强制转换,bluetooth_module_t的第一个成员为abstraction
            bluetooth_module_t* btStack = (bluetooth_module_t *)abstraction; 
            sBluetoothInterface = btStack->get_bluetooth_interface();  //GJ:JAVA层的sBuletooth获得bluedroid中实现的bluetoothInterface
        } 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
########################BT FM ########################## Download the image using command: 1 # Flash Image Put the board in Flashing mode. Refer below Appendix - 1 cd <your path>/Nvidia_Demo/android_gb_cardhu_os_image sudo ./nvflash --bct flash.bct --setbct --odmdata 0x40080105 --configfile flash.cfg --create --bl bootloader.bin --go #################################################################################################################################################################################################### Appendix - 1 Nvidia Board in Flashing Mode #################################################################################################################################################################################################### 1. Connect the Debug board to Cardhu board. 2. Connect the power supply and Micro USB to Cardhu 3. On the Debug Board Press S12 (FRC RCV), Keeping this pressed Press and release S7 (RESET), Now Release S12. 4. Now Device is in Flashing mode, We can start nvflash command now. #################################################################################################################################################################################################### Appendix - 2 Nvidia Board Keys (On Debug Board) #################################################################################################################################################################################################### 1. S7 (RESET) --> is the RESET button. 2. S5 (ROW1) --> is the BACK button. 2. S10 (ROW2) --> is the Home button. 4. S6 (ON KEY) --> is Wake up button. #################################################################################################################################################################################################### Appendix - 3 Nvidia Board unavailable Keys workaround #################################################################################################################################################################################################### 1.To execute teh specific keys, provide the key inputs from adb shell. Provide the keyevent for the desired key.Refer teh key list below. Eg: for MENU key run adb shell #input keyevent 82 { "STAR", 17 }, { "POUND", 18 }, { "DPAD_UP", 19 }, { "DPAD_DOWN", 20 }, { "DPAD_LEFT", 21 }, { "DPAD_RIGHT", 22 }, { "DPAD_CENTER", 23 }, { "VOLUME_UP", 24 }, { "VOLUME_DOWN", 25 }, { "POWER", 26 }, { "CAMERA", 27 }, { "CLEAR", 28 }, { "HEADSETHOOK", 79 }, { "FOCUS", 80 }, { "PLUS", 81 }, { "MENU", 82 }, { "NOTIFICATION", 83 }, { "SEARCH", 84 }, { "MEDIA_PLAY_PAUSE", 85 }, { "MEDIA_STOP", 86 }, { "MEDIA_NEXT", 87 },

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值