• 【android12-linux-5.1】【ST芯片】【RK3588】【LSM6DSR】HAL源码分析


    一、环境介绍

    RK3588主板搭载Android12操作系统,内核是Linux5.10,使用ST的六轴传感器LSM6DSR芯片。

    二、芯片介绍

    LSM6DSR是一款加速度和角速度(陀螺仪)六轴传感器,还内置了一个温度传感器。该芯片可以选择I2C,SPI通讯,还有可编程终端,可以后置摄像头等设备,功能是很强大的(感兴趣的可以去看数据手册)。该芯片原厂公开了input和iio两种驱动和HAL,我这边选用的是iio驱动,所以HAL也配套选择了iio的。

    三、驱动移植

    【android12-linux-5.1】【ST芯片】【RK3588】【LSM6DSR】驱动移植__花花的博客-CSDN博客

    四、HAL移植

    【android12-linux-5.1】【ST芯片】【RK3588】【LSM6DSR】HAL移植__花花的博客-CSDN博客

    五、源码结构

    1,包总结构

    2,源码结构

    1. 2022/04/29 17:12 6,971 Accelerometer.cpp
    2. 2022/04/29 17:12 1,532 Accelerometer.h
    3. 2022/04/29 17:12 8,555 Android.mk
    4. 2022/04/29 17:12 3,184 android_KK_defconfig
    5. 2022/04/29 17:12 3,227 android_L_defconfig
    6. 2022/04/29 17:12 3,227 android_M_defconfig
    7. 2022/04/29 17:12 3,227 android_N_defconfig
    8. 2022/04/29 17:12 3,296 android_O_defconfig
    9. 2022/04/29 17:12 3,356 android_P_defconfig
    10. 2022/04/29 17:12 3,398 android_Q_defconfig
    11. 2022/04/29 17:12 3,386 android_R_defconfig
    12. 2022/04/29 17:12 1,782 ChangeODRTimestampStack.cpp
    13. 2022/04/29 17:12 1,407 ChangeODRTimestampStack.h
    14. 2022/04/29 17:12 3,903 CircularBuffer.cpp
    15. 2022/04/29 17:12 1,563 CircularBuffer.h
    16. 2022/04/29 17:12 3,695 common_data.h
    17. 2022/04/29 17:12 1,496 DeviceOrientation.cpp
    18. 2022/04/29 17:12 1,191 DeviceOrientation.h
    19. 2022/04/29 17:12 2,453 DynamicSensorProxy.cpp
    20. 2022/04/29 17:12 1,680 DynamicSensorProxy.h
    21. 2022/04/29 17:12 1,882 FlushBufferStack.cpp
    22. 2022/04/29 17:12 1,425 FlushBufferStack.h
    23. 2022/04/29 17:12 1,223 FlushRequested.cpp
    24. 2022/04/29 17:12 1,263 FlushRequested.h
    25. 2022/04/29 17:12 1,848 Gesture.cpp
    26. 2022/04/29 17:12 1,264 Gesture.h
    27. 2022/04/29 17:12 7,439 Gyroscope.cpp
    28. 2022/04/29 17:12 1,776 Gyroscope.h
    29. 2022/04/29 17:12 27,339 HWSensorBase.cpp
    30. 2022/04/29 17:12 4,279 HWSensorBase.h
    31. 2022/04/29 17:12 6,015 Magnetometer.cpp
    32. 2022/04/29 17:12 1,540 Magnetometer.h
    33. 2022/04/29 17:12 1,701 Pressure.cpp
    34. 2022/04/29 17:12 1,116 Pressure.h
    35. 2022/04/29 17:12 1,759 RHumidity.cpp
    36. 2022/04/29 17:12 1,132 RHumidity.h
    37. 2022/04/29 17:12 10,134 RingBuffer.cpp
    38. 2022/04/29 17:12 2,393 RingBuffer.h
    39. 2022/04/29 17:12 2,986 SelfTest.cpp
    40. 2022/04/29 17:12 1,285 SelfTest.h
    41. 2022/04/29 17:12 1,869 SensorAdditionalInfo.cpp
    42. 2022/04/29 17:12 1,524 SensorAdditionalInfo.h
    43. 2022/04/29 17:12 22,098 SensorBase.cpp
    44. 2022/04/29 17:12 8,760 SensorBase.h
    45. 2022/04/29 17:12 106,872 SensorHAL.cpp
    46. 2022/04/29 17:12 6,754 SensorHAL.h
    47. 2022/04/29 17:12 1,769 SignificantMotion.cpp
    48. 2022/04/29 17:12 1,205 SignificantMotion.h
    49. 2022/04/29 17:12 3,137 StepCounter.cpp
    50. 2022/04/29 17:12 1,244 StepCounter.h
    51. 2022/04/29 17:12 2,168 StepDetector.cpp
    52. 2022/04/29 17:12 1,247 StepDetector.h
    53. 2022/04/29 17:12 2,720 SWAccelerometerUncalibrated.cpp
    54. 2022/04/29 17:12 1,361 SWAccelerometerUncalibrated.h
    55. 2022/04/29 17:12 4,833 SWAccelGyroFusion6X.cpp
    56. 2022/04/29 17:12 1,227 SWAccelGyroFusion6X.h
    57. 2022/04/29 17:12 4,994 SWAccelMagnFusion6X.cpp
    58. 2022/04/29 17:12 1,227 SWAccelMagnFusion6X.h
    59. 2022/04/29 17:12 5,260 SWAccelMagnGyroFusion9X.cpp
    60. 2022/04/29 17:12 1,254 SWAccelMagnGyroFusion9X.h
    61. 2022/04/29 17:12 3,226 SWGameRotationVector.cpp
    62. 2022/04/29 17:12 1,321 SWGameRotationVector.h
    63. 2022/04/29 17:12 1,253 SWGeoMagRotationVector.cpp
    64. 2022/04/29 17:12 1,018 SWGeoMagRotationVector.h
    65. 2022/04/29 17:12 2,363 SWGravity.cpp
    66. 2022/04/29 17:12 1,249 SWGravity.h
    67. 2022/04/29 17:12 2,657 SWGyroscopeUncalibrated.cpp
    68. 2022/04/29 17:12 1,336 SWGyroscopeUncalibrated.h
    69. 2022/04/29 17:12 2,589 SWLinearAccel.cpp
    70. 2022/04/29 17:12 1,303 SWLinearAccel.h
    71. 2022/04/29 17:12 1,774 SWMagnetometerUncalibrated.cpp
    72. 2022/04/29 17:12 1,039 SWMagnetometerUncalibrated.h
    73. 2022/04/29 17:12 1,531 SWOrientation.cpp
    74. 2022/04/29 17:12 958 SWOrientation.h
    75. 2022/04/29 17:12 1,636 SWRotationVector.cpp
    76. 2022/04/29 17:12 979 SWRotationVector.h
    77. 2022/04/29 17:12 12,457 SWSensorBase.cpp
    78. 2022/04/29 17:12 2,484 SWSensorBase.h
    79. 2022/04/29 17:12 1,214 SWVirtualGyroscope.cpp
    80. 2022/04/29 17:12 991 SWVirtualGyroscope.h
    81. 2022/04/29 17:12 1,726 Temp.cpp
    82. 2022/04/29 17:12 1,097 Temp.h
    83. 2022/04/29 17:12 1,794 TiltSensor.cpp
    84. 2022/04/29 17:12 1,199 TiltSensor.h
    85. 2022/04/29 17:12 25,399 utils.cpp
    86. 2022/04/29 17:12 5,302 utils.h
    87. 2022/04/29 17:12 1,341 WristTiltGesture.cpp
    88. 2022/04/29 17:12 1,202 WristTiltGesture.h

    3,源码文件概要

    文件名类型备注
    Android.mk配置文件编译配置
    android_KK_defconfig配置文件android_KK系统配置文件
    android_L_defconfig配置文件android_L系统配置文件
    android_M_defconfig配置文件android_M系统配置文件
    android_N_defconfig配置文件android_N系统配置文件
    android_O_defconfig配置文件android_O系统配置文件
    android_P_defconfig配置文件android_P系统配置文件
    android_Q_defconfig配置文件android_Q系统配置文件
    android_R_defconfig配置文件android_R系统配置文件
    ChangeODRTimestampStack.cppHAL框架
    ChangeODRTimestampStack.hHAL框架
    CircularBuffer.cppHAL框架
    CircularBuffer.hHAL框架
    RingBuffer.cppHAL框架
    RingBuffer.hHAL框架
    SelfTest.cppHAL框架
    SelfTest.hHAL框架
    common_data.hHAL框架
    DynamicSensorProxy.cppHAL框架
    DynamicSensorProxy.hHAL框架
    FlushBufferStack.cppHAL框架
    FlushBufferStack.hHAL框架
    FlushRequested.cppHAL框架
    FlushRequested.hHAL框架
    SensorAdditionalInfo.cppHAL框架
    SensorAdditionalInfo.hHAL框架
    utils.cppHAL框架工具类
    utils.hHAL框架
    HWSensorBase.cppHAL框架传感器次基类
    HWSensorBase.hHAL框架
    SensorBase.cppHAL框架传感器基类
    SensorBase.hHAL框架
    SensorHAL.cppHAL框架对接系统上层接口
    SensorHAL.hHAL框架
    Accelerometer.cpp芯片传感器类加速度传感器子类
    Accelerometer.h芯片传感器类
    Gesture.cpp芯片传感器类
    Gesture.h芯片传感器类
    Gyroscope.cpp芯片传感器类陀螺仪子类
    Gyroscope.h芯片传感器类
    Magnetometer.cpp芯片传感器类磁力计子类
    Magnetometer.h芯片传感器类
    Pressure.cpp芯片传感器类压力计子类
    Pressure.h芯片传感器类
    RHumidity.cpp芯片传感器类湿度计子类
    RHumidity.h芯片传感器类
    Temp.cpp芯片传感器类温度计子类
    Temp.h芯片传感器类
    SignificantMotion.cpp芯片传感器类特殊动作触发子类
    SignificantMotion.h芯片传感器类
    StepCounter.cpp芯片传感器类计步器子类
    StepCounter.h芯片传感器类
    StepDetector.cpp芯片传感器类步测子类
    StepDetector.h芯片传感器类
    TiltSensor.cpp芯片传感器类倾斜检测子类
    TiltSensor.h芯片传感器类
    WristTiltGesture.cpp芯片传感器类手腕倾斜手势检测子类
    WristTiltGesture.h芯片传感器类
    DeviceOrientation.cpp芯片传感器类设备角度检测子类
    DeviceOrientation.h芯片传感器类
    SWAccelerometerUncalibrated.cpp软件传感器类
    SWAccelerometerUncalibrated.h软件传感器类
    SWAccelGyroFusion6X.cpp软件传感器类
    SWAccelGyroFusion6X.h软件传感器类
    SWAccelMagnFusion6X.cpp软件传感器类
    SWAccelMagnFusion6X.h软件传感器类
    SWAccelMagnGyroFusion9X.cpp软件传感器类
    SWAccelMagnGyroFusion9X.h软件传感器类
    SWGameRotationVector.cpp软件传感器类
    SWGameRotationVector.h软件传感器类
    SWGeoMagRotationVector.cpp软件传感器类
    SWGeoMagRotationVector.h软件传感器类
    SWGravity.cpp软件传感器类
    SWGravity.h软件传感器类
    SWGyroscopeUncalibrated.cpp软件传感器类
    SWGyroscopeUncalibrated.h软件传感器类
    SWLinearAccel.cpp软件传感器类
    SWLinearAccel.h软件传感器类
    SWMagnetometerUncalibrated.cpp软件传感器类
    SWMagnetometerUncalibrated.h软件传感器类
    SWOrientation.cpp软件传感器类
    SWOrientation.h软件传感器类
    SWRotationVector.cpp软件传感器类
    SWRotationVector.h软件传感器类
    SWSensorBase.cpp软件传感器类
    SWSensorBase.h软件传感器类
    SWVirtualGyroscope.cpp软件传感器类
    SWVirtualGyroscope.h软件传感器类
    六,源码分析

    本文主要从传感器注册到数据读取流程分析,并取加速度传感器子类做概要分析。

    1,传感器注册流程

    1)SensorHAL.cpp中ST_sensors_supported结构体数组的列表含括所有支持的传感器列表及基本配置,以LSM6DSR的加速度传感器为例,源码:

    1. #ifdef CONFIG_ST_HAL_LSM6DSR_ENABLED
    2. ST_HAL_NEW_SENSOR_SUPPORTED(CONCATENATE_STRING(ST_SENSORS_LIST_46, ACCEL_NAME_SUFFIX_IIO), SENSOR_TYPE_ACCELEROMETER, DEVICE_IIO_ACC, "LSM6DSR Accelerometer Sensor", 0.0f)
    3. #endif /* CONFIG_ST_HAL_LSM6DSR_ENABLED */

    1> CONFIG_ST_HAL_LSM6DSR_ENABLED是配置文件/hardware/STMicroelectronics/SensorHAL_IIO/configuration.h中配置的,设置为1才能支持该传感器

    2> ST_SENSORS_LIST_46定义在SensorHAL.h中,是传感器设备型号名称,用于后续传感器注册检索

    #define ST_SENSORS_LIST_46				"lsm6dsr"

    3> ACCEL_NAME_SUFFIX_IIO定义在SensorHAL.h中,是传感器类型,用于后续传感器注册检索

    #define ACCEL_NAME_SUFFIX_IIO				"_accel"

    4> 结合2>和3>,再回顾下驱动移植篇,传感器设备全名“lsm6dsr_accel”就满足该配置的检索要求

    5> SENSOR_TYPE_ACCELEROMETER定义在/prebuilts/vndk/v31/x86_64/include/hardware/libhardware/include/hardware/sensors-base.h中,与应用层传感器类型对应。

    6> DEVICE_IIO_ACC定义在/hardware/STMicroelectronics/SensorHAL_IIO/src/utils.h中。

    7> "LSM6DSR Accelerometer Sensor"是上送到SensorManger的传感器名称。

    2)HAL入口定义

    3)st_hal_open_sensors函数主要流程

    1> 内存与接口指针初始化

    2> iio设备自动检索载入st_hal_load_iio_devices_data

    3>基于载入的设备实例化传感器类st_hal_create_class_sensor

    4>基于载入的设备实例化软件传感器类st_hal_create_virtual_class_sensor

    5>针对数据读取通道的设备开启数据读取线程

    pthread_create(&hal_data->data_threads[j], NULL, &SensorBase::ThreadDataWork, (void *)temp_sensor_class[i]);

    6>针对有事件通道的设备开启数据事件获取线程

    pthread_create(&hal_data->events_threads[k], NULL, &SensorBase::ThreadEventsWork, (void *)temp_sensor_class[i]);

    2,设备自动检索载入流程(st_hal_load_iio_devices_data)

    该函数会检索可用设备并设置,存储其必要参数。

    1>device_iio_utils::get_devices_name检索"/sys/bus/iio/devices/"路径下的iio设备并记录其设备号与设备名称。

    2>遍历检索所得设备名称,与HAL支持的设备列表做对比ST_sensors_supported,能匹配的上的设备才做处理。

    3>检索支持设备的通道数据device_iio_utils::scan_channel

    检索设备路径下scan_elements目录,使能所有xxx_en文件并读取确认,读取所有支持的类型并记录通道信息。在get_type函数中,读取xxx__type文件并解析内容,存储通道数据读取信息。该数据将用于后续数据读取线程的数据解析。

    小彩蛋:在get_type函数中有一个小bug,该问题在后续更新的版本中已修复。会引起bits_used大于16时,mask数据为0,后续得到的数据结果也为0。

    修改前代码:常量数据1默认数据类型为整型int,该类型占16位,1左移大于16位时,有效值溢出了,有效位中数值将为0。

    channel->mask = (1 << channel->bits_used) - 1;
    

    修改后代码:

    channel->mask = ((unsigned long long int)1 << channel->bits_used) - 1;

    以加速度计为例,检索到的数据通道信息如下:

    1. num_channels=4
    2. channels[0].name=[in_accel_x].type_name=[(null)].index=[0].enabled=[1].scale=[0.004785].offset=[0.000000].bytes=[2].bits_used=[16].shift=[0].mask=[65535].be=[0].sign=[1].location=[0]
    3. channels[1].name=[in_accel_y].type_name=[(null)].index=[1].enabled=[1].scale=[0.004785].offset=[0.000000].bytes=[2].bits_used=[16].shift=[0].mask=[65535].be=[0].sign=[1].location=[2]
    4. channels[2].name=[in_accel_z].type_name=[(null)].index=[2].enabled=[1].scale=[0.004785].offset=[0.000000].bytes=[2].bits_used=[16].shift=[0].mask=[65535].be=[0].sign=[1].location=[4]
    5. channels[3].name=[in_timestamp].type_name=[(null)].index=[3].enabled=[1].scale=[1.000000].offset=[0.000000].bytes=[8].bits_used=[64].shift=[0].mask=[-1].be=[0].sign=[1].location=[8]

    4>关闭使能设备device_iio_utils::enable_sensor

    数据0写入到设备路径下"buffer/enable"文件。

    5>设置时钟device_iio_utils::set_clock_type

    数据"boottime"写入到设备路径下"current_timestamp_clock"文件。

    6>获取支持的采样频率列表device_iio_utils::get_sampling_frequency_available

    读取设备路径下“sampling_frequency_available”文件,获取采样频率列表。

    7>获取支持的分辨率列表device_iio_utils::get_available_scales

    读取设备路径下“in_xxx_scale_available”文件,获取分辨率列表。

    8>设定设备到最高分辨率st_hal_set_fullscale

    计算最高分辨率并写入到设备路径下"in_xxx_xxx_scale"文件中。

    9>取设备缓冲区长度device_iio_utils::get_hw_fifo_length

    读取设备路径下“hwfifo_watermark_max”文件,将读到的数据乘以2再写入到“buffer/length”文件,“hwfifo_enabled”写入1使能硬件缓冲区。(此处理解描述可能有点不到位,后续有更准确的描述请私信我修改,作为回报将退回VIP查看费用)

    3,数据读取流程(SensorBase::ThreadDataWork)

    1)基本流程(HWSensorBase::ThreadDataTask())

    按设备硬件缓冲区长度开辟缓冲区malloc;死循环检索设备“/dev/iio:device”是否可读poll;若设备可读,则按硬件缓冲区长度读取其中数据。读取到数据后按载入设备时获取到的通道信息进行解析(ProcessScanData)。后处理时间戳(一定要求,不然数据不能正常上送)等信息,这部分比较复杂,也非当前必须内容,我就没分析了。

    2)数据解析ProcessScanData

    该函数流程是解析单组数据,根据每个数据通道信息,获取location偏移地址的bits_used长度数据,将数据按然后shift移位后再与上mask(取有效位,处理负数情况),后将获得的原始采样数据加上偏移量offse后再乘以分辨率scale。

    以加速度计为例,获取到的一份数据解析日志(按ThreadDataTask流程)

    1. LSM6DSRAccelerometerSensor--read_size=48scan_size=16(read_size/scan_size)=3
    2. LSM6DSRAccelerometerSensor--data[0]=0x17
    3. LSM6DSRAccelerometerSensor--data[1]=0xFF
    4. LSM6DSRAccelerometerSensor--data[2]=0xDF
    5. LSM6DSRAccelerometerSensor--data[3]=0xFF
    6. LSM6DSRAccelerometerSensor--data[4]=0xDA
    7. LSM6DSRAccelerometerSensor--data[5]=0x7
    8. LSM6DSRAccelerometerSensor--data[6]=0xFF
    9. LSM6DSRAccelerometerSensor--data[7]=0xFF
    10. LSM6DSRAccelerometerSensor--data[8]=0xDB
    11. LSM6DSRAccelerometerSensor--data[9]=0x7C
    12. LSM6DSRAccelerometerSensor--data[10]=0xA1
    13. LSM6DSRAccelerometerSensor--data[11]=0xEC
    14. LSM6DSRAccelerometerSensor--data[12]=0x9
    15. LSM6DSRAccelerometerSensor--data[13]=0x0
    16. LSM6DSRAccelerometerSensor--data[14]=0x0
    17. LSM6DSRAccelerometerSensor--data[15]=0x0
    18. LSM6DSRAccelerometerSensor--data[16]=0x17
    19. LSM6DSRAccelerometerSensor--data[17]=0xFF
    20. LSM6DSRAccelerometerSensor--data[18]=0xDF
    21. LSM6DSRAccelerometerSensor--data[19]=0xFF
    22. LSM6DSRAccelerometerSensor--data[20]=0xDB
    23. LSM6DSRAccelerometerSensor--data[21]=0x7
    24. LSM6DSRAccelerometerSensor--data[22]=0xFF
    25. LSM6DSRAccelerometerSensor--data[23]=0xFF
    26. LSM6DSRAccelerometerSensor--data[24]=0xDB
    27. LSM6DSRAccelerometerSensor--data[25]=0x40
    28. LSM6DSRAccelerometerSensor--data[26]=0xDE
    29. LSM6DSRAccelerometerSensor--data[27]=0xEE
    30. LSM6DSRAccelerometerSensor--data[28]=0x9
    31. LSM6DSRAccelerometerSensor--data[29]=0x0
    32. LSM6DSRAccelerometerSensor--data[30]=0x0
    33. LSM6DSRAccelerometerSensor--data[31]=0x0
    34. LSM6DSRAccelerometerSensor--data[32]=0x18
    35. LSM6DSRAccelerometerSensor--data[33]=0xFF
    36. LSM6DSRAccelerometerSensor--data[34]=0xE0
    37. LSM6DSRAccelerometerSensor--data[35]=0xFF
    38. LSM6DSRAccelerometerSensor--data[36]=0xDC
    39. LSM6DSRAccelerometerSensor--data[37]=0x7
    40. LSM6DSRAccelerometerSensor--data[38]=0xFF
    41. LSM6DSRAccelerometerSensor--data[39]=0xFF
    42. LSM6DSRAccelerometerSensor--data[40]=0xDB
    43. LSM6DSRAccelerometerSensor--data[41]=0x4
    44. LSM6DSRAccelerometerSensor--data[42]=0x1B
    45. LSM6DSRAccelerometerSensor--data[43]=0xF1
    46. LSM6DSRAccelerometerSensor--data[44]=0x9
    47. LSM6DSRAccelerometerSensor--data[45]=0x0
    48. LSM6DSRAccelerometerSensor--data[46]=0x0
    49. LSM6DSRAccelerometerSensor--data[47]=0x0
    50. num_channels=4
    51. channels[0].name=[in_accel_x].type_name=[(null)].index=[0].enabled=[1].scale=[0.004785].offset=[0.000000].bytes=[2].bits_used=[16].shift=[0].mask=[65535].be=[0].sign=[1].location=[0]
    52. input=65303le16toh
    53. val=-233shift
    54. val=-233sign
    55. sensor_out_data->raw[k]=-1.114905process_2byte_received
    56. channels[1].name=[in_accel_y].type_name=[(null)].index=[1].enabled=[1].scale=[0.004785].offset=[0.000000].bytes=[2].bits_used=[16].shift=[0].mask=[65535].be=[0].sign=[1].location=[2]
    57. input=65503le16toh
    58. val=-33shift
    59. val=-33sign
    60. sensor_out_data->raw[k]=-0.157905process_2byte_received
    61. channels[2].name=[in_accel_z].type_name=[(null)].index=[2].enabled=[1].scale=[0.004785].offset=[0.000000].bytes=[2].bits_used=[16].shift=[0].mask=[65535].be=[0].sign=[1].location=[4]
    62. input=2010le16toh
    63. val=2010shift
    64. val=2010sign
    65. sensor_out_data->raw[k]=9.617849process_2byte_received
    66. channels[3].name=[in_timestamp].type_name=[(null)].index=[3].enabled=[1].scale=[1.000000].offset=[0.000000].bytes=[8].bits_used=[64].shift=[0].mask=[-1].be=[0].sign=[1].location=[8]
    67. num_channels=4
    68. channels[0].name=[in_accel_x].type_name=[(null)].index=[0].enabled=[1].scale=[0.004785].offset=[0.000000].bytes=[2].bits_used=[16].shift=[0].mask=[65535].be=[0].sign=[1].location=[0]
    69. input=65303le16toh
    70. val=-233shift
    71. val=-233sign
    72. sensor_out_data->raw[k]=-1.114905process_2byte_received
    73. channels[1].name=[in_accel_y].type_name=[(null)].index=[1].enabled=[1].scale=[0.004785].offset=[0.000000].bytes=[2].bits_used=[16].shift=[0].mask=[65535].be=[0].sign=[1].location=[2]
    74. input=65503le16toh
    75. val=-33shift
    76. val=-33sign
    77. sensor_out_data->raw[k]=-0.157905process_2byte_received
    78. channels[2].name=[in_accel_z].type_name=[(null)].index=[2].enabled=[1].scale=[0.004785].offset=[0.000000].bytes=[2].bits_used=[16].shift=[0].mask=[65535].be=[0].sign=[1].location=[4]
    79. input=2011le16toh
    80. val=2011shift
    81. val=2011sign
    82. sensor_out_data->raw[k]=9.622635process_2byte_received
    83. channels[3].name=[in_timestamp].type_name=[(null)].index=[3].enabled=[1].scale=[1.000000].offset=[0.000000].bytes=[8].bits_used=[64].shift=[0].mask=[-1].be=[0].sign=[1].location=[8]
    84. num_channels=4
    85. channels[0].name=[in_accel_x].type_name=[(null)].index=[0].enabled=[1].scale=[0.004785].offset=[0.000000].bytes=[2].bits_used=[16].shift=[0].mask=[65535].be=[0].sign=[1].location=[0]
    86. input=65304le16toh
    87. val=-232shift
    88. val=-232sign
    89. sensor_out_data->raw[k]=-1.11012process_2byte_received
    90. channels[1].name=[in_accel_y].type_name=[(null)].index=[1].enabled=[1].scale=[0.004785].offset=[0.000000].bytes=[2].bits_used=[16].shift=[0].mask=[65535].be=[0].sign=[1].location=[2]
    91. input=65504le16toh
    92. val=-32shift
    93. val=-32sign
    94. sensor_out_data->raw[k]=-0.15312process_2byte_received
    95. channels[2].name=[in_accel_z].type_name=[(null)].index=[2].enabled=[1].scale=[0.004785].offset=[0.000000].bytes=[2].bits_used=[16].shift=[0].mask=[65535].be=[0].sign=[1].location=[4]
    96. input=2012le16toh
    97. val=2012shift
    98. val=2012sign
    99. sensor_out_data->raw[k]=9.627419process_2byte_received
    100. channels[3].name=[in_timestamp].type_name=[(null)].index=[3].enabled=[1].scale=[1.000000].offset=[0.000000].bytes=[8].bits_used=[64].shift=[0].mask=[-1].be=[0].sign=[1].location=[8]

    4,加速速度传感器子类(Accelerometer)

    Accelerometer(传感器类)--继承-->HWSensorBaseWithPollrate--继承-->HWSensorBase--继承-->SensorBase

    基于C++特性,在传感器类中实现特性部分即可,公共特征部分由父类实现。

    若要自己增加一个特殊的传感器,可参考该类来编码实现。

    1)构造函数Accelerometer::Accelerometer

    初始化精度、最大范围等特征值。

    2)使能函数Accelerometer::Enable

    执行校准使能(若配置支持的话)后调用父类使能函数。

    3)数据处理函数Accelerometer::ProcessData

    执行坐标系旋转,校准,和数据上送流程。

    本文只是个人笔记,可能有些问题和不足之处,欢迎指正。

    码字不易请尊重版权,本文不授权任何单位及个体转载。

    新人入行,经验分享,如有所误,欢迎指出~

    版权归属:深圳市琪智科技有限公司-花花

  • 相关阅读:
    大型企业是否有必要进行数字化转型?_数据治理平台_光点科技
    进程和线程详解
    加密货币交易所偿付能力的零知识证明
    Python测试框架 Pytest —— mock使用(pytest-mock)
    【SpringBoot】一文吃透SpringBoot多环境开发
    maven分环境打包,普通胖jar
    ubuntu20下安装nginx插件geoip2查询ip信息
    Python 3.12 目标:还可以更快!
    MySQL数据库脱敏方案
    鸿蒙跨包跳转页面-HSP页面路由
  • 原文地址:https://blog.csdn.net/lsh670660992/article/details/132699831