infrared_common_i.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #pragma once
  2. #include <stdint.h>
  3. #include "infrared.h"
  4. #include "infrared_i.h"
  5. #define MATCH_TIMING(x, v, delta) (((x) < ((v) + (delta))) && ((x) > ((v) - (delta))))
  6. typedef struct InfraredCommonDecoder InfraredCommonDecoder;
  7. typedef struct InfraredCommonEncoder InfraredCommonEncoder;
  8. typedef InfraredStatus (*InfraredCommonDecode)(InfraredCommonDecoder*, bool, uint32_t);
  9. typedef InfraredStatus (*InfraredCommonDecodeRepeat)(InfraredCommonDecoder*);
  10. typedef bool (*InfraredCommonInterpret)(InfraredCommonDecoder*);
  11. typedef InfraredStatus (
  12. *InfraredCommonEncode)(InfraredCommonEncoder* encoder, uint32_t* out, bool* polarity);
  13. typedef struct {
  14. InfraredTimings timings;
  15. bool manchester_start_from_space;
  16. bool no_stop_bit;
  17. uint8_t databit_len[4];
  18. InfraredCommonDecode decode;
  19. InfraredCommonDecodeRepeat decode_repeat;
  20. InfraredCommonInterpret interpret;
  21. InfraredCommonEncode encode;
  22. InfraredCommonEncode encode_repeat;
  23. } InfraredCommonProtocolSpec;
  24. typedef enum {
  25. InfraredCommonDecoderStateWaitPreamble,
  26. InfraredCommonDecoderStateDecode,
  27. InfraredCommonDecoderStateProcessRepeat,
  28. } InfraredCommonStateDecoder;
  29. typedef enum {
  30. InfraredCommonEncoderStateSilence,
  31. InfraredCommonEncoderStatePreamble,
  32. InfraredCommonEncoderStateEncode,
  33. InfraredCommonEncoderStateEncodeRepeat,
  34. } InfraredCommonStateEncoder;
  35. struct InfraredCommonDecoder {
  36. const InfraredCommonProtocolSpec* protocol;
  37. void* context;
  38. uint32_t timings[6];
  39. InfraredMessage message;
  40. InfraredCommonStateDecoder state;
  41. uint8_t timings_cnt;
  42. bool switch_detect;
  43. bool level;
  44. uint16_t databit_cnt;
  45. uint8_t data[];
  46. };
  47. struct InfraredCommonEncoder {
  48. const InfraredCommonProtocolSpec* protocol;
  49. InfraredCommonStateEncoder state;
  50. bool switch_detect;
  51. uint8_t bits_to_encode;
  52. uint8_t bits_encoded;
  53. uint32_t timings_sum;
  54. uint32_t timings_encoded;
  55. void* context;
  56. uint8_t data[];
  57. };
  58. InfraredMessage*
  59. infrared_common_decode(InfraredCommonDecoder* decoder, bool level, uint32_t duration);
  60. InfraredStatus
  61. infrared_common_decode_pdwm(InfraredCommonDecoder* decoder, bool level, uint32_t timing);
  62. InfraredStatus
  63. infrared_common_decode_manchester(InfraredCommonDecoder* decoder, bool level, uint32_t timing);
  64. void* infrared_common_decoder_alloc(const InfraredCommonProtocolSpec* protocol);
  65. void infrared_common_decoder_free(InfraredCommonDecoder* decoder);
  66. void infrared_common_decoder_reset(InfraredCommonDecoder* decoder);
  67. InfraredMessage* infrared_common_decoder_check_ready(InfraredCommonDecoder* decoder);
  68. InfraredStatus
  69. infrared_common_encode(InfraredCommonEncoder* encoder, uint32_t* duration, bool* polarity);
  70. InfraredStatus
  71. infrared_common_encode_pdwm(InfraredCommonEncoder* encoder, uint32_t* duration, bool* polarity);
  72. InfraredStatus infrared_common_encode_manchester(
  73. InfraredCommonEncoder* encoder,
  74. uint32_t* duration,
  75. bool* polarity);
  76. void* infrared_common_encoder_alloc(const InfraredCommonProtocolSpec* protocol);
  77. void infrared_common_encoder_free(InfraredCommonEncoder* encoder);
  78. void infrared_common_encoder_reset(InfraredCommonEncoder* encoder);