Skip to content

Commit

Permalink
Ham: PTT button function with NFM voice transmit feature on a single …
Browse files Browse the repository at this point in the history
…(emergency) user-defined 2m/70cm band frequency
  • Loading branch information
lyusupov committed Nov 20, 2023
1 parent 28e18a9 commit 403153e
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,14 @@ Generic<br>NMEA|[Standalone](https://github.com/lyusupov/SoftRF/wiki/Standalone-
* [ESP32 adapter](https://github.com/lyusupov/ESP32-NODEMCU-ADAPTER)
* [ESP32‐C3 upgrade](https://github.com/lyusupov/SoftRF/wiki/ESP32%E2%80%90C3-upgrade-for-Standalone-Edition) ![](https://github.com/lyusupov/SoftRF/raw/master/documents/images/new-icon.jpg)
* [Ham Edition](https://github.com/lyusupov/SoftRF/wiki/Ham-Edition) ![](https://github.com/lyusupov/SoftRF/raw/master/documents/images/new-icon.jpg)
* [Quick start](https://github.com/lyusupov/SoftRF/wiki/Ham-Edition.-Quick-start)
* [ES Edition](https://github.com/lyusupov/SoftRF/wiki/ES-Edition)
* [Octave Concept](https://github.com/lyusupov/SoftRF/wiki/Octave-Concept)
* [Uni Edition](https://github.com/lyusupov/SoftRF/wiki/Uni-Edition)
* [Firmware installation](https://github.com/lyusupov/SoftRF/wiki/Uni-Edition.-Firmware-maintenance-procedures)
* [Enclosure](https://github.com/lyusupov/SoftRF/tree/master/case/Uni)
* [Midi Edition](https://github.com/lyusupov/SoftRF/wiki/Midi-Edition) ![](https://github.com/lyusupov/SoftRF/raw/master/documents/images/new-icon.jpg)
* [Quick start](https://github.com/lyusupov/SoftRF/wiki/Midi-Edition.-Quick-start)
* [Mini Edition](https://github.com/lyusupov/SoftRF/wiki/Mini-Edition)
* [Firmware installation](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/binaries#cubecell)
* [Quick start](https://github.com/lyusupov/SoftRF/wiki/Mini-Edition.-Quick-start)
Expand Down
5 changes: 3 additions & 2 deletions software/firmware/source/SoftRF/src/driver/OLED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ U8X8_OLED_I2C_BUS_TYPE u8x8_i2c(U8X8_PIN_NONE);

U8X8 *u8x8 = NULL;
uint8_t OLED_flip = 0;
static bool OLED_display_titles = false;
bool OLED_display_titles = false;
bool OLED_busy = false;

static uint32_t prev_tx_packets_counter = (uint32_t) -1;
static uint32_t prev_rx_packets_counter = (uint32_t) -1;
Expand Down Expand Up @@ -951,7 +952,7 @@ void OLED_049_func()
void OLED_loop()
{
if (u8x8) {
if (isTimeToOLED()) {
if (isTimeToOLED() && !OLED_busy) {
#if !defined(EXCLUDE_OLED_049)
if (hw_info.display == DISPLAY_OLED_0_49) {
OLED_049_func();
Expand Down
2 changes: 2 additions & 0 deletions software/firmware/source/SoftRF/src/driver/OLED.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ void OLED_Up(void);

extern U8X8 *u8x8;
extern uint8_t OLED_flip;
extern bool OLED_display_titles;
extern bool OLED_busy;

extern const char *ISO3166_CC[];
extern const char SoftRF_text1[];
Expand Down
4 changes: 3 additions & 1 deletion software/firmware/source/SoftRF/src/driver/RF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ bool RF_Transmit(size_t size, bool wait)

if (memcmp(TxBuffer, RxBuffer, RF_tx_size) != 0) {

rf_chip->transmit();
rf_chip->transmit(); /* TODO */

if (settings->nmea_p) {
StdOut.print(F("$PSRFO,"));
Expand Down Expand Up @@ -2555,6 +2555,8 @@ static bool sa8x8_receive()

static void sa8x8_transmit()
{
if (controller.getTxStatus()) return;

uint8_t powerPin = SOC_GPIO_PIN_TWR2_RADIO_HL;
AFSK_TimerEnable(false);

Expand Down
87 changes: 79 additions & 8 deletions software/firmware/source/SoftRF/src/platform/ESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> TWR2_Pixel(1, SOC_GPIO_PIN_TWR2_NEO
extern SA818Controller controller;
extern uint32_t Data_Frequency;
extern uint32_t Voice_Frequency;
extern void sa868_Tx_LED_state(bool);
#endif /* USE_SA8X8 */
#endif /* CONFIG_IDF_TARGET_ESP32S3 */

Expand Down Expand Up @@ -2648,8 +2649,8 @@ static bool ESP32_EEPROM_begin(size_t size)

static void ESP32_EEPROM_extension(int cmd)
{
if (cmd == EEPROM_EXT_LOAD) {
#if defined(CONFIG_IDF_TARGET_ESP32S3)
if (cmd == EEPROM_EXT_LOAD || cmd == EEPROM_EXT_DEFAULTS) {
if ( ESP32_has_spiflash && FATFS_is_mounted ) {
File32 file = fatfs.open(SETTINGS_JSON_PATH, FILE_READ);

Expand Down Expand Up @@ -2783,8 +2784,10 @@ static void ESP32_EEPROM_extension(int cmd)
file.close();
}
}
}
#endif /* CONFIG_IDF_TARGET_ESP32S3 */

if (cmd == EEPROM_EXT_LOAD) {
#if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32C3) || \
defined(USE_USB_HOST)
if (settings->nmea_out == NMEA_USB) {
Expand Down Expand Up @@ -3912,19 +3915,67 @@ static void ESP32_WDT_fini()
using namespace ace_button;

AceButton button_1(SOC_GPIO_PIN_TBEAM_V05_BUTTON);
#if defined(USE_SA8X8)
AceButton button_ptt(SOC_GPIO_PIN_TWR2_BUTTON);
static float PTT_TxF;
#endif /* USE_SA8X8 */

// The event handler for the button.
void handleMainEvent(AceButton* button, uint8_t eventType,
uint8_t buttonState) {

switch (eventType) {
#if defined(USE_SA8X8)
case AceButton::kEventPressed:
if (button == &button_ptt &&
Voice_Frequency > 0 &&
(settings->power_save & POWER_SAVE_NORECEIVE)) {
pinMode(SOC_GPIO_PIN_TWR2_MIC_CH_SEL, INPUT_PULLDOWN);
PTT_TxF = controller.getTXF();
controller.setTXF(Voice_Frequency / 1000000.0);
controller.update();
#if defined(USE_OLED)
if (u8x8) {
char buf[16];
int MHz = Voice_Frequency / 1000000;
int KHz = (Voice_Frequency - MHz * 1000000) / 1000;
if (MHz > 999) { MHz = 999; }
snprintf(buf, sizeof(buf), "%03d.%03d", MHz, KHz);

u8x8->setFont(u8x8_font_chroma48medium8_r);
u8x8->clear();
u8x8->draw2x2String( 2, 1, "ON AIR");
u8x8->draw2x2String( 1, 5, buf);
OLED_busy = true;
}
#endif /* USE_OLED */
sa868_Tx_LED_state(true);
controller.transmit();
}
break;
#endif /* USE_SA8X8 */
case AceButton::kEventClicked:
case AceButton::kEventReleased:
#if defined(USE_OLED)
if (button == &button_1) {
OLED_Next_Page();
}
#endif
#endif /* USE_OLED */
#if defined(USE_SA8X8)
if (button == &button_ptt &&
Voice_Frequency > 0 &&
(settings->power_save & POWER_SAVE_NORECEIVE)) {
controller.receive();
sa868_Tx_LED_state(false);
pinMode(SOC_GPIO_PIN_TWR2_MIC_CH_SEL, INPUT_PULLUP);
#if defined(USE_OLED)
OLED_busy = false;
OLED_display_titles = false;
#endif /* USE_OLED */
controller.setTXF(PTT_TxF);
controller.update();
}
#endif /* USE_SA8X8 */
break;
case AceButton::kEventDoubleClicked:
break;
Expand All @@ -3946,7 +3997,7 @@ void handleAuxEvent(AceButton* button, uint8_t eventType,
if (button == &button_1) {
OLED_Up();
}
#endif
#endif /* USE_OLED */
break;
case AceButton::kEventDoubleClicked:
break;
Expand All @@ -3965,13 +4016,13 @@ static void ESP32_Button_setup()
if (( hw_info.model == SOFTRF_MODEL_PRIME_MK2 &&
(hw_info.revision == 2 || hw_info.revision == 5)) ||
esp32_board == ESP32_S2_T8_V1_1 ||
esp32_board == ESP32_LILYGO_T_TWR_V2_0 ||
hw_info.model == SOFTRF_MODEL_HAM ||
esp32_board == ESP32_HELTEC_TRACKER ||
esp32_board == ESP32_S3_DEVKIT) {
button_pin = esp32_board == ESP32_S2_T8_V1_1 ? SOC_GPIO_PIN_T8_S2_BUTTON :
esp32_board == ESP32_S3_DEVKIT ? SOC_GPIO_PIN_S3_BUTTON :
esp32_board == ESP32_HELTEC_TRACKER ? SOC_GPIO_PIN_S3_BUTTON :
esp32_board == ESP32_LILYGO_T_TWR_V2_0 ?
hw_info.model == SOFTRF_MODEL_HAM ?
SOC_GPIO_PIN_TWR2_ENC_BUTTON : SOC_GPIO_PIN_TBEAM_V05_BUTTON;

// Button(s) uses external pull up resistor.
Expand All @@ -3989,6 +4040,21 @@ static void ESP32_Button_setup()
// PageButtonConfig->setDebounceDelay(15);
PageButtonConfig->setClickDelay(600);
PageButtonConfig->setLongPressDelay(2000);

#if defined(USE_SA8X8)
if (hw_info.model == SOFTRF_MODEL_HAM) {
int ptt_pin = SOC_GPIO_PIN_TWR2_BUTTON;

pinMode(ptt_pin, INPUT_PULLUP);
button_ptt.init(ptt_pin);

ButtonConfig* PTTButtonConfig = button_ptt.getButtonConfig();
PTTButtonConfig->setEventHandler(handleMainEvent);
PTTButtonConfig->setFeature(ButtonConfig::kFeatureClick);
PTTButtonConfig->setFeature(ButtonConfig::kFeatureSuppressAfterClick);
PTTButtonConfig->setClickDelay(600);
}
#endif /* USE_SA8X8 */
} else if ((hw_info.model == SOFTRF_MODEL_PRIME_MK2 && hw_info.revision >= 8) ||
esp32_board == ESP32_TTGO_T_BEAM_SUPREME) {
button_pin = (esp32_board == ESP32_TTGO_T_BEAM_SUPREME) ?
Expand All @@ -4013,21 +4079,26 @@ static void ESP32_Button_loop()
if (esp32_board == ESP32_TTGO_T_BEAM ||
esp32_board == ESP32_TTGO_T_BEAM_SUPREME ||
esp32_board == ESP32_S2_T8_V1_1 ||
esp32_board == ESP32_LILYGO_T_TWR_V2_0 ||
hw_info.model == SOFTRF_MODEL_HAM ||
esp32_board == ESP32_HELTEC_TRACKER ||
esp32_board == ESP32_S3_DEVKIT) {
button_1.check();
#if defined(USE_SA8X8)
if (hw_info.model == SOFTRF_MODEL_HAM) {
button_ptt.check();
}
#endif /* USE_SA8X8 */
}
}

static void ESP32_Button_fini()
{
if (esp32_board == ESP32_S2_T8_V1_1 ||
esp32_board == ESP32_LILYGO_T_TWR_V2_0 ||
hw_info.model == SOFTRF_MODEL_HAM ||
esp32_board == ESP32_HELTEC_TRACKER ||
esp32_board == ESP32_S3_DEVKIT) {
int button_pin = esp32_board == ESP32_S2_T8_V1_1 ? SOC_GPIO_PIN_T8_S2_BUTTON :
esp32_board == ESP32_LILYGO_T_TWR_V2_0?
hw_info.model == SOFTRF_MODEL_HAM ?
SOC_GPIO_PIN_TWR2_ENC_BUTTON : SOC_GPIO_PIN_S3_BUTTON;
while (digitalRead(button_pin) == LOW);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ void SA818Controller::setTXF(float tx) {
tx_f_ = tx;
}

float SA818Controller::getTXF() {
return tx_f_;
}

void SA818Controller::setRXF(float rx) {
rx_f_ = rx;
}
Expand Down Expand Up @@ -265,3 +269,8 @@ void SA818Controller::transmit()
_transmitStatus = true;
digitalWrite(ptt_, LOW);
}

bool SA818Controller::getTxStatus()
{
return _transmitStatus;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SA818Controller {

void setBW(byte);
void setTXF(float);
float getTXF();
void setRXF(float);
void setTXSub(int);
void setSQ(byte);
Expand Down Expand Up @@ -66,6 +67,7 @@ class SA818Controller {
void lowPower();
void receive();
void transmit();
bool getTxStatus();
};

#endif

1 comment on commit 403153e

@lyusupov
Copy link
Owner Author

@lyusupov lyusupov commented on 403153e Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.