tmd26353接近传感器之i2c驱动RK标准sensor框架,HAL层无需修改

一、dts配置ps_tmd26353: tmd26353@39 { compatible = "ps_tmd26353"; reg = <0x39>; type = <SENSOR_TYPE_PROXIMITY>; pinctrl-names = "default"; //pinctrl-0 = <&gpio2_c3>; irq-gpio = <&a
摘要由CSDN通过智能技术生成

一、dts配置

ps_tmd26353: tmd26353@39 {
   
         compatible = "ps_tmd26353";
         reg = <0x39>;
         type = <SENSOR_TYPE_PROXIMITY>;
         pinctrl-names = "default";
         //pinctrl-0 = <&gpio2_c3>;
         irq-gpio = <&gpio3 RK_PC3 IRQ_TYPE_LEVEL_LOW>;
         irq_enable = <0>;
         ps_threshold_high = <0x200>;
         ps_threshold_low = <0x100>;
         //ps_ctrl_gain = <3>; /* 0:x1 1:x4 2:x16 3:x64 */
         //ps_led_current = <3>; /* 0:12.5mA 1:25mA 2:50mA 3:100mA */
         poll_delay_ms = <100>;
		 status = "okay";
};

二、驱动代码

#include <linux/interrupt.h>
#include <linux/i2c.h>
#include <linux/slab.h>
#include <linux/irq.h>
#include <linux/miscdevice.h>
#include <linux/gpio.h>
#include <linux/uaccess.h>
#include <linux/atomic.h>
#include <linux/delay.h>
#include <linux/input.h>
#include <linux/workqueue.h>
#include <linux/freezer.h>
#include <linux/of_gpio.h>
#ifdef CONFIG_HAS_EARLYSUSPEND
#include <linux/earlysuspend.h>
#endif
#include <linux/sensor-dev.h>


/*********************************************
Register
**********************************************/
#define TMD26353_ENABLE_PROXIMITY  		 	 0x80  
#define TMD26353_PRATE						 0x82	//采样时间PRATE
#define TMD26353_PCFG0						 0x8E	//增益
#define TMD26353_PCFG1						 0x8F
#define TMD26353_DEVICE_ID			 		 0x92
#define TMD26353_PDATAL						 0x9C   //ADC
#define TMD26353_PDATAH						 0x9D
#define TMD26353_CFG6_APC				     0xAE   //使能APC
#define TMD26353_POFFSETL					 0xC0	自动校准
#define TMD26353_POFFSETH					 0xC1
#define TMD26353_CALIBCFG					 0xD9	//样本数量CALIBCFG

#define TMD26353_INT_ENABLE					 0xDD

#define TMD26353_INT_STATUS					 0x9B	//中断状态

#define	PS_ENABLE	(1 << 2)

static int ps_threshold_low;
static int ps_threshold_high;

enum tmd26353_register_name {
   
    REG_PDATA = 0,
	REG_DEVICE_ID = 1,
	REG_ENABLE = 2,
	REG_POFFSET = 3,
	REG_PRATE = 4,
	REG_CALIBCFG = 5,
	REG_CFG6_APC = 6,
	REG_PCFG0 = 7,
	REG_PCFG1 = 8,
	REG_INT_ENABLE,
};
struct tmd26353_register_desc {
   
    u8 msb;
    u8 lsb;
};

static const struct tmd26353_register_desc tmd26353_registers[] = {
   
    [REG_PDATA] = {
   
		.msb = 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CodeAmmon

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值