MiLightRadioPL1167_LT8900.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 <MiLightRadioInterface.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 MiLightRadioPL1167_LT8900 : public MiLightRadioInterface{
  38. public:
  39. MiLightRadioPL1167_LT8900(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. private:
  48. void vInitRadioModule(MiLightRadioType type);
  49. void vSetSyncWord(uint16_t syncWord3, uint16_t syncWord2, uint16_t syncWord1, uint16_t syncWord0);
  50. uint16_t uiReadRegister(uint8_t reg);
  51. void regWrite16(byte ADDR, byte V1, byte V2, byte WAIT);
  52. uint8_t uiWriteRegister(uint8_t reg, uint16_t data);
  53. bool bAvailablePin(void);
  54. bool bAvailableRegister(void);
  55. void vStartListening(uint uiChannelToListenTo);
  56. void vResumeRX(void);
  57. int iReadRXBuffer(uint8_t *buffer, size_t maxBuffer);
  58. void vSetChannel(uint8_t channel);
  59. void vGenericSendPacket(int iMode, int iLength, byte *pbyFrame, byte byChannel );
  60. bool bCheckRadioConnection(void);
  61. bool sendPacket(uint8_t *data, size_t packetSize,byte byChannel);
  62. byte _pin_pktflag;
  63. byte _csPin;
  64. const MiLightRadioConfig& config;
  65. //uint32_t _prev_packet_id;
  66. uint8_t _channel = 0;
  67. uint8_t _packet[10];
  68. uint8_t _out_packet[10];
  69. bool _waiting;
  70. int _dupes_received;
  71. };
  72. #endif /* MILIGHTRADIO_H_ */