irda_i.h 1.1 KB

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