From 9f343b14911eaf6769798fbd8526eee2c6af4492 Mon Sep 17 00:00:00 2001 From: "Yang.Chen" Date: Mon, 6 Jun 2022 14:25:22 +0800 Subject: [PATCH] Modify sensor initialize function Summary: - A sensor may have i2c mux in front of the sensor, so check whether has pre_sensor_read_hook to do pre-sensor read. Test Plan: - Build code: Pass --- common/service/sensor/sensor.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/common/service/sensor/sensor.c b/common/service/sensor/sensor.c index d495f6c228..a18b6119da 100644 --- a/common/service/sensor/sensor.c +++ b/common/service/sensor/sensor.c @@ -33,9 +33,9 @@ static bool sensor_poll_enable_flag = true; static bool is_sensor_ready_flag = false; -const int negative_ten_power[16] = { 1, 1, 1, 1, 1, 1, - 1, 1000000000, 100000000, 10000000, 1000000, 100000, - 10000, 1000, 100, 10 }; +const int negative_ten_power[16] = { 1, 1, 1, 1, 1, 1, + 1, 1000000000, 100000000, 10000000, 1000000, 100000, + 10000, 1000, 100, 10 }; sensor_cfg *sensor_config; uint8_t sensor_config_num; @@ -284,22 +284,22 @@ __weak void pal_fix_sensor_config(void) return; } -bool stby_access(uint8_t sensor_number) +bool stby_access(uint8_t sensor_num) { return true; } -bool dc_access(uint8_t sensor_number) +bool dc_access(uint8_t sensor_num) { return get_DC_on_delayed_status(); } -bool post_access(uint8_t sensor_number) +bool post_access(uint8_t sensor_num) { return get_post_status(); } -bool me_access(uint8_t sensor_number) +bool me_access(uint8_t sensor_num) { if (get_me_mode() == ME_NORMAL_MODE) { return get_post_status(); @@ -364,6 +364,13 @@ static void drive_init(void) sensor_cfg *p = sensor_config + i; for (j = 0; j < drive_num; j++) { if (p->type == sensor_drive_tbl[j].dev) { + if (p->pre_sensor_read_hook) { + if (p->pre_sensor_read_hook( + p->num, p->pre_sensor_read_args) == false) { + printk("[%s] sensor %d pre sensor read failed!\n", + __func__, p->num); + } + } ret = sensor_drive_tbl[j].init(p->num); if (ret != SENSOR_INIT_SUCCESS) printf("sensor num %d initial fail, ret %d\n", p->num, ret);