From 6a17bb848392bb77dbbe62a73de3823903c25d6a Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Thu, 7 Sep 2023 11:31:30 +0200 Subject: [PATCH] ttwrplus: implemented radio band detection. --- platform/drivers/baseband/SA8x8.c | 2 +- platform/drivers/baseband/radio_ttwrplus.cpp | 7 ++-- platform/targets/ttwrplus/platform.c | 36 +++++++++++++++++--- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/platform/drivers/baseband/SA8x8.c b/platform/drivers/baseband/SA8x8.c index 68739e73..e53fa814 100644 --- a/platform/drivers/baseband/SA8x8.c +++ b/platform/drivers/baseband/SA8x8.c @@ -118,7 +118,7 @@ static inline bool checkFwVersion() uint8_t patch; uint8_t release; - char *fwVersionStr = sa8x8_getFwVersion(); + const char *fwVersionStr = sa8x8_getFwVersion(); sscanf(fwVersionStr, "sa8x8-fw/v%hhu.%hhu.%hhu.r%hhu", &major, &minor, &patch, &release); diff --git a/platform/drivers/baseband/radio_ttwrplus.cpp b/platform/drivers/baseband/radio_ttwrplus.cpp index 1eb1e977..153aee7d 100644 --- a/platform/drivers/baseband/radio_ttwrplus.cpp +++ b/platform/drivers/baseband/radio_ttwrplus.cpp @@ -39,11 +39,8 @@ void radio_init(const rtxStatus_t *rtxState) config = rtxState; radioStatus = OFF; - // Turn on baseband - pmu_setBasebandPower(true); - - // Init the SA8x8 mode, set serial to 115200 baud - sa8x8_init(); + // Set SA8x8 serial to 115200 baud, module has alredy been initialized in + // platform_init() sa8x8_enableHSMode(); /* diff --git a/platform/targets/ttwrplus/platform.c b/platform/targets/ttwrplus/platform.c index 5b0ba545..fc576f07 100644 --- a/platform/targets/ttwrplus/platform.c +++ b/platform/targets/ttwrplus/platform.c @@ -25,7 +25,8 @@ #include #include #include -#include "pmu.h" +#include +#include #define BUTTON_PTT_NODE DT_NODELABEL(button_ptt) @@ -33,14 +34,16 @@ static const struct gpio_dt_spec button_ptt = GPIO_DT_SPEC_GET_OR(BUTTON_PTT_NOD static const struct device *const qdec_dev = DEVICE_DT_GET(DT_ALIAS(qdec0)); static const struct device *const led_dev = DEVICE_DT_GET(DT_ALIAS(led0)); -static const hwInfo_t hwInfo = +static hwInfo_t hwInfo = { .name = "ttwrplus", .hw_version = 0, - .uhf_band = 1, + .uhf_band = 0, .vhf_band = 0, - .uhf_maxFreq = 430, - .uhf_minFreq = 440, + .uhf_maxFreq = 0, + .uhf_minFreq = 0, + .vhf_maxFreq = 0, + .vhf_minFreq = 0, }; // RGB led color data @@ -74,6 +77,29 @@ void platform_init() ret = led_strip_update_rgb(led_dev, &led_color, 1); if (ret) printk("couldn't update strip: %d", ret); + + // Turn on baseband and initialize the SA868 module + pmu_setBasebandPower(true); + sa8x8_init(); + + // Detect radio model and set hwInfo accordingly + const char *model = sa8x8_getModel(); + if(strncmp(model, "SA868S-VHF", 10) == 0) + { + hwInfo.vhf_band = 1; + hwInfo.vhf_minFreq = 134; + hwInfo.vhf_maxFreq = 174; + } + else if(strncmp(model, "SA868S-UHF\r", 10) == 0) + { + hwInfo.uhf_band = 1; + hwInfo.uhf_minFreq = 400; + hwInfo.uhf_maxFreq = 480; + } + else + { + printk("Error detecting SA868 model"); + } } void platform_terminate()