Skip to content

Commit

Permalink
reworked cc1101 init, added settings RfModule and RfFreq (pr3y#139), …
Browse files Browse the repository at this point in the history
…added subghz tx cmd
  • Loading branch information
eadmaster committed Aug 8, 2024
1 parent 0f5e226 commit c317dd9
Show file tree
Hide file tree
Showing 9 changed files with 422 additions and 220 deletions.
75 changes: 61 additions & 14 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ lib_deps =
ESP8266SAM
TinyGPSPlus
tinyu-zhao/FFT@^0.0.1
lsatan/SmartRC-CC1101-Driver-Lib@^2.5.7
;lsatan/SmartRC-CC1101-Driver-Lib@^2.5.7
https://github.com/bmorcelli/SmartRC-CC1101-Driver-Lib

[env:m5stack-cplus2]
platform = espressif32
Expand Down Expand Up @@ -101,6 +102,15 @@ build_flags =
-DRF_TX_PINS='{ {"M5 RF433T", GROVE_SDA}, {"G26",26}, {"G25",25}, {"G0",0}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}'
-DRF_RX_PINS='{ {"M5 RF433R", GROVE_SCL}, {"G26",26}, {"G25",25}, {"G0",0}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}'

; connection pins for CC1101 https://github.com/bmorcelli/io433/blob/master/platformio.ini
-DUSE_CC1101_VIA_SPI
-DCC1101_GDO0_PIN=25
-DCC1101_SS_PIN=26 ; chip select
-DCC1101_MOSI_PIN=32
-DCC1101_SCK_PIN=0
-DCC1101_MISO_PIN=33
;-DCC1101_GDO2_PIN=-1

;Battery ADC read pin
-DBAT_PIN=38

Expand Down Expand Up @@ -189,6 +199,15 @@ build_flags =
-DRF_TX_PINS='{ {"M5 RF433T", GROVE_SDA}, {"G26",26}, {"G25",25}, {"G0",0}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}'
-DRF_RX_PINS='{ {"M5 RF433R", GROVE_SCL}, {"G26",26}, {"G25",25}, {"G0",0}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}'

; connection pins for CC1101 https://github.com/bmorcelli/io433/blob/master/platformio.ini
-DUSE_CC1101_VIA_SPI
-DCC1101_GDO0_PIN=25
-DCC1101_SS_PIN=26 ; chip select
-DCC1101_MOSI_PIN=32
-DCC1101_SCK_PIN=0
-DCC1101_MISO_PIN=33
;-DCC1101_GDO2_PIN=-1

;Battery ADC read pin
-DBAT_PIN=10

Expand Down Expand Up @@ -292,7 +311,16 @@ 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
-DCC1101_GDO0_PIN=GROVE_SDA
-DCC1101_SS_PIN=GROVE_SCL ; chip select
-DCC1101_MOSI_PIN=14
-DCC1101_SCK_PIN=40
-DCC1101_MISO_PIN=39
;-DCC1101_GDO2_PIN=-1

;Screen Setup
-DHAS_SCREEN=1
-DROTATION=1
Expand Down Expand Up @@ -689,33 +717,50 @@ framework = arduino
build_flags =
${common.build_flags}
-DESP32S3DEVKITC1
-DUSB_as_HID=1
-DUSB_as_HID=1
; needed for serial
-DARDUINO_USB_CDC_ON_BOOT=1

; grove pins
; defaults from https://github.com/espressif/arduino-esp32/blob/master/variants/esp32s3/pins_arduino.h
-DGROVE_SDA=8 ; default RF TX pin
-DGROVE_SCL=9 ; default IR/RF RX pin
;-DALLOW_ALL_GPIO_FOR_IR_RF=1 ; Set this option to make use of all GPIOs, from 1 to 44 to be chosen, except TFT and SD pins

; ir led pin
-DIR_TX_PINS='{{"M5 IR Mod", GROVE_SDA}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}'
-DIR_RX_PINS='{{"M5 IR Mod", GROVE_SCL}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}'
-DLED=40
-DLED_ON=HIGH
-DLED_OFF=LOW

;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}}'

