summaryrefslogtreecommitdiff
path: root/components/drivers/include
diff options
context:
space:
mode:
authortangweikang <[email protected]>2019-08-09 18:37:16 +0800
committertangweikang <[email protected]>2019-08-09 18:42:14 +0800
commitcc565da5a178d598d35cc9b7d4a1a36be5fb17f5 (patch)
treeffc99ab21011cccde69baf6825ac98c5d6d54f09 /components/drivers/include
parent532ad16b7bd5ba5201f42d26da80121a6ccd0d89 (diff)
[components][drivers] add encoder driven framework
Diffstat (limited to 'components/drivers/include')
-rw-r--r--components/drivers/include/drivers/encoder.h65
-rw-r--r--components/drivers/include/rtdevice.h4
2 files changed, 69 insertions, 0 deletions
diff --git a/components/drivers/include/drivers/encoder.h b/components/drivers/include/drivers/encoder.h
new file mode 100644
index 0000000000..c6c3e4d708
--- /dev/null
+++ b/components/drivers/include/drivers/encoder.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2019-08-08 balanceTWK the first version
+ */
+
+#ifndef __ENCODER_H__
+#define __ENCODER_H__
+
+#include <rtthread.h>
+#include <rtdevice.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* encoder control command */
+typedef enum
+{
+ ENCODER_INFO_GET = 0x01, /* get a encoder feature information */
+ ENCODER_SWITCH_ON, /* switch on encoder */
+ ENCODER_SWITCH_OFF, /* switch off encoder */
+ ENCODER_COUNT_CLEAR, /* clear encoder count */
+} rt_encoder_ctrl_t;
+
+/* encoder type */
+typedef enum
+{
+ SINGLE_PHASE_ENCODER = 0x01, /* single phase encoder */
+ AB_PHASE_ENCODER /* two phase encoder */
+} rt_encoder_type_t;
+
+struct rt_encoder_device;
+
+struct rt_encoder_ops
+{
+ rt_err_t (*init)(struct rt_encoder_device *encoder);
+ rt_int32_t (*get_count)(struct rt_encoder_device *encoder);
+ rt_err_t (*control)(struct rt_encoder_device *encoder, rt_uint32_t cmd, void *args);
+};
+
+/* Encoder feature information */
+struct rt_encoder_info
+{
+ rt_encoder_type_t type; /* the type of encoder */
+};
+
+typedef struct rt_encoder_device
+{
+ struct rt_device parent;
+ const struct rt_encoder_ops *ops;
+ const struct rt_encoder_info *info;
+} rt_encoder_t;
+
+rt_err_t rt_device_encoder_register(rt_encoder_t *encoder, const char *name, void *user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ENCODER_H__ */
diff --git a/components/drivers/include/rtdevice.h b/components/drivers/include/rtdevice.h
index f764d30c24..0c009e9580 100644
--- a/components/drivers/include/rtdevice.h
+++ b/components/drivers/include/rtdevice.h
@@ -126,6 +126,10 @@ extern "C" {
#include "drivers/crypto.h"
#endif
+#ifdef RT_USING_ENCODER
+#include "drivers/encoder.h"
+#endif
+
#ifdef __cplusplus
}
#endif