一、环境介绍

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,源码结构

2022/04/29  17:12             6,971 Accelerometer.cpp
2022/04/29  17:12             1,532 Accelerometer.h
2022/04/29  17:12             8,555 Android.mk
2022/04/29  17:12             3,184 android_KK_defconfig
2022/04/29  17:12             3,227 android_L_defconfig
2022/04/29  17:12             3,227 android_M_defconfig
2022/04/29  17:12             3,227 android_N_defconfig
2022/04/29  17:12             3,296 android_O_defconfig
2022/04/29  17:12             3,356 android_P_defconfig
2022/04/29  17:12             3,398 android_Q_defconfig
2022/04/29  17:12             3,386 android_R_defconfig
2022/04/29  17:12             1,782 ChangeODRTimestampStack.cpp
2022/04/29  17:12             1,407 ChangeODRTimestampStack.h
2022/04/29  17:12             3,903 CircularBuffer.cpp
2022/04/29  17:12             1,563 CircularBuffer.h
2022/04/29  17:12             3,695 common_data.h
2022/04/29  17:12             1,496 DeviceOrientation.cpp
2022/04/29  17:12             1,191 DeviceOrientation.h
2022/04/29  17:12             2,453 DynamicSensorProxy.cpp
2022/04/29  17:12             1,680 DynamicSensorProxy.h
2022/04/29  17:12             1,882 FlushBufferStack.cpp
2022/04/29  17:12             1,425 FlushBufferStack.h
2022/04/29  17:12             1,223 FlushRequested.cpp
2022/04/29  17:12             1,263 FlushRequested.h
2022/04/29  17:12             1,848 Gesture.cpp
2022/04/29  17:12             1,264 Gesture.h
2022/04/29  17:12             7,439 Gyroscope.cpp
2022/04/29  17:12             1,776 Gyroscope.h
2022/04/29  17:12            27,339 HWSensorBase.cpp
2022/04/29  17:12             4,279 HWSensorBase.h
2022/04/29  17:12             6,015 Magnetometer.cpp
2022/04/29  17:12             1,540 Magnetometer.h
2022/04/29  17:12             1,701 Pressure.cpp
2022/04/29  17:12             1,116 Pressure.h
2022/04/29  17:12             1,759 RHumidity.cpp
2022/04/29  17:12             1,132 RHumidity.h
2022/04/29  17:12            10,134 RingBuffer.cpp
2022/04/29  17:12             2,393 RingBuffer.h
2022/04/29  17:12             2,986 SelfTest.cpp
2022/04/29  17:12             1,285 SelfTest.h
2022/04/29  17:12             1,869 SensorAdditionalInfo.cpp
2022/04/29  17:12             1,524 SensorAdditionalInfo.h
2022/04/29  17:12            22,098 SensorBase.cpp
2022/04/29  17:12             8,760 SensorBase.h
2022/04/29  17:12           106,872 SensorHAL.cpp
2022/04/29  17:12             6,754 SensorHAL.h
2022/04/29  17:12             1,769 SignificantMotion.cpp
2022/04/29  17:12             1,205 SignificantMotion.h
2022/04/29  17:12             3,137 StepCounter.cpp
2022/04/29  17:12             1,244 StepCounter.h
2022/04/29  17:12             2,168 StepDetector.cpp
2022/04/29  17:12             1,247 StepDetector.h
2022/04/29  17:12             2,720 SWAccelerometerUncalibrated.cpp
2022/04/29  17:12             1,361 SWAccelerometerUncalibrated.h
2022/04/29  17:12             4,833 SWAccelGyroFusion6X.cpp
2022/04/29  17:12             1,227 SWAccelGyroFusion6X.h
2022/04/29  17:12             4,994 SWAccelMagnFusion6X.cpp
2022/04/29  17:12             1,227 SWAccelMagnFusion6X.h
2022/04/29  17:12             5,260 SWAccelMagnGyroFusion9X.cpp
2022/04/29  17:12             1,254 SWAccelMagnGyroFusion9X.h
2022/04/29  17:12             3,226 SWGameRotationVector.cpp
2022/04/29  17:12             1,321 SWGameRotationVector.h
2022/04/29  17:12             1,253 SWGeoMagRotationVector.cpp
2022/04/29  17:12             1,018 SWGeoMagRotationVector.h
2022/04/29  17:12             2,363 SWGravity.cpp
2022/04/29  17:12             1,249 SWGravity.h
2022/04/29  17:12             2,657 SWGyroscopeUncalibrated.cpp
2022/04/29  17:12             1,336 SWGyroscopeUncalibrated.h
2022/04/29  17:12             2,589 SWLinearAccel.cpp
2022/04/29  17:12             1,303 SWLinearAccel.h
2022/04/29  17:12             1,774 SWMagnetometerUncalibrated.cpp
2022/04/29  17:12             1,039 SWMagnetometerUncalibrated.h
2022/04/29  17:12             1,531 SWOrientation.cpp
2022/04/29  17:12               958 SWOrientation.h
2022/04/29  17:12             1,636 SWRotationVector.cpp
2022/04/29  17:12               979 SWRotationVector.h
2022/04/29  17:12            12,457 SWSensorBase.cpp
2022/04/29  17:12             2,484 SWSensorBase.h
2022/04/29  17:12             1,214 SWVirtualGyroscope.cpp
2022/04/29  17:12               991 SWVirtualGyroscope.h
2022/04/29  17:12             1,726 Temp.cpp
2022/04/29  17:12             1,097 Temp.h
2022/04/29  17:12             1,794 TiltSensor.cpp
2022/04/29  17:12             1,199 TiltSensor.h
2022/04/29  17:12            25,399 utils.cpp
2022/04/29  17:12             5,302 utils.h
2022/04/29  17:12             1,341 WristTiltGesture.cpp
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.cpp HAL框架
ChangeODRTimestampStack.h HAL框架
CircularBuffer.cpp HAL框架
CircularBuffer.h HAL框架
RingBuffer.cpp HAL框架
RingBuffer.h HAL框架
SelfTest.cpp HAL框架
SelfTest.h HAL框架
common_data.h HAL框架
DynamicSensorProxy.cpp HAL框架
DynamicSensorProxy.h HAL框架
FlushBufferStack.cpp HAL框架
FlushBufferStack.h HAL框架
FlushRequested.cpp HAL框架
FlushRequested.h HAL框架
SensorAdditionalInfo.cpp HAL框架
SensorAdditionalInfo.h HAL框架
utils.cpp HAL框架 工具类
utils.h HAL框架
HWSensorBase.cpp HAL框架 传感器次基类
HWSensorBase.h HAL框架
SensorBase.cpp HAL框架 传感器基类
SensorBase.h HAL框架
SensorHAL.cpp HAL框架 对接系统上层接口
SensorHAL.h HAL框架
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的加速度传感器为例,源码:

