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-08 balanceTWK the first version 9 */ 10 11 #ifndef __PULSE_ENCODER_H__ 12 #define __PULSE_ENCODER_H__ 13 14 #include <rtthread.h> 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 /* pulse_encoder control command */ 21 #define PULSE_ENCODER_CMD_GET_TYPE (128 + 0) /* get a pulse_encoder type information */ 22 #define PULSE_ENCODER_CMD_ENABLE (128 + 1) /* enable pulse_encoder */ 23 #define PULSE_ENCODER_CMD_DISABLE (128 + 2) /* disable pulse_encoder */ 24 #define PULSE_ENCODER_CMD_CLEAR_COUNT (128 + 3) /* clear pulse_encoder count */ 25 26 /* pulse_encoder type */ 27 enum rt_pulse_encoder_type 28 { 29 UNKNOWN_PULSE_ENCODER_TYPE = 0x00, /* Unknown pulse_encoder type */ 30 SINGLE_PHASE_PULSE_ENCODER, /* single phase pulse_encoder */ 31 AB_PHASE_PULSE_ENCODER /* two phase pulse_encoder */ 32 }; 33 34 struct rt_pulse_encoder_device; 35 36 struct rt_pulse_encoder_ops 37 { 38 rt_err_t (*init)(struct rt_pulse_encoder_device *pulse_encoder); 39 rt_int32_t (*get_count)(struct rt_pulse_encoder_device *pulse_encoder); 40 rt_err_t (*clear_count)(struct rt_pulse_encoder_device *pulse_encoder); 41 rt_err_t (*control)(struct rt_pulse_encoder_device *pulse_encoder, rt_uint32_t cmd, void *args); 42 }; 43 44 struct rt_pulse_encoder_device 45 { 46 struct rt_device parent; 47 const struct rt_pulse_encoder_ops *ops; 48 enum rt_pulse_encoder_type type; 49 }; 50 51 rt_err_t rt_device_pulse_encoder_register(struct rt_pulse_encoder_device *pulse_encoder, const char *name, void *user_data); 52 53 #ifdef __cplusplus 54 } 55 #endif 56 57 #endif /* __PULSE_ENCODER_H__ */ 58