pulse_encoder.h 1.7 KB

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