From 6bf4592ae972598d2ef046674fe9c75e357703e6 Mon Sep 17 00:00:00 2001 From: eadmaster <925171+eadmaster@users.noreply.github.com> Date: Sat, 10 Aug 2024 16:04:49 +0200 Subject: [PATCH 1/7] added support for cc1101 raw send (#66), cleanups --- src/core/serialcmds.cpp | 6 +-- src/core/settings.cpp | 2 +- src/modules/rf/rf.cpp | 116 +++++++++++++++++++++++++++------------- src/modules/rf/rf.h | 2 +- 4 files changed, 83 insertions(+), 43 deletions(-) diff --git a/src/core/serialcmds.cpp b/src/core/serialcmds.cpp index fa454794..2fa178f9 100644 --- a/src/core/serialcmds.cpp +++ b/src/core/serialcmds.cpp @@ -229,7 +229,7 @@ bool processSerialCommand(String cmd_str) { // flipperzero-like cmd https://docs.flipper.net/development/cli/#wLVht // e.g. subghz tx 0000000000200001 868250000 403 10 // https://forum.flipper.net/t/friedland-libra-48249sl-wireless-doorbell-request/4528/20 // {hex_key} {frequency} {te} {count} - // subghz tx 000000000044553C 433920000 174 10 + // subghz tx 0000000000445533 433920000 174 10 const char* args = cmd_str.c_str() + strlen("subghz tx"); uint64_t key=0; unsigned long frequency=433920000; @@ -237,10 +237,10 @@ bool processSerialCommand(String cmd_str) { unsigned int count=10; if(strlen(args)<=1) return false; if(sscanf(args, " %llx %lu %u %u", &key, &frequency, &te, &count)<=0) return false; // missing 1 req arg + unsigned int bits=24; // TODO: compute from key if(!initRfModule("tx", float(frequency/1000000.0))) return false; // check valid frequency and init the rf module - unsigned int bits=64; // TODO: compute from key - //RCSwitch_send( hexStringToDecimal(txt.c_str()) , bits, pulse, protocol, repeat); RCSwitch_send( key, bits, te, 1, count ); + deinitRfModule(); return true; } diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 97795c4d..a4c55cd5 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -283,7 +283,7 @@ void setRFModuleMenu() { */ }; delay(200); - loopOptions(options); // TODO: pre-select current value of RfModule + loopOptions(options, idx); // 2fix: idx highlight not working? delay(200); EEPROM.begin(EEPROMSIZE); // open eeprom if(result == 1) { diff --git a/src/modules/rf/rf.cpp b/src/modules/rf/rf.cpp index e4742c62..0e015005 100644 --- a/src/modules/rf/rf.cpp +++ b/src/modules/rf/rf.cpp @@ -90,7 +90,7 @@ void rf_spectrum() { //@IncursioHack - https://github.com/IncursioHack ----thank tft.fillScreen(TFT_BLACK); tft.setTextSize(1); tft.println(""); - tft.println(" RF433 - Spectrum"); + tft.println(" RF - Spectrum"); pinMode(RfRx, INPUT); initRMT(); @@ -128,15 +128,25 @@ void rf_spectrum() { //@IncursioHack - https://github.com/IncursioHack ----thank void rf_jammerFull() { //@IncursioHack - https://github.com/IncursioHack - thanks @EversonPereira - rfcardputer - pinMode(RfTx, OUTPUT); + // init rf module + int nTransmitterPin = RfTx; + if(!initRfModule("tx")) return; + if(RfModule == 1) { // CC1101 in use + #ifdef USE_CC1101_VIA_SPI + nTransmitterPin = CC1101_GDO0_PIN; + #else + return; + #endif + } + tft.fillScreen(TFT_BLACK); tft.println(""); - tft.println(" RF433 - Jammer Full"); + tft.println(" RF - Jammer Full"); tft.println(""); tft.println(""); tft.setTextSize(2); sendRF = true; - digitalWrite(RfTx, HIGH); // Turn on Jammer + digitalWrite(nTransmitterPin, HIGH); // Turn on Jammer int tmr0=millis(); // control total jammer time; tft.println("Sending... Press ESC to stop."); while (sendRF) { @@ -146,15 +156,24 @@ void rf_jammerFull() { //@IncursioHack - https://github.com/IncursioHack - than break; } } - digitalWrite(RfTx, LOW); // Turn Jammer OFF + deinitRfModule(); // Turn Jammer OFF } void rf_jammerIntermittent() { //@IncursioHack - https://github.com/IncursioHack - thanks @EversonPereira - rfcardputer - pinMode(RfTx, OUTPUT); + int nTransmitterPin = RfTx; + if(!initRfModule("tx")) return; + if(RfModule == 1) { // CC1101 in use + #ifdef USE_CC1101_VIA_SPI + nTransmitterPin = CC1101_GDO0_PIN; + #else + return; + #endif + } + tft.fillScreen(TFT_BLACK); tft.println(""); - tft.println(" RF433 - Jammer Intermittent"); + tft.println(" RF - Jammer Intermittent"); tft.println(""); tft.println(""); tft.setTextSize(2); @@ -170,13 +189,13 @@ void rf_jammerIntermittent() { //@IncursioHack - https://github.com/IncursioHack returnToMenu=true; break; } - digitalWrite(RfTx, HIGH); // Ativa o pino + digitalWrite(nTransmitterPin, HIGH); // Ativa o pino // keeps the pin active for a while and increase increase for (int widthsize = 1; widthsize <= (1 + sequence); widthsize++) { delayMicroseconds(50); } - digitalWrite(RfTx, LOW); // Desativa o pino + digitalWrite(nTransmitterPin, LOW); // Desativa o pino // keeps the pin inactive for the same time as before for (int widthsize = 1; widthsize <= (1 + sequence); widthsize++) { delayMicroseconds(50); @@ -185,7 +204,7 @@ void rf_jammerIntermittent() { //@IncursioHack - https://github.com/IncursioHack } } - digitalWrite(RfTx, LOW); // Deactivate pin + deinitRfModule(); } @@ -197,10 +216,7 @@ void RCSwitch_send(uint64_t data, unsigned int bits, int pulse, int protocol, in if(RfModule==1) { #ifdef USE_CC1101_VIA_SPI - pinMode(CC1101_GDO0_PIN, OUTPUT); mySwitch.enableTransmit(CC1101_GDO0_PIN); - ELECHOUSE_cc1101.setPA(12); // set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max! - ELECHOUSE_cc1101.SetTx(); #else Serial.println("USE_CC1101_VIA_SPI not defined"); return; // not enabled for this board @@ -220,7 +236,7 @@ void RCSwitch_send(uint64_t data, unsigned int bits, int pulse, int protocol, in Serial.println(pulse); Serial.println(protocol); Serial.println(repeat); - * */ + */ mySwitch.disableTransmit(); @@ -390,6 +406,9 @@ void deinitRfModule() { bool initRfModule(String mode, float frequency) { + // use default frequency if no one is passed + if(!frequency) frequency = RfFreq; + if(RfModule == 1) { // CC1101 in use #ifdef USE_CC1101_VIA_SPI if (ELECHOUSE_cc1101.getCC1101()){ // Check the CC1101 Spi connection. @@ -404,22 +423,24 @@ bool initRfModule(String mode, float frequency) { // make sure it is in idle state when changing frequency and other parameters // "If any frequency programming register is altered when the frequency synthesizer is running, the synthesizer may give an undesired response. Hence, the frequency programming should only be updated when the radio is in the IDLE state." https://github.com/LSatan/SmartRC-CC1101-Driver-Lib/issues/65 ELECHOUSE_cc1101.setSidle(); - - // use default frequency if no one is passed - if(!frequency) frequency = RfFreq; - + if(!(frequency>=300 && frequency<=928)) // TODO: check all supported subranges: 300-348 MHZ, 387-464MHZ and 779-928MHZ. return false; // else ELECHOUSE_cc1101.setMHZ(frequency); - /* MEMO: cannot change other params after this is executed -> moved in the caller func - if(mode=="tx") + /* MEMO: cannot change other params after this is executed */ + if(mode=="tx") { + pinMode(CC1101_GDO0_PIN, OUTPUT); ELECHOUSE_cc1101.setPA(12); // set TxPower. The following settings are possible depending ELECHOUSE_cc1101.SetTx(); - else + } + else if(mode=="rx") { + pinMode(CC1101_GDO0_PIN, INPUT); ELECHOUSE_cc1101.SetRx(); - */ + } + // else if mode is unspecified wont start TX/RX mode here -> done by the caller + #else // TODO: PCA9554-based implmentation return false; @@ -437,7 +458,8 @@ bool initRfModule(String mode, float frequency) { //if(RfTx==0) RfTx=GROVE_SDA; // quick fix pinMode(RfTx, OUTPUT); digitalWrite(RfTx, LED_OFF); - } else { + } + else if(mode=="rx") { // Rx Mode gsetRfRxPin(false); //if(RfRx==0) RfRx=GROVE_SCL; // quick fix @@ -469,10 +491,8 @@ bool RCSwitch_Read_Raw(float frequency) { #ifdef CC1101_GDO2_PIN rcswitch.enableReceive(CC1101_GDO2_PIN); #else - pinMode(CC1101_GDO0_PIN, INPUT); rcswitch.enableReceive(CC1101_GDO0_PIN); #endif - ELECHOUSE_cc1101.SetRx(); #else return false; #endif @@ -601,9 +621,16 @@ bool RCSwitch_Read_Raw(float frequency) { // ported from https://github.com/sui77/rc-switch/blob/3a536a172ab752f3c7a58d831c5075ca24fd920b/RCSwitch.cpp -void RCSwitch_RAW_Bit_send(int nTransmitterPin, RfCodes data) { - if (nTransmitterPin == -1) - return; +void RCSwitch_RAW_Bit_send(RfCodes data) { + int nTransmitterPin = RfTx; + if(RfModule==1) { + #ifdef USE_CC1101_VIA_SPI + nTransmitterPin = CC1101_GDO0_PIN; + #else + return; + #endif + } + if (data.data == "") return; bool currentlogiclevel = false; @@ -626,19 +653,27 @@ void RCSwitch_RAW_Bit_send(int nTransmitterPin, RfCodes data) { digitalWrite(nTransmitterPin, currentlogiclevel ? HIGH : LOW); delayMicroseconds(data.te); - Serial.print(currentBit); - Serial.print("="); - Serial.println(currentlogiclevel); + //Serial.print(currentBit); + //Serial.print("="); + //Serial.println(currentlogiclevel); currentBit--; } digitalWrite(nTransmitterPin, LOW); } } -void RCSwitch_RAW_send(int nTransmitterPin, int * ptrtransmittimings) { - if (nTransmitterPin == -1) - return; + +void RCSwitch_RAW_send(int * ptrtransmittimings) { + int nTransmitterPin = RfTx; + if(RfModule==1) { + #ifdef USE_CC1101_VIA_SPI + nTransmitterPin = CC1101_GDO0_PIN; + #else + return; + #endif + } + if (!ptrtransmittimings) return; @@ -744,7 +779,7 @@ void sendRfCommand(struct RfCodes rfcode) { } // init transmitter - if(!initRfModule("tx", frequency/1000000.0)) return; + if(!initRfModule("", frequency/1000000.0)) return; if(RfModule == 1) { // CC1101 in use #ifdef USE_CC1101_VIA_SPI // derived from https://github.com/LSatan/SmartRC-CC1101-Driver-Lib/blob/master/examples/Rc-Switch%20examples%20cc1101/SendDemo_cc1101/SendDemo_cc1101.ino @@ -752,7 +787,11 @@ void sendRfCommand(struct RfCodes rfcode) { if(deviation) ELECHOUSE_cc1101.setDeviation(deviation); if(rxBW) ELECHOUSE_cc1101.setRxBW(rxBW); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz. if(dataRate) ELECHOUSE_cc1101.setDRate(dataRate); + pinMode(CC1101_GDO0_PIN, OUTPUT); + ELECHOUSE_cc1101.setPA(12); // set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max! + ELECHOUSE_cc1101.SetTx(); #else + Serial.println("USE_CC1101_VIA_SPI not defined"); return; #endif } else { @@ -762,6 +801,7 @@ void sendRfCommand(struct RfCodes rfcode) { Serial.println(modulation); return; } + initRfModule("tx", frequency/1000000.0); } if(protocol == "RAW") { @@ -792,14 +832,14 @@ void sendRfCommand(struct RfCodes rfcode) { // send rf command displayRedStripe("Sending..",TFT_WHITE,FGCOLOR); - RCSwitch_RAW_send(RfTx, transmittimings); + RCSwitch_RAW_send(transmittimings); free(transmittimings); } else if (protocol == "BinRAW") { rfcode.data = hexStrToBinStr(rfcode.data); // transform from "00 01 02 ... FF" into "00000000 00000001 00000010 .... 11111111" - Serial.println(rfcode.data); + //Serial.println(rfcode.data); rfcode.data.trim(); - RCSwitch_RAW_Bit_send(RfTx,rfcode); + RCSwitch_RAW_Bit_send(rfcode); } else if(protocol == "RcSwitch") { diff --git a/src/modules/rf/rf.h b/src/modules/rf/rf.h index 2aab46a0..951b18a2 100644 --- a/src/modules/rf/rf.h +++ b/src/modules/rf/rf.h @@ -22,6 +22,6 @@ bool RCSwitch_Read_Raw(float frequency=0); void RCSwitch_send(uint64_t data, unsigned int bits, int pulse=0, int protocol=1, int repeat=10); void addToRecentCodes(struct RfCodes rfcode); void sendRfCommand(struct RfCodes rfcode); -bool initRfModule(String mode, float frequency=0); +bool initRfModule(String mode="", float frequency=0); void initCC1101once(); void deinitRfModule(); \ No newline at end of file From a7a47a340fd314872088028313fbfcad0e2dd991 Mon Sep 17 00:00:00 2001 From: eadmaster <925171+eadmaster@users.noreply.github.com> Date: Sat, 10 Aug 2024 17:20:53 +0200 Subject: [PATCH 2/7] added gpio serial cmds --- src/core/serialcmds.cpp | 93 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 88 insertions(+), 5 deletions(-) diff --git a/src/core/serialcmds.cpp b/src/core/serialcmds.cpp index 2fa178f9..5b9aa975 100644 --- a/src/core/serialcmds.cpp +++ b/src/core/serialcmds.cpp @@ -47,6 +47,29 @@ void startSerialCommandsHandlerTask() { } +bool is_free_gpio_pin(int pin_no ){ + // check if pin_no is usable for general GPIO + std::vector usable_pins = {GROVE_SDA, GROVE_SCL}; + + #if defined(STICK_C_PLUS2) || defined(STICK_C_PLUS) + usable_pins.insert(usable_pins.end(), { 25, 26, 32, 33, 0 }); + #elif defined(ESP32S3DEVKITC1) + usable_pins.insert(usable_pins.end(), { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, // GPIO1 to GPIO25 + 33, // GPIO33 + 38, 39, 40, 41, 42, 43, 44, // GPIO38 to GPIO44 + 47, 48 // GPIO47 to GPIO48 + }); + #endif + + for (int usable_pin : usable_pins) + if (pin_no == usable_pin ) + return true; + // else + return false; +} + + void SerialPrintHexString(uint64_t val) { char s[18] = {0}; //snprintf(s, 10, "%x", val); @@ -229,7 +252,7 @@ bool processSerialCommand(String cmd_str) { // flipperzero-like cmd https://docs.flipper.net/development/cli/#wLVht // e.g. subghz tx 0000000000200001 868250000 403 10 // https://forum.flipper.net/t/friedland-libra-48249sl-wireless-doorbell-request/4528/20 // {hex_key} {frequency} {te} {count} - // subghz tx 0000000000445533 433920000 174 10 + // subghz tx 445533 433920000 174 10 const char* args = cmd_str.c_str() + strlen("subghz tx"); uint64_t key=0; unsigned long frequency=433920000; @@ -424,11 +447,71 @@ bool processSerialCommand(String cmd_str) { //esp_timer_stop(screensaver_timer); return true; } + + // gpio cmds https://docs.flipper.net/development/cli/#aqA4b + if(cmd_str.startsWith("gpio mode ")) { + const char* args = cmd_str.c_str() + strlen("gpio mode "); + int pin_number=-1; + int mode=0; + if (sscanf(args, "%d %d", &pin_number, &mode) == 2) { + // check usable pins according to the env + if(mode>=0 && mode<=1 && is_free_gpio_pin(pin_number)) { + pinMode(pin_number, mode); + return true; + } + } + // else + Serial.print("invalid args: "); + Serial.println(args); + return false; + } + if(cmd_str.startsWith("gpio set ")) { + const char* args = cmd_str.c_str() + strlen("gpio set "); + int pin_number=-1; + int value=0; + if (sscanf(args, "%d %d", &pin_number, &value) == 2) { + // check usable pins according to the env + if(value>=0 && value<=1 && is_free_gpio_pin(pin_number)) { + digitalWrite(pin_number, value); + return true; + } + } + // else + Serial.print("invalid args: "); + Serial.println(args); + return false; + } + if(cmd_str.startsWith("gpio read ")) { + const char* args = cmd_str.c_str() + strlen("gpio read "); + int pin_number=-1; + if (sscanf(args, "%d", &pin_number) == 1) { + // check usable pins according to the env + if(is_free_gpio_pin(pin_number)) { + Serial.println(digitalRead(pin_number)); + return true; + } + } + // else + Serial.print("invalid args: "); + Serial.println(args); + return false; + } - // TODO: "storage" cmd to manage files https://docs.flipper.net/development/cli/#Xgais - - // TODO: "gpio" cmds https://docs.flipper.net/development/cli/#aqA4b - + // "storage" cmd to manage files https://docs.flipper.net/development/cli/#Xgais + /* + if(cmd_str.startsWith("storage read ")) { + String txt = ""; + String filepath = cmd_str.substring(strlen("storage read "), cmd_str.length()); + filepath.trim(); + if(!filepath.startsWith("/")) filepath = "/" + filepath; // add "/" if missing + if(SD.exists(filepath)) txt = readSmallFile(SD, filepath);; + if(LittleFS.exists(filepath)) txt = readSmallFile(LittleFS, filepath); + if(txt.length()!=0) { + Serial.println(txt); + return true; + } else return false; + }*/ + // TODO: more commands https://docs.flipper.net/development/cli#0Z9fs Serial.println("unsupported serial command: " + cmd_str); From 084f5d747299eb0a8b8d554ade199ec992278776 Mon Sep 17 00:00:00 2001 From: eadmaster <925171+eadmaster@users.noreply.github.com> Date: Sat, 10 Aug 2024 18:29:01 +0200 Subject: [PATCH 3/7] added i2c scanner serial cmd --- src/core/serialcmds.cpp | 45 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/core/serialcmds.cpp b/src/core/serialcmds.cpp index 5b9aa975..a0e9bcda 100644 --- a/src/core/serialcmds.cpp +++ b/src/core/serialcmds.cpp @@ -5,7 +5,7 @@ //#include #include "cJSON.h" #include // for PRIu64 - +#include #include "sd_functions.h" #include "settings.h" @@ -497,8 +497,49 @@ bool processSerialCommand(String cmd_str) { return false; } + if(cmd_str == "i2c") { + // scan for connected i2c modules + // derived from https://learn.adafruit.com/scanning-i2c-addresses/arduino + Wire.begin(GROVE_SDA, GROVE_SCL); + byte error, address; + int nDevices; + Serial.println("Scanning..."); + nDevices = 0; + for(address = 1; address < 127; address++ ) + { + // The i2c_scanner uses the return value of + // the Write.endTransmisstion to see if + // a device did acknowledge to the address. + Wire.beginTransmission(address); + error = Wire.endTransmission(); + if (error == 0) + { + Serial.print("I2C device found at address 0x"); + if (address<16) + Serial.print("0"); + Serial.print(address,HEX); + Serial.println(" !"); + nDevices++; + } + else if (error==4) + { + Serial.print("Unknown error at address 0x"); + if (address<16) + Serial.print("0"); + Serial.println(address,HEX); + } + } // end for + if (nDevices == 0) { + Serial.println("No I2C devices found\n"); + return false; + } else { + Serial.println("done\n"); + return true; + } + } + + /* WIP // "storage" cmd to manage files https://docs.flipper.net/development/cli/#Xgais - /* if(cmd_str.startsWith("storage read ")) { String txt = ""; String filepath = cmd_str.substring(strlen("storage read "), cmd_str.length()); From ee6f92c967ac147586a77d431ee226ea6be30d1c Mon Sep 17 00:00:00 2001 From: eadmaster <925171+eadmaster@users.noreply.github.com> Date: Sat, 10 Aug 2024 19:29:03 +0200 Subject: [PATCH 4/7] disabled CC1101 on cardputer (#164) --- platformio.ini | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index f7a01c72..96b98807 100644 --- a/platformio.ini +++ b/platformio.ini @@ -310,9 +310,8 @@ build_flags = ;Radio Frequency (one pin modules) pin setting -DRF_TX_PINS='{ {"M5 RF433T", GROVE_SDA}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}' -DRF_RX_PINS='{ {"M5 RF433R", GROVE_SCL}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}' - -DUSE_CC1101_VIA_SPI ; connection pins using microSD sniffer module https://www.sparkfun.com/products/9419 https://docs.m5stack.com/en/core/Cardputer - -DUSE_CC1101_VIA_SPI + ;-DUSE_CC1101_VIA_SPI -DCC1101_GDO0_PIN=GROVE_SDA -DCC1101_SS_PIN=GROVE_SCL ; chip select -DCC1101_MOSI_PIN=14 From 3999ddcdf2818ac54036ef288c35eb24ce64a997 Mon Sep 17 00:00:00 2001 From: eadmaster <925171+eadmaster@users.noreply.github.com> Date: Sat, 10 Aug 2024 19:31:17 +0200 Subject: [PATCH 5/7] added info, free, settings and factory_reset serial cmds --- src/core/serialcmds.cpp | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/core/serialcmds.cpp b/src/core/serialcmds.cpp index a0e9bcda..2a125690 100644 --- a/src/core/serialcmds.cpp +++ b/src/core/serialcmds.cpp @@ -497,6 +497,51 @@ bool processSerialCommand(String cmd_str) { return false; } + if(cmd_str == "factory_reset") { + // remove config file and recreate + if(SD.exists(CONFIG_FILE)) SD.remove(CONFIG_FILE); + if(LittleFS.exists(CONFIG_FILE)) LittleFS.remove(CONFIG_FILE); + // TODO: need to reset EEPROM too? + getConfigs(); // recreate config file if it does not exists + return true; + } + + if(cmd_str == "settings") { + // view current settings + JsonObject setting = settings[0]; + serializeJsonPretty(settings, Serial); + Serial.println(""); + return true; + } + if(cmd_str == "info device" || cmd_str == "!") { + Serial.print("Bruce v"); + Serial.println(BRUCE_VERSION); + // https://github.com/espressif/arduino-esp32/blob/master/libraries/ESP32/examples/ChipID/GetChipID/GetChipID.ino + Serial.printf("Chip is %s (revision v%d)\n", ESP.getChipModel(), ESP.getChipRevision()); + Serial.printf("Detected flash size: %d\n", ESP.getFlashChipSize()); + //Serial.printf("This chip has %d cores\n", ESP.getChipCores()); + //Serial.printf("CPU Freq is %d\n", ESP.getCpuFreqMHz()); + // Features: WiFi, BLE, Embedded Flash 8MB (GD) + // Crystal is 40MHz + // MAC: 24:58:7c:5b:24:5c + return true; + } + + if(cmd_str == "free") { + // report free memory + Serial.print("Total heap: "); + Serial.println(ESP.getHeapSize()); + Serial.print("Free heap: "); + Serial.println(ESP.getFreeHeap()); + if(psramFound()) { + Serial.print("Total PSRAM: "); + Serial.println(ESP.getPsramSize()); + Serial.print("Free PSRAM: "); + Serial.println(ESP.getFreePsram()); + } + return true; + } + if(cmd_str == "i2c") { // scan for connected i2c modules // derived from https://learn.adafruit.com/scanning-i2c-addresses/arduino @@ -553,6 +598,10 @@ bool processSerialCommand(String cmd_str) { } else return false; }*/ + // TODO: date + // TODO: uptime + // TODO: help + // TODO: more commands https://docs.flipper.net/development/cli#0Z9fs Serial.println("unsupported serial command: " + cmd_str); From 8a351558e79728f97780b58217a8efa3f3e33dd4 Mon Sep 17 00:00:00 2001 From: eadmaster <925171+eadmaster@users.noreply.github.com> Date: Sun, 11 Aug 2024 04:39:03 +0200 Subject: [PATCH 6/7] updated rf_spectrum for cc1101 --- src/modules/rf/rf.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/modules/rf/rf.cpp b/src/modules/rf/rf.cpp index 0e015005..d0ac4d36 100644 --- a/src/modules/rf/rf.cpp +++ b/src/modules/rf/rf.cpp @@ -69,7 +69,10 @@ void initRMT() { rmt_config_t rxconfig; rxconfig.rmt_mode = RMT_MODE_RX; rxconfig.channel = RMT_RX_CHANNEL; - rxconfig.gpio_num = gpio_num_t(RfRx); + if(RfModule==1) + rxconfig.gpio_num = gpio_num_t(CC1101_GDO0_PIN); + else + rxconfig.gpio_num = gpio_num_t(RfRx); rxconfig.clk_div = RMT_CLK_DIV; // RMT_DEFAULT_CLK_DIV=32 rxconfig.mem_block_num = 1; rxconfig.flags = 0; @@ -91,7 +94,7 @@ void rf_spectrum() { //@IncursioHack - https://github.com/IncursioHack ----thank tft.setTextSize(1); tft.println(""); tft.println(" RF - Spectrum"); - pinMode(RfRx, INPUT); + if(!initRfModule("rx", RfFreq)) return; initRMT(); RingbufHandle_t rb = nullptr; @@ -361,8 +364,6 @@ static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength) { return bin; } - - void initCC1101once() { // the init (); command may only be executed once in the entire program sequence. Otherwise problems can arise. https://github.com/LSatan/SmartRC-CC1101-Driver-Lib/issues/65 @@ -410,7 +411,9 @@ bool initRfModule(String mode, float frequency) { if(!frequency) frequency = RfFreq; if(RfModule == 1) { // CC1101 in use - #ifdef USE_CC1101_VIA_SPI + #ifdef USE_CC1101_VIA_SPI + ELECHOUSE_cc1101.Init(); + if (ELECHOUSE_cc1101.getCC1101()){ // Check the CC1101 Spi connection. Serial.println("cc1101 Connection OK"); } else { @@ -418,8 +421,6 @@ bool initRfModule(String mode, float frequency) { return false; } - ELECHOUSE_cc1101.Init(); - // make sure it is in idle state when changing frequency and other parameters // "If any frequency programming register is altered when the frequency synthesizer is running, the synthesizer may give an undesired response. Hence, the frequency programming should only be updated when the radio is in the IDLE state." https://github.com/LSatan/SmartRC-CC1101-Driver-Lib/issues/65 ELECHOUSE_cc1101.setSidle(); From 984a860a34a67971afbac5ba9e91071a4bcb8328 Mon Sep 17 00:00:00 2001 From: eadmaster <925171+eadmaster@users.noreply.github.com> Date: Sun, 11 Aug 2024 05:08:22 +0200 Subject: [PATCH 7/7] fixed build on the core series --- src/core/settings.cpp | 3 ++- src/modules/rf/rf.cpp | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core/settings.cpp b/src/core/settings.cpp index a4c55cd5..ff05f149 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -287,7 +287,8 @@ void setRFModuleMenu() { delay(200); EEPROM.begin(EEPROMSIZE); // open eeprom if(result == 1) { - #ifdef USE_CC1101_VIA_SPI + #ifdef USE_CC1101_VIA_SPI + ELECHOUSE_cc1101.Init(); if (ELECHOUSE_cc1101.getCC1101()){ RfModule=1; EEPROM.write(13, RfModule); //set the byte diff --git a/src/modules/rf/rf.cpp b/src/modules/rf/rf.cpp index d0ac4d36..960e30af 100644 --- a/src/modules/rf/rf.cpp +++ b/src/modules/rf/rf.cpp @@ -69,10 +69,11 @@ void initRMT() { rmt_config_t rxconfig; rxconfig.rmt_mode = RMT_MODE_RX; rxconfig.channel = RMT_RX_CHANNEL; + rxconfig.gpio_num = gpio_num_t(RfRx); + #ifdef USE_CC1101_VIA_SPI if(RfModule==1) rxconfig.gpio_num = gpio_num_t(CC1101_GDO0_PIN); - else - rxconfig.gpio_num = gpio_num_t(RfRx); + #endif rxconfig.clk_div = RMT_CLK_DIV; // RMT_DEFAULT_CLK_DIV=32 rxconfig.mem_block_num = 1; rxconfig.flags = 0;