diff options
| author | guozhanxin <[email protected]> | 2019-03-08 10:32:36 +0800 |
|---|---|---|
| committer | guozhanxin <[email protected]> | 2019-03-08 10:34:10 +0800 |
| commit | 507a90f05583c381f3a9cb53ad345b1277cbe06b (patch) | |
| tree | 0c007521078a2be99328874570fd0cfe81dadcad | |
| parent | 366b9171a1346fd45786548d58038be717254bd7 (diff) | |
[sensor] add irq_handle for driver. | 为底层驱动添加中断回调。
| -rw-r--r-- | components/drivers/sensors/sensor.c | 5 | ||||
| -rw-r--r-- | components/drivers/sensors/sensor.h | 6 |
2 files changed, 10 insertions, 1 deletions
diff --git a/components/drivers/sensors/sensor.c b/components/drivers/sensors/sensor.c index 99f366ddac..ec1ad98fb6 100644 --- a/components/drivers/sensors/sensor.c +++ b/components/drivers/sensors/sensor.c @@ -43,6 +43,11 @@ void rt_sensor_cb(rt_sensor_t sen) { return; } + + if (sen->irq_handle != RT_NULL) + { + sen->irq_handle(sen); + } /* The buffer is not empty. Read the data in the buffer first */ if (sen->data_len > 0) diff --git a/components/drivers/sensors/sensor.h b/components/drivers/sensors/sensor.h index fd437e4e09..94650ea886 100644 --- a/components/drivers/sensors/sensor.h +++ b/components/drivers/sensors/sensor.h @@ -68,6 +68,7 @@ extern "C" { #define RT_SENSOR_UNIT_HZ (9) /* Frequency unit: HZ */ #define RT_SENSOR_UNIT_ONE (10) /* Dimensionless quantity unit: 1 */ #define RT_SENSOR_UNIT_BPM (11) /* Heart rate unit: bpm */ +#define RT_SENSOR_UNIT_MM (12) /* Distance unit: mm */ /* Sensor communication interface types */ @@ -131,6 +132,8 @@ struct rt_sensor_config rt_int32_t range; /* sensor range of measurement */ }; +typedef struct rt_sensor_device *rt_sensor_t; + struct rt_sensor_device { struct rt_device parent; /* The standard device */ @@ -144,8 +147,9 @@ struct rt_sensor_device const struct rt_sensor_ops *ops; /* The sensor ops */ struct rt_sensor_module *module; /* The sensor module */ + + rt_err_t (*irq_handle)(rt_sensor_t sensor); /* Called when an interrupt is generated, registered by the driver */ }; -typedef struct rt_sensor_device *rt_sensor_t; struct rt_sensor_module { |
