From 2fbf427e0a0bb61968731a652330710c8b49818f Mon Sep 17 00:00:00 2001 From: coreglitch Date: Thu, 25 Feb 2021 13:29:00 +0300 Subject: [PATCH] Switch sub-1GHz band (#349) * switch band * extract subghz api to files --- .../cc1101-workaround/cc1101-workaround.cpp | 37 ++++++++++++++----- .../targets/api-hal-include/api-hal-subghz.h | 18 +++++++++ firmware/targets/api-hal-include/api-hal.h | 1 + firmware/targets/f4/api-hal/api-hal-subghz.c | 5 +++ firmware/targets/f4/api-hal/api-hal.c | 2 +- firmware/targets/f5/api-hal/api-hal-subghz.c | 19 ++++++++++ firmware/targets/f5/api-hal/api-hal.c | 2 +- flash_otp_version.sh | 4 +- 8 files changed, 74 insertions(+), 14 deletions(-) create mode 100644 firmware/targets/api-hal-include/api-hal-subghz.h create mode 100644 firmware/targets/f4/api-hal/api-hal-subghz.c create mode 100644 firmware/targets/f5/api-hal/api-hal-subghz.c diff --git a/applications/cc1101-workaround/cc1101-workaround.cpp b/applications/cc1101-workaround/cc1101-workaround.cpp index 514bae35..5f849836 100644 --- a/applications/cc1101-workaround/cc1101-workaround.cpp +++ b/applications/cc1101-workaround/cc1101-workaround.cpp @@ -211,17 +211,17 @@ void tx_config(CC1101* cc1101) { // TODO: reg values not affetcts const Band bands[] = { - {300., {0x00, 0x00, 0x00}, 0, 255, 74}, + {301., {0x00, 0x00, 0x00}, 0, 255, 74}, {315., {0x00, 0x00, 0x00}, 0, 255, 74}, - {348., {0x00, 0x00, 0x00}, 0, 255, 74}, - {386., {0x00, 0x00, 0x00}, 0, 255, 74}, + {346., {0x00, 0x00, 0x00}, 0, 255, 74}, + {385., {0x00, 0x00, 0x00}, 0, 255, 74}, {433.92, {0x00, 0x00, 0x00}, 0, 255, 74}, {438.9, {0x00, 0x00, 0x00}, 0, 255, 74}, - {464., {0x00, 0x00, 0x00}, 0, 255, 74}, - {779., {0x00, 0x00, 0x00}, 0, 255, 74}, + {463., {0x00, 0x00, 0x00}, 0, 255, 74}, + {781., {0x00, 0x00, 0x00}, 0, 255, 74}, {868., {0x00, 0x00, 0x00}, 0, 255, 74}, {915., {0x00, 0x00, 0x00}, 0, 255, 74}, - {928., {0x00, 0x00, 0x00}, 0, 255, 74}, + {925., {0x00, 0x00, 0x00}, 0, 255, 74}, }; const FreqConfig FREQ_LIST[] = { @@ -278,6 +278,7 @@ typedef struct { int16_t last_rssi; size_t tx_level; bool need_cc1101_conf; + RfBand rf_band; } State; static void render_callback(Canvas* canvas, void* ctx) { @@ -328,10 +329,15 @@ static void render_callback(Canvas* canvas, void* ctx) { { char buf[24]; - sprintf(buf, "tx level: %d dBm", TX_LEVELS[state->tx_level].dbm); + // sprintf(buf, "tx level: %d dBm", TX_LEVELS[state->tx_level].dbm); + sprintf(buf, "RF band: %d", (uint8_t)state->rf_band); canvas_set_font(canvas, FontSecondary); - canvas_draw_str(canvas, 2, 63, buf); + if(state->rf_band == RfBandIsolation) { + canvas_draw_str(canvas, 2, 63, "RF band: isolation"); + } else { + canvas_draw_str(canvas, 2, 63, buf); + } } release_mutex((ValueMutex*)ctx, state); @@ -360,6 +366,7 @@ extern "C" int32_t cc1101_workaround(void* p) { _state.need_cc1101_conf = true; _state.last_rssi = 0; _state.tx_level = 0; + _state.rf_band = RfBand1; ValueMutex state_mutex; if(!init_mutex(&state_mutex, &_state, sizeof(State))) { @@ -469,7 +476,11 @@ extern "C" int32_t cc1101_workaround(void* p) { } */ - state->active_freq += 0.25; + if(state->rf_band < RfBand3) { + state->rf_band = (RfBand)((uint8_t)state->rf_band + 1); + } else { + state->active_freq += 0.25; + } state->need_cc1101_conf = true; } @@ -483,7 +494,11 @@ extern "C" int32_t cc1101_workaround(void* p) { } */ - state->active_freq -= 0.25; + if(state->rf_band > RfBandIsolation) { + state->rf_band = (RfBand)((uint8_t)state->rf_band - 1); + } else { + state->active_freq -= 0.25; + } state->need_cc1101_conf = true; } @@ -518,6 +533,8 @@ extern "C" int32_t cc1101_workaround(void* p) { gpio_write(&cc1101_g0_gpio, false); } + api_hal_rf_band_set(state->rf_band); + state->need_cc1101_conf = false; } diff --git a/firmware/targets/api-hal-include/api-hal-subghz.h b/firmware/targets/api-hal-include/api-hal-subghz.h new file mode 100644 index 00000000..1321bcb3 --- /dev/null +++ b/firmware/targets/api-hal-include/api-hal-subghz.h @@ -0,0 +1,18 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + RfBandIsolation = 0, + RfBand1 = 1, + RfBand2 = 2, + RfBand3 = 3 +} RfBand; + +void api_hal_rf_band_set(RfBand band); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/firmware/targets/api-hal-include/api-hal.h b/firmware/targets/api-hal-include/api-hal.h index 60eedbef..f547da45 100644 --- a/firmware/targets/api-hal-include/api-hal.h +++ b/firmware/targets/api-hal-include/api-hal.h @@ -21,5 +21,6 @@ template struct STOP_EXTERNING_ME {}; #include "api-hal-bt.h" #include "api-hal-spi.h" #include "api-hal-flash.h" +#include "api-hal-subghz.h" void api_hal_init(); diff --git a/firmware/targets/f4/api-hal/api-hal-subghz.c b/firmware/targets/f4/api-hal/api-hal-subghz.c new file mode 100644 index 00000000..3474bdf7 --- /dev/null +++ b/firmware/targets/f4/api-hal/api-hal-subghz.c @@ -0,0 +1,5 @@ +#include "api-hal-subghz.h" + +void api_hal_rf_band_set(RfBand band) { + +} \ No newline at end of file diff --git a/firmware/targets/f4/api-hal/api-hal.c b/firmware/targets/f4/api-hal/api-hal.c index f337be81..70fe3108 100644 --- a/firmware/targets/f4/api-hal/api-hal.c +++ b/firmware/targets/f4/api-hal/api-hal.c @@ -7,4 +7,4 @@ void api_hal_init() { api_hal_i2c_init(); api_hal_power_init(); api_hal_light_init(); -} +} \ No newline at end of file diff --git a/firmware/targets/f5/api-hal/api-hal-subghz.c b/firmware/targets/f5/api-hal/api-hal-subghz.c new file mode 100644 index 00000000..297f06b5 --- /dev/null +++ b/firmware/targets/f5/api-hal/api-hal-subghz.c @@ -0,0 +1,19 @@ +#include "api-hal-subghz.h" +#include +#include "main.h" + +void api_hal_rf_band_set(RfBand band) { + if (band == RfBand1) { + LL_GPIO_ResetOutputPin(PA_SW_0_GPIO_Port, PA_SW_0_Pin); + LL_GPIO_SetOutputPin(PA_SW_1_GPIO_Port, PA_SW_1_Pin); + } else if (band == RfBand2) { + LL_GPIO_SetOutputPin(PA_SW_0_GPIO_Port, PA_SW_0_Pin); + LL_GPIO_ResetOutputPin(PA_SW_1_GPIO_Port, PA_SW_1_Pin); + } else if (band == RfBand3) { + LL_GPIO_SetOutputPin(PA_SW_0_GPIO_Port, PA_SW_0_Pin); + LL_GPIO_SetOutputPin(PA_SW_1_GPIO_Port, PA_SW_1_Pin); + } else if (band == RfBandIsolation) { + LL_GPIO_ResetOutputPin(PA_SW_0_GPIO_Port, PA_SW_0_Pin); + LL_GPIO_ResetOutputPin(PA_SW_1_GPIO_Port, PA_SW_1_Pin); + } +} diff --git a/firmware/targets/f5/api-hal/api-hal.c b/firmware/targets/f5/api-hal/api-hal.c index 70fe3108..f337be81 100644 --- a/firmware/targets/f5/api-hal/api-hal.c +++ b/firmware/targets/f5/api-hal/api-hal.c @@ -7,4 +7,4 @@ void api_hal_init() { api_hal_i2c_init(); api_hal_power_init(); api_hal_light_init(); -} \ No newline at end of file +} diff --git a/flash_otp_version.sh b/flash_otp_version.sh index 1bfe1411..0a9526d4 100755 --- a/flash_otp_version.sh +++ b/flash_otp_version.sh @@ -12,6 +12,6 @@ if [ ! -f $1 ]; then exit fi -STM32_Programmer_CLI -c port=swd -d $1 0x1FFF7000 +STM32_Programmer_CLI -c port=usb1 -d $1 0x1FFF7000 -STM32_Programmer_CLI -c port=swd -r8 0x1FFF7000 8 +STM32_Programmer_CLI -c port=usb1 -r8 0x1FFF7000 8