; sd card pins
; suggested https://github.com/espressif/esp-idf/tree/master/examples/storage/sd_card/sdmmc
-DSDCARD_CS=-1
-DSDCARD_SCK=-1
-DSDCARD_MISO=-1
-DSDCARD_MOSI=-1
; grove pins (SDA=default TX pin, SCL=default RX pin, for both IR and RF)
; defaults from https://github.com/espressif/arduino-esp32/blob/master/variants/esp32s3/pins_arduino.h
-DGROVE_SDA=8 ; default RF TX pin
-DGROVE_SCL=9 ; default IR/RF RX pin

; tft vars
-DROTATION=1
-DBACKLIGHT=-1 ; tft backlight pin
-DWIDTH=240
-DHEIGHT=135
-DMINBRIGHT=160 ; unused?

-DSMOOTH_FONT=1
-DTFT_DISPON=0x29
-DTFT_DISPOFF=0x28
-DTFT_CS=-1
-DTFT_DC=-1
-DTFT_RST=-1
-DTOUCH_CS=-1
-DTFT_MOSI=-1
-DTFT_SCLK=-1
-DTFT_BL=-1
; text sizes
-DFP=1
-DFM=2
Expand All @@ -725,21 +770,23 @@ build_flags =
;-DUP_BTN=2 ; also work as ESC
;-DDW_BTN=3 ; also work as NEXT
-DBTN_ALIAS='"OK"'

;Microphone
;-DMIC_SPM1423=1 ; uncomment to enable Applicable for SPM1423 device
;-DPIN_CLK=-1
;-DI2S_SCLK_PIN=-1
;-DI2S_DATA_PIN=-1
;-DPIN_DATA=-1
;CC1101 SPI connection pins, can use any on this board https://esp32.com/viewtopic.php?t=37729

;CC1101 SPI connection pins
; best connection pins for higher speed https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/peripherals/spi_master.html#gpio-matrix-and-io-mux
-DUSE_CC1101_VIA_SPI
-DCC1101_GDO0_PIN=9 ; RFSend (SPI2_IOMUX_PIN_NUM_HD / FSPIHD)
-DCC1101_SS_PIN=10
-DCC1101_MOSI_PIN=11
-DCC1101_GDO0_PIN=9
-DCC1101_SS_PIN=10
-DCC1101_MOSI_PIN=11
-DCC1101_SCK_PIN=12
-DCC1101_MISO_PIN=13
-DCC1101_GDO2_PIN=14 ; RFRecv (SPI2_IOMUX_PIN_NUM_CS / FSPIWP)
-DCC1101_MISO_PIN=13
;-DCC1101_GDO2_PIN=14 ; optional
lib_deps =
${common.lib_deps}

Expand Down
4 changes: 4 additions & 0 deletions src/core/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ extern int RfTx;

extern int RfRx;

extern int RfModule;

extern float RfFreq;

