ci24r1.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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_CI24R1_H__
  15. #define __FW_CI24R1_H__
  16. #include "fw_hal.h"
  17. #include "string.h"
  18. #define CI24R1_PLOAD_WIDTH 16 // Payload width, 0:dynamic, [1,32]:fixed
  19. #define CI24R1_CSN P35
  20. #define CI24R1_MOSI P34
  21. #define CI24R1_SCK P32
  22. #define CI24R1_DATA_OUT() GPIO_P3_SetMode(GPIO_Pin_4, GPIO_Mode_Output_PP)
  23. #define CI24R1_DATA_IN() GPIO_P3_SetMode(GPIO_Pin_4, GPIO_Mode_Input_HIP)
  24. #define CI24R1_DATA_LOW() CI24R1_MOSI = 0
  25. #define CI24R1_DATA_HIGH() CI24R1_MOSI = 1
  26. #define CI24R1_DATA_READ() CI24R1_MOSI
  27. #define CI24R1_CLK_LOW() CI24R1_SCK = 0
  28. #define CI24R1_CLK_HIGH() CI24R1_SCK = 1
  29. #define CI24R1_NSS_LOW() CI24R1_CSN = 0
  30. #define CI24R1_NSS_HIGH() CI24R1_CSN = 1
  31. #define CI24R1_CE_LOW() CI24R1_WriteReg(CI24R1_CMD_CE_OFF, CI24R1_CMD_NOP)
  32. #define CI24R1_CE_HIGH() CI24R1_WriteReg(CI24R1_CMD_CE_ON, CI24R1_CMD_NOP)
  33. /**
  34. * REGISTER TABLE
  35. */
  36. /****************** CMD REGISTER ********************/
  37. #define CI24R1_CMD_R_REGISTER 0x00 // [000A AAAA] Register read
  38. #define CI24R1_CMD_W_REGISTER 0x20 // [001A AAAA] Register write
  39. #define CI24R1_CMD_R_RX_PAYLOAD 0x61 // Read RX payload
  40. #define CI24R1_CMD_W_TX_PAYLOAD 0xA0 // Write TX payload
  41. #define CI24R1_CMD_FLUSH_TX 0xE1 // Flush TX FIFO
  42. #define CI24R1_CMD_FLUSH_RX 0xE2 // Flush RX FIFO
  43. #define CI24R1_CMD_REUSE_TX_PL 0xE3 // Reuse TX Payload
  44. #define CI24R1_CMD_R_RX_PL_WID 0x60 // Read width of RX data
  45. #define CI24R1_CMD_W_ACK_PAYLOAD 0xA8 // Data with ACK
  46. #define CI24R1_CMD_W_TX_PAYLOAD_NOACK 0xB0 // TX Payload no ACK Request
  47. #define CI24R1_CMD_NOP 0xFF // No operation (used for reading status register)
  48. #define CI24R1_CMD_CE_ON 0x70 // CE high
  49. #define CI24R1_CMD_CE_OFF 0x71 // CE low
  50. #define CI24R1_CMD_SELSPI 0x74 // DATA pin as SPI
  51. #define CI24R1_CMD_SELIRQ 0x75 // DATA pin as IRQ
  52. /******************CONTROL REGISTER ******************/
  53. #define CI24R1_REG_CONFIG 0x00 // Configuration register
  54. #define CI24R1_REG_EN_AA 0x01 // Enable "Auto acknowledgment"
  55. #define CI24R1_REG_EN_RXADDR 0x02 // Enable RX addresses
  56. #define CI24R1_REG_SETUP_AW 0x03 // Setup of address widths
  57. #define CI24R1_REG_SETUP_RETR 0x04 // Setup of automatic re-transmit
  58. #define CI24R1_REG_RF_CH 0x05 // RF channel, [0,6] -> 0~125 -> 2400~2525 MHz
  59. #define CI24R1_REG_RF_SETUP 0x06 // RF setup
  60. #define CI24R1_REG_STATUS 0x07 // Status
  61. #define CI24R1_REG_OBSERVE_TX 0x08 // Transmit observe register
  62. #define CI24R1_REG_RSSI 0x09 // Data output and RSSI
  63. #define CI24R1_REG_RX_ADDR_P0 0x0A // Receive address data pipe 0, 40 bits
  64. #define CI24R1_REG_RX_ADDR_P1 0x0B // Receive address data pipe 1, 40 bits
  65. #define CI24R1_REG_RX_ADDR_P2 0x0C // Receive address data pipe 2
  66. #define CI24R1_REG_RX_ADDR_P3 0x0D // Receive address data pipe 3
  67. #define CI24R1_REG_RX_ADDR_P4 0x0E // Receive address data pipe 4
  68. #define CI24R1_REG_RX_ADDR_P5AF 0x0F // Receive address data pipe 5 and other settings
  69. // 0x0F can be switched to different function registers
  70. // according 0x06(CI24R1_REG_RF_SETUP) bit [0,2], defined
  71. // by CI24R1_EN_RXADDR_xxx
  72. #define CI24R1_REG_TX_ADDR 0x10 // Transmit address, 40 bits
  73. #define CI24R1_REG_RX_PW_P0 0x11 // Length of RX payload of pipe 0, set to 0 will stop receiving
  74. #define CI24R1_REG_RX_PW_P1 0x12 // Length of RX payload of pipe 1
  75. #define CI24R1_REG_RX_PW_P2 0x13 // Length of RX payload of pipe 2
  76. #define CI24R1_REG_RX_PW_P3 0x14 // Length of RX payload of pipe 3
  77. #define CI24R1_REG_RX_PW_P4 0x15 // Length of RX payload of pipe 4
  78. #define CI24R1_REG_RX_PW_P5 0x16 // Length of RX payload of pipe 5
  79. #define CI24R1_REG_FIFO_STATUS 0x17 // FIFO status
  80. #define CI24R1_REG_DYNPD 0x1C // Enable dynamic payload length
  81. #define CI24R1_REG_FEATURE 0x1D // Feature config
  82. /**************************** CONFIGs ************************************/
  83. #define CI24R1_EN_RXADDR_P5 0x00 // [0,1]->EN_AA[6,7], [2,3]->EN_RXADDR[6,7]
  84. #define CI24R1_EN_RXADDR_CRC 0x01
  85. #define CI24R1_EN_RXADDR_OSC_C 0x02
  86. #define CI24R1_EN_RXADDR_BT 0x04
  87. #define CI24R1_EN_RXADDR_BT_CRC_L 0x06
  88. #define CI24R1_EN_RXADDR_BT_CRC_M 0x07
  89. #define CI24R1_EN_RXADDR_BT_CRC_H 0x08
  90. #define CI24R1_RF_SETUP_11DB 0x07
  91. #define CI24R1_RF_SETUP_10DB 0x06
  92. #define CI24R1_RF_SETUP_9DB 0x05
  93. #define CI24R1_RF_SETUP_7DB 0x04
  94. #define CI24R1_RF_SETUP_3DB 0x03
  95. #define CI24R1_RF_SETUP__1DB 0x02
  96. #define CI24R1_RF_SETUP__4DB 0x01
  97. #define CI24R1_RF_SETUP__9DB 0x00
  98. #define CI24R1_RF_SETUP_250K 0x20
  99. #define CI24R1_RF_SETUP_1M 0x00
  100. #define CI24R1_RF_SETUP_2M 0x08
  101. #define CI24R1_FLAG_RX_READY 0x40 // RX_DR bit (data ready RX FIFO interrupt)
  102. #define CI24R1_FLAG_TX_SENT 0x20 // TX_DS bit (data sent TX FIFO interrupt)
  103. #define CI24R1_FLAG_MAX_RT 0x10 // MAX_RT bit (maximum number of TX re-transmits interrupt)
  104. #define CI24R1_PLOAD_MAX_WIDTH 32 // Max payload width
  105. #define CI24R1_TEST_ADDR "CI24R"
  106. /******************* FUNCTION DECLARE *******************/
  107. void CI24R1_WriteReg(uint8_t reg, uint8_t value);
  108. uint8_t CI24R1_ReadReg(uint8_t reg);
  109. void CI24R1_WriteFromBuf(uint8_t reg, const uint8_t *pBuf, uint8_t len);
  110. void CI24R1_ReadToBuf(uint8_t reg, uint8_t *pBuf, uint8_t len);
  111. uint8_t CI24R1_SPI_Test(void);
  112. void CI24R1_Init(void);
  113. void CI24R1_SetChannel(uint8_t channel);
  114. void CI24R1_SetTxAddress(uint8_t *address);
  115. void CI24R1_SetRxAddress(uint8_t *address);
  116. void CI24R1_SetTxMode(void);
  117. void CI24R1_SetRxMode(void);
  118. uint8_t CI24R1_Tx(uint8_t *ucPayload, uint8_t length);
  119. uint8_t CI24R1_Rx(void);
  120. uint8_t CI24R1_ReadStatus(void);
  121. uint8_t CI24R1_PrintStatus(void);
  122. #endif