LT8900MiLightRadio.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifdef ARDUINO
  2. #include "Arduino.h"
  3. #else
  4. #include <stdint.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #endif
  8. #include <MiLightRadioConfig.h>
  9. #include <MiLightButtons.h>
  10. #include <MiLightRadio.h>
  11. //#define DEBUG_PRINTF
  12. // Register defines
  13. #define REGISTER_READ 0b10000000 //bin
  14. #define REGISTER_WRITE 0b00000000 //bin
  15. #define REGISTER_MASK 0b01111111 //bin
  16. #define R_CHANNEL 7
  17. #define CHANNEL_RX_BIT 7
  18. #define CHANNEL_TX_BIT 8
  19. #define CHANNEL_MASK 0b01111111 ///bin
  20. #define STATUS_PKT_BIT_MASK 0x40
  21. #define R_STATUS 48
  22. #define STATUS_CRC_BIT 15
  23. #define R_FIFO 50
  24. #define R_FIFO_CONTROL 52
  25. #define R_SYNCWORD1 36
  26. #define R_SYNCWORD2 37
  27. #define R_SYNCWORD3 38
  28. #define R_SYNCWORD4 39
  29. //#define DEFAULT_TIME_BETWEEN_RETRANSMISSIONS_uS 350
  30. #define DEFAULT_TIME_BETWEEN_RETRANSMISSIONS_uS 0
  31. #ifndef MILIGHTRADIOPL1167_LT8900_H_
  32. #define MILIGHTRADIOPL1167_LT8900_H_
  33. class LT8900MiLightRadio : public MiLightRadio {
  34. public:
  35. LT8900MiLightRadio(byte byCSPin, byte byResetPin, byte byPktFlag, const MiLightRadioConfig& config);
  36. virtual int begin();
  37. virtual bool available();
  38. virtual int read(uint8_t frame[], size_t &frame_length);
  39. virtual int dupesReceived();
  40. virtual int write(uint8_t frame[], size_t frame_length);
  41. virtual int resend();
  42. virtual int configure();
  43. virtual const MiLightRadioConfig& config();
  44. private:
  45. void vInitRadioModule(MiLightRadioType type);
  46. void vSetSyncWord(uint16_t syncWord3, uint16_t syncWord2, uint16_t syncWord1, uint16_t syncWord0);
  47. uint16_t uiReadRegister(uint8_t reg);
  48. void regWrite16(byte ADDR, byte V1, byte V2, byte WAIT);
  49. uint8_t uiWriteRegister(uint8_t reg, uint16_t data);
  50. bool bAvailablePin(void);
  51. bool bAvailableRegister(void);
  52. void vStartListening(uint uiChannelToListenTo);
  53. void vResumeRX(void);
  54. int iReadRXBuffer(uint8_t *buffer, size_t maxBuffer);
  55. void vSetChannel(uint8_t channel);
  56. void vGenericSendPacket(int iMode, int iLength, byte *pbyFrame, byte byChannel );
  57. bool bCheckRadioConnection(void);
  58. bool sendPacket(uint8_t *data, size_t packetSize,byte byChannel);
  59. byte _pin_pktflag;
  60. byte _csPin;
  61. bool _bConnected;
  62. const MiLightRadioConfig& _config;
  63. uint8_t _channel;
  64. uint8_t _packet[10];
  65. uint8_t _out_packet[10];
  66. bool _waiting;
  67. int _dupes_received;
  68. };
  69. #endif