// Screen sleep control variables
extern unsigned long previousMillis;
extern bool isSleeping;
Expand Down
4 changes: 4 additions & 0 deletions src/core/main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ void configOptions(){
{"Ir RX Pin", [=]() { gsetIrRxPin(true); saveConfigs();}},
{"RF TX Pin", [=]() { gsetRfTxPin(true); saveConfigs();}},
{"RF RX Pin", [=]() { gsetRfRxPin(true); saveConfigs();}},
#ifdef USE_CC1101_VIA_SPI
{"RF Module", [=]() { setRFModuleMenu(); saveConfigs();}},
#endif
{"RF Frequency", [=]() { setRFFreqMenu(); saveConfigs();}},
{"Sleep", [=]() { setSleepMode(); }},
{"Restart", [=]() { ESP.restart(); }},
{"Main Menu", [=]() { backToMenu(); }},
Expand Down
53 changes: 36 additions & 17 deletions src/core/serialcmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ void handleSerialCommands() {
// try again on next iteration
return;
}

//log_d(cmd_str.c_str());
cmd_str.trim();
// case-insensitive matching only without filename args -- TODO: better solution for this
if(cmd_str.indexOf("from_file ") == -1)
cmd_str.toLowerCase();

bool r = processSerialCommand(cmd_str);
if(r) setup_gpio(); // temp fix for menu inf. loop
Expand All @@ -96,15 +90,24 @@ void handleSerialCommands() {

bool processSerialCommand(String cmd_str) {
// return true on success, false on error
// TODO: rewrite using https://github.com/SpacehuhnTech/SimpleCLI (auto-generated help and args checking)

cmd_str.trim();

if(cmd_str == "" ) { // empty
if(cmd_str == "" || cmd_str.startsWith("#") || cmd_str.startsWith(";") || cmd_str.startsWith("/")) {
// ignore empty lines and comments
return false;
}

// case-insensitive matching only without filename args -- TODO: better solution for this
if(cmd_str.indexOf("from_file ") == -1)
cmd_str.toLowerCase();

// switch on cmd_str
if(cmd_str.startsWith("ir") ) {

gsetIrTxPin(false);
//if(IrTx==0) IrTx = LED; // quickfix init issue? CARDPUTER is 44
gsetIrTxPin(false);
//if(IrTx==0) IrTx = LED; // quickfix init issue? CARDPUTER is 44

// ir tx <protocol> <address> <command>
// <protocol>: NEC, NECext, NEC42, NEC42ext, Samsung32, RC6, RC5, RC5X, SIRC, SIRC15, SIRC20, Kaseikyo, RCA
Expand Down Expand Up @@ -203,11 +206,13 @@ bool processSerialCommand(String cmd_str) {

if(cmd_str.startsWith("rf") || cmd_str.startsWith("subghz" )) {

if(cmd_str.startsWith("subghz rx")) {
float frequency=433.92; // TODO: custom frequency passed as arg. valid ranges for cc1101: 300-348 MHZ, 387-464MHZ and 779-928MHZ.
//String frequency_arg = cmd_str.substring(strlen("subghz rx"), cmd_str.length());
RCSwitch_Read_Raw(frequency);
return true;
if(cmd_str.startsWith("subghz rx")) {
const char* args = cmd_str.c_str() + strlen("subghz rx");
float frequency=RfFreq; // global default
if(strlen(args)>1) sscanf(args, " %f", &frequency);
//Serial.print("frequency:");
//Serial.println((int) frequency);
return RCSwitch_Read_Raw(frequency);
}
if(cmd_str.startsWith("subghz tx_from_file")) {
String filepath = cmd_str.substring(strlen("subghz tx_from_file "), cmd_str.length());
Expand All @@ -219,13 +224,25 @@ bool processSerialCommand(String cmd_str) {
// else file not found
return false;
}
/* TODO:

if(cmd_str.startsWith("subghz tx")) {
// 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}
* //RCSwitch_send( hexStringToDecimal(txt.c_str()) , bits, pulse, protocol, repeat);
}*/
// subghz tx 000000000044553C 433920000 174 10
const char* args = cmd_str.c_str() + strlen("subghz tx");
uint64_t key=0;
unsigned long frequency=433920000;
unsigned int te=0;
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
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 );
return true;
}

if(cmd_str.startsWith("rfsend")) {
// tasmota json command https://tasmota.github.io/docs/RF-Protocol/
Expand Down Expand Up @@ -265,6 +282,8 @@ bool processSerialCommand(String cmd_str) {
//Serial.println(dataStr);
//SerialPrintHexString(data);
//Serial.println(bits);

if(!initRfModule("tx")) return false;

RCSwitch_send(data, bits, pulse, protocol, repeat);

Expand Down
Loading

0 comments on commit c317dd9

Please sign in to comment.