irda_i.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. #include "irda.h"
  3. #include <stddef.h>
  4. #include <stdint.h>
  5. typedef struct {
  6. uint32_t silence_time;
  7. uint16_t preamble_mark;
  8. uint16_t preamble_space;
  9. uint16_t bit1_mark;
  10. uint16_t bit1_space;
  11. uint16_t bit0_mark;
  12. uint16_t bit0_space;
  13. uint32_t preamble_tolerance;
  14. uint32_t bit_tolerance;
  15. } IrdaTimings;
  16. typedef struct {
  17. const char* name;
  18. uint8_t address_length;
  19. uint8_t command_length;
  20. uint32_t frequency;
  21. float duty_cycle;
  22. } IrdaProtocolSpecification;
  23. typedef const IrdaProtocolSpecification* (*IrdaGetProtocolSpec) (IrdaProtocol protocol);
  24. typedef void* (*IrdaAlloc) (void);
  25. typedef void (*IrdaFree) (void*);
  26. typedef void (*IrdaDecoderReset) (void*);
  27. typedef IrdaMessage* (*IrdaDecode) (void* ctx, bool level, uint32_t duration);
  28. typedef IrdaMessage* (*IrdaDecoderCheckReady) (void*);
  29. typedef void (*IrdaEncoderReset)(void* encoder, const IrdaMessage* message);
  30. typedef IrdaStatus (*IrdaEncode)(void* encoder, uint32_t* out, bool* polarity);
  31. static inline uint8_t reverse(uint8_t value) {
  32. uint8_t reverse_value = 0;
  33. for (int i = 0; i < 8; ++i) {
  34. reverse_value |= (value & (0x01 << i)) ? 1 << (7 - i) : 0;
  35. }
  36. return reverse_value;
  37. }