#ifdef CONFIG_ST_HAL_LSM6DSR_ENABLED
	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)
#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;

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

num_channels=4
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]
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]
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]
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流程)

LSM6DSRAccelerometerSensor--read_size=48scan_size=16(read_size/scan_size)=3
LSM6DSRAccelerometerSensor--data[0]=0x17
LSM6DSRAccelerometerSensor--data[1]=0xFF
LSM6DSRAccelerometerSensor--data[2]=0xDF
LSM6DSRAccelerometerSensor--data[3]=0xFF
LSM6DSRAccelerometerSensor--data[4]=0xDA
LSM6DSRAccelerometerSensor--data[5]=0x7
LSM6DSRAccelerometerSensor--data[6]=0xFF
LSM6DSRAccelerometerSensor--data[7]=0xFF
LSM6DSRAccelerometerSensor--data[8]=0xDB
LSM6DSRAccelerometerSensor--data[9]=0x7C
LSM6DSRAccelerometerSensor--data[10]=0xA1
LSM6DSRAccelerometerSensor--data[11]=0xEC
LSM6DSRAccelerometerSensor--data[12]=0x9
LSM6DSRAccelerometerSensor--data[13]=0x0
LSM6DSRAccelerometerSensor--data[14]=0x0
LSM6DSRAccelerometerSensor--data[15]=0x0
LSM6DSRAccelerometerSensor--data[16]=0x17
LSM6DSRAccelerometerSensor--data[17]=0xFF
LSM6DSRAccelerometerSensor--data[18]=0xDF
LSM6DSRAccelerometerSensor--data[19]=0xFF
LSM6DSRAccelerometerSensor--data[20]=0xDB
LSM6DSRAccelerometerSensor--data[21]=0x7
LSM6DSRAccelerometerSensor--data[22]=0xFF
LSM6DSRAccelerometerSensor--data[23]=0xFF
LSM6DSRAccelerometerSensor--data[24]=0xDB
LSM6DSRAccelerometerSensor--data[25]=0x40
LSM6DSRAccelerometerSensor--data[26]=0xDE
LSM6DSRAccelerometerSensor--data[27]=0xEE
LSM6DSRAccelerometerSensor--data[28]=0x9
LSM6DSRAccelerometerSensor--data[29]=0x0
LSM6DSRAccelerometerSensor--data[30]=0x0
LSM6DSRAccelerometerSensor--data[31]=0x0
LSM6DSRAccelerometerSensor--data[32]=0x18
LSM6DSRAccelerometerSensor--data[33]=0xFF
LSM6DSRAccelerometerSensor--data[34]=0xE0
LSM6DSRAccelerometerSensor--data[35]=0xFF
LSM6DSRAccelerometerSensor--data[36]=0xDC
LSM6DSRAccelerometerSensor--data[37]=0x7
LSM6DSRAccelerometerSensor--data[38]=0xFF
LSM6DSRAccelerometerSensor--data[39]=0xFF
LSM6DSRAccelerometerSensor--data[40]=0xDB
LSM6DSRAccelerometerSensor--data[41]=0x4
LSM6DSRAccelerometerSensor--data[42]=0x1B
LSM6DSRAccelerometerSensor--data[43]=0xF1
LSM6DSRAccelerometerSensor--data[44]=0x9
LSM6DSRAccelerometerSensor--data[45]=0x0
LSM6DSRAccelerometerSensor--data[46]=0x0
LSM6DSRAccelerometerSensor--data[47]=0x0
num_channels=4
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]
input=65303le16toh
val=-233shift
val=-233sign
sensor_out_data->raw[k]=-1.114905process_2byte_received
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]
input=65503le16toh
val=-33shift
val=-33sign
sensor_out_data->raw[k]=-0.157905process_2byte_received
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]
input=2010le16toh
val=2010shift
val=2010sign
sensor_out_data->raw[k]=9.617849process_2byte_received
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]
num_channels=4
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]
input=65303le16toh
val=-233shift
val=-233sign
sensor_out_data->raw[k]=-1.114905process_2byte_received
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]
input=65503le16toh
val=-33shift
val=-33sign
sensor_out_data->raw[k]=-0.157905process_2byte_received
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]
input=2011le16toh
val=2011shift
val=2011sign
sensor_out_data->raw[k]=9.622635process_2byte_received
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]
num_channels=4
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]
input=65304le16toh
val=-232shift
val=-232sign
sensor_out_data->raw[k]=-1.11012process_2byte_received
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]
input=65504le16toh
val=-32shift
val=-32sign
sensor_out_data->raw[k]=-0.15312process_2byte_received
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]
input=2012le16toh
val=2012shift
val=2012sign
sensor_out_data->raw[k]=9.627419process_2byte_received
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

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

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

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

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

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

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