完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
lsm6dsl硬件上没接中断管脚,iio驱动修改方法。
方法一 设备树 硬件上并未接中断管脚,设备树配置一没有被使用的GPIO管脚作为中断管脚。 &i2c2 { status = "okay"; clock-frequency = <400000>; lsm6dsl: lsm6dsl@6b { status = "okay"; compatible = "st,lsm6dsl"; reg = <0x6b>; interrupt-parent = <&gpio0>; interrupts = <30 IRQ_TYPE_EDGE_RISING>; }; }; 否则st_lsm6dsx_fifo_setup不会被调用。不会出现/sys/bus/iio/devices/iio:device1/buffer目录。 844 if (hw->irq > 0) { 845 err = st_lsm6dsx_fifo_setup(hw); 846 if (err < 0) 847 return err; 848 } 代码修改 由于没有连接中断管脚,增加内核线程来采集数据。 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h @@ -161,6 +161,7 @@ struct st_lsm6dsx_hw { struct iio_dev *iio_devs[ST_LSM6DSX_ID_MAX]; const struct st_lsm6dsx_settings *settings; + struct task_struct *task; }; extern const struct dev_pm_ops st_lsm6dsx_pm_ops; --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -414,6 +415,23 @@ int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw) return err; } +static int kthread_read_fifo(void *arg) +{ + struct st_lsm6dsx_hw *hw = (struct st_lsm6dsx_hw *)arg; + int count; + + while (!kthread_should_stop()) { + mutex_lock(&hw->fifo_lock); + count = st_lsm6dsx_read_fifo(hw); + mutex_unlock(&hw->fifo_lock); + if (count <= 0) { + schedule_timeout_interruptible(msecs_to_jiffies(10)); + } + } + + return 0; +} + static int st_lsm6dsx_update_fifo(struct iio_dev *iio_dev, bool enable) { struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); @@ -457,6 +475,14 @@ static int st_lsm6dsx_update_fifo(struct iio_dev *iio_dev, bool enable) goto out; err = st_lsm6dsx_set_fifo_mode(hw, ST_LSM6DSX_FIFO_CONT); + if (!hw->task) { + hw->task = kthread_run(kthread_read_fifo, hw, "lsm6dsxd"); + } + } else { + if (hw->task) { + kthread_stop(hw->task); + hw->task = NULL; + } } out: 方法二 设备树 设备树不配置中断管脚。 &i2c2 { status = "okay"; clock-frequency = <400000>; lsm6dsl: lsm6dsl@6b { status = "okay"; compatible = "st,lsm6dsl"; reg = <0x6b>; }; }; 代码修改 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h @@ -161,6 +161,7 @@ struct st_lsm6dsx_hw { struct iio_dev *iio_devs[ST_LSM6DSX_ID_MAX]; const struct st_lsm6dsx_settings *settings; + struct task_struct *task; }; extern const struct dev_pm_ops st_lsm6dsx_pm_ops; @@ -170,6 +171,7 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, const char *name, int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor); int st_lsm6dsx_sensor_disable(struct st_lsm6dsx_sensor *sensor); int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw); +int st_lsm6dsx_fifo_setup_noirq(struct st_lsm6dsx_hw *hw); int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark); int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw); --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -414,6 +415,23 @@ int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw) |
|
|
|
lsm6dsl硬件上没接中断管脚,iio驱动修改方法。
方法一 设备树 硬件上并未接中断管脚,设备树配置一没有被使用的GPIO管脚作为中断管脚。 &i2c2 { status = "okay"; clock-frequency = <400000>; lsm6dsl: lsm6dsl@6b { status = "okay"; compatible = "st,lsm6dsl"; reg = <0x6b>; interrupt-parent = <&gpio0>; interrupts = <30 IRQ_TYPE_EDGE_RISING>; }; }; 否则st_lsm6dsx_fifo_setup不会被调用。不会出现/sys/bus/iio/devices/iio:device1/buffer目录。 844 if (hw->irq > 0) { 845 err = st_lsm6dsx_fifo_setup(hw); 846 if (err < 0) 847 return err; 848 } 代码修改 由于没有连接中断管脚,增加内核线程来采集数据。 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h @@ -161,6 +161,7 @@ struct st_lsm6dsx_hw { struct iio_dev *iio_devs[ST_LSM6DSX_ID_MAX]; const struct st_lsm6dsx_settings *settings; + struct task_struct *task; }; extern const struct dev_pm_ops st_lsm6dsx_pm_ops; --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -414,6 +415,23 @@ int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw) return err; } +static int kthread_read_fifo(void *arg) +{ + struct st_lsm6dsx_hw *hw = (struct st_lsm6dsx_hw *)arg; + int count; + + while (!kthread_should_stop()) { + mutex_lock(&hw->fifo_lock); + count = st_lsm6dsx_read_fifo(hw); + mutex_unlock(&hw->fifo_lock); + if (count <= 0) { + schedule_timeout_interruptible(msecs_to_jiffies(10)); + } + } + + return 0; +} + static int st_lsm6dsx_update_fifo(struct iio_dev *iio_dev, bool enable) { struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); @@ -457,6 +475,14 @@ static int st_lsm6dsx_update_fifo(struct iio_dev *iio_dev, bool enable) goto out; err = st_lsm6dsx_set_fifo_mode(hw, ST_LSM6DSX_FIFO_CONT); + if (!hw->task) { + hw->task = kthread_run(kthread_read_fifo, hw, "lsm6dsxd"); + } + } else { + if (hw->task) { + kthread_stop(hw->task); + hw->task = NULL; + } } out: 方法二 设备树 设备树不配置中断管脚。 &i2c2 { status = "okay"; clock-frequency = <400000>; lsm6dsl: lsm6dsl@6b { status = "okay"; compatible = "st,lsm6dsl"; reg = <0x6b>; }; }; 代码修改 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h @@ -161,6 +161,7 @@ struct st_lsm6dsx_hw { struct iio_dev *iio_devs[ST_LSM6DSX_ID_MAX]; const struct st_lsm6dsx_settings *settings; + struct task_struct *task; }; extern const struct dev_pm_ops st_lsm6dsx_pm_ops; @@ -170,6 +171,7 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, const char *name, int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor); int st_lsm6dsx_sensor_disable(struct st_lsm6dsx_sensor *sensor); int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw); +int st_lsm6dsx_fifo_setup_noirq(struct st_lsm6dsx_hw *hw); int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark); int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw); --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -414,6 +415,23 @@ int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw) |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
基于米尔瑞芯微RK3576核心板/开发板的人脸疲劳检测应用方案
1009 浏览 0 评论
1194 浏览 1 评论
956 浏览 1 评论
2212 浏览 1 评论
3533 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-28 16:55 , Processed in 0.624208 second(s), Total 74, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (威廉希尔官方网站 图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号