xl2400.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // Copyright 2021 IOsetting <iosetting(at)outlook.com>
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef __FW_XL2400_H__
  15. #define __FW_XL2400_H__
  16. #include "fw_hal.h"
  17. #include "string.h"
  18. #define XL2400_CSN P35
  19. #define XL2400_SCK P32
  20. #define XL2400_MOSI P34
  21. #define XL2400_PLOAD_WIDTH 32 // Payload width
  22. /**
  23. * REGISTER TABLE
  24. */
  25. /****************** SPI REGISTER ********************/
  26. #define XL2400_CMD_R_REGISTER 0x00 // [000A AAAA] Register read
  27. #define XL2400_CMD_W_REGISTER 0x20 // [001A AAAA] Register write
  28. #define XL2400_CMD_R_RX_PAYLOAD 0x61 // Read RX payload
  29. #define XL2400_CMD_W_TX_PAYLOAD 0xA0 // Write TX payload
  30. #define XL2400_CMD_FLUSH_TX 0xE1 // Flush TX FIFO
  31. #define XL2400_CMD_FLUSH_RX 0xE2 // Flush RX FIFO
  32. #define XL2400_CMD_REUSE_TX_PL 0xE3 // Reuse TX Payload
  33. #define XL2400_CMD_ACTIVATE 0x50 // ACTIVATE
  34. #define XL2400_CMD_DEACTIVATE 0x50 // DEACTIVATE
  35. #define XL2400_CMD_RST_FSPI 0x53 // RESET
  36. #define XL2400_CMD_R_RX_PL_WID 0x60 // Read width of RX data
  37. #define XL2400_CMD_W_ACK_PAYLOAD 0xA8 // Data with ACK
  38. #define XL2400_CMD_W_TX_PAYLOAD_NOACK 0xB0 // TX Payload no ACK Request
  39. #define XL2400_CMD_NOP 0xFF // No operation (used for reading status register)
  40. /******************CONTROL REGISTER ******************/
  41. #define XL2400_REG_CFG_TOP 0x00 // Configuration register, 20 bits
  42. #define XL2400_REG_EN_AA 0x01 // Enable "Auto acknowledgment"
  43. #define XL2400_REG_EN_RXADDR 0x02 // Enable RX addresses
  44. #define XL2400_REG_SETUP_AW 0x03 // Setup of address widths
  45. #define XL2400_REG_SETUP_RETR 0x04 // Setup of automatic re-transmit, 30 bits
  46. #define XL2400_REG_RF_CH 0x05 // RF channel, 22 bits
  47. #define XL2400_REG_RF_SETUP 0x06 // RF setup, 16 bits
  48. #define XL2400_REG_STATUS 0x07 // Status
  49. #define XL2400_REG_OBSERVE_TX 0x08 // Transmit observe register, 32 bits
  50. #define XL2400_REG_RSSI 0x09 // Data output and RSSI, 14 bits
  51. #define XL2400_REG_RX_ADDR_P0 0x0A // Receive address data pipe 0, 40 bits
  52. #define XL2400_REG_RX_ADDR_P1 0x0B // Receive address data pipe 1, 40 bits
  53. #define XL2400_REG_RX_ADDR_P2_P5 0x0C // Receive address data pipe 2~5, 32 bits
  54. #define XL2400_REG_BER_RESULT 0x0D // BER(PN9) test result, 64 bits
  55. #define XL2400_REG_AGC_SETTING 0x0E // AGC settings, 32 bits
  56. #define XL2400_REG_PGA_SETTING 0x0F // PGA settings, 39 bits
  57. #define XL2400_REG_TX_ADDR 0x10 // Transmit address, 40 bits
  58. #define XL2400_REG_RX_PW_PX 0x11 // Number of bytes in RX payload in data pipe 0 ~ pipe 5, 48 bits
  59. #define XL2400_REG_ANALOG_CFG0 0x12 // Analog config 0, 128 bits
  60. #define XL2400_REG_ANALOG_CFG1 0x13 // Analog config 1, 128 bits
  61. #define XL2400_REG_ANALOG_CFG2 0x14 // Analog config 2, 128 bits
  62. #define XL2400_REG_ANALOG_CFG3 0x15 // Analog config 3, 128 bits
  63. #define XL2400_REG_FIFO_STATUS 0x17 // FIFO status, 20 bits
  64. #define XL2400_REG_RSSIREC 0x18 // RSSI recorder feature, 32 bits
  65. #define XL2400_REG_TXPROC_CFG 0x19 // TX Process configuration, 29 bits
  66. #define XL2400_REG_RXPROC_CFG 0x1A // RX Process configuration, 40 bits
  67. #define XL2400_REG_DYNPD 0x1C // Enable dynamic payload length
  68. #define XL2400_REG_FEATURE 0x1D // Feature config
  69. #define XL2400_REG_RAMP_CFG 0x1E // PA Ramp Configuration, 88 bits
  70. /**************************** CONFIGs ************************************/
  71. #define XL2400_PL_WIDTH_MAX 64 // Max payload width
  72. #define XL2400_RF_10DB 0x3F
  73. #define XL2400_RF_9DB 0x38
  74. #define XL2400_RF_8DB 0x34
  75. #define XL2400_RF_7DB 0x30
  76. #define XL2400_RF_6DB 0x2C // 250Kbps Maximum
  77. #define XL2400_RF_5DB 0x28
  78. #define XL2400_RF_4DB 0x24
  79. #define XL2400_RF_3DB 0x20
  80. #define XL2400_RF_2DB 0x14
  81. #define XL2400_RF_0DB 0x10 // 1Mbps Maximum
  82. #define XL2400_RF__2DB 0x0C
  83. #define XL2400_RF__6DB 0x08
  84. #define XL2400_RF__12DB 0x04
  85. #define XL2400_RF__18DB 0x02
  86. #define XL2400_RF__24DB 0x01
  87. #define XL2400_RF_DR_1M 0x02 // 1Mbps
  88. #define XL2400_RF_DR_250K 0x22 // 250Kbps
  89. #define RX_DR_FLAG 0X40 // Data ready
  90. #define TX_DS_FLAG 0X20 // Data sent
  91. #define RX_TX_CMP_FLAG 0X60 // Data sent & acked
  92. #define MAX_RT_FLAG 0X10 // Max retried
  93. #define XL2400_TEST_ADDR "XL240"
  94. /******************* FUNCTION DECLARE *******************/
  95. void XL2400_WriteReg(uint8_t reg, uint8_t value);
  96. uint8_t XL2400_ReadReg(uint8_t reg);
  97. void XL2400_WriteFromBuf(uint8_t reg, const uint8_t *pBuf, uint8_t len);
  98. void XL2400_ReadToBuf(uint8_t reg, uint8_t len);
  99. void XL2400_WriteBack(uint8_t reg, uint8_t len);
  100. void XL2400_CE_Low(void);
  101. void XL2400_CE_High(void);
  102. uint8_t XL2400_SPI_Test(void);
  103. void XL2400_Init(void);
  104. void XL2400_SetChannel(uint8_t channel);
  105. void XL2400_SetTxAddress(uint8_t *address);
  106. void XL2400_SetRxAddress(uint8_t *address);
  107. void XL2400_SetPower(uint8_t power);
  108. void XL2400_Sleep(void);
  109. void XL2400_WakeUp(void);
  110. uint8_t XL2400_RxCalibrate(void);
  111. void XL2400_SetTxMode(void);
  112. void XL2400_SetRxMode(void);
  113. uint8_t XL2400_Tx(uint8_t *ucPayload, uint8_t length);
  114. uint8_t XL2400_Rx(void);
  115. uint8_t XL2400_ReadStatus(void);
  116. void XL2400_ClearStatus(void);
  117. void XL2400_FlushRxTX(void);
  118. void XL2400_CarrierTest(void);
  119. uint8_t XL2400_PrintStatus(void);
  120. #endif