infrared.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) 2006-2019, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-03-25 balanceTWK the first version
  9. */
  10. #ifndef __INFRARED__
  11. #define __INFRARED__
  12. #include <rtthread.h>
  13. #include "decoder.h"
  14. #define CARRIER_WAVE 0xA
  15. #define IDLE_SIGNAL 0xB
  16. #define NO_SIGNAL 0x0
  17. #define MAX_SIZE 5
  18. #define INFRARED_BUFF_SIZE 200
  19. struct ir_raw_data
  20. {
  21. rt_uint32_t level : 4,
  22. us : 28;
  23. };
  24. struct decoder_ops
  25. {
  26. rt_err_t (*init)(void);
  27. rt_err_t (*deinit)(void);
  28. rt_err_t (*read)(struct infrared_decoder_data* data);
  29. rt_err_t (*write)(struct infrared_decoder_data* data);
  30. rt_err_t (*decode)(rt_size_t size);
  31. rt_err_t (*control)(int cmd, void *arg);
  32. };
  33. struct decoder_class
  34. {
  35. char* name;
  36. struct decoder_ops* ops;
  37. void* user_data;
  38. };
  39. struct infrared_class
  40. {
  41. struct decoder_class* current_decoder;
  42. struct decoder_class* decoder_tab[MAX_SIZE];
  43. rt_uint32_t count;
  44. struct rt_ringbuffer *ringbuff;
  45. rt_size_t (*send)(struct ir_raw_data* data, rt_size_t size);
  46. };
  47. rt_err_t driver_report_raw_data(rt_uint8_t level, rt_uint32_t us);
  48. struct infrared_class* infrared_init(void);
  49. int infrared_deinit(void);
  50. rt_err_t ir_decoder_register(struct decoder_class *decoder);
  51. rt_err_t ir_select_decoder(const char* name);
  52. rt_err_t decoder_read_data(struct ir_raw_data* data);
  53. rt_err_t decoder_write_data(struct ir_raw_data* data, rt_size_t size);
  54. rt_err_t infrared_read(const char* decoder_name,struct infrared_decoder_data* data);
  55. rt_err_t infrared_write(const char* decoder_name, struct infrared_decoder_data* data);
  56. #endif /* __INFRARED__ */