本文将介绍基于Android11 系统下i.MX8MQ设备添加光强传感器驱动调试介绍:
1. Linux 部分
opt3001驱动文件
./drivers/iio/light/opt3001.c
在挂载I2C节点下添加设备树
opt3001: opt3001@44 {
compatible = "ti,opt3001";
reg = < 0x44 >;
pinctrl-0 = < &pinctrl_i2c1_dsi_ts_int >;
interrupt-parent = < &gpio3 >;
interrupts = < 10 IRQ_TYPE_EDGE_RISING >;
status = "okay";
};
别忘记在iomux下添加IO初始化,在节点&iomuxc
pinctrl_i2c1_dsi_ts_int: dsi_ts_int {
fsl,pins = <
MX8MQ_IOMUXC_NAND_DATA04_GPIO3_IO10 0x19
>;
};
添加内核配置
CONFIG_OPT3001=y
调试相关 :
可以用i2cdetect 工具进行检测opt3001是否存在
图中0x44已经发现是存在的。
Linux 加载成功后,可以看到在iio子系统下看到一个新的设备:
evk_8mq:/ # ls /sys/bus/iio/devices/iio:device0/
current_timestamp_clock in_illuminance_input name subsystem
dev in_illuminance_integration_time of_node uevent
events integration_time_available power
2. Android 修改部分
device/nxp/imx8m/evk_8mq/evk_8mq.mk中新增内容
USE_SENSOR_MULTI_HAL := true
BOARD_USE_SENSOR_FUSION := true
TARGET_SUPPORT_DIRECT_REPORT := true
# Enable sensor Version V_2
USE_SENSOR_HAL_VER := 2.0
PRODUCT_PACKAGES +=
android.hardware.sensors@2.0-nxp-IIO-Subhal
android.hardware.sensors@2.0-service.multihal
android.hardware.sensors@2.0-service.multihal.rc
PRODUCT_COPY_FILES +=
frameworks/native/data/etc/android.hardware.sensor.accelerometer.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.accelerometer.xml
frameworks/native/data/etc/android.hardware.sensor.assist.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.assist.xml
frameworks/native/data/etc/android.hardware.sensor.compass.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.compass.xml
frameworks/native/data/etc/android.hardware.sensor.gyroscope.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.gyroscope.xml
frameworks/native/data/etc/android.hardware.sensor.light.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.light.xml
frameworks/native/data/etc/android.hardware.sensor.proximity.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.proximity.xml
frameworks/native/data/etc/android.hardware.sensor.barometer.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.barometer.xml
frameworks/native/data/etc/android.hardware.sensor.stepcounter.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.stepcounter.xml
frameworks/native/data/etc/android.hardware.sensor.stepdetector.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.stepdetector.xml
frameworks/native/data/etc/android.hardware.sensor.hifi_sensors.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.hifi_sensors.xml
PRODUCT_COPY_FILES +=
$(IMX_PATH)/imx/iio_sensor/hals.conf:vendor/etc/sensors/hals.conf
$(IMX_PATH)/imx/iio_sensor/config/sensor_hal_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/sensors/sensor_hal_configuration.xml
$(IMX_PATH)/imx/iio_sensor/config/sensor_hal_configuration.xsd:$(TARGET_COPY_OUT_VENDOR)/etc/sensors/sensor_hal_configuration.xsd
PRODUCT_COPY_FILES +=
$(IMX_PATH)/imx/iio_sensor/config/sensor_hal_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/odm/etc/sensors/sensor_hal_configuration.xml
PRODUCT_COPY_FILES +=
$(IMX_DEVICE_PATH)/thermal_info_config_imx8mq.json:$(TARGET_COPY_OUT_VENDOR)/etc/configs/thermal_info_config_imx8mq.json
其实在device/nxp/imx8m/evk_8mq/evk_8mq.mk主要是将sensor 这个服务进行加入编译,选定版本,再把一些文件进行拷贝。
修改./vendor/nxp-opensource/imx/iio_sensor/SensorsSubHal.cpp
将opt3001传感器加入到列表中
static const std::vector< sensors_supported_hal > sensors_supported = {
SENSOR_SUPPORTED("fxas21002c", SensorType::GYROSCOPE),
SENSOR_SUPPORTED("mpl3115", SensorType::PRESSURE),
SENSOR_SUPPORTED("mpl3115", SensorType::TEMPERATURE),
SENSOR_SUPPORTED("fxos8700", SensorType::ACCELEROMETER),
SENSOR_SUPPORTED("fxos8700", SensorType::MAGNETIC_FIELD),
SENSOR_SUPPORTED("opt3001", SensorType::LIGHT), //add LIGHT SENSOR
};
但是添加完毕后发现还是存在问题,进一步发现中间层代码存在问题
./vendor/nxp-opensource/imx/iio_sensor/LightSensor.cpp
LightSensor::LightSensor(int32_t sensorHandle, ISensorsEventCallback* callback,
struct iio_device_data& iio_data,
const std::optional< std::vector< Configuration > >& config)
: HWSensorBase(sensorHandle, callback, iio_data, config) {
// no power_microwatts sys node, so mSensorInfo.power fake the default one.
mSensorInfo.power = 0.001f;
mSensorInfo.flags |= V1_0::SensorFlagBits::DATA_INJECTION | V1_0::SensorFlagBits::ON_CHANGE_MODE;
std::string time_file;
//time_file = iio_data.sysfspath + "/in_illuminance_integration_time_available";
time_file = iio_data.sysfspath + "/integration_time_available"; //opt3001
get_sampling_time_available(time_file, &iio_data.sampling_time_avl);
//...... 省略代码
}
./vendor/nxp-opensource/imx/iio_sensor/iio_utils.cpp
//static const char* IIO_LIGHT_INPUT = "in_illuminance0_input";
static const char* IIO_LIGHT_INPUT = "in_illuminance_input";
根据xml文件提示android.hardware.sernsors支持1.0与2.0-1版本,这里将选用1.0即可。
./hardware/interfaces/compatibility_matrices/compatibility_matrix.5.xml【无需添加】
< hal format="hidl" optional="true" >
< name >android.hardware.sensors< /name >
< version >1.0< /version >
< version >2.0-1< /version >
< interface >
< name >ISensors< /name >
< instance >default< /instance >
< /interface >
< /hal >
./device/nxp/imx8m/evk_8mq/manifest.xml【需要添加】
添加sensors
< hal format="hidl" >
< name >android.hardware.sensors< /name >
< transport >hwbinder< /transport >
< version >1.0< /version >
< interface >
< name >ISensors< /name >
< instance >default< /instance >
< /interface >
< fqname >@1.0::ISensors/default< /fqname >
< /hal >
安卓部分添加完毕,直接编译既可;
烧写系统可以查看相关信息,
命令:dumpsys sensorservice
3. 问题:
发现通过光强传感器自动调整屏幕亮度非常低钝,可以修改以下文件解决:
frameworks/base/core/res/res/values/config.xml
< integer name="config_autoBrightnessBrighteningLightDebounce" >1500< /integer >
< integer name="config_autoBrightnessDarkeningLightDebounce" >1500< /integer >
评论
查看更多