From 1d8ca65a61acc8ceaab708e0eb50f75d23aa69ee Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 4 Jan 2023 14:59:48 +0100 Subject: [PATCH] Support for custom CC1101 presets. --- app.h | 1 + app_subghz.c | 25 +++++++++++++++++-------- custom_presets.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 custom_presets.h diff --git a/app.h b/app.h index 4c809e593a4..bf80c50c15b 100644 --- a/app.h +++ b/app.h @@ -49,6 +49,7 @@ typedef enum { typedef struct { const char *name; FuriHalSubGhzPreset preset; + uint8_t *custom; } ProtoViewModulation; extern ProtoViewModulation ProtoViewModulations[]; /* In app_subghz.c */ diff --git a/app_subghz.c b/app_subghz.c index e89cab2149c..987dd1aac15 100644 --- a/app_subghz.c +++ b/app_subghz.c @@ -2,17 +2,19 @@ * See the LICENSE file for information about the license. */ #include "app.h" +#include "custom_presets.h" #include ProtoViewModulation ProtoViewModulations[] = { - {"OOK 650Khz", FuriHalSubGhzPresetOok650Async}, - {"OOK 270Khz", FuriHalSubGhzPresetOok270Async}, - {"2FSK 2.38Khz", FuriHalSubGhzPreset2FSKDev238Async}, - {"2FSK 47.6Khz", FuriHalSubGhzPreset2FSKDev476Async}, - {"MSK", FuriHalSubGhzPresetMSK99_97KbAsync}, - {"GFSK", FuriHalSubGhzPresetGFSK9_99KbAsync}, - {NULL, 0} /* End of list sentinel. */ + {"OOK 650Khz", FuriHalSubGhzPresetOok650Async, NULL}, + {"OOK 270Khz", FuriHalSubGhzPresetOok270Async, NULL}, + {"2FSK 2.38Khz", FuriHalSubGhzPreset2FSKDev238Async, NULL}, + {"2FSK 47.6Khz", FuriHalSubGhzPreset2FSKDev476Async, NULL}, + {"MSK", FuriHalSubGhzPresetMSK99_97KbAsync, NULL}, + {"GFSK", FuriHalSubGhzPresetGFSK9_99KbAsync, NULL}, + {"FSK for TPMS", 0, (uint8_t*)protoview_subghz_tpms_async_regs}, + {NULL, 0, NULL} /* End of list sentinel. */ }; /* Called after the application initialization in order to setup the @@ -23,7 +25,14 @@ void radio_begin(ProtoViewApp* app) { furi_assert(app); furi_hal_subghz_reset(); furi_hal_subghz_idle(); - furi_hal_subghz_load_preset(ProtoViewModulations[app->modulation].preset); + + /* The CC1101 preset can be either one of the standard presets, if + * the modulation "custom" field is NULL, or a custom preset we + * defined in custom_presets.h. */ + if (ProtoViewModulations[app->modulation].custom == NULL) + furi_hal_subghz_load_preset(ProtoViewModulations[app->modulation].preset); + else + furi_hal_subghz_load_custom_preset(ProtoViewModulations[app->modulation].custom); furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow); app->txrx->txrx_state = TxRxStateIDLE; } diff --git a/custom_presets.h b/custom_presets.h new file mode 100644 index 00000000000..cca03859f8a --- /dev/null +++ b/custom_presets.h @@ -0,0 +1,46 @@ +#include + +static uint8_t protoview_subghz_tpms_async_regs[][2] = { + /* GPIO GD0 */ + {CC1101_IOCFG0, 0x0D}, // GD0 as async serial data output/input + + /* Frequency Synthesizer Control */ + {CC1101_FSCTRL1, 0x06}, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz + + /* Packet engine */ + {CC1101_PKTCTRL0, 0x32}, // Async, continious, no whitening + {CC1101_PKTCTRL1, 0x04}, + + // // Modem Configuration + {CC1101_MDMCFG0, 0x00}, + {CC1101_MDMCFG1, 0x02}, + {CC1101_MDMCFG2, 0x04}, // Format 2-FSK/FM, No preamble/sync, Disable (current optimized) + {CC1101_MDMCFG3, 0x93}, // Data rate is 20kBaud + {CC1101_MDMCFG4, 0x59}, // Rx bandwidth filter is 325 kHz + {CC1101_DEVIATN, 0x41}, // Deviation 28.56 kHz + + /* Main Radio Control State Machine */ + {CC1101_MCSM0, 0x18}, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us) + + /* Frequency Offset Compensation Configuration */ + {CC1101_FOCCFG, + 0x16}, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off + + /* Automatic Gain Control */ + {CC1101_AGCCTRL0, + 0x91}, //10 - Medium hysteresis, medium asymmetric dead zone, medium gain ; 01 - 16 samples agc; 00 - Normal AGC, 01 - 8dB boundary + {CC1101_AGCCTRL1, + 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 + {CC1101_AGCCTRL2, 0x07}, // 00 - DVGA all; 000 - MAX LNA+LNA2; 111 - MAIN_TARGET 42 dB + + /* Wake on radio and timeouts control */ + {CC1101_WORCTRL, 0xFB}, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours + + /* Frontend configuration */ + {CC1101_FREND0, 0x10}, // Adjusts current TX LO buffer + {CC1101_FREND1, 0x56}, + + /* End */ + {0, 0}, +}; +