From ed92d81543c1c5047537c4e1e6a7d2e9d88aa489 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Sat, 9 Mar 2024 11:20:31 +0100 Subject: [PATCH] Module17: implemented configurable logic levels for PTT in/out See #248 --- openrtx/include/calibration/calibInfo_Mod17.h | 14 ++++++++------ openrtx/include/ui/ui_mod17.h | 4 +++- openrtx/src/ui/module17/ui.c | 16 +++++++++++++++- openrtx/src/ui/module17/ui_menu.c | 6 ++++++ platform/drivers/baseband/radio_Mod17.cpp | 19 ++++++++++++++++--- platform/targets/Module17/platform.c | 8 ++++++-- 6 files changed, 54 insertions(+), 13 deletions(-) diff --git a/openrtx/include/calibration/calibInfo_Mod17.h b/openrtx/include/calibration/calibInfo_Mod17.h index be9ae570..a212b94f 100644 --- a/openrtx/include/calibration/calibInfo_Mod17.h +++ b/openrtx/include/calibration/calibInfo_Mod17.h @@ -30,12 +30,14 @@ */ typedef struct { - uint16_t tx_wiper; - uint16_t rx_wiper; - uint8_t mic_gain; - uint8_t tx_invert : 1, - rx_invert : 1, - _padding : 6; + uint16_t tx_wiper; ///< Baseband TX potentiometer + uint16_t rx_wiper; ///< Baseband RX potentiometer + uint8_t mic_gain; ///< Microphone gain + uint8_t tx_invert : 1, ///< Invert TX baseband + rx_invert : 1, ///< Invert RX baseband + ptt_in_level : 1, ///< PTT in acive level + ptt_out_level : 1, ///< PTT out active level + _padding : 4; } mod17Calib_t; diff --git a/openrtx/include/ui/ui_mod17.h b/openrtx/include/ui/ui_mod17.h index baf42280..da41e8b3 100644 --- a/openrtx/include/ui/ui_mod17.h +++ b/openrtx/include/ui/ui_mod17.h @@ -133,7 +133,9 @@ enum module17Items D_RXWIPER, D_TXINVERT, D_RXINVERT, - D_MICGAIN + D_MICGAIN, + D_PTTINLEVEL, + D_PTTOUTLEVEL }; /** diff --git a/openrtx/src/ui/module17/ui.c b/openrtx/src/ui/module17/ui.c index 914c8f1d..a61dce3c 100644 --- a/openrtx/src/ui/module17/ui.c +++ b/openrtx/src/ui/module17/ui.c @@ -104,7 +104,9 @@ const char *module17_items[] = "RX Softpot", "TX Phase", "RX Phase", - "Mic Gain" + "Mic Gain", + "PTT In", + "PTT Out" }; #ifdef CONFIG_GPS @@ -1000,6 +1002,12 @@ void ui_updateFSM(bool *sync_rtx) case D_MICGAIN: _ui_changeMicGain(-1); break; + case D_PTTINLEVEL: + mod17CalData.ptt_in_level -= 1; + break; + case D_PTTOUTLEVEL: + mod17CalData.ptt_out_level -= 1; + break; default: state.ui_screen = SETTINGS_MODULE17; } @@ -1023,6 +1031,12 @@ void ui_updateFSM(bool *sync_rtx) case D_MICGAIN: _ui_changeMicGain(+1); break; + case D_PTTINLEVEL: + mod17CalData.ptt_in_level += 1; + break; + case D_PTTOUTLEVEL: + mod17CalData.ptt_out_level += 1; + break; default: state.ui_screen = SETTINGS_MODULE17; } diff --git a/openrtx/src/ui/module17/ui_menu.c b/openrtx/src/ui/module17/ui_menu.c index e802cb72..38531076 100644 --- a/openrtx/src/ui/module17/ui_menu.c +++ b/openrtx/src/ui/module17/ui_menu.c @@ -240,6 +240,12 @@ int _ui_getModule17ValueName(char *buf, uint8_t max_len, uint8_t index) case D_MICGAIN: snprintf(buf, max_len, "%s", mic_gain_values[mod17CalData.mic_gain]); break; + case D_PTTINLEVEL: + snprintf(buf, max_len, "%s", mod17CalData.ptt_in_level ? "Act high" : "Act low"); + break; + case D_PTTOUTLEVEL: + snprintf(buf, max_len, "%s", mod17CalData.ptt_out_level ? "Act high" : "Act low"); + break; } return 0; diff --git a/platform/drivers/baseband/radio_Mod17.cpp b/platform/drivers/baseband/radio_Mod17.cpp index de8f54fd..d41c10ce 100644 --- a/platform/drivers/baseband/radio_Mod17.cpp +++ b/platform/drivers/baseband/radio_Mod17.cpp @@ -73,25 +73,38 @@ void radio_disableAfOutput() void radio_enableRx() { radioStatus = RX; - gpio_clearPin(PTT_OUT); mcp4551_setWiper(SOFTPOT_TX, mod17CalData.tx_wiper); mcp4551_setWiper(SOFTPOT_RX, mod17CalData.rx_wiper); + + // Module17 PTT output is open drain. This means that, on MCU side, we have + // to assert the gpio to bring it to low state. + if(mod17CalData.ptt_out_level) + gpio_setPin(PTT_OUT); + else + gpio_clearPin(PTT_OUT); } void radio_enableTx() { radioStatus = TX; - gpio_setPin(PTT_OUT); mcp4551_setWiper(SOFTPOT_TX, mod17CalData.tx_wiper); mcp4551_setWiper(SOFTPOT_RX, mod17CalData.rx_wiper); max9814_setGain(mod17CalData.mic_gain); + + if(mod17CalData.ptt_out_level) + gpio_clearPin(PTT_OUT); + else + gpio_setPin(PTT_OUT); } void radio_disableRtx() { - + if(mod17CalData.ptt_out_level) + gpio_setPin(PTT_OUT); + else + gpio_clearPin(PTT_OUT); } void radio_updateConfiguration() diff --git a/platform/targets/Module17/platform.c b/platform/targets/Module17/platform.c index 0ba2f354..3d1718cc 100644 --- a/platform/targets/Module17/platform.c +++ b/platform/targets/Module17/platform.c @@ -135,8 +135,12 @@ int8_t platform_getChSelector() bool platform_getPttStatus() { - /* PTT line has a pullup resistor with PTT switch closing to ground */ - return (gpio_readPin(PTT_SW) == 0) ? true : false; + // Return true if gpio status matches the PTT in active level + uint8_t ptt_status = gpio_readPin(PTT_SW); + if(ptt_status == mod17CalData.ptt_in_level) + return true; + + return false; } bool platform_pwrButtonStatus()