Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 42 additions & 28 deletions code/src/PhoenixSketch/CAT.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "CAT.h"
#include "MainBoard_AudioIO.h" // GetFt8Mode()

// Kenwood TS-480 CAT Interface (partial)
//
Expand Down Expand Up @@ -693,10 +694,22 @@ char *RX_write( char* cmd ){
char *TX_write( char* cmd ){
switch (modeSM.state_id){
case (ModeSm_StateId_SSB_RECEIVE):{
#ifdef T41_USB_AUDIO
// Only allow CAT PTT (WSJT-X TX) when FT8 mode is enabled
if (GetFt8Mode()) {
ModeSm_dispatch_event(&modeSM, ModeSm_EventId_PTT_PRESSED);
} else {
// Ignore TX request if not in FT8 mode
// (optional) Serial.println("CAT TX ignored: FT8 mode is OFF");
}
#else
// No USB audio build: allow normal CAT PTT behavior
ModeSm_dispatch_event(&modeSM, ModeSm_EventId_PTT_PRESSED);
#endif
break;
}
case (ModeSm_StateId_CW_RECEIVE):{
// CW keying via CAT still allowed
ModeSm_dispatch_event(&modeSM, ModeSm_EventId_KEY_PRESSED);
break;
}
Expand All @@ -706,6 +719,7 @@ char *TX_write( char* cmd ){
return empty_string_p;
}


char *VX_write( char* cmd ){
Debug("Got VX write");
return empty_string_p;
Expand Down Expand Up @@ -740,7 +754,6 @@ char *PR_read( char* cmd ){
return obuf;
}


/**
* Poll SerialUSB1 for incoming CAT commands and process them
*
Expand All @@ -751,55 +764,56 @@ char *PR_read( char* cmd ){
void CheckForCATSerialEvents(void){
int i;
char c;
while( ( i = SerialUSB1.available() ) > 0 ){
c = ( char )SerialUSB1.read();

#ifdef T41_USB_AUDIO
while ( (i = Serial.available()) > 0 ) {
c = (char)Serial.read();
#else
while ( (i = SerialUSB1.available()) > 0 ) {
c = (char)SerialUSB1.read();
#endif
i--;
catCommand[ catCommandIndex ] = c;
#ifdef DEBUG_CAT

#ifdef DEBUG_CAT
Serial.print( catCommand[ catCommandIndex ] );
#endif
#endif

if( c == ';' ){
// Finished reading CAT command
#ifdef DEBUG_CAT
#ifdef DEBUG_CAT
Serial.println();
#endif // DEBUG_CAT

// Check to see if the command is a good one BEFORE sending it
// to the command executor
//Serial.println( String("catCommand is ")+String(catCommand)+String(" catCommandIndex is ")+String(catCommandIndex));
#endif
char *parser_output = command_parser( catCommand );
catCommandIndex = 0;
// We executed it, now erase it
memset( catCommand, 0, sizeof( catCommand ));

if( parser_output[0] != '\0' ){
#ifdef DEBUG_CAT1
Serial.println( parser_output );
#endif // DEBUG_CAT
int i = 0;
while( parser_output[i] != '\0' ){
#ifdef T41_USB_AUDIO
if( Serial.availableForWrite() > 0 ){
Serial.print( parser_output[i] );
#else
if( SerialUSB1.availableForWrite() > 0 ){
SerialUSB1.print( parser_output[i] );
#ifdef DEBUG_CAT
Serial.print( parser_output[i] );
#endif
#endif
i++;
}else{
SerialUSB1.flush();
}
}
#ifdef T41_USB_AUDIO
Serial.flush();
#else
SerialUSB1.flush();
#ifdef DEBUG_CAT
Serial.println();
#endif // DEBUG_CAT
#endif
}
}else{
} else {
catCommandIndex++;
if( catCommandIndex >= 128 ){
catCommandIndex = 0;
memset( catCommand, 0, sizeof( catCommand )); //clear out that overflowed buffer!
#ifdef DEBUG_CAT
memset( catCommand, 0, sizeof( catCommand ));
#ifdef DEBUG_CAT
Serial.println( "CAT command buffer overflow" );
#endif
#endif
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion code/src/PhoenixSketch/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

// Control encoder direction and speed
#define FAST_TUNE // comment this out to disable the FAST_TUNE algorithm
#define VOLUME_REVERSED true
#define VOLUME_REVERSED true
#define FILTER_REVERSED true
#define MAIN_TUNE_REVERSED true
#define FINE_TUNE_REVERSED false
Expand All @@ -32,6 +32,8 @@
// Default uses AD7991 digital SWR.
//#define USE_ANALOG_SWR

//#define ENABLE_DEBUG_SERIAL // TO ENABLE DEBUG UNCOMMENT THIS LINE AND SWITCH OFF FT8/DIGITAL NEED TO PROGRAM TEENSY AS DUAL SERIAL
//#define T41_USB_AUDIO 1 // TO ENABLE FT8 UNCOMMENT THIS LINE AND SWITCH ON FT8/DIGITAL NEED TO PROGRAM TEENSY AS SERIAL + MIDI + AUDIO.

// CW configuration
#define CW_TRANSMIT_SPACE_TIMEOUT_MS 200 // how long to wait for another key press before exiting CW transmit state
Expand Down
78 changes: 72 additions & 6 deletions code/src/PhoenixSketch/DSP.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "SDT.h"
#include "Ft8UsbBridge.h"
#include "MainBoard_AudioIO.h" // for GetFt8Mode()

float32_t DMAMEM float_buffer_L[READ_BUFFER_SIZE];
float32_t DMAMEM float_buffer_R[READ_BUFFER_SIZE];
Expand All @@ -14,6 +16,11 @@ static char *filename = nullptr;
void SaveData(DataBlock *data, uint32_t suffix); // used by the unit tests
static uint32_t swrTimer_ms = 0;

#ifdef T41_USB_AUDIO
extern AudioPlayQueue Q_usbOut_L;
extern AudioPlayQueue Q_usbOut_R;
#endif

#define RXTXZoom 3
#define TXIQZOOM 3

Expand Down Expand Up @@ -718,6 +725,36 @@ void PlayBuffer(DataBlock *data){
}
}

#ifdef T41_USB_AUDIO
static float32_t usbTmp[BUFFER_SIZE];
static float32_t g_usbRxGain = 1.5f; // GAIN SET FOR WJST, DEFAULT IS 2

void PlayUsbBufferPreVol(DataBlock *data){
for (unsigned i = 0; i < N_BLOCKS; i++) {
int16_t *pL = Q_usbOut_L.getBuffer();
int16_t *pR = Q_usbOut_R.getBuffer();

// Copy one block then apply gain
arm_copy_f32(&data->I[BUFFER_SIZE * i], usbTmp, BUFFER_SIZE);
arm_scale_f32(usbTmp, g_usbRxGain, usbTmp, BUFFER_SIZE);

// Optional: clip to [-1, +1] to avoid wrap distortion
for (size_t k = 0; k < BUFFER_SIZE; k++) {
if (usbTmp[k] > 1.0f) usbTmp[k] = 1.0f;
else if (usbTmp[k] < -1.0f) usbTmp[k] = -1.0f;
}

arm_float_to_q15(usbTmp, pL, BUFFER_SIZE);
arm_float_to_q15(usbTmp, pR, BUFFER_SIZE);

Q_usbOut_L.playBuffer();
Q_usbOut_R.playBuffer();
}
}
#endif



/**
* Initialize the global variables to their default startup values
* 1) Configure the RXfilters
Expand Down Expand Up @@ -924,19 +961,21 @@ DataBlock * ReceiveProcessing(const char *fname){
// Interpolate
InterpolateReceiveData(&data, &RXfilters);

// Volume adjust for audio volume setting. I and Q contain duplicate data, don't
// need to scale both
#if defined(T41_USB_AUDIO) && (defined(USB_AUDIO) || defined(USB_MIDI_AUDIO_SERIAL))
// Send audio to PC *before* volume knob affects it
PlayUsbBufferPreVol(&data);
#endif

// Speaker path volume knob
AdjustVolume(&data, &RXfilters);

SaveData(&data, 6); // used by the unit tests

// Play sound on the speaker
// Always feed the speaker output (works in both builds)
PlayBuffer(&data);

elapsed_micros_sum = elapsed_micros_sum + usec;
elapsed_micros_idx_t++;
//Flag(0);

return &data;
}

Expand Down Expand Up @@ -965,7 +1004,34 @@ float32_t GetMicRRMS(void){
* @param data The data block to put the samples in
* @return ESUCCESS if samples were read, EFAIL if insufficient samples are available
*/
errno_t ReadMicrophoneBuffer(DataBlock *data){
errno_t ReadMicrophoneBuffer(DataBlock *data)
{
if (!data) return EFAIL;

#ifdef T41_USB_AUDIO
if (GetFt8Mode()) {
const uint32_t outCount = N_BLOCKS_EX * BUFFER_SIZE;

bool ok = Ft8UsbBridge_GetSamples(data->I, outCount);
if (!ok) {
memset(data->I, 0, outCount * sizeof(float32_t));
}

// Dual-mono + attenuation (prevents harshness/clipping/pulsing)
for (uint32_t i = 0; i < outCount; i++) {
float s = data->I[i] * 0.20f; // try 0.10–0.30
data->I[i] = s;
data->Q[i] = s;
}

data->N = outCount;
data->sampleRate_Hz = SR[SampleRate].rate;
return ESUCCESS;
}
#endif

// ----- existing microphone code continues below -----

// are there at least N_BLOCKS buffers in each channel available ?
if ((uint32_t)Q_in_L_Ex.available() > N_BLOCKS_EX+0 && (uint32_t)Q_in_R_Ex.available() > N_BLOCKS_EX+0) {
//counter++;
Expand Down
Loading