#include "sensors.h"
#include "sensors_i2c_operate.h"
#include "ltr553_light_driver.h"
#include "dual_light_interface.h"
#include "sensor_driver_light_common.h"
#include "sensor_manager.h"
#include "error_type.h"
#include "sensor_hub_ap_core.h"
#include <stdint.h>
#include "gpio_drvapi.h"
static float sensitivity_coef = 1;
static int8_t light_cali_cmd_flag = NON_CALI_CMD;
static int8_t light_cali_status_flag = CALI_STATUS_NON;
static const float LIGHT_CALI_MIN = 280;
static const float LIGHT_CALI_MAX = 520;
static const float LIGHT_CALI_STANDARD = 400;
static const uint8_t LTR553_LIGHT_INIT_REG1 = 0x82;
static const uint8_t LTR553_LIGHT_INIT_REG2 = 0x83;
static const uint8_t LTR553_LIGHT_INIT_REG3 = 0x85;
static const uint8_t LTR553_LIGHT_INIT_REG4 = 0x9E;
static const uint8_t LTR553_LIGHT_INIT_VALUE1 = 0x7A;
static const uint8_t LTR553_LIGHT_INIT_VALUE2 = 0x01;
static const uint8_t LTR553_LIGHT_INIT_VALUE3 = 0x33;
static const uint8_t LTR553_LIGHT_INIT_VALUE4 = 0x11;
static const uint8_t LTR553_LIGHT_CONTR_REG = 0x80;
static const uint8_t LTR553_LIGHT_ENABLE_VALUE = 0x0D;
static const uint8_t LTR553_LIGHT_DISABLE_VALUE = 0x00;
static const uint8_t LTR553_LIGHT_DATA_STATUS_REG = 0x8C;
static const uint8_t LTR553_LIGHT_DATA_STATUS_VALUE = 0x04;
static const uint8_t LTR553_LIGHT_RAW_CH1_REG_L = 0x88;
static const uint8_t LTR553_LIGHT_RAW_CH1_REG_H = 0x89;
static const uint8_t LTR553_LIGHT_RAW_CH0_REG_L = 0x8A;
static const uint8_t LTR553_LIGHT_RAW_CH0_REG_H = 0x8B;
static const uint8_t LTR553_LIGHT_DATA_RATE_REG = 0x85;
static const uint8_t LTR553_LIGHT_DATA_RATE_10HZ = 0x01;
static const uint8_t LTR553_LIGHT_CHECK_ID_REG = 0x86;
static const uint8_t LTR553_LIGHT_CHECK_ID_DATA = 0x92;
static int ltr553_sensor_check_id();
static int ltr553_sensor_hw_init();
static struct phy_light_interface *ltr553_sensor_init();
static int ltr553_sensor_set_cali_data(void *cali_data);
static int ltr553_sensor_rate(int32_t sampling_period_us);
static int ltr553_sensor_enable();
static int ltr553_sensor_disable();
static int ltr553_sensor_set_status();
static int ltr553_sensor_get_status();
static void ltr553_sensor_cali_cmd_handle(int cal_cmd, int cali_type, int golden_sample);
static void ltr553_sensor_get_cali_data();
static int ltr553_sensor_read_data(struct sensor_data *sensor_data, uint64_t timestamp);
static int ltr553_sensor_set_mode(int mode);
static int ltr553_sensor_get_fifo_data(struct sensor_data *sensor_data);
static int ltr553_sensor_flush(int sensor);
static int ltr553_sensor_selftest();
sensor_info_t ltr553_light_info = {
.name = "ltr553 light sensor",
.vendor = "liteon",
.version = 0,
.sensor_type = DUAL_LIGHT_SECOND,
.maxrange = 65535,
.resolution = 1.0f,
.power = 0.15f,
.mindelay_us = 0,
.fifo_reserved_event_count = 0,
.fifo_max_event_count = 0,
.maxdelay_us = 0,
};
struct sensor_hw_info ltr553_light_hw_info_t = {
.position = 0,
.i2c_info = {
.interface_freq = 400,
.interface_num = 0,
.slave_addr = 0x23,
.reg_addr_len = 1
},
};
static struct phy_light_interface ltr553_sensor_interface = {
.sensor_data = {0},
.sensor_driver_handle = DRV_PHY2_LIGHT,
.enabled = 0,
.sampling_period_us = 320000,
.init = ltr553_sensor_init,
.set_cali_data = ltr553_sensor_set_cali_data,
.set_rate = ltr553_sensor_rate,
.activate = ltr553_sensor_enable,
.deactivate = ltr553_sensor_disable,
.set_status = ltr553_sensor_set_status,
.get_status = ltr553_sensor_get_status,
.get_data = ltr553_sensor_read_data,
.set_mode = ltr553_sensor_set_mode,
.get_fifo_data = ltr553_sensor_get_fifo_data,
.self_test = ltr553_sensor_selftest,
.flush = ltr553_sensor_flush,
.cali_cmd = ltr553_sensor_cali_cmd_handle,
.get_cali_data = ltr553_sensor_get_cali_data,
};
static float last_luxdata = -1.0f;
static uint8_t enable_state;
static uint8_t reject_frames_num;
static int ltr553_sensor_check_id()
{
int ret = FAIL;
uint8_t reg_addr = LTR553_LIGHT_CHECK_ID_REG, reg_data = LTR553_LIGHT_CHECK_ID_DATA;
ret = sensor_i2c_check_reg_data(<r553_light_hw_info_t.i2c_info, ®_addr, ®_data, 0xff);
if (ret != NO_ERROR)
SENSORHUB_TRACE("light sensor check id failed!");
else
SENSORHUB_TRACE("light sensor check id successed!");
return ret;
}
static int ltr553_sensor_hw_init()
{
int i, ret = FAIL;
uint8_t reg_addr[4] = {LTR553_LIGHT_INIT_REG1, LTR553_LIGHT_INIT_REG2, LTR553_LIGHT_INIT_REG3, LTR553_LIGHT_INIT_REG4};
uint8_t reg_data[4] = {LTR553_LIGHT_INIT_VALUE1, LTR553_LIGHT_INIT_VALUE2, LTR553_LIGHT_INIT_VALUE3, LTR553_LIGHT_INIT_VALUE4};
for (i = 0; i < sizeof(reg_data); i++) {
ret = sensors_i2c_reg_write(<r553_light_hw_info_t.i2c_info, ®_addr[i], ®_data[i], 1, 0xff);
if (ret < 0) {
SENSORHUB_TRACE("light init%d failed!", i);
return FAIL;
}
}
SENSORHUB_TRACE("init success!");
return NO_ERROR;
}
static struct phy_light_interface *ltr553_sensor_init()
{
int ret = FAIL;
ret = sensor_property_parse(ltr553_light_info.name, <r553_light_hw_info_t);
if (ret < NO_ERROR)
SENSORHUB_TRACE("not match sensor name, config default property");
ret = ltr553_sensor_check_id();
if (ret < NO_ERROR) {
SENSORHUB_TRACE_ERR("light check id error ret = %d!", ret);
return 0;
}
ret = ltr553_sensor_hw_init();
if (ret < NO_ERROR) {
SENSORHUB_TRACE_ERR("light hw init error ret = %d!", ret);
return 0;
}
return <r553_sensor_interface;
}
static int ltr553_sensor_set_cali_data(void *cali_data)
{
int als_cali_data;
memcpy(&als_cali_data, cali_data, sizeof(als_cali_data));
if (als_cali_data <= 0) {
sensitivity_coef = 1;
} else {
sensitivity_coef = (float)als_cali_data / 10000.0f;
}
SENSORHUB_TRACE("cali_data = %d sensitivity_coef = %f\n",
als_cali_data, sensitivity_coef);
return NO_ERROR;
}
static int ltr553_sensor_rate(int32_t sampling_period_us)
{
int ret = FAIL;
uint8_t reg_addr = LTR553_LIGHT_DATA_RATE_REG, temp_value = LTR553_LIGHT_DATA_RATE_10HZ;
ret = sensors_i2c_reg_write(<r553_light_hw_info_t.i2c_info, ®_addr, &temp_value, 1, 0xff);
if (ret >= 0)
ret = NO_ERROR;
return ret;
}
static int ltr553_sensor_enable()
{
int ret = FAIL;
uint8_t reg_addr = LTR553_LIGHT_CONTR_REG, temp_value = LTR553_LIGHT_ENABLE_VALUE;
if (enable_state != 1) {
ret = sensors_i2c_reg_write(<r553_light_hw_info_t.i2c_info, ®_addr, &temp_value, 1, 0xff);
if (ret >= 0) {
enable_state = 1;
ret = NO_ERROR;
SENSORHUB_TRACE("light enable sensor successed!\n");
} else {
SENSORHUB_TRACE_ERR("light enable sensor failed! error! ret=%d\n", ret);
return ret;
}
} else {
ret = NO_ERROR;
SENSORHUB_TRACE("already enabled!");
}
reject_frames_num = 0;
return ret;
}
static int ltr553_sensor_disable()
{
int ret = FAIL;
uint8_t reg_addr = LTR553_LIGHT_CONTR_REG, temp_value = LTR553_LIGHT_DISABLE_VALUE;
if (enable_state != 0) {
ret = sensors_i2c_reg_write(<r553_light_hw_info_t.i2c_info, ®_addr, &temp_value, 1, 0xff);
if (ret >= 0) {
enable_state = 0;
ret = NO_ERROR;
SENSORHUB_TRACE("light disable sensor successed!\n");
} else {
SENSORHUB_TRACE_ERR("light disable sensor failed! error! ret=%d\n", ret);
return ret;
}
} else {
ret = NO_ERROR;
SENSORHUB_TRACE("already disabled!");
}
last_luxdata = -1.0f;
return ret;
}
static int ltr553_sensor_set_status()
{
return NO_ERROR;
}
static int ltr553_sensor_get_status()
{
uint8_t reg_addr = LTR553_LIGHT_DATA_STATUS_REG;
uint8_t reg_data = LTR553_LIGHT_DATA_STATUS_VALUE;
return share_ic_sensor_i2c_check_data_status(PROX_AND_LIGHT, <r553_light_hw_info_t.i2c_info, ®_addr, ®_data,
0x04);
}
static void ltr553_sensor_cali_cmd_handle(int cal_cmd, int cali_type, int golden_sample)
{
light_cali_cmd_flag = cal_cmd;
if (light_cali_cmd_flag
展锐平台实现前后双光距感功能
需积分: 0 19 浏览量
更新于2025-05-07
收藏 5KB 7Z 举报
展锐平台实现前后双光距感功能,是指在展锐移动平台硬件上开发和实现一套软件系统,该系统通过特定的驱动代码,能够有效地控制和管理前后两个光感传感器的工作。前后双光距感功能在现代智能手机中越来越重要,它们主要用于改善自动对焦系统性能,增强拍照体验,提升用户界面响应速度,甚至在某些情况下能够辅助设备确定周围环境的光线条件,进而实现更智能的电源管理。
该功能的实现涉及多个技术层面,首先需要有与展锐平台硬件兼容的前后光距传感器,这些传感器必须能够精确捕捉到光源的变化,并将其转换为电信号。这些信号通过特定的接口传输给处理器,处理器则通过软件算法来解析这些信号,以确定光源距离和光线强度。
驱动代码是这一功能实现的关键,它负责与硬件设备进行通信,控制硬件的工作状态,以及对硬件收集的数据进行初步处理。驱动代码通常需要具备高度的优化,以确保硬件的性能得到充分发挥,同时保持系统的稳定性和高效性。驱动的开发需要深入了解展锐平台的硬件架构,包括其处理器、内存管理、I/O接口等,并严格遵守展锐提供的开发规范。
软件插件是驱动代码的另一个重要组成部分,它是指一段可以让硬件或软件系统具备额外功能的代码。在这个上下文中,软件插件可能指的是负责处理光距数据的高级算法,这些算法可能会集成到系统软件中,通过不断的更新来改进光距感功能的性能和精度。软件插件也可能是与第三方应用程序进行交互的接口,允许开发者利用前后双光距感功能为用户提供更加丰富的应用体验。
由于是关于手机平台的前后双光距感功能的实现,相关文件名称“dual_light”表明了这项技术可能涉及到两个主要部分:前后光距传感器的驱动代码以及与之相关的软件接口或数据处理插件。文件名称暗示了项目的核心目标是同时控制和利用前后两个传感器的数据,以达到提升设备光感应能力的目的。
实现前后双光距感功能不仅对提升拍照质量有着显著作用,还能够影响设备在多媒体播放、环境光线自适应调节等多个方面的表现。为了实现这一目标,开发团队需要在软件算法开发、硬件驱动优化、系统架构整合等方面进行深入研究和开发工作。
通过精准的硬件控制和高效的软件处理,前后双光距感功能能够显著提升移动设备的性能和用户体验。这项技术的成熟和普及,将为智能手机行业带来新的发展方向,同时也为消费者带来更多智能化、个性化的使用体验。

maji9143
- 粉丝: 39
最新资源
- 基于STC89C52系列单片机的倒计时器制作研究.doc
- A星算法matlab源码及详细注释.doc
- 宾馆信息管理系统数据库课程设计报告.doc
- 网络安全的基本知识.docx
- 软件工程开题报告.doc
- 基于医疗大数据的DRGs分析(白板).ppt
- 医疗改革中公共卫生体系信息化建设探讨.doc
- 基于面向对象技术的楼宇自控网络协议的实现.doc
- 电器有限公司网络营销策划方案.pptx
- 基于MicroBlaze的嵌入式系统设计.doc
- 网络社交聊天的吸引力话术.doc
- 数据库培训-高主任1.ppt
- 各种BIOS详细设置图解.docx
- 矿井开采设计CAD第章专业图纸绘制.ppt
- 网络基础设施安全.ppt
- 计算机联锁系统故障处理.ppt