本文將介紹基于Android11 系統(tǒng)下i.MX8MQ設(shè)備添加光強(qiáng)傳感器驅(qū)動調(diào)試介紹:
1. Linux 部分
opt3001驅(qū)動文件
./drivers/iio/light/opt3001.c
在掛載I2C節(jié)點(diǎn)下添加設(shè)備樹
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初始化,在節(jié)點(diǎn)&iomuxc
pinctrl_i2c1_dsi_ts_int: dsi_ts_int {
fsl,pins = <
MX8MQ_IOMUXC_NAND_DATA04_GPIO3_IO10 0x19
?>;
};
添加內(nèi)核配置
CONFIG_OPT3001=y
調(diào)試相關(guān) :
可以用i2cdetect 工具進(jìn)行檢測opt3001是否存在
圖中0x44已經(jīng)發(fā)現(xiàn)是存在的。
Linux 加載成功后,可以看到在iio子系統(tǒng)下看到一個新的設(shè)備:
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中新增內(nèi)容
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
其實(shí)在device/nxp/imx8m/evk_8mq/evk_8mq.mk主要是將sensor 這個服務(wù)進(jìn)行加入編譯,選定版本,再把一些文件進(jìn)行拷貝。
修改./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
};
但是添加完畢后發(fā)現(xiàn)還是存在問題,進(jìn)一步發(fā)現(xiàn)中間層代碼存在問題
./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";
根據(jù)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 >
安卓部分添加完畢,直接編譯既可;
燒寫系統(tǒng)可以查看相關(guān)信息,
命令:dumpsys sensorservice
3. 問題:
發(fā)現(xiàn)通過光強(qiáng)傳感器自動調(diào)整屏幕亮度非常低鈍,可以修改以下文件解決:
frameworks/base/core/res/res/values/config.xml
< integer name="config_autoBrightnessBrighteningLightDebounce" >1500< /integer >
< integer name="config_autoBrightnessDarkeningLightDebounce" >1500< /integer >
評論
查看更多