custom_presets.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. #include <cc1101_regs.h>
  2. /* ========================== DATA RATE SETTINGS ===============================
  3. *
  4. * This is how to configure registers MDMCFG3 and MDMCFG4.
  5. *
  6. * MDMCFG3 is the data rate mantissa, the exponent is in MDMCFG4,
  7. * last 4 bits of the register.
  8. *
  9. * The rate (assuming 26Mhz crystal) is calculated as follows:
  10. *
  11. * ((256+MDMCFG3)*(2^MDMCFG4:0..3bits)) / 2^28 * 26000000.
  12. *
  13. * For instance for the default values of MDMCFG3[0..3] (34) and MDMCFG4 (12):
  14. *
  15. * ((256+34)*(2^12))/(2^28)*26000000 = 115051.2688000000, that is 115KBaud
  16. *
  17. * ============================ BANDWIDTH FILTER ===============================
  18. *
  19. * Bandwidth filter setting:
  20. *
  21. * BW filter as just 16 possibilities depending on how the first nibble
  22. * (first 4 bits) of the MDMCFG4 bits are set. Instead of providing the
  23. * formula, it is simpler to show all the values of the nibble and the
  24. * corresponding bandwidth filter.
  25. *
  26. * 0 812khz
  27. * 1 650khz
  28. * 2 541khz
  29. * 3 464khz
  30. * 4 406khz
  31. * 5 325khz
  32. * 6 270khz
  33. * 7 232khz
  34. * 8 203khz
  35. * 9 162khz
  36. * a 135khz
  37. * b 116khz
  38. * c 102khz
  39. * d 82 khz
  40. * e 68 khz
  41. * f 58 khz
  42. *
  43. * ============================== FSK DEVIATION ================================
  44. *
  45. * FSK deviation is controlled by the DEVIATION register. In Ruby:
  46. *
  47. * dev = (26000000.0/2**17)*(8+(deviation&7))*(2**(deviation>>4&7))
  48. *
  49. * deviation&7 (last three bits) is the deviation mantissa, while
  50. * deviation>>4&7 (bits 6,5,4) are the exponent.
  51. *
  52. * Deviations values according to certain configuration of DEVIATION:
  53. *
  54. * 0x04 -> 2.380371 kHz
  55. * 0x24 -> 9.521484 kHz
  56. * 0x34 -> 19.042969 Khz
  57. * 0x40 -> 25.390625 Khz
  58. * 0x43 -> 34.912109 Khz
  59. * 0x45 -> 41.259765 Khz
  60. * 0x47 -> 47.607422 kHz
  61. */
  62. /* 20 KBaud, 2FSK, 28.56 kHz deviation, 325 Khz bandwidth filter. */
  63. static uint8_t protoview_subghz_tpms1_fsk_async_regs[][2] = {
  64. /* GPIO GD0 */
  65. {CC1101_IOCFG0, 0x0D}, // GD0 as async serial data output/input
  66. /* Frequency Synthesizer Control */
  67. {CC1101_FSCTRL1, 0x06}, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
  68. /* Packet engine */
  69. {CC1101_PKTCTRL0, 0x32}, // Async, continious, no whitening
  70. {CC1101_PKTCTRL1, 0x04},
  71. // // Modem Configuration
  72. {CC1101_MDMCFG0, 0x00},
  73. {CC1101_MDMCFG1, 0x02},
  74. {CC1101_MDMCFG2,
  75. 0x04}, // Format 2-FSK/FM, No preamble/sync, Disable (current optimized). Other code reading TPMS uses GFSK, but should be the same when in RX mode.
  76. {CC1101_MDMCFG3, 0x93}, // Data rate is 20kBaud
  77. {CC1101_MDMCFG4, 0x59}, // Rx bandwidth filter is 325 kHz
  78. {CC1101_DEVIATN, 0x41}, // Deviation 28.56 kHz
  79. /* Main Radio Control State Machine */
  80. {CC1101_MCSM0, 0x18}, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
  81. /* Frequency Offset Compensation Configuration */
  82. {CC1101_FOCCFG,
  83. 0x16}, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
  84. /* Automatic Gain Control */
  85. {CC1101_AGCCTRL0,
  86. 0x91}, //10 - Medium hysteresis, medium asymmetric dead zone, medium gain ; 01 - 16 samples agc; 00 - Normal AGC, 01 - 8dB boundary
  87. {CC1101_AGCCTRL1,
  88. 0x00}, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
  89. {CC1101_AGCCTRL2, 0x07}, // 00 - DVGA all; 000 - MAX LNA+LNA2; 111 - MAIN_TARGET 42 dB
  90. /* Wake on radio and timeouts control */
  91. {CC1101_WORCTRL, 0xFB}, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
  92. /* Frontend configuration */
  93. {CC1101_FREND0, 0x10}, // Adjusts current TX LO buffer
  94. {CC1101_FREND1, 0x56},
  95. /* End */
  96. {0, 0},
  97. /* CC1101 2FSK PATABLE. */
  98. {0xC0, 0},
  99. {0, 0},
  100. {0, 0},
  101. {0, 0}};
  102. /* This is like the default Flipper OOK 640Khz bandwidth preset, but
  103. * the bandwidth is changed to 10kBaud to accomodate TPMS frequency. */
  104. static const uint8_t protoview_subghz_tpms2_ook_async_regs[][2] = {
  105. /* GPIO GD0 */
  106. {CC1101_IOCFG0, 0x0D}, // GD0 as async serial data output/input
  107. /* FIFO and internals */
  108. {CC1101_FIFOTHR, 0x07}, // The only important bit is ADC_RETENTION
  109. /* Packet engine */
  110. {CC1101_PKTCTRL0, 0x32}, // Async, continious, no whitening
  111. /* Frequency Synthesizer Control */
  112. {CC1101_FSCTRL1, 0x06}, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
  113. // Modem Configuration
  114. {CC1101_MDMCFG0, 0x00}, // Channel spacing is 25kHz
  115. {CC1101_MDMCFG1, 0x00}, // Channel spacing is 25kHz
  116. {CC1101_MDMCFG2, 0x30}, // Format ASK/OOK, No preamble/sync
  117. {CC1101_MDMCFG3, 0x93}, // Data rate is 10kBaud
  118. {CC1101_MDMCFG4, 0x18}, // Rx BW filter is 650.000kHz
  119. /* Main Radio Control State Machine */
  120. {CC1101_MCSM0, 0x18}, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
  121. /* Frequency Offset Compensation Configuration */
  122. {CC1101_FOCCFG,
  123. 0x18}, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
  124. /* Automatic Gain Control */
  125. {CC1101_AGCCTRL0,
  126. 0x91}, // 10 - Medium hysteresis, medium asymmetric dead zone, medium gain ; 01 - 16 samples agc; 00 - Normal AGC, 01 - 8dB boundary
  127. {CC1101_AGCCTRL1,
  128. 0x0}, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
  129. {CC1101_AGCCTRL2, 0x07}, // 00 - DVGA all; 000 - MAX LNA+LNA2; 111 - MAIN_TARGET 42 dB
  130. /* Wake on radio and timeouts control */
  131. {CC1101_WORCTRL, 0xFB}, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
  132. /* Frontend configuration */
  133. {CC1101_FREND0, 0x11}, // Adjusts current TX LO buffer + high is PATABLE[1]
  134. {CC1101_FREND1, 0xB6}, //
  135. /* End */
  136. {0, 0},
  137. /* CC1101 OOK PATABLE. */
  138. {0, 0xC0},
  139. {0, 0},
  140. {0, 0},
  141. {0, 0}};
  142. /* GFSK 19k dev, 325 Khz filter, 20kBaud. Different AGI settings.
  143. * Works well with Toyota. */
  144. static uint8_t protoview_subghz_tpms3_gfsk_async_regs[][2] = {
  145. /* GPIO GD0 */
  146. {CC1101_IOCFG0, 0x0D}, // GD0 as async serial data output/input
  147. /* Frequency Synthesizer Control */
  148. {CC1101_FSCTRL1, 0x06}, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
  149. /* Packet engine */
  150. {CC1101_PKTCTRL0, 0x32}, // Async, continious, no whitening
  151. {CC1101_PKTCTRL1, 0x04},
  152. // // Modem Configuration
  153. {CC1101_MDMCFG0, 0x00},
  154. {CC1101_MDMCFG1, 0x02}, // 2 is the channel spacing exponet: not used
  155. {CC1101_MDMCFG2, 0x10}, // GFSK without any other check
  156. {CC1101_MDMCFG3, 0x93}, // Data rate is 20kBaud
  157. {CC1101_MDMCFG4, 0x59}, // Rx bandwidth filter is 325 kHz
  158. {CC1101_DEVIATN, 0x34}, // Deviation 19.04 Khz.
  159. /* Main Radio Control State Machine */
  160. {CC1101_MCSM0, 0x18}, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
  161. /* Frequency Offset Compensation Configuration */
  162. {CC1101_FOCCFG,
  163. 0x16}, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
  164. /* Automatic Gain Control */
  165. {CC1101_AGCCTRL0, 0x80},
  166. {CC1101_AGCCTRL1, 0x58},
  167. {CC1101_AGCCTRL2, 0x87},
  168. /* Wake on radio and timeouts control */
  169. {CC1101_WORCTRL, 0xFB}, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
  170. /* Frontend configuration */
  171. {CC1101_FREND0, 0x10}, // Adjusts current TX LO buffer
  172. {CC1101_FREND1, 0x56},
  173. /* End */
  174. {0, 0},
  175. /* CC1101 2FSK PATABLE. */
  176. {0xC0, 0},
  177. {0, 0},
  178. {0, 0},
  179. {0, 0}};
  180. /* 40 KBaud, 2FSK, 28 kHz deviation, 270 Khz bandwidth filter. */
  181. static uint8_t protoview_subghz_40k_fsk_async_regs[][2] = {
  182. /* GPIO GD0 */
  183. {CC1101_IOCFG0, 0x0D}, // GD0 as async serial data output/input
  184. /* Frequency Synthesizer Control */
  185. {CC1101_FSCTRL1, 0x06}, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
  186. /* Packet engine */
  187. {CC1101_PKTCTRL0, 0x32}, // Async, continious, no whitening
  188. {CC1101_PKTCTRL1, 0x04},
  189. // // Modem Configuration
  190. {CC1101_MDMCFG0, 0x00},
  191. {CC1101_MDMCFG1, 0x02},
  192. {CC1101_MDMCFG2,
  193. 0x04}, // Format 2-FSK/FM, No preamble/sync, Disable (current optimized). Other code reading TPMS uses GFSK, but should be the same when in RX mode.
  194. {CC1101_MDMCFG3, 0x93}, // Data rate is 40kBaud
  195. {CC1101_MDMCFG4, 0x6A}, // 6 = BW filter 270kHz, A = Data rate exp
  196. {CC1101_DEVIATN, 0x41}, // Deviation 28kHz
  197. /* Main Radio Control State Machine */
  198. {CC1101_MCSM0, 0x18}, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
  199. /* Frequency Offset Compensation Configuration */
  200. {CC1101_FOCCFG,
  201. 0x16}, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
  202. /* Automatic Gain Control */
  203. {CC1101_AGCCTRL0,
  204. 0x91}, //10 - Medium hysteresis, medium asymmetric dead zone, medium gain ; 01 - 16 samples agc; 00 - Normal AGC, 01 - 8dB boundary
  205. {CC1101_AGCCTRL1,
  206. 0x00}, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
  207. {CC1101_AGCCTRL2, 0x07}, // 00 - DVGA all; 000 - MAX LNA+LNA2; 111 - MAIN_TARGET 42 dB
  208. /* Wake on radio and timeouts control */
  209. {CC1101_WORCTRL, 0xFB}, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
  210. /* Frontend configuration */
  211. {CC1101_FREND0, 0x10}, // Adjusts current TX LO buffer
  212. {CC1101_FREND1, 0x56},
  213. /* End */
  214. {0, 0},
  215. /* CC1101 2FSK PATABLE. */
  216. {0xC0, 0},
  217. {0, 0},
  218. {0, 0},
  219. {0, 0}};
  220. /* This is like the default Flipper OOK 640Khz bandwidth preset, but
  221. * the bandwidth is changed to 40kBaud, in order to receive signals
  222. * with a pulse width ~25us/30us. */
  223. static const uint8_t protoview_subghz_40k_ook_async_regs[][2] = {
  224. /* GPIO GD0 */
  225. {CC1101_IOCFG0, 0x0D}, // GD0 as async serial data output/input
  226. /* FIFO and internals */
  227. {CC1101_FIFOTHR, 0x07}, // The only important bit is ADC_RETENTION
  228. /* Packet engine */
  229. {CC1101_PKTCTRL0, 0x32}, // Async, continious, no whitening
  230. /* Frequency Synthesizer Control */
  231. {CC1101_FSCTRL1, 0x06}, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
  232. // Modem Configuration
  233. {CC1101_MDMCFG0, 0x00}, // Channel spacing is 25kHz
  234. {CC1101_MDMCFG1, 0x00}, // Channel spacing is 25kHz
  235. {CC1101_MDMCFG2, 0x30}, // Format ASK/OOK, No preamble/sync
  236. {CC1101_MDMCFG3, 0x93}, // Data rate is 40kBaud
  237. {CC1101_MDMCFG4, 0x1A}, // Rx BW filter is 650.000kHz
  238. /* Main Radio Control State Machine */
  239. {CC1101_MCSM0, 0x18}, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
  240. /* Frequency Offset Compensation Configuration */
  241. {CC1101_FOCCFG,
  242. 0x18}, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
  243. /* Automatic Gain Control */
  244. {CC1101_AGCCTRL0,
  245. 0x91}, // 10 - Medium hysteresis, medium asymmetric dead zone, medium gain ; 01 - 16 samples agc; 00 - Normal AGC, 01 - 8dB boundary
  246. {CC1101_AGCCTRL1,
  247. 0x0}, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
  248. {CC1101_AGCCTRL2, 0x07}, // 00 - DVGA all; 000 - MAX LNA+LNA2; 111 - MAIN_TARGET 42 dB
  249. /* Wake on radio and timeouts control */
  250. {CC1101_WORCTRL, 0xFB}, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
  251. /* Frontend configuration */
  252. {CC1101_FREND0, 0x11}, // Adjusts current TX LO buffer + high is PATABLE[1]
  253. {CC1101_FREND1, 0xB6}, //
  254. /* End */
  255. {0, 0},
  256. /* CC1101 OOK PATABLE. */
  257. {0, 0xC0},
  258. {0, 0},
  259. {0, 0},
  260. {0, 0}};