mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-09 20:45:41 +08:00
1. 优化pin.h, sensor.h, rtdevice.h,避免反向包含
2. 优化rt_sensor_close函数,polling模式下不需要操作和rt_pin_irq_enable函数 3. 优化rt_device_register和sensor_polling的LOG信息 4. 修复sensor_polling函数打开设备时的标志错误的问题
This commit is contained in:
1 parent
da0e3ed35d
commit
3487f2790a
6 files changed
+18
-237
No files matched your search
@@ -13,7 +13,6 @@
|
||||
#define PIN_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#define __SENSOR_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include "pin.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -80,9 +80,6 @@ extern "C" {
|
||||
#include "drivers/sdio.h"
|
||||
#endif /* RT_USING_SDIO */
|
||||
|
||||
#ifdef RT_USING_SENSOR
|
||||
#include "drivers/sensor.h"
|
||||
#endif /* RT_USING_SENSOR */
|
||||
|
||||
#ifdef RT_USING_WDT
|
||||
#include "drivers/watchdog.h"
|
||||
@@ -92,6 +89,10 @@ extern "C" {
|
||||
#include "drivers/pin.h"
|
||||
#endif /* RT_USING_PIN */
|
||||
|
||||
#ifdef RT_USING_SENSOR
|
||||
#include "drivers/sensor.h"
|
||||
#endif /* RT_USING_SENSOR */
|
||||
|
||||
#ifdef RT_USING_CAN
|
||||
#include "drivers/can.h"
|
||||
#endif /* RT_USING_CAN */
|
||||
|
||||
@@ -256,10 +256,13 @@ static rt_err_t rt_sensor_close(rt_device_t dev)
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Sensor disable interrupt */
|
||||
if (sensor->config.irq_pin.pin != RT_PIN_NONE)
|
||||
if (sensor->config.mode != RT_SENSOR_MODE_POLLING)
|
||||
{
|
||||
rt_pin_irq_enable(sensor->config.irq_pin.pin, RT_FALSE);
|
||||
/* Sensor disable interrupt */
|
||||
if (sensor->config.irq_pin.pin != RT_PIN_NONE)
|
||||
{
|
||||
rt_pin_irq_enable(sensor->config.irq_pin.pin, RT_FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
__exit:
|
||||
@@ -476,12 +479,12 @@ int rt_hw_sensor_register(rt_sensor_t sensor,
|
||||
result = rt_device_register(device, device_name, flag | RT_DEVICE_FLAG_STANDALONE);
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
LOG_E("rt_sensor[%s] register err code: %d", device_name, result);
|
||||
rt_free(device_name);
|
||||
LOG_E("rt_sensor register err code: %d", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
rt_free(device_name);
|
||||
LOG_I("rt_sensor init success");
|
||||
LOG_I("rt_sensor[%s] init success", device_name);
|
||||
return RT_EOK;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -231,6 +231,7 @@ static void sensor_polling(int argc, char **argv)
|
||||
struct rt_sensor_data data;
|
||||
rt_size_t res, i;
|
||||
rt_int32_t delay;
|
||||
rt_err_t result;
|
||||
|
||||
dev = rt_device_find(argv[1]);
|
||||
if (dev == RT_NULL)
|
||||
@@ -244,9 +245,10 @@ static void sensor_polling(int argc, char **argv)
|
||||
sensor = (rt_sensor_t)dev;
|
||||
delay = sensor->info.period_min > 100 ? sensor->info.period_min : 100;
|
||||
|
||||
if (rt_device_open(dev, RT_DEVICE_FLAG_RDWR) != RT_EOK)
|
||||
result = rt_device_open(dev, RT_DEVICE_FLAG_RDONLY);
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
LOG_E("open device failed!");
|
||||
LOG_E("open device failed! error code : %d", result);
|
||||
return;
|
||||
}
|
||||
rt_device_control(dev, RT_SENSOR_CTRL_SET_ODR, (void *)100);
|
||||
@@ -451,7 +453,7 @@ static void sensor(int argc, char **argv)
|
||||
dev = rt_device_find(argv[2]);
|
||||
if (dev == RT_NULL)
|
||||
{
|
||||
LOG_E("Can't find device:%s", argv[1]);
|
||||
LOG_E("Can't find device:%s", argv[2]);
|
||||
return;
|
||||
}
|
||||
if (rt_device_open(dev, RT_DEVICE_FLAG_RDWR) != RT_EOK)
|
||||
|
||||
Reference in new issue
Block a user