| 215 | const std::vector<KeeloqKey> &KeeloqKeystore::get_keys() { return keys; } |
| 216 | |
| 217 | bool initRfModule(String mode, float frequency) { |
| 218 | // use default frequency if no one is passed |
| 219 | if (!frequency) frequency = bruceConfigPins.rfFreq; |
| 220 | |
| 221 | if (bruceConfigPins.rfModule == CC1101_SPI_MODULE) { // CC1101 in use |
| 222 | if (bruceConfigPins.CC1101_bus.mosi == (gpio_num_t)TFT_MOSI && |
| 223 | bruceConfigPins.CC1101_bus.mosi != GPIO_NUM_NC) { // (T_EMBED), CORE2 and others |
| 224 | #if TFT_MOSI > 0 |
| 225 | initCC1101once(&tft.getSPIinstance()); |
| 226 | #else |
| 227 | yield(); |
| 228 | #endif |
| 229 | } else if (bruceConfigPins.CC1101_bus.mosi == |
| 230 | bruceConfigPins.SDCARD_bus.mosi) { // (CARDPUTER) and (ESP32S3DEVKITC1) and devices that |
| 231 | // share CC1101 pin with only SDCard |
| 232 | initCC1101once(&sdcardSPI); |
| 233 | } else if (bruceConfigPins.NRF24_bus.mosi == bruceConfigPins.CC1101_bus.mosi && |
| 234 | bruceConfigPins.CC1101_bus.mosi != |
| 235 | bruceConfigPins.SDCARD_bus |
| 236 | .mosi) { // This board uses the same Bus for NRF and CC1101, but with |
| 237 | // different CS pins, different from Stick_Cs down below.. |
| 238 | |
| 239 | CC_NRF_SPI.end(); // Closes in case it was already in use, it will overwrite the attempt |
| 240 | // of SD start over to save configurations |
| 241 | delay(10); |
| 242 | if (!CC_NRF_SPI.begin( |
| 243 | bruceConfigPins.CC1101_bus.sck, |
| 244 | bruceConfigPins.CC1101_bus.miso, |
| 245 | bruceConfigPins.CC1101_bus.mosi |
| 246 | )) { |
| 247 | Serial.println("Failed to start CC1101 SPI on NRF24 pins!"); |
| 248 | } |
| 249 | |
| 250 | initCC1101once(&CC_NRF_SPI); |
| 251 | } else { |
| 252 | // (STICK_C_PLUS) || (STICK_C_PLUS2) and others that doesn´t share SPI with other devices (need to |
| 253 | // change it when Bruce board comes to shore) |
| 254 | // make sure to use BeginEndLogic for StickCs in the shared pins (not bus) config |
| 255 | ELECHOUSE_cc1101.setBeginEndLogic(true); |
| 256 | initCC1101once(NULL); |
| 257 | } |
| 258 | ELECHOUSE_cc1101.Init(); |
| 259 | if (ELECHOUSE_cc1101.getCC1101()) { // Check the CC1101 Spi connection. |
| 260 | Serial.println("cc1101 Connection OK"); |
| 261 | } else { |
| 262 | displayError("CC1101 not found"); |
| 263 | Serial.println("cc1101 Connection Error"); |
| 264 | return false; |
| 265 | } |
| 266 | |
| 267 | // make sure it is in idle state when changing frequency and other parameters |
| 268 | // "If any frequency programming register is altered when the frequency synthesizer is running, the |
| 269 | // synthesizer may give an undesired response. Hence, the frequency programming should only be updated |
| 270 | // when the radio is in the IDLE state." https://github.com/LSatan/SmartRC-CC1101-Driver-Lib/issues/65 |
| 271 | // ELECHOUSE_cc1101.setSidle(); |
| 272 | // Serial.println("cc1101 setSidle();"); |
| 273 | |
| 274 | if (!((frequency >= 280 && frequency <= 350) || (frequency >= 387 && frequency <= 468) || |