1 /*
2  * Copyright (c) 2006-2023, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2019-08-13     balanceTWK   first version.
9  */
10 
11 #ifndef __RT_INPUT_CAPTURE_H__
12 #define __RT_INPUT_CAPTURE_H__
13 
14 #include <rtthread.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 /* capture control command */
21 #define INPUTCAPTURE_CMD_CLEAR_BUF        (128 + 0)    /* clear capture buf */
22 #define INPUTCAPTURE_CMD_SET_WATERMARK    (128 + 1)    /* Set the callback threshold */
23 
24 struct rt_inputcapture_data
25 {
26     rt_uint32_t pulsewidth_us;
27     rt_bool_t   is_high;
28 };
29 
30 struct rt_inputcapture_device
31 {
32     struct rt_device                    parent;
33 
34     const struct rt_inputcapture_ops    *ops;
35     struct rt_ringbuffer                *ringbuff;
36     rt_size_t                           watermark;
37 };
38 
39 /**
40  * capture operators
41  */
42 struct rt_inputcapture_ops
43 {
44     rt_err_t (*init)(struct rt_inputcapture_device *inputcapture);
45     rt_err_t (*open)(struct rt_inputcapture_device *inputcapture);
46     rt_err_t (*close)(struct rt_inputcapture_device *inputcapture);
47     rt_err_t (*get_pulsewidth)(struct rt_inputcapture_device *inputcapture, rt_uint32_t *pulsewidth_us);
48 };
49 
50 void rt_hw_inputcapture_isr(struct rt_inputcapture_device *inputcapture, rt_bool_t level);
51 
52 rt_err_t rt_device_inputcapture_register(struct rt_inputcapture_device *inputcapture,
53                                          const char                    *name,
54                                          void                          *data);
55 #ifdef __cplusplus
56 }
57 #endif
58 
59 #endif /* __RT_INPUT_CAPTURE_H__ */
60