Import realme drivers/modules

Signed-off-by: SagarMakhar <sagarmakhar@gmail.com>
This commit is contained in:
SagarMakhar
2021-11-17 18:30:30 +00:00
parent da929dba3f
commit 07e22f40f7
1935 changed files with 1512837 additions and 0 deletions

228
OplusKernelEnvConfig.mk Normal file
View File

@@ -0,0 +1,228 @@
# Copyright (C), 2008-2030, OPPO Mobile Comm Corp., Ltd
### All rights reserved.
###
### File: - OplusKernelEnvConfig.mk
### Description:
### you can get the oplus feature variables set in android side in this file
### this file will add global macro for common oplus added feature
### BSP team can do customzation by referring the feature variables
### Version: 1.0
### Date: 2020-03-18
### Author: Liang.Sun
###
### ------------------------------- Revision History: ----------------------------
### <author> <date> <version> <desc>
### ------------------------------------------------------------------------------
### Liang.Sun@TECH.Build 2020-03-18 1.0 Create this moudle
##################################################################################
-include ./oplus_native_features.mk
###ifdef OPLUS_ARCH_INJECT
OPLUS_CONNECTIVITY_NATIVE_FEATURE_SET :=
ifeq ($(OPLUS_FEATURE_WIFI_MTUDETECT), yes)
OPLUS_CONNECTIVITY_NATIVE_FEATURE_SET += OPLUS_FEATURE_WIFI_MTUDETECT
endif
ifeq ($(OPLUS_FEATURE_WIFI_LIMMITBGSPEED), yes)
OPLUS_CONNECTIVITY_NATIVE_FEATURE_SET += OPLUS_FEATURE_WIFI_LIMMITBGSPEED
endif
$(foreach myfeature,$(OPLUS_CONNECTIVITY_NATIVE_FEATURE_SET),\
$( \
$(eval KBUILD_CFLAGS += -D$(myfeature)) \
$(eval KBUILD_CPPFLAGS += -D$(myfeature)) \
$(eval CFLAGS_KERNEL += -D$(myfeature)) \
$(eval CFLAGS_MODULE += -D$(myfeature)) \
) \
)
###endif OPLUS_ARCH_INJECT
ALLOWED_MCROS := OPLUS_FEATURE_FG_IO_OPT \
OPLUS_FEATURE_SPECIALOPT \
OPLUS_FEATURE_STORAGE_TOOL \
OPLUS_FEATURE_UFS_DRIVER \
OPLUS_FEATURE_UFS_SHOW_LATENCY \
OPLUS_FEATURE_UFSPLUS \
OPLUS_FEATURE_EMMC_SDCARD_OPTIMIZE \
OPLUS_FEATURE_EMMC_DRIVER \
OPLUS_FEATURE_HEALTHINFO \
OPLUS_FEATURE_IOMONITOR \
OPLUS_FEATURE_TASK_CPUSTATS \
OPLUS_FEATURE_HANS_FREEZE \
OPLUS_FEATURE_UIFIRST \
OPLUS_FEATURE_TP_BSPFWUPDATE \
OPLUS_FEATURE_LOWMEM_DBG \
OPLUS_FEATURE_QCOM_PMICWD \
OPLUS_FEATURE_CHG_BASIC \
OPLUS_FEATURE_NWPOWER \
OPLUS_FEATURE_WIFI_BDF \
OPLUS_FEATURE_CONNFCSOFT \
OPLUS_FEATURE_AGINGTEST \
OPLUS_FEATURE_SENSOR_SMEM \
OPLUS_FEATURE_SSR \
OPLUS_FEATURE_TP_BASIC \
OPLUS_FEATURE_EDTASK_IMPROVE \
OPLUS_FEATURE_WIFI_LIMMITBGSPEED \
OPLUS_FEATURE_WIFI_SLA \
OPLUS_FEATURE_DHCP \
OPLUS_FEATURE_PHOENIX \
OPLUS_FEATURE_DUMPDEVICE \
OPLUS_FEATURE_SAUPWK \
OPLUS_FEATURE_MEMORY_ISOLATE \
OPLUS_FEATURE_MULTI_KSWAPD \
OPLUS_FEATURE_WIFI_MTUDETECT \
OPLUS_FEATURE_XTOWNER_INPUT \
OPLUS_FEATURE_SELINUX_CONTROL_LOG \
OPLUS_FEATURE_PW_4096 \
OPLUS_FEATURE_PXLW_IRIS5 \
OPLUS_FEATURE_MULTI_FREEAREA \
OPLUS_FEATURE_VIRTUAL_RESERVE_MEMORY \
OPLUS_FEATURE_GPU_MINIDUMP \
OPLUS_FEATURE_PROCESS_RECLAIM \
OPLUS_FEATURE_ZRAM_OPT \
OPLUS_FEATURE_AUDIO_FTM \
OPLUS_FEATURE_SPEAKER_MUTE \
OPLUS_FEATURE_MI2S_SLAVE \
OPLUS_FEATURE_KTV \
OPLUS_FEATURE_MUTE_DETECT \
OPLUS_FEATURE_MEMLEAK_DETECT \
OPLUS_FEATURE_EXFAT_SUPPORT \
OPLUS_FEATURE_SDCARDFS_SUPPORT \
OPLUS_FEATURE_CAMERA_OIS \
OPLUS_FEATURE_SAU \
OPLUS_BUG_COMPATIBILITY \
OPLUS_BUG_STABILITY \
OPLUS_BUG_DEBUG \
OPLUS_ARCH_INJECT \
OPLUS_ARCH_EXTENDS \
VENDOR_EDIT \
COLOROS_EDIT \
OPLUS_FEATURE_POWERINFO_STANDBY \
OPLUS_FEATURE_POWERINFO_STANDBY_DEBUG \
OPLUS_FEATURE_POWERINFO_RPMH \
OPLUS_FEATURE_POWERINFO_FTM \
OPLUS_FEATURE_CAMERA_COMMON \
OPLUS_FEATURE_ADSP_RECOVERY \
OPLUS_FEATURE_MODEM_MINIDUMP \
OPLUS_FEATURE_MODEM_DATA_NWPOWER \
OPLUS_FEATURE_PERFORMANCE
$(foreach myfeature,$(ALLOWED_MCROS),\
$(warning make $(myfeature) to be a macro here) \
$(eval KBUILD_CFLAGS += -D$(myfeature)) \
$(eval KBUILD_CPPFLAGS += -D$(myfeature)) \
$(eval CFLAGS_KERNEL += -D$(myfeature)) \
$(eval CFLAGS_MODULE += -D$(myfeature)) \
)
# BSP team can do customzation by referring the feature variables
ifeq ($(OPLUS_FEATURE_SECURE_GUARD),yes)
export CONFIG_OPLUS_SECURE_GUARD=y
KBUILD_CFLAGS += -DCONFIG_OPLUS_SECURE_GUARD
KBUILD_CPPFLAGS += -DCONFIG_OPLUS_SECURE_GUARD
CFLAGS_KERNEL += -DCONFIG_OPLUS_SECURE_GUARD
CFLAGS_MODULE += -DCONFIG_OPLUS_SECURE_GUARD
endif
ifeq ($(OPLUS_FEATURE_QCOM_PMICWD),yes)
export OPLUS_FEATURE_QCOM_PMICWD=yes
export CONFIG_OPLUS_FEATURE_QCOM_PMICWD=y
KBUILD_CFLAGS += -DCONFIG_OPLUS_FEATURE_QCOM_PMICWD
endif
ifeq ($(OPLUS_FEATURE_DUMPDEVICE),yes)
export CONFIG_OPLUS_FEATURE_DUMP_DEVICE_INFO=y
KBUILD_CFLAGS += -DCONFIG_OPLUS_FEATURE_DUMP_DEVICE_INFO
endif
ifeq ($(OPLUS_FEATURE_SECURE_ROOTGUARD),yes)
export CONFIG_OPLUS_ROOT_CHECK=y
KBUILD_CFLAGS += -DCONFIG_OPLUS_ROOT_CHECK
KBUILD_CPPFLAGS += -DCONFIG_OPLUS_ROOT_CHECK
CFLAGS_KERNEL += -DCONFIG_OPLUS_ROOT_CHECK
CFLAGS_MODULE += -DCONFIG_OPLUS_ROOT_CHECK
endif
ifeq ($(OPLUS_FEATURE_SECURE_MOUNTGUARD),yes)
export CONFIG_OPLUS_MOUNT_BLOCK=y
KBUILD_CFLAGS += -DCONFIG_OPLUS_MOUNT_BLOCK
endif
ifeq ($(OPLUS_FEATURE_SECURE_EXECGUARD),yes)
export CONFIG_OPLUS_EXECVE_BLOCK=y
KBUILD_CFLAGS += -DCONFIG_OPLUS_EXECVE_BLOCK
KBUILD_CFLAGS += -DCONFIG_OPLUS_EXECVE_REPORT
endif
ifeq ($(OPLUS_FEATURE_SECURE_KEVENTUPLOAD),yes)
export CONFIG_OPLUS_KEVENT_UPLOAD=y
KBUILD_CFLAGS += -DCONFIG_OPLUS_KEVENT_UPLOAD
KBUILD_CPPFLAGS += -DCONFIG_OPLUS_KEVENT_UPLOAD
CFLAGS_KERNEL += -DCONFIG_OPLUS_KEVENT_UPLOAD
CFLAGS_MODULE += -DCONFIG_OPLUS_KEVENT_UPLOAD
endif
ifeq ($(OPLUS_FEATURE_SECURE_KEYINTERFACESGUARD),yes)
KBUILD_CFLAGS += -DOPPO_DISALLOW_KEY_INTERFACES
endif
# Yuwei.Zhang@MULTIMEDIA.DISPLAY.LCD, 2020/09/25, sepolicy for aod ramless
ifeq ($(OPLUS_FEATURE_AOD_RAMLESS),yes)
KBUILD_CFLAGS += -DOPLUS_FEATURE_AOD_RAMLESS
KBUILD_CPPFLAGS += -DOPLUS_FEATURE_AOD_RAMLESS
CFLAGS_KERNEL += -DOPLUS_FEATURE_AOD_RAMLESS
CFLAGS_MODULE += -DOPLUS_FEATURE_AOD_RAMLESS
endif
#Chao.Zhang@MULTIMEDIA.DISPLAY.LCD, 2020/10/23, add for DP MAX20328
ifeq ($(OPLUS_FEATURE_DP_MAX20328),yes)
KBUILD_CFLAGS += -DOPLUS_FEATURE_DP_MAX20328
endif
#xupengcheng@MULTIMEDIA.DISPLAY.LCD, 2020/11/11, add for cabc feature
ifeq ($(OPLUS_FEATURE_LCD_CABC),yes)
KBUILD_CFLAGS += -DOPLUS_FEATURE_LCD_CABC
endif
#ifdef OPLUS_FEATURE_POWERINFO_STANDBY
#Yunqing.Zeng@BSP.Power.Basic, 2020/09/10, add for feature powerinfo standby.
inner_mk_path := $(abspath $(lastword $(MAKEFILE_LIST)))
inner_mk_dir := $(shell dirname $(inner_mk_path))
inner_oplus_wakelock_dir1 := $(inner_mk_dir)/../vendor/oplus/kernel/wakelock_profiler
inner_oplus_wakelock_dir2 := $(inner_mk_dir)/../vendor/oplus/kernel/oppo_wakelock_profiler
inner_oplus_wakelock_dir1_exist := $(shell if [ -d $(inner_oplus_wakelock_dir1) ]; then echo "exist"; else echo "notexist"; fi;)
inner_oplus_wakelock_dir2_exist := $(shell if [ -d $(inner_oplus_wakelock_dir2) ]; then echo "exist"; else echo "notexist"; fi;)
inner_oplus_link_name := oplus_wakelock
inner_oplus_link_target := $(inner_mk_dir)/../kernel/msm-5.4/drivers/soc/oplus/$(inner_oplus_link_name)
ifeq ($(inner_oplus_wakelock_dir1_exist), exist)
$(warning "source is $(inner_oplus_wakelock_dir1)")
$(shell ln -sf $(inner_oplus_wakelock_dir1) $(inner_oplus_link_target))
else ifeq ($(inner_oplus_wakelock_dir2_exist), exist)
$(warning "source is $(inner_oplus_wakelock_dir2)")
$(shell ln -sf $(inner_oplus_wakelock_dir2) $(inner_oplus_link_target))
else
$(warning "source is nothing")
endif
#endif /* OPLUS_FEATURE_POWERINFO_STANDBY */
ifeq ($(OPLUS_FEATURE_SAUPWK),yes)
export CONFIG_OPLUS_FEATURE_SAUPWK=y
KBUILD_CFLAGS += -DCONFIG_OPLUS_FEATURE_SAUPWK
endif
ifeq ($(OPLUS_FEATURE_BRAND_SHOW_FLAG),realme)
export CONFIG_BRAND_SHOW_FLAG=realme
KBUILD_CFLAGS += -DCONFIG_BRAND_SHOW_FLAG
endif
ifeq ($(OPLUS_FEATURE_SHIPPING_API_LEVEL),28)
export CONFIG_SHIPPING_API_LEVEL=28
KBUILD_CFLAGS += -DCONFIG_SHIPPING_API_LEVEL
endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,137 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/**************************************************************
* Copyright (c) 2008- 2030 OPPO Mobile communication Corp.ltd, All rights reserved.
* File : oplus_root.S
* Description: OPPO Block root code,block root action and record. This program is
* distributed in the hope that it will block process to elevate privilege of root.
*
* Version : 1.0
* Date :
* Author :
* TAG :
****************************************************************/
#include <linux/init.h>
#include <linux/linkage.h>
#include <generated/asm-offsets.h>
#include <asm/assembler.h>
#include <asm/errno.h>
#include <asm/esr.h>
#include <asm/thread_info.h>
#include <asm/unistd.h>
#include "rootguard/oplus_root.h"
/*
X26 : syscall number
x27 : syscall table pointer
x28 : current thread_info
X25 : number of system calls
X19,X20,X29: store uid\gid\euid\egid\fsuid\fsgid
*/
.extern oplus_root_reboot
#ifdef CONFIG_OPLUS_KEVENT_UPLOAD
.extern oplus_root_check_succ
.extern is_unlocked
#endif
ENTRY(oplus_root_check)
mov x21, x30
#ifdef CONFIG_THREAD_INFO_IN_TASK
mrs x16, sp_el0
#else
ldr x16, [x28, #PROOT_THREAD_TSK]
#endif
ldr x15, [x16, #PROOT_TSK_CRED]
ldr x19, [x15, #PROOT_CRED_UID]
ldr x20, [x15, #PROOT_CRED_EUID]
ldr x29, [x15, #PROOT_CRED_FSUID]
ldr x16, [x27, x26, lsl #3] // address in the syscall table
blr x16
mov x22, x0
cmp x19, #0 //if phone adb have root permission,we donnot check
beq 2f
bl is_unlocked
cmp x0, #0
bne 2f
#ifdef CONFIG_THREAD_INFO_IN_TASK
mrs x16, sp_el0
ldr x15, [x16, #PROOT_THREAD_ADDR_LIMIT]
#else
ldr x15, [x28, #PROOT_THREAD_ADDR_LIMIT]
#endif
mov x17, #0x0000008000000000
cmp x15, x17
b.hi 5f
#ifdef CONFIG_THREAD_INFO_IN_TASK
mrs x15, sp_el0 //if uid not change,we return
#else
ldr x15, [x28, #PROOT_THREAD_TSK] //if uid not change,we return
#endif
ldr x17, [x15, #PROOT_TSK_CRED]
ldr x16, [x17, #PROOT_CRED_UID]
cmp x16, x19
bne 3f
ldr x16, [x17, #PROOT_CRED_EUID] //if euid not change,we return
cmp x16, x20
bne 3f
ldr x16, [x17, #PROOT_CRED_FSUID] //if fsuid not change,we return
cmp x16, x29
bne 3f
2:
mov x30, x21
mov x0, x22
ret
3:
/*
//In Android R K 4.14, there both have 32 and 64 bit syscalls
#ifdef CONFIG_COMPAT
cmp X25, #__NR_compat_syscalls
beq 4f
#endif
*/
cmp x26, #__NR_setresgid
beq 2b
sub x15, x26, #__NR_setregid
cmp x15, #0x4
b.ls 2b
// b 5f
#ifdef CONFIG_COMPAT
4:
cmp x26, #__NR_setreuid32
beq 2b
cmp x26, #__NR_setregid32
beq 2b
cmp x26, #__NR_setresuid32
beq 2b
cmp x26, #__NR_setresgid32
beq 2b
cmp x26, #__NR_setuid32
beq 2b
cmp x26, #__NR_setgid32
beq 2b
#endif
5:
#ifdef CONFIG_OPLUS_KEVENT_UPLOAD
mov x0, x19
mov x1, x20
mov x2, x29
mov x3, x26
bl oplus_root_check_succ
#endif
mov x0, #0
bl oplus_root_reboot
END(oplus_root_check)

View File

@@ -0,0 +1,7 @@
#ifdef CONFIG_OPLUS_SECURE_GUARD
obj-$(CONFIG_OPLUS_ROOT_CHECK) += oplus_root_check.o
obj-$(CONFIG_OPLUS_EXECVE_BLOCK) += oplus_exec_block.o
obj-$(CONFIG_OPLUS_MOUNT_BLOCK) += oplus_mount_block.o
obj-$(CONFIG_OPLUS_SECURE_GUARD) += oplus_guard_general.o
obj-$(CONFIG_OPLUS_SECURE_GUARD) += oplus_hook_syscall.o
#endif /* CONFIG_OPLUS_SECURE_GUARD */

View File

@@ -0,0 +1,144 @@
// SPDX-License-Identifier: GPL-2.0-only
/**************************************************************
* Copyright (c) 2008- 2020 Oplus. All rights reserved.
* VENDOR_EDIT
* File : oplus_exec_block.c
* Description: For exec block
* Version : 1.0
* Date : 2019-12-19
* Author :
* TAG :
****************************************************************/
#ifdef CONFIG_OPLUS_SECURE_GUARD
#include <linux/slab.h>
#include <linux/file.h>
#include <linux/fdtable.h>
#include <linux/mm.h>
#include <linux/vmacache.h>
#include <linux/stat.h>
#include <linux/fcntl.h>
#include <linux/swap.h>
#include <linux/string.h>
#include <linux/init.h>
#if defined(CONFIG_OPLUS_EXECVE_BLOCK) || defined(CONFIG_OPLUS_EXECVE_REPORT)
#ifdef CONFIG_OPLUS_KEVENT_UPLOAD
#include <linux/oplus_kevent.h>
#include <linux/cred.h>
#endif /* CONFIG_OPLUS_KEVENT_UPLOAD */
#ifdef OPLUS_DISALLOW_KEY_INTERFACES
#include "oplus_guard_general.h"
static void oplus_report_execveat(const char *path, const char* dcs_event_id)
{
#ifdef CONFIG_OPLUS_KEVENT_UPLOAD
struct kernel_packet_info* dcs_event;
char dcs_stack[sizeof(struct kernel_packet_info) + 256];
const char* dcs_event_tag = "kernel_event";
// const char* dcs_event_id = "execve_report";
char* dcs_event_payload = NULL;
int uid = current_uid().val;
//const struct cred *cred = current_cred();
dcs_event = (struct kernel_packet_info*)dcs_stack;
dcs_event_payload = dcs_stack +
sizeof(struct kernel_packet_info);
dcs_event->type = 3;
strncpy(dcs_event->log_tag, dcs_event_tag,
sizeof(dcs_event->log_tag));
strncpy(dcs_event->event_id, dcs_event_id,
sizeof(dcs_event->event_id));
dcs_event->payload_length = snprintf(dcs_event_payload, 256,
"%d,path@@%s", uid, path);
if (dcs_event->payload_length < 256) {
dcs_event->payload_length += 1;
}
kevent_send_to_user(dcs_event);
#endif /* CONFIG_OPLUS_KEVENT_UPLOAD */
printk(KERN_ERR "=======>[kevent_send_to_user:execve]:common %s result %s\n", path, dcs_event_id);
}
static int oplus_check_execveat_perm(struct file* filp)
{
char *absolute_path_buf = NULL;
char *absolute_path = NULL;
char *context = NULL;
u32 context_len = 0;
int rc = 0;
int retval = 0;
/*if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
goto out_ret;*/
absolute_path_buf = (char *)__get_free_page(GFP_KERNEL);
retval = -ENOMEM;
if (absolute_path_buf == NULL)
goto out_ret;
absolute_path = d_path(&filp->f_path, absolute_path_buf, PAGE_SIZE);
retval = PTR_ERR(absolute_path);
if (IS_ERR(absolute_path))
goto out_free;
retval = 0;
if (strncmp(absolute_path, "/data", 5))
goto out_free;
//ChenYong@Plt.Framework, 2018/11/30, add for vts test.
if (!strncmp(absolute_path, "/data/local/tmp", 15)) {
goto out_free;
}
//add end
if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
#ifdef CONFIG_OPLUS_EXECVE_REPORT
oplus_report_execveat(absolute_path, "execve_report");
#endif /* CONFIG_OPLUS_EXECVE_REPORT */
} else {
#ifdef CONFIG_OPLUS_EXECVE_BLOCK
rc = get_current_security_context(&context, &context_len);
retval = -EPERM;
if (rc) {
oplus_report_execveat(absolute_path, "execve_block");
goto out_free;
}
retval = -EPERM;
#endif /* CONFIG_OPLUS_EXECVE_BLOCK */
}
retval = 0;
out_free:
kfree(context);
free_page((unsigned long)absolute_path_buf);
out_ret:
return retval;
}
int oplus_exec_block(struct file *file)
{
int retval = 0;
if (!is_unlocked()) {
retval = oplus_check_execveat_perm(file);
if (retval < 0) {
return retval;
}
}
return retval;
}
#else
int oplus_exec_block(struct file *file)
{
int retval = 0;
return retval;
}
#endif /* OPLUS_DISALLOW_KEY_INTERFACES */
#endif /* CONFIG_OPLUS_EXECVE_BLOCK or CONFIG_OPLUS_EXECVE_REPORT */
#endif /* CONFIG_OPLUS_SECURE_GUARD */

View File

@@ -0,0 +1,94 @@
// SPDX-License-Identifier: GPL-2.0-only
/**************************************************************
* Copyright (c) 2008- 2020 Oplus. All rights reserved..
* VENDOR_EDIT
* File : oplus_guard_general.c
* Description: some common function for root guard
* Version : 1.0
* Date : 2019-12-19
* Author :
* TAG :
****************************************************************/
#ifdef CONFIG_OPLUS_SECURE_GUARD
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/types.h>
#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM
enum{
MSM_BOOT_MODE__NORMAL,
MSM_BOOT_MODE__FASTBOOT,
MSM_BOOT_MODE__RECOVERY,
MSM_BOOT_MODE__FACTORY,
MSM_BOOT_MODE__RF,
MSM_BOOT_MODE__WLAN,
MSM_BOOT_MODE__MOS,
MSM_BOOT_MODE__CHARGE,
MSM_BOOT_MODE__SILENCE,
MSM_BOOT_MODE__SAU,
MSM_BOOT_MODE__AGING = 998,
MSM_BOOT_MODE__SAFE = 999,
};
extern int get_boot_mode(void);
bool is_normal_boot_mode(void)
{
return MSM_BOOT_MODE__NORMAL == get_boot_mode();
}
#else
#define MTK_NORMAL_BOOT 0
extern unsigned int get_boot_mode(void);
bool is_normal_boot_mode(void)
{
return MTK_NORMAL_BOOT == get_boot_mode();
}
#endif
enum{
BOOT_STATE__GREEN,
BOOT_STATE__ORANGE,
BOOT_STATE__YELLOW,
BOOT_STATE__RED,
};
static int __ro_after_init g_boot_state = BOOT_STATE__GREEN;
bool is_unlocked(void)
{
return BOOT_STATE__ORANGE== g_boot_state;
}
static int __init boot_state_init(void)
{
char * substr = strstr(boot_command_line, "androidboot.verifiedbootstate=");
if (substr) {
substr += strlen("androidboot.verifiedbootstate=");
if (strncmp(substr, "green", 5) == 0) {
g_boot_state = BOOT_STATE__GREEN;
} else if (strncmp(substr, "orange", 6) == 0) {
g_boot_state = BOOT_STATE__ORANGE;
} else if (strncmp(substr, "yellow", 6) == 0) {
g_boot_state = BOOT_STATE__YELLOW;
} else if (strncmp(substr, "red", 3) == 0) {
g_boot_state = BOOT_STATE__RED;
}
}
return 0;
}
static void __exit boot_state_exit()
{
return ;
}
module_init(boot_state_init);
module_exit(boot_state_exit);
MODULE_LICENSE("GPL");
#endif/*OPLUS_GUARD_GENERAL_H_*/

View File

@@ -0,0 +1,19 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/**************************************************************
* Copyright (c) 2008- 2020 Oplus. All rights reserved..
* VENDOR_EDIT
* File : oplus_guard_general.h
* Description: For rootguard general function
* Version : 1.0
* Date : 2019-12-19
* Author :
* TAG :
****************************************************************/
#ifndef OPLUS_GUARD_GENERAL_H_
#define OPLUS_GUARD_GENERAL_H_
bool is_unlocked(void);
bool is_normal_boot_mode(void);
#endif /*OPLUS_GUARD_GENERAL_H_*/

View File

@@ -0,0 +1,101 @@
// SPDX-License-Identifier: GPL-2.0-only
/**************************************************************
* Copyright (c) 2008- 2020 Oplus. All rights reserved..
* VENDOR_EDIT
* File : oplus_hook_syscall.c
* Description: replace the syscall.c
* Version : 1.0
* Date : 2019-12-19
* Author :
* TAG :
****************************************************************/
#include <linux/version.h>
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0))
#include <linux/compiler.h>
#include <linux/context_tracking.h>
#include <linux/errno.h>
#include <linux/nospec.h>
#include <linux/ptrace.h>
#include <linux/syscalls.h>
#include <asm/daifflags.h>
#include <asm/debug-monitors.h>
#include <asm/fpsimd.h>
#include <asm/syscall.h>
#include <asm/thread_info.h>
#include <asm/unistd.h>
#ifdef CONFIG_OPLUS_SECURE_GUARD
#define KERNEL_ADDR_LIMIT 0x0000008000000000
#include <asm/uaccess.h>
#include <linux/cred.h>
#include <linux/selinux.h>
#include "oplus_root.h"
#endif /* CONFIG_OPLUS_SECURE_GUARD */
long compat_arm_syscall(struct pt_regs *regs, int scno);
long sys_ni_syscall(void);
#ifdef CONFIG_OPLUS_ROOT_CHECK
extern void oplus_root_check_succ(uid_t uid, uid_t euid, uid_t fsuid, uid_t callnum);
extern bool is_unlocked(void);
extern void oplus_root_reboot(void);
#endif /* CONFIG_OPLUS_ROOT_CHECK */
static long oplus_do_ni_syscall(struct pt_regs *regs, int scno)
{
#ifdef CONFIG_COMPAT
long ret;
if (is_compat_task()) {
ret = compat_arm_syscall(regs, scno);
if (ret != -ENOSYS)
return ret;
}
#endif
return sys_ni_syscall();
}
static long __oplus_invoke_syscall(struct pt_regs *regs, syscall_fn_t syscall_fn)
{
return syscall_fn(regs);
}
void oplus_invoke_syscall(struct pt_regs *regs, unsigned int scno,
unsigned int sc_nr,
const syscall_fn_t syscall_table[])
{
long ret;
#ifdef CONFIG_OPLUS_ROOT_CHECK
unsigned int IntUid_1st = current_uid().val;
unsigned int IntEuid_1st = current_euid().val;
unsigned int IntFsuid_1st = current_fsuid().val;
#endif /* CONFIG_OPLUS_ROOT_CHECK */
if (scno < sc_nr) {
syscall_fn_t syscall_fn;
syscall_fn = syscall_table[array_index_nospec(scno, sc_nr)];
ret = __oplus_invoke_syscall(regs, syscall_fn);
} else {
ret = oplus_do_ni_syscall(regs, scno);
}
#ifdef CONFIG_OPLUS_ROOT_CHECK
if ((IntUid_1st != 0) && (is_unlocked() == 0) ){
if((scno != __NR_setreuid32) && (scno != __NR_setregid32) && (scno != __NR_setresuid32) && (scno != __NR_setresgid32) && (scno != __NR_setuid32) && (scno != __NR_setgid32)
&& (scno != __NR_setreuid) && (scno != __NR_setregid) && (scno != __NR_setresuid) && (scno != __NR_setresgid) && (scno != __NR_setuid) && (scno != __NR_setgid)
){
//make sure the addr_limit in kernel space
//KERNEL_DS: 0x7f ffff ffff
//KERNEL_ADDR_LIMIT:0x80 0000 0000
if (((current_uid().val != IntUid_1st) || (current_euid().val != IntEuid_1st) || (current_fsuid().val != IntFsuid_1st)) || (get_fs() > KERNEL_ADDR_LIMIT)){
oplus_root_check_succ(IntUid_1st, IntEuid_1st, IntFsuid_1st, scno);
oplus_root_reboot();
}
}
}
#endif /* CONFIG_OPLUS_ROOT_CHECK */
regs->regs[0] = ret;
}
#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) */

View File

@@ -0,0 +1,84 @@
// SPDX-License-Identifier: GPL-2.0-only
/**************************************************************
* Copyright (c) 2008- 2020 Oplus. All rights reserved.
* VENDOR_EDIT
* File : oplus_mount_block.c
* Description: remount block.
* Version : 1.0
* Date : 2019-12-19
* Author :
* TAG :
****************************************************************/
#ifdef CONFIG_OPLUS_SECURE_GUARD
#include <linux/syscalls.h>
#include <linux/export.h>
#include <linux/capability.h>
#include <linux/mnt_namespace.h>
#include <linux/user_namespace.h>
#include <linux/uaccess.h>
#include <linux/file.h>
#include <linux/proc_ns.h>
#include <linux/magic.h>
#include <linux/bootmem.h>
#include <linux/task_work.h>
#include <linux/sched/task.h>
#ifdef CONFIG_OPLUS_MOUNT_BLOCK
#include "oplus_guard_general.h"
#ifdef CONFIG_OPLUS_KEVENT_UPLOAD
#include <linux/oplus_kevent.h>
#endif /* CONFIG_OPLUS_KEVENT_UPLOAD */
#ifdef OPLUS_DISALLOW_KEY_INTERFACES
int oplus_mount_block(const char __user *dir_name, unsigned long flags)
{
#ifdef CONFIG_OPLUS_KEVENT_UPLOAD
struct kernel_packet_info* dcs_event;
char dcs_stack[sizeof(struct kernel_packet_info) + 256];
const char* dcs_event_tag = "kernel_event";
const char* dcs_event_id = "mount_report";
char* dcs_event_payload = NULL;
#endif /* CONFIG_OPLUS_KEVENT_UPLOAD */
char dname[16] = {0};
if (dir_name != NULL && copy_from_user(dname,dir_name,8) == 0){
if ((!strncmp(dname, "/system", 8) || !strncmp(dname, "/vendor", 8))&& !(flags & MS_RDONLY)
&& (is_normal_boot_mode())) {
printk(KERN_ERR "[OPLUS]System partition is not permitted to be mounted as readwrite\n");
#ifdef CONFIG_OPLUS_KEVENT_UPLOAD
printk(KERN_ERR "do_mount:kevent_send_to_user\n");
dcs_event = (struct kernel_packet_info*)dcs_stack;
dcs_event_payload = dcs_stack +
sizeof(struct kernel_packet_info);
dcs_event->type = 2;
strncpy(dcs_event->log_tag, dcs_event_tag,
sizeof(dcs_event->log_tag));
strncpy(dcs_event->event_id, dcs_event_id,
sizeof(dcs_event->event_id));
dcs_event->payload_length = snprintf(dcs_event_payload, 256, "partition@@system");
if (dcs_event->payload_length < 256) {
dcs_event->payload_length += 1;
}
kevent_send_to_user(dcs_event);
#endif /* CONFIG_OPLUS_KEVENT_UPLOAD */
return -EPERM;
}
}
return 0;
}
#else
int oplus_mount_block(const char __user *dir_name, unsigned long flags)
{
return 0;
}
#endif /* OPLUS_DISALLOW_KEY_INTERFACES */
#endif /* CONFIG_OPLUS_MOUNT_BLOCK */
#endif /* CONFIG_OPLUS_SECURE_GUARD */

View File

@@ -0,0 +1,32 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/**************************************************************
* Copyright (c) 2008- 2020 Oplus. All rights reserved..
* VENDOR_EDIT
* File : oplus_root.h
* Description: For rootguard syscall num
* Version : 1.0
* Date : 2019-12-19
* Author :
* TAG :
****************************************************************/
#ifdef CONFIG_OPLUS_SECURE_GUARD
#ifndef __ARCH_ARM64_OPLUS_ROOT_H_
#define __ARCH_ARM64_OPLUS_ROOT_H_
#define __NR_setreuid32 203
#define __NR_setregid32 204
#define __NR_setresuid32 208
#define __NR_setresgid32 210
#define __NR_setuid32 213
#define __NR_setgid32 214
#define __NR_setregid 143
#define __NR_setgid 144
#define __NR_setreuid 145
#define __NR_setuid 146
#define __NR_setresuid 147
#define __NR_setresgid 149
#endif
#endif /* CONFIG_OPLUS_SECURE_GUARD */

View File

@@ -0,0 +1,90 @@
// SPDX-License-Identifier: GPL-2.0-only
/**************************************************************
* Copyright (c) 2008- 2020 Oplus. All rights reserved.
* VENDOR_EDIT
* File : oplus_root_check.c
* Description: root check and kill process.
* Version : 1.0
* Date : 2019-12-19
* Author :
* TAG :
****************************************************************/
#include <linux/delay.h>
#include <linux/kernel.h>
#include <linux/reboot.h>
#include <linux/string.h>
#include <linux/types.h>
#include <linux/version.h>
#include <linux/vmalloc.h>
#include <linux/selinux.h>
#ifdef VENDOR_EDIT
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,19,0)
#include <linux/sched/task.h>
#endif/* LINUX_VERSION_CODE < KERNEL_VERSION(4,19,0) */
#endif/* VENDOR_EDIT */
#include <linux/oplus_kevent.h>
#ifdef CONFIG_OPLUS_KEVENT_UPLOAD
void oplus_root_check_succ(uid_t uid, uid_t euid, uid_t fsuid, uid_t callnum)
{
struct kernel_packet_info *dcs_event;
char dcs_stack[sizeof(struct kernel_packet_info) + 256];
const char* dcs_event_tag = "kernel_event";
const char* dcs_event_id = "root_check";
char* dcs_event_payload = NULL;
int ret = -1;
char comm[TASK_COMM_LEN], nameofppid[TASK_COMM_LEN];//
struct task_struct * parent_task = NULL;
int ppid = -1;
memset(comm, 0, TASK_COMM_LEN);
memset(nameofppid, 0, TASK_COMM_LEN);
ppid = task_ppid_nr(current);
parent_task = rcu_dereference(current->real_parent);
if (parent_task){
get_task_comm(nameofppid, parent_task);
}
dcs_event = (struct kernel_packet_info*)dcs_stack;
dcs_event->type = 0;
strncpy(dcs_event->log_tag, dcs_event_tag, sizeof(dcs_event->log_tag));
strncpy(dcs_event->event_id, dcs_event_id, sizeof(dcs_event->event_id));
dcs_event_payload = kmalloc(256, GFP_ATOMIC);
if (NULL == dcs_event_payload){
return;
}
memset(dcs_event_payload, 0, 256);
dcs_event->payload_length = snprintf(dcs_event_payload,256,
"%d$$old_euid@@%d$$old_fsuid@@%d$$sys_call_number@@%d$$addr_limit@@%lx$$curr_uid@@%d$$curr_euid@@%d$$curr_fsuid@@%d$$curr_name@@%s$$ppid@@%d$$ppidname@@%s$$enforce@@%d\n",
uid,euid,fsuid,callnum,
get_fs(),current_uid().val,current_euid().val,current_fsuid().val,get_task_comm(comm, current), ppid, nameofppid,selinux_is_enabled());
printk(KERN_INFO "oplus_root_check_succ,payload:%s\n",dcs_event_payload);
memcpy(dcs_event->payload, dcs_event_payload, strlen(dcs_event_payload));
ret = kevent_send_to_user(dcs_event);
if (ret != 0 ){
printk(KERN_INFO "Send to user failed\n");
}
kfree(dcs_event_payload);
msleep(5000);
return;
}
#endif
#ifdef CONFIG_OPLUS_ROOT_CHECK
void oplus_root_reboot(void)
{
printk(KERN_INFO "[OPLUS_ROOT_CHECK]:Kill the process of escalation...");
do_group_exit(SIGKILL);
}
#endif /* CONFIG_OPLUS_ROOT_CHECK */

View File

@@ -0,0 +1,9 @@
# SPDX-License-Identifier: GPL-2.0-only
# Copyright (C) 2018-2020 Oplus. All rights reserved.
config OPPO_FG_IO_OPT
bool "Enable oppo foreground io optimization"
depends on FG_TASK_UID
default y
help
oppo foreground io optimization

View File

@@ -0,0 +1,4 @@
# SPDX-License-Identifier: GPL-2.0-only
# Copyright (C) 2018-2020 Oplus. All rights reserved.
obj-y += oppo_high_prio_task.o oppo_foreground_io_opt.o

View File

@@ -0,0 +1,165 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2018-2020 Oplus. All rights reserved.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/bio.h>
#include <linux/blkdev.h>
#include <linux/blk-mq.h>
#include <linux/init.h>
#include <linux/pm.h>
#include <linux/list_sort.h>
#include "oppo_foreground_io_opt.h"
#define CREATE_TRACE_POINTS
#include <trace/oppo_foreground_io_opt_trace.h>
#define FG_CNT_DEF 20
#define BOTH_CNT_DEF 10
void fg_bg_max_count_init(struct request_queue *q)
{
q->fg_count_max = FG_CNT_DEF;
q->both_count_max = BOTH_CNT_DEF;
q->fg_count = FG_CNT_DEF;
q->both_count = BOTH_CNT_DEF;
}
static inline bool should_get_fg_req(struct request_queue *q)
{
if (!list_empty(&q->fg_head)
&& (q->fg_count > 0))
return true;
return false;
}
static inline bool should_get_bg_req(struct request_queue *q)
{
if (q->both_count > 0)
return true;
return false;
}
static struct request *get_fg_bg_req(struct request_queue *q)
{
struct request *rq = NULL;
if (!list_empty(&q->queue_head)) {
if (should_get_fg_req(q)) {
rq = list_entry(q->fg_head.next, struct request, fg_list);
q->fg_count--;
trace_block_fg_io_peek_req(current, (long)rq,"FG\0",q->fg_count);
}
else if (should_get_bg_req(q)) {
rq = list_entry_rq(q->queue_head.next);
q->both_count--;
trace_block_fg_io_peek_req(current, (long)rq,"BG\0",q->both_count);
}
else {
q->fg_count = q->fg_count_max;
q->both_count = q->both_count_max;
rq = list_entry_rq(q->queue_head.next);
}
}
return rq;
}
struct request * smart_peek_request(struct request_queue *q)
{
return get_fg_bg_req(q);
}
void queue_throtl_add_request(struct request_queue *q,
struct request *rq, bool front)
{
struct list_head *head;
if (unlikely(!sysctl_fg_io_opt))
return;
if (rq->cmd_flags & REQ_FG) {
head = &q->fg_head;
if (front)
list_add(&rq->fg_list, head);
else
list_add_tail(&rq->fg_list, head);
}
}
/*blk-sys*/
static ssize_t
queue_var_show(unsigned long var, char *page)
{
if (unlikely(!sysctl_fg_io_opt))
return 0;
return sprintf(page, "%lu\n", var);
}
static ssize_t
queue_var_store(unsigned long *var, const char *page, size_t count)
{
int err;
unsigned long v;
if (unlikely(!sysctl_fg_io_opt))
return 0;
err = kstrtoul(page, 10, &v);
if (err || v > UINT_MAX)
return -EINVAL;
*var = v;
return count;
}
ssize_t queue_fg_count_max_show(struct request_queue *q,
char *page)
{
int cnt = q->fg_count_max;
return queue_var_show(cnt, (page));
}
ssize_t queue_fg_count_max_store(struct request_queue *q,
const char *page, size_t count)
{
unsigned long cnt;
ssize_t ret = queue_var_store(&cnt, page, count);
if (ret < 0)
return ret;
q->fg_count_max= cnt;
return ret;
}
ssize_t queue_both_count_max_show(struct request_queue *q,
char *page)
{
int cnt = q->both_count_max;
return queue_var_show(cnt, (page));
}
ssize_t queue_both_count_max_store(struct request_queue *q,
const char *page, size_t count)
{
unsigned long cnt;
ssize_t ret = queue_var_store(&cnt, page, count);
if (ret < 0)
return ret;
q->both_count_max= cnt;
return ret;
}

View File

@@ -0,0 +1,24 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (C) 2018-2020 Oplus. All rights reserved.
*/
#ifndef __OPPO_FOREGROUND_IO_OPT__
#define __OPPO_FOREGROUND_IO_OPT__
extern unsigned int sysctl_fg_io_opt;
extern void fg_bg_max_count_init(struct request_queue *q);
extern void queue_throtl_add_request(struct request_queue *q,
struct request *rq, bool front);
extern ssize_t queue_fg_count_max_show(struct request_queue *q,
char *page);
extern ssize_t queue_fg_count_max_store(struct request_queue *q,
const char *page, size_t count);
extern ssize_t queue_both_count_max_show(struct request_queue *q,
char *page);
extern ssize_t queue_both_count_max_store(struct request_queue *q,
const char *page, size_t count);
extern bool high_prio_for_task(struct task_struct *t);
extern struct request * smart_peek_request(struct request_queue *q);
#endif /*__OPPO_FOREGROUND_IO_OPT__*/

View File

@@ -0,0 +1,94 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2018-2020 Oplus. All rights reserved.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/bio.h>
#include <linux/blkdev.h>
#include <linux/blk-mq.h>
#include <linux/init.h>
#include <linux/list_sort.h>
#include <linux/sched.h>
#include "oppo_foreground_io_opt.h"
#define SYSTEM_APP_UID 1000
#ifdef CONFIG_FG_TASK_UID
extern bool is_fg(int uid);
#endif /*CONFIG_FG_TASK_UID*/
static bool is_system_uid(struct task_struct *t)
{
int cur_uid;
cur_uid = task_uid(t).val;
if (cur_uid == SYSTEM_APP_UID)
return true;
return false;
}
static bool is_zygote_process(struct task_struct *t)
{
const struct cred *tcred = __task_cred(t);
struct task_struct * first_child = NULL;
if(t->children.next && t->children.next != (struct list_head*)&t->children.next)
first_child = container_of(t->children.next, struct task_struct, sibling);
if(!strcmp(t->comm, "main") && (tcred->uid.val == 0) && (t->parent != 0 && !strcmp(t->parent->comm,"init")) )
return true;
else
return false;
return false;
}
static bool is_system_process(struct task_struct *t)
{
if (is_system_uid(t)) {
if (t->group_leader && (!strncmp(t->group_leader->comm,"system_server", 13) ||
!strncmp(t->group_leader->comm, "surfaceflinger", 14) ||
!strncmp(t->group_leader->comm, "servicemanager", 14) ||
!strncmp(t->group_leader->comm, "ndroid.systemui", 15)))
return true;
}
return false;
}
bool is_critial_process(struct task_struct *t)
{
if( is_zygote_process(t) || is_system_process(t))
return true;
return false;
}
bool is_filter_process(struct task_struct *t)
{
if(!strncmp(t->comm,"logcat", TASK_COMM_LEN) )
return true;
return false;
}
static inline bool is_fg_task_without_sysuid(struct task_struct *t)
{
if(!is_system_uid(t)
#ifdef CONFIG_FG_TASK_UID
&&is_fg(task_uid(t).val)
#endif /*CONFIG_FG_TASK_UID*/
)
return true;
return false;
}
bool high_prio_for_task(struct task_struct *t)
{
if (!sysctl_fg_io_opt)
return false;
if ((is_fg_task_without_sysuid(t) && !is_filter_process(t))
|| is_critial_process(t))
return true;
return false;
}

View File

@@ -0,0 +1,43 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (C) 2018-2020 Oplus. All rights reserved.
*/
#undef TRACE_SYSTEM
#define TRACE_INCLUDE_PATH ../../block/oppo_foreground_io_opt/trace
#define TRACE_SYSTEM oppo_foreground_io_opt_trace
#if !defined(_OPPO_FOREGROUND_IO_OPT_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
#define _OPPO_FOREGROUND_IO_OPT_TRACE_H
#include <linux/tracepoint.h>
/*trace*/
TRACE_EVENT(block_fg_io_peek_req,
TP_PROTO(struct task_struct *task, long req_addr, \
char * fg, int count),
TP_ARGS(task, req_addr, fg, count),
TP_STRUCT__entry(
__array(char, comm, TASK_COMM_LEN)
__field(pid_t, pid)
__field(long, req_addr)
__array(char, fg, 3)
__field(int, count)
),
TP_fast_assign(
memcpy(__entry->comm, task->comm, TASK_COMM_LEN);
__entry->pid = task->pid;
__entry->req_addr = req_addr;
memcpy(__entry->fg, fg, 3);
__entry->count = count;
),
TP_printk("%s (%d), req_addr %x task_group:%s, count %d",
__entry->comm, __entry->pid, __entry->req_addr,
__entry->fg, __entry->count)
);
#endif /*_OPPO_FOREGROUND_IO_OPT_TRACE_H*/
#include <trace/define_trace.h>

View File

@@ -0,0 +1,249 @@
/***************************************************************
** Copyright (C), 2020, OPLUS Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oplus_display_panel_cabc.c
** Description : oplus display panel cabc feature
** Version : 1.0
** Date : 2020/07/06
** Author : xupengcheng@MULTIMEDIA.DISPLAY.LCD
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Li.Sheng 2020/07/06 1.0 Build this feature
******************************************************************/
#ifdef OPLUS_FEATURE_LCD_CABC
#include "oplus_display_panel_cabc.h"
#include "oppo_dsi_support.h"
int cabc_mode = 0;
DEFINE_MUTEX(oplus_cabc_lock);
int dsi_panel_cabc_video(struct dsi_panel *panel) {
int rc = 0;
if (!panel) {
pr_err("Invalid params\n");
return -EINVAL;
}
mutex_lock(&panel->panel_lock);
if (!dsi_panel_initialized(panel)) {
rc = -EINVAL;
goto error;
}
rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_CABC_VIDEO);
if (rc) {
pr_err("[%s] failed to send DSI_CMD_CABC_VIDEO cmds, rc=%d\n",
panel->name, rc);
}
error:
mutex_unlock(&panel->panel_lock);
return rc;
}
int dsi_panel_cabc_image(struct dsi_panel *panel) {
int rc = 0;
if (!panel) {
pr_err("Invalid params\n");
return -EINVAL;
}
mutex_lock(&panel->panel_lock);
if (!dsi_panel_initialized(panel)) {
rc = -EINVAL;
goto error;
}
rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_CABC_IMAGE);
if (rc) {
pr_err("[%s] failed to send DSI_CMD_CABC_IMAGE cmds, rc=%d\n",
panel->name, rc);
}
error:
mutex_unlock(&panel->panel_lock);
return rc;
}
int dsi_panel_cabc_ui(struct dsi_panel *panel) {
int rc = 0;
if (!panel) {
pr_err("Invalid params\n");
return -EINVAL;
}
mutex_lock(&panel->panel_lock);
if (!dsi_panel_initialized(panel)) {
rc = -EINVAL;
goto error;
}
rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_CABC_UI);
if (rc) {
pr_err("[%s] failed to send DSI_CMD_CABC_UI cmds, rc=%d\n",
panel->name, rc);
}
error:
mutex_unlock(&panel->panel_lock);
return rc;
}
int dsi_panel_cabc_off(struct dsi_panel *panel) {
int rc = 0;
if (!panel) {
pr_err("Invalid params\n");
return -EINVAL;
}
mutex_lock(&panel->panel_lock);
if (!dsi_panel_initialized(panel)) {
rc = -EINVAL;
goto error;
}
rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_CABC_OFF);
if (rc) {
pr_err("[%s] failed to send DSI_CMD_CABC_OFF cmds, rc=%d\n",
panel->name, rc);
}
error:
mutex_unlock(&panel->panel_lock);
return rc;
}
int dsi_display_cabc_video(struct dsi_display *display) {
int rc = 0;
if (!display || !display->panel) {
pr_err("Invalid params\n");
return -EINVAL;
}
mutex_lock(&display->display_lock);
/* enable the clk vote for CMD mode panels */
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_ON);
}
rc = dsi_panel_cabc_video(display->panel);
if (rc) {
pr_err("[%s] failed to dsi_panel_cabc_video, rc=%d\n",
display->name, rc);
}
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_OFF);
}
mutex_unlock(&display->display_lock);
return rc;
}
int dsi_display_cabc_image(struct dsi_display *display) {
int rc = 0;
if (!display || !display->panel) {
pr_err("Invalid params\n");
return -EINVAL;
}
mutex_lock(&display->display_lock);
/* enable the clk vote for CMD mode panels */
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_ON);
}
rc = dsi_panel_cabc_image(display->panel);
if (rc) {
pr_err("[%s] failed to dsi_panel_cabc_image, rc=%d\n",
display->name, rc);
}
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_OFF);
}
mutex_unlock(&display->display_lock);
return rc;
}
int dsi_display_cabc_ui(struct dsi_display *display) {
int rc = 0;
if (!display || !display->panel) {
pr_err("Invalid params\n");
return -EINVAL;
}
mutex_lock(&display->display_lock);
/* enable the clk vote for CMD mode panels */
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_ON);
}
rc = dsi_panel_cabc_ui(display->panel);
if (rc) {
pr_err("[%s] failed to dsi_panel_cabc_ui, rc=%d\n",
display->name, rc);
}
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_OFF);
}
mutex_unlock(&display->display_lock);
return rc;
}
int dsi_display_cabc_off(struct dsi_display *display) {
int rc = 0;
if (!display || !display->panel) {
pr_err("Invalid params\n");
return -EINVAL;
}
mutex_lock(&display->display_lock);
/* enable the clk vote for CMD mode panels */
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_ON);
}
rc = dsi_panel_cabc_off(display->panel);
if (rc) {
pr_err("[%s] failed to dsi_panel_cabc_off, rc=%d\n",
display->name, rc);
}
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_OFF);
}
mutex_unlock(&display->display_lock);
return rc;
}
int __oplus_display_set_cabc(int mode) {
mutex_lock(&oplus_cabc_lock);
if(mode != cabc_mode) {
cabc_mode = mode;
}
mutex_unlock(&oplus_cabc_lock);
return 0;
}
#endif /*OPLUS_FEATURE_LCD_CABC*/

View File

@@ -0,0 +1,37 @@
/***************************************************************
** Copyright (C), 2020, OPLUS Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oplus_display_panel_cabc.h
** Description : oplus display panel cabc feature
** Version : 1.0
** Date : 2020/07/06
** Author : Li.Sheng@MULTIMEDIA.DISPLAY.LCD
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Li.Sheng 2020/07/06 1.0 Build this feature
******************************************************************/
#ifndef _OPLUS_DISPLAY_PANEL_CABC_H_
#define _OPLUS_DISPLAY_PANEL_CABC_H_
#ifdef OPLUS_FEATURE_LCD_CABC
#include <linux/err.h>
#include "dsi_display.h"
#include "dsi_panel.h"
#include "dsi_ctrl.h"
#include "dsi_ctrl_hw.h"
#include "dsi_drm.h"
#include "dsi_clk.h"
#include "dsi_pwr.h"
#include "sde_dbg.h"
int dsi_panel_cabc_video(struct dsi_panel *panel);
int dsi_panel_cabc_image(struct dsi_panel *panel);
int dsi_panel_cabc_ui(struct dsi_panel *panel);
int dsi_panel_cabc_off(struct dsi_panel *panel);
int dsi_display_cabc_video(struct dsi_display *display);
int dsi_display_cabc_image(struct dsi_display *display);
int dsi_display_cabc_ui(struct dsi_display *display);
int dsi_display_cabc_off(struct dsi_display *display);
int __oplus_display_set_cabc(int mode);
#endif /*OPLUS_FEATURE_LCD_CABC*/
#endif /*_OPLUS_DISPLAY_PANEL_CABC_H_*/

View File

@@ -0,0 +1,243 @@
/***************************************************************
** Copyright (C), 2020, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_aod.c
** Description : oppo aod feature
** Version : 1.0
** Date : 2020/04/23
** Author : Qianxu@MM.Display.LCD Driver
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Qianxu 2020/04/23 1.0 Build this moudle
******************************************************************/
#include "dsi_defs.h"
#include "oppo_aod.h"
int aod_light_mode = 0;
DEFINE_MUTEX(oppo_aod_light_mode_lock);
int __oppo_display_set_aod_light_mode(int mode) {
mutex_lock(&oppo_aod_light_mode_lock);
if(mode != aod_light_mode) {
aod_light_mode = mode;
}
mutex_unlock(&oppo_aod_light_mode_lock);
return 0;
}
int oppo_update_aod_light_mode_unlock(struct dsi_panel *panel)
{
int rc = 0;
enum dsi_cmd_set_type type;
if (aod_light_mode == 1)
type = DSI_CMD_AOD_LOW_LIGHT_MODE;
else
type = DSI_CMD_AOD_HIGH_LIGHT_MODE;
rc = dsi_panel_tx_cmd_set(panel, type);
if (rc) {
pr_err("[%s] failed to send DSI_CMD_AOD_LIGHT_MODE cmds, rc=%d\n",
panel->name, rc);
}
return rc;
}
#ifdef OPLUS_FEATURE_AOD_RAMLESS
/* Yuwei.Zhang@MULTIMEDIA.DISPLAY.LCD, 2020/09/25, sepolicy for aod ramless */
extern bool is_oppo_display_aod_mode(void);
#endif /* OPLUS_FEATURE_AOD_RAMLESS */
int oppo_update_aod_light_mode(void)
{
struct dsi_display *display = get_main_display();
int ret = 0;
if (!display || !display->panel) {
printk(KERN_INFO "oppo_set_aod_light_mode and main display is null");
return -EINVAL;
}
if (display->panel->is_hbm_enabled) {
pr_err("%s error panel->is_hbm_enabled\n", __func__);
return -EINVAL;
}
if (get_oppo_display_scene() != OPPO_DISPLAY_AOD_SCENE) {
pr_err("%s error get_oppo_display_scene = %d, \n", __func__, get_oppo_display_scene());
return -EFAULT;
}
mutex_lock(&display->display_lock);
/* enable the clk vote for CMD mode panels */
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_ON);
}
mutex_lock(&display->panel->panel_lock);
#ifdef OPLUS_FEATURE_AOD_RAMLESS
/* Yuwei.Zhang@MULTIMEDIA.DISPLAY.LCD, 2020/09/25, sepolicy for aod ramless */
if (display->panel->oppo_priv.is_aod_ramless &&
!is_oppo_display_aod_mode()) {
pr_err("not support update aod_light_mode at non-aod mode\n");
ret = -EINVAL;
goto error;
}
#endif /* OPLUS_FEATURE_AOD_RAMLESS */
if (!dsi_panel_initialized(display->panel)) {
pr_err("dsi_panel_aod_low_light_mode is not init\n");
ret = -EINVAL;
goto error;
}
ret = oppo_update_aod_light_mode_unlock(display->panel);
if (ret) {
pr_err("failed to set aod light status ret=%d", ret);
goto error;
}
error:
mutex_unlock(&display->panel->panel_lock);
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_ALL_CLKS, DSI_CLK_OFF);
}
mutex_unlock(&display->display_lock);
return ret;
}
int oppo_panel_set_aod_light_mode(void *buf)
{
unsigned int *temp_save = buf;
__oppo_display_set_aod_light_mode(*temp_save);
oppo_update_aod_light_mode();
return 0;
}
int oppo_panel_get_aod_light_mode(void *buf)
{
unsigned int *aod_mode = buf;
(*aod_mode) = aod_light_mode;
printk(KERN_INFO "oppo_get_aod_light_mode = %d\n", aod_light_mode);
return 0;
}
int dsi_panel_aod_on(struct dsi_panel *panel) {
int rc = 0;
if (!panel) {
pr_err("Invalid params\n");
return -EINVAL;
}
mutex_lock(&panel->panel_lock);
if (!dsi_panel_initialized(panel)) {
rc = -EINVAL;
goto error;
}
rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_AOD_ON);
if (rc) {
pr_err("[%s] failed to send DSI_CMD_AOD_ON cmds, rc=%d\n",
panel->name, rc);
}
error:
mutex_unlock(&panel->panel_lock);
return rc;
}
int dsi_panel_aod_off(struct dsi_panel *panel) {
int rc = 0;
if (!panel) {
pr_err("Invalid params\n");
return -EINVAL;
}
mutex_lock(&panel->panel_lock);
if (!dsi_panel_initialized(panel)) {
rc = -EINVAL;
goto error;
}
rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_AOD_OFF);
if (rc) {
pr_err("[%s] failed to send DSI_CMD_AOD_OFF cmds, rc=%d\n",
panel->name, rc);
}
error:
mutex_unlock(&panel->panel_lock);
return rc;
}
int dsi_display_aod_on(struct dsi_display *display) {
int rc = 0;
if (!display || !display->panel) {
pr_err("Invalid params\n");
return -EINVAL;
}
mutex_lock(&display->display_lock);
/* enable the clk vote for CMD mode panels */
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_ON);
}
rc = dsi_panel_aod_on(display->panel);
if (rc) {
pr_err("[%s] failed to dsi_panel_aod_on, rc=%d\n",
display->name, rc);
}
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_OFF);
}
mutex_unlock(&display->display_lock);
return rc;
}
int dsi_display_aod_off(struct dsi_display *display) {
int rc = 0;
if (!display || !display->panel) {
pr_err("Invalid params\n");
return -EINVAL;
}
mutex_lock(&display->display_lock);
/* enable the clk vote for CMD mode panels */
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_ON);
}
rc = dsi_panel_aod_off(display->panel);
if (rc) {
pr_err("[%s] failed to dsi_panel_aod_off, rc=%d\n",
display->name, rc);
}
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_OFF);
}
mutex_unlock(&display->display_lock);
return rc;
}

View File

@@ -0,0 +1,32 @@
/***************************************************************
** Copyright (C), 2020, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_aod.h
** Description : oppo aod feature
** Version : 1.0
** Date : 2020/04/23
** Author : Qianxu@MM.Display.LCD Driver
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Qianxu 2020/04/23 1.0 Build this moudle
******************************************************************/
#ifndef _OPPO_AOD_H_
#define _OPPO_AOD_H_
#include "dsi_display.h"
#include "oppo_dsi_support.h"
int dsi_display_aod_on(struct dsi_display *display);
int dsi_display_aod_off(struct dsi_display *display);
int oppo_update_aod_light_mode_unlock(struct dsi_panel *panel);
int oppo_update_aod_light_mode(void);
int oppo_panel_set_aod_light_mode(void *buf);
int oppo_panel_get_aod_light_mode(void *buf);
int __oppo_display_set_aod_light_mode(int mode);
#endif /* _OPPO_AOD_H_ */

View File

@@ -0,0 +1,699 @@
/***************************************************************
** Copyright (C), 2020, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_dc_diming.c
** Description : oppo dc_diming feature
** Version : 1.0
** Date : 2020/04/15
** Author : Qianxu@MM.Display.LCD Driver
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Qianxu 2020/04/15 1.0 Build this moudle
******************************************************************/
#include "oppo_display_private_api.h"
#include "oppo_dc_diming.h"
#include "oppo_onscreenfingerprint.h"
#include "oppo_aod.h"
int oppo_dimlayer_bl = 0;
int oppo_dimlayer_bl_enabled = 0;
int oppo_datadimming_v3_skip_frame = 2;
int oppo_panel_alpha = 0;
int oppo_underbrightness_alpha = 0;
static struct dsi_panel_cmd_set oppo_priv_seed_cmd_set;
extern int oppo_dimlayer_bl_on_vblank;
extern int oppo_dimlayer_bl_off_vblank;
extern int oppo_dimlayer_bl_delay;
extern int oppo_dimlayer_bl_delay_after;
extern int oppo_dimlayer_bl_enable_v2;
extern int oppo_dimlayer_bl_enable_v2_real;
extern int oppo_dimlayer_bl_enable_v3;
extern int oppo_dimlayer_bl_enable_v3_real;
extern int oppo_datadimming_vblank_count;
extern atomic_t oppo_datadimming_vblank_ref;
extern int oppo_fod_on_vblank;
extern int oppo_fod_off_vblank;
extern bool oppo_skip_datadimming_sync;
extern int oppo_dimlayer_hbm_vblank_count;
extern atomic_t oppo_dimlayer_hbm_vblank_ref;
extern int oppo_dc2_alpha;
extern int oppo_seed_backlight;
extern int oppo_panel_alpha;
extern oppo_dc_v2_on;
extern ktime_t oppo_backlight_time;
#ifdef OPLUS_FEATURE_AOD_RAMLESS
/* Yuwei.Zhang@MULTIMEDIA.DISPLAY.LCD, 2020/09/25, sepolicy for aod ramless */
extern int oppo_display_mode;
extern atomic_t aod_onscreenfp_status;
#endif /* OPLUS_FEATURE_AOD_RAMLESS */
static struct oppo_brightness_alpha brightness_seed_alpha_lut_dc[] = {
{0, 0xff},
{1, 0xfc},
{2, 0xfb},
{3, 0xfa},
{4, 0xf9},
{5, 0xf8},
{6, 0xf7},
{8, 0xf6},
{10, 0xf4},
{15, 0xf0},
{20, 0xea},
{30, 0xe0},
{45, 0xd0},
{70, 0xbc},
{100, 0x98},
{120, 0x80},
{140, 0x70},
{160, 0x58},
{180, 0x48},
{200, 0x30},
{220, 0x20},
{240, 0x10},
{260, 0x00},
};
/*Jiasong.ZhongPSW.MM.Display.LCD.Stable,2020-09-17 add for DC backlight */
int dsi_panel_parse_oppo_dc_config(struct dsi_panel *panel)
{
int rc = 0;
int i;
u32 length = 0;
u32 count = 0;
u32 size = 0;
u32 *arr_32 = NULL;
const u32 *arr;
struct dsi_parser_utils *utils = &panel->utils;
struct oppo_brightness_alpha *seq;
arr = utils->get_property(utils->data, "oppo,dsi-dc-brightness", &length);
if (!arr) {
DSI_ERR("[%s] oppo,dsi-dc-brightness not found\n", panel->name);
return -EINVAL;
}
if (length & 0x1) {
DSI_ERR("[%s] oppo,dsi-dc-brightness length error\n", panel->name);
return -EINVAL;
}
DSI_DEBUG("RESET SEQ LENGTH = %d\n", length);
length = length / sizeof(u32);
size = length * sizeof(u32);
arr_32 = kzalloc(size, GFP_KERNEL);
if (!arr_32) {
rc = -ENOMEM;
goto error;
}
rc = utils->read_u32_array(utils->data, "oppo,dsi-dc-brightness",
arr_32, length);
if (rc) {
DSI_ERR("[%s] cannot read dsi-dc-brightness\n", panel->name);
goto error_free_arr_32;
}
count = length / 2;
size = count * sizeof(*seq);
seq = kzalloc(size, GFP_KERNEL);
if (!seq) {
rc = -ENOMEM;
goto error_free_arr_32;
}
panel->dc_ba_seq = seq;
panel->dc_ba_count = count;
for (i = 0; i < length; i += 2) {
seq->brightness = arr_32[i];
seq->alpha = arr_32[i + 1];
seq++;
}
error_free_arr_32:
kfree(arr_32);
error:
return rc;
}
int sde_connector_update_backlight(struct drm_connector *connector, bool post)
{
struct sde_connector *c_conn = to_sde_connector(connector);
struct dsi_display *dsi_display;
if (c_conn->connector_type != DRM_MODE_CONNECTOR_DSI)
return 0;
dsi_display = c_conn->display;
if (!dsi_display || !dsi_display->panel || !dsi_display->panel->cur_mode) {
SDE_ERROR("Invalid params(s) dsi_display %pK, panel %pK\n",
dsi_display,
((dsi_display) ? dsi_display->panel : NULL));
return -EINVAL;
}
if (!connector->state || !connector->state->crtc)
return 0;
if (oppo_dimlayer_bl != oppo_dimlayer_bl_enabled) {
struct sde_connector *c_conn = to_sde_connector(connector);
struct drm_crtc *crtc = connector->state->crtc;
struct dsi_panel *panel = dsi_display->panel;
int bl_lvl = dsi_display->panel->bl_config.bl_level;
u32 current_vblank;
int on_vblank = 0;
int off_vblank = 0;
int vblank = 0;
int ret = 0;
int vblank_get = -EINVAL;
int on_delay = 0, on_delay_after = 0;
int off_delay = 0, off_delay_after = 0;
int delay = 0, delay_after = 0;
if (sde_crtc_get_fingerprint_mode(crtc->state)) {
oppo_dimlayer_bl_enabled = oppo_dimlayer_bl;
goto done;
}
if (bl_lvl < panel->cur_mode->priv_info->fod_th_brightness) {
on_vblank = panel->cur_mode->priv_info->fod_on_vblank;
off_vblank = panel->cur_mode->priv_info->fod_off_vblank;
on_delay = panel->cur_mode->priv_info->fod_on_delay;
off_delay = panel->cur_mode->priv_info->fod_off_delay;
} else {
on_vblank = panel->cur_mode->priv_info->fod_on_vblank_above_th;
off_vblank = panel->cur_mode->priv_info->fod_off_vblank_above_th;
on_delay = panel->cur_mode->priv_info->fod_on_delay_above_th;
off_delay = panel->cur_mode->priv_info->fod_off_delay_above_th;
}
if (oppo_dimlayer_bl_on_vblank != INT_MAX)
on_vblank = oppo_dimlayer_bl_on_vblank;
if (oppo_dimlayer_bl_off_vblank != INT_MAX)
off_vblank = oppo_dimlayer_bl_off_vblank;
if (oppo_dimlayer_bl) {
vblank = on_vblank;
delay = on_delay;
delay_after = on_delay_after;
} else {
vblank = off_vblank;
delay = off_delay;
delay_after = off_delay_after;
}
if (oppo_dimlayer_bl_delay >= 0)
delay = oppo_dimlayer_bl_delay;
if (oppo_dimlayer_bl_delay_after >= 0)
delay_after = oppo_dimlayer_bl_delay_after;
vblank_get = drm_crtc_vblank_get(crtc);
if (vblank >= 0) {
if (!post) {
oppo_dimlayer_bl_enabled = oppo_dimlayer_bl;
current_vblank = drm_crtc_vblank_count(crtc);
ret = wait_event_timeout(*drm_crtc_vblank_waitqueue(crtc),
current_vblank != drm_crtc_vblank_count(crtc),
msecs_to_jiffies(34));
current_vblank = drm_crtc_vblank_count(crtc) + vblank;
if (delay > 0)
usleep_range(delay, delay + 100);
_sde_connector_update_bl_scale_(c_conn);
if (delay_after)
usleep_range(delay_after, delay_after + 100);
if (vblank > 0) {
ret = wait_event_timeout(*drm_crtc_vblank_waitqueue(crtc),
current_vblank == drm_crtc_vblank_count(crtc),
msecs_to_jiffies(17 * 3));
}
}
} else {
if (!post) {
current_vblank = drm_crtc_vblank_count(crtc);
ret = wait_event_timeout(*drm_crtc_vblank_waitqueue(crtc),
current_vblank != drm_crtc_vblank_count(crtc),
msecs_to_jiffies(34));
} else {
if (vblank < -1) {
current_vblank = drm_crtc_vblank_count(crtc) + 1 - vblank;
ret = wait_event_timeout(*drm_crtc_vblank_waitqueue(crtc),
current_vblank == drm_crtc_vblank_count(crtc),
msecs_to_jiffies(17 * 3));
}
oppo_dimlayer_bl_enabled = oppo_dimlayer_bl;
if (delay > 0)
usleep_range(delay, delay + 100);
_sde_connector_update_bl_scale_(c_conn);
if (delay_after)
usleep_range(delay_after, delay_after + 100);
}
}
if (!vblank_get)
drm_crtc_vblank_put(crtc);
}
if (oppo_dimlayer_bl_enable_v2 != oppo_dimlayer_bl_enable_v2_real) {
struct sde_connector *c_conn = to_sde_connector(connector);
oppo_dimlayer_bl_enable_v2_real = oppo_dimlayer_bl_enable_v2;
_sde_connector_update_bl_scale_(c_conn);
}
done:
if (post) {
if (oppo_datadimming_vblank_count> 0) {
oppo_datadimming_vblank_count--;
} else {
while (atomic_read(&oppo_datadimming_vblank_ref) > 0) {
drm_crtc_vblank_put(connector->state->crtc);
atomic_dec(&oppo_datadimming_vblank_ref);
}
}
}
return 0;
}
int sde_connector_update_hbm(struct drm_connector *connector)
{
struct sde_connector *c_conn = to_sde_connector(connector);
struct dsi_display *dsi_display;
struct sde_connector_state *c_state;
int rc = 0;
int fingerprint_mode;
if (!c_conn) {
SDE_ERROR("Invalid params sde_connector null\n");
return -EINVAL;
}
if (c_conn->connector_type != DRM_MODE_CONNECTOR_DSI)
return 0;
c_state = to_sde_connector_state(connector->state);
dsi_display = c_conn->display;
if (!dsi_display || !dsi_display->panel) {
SDE_ERROR("Invalid params(s) dsi_display %pK, panel %pK\n",
dsi_display,
((dsi_display) ? dsi_display->panel : NULL));
return -EINVAL;
}
if (!c_conn->encoder || !c_conn->encoder->crtc ||
!c_conn->encoder->crtc->state) {
return 0;
}
fingerprint_mode = sde_crtc_get_fingerprint_mode(c_conn->encoder->crtc->state);
if (OPPO_DISPLAY_AOD_SCENE == get_oppo_display_scene()) {
if (sde_crtc_get_fingerprint_pressed(c_conn->encoder->crtc->state)) {
sde_crtc_set_onscreenfinger_defer_sync(c_conn->encoder->crtc->state, true);
} else {
sde_crtc_set_onscreenfinger_defer_sync(c_conn->encoder->crtc->state, false);
fingerprint_mode = false;
}
} else {
sde_crtc_set_onscreenfinger_defer_sync(c_conn->encoder->crtc->state, false);
}
if (fingerprint_mode != dsi_display->panel->is_hbm_enabled) {
struct drm_crtc *crtc = c_conn->encoder->crtc;
struct dsi_panel *panel = dsi_display->panel;
int vblank = 0;
u32 target_vblank, current_vblank;
int ret;
if (oppo_fod_on_vblank >= 0)
panel->cur_mode->priv_info->fod_on_vblank = oppo_fod_on_vblank;
if (oppo_fod_off_vblank >= 0)
panel->cur_mode->priv_info->fod_off_vblank = oppo_fod_off_vblank;
pr_err("OnscreenFingerprint mode: %s",
fingerprint_mode ? "Enter" : "Exit");
dsi_display->panel->is_hbm_enabled = fingerprint_mode;
if (fingerprint_mode) {
#ifdef OPLUS_FEATURE_AOD_RAMLESS
/* Yuwei.Zhang@MULTIMEDIA.DISPLAY.LCD, 2020/09/25, sepolicy for aod ramless */
if (!dsi_display->panel->oppo_priv.is_aod_ramless || oppo_display_mode) {
#endif /* OPLUS_FEATURE_AOD_RAMLESS */
mutex_lock(&dsi_display->panel->panel_lock);
if (!dsi_display->panel->panel_initialized) {
dsi_display->panel->is_hbm_enabled = false;
pr_err("panel not initialized, failed to Enter OnscreenFingerprint\n");
mutex_unlock(&dsi_display->panel->panel_lock);
return 0;
}
dsi_display_clk_ctrl(dsi_display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_ON);
if (oppo_seed_backlight) {
int frame_time_us;
frame_time_us = mult_frac(1000, 1000, panel->cur_mode->timing.refresh_rate);
oppo_panel_process_dimming_v2(panel, panel->bl_config.bl_level, true);
mipi_dsi_dcs_set_display_brightness(&panel->mipi_device, panel->bl_config.bl_level);
oppo_panel_process_dimming_v2_post(panel, true);
usleep_range(frame_time_us, frame_time_us + 100);
}
#ifdef OPLUS_FEATURE_AOD_RAMLESS
/* Yuwei.Zhang@MULTIMEDIA.DISPLAY.LCD, 2020/09/25, sepolicy for aod ramless */
else if (dsi_display->panel->oppo_priv.is_aod_ramless) {
ktime_t delta = ktime_sub(ktime_get(), oppo_backlight_time);
s64 delta_us = ktime_to_us(delta);
if (delta_us < 34000 && delta_us >= 0)
usleep_range(34000 - delta_us, 34000 - delta_us + 100);
}
#endif /* OPLUS_FEATURE_AOD_RAMLESS */
if (OPPO_DISPLAY_AOD_SCENE != get_oppo_display_scene() &&
dsi_display->panel->bl_config.bl_level) {
if (dsi_display->config.panel_mode != DSI_OP_VIDEO_MODE) {
current_vblank = drm_crtc_vblank_count(crtc);
ret = wait_event_timeout(*drm_crtc_vblank_waitqueue(crtc),
current_vblank != drm_crtc_vblank_count(crtc),
msecs_to_jiffies(17));
}
if (!strcmp(panel->oppo_priv.vendor_name, "AMS643YE01"))
usleep_range(4500,4600);
vblank = panel->cur_mode->priv_info->fod_on_vblank;
target_vblank = drm_crtc_vblank_count(crtc) + vblank;
rc = dsi_panel_tx_cmd_set(dsi_display->panel, DSI_CMD_AOD_HBM_ON);
if (vblank) {
ret = wait_event_timeout(*drm_crtc_vblank_waitqueue(crtc),
target_vblank == drm_crtc_vblank_count(crtc),
msecs_to_jiffies((vblank + 1) * 17));
if (!ret) {
pr_err("OnscreenFingerprint failed to wait vblank timeout target_vblank=%d current_vblank=%d\n",
target_vblank, drm_crtc_vblank_count(crtc));
}
}
} else {
rc = dsi_panel_tx_cmd_set(dsi_display->panel, DSI_CMD_AOD_HBM_ON);
}
dsi_display_clk_ctrl(dsi_display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_OFF);
mutex_unlock(&dsi_display->panel->panel_lock);
if (rc) {
pr_err("failed to send DSI_CMD_HBM_ON cmds, rc=%d\n", rc);
return rc;
}
#ifdef OPLUS_FEATURE_AOD_RAMLESS
/* Yuwei.Zhang@MULTIMEDIA.DISPLAY.LCD, 2020/09/25, sepolicy for aod ramless */
}
#endif /* OPLUS_FEATURE_AOD_RAMLESS */
} else {
bool aod_hbm_off = true;
bool set_bl_off = true;
#ifdef OPLUS_FEATURE_AOD_RAMLESS
/* Yuwei.Zhang@MULTIMEDIA.DISPLAY.LCD, 2020/09/25, sepolicy for aod ramless */
if(dsi_display->panel->oppo_priv.is_aod_ramless) {
if(atomic_read(&aod_onscreenfp_status)) {
aod_hbm_off = false;
pr_err("%s, skip AOD_HBM_OFF for ramless panel\n", __func__);
}
set_bl_off = false;
}
#endif /* OPLUS_FEATURE_AOD_RAMLESS */
mutex_lock(&dsi_display->panel->panel_lock);
if (!dsi_display->panel->panel_initialized) {
dsi_display->panel->is_hbm_enabled = true;
pr_err("panel not initialized, failed to Exit OnscreenFingerprint\n");
mutex_unlock(&dsi_display->panel->panel_lock);
return 0;
}
current_vblank = drm_crtc_vblank_count(crtc);
ret = wait_event_timeout(*drm_crtc_vblank_waitqueue(crtc),
current_vblank != drm_crtc_vblank_count(crtc),
msecs_to_jiffies(17));
if(!dsi_display->panel->oppo_priv.prj_flag) {
oppo_skip_datadimming_sync = true;
oppo_panel_update_backlight_unlock(panel);
oppo_skip_datadimming_sync = false;
}
vblank = panel->cur_mode->priv_info->fod_off_vblank;
target_vblank = drm_crtc_vblank_count(crtc) + vblank;
dsi_display_clk_ctrl(dsi_display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_ON);
if(OPPO_DISPLAY_AOD_HBM_SCENE == get_oppo_display_scene()) {
if (OPPO_DISPLAY_POWER_DOZE_SUSPEND == get_oppo_display_power_status() ||
OPPO_DISPLAY_POWER_DOZE == get_oppo_display_power_status()) {
rc = dsi_panel_tx_cmd_set(dsi_display->panel, DSI_CMD_AOD_HBM_OFF);
#ifdef OPLUS_FEATURE_AOD_RAMLESS
/* Yuwei.Zhang@MULTIMEDIA.DISPLAY.LCD, 2020/09/25, sepolicy for aod ramless */
if (dsi_display->panel->oppo_priv.is_aod_ramless) {
oppo_update_aod_light_mode_unlock(panel);
}
#endif /* OPLUS_FEATURE_AOD_RAMLESS */
set_oppo_display_scene(OPPO_DISPLAY_AOD_SCENE);
} else {
rc = dsi_panel_tx_cmd_set(dsi_display->panel, DSI_CMD_SET_NOLP);
/* set nolp would exit hbm, restore when panel status on hbm */
if(panel->bl_config.bl_level > 1023)
oppo_panel_update_backlight_unlock(panel);
if (oppo_display_get_hbm_mode()) {
rc = dsi_panel_tx_cmd_set(dsi_display->panel, DSI_CMD_AOD_HBM_ON);
}
set_oppo_display_scene(OPPO_DISPLAY_NORMAL_SCENE);
}
} else if (oppo_display_get_hbm_mode()) {
/* Do nothing to skip hbm off */
} else if (OPPO_DISPLAY_AOD_SCENE == get_oppo_display_scene()) {
if(aod_hbm_off) {
rc = dsi_panel_tx_cmd_set(dsi_display->panel, DSI_CMD_AOD_HBM_OFF);
#ifdef OPLUS_FEATURE_AOD_RAMLESS
/* Yuwei.Zhang@MULTIMEDIA.DISPLAY.LCD, 2020/09/25, sepolicy for aod ramless */
if (dsi_display->panel->oppo_priv.is_aod_ramless) {
oppo_update_aod_light_mode_unlock(panel);
}
#endif /* OPLUS_FEATURE_AOD_RAMLESS */
}
} else {
rc = dsi_panel_tx_cmd_set(dsi_display->panel, DSI_CMD_HBM_OFF);
if(set_bl_off) {
if(panel->bl_config.bl_level > 1023)
dsi_panel_set_backlight(panel, panel->bl_config.bl_level);
}
}
dsi_display_clk_ctrl(dsi_display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_OFF);
if(dsi_display->panel->oppo_priv.prj_flag) {
oppo_skip_datadimming_sync = true;
oppo_panel_update_backlight_unlock(panel);
oppo_skip_datadimming_sync = false;
}
mutex_unlock(&dsi_display->panel->panel_lock);
if (vblank) {
ret = wait_event_timeout(*drm_crtc_vblank_waitqueue(crtc),
target_vblank == drm_crtc_vblank_count(crtc),
msecs_to_jiffies((vblank + 1) * 17));
if (!ret) {
pr_err("OnscreenFingerprint failed to wait vblank timeout target_vblank=%d current_vblank=%d\n",
target_vblank, drm_crtc_vblank_count(crtc));
}
}
}
}
if (oppo_dimlayer_hbm_vblank_count > 0) {
oppo_dimlayer_hbm_vblank_count--;
} else {
while (atomic_read(&oppo_dimlayer_hbm_vblank_ref) > 0) {
drm_crtc_vblank_put(connector->state->crtc);
atomic_dec(&oppo_dimlayer_hbm_vblank_ref);
}
}
return 0;
}
int oppo_seed_bright_to_alpha(int brightness)
{
struct dsi_display *display = get_main_display();
struct oppo_brightness_alpha *lut = NULL;
int count = 0;
int i = 0;
int alpha;
if (!display)
return 0;
if (oppo_panel_alpha)
return oppo_panel_alpha;
if (display->panel->dc_ba_seq && display->panel->dc_ba_count) {
count = display->panel->dc_ba_count;
lut = display->panel->dc_ba_seq;
} else {
count = ARRAY_SIZE(brightness_seed_alpha_lut_dc);
lut = brightness_seed_alpha_lut_dc;
}
for (i = 0; i < count; i++) {
if (lut[i].brightness >= brightness)
break;
}
if (i == 0)
alpha = lut[0].alpha;
else if (i == count)
alpha = lut[count - 1].alpha;
else
alpha = interpolate(brightness, lut[i-1].brightness,
lut[i].brightness, lut[i-1].alpha,
lut[i].alpha);
return alpha;
}
struct dsi_panel_cmd_set *
oppo_dsi_update_seed_backlight(struct dsi_panel *panel, int brightness,
enum dsi_cmd_set_type type)
{
enum dsi_cmd_set_state state;
struct dsi_cmd_desc *cmds;
struct dsi_cmd_desc *oppo_cmd;
u8 *tx_buf;
int count, rc = 0;
int i = 0;
int k = 0;
int alpha = oppo_seed_bright_to_alpha(brightness);
int seed_bl_max = panel->oppo_priv.seed_bl_max;
if (type != DSI_CMD_SEED_MODE0 &&
type != DSI_CMD_SEED_MODE1 &&
type != DSI_CMD_SEED_MODE2 &&
type != DSI_CMD_SEED_MODE3 &&
type != DSI_CMD_SEED_MODE4 &&
type != DSI_CMD_SEED_OFF) {
return NULL;
}
if (type == DSI_CMD_SEED_OFF)
type = DSI_CMD_SEED_MODE0;
cmds = panel->cur_mode->priv_info->cmd_sets[type].cmds;
count = panel->cur_mode->priv_info->cmd_sets[type].count;
state = panel->cur_mode->priv_info->cmd_sets[type].state;
oppo_cmd = kmemdup(cmds, sizeof(*cmds) * count, GFP_KERNEL);
if (!oppo_cmd) {
rc = -ENOMEM;
goto error;
}
for (i = 0; i < count; i++)
oppo_cmd[i].msg.tx_buf = NULL;
for (i = 0; i < count; i++) {
u32 size;
size = oppo_cmd[i].msg.tx_len * sizeof(u8);
oppo_cmd[i].msg.tx_buf = kmemdup(cmds[i].msg.tx_buf, size, GFP_KERNEL);
if (!oppo_cmd[i].msg.tx_buf) {
rc = -ENOMEM;
goto error;
}
}
for (i = 0; i < count; i++) {
if (oppo_cmd[i].msg.tx_len != 0x16)
continue;
tx_buf = (u8 *)oppo_cmd[i].msg.tx_buf;
for (k = 0; k < oppo_cmd[i].msg.tx_len; k++) {
if (k == 0) {
continue;
}
tx_buf[k] = tx_buf[k] * (seed_bl_max - alpha) / seed_bl_max;
}
}
if (oppo_priv_seed_cmd_set.cmds) {
for (i = 0; i < oppo_priv_seed_cmd_set.count; i++)
kfree(oppo_priv_seed_cmd_set.cmds[i].msg.tx_buf);
kfree(oppo_priv_seed_cmd_set.cmds);
}
oppo_priv_seed_cmd_set.cmds = oppo_cmd;
oppo_priv_seed_cmd_set.count = count;
oppo_priv_seed_cmd_set.state = state;
oppo_dc2_alpha = alpha;
return &oppo_priv_seed_cmd_set;
error:
if (oppo_cmd) {
for (i = 0; i < count; i++)
kfree(oppo_cmd[i].msg.tx_buf);
kfree(oppo_cmd);
}
return ERR_PTR(rc);
}
int oppo_display_panel_get_dim_alpha(void *buf) {
unsigned int *temp_alpha = buf;
struct dsi_display *display = get_main_display();
if (!display->panel->is_hbm_enabled ||
(get_oppo_display_power_status() != OPPO_DISPLAY_POWER_ON)) {
(*temp_alpha) = 0;
return 0;
}
(*temp_alpha) = oppo_underbrightness_alpha;
return 0;
}
int oppo_display_panel_set_dim_alpha(void *buf) {
unsigned int *temp_alpha = buf;
(*temp_alpha) = oppo_panel_alpha;
return 0;
}
int oppo_display_panel_get_dim_dc_alpha(void *buf) {
int ret = 0;
unsigned int *temp_dim_alpha = buf;
struct dsi_display *display = get_main_display();
if (display->panel->is_hbm_enabled ||
get_oppo_display_power_status() != OPPO_DISPLAY_POWER_ON) {
ret = 0;
}
if (oppo_dc2_alpha != 0) {
ret = oppo_dc2_alpha;
} else if (oppo_underbrightness_alpha != 0) {
ret = oppo_underbrightness_alpha;
} else if (oppo_dimlayer_bl_enable_v3_real) {
ret = 1;
}
(*temp_dim_alpha) = ret;
return 0;
}

View File

@@ -0,0 +1,35 @@
/***************************************************************
** Copyright (C), 2020, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_dc_diming.h
** Description : oppo dc_diming feature
** Version : 1.0
** Date : 2020/04/15
** Author : Qianxu@MM.Display.LCD Driver
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Qianxu 2020/04/15 1.0 Build this moudle
******************************************************************/
#ifndef _OPPO_DC_DIMING_H_
#define _OPPO_DC_DIMING_H_
#include <drm/drm_connector.h>
#include "dsi_panel.h"
#include "dsi_defs.h"
#include "oppo_display_panel_hbm.h"
int sde_connector_update_backlight(struct drm_connector *connector, bool post);
int sde_connector_update_hbm(struct drm_connector *connector);
int oppo_seed_bright_to_alpha(int brightness);
struct dsi_panel_cmd_set * oppo_dsi_update_seed_backlight(struct dsi_panel *panel, int brightness,
enum dsi_cmd_set_type type);
int oppo_display_panel_get_dim_alpha(void *buf);
int oppo_display_panel_set_dim_alpha(void *buf);
int oppo_display_panel_get_dim_dc_alpha(void *buf);
int dsi_panel_parse_oppo_dc_config(struct dsi_panel *panel);
#endif /*_OPPO_DC_DIMING_H_*/

View File

@@ -0,0 +1,220 @@
/***************************************************************
** Copyright (C), 2020, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_display_panel.c
** Description : oppo display panel char dev /dev/oppo_panel
** Version : 1.0
** Date : 2020/06/13
** Author : Li.Sheng@MULTIMEDIA.DISPLAY.LCD
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Li.Sheng 2020/06/13 1.0 Build this moudle
******************************************************************/
#include "oppo_display_panel.h"
#define PANEL_IOCTL_DEF(ioctl, _func) \
[PANEL_IOCTL_NR(ioctl)] = { \
.cmd = ioctl, \
.func = _func, \
.name = #ioctl, \
}
static const struct panel_ioctl_desc panel_ioctls[] = {
PANEL_IOCTL_DEF(PANEL_IOCTL_SET_POWER, oppo_display_panel_set_pwr),
PANEL_IOCTL_DEF(PANEL_IOCTL_GET_POWER, oppo_display_panel_get_pwr),
PANEL_IOCTL_DEF(PANEL_IOCTL_SET_SEED, oppo_display_panel_set_seed),
PANEL_IOCTL_DEF(PANEL_IOCTL_GET_SEED, oppo_display_panel_get_seed),
PANEL_IOCTL_DEF(PANEL_IOCTL_GET_PANELID, oppo_display_panel_get_id),
PANEL_IOCTL_DEF(PANEL_IOCTL_SET_FFL, oppo_display_panel_set_ffl),
PANEL_IOCTL_DEF(PANEL_IOCTL_GET_FFL, oppo_display_panel_get_ffl),
PANEL_IOCTL_DEF(PANEL_IOCTL_SET_AOD, oppo_panel_set_aod_light_mode),
PANEL_IOCTL_DEF(PANEL_IOCTL_GET_AOD, oppo_panel_get_aod_light_mode),
PANEL_IOCTL_DEF(PANEL_IOCTL_SET_MAX_BRIGHTNESS, oppo_display_panel_set_max_brightness),
PANEL_IOCTL_DEF(PANEL_IOCTL_GET_MAX_BRIGHTNESS, oppo_display_panel_get_max_brightness),
PANEL_IOCTL_DEF(PANEL_IOCTL_GET_PANELINFO, oppo_display_panel_get_vendor),
PANEL_IOCTL_DEF(PANEL_IOCTL_GET_CCD, oppo_display_panel_get_ccd_check),
PANEL_IOCTL_DEF(PANEL_IOCTL_GET_SERIAL_NUMBER, oppo_display_panel_get_serial_number),
PANEL_IOCTL_DEF(PANEL_IOCTL_SET_HBM, oppo_display_panel_set_hbm),
PANEL_IOCTL_DEF(PANEL_IOCTL_GET_HBM, oppo_display_panel_get_hbm),
PANEL_IOCTL_DEF(PANEL_IOCTL_SET_DIM_ALPHA, oppo_display_panel_set_dim_alpha),
PANEL_IOCTL_DEF(PANEL_IOCTL_GET_DIM_ALPHA, oppo_display_panel_get_dim_alpha),
PANEL_IOCTL_DEF(PANEL_IOCTL_SET_DIM_DC_ALPHA, oppo_display_panel_set_dim_alpha),
PANEL_IOCTL_DEF(PANEL_IOCTL_GET_DIM_DC_ALPHA, oppo_display_panel_get_dim_dc_alpha),
};
static int panel_open(struct inode *inode, struct file *filp)
{
if (panel_ref) {
pr_err("%s panel has already open\n", __func__);
return -1;
}
++panel_ref;
try_module_get(THIS_MODULE);
return 0;
}
static ssize_t panel_read(struct file *filp, char __user *buffer,
size_t count, loff_t *offset)
{
pr_err("%s\n", __func__);
return count;
}
static ssize_t panel_write(struct file *file, const char __user *buffer,
size_t count, loff_t *f_pos)
{
pr_err("%s\n", __func__);
return count;
}
long panel_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
unsigned int in_size, out_size, drv_size, ksize;
unsigned int nr = PANEL_IOCTL_NR(cmd);
char static_data[128];
char *kdata = NULL;
const struct panel_ioctl_desc *ioctl = NULL;
oppo_panel_feature *func = NULL;
int retcode = -EINVAL;
if ((nr >= PANEL_COMMOND_MAX) || (nr <= PANEL_COMMOND_BASE)) {
pr_err("%s invalid cmd\n", __func__);
return retcode;
}
ioctl = &panel_ioctls[nr];
func = ioctl->func;
if (unlikely(!func)) {
pr_err("%s no function\n", __func__);
retcode = -EINVAL;
return retcode;
}
in_size = out_size = drv_size = PANEL_IOCTL_SIZE(cmd);
if ((cmd & ioctl->cmd & IOC_IN) == 0) {
in_size = 0;
}
if ((cmd & ioctl->cmd & IOC_OUT) == 0) {
out_size = 0;
}
ksize = max(max(in_size, out_size), drv_size);
pr_err("%s pid = %d, cmd = %s\n", __func__, task_pid_nr(current), ioctl->name);
if (ksize <= sizeof(static_data)) {
kdata = static_data;
} else {
kdata = kmalloc(sizeof(ksize), GFP_KERNEL);
if (!kdata) {
retcode = -ENOMEM;
goto err_panel;
}
}
if (copy_from_user(kdata, (void __user *)arg, in_size) != 0) {
retcode = -EFAULT;
goto err_panel;
}
if (ksize > in_size) {
memset(kdata+in_size, 0, ksize-in_size);
}
retcode = func(kdata); /*any lock here?*/
if (copy_to_user((void __user *)arg, kdata, out_size) != 0) {
retcode = -EFAULT;
goto err_panel;
}
err_panel:
if (!ioctl) {
pr_err("%s invalid ioctl\n", __func__);
}
if (kdata != static_data) {
kfree(kdata);
}
if (retcode) {
pr_err("%s pid = %d, retcode = %s\n", __func__, task_pid_nr(current), retcode);
}
return retcode;
}
int panel_release(struct inode *inode, struct file *filp)
{
--panel_ref;
module_put(THIS_MODULE);
pr_err("%s\n", __func__);
return 0;
}
static const struct file_operations panel_ops =
{
.owner = THIS_MODULE,
.open = panel_open,
.release = panel_release,
.unlocked_ioctl = panel_ioctl,
.compat_ioctl = panel_ioctl,
.read = panel_read,
.write = panel_write,
};
static int __init oppo_display_panel_init()
{
int rc = 0;
printk("%s\n", __func__);
rc = alloc_chrdev_region(&dev_num, 0, 1, OPPO_PANEL_NAME);
if (rc < 0) {
pr_err("%s: failed to alloc chrdev region\n", __func__);
return rc;
}
panel_class = class_create(THIS_MODULE, OPPO_PANEL_CLASS_NAME);
if (IS_ERR(panel_class)) {
pr_err("%s class create error\n", __func__);
goto err_class_create;
}
cdev_init(&panel_cdev, &panel_ops);
rc = cdev_add(&panel_cdev, dev_num, 1);
if (rc < 0) {
pr_err("%s: failed to add cdev\n", __func__);
goto err_cdev_add;
}
panel_dev = device_create(panel_class, NULL, dev_num, NULL, OPPO_PANEL_NAME);
if (IS_ERR(panel_dev)) {
pr_err("%s device create error\n", __func__);
goto err_device_create;
}
return 0;
err_device_create:
cdev_del(&panel_cdev);
err_cdev_add:
class_destroy(panel_class);
err_class_create:
unregister_chrdev_region(dev_num, 1);
return rc;
}
void __exit oppo_display_panel_exit()
{
pr_err("%s\n", __func__);
cdev_del(&panel_cdev);
device_destroy(panel_class, dev_num);
class_destroy(panel_class);
unregister_chrdev_region(dev_num, 1);
}
module_init(oppo_display_panel_init);
module_exit(oppo_display_panel_exit);
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Lisheng <>");

View File

@@ -0,0 +1,88 @@
/***************************************************************
** Copyright (C), 2020, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_display_panel.h
** Description : oppo display panel char dev /dev/oppo_panel
** Version : 1.0
** Date : 2020/06/13
** Author : Li.Sheng@MULTIMEDIA.DISPLAY.LCD
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Li.Sheng 2020/06/13 1.0 Build this moudle
******************************************************************/
#ifndef _OPPO_DISPLAY_PANEL_H_
#define _OPPO_DISPLAY_PANEL_H_
#include <linux/fs.h>
#include <linux/printk.h>
#include <linux/device.h>
#include <asm/ioctl.h>
#include <linux/err.h>
#include <linux/notifier.h>
#include <linux/kobject.h>
#include <linux/string.h>
#include <linux/sysfs.h>
#include <linux/module.h>
#include <linux/init.h>
#include "oppo_display_panel_power.h"
#include "oppo_display_panel_seed.h"
#include "oppo_display_panel_common.h"
#include "oppo_ffl.h"
#include "oppo_aod.h"
#include "oppo_dc_diming.h"
#define OPPO_PANEL_NAME "oppo_display"
#define OPPO_PANEL_CLASS_NAME "oppo_display_class"
#define OPPO_PANEL_IOCTL_BASE 'o'
#define PANEL_IO(nr) _IO(OPPO_PANEL_IOCTL_BASE, nr)
#define PANEL_IOR(nr, type) _IOR(OPPO_PANEL_IOCTL_BASE, nr, type)
#define PANEL_IOW(nr, type) _IOW(OPPO_PANEL_IOCTL_BASE, nr, type)
#define PANEL_IOWR(nr, type) _IOWR(OPPO_PANEL_IOCTL_BASE, nr, type)
#define PANEL_IOCTL_NR(n) _IOC_NR(n)
#define PANEL_IOCTL_SIZE(n) _IOC_SIZE(n)
typedef int oppo_panel_feature(void *data);
static dev_t dev_num = 0;
static struct class *panel_class;
static struct device *panel_dev;
static int panel_ref = 0;
static struct cdev panel_cdev;
struct panel_ioctl_desc {
unsigned int cmd;
oppo_panel_feature *func;
const char *name;
};
/*oppo ioctl case start*/
#define PANEL_COMMOND_BASE 0x00
#define PANEL_COMMOND_MAX 0x15
#define PANEL_IOCTL_SET_POWER PANEL_IOW(0x01, struct panel_vol_set)
#define PANEL_IOCTL_GET_POWER PANEL_IOWR(0x02, struct panel_vol_get)
#define PANEL_IOCTL_SET_SEED PANEL_IOW(0x03, unsigned int)
#define PANEL_IOCTL_GET_SEED PANEL_IOWR(0x04, unsigned int)
#define PANEL_IOCTL_GET_PANELID PANEL_IOWR(0x05, struct panel_id)
#define PANEL_IOCTL_SET_FFL PANEL_IOW(0x06, unsigned int)
#define PANEL_IOCTL_GET_FFL PANEL_IOWR(0x07, unsigned int)
#define PANEL_IOCTL_SET_AOD PANEL_IOW(0x08, unsigned int)
#define PANEL_IOCTL_GET_AOD PANEL_IOWR(0x09, unsigned int)
#define PANEL_IOCTL_SET_MAX_BRIGHTNESS PANEL_IOW(0x0A, unsigned int)
#define PANEL_IOCTL_GET_MAX_BRIGHTNESS PANEL_IOWR(0x0B, unsigned int)
#define PANEL_IOCTL_GET_PANELINFO PANEL_IOWR(0x0C, struct panel_info)
#define PANEL_IOCTL_GET_CCD PANEL_IOWR(0x0D, unsigned int)
#define PANEL_IOCTL_GET_SERIAL_NUMBER PANEL_IOWR(0x0E, struct panel_serial_number)
#define PANEL_IOCTL_SET_HBM PANEL_IOW(0x0F, unsigned int)
#define PANEL_IOCTL_GET_HBM PANEL_IOWR(0x10, unsigned int)
#define PANEL_IOCTL_SET_DIM_ALPHA PANEL_IOW(0x11, unsigned int)
#define PANEL_IOCTL_GET_DIM_ALPHA PANEL_IOWR(0x12, unsigned int)
#define PANEL_IOCTL_SET_DIM_DC_ALPHA PANEL_IOW(0x13, unsigned int)
#define PANEL_IOCTL_GET_DIM_DC_ALPHA PANEL_IOWR(0x14, unsigned int)
/*oppo ioctl case end*/
#endif /*_OPPO_DISPLAY_PANEL_H_*/

View File

@@ -0,0 +1,384 @@
/***************************************************************
** Copyright (C), 2020, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_display_panel_common.c
** Description : oppo display panel common feature
** Version : 1.0
** Date : 2020/06/13
** Author : Li.Sheng@MULTIMEDIA.DISPLAY.LCD
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Li.Sheng 2020/06/13 1.0 Build this moudle
******************************************************************/
#include "oppo_display_panel_common.h"
int oppo_debug_max_brightness = 0;
extern int dsi_display_read_panel_reg(struct dsi_display *display, u8 cmd,
void *data, size_t len);
int oppo_display_panel_get_id(void *buf)
{
struct dsi_display *display = get_main_display();
int ret = 0;
unsigned char read[30];
struct panel_id *panel_rid = buf;
if (get_oppo_display_power_status() == OPPO_DISPLAY_POWER_ON) {
if (display == NULL) {
printk(KERN_INFO "oppo_display_get_panel_id and main display is null");
ret = -1;
return ret;
}
ret = dsi_display_read_panel_reg(display, 0xDA, read, 1);
if (ret < 0) {
pr_err("failed to read DA ret=%d\n", ret);
return -EINVAL;
}
panel_rid->DA = (uint32_t)read[0];
ret = dsi_display_read_panel_reg(display, 0xDB, read, 1);
if (ret < 0) {
pr_err("failed to read DB ret=%d\n", ret);
return -EINVAL;
}
panel_rid->DB = (uint32_t)read[0];
ret = dsi_display_read_panel_reg(display, 0xDC, read, 1);
if (ret < 0) {
pr_err("failed to read DC ret=%d\n", ret);
return -EINVAL;
}
panel_rid->DC = (uint32_t)read[0];
} else {
printk(KERN_ERR
"%s oppo_display_get_panel_id, but now display panel status is not on\n",
__func__);
return -EINVAL;
}
return ret;
}
int oppo_display_panel_get_max_brightness(void *buf)
{
uint32_t *max_brightness = buf;
(*max_brightness) = oppo_debug_max_brightness;
return 0;
}
int oppo_display_panel_set_max_brightness(void *buf)
{
uint32_t *max_brightness = buf;
oppo_debug_max_brightness = (*max_brightness);
return 0;
}
int oppo_display_panel_get_vendor(void *buf)
{
struct panel_info *p_info = buf;
struct dsi_display *display = get_main_display();
char *vendor = (char *)display->panel->oppo_priv.vendor_name;
char *manu_name = (char *)display->panel->oppo_priv.manufacture_name;
if (!display || !display->panel ||
!display->panel->oppo_priv.vendor_name ||
!display->panel->oppo_priv.manufacture_name) {
pr_err("failed to config lcd proc device");
return -EINVAL;
}
memcpy(p_info->version, vendor,
strlen(vendor) > 31 ? 31 : (strlen(vendor) + 1));
memcpy(p_info->manufacture, manu_name,
strlen(manu_name) > 31 ? 31 : (strlen(manu_name) + 1));
return 0;
}
int oppo_display_panel_get_ccd_check(void *buf)
{
struct dsi_display *display = get_main_display();
struct mipi_dsi_device *mipi_device;
int rc = 0;
unsigned int *ccd_check = buf;
if (!display || !display->panel) {
pr_err("failed for: %s %d\n", __func__, __LINE__);
return -EINVAL;
}
if (get_oppo_display_power_status() != OPPO_DISPLAY_POWER_ON) {
printk(KERN_ERR"%s display panel in off status\n", __func__);
return -EFAULT;
}
if (display->panel->panel_mode != DSI_OP_CMD_MODE) {
pr_err("only supported for command mode\n");
return -EFAULT;
}
if (!(display && display->panel->oppo_priv.vendor_name) ||
!strcmp(display->panel->oppo_priv.vendor_name, "NT37800")) {
(*ccd_check) = 0;
goto end;
}
mipi_device = &display->panel->mipi_device;
mutex_lock(&display->display_lock);
mutex_lock(&display->panel->panel_lock);
if (!dsi_panel_initialized(display->panel)) {
rc = -EINVAL;
goto unlock;
}
rc = dsi_display_cmd_engine_enable(display);
if (rc) {
pr_err("%s, cmd engine enable failed\n", __func__);
goto unlock;
}
/* enable the clk vote for CMD mode panels */
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_ON);
}
if (!strcmp(display->panel->oppo_priv.vendor_name, "AMB655UV01")) {
{
char value[] = { 0x5A, 0x5A };
rc = mipi_dsi_dcs_write(mipi_device, 0xF0, value, sizeof(value));
}
{
char value[] = { 0x44, 0x50 };
rc = mipi_dsi_dcs_write(mipi_device, 0xE7, value, sizeof(value));
}
usleep_range(1000, 1100);
{
char value[] = { 0x03 };
rc = mipi_dsi_dcs_write(mipi_device, 0xB0, value, sizeof(value));
}
} else {
{
char value[] = { 0x5A, 0x5A };
rc = mipi_dsi_dcs_write(mipi_device, 0xF0, value, sizeof(value));
}
{
char value[] = { 0x02 };
rc = mipi_dsi_dcs_write(mipi_device, 0xB0, value, sizeof(value));
}
{
char value[] = { 0x44, 0x50 };
rc = mipi_dsi_dcs_write(mipi_device, 0xCC, value, sizeof(value));
}
usleep_range(1000, 1100);
{
char value[] = { 0x05 };
rc = mipi_dsi_dcs_write(mipi_device, 0xB0, value, sizeof(value));
}
}
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_OFF);
}
dsi_display_cmd_engine_disable(display);
mutex_unlock(&display->panel->panel_lock);
mutex_unlock(&display->display_lock);
if (!strcmp(display->panel->oppo_priv.vendor_name, "AMB655UV01")) {
{
unsigned char read[10];
rc = dsi_display_read_panel_reg(display, 0xE1, read, 1);
pr_err("read ccd_check value = 0x%x rc=%d\n", read[0], rc);
(*ccd_check) = read[0];
}
} else {
{
unsigned char read[10];
rc = dsi_display_read_panel_reg(display, 0xCC, read, 1);
pr_err("read ccd_check value = 0x%x rc=%d\n", read[0], rc);
(*ccd_check) = read[0];
}
}
mutex_lock(&display->display_lock);
mutex_lock(&display->panel->panel_lock);
if (!dsi_panel_initialized(display->panel)) {
rc = -EINVAL;
goto unlock;
}
rc = dsi_display_cmd_engine_enable(display);
if (rc) {
pr_err("%s, cmd engine enable failed\n", __func__);
goto unlock;
}
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_ON);
}
{
char value[] = { 0xA5, 0xA5 };
rc = mipi_dsi_dcs_write(mipi_device, 0xF0, value, sizeof(value));
}
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_OFF);
}
dsi_display_cmd_engine_disable(display);
unlock:
mutex_unlock(&display->panel->panel_lock);
mutex_unlock(&display->display_lock);
end:
pr_err("[%s] ccd_check = %d\n", display->panel->oppo_priv.vendor_name,
(*ccd_check));
return 0;
}
int oppo_display_panel_get_serial_number(void *buf)
{
int ret = 0, i;
unsigned char read[30] = {0};
struct panel_serial_number *panel_rnum = buf;
struct dsi_display *display = get_main_display();
unsigned base_index = 10;
panel_rnum->date = 0;
panel_rnum->precise_time = 0;
if (!display) {
printk(KERN_INFO
"oppo_display_get_panel_serial_number and main display is null");
return -1;
}
if (get_oppo_display_power_status() != OPPO_DISPLAY_POWER_ON) {
printk(KERN_ERR"%s display panel in off status\n", __func__);
return ret;
}
/*
* for some unknown reason, the panel_serial_info may read dummy,
* retry when found panel_serial_info is abnormal.
*/
for (i = 0; i < 10; i++) {
ret = dsi_display_read_panel_reg(get_main_display(), 0xA1, read, 17);
if (ret < 0) {
ret = scnprintf(buf, PAGE_SIZE,
"Get panel serial number failed, reason:%d", ret);
msleep(20);
continue;
}
/* 0xA1 11th 12th 13th 14th 15th
* HEX 0x32 0x0C 0x0B 0x29 0x37
* Bit [D7:D4][D3:D0] [D5:D0] [D5:D0] [D5:D0] [D5:D0]
* exp 3 2 C B 29 37
* Yyyy,mm,dd 2014 2m 12d 11h 41min 55sec
* panel_rnum.data[24:21][20:16] [15:8] [7:0]
* panel_rnum:precise_time [31:24] [23:16] [reserved]
*/
panel_rnum->date =
(((read[base_index] & 0xF0) << 20)
| ((read[base_index] & 0x0F) << 16)
| ((read[base_index + 1] & 0x1F) << 8)
| (read[base_index + 2] & 0x1F));
panel_rnum->precise_time =
(((read[base_index + 3] & 0x3F) << 24)
| ((read[base_index + 4] & 0x3F) << 16)
| (read[base_index + 5] << 8)
| (read[base_index + 6]));
if (!read[base_index]) {
/*
* the panel we use always large than 2011, so
* force retry when year is 2011
*/
msleep(20);
continue;
}
break;
}
return 0;
}
#ifdef OPLUS_BUG_STABILITY
/* xupengcheng@MULTIMEDIA.DISPLAY.LCD.Feature,2020-10-21 optimize osc adaptive */
int oplus_display_get_panel_parameters(struct dsi_panel *panel,
struct dsi_parser_utils *utils)
{
int ret = 0;
if (!panel || !utils) {
pr_err("[%s]invalid params\n", __func__);
return -EINVAL;
}
panel->oppo_priv.is_osc_support = utils->read_bool(utils->data, "oplus,osc-support");
pr_info("[%s]osc mode support: %s", __func__, panel->oppo_priv.is_osc_support ? "Yes" : "Not");
ret = utils->read_u32(utils->data,
"oplus,mdss-dsi-osc-clk-mode0-rate",
&panel->oppo_priv.osc_clk_mode0_rate);
if (ret) {
pr_err("[%s]failed get panel parameter: oplus,mdss-dsi-osc-clk-mode0-rate\n",
__func__);
panel->oppo_priv.osc_clk_mode0_rate = 0;
}
panel->oppo_priv.osc_clk_current_rate = panel->oppo_priv.osc_clk_mode0_rate;
pr_err("[%s]osc_clk_mode0_rate=%d\n", __func__, panel->oppo_priv.osc_clk_mode0_rate); //temp
ret = utils->read_u32(utils->data,
"oplus,mdss-dsi-osc-clk-mode1-rate",
&panel->oppo_priv.osc_clk_mode1_rate);
if (ret) {
pr_err("[%s]failed get panel parameter: oplus,mdss-dsi-osc-clk-mode0-rate\n",
__func__);
panel->oppo_priv.osc_clk_mode1_rate = 0;
}
pr_err("[%s]osc_clk_mode1_rate=%d\n", __func__, panel->oppo_priv.osc_clk_mode1_rate); //temp
return ret;
}
#endif /* OPLUS_BUG_STABILITY */

View File

@@ -0,0 +1,54 @@
/***************************************************************
** Copyright (C), 2020, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_display_panel_common.c
** Description : oppo display panel common feature
** Version : 1.0
** Date : 2020/06/13
** Author : Li.Sheng@MULTIMEDIA.DISPLAY.LCD
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Li.Sheng 2020/06/13 1.0 Build this moudle
******************************************************************/
#ifndef _OPPO_DISPLAY_PANEL_COMMON_H_
#define _OPPO_DISPLAY_PANEL_COMMON_H_
#include <linux/err.h>
#include "dsi_display.h"
#include "dsi_panel.h"
#include "dsi_ctrl.h"
#include "dsi_ctrl_hw.h"
#include "dsi_drm.h"
#include "dsi_clk.h"
#include "dsi_pwr.h"
#include "sde_dbg.h"
#include "oppo_dsi_support.h"
struct panel_id
{
uint32_t DA;
uint32_t DB;
uint32_t DC;
};
struct panel_info
{
char version[32];
char manufacture[32];
};
struct panel_serial_number
{
uint32_t date; /*year:month:day:hour 8bit uint*/
uint32_t precise_time; /* minute:second:reserved:reserved 8bit uint*/
};
int oppo_display_panel_get_id(void *buf);
int oppo_display_panel_get_max_brightness(void *buf);
int oppo_display_panel_set_max_brightness(void *buf);
int oppo_display_panel_get_vendor(void *buf);
int oppo_display_panel_get_ccd_check(void *buf);
int oppo_display_panel_get_serial_number(void *buf);
int oplus_display_get_panel_parameters(struct dsi_panel *panel, struct dsi_parser_utils *utils);
#endif /*_OPPO_DISPLAY_PANEL_COMMON_H_*/

View File

@@ -0,0 +1,258 @@
/***************************************************************
** Copyright (C), 2020, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_display_panel_hbm.c
** Description : oppo display panel hbm feature
** Version : 1.0
** Date : 2020/07/06
** Author : Li.Sheng@MULTIMEDIA.DISPLAY.LCD
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Li.Sheng 2020/07/06 1.0 Build this feature
******************************************************************/
#include "oppo_display_panel_hbm.h"
#include "oppo_dsi_support.h"
int hbm_mode = 0;
DEFINE_MUTEX(oppo_hbm_lock);
int dsi_panel_hbm_on(struct dsi_panel *panel)
{
int rc = 0;
if (!panel) {
pr_err("Invalid params\n");
return -EINVAL;
}
mutex_lock(&panel->panel_lock);
if (!dsi_panel_initialized(panel)) {
rc = -EINVAL;
goto error;
}
rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_HBM_ON);
if (rc) {
pr_err("[%s] failed to send DSI_CMD_HBM_ON cmds, rc=%d\n",
panel->name, rc);
}
error:
mutex_unlock(&panel->panel_lock);
return rc;
}
int dsi_panel_normal_hbm_on(struct dsi_panel *panel)
{
int rc = 0;
if (!panel) {
pr_err("Invalid params\n");
return -EINVAL;
}
mutex_lock(&panel->panel_lock);
if (!dsi_panel_initialized(panel)) {
rc = -EINVAL;
goto error;
}
rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_NORMAL_HBM_ON);
if (rc) {
pr_err("[%s] failed to send DSI_CMD_NORMAL_HBM_ON cmds, rc=%d\n",
panel->name, rc);
}
error:
mutex_unlock(&panel->panel_lock);
return rc;
}
int dsi_panel_hbm_off(struct dsi_panel *panel)
{
int rc = 0;
if (!panel) {
pr_err("Invalid params\n");
return -EINVAL;
}
mutex_lock(&panel->panel_lock);
if (!dsi_panel_initialized(panel)) {
rc = -EINVAL;
goto error;
}
/* if hbm already set by onscreenfinger, keep it */
if (panel->is_hbm_enabled) {
rc = 0;
goto error;
}
dsi_panel_set_backlight(panel, panel->bl_config.bl_level);
rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_HBM_OFF);
if (rc) {
pr_err("[%s] failed to send DSI_CMD_HBM_OFF cmds, rc=%d\n",
panel->name, rc);
}
error:
mutex_unlock(&panel->panel_lock);
return rc;
}
int dsi_display_hbm_on(struct dsi_display *display)
{
int rc = 0;
if (!display || !display->panel) {
pr_err("Invalid params\n");
return -EINVAL;
}
mutex_lock(&display->display_lock);
/* enable the clk vote for CMD mode panels */
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_ON);
}
rc = dsi_panel_hbm_on(display->panel);
if (rc) {
pr_err("[%s] failed to dsi_panel_hbm_on, rc=%d\n",
display->name, rc);
}
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_OFF);
}
mutex_unlock(&display->display_lock);
return rc;
}
int dsi_display_normal_hbm_on(struct dsi_display *display)
{
int rc = 0;
if (!display || !display->panel) {
pr_err("Invalid params\n");
return -EINVAL;
}
mutex_lock(&display->display_lock);
/* enable the clk vote for CMD mode panels */
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_ON);
}
rc = dsi_panel_normal_hbm_on(display->panel);
if (rc) {
pr_err("[%s] failed to dsi_panel_normal_hbm_on, rc=%d\n",
display->name, rc);
}
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_OFF);
}
mutex_unlock(&display->display_lock);
return rc;
}
int dsi_display_hbm_off(struct dsi_display *display)
{
int rc = 0;
if (!display || !display->panel) {
pr_err("Invalid params\n");
return -EINVAL;
}
mutex_lock(&display->display_lock);
/* enable the clk vote for CMD mode panels */
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_ON);
}
rc = dsi_panel_hbm_off(display->panel);
if (rc) {
pr_err("[%s] failed to dsi_panel_hbm_off, rc=%d\n",
display->name, rc);
}
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_OFF);
}
mutex_unlock(&display->display_lock);
return rc;
}
int oppo_display_get_hbm_mode(void)
{
return hbm_mode;
}
int __oppo_display_set_hbm(int mode)
{
mutex_lock(&oppo_hbm_lock);
if (mode != hbm_mode) {
hbm_mode = mode;
}
mutex_unlock(&oppo_hbm_lock);
return 0;
}
int oppo_display_panel_set_hbm(void *buf)
{
struct dsi_display *display = get_main_display();
unsigned int *temp_save = buf;
int ret = 0;
sscanf(buf, "%du", &temp_save);
printk(KERN_INFO "%s oppo_display_set_hbm = %d\n", __func__, (*temp_save));
if (get_oppo_display_power_status() != OPPO_DISPLAY_POWER_ON) {
printk(KERN_ERR "%s oppo_display_set_hbm = %d, but now display panel status is not on\n", __func__, (*temp_save));
return -EFAULT;
}
if (!display) {
printk(KERN_INFO "oppo_display_set_hbm and main display is null");
return -EINVAL;
}
__oppo_display_set_hbm((*temp_save));
if ((hbm_mode > 1) &&(hbm_mode <= 10)) {
ret = dsi_display_normal_hbm_on(get_main_display());
} else if (hbm_mode == 1) {
ret = dsi_display_hbm_on(get_main_display());
} else if (hbm_mode == 0) {
ret = dsi_display_hbm_off(get_main_display());
}
if (ret) {
pr_err("failed to set hbm status ret=%d", ret);
return ret;
}
return 0;
}
int oppo_display_panel_get_hbm(void *buf)
{
unsigned int *hbm_temp = buf;
printk(KERN_INFO "oppo_display_get_hbm = %d\n", hbm_mode);
(*hbm_temp) = hbm_mode;
return 0;
}

View File

@@ -0,0 +1,37 @@
/***************************************************************
** Copyright (C), 2020, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_display_panel_hbm.h
** Description : oppo display panel hbm feature
** Version : 1.0
** Date : 2020/07/06
** Author : Li.Sheng@MULTIMEDIA.DISPLAY.LCD
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Li.Sheng 2020/07/06 1.0 Build this feature
******************************************************************/
#ifndef _OPPO_DISPLAY_PANEL_HBM_H_
#define _OPPO_DISPLAY_PANEL_HBM_H_
#include <linux/err.h>
#include "dsi_display.h"
#include "dsi_panel.h"
#include "dsi_ctrl.h"
#include "dsi_ctrl_hw.h"
#include "dsi_drm.h"
#include "dsi_clk.h"
#include "dsi_pwr.h"
#include "sde_dbg.h"
int oppo_display_get_hbm_mode(void);
int __oppo_display_set_hbm(int mode);
int dsi_display_hbm_off(struct dsi_display *display);
int dsi_display_normal_hbm_on(struct dsi_display *display);
int dsi_display_hbm_on(struct dsi_display *display);
int dsi_panel_normal_hbm_on(struct dsi_panel *panel);
int dsi_panel_hbm_off(struct dsi_panel *panel);
int dsi_panel_hbm_on(struct dsi_panel *panel);
int oppo_display_panel_set_hbm(void *buf);
int oppo_display_panel_get_hbm(void *buf);
#endif /*_OPPO_DISPLAY_PANEL_HBM_H_*/

View File

@@ -0,0 +1,224 @@
/***************************************************************
** Copyright (C), 2020, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_display_panel_power.c
** Description : oppo display panel power control
** Version : 1.0
** Date : 2020/06/13
** Author : Li.Sheng@MULTIMEDIA.DISPLAY.LCD
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Li.Sheng 2020/06/13 1.0 Build this moudle
******************************************************************/
#include "oppo_display_panel_power.h"
PANEL_VOLTAGE_BAK panel_vol_bak[PANEL_VOLTAGE_ID_MAX] = {{0}, {0}, {2, 0, 1, 2, ""}};
u32 panel_pwr_vg_base = 0;
static int oppo_panel_find_vreg_by_name(const char *name)
{
int count = 0, i = 0;
struct dsi_vreg *vreg = NULL;
struct dsi_regulator_info *dsi_reg = NULL;
struct dsi_display *display = get_main_display();
if (!display) {
return -ENODEV;
}
if (!display->panel) {
return -EINVAL;
}
dsi_reg = &display->panel->power_info;
count = dsi_reg->count;
for (i = 0; i < count; i++) {
vreg = &dsi_reg->vregs[i];
pr_err("%s : find %s", __func__, vreg->vreg_name);
if (!strcmp(vreg->vreg_name, name)) {
pr_err("%s : find the vreg %s", __func__, name);
return i;
} else {
continue;
}
}
pr_err("%s : dose not find the vreg [%s]", __func__, name);
return -EINVAL;
}
int dsi_panel_parse_panel_power_cfg(struct dsi_panel *panel)
{
int rc = 0, i = 0;
const char *name_vddi = NULL;
const char *name_vddr = NULL;
u32 *panel_vol = NULL;
struct dsi_parser_utils *utils = &panel->utils;
pr_err("[%s] \n", __func__);
if (!strcmp(panel->type, "primary")) {
panel_vol = &panel_vol_bak[PANEL_VOLTAGE_ID_VDDI].voltage_id;
rc = utils->read_u32_array(utils->data, "qcom,panel_voltage_vddi",
panel_vol, PANEL_VOLTAGE_VALUE_COUNT);
if (rc) {
pr_err("[%s] failed to parse panel_voltage vddi\n", panel->name);
goto error;
}
rc = utils->read_string(utils->data, "qcom,panel_voltage_vddi_name",
&name_vddi);
if (rc) {
pr_err("[%s] failed to parse vddi name\n", panel->name);
goto error;
} else {
pr_err("[%s] surccess to parse vddi name %s\n", panel->name, name_vddi);
strcpy(panel_vol_bak[PANEL_VOLTAGE_ID_VDDI].pwr_name, name_vddi);
}
panel_vol = &panel_vol_bak[PANEL_VOLTAGE_ID_VDDR].voltage_id;
rc = utils->read_u32_array(utils->data, "qcom,panel_voltage_vddr",
panel_vol, PANEL_VOLTAGE_VALUE_COUNT);
if (rc) {
pr_err("[%s] failed to parse panel_voltage vddr\n", panel->name);
goto error;
}
rc = utils->read_string(utils->data, "qcom,panel_voltage_vddr_name",
&name_vddr);
if (rc) {
pr_err("[%s] failed to parse vddr name\n", panel->name);
goto error;
} else {
pr_err("[%s] surccess to parse vddr name %s\n", panel->name, name_vddr);
strcpy(panel_vol_bak[PANEL_VOLTAGE_ID_VDDR].pwr_name, name_vddr);
}
/*add for debug*/
for(i; i < PANEL_VOLTAGE_ID_MAX; i++) {
pr_err("[%s] panel_voltage[%d] = %d,%d,%d,%d,%s\n", __func__, i, panel_vol_bak[i].voltage_id,
panel_vol_bak[i].voltage_min, panel_vol_bak[i].voltage_current,
panel_vol_bak[i].voltage_max, panel_vol_bak[i].pwr_name);
}
}
error:
return rc;
}
static u32 oppo_panel_update_current_voltage(u32 id)
{
int vol_current = 0, pwr_id = 0;
struct dsi_vreg *dsi_reg = NULL;
struct dsi_regulator_info *dsi_reg_info = NULL;
struct dsi_display *display = get_main_display();
if (!display) {
return -ENODEV;
}
if (!display->panel || !display->drm_conn) {
return -EINVAL;
}
dsi_reg_info = &display->panel->power_info;
pwr_id = oppo_panel_find_vreg_by_name(panel_vol_bak[id].pwr_name);
if (pwr_id < 0) {
pr_err("%s: can't find the pwr_id, please check the vreg name\n", __func__);
return pwr_id;
}
dsi_reg = &dsi_reg_info->vregs[pwr_id];
if (!dsi_reg) {
return -EINVAL;
}
vol_current = regulator_get_voltage(dsi_reg->vreg);
return vol_current;
}
int oppo_display_panel_get_pwr(void *data)
{
int ret = 0;
struct panel_vol_get *panel_vol = data;
int pid = (panel_vol->panel_id - 1);
pr_err("%s : [id] = %d\n", __func__, pid);
panel_vol->panel_min = panel_vol_bak[pid].voltage_min;
panel_vol->panel_max = panel_vol_bak[pid].voltage_max;
panel_vol->panel_cur = panel_vol_bak[pid].voltage_current;
if (pid < PANEL_VOLTAGE_ID_VG_BASE &&
pid >= PANEL_VOLTAGE_ID_VDDI) {
ret = oppo_panel_update_current_voltage(pid);
if (ret < 0) {
pr_err("%s : update_current_voltage error = %d\n", __func__, ret);
return ret;
} else {
panel_vol->panel_cur = ret;
pr_err("%s : [id min cur max] = [%u32, %u32, %u32, %u32]\n", __func__,
pid, panel_vol->panel_min,
panel_vol->panel_cur, panel_vol->panel_max);
return 0;
}
}
return ret;
}
int oppo_display_panel_set_pwr(void *data)
{
struct panel_vol_set *panel_vol = data;
u32 panel_vol_value = 0, rc = 0, panel_vol_id = 0, pwr_id = 0;
struct dsi_vreg *dsi_reg = NULL;
struct dsi_regulator_info *dsi_reg_info = NULL;
struct dsi_display *display = get_main_display();
panel_vol_id = ((panel_vol->panel_id & 0x0F)-1);
panel_vol_value = panel_vol->panel_vol;
pr_err("debug for %s, id = %d value = %d\n",
__func__, panel_vol_id, panel_vol_value);
if (panel_vol_id < 0 || panel_vol_id > PANEL_VOLTAGE_ID_MAX) {
return -EINVAL;
}
if (panel_vol_value < panel_vol_bak[panel_vol_id].voltage_min ||
panel_vol_id > panel_vol_bak[panel_vol_id].voltage_max)
return -EINVAL;
if (!display) {
return -ENODEV;
}
if (!display->panel || !display->drm_conn) {
return -EINVAL;
}
if (panel_vol_id == PANEL_VOLTAGE_ID_VG_BASE) {
pr_err("%s: set the VGH_L pwr = %d \n", __func__, panel_vol_value);
panel_pwr_vg_base = panel_vol_value;
return rc;
}
dsi_reg_info = &display->panel->power_info;
pwr_id = oppo_panel_find_vreg_by_name(panel_vol_bak[panel_vol_id].pwr_name);
if (pwr_id < 0) {
pr_err("%s: can't find the vreg name, please re-check vreg name: %s \n",
__func__, panel_vol_bak[panel_vol_id].pwr_name);
return pwr_id;
}
dsi_reg = &dsi_reg_info->vregs[pwr_id];
rc = regulator_set_voltage(dsi_reg->vreg, panel_vol_value, panel_vol_value);
if (rc) {
pr_err("Set voltage(%s) fail, rc=%d\n",
dsi_reg->vreg_name, rc);
return -EINVAL;
}
return rc;
}

View File

@@ -0,0 +1,59 @@
/***************************************************************
** Copyright (C), 2020, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_display_panel_power.h
** Description : oppo display panel power control
** Version : 1.0
** Date : 2020/06/13
** Author : Li.Sheng@MULTIMEDIA.DISPLAY.LCD
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Li.Sheng 2020/06/13 1.0 Build this moudle
******************************************************************/
#ifndef _OPPO_DISPLAY_PANEL_POWER_H_
#define _OPPO_DISPLAY_PANEL_POWER_H_
#include <linux/err.h>
#include "dsi_display.h"
#include "dsi_panel.h"
#include "dsi_ctrl.h"
#include "dsi_ctrl_hw.h"
#include "dsi_drm.h"
#include "dsi_clk.h"
#include "dsi_pwr.h"
#include "sde_dbg.h"
struct panel_vol_set {
uint32_t panel_id;
uint32_t panel_vol;
};
struct panel_vol_get {
uint32_t panel_id;
uint32_t panel_min;
uint32_t panel_cur;
uint32_t panel_max;
};
enum PANEL_VOLTAGE_ENUM {
PANEL_VOLTAGE_ID_VDDI = 0,
PANEL_VOLTAGE_ID_VDDR,
PANEL_VOLTAGE_ID_VG_BASE,
PANEL_VOLTAGE_ID_MAX,
};
#define PANEL_VOLTAGE_VALUE_COUNT 4
typedef struct panel_voltage_bak {
u32 voltage_id;
u32 voltage_min;
u32 voltage_current;
u32 voltage_max;
char pwr_name[20];
} PANEL_VOLTAGE_BAK;
int oppo_display_panel_set_pwr(void *data);
int oppo_display_panel_get_pwr(void *data);
#endif /* _OPPO_DISPLAY_PANEL_POWER_H_ */

View File

@@ -0,0 +1,228 @@
/***************************************************************
** Copyright (C), 2020, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_display_panel_seed.c
** Description : oppo display panel seed feature
** Version : 1.0
** Date : 2020/06/13
** Author : Li.Sheng@MULTIMEDIA.DISPLAY.LCD
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Li.Sheng 2020/06/13 1.0 Build this moudle
******************************************************************/
#include "oppo_display_panel_seed.h"
#include "oppo_dsi_support.h"
int seed_mode = 0;
extern bool oppo_dc_v2_on;
DEFINE_MUTEX(oppo_seed_lock);
int oppo_display_get_seed_mode(void)
{
return seed_mode;
}
int __oppo_display_set_seed(int mode)
{
mutex_lock(&oppo_seed_lock);
if (mode != seed_mode) {
seed_mode = mode;
}
mutex_unlock(&oppo_seed_lock);
return 0;
}
int dsi_panel_seed_mode_unlock(struct dsi_panel *panel, int mode)
{
int rc = 0;
if (!dsi_panel_initialized(panel)) {
return -EINVAL;
}
if (oppo_dc_v2_on) {
rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SEED_ENTER);
if (rc) {
pr_err("[%s] failed to send DSI_CMD_SEED_ENTER cmds, rc=%d\n",
panel->name, rc);
}
}
switch (mode) {
case 0:
rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SEED_MODE0);
if (rc) {
pr_err("[%s] failed to send DSI_CMD_SEED_MODE0 cmds, rc=%d\n",
panel->name, rc);
}
break;
case 1:
rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SEED_MODE1);
if (rc) {
pr_err("[%s] failed to send DSI_CMD_SEED_MODE1 cmds, rc=%d\n",
panel->name, rc);
}
break;
case 2:
rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SEED_MODE2);
if (rc) {
pr_err("[%s] failed to send DSI_CMD_SEED_MODE2 cmds, rc=%d\n",
panel->name, rc);
}
break;
case 3:
rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SEED_MODE3);
if (rc) {
pr_err("[%s] failed to send DSI_CMD_SEED_MODE3 cmds, rc=%d\n",
panel->name, rc);
}
break;
case 4:
rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SEED_MODE4);
if (rc) {
pr_err("[%s] failed to send DSI_CMD_SEED_MODE4 cmds, rc=%d\n",
panel->name, rc);
}
break;
default:
rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SEED_OFF);
if (rc) {
pr_err("[%s] failed to send DSI_CMD_SEED_OFF cmds, rc=%d\n",
panel->name, rc);
}
pr_err("[%s] seed mode Invalid %d\n",
panel->name, mode);
}
if (!oppo_dc_v2_on) {
rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SEED_EXIT);
if (rc) {
pr_err("[%s] failed to send DSI_CMD_SEED_EXIT cmds, rc=%d\n",
panel->name, rc);
}
}
return rc;
}
int dsi_panel_seed_mode(struct dsi_panel *panel, int mode)
{
int rc = 0;
if (!panel) {
pr_err("Invalid params\n");
return -EINVAL;
}
mutex_lock(&panel->panel_lock);
rc = dsi_panel_seed_mode_unlock(panel, mode);
mutex_unlock(&panel->panel_lock);
return rc;
}
int dsi_display_seed_mode(struct dsi_display *display, int mode)
{
int rc = 0;
if (!display || !display->panel) {
pr_err("Invalid params\n");
return -EINVAL;
}
mutex_lock(&display->display_lock);
/* enable the clk vote for CMD mode panels */
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_ON);
}
rc = dsi_panel_seed_mode(display->panel, mode);
if (rc) {
pr_err("[%s] failed to dsi_panel_seed_on, rc=%d\n",
display->name, rc);
}
if (display->config.panel_mode == DSI_OP_CMD_MODE) {
rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_OFF);
}
mutex_unlock(&display->display_lock);
return rc;
}
int oppo_dsi_update_seed_mode(void)
{
struct dsi_display *display = get_main_display();
int ret = 0;
if (!display) {
pr_err("failed for: %s %d\n", __func__, __LINE__);
return -EINVAL;
}
ret = dsi_display_seed_mode(display, seed_mode);
return ret;
}
int oppo_display_panel_get_seed(void *data)
{
uint32_t *temp = data;
printk(KERN_INFO "oppo_display_get_seed = %d\n", seed_mode);
(*temp) = seed_mode;
return 0;
}
int oppo_display_panel_set_seed(void *data)
{
uint32_t *temp_save = data;
printk(KERN_INFO "%s oppo_display_set_seed = %d\n", __func__, *temp_save);
seed_mode = *temp_save;
__oppo_display_set_seed(*temp_save);
if (get_oppo_display_power_status() == OPPO_DISPLAY_POWER_ON) {
if (get_main_display() == NULL) {
printk(KERN_INFO "oppo_display_set_seed and main display is null");
return -EINVAL;
}
dsi_display_seed_mode(get_main_display(), seed_mode);
} else {
printk(KERN_ERR
"%s oppo_display_set_seed = %d, but now display panel status is not on\n",
__func__, *temp_save);
}
return 0;
}

View File

@@ -0,0 +1,35 @@
/***************************************************************
** Copyright (C), 2020, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_display_panel_seed.h
** Description : oppo display panel seed feature
** Version : 1.0
** Date : 2020/06/13
** Author : Li.Sheng@MULTIMEDIA.DISPLAY.LCD
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Li.Sheng 2020/06/13 1.0 Build this moudle
******************************************************************/
#ifndef _OPPO_DISPLAY_PANEL_SEED_H_
#define _OPPO_DISPLAY_PANEL_SEED_H_
#include <linux/err.h>
#include "dsi_display.h"
#include "dsi_panel.h"
#include "dsi_ctrl.h"
#include "dsi_ctrl_hw.h"
#include "dsi_drm.h"
#include "dsi_clk.h"
#include "dsi_pwr.h"
#include "sde_dbg.h"
int oppo_display_panel_get_seed(void *data);
int oppo_display_panel_set_seed(void *data);
int oppo_dsi_update_seed_mode(void);
int __oppo_display_set_seed(int mode);
int dsi_panel_seed_mode(struct dsi_panel *panel, int mode);
int dsi_panel_seed_mode_unlock(struct dsi_panel *panel, int mode);
int dsi_display_seed_mode(struct dsi_display *display, int mode);
#endif /* _OPPO_DISPLAY_PANEL_SEED_H_ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,65 @@
/***************************************************************
** Copyright (C), 2018, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_display_private_api.h
** Description : oppo display private api implement
** Version : 1.0
** Date : 2018/03/20
** Author : Jie.Hu@PSW.MM.Display.Stability
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Hu.Jie 2018/03/20 1.0 Build this moudle
******************************************************************/
#ifndef _OPPO_DISPLAY_PRIVATE_API_H_
#define _OPPO_DISPLAY_PRIVATE_API_H_
#include <linux/err.h>
#include <linux/list.h>
#include <linux/of.h>
#include "msm_drv.h"
#include "sde_connector.h"
#include "sde_crtc.h"
#include "sde_hw_dspp.h"
#include "sde_plane.h"
#include "msm_mmu.h"
#include "dsi_display.h"
#include "dsi_panel.h"
#include "dsi_ctrl.h"
#include "dsi_ctrl_hw.h"
#include "dsi_drm.h"
#include "dsi_clk.h"
#include "dsi_pwr.h"
#include "sde_dbg.h"
#include <linux/kobject.h>
#include <linux/string.h>
#include <linux/sysfs.h>
#include <linux/module.h>
#include <linux/init.h>
#include <drm/drm_mipi_dsi.h>
#include "oppo_dsi_support.h"
int oppo_panel_update_backlight_unlock(struct dsi_panel *panel);
int oppo_set_display_vendor(struct dsi_display *display);
int oppo_dsi_update_spr_mode(void);
int oppo_dsi_update_seed_mode(void);
void oppo_panel_process_dimming_v2_post(struct dsi_panel *panel, bool force_disable);
int oppo_panel_process_dimming_v2(struct dsi_panel *panel, int bl_lvl, bool force_disable);
int oppo_panel_process_dimming_v3(struct dsi_panel *panel, int brightness);
bool is_dsi_panel(struct drm_crtc *crtc);
int interpolate(int x, int xa, int xb, int ya, int yb);
int dsi_display_oppo_set_power(struct drm_connector *connector, int power_mode, void *disp);
int oppo_display_dynamic_clk_update_osc_clk(int clk_rate);
#endif /* _OPPO_DISPLAY_PRIVATE_API_H_ */

View File

@@ -0,0 +1,265 @@
/***************************************************************
** Copyright (C), 2018, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_dsi_support.c
** Description : display driver private management
** Version : 1.0
** Date : 2018/03/17
** Author : Jie.Hu@PSW.MM.Display.Stability
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Hu.Jie 2018/03/17 1.0 Build this moudle
******************************************************************/
#include "oppo_dsi_support.h"
#include <soc/oppo/boot_mode.h>
#include <soc/oplus/system/oppo_project.h>
#include <soc/oppo/device_info.h>
#include <linux/notifier.h>
#include <linux/module.h>
enum oppo_display_support_list oppo_display_vendor =
OPPO_DISPLAY_UNKNOW;
static enum oppo_display_power_status oppo_display_status =
OPPO_DISPLAY_POWER_OFF;
static enum oppo_display_scene oppo_siaplay_save_scene =
OPPO_DISPLAY_NORMAL_SCENE;
static BLOCKING_NOTIFIER_HEAD(oppo_display_notifier_list);
int oppo_display_register_client(struct notifier_block *nb)
{
return blocking_notifier_chain_register(&oppo_display_notifier_list,
nb);
}
EXPORT_SYMBOL(oppo_display_register_client);
int oppo_display_unregister_client(struct notifier_block *nb)
{
return blocking_notifier_chain_unregister(&oppo_display_notifier_list,
nb);
}
EXPORT_SYMBOL(oppo_display_unregister_client);
static int oppo_display_notifier_call_chain(unsigned long val, void *v)
{
return blocking_notifier_call_chain(&oppo_display_notifier_list, val,
v);
}
bool is_oppo_correct_display(enum oppo_display_support_list lcd_name)
{
return (oppo_display_vendor == lcd_name ? true : false);
}
bool is_silence_reboot(void)
{
if ((MSM_BOOT_MODE__SILENCE == get_boot_mode())
|| (MSM_BOOT_MODE__SAU == get_boot_mode())) {
return true;
} else {
return false;
}
}
int set_oppo_display_vendor(const char *display_name)
{
if (display_name == NULL) {
return -1;
}
/* add lcd info begin */
if (!strcmp(display_name, "dsi_oppo19365samsung_ams644vk01_1080_2400_cmd_display")) {
oppo_display_vendor = OPPO_SAMSUNG_AMS644VK01_DISPALY_FHD_PLUS_CMD_PANEL;
register_device_proc("lcd", "AMS644VK01", "samsung1024");
} else if (!strcmp(display_name, "dsi_oppo19567samsung_amb655uv01_1080_2400_cmd_display")) {
oppo_display_vendor = OPPO_SAMSUNG_AMB655UV01_DISPALY_FHD_PLUS_90FPS_PANEL;
register_device_proc("lcd", "AMB655UV01", "samsung1024");
} else if (!strcmp(display_name, "dsi_oppo19365samsung_ams643xf01_1080_2400_cmd_display")) {
oppo_display_vendor = OPPO_SAMSUNG_AMS643XF01_DISPALY_FHD_PLUS_CMD_PANEL;
register_device_proc("lcd", "AMS643XF01", "samsung1024");
/* Chao.Zhang@PSW.MM.DISPLAY.LCD, 20200914, add for 19031 lcd bringup */
} else if (!strcmp(display_name, "dsi_oppo19031samsung_ams641rw01_1080_2400_cmd_display")) {
oppo_display_vendor = OPPO_SAMSUNG_AMS641RW01_DISPLAY_FHD_PLUS_CMD_PANEL;
register_device_proc("lcd", "AMS641RW01", "samsung1024");
} else if (!strcmp(display_name, "dsi_oppo19031samsung_ams641rw01_1080_2400_61fps_cmd_display")) {
oppo_display_vendor = OPPO_SAMSUNG_AMS641RW01_DISPLAY_FHD_PLUS_61FPS_PANEL;
register_device_proc("lcd", "AMS641RW01", "samsung1024");
} else if (!strcmp(display_name, "dsi_oppo19031samsung_ams655ue01_1080_2400_61fps_cmd_display")) {
oppo_display_vendor = OPPO_SAMSUNG_AMS655UE01_DISPLAY_FHD_PLUS_61FPS_PANEL;
register_device_proc("lcd", "AMS655UE01", "samsung1024");
} else if (!strcmp(display_name, "dsi_oppo19111samsung_ams641rw16_1080_2340_cmd_display")) {
oppo_display_vendor = OPPO_SAMSUNG_AMS641RW16_DISPLAY_FHD_PLUS_CMD_PANEL;
register_device_proc("lcd", "AMS641RW16", "samsung1024");
/* Chao.Zhang@MULTIMEDIA.DISPLAY.LCD, 2020/09/25, add for 19081 LCD */
} else if (!strcmp(display_name, "dsi_samsung_fhd_plus_dsc_cmd_90fps_display")) {
oppo_display_vendor = OPPO_SAMSUNG_SOFEF03F_M_DISPLAY_FHD_DSC_CMD_PANEL;
register_device_proc("lcd", "SOFEF03F_M", "samsung1024");
} else {
oppo_display_vendor = OPPO_DISPLAY_UNKNOW;
pr_err("%s panel vendor info set failed!", __func__);
}
/* end */
return 0;
}
void notifier_oppo_display_early_status(enum oppo_display_power_status
power_status)
{
int blank;
OPPO_DISPLAY_NOTIFIER_EVENT oppo_notifier_data;
switch (power_status) {
case OPPO_DISPLAY_POWER_ON:
blank = OPPO_DISPLAY_POWER_ON;
oppo_notifier_data.data = &blank;
oppo_notifier_data.status = OPPO_DISPLAY_POWER_ON;
oppo_display_notifier_call_chain(OPPO_DISPLAY_EARLY_EVENT_BLANK,
&oppo_notifier_data);
break;
case OPPO_DISPLAY_POWER_DOZE:
blank = OPPO_DISPLAY_POWER_DOZE;
oppo_notifier_data.data = &blank;
oppo_notifier_data.status = OPPO_DISPLAY_POWER_DOZE;
oppo_display_notifier_call_chain(OPPO_DISPLAY_EARLY_EVENT_BLANK,
&oppo_notifier_data);
break;
case OPPO_DISPLAY_POWER_DOZE_SUSPEND:
blank = OPPO_DISPLAY_POWER_DOZE_SUSPEND;
oppo_notifier_data.data = &blank;
oppo_notifier_data.status = OPPO_DISPLAY_POWER_DOZE_SUSPEND;
oppo_display_notifier_call_chain(OPPO_DISPLAY_EARLY_EVENT_BLANK,
&oppo_notifier_data);
break;
case OPPO_DISPLAY_POWER_OFF:
blank = OPPO_DISPLAY_POWER_OFF;
oppo_notifier_data.data = &blank;
oppo_notifier_data.status = OPPO_DISPLAY_POWER_OFF;
oppo_display_notifier_call_chain(OPPO_DISPLAY_EARLY_EVENT_BLANK,
&oppo_notifier_data);
break;
default:
break;
}
}
void notifier_oppo_display_status(enum oppo_display_power_status power_status)
{
int blank;
OPPO_DISPLAY_NOTIFIER_EVENT oppo_notifier_data;
switch (power_status) {
case OPPO_DISPLAY_POWER_ON:
blank = OPPO_DISPLAY_POWER_ON;
oppo_notifier_data.data = &blank;
oppo_notifier_data.status = OPPO_DISPLAY_POWER_ON;
oppo_display_notifier_call_chain(OPPO_DISPLAY_EVENT_BLANK,
&oppo_notifier_data);
break;
case OPPO_DISPLAY_POWER_DOZE:
blank = OPPO_DISPLAY_POWER_DOZE;
oppo_notifier_data.data = &blank;
oppo_notifier_data.status = OPPO_DISPLAY_POWER_DOZE;
oppo_display_notifier_call_chain(OPPO_DISPLAY_EVENT_BLANK,
&oppo_notifier_data);
break;
case OPPO_DISPLAY_POWER_DOZE_SUSPEND:
blank = OPPO_DISPLAY_POWER_DOZE_SUSPEND;
oppo_notifier_data.data = &blank;
oppo_notifier_data.status = OPPO_DISPLAY_POWER_DOZE_SUSPEND;
oppo_display_notifier_call_chain(OPPO_DISPLAY_EVENT_BLANK,
&oppo_notifier_data);
break;
case OPPO_DISPLAY_POWER_OFF:
blank = OPPO_DISPLAY_POWER_OFF;
oppo_notifier_data.data = &blank;
oppo_notifier_data.status = OPPO_DISPLAY_POWER_OFF;
oppo_display_notifier_call_chain(OPPO_DISPLAY_EVENT_BLANK,
&oppo_notifier_data);
break;
default:
break;
}
}
void set_oppo_display_power_status(enum oppo_display_power_status power_status)
{
oppo_display_status = power_status;
}
enum oppo_display_power_status get_oppo_display_power_status(void)
{
return oppo_display_status;
}
EXPORT_SYMBOL(get_oppo_display_power_status);
void set_oppo_display_scene(enum oppo_display_scene display_scene)
{
oppo_siaplay_save_scene = display_scene;
}
enum oppo_display_scene get_oppo_display_scene(void)
{
return oppo_siaplay_save_scene;
}
EXPORT_SYMBOL(get_oppo_display_scene);
bool is_oppo_display_support_feature(enum oppo_display_feature feature_name)
{
bool ret = false;
switch (feature_name) {
case OPPO_DISPLAY_HDR:
ret = false;
break;
case OPPO_DISPLAY_SEED:
ret = true;
break;
case OPPO_DISPLAY_HBM:
ret = true;
break;
case OPPO_DISPLAY_LBR:
ret = true;
break;
case OPPO_DISPLAY_AOD:
ret = true;
break;
case OPPO_DISPLAY_ULPS:
ret = false;
break;
case OPPO_DISPLAY_ESD_CHECK:
ret = true;
break;
case OPPO_DISPLAY_DYNAMIC_MIPI:
ret = true;
break;
case OPPO_DISPLAY_PARTIAL_UPDATE:
ret = false;
break;
default:
break;
}
return ret;
}

View File

@@ -0,0 +1,122 @@
/***************************************************************
** Copyright (C), 2018, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_dsi_support.h
** Description : display driver private management
** Version : 1.0
** Date : 2018/03/17
** Author : Jie.Hu@PSW.MM.Display.Stability
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Hu.Jie 2018/03/17 1.0 Build this moudle
******************************************************************/
#ifndef _OPPO_DSI_SUPPORT_H_
#define _OPPO_DSI_SUPPORT_H_
#include <linux/err.h>
#include <linux/string.h>
#include <linux/notifier.h>
/* A hardware display blank change occurred */
#define OPPO_DISPLAY_EVENT_BLANK 0x01
/* A hardware display blank early change occurred */
#define OPPO_DISPLAY_EARLY_EVENT_BLANK 0x02
enum oppo_display_support_list {
OPPO_SAMSUNG_S6E3FC2X01_DISPLAY_FHD_DSC_CMD_PANEL = 0,
OPPO_SAMSUNG_S6E8FC1X01_DISPALY_FHD_PLUS_VIDEO_PANEL = 1,
OPPO_BOE_HX83112A_FHD_PLUS_VIDEO_PANEL = 2,
OPPO_HUAXING_HX83112A_DISPALY_FHD_PLUS_VIDEO_PANEL = 3,
OPPO_HLT_HX83112A_DISPALY_FHD_PLUS_VIDEO_PANEL = 4,
OPPO_TM_NT36672A_DISPALY_FHD_PLUS_VIDEO_PANEL = 5,
OPPO_SAMSUNG_AMS644VK01_DISPALY_FHD_PLUS_CMD_PANEL = 6,
OPPO_SAMSUNG_AMB655UV01_DISPALY_FHD_PLUS_90FPS_PANEL = 7,
OPPO_SAMSUNG_AMS643XF01_DISPALY_FHD_PLUS_CMD_PANEL = 8,
/* Chao.Zhang@PSW.MM.DISPLAY.LCD, 20200914, add for 19031 lcd bringup */
OPPO_SAMSUNG_AMS641RW01_DISPLAY_FHD_PLUS_CMD_PANEL = 9,
OPPO_SAMSUNG_AMS641RW01_DISPLAY_FHD_PLUS_61FPS_PANEL = 10,
OPPO_SAMSUNG_AMS655UE01_DISPLAY_FHD_PLUS_61FPS_PANEL = 11,
OPPO_SAMSUNG_AMS641RW16_DISPLAY_FHD_PLUS_CMD_PANEL = 12,
/* Chao.Zhang@MULTIMEDIA.DISPLAY.LCD, 2020/09/25, add for 19081 LCD */
OPPO_SAMSUNG_SOFEF03F_M_DISPLAY_FHD_DSC_CMD_PANEL = 13,
OPPO_DISPLAY_UNKNOW,
};
enum oppo_display_power_status {
OPPO_DISPLAY_POWER_OFF = 0,
OPPO_DISPLAY_POWER_DOZE,
OPPO_DISPLAY_POWER_ON,
OPPO_DISPLAY_POWER_DOZE_SUSPEND,
OPPO_DISPLAY_POWER_ON_UNKNOW,
};
enum oppo_display_scene {
OPPO_DISPLAY_NORMAL_SCENE = 0,
OPPO_DISPLAY_NORMAL_HBM_SCENE,
OPPO_DISPLAY_AOD_SCENE,
OPPO_DISPLAY_AOD_HBM_SCENE,
OPPO_DISPLAY_UNKNOW_SCENE,
};
enum oppo_display_feature {
OPPO_DISPLAY_HDR = 0,
OPPO_DISPLAY_SEED,
OPPO_DISPLAY_HBM,
OPPO_DISPLAY_LBR,
OPPO_DISPLAY_AOD,
OPPO_DISPLAY_ULPS,
OPPO_DISPLAY_ESD_CHECK,
OPPO_DISPLAY_DYNAMIC_MIPI,
OPPO_DISPLAY_PARTIAL_UPDATE,
OPPO_DISPLAY_FEATURE_MAX,
};
typedef struct panel_serial_info
{
int reg_index;
uint64_t year;
uint64_t month;
uint64_t day;
uint64_t hour;
uint64_t minute;
uint64_t second;
uint64_t reserved[2];
} PANEL_SERIAL_INFO;
typedef struct oppo_display_notifier_event {
enum oppo_display_power_status status;
void *data;
}OPPO_DISPLAY_NOTIFIER_EVENT;
int oppo_display_register_client(struct notifier_block *nb);
int oppo_display_unregister_client(struct notifier_block *nb);
void notifier_oppo_display_early_status(enum oppo_display_power_status power_status);
void notifier_oppo_display_status(enum oppo_display_power_status power_status);
bool is_oppo_correct_display(enum oppo_display_support_list lcd_name);
bool is_silence_reboot(void);
int set_oppo_display_vendor(const char * display_name);
void set_oppo_display_power_status(enum oppo_display_power_status power_status);
enum oppo_display_power_status get_oppo_display_power_status(void);
void set_oppo_display_scene(enum oppo_display_scene display_scene);
enum oppo_display_scene get_oppo_display_scene(void);
bool is_oppo_display_support_feature(enum oppo_display_feature feature_name);
int oppo_display_get_resolution(unsigned int *xres, unsigned int *yres);
#endif /* _OPPO_DSI_SUPPORT_H_ */

View File

@@ -0,0 +1,243 @@
/***************************************************************
** Copyright (C), 2020, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_ffl.c
** Description : oppo ffl feature
** Version : 1.0
** Date : 2020/04/23
** Author : Qianxu@MM.Display.LCD Driver
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Qianxu 2020/04/23 1.0 Build this moudle
******************************************************************/
#include <linux/mutex.h>
#include "dsi_display.h"
#include "oppo_dsi_support.h"
#include "oppo_onscreenfingerprint.h"
#include "oppo_mm_kevent_fb.h"
#define FFL_LEVEL_START 2
#define FFL_LEVEL_END 236
#define FFLUPRARE 1
#define BACKUPRATE 6
#define FFL_PENDING_END 600
#define FFL_EXIT_CONTROL 0
#define FFL_TRIGGLE_CONTROL 1
#define FFL_EXIT_FULLY_CONTROL 2
bool oppo_ffl_trigger_finish = true;
bool ffl_work_running = false;
int is_ffl_enable = FFL_EXIT_CONTROL;
struct task_struct *oppo_ffl_thread;
struct kthread_worker oppo_ffl_worker;
struct kthread_work oppo_ffl_work;
static DEFINE_MUTEX(oppo_ffl_lock);
void oppo_ffl_set(int enable)
{
unsigned char payload[150] = "";
mutex_lock(&oppo_ffl_lock);
if (enable != is_ffl_enable) {
pr_debug("set_ffl_setting need change is_ffl_enable\n");
is_ffl_enable = enable;
if ((is_ffl_enable == FFL_TRIGGLE_CONTROL) && ffl_work_running) {
oppo_ffl_trigger_finish = false;
kthread_queue_work(&oppo_ffl_worker, &oppo_ffl_work);
}
}
mutex_unlock(&oppo_ffl_lock);
if ((is_ffl_enable == FFL_TRIGGLE_CONTROL) && ffl_work_running) {
scnprintf(payload, sizeof(payload), "NULL$$EventID@@%d$$fflset@@%d",
OPPO_MM_DIRVER_FB_EVENT_ID_FFLSET, enable);
upload_mm_kevent_fb_data(OPPO_MM_DIRVER_FB_EVENT_MODULE_DISPLAY, payload);
}
}
int oppo_display_panel_get_ffl(void *buf)
{
unsigned int *enable = buf;
(*enable) = is_ffl_enable;
return 0;
}
int oppo_display_panel_set_ffl(void *buf)
{
unsigned int *enable = buf;
printk(KERN_INFO "%s oppo_set_ffl_setting = %d\n", __func__, (*enable));
oppo_ffl_set(*enable);
return 0;
}
void oppo_ffl_setting_thread(struct kthread_work *work)
{
struct dsi_display *display = get_main_display();
int index = 0;
int pending = 0;
int system_backlight_target;
int rc;
if (get_oppo_display_power_status() == OPPO_DISPLAY_POWER_OFF) {
return;
}
if (is_ffl_enable != FFL_TRIGGLE_CONTROL) {
return;
}
if (!display || !display->panel) {
pr_err("failed to find display panel \n");
return;
}
if (!ffl_work_running) {
return;
}
rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_ON);
if (rc) {
pr_err("[%s] failed to enable DSI core clocks, rc=%d\n",
display->name, rc);
return;
}
for (index = FFL_LEVEL_START; index < FFL_LEVEL_END;
index = index + FFLUPRARE) {
if ((is_ffl_enable == FFL_EXIT_CONTROL) ||
(is_ffl_enable == FFL_EXIT_FULLY_CONTROL) ||
!ffl_work_running) {
break;
}
/*
* On Onscreenfingerprint mode, max backlight level should be FFL_FP_LEVEL
*/
if (display->panel->is_hbm_enabled && index > FFL_FP_LEVEL) {
break;
}
mutex_lock(&display->panel->panel_lock);
dsi_panel_set_backlight(display->panel, index);
mutex_unlock(&display->panel->panel_lock);
usleep_range(1000, 1100);
}
for (pending = 0; pending <= FFL_PENDING_END; pending++) {
if ((is_ffl_enable == FFL_EXIT_CONTROL) ||
(is_ffl_enable == FFL_EXIT_FULLY_CONTROL) ||
!ffl_work_running) {
break;
}
usleep_range(8000, 8100);
}
system_backlight_target = display->panel->bl_config.bl_level;
if (index < system_backlight_target) {
for (index; index < system_backlight_target; index = index + BACKUPRATE) {
if ((is_ffl_enable == FFL_EXIT_FULLY_CONTROL) ||
!ffl_work_running) {
break;
}
mutex_lock(&display->panel->panel_lock);
dsi_panel_set_backlight(display->panel, index);
mutex_unlock(&display->panel->panel_lock);
usleep_range(6000, 6100);
}
} else if (index > system_backlight_target) {
for (index; index > system_backlight_target; index = index - BACKUPRATE) {
if ((is_ffl_enable == FFL_EXIT_FULLY_CONTROL) ||
!ffl_work_running) {
break;
}
mutex_lock(&display->panel->panel_lock);
dsi_panel_set_backlight(display->panel, index);
mutex_unlock(&display->panel->panel_lock);
usleep_range(6000, 6100);
}
}
mutex_lock(&display->panel->panel_lock);
system_backlight_target = display->panel->bl_config.bl_level;
dsi_panel_set_backlight(display->panel, system_backlight_target);
oppo_ffl_trigger_finish = true;
mutex_unlock(&display->panel->panel_lock);
rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
DSI_CORE_CLK, DSI_CLK_OFF);
if (rc) {
pr_err("[%s] failed to disable DSI core clocks, rc=%d\n",
display->name, rc);
}
}
void oppo_start_ffl_thread(void)
{
mutex_lock(&oppo_ffl_lock);
ffl_work_running = true;
if (is_ffl_enable == FFL_TRIGGLE_CONTROL) {
oppo_ffl_trigger_finish = false;
kthread_queue_work(&oppo_ffl_worker, &oppo_ffl_work);
}
mutex_unlock(&oppo_ffl_lock);
}
void oppo_stop_ffl_thread(void)
{
mutex_lock(&oppo_ffl_lock);
oppo_ffl_trigger_finish = true;
ffl_work_running = false;
kthread_flush_worker(&oppo_ffl_worker);
mutex_unlock(&oppo_ffl_lock);
}
int oppo_ffl_thread_init(void)
{
kthread_init_worker(&oppo_ffl_worker);
kthread_init_work(&oppo_ffl_work, &oppo_ffl_setting_thread);
oppo_ffl_thread = kthread_run(kthread_worker_fn,
&oppo_ffl_worker, "oppo_ffl");
if (IS_ERR(oppo_ffl_thread)) {
pr_err("fail to start oppo_ffl_thread\n");
oppo_ffl_thread = NULL;
return -1;
}
return 0;
}
void oppo_ffl_thread_exit(void)
{
if (oppo_ffl_thread) {
is_ffl_enable = FFL_EXIT_FULLY_CONTROL;
kthread_flush_worker(&oppo_ffl_worker);
kthread_stop(oppo_ffl_thread);
oppo_ffl_thread = NULL;
}
}

View File

@@ -0,0 +1,35 @@
/***************************************************************
** Copyright (C), 2020, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_ffl.h
** Description : oppo ffl feature
** Version : 1.0
** Date : 2020/04/23
** Author : Qianxu@MM.Display.LCD Driver
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Qianxu 2020/04/23 1.0 Build this moudle
******************************************************************/
#ifndef _OPPO_FFL_H_
#define _OPPO_FFL_H_
#include <linux/kthread.h>
void oppo_ffl_set(int enable);
void oppo_ffl_setting_thread(struct kthread_work *work);
void oppo_start_ffl_thread(void);
void oppo_stop_ffl_thread(void);
int oppo_ffl_thread_init(void);
void oppo_ffl_thread_exit(void);
int oppo_display_panel_set_ffl(void *buf);
int oppo_display_panel_get_ffl(void *buf);
#endif /* _OPPO_FFL_H_ */

View File

@@ -0,0 +1,228 @@
/*
* oppo_mm_kevent.c - for kevent action upload,root action upload to user layer
* author by Deliang.Peng@MULTIMEDIA.Basic.Stability
*/
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/sched.h>
#include <linux/string.h>
#include <linux/skbuff.h>
#include <linux/types.h>
#include <linux/netlink.h>
#include <net/net_namespace.h>
#include <linux/proc_fs.h>
#include <net/sock.h>
#include <linux/vmalloc.h>
#include <linux/version.h>
#include <linux/uaccess.h>
#include "oppo_mm_kevent.h"
#ifdef CONFIG_OPPO_MM_KEVENT
static struct sock *mm_netlink_fd = NULL;
static struct mm_kevent_module mm_modules[MM_KEVENT_MODULE_SIZE_MAX];
static u32 mm_kevent_pid;
static mm_kevent_recv_user_func mm_kevent_recv_fb = NULL;
/* record connect pid and modules*/
void mm_kevent_add_module(u32 pid, char* module) {
int i = 0x0;
int len = 0x0;
if (!module) {
return;
}
len = strlen(module);
if (len > MM_KEVENT_MODULE_LEN_MAX) {
return;
}
for (i = 0; i < MM_KEVENT_MODULE_SIZE_MAX; i++) {
if ((!mm_modules[i].pid) || (!strcmp(mm_modules[i].modl, module))) {
mm_modules[i].pid = pid;
memcpy(mm_modules[i].modl, module, len);
mm_modules[i].modl[len] = 0x0;
return;
}
}
return;
}
/* record connect pid and modules*/
int mm_kevent_get_pid(char* module) {
int i = 0;
if (!module) {
return MM_KEVENT_BAD_VALUE;
}
for (i = 0; i < MM_KEVENT_MODULE_SIZE_MAX; i++) {
if (!strcmp(mm_modules[i].modl, module)) {
return mm_modules[i].pid;
}
}
return MM_KEVENT_BAD_VALUE;
}
/* send to user space */
int mm_kevent_send_to_user(struct mm_kevent_packet *userinfo) {
int ret, size, size_use;
unsigned int o_tail;
struct sk_buff *skbuff;
struct nlmsghdr *nlh;
struct mm_kevent_packet *packet;
int pid;
/* protect payload too long problem*/
if (userinfo->len >= MAX_PAYLOAD_DATASIZE) {
printk(KERN_ERR "mm_kevent payload_length out of range\n");
return MM_KEVENT_BAD_VALUE;
}
size = NLMSG_SPACE(sizeof(struct mm_kevent_packet) + userinfo->len);
/*allocate new buffer cache */
skbuff = alloc_skb(size, GFP_ATOMIC);
if (skbuff == NULL) {
printk(KERN_ERR "mm_kevent skbuff alloc_skb failed\n");
return MM_KEVENT_BAD_VALUE;
}
/* fill in the data structure */
nlh = nlmsg_put(skbuff, 0, 0, 0, size - sizeof(*nlh), 0);
if (nlh == NULL) {
printk(KERN_ERR "mm_kevent nlmsg_put failaure\n");
nlmsg_free(skbuff);
return MM_KEVENT_BAD_VALUE;
}
o_tail = skbuff->tail;
size_use = sizeof(struct mm_kevent_packet) + userinfo->len;
/* use struct mm_kernel_packet_info for data of nlmsg */
packet = NLMSG_DATA(nlh);
memset(packet, 0, size_use);
/* copy the payload content */
memcpy(packet, userinfo, size_use);
//compute nlmsg length
nlh->nlmsg_len = skbuff->tail - o_tail;
/* set control field,sender's pid */
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0))
NETLINK_CB(skbuff).pid = 0;
#else
NETLINK_CB(skbuff).portid = 0;
#endif
NETLINK_CB(skbuff).dst_group = 0;
/* send data */
pid = mm_kevent_get_pid(userinfo->tag);
if (pid == MM_KEVENT_BAD_VALUE) {
printk("mm_kevent chang send pid=%d,%s \n", mm_kevent_pid, userinfo->tag);
pid = mm_kevent_pid;
}
ret = netlink_unicast(mm_netlink_fd, skbuff, pid, MSG_DONTWAIT);
if (ret < 0) {
printk(KERN_ERR "mm_kevent send fail=%d, pid=%d \n", ret, pid);
return MM_KEVENT_BAD_VALUE;
}
return MM_KEVENT_NO_ERROR;
}
EXPORT_SYMBOL(mm_kevent_send_to_user);
void mm_kevent_set_recv_user(mm_kevent_recv_user_func recv_func) {
mm_kevent_recv_fb = recv_func;
}
EXPORT_SYMBOL(mm_kevent_set_recv_user);
/* kernel receive message from user space */
void mm_kevent_receive(struct sk_buff *__skbbr) {
struct sk_buff *skbu = NULL;
struct nlmsghdr *nlh;
char* pmesg = NULL;
uint32_t size = 0x0;
skbu = skb_get(__skbbr);
if (skbu->len >= sizeof(struct nlmsghdr)) {
nlh = (struct nlmsghdr *)skbu->data;
if ((nlh->nlmsg_len >= sizeof(struct nlmsghdr))
&& (__skbbr->len >= nlh->nlmsg_len)) {
u32 mm_kevent_type = nlh->nlmsg_type;
u32 mm_kevent_flags = nlh->nlmsg_flags;
mm_kevent_pid = nlh->nlmsg_pid;
size = (nlh->nlmsg_len - NLMSG_LENGTH(0));
if (size) {
pmesg = (char*)kmalloc(size + 0x10, GFP_KERNEL);
if (pmesg) {
memcpy(pmesg, NLMSG_DATA(nlh), size);
pmesg[size] = 0x0;
if (mm_kevent_type == MM_KEVENT_CONNECT) {
mm_kevent_add_module(mm_kevent_pid, pmesg);
}
if (mm_kevent_flags) {
printk("mm_kevent recv pid=%d, type=%d, flags=%d, data:%s\n",
mm_kevent_pid, mm_kevent_type, mm_kevent_flags, pmesg);
}
}
}
if (mm_kevent_recv_fb) {
mm_kevent_recv_fb(mm_kevent_type, mm_kevent_flags, pmesg);
}
}
}
if (pmesg) {
kfree(pmesg);
}
if (skbu) {
kfree_skb(skbu);
}
}
int __init mm_kevent_module_init(void) {
struct netlink_kernel_cfg cfg = {
.groups = 0x0,
.input = mm_kevent_receive,
};
mm_netlink_fd = netlink_kernel_create(&init_net, OPLUS_NETLINK_MM_KEVENT, &cfg);
if (!mm_netlink_fd) {
printk(KERN_ERR "mm_kevent can not create a socket\n");
return MM_KEVENT_BAD_VALUE;
}
memset(mm_modules, 0x0, sizeof(mm_modules));
printk(KERN_ERR "mm_kevent ok\n");
return MM_KEVENT_NO_ERROR;
}
void __exit mm_kevent_module_exit(void) {
sock_release(mm_netlink_fd->sk_socket);
printk("mm_kevent exit\n");
}
module_init(mm_kevent_module_init);
module_exit(mm_kevent_module_exit);
MODULE_AUTHOR("deliang.peng <>");
MODULE_DESCRIPTION("mm_kevent@1.0");
MODULE_VERSION("1.0");
MODULE_LICENSE("GPL");
#endif /* CONFIG_OPPO_MM_KEVENT */

View File

@@ -0,0 +1,64 @@
/*
* oppo_kevent.h - for kevent action upload upload to user layer
* author by
*/
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/sched.h>
#include <linux/string.h>
#include <linux/skbuff.h>
#include <linux/types.h>
#include <linux/netlink.h>
#include <net/net_namespace.h>
#include <net/sock.h>
#include <linux/version.h>
#ifndef CONFIG_OPPO_MM_KEVENT
#define CONFIG_OPPO_MM_KEVENT
#define MAX_PAYLOAD_TAG (128)
#define MAX_PAYLOAD_EVENTID (128)
#define MAX_PAYLOAD_DATASIZE (1024)
#define OPLUS_NETLINK_MM_KEVENT (35)
#define MM_KEVENT_MODULE_SIZE_MAX (16)
#define MM_KEVENT_MODULE_LEN_MAX (64)
#define MM_KEVENT_BAD_VALUE (-1)
#define MM_KEVENT_NO_ERROR (0)
//#define OPLUS_NETLINK_MM_KEVENT_TEST
#define OPLUS_NETLINK_MM_DBG_LV1 0x1
#define OPLUS_NETLINK_MM_DBG_LV2 0x2
#define DP_FB_EVENT "mm_kevent_dp"
#define AUDIO_EVENT "mm_kevent_ad"
enum mm_kevent_type {
MM_KEVENT_NOME = 0x0,
MM_KEVENT_CONNECT,
};
struct mm_kevent_module {
u32 pid;
char modl[MM_KEVENT_MODULE_LEN_MAX];
};
typedef void (*mm_kevent_recv_user_func)(int type, int flags, char* data);
struct mm_kevent_packet {
int type; /* 0:warrning,1:error,2:hw error*/
char tag[MAX_PAYLOAD_TAG]; /* logTag */
char event_id[MAX_PAYLOAD_EVENTID]; /* eventID */
size_t len; /* Length of packet data */
unsigned char data[0]; /* Optional packet data */
}__attribute__((packed));
int mm_kevent_send_to_user(struct mm_kevent_packet *userinfo);
void mm_kevent_set_recv_user(mm_kevent_recv_user_func recv_func);
void mm_kevent_receive(struct sk_buff *__skbbr);
#endif /* CONFIG_OPPO_KEVENT_UPLOAD */

View File

@@ -0,0 +1,220 @@
#include <linux/sysfs.h>
#include "oppo_mm_kevent.h"
#include "oppo_mm_kevent_fb.h"
#include <linux/delay.h>
#include <linux/mutex.h>
static void mm_kevent_upload_jobs(struct work_struct *work);
static LIST_HEAD(mm_kevent_list);
static DEFINE_MUTEX(mm_kevent_lock);
static DECLARE_DELAYED_WORK(mm_kevent_upload_work_thread, mm_kevent_upload_jobs);
static struct workqueue_struct *mm_kevent_wq;
static int mm_kevent_len = 0;
struct mm_kevent {
struct list_head head;
enum OPPO_MM_DIRVER_FB_EVENT_MODULE module;
struct mutex lock;
int count;
int count_total;
u32 count_limit;
int rate_limit_ms;
ktime_t first;
ktime_t last;
ktime_t last_upload;
struct delayed_work dwork;
char *payload;
char name[0];
};
static void mm_kevent_upload_jobs(struct work_struct *work)
{
struct mm_kevent *kevent = NULL, *n = NULL;
unsigned char payload[150] = "";
int cnt;
list_for_each_entry_safe(kevent, n, &mm_kevent_list, head) {
if (ktime_before(kevent->last, kevent->last_upload))
continue;
if (kevent->count_limit && (kevent->count_total % kevent->count_limit == 0)) {
kevent->count_limit <<= 1;
if (kevent->count_limit > 4096)
kevent->count_limit = 4096;
} else if (!kevent->rate_limit_ms || (kevent->rate_limit_ms &&
ktime_before(ktime_get(), ktime_add_ms(kevent->last_upload, kevent->rate_limit_ms)))) {
continue;
}
mutex_lock(&kevent->lock);
cnt = 0;
#define PAYLOAD(fmt, ...) \
if (sizeof(payload) > cnt) \
cnt += scnprintf(payload + cnt, sizeof(payload) - cnt, fmt, ##__VA_ARGS__);
PAYLOAD("%s$$EventID@@%d$$", kevent->name, OPPO_MM_DIRVER_FB_EVENT_ID_ERROR);
PAYLOAD("CT@@%d$$", kevent->count);
PAYLOAD("FT@@%lu$$", ktime_to_ms(kevent->first) / 1000);
PAYLOAD("ET@@%lu$$", ktime_to_ms(kevent->last) / 1000);
PAYLOAD("MSG@@%s", kevent->payload ? kevent->payload : "NULL");
if (kevent->payload) {
kfree(kevent->payload);
kevent->payload = NULL;
}
kevent->count = 0;
kevent->last_upload = ktime_get();
mutex_unlock(&kevent->lock);
upload_mm_kevent_fb_data(kevent->module, payload);
}
mod_delayed_work(mm_kevent_wq, &mm_kevent_upload_work_thread, 60 * 60 * HZ);
}
void mm_kevent_upload_recv_user(int type, int flags, char* data) {
printk(KERN_INFO "mm_kevent fb recv user type=0x%x, flags=0x%x, data=%s\n",
type, flags, data);
#ifdef OPLUS_NETLINK_MM_KEVENT_TEST
if ((type == OPPO_MM_DIRVER_FB_EVENT_MODULE_DISPLAY)
&& (flags & OPLUS_NETLINK_MM_DBG_LV2)) {
printk(KERN_INFO "mm_kevent: send to user \n");
upload_mm_kevent_fb_data(OPPO_MM_DIRVER_FB_EVENT_MODULE_DISPLAY, data);
}
#endif
}
int mm_kevent_init(void)
{
mm_kevent_wq = create_workqueue("mm_kevent");
if (!mm_kevent_wq)
return -ENOMEM;
queue_delayed_work(mm_kevent_wq, &mm_kevent_upload_work_thread, 0);
mm_kevent_set_recv_user(mm_kevent_upload_recv_user);
return 0;
}
void mm_kevent_deinit(void)
{
if (mm_kevent_wq)
destroy_workqueue(mm_kevent_wq);
mm_kevent_set_recv_user(NULL);
}
int upload_mm_kevent_fb_data(enum OPPO_MM_DIRVER_FB_EVENT_MODULE module, unsigned char *payload) {
struct mm_kevent_packet *user_msg_info;
char log_tag[32] = DP_FB_EVENT;
char event_id_display[20] = "20181203";
char event_id_audio[20] = "20181205";
void* buffer = NULL;
int len, size;
mutex_lock(&mm_kevent_lock);
len = strlen(payload);
size = sizeof(struct mm_kevent_packet) + len + 1;
printk(KERN_INFO "kevent_send_to_user:size=%d\n", size);
buffer = kmalloc(size, GFP_ATOMIC);
memset(buffer, 0, size);
user_msg_info = (struct mm_kevent_packet *)buffer;
user_msg_info->type = 1;
memcpy(user_msg_info->tag, log_tag, strlen(log_tag) + 1);
if (OPPO_MM_DIRVER_FB_EVENT_MODULE_DISPLAY == module) {
memcpy(user_msg_info->event_id, event_id_display, strlen(event_id_display) + 1);
} else {
memcpy(user_msg_info->event_id, event_id_audio, strlen(event_id_audio) + 1);
}
user_msg_info->len = len + 1;
memcpy(user_msg_info->data, payload, len + 1);
mm_kevent_send_to_user(user_msg_info);
//msleep(20);
kfree(buffer);
mutex_unlock(&mm_kevent_lock);
return 0;
}
static void mm_kevent_upload_work(struct work_struct *work)
{
struct delayed_work *dwork = to_delayed_work(work);
struct mm_kevent *new_kevent = container_of(dwork, struct mm_kevent, dwork);
struct mm_kevent *kevent = NULL, *n = NULL;
bool found = false;
list_for_each_entry_safe(kevent, n, &mm_kevent_list, head) {
if (!strcmp(kevent->name, new_kevent->name)) {
found = true;
break;
}
}
if (!found) {
if (mm_kevent_len > 200) {
unsigned char payload[150] = "";
pr_err("mm_kevent large than 200");
scnprintf(payload, sizeof(payload), "OutOfEvent$$EventID@@420$$MSG@@%s", new_kevent->name);
upload_mm_kevent_fb_data(kevent->module, payload);
goto done;
}
kevent = new_kevent;
kevent->count = 1;
kevent->count_total = 1;
new_kevent = NULL;
mm_kevent_len++;
list_add_tail(&kevent->head, &mm_kevent_list);
goto done;
}
if (WARN_ON(!kevent))
goto done;
mutex_lock(&kevent->lock);
kevent->count++;
kevent->count_total++;
kevent->last = new_kevent->first;
kfree(kevent->payload);
kevent->payload = new_kevent->payload;
new_kevent->payload = NULL;
mutex_unlock(&kevent->lock);
done:
mm_kevent_upload_jobs(NULL);
if (new_kevent)
kfree(new_kevent->payload);
kfree(new_kevent);
}
int mm_kevent_upload(enum OPPO_MM_DIRVER_FB_EVENT_MODULE module, const char *name,
int rate_limit_ms, char *payload)
{
struct mm_kevent *kevent = NULL;
int size;
if (!mm_kevent_wq)
return -EINVAL;
size = strlen(name) + sizeof(*kevent) + 1;
kevent = kzalloc(size, GFP_ATOMIC);
if (!kevent)
return -ENOMEM;
kevent->count_limit = 1;
kevent->first = ktime_get();
kevent->last = ktime_get();
kevent->last_upload = ktime_get();
kevent->rate_limit_ms = rate_limit_ms;
memcpy(kevent->name, name, strlen(name) + 1);
kevent->payload = kmemdup(payload, strlen(payload) + 1, GFP_ATOMIC);
mutex_init(&kevent->lock);
INIT_DELAYED_WORK(&kevent->dwork, mm_kevent_upload_work);
queue_delayed_work(mm_kevent_wq, &kevent->dwork, 0);
return 0;
}

View File

@@ -0,0 +1,74 @@
/***************************************************************
** Copyright (C), 2018, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_mm_kevent_fb.h
** Description : MM kevent fb data
** Version : 1.0
** Date : 2018/12/03
** Author : Ling.Guo@PSW.MM.Display.Stability
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Guo.Ling 2018/12/03 1.0 Build this moudle
** LiPing-M 2019/01/29 1.1 Add SMMU for QCOM
******************************************************************/
#ifndef _OPPO_MM_KEVENT_FB_
#define _OPPO_MM_KEVENT_FB_
#define MM_KEVENT_MAX_PAYLOAD_SIZE 150
enum {
MM_KEY_RATELIMIT_NONE = 0,
MM_KEY_RATELIMIT_30MIN = 60 * 30 * 1000,
MM_KEY_RATELIMIT_1H = MM_KEY_RATELIMIT_30MIN * 2,
MM_KEY_RATELIMIT_1DAY = MM_KEY_RATELIMIT_1H * 24,
};
enum OPPO_MM_DIRVER_FB_EVENT_ID {
OPPO_MM_DIRVER_FB_EVENT_ID_ESD = 401,
OPPO_MM_DIRVER_FB_EVENT_ID_VSYNC,
OPPO_MM_DIRVER_FB_EVENT_ID_HBM,
OPPO_MM_DIRVER_FB_EVENT_ID_FFLSET,
OPPO_MM_DIRVER_FB_EVENT_ID_MTK_CMDQ,
OPPO_MM_DIRVER_FB_EVENT_ID_MTK_UNDERFLOW,
OPPO_MM_DIRVER_FB_EVENT_ID_MTK_FENCE,
OPPO_MM_DIRVER_FB_EVENT_ID_MTK_JS,
OPPO_MM_DIRVER_FB_EVENT_ID_SMMU,
OPPO_MM_DIRVER_FB_EVENT_ID_GPU_FAULT,
OPPO_MM_DIRVER_FB_EVENT_ID_PANEL_MATCH_FAULT,
OPPO_MM_DIRVER_FB_EVENT_ID_ERROR = 420,
OPPO_MM_DIRVER_FB_EVENT_ID_INFO = 421,
OPPO_MM_DIRVER_FB_EVENT_ID_AUDIO = 801,
};
enum OPPO_MM_DIRVER_FB_EVENT_MODULE {
OPPO_MM_DIRVER_FB_EVENT_MODULE_DISPLAY = 0,
OPPO_MM_DIRVER_FB_EVENT_MODULE_AUDIO
};
int upload_mm_kevent_fb_data(enum OPPO_MM_DIRVER_FB_EVENT_MODULE module, unsigned char *payload);
int mm_kevent_upload(enum OPPO_MM_DIRVER_FB_EVENT_MODULE module, const char *name,
int rate_limit_ms, char *payload);
#define mm_kevent(m, name, rate_limit_ms, fmt, ...) \
do { \
char kv_data[MM_KEVENT_MAX_PAYLOAD_SIZE] = ""; \
scnprintf(kv_data, sizeof(kv_data), fmt, ##__VA_ARGS__); \
mm_kevent_upload(m, name, rate_limit_ms, kv_data); \
} while (0)
#define mm_display_kevent(name, rate_limit_ms, fmt, ...) \
mm_kevent(OPPO_MM_DIRVER_FB_EVENT_MODULE_DISPLAY, name, rate_limit_ms, fmt, ##__VA_ARGS__)
#define mm_display_kevent_named(rate_limit_ms, fmt, ...) \
do { \
char name[MM_KEVENT_MAX_PAYLOAD_SIZE]; \
scnprintf(name, sizeof(name), "%s:%d", __func__, __LINE__); \
mm_display_kevent(name, rate_limit_ms, fmt, ##__VA_ARGS__); \
} while (0)
int mm_kevent_init(void);
void mm_kevent_deinit(void);
#endif /* _OPPO_MM_KEVENT_FB_ */

View File

@@ -0,0 +1,737 @@
/***************************************************************
** Copyright (C), 2020, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_onscreenfingerprint.c
** Description : oppo onscreenfingerprint feature
** Version : 1.0
** Date : 2020/04/15
** Author : Qianxu@MM.Display.LCD Driver
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Qianxu 2020/04/15 1.0 Build this moudle
******************************************************************/
#include "sde_crtc.h"
#include "oppo_onscreenfingerprint.h"
#include "oppo_display_private_api.h"
#define DSI_PANEL_OPPO_DUMMY_VENDOR_NAME "PanelVendorDummy"
#define DSI_PANEL_OPPO_DUMMY_MANUFACTURE_NAME "dummy1024"
bool oppo_pcc_enabled = false;
bool oppo_skip_pcc = false;
bool oppo_fp_mode = false;
struct drm_msm_pcc oppo_save_pcc;
extern int oppo_underbrightness_alpha;
extern int oppo_dimlayer_dither_threshold;
extern u32 oppo_last_backlight;
extern int oppo_dimlayer_hbm;
extern int oppo_panel_alpha;
extern int hbm_mode;
extern bool oppo_ffl_trigger_finish;
static struct oppo_brightness_alpha brightness_alpha_lut[] = {
{0, 0xff},
{1, 0xee},
{2, 0xe8},
{3, 0xe6},
{4, 0xe5},
{6, 0xe4},
{10, 0xe0},
{20, 0xd5},
{30, 0xce},
{45, 0xc6},
{70, 0xb7},
{100, 0xad},
{150, 0xa0},
{227, 0x8a},
{300, 0x80},
{400, 0x6e},
{500, 0x5b},
{600, 0x50},
{800, 0x38},
{1023, 0x18},
};
static struct oppo_brightness_alpha brightness_alpha_lut_dc[] = {
{0, 0xff},
{1, 0xE0},
{2, 0xd6},
{3, 0xd5},
{4, 0xcf},
{5, 0xcb},
{6, 0xc9},
{8, 0xc5},
{10, 0xc1},
{15, 0xb6},
{20, 0xac},
{30, 0x9d},
{45, 0x82},
{70, 0x6c},
{100, 0x56},
{120, 0x47},
{140, 0x3a},
{160, 0x2f},
{180, 0x22},
{200, 0x16},
{220, 0xe},
{240, 0x6},
{260, 0x00},
};
int oppo_get_panel_brightness(void)
{
struct dsi_display *display = get_main_display();
if (!display) {
return 0;
}
return display->panel->bl_config.bl_level;
}
static int bl_to_alpha(int brightness)
{
struct dsi_display *display = get_main_display();
struct oppo_brightness_alpha *lut = NULL;
int count = 0;
int i = 0;
int alpha;
if (!display)
return 0;
if (display->panel->ba_seq && display->panel->ba_count) {
count = display->panel->ba_count;
lut = display->panel->ba_seq;
} else {
count = ARRAY_SIZE(brightness_alpha_lut);
lut = brightness_alpha_lut;
}
for (i = 0; i < count; i++) {
if (lut[i].brightness >= brightness)
break;
}
if (i == 0)
alpha = lut[0].alpha;
else if (i == count)
alpha = lut[count - 1].alpha;
else
alpha = interpolate(brightness, lut[i-1].brightness,
lut[i].brightness, lut[i-1].alpha,
lut[i].alpha);
return alpha;
}
static int bl_to_alpha_dc(int brightness)
{
int level = ARRAY_SIZE(brightness_alpha_lut_dc);
int i = 0;
int alpha;
for (i = 0; i < ARRAY_SIZE(brightness_alpha_lut_dc); i++) {
if (brightness_alpha_lut_dc[i].brightness >= brightness) {
break;
}
}
if (i == 0) {
alpha = brightness_alpha_lut_dc[0].alpha;
} else if (i == level) {
alpha = brightness_alpha_lut_dc[level - 1].alpha;
} else
alpha = interpolate(brightness,
brightness_alpha_lut_dc[i - 1].brightness,
brightness_alpha_lut_dc[i].brightness,
brightness_alpha_lut_dc[i - 1].alpha,
brightness_alpha_lut_dc[i].alpha);
return alpha;
}
static int brightness_to_alpha(int brightness)
{
int alpha;
if (brightness == 0 || brightness == 1) {
brightness = oppo_last_backlight;
}
if (oppo_dimlayer_hbm) {
alpha = bl_to_alpha(brightness);
} else {
alpha = bl_to_alpha_dc(brightness);
}
return alpha;
}
static int oppo_get_panel_brightness_to_alpha(void)
{
struct dsi_display *display = get_main_display();
if (!display) {
return 0;
}
if (oppo_panel_alpha) {
return oppo_panel_alpha;
}
if (hbm_mode) {
return 0;
}
if (!oppo_ffl_trigger_finish) {
return brightness_to_alpha(FFL_FP_LEVEL);
}
return brightness_to_alpha(display->panel->bl_config.bl_level);
}
/*Mark.Yao@PSW.MM.Display.LCD.Stable,2019-10-24 add for fingerprint */
int dsi_panel_parse_oppo_fod_config(struct dsi_panel *panel)
{
int rc = 0;
int i;
u32 length = 0;
u32 count = 0;
u32 size = 0;
u32 *arr_32 = NULL;
const u32 *arr;
struct dsi_parser_utils *utils = &panel->utils;
struct oppo_brightness_alpha *seq;
arr = utils->get_property(utils->data, "oppo,dsi-fod-brightness", &length);
if (!arr) {
DSI_ERR("[%s] oppo,dsi-fod-brightness not found\n", panel->name);
return -EINVAL;
}
if (length & 0x1) {
DSI_ERR("[%s] oppo,dsi-fod-brightness length error\n", panel->name);
return -EINVAL;
}
DSI_DEBUG("RESET SEQ LENGTH = %d\n", length);
length = length / sizeof(u32);
size = length * sizeof(u32);
arr_32 = kzalloc(size, GFP_KERNEL);
if (!arr_32) {
rc = -ENOMEM;
goto error;
}
rc = utils->read_u32_array(utils->data, "oppo,dsi-fod-brightness",
arr_32, length);
if (rc) {
DSI_ERR("[%s] cannot read dsi-fod-brightness\n", panel->name);
goto error_free_arr_32;
}
count = length / 2;
size = count * sizeof(*seq);
seq = kzalloc(size, GFP_KERNEL);
if (!seq) {
rc = -ENOMEM;
goto error_free_arr_32;
}
panel->ba_seq = seq;
panel->ba_count = count;
for (i = 0; i < length; i += 2) {
seq->brightness = arr_32[i];
seq->alpha = arr_32[i + 1];
seq++;
}
error_free_arr_32:
kfree(arr_32);
error:
return rc;
}
static int dsi_panel_parse_oppo_backlight_remapping_config(struct dsi_panel *panel)
{
int rc = 0;
int i;
u32 length = 0;
u32 count = 0;
u32 size = 0;
u32 *arr_32 = NULL;
const u32 *arr;
struct dsi_parser_utils *utils = &panel->utils;
struct oppo_brightness_alpha *bl_remap;
panel->oppo_priv.bl_interpolate_nosub = utils->read_bool(utils->data,
"oppo,bl_interpolate_nosub");
arr = utils->get_property(utils->data, "oppo,dsi-brightness-remapping", &length);
if (!arr) {
DSI_DEBUG("[%s] oppo,dsi-brightness-remapping not found\n", panel->name);
return -EINVAL;
}
if (length & 0x1) {
DSI_ERR("[%s] oppo,dsi-brightness-remapping length error\n", panel->name);
return -EINVAL;
}
DSI_INFO("oppo,dsi-brightness-remapping's length = %d, interpolate_nosub = %d\n", length, panel->oppo_priv.bl_interpolate_nosub ? 1 : 0);
length = length / sizeof(u32);
size = length * sizeof(u32);
arr_32 = kzalloc(size, GFP_KERNEL);
if (!arr_32) {
rc = -ENOMEM;
goto error;
}
rc = utils->read_u32_array(utils->data, "oppo,dsi-brightness-remapping",
arr_32, length);
if (rc) {
DSI_ERR("[%s] cannot read oppo,dsi-brightness-remapping\n", panel->name);
goto error_free_arr_32;
}
count = length / 2;
size = count * sizeof(*bl_remap);
bl_remap = kzalloc(size, GFP_KERNEL);
if (!bl_remap) {
rc = -ENOMEM;
goto error_free_arr_32;
}
panel->oppo_priv.bl_remap = bl_remap;
panel->oppo_priv.bl_remap_count = count;
for (i = 0; i < length; i += 2) {
bl_remap->brightness = arr_32[i];
bl_remap->alpha = arr_32[i + 1];
bl_remap++;
}
error_free_arr_32:
kfree(arr_32);
error:
return rc;
}
int dsi_panel_parse_oppo_config(struct dsi_panel *panel)
{
struct dsi_parser_utils *utils = &panel->utils;
dsi_panel_parse_oppo_fod_config(panel);
dsi_panel_parse_oppo_backlight_remapping_config(panel);
panel->oppo_priv.vendor_name = utils->get_property(utils->data,
"oppo,mdss-dsi-vendor-name", NULL);
if (!panel->oppo_priv.vendor_name) {
pr_err("Failed to found panel name, using dumming name\n");
panel->oppo_priv.vendor_name = DSI_PANEL_OPPO_DUMMY_VENDOR_NAME;
}
panel->oppo_priv.manufacture_name = utils->get_property(utils->data,
"oppo,mdss-dsi-manufacture", NULL);
if (!panel->oppo_priv.manufacture_name) {
pr_err("Failed to found panel name, using dumming name\n");
panel->oppo_priv.manufacture_name = DSI_PANEL_OPPO_DUMMY_MANUFACTURE_NAME;
}
panel->oppo_priv.is_pxlw_iris5 = utils->read_bool(utils->data,
"oppo,is_pxlw_iris5");
DSI_INFO("is_pxlw_iris5: %s",
panel->oppo_priv.is_pxlw_iris5 ? "true" : "false");
#ifdef OPLUS_FEATURE_AOD_RAMLESS
/* Yuwei.Zhang@MULTIMEDIA.DISPLAY.LCD, 2020/09/25, sepolicy for aod ramless */
panel->oppo_priv.is_aod_ramless = utils->read_bool(utils->data,
"oppo,aod_ramless");
DSI_INFO("aod ramless mode: %s", panel->oppo_priv.is_aod_ramless ? "true" : "false");
#endif /* OPLUS_FEATURE_AOD_RAMLESS */
#ifdef OPLUS_BUG_STABILITY
/* xupengcheng@MULTIMEDIA.DISPLAY.LCD, 2020/10/20,add for 19781 discard the first osc clock setting */
panel->oppo_priv.is_19781_lcd = utils->read_bool(utils->data,
"oplus,is_19781_lcd");
DSI_INFO("is_19781_lcd: %s",
panel->oppo_priv.is_19781_lcd ? "true" : "false");
/* Yuwei.Zhang@MULTIMEDIA.DISPLAY.LCD, 2021/01/05, fix flicker when mipi clock is switched at low brightness */
{
u32 val = 0;
int rc;
rc = utils->read_u32(utils->data, "oplus,dsi-pll-delay", &val);
panel->oppo_priv.pll_delay = !rc ? val : 0;
DSI_INFO("oplus_dsi_pll_delay = %d\n", panel->oppo_priv.pll_delay);
rc = utils->read_u32(utils->data, "oplus,prj-flag", &val);
panel->oppo_priv.prj_flag = !rc ? val : 0;
DSI_INFO("oplus_prj_flag = %d\n", panel->oppo_priv.prj_flag);
}
#endif /* OPLUS_BUG_STABILITY */
#ifdef OPLUS_FEATURE_LCD_CABC
/*xupengcheng@MULTIMEDIA.MM.Display.LCD.Stability,2020/09/18,add for 19696 LCD CABC feature*/
panel->oppo_priv.is_19696_lcd = utils->read_bool(utils->data,
"oplus,is_19696_lcd");
DSI_INFO("is_19696_lcd: %s",
panel->oppo_priv.is_19696_lcd ? "true" : "false");
#endif /* OPLUS_FEATURE_LCD_CABC */
return 0;
}
int dsi_panel_parse_oppo_mode_config(struct dsi_display_mode *mode,
struct dsi_parser_utils *utils)
{
int rc;
struct dsi_display_mode_priv_info *priv_info;
int val = 0;
priv_info = mode->priv_info;
rc = utils->read_u32(utils->data, "oppo,fod-th-brightness", &val);
if (rc) {
DSI_ERR("oppo,fod-th-brightness is not defined, rc=%d\n", rc);
priv_info->fod_th_brightness = 0;
} else {
priv_info->fod_th_brightness = val;
DSI_INFO("oppo,fod-th-brightness is %d", val);
}
rc = utils->read_u32(utils->data, "oppo,fod-on-vblank", &val);
if (rc) {
DSI_ERR("oppo,fod-on-vblank is not defined, rc=%d\n", rc);
priv_info->fod_on_vblank = 0;
} else {
priv_info->fod_on_vblank = val;
DSI_INFO("oppo,fod-on-vblank is %d", val);
}
rc = utils->read_u32(utils->data, "oppo,fod-off-vblank", &val);
if (rc) {
DSI_ERR("oppo,fod-off-vblank is not defined, rc=%d\n", rc);
priv_info->fod_off_vblank = 0;
} else {
priv_info->fod_off_vblank = val;
DSI_INFO("oppo,fod-off-vblank is %d", val);
}
rc = utils->read_u32(utils->data, "oppo,fod-on-delay", &val);
if (rc) {
DSI_ERR("oppo,fod-on-delay is not defined, rc=%d\n", rc);
priv_info->fod_on_delay = 0;
} else {
priv_info->fod_on_delay = val;
DSI_INFO("oppo,fod-on-delay is %d", val);
}
rc = utils->read_u32(utils->data, "oppo,fod-off-delay", &val);
if (rc) {
DSI_ERR("oppo,fod-off-delay is not defined, rc=%d\n", rc);
priv_info->fod_off_delay = 0;
} else {
priv_info->fod_off_delay = val;
DSI_INFO("oppo,fod-off-delay is %d", val);
}
rc = utils->read_u32(utils->data, "oppo,fod-on-vblank_above_th", &val);
if (rc) {
DSI_ERR("oppo,fod-on-vblank_above_th is not defined, rc=%d\n", rc);
priv_info->fod_on_vblank_above_th = 0;
} else {
priv_info->fod_on_vblank_above_th = val;
DSI_INFO("oppo,fod-on-vblank_above_th is %d", val);
}
rc = utils->read_u32(utils->data, "oppo,fod-off-vblank_above_th", &val);
if (rc) {
DSI_ERR("oppo,fod-off-vblank_above_th is not defined, rc=%d\n", rc);
priv_info->fod_off_vblank_above_th = 0;
} else {
priv_info->fod_off_vblank_above_th = val;
DSI_INFO("oppo,fod-off-vblank_above_th is %d", val);
}
rc = utils->read_u32(utils->data, "oppo,fod-on-delay_above_th", &val);
if (rc) {
DSI_ERR("oppo,fod-on-delay_above_th is not defined, rc=%d\n", rc);
priv_info->fod_on_delay_above_th = 0;
} else {
priv_info->fod_on_delay_above_th = val;
DSI_INFO("oppo,fod-on-delay_above_th is %d", val);
}
rc = utils->read_u32(utils->data, "oppo,fod-off-delay_above_th", &val);
if (rc) {
DSI_ERR("oppo,fod-off-delay_above_th is not defined, rc=%d\n", rc);
priv_info->fod_off_delay_above_th = 0;
} else {
priv_info->fod_off_delay_above_th = val;
DSI_INFO("oppo,fod-off-delay_above_th is %d", val);
}
return 0;
}
/* End of Mark.Yao@PSW.MM.Display.LCD.Stable,2019-10-24 add for fingerprint */
bool sde_crtc_get_dimlayer_mode(struct drm_crtc_state *crtc_state)
{
struct sde_crtc_state *cstate;
if (!crtc_state) {
return false;
}
cstate = to_sde_crtc_state(crtc_state);
return !!cstate->fingerprint_dim_layer;
}
bool sde_crtc_get_fingerprint_mode(struct drm_crtc_state *crtc_state)
{
struct sde_crtc_state *cstate;
if (!crtc_state) {
return false;
}
cstate = to_sde_crtc_state(crtc_state);
return !!cstate->fingerprint_mode;
}
bool sde_crtc_get_fingerprint_pressed(struct drm_crtc_state *crtc_state)
{
struct sde_crtc_state *cstate;
if (!crtc_state) {
return false;
}
cstate = to_sde_crtc_state(crtc_state);
return cstate->fingerprint_pressed;
}
bool sde_connector_get_fp_mode(struct drm_connector *connector)
{
if (!connector || !connector->state || !connector->state->crtc)
return false;
return sde_crtc_get_fingerprint_mode(connector->state->crtc->state);
}
bool sde_connector_get_fppress_mode(struct drm_connector *connector)
{
if (!connector || !connector->state || !connector->state->crtc)
return false;
return sde_crtc_get_fingerprint_pressed(connector->state->crtc->state);
}
int sde_crtc_set_onscreenfinger_defer_sync(struct drm_crtc_state *crtc_state,
bool defer_sync)
{
struct sde_crtc_state *cstate;
if (!crtc_state) {
return -EINVAL;
}
cstate = to_sde_crtc_state(crtc_state);
cstate->fingerprint_defer_sync = defer_sync;
return 0;
}
int sde_crtc_config_fingerprint_dim_layer(struct drm_crtc_state *crtc_state,
int stage)
{
struct sde_crtc_state *cstate;
struct drm_display_mode *mode = &crtc_state->adjusted_mode;
struct sde_hw_dim_layer *fingerprint_dim_layer;
int alpha = oppo_get_panel_brightness_to_alpha();
struct sde_kms *kms;
kms = _sde_crtc_get_kms_(crtc_state->crtc);
if (!kms || !kms->catalog) {
SDE_ERROR("invalid kms\n");
return -EINVAL;
}
cstate = to_sde_crtc_state(crtc_state);
if (cstate->num_dim_layers == SDE_MAX_DIM_LAYERS - 1) {
pr_err("failed to get available dim layer for custom\n");
return -EINVAL;
}
if ((stage + SDE_STAGE_0) >= kms->catalog->mixer[0].sblk->maxblendstages) {
return -EINVAL;
}
fingerprint_dim_layer = &cstate->dim_layer[cstate->num_dim_layers];
fingerprint_dim_layer->flags = SDE_DRM_DIM_LAYER_INCLUSIVE;
fingerprint_dim_layer->stage = stage + SDE_STAGE_0;
fingerprint_dim_layer->rect.x = 0;
fingerprint_dim_layer->rect.y = 0;
fingerprint_dim_layer->rect.w = mode->hdisplay;
fingerprint_dim_layer->rect.h = mode->vdisplay;
fingerprint_dim_layer->color_fill = (struct sde_mdss_color) {
0, 0, 0, alpha
};
cstate->fingerprint_dim_layer = fingerprint_dim_layer;
oppo_underbrightness_alpha = alpha;
return 0;
}
bool is_skip_pcc(struct drm_crtc *crtc)
{
if (OPPO_DISPLAY_POWER_DOZE_SUSPEND == get_oppo_display_power_status() ||
OPPO_DISPLAY_POWER_DOZE == get_oppo_display_power_status() ||
sde_crtc_get_fingerprint_mode(crtc->state)) {
return true;
}
return false;
}
bool sde_cp_crtc_update_pcc(struct drm_crtc *crtc)
{
struct sde_hw_cp_cfg hw_cfg;
struct sde_hw_dspp *hw_dspp;
struct sde_hw_mixer *hw_lm;
struct sde_crtc *sde_crtc = to_sde_crtc(crtc);
struct sde_mdss_cfg *catalog = NULL;
u32 num_mixers = sde_crtc->num_mixers;
bool pcc_skip_mode;
int i = 0;
if (!is_dsi_panel(&sde_crtc->base)) {
return false;
}
pcc_skip_mode = is_skip_pcc(crtc);
if (oppo_skip_pcc == pcc_skip_mode)
return false;
oppo_skip_pcc = pcc_skip_mode;
memset(&hw_cfg, 0, sizeof(hw_cfg));
if (!pcc_skip_mode && oppo_pcc_enabled) {
hw_cfg.payload = &oppo_save_pcc;
hw_cfg.len = sizeof(oppo_save_pcc);
}
hw_cfg.num_of_mixers = sde_crtc->num_mixers;
hw_cfg.last_feature = 0;
for (i = 0; i < num_mixers; i++) {
hw_dspp = sde_crtc->mixers[i].hw_dspp;
if (!hw_dspp || i >= DSPP_MAX)
continue;
hw_cfg.dspp[i] = hw_dspp;
}
catalog = get_kms_(&sde_crtc->base)->catalog;
hw_cfg.broadcast_disabled = catalog->dma_cfg.broadcast_disabled;
for (i = 0; i < num_mixers; i++) {
hw_lm = sde_crtc->mixers[i].hw_lm;
hw_dspp = sde_crtc->mixers[i].hw_dspp;
if (!hw_lm) {
continue;
}
if (!hw_dspp || !hw_dspp->ops.setup_pcc) {
continue;
}
hw_cfg.ctl = sde_crtc->mixers[i].hw_ctl;
hw_cfg.mixer_info = hw_lm;
hw_cfg.displayh = num_mixers * hw_lm->cfg.out_width;
hw_cfg.displayv = hw_lm->cfg.out_height;
hw_dspp->ops.setup_pcc(hw_dspp, &hw_cfg);
}
return true;
}
bool
_sde_encoder_setup_dither_for_onscreenfingerprint(
struct sde_encoder_phys *phys, void *dither_cfg, int len)
{
struct drm_encoder *drm_enc = phys->parent;
struct drm_msm_dither dither;
if (!drm_enc || !drm_enc->crtc)
return -EFAULT;
if (!sde_crtc_get_dimlayer_mode(drm_enc->crtc->state))
return -EINVAL;
if (len != sizeof(dither))
return -EINVAL;
if (oppo_get_panel_brightness_to_alpha() < oppo_dimlayer_dither_threshold)
return -EINVAL;
memcpy(&dither, dither_cfg, len);
/*Jian.Zhou@PSW.MM.Display.LCD.Stable,2020-01-16 add for fix green screen issue*/
dither.c0_bitdepth = 6;
dither.c1_bitdepth = 8;
dither.c2_bitdepth = 8;
dither.c3_bitdepth = 8;
dither.temporal_en = 1;
phys->hw_pp->ops.setup_dither(phys->hw_pp, &dither, len);
return 0;
}
int sde_plane_check_fingerprint_layer(const struct drm_plane_state *drm_state)
{
struct sde_plane_state *pstate;
if (!drm_state) {
return 0;
}
pstate = to_sde_plane_state(drm_state);
return sde_plane_get_property(pstate, PLANE_PROP_CUSTOM);
}

View File

@@ -0,0 +1,58 @@
/***************************************************************
** Copyright (C), 2020, OPPO Mobile Comm Corp., Ltd
** VENDOR_EDIT
** File : oppo_onscreenfingerprint.h
** Description : oppo onscreenfingerprint feature
** Version : 1.0
** Date : 2020/04/15
** Author : Qianxu@MM.Display.LCD Driver
**
** ------------------------------- Revision History: -----------
** <author> <data> <version > <desc>
** Qianxu 2020/04/15 1.0 Build this moudle
******************************************************************/
#ifndef _OPPO_ONSCREENFINGERPRINT_H_
#define _OPPO_ONSCREENFINGERPRINT_H_
#include <drm/drm_crtc.h>
#include "dsi_panel.h"
#include "dsi_defs.h"
#include "dsi_parser.h"
#include "sde_encoder_phys.h"
#define FFL_FP_LEVEL 150
int oppo_get_panel_brightness(void);
int dsi_panel_parse_oppo_fod_config(struct dsi_panel *panel);
int dsi_panel_parse_oppo_config(struct dsi_panel *panel);
int dsi_panel_parse_oppo_mode_config(struct dsi_display_mode *mode, struct dsi_parser_utils *utils);
bool sde_crtc_get_dimlayer_mode(struct drm_crtc_state *crtc_state);
bool sde_crtc_get_fingerprint_mode(struct drm_crtc_state *crtc_state);
bool sde_crtc_get_fingerprint_pressed(struct drm_crtc_state *crtc_state);
bool sde_connector_get_fppress_mode(struct drm_connector *connector);
bool sde_connector_get_fp_mode(struct drm_connector *connector);
int sde_crtc_set_onscreenfinger_defer_sync(struct drm_crtc_state *crtc_state, bool defer_sync);
int sde_crtc_config_fingerprint_dim_layer(struct drm_crtc_state *crtc_state, int stage);
bool is_skip_pcc(struct drm_crtc *crtc);
bool sde_cp_crtc_update_pcc(struct drm_crtc *crtc);
bool _sde_encoder_setup_dither_for_onscreenfingerprint(struct sde_encoder_phys *phys,
void *dither_cfg, int len);
int sde_plane_check_fingerprint_layer(const struct drm_plane_state *drm_state);
#endif /*_OPPO_ONSCREENFINGERPRINT_H_*/

View File

@@ -0,0 +1,91 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2018-2020 Oplus. All rights reserved.
*/
#include <linux/mm.h>
#include <linux/resmap_account.h>
#include "kgsl_reserved_area.h"
unsigned long kgsl_search_range(struct kgsl_process_private *private,
struct kgsl_mem_entry *entry,
unsigned long start, unsigned end,
unsigned long addr, unsigned long len, uint64_t align,
unsigned long hint, search_range_function_t search_range)
{
struct vm_area_struct *reserve_vma;
unsigned long res_start, res_end;
unsigned long result = -ENOMEM;
struct vm_area_struct *vma;
struct mm_struct *mm = current->mm;
result = search_range(private, entry, start, addr, len, align, 0);
if (!IS_ERR_VALUE(result))
return result;
if (hint != 0) {
result = search_range(private, entry, addr, end, len,
align, 0);
if (!IS_ERR_VALUE(result))
return result;
}
reserve_vma = mm->reserve_vma;
if (reserve_vma) {
count_resmap_event(RESMAP_ACTION);
res_start = reserve_vma->vm_start;
res_end = reserve_vma->vm_end;
if (len > (res_end - res_start)) {
count_resmap_event(RESMAP_FAIL);
return result;
}
result = search_range(private, entry, res_start, res_end, len, align,
VM_UNMAPPED_AREA_RESERVED);
if (IS_ERR_VALUE(result)) {
static DEFINE_RATELIMIT_STATE(try_reserve_fail_rs,
5*HZ, 8);
unsigned long chunk, chunk_start;
unsigned long used_size, vma_size, lastend;
count_resmap_event(RESMAP_FAIL);
if (__ratelimit(&try_reserve_fail_rs)) {
used_size = 0;
lastend = res_start;
chunk = 0;
chunk_start = 0;
for (vma = mm->reserve_mmap; vma;
vma = vma->vm_next) {
vma_size = vma->vm_end - vma->vm_start;
if ((vma->vm_start - lastend) > chunk) {
chunk = vma->vm_start - lastend;
chunk_start = lastend;
}
lastend = vma->vm_end;
used_size += vma_size;
}
if ((res_end - lastend) > chunk) {
chunk = res_end - lastend;
chunk_start = lastend;
}
pr_err("emergency! current:%s pid:%d leader:%s result:%lx reserve_vma:%p(%lu) alloc len:%luKB start:0x%lx end:0x%lx reserve_map_count:%d used_size:%luKB chunk:%luKB chunk_start:%#lx align:%#lx reserve_highest_vm_end:%#lx\n",
current->comm, current->pid,
current->group_leader->comm,
result, reserve_vma, res_end - res_start,
len>>10, res_start, res_end,
mm->reserve_map_count, used_size>>10,
chunk>>10, chunk_start, align,
mm->reserve_highest_vm_end);
}
} else
count_resmap_event(RESMAP_SUCCESS);
}
return result;
}

View File

@@ -0,0 +1,38 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (C) 2018-2020 Oplus. All rights reserved.
*/
#include "kgsl_device.h"
#include <linux/resmap_account.h>
typedef unsigned long search_range_function_t(struct kgsl_process_private *private,
struct kgsl_mem_entry *entry,
unsigned long start, unsigned long end,
unsigned long len, uint64_t align, unsigned long mmap_flags);
#define try_reserved_region(vma, addr, len, private, entry, result) do {\
if ((!vma && check_valid_reserve_addr(current->mm, addr, addr+len)) ||\
(vma && ((addr + len) <= vma->vm_start))) {\
result = _gpu_set_svm_region(private, entry, addr, len);\
if (!IS_ERR_VALUE(result))\
return result;\
}\
} while (0);
#define record_svm_oom_info(val) do {\
if (IS_ERR_VALUE(val)) {\
static DEFINE_RATELIMIT_STATE(svm_log_limit, 1*HZ, 1);\
if (__ratelimit(&svm_log_limit)) {\
svm_oom_pid = current->tgid;\
svm_oom_jiffies = jiffies;\
}\
}\
} while (0);
extern unsigned long kgsl_search_range(struct kgsl_process_private *private,
struct kgsl_mem_entry *entry,
unsigned long start, unsigned end,
unsigned long addr, unsigned long len, uint64_t align,
unsigned long hint, search_range_function_t search_range);

View File

@@ -0,0 +1,30 @@
#
# Kbuild for the vl53L1 drivers.
#
ccflags-y += -I$(src)/inc -I$(src)/ipp -I$(src)
ccflags-y += -Idrivers/media/platform/msm/camera_8150/cam_sensor_module/cam_cci
# define this environment variable if you want to compile driver for an old
# kernel
ifdef OLD_NETLINK_API
ccflags-y += -DOLD_NETLINK_API
endif
ifdef VL53L1_LOG_ENABLE
ccflags-y += -DVL53L1_LOG_ENABLE
endif
obj-$(CONFIG_STMVL53L1) += stmvl53l1.o
stmvl53l1-objs := stmvl53l1_module.o stmvl53l1_module-i2c.o stmvl53l1_module-cci.o
stmvl53l1-objs += stmvl53l1_i2c.o stmvl53l1_ipp_nl.o stmvl53l1_log.o
stmvl53l1-objs += src/vl53l1_api.o src/vl53l1_api_core.o
stmvl53l1-objs += src/vl53l1_api_strings.o src/vl53l1_error_strings.o
stmvl53l1-objs += src/vl53l1_core.o src/vl53l1_register_funcs.o
stmvl53l1-objs += src/vl53l1_api_preset_modes.o
stmvl53l1-objs += src/vl53l1_api_calibration.o
stmvl53l1-objs += src/vl53l1_silicon_core.o
stmvl53l1-objs += src/vl53l1_zone_presets.o src/vl53l1_nvm.o
stmvl53l1-objs += src/vl53l1_api_debug.o src/vl53l1_core_support.o
stmvl53l1-objs += src/vl53l1_wait.o ipp/ipp_linux.o
stmvl53l1-objs += src/vl53l1_nvm_debug.o

View File

@@ -0,0 +1,12 @@
ifneq ($(KERNELRELEASE),)
include Kbuild
else
KDIR ?= /lib/modules/`uname -r`/build
default:
CONFIG_STMVL53L1=m $(MAKE) -C $(KDIR) M=$$PWD
clean:
CONFIG_STMVL53L1=m $(MAKE) -C $(KDIR) M=$$PWD clean
endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,596 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#ifndef _VL53L1_API_CALIBRATION_H_
#define _VL53L1_API_CALIBRATION_H_
#include "vl53l1_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
VL53L1_Error VL53L1_run_ref_spad_char(VL53L1_DEV Dev,
VL53L1_Error * pcal_status);
VL53L1_Error VL53L1_run_device_test(
VL53L1_DEV Dev,
VL53L1_DeviceTestMode device_test_mode);
VL53L1_Error VL53L1_run_spad_rate_map(
VL53L1_DEV Dev,
VL53L1_DeviceTestMode device_test_mode,
VL53L1_DeviceSscArray array_select,
uint32_t ssc_config_timeout_us,
VL53L1_spad_rate_data_t *pspad_rate_data);
VL53L1_Error VL53L1_run_xtalk_extraction(
VL53L1_DEV Dev,
VL53L1_Error *pcal_status);
VL53L1_Error VL53L1_get_and_avg_xtalk_samples(
VL53L1_DEV Dev,
uint8_t num_of_samples,
uint8_t measurement_mode,
int16_t xtalk_filter_thresh_max_mm,
int16_t xtalk_filter_thresh_min_mm,
uint16_t xtalk_max_valid_rate_kcps,
uint8_t xtalk_result_id,
uint8_t xtalk_histo_id,
VL53L1_xtalk_range_results_t *pxtalk_results,
VL53L1_histogram_bin_data_t *psum_histo,
VL53L1_histogram_bin_data_t *pavg_histo);
VL53L1_Error VL53L1_run_offset_calibration(
VL53L1_DEV Dev,
int16_t cal_distance_mm,
uint16_t cal_reflectance_pc,
VL53L1_Error *pcal_status);
VL53L1_Error VL53L1_run_phasecal_average(
VL53L1_DEV Dev,
uint8_t measurement_mode,
uint8_t phasecal_result__vcsel_start,
uint16_t phasecal_num_of_samples,
VL53L1_range_results_t *prange_results,
uint16_t *pphasecal_result__reference_phase,
uint16_t *pzero_distance_phase);
VL53L1_Error VL53L1_run_zone_calibration(
VL53L1_DEV Dev,
VL53L1_DevicePresetModes device_preset_mode,
VL53L1_DeviceZonePreset zone_preset,
VL53L1_zone_config_t *pzone_cfg,
int16_t cal_distance_mm,
uint16_t cal_reflectance_pc,
VL53L1_Error *pcal_status);
void VL53L1_hist_xtalk_extract_data_init(
VL53L1_hist_xtalk_extract_data_t *pxtalk_data);
VL53L1_Error VL53L1_hist_xtalk_extract_update(
int16_t target_distance_mm,
uint16_t target_width_oversize,
VL53L1_histogram_bin_data_t *phist_bins,
VL53L1_hist_xtalk_extract_data_t *pxtalk_data);
VL53L1_Error VL53L1_hist_xtalk_extract_fini(
VL53L1_histogram_bin_data_t *phist_bins,
VL53L1_hist_xtalk_extract_data_t *pxtalk_data,
VL53L1_xtalk_calibration_results_t *pxtalk_cal,
VL53L1_xtalk_histogram_shape_t *pxtalk_shape);
VL53L1_Error VL53L1_run_hist_xtalk_extraction(
VL53L1_DEV Dev,
int16_t cal_distance_mm,
VL53L1_Error *pcal_status);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,756 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#ifndef _VL53L1_API_DEBUG_H_
#define _VL53L1_API_DEBUG_H_
#include "vl53l1_platform.h"
#include "vl53l1_nvm_structs.h"
#ifdef __cplusplus
extern "C" {
#endif
VL53L1_Error VL53L1_decode_calibration_data_buffer(
uint16_t buf_size,
uint8_t *pbuffer,
VL53L1_calibration_data_t *pdata);
VL53L1_Error VL53L1_get_nvm_debug_data(
VL53L1_DEV Dev,
VL53L1_decoded_nvm_data_t *pdata);
VL53L1_Error VL53L1_get_histogram_debug_data(
VL53L1_DEV Dev,
VL53L1_histogram_bin_data_t *pdata);
VL53L1_Error VL53L1_get_additional_data(
VL53L1_DEV Dev,
VL53L1_additional_data_t *pdata);
VL53L1_Error VL53L1_get_xtalk_debug_data(
VL53L1_DEV Dev,
VL53L1_xtalk_debug_data_t *pdata);
VL53L1_Error VL53L1_get_offset_debug_data(
VL53L1_DEV Dev,
VL53L1_offset_debug_data_t *pdata);
#ifdef VL53L1_LOG_ENABLE
void VL53L1_signed_fixed_point_sprintf(
int32_t fp_value,
uint8_t frac_bits,
uint16_t buf_size,
char *pbuffer);
void VL53L1_print_static_nvm_managed(
VL53L1_static_nvm_managed_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_customer_nvm_managed(
VL53L1_customer_nvm_managed_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_nvm_copy_data(
VL53L1_nvm_copy_data_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_histogram_bin_data(
VL53L1_histogram_bin_data_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_xtalk_histogram_data(
VL53L1_xtalk_histogram_data_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_xtalk_histogram_shape_data(
VL53L1_xtalk_histogram_shape_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_range_results(
VL53L1_range_results_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_range_data(
VL53L1_range_data_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_offset_range_results(
VL53L1_offset_range_results_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_offset_range_data(
VL53L1_offset_range_data_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_cal_peak_rate_map(
VL53L1_cal_peak_rate_map_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_additional_offset_cal_data(
VL53L1_additional_offset_cal_data_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_additional_data(
VL53L1_additional_data_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_gain_calibration_data(
VL53L1_gain_calibration_data_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_zone_calibration_data(
VL53L1_zone_calibration_data_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_zone_calibration_results(
VL53L1_zone_calibration_results_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_xtalk_range_results(
VL53L1_xtalk_range_results_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_xtalk_range_data(
VL53L1_xtalk_range_data_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_xtalk_calibration_results(
VL53L1_xtalk_calibration_results_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_xtalk_config(
VL53L1_xtalk_config_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_xtalk_extract_config(
VL53L1_xtalkextract_config_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_zone_cal_config(
VL53L1_zonecal_config_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_offset_cal_config(
VL53L1_offsetcal_config_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_dmax_calibration_data(
VL53L1_dmax_calibration_data_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_calibration_data(
VL53L1_calibration_data_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_xtalk_debug_data(
VL53L1_xtalk_debug_data_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_offset_debug_data(
VL53L1_offset_debug_data_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_optical_centre(
VL53L1_optical_centre_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_user_zone(
VL53L1_user_zone_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_zone_config(
VL53L1_zone_config_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_spad_rate_data(
VL53L1_spad_rate_data_t *pspad_rates,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_spad_rate_map(
VL53L1_spad_rate_data_t *pspad_rates,
char *pprefix,
uint32_t trace_flags);
#endif
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,210 @@
/******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
******************************************************************************
'STMicroelectronics Proprietary license'
*******************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
*******************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones mentioned above :
*******************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
/**
* @file vl53l1_api_strings.h
* @brief VL53L1 API function declarations for decoding error codes to a
* text strings
*/
#ifndef VL53L1_API_STRINGS_H_
#define VL53L1_API_STRINGS_H_
#include "vl53l1_def.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Generates a string for the input device range status code
*
* @param[in] RangeStatus : Device Range AStatus Code
* @param[out] pRangeStatusString : pointer to character buffer
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/
VL53L1_Error VL53L1_get_range_status_string(
uint8_t RangeStatus,
char *pRangeStatusString);
/**
* @brief Generates an error string for the input PAL error code
*
* @param[in] PalErrorCode : PAL Error Code
* @param[out] pPalErrorString : pointer to character buffer
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/
VL53L1_Error VL53L1_get_pal_error_string(
VL53L1_Error PalErrorCode,
char *pPalErrorString);
/**
* @brief Generates a string for the input PAL State code
*
* @param[in] PalStateCode : PAL State Code
* @param[out] pPalStateString : pointer to character buffer
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/
VL53L1_Error VL53L1_get_pal_state_string(
VL53L1_State PalStateCode,
char *pPalStateString);
/**
* @brief Generates a string for the sequence step Id
*
* @param[in] SequenceStepId : Sequence Step Id
* @param[out] pSequenceStepsString : pointer to character buffer
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/
VL53L1_Error VL53L1_get_sequence_steps_info(
VL53L1_SequenceStepId SequenceStepId,
char *pSequenceStepsString);
/**
* @brief Generates a string for the limit check Id
*
* @param[in] LimitCheckId : Limit check Id
* @param[out] pLimitCheckString : pointer to character buffer
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/
VL53L1_Error VL53L1_get_limit_check_info(uint16_t LimitCheckId,
char *pLimitCheckString);
#ifndef VL53L1_USE_EMPTY_STRING
#define VL53L1_STRING_DEVICE_INFO_NAME0 "VL53L1 cut1.0"
#define VL53L1_STRING_DEVICE_INFO_NAME1 "VL53L1 cut1.1"
#define VL53L1_STRING_DEVICE_INFO_TYPE "VL53L1"
/* Range Status */
#define VL53L1_STRING_RANGESTATUS_NONE "No Update"
#define VL53L1_STRING_RANGESTATUS_RANGEVALID "Range Valid"
#define VL53L1_STRING_RANGESTATUS_SIGMA "Sigma Fail"
#define VL53L1_STRING_RANGESTATUS_SIGNAL "Signal Fail"
#define VL53L1_STRING_RANGESTATUS_MINRANGE "Min Range Fail"
#define VL53L1_STRING_RANGESTATUS_PHASE "Phase Fail"
#define VL53L1_STRING_RANGESTATUS_HW "Hardware Fail"
/* Range Status */
#define VL53L1_STRING_STATE_POWERDOWN "POWERDOWN State"
#define VL53L1_STRING_STATE_WAIT_STATICINIT \
"Wait for staticinit State"
#define VL53L1_STRING_STATE_STANDBY "STANDBY State"
#define VL53L1_STRING_STATE_IDLE "IDLE State"
#define VL53L1_STRING_STATE_RUNNING "RUNNING State"
#define VL53L1_STRING_STATE_RESET "RESET State"
#define VL53L1_STRING_STATE_UNKNOWN "UNKNOWN State"
#define VL53L1_STRING_STATE_ERROR "ERROR State"
/* Check Enable */
#define VL53L1_STRING_CHECKENABLE_SIGMA_FINAL_RANGE \
"SIGMA FINAL RANGE"
#define VL53L1_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE \
"SIGNAL RATE FINAL RANGE"
#define VL53L1_STRING_CHECKENABLE_SIGNAL_MIN_CLIP \
"SIGNAL MIN CLIP"
#define VL53L1_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD \
"RANGE IGNORE THRESHOLD"
#define VL53L1_STRING_CHECKENABLE_RANGE_PHASE_HIGH \
"RANGE PHASE HIGH"
#define VL53L1_STRING_CHECKENABLE_RANGE_PHASE_LOW \
"RANGE PHASE LOW"
#define VL53L1_STRING_CHECKENABLE_RANGE_PHASE_CONSISTENCY \
"RANGE PHASE CONSISTENCY"
/* Sequence Step */
#define VL53L1_STRING_SEQUENCESTEP_VHV "VHV"
#define VL53L1_STRING_SEQUENCESTEP_PHASECAL "PHASE CAL"
#define VL53L1_STRING_SEQUENCESTEP_REFPHASE "REF PHASE"
#define VL53L1_STRING_SEQUENCESTEP_DSS1 "DSS1"
#define VL53L1_STRING_SEQUENCESTEP_DSS2 "DSS2"
#define VL53L1_STRING_SEQUENCESTEP_MM1 "MM1"
#define VL53L1_STRING_SEQUENCESTEP_MM2 "MM2"
#define VL53L1_STRING_SEQUENCESTEP_RANGE "RANGE"
#endif /* VL53L1_USE_EMPTY_STRING */
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,414 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#ifndef _VL53L1_CORE_SUPPORT_H_
#define _VL53L1_CORE_SUPPORT_H_
#include "vl53l1_types.h"
#include "vl53l1_hist_structs.h"
#ifdef __cplusplus
extern "C" {
#endif
uint32_t VL53L1_calc_pll_period_us(
uint16_t fast_osc_frequency);
uint32_t VL53L1_duration_maths(
uint32_t pll_period_us,
uint32_t vcsel_parm_pclks,
uint32_t window_vclks,
uint32_t periods_elapsed_mclks);
uint32_t VL53L1_events_per_spad_maths(
int32_t VL53L1_p_013,
uint16_t num_spads,
uint32_t duration);
uint32_t VL53L1_isqrt(
uint32_t num);
void VL53L1_hist_calc_zero_distance_phase(
VL53L1_histogram_bin_data_t *pdata);
void VL53L1_hist_estimate_ambient_from_thresholded_bins(
int32_t ambient_threshold_sigma,
VL53L1_histogram_bin_data_t *pdata);
void VL53L1_hist_remove_ambient_bins(
VL53L1_histogram_bin_data_t *pdata);
uint32_t VL53L1_calc_pll_period_mm(
uint16_t fast_osc_frequency);
uint16_t VL53L1_rate_maths(
int32_t VL53L1_p_008,
uint32_t time_us);
uint16_t VL53L1_rate_per_spad_maths(
uint32_t frac_bits,
uint32_t peak_count_rate,
uint16_t num_spads,
uint32_t max_output_value);
int32_t VL53L1_range_maths(
uint16_t fast_osc_frequency,
uint16_t VL53L1_p_017,
uint16_t zero_distance_phase,
uint8_t fractional_bits,
int32_t gain_factor,
int32_t range_offset_mm);
uint8_t VL53L1_decode_vcsel_period(
uint8_t vcsel_period_reg);
void VL53L1_copy_xtalk_bin_data_to_histogram_data_struct(
VL53L1_xtalk_histogram_shape_t *pxtalk,
VL53L1_histogram_bin_data_t *phist);
void VL53L1_init_histogram_bin_data_struct(
int32_t bin_value,
uint16_t VL53L1_p_024,
VL53L1_histogram_bin_data_t *pdata);
void VL53L1_decode_row_col(
uint8_t spad_number,
uint8_t *prow,
uint8_t *pcol);
void VL53L1_hist_find_min_max_bin_values(
VL53L1_histogram_bin_data_t *pdata);
void VL53L1_hist_estimate_ambient_from_ambient_bins(
VL53L1_histogram_bin_data_t *pdata);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,848 @@
/******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
******************************************************************************
'STMicroelectronics Proprietary license'
*******************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
*******************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones mentioned above :
*******************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
/**
* @file vl53l1_def.h
*
* @brief Type definitions for VL53L1 API.
*
*/
#ifndef _VL53L1_DEF_H_
#define _VL53L1_DEF_H_
#include "vl53l1_ll_def.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @defgroup VL53L1_globaldefine_group VL53L1 Defines
* @brief VL53L1 Defines
* @{
*/
/** VL53L1 IMPLEMENTATION major version */
#define VL53L1_IMPLEMENTATION_VER_MAJOR 6
/** VL53L1 IMPLEMENTATION minor version */
#define VL53L1_IMPLEMENTATION_VER_MINOR 0
/** VL53L1 IMPLEMENTATION sub version */
#define VL53L1_IMPLEMENTATION_VER_SUB 1
/** VL53L1 IMPLEMENTATION sub version */
#define VL53L1_IMPLEMENTATION_VER_REVISION 2003
/****************************************
* PRIVATE define do not edit
****************************************/
/** @brief Defines the parameters of the Get Version Functions
*/
typedef struct {
uint32_t revision; /*!< revision number */
uint8_t major; /*!< major number */
uint8_t minor; /*!< minor number */
uint8_t build; /*!< build number */
} VL53L1_Version_t;
#define VL53L1_DEVINFO_STRLEN 32
/** @brief Defines the parameters of the Get Device Info Functions
*/
typedef struct {
char Name[VL53L1_DEVINFO_STRLEN];
/*!< Name of the Device e.g. Left_Distance */
char Type[VL53L1_DEVINFO_STRLEN];
/*!< Type of the Device e.g VL53L1 */
char ProductId[VL53L1_DEVINFO_STRLEN];
/*!< Product Identifier String
* @warning Not yet implemented
*/
uint8_t ProductType;
/*!< Product Type, VL53L1 = 1, VL53L1 = 2*/
uint8_t ProductRevisionMajor;
/*!< Product revision major */
uint8_t ProductRevisionMinor;
/*!< Product revision minor */
} VL53L1_DeviceInfo_t;
/** @defgroup VL53L1_define_PresetModes_group Defines Preset modes
* Defines all possible preset modes for the device
* @{
*/
typedef uint8_t VL53L1_PresetModes;
#define VL53L1_PRESETMODE_RANGING ((VL53L1_PresetModes) 1)
#define VL53L1_PRESETMODE_MULTIZONES_SCANNING ((VL53L1_PresetModes) 2)
#define VL53L1_PRESETMODE_AUTONOMOUS ((VL53L1_PresetModes) 3)
#define VL53L1_PRESETMODE_LITE_RANGING ((VL53L1_PresetModes) 4)
#define VL53L1_PRESETMODE_OLT ((VL53L1_PresetModes) 7)
#define VL53L1_PRESETMODE_LOWPOWER_AUTONOMOUS ((VL53L1_PresetModes) 8)
#define VL53L1_PRESETMODE_PROXY_RANGING_MODE ((VL53L1_PresetModes) 9)
/** default preset ranging mode */
//songyt test replace VL53L1_PRESETMODE_RANGING
#define STMVL53L1_CFG_DEFAULT_MODE VL53L1_PRESETMODE_RANGING
/* ... Modes to be added depending on device */
/** @} VL53L1_define_PresetModes_group */
/** @defgroup VL53L1_define_DistanceModes_group Defines Distance modes
* Defines all possible Distance modes for the device
* @{
*/
typedef uint8_t VL53L1_DistanceModes;
#define VL53L1_DISTANCEMODE_SHORT ((VL53L1_DistanceModes) 1)
#define VL53L1_DISTANCEMODE_MEDIUM ((VL53L1_DistanceModes) 2)
#define VL53L1_DISTANCEMODE_LONG ((VL53L1_DistanceModes) 3)
/** @} VL53L1_define_DistanceModes_group */
/** @defgroup VL53L1_define_OutputModes_group Defines Output modes
* Defines all possible Output modes for the device
* @{
*/
typedef uint8_t VL53L1_OutputModes;
#define VL53L1_OUTPUTMODE_NEAREST ((VL53L1_OutputModes) 1)
#define VL53L1_OUTPUTMODE_STRONGEST ((VL53L1_OutputModes) 2)
/** @} VL53L1_define_OutputModes_group */
/** @defgroup VL53L1_define_XtalkCal_group Defines Xtalk Calibration modes
* Defines all possible Offset Calibration modes for the device
* @{
*/
typedef uint8_t VL53L1_XtalkCalibrationModes;
#define VL53L1_XTALKCALIBRATIONMODE_NO_TARGET \
((VL53L1_OffsetCalibrationModes) 0)
/*!< To perform Xtalk calibration with no target below 80 cm */
#define VL53L1_XTALKCALIBRATIONMODE_SINGLE_TARGET \
((VL53L1_OffsetCalibrationModes) 1)
/*!< To perform Xtalk calibration with one target */
#define VL53L1_XTALKCALIBRATIONMODE_FULL_ROI \
((VL53L1_OffsetCalibrationModes) 2)
/*!< To perform Xtalk calibration based on histogram with full ROI */
/** @} VL53L1_define_XtalkCal_group */
/** @defgroup VL53L1_define_OffsetCal_group Defines Offset Calibration modes
* Defines all possible Offset Calibration modes for the device
* @{
*/
typedef uint8_t VL53L1_OffsetCalibrationModes;
#define VL53L1_OFFSETCALIBRATIONMODE_STANDARD \
((VL53L1_OffsetCalibrationModes) 1)
#define VL53L1_OFFSETCALIBRATIONMODE_PRERANGE_ONLY \
((VL53L1_OffsetCalibrationModes) 2)
#define VL53L1_OFFSETCALIBRATIONMODE_MULTI_ZONE \
((VL53L1_OffsetCalibrationModes) 3)
/** @} VL53L1_define_OffsetCal_group */
/** @defgroup VL53L1_define_DeviceDmaxModes_group Defines Dmax source modes
* Defines all possible sources for Dmax calibration for the device
* @{
*/
typedef uint8_t VL53L1_DeviceDmaxModes;
#define VL53L1_DMAXMODE_FMT_CAL_DATA ((VL53L1_DeviceDmaxModes) 1)
#define VL53L1_DMAXMODE_CUSTCAL_DATA ((VL53L1_DeviceDmaxModes) 2)
#define VL53L1_DMAXMODE_PER_ZONE_CAL_DATA ((VL53L1_DeviceDmaxModes) 3)
/** @} VL53L1_define_DeviceDmaxModes_group */
/** @defgroup VL53L1_define_OffsetCorrectionModesBD_group
* Device Offset Correction Mode
*
* @brief Defines all possible offset correction modes for the device
* @{
*/
typedef uint8_t VL53L1_OffsetCorrectionModes;
#define VL53L1_OFFSETCORRECTIONMODE_STANDARD ((VL53L1_OffsetCorrectionMode) 1)
#define VL53L1_OFFSETCORRECTIONMODE_PERZONE ((VL53L1_OffsetCorrectionMode) 2)
/** @} VL53L1_define_OffsetCorrectionModesBD_group */
/** @defgroup VL53L1_define_RoiStatus_group Defines Roi Status
* Defines the read status mode
* @{
*/
typedef uint8_t VL53L1_RoiStatus;
#define VL53L1_ROISTATUS_NOT_VALID ((VL53L1_RoiStatus) 0)
#define VL53L1_ROISTATUS_VALID_NOT_LAST ((VL53L1_RoiStatus) 1)
#define VL53L1_ROISTATUS_VALID_LAST ((VL53L1_RoiStatus) 2)
/** @} VL53L1_define_RoiStatus_group */
/** @defgroup VL53L1_CheckEnable_group Check Enable list
* @brief Check Enable code
*
* Define used to specify the LimitCheckId.
* Use @a VL53L1_GetLimitCheckInfo() to get the string.
* @{
*/
#define VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE 0
#define VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE 1
#define VL53L1_CHECKENABLE_NUMBER_OF_CHECKS 2
/** @} end of VL53L1_CheckEnable_group */
/** @defgroup VL53L1_ThresholdMode_gropup Detection Functionality
* @brief Defines the different functionalities for the detection feature
* @{
*/
typedef uint8_t VL53L1_ThresholdMode;
#define VL53L1_THRESHOLD_CROSSED_LOW \
((VL53L1_ThresholdMode) 0)
/*!< Trigger interrupt if value < thresh_low */
#define VL53L1_THRESHOLD_CROSSED_HIGH \
((VL53L1_ThresholdMode) 1)
/*!< Trigger interrupt if value > thresh_high */
#define VL53L1_THRESHOLD_OUT_OF_WINDOW \
((VL53L1_ThresholdMode) 2)
/*!< Trigger interrupt if value < thresh_low OR value > thresh_high */
#define VL53L1_THRESHOLD_IN_WINDOW \
((VL53L1_ThresholdMode) 3)
/*!< Trigger interrupt if value > thresh_low AND value < thresh_high */
/** @} end of VL53L1_ThresholdMode_gropup */
/** @brief Defines parameters for Distance detection Thresholds configuration
*/
typedef struct {
VL53L1_ThresholdMode CrossMode;
uint16_t High; /*!< Distance threshold high limit in mm */
uint16_t Low; /*!< Distance threshold low limit in mm */
} VL53L1_DistanceThreshold_t;
/** @brief Defines parameters for Signal rate detection Thresholds configuration
*/
typedef struct {
VL53L1_ThresholdMode CrossMode;
FixPoint1616_t High; /*!< Signal rate threshold high limit */
FixPoint1616_t Low; /*!< Signal rate threshold low limit */
} VL53L1_RateThreshold_t;
/** @defgroup VL53L1_DetectionMode_group Gpio Functionality
* @brief Defines conditions leading to device's IT on GPIO
* @{
*/
typedef uint8_t VL53L1_DetectionMode;
#define VL53L1_DETECTION_NORMAL_RUN \
((VL53L1_DetectionMode) 0)
/*!< Trigger interrupt on new measurement regardless of threshold
* just like after a VL53L1_SetPresetMode() call
*/
#define VL53L1_DETECTION_DISTANCE_ONLY \
((VL53L1_DetectionMode) 1)
/*!< Trigger interrupt if "threshold event" occurs on distance */
#define VL53L1_DETECTION_RATE_ONLY \
((VL53L1_DetectionMode) 2)
/*!< Trigger interrupt if "threshold event" occurs on signal rate */
#define VL53L1_DETECTION_DISTANCE_AND_RATE \
((VL53L1_DetectionMode) 3)
/*!< Trigger interrupt if "threshold event" occurs on distance AND rate
*/
#define VL53L1_DETECTION_DISTANCE_OR_RATE \
((VL53L1_DetectionMode) 4)
/*!< Trigger interrupt if "threshold event" occurs on distance OR rate
*/
/** @} end of VL53L1_DetectionMode_group */
/** @brief Defines parameters for User/object Detection configuration
*/
typedef struct {
VL53L1_DetectionMode DetectionMode; /*!< See #VL53L1_DetectionMode*/
uint8_t IntrNoTarget; /*!< 1 to trigger IT in case of no target found */
VL53L1_DistanceThreshold_t Distance; /*!< limits in mm */
VL53L1_RateThreshold_t Rate;/*!< limits in FixPoint1616_t */
} VL53L1_DetectionConfig_t;
/** @brief Defines all parameters for the device
*/
typedef struct {
VL53L1_PresetModes PresetMode;
/*!< Defines the operating mode to be used for the next measure */
VL53L1_OutputModes OutputMode;
/*!< Defines the Output mode to be used for the next measure */
VL53L1_DistanceModes DistanceMode;
/*!< Defines the operating mode to be used for the next measure */
uint32_t MeasurementTimingBudgetMicroSeconds;
/*!< Defines the allowed total time for a single measurement */
uint8_t LimitChecksEnable[VL53L1_CHECKENABLE_NUMBER_OF_CHECKS];
/*!< This Array store all the Limit Check enable for this device. */
uint8_t LimitChecksStatus[VL53L1_CHECKENABLE_NUMBER_OF_CHECKS];
/*!< This Array stores all the Status of the check linked to last
* measurement.
*/
FixPoint1616_t LimitChecksValue[VL53L1_CHECKENABLE_NUMBER_OF_CHECKS];
/*!< This Array stores all the Limit Check value for this device */
FixPoint1616_t LimitChecksCurrent[VL53L1_CHECKENABLE_NUMBER_OF_CHECKS];
/*!< This Array stores all the Limit Check current value from latest
* ranging
*/
} VL53L1_DeviceParameters_t;
/** @defgroup VL53L1_define_State_group Defines the current status of the device
* Defines the current status of the device
* @{
*/
typedef uint8_t VL53L1_State;
#define VL53L1_STATE_POWERDOWN ((VL53L1_State) 0)
/*!< Device is in HW reset */
#define VL53L1_STATE_WAIT_STATICINIT ((VL53L1_State) 1)
/*!< Device is initialized and wait for static initialization */
#define VL53L1_STATE_STANDBY ((VL53L1_State) 2)
/*!< Device is in Low power Standby mode */
#define VL53L1_STATE_IDLE ((VL53L1_State) 3)
/*!< Device has been initialized and ready to do measurements */
#define VL53L1_STATE_RUNNING ((VL53L1_State) 4)
/*!< Device is performing measurement */
#define VL53L1_STATE_RESET ((VL53L1_State) 5)
/*!< Soft reset has been run on Device */
#define VL53L1_STATE_UNKNOWN ((VL53L1_State) 98)
/*!< Device is in unknown state and need to be rebooted */
#define VL53L1_STATE_ERROR ((VL53L1_State) 99)
/*!< Device is in error state and need to be rebooted */
/** @} VL53L1_define_State_group */
/** @defgroup VL53L1_define_Smudge_Mode_group Defines smudge correction modes
* Defines the smudge correction modes
* @{
*/
typedef uint8_t VL53L1_SmudgeCorrectionModes;
#define VL53L1_SMUDGE_CORRECTION_NONE ((VL53L1_SmudgeCorrectionModes) 0)
/*!< Smudge correction is applied continously accross the rangings */
#define VL53L1_SMUDGE_CORRECTION_CONTINUOUS ((VL53L1_SmudgeCorrectionModes) 1)
/*!< Smudge correction is applied continously accross the rangings */
#define VL53L1_SMUDGE_CORRECTION_SINGLE ((VL53L1_SmudgeCorrectionModes) 2)
/*!< Smudge correction is applied only once accross the rangings */
#define VL53L1_SMUDGE_CORRECTION_DEBUG ((VL53L1_SmudgeCorrectionModes) 3)
/*!< Smudge detection is applied continously but Xtalk values are not
* updated automatically within the driver
*/
/** @} VL53L1_define_Smudge_Correction_Mode_group */
/**
* @struct VL53L1_RangingMeasurementData_t
* @brief Single Range measurement data.
*/
typedef struct {
uint32_t TimeStamp;
/*!< 32-bit time stamp.
* @warning Not yet implemented
*/
uint8_t StreamCount;
/*!< 8-bit Stream Count. */
uint8_t RangeQualityLevel;
/*!< indicate a quality level in percentage from 0 to 100
* @warning Not yet implemented
*/
FixPoint1616_t SignalRateRtnMegaCps;
/*!< Return signal rate (MCPS)\n these is a 16.16 fix point
* value, which is effectively a measure of target
* reflectance.
*/
FixPoint1616_t AmbientRateRtnMegaCps;
/*!< Return ambient rate (MCPS)\n these is a 16.16 fix point
* value, which is effectively a measure of the ambien
* t light.
*/
uint16_t EffectiveSpadRtnCount;
/*!< Return the effective SPAD count for the return signal.
* To obtain Real value it should be divided by 256
*/
FixPoint1616_t SigmaMilliMeter;
/*!< Return the Sigma value in millimeter */
int16_t RangeMilliMeter;
/*!< range distance in millimeter. This should be between
* RangeMinMilliMeter and RangeMaxMilliMeter
*/
uint8_t RangeFractionalPart;
/*!< Fractional part of range distance. Final value is a
* RangeMilliMeter + RangeFractionalPart/256.
* @warning Not yet implemented
*/
uint8_t RangeStatus;
/*!< Range Status for the current measurement. This is device
* dependent. Value = 0 means value is valid.
*/
} VL53L1_RangingMeasurementData_t;
/**
* @struct VL53L1_TargetRangeData_t
* @brief One Range measurement data for each target.
*/
typedef struct {
uint8_t RangeQualityLevel;
/*!< indicate a quality level in percentage from 0 to 100
* @warning Not yet implemented
*/
int16_t RangeMaxMilliMeter;
/*!< Tells what is the maximum detection distance of the object
* in current setup and environment conditions (Filled when
* applicable)
*/
int16_t RangeMinMilliMeter;
/*!< Tells what is the minimum detection distance of the object
* in current setup and environment conditions (Filled when
* applicable)
*/
FixPoint1616_t SignalRateRtnMegaCps;
/*!< Return signal rate (MCPS)\n these is a 16.16 fix point
* value, which is effectively a measure of target
* reflectance.
*/
FixPoint1616_t AmbientRateRtnMegaCps;
/*!< Return ambient rate (MCPS)\n these is a 16.16 fix point
* value, which is effectively a measure of the ambien
* t light.
*/
FixPoint1616_t SigmaMilliMeter;
/*!< Return the Sigma value in millimeter */
int16_t RangeMilliMeter;
/*!< range distance in millimeter. This should be between
* RangeMinMilliMeter and RangeMaxMilliMeter
*/
uint8_t RangeFractionalPart;
/*!< Fractional part of range distance. Final value is a
* RangeMilliMeter + RangeFractionalPart/256.
* @warning Not yet implemented
*/
uint8_t RangeStatus;
/*!< Range Status for the current measurement. This is device
* dependent. Value = 0 means value is valid.
*/
} VL53L1_TargetRangeData_t;
/**
* @struct VL53L1_MultiRangingData_t
* @brief Structure for storing the set of range results for a single ROI
*
*/
typedef struct {
uint32_t TimeStamp;
/*!< 32-bit time stamp.
* @warning Not yet implemented
*/
uint8_t StreamCount;
/*!< 8-bit Stream Count. */
uint8_t RoiNumber;
/*!< Denotes on which ROI the range data is related to. */
uint8_t NumberOfObjectsFound;
/*!< Indicate the number of objects found in the current ROI.
* This is used to know how many ranging data should be get.
* NumberOfObjectsFound is in the range 0 to
* VL53L1_MAX_RANGE_RESULTS.
*/
VL53L1_RoiStatus RoiStatus;
/*!< Indicate if the data read is valid or not or if this is
* the last valid data in the ROI.
*/
VL53L1_TargetRangeData_t RangeData[VL53L1_MAX_RANGE_RESULTS];
/*!< Range data each target distance */
uint8_t HasXtalkValueChanged;
/*!< set to 1 if a new Xtalk value has been computed whilst
* smudge correction mode enable by with
* VL53L1_SmudgeCorrectionEnable() function is either
* VL53L1_SMUDGE_CORRECTION_CONTINUOUS or
* VL53L1_SMUDGE_CORRECTION_SINGLE.
*/
uint16_t EffectiveSpadRtnCount;
/*!< Return the effective SPAD count for the return signal.
* To obtain Real value it should be divided by 256
*/
int16_t DmaxMilliMeter;
/*!< range Dmax distance in millimeter.
*/
VL53L1_DistanceModes RecommendedDistanceMode;
/*!< suggestion for a better distance mode choice to improve
* range accuracy.
*/
} VL53L1_MultiRangingData_t;
/** @brief Defines User Zone(ROI) parameters
*
*/
typedef struct {
uint8_t TopLeftX; /*!< Top Left x coordinate: 0-15 range */
uint8_t TopLeftY; /*!< Top Left y coordinate: 0-15 range */
uint8_t BotRightX; /*!< Bot Right x coordinate: 0-15 range */
uint8_t BotRightY; /*!< Bot Right y coordinate: 0-15 range */
} VL53L1_UserRoi_t;
/** @brief Defines ROI configuration parameters
*
* Support up a max of 16 zones, Each Zone has the same size
*
*/
typedef struct {
uint8_t NumberOfRoi; /*!< Number of Rois defined*/
VL53L1_UserRoi_t UserRois[VL53L1_MAX_USER_ZONES];
/*!< List of Rois */
} VL53L1_RoiConfig_t;
/**
* @struct VL53L1_CustomerNvmManaged_t
*
*/
typedef struct {
uint8_t global_config__spad_enables_ref_0;
uint8_t global_config__spad_enables_ref_1;
uint8_t global_config__spad_enables_ref_2;
uint8_t global_config__spad_enables_ref_3;
uint8_t global_config__spad_enables_ref_4;
uint8_t global_config__spad_enables_ref_5;
uint8_t global_config__ref_en_start_select;
uint8_t ref_spad_man__num_requested_ref_spads;
uint8_t ref_spad_man__ref_location;
uint32_t algo__crosstalk_compensation_plane_offset_kcps;
int16_t algo__crosstalk_compensation_x_plane_gradient_kcps;
int16_t algo__crosstalk_compensation_y_plane_gradient_kcps;
uint16_t ref_spad_char__total_rate_target_mcps;
int16_t algo__part_to_part_range_offset_mm;
int16_t mm_config__inner_offset_mm;
int16_t mm_config__outer_offset_mm;
} VL53L1_CustomerNvmManaged_t;
/**
* @struct VL53L1_CalibrationData_t
* @brief Structure for storing the Calibration Data
*
*/
typedef struct {
uint32_t struct_version;
VL53L1_CustomerNvmManaged_t customer;
VL53L1_dmax_calibration_data_t fmt_dmax_cal;
VL53L1_dmax_calibration_data_t cust_dmax_cal;
VL53L1_additional_offset_cal_data_t add_off_cal_data;
VL53L1_optical_centre_t optical_centre;
VL53L1_xtalk_histogram_data_t xtalkhisto;
VL53L1_gain_calibration_data_t gain_cal;
VL53L1_cal_peak_rate_map_t cal_peak_rate_map;
} VL53L1_CalibrationData_t;
#define VL53L1_ADDITIONAL_CALIBRATION_DATA_STRUCT_VERSION 0x10
/** VL53L1 additional Calibration Data struct version final struct version
* is given by adding it to VL53L1_LL_CALIBRATION_DATA_STRUCT_VERSION
*/
#define VL53L1_CALIBRATION_DATA_STRUCT_VERSION \
(VL53L1_LL_CALIBRATION_DATA_STRUCT_VERSION + \
VL53L1_ADDITIONAL_CALIBRATION_DATA_STRUCT_VERSION)
/* VL53L1 Calibration Data struct version */
/**
* @struct VL53L1_AdditionalData_t
* @brief Structure for storing the Additional Data
*
*/
typedef VL53L1_additional_data_t VL53L1_AdditionalData_t;
/**
* @struct VL53L1_ZoneCalibrationData_t
* @brief Structure for storing the Zone Calibration Data
*
*/
typedef VL53L1_zone_calibration_results_t VL53L1_ZoneCalibrationData_t;
/** @defgroup VL53L1_define_SequenceStepId_group Defines the SequenceStep
* Defines the the sequence steps performed during ranging..
* @{
*/
typedef uint8_t VL53L1_SequenceStepId;
#define VL53L1_SEQUENCESTEP_VHV ((VL53L1_SequenceStepId) 0)
/*!<VHV. */
#define VL53L1_SEQUENCESTEP_PHASECAL ((VL53L1_SequenceStepId) 1)
/*!<Phase Calibration. */
#define VL53L1_SEQUENCESTEP_REFPHASE ((VL53L1_SequenceStepId) 2)
/*!<Reference Phase. */
#define VL53L1_SEQUENCESTEP_DSS1 ((VL53L1_SequenceStepId) 3)
/*!<DSS1. */
#define VL53L1_SEQUENCESTEP_DSS2 ((VL53L1_SequenceStepId) 4)
/*!<DSS2. */
#define VL53L1_SEQUENCESTEP_MM1 ((VL53L1_SequenceStepId) 5)
/*!<Mode Mitigation 1. */
#define VL53L1_SEQUENCESTEP_MM2 ((VL53L1_SequenceStepId) 6)
/*!<Mode Mitigation 2. */
#define VL53L1_SEQUENCESTEP_RANGE ((VL53L1_SequenceStepId) 7)
/*!<Final Range step. */
#define VL53L1_SEQUENCESTEP_NUMBER_OF_ITEMS 8
/*!<Number of Sequence Step Managed by the API. */
/** @} VL53L1_define_SequenceStepId_group */
/** @defgroup VL53L1_define_RangeStatus_group Defines the Range Status
* @{
*/
#define VL53L1_RANGESTATUS_RANGE_VALID 0
/*!<The Range is valid. */
#define VL53L1_RANGESTATUS_SIGMA_FAIL 1
/*!<Sigma Fail. */
#define VL53L1_RANGESTATUS_SIGNAL_FAIL 2
/*!<Signal fail. */
#define VL53L1_RANGESTATUS_RANGE_VALID_MIN_RANGE_CLIPPED 3
/*!<Target is below minimum detection threshold. */
#define VL53L1_RANGESTATUS_OUTOFBOUNDS_FAIL 4
/*!<Phase out of valid limits - different to a wrap exit. */
#define VL53L1_RANGESTATUS_HARDWARE_FAIL 5
/*!<Hardware fail. */
#define VL53L1_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK_FAIL 6
/*!<The Range is valid but the wraparound check has not been done. */
#define VL53L1_RANGESTATUS_WRAP_TARGET_FAIL 7
/*!<Wrapped target - no matching phase in other VCSEL period timing. */
#define VL53L1_RANGESTATUS_PROCESSING_FAIL 8
/*!<Internal algo underflow or overflow in lite ranging. */
#define VL53L1_RANGESTATUS_XTALK_SIGNAL_FAIL 9
/*!<Specific to lite ranging. */
#define VL53L1_RANGESTATUS_SYNCRONISATION_INT 10
/*!<1st interrupt when starting ranging in back to back mode. Ignore data. */
#define VL53L1_RANGESTATUS_RANGE_VALID_MERGED_PULSE 11
/*!<All Range ok but object is result of multiple pulses merging together.
* Used by RQL for merged pulse detection
*/
#define VL53L1_RANGESTATUS_TARGET_PRESENT_LACK_OF_SIGNAL 12
/*!<Used by RQL as different to phase fail. */
#define VL53L1_RANGESTATUS_MIN_RANGE_FAIL 13
/*!<User ROI input is not valid e.g. beyond SPAD Array.*/
#define VL53L1_RANGESTATUS_RANGE_INVALID 14
/*!<lld returned valid range but negative value ! */
#define VL53L1_RANGESTATUS_NONE 255
/*!<No Update. */
/** @} VL53L1_define_RangeStatus_group */
/** @brief Contains the Internal data of the Bare Driver
*/
typedef struct {
VL53L1_LLDriverData_t LLData;
/*!< Low Level Driver data structure */
VL53L1_LLDriverResults_t llresults;
/*!< Low Level Driver data structure */
VL53L1_State PalState; /* Store the pal state */
VL53L1_DeviceParameters_t CurrentParameters;
/*!< Current Device Parameter */
} VL53L1_DevData_t;
/* MACRO Definitions */
/** @defgroup VL53L1_define_GeneralMacro_group General Macro Defines
* General Macro Defines
* @{
*/
/* Defines */
#define VL53L1_SETPARAMETERFIELD(Dev, field, value) \
(VL53L1DevDataSet(Dev, CurrentParameters.field, value))
#define VL53L1_GETPARAMETERFIELD(Dev, field, variable) \
(variable = VL53L1DevDataGet(Dev, CurrentParameters).field)
#define VL53L1_SETARRAYPARAMETERFIELD(Dev, field, index, value) \
(VL53L1DevDataSet(Dev, CurrentParameters.field[index], value))
#define VL53L1_GETARRAYPARAMETERFIELD(Dev, field, index, variable) \
(variable = VL53L1DevDataGet(Dev, CurrentParameters).field[index])
#define VL53L1_SETDEVICESPECIFICPARAMETER(Dev, field, value) \
(VL53L1DevDataSet(Dev, DeviceSpecificParameters.field, value))
#define VL53L1_GETDEVICESPECIFICPARAMETER(Dev, field) \
(VL53L1DevDataGet(Dev, DeviceSpecificParameters).field)
#define VL53L1_FIXPOINT1616TOFIXPOINT44(Value) \
(uint16_t)((Value>>12)&0xFFFF)
#define VL53L1_FIXPOINT44TOFIXPOINT1616(Value) \
(FixPoint1616_t)((uint32_t)Value<<12)
#define VL53L1_FIXPOINT1616TOFIXPOINT72(Value) \
(uint16_t)((Value>>14)&0xFFFF)
#define VL53L1_FIXPOINT72TOFIXPOINT1616(Value) \
(FixPoint1616_t)((uint32_t)Value<<14)
#define VL53L1_FIXPOINT1616TOFIXPOINT97(Value) \
(uint16_t)((Value>>9)&0xFFFF)
#define VL53L1_FIXPOINT97TOFIXPOINT1616(Value) \
(FixPoint1616_t)((uint32_t)Value<<9)
#define VL53L1_FIXPOINT1616TOFIXPOINT88(Value) \
(uint16_t)((Value>>8)&0xFFFF)
#define VL53L1_FIXPOINT88TOFIXPOINT1616(Value) \
(FixPoint1616_t)((uint32_t)Value<<8)
#define VL53L1_FIXPOINT1616TOFIXPOINT412(Value) \
(uint16_t)((Value>>4)&0xFFFF)
#define VL53L1_FIXPOINT412TOFIXPOINT1616(Value) \
(FixPoint1616_t)((uint32_t)Value<<4)
#define VL53L1_FIXPOINT1616TOFIXPOINT313(Value) \
(uint16_t)((Value>>3)&0xFFFF)
#define VL53L1_FIXPOINT313TOFIXPOINT1616(Value) \
(FixPoint1616_t)((uint32_t)Value<<3)
#define VL53L1_FIXPOINT1616TOFIXPOINT08(Value) \
(uint8_t)((Value>>8)&0x00FF)
#define VL53L1_FIXPOINT08TOFIXPOINT1616(Value) \
(FixPoint1616_t)((uint32_t)Value<<8)
#define VL53L1_FIXPOINT1616TOFIXPOINT53(Value) \
(uint8_t)((Value>>13)&0x00FF)
#define VL53L1_FIXPOINT53TOFIXPOINT1616(Value) \
(FixPoint1616_t)((uint32_t)Value<<13)
#define VL53L1_FIXPOINT1616TOFIXPOINT102(Value) \
(uint16_t)((Value>>14)&0x0FFF)
#define VL53L1_FIXPOINT102TOFIXPOINT1616(Value) \
(FixPoint1616_t)((uint32_t)Value<<14)
#define VL53L1_FIXPOINT1616TOFIXPOINT142(Value) \
(uint16_t)((Value>>14)&0xFFFF)
#define VL53L1_FIXPOINT142TOFIXPOINT1616(Value) \
(FixPoint1616_t)((uint32_t)Value<<14)
#define VL53L1_FIXPOINT1616TOFIXPOINT160(Value) \
(uint16_t)((Value>>16)&0xFFFF)
#define VL53L1_FIXPOINT160TOFIXPOINT1616(Value) \
(FixPoint1616_t)((uint32_t)Value<<16)
#define VL53L1_MAKEUINT16(lsb, msb) (uint16_t)((((uint16_t)msb)<<8) + \
(uint16_t)lsb)
#ifndef SUPPRESS_UNUSED_WARNING
#define SUPPRESS_UNUSED_WARNING(x) ((void) (x))
#endif
/** @} VL53L1_define_GeneralMacro_group */
/** @} VL53L1_globaldefine_group */
#ifdef __cplusplus
}
#endif
#endif /* _VL53L1_DEF_H_ */

View File

@@ -0,0 +1,210 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#ifndef _VL53L1_DMAX_STRUCTS_H_
#define _VL53L1_DMAX_STRUCTS_H_
#include "vl53l1_types.h"
#ifdef __cplusplus
extern "C"
{
#endif
#define VL53L1_MAX_AMBIENT_DMAX_VALUES 5
typedef struct {
uint16_t ref__actual_effective_spads;
uint16_t ref__peak_signal_count_rate_mcps;
uint16_t ref__distance_mm;
uint16_t ref_reflectance_pc;
uint16_t coverglass_transmission;
} VL53L1_dmax_calibration_data_t;
typedef struct {
uint8_t signal_thresh_sigma;
uint8_t ambient_thresh_sigma;
int32_t min_ambient_thresh_events;
int32_t signal_total_events_limit;
uint16_t target_reflectance_for_dmax_calc[
VL53L1_MAX_AMBIENT_DMAX_VALUES];
uint16_t max_effective_spads;
uint16_t dss_config__target_total_rate_mcps;
uint8_t dss_config__aperture_attenuation;
} VL53L1_hist_gen3_dmax_config_t;
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,273 @@
/******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
******************************************************************************
'STMicroelectronics Proprietary license'
*******************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
*******************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones mentioned above :
*******************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
/**
* @file vl53l1_error_codes.h
*
* @brief Error Code definitions for VL53L1 API.
*
*/
#ifndef _VL53L1_ERROR_CODES_H_
#define _VL53L1_ERROR_CODES_H_
#include "vl53l1_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
****************************************
* PRIVATE define do not edit
***************************************
*/
/*
* @defgroup VL53L1_define_Error_group Error and Warning code returned by API
* The following DEFINE are used to identify the PAL ERROR
* @{
*/
typedef int8_t VL53L1_Error;
#define VL53L1_ERROR_NONE ((VL53L1_Error) 0)
#define VL53L1_ERROR_CALIBRATION_WARNING ((VL53L1_Error) - 1)
/*!< Warning invalid calibration data may be in used
* \a VL53L1_InitData()
* \a VL53L1_GetOffsetCalibrationData
* \a VL53L1_SetOffsetCalibrationData
*/
#define VL53L1_ERROR_MIN_CLIPPED ((VL53L1_Error) - 2)
/*!< Warning parameter passed was clipped to min before to be applied */
#define VL53L1_ERROR_UNDEFINED ((VL53L1_Error) - 3)
/*!< Unqualified error */
#define VL53L1_ERROR_INVALID_PARAMS ((VL53L1_Error) - 4)
/*!< Parameter passed is invalid or out of range */
#define VL53L1_ERROR_NOT_SUPPORTED ((VL53L1_Error) - 5)
/*!< Function is not supported in current mode or configuration */
#define VL53L1_ERROR_RANGE_ERROR ((VL53L1_Error) - 6)
/*!< Device report a ranging error interrupt status */
#define VL53L1_ERROR_TIME_OUT ((VL53L1_Error) - 7)
/*!< Aborted due to time out */
#define VL53L1_ERROR_MODE_NOT_SUPPORTED ((VL53L1_Error) - 8)
/*!< Asked mode is not supported by the device */
#define VL53L1_ERROR_BUFFER_TOO_SMALL ((VL53L1_Error) - 9)
/*!< ... */
#define VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL ((VL53L1_Error) - 10)
/*!< Supplied buffer is larger than I2C supports */
#define VL53L1_ERROR_GPIO_NOT_EXISTING ((VL53L1_Error) - 11)
/*!< User tried to setup a non-existing GPIO pin */
#define VL53L1_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED ((VL53L1_Error) - 12)
/*!< unsupported GPIO functionality */
#define VL53L1_ERROR_CONTROL_INTERFACE ((VL53L1_Error) - 13)
/*!< error reported from IO functions */
#define VL53L1_ERROR_INVALID_COMMAND ((VL53L1_Error) - 14)
/*!< The command is not allowed in the current device state
* (power down)
*/
#define VL53L1_ERROR_DIVISION_BY_ZERO ((VL53L1_Error) - 15)
/*!< In the function a division by zero occurs */
#define VL53L1_ERROR_REF_SPAD_INIT ((VL53L1_Error) - 16)
/*!< Error during reference SPAD initialization */
#define VL53L1_ERROR_GPH_SYNC_CHECK_FAIL ((VL53L1_Error) - 17)
/*!< GPH sync interrupt check fail - API out of sync with device*/
#define VL53L1_ERROR_STREAM_COUNT_CHECK_FAIL ((VL53L1_Error) - 18)
/*!< Stream count check fail - API out of sync with device */
#define VL53L1_ERROR_GPH_ID_CHECK_FAIL ((VL53L1_Error) - 19)
/*!< GPH ID check fail - API out of sync with device */
#define VL53L1_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL ((VL53L1_Error) - 20)
/*!< Zone dynamic config stream count check failed - API out of sync */
#define VL53L1_ERROR_ZONE_GPH_ID_CHECK_FAIL ((VL53L1_Error) - 21)
/*!< Zone dynamic config GPH ID check failed - API out of sync */
#define VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL ((VL53L1_Error) - 22)
/*!< Thrown when run_xtalk_extraction fn has 0 succesful samples
* when using the full array to sample the xtalk. In this case there is
* not enough information to generate new Xtalk parm info. The function
* will exit and leave the current xtalk parameters unaltered
*/
#define VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL ((VL53L1_Error) - 23)
/*!< Thrown when run_xtalk_extraction fn has found that the
* avg sigma estimate of the full array xtalk sample is > than the
* maximal limit allowed. In this case the xtalk sample is too noisy for
* measurement. The function will exit and leave the current xtalk
* parameters unaltered.
*/
#define VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL ((VL53L1_Error) - 24)
/*!< Thrown if there one of stages has no valid offset calibration
* samples. A fatal error calibration not valid
*/
#define VL53L1_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL ((VL53L1_Error) - 25)
/*!< Thrown if there one of stages has zero effective SPADS
* Traps the case when MM1 SPADs is zero.
* A fatal error calibration not valid
*/
#define VL53L1_ERROR_ZONE_CAL_NO_SAMPLE_FAIL ((VL53L1_Error) - 26)
/*!< Thrown if then some of the zones have no valid samples
* A fatal error calibration not valid
*/
#define VL53L1_ERROR_TUNING_PARM_KEY_MISMATCH ((VL53L1_Error) - 27)
/*!< Thrown if the tuning file key table version does not match with
* expected value. The driver expects the key table version to match
* the compiled default version number in the define
* #VL53L1_TUNINGPARM_KEY_TABLE_VERSION_DEFAULT
*/
#define VL53L1_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS ((VL53L1_Error) - 28)
/*!< Thrown if there are less than 5 good SPADs are available. */
#define VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH ((VL53L1_Error) - 29)
/*!< Thrown if the final reference rate is greater than
* the upper reference rate limit - default is 40 Mcps.
* Implies a minimum Q3 (x10) SPAD (5) selected
*/
#define VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW ((VL53L1_Error) - 30)
/*!< Thrown if the final reference rate is less than
* the lower reference rate limit - default is 10 Mcps.
* Implies maximum Q1 (x1) SPADs selected
*/
#define VL53L1_WARNING_OFFSET_CAL_MISSING_SAMPLES ((VL53L1_Error) - 31)
/*!< Thrown if there is less than the requested number of
* valid samples.
*/
#define VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH ((VL53L1_Error) - 32)
/*!< Thrown if the offset calibration range sigma estimate is greater
* than 8.0 mm. This is the recommended min value to yield a stable
* offset measurement
*/
#define VL53L1_WARNING_OFFSET_CAL_RATE_TOO_HIGH ((VL53L1_Error) - 33)
/*!< Thrown when VL53L1_run_offset_calibration() peak rate is greater
* than that 50.0Mcps. This is the recommended max rate to avoid
* pile-up influencing the offset measurement
*/
#define VL53L1_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW ((VL53L1_Error) - 34)
/*!< Thrown when VL53L1_run_offset_calibration() when one of stages
* range has less that 5.0 effective SPADS. This is the recommended
* min value to yield a stable offset
*/
#define VL53L1_WARNING_ZONE_CAL_MISSING_SAMPLES ((VL53L1_Error) - 35)
/*!< Thrown if one of more of the zones have less than
* the requested number of valid samples
*/
#define VL53L1_WARNING_ZONE_CAL_SIGMA_TOO_HIGH ((VL53L1_Error) - 36)
/*!< Thrown if one or more zones have sigma estimate value greater
* than 8.0 mm. This is the recommended min value to yield a stable
* offset measurement
*/
#define VL53L1_WARNING_ZONE_CAL_RATE_TOO_HIGH ((VL53L1_Error) - 37)
/*!< Thrown if one of more zones have peak rate higher than
* that 50.0Mcps. This is the recommended max rate to avoid
* pile-up influencing the offset measurement
*/
#define VL53L1_WARNING_XTALK_MISSING_SAMPLES ((VL53L1_Error) - 38)
/*!< Thrown to notify that some of the xtalk samples did not yield
* valid ranging pulse data while attempting to measure
* the xtalk signal in vl53l1_run_xtalk_extract(). This can signify any
* of the zones are missing samples, for further debug information the
* xtalk_results struct should be referred to. This warning is for
* notification only, xtalk pulse and shape have still been generated
*/
#define VL53L1_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT ((VL53L1_Error) - 39)
/*!< Thrown to notify that some of teh xtalk samples used for gradient
* generation did not yield valid ranging pulse data while attempting to
* measure the xtalk signal in vl53l1_run_xtalk_extract(). This can
* signify that any one of the zones 0-3 yielded no successful samples.
* xtalk_results struct should be referred to for further debug info.
* This warning is for notification only, the xtalk pulse and shape
* have still been generated.
*/
#define VL53L1_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT ((VL53L1_Error) - 40)
/*!< Thrown to notify that some of the xtalk samples used for gradient
* generation did not pass the sigma limit check while attempting to
* measure the xtalk signal in vl53l1_run_xtalk_extract(). This can
* signify that any one of the zones 0-3 yielded an avg sigma_mm
* value > the limit. The xtalk_results struct should be referred to for
* further debug info.
* This warning is for notification only, the xtalk pulse and shape
* have still been generated.
*/
#define VL53L1_ERROR_NOT_IMPLEMENTED ((VL53L1_Error) - 41)
/*!< Tells requested functionality has not been implemented yet or
* not compatible with the device
*/
#define VL53L1_ERROR_PLATFORM_SPECIFIC_START ((VL53L1_Error) - 60)
/*!< Tells the starting code for platform */
/** @} VL53L1_define_Error_group */
#ifdef __cplusplus
}
#endif
#endif /* _VL53L1_ERROR_CODES_H_ */

View File

@@ -0,0 +1,126 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#ifndef _VL53L1_ERROR_EXCEPTIONS_H_
#define _VL53L1_ERROR_EXCEPTIONS_H_
#define IGNORE_DIVISION_BY_ZERO 0
#define IGNORE_XTALK_EXTRACTION_NO_SAMPLE_FAIL 0
#define IGNORE_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL 0
#define IGNORE_XTALK_EXTRACTION_NO_SAMPLE_FOR_GRADIENT_WARN 0
#define IGNORE_XTALK_EXTRACTION_SIGMA_LIMIT_FOR_GRADIENT_WARN 0
#define IGNORE_XTALK_EXTRACTION_MISSING_SAMPLES_WARN 0
#define IGNORE_REF_SPAD_CHAR_NOT_ENOUGH_SPADS 0
#define IGNORE_REF_SPAD_CHAR_RATE_TOO_HIGH 0
#define IGNORE_REF_SPAD_CHAR_RATE_TOO_LOW 0
#define IGNORE_OFFSET_CAL_MISSING_SAMPLES 0
#define IGNORE_OFFSET_CAL_SIGMA_TOO_HIGH 0
#define IGNORE_OFFSET_CAL_RATE_TOO_HIGH 0
#define IGNORE_OFFSET_CAL_SPAD_COUNT_TOO_LOW 0
#define IGNORE_ZONE_CAL_MISSING_SAMPLES 0
#define IGNORE_ZONE_CAL_SIGMA_TOO_HIGH 0
#define IGNORE_ZONE_CAL_RATE_TOO_HIGH 0
#endif

View File

@@ -0,0 +1,244 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#ifndef VL53L1_ERROR_STRINGS_H_
#define VL53L1_ERROR_STRINGS_H_
#include "vl53l1_error_codes.h"
#ifdef __cplusplus
extern "C" {
#endif
VL53L1_Error VL53L1_get_pal_error_string(
VL53L1_Error PalErrorCode,
char *pPalErrorString);
#ifndef VL53L1_USE_EMPTY_STRING
#define VL53L1_STRING_ERROR_NONE \
"No Error"
#define VL53L1_STRING_ERROR_CALIBRATION_WARNING \
"Calibration Warning Error"
#define VL53L1_STRING_ERROR_MIN_CLIPPED \
"Min clipped error"
#define VL53L1_STRING_ERROR_UNDEFINED \
"Undefined error"
#define VL53L1_STRING_ERROR_INVALID_PARAMS \
"Invalid parameters error"
#define VL53L1_STRING_ERROR_NOT_SUPPORTED \
"Not supported error"
#define VL53L1_STRING_ERROR_RANGE_ERROR \
"Range error"
#define VL53L1_STRING_ERROR_TIME_OUT \
"Time out error"
#define VL53L1_STRING_ERROR_MODE_NOT_SUPPORTED \
"Mode not supported error"
#define VL53L1_STRING_ERROR_BUFFER_TOO_SMALL \
"Buffer too small"
#define VL53L1_STRING_ERROR_COMMS_BUFFER_TOO_SMALL \
"Comms Buffer too small"
#define VL53L1_STRING_ERROR_GPIO_NOT_EXISTING \
"GPIO not existing"
#define VL53L1_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED \
"GPIO funct not supported"
#define VL53L1_STRING_ERROR_CONTROL_INTERFACE \
"Control Interface Error"
#define VL53L1_STRING_ERROR_INVALID_COMMAND \
"Invalid Command Error"
#define VL53L1_STRING_ERROR_DIVISION_BY_ZERO \
"Division by zero Error"
#define VL53L1_STRING_ERROR_REF_SPAD_INIT \
"Reference Spad Init Error"
#define VL53L1_STRING_ERROR_GPH_SYNC_CHECK_FAIL \
"GPH Sync Check Fail - API out of sync"
#define VL53L1_STRING_ERROR_STREAM_COUNT_CHECK_FAIL \
"Stream Count Check Fail - API out of sync"
#define VL53L1_STRING_ERROR_GPH_ID_CHECK_FAIL \
"GPH ID Check Fail - API out of sync"
#define VL53L1_STRING_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL \
"Zone Stream Count Check Fail - API out of sync"
#define VL53L1_STRING_ERROR_ZONE_GPH_ID_CHECK_FAIL \
"Zone GPH ID Check Fail - API out of sync"
#define VL53L1_STRING_ERROR_XTALK_EXTRACTION_NO_SAMPLES_FAIL \
"No Xtalk using full array - Xtalk Extract Fail"
#define VL53L1_STRING_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL \
"Xtalk does not meet required VL53L1_p_011 limit - Xtalk Extract Fail"
#define VL53L1_STRING_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL \
"Offset Cal - one of more stages with no valid samples - fatal"
#define VL53L1_STRING_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL \
"Offset Cal - one of more stages with no SPADS enables - fatal"
#define VL53L1_STRING_ERROR_ZONE_CAL_NO_SAMPLE_FAIL \
"Zone Cal - one of more zones with no valid samples - fatal"
#define VL53L1_STRING_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS \
"Ref SPAD Char - Not Enough Good SPADs"
#define VL53L1_STRING_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH \
"Ref SPAD Char - Final Ref Rate too high"
#define VL53L1_STRING_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW \
"Ref SPAD Char - Final Ref Rate too low"
#define VL53L1_STRING_WARNING_OFFSET_CAL_MISSING_SAMPLES \
"Offset Cal - Less than the requested number of valid samples"
#define VL53L1_STRING_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH \
"Offset Cal - Sigma estimate value too high - offset not stable"
#define VL53L1_STRING_WARNING_OFFSET_CAL_RATE_TOO_HIGH \
"Offset Cal - Rate too high - in pile up"
#define VL53L1_STRING_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW \
"Offset Cal - Insufficient SPADs - offset may not be stable"
#define VL53L1_STRING_WARNING_ZONE_CAL_MISSING_SAMPLES \
"Zone Cal - One or more zone with less than requested valid samples"
#define VL53L1_STRING_WARNING_ZONE_CAL_SIGMA_TOO_HIGH \
"Zone Cal - One of more zones the VL53L1_p_011 estimate too high"
#define VL53L1_STRING_WARNING_ZONE_CAL_RATE_TOO_HIGH \
"Zone Cal - One of more zones with rate too high - in pile up"
#define VL53L1_STRING_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT \
"Xtalk - Gradient sample num = 0"
#define VL53L1_STRING_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT \
"Xtalk - Gradient Sigma > Limit"
#define VL53L1_STRING_WARNING_XTALK_MISSING_SAMPLES \
"Xtalk - Some missing and invalid samples"
#define VL53L1_STRING_ERROR_DEVICE_FIRMWARE_TOO_OLD \
"Device Firmware too old"
#define VL53L1_STRING_ERROR_DEVICE_FIRMWARE_TOO_NEW \
"Device Firmware too new"
#define VL53L1_STRING_ERROR_UNIT_TEST_FAIL \
"Unit Test Fail"
#define VL53L1_STRING_ERROR_FILE_READ_FAIL \
"File Read Fail"
#define VL53L1_STRING_ERROR_FILE_WRITE_FAIL \
"File Write Fail"
#define VL53L1_STRING_ERROR_NOT_IMPLEMENTED \
"Not implemented error"
#define VL53L1_STRING_UNKNOW_ERROR_CODE \
"Unknown Error Code"
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,176 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#ifndef _VL53L1_HIST_CHAR_H_
#define _VL53L1_HIST_CHAR_H_
#include "vl53l1_platform.h"
#ifdef __cplusplus
extern "C"
{
#endif
VL53L1_Error VL53L1_set_calib_config(
VL53L1_DEV Dev,
uint8_t vcsel_delay__a0,
uint8_t calib_1,
uint8_t calib_2,
uint8_t calib_3,
uint8_t calib_2__a0,
uint8_t spad_readout);
VL53L1_Error VL53L1_set_hist_calib_pulse_delay(
VL53L1_DEV Dev,
uint8_t calib_delay);
VL53L1_Error VL53L1_disable_calib_pulse_delay(
VL53L1_DEV Dev);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,156 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#ifndef _VL53L1_HIST_MAP_H_
#define _VL53L1_HIST_MAP_H_
#include "vl53l1_register_map.h"
#ifdef __cplusplus
extern "C"
{
#endif
#define VL53L1_HISTOGRAM_CONFIG__OPCODE_SEQUENCE_0 \
VL53L1_SIGMA_ESTIMATOR__EFFECTIVE_PULSE_WIDTH_NS
#define VL53L1_HISTOGRAM_CONFIG__OPCODE_SEQUENCE_1 \
VL53L1_SIGMA_ESTIMATOR__EFFECTIVE_AMBIENT_WIDTH_NS
#define VL53L1_HISTOGRAM_CONFIG__OPCODE_SEQUENCE_2 \
VL53L1_SIGMA_ESTIMATOR__SIGMA_REF_MM
#define VL53L1_HISTOGRAM_CONFIG__AMB_THRESH_HIGH \
VL53L1_ALGO__RANGE_IGNORE_THRESHOLD_MCPS
#define VL53L1_RESULT__HISTOGRAM_BIN_0_2 0x008E
#define VL53L1_RESULT__HISTOGRAM_BIN_0_1 0x008F
#define VL53L1_RESULT__HISTOGRAM_BIN_0_0 0x0090
#define VL53L1_RESULT__HISTOGRAM_BIN_23_2 0x00D3
#define VL53L1_RESULT__HISTOGRAM_BIN_23_1 0x00D4
#define VL53L1_RESULT__HISTOGRAM_BIN_23_0 0x00D5
#define VL53L1_RESULT__HISTOGRAM_BIN_23_0_MSB 0x00D9
#define VL53L1_RESULT__HISTOGRAM_BIN_23_0_LSB 0x00DA
#define VL53L1_HISTOGRAM_BIN_DATA_I2C_INDEX \
VL53L1_RESULT__INTERRUPT_STATUS
#define VL53L1_HISTOGRAM_BIN_DATA_I2C_SIZE_BYTES \
(VL53L1_RESULT__HISTOGRAM_BIN_23_0_LSB - \
VL53L1_RESULT__INTERRUPT_STATUS + 1)
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,515 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#ifndef _VL53L1_HIST_STRUCTS_H_
#define _VL53L1_HIST_STRUCTS_H_
#include "vl53l1_ll_device.h"
#include "vl53l1_dmax_structs.h"
#ifdef __cplusplus
extern "C"
{
#endif
#define VL53L1_MAX_BIN_SEQUENCE_LENGTH 6
#define VL53L1_MAX_BIN_SEQUENCE_CODE 15
#define VL53L1_HISTOGRAM_BUFFER_SIZE 24
#define VL53L1_XTALK_HISTO_BINS 12
typedef struct {
uint8_t histogram_config__spad_array_selection;
uint8_t histogram_config__low_amb_even_bin_0_1;
uint8_t histogram_config__low_amb_even_bin_2_3;
uint8_t histogram_config__low_amb_even_bin_4_5;
uint8_t histogram_config__low_amb_odd_bin_0_1;
uint8_t histogram_config__low_amb_odd_bin_2_3;
uint8_t histogram_config__low_amb_odd_bin_4_5;
uint8_t histogram_config__mid_amb_even_bin_0_1;
uint8_t histogram_config__mid_amb_even_bin_2_3;
uint8_t histogram_config__mid_amb_even_bin_4_5;
uint8_t histogram_config__mid_amb_odd_bin_0_1;
uint8_t histogram_config__mid_amb_odd_bin_2;
uint8_t histogram_config__mid_amb_odd_bin_3_4;
uint8_t histogram_config__mid_amb_odd_bin_5;
uint8_t histogram_config__user_bin_offset;
uint8_t histogram_config__high_amb_even_bin_0_1;
uint8_t histogram_config__high_amb_even_bin_2_3;
uint8_t histogram_config__high_amb_even_bin_4_5;
uint8_t histogram_config__high_amb_odd_bin_0_1;
uint8_t histogram_config__high_amb_odd_bin_2_3;
uint8_t histogram_config__high_amb_odd_bin_4_5;
uint16_t histogram_config__amb_thresh_low;
uint16_t histogram_config__amb_thresh_high;
} VL53L1_histogram_config_t;
typedef struct {
VL53L1_HistAlgoSelect hist_algo_select;
VL53L1_HistTargetOrder hist_target_order;
uint8_t filter_woi0;
uint8_t filter_woi1;
VL53L1_HistAmbEstMethod hist_amb_est_method;
uint8_t ambient_thresh_sigma0;
uint8_t ambient_thresh_sigma1;
uint16_t ambient_thresh_events_scaler;
int32_t min_ambient_thresh_events;
uint16_t noise_threshold;
int32_t signal_total_events_limit;
uint8_t sigma_estimator__sigma_ref_mm;
uint16_t sigma_thresh;
int16_t range_offset_mm;
uint16_t gain_factor;
uint8_t valid_phase_low;
uint8_t valid_phase_high;
uint8_t algo__consistency_check__phase_tolerance;
uint8_t algo__consistency_check__event_sigma;
uint16_t algo__consistency_check__event_min_spad_count;
uint16_t algo__consistency_check__min_max_tolerance;
uint8_t algo__crosstalk_compensation_enable;
uint32_t algo__crosstalk_compensation_plane_offset_kcps;
int16_t algo__crosstalk_compensation_x_plane_gradient_kcps;
int16_t algo__crosstalk_compensation_y_plane_gradient_kcps;
int16_t algo__crosstalk_detect_min_valid_range_mm;
int16_t algo__crosstalk_detect_max_valid_range_mm;
uint16_t algo__crosstalk_detect_max_valid_rate_kcps;
uint16_t algo__crosstalk_detect_max_sigma_mm;
uint8_t algo__crosstalk_detect_event_sigma;
uint16_t algo__crosstalk_detect_min_max_tolerance;
} VL53L1_hist_post_process_config_t;
typedef struct {
VL53L1_DeviceState cfg_device_state;
VL53L1_DeviceState rd_device_state;
uint8_t zone_id;
uint32_t time_stamp;
uint8_t VL53L1_p_022;
uint8_t VL53L1_p_023;
uint8_t VL53L1_p_024;
uint8_t number_of_ambient_bins;
uint8_t bin_seq[VL53L1_MAX_BIN_SEQUENCE_LENGTH];
uint8_t bin_rep[VL53L1_MAX_BIN_SEQUENCE_LENGTH];
int32_t bin_data[VL53L1_HISTOGRAM_BUFFER_SIZE];
uint8_t result__interrupt_status;
uint8_t result__range_status;
uint8_t result__report_status;
uint8_t result__stream_count;
uint16_t result__dss_actual_effective_spads;
uint16_t phasecal_result__reference_phase;
uint8_t phasecal_result__vcsel_start;
uint8_t cal_config__vcsel_start;
uint16_t vcsel_width;
uint8_t VL53L1_p_009;
uint16_t VL53L1_p_019;
uint32_t total_periods_elapsed;
uint32_t peak_duration_us;
uint32_t woi_duration_us;
int32_t min_bin_value;
int32_t max_bin_value;
uint16_t zero_distance_phase;
uint8_t number_of_ambient_samples;
int32_t ambient_events_sum;
int32_t VL53L1_p_004;
uint8_t roi_config__user_roi_centre_spad;
uint8_t roi_config__user_roi_requested_global_xy_size;
} VL53L1_histogram_bin_data_t;
typedef struct {
uint8_t zone_id;
uint32_t time_stamp;
uint8_t VL53L1_p_022;
uint8_t VL53L1_p_023;
uint8_t VL53L1_p_024;
uint32_t bin_data[VL53L1_XTALK_HISTO_BINS];
uint16_t phasecal_result__reference_phase;
uint8_t phasecal_result__vcsel_start;
uint8_t cal_config__vcsel_start;
uint16_t vcsel_width;
uint16_t VL53L1_p_019;
uint16_t zero_distance_phase;
} VL53L1_xtalk_histogram_shape_t;
typedef struct {
VL53L1_xtalk_histogram_shape_t xtalk_shape;
VL53L1_histogram_bin_data_t xtalk_hist_removed;
} VL53L1_xtalk_histogram_data_t;
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,459 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#ifndef _VL53L1_NVM_H_
#define _VL53L1_NVM_H_
#include "vl53l1_ll_def.h"
#include "vl53l1_platform.h"
#ifdef __cplusplus
extern "C"
{
#endif
#define VL53L1_NVM_POWER_UP_DELAY_US 50
#define VL53L1_NVM_READ_TRIGGER_DELAY_US 5
VL53L1_Error VL53L1_nvm_enable(
VL53L1_DEV Dev,
uint16_t nvm_ctrl_pulse_width,
int32_t nvm_power_up_delay_us);
VL53L1_Error VL53L1_nvm_read(
VL53L1_DEV Dev,
uint8_t start_address,
uint8_t count,
uint8_t *pdata);
VL53L1_Error VL53L1_nvm_disable(
VL53L1_DEV Dev);
VL53L1_Error VL53L1_nvm_format_decode(
uint16_t buf_size,
uint8_t *pbuffer,
VL53L1_decoded_nvm_data_t *pdata);
VL53L1_Error VL53L1_nvm_decode_optical_centre(
uint16_t buf_size,
uint8_t *pbuffer,
VL53L1_optical_centre_t *pdata);
VL53L1_Error VL53L1_nvm_decode_cal_peak_rate_map(
uint16_t buf_size,
uint8_t *pbuffer,
VL53L1_cal_peak_rate_map_t *pdata);
VL53L1_Error VL53L1_nvm_decode_additional_offset_cal_data(
uint16_t buf_size,
uint8_t *pbuffer,
VL53L1_additional_offset_cal_data_t *pdata);
VL53L1_Error VL53L1_nvm_decode_fmt_range_results_data(
uint16_t buf_size,
uint8_t *pbuffer,
VL53L1_decoded_nvm_fmt_range_data_t *pdata);
VL53L1_Error VL53L1_nvm_decode_fmt_info(
uint16_t buf_size,
uint8_t *pbuffer,
VL53L1_decoded_nvm_fmt_info_t *pdata);
VL53L1_Error VL53L1_nvm_decode_ews_info(
uint16_t buf_size,
uint8_t *pbuffer,
VL53L1_decoded_nvm_ews_info_t *pdata);
void VL53L1_nvm_format_encode(
VL53L1_decoded_nvm_data_t *pnvm_info,
uint8_t *pnvm_data);
VL53L1_Error VL53L1_read_nvm_raw_data(
VL53L1_DEV Dev,
uint8_t start_address,
uint8_t count,
uint8_t *pnvm_raw_data);
VL53L1_Error VL53L1_read_nvm(
VL53L1_DEV Dev,
uint8_t nvm_format,
VL53L1_decoded_nvm_data_t *pnvm_info);
VL53L1_Error VL53L1_read_nvm_optical_centre(
VL53L1_DEV Dev,
VL53L1_optical_centre_t *pcentre);
VL53L1_Error VL53L1_read_nvm_cal_peak_rate_map(
VL53L1_DEV Dev,
VL53L1_cal_peak_rate_map_t *pcal_data);
VL53L1_Error VL53L1_read_nvm_additional_offset_cal_data(
VL53L1_DEV Dev,
VL53L1_additional_offset_cal_data_t *pcal_data);
VL53L1_Error VL53L1_read_nvm_fmt_range_results_data(
VL53L1_DEV Dev,
uint16_t range_results_select,
VL53L1_decoded_nvm_fmt_range_data_t *prange_data);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,202 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#ifndef _VL53L1_NVM_DEBUG_H_
#define _VL53L1_NVM_DEBUG_H_
#include "vl53l1_ll_def.h"
#include "vl53l1_nvm_structs.h"
#ifdef __cplusplus
extern "C"
{
#endif
#ifdef VL53L1_LOG_ENABLE
void VL53L1_print_nvm_raw_data(
uint8_t *pnvm_raw_data,
uint32_t trace_flags);
void VL53L1_print_decoded_nvm_data(
VL53L1_decoded_nvm_data_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_decoded_nvm_fmt_range_data(
VL53L1_decoded_nvm_fmt_range_data_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_decoded_nvm_fmt_info(
VL53L1_decoded_nvm_fmt_info_t *pdata,
char *pprefix,
uint32_t trace_flags);
void VL53L1_print_decoded_nvm_ews_info(
VL53L1_decoded_nvm_ews_info_t *pdata,
char *pprefix,
uint32_t trace_flags);
#endif
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,809 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#ifndef _VL53L1_NVM_STRUCTS_H_
#define _VL53L1_NVM_STRUCTS_H_
#ifdef __cplusplus
extern "C"
{
#endif
#include "vl53l1_platform.h"
#include "vl53l1_ll_def.h"
typedef struct {
uint16_t result__actual_effective_rtn_spads;
uint8_t ref_spad_array__num_requested_ref_spads;
uint8_t ref_spad_array__ref_location;
uint16_t result__peak_signal_count_rate_rtn_mcps;
uint16_t result__ambient_count_rate_rtn_mcps;
uint16_t result__peak_signal_count_rate_ref_mcps;
uint16_t result__ambient_count_rate_ref_mcps;
uint16_t measured_distance_mm;
uint16_t measured_distance_stdev_mm;
} VL53L1_decoded_nvm_fmt_range_data_t;
typedef struct {
char nvm__fmt__fgc[19];
uint8_t nvm__fmt__test_program_major;
uint8_t nvm__fmt__test_program_minor;
uint8_t nvm__fmt__map_major;
uint8_t nvm__fmt__map_minor;
uint8_t nvm__fmt__year;
uint8_t nvm__fmt__month;
uint8_t nvm__fmt__day;
uint8_t nvm__fmt__module_date_phase;
uint16_t nvm__fmt__time;
uint8_t nvm__fmt__tester_id;
uint8_t nvm__fmt__site_id;
uint8_t nvm__ews__test_program_major;
uint8_t nvm__ews__test_program_minor;
uint8_t nvm__ews__probe_card_major;
uint8_t nvm__ews__probe_card_minor;
uint8_t nvm__ews__tester_id;
char nvm__ews__lot[8];
uint8_t nvm__ews__wafer;
uint8_t nvm__ews__xcoord;
uint8_t nvm__ews__ycoord;
} VL53L1_decoded_nvm_fmt_info_t;
typedef struct {
uint8_t nvm__ews__test_program_major;
uint8_t nvm__ews__test_program_minor;
uint8_t nvm__ews__probe_card_major;
uint8_t nvm__ews__probe_card_minor;
uint8_t nvm__ews__tester_id;
char nvm__ews__lot[8];
uint8_t nvm__ews__wafer;
uint8_t nvm__ews__xcoord;
uint8_t nvm__ews__ycoord;
} VL53L1_decoded_nvm_ews_info_t;
typedef struct {
uint8_t nvm__identification_model_id;
uint8_t nvm__identification_module_type;
uint8_t nvm__identification_revision_id;
uint16_t nvm__identification_module_id;
uint8_t nvm__i2c_valid;
uint8_t nvm__i2c_device_address_ews;
uint16_t nvm__ews__fast_osc_frequency;
uint8_t nvm__ews__fast_osc_trim_max;
uint8_t nvm__ews__fast_osc_freq_set;
uint16_t nvm__ews__slow_osc_calibration;
uint16_t nvm__fmt__fast_osc_frequency;
uint8_t nvm__fmt__fast_osc_trim_max;
uint8_t nvm__fmt__fast_osc_freq_set;
uint16_t nvm__fmt__slow_osc_calibration;
uint8_t nvm__vhv_config_unlock;
uint8_t nvm__ref_selvddpix;
uint8_t nvm__ref_selvquench;
uint8_t nvm__regavdd1v2_sel;
uint8_t nvm__regdvdd1v2_sel;
uint8_t nvm__vhv_timeout__macrop;
uint8_t nvm__vhv_loop_bound;
uint8_t nvm__vhv_count_threshold;
uint8_t nvm__vhv_offset;
uint8_t nvm__vhv_init_enable;
uint8_t nvm__vhv_init_value;
uint8_t nvm__laser_safety_vcsel_trim_ll;
uint8_t nvm__laser_safety_vcsel_selion_ll;
uint8_t nvm__laser_safety_vcsel_selion_max_ll;
uint8_t nvm__laser_safety_mult_ll;
uint8_t nvm__laser_safety_clip_ll;
uint8_t nvm__laser_safety_vcsel_trim_ld;
uint8_t nvm__laser_safety_vcsel_selion_ld;
uint8_t nvm__laser_safety_vcsel_selion_max_ld;
uint8_t nvm__laser_safety_mult_ld;
uint8_t nvm__laser_safety_clip_ld;
uint8_t nvm__laser_safety_lock_byte;
uint8_t nvm__laser_safety_unlock_byte;
uint8_t nvm__ews__spad_enables_rtn[VL53L1_RTN_SPAD_BUFFER_SIZE];
uint8_t nvm__ews__spad_enables_ref__loc1[VL53L1_REF_SPAD_BUFFER_SIZE];
uint8_t nvm__ews__spad_enables_ref__loc2[VL53L1_REF_SPAD_BUFFER_SIZE];
uint8_t nvm__ews__spad_enables_ref__loc3[VL53L1_REF_SPAD_BUFFER_SIZE];
uint8_t nvm__fmt__spad_enables_rtn[VL53L1_RTN_SPAD_BUFFER_SIZE];
uint8_t nvm__fmt__spad_enables_ref__loc1[VL53L1_REF_SPAD_BUFFER_SIZE];
uint8_t nvm__fmt__spad_enables_ref__loc2[VL53L1_REF_SPAD_BUFFER_SIZE];
uint8_t nvm__fmt__spad_enables_ref__loc3[VL53L1_REF_SPAD_BUFFER_SIZE];
uint8_t nvm__fmt__roi_config__mode_roi_centre_spad;
uint8_t nvm__fmt__roi_config__mode_roi_x_size;
uint8_t nvm__fmt__roi_config__mode_roi_y_size;
uint8_t nvm__fmt__ref_spad_apply__num_requested_ref_spad;
uint8_t nvm__fmt__ref_spad_man__ref_location;
uint16_t nvm__fmt__mm_config__inner_offset_mm;
uint16_t nvm__fmt__mm_config__outer_offset_mm;
uint16_t nvm__fmt__algo_part_to_part_range_offset_mm;
uint16_t nvm__fmt__algo__crosstalk_compensation_plane_offset_kcps;
uint16_t nvm__fmt__algo__crosstalk_compensation_x_plane_gradient_kcps;
uint16_t nvm__fmt__algo__crosstalk_compensation_y_plane_gradient_kcps;
uint8_t nvm__fmt__spare__host_config__nvm_config_spare_0;
uint8_t nvm__fmt__spare__host_config__nvm_config_spare_1;
uint8_t nvm__customer_space_programmed;
uint8_t nvm__cust__i2c_device_address;
uint8_t nvm__cust__ref_spad_apply__num_requested_ref_spad;
uint8_t nvm__cust__ref_spad_man__ref_location;
uint16_t nvm__cust__mm_config__inner_offset_mm;
uint16_t nvm__cust__mm_config__outer_offset_mm;
uint16_t nvm__cust__algo_part_to_part_range_offset_mm;
uint16_t nvm__cust__algo__crosstalk_compensation_plane_offset_kcps;
uint16_t nvm__cust__algo__crosstalk_compensation_x_plane_gradient_kcps;
uint16_t nvm__cust__algo__crosstalk_compensation_y_plane_gradient_kcps;
uint8_t nvm__cust__spare__host_config__nvm_config_spare_0;
uint8_t nvm__cust__spare__host_config__nvm_config_spare_1;
VL53L1_optical_centre_t fmt_optical_centre;
VL53L1_cal_peak_rate_map_t fmt_peak_rate_map;
VL53L1_additional_offset_cal_data_t fmt_add_offset_data;
VL53L1_decoded_nvm_fmt_range_data_t
fmt_range_data[VL53L1_NVM_MAX_FMT_RANGE_DATA];
VL53L1_decoded_nvm_fmt_info_t fmt_info;
VL53L1_decoded_nvm_ews_info_t ews_info;
} VL53L1_decoded_nvm_data_t;
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,110 @@
/******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
******************************************************************************
'STMicroelectronics Proprietary license'
*******************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
*******************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones mentioned above :
*******************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#ifndef _VL53L1_PRESET_SETUP_H_
#define _VL53L1_PRESET_SETUP_H_
#ifdef __cplusplus
extern "C"
{
#endif
/* indexes for the bare driver tuning setting API function */
enum VL53L1_Tuning_t {
VL53L1_TUNING_VERSION = 0,
VL53L1_TUNING_PROXY_MIN,
VL53L1_TUNING_SINGLE_TARGET_XTALK_TARGET_DISTANCE_MM,
VL53L1_TUNING_SINGLE_TARGET_XTALK_SAMPLE_NUMBER,
VL53L1_TUNING_MIN_AMBIENT_DMAX_VALID,
VL53L1_TUNING_MAX_SIMPLE_OFFSET_CALIBRATION_SAMPLE_NUMBER,
VL53L1_TUNING_XTALK_FULL_ROI_TARGET_DISTANCE_MM,
VL53L1_TUNING_SIMPLE_OFFSET_CALIBRATION_REPEAT,
VL53L1_TUNING_MAX_TUNABLE_KEY
};
/* default values for the tuning settings parameters */
#define TUNING_VERSION 0x0004
#define TUNING_PROXY_MIN -30 /* min distance in mm */
#define TUNING_SINGLE_TARGET_XTALK_TARGET_DISTANCE_MM 600
/* Target distance in mm for single target Xtalk */
#define TUNING_SINGLE_TARGET_XTALK_SAMPLE_NUMBER 50
/* Number of sample used for single target Xtalk */
#define TUNING_MIN_AMBIENT_DMAX_VALID 8
/* Minimum ambient level to state the Dmax returned by the device is valid */
#define TUNING_MAX_SIMPLE_OFFSET_CALIBRATION_SAMPLE_NUMBER 5
/* Maximum loops to perform simple offset calibration */
#define TUNING_XTALK_FULL_ROI_TARGET_DISTANCE_MM 600
/* Target distance in mm for target Xtalk from Bins method*/
#define TUNING_SIMPLE_OFFSET_CALIBRATION_REPEAT 3
/* Number of loops done during the simple offset calibration*/
/* the following table should actually be defined as static and shall be part
* of the VL53L1_StaticInit() function code
*/
#ifdef __cplusplus
}
#endif
#endif /* _VL53L1_PRESET_SETUP_H_ */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,274 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#ifndef _VL53L1_REGISTER_SETTINGS_H_
#define _VL53L1_REGISTER_SETTINGS_H_
#define VL53L1_DEVICESCHEDULERMODE_PSEUDO_SOLO 0x00
#define VL53L1_DEVICESCHEDULERMODE_STREAMING 0x01
#define VL53L1_DEVICESCHEDULERMODE_HISTOGRAM 0x02
#define VL53L1_DEVICEREADOUTMODE_SINGLE_SD (0x00 << 2)
#define VL53L1_DEVICEREADOUTMODE_DUAL_SD (0x01 << 2)
#define VL53L1_DEVICEREADOUTMODE_SPLIT_READOUT (0x02 << 2)
#define VL53L1_DEVICEREADOUTMODE_SPLIT_MANUAL (0x03 << 2)
#define VL53L1_DEVICEMEASUREMENTMODE_MODE_MASK 0xF0
#define VL53L1_DEVICEMEASUREMENTMODE_STOP_MASK 0x0F
#define VL53L1_GROUPEDPARAMETERHOLD_ID_MASK 0x02
#define VL53L1_EWOK_I2C_DEV_ADDR_DEFAULT 0x29
#define VL53L1_OSC_FREQUENCY 0x00
#define VL53L1_OSC_TRIM_DEFAULT 0x00
#define VL53L1_OSC_FREQ_SET_DEFAULT 0x00
#define VL53L1_RANGE_HISTOGRAM_REF 0x08
#define VL53L1_RANGE_HISTOGRAM_RET 0x10
#define VL53L1_RANGE_HISTOGRAM_BOTH 0x18
#define VL53L1_RANGE_HISTOGRAM_INIT 0x20
#define VL53L1_RANGE_VHV_INIT 0x40
#define VL53L1_RESULT_RANGE_STATUS 0x1F
#define VL53L1_SYSTEM__SEED_CONFIG__MANUAL 0x00
#define VL53L1_SYSTEM__SEED_CONFIG__STANDARD 0x01
#define VL53L1_SYSTEM__SEED_CONFIG__EVEN_UPDATE_ONLY 0x02
#define VL53L1_INTERRUPT_CONFIG_LEVEL_LOW 0x00
#define VL53L1_INTERRUPT_CONFIG_LEVEL_HIGH 0x01
#define VL53L1_INTERRUPT_CONFIG_OUT_OF_WINDOW 0x02
#define VL53L1_INTERRUPT_CONFIG_IN_WINDOW 0x03
#define VL53L1_INTERRUPT_CONFIG_NEW_SAMPLE_READY 0x20
#define VL53L1_CLEAR_RANGE_INT 0x01
#define VL53L1_CLEAR_ERROR_INT 0x02
#define VL53L1_SEQUENCE_VHV_EN 0x01
#define VL53L1_SEQUENCE_PHASECAL_EN 0x02
#define VL53L1_SEQUENCE_REFERENCE_PHASE_EN 0x04
#define VL53L1_SEQUENCE_DSS1_EN 0x08
#define VL53L1_SEQUENCE_DSS2_EN 0x10
#define VL53L1_SEQUENCE_MM1_EN 0x20
#define VL53L1_SEQUENCE_MM2_EN 0x40
#define VL53L1_SEQUENCE_RANGE_EN 0x80
#define VL53L1_DSS_CONTROL__ROI_SUBTRACT 0x20
#define VL53L1_DSS_CONTROL__ROI_INTERSECT 0x10
#define VL53L1_DSS_CONTROL__MODE_DISABLED 0x00
#define VL53L1_DSS_CONTROL__MODE_TARGET_RATE 0x01
#define VL53L1_DSS_CONTROL__MODE_EFFSPADS 0x02
#define VL53L1_DSS_CONTROL__MODE_BLOCKSELECT 0x03
#define VL53L1_RANGING_CORE__SPAD_READOUT__STANDARD 0x45
#define VL53L1_RANGING_CORE__SPAD_READOUT__RETURN_ARRAY_ONLY 0x05
#define VL53L1_RANGING_CORE__SPAD_READOUT__REFERENCE_ARRAY_ONLY 0x55
#define VL53L1_RANGING_CORE__SPAD_READOUT__RETURN_SPLIT_ARRAY 0x25
#define VL53L1_RANGING_CORE__SPAD_READOUT__CALIB_PULSES 0xF5
#define VL53L1_LASER_SAFETY__KEY_VALUE 0x6C
#define VL53L1_RANGE_STATUS__RANGE_STATUS_MASK 0x1F
#define VL53L1_RANGE_STATUS__MAX_THRESHOLD_HIT_MASK 0x20
#define VL53L1_RANGE_STATUS__MIN_THRESHOLD_HIT_MASK 0x40
#define VL53L1_RANGE_STATUS__GPH_ID_RANGE_STATUS_MASK 0x80
#define VL53L1_INTERRUPT_STATUS__INT_STATUS_MASK 0x07
#define VL53L1_INTERRUPT_STATUS__INT_ERROR_STATUS_MASK 0x18
#define VL53L1_INTERRUPT_STATUS__GPH_ID_INT_STATUS_MASK 0x20
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,134 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#ifndef _VL53L1_SILICON_CORE_H_
#define _VL53L1_SILICON_CORE_H_
#include "vl53l1_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
VL53L1_Error VL53L1_is_firmware_ready_silicon(
VL53L1_DEV Dev,
uint8_t *pready);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,410 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#ifndef _VL53L1_TUNING_PARM_DEFAULTS_H_
#define _VL53L1_TUNING_PARM_DEFAULTS_H_
#ifdef __cplusplus
extern "C" {
#endif
#define VL53L1_TUNINGPARM_VERSION_DEFAULT \
((uint16_t) 27)
#define VL53L1_TUNINGPARM_KEY_TABLE_VERSION_DEFAULT \
((uint16_t) 14)
#define VL53L1_TUNINGPARM_LLD_VERSION_DEFAULT \
((uint16_t) 12180)
#define VL53L1_TUNINGPARM_HIST_ALGO_SELECT_DEFAULT \
((uint8_t) 4)
#define VL53L1_TUNINGPARM_HIST_TARGET_ORDER_DEFAULT \
((uint8_t) 1)
#define VL53L1_TUNINGPARM_HIST_FILTER_WOI_0_DEFAULT \
((uint8_t) 1)
#define VL53L1_TUNINGPARM_HIST_FILTER_WOI_1_DEFAULT \
((uint8_t) 2)
#define VL53L1_TUNINGPARM_HIST_AMB_EST_METHOD_DEFAULT \
((uint8_t) 1)
#define VL53L1_TUNINGPARM_HIST_AMB_THRESH_SIGMA_0_DEFAULT \
((uint8_t) 80)
#define VL53L1_TUNINGPARM_HIST_AMB_THRESH_SIGMA_1_DEFAULT \
((uint8_t) 112)
#define VL53L1_TUNINGPARM_HIST_MIN_AMB_THRESH_EVENTS_DEFAULT \
((int32_t) 16)
#define VL53L1_TUNINGPARM_HIST_AMB_EVENTS_SCALER_DEFAULT \
((uint16_t) 4157)
#define VL53L1_TUNINGPARM_HIST_NOISE_THRESHOLD_DEFAULT \
((uint16_t) 50)
#define VL53L1_TUNINGPARM_HIST_SIGNAL_TOTAL_EVENTS_LIMIT_DEFAULT \
((int32_t) 100)
#define VL53L1_TUNINGPARM_HIST_SIGMA_EST_REF_MM_DEFAULT \
((uint8_t) 1)
#define VL53L1_TUNINGPARM_HIST_SIGMA_THRESH_MM_DEFAULT \
((uint16_t) 160)
#define VL53L1_TUNINGPARM_HIST_GAIN_FACTOR_DEFAULT \
((uint16_t) 1997)
#define VL53L1_TUNINGPARM_CONSISTENCY_HIST_PHASE_TOLERANCE_DEFAULT \
((uint8_t) 8)
#define VL53L1_TUNINGPARM_CONSISTENCY_HIST_MIN_MAX_TOLERANCE_MM_DEFAULT \
((uint16_t) 250)
#define VL53L1_TUNINGPARM_CONSISTENCY_HIST_EVENT_SIGMA_DEFAULT \
((uint8_t) 240)
#define VL53L1_TUNINGPARM_CONSISTENCY_HIST_EVENT_SIGMA_MIN_SPAD_LIMIT_DEFAULT \
((uint16_t) 2048)
#define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_HISTO_LONG_RANGE_DEFAULT \
((uint8_t) 9)
#define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_HISTO_MED_RANGE_DEFAULT \
((uint8_t) 5)
#define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_HISTO_SHORT_RANGE_DEFAULT \
((uint8_t) 3)
#define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_HISTO_LONG_RANGE_DEFAULT \
((uint8_t) 6)
#define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_HISTO_MED_RANGE_DEFAULT \
((uint8_t) 6)
#define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_HISTO_SHORT_RANGE_DEFAULT \
((uint8_t) 6)
#define VL53L1_TUNINGPARM_XTALK_DETECT_MIN_VALID_RANGE_MM_DEFAULT \
((int16_t) -50)
#define VL53L1_TUNINGPARM_XTALK_DETECT_MAX_VALID_RANGE_MM_DEFAULT \
((int16_t) 50)
#define VL53L1_TUNINGPARM_XTALK_DETECT_MAX_SIGMA_MM_DEFAULT \
((uint16_t) 140)
#define VL53L1_TUNINGPARM_XTALK_DETECT_MIN_MAX_TOLERANCE_DEFAULT \
((uint16_t) 50)
#define VL53L1_TUNINGPARM_XTALK_DETECT_MAX_VALID_RATE_KCPS_DEFAULT \
((uint16_t) 64000)
#define VL53L1_TUNINGPARM_XTALK_DETECT_EVENT_SIGMA_DEFAULT \
((uint8_t) 80)
#define VL53L1_TUNINGPARM_HIST_XTALK_MARGIN_KCPS_DEFAULT \
((int16_t) 512)
#define VL53L1_TUNINGPARM_CONSISTENCY_LITE_PHASE_TOLERANCE_DEFAULT \
((uint8_t) 2)
#define VL53L1_TUNINGPARM_PHASECAL_TARGET_DEFAULT \
((uint8_t) 33)
#define VL53L1_TUNINGPARM_LITE_CAL_REPEAT_RATE_DEFAULT \
((uint16_t) 0)
#define VL53L1_TUNINGPARM_LITE_RANGING_GAIN_FACTOR_DEFAULT \
((uint16_t) 2011)
#define VL53L1_TUNINGPARM_LITE_MIN_CLIP_MM_DEFAULT \
((uint8_t) 0)
#define VL53L1_TUNINGPARM_LITE_LONG_SIGMA_THRESH_MM_DEFAULT \
((uint16_t) 60)
#define VL53L1_TUNINGPARM_LITE_MED_SIGMA_THRESH_MM_DEFAULT \
((uint16_t) 60)
#define VL53L1_TUNINGPARM_LITE_SHORT_SIGMA_THRESH_MM_DEFAULT \
((uint16_t) 60)
#define VL53L1_TUNINGPARM_LITE_LONG_MIN_COUNT_RATE_RTN_MCPS_DEFAULT \
((uint16_t) 128)
#define VL53L1_TUNINGPARM_LITE_MED_MIN_COUNT_RATE_RTN_MCPS_DEFAULT \
((uint16_t) 128)
#define VL53L1_TUNINGPARM_LITE_SHORT_MIN_COUNT_RATE_RTN_MCPS_DEFAULT \
((uint16_t) 128)
#define VL53L1_TUNINGPARM_LITE_SIGMA_EST_PULSE_WIDTH_DEFAULT \
((uint8_t) 8)
#define VL53L1_TUNINGPARM_LITE_SIGMA_EST_AMB_WIDTH_NS_DEFAULT \
((uint8_t) 16)
#define VL53L1_TUNINGPARM_LITE_SIGMA_REF_MM_DEFAULT \
((uint8_t) 1)
#define VL53L1_TUNINGPARM_LITE_RIT_MULT_DEFAULT \
((uint8_t) 64)
#define VL53L1_TUNINGPARM_LITE_SEED_CONFIG_DEFAULT \
((uint8_t) 2)
#define VL53L1_TUNINGPARM_LITE_QUANTIFIER_DEFAULT \
((uint8_t) 2)
#define VL53L1_TUNINGPARM_LITE_FIRST_ORDER_SELECT_DEFAULT \
((uint8_t) 0)
#define VL53L1_TUNINGPARM_LITE_XTALK_MARGIN_KCPS_DEFAULT \
((int16_t) 0)
#define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_LONG_RANGE_DEFAULT \
((uint8_t) 14)
#define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_MED_RANGE_DEFAULT \
((uint8_t) 10)
#define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_SHORT_RANGE_DEFAULT \
((uint8_t) 6)
#define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_LONG_RANGE_DEFAULT \
((uint8_t) 14)
#define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_MED_RANGE_DEFAULT \
((uint8_t) 10)
#define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_SHORT_RANGE_DEFAULT \
((uint8_t) 6)
#define VL53L1_TUNINGPARM_TIMED_SEED_CONFIG_DEFAULT \
((uint8_t) 1)
#define VL53L1_TUNINGPARM_DMAX_CFG_SIGNAL_THRESH_SIGMA_DEFAULT \
((uint8_t) 32)
#define VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_0_DEFAULT \
((uint16_t) 15)
#define VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_1_DEFAULT \
((uint16_t) 52)
#define VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_2_DEFAULT \
((uint16_t) 200)
#define VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_3_DEFAULT \
((uint16_t) 364)
#define VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_4_DEFAULT \
((uint16_t) 400)
#define VL53L1_TUNINGPARM_VHV_LOOPBOUND_DEFAULT \
((uint8_t) 129)
#define VL53L1_TUNINGPARM_REFSPADCHAR_DEVICE_TEST_MODE_DEFAULT \
((uint8_t) 8)
#define VL53L1_TUNINGPARM_REFSPADCHAR_VCSEL_PERIOD_DEFAULT \
((uint8_t) 11)
#define VL53L1_TUNINGPARM_REFSPADCHAR_PHASECAL_TIMEOUT_US_DEFAULT \
((uint32_t) 1000)
#define VL53L1_TUNINGPARM_REFSPADCHAR_TARGET_COUNT_RATE_MCPS_DEFAULT \
((uint16_t) 2560)
#define VL53L1_TUNINGPARM_REFSPADCHAR_MIN_COUNTRATE_LIMIT_MCPS_DEFAULT \
((uint16_t) 1280)
#define VL53L1_TUNINGPARM_REFSPADCHAR_MAX_COUNTRATE_LIMIT_MCPS_DEFAULT \
((uint16_t) 5120)
#define VL53L1_TUNINGPARM_XTALK_EXTRACT_NUM_OF_SAMPLES_DEFAULT \
((uint8_t) 7)
#define VL53L1_TUNINGPARM_XTALK_EXTRACT_MIN_FILTER_THRESH_MM_DEFAULT \
((int16_t) -70)
#define VL53L1_TUNINGPARM_XTALK_EXTRACT_MAX_FILTER_THRESH_MM_DEFAULT \
((int16_t) 70)
#define VL53L1_TUNINGPARM_XTALK_EXTRACT_DSS_RATE_MCPS_DEFAULT \
((uint16_t) 5120)
#define VL53L1_TUNINGPARM_XTALK_EXTRACT_PHASECAL_TIMEOUT_US_DEFAULT \
((uint32_t) 15000)
#define VL53L1_TUNINGPARM_XTALK_EXTRACT_MAX_VALID_RATE_KCPS_DEFAULT \
((uint16_t) 64000)
#define VL53L1_TUNINGPARM_XTALK_EXTRACT_SIGMA_THRESHOLD_MM_DEFAULT \
((uint16_t) 140)
#define VL53L1_TUNINGPARM_XTALK_EXTRACT_DSS_TIMEOUT_US_DEFAULT \
((uint32_t) 2000)
#define VL53L1_TUNINGPARM_XTALK_EXTRACT_BIN_TIMEOUT_US_DEFAULT \
((uint32_t) 10000)
#define VL53L1_TUNINGPARM_OFFSET_CAL_DSS_RATE_MCPS_DEFAULT \
((uint16_t) 2560)
#define VL53L1_TUNINGPARM_OFFSET_CAL_PHASECAL_TIMEOUT_US_DEFAULT \
((uint32_t) 1000)
#define VL53L1_TUNINGPARM_OFFSET_CAL_MM_TIMEOUT_US_DEFAULT \
((uint32_t) 13000)
#define VL53L1_TUNINGPARM_OFFSET_CAL_RANGE_TIMEOUT_US_DEFAULT \
((uint32_t) 13000)
#define VL53L1_TUNINGPARM_OFFSET_CAL_PRE_SAMPLES_DEFAULT \
((uint8_t) 8)
#define VL53L1_TUNINGPARM_OFFSET_CAL_MM1_SAMPLES_DEFAULT \
((uint8_t) 40)
#define VL53L1_TUNINGPARM_OFFSET_CAL_MM2_SAMPLES_DEFAULT \
((uint8_t) 9)
#define VL53L1_TUNINGPARM_ZONE_CAL_DSS_RATE_MCPS_DEFAULT \
((uint16_t) 5120)
#define VL53L1_TUNINGPARM_ZONE_CAL_PHASECAL_TIMEOUT_US_DEFAULT \
((uint32_t) 15000)
#define VL53L1_TUNINGPARM_ZONE_CAL_DSS_TIMEOUT_US_DEFAULT \
((uint32_t) 2000)
#define VL53L1_TUNINGPARM_ZONE_CAL_PHASECAL_NUM_SAMPLES_DEFAULT \
((uint16_t) 16)
#define VL53L1_TUNINGPARM_ZONE_CAL_RANGE_TIMEOUT_US_DEFAULT \
((uint32_t) 1000)
#define VL53L1_TUNINGPARM_ZONE_CAL_ZONE_NUM_SAMPLES_DEFAULT \
((uint16_t) 8)
#define VL53L1_TUNINGPARM_SPADMAP_VCSEL_PERIOD_DEFAULT \
((uint8_t) 18)
#define VL53L1_TUNINGPARM_SPADMAP_VCSEL_START_DEFAULT \
((uint8_t) 15)
#define VL53L1_TUNINGPARM_SPADMAP_RATE_LIMIT_MCPS_DEFAULT \
((uint16_t) 12)
#define VL53L1_TUNINGPARM_LITE_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS_DEFAULT \
((uint16_t) 2560)
#define VL53L1_TUNINGPARM_RANGING_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS_DEFAULT \
((uint16_t) 5120)
#define VL53L1_TUNINGPARM_MZ_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS_DEFAULT \
((uint16_t) 5120)
#define VL53L1_TUNINGPARM_TIMED_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS_DEFAULT \
((uint16_t) 2560)
#define VL53L1_TUNINGPARM_LITE_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT \
((uint32_t) 1000)
#define VL53L1_TUNINGPARM_RANGING_LONG_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT \
((uint32_t) 15000)
#define VL53L1_TUNINGPARM_RANGING_MED_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT \
((uint32_t) 9000)
#define VL53L1_TUNINGPARM_RANGING_SHORT_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT \
((uint32_t) 6000)
#define VL53L1_TUNINGPARM_MZ_LONG_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT \
((uint32_t) 15000)
#define VL53L1_TUNINGPARM_MZ_MED_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT \
((uint32_t) 9000)
#define VL53L1_TUNINGPARM_MZ_SHORT_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT \
((uint32_t) 6000)
#define VL53L1_TUNINGPARM_TIMED_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT \
((uint32_t) 1000)
#define VL53L1_TUNINGPARM_LITE_MM_CONFIG_TIMEOUT_US_DEFAULT \
((uint32_t) 2000)
#define VL53L1_TUNINGPARM_RANGING_MM_CONFIG_TIMEOUT_US_DEFAULT \
((uint32_t) 2000)
#define VL53L1_TUNINGPARM_MZ_MM_CONFIG_TIMEOUT_US_DEFAULT \
((uint32_t) 2000)
#define VL53L1_TUNINGPARM_TIMED_MM_CONFIG_TIMEOUT_US_DEFAULT \
((uint32_t) 2000)
#define VL53L1_TUNINGPARM_LITE_RANGE_CONFIG_TIMEOUT_US_DEFAULT \
((uint32_t) 63000)
#define VL53L1_TUNINGPARM_RANGING_RANGE_CONFIG_TIMEOUT_US_DEFAULT \
((uint32_t) 2500)
#define VL53L1_TUNINGPARM_MZ_RANGE_CONFIG_TIMEOUT_US_DEFAULT \
((uint32_t) 2500)
#define VL53L1_TUNINGPARM_TIMED_RANGE_CONFIG_TIMEOUT_US_DEFAULT \
((uint32_t) 13000)
#define VL53L1_TUNINGPARM_DYNXTALK_SMUDGE_MARGIN_DEFAULT \
((uint16_t) 512)
#define VL53L1_TUNINGPARM_DYNXTALK_NOISE_MARGIN_DEFAULT \
((uint32_t) 500)
#define VL53L1_TUNINGPARM_DYNXTALK_XTALK_OFFSET_LIMIT_DEFAULT \
((uint32_t) 0)
#define VL53L1_TUNINGPARM_DYNXTALK_XTALK_OFFSET_LIMIT_HI_DEFAULT \
((uint8_t) 0)
#define VL53L1_TUNINGPARM_DYNXTALK_SAMPLE_LIMIT_DEFAULT \
((uint32_t) 200)
#define VL53L1_TUNINGPARM_DYNXTALK_SINGLE_XTALK_DELTA_DEFAULT \
((uint32_t) 10240)
#define VL53L1_TUNINGPARM_DYNXTALK_AVERAGED_XTALK_DELTA_DEFAULT \
((uint32_t) 4096)
#define VL53L1_TUNINGPARM_DYNXTALK_CLIP_LIMIT_DEFAULT \
((uint32_t) 1046528)
#define VL53L1_TUNINGPARM_DYNXTALK_SCALER_CALC_METHOD_DEFAULT \
((uint8_t) 0)
#define VL53L1_TUNINGPARM_DYNXTALK_XGRADIENT_SCALER_DEFAULT \
((int16_t) 256)
#define VL53L1_TUNINGPARM_DYNXTALK_YGRADIENT_SCALER_DEFAULT \
((int16_t) 256)
#define VL53L1_TUNINGPARM_DYNXTALK_USER_SCALER_SET_DEFAULT \
((uint8_t) 0)
#define VL53L1_TUNINGPARM_DYNXTALK_SMUDGE_COR_SINGLE_APPLY_DEFAULT \
((uint8_t) 0)
#define VL53L1_TUNINGPARM_DYNXTALK_XTALK_AMB_THRESHOLD_DEFAULT \
((uint32_t) 1280)
#define VL53L1_TUNINGPARM_DYNXTALK_NODETECT_AMB_THRESHOLD_KCPS_DEFAULT \
((uint32_t) 57671680)
#define VL53L1_TUNINGPARM_DYNXTALK_NODETECT_SAMPLE_LIMIT_DEFAULT \
((uint32_t) 10)
#define VL53L1_TUNINGPARM_DYNXTALK_NODETECT_XTALK_OFFSET_KCPS_DEFAULT \
((uint32_t) 2048)
#define VL53L1_TUNINGPARM_DYNXTALK_NODETECT_MIN_RANGE_MM_DEFAULT \
((uint16_t) 900)
#define VL53L1_TUNINGPARM_LOWPOWERAUTO_VHV_LOOP_BOUND_DEFAULT \
((uint8_t) 3)
#define VL53L1_TUNINGPARM_LOWPOWERAUTO_MM_CONFIG_TIMEOUT_US_DEFAULT \
((uint32_t) 1)
#define VL53L1_TUNINGPARM_LOWPOWERAUTO_RANGE_CONFIG_TIMEOUT_US_DEFAULT \
((uint32_t) 8000)
#define VL53L1_TUNINGPARM_VERY_SHORT_DSS_RATE_MCPS_DEFAULT \
((uint16_t) 10240)
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,319 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#ifndef _VL53L1_WAIT_H_
#define _VL53L1_WAIT_H_
#include "vl53l1_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
VL53L1_Error VL53L1_wait_for_boot_completion(
VL53L1_DEV Dev);
VL53L1_Error VL53L1_wait_for_firmware_ready(
VL53L1_DEV Dev);
VL53L1_Error VL53L1_wait_for_range_completion(
VL53L1_DEV Dev);
VL53L1_Error VL53L1_wait_for_test_completion(
VL53L1_DEV Dev);
VL53L1_Error VL53L1_is_boot_complete(
VL53L1_DEV Dev,
uint8_t *pready);
VL53L1_Error VL53L1_is_firmware_ready(
VL53L1_DEV Dev,
uint8_t *pready);
VL53L1_Error VL53L1_is_new_data_ready(
VL53L1_DEV Dev,
uint8_t *pready);
VL53L1_Error VL53L1_poll_for_boot_completion(
VL53L1_DEV Dev,
uint32_t timeout_ms);
VL53L1_Error VL53L1_poll_for_firmware_ready(
VL53L1_DEV Dev,
uint32_t timeout_ms);
VL53L1_Error VL53L1_poll_for_range_completion(
VL53L1_DEV Dev,
uint32_t timeout_ms);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,183 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#ifndef _VL53L1_ZONE_PRESETS_H_
#define _VL53L1_ZONE_PRESETS_H_
#include "vl53l1_ll_def.h"
#ifdef __cplusplus
extern "C" {
#endif
VL53L1_Error VL53L1_init_zone_config_structure(
uint8_t x_off,
uint8_t x_inc,
uint8_t x_zones,
uint8_t y_off,
uint8_t y_inc,
uint8_t y_zones,
uint8_t width,
uint8_t height,
VL53L1_zone_config_t *pdata);
VL53L1_Error VL53L1_zone_preset_xtalk_planar(
VL53L1_general_config_t *pgeneral,
VL53L1_zone_config_t *pzone_cfg);
VL53L1_Error VL53L1_init_zone_config_histogram_bins(
VL53L1_zone_config_t *pdata);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,343 @@
/**************************************************************************
* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
****************************************************************************/
/**
* @file ipp_linux.c kernel side implementation of vl53l1 protected processing
*
* @date Sep 1, 2016
* @author : imaging
*
* @ingroup ipp_dev
*/
#include "stmvl53l1.h"
#define IPP_ERR_CODE (VL53L1_ERROR_PLATFORM_SPECIFIC_START-1)
static int stmvl53l1_ipp_do_wrapper(struct stmvl53l1_data *data,
struct ipp_work_t *pin, struct ipp_work_t *pout, int payload_out)
{
int rc;
if (data->ipp.buzy) {
vl53l1_errmsg("try exec new ipp but still buzy on previous");
/* TODO shall we discard it and push new ? */
rc = IPP_ERR_CODE;
goto done;
}
WARN_ON(pin->payload > IPP_WORK_MAX_PAYLOAD);
stmvl531_ipp_tim_start(data);
rc = stmvl53l1_ipp_do(data, pin, pout);
if (rc != 0) {
vl53l1_errmsg("stmvl53l1_ipp_do err %d\n", rc);
rc = IPP_ERR_CODE;
goto done;
}
//vl53l1_dbgmsg("ipp ok \n");
/* check what we got back if valid answer error etc */
if (pout->status) {
vl53l1_errmsg("ipp error status %d from user", pout->status);
if (pout->status >= stmvl53l1_ipp_status_proc_code)
rc = pout->status & (stmvl53l1_ipp_status_proc_code-1);
else
rc = IPP_ERR_CODE;
goto done;
}
WARN_ON(pout->payload > IPP_WORK_MAX_PAYLOAD);
if (pout->payload != payload_out) {
/* bad formated answer */
vl53l1_errmsg("bad payload %d != %d in ipp work back",
pout->payload, payload_out);
rc = IPP_ERR_CODE;
goto done;
}
stmvl531_ipp_tim_stop(data);
/*stmvl531_ipp_stat(data, "ipp #%5x to=%3d fm=%3d in %5ld us",
pin->xfer_id, pin->payload,
pout->payload,
stmvl531_ipp_time(data));*/
rc = 0;
done:
return rc;
}
/**
* @file vl53l1_platform_ipp.h
*
* @brief EwokPlus25 IPP Wrapper Functions
*/
/**
* @brief IPP Wrapper call for histogram post processing
*
*
* @param[in] Dev : Device handle
* @param[in] pdmax_cal : DMAX calibration data
* @param[in] pdmax_cfg : DMAX configuration data
* @param[in] ppost_cfg : VL53L1_hist_post_process_config_t
* @param[in] pbins : Input histogram raw bin data
* @param[in] pxtalk : Cross talk histogram data
* @param[out] presults : Output VL53L1_range_results_t
* structure
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/
VL53L1_Error VL53L1_ipp_hist_process_data(
VL53L1_DEV dev,
VL53L1_dmax_calibration_data_t *pdmax_cal,
VL53L1_hist_gen3_dmax_config_t *pdmax_cfg,
VL53L1_hist_post_process_config_t *ppost_cfg,
VL53L1_histogram_bin_data_t *pbins,
VL53L1_xtalk_histogram_data_t *pxtalk,
VL53L1_range_results_t *presults)
{
struct stmvl53l1_data *data = (struct stmvl53l1_data *)
container_of(dev, struct stmvl53l1_data, stdev);
struct ipp_work_t *pout = &data->ipp.work_out;
struct ipp_work_t *pin = &data->ipp.work;
int rc;
VL53L1_range_results_t *presults_ipp;
IPP_SERIALIZE_VAR;
/* setup pin */
IPP_SERIALIZE_START(pin->data, 5);
IPP_SET_ARG_PTR(pin->data, 0, pdmax_cal);
IPP_SET_ARG_PTR(pin->data, 1, pdmax_cfg);
IPP_SET_ARG_PTR(pin->data, 2, ppost_cfg);
IPP_SET_ARG_PTR(pin->data, 3, pbins);
IPP_SET_ARG_PTR(pin->data, 4, pxtalk);
pin->payload = IPP_SERIALIZE_PAYLAOD();
pin->process_no = stmvl53l1_ipp_cal_hist;
/* setup pout */
IPP_SERIALIZE_START(pout->data, 1);
IPP_OUT_ARG_PTR(pout->data, 0, presults_ipp);
/* do ipp */
rc = stmvl53l1_ipp_do_wrapper(data, pin, pout, IPP_SERIALIZE_PAYLAOD());
if (rc)
goto done;
/* copy output */
memcpy(presults, presults_ipp, sizeof(*presults));
rc = 0;
done:
return rc;
}
/**
* @brief IPP Wrapper call for histogram ambient dmax calc
*
* The target reflectance in percent for the DMAX calculation
* is set by target_reflectance input
*
* The fixed point format is 7.2
*
* @param[in] Dev : Device handle
* @param[in] target_reflectance : target reflectance to report ambient DMAX
* Percentage in 7.2 fixed point format
* @param[in] pdmax_cal : DMAX calibration data
* @param[in] pdmax_cfg : DMAX configuration data
* @param[in] pbins : Input histogram raw bin data
* @param[out] pambient_dmax_mm : Output ambient DMAX distance in [mm]
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/
VL53L1_Error VL53L1_ipp_hist_ambient_dmax(
VL53L1_DEV dev,
uint16_t target_reflectance,
VL53L1_dmax_calibration_data_t *pdmax_cal,
VL53L1_hist_gen3_dmax_config_t *pdmax_cfg,
VL53L1_histogram_bin_data_t *pbins,
int16_t *pambient_dmax_mm)
{
struct stmvl53l1_data *data = (struct stmvl53l1_data *)
container_of(dev, struct stmvl53l1_data, stdev);
struct ipp_work_t *pout = &data->ipp.work_out;
struct ipp_work_t *pin = &data->ipp.work;
int rc;
int16_t *pambient_dmax_mm_ipp;
IPP_SERIALIZE_VAR;
/* setup pin */
IPP_SERIALIZE_START(pin->data, 4);
IPP_SET_ARG(pin->data, 0, target_reflectance);
IPP_SET_ARG_PTR(pin->data, 1, pdmax_cal);
IPP_SET_ARG_PTR(pin->data, 2, pdmax_cfg);
IPP_SET_ARG_PTR(pin->data, 3, pbins);
pin->payload = IPP_SERIALIZE_PAYLAOD();
pin->process_no = stmvl53l1_ipp_hist_ambient_dmax;
/* setup pout */
IPP_SERIALIZE_START(pout->data, 1);
IPP_OUT_ARG_PTR(pout->data, 0, pambient_dmax_mm_ipp);
/* do ipp */
rc = stmvl53l1_ipp_do_wrapper(data, pin, pout, IPP_SERIALIZE_PAYLAOD());
if (rc)
goto done;
/* copy output */
memcpy(pambient_dmax_mm, pambient_dmax_mm_ipp,
sizeof(*pambient_dmax_mm));
rc = 0;
done:
return rc;
}
/**
* @brief IPP Wrapper call for xtalk calibration post processing
*
* @param[in] Dev : Device handle
* @param[in] pxtalk_ranges : Input VL53L1_xtalk_range_results_t
* Must contain 5 ranges, 4 quadrants + 1
* full FoV
* @param[out] pxtalk_shape : Output normalised Cross talk histogram
* shape
* @param[out] pxtalk_cal : Output VL53L1_xtalk_calibration_results_t
* structure
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/
VL53L1_Error VL53L1_ipp_xtalk_calibration_process_data(
VL53L1_DEV dev,
VL53L1_xtalk_range_results_t *pxtalk_ranges,
VL53L1_xtalk_histogram_data_t *pxtalk_shape,
VL53L1_xtalk_calibration_results_t *pxtalk_cal)
{
struct stmvl53l1_data *data = (struct stmvl53l1_data *)
container_of(dev, struct stmvl53l1_data, stdev);
struct ipp_work_t *pout = &data->ipp.work_out;
struct ipp_work_t *pin = &data->ipp.work;
int rc;
VL53L1_xtalk_histogram_data_t *pxtalk_shape_ipp;
VL53L1_xtalk_calibration_results_t *pxtalk_cal_ipp;
IPP_SERIALIZE_VAR;
/* setup pin */
IPP_SERIALIZE_START(pin->data, 1);
IPP_SET_ARG_PTR(pin->data, 0, pxtalk_ranges);
pin->payload = IPP_SERIALIZE_PAYLAOD();
pin->process_no = stmvl53l1_ipp_xtalk_calibration;
/* setup pout */
IPP_SERIALIZE_START(pout->data, 2);
IPP_OUT_ARG_PTR(pout->data, 0, pxtalk_shape_ipp);
IPP_OUT_ARG_PTR(pout->data, 1, pxtalk_cal_ipp);
/* do ipp */
rc = stmvl53l1_ipp_do_wrapper(data, pin, pout, IPP_SERIALIZE_PAYLAOD());
if (rc)
goto done;
/* copy output */
memcpy(pxtalk_shape, pxtalk_shape_ipp, sizeof(*pxtalk_shape));
memcpy(pxtalk_cal, pxtalk_cal_ipp, sizeof(*pxtalk_cal));
rc = 0;
done:
return rc;
}
/**
* @brief IPP Wrapper call for Generating Xtalk data from dual reflectance
* histogram data
*
* @param[in] Dev : Device handle
* @param[in] pxtalk_results : Pointer to xtalk_results structure
* containing dual reflectance
* histogram data
* @param[in] expected_target_distance_mm : User input of true target distance
* @param[in] higher_reflectance : User input detailing which
* histogram data 1 or 2 has the
* highest reflectance.
* @param[out] pxtalk_avg_samples : Pointer to output xtalk histogram
* data
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/
VL53L1_Error VL53L1_ipp_generate_dual_reflectance_xtalk_samples(
VL53L1_DEV dev,
VL53L1_xtalk_range_results_t *pxtalk_results,
uint16_t expected_target_distance_mm,
uint8_t higher_reflectance,
VL53L1_histogram_bin_data_t *pxtalk_avg_samples)
{
struct stmvl53l1_data *data = (struct stmvl53l1_data *)
container_of(dev, struct stmvl53l1_data, stdev);
struct ipp_work_t *pout = &data->ipp.work_out;
struct ipp_work_t *pin = &data->ipp.work;
int rc;
VL53L1_histogram_bin_data_t *pxtalk_avg_samples_ipp;
IPP_SERIALIZE_VAR;
/* setup pin */
IPP_SERIALIZE_START(pin->data, 3);
IPP_SET_ARG_PTR(pin->data, 0, pxtalk_results);
IPP_SET_ARG(pin->data, 1, expected_target_distance_mm);
IPP_SET_ARG(pin->data, 2, higher_reflectance);
pin->payload = IPP_SERIALIZE_PAYLAOD();
pin->process_no = stmvl53l1_ipp_generate_dual_reflectance_xtalk_samples;
/* setup pout */
IPP_SERIALIZE_START(pout->data, 1);
IPP_OUT_ARG_PTR(pout->data, 0, pxtalk_avg_samples_ipp);
/* do ipp */
rc = stmvl53l1_ipp_do_wrapper(data, pin, pout, IPP_SERIALIZE_PAYLAOD());
if (rc)
goto done;
/* copy output */
memcpy(pxtalk_avg_samples, pxtalk_avg_samples_ipp,
sizeof(*pxtalk_avg_samples));
rc = 0;
done:
return rc;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,334 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#include "vl53l1_api_core.h"
#include "vl53l1_api_strings.h"
#include "vl53l1_error_codes.h"
#include "vl53l1_error_strings.h"
#define LOG_FUNCTION_START(fmt, ...) \
_LOG_FUNCTION_START(VL53L1_TRACE_MODULE_API, fmt, ##__VA_ARGS__)
#define LOG_FUNCTION_END(status, ...) \
_LOG_FUNCTION_END(VL53L1_TRACE_MODULE_API, status, ##__VA_ARGS__)
#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
_LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_API, status, fmt, \
##__VA_ARGS__)
VL53L1_Error VL53L1_get_range_status_string(
uint8_t RangeStatus,
char *pRangeStatusString)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
LOG_FUNCTION_START("");
#ifdef VL53L1_USE_EMPTY_STRING
VL53L1_COPYSTRING(pRangeStatusString, "");
#else
switch (RangeStatus) {
case 0:
VL53L1_COPYSTRING(pRangeStatusString,
VL53L1_STRING_RANGESTATUS_RANGEVALID);
break;
case 1:
VL53L1_COPYSTRING(pRangeStatusString,
VL53L1_STRING_RANGESTATUS_SIGMA);
break;
case 2:
VL53L1_COPYSTRING(pRangeStatusString,
VL53L1_STRING_RANGESTATUS_SIGNAL);
break;
case 3:
VL53L1_COPYSTRING(pRangeStatusString,
VL53L1_STRING_RANGESTATUS_MINRANGE);
break;
case 4:
VL53L1_COPYSTRING(pRangeStatusString,
VL53L1_STRING_RANGESTATUS_PHASE);
break;
case 5:
VL53L1_COPYSTRING(pRangeStatusString,
VL53L1_STRING_RANGESTATUS_HW);
break;
default:
VL53L1_COPYSTRING(pRangeStatusString,
VL53L1_STRING_RANGESTATUS_NONE);
}
#endif
LOG_FUNCTION_END(status);
return status;
}
VL53L1_Error VL53L1_get_pal_state_string(
VL53L1_State PalStateCode,
char *pPalStateString)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
LOG_FUNCTION_START("");
#ifdef VL53L1_USE_EMPTY_STRING
VL53L1_COPYSTRING(pPalStateString, "");
#else
switch (PalStateCode) {
case VL53L1_STATE_POWERDOWN:
VL53L1_COPYSTRING(pPalStateString,
VL53L1_STRING_STATE_POWERDOWN);
break;
case VL53L1_STATE_WAIT_STATICINIT:
VL53L1_COPYSTRING(pPalStateString,
VL53L1_STRING_STATE_WAIT_STATICINIT);
break;
case VL53L1_STATE_STANDBY:
VL53L1_COPYSTRING(pPalStateString,
VL53L1_STRING_STATE_STANDBY);
break;
case VL53L1_STATE_IDLE:
VL53L1_COPYSTRING(pPalStateString,
VL53L1_STRING_STATE_IDLE);
break;
case VL53L1_STATE_RUNNING:
VL53L1_COPYSTRING(pPalStateString,
VL53L1_STRING_STATE_RUNNING);
break;
case VL53L1_STATE_RESET:
VL53L1_COPYSTRING(pPalStateString,
VL53L1_STRING_STATE_RESET);
break;
case VL53L1_STATE_UNKNOWN:
VL53L1_COPYSTRING(pPalStateString,
VL53L1_STRING_STATE_UNKNOWN);
break;
case VL53L1_STATE_ERROR:
VL53L1_COPYSTRING(pPalStateString,
VL53L1_STRING_STATE_ERROR);
break;
default:
VL53L1_COPYSTRING(pPalStateString,
VL53L1_STRING_STATE_UNKNOWN);
}
#endif
LOG_FUNCTION_END(status);
return status;
}
VL53L1_Error VL53L1_get_sequence_steps_info(
VL53L1_SequenceStepId SequenceStepId,
char *pSequenceStepsString)
{
VL53L1_Error Status = VL53L1_ERROR_NONE;
LOG_FUNCTION_START("");
#ifdef VL53L1_USE_EMPTY_STRING
VL53L1_COPYSTRING(pSequenceStepsString, "");
#else
switch (SequenceStepId) {
case VL53L1_SEQUENCESTEP_VHV:
VL53L1_COPYSTRING(pSequenceStepsString,
VL53L1_STRING_SEQUENCESTEP_VHV);
break;
case VL53L1_SEQUENCESTEP_PHASECAL:
VL53L1_COPYSTRING(pSequenceStepsString,
VL53L1_STRING_SEQUENCESTEP_PHASECAL);
break;
case VL53L1_SEQUENCESTEP_REFPHASE:
VL53L1_COPYSTRING(pSequenceStepsString,
VL53L1_STRING_SEQUENCESTEP_DSS1);
break;
case VL53L1_SEQUENCESTEP_DSS1:
VL53L1_COPYSTRING(pSequenceStepsString,
VL53L1_STRING_SEQUENCESTEP_DSS1);
break;
case VL53L1_SEQUENCESTEP_DSS2:
VL53L1_COPYSTRING(pSequenceStepsString,
VL53L1_STRING_SEQUENCESTEP_DSS2);
break;
case VL53L1_SEQUENCESTEP_MM1:
VL53L1_COPYSTRING(pSequenceStepsString,
VL53L1_STRING_SEQUENCESTEP_MM1);
break;
case VL53L1_SEQUENCESTEP_MM2:
VL53L1_COPYSTRING(pSequenceStepsString,
VL53L1_STRING_SEQUENCESTEP_MM2);
break;
case VL53L1_SEQUENCESTEP_RANGE:
VL53L1_COPYSTRING(pSequenceStepsString,
VL53L1_STRING_SEQUENCESTEP_RANGE);
break;
default:
Status = VL53L1_ERROR_INVALID_PARAMS;
}
#endif
LOG_FUNCTION_END(Status);
return Status;
}
VL53L1_Error VL53L1_get_limit_check_info(uint16_t LimitCheckId,
char *pLimitCheckString)
{
VL53L1_Error Status = VL53L1_ERROR_NONE;
LOG_FUNCTION_START("");
#ifdef VL53L1_USE_EMPTY_STRING
VL53L1_COPYSTRING(pLimitCheckString, "");
#else
switch (LimitCheckId) {
case VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE:
VL53L1_COPYSTRING(pLimitCheckString,
VL53L1_STRING_CHECKENABLE_SIGMA_FINAL_RANGE);
break;
case VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
VL53L1_COPYSTRING(pLimitCheckString,
VL53L1_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE);
break;
default:
VL53L1_COPYSTRING(pLimitCheckString,
VL53L1_STRING_UNKNOW_ERROR_CODE);
}
#endif
LOG_FUNCTION_END(Status);
return Status;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,938 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#include "vl53l1_ll_def.h"
#include "vl53l1_ll_device.h"
#include "vl53l1_platform_log.h"
#include "vl53l1_core_support.h"
#include "vl53l1_platform_user_data.h"
#include "vl53l1_platform_user_defines.h"
#define LOG_FUNCTION_START(fmt, ...) \
_LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
#define LOG_FUNCTION_END(status, ...) \
_LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
_LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, \
status, fmt, ##__VA_ARGS__)
#define trace_print(level, ...) \
_LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_CORE, \
level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
uint32_t VL53L1_calc_pll_period_us(
uint16_t fast_osc_frequency)
{
uint32_t pll_period_us = 0;
LOG_FUNCTION_START("");
pll_period_us = (0x01 << 30) / fast_osc_frequency;
LOG_FUNCTION_END(0);
return pll_period_us;
}
uint32_t VL53L1_duration_maths(
uint32_t pll_period_us,
uint32_t vcsel_parm_pclks,
uint32_t window_vclks,
uint32_t elapsed_mclks)
{
uint64_t tmp_long_int = 0;
uint32_t duration_us = 0;
duration_us = window_vclks * pll_period_us;
duration_us = duration_us >> 12;
tmp_long_int = (uint64_t)duration_us;
duration_us = elapsed_mclks * vcsel_parm_pclks;
duration_us = duration_us >> 4;
tmp_long_int = tmp_long_int * (uint64_t)duration_us;
tmp_long_int = tmp_long_int >> 12;
if (tmp_long_int > 0xFFFFFFFF)
tmp_long_int = 0xFFFFFFFF;
duration_us = (uint32_t)tmp_long_int;
return duration_us;
}
uint32_t VL53L1_events_per_spad_maths(
int32_t VL53L1_p_013,
uint16_t num_spads,
uint32_t duration)
{
uint64_t total_hist_counts = 0;
uint64_t xtalk_per_spad = 0;
uint32_t rate_per_spad_kcps = 0;
uint64_t dividend = ((uint64_t)VL53L1_p_013
* 1000 * 256);
total_hist_counts = do_division_u(dividend, (uint64_t)num_spads);
if (duration > 0) {
uint64_t dividend = (((uint64_t)(total_hist_counts << 11))
+ ((uint64_t)duration / 2));
xtalk_per_spad = do_division_u(dividend, (uint64_t)duration);
} else {
xtalk_per_spad = (uint64_t)(total_hist_counts << 11);
}
rate_per_spad_kcps = (uint32_t)xtalk_per_spad;
return rate_per_spad_kcps;
}
uint32_t VL53L1_isqrt(uint32_t num)
{
uint32_t res = 0;
uint32_t bit = 1 << 30;
while (bit > num)
bit >>= 2;
while (bit != 0) {
if (num >= res + bit) {
num -= res + bit;
res = (res >> 1) + bit;
} else {
res >>= 1;
}
bit >>= 2;
}
return res;
}
void VL53L1_hist_calc_zero_distance_phase(
VL53L1_histogram_bin_data_t *pdata)
{
uint32_t period = 0;
uint32_t VL53L1_p_017 = 0;
LOG_FUNCTION_START("");
period = 2048 *
(uint32_t)VL53L1_decode_vcsel_period(pdata->VL53L1_p_009);
VL53L1_p_017 = period;
VL53L1_p_017 += (uint32_t)pdata->phasecal_result__reference_phase;
VL53L1_p_017 += (2048 * (uint32_t)pdata->phasecal_result__vcsel_start);
VL53L1_p_017 -= (2048 * (uint32_t)pdata->cal_config__vcsel_start);
VL53L1_p_017 = VL53L1_p_017 % period;
pdata->zero_distance_phase = (uint16_t)VL53L1_p_017;
LOG_FUNCTION_END(0);
}
void VL53L1_hist_estimate_ambient_from_thresholded_bins(
int32_t ambient_threshold_sigma,
VL53L1_histogram_bin_data_t *pdata)
{
uint8_t bin = 0;
int32_t VL53L1_p_032 = 0;
LOG_FUNCTION_START("");
VL53L1_hist_find_min_max_bin_values(pdata);
VL53L1_p_032 =
(int32_t)VL53L1_isqrt((uint32_t)pdata->min_bin_value);
VL53L1_p_032 *= ambient_threshold_sigma;
VL53L1_p_032 += 0x07;
VL53L1_p_032 = VL53L1_p_032 >> 4;
VL53L1_p_032 += pdata->min_bin_value;
pdata->number_of_ambient_samples = 0;
pdata->ambient_events_sum = 0;
for (bin = 0; bin < pdata->VL53L1_p_024; bin++)
if (pdata->bin_data[bin] < VL53L1_p_032) {
pdata->ambient_events_sum += pdata->bin_data[bin];
pdata->number_of_ambient_samples++;
}
if (pdata->number_of_ambient_samples > 0) {
pdata->VL53L1_p_004 =
pdata->ambient_events_sum;
pdata->VL53L1_p_004 +=
((int32_t)pdata->number_of_ambient_samples/2);
pdata->VL53L1_p_004 /=
(int32_t)pdata->number_of_ambient_samples;
}
LOG_FUNCTION_END(0);
}
void VL53L1_hist_remove_ambient_bins(
VL53L1_histogram_bin_data_t *pdata)
{
uint8_t bin = 0;
uint8_t lc = 0;
uint8_t i = 0;
if ((pdata->bin_seq[0] & 0x07) == 0x07) {
i = 0;
for (lc = 0; lc < VL53L1_MAX_BIN_SEQUENCE_LENGTH; lc++) {
if ((pdata->bin_seq[lc] & 0x07) != 0x07) {
pdata->bin_seq[i] = pdata->bin_seq[lc];
pdata->bin_rep[i] = pdata->bin_rep[lc];
i++;
}
}
for (lc = i; lc < VL53L1_MAX_BIN_SEQUENCE_LENGTH; lc++) {
pdata->bin_seq[lc] = VL53L1_MAX_BIN_SEQUENCE_CODE + 1;
pdata->bin_rep[lc] = 0;
}
}
if (pdata->number_of_ambient_bins > 0) {
for (bin = pdata->number_of_ambient_bins;
bin < pdata->VL53L1_p_023; bin++) {
pdata->bin_data[bin-pdata->number_of_ambient_bins] =
pdata->bin_data[bin];
}
pdata->VL53L1_p_024 =
pdata->VL53L1_p_024 -
pdata->number_of_ambient_bins;
pdata->number_of_ambient_bins = 0;
}
}
uint32_t VL53L1_calc_pll_period_mm(
uint16_t fast_osc_frequency)
{
uint32_t pll_period_us = 0;
uint32_t pll_period_mm = 0;
LOG_FUNCTION_START("");
pll_period_us = VL53L1_calc_pll_period_us(fast_osc_frequency);
pll_period_mm =
VL53L1_SPEED_OF_LIGHT_IN_AIR_DIV_8 *
(pll_period_us >> 2);
pll_period_mm = (pll_period_mm + (0x01<<15)) >> 16;
LOG_FUNCTION_END(0);
return pll_period_mm;
}
uint16_t VL53L1_rate_maths(
int32_t VL53L1_p_008,
uint32_t time_us)
{
uint32_t tmp_int = 0;
uint32_t frac_bits = 7;
uint16_t rate_mcps = 0;
if (VL53L1_p_008 > VL53L1_SPAD_TOTAL_COUNT_MAX)
tmp_int = VL53L1_SPAD_TOTAL_COUNT_MAX;
else if (VL53L1_p_008 > 0)
tmp_int = (uint32_t)VL53L1_p_008;
if (VL53L1_p_008 > VL53L1_SPAD_TOTAL_COUNT_RES_THRES)
frac_bits = 3;
else
frac_bits = 7;
if (time_us > 0)
tmp_int = ((tmp_int << frac_bits) + (time_us / 2)) / time_us;
if (VL53L1_p_008 > VL53L1_SPAD_TOTAL_COUNT_RES_THRES)
tmp_int = tmp_int << 4;
if (tmp_int > 0xFFFF)
tmp_int = 0xFFFF;
rate_mcps = (uint16_t)tmp_int;
return rate_mcps;
}
uint16_t VL53L1_rate_per_spad_maths(
uint32_t frac_bits,
uint32_t peak_count_rate,
uint16_t num_spads,
uint32_t max_output_value)
{
uint32_t tmp_int = 0;
uint16_t rate_per_spad = 0;
if (num_spads > 0) {
tmp_int = (peak_count_rate << 8) << frac_bits;
tmp_int = (tmp_int +
((uint32_t)num_spads / 2)) /
(uint32_t)num_spads;
} else {
tmp_int = ((peak_count_rate) << frac_bits);
}
if (tmp_int > max_output_value)
tmp_int = max_output_value;
rate_per_spad = (uint16_t)tmp_int;
return rate_per_spad;
}
int32_t VL53L1_range_maths(
uint16_t fast_osc_frequency,
uint16_t VL53L1_p_017,
uint16_t zero_distance_phase,
uint8_t fractional_bits,
int32_t gain_factor,
int32_t range_offset_mm)
{
uint32_t pll_period_us = 0;
int64_t tmp_long_int = 0;
int32_t range_mm = 0;
int32_t range_mm_10 = 0;
pll_period_us = VL53L1_calc_pll_period_us(fast_osc_frequency);
tmp_long_int = (int64_t)VL53L1_p_017 - (int64_t)zero_distance_phase;
tmp_long_int = tmp_long_int * (int64_t)pll_period_us;
tmp_long_int = tmp_long_int / (0x01 << 9);
tmp_long_int = tmp_long_int * VL53L1_SPEED_OF_LIGHT_IN_AIR_DIV_8;
tmp_long_int = tmp_long_int / (0x01 << 22);
range_mm = (int32_t)tmp_long_int + range_offset_mm;
range_mm *= gain_factor;
range_mm += 0x0400;
range_mm /= 0x0800;
if (fractional_bits == 0) {
range_mm_10 = range_mm * 10;
range_mm_10 = range_mm_10 / (0x01 << 2);
if ((range_mm_10 % 10) < 5)
range_mm = (int16_t)(range_mm_10 / 10);
else
range_mm = (int16_t)(range_mm_10 / 10 + 1);
} else if (fractional_bits == 1)
range_mm = range_mm / (0x01 << 1);
return range_mm;
}
uint8_t VL53L1_decode_vcsel_period(uint8_t vcsel_period_reg)
{
uint8_t VL53L1_p_031 = 0;
VL53L1_p_031 = (vcsel_period_reg + 1) << 1;
return VL53L1_p_031;
}
void VL53L1_copy_xtalk_bin_data_to_histogram_data_struct(
VL53L1_xtalk_histogram_shape_t *pxtalk,
VL53L1_histogram_bin_data_t *phist)
{
phist->cal_config__vcsel_start =
pxtalk->cal_config__vcsel_start;
phist->VL53L1_p_019 =
pxtalk->VL53L1_p_019;
phist->VL53L1_p_022 =
pxtalk->VL53L1_p_022;
phist->phasecal_result__reference_phase =
pxtalk->phasecal_result__reference_phase;
phist->phasecal_result__vcsel_start =
pxtalk->phasecal_result__vcsel_start;
phist->vcsel_width =
pxtalk->vcsel_width;
phist->zero_distance_phase =
pxtalk->zero_distance_phase;
phist->zone_id = pxtalk->zone_id;
phist->VL53L1_p_023 = pxtalk->VL53L1_p_023;
phist->time_stamp = pxtalk->time_stamp;
}
void VL53L1_init_histogram_bin_data_struct(
int32_t bin_value,
uint16_t VL53L1_p_024,
VL53L1_histogram_bin_data_t *pdata)
{
uint16_t i = 0;
pdata->cfg_device_state = VL53L1_DEVICESTATE_SW_STANDBY;
pdata->rd_device_state = VL53L1_DEVICESTATE_SW_STANDBY;
pdata->zone_id = 0;
pdata->time_stamp = 0;
pdata->VL53L1_p_022 = 0;
pdata->VL53L1_p_023 = VL53L1_HISTOGRAM_BUFFER_SIZE;
pdata->VL53L1_p_024 = (uint8_t)VL53L1_p_024;
pdata->number_of_ambient_bins = 0;
pdata->result__interrupt_status = 0;
pdata->result__range_status = 0;
pdata->result__report_status = 0;
pdata->result__stream_count = 0;
pdata->result__dss_actual_effective_spads = 0;
pdata->phasecal_result__reference_phase = 0;
pdata->phasecal_result__vcsel_start = 0;
pdata->cal_config__vcsel_start = 0;
pdata->vcsel_width = 0;
pdata->VL53L1_p_009 = 0;
pdata->VL53L1_p_019 = 0;
pdata->total_periods_elapsed = 0;
pdata->min_bin_value = 0;
pdata->max_bin_value = 0;
pdata->zero_distance_phase = 0;
pdata->number_of_ambient_samples = 0;
pdata->ambient_events_sum = 0;
pdata->VL53L1_p_004 = 0;
for (i = 0; i < VL53L1_MAX_BIN_SEQUENCE_LENGTH; i++)
pdata->bin_seq[i] = (uint8_t)i;
for (i = 0; i < VL53L1_MAX_BIN_SEQUENCE_LENGTH; i++)
pdata->bin_rep[i] = 1;
for (i = 0; i < VL53L1_HISTOGRAM_BUFFER_SIZE; i++)
if (i < VL53L1_p_024)
pdata->bin_data[i] = bin_value;
else
pdata->bin_data[i] = 0;
}
void VL53L1_decode_row_col(
uint8_t spad_number,
uint8_t *prow,
uint8_t *pcol)
{
if (spad_number > 127) {
*prow = 8 + ((255-spad_number) & 0x07);
*pcol = (spad_number-128) >> 3;
} else {
*prow = spad_number & 0x07;
*pcol = (127-spad_number) >> 3;
}
}
void VL53L1_hist_find_min_max_bin_values(
VL53L1_histogram_bin_data_t *pdata)
{
uint8_t bin = 0;
LOG_FUNCTION_START("");
for (bin = 0; bin < pdata->VL53L1_p_024; bin++) {
if (bin == 0 || pdata->min_bin_value >= pdata->bin_data[bin])
pdata->min_bin_value = pdata->bin_data[bin];
if (bin == 0 || pdata->max_bin_value <= pdata->bin_data[bin])
pdata->max_bin_value = pdata->bin_data[bin];
}
LOG_FUNCTION_END(0);
}
void VL53L1_hist_estimate_ambient_from_ambient_bins(
VL53L1_histogram_bin_data_t *pdata)
{
uint8_t bin = 0;
LOG_FUNCTION_START("");
if (pdata->number_of_ambient_bins > 0) {
pdata->number_of_ambient_samples =
pdata->number_of_ambient_bins;
pdata->ambient_events_sum = 0;
for (bin = 0; bin < pdata->number_of_ambient_bins; bin++)
pdata->ambient_events_sum += pdata->bin_data[bin];
pdata->VL53L1_p_004 = pdata->ambient_events_sum;
pdata->VL53L1_p_004 +=
((int32_t)pdata->number_of_ambient_bins / 2);
pdata->VL53L1_p_004 /=
(int32_t)pdata->number_of_ambient_bins;
}
LOG_FUNCTION_END(0);
}

View File

@@ -0,0 +1,334 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#include "vl53l1_error_codes.h"
#include "vl53l1_error_strings.h"
#include "vl53l1_platform_log.h"
#include "vl53l1_ll_def.h"
#define LOG_FUNCTION_START(fmt, ...) \
_LOG_FUNCTION_START(VL53L1_TRACE_MODULE_API, fmt, ##__VA_ARGS__)
#define LOG_FUNCTION_END(status, ...) \
_LOG_FUNCTION_END(VL53L1_TRACE_MODULE_API, status, ##__VA_ARGS__)
#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
_LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_API, \
status, fmt, ##__VA_ARGS__)
VL53L1_Error VL53L1_get_pal_error_string(
#ifndef VL53L1_USE_EMPTY_STRING
VL53L1_Error PalErrorCode,
#endif
char *pPalErrorString)
{
VL53L1_Error Status = VL53L1_ERROR_NONE;
#ifdef VL53L1_USE_EMPTY_STRING
SUPPRESS_UNUSED_WARNING(PalErrorCode);
#endif
LOG_FUNCTION_START("");
#ifdef VL53L1_USE_EMPTY_STRING
VL53L1_COPYSTRING(pPalErrorString, "");
#else
switch (PalErrorCode) {
case VL53L1_ERROR_NONE:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_NONE);
break;
case VL53L1_ERROR_CALIBRATION_WARNING:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_CALIBRATION_WARNING);
break;
case VL53L1_ERROR_MIN_CLIPPED:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_MIN_CLIPPED);
break;
case VL53L1_ERROR_UNDEFINED:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_UNDEFINED);
break;
case VL53L1_ERROR_INVALID_PARAMS:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_INVALID_PARAMS);
break;
case VL53L1_ERROR_NOT_SUPPORTED:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_NOT_SUPPORTED);
break;
case VL53L1_ERROR_RANGE_ERROR:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_RANGE_ERROR);
break;
case VL53L1_ERROR_TIME_OUT:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_TIME_OUT);
break;
case VL53L1_ERROR_MODE_NOT_SUPPORTED:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_MODE_NOT_SUPPORTED);
break;
case VL53L1_ERROR_BUFFER_TOO_SMALL:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_BUFFER_TOO_SMALL);
break;
case VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_COMMS_BUFFER_TOO_SMALL);
break;
case VL53L1_ERROR_GPIO_NOT_EXISTING:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_GPIO_NOT_EXISTING);
break;
case VL53L1_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED);
break;
case VL53L1_ERROR_CONTROL_INTERFACE:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_CONTROL_INTERFACE);
break;
case VL53L1_ERROR_INVALID_COMMAND:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_INVALID_COMMAND);
break;
case VL53L1_ERROR_DIVISION_BY_ZERO:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_DIVISION_BY_ZERO);
break;
case VL53L1_ERROR_REF_SPAD_INIT:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_REF_SPAD_INIT);
break;
case VL53L1_ERROR_GPH_SYNC_CHECK_FAIL:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_GPH_SYNC_CHECK_FAIL);
break;
case VL53L1_ERROR_STREAM_COUNT_CHECK_FAIL:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_STREAM_COUNT_CHECK_FAIL);
break;
case VL53L1_ERROR_GPH_ID_CHECK_FAIL:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_GPH_ID_CHECK_FAIL);
break;
case VL53L1_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL);
break;
case VL53L1_ERROR_ZONE_GPH_ID_CHECK_FAIL:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_ZONE_GPH_ID_CHECK_FAIL);
break;
case VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_XTALK_EXTRACTION_NO_SAMPLES_FAIL);
break;
case VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL);
break;
case VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL);
break;
case VL53L1_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL);
break;
case VL53L1_ERROR_ZONE_CAL_NO_SAMPLE_FAIL:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_ZONE_CAL_NO_SAMPLE_FAIL);
break;
case VL53L1_WARNING_OFFSET_CAL_MISSING_SAMPLES:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_WARNING_OFFSET_CAL_MISSING_SAMPLES);
break;
case VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH);
break;
case VL53L1_WARNING_OFFSET_CAL_RATE_TOO_HIGH:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_WARNING_OFFSET_CAL_RATE_TOO_HIGH);
break;
case VL53L1_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW);
break;
case VL53L1_WARNING_ZONE_CAL_MISSING_SAMPLES:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_WARNING_ZONE_CAL_MISSING_SAMPLES);
break;
case VL53L1_WARNING_ZONE_CAL_SIGMA_TOO_HIGH:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_WARNING_ZONE_CAL_SIGMA_TOO_HIGH);
break;
case VL53L1_WARNING_ZONE_CAL_RATE_TOO_HIGH:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_WARNING_ZONE_CAL_RATE_TOO_HIGH);
break;
case VL53L1_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS);
break;
case VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH);
break;
case VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW);
break;
case VL53L1_WARNING_XTALK_MISSING_SAMPLES:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_WARNING_XTALK_MISSING_SAMPLES);
break;
case VL53L1_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT);
break;
case VL53L1_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT);
break;
case VL53L1_ERROR_DEVICE_FIRMWARE_TOO_OLD:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_DEVICE_FIRMWARE_TOO_OLD);
break;
case VL53L1_ERROR_DEVICE_FIRMWARE_TOO_NEW:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_DEVICE_FIRMWARE_TOO_NEW);
break;
case VL53L1_ERROR_UNIT_TEST_FAIL:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_UNIT_TEST_FAIL);
break;
case VL53L1_ERROR_FILE_READ_FAIL:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_FILE_READ_FAIL);
break;
case VL53L1_ERROR_FILE_WRITE_FAIL:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_FILE_WRITE_FAIL);
break;
case VL53L1_ERROR_NOT_IMPLEMENTED:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_ERROR_NOT_IMPLEMENTED);
break;
default:
VL53L1_COPYSTRING(pPalErrorString,
VL53L1_STRING_UNKNOW_ERROR_CODE);
}
#endif
LOG_FUNCTION_END(Status);
return Status;
}

View File

@@ -0,0 +1,282 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include "vl53l1_core.h"
#include "vl53l1_register_settings.h"
#include "vl53l1_hist_char.h"
#define LOG_FUNCTION_START(fmt, ...) \
_LOG_FUNCTION_START(VL53L1_TRACE_MODULE_HISTOGRAM, fmt, ##__VA_ARGS__)
#define LOG_FUNCTION_END(status, ...) \
_LOG_FUNCTION_END(VL53L1_TRACE_MODULE_HISTOGRAM, status, ##__VA_ARGS__)
#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
_LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_HISTOGRAM,\
status, fmt, ##__VA_ARGS__)
VL53L1_Error VL53L1_set_calib_config(
VL53L1_DEV Dev,
uint8_t vcsel_delay__a0,
uint8_t calib_1,
uint8_t calib_2,
uint8_t calib_3,
uint8_t calib_2__a0,
uint8_t spad_readout)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
uint8_t comms_buffer[3];
LOG_FUNCTION_START("");
status = VL53L1_enable_powerforce(Dev);
if (status == VL53L1_ERROR_NONE)
status = VL53L1_disable_firmware(Dev);
if (status == VL53L1_ERROR_NONE) {
status = VL53L1_WrByte(
Dev,
VL53L1_RANGING_CORE__VCSEL_DELAY__A0,
vcsel_delay__a0);
}
if (status == VL53L1_ERROR_NONE) {
comms_buffer[0] = calib_1;
comms_buffer[1] = calib_2;
comms_buffer[2] = calib_3;
status = VL53L1_WriteMulti(
Dev,
VL53L1_RANGING_CORE__CALIB_1,
comms_buffer,
3);
}
if (status == VL53L1_ERROR_NONE)
status = VL53L1_WrByte(
Dev,
VL53L1_RANGING_CORE__CALIB_2__A0,
calib_2__a0);
if (status == VL53L1_ERROR_NONE)
status = VL53L1_WrByte(
Dev,
VL53L1_RANGING_CORE__SPAD_READOUT,
spad_readout);
if (status == VL53L1_ERROR_NONE)
status = VL53L1_enable_firmware(Dev);
LOG_FUNCTION_END(status);
return status;
}
VL53L1_Error VL53L1_set_hist_calib_pulse_delay(
VL53L1_DEV Dev,
uint8_t calib_delay)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
LOG_FUNCTION_START("");
status =
VL53L1_set_calib_config(
Dev,
0x01,
calib_delay,
0x04,
0x08,
0x14,
VL53L1_RANGING_CORE__SPAD_READOUT__CALIB_PULSES);
LOG_FUNCTION_END(status);
return status;
}
VL53L1_Error VL53L1_disable_calib_pulse_delay(
VL53L1_DEV Dev)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
LOG_FUNCTION_START("");
status =
VL53L1_set_calib_config(
Dev,
0x00,
0x00,
0x00,
0x00,
0x00,
VL53L1_RANGING_CORE__SPAD_READOUT__STANDARD);
LOG_FUNCTION_END(status);
return status;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,187 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#include "vl53l1_ll_def.h"
#include "vl53l1_platform.h"
#include "vl53l1_register_map.h"
#include "vl53l1_core.h"
#include "vl53l1_silicon_core.h"
#define LOG_FUNCTION_START(fmt, ...) \
_LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
#define LOG_FUNCTION_END(status, ...) \
_LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
_LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE,\
status, fmt, ##__VA_ARGS__)
VL53L1_Error VL53L1_is_firmware_ready_silicon(
VL53L1_DEV Dev,
uint8_t *pready)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
uint8_t comms_buffer[5];
LOG_FUNCTION_START("");
status = VL53L1_ReadMulti(
Dev,
VL53L1_INTERRUPT_MANAGER__ENABLES,
comms_buffer,
5);
if (status != VL53L1_ERROR_NONE)
goto ENDFUNC;
pdev->dbg_results.interrupt_manager__enables =
comms_buffer[0];
pdev->dbg_results.interrupt_manager__clear =
comms_buffer[1];
pdev->dbg_results.interrupt_manager__status =
comms_buffer[2];
pdev->dbg_results.mcu_to_host_bank__wr_access_en =
comms_buffer[3];
pdev->dbg_results.power_management__go1_reset_status =
comms_buffer[4];
if ((pdev->sys_ctrl.power_management__go1_power_force & 0x01)
== 0x01) {
if (((pdev->dbg_results.interrupt_manager__enables &
0x1F) == 0x1F) &&
((pdev->dbg_results.interrupt_manager__clear
& 0x1F) == 0x1F))
*pready = 0x01;
else
*pready = 0x00;
} else {
if ((pdev->dbg_results.power_management__go1_reset_status
& 0x01) == 0x00)
*pready = 0x01;
else
*pready = 0x00;
}
ENDFUNC:
LOG_FUNCTION_END(status);
return status;
}

View File

@@ -0,0 +1,621 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#include "vl53l1_ll_def.h"
#include "vl53l1_ll_device.h"
#include "vl53l1_platform.h"
#include "vl53l1_core.h"
#include "vl53l1_silicon_core.h"
#include "vl53l1_wait.h"
#include "vl53l1_register_settings.h"
#define LOG_FUNCTION_START(fmt, ...) \
_LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
#define LOG_FUNCTION_END(status, ...) \
_LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
_LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, status, \
fmt, ##__VA_ARGS__)
VL53L1_Error VL53L1_wait_for_boot_completion(
VL53L1_DEV Dev)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
uint8_t fw_ready = 0;
LOG_FUNCTION_START("");
if (pdev->wait_method == VL53L1_WAIT_METHOD_BLOCKING) {
status =
VL53L1_poll_for_boot_completion(
Dev,
VL53L1_BOOT_COMPLETION_POLLING_TIMEOUT_MS);
} else {
fw_ready = 0;
while (fw_ready == 0x00 && status == VL53L1_ERROR_NONE) {
status = VL53L1_is_boot_complete(
Dev,
&fw_ready);
if (status == VL53L1_ERROR_NONE) {
status = VL53L1_WaitMs(
Dev,
VL53L1_POLLING_DELAY_MS);
}
}
}
LOG_FUNCTION_END(status);
return status;
}
VL53L1_Error VL53L1_wait_for_firmware_ready(
VL53L1_DEV Dev)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
uint8_t fw_ready = 0;
uint8_t mode_start = 0;
LOG_FUNCTION_START("");
mode_start =
pdev->sys_ctrl.system__mode_start &
VL53L1_DEVICEMEASUREMENTMODE_MODE_MASK;
if ((mode_start == VL53L1_DEVICEMEASUREMENTMODE_TIMED) ||
(mode_start == VL53L1_DEVICEMEASUREMENTMODE_SINGLESHOT)) {
if (pdev->wait_method == VL53L1_WAIT_METHOD_BLOCKING) {
status =
VL53L1_poll_for_firmware_ready(
Dev,
VL53L1_RANGE_COMPLETION_POLLING_TIMEOUT_MS);
} else {
fw_ready = 0;
while (fw_ready == 0x00 && status ==
VL53L1_ERROR_NONE) {
status = VL53L1_is_firmware_ready(
Dev,
&fw_ready);
if (status == VL53L1_ERROR_NONE) {
status = VL53L1_WaitMs(
Dev,
VL53L1_POLLING_DELAY_MS);
}
}
}
}
LOG_FUNCTION_END(status);
return status;
}
VL53L1_Error VL53L1_wait_for_range_completion(
VL53L1_DEV Dev)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
uint8_t data_ready = 0;
LOG_FUNCTION_START("");
if (pdev->wait_method == VL53L1_WAIT_METHOD_BLOCKING) {
status =
VL53L1_poll_for_range_completion(
Dev,
VL53L1_RANGE_COMPLETION_POLLING_TIMEOUT_MS);
} else {
data_ready = 0;
while (data_ready == 0x00 && status == VL53L1_ERROR_NONE) {
status = VL53L1_is_new_data_ready(
Dev,
&data_ready);
if (status == VL53L1_ERROR_NONE) {
status = VL53L1_WaitMs(
Dev,
VL53L1_POLLING_DELAY_MS);
}
}
}
LOG_FUNCTION_END(status);
return status;
}
VL53L1_Error VL53L1_wait_for_test_completion(
VL53L1_DEV Dev)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
uint8_t data_ready = 0;
LOG_FUNCTION_START("");
if (pdev->wait_method == VL53L1_WAIT_METHOD_BLOCKING) {
status =
VL53L1_poll_for_range_completion(
Dev,
VL53L1_TEST_COMPLETION_POLLING_TIMEOUT_MS);
} else {
data_ready = 0;
while (data_ready == 0x00 && status == VL53L1_ERROR_NONE) {
status = VL53L1_is_new_data_ready(
Dev,
&data_ready);
if (status == VL53L1_ERROR_NONE) {
status = VL53L1_WaitMs(
Dev,
VL53L1_POLLING_DELAY_MS);
}
}
}
LOG_FUNCTION_END(status);
return status;
}
VL53L1_Error VL53L1_is_boot_complete(
VL53L1_DEV Dev,
uint8_t *pready)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
uint8_t firmware__system_status = 0;
LOG_FUNCTION_START("");
status =
VL53L1_RdByte(
Dev,
VL53L1_FIRMWARE__SYSTEM_STATUS,
&firmware__system_status);
if ((firmware__system_status & 0x01) == 0x01) {
*pready = 0x01;
VL53L1_init_ll_driver_state(
Dev,
VL53L1_DEVICESTATE_SW_STANDBY);
} else {
*pready = 0x00;
VL53L1_init_ll_driver_state(
Dev,
VL53L1_DEVICESTATE_FW_COLDBOOT);
}
LOG_FUNCTION_END(status);
return status;
}
VL53L1_Error VL53L1_is_firmware_ready(
VL53L1_DEV Dev,
uint8_t *pready)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
LOG_FUNCTION_START("");
status = VL53L1_is_firmware_ready_silicon(
Dev,
pready);
pdev->fw_ready = *pready;
LOG_FUNCTION_END(status);
return status;
}
VL53L1_Error VL53L1_is_new_data_ready(
VL53L1_DEV Dev,
uint8_t *pready)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
uint8_t gpio__mux_active_high_hv = 0;
uint8_t gpio__tio_hv_status = 0;
uint8_t interrupt_ready = 0;
LOG_FUNCTION_START("");
gpio__mux_active_high_hv =
pdev->stat_cfg.gpio_hv_mux__ctrl &
VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_MASK;
if (gpio__mux_active_high_hv == VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_HIGH)
interrupt_ready = 0x01;
else
interrupt_ready = 0x00;
status = VL53L1_RdByte(
Dev,
VL53L1_GPIO__TIO_HV_STATUS,
&gpio__tio_hv_status);
if ((gpio__tio_hv_status & 0x01) == interrupt_ready)
*pready = 0x01;
else
*pready = 0x00;
LOG_FUNCTION_END(status);
return status;
}
VL53L1_Error VL53L1_poll_for_boot_completion(
VL53L1_DEV Dev,
uint32_t timeout_ms)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
LOG_FUNCTION_START("");
status = VL53L1_WaitUs(
Dev,
VL53L1_FIRMWARE_BOOT_TIME_US);
if (status == VL53L1_ERROR_NONE)
status =
VL53L1_WaitValueMaskEx(
Dev,
timeout_ms,
VL53L1_FIRMWARE__SYSTEM_STATUS,
0x01,
0x01,
VL53L1_POLLING_DELAY_MS);
if (status == VL53L1_ERROR_NONE)
VL53L1_init_ll_driver_state(Dev, VL53L1_DEVICESTATE_SW_STANDBY);
LOG_FUNCTION_END(status);
return status;
}
VL53L1_Error VL53L1_poll_for_firmware_ready(
VL53L1_DEV Dev,
uint32_t timeout_ms)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
uint32_t start_time_ms = 0;
uint32_t current_time_ms = 0;
int32_t poll_delay_ms = VL53L1_POLLING_DELAY_MS;
uint8_t fw_ready = 0;
VL53L1_GetTickCount(&start_time_ms);
pdev->fw_ready_poll_duration_ms = 0;
while ((status == VL53L1_ERROR_NONE) &&
(pdev->fw_ready_poll_duration_ms < timeout_ms) &&
(fw_ready == 0)) {
status = VL53L1_is_firmware_ready(
Dev,
&fw_ready);
if (status == VL53L1_ERROR_NONE &&
fw_ready == 0 &&
poll_delay_ms > 0) {
status = VL53L1_WaitMs(
Dev,
poll_delay_ms);
}
VL53L1_GetTickCount(&current_time_ms);
pdev->fw_ready_poll_duration_ms =
current_time_ms - start_time_ms;
}
if (fw_ready == 0 && status == VL53L1_ERROR_NONE)
status = VL53L1_ERROR_TIME_OUT;
LOG_FUNCTION_END(status);
return status;
}
VL53L1_Error VL53L1_poll_for_range_completion(
VL53L1_DEV Dev,
uint32_t timeout_ms)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
uint8_t gpio__mux_active_high_hv = 0;
uint8_t interrupt_ready = 0;
LOG_FUNCTION_START("");
gpio__mux_active_high_hv =
pdev->stat_cfg.gpio_hv_mux__ctrl &
VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_MASK;
if (gpio__mux_active_high_hv == VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_HIGH)
interrupt_ready = 0x01;
else
interrupt_ready = 0x00;
status =
VL53L1_WaitValueMaskEx(
Dev,
timeout_ms,
VL53L1_GPIO__TIO_HV_STATUS,
interrupt_ready,
0x01,
VL53L1_POLLING_DELAY_MS);
LOG_FUNCTION_END(status);
return status;
}

View File

@@ -0,0 +1,253 @@
/*******************************************************************************
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
This file is part of VL53L1 Core and is dual licensed,
either 'STMicroelectronics
Proprietary license'
or 'BSD 3-clause "New" or "Revised" License' , at your option.
********************************************************************************
'STMicroelectronics Proprietary license'
********************************************************************************
License terms: STMicroelectronics Proprietary in accordance with licensing
terms at www.st.com/sla0081
STMicroelectronics confidential
Reproduction and Communication of this document is strictly prohibited unless
specifically authorized in writing by STMicroelectronics.
********************************************************************************
Alternatively, VL53L1 Core may be distributed under the terms of
'BSD 3-clause "New" or "Revised" License', in which case the following
provisions apply instead of the ones
mentioned above :
********************************************************************************
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#include "vl53l1_ll_def.h"
#include "vl53l1_ll_device.h"
#include "vl53l1_platform_log.h"
#include "vl53l1_zone_presets.h"
#define LOG_FUNCTION_START(fmt, ...) \
_LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
#define LOG_FUNCTION_END(status, ...) \
_LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
_LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE,\
status, fmt, ##__VA_ARGS__)
VL53L1_Error VL53L1_init_zone_config_structure(
uint8_t x_off,
uint8_t x_inc,
uint8_t x_zones,
uint8_t y_off,
uint8_t y_inc,
uint8_t y_zones,
uint8_t width,
uint8_t height,
VL53L1_zone_config_t *pdata)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
uint8_t x = 0;
uint8_t y = 0;
uint16_t i = 0;
LOG_FUNCTION_START("");
pdata->max_zones = VL53L1_MAX_USER_ZONES;
i = 0;
for (x = 0 ; x < x_zones ; x++) {
for (y = 0 ; y < y_zones ; y++) {
if (i < VL53L1_MAX_USER_ZONES) {
pdata->active_zones = (uint8_t)i;
pdata->user_zones[i].height = height;
pdata->user_zones[i].width = width;
pdata->user_zones[i].x_centre =
x_off + (x * x_inc);
pdata->user_zones[i].y_centre =
y_off + (y * y_inc);
}
i++;
}
}
status = VL53L1_init_zone_config_histogram_bins(pdata);
LOG_FUNCTION_END(status);
return status;
}
VL53L1_Error VL53L1_zone_preset_xtalk_planar(
VL53L1_general_config_t *pgeneral,
VL53L1_zone_config_t *pzone_cfg)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
LOG_FUNCTION_START("");
pgeneral->global_config__stream_divider = 0x05;
pzone_cfg->active_zones = 0x04;
pzone_cfg->user_zones[0].height = 15;
pzone_cfg->user_zones[0].width = 7;
pzone_cfg->user_zones[0].x_centre = 4;
pzone_cfg->user_zones[0].y_centre = 8;
pzone_cfg->user_zones[1].height = 15;
pzone_cfg->user_zones[1].width = 7;
pzone_cfg->user_zones[1].x_centre = 12;
pzone_cfg->user_zones[1].y_centre = 8;
pzone_cfg->user_zones[2].height = 7;
pzone_cfg->user_zones[2].width = 15;
pzone_cfg->user_zones[2].x_centre = 8;
pzone_cfg->user_zones[2].y_centre = 4;
pzone_cfg->user_zones[3].height = 7;
pzone_cfg->user_zones[3].width = 15;
pzone_cfg->user_zones[3].x_centre = 8;
pzone_cfg->user_zones[3].y_centre = 12;
pzone_cfg->user_zones[4].height = 15;
pzone_cfg->user_zones[4].width = 15;
pzone_cfg->user_zones[4].x_centre = 8;
pzone_cfg->user_zones[4].y_centre = 8;
status = VL53L1_init_zone_config_histogram_bins(pzone_cfg);
LOG_FUNCTION_END(status);
return status;
}
VL53L1_Error VL53L1_init_zone_config_histogram_bins(
VL53L1_zone_config_t *pdata)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
uint8_t i;
LOG_FUNCTION_START("");
for (i = 0; i < pdata->max_zones; i++)
pdata->bin_config[i] = VL53L1_ZONECONFIG_BINCONFIG__LOWAMB;
LOG_FUNCTION_END(status);
return status;
}

View File

@@ -0,0 +1,26 @@
StMicroelectronis vl53l1
Requires properties:
- compatible: must be "st,stmvl53l1".
- reg: I2C address of the chip.
- xsdn-gpio: gpio number connected to vl53l1 reset pin.
Optional properties:
- intr-gpio: gpio number connected to vl53l1 irq pin.
- vdd: a phandle for the regulator supplying power for vl53l1.
- pwren-gpio: gpio number use to control vl53l1 power.
Example:
&i2c1 {
/* ... */
stmvl53l1: stmvl53l1@29 {
compatible = "st,stmvl53l1";
reg = <0x29>;
xsdn-gpio = <19>;
pwren-gpio = <12>;
intr-gpio = <16>;
};
/* ... */
};

View File

@@ -0,0 +1,114 @@
/**************************************************************************
* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
****************************************************************************/
/** @file stmvl53l1-i2c.h
* Linux kernel i2c/cci wrapper for ST VL53L1 sensor i2c interface
**/
#ifndef STMVL53L1_I2C_H
#define STMVL53L1_I2C_H
#include <linux/types.h>
#include "stmvl53l1.h"
struct i2c_data {
struct i2c_client *client;
/** back link to driver for interrupt and clean-up */
struct stmvl53l1_data *vl53l1_data;
/* reference counter */
struct kref ref;
/*!< if null no regulator use for power ctrl */
struct regulator *vdd;
/*!< power enable gpio number
*
* if -1 no gpio if vdd not avl pwr is not controllable
*/
int pwren_gpio;
/*!< xsdn reset (low active) gpio number to device
*
* -1 mean none assume no "resetable"
*/
int xsdn_gpio;
/*!< intr gpio number to device
*
* intr is active/low negative edge by default
*
* -1 mean none assume use polling
* @warning if the dev tree and intr gpio is require please adapt code
*/
int intr_gpio;
/*!< device boot i2c register address
*
* boot_reg is the value of device i2c address after it is bring out
* of reset.
*/
int boot_reg;
/*!< is set if above irq gpio got acquired */
struct i2d_data_flags_t {
unsigned pwr_owned:1; /*!< set if pwren gpio is owned*/
unsigned xsdn_owned:1; /*!< set if sxdn gpio is owned*/
unsigned intr_owned:1; /*!< set if intr gpio is owned*/
unsigned intr_started:1; /*!< set if irq is hanlde */
} io_flag;
/** the irq vectore assigned to gpio
* -1 if no irq hanled
*/
int irq;
struct msgtctrl_t {
unsigned unhandled_irq_vec:1;
} msg_flag;
};
#ifdef USE_CAMERA_CCI
int __init stmvl53l1_init_cci(void);
void __exit stmvl53l1_exit_cci(void*);
#else
int stmvl53l1_init_i2c(void);
void __exit stmvl53l1_exit_i2c(void *arg);
#endif
int stmvl53l1_power_up_i2c(void *arg);
int stmvl53l1_power_down_i2c(void *arg);
int stmvl53l1_reset_release_i2c(void *arg);
int stmvl53l1_reset_hold_i2c(void *arg);
void stmvl53l1_clean_up_i2c(void);
int stmvl53l1_start_intr(void *object, int *poll_mode);
void *stmvl53l1_get(void *arg);
void stmvl53l1_put(void *arg);
#endif /* STMVL53L1_I2C_H */

View File

@@ -0,0 +1,391 @@
/**************************************************************************
* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
License terms: BSD 3-clause "New" or "Revised" License.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
****************************************************************************/
/**
* @file stmvl53l1.h header for vl53l1 sensor driver
*/
#ifndef STMVL53L1_H
#define STMVL53L1_H
#include <linux/types.h>
#include <linux/mutex.h>
#include <linux/workqueue.h>
#include <linux/miscdevice.h>
#include <linux/wait.h>
#include "vl53l1_api.h"
/**
* IPP adapt
*/
#ifdef DEBUG
# define IPP_PRINT(...) printk(__VA_ARGS__)
#else
# define IPP_PRINT(...) (void)0
#endif
#include "stmvl53l1_ipp.h"
#include "stmvl53l1_if.h"
/**
* Configure the Netlink-id use
*/
#define STMVL531_CFG_NETLINK_USER 31
#define STMVL53L1_MAX_CCI_XFER_SZ 256
#define STMVL53L1_DRV_NAME "stmvl53l1"
/**
* configure usage of regulator device from device tree info
* to enable/disable sensor power
* see module-i2c or module-cci file
*/
/* define CFG_STMVL53L1_HAVE_REGULATOR */
#define DRIVER_VERSION "13.0.1"
/** @ingroup vl53l1_config
* @{
*/
/**
* Configure max number of device the driver can support
*/
#define STMVL53L1_CFG_MAX_DEV 2
/** @} */ /* ingroup vl53l1_config */
/** @ingroup vl53l1_mod_dbg
* @{
*/
#if 0
#define DEBUG 1
#endif
#if 0
#define FORCE_CONSOLE_DEBUG
#endif
extern int stmvl53l1_enable_debug;
#ifdef DEBUG
#ifdef FORCE_CONSOLE_DEBUG
#define vl53l1_dbgmsg(str, ...) do { \
if (stmvl53l1_enable_debug) \
pr_info("%s: " str, __func__, ##__VA_ARGS__); \
} while (0)
#else
#define vl53l1_dbgmsg(str, ...) do { \
if (stmvl53l1_enable_debug) \
pr_info("%s: " str, __func__, ##__VA_ARGS__); \
} while (0)
#endif
#else
#define vl53l1_dbgmsg(...) (void)0
#endif
/**
* set to 0 1 activate or not debug from work (data interrupt/polling)
*/
#define WORK_DEBUG 0
#if WORK_DEBUG
# define work_dbg(msg, ...)\
printk("[D WK53L1] :" msg "\n", ##__VA_ARGS__)
#else
# define work_dbg(...) (void)0
#endif
#define vl53l1_info(str, args...) \
pr_info("%s: " str "\n", __func__, ##args)
#define vl53l1_errmsg(str, args...) \
pr_err("%s: " str, __func__, ##args)
#define vl53l1_wanrmsg(str, args...) \
pr_warn("%s: " str, __func__, ##args)
/* turn off poll log if not defined */
#ifndef STMVL53L1_LOG_POLL_TIMING
# define STMVL53L1_LOG_POLL_TIMING 0
#endif
/* turn off cci log timing if not defined */
#ifndef STMVL53L1_LOG_CCI_TIMING
# define STMVL53L1_LOG_CCI_TIMING 0
#endif
/**@} */ /* ingroup mod_dbg*/
#include <net/sock.h>
#include <linux/netlink.h>
#include <linux/wait.h>
/** if set to 1 enable ipp execution timing (if debug enabled)
* @ingroup vl53l1_mod_dbg
*/
#define IPP_LOG_TIMING 1
struct ipp_data_t {
struct ipp_work_t work;
struct ipp_work_t work_out;
int test_n;
/*!< buzy state 0 is idle
*any other value do not try to use (state value defined in source)
*/
int buzy;
int waited_xfer_id;
/*!< when buzy is set that is the id we are expecting
* note that value 0 is reserved and stand for "not waiting"
* as such never id 0 will be in any round trip exchange
* it's ok for daemon to use 0 in "ping" when it identify himself
*/
int status; /** if that is not 0 do not look at out work data */
wait_queue_head_t waitq;
/*!< ipp caller are put in that queue wait while job is posted to user
* @warning ipp and dev mutex will be released before waiting
* see @ref ipp_abort
*/
#if IPP_LOG_TIMING
struct timeval start_tv, stop_tv;
#endif
};
struct stmvl53l1_waiters {
struct list_head list;
pid_t pid;
};
/*
* driver data structs
*/
struct stmvl53l1_data {
int id; /*!< multiple device id 0 based*/
char name[64]; /*!< misc device name */
VL53L1_DevData_t stdev; /*!<embed ST VL53L0 Dev data as "stdev" */
void *client_object; /*!< cci or i2c model i/f specific ptr */
bool is_device_remove; /*!< true when device has been remove */
struct mutex work_mutex; /*!< main dev mutex/lock */;
struct delayed_work dwork;
/*!< work for pseudo irq polling check */
struct input_dev *input_dev_ps;
/*!< input device used for sending event */
/* misc device */
struct miscdevice miscdev;
/* first irq has no valid data, so avoid to update data on first one */
int is_first_irq;
/* set when first start has be done */
int is_first_start_done;
/* control data */
int poll_mode; /*!< use poll even if interrupt line present*/
int poll_delay_ms; /*!< rescheduled time use in poll mode */
int enable_sensor; /*!< actual device enabled state */
struct timeval start_tv;/*!< stream start time */
int enable_debug;
bool allow_hidden_start_stop; /*!< allow stop/start sequence in bare */
/* Custom values set by app */
int preset_mode; /*!< preset working mode of the device */
uint32_t timing_budget; /*!< Timing Budget */
int distance_mode; /*!< distance mode of the device */
int crosstalk_enable; /*!< is crosstalk compensation is enable */
int output_mode; /*!< output mode of the device */
bool force_device_on_en;/*!< keep device active when stopped */
VL53L1_Error last_error;/*!< last device internal error */
int offset_correction_mode;/*!< offset correction mode to apply */
FixPoint1616_t dmax_reflectance;/*!< reflectance use for dmax calc */
int dmax_mode; /*!< Dmax mode of the device */
int smudge_correction_mode; /*!< smudge mode */
/* Read only values */
FixPoint1616_t optical_offset_x;
FixPoint1616_t optical_offset_y;
bool is_xtalk_value_changed; /*!< xtalk values has been updated */
/* PS parameters */
/* Calibration parameters */
bool is_calibrating; /*!< active during calibration phases */
/* Range Data and stat */
struct range_t {
uint32_t cnt;
uint32_t intr;
int poll_cnt;
uint32_t err_cnt; /* on actual measurement */
uint32_t err_tot; /* from start */
struct timeval start_tv;
struct timeval comp_tv;
VL53L1_RangingMeasurementData_t single_range_data;
VL53L1_MultiRangingData_t multi_range_data;
VL53L1_MultiRangingData_t tmp_range_data;
VL53L1_AdditionalData_t additional_data;
/* non mode 1 for data agregation */
} meas;
/* workqueue use to fire flush event */
uint32_t flushCount;
int flush_todo_counter;
/* Device parameters */
/* Polling thread */
/* Wait Queue on which the poll thread blocks */
/* Manage blocking ioctls */
struct list_head simple_data_reader_list;
struct list_head mz_data_reader_list;
wait_queue_head_t waiter_for_data;
bool is_data_valid;
/* control when using delay is acceptable */
bool is_delay_allowed;
/* maintain reset state */
int reset_state;
/* Recent interrupt status */
/* roi */
VL53L1_RoiConfig_t roi_cfg;
/* use for zone calibration / roi mismatch detection */
uint32_t current_roi_id;
/* Embed here since it's too huge for kernek stack */
struct stmvl53l1_ioctl_zone_calibration_data_t calib;
/* autonomous config */
uint32_t auto_pollingTimeInMs;
VL53L1_DetectionConfig_t auto_config;
/* Debug */
struct ipp_data_t ipp;
#if IPP_LOG_TIMING
# define stmvl531_ipp_tim_stop(data)\
do_gettimeofday(&data->ipp.stop_tv)
# define stmvl531_ipp_tim_start(data)\
do_gettimeofday(&data->ipp.start_tv)
# define stmvl531_ipp_time(data)\
stmvl53l1_tv_dif(&data->ipp.start_tv, &data->ipp.stop_tv)
# define stmvl531_ipp_stat(data, fmt, ...)\
vl53l1_dbgmsg("IPPSTAT " fmt "\n", ##__VA_ARGS__)
#else
# define stmvl531_ipp_tim_stop(data) (void)0
# define stmvl531_ipp_tim_start(data) (void)0
# define stmvl531_ipp_stat(...) (void)0
#endif
};
/**
* timeval diff in us
*
* @param pstart_tv
* @param pstop_tv
*/
long stmvl53l1_tv_dif(struct timeval *pstart_tv, struct timeval *pstop_tv);
/**
* The device table list table is update as device get added
* we do not support adding removing device mutiple time !
* use for clean "unload" purpose
*/
extern struct stmvl53l1_data *stmvl53l1_dev_table[];
int stmvl53l1_setup(struct stmvl53l1_data *data);
void stmvl53l1_cleanup(struct stmvl53l1_data *data);
#ifdef CONFIG_PM_SLEEP
void stmvl53l1_pm_suspend_stop(struct stmvl53l1_data *data);
#endif
int stmvl53l1_intr_handler(struct stmvl53l1_data *data);
/**
* request ipp to abort or stop
*
* require dev work_mutex held
*
* @warning because the "waiting" work can't be aborted we must wake it up
* it will happen and at some later time not earlier than release of lock
* if after lock release we have a new request to start the race may not be
* handled correctly
*
* @param data the device
* @return 0 if no ipp got canceled, @warning this is maybe not grant we
* can't re-sched "dev work" and re-run the worker back
*/
int stmvl53l1_ipp_stop(struct stmvl53l1_data *data);
int stmvl53l1_ipp_do(struct stmvl53l1_data *data, struct ipp_work_t *work_in,
struct ipp_work_t *work_out);
/**
* per device netlink init
* @param data
* @return
*/
int stmvl53l1_ipp_setup(struct stmvl53l1_data *data);
/**
* per device ipp netlink cleaning
* @param data
* @return
*/
void stmvl53l1_ipp_cleanup(struct stmvl53l1_data *data);
/**
* Module init for netlink
* @return 0 on success
*/
int stmvl53l1_ipp_init(void);
/**
* Module exit for netlink
* @return 0 on success
*/
void stmvl53l1_ipp_exit(void);
/**
* enable and start ipp exhange
* @param n_dev number of device to run on
* @param data dev struct
* @return 0 on success
*/
int stmvl53l1_ipp_enable(int n_dev, struct stmvl53l1_data *data);
/*
* function pointer structs
*/
#endif /* STMVL53L1_H */

Some files were not shown because too many files have changed in this diff Show More