LT8900MiLightRadio.h 2.4 KB

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