Update to include basic audio functionality. Compiles. Need to add more debug checking.
This commit is contained in:
144
TeensyDSP/DSP.cpp
Normal file
144
TeensyDSP/DSP.cpp
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
//======================================================================
|
||||||
|
// DSP.cpp
|
||||||
|
//======================================================================
|
||||||
|
|
||||||
|
#include "DSP.h"
|
||||||
|
|
||||||
|
#include <Audio.h>
|
||||||
|
#include <i2c_t3.h>
|
||||||
|
//#include <Wire.h>
|
||||||
|
//#include <SPI.h>
|
||||||
|
//#include <SD.h>
|
||||||
|
//#include <SerialFlash.h>
|
||||||
|
|
||||||
|
#define RX_AUDIO_CH 0
|
||||||
|
|
||||||
|
#define TX_MIC_IN_CH 0
|
||||||
|
#define TX_LINE_IN_CH 0
|
||||||
|
#define TX_USB_IN_CH1 1
|
||||||
|
#define TX_USB_IN_CH2 2
|
||||||
|
|
||||||
|
UBitxDSP DSP;
|
||||||
|
|
||||||
|
//static struct {
|
||||||
|
|
||||||
|
// GUItool: begin automatically generated code
|
||||||
|
AudioInputI2S lineIn; //xy=137,220
|
||||||
|
AudioInputUSB usbIn; //xy=142,326
|
||||||
|
AudioMixer4 rxAudio; //xy=394,134
|
||||||
|
AudioMixer4 txAudio; //xy=398,322
|
||||||
|
AudioOutputAnalog spkrOut; //xy=774,104
|
||||||
|
AudioOutputUSB usbOut; //xy=774,138
|
||||||
|
AudioOutputI2S lineOut; //xy=776,236
|
||||||
|
AudioConnection patchCord1(lineIn, 0, rxAudio, 0);
|
||||||
|
AudioConnection patchCord2(lineIn, 1, txAudio, 0);
|
||||||
|
AudioConnection patchCord3(usbIn, 0, txAudio, 1);
|
||||||
|
AudioConnection patchCord4(usbIn, 1, txAudio, 2);
|
||||||
|
AudioConnection patchCord5(rxAudio, spkrOut);
|
||||||
|
AudioConnection patchCord6(rxAudio, 0, lineOut, 0);
|
||||||
|
AudioConnection patchCord7(rxAudio, 0, usbOut, 0);
|
||||||
|
AudioConnection patchCord8(rxAudio, 0, usbOut, 1);
|
||||||
|
AudioConnection patchCord9(txAudio, 0, lineOut, 1);
|
||||||
|
AudioControlSGTL5000 audioCtrl; //xy=403,463
|
||||||
|
// GUItool: end automatically generated code
|
||||||
|
|
||||||
|
//} audio;
|
||||||
|
|
||||||
|
void UBitxDSP::begin() {
|
||||||
|
AudioMemory(20);
|
||||||
|
audioCtrl.enable();
|
||||||
|
audioCtrl.volume(0.0); // headphone volume...
|
||||||
|
audioCtrl.muteHeadphone(); // ...not used by UBitxDSP
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
if (i == RX_AUDIO_CH)
|
||||||
|
rxAudio.gain(i, 1.0);
|
||||||
|
else
|
||||||
|
rxAudio.gain(i, 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
txAudio.gain(i, 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// SETUP THE AUDIO INPUTS
|
||||||
|
|
||||||
|
// Rig (Line) Input (RX)
|
||||||
|
audioCtrl.inputSelect(AUDIO_INPUT_LINEIN);
|
||||||
|
audioCtrl.unmuteLineout();
|
||||||
|
|
||||||
|
// Mic Input (TX)
|
||||||
|
audioCtrl.micGain(0); // TODO: set value
|
||||||
|
|
||||||
|
// Line Input (TX)
|
||||||
|
|
||||||
|
// USB Input (TX)
|
||||||
|
|
||||||
|
// SETUP THE AUDIO OUTPUTS
|
||||||
|
|
||||||
|
// Speaker Output (RX)
|
||||||
|
spkrOut.analogReference(INTERNAL);
|
||||||
|
|
||||||
|
// Line Output (RX)
|
||||||
|
|
||||||
|
// USB Output (RX)
|
||||||
|
|
||||||
|
// Rig (Line) Output (TX)
|
||||||
|
}
|
||||||
|
|
||||||
|
void UBitxDSP::end() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void UBitxDSP::rx() {
|
||||||
|
// mute all tx audio
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
txAudio.gain(i, 0.0);
|
||||||
|
}
|
||||||
|
// select line in for rx
|
||||||
|
audioCtrl.inputSelect(AUDIO_INPUT_LINEIN);
|
||||||
|
// restore rx audio
|
||||||
|
rxAudio.gain(RX_AUDIO_CH, 1.0); // restore the RX audio
|
||||||
|
}
|
||||||
|
|
||||||
|
void UBitxDSP::txMicIn() {
|
||||||
|
// mute the rx audio
|
||||||
|
rxAudio.gain(RX_AUDIO_CH, 0.0);
|
||||||
|
// restore the tx mic audio
|
||||||
|
audioCtrl.inputSelect(AUDIO_INPUT_MIC);
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
if (i == TX_MIC_IN_CH)
|
||||||
|
txAudio.gain(i, 1.0);
|
||||||
|
else
|
||||||
|
txAudio.gain(i, 0.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UBitxDSP::txLineIn() {
|
||||||
|
// mute the rx audio
|
||||||
|
rxAudio.gain(RX_AUDIO_CH, 0.0);
|
||||||
|
// restore the tx line in audio
|
||||||
|
audioCtrl.inputSelect(AUDIO_INPUT_LINEIN);
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
if (i == TX_LINE_IN_CH)
|
||||||
|
txAudio.gain(i, 1.0);
|
||||||
|
else
|
||||||
|
txAudio.gain(i, 0.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UBitxDSP::txUSBIn() {
|
||||||
|
// mute the rx audio
|
||||||
|
rxAudio.gain(RX_AUDIO_CH, 0.0);
|
||||||
|
// restore the tx usb in audio
|
||||||
|
audioCtrl.inputSelect(AUDIO_INPUT_LINEIN);
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
if (i == TX_USB_IN_CH1 || i == TX_USB_IN_CH2)
|
||||||
|
txAudio.gain(i, 1.0);
|
||||||
|
else
|
||||||
|
txAudio.gain(i, 0.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//======================================================================
|
||||||
|
// EOF
|
||||||
|
//======================================================================
|
||||||
42
TeensyDSP/DSP.h
Normal file
42
TeensyDSP/DSP.h
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
//======================================================================
|
||||||
|
// DSP.h
|
||||||
|
//======================================================================
|
||||||
|
|
||||||
|
#ifndef __DSP_h__
|
||||||
|
#define __DSP_h__
|
||||||
|
|
||||||
|
#include "Debug.h"
|
||||||
|
|
||||||
|
enum TRState {
|
||||||
|
TRANSMIT,
|
||||||
|
RECEIVE
|
||||||
|
};
|
||||||
|
|
||||||
|
enum RxAudioIn {
|
||||||
|
RIG_AUDIO
|
||||||
|
};
|
||||||
|
|
||||||
|
enum TxAudioIn {
|
||||||
|
MIC_IN,
|
||||||
|
LINE_IN,
|
||||||
|
USB_IN
|
||||||
|
};
|
||||||
|
|
||||||
|
class UBitxDSP {
|
||||||
|
public:
|
||||||
|
UBitxDSP() {};
|
||||||
|
void begin();
|
||||||
|
void end();
|
||||||
|
void rx();
|
||||||
|
void txMicIn();
|
||||||
|
void txLineIn();
|
||||||
|
void txUSBIn();
|
||||||
|
};
|
||||||
|
|
||||||
|
extern UBitxDSP DSP;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//======================================================================
|
||||||
|
// EOF
|
||||||
|
//======================================================================
|
||||||
18
TeensyDSP/Debug.h
Normal file
18
TeensyDSP/Debug.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef __Debug_h__
|
||||||
|
#define __Debug_h__
|
||||||
|
|
||||||
|
#define DEBUG
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define DBGPRINT(MSG) do { Serial.print("DBG: "); Serial.print(MSG); } while (0)
|
||||||
|
#define DBGPRINTLN(MSG) do { Serial.print("DBG: "); Serial.println(MSG); } while (0)
|
||||||
|
#define DBGNEWLINE() do { Serial.println(); } while (0)
|
||||||
|
#define DBGCMD(CMD) do { Serial.println("DBG: "); Serial.println(#CMD); CMD; } while (0)
|
||||||
|
#else
|
||||||
|
#define DBGPRINT(MSG) do {} while (0)
|
||||||
|
#define DBGPRINTLN(MSG) do {} while (0)
|
||||||
|
#define DBGNEWLINE() do {} while (0)
|
||||||
|
#define DBGCMD(CMD) do { CMD; } while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
#define __Nextion_h__
|
#define __Nextion_h__
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include "Debug.h"
|
||||||
|
|
||||||
#define SWS_HEADER_CHAR_TYPE 'c' //1Byte Protocol Prefix
|
#define SWS_HEADER_CHAR_TYPE 'c' //1Byte Protocol Prefix
|
||||||
#define SWS_HEADER_INT_TYPE 'v' //Numeric Protocol Prefex
|
#define SWS_HEADER_INT_TYPE 'v' //Numeric Protocol Prefex
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define __Sensor_h__
|
#define __Sensor_h__
|
||||||
|
|
||||||
#include <ADC.h>
|
#include <ADC.h>
|
||||||
|
#include "Debug.h"
|
||||||
#include "HamFuncs.h"
|
#include "HamFuncs.h"
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
|
|||||||
45
TeensyDSP/TR.cpp
Normal file
45
TeensyDSP/TR.cpp
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
//======================================================================
|
||||||
|
// TR.cpp
|
||||||
|
//======================================================================
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "TR.h"
|
||||||
|
|
||||||
|
UBitxTR TR(DSP);
|
||||||
|
|
||||||
|
void UBitxTR::update(bool cw) {
|
||||||
|
updatePTT();
|
||||||
|
updateVOX();
|
||||||
|
updateKey();
|
||||||
|
|
||||||
|
if (isTX) {
|
||||||
|
// If we are currently transmitting, then ANY T/R release (key
|
||||||
|
// release) will result in exitting transmit... except for VOX
|
||||||
|
// and CAT which can only function as a release if it was enabled.
|
||||||
|
if (pttReleased() || keyReleased() ||
|
||||||
|
(voxEnabled && voxDeactivated()) ||
|
||||||
|
(catEnabled && catDeactivated())) {
|
||||||
|
// first, stop transmitting; then, setup RX audio
|
||||||
|
DBGCMD( setRX() );
|
||||||
|
DBGCMD( dsp.rx() );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((pttEnabled && pttPressed()) || (voxEnabled && voxActivated())) {
|
||||||
|
// first, setup TX audio; then, start transmitting (from Mic)
|
||||||
|
DBGCMD( dsp.txMicIn() );
|
||||||
|
DBGCMD( setTX() );
|
||||||
|
} else if (keyEnabled && keyPressed()) {
|
||||||
|
// first, setup TX audio; then, start transmitting (from Line In)
|
||||||
|
DBGCMD( dsp.txLineIn() );
|
||||||
|
DBGCMD( setTX() );
|
||||||
|
} else if (catEnabled && catActivated()) {
|
||||||
|
// first, setup TX audio; then, start transmitting (USB)
|
||||||
|
DBGCMD( dsp.txUSBIn() );
|
||||||
|
DBGCMD( setTX() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//======================================================================
|
||||||
|
// EOF
|
||||||
|
//======================================================================
|
||||||
169
TeensyDSP/TR.h
Normal file
169
TeensyDSP/TR.h
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
//======================================================================
|
||||||
|
// TR.h
|
||||||
|
//======================================================================
|
||||||
|
|
||||||
|
#ifndef __TR_h__
|
||||||
|
#define __TR_h__
|
||||||
|
|
||||||
|
#include <Bounce2.h>
|
||||||
|
#include "Debug.h"
|
||||||
|
#include "DSP.h"
|
||||||
|
|
||||||
|
#define UBITX_TR_OUT_PIN 2
|
||||||
|
#define UBITX_TR_PTT_PIN 3
|
||||||
|
#define UBITX_TR_VOX_PIN 4
|
||||||
|
#define UBITX_TR_KEY_PIN 5
|
||||||
|
|
||||||
|
const int uBitxTROutPin = UBITX_TR_OUT_PIN;
|
||||||
|
const int uBitxTRPttPin = UBITX_TR_PTT_PIN;
|
||||||
|
const int uBitxTRVoxPin = UBITX_TR_VOX_PIN;
|
||||||
|
const int uBitxTRKeyPin = UBITX_TR_KEY_PIN;
|
||||||
|
|
||||||
|
class UBitxTR {
|
||||||
|
public:
|
||||||
|
UBitxTR(UBitxDSP& d, int out = uBitxTROutPin, int p = uBitxTRPttPin, int v = uBitxTRVoxPin, int k = uBitxTRKeyPin):
|
||||||
|
dsp(d), outPin(out), pttPin(p), voxPin(v), keyPin(k) {}
|
||||||
|
|
||||||
|
void begin() {
|
||||||
|
pinMode(outPin, OUTPUT);
|
||||||
|
pinMode(voxPin, INPUT_PULLUP);
|
||||||
|
pinMode(keyPin, INPUT_PULLUP);
|
||||||
|
ptt.attach(pttPin, INPUT_PULLUP);
|
||||||
|
ptt.interval(5);
|
||||||
|
|
||||||
|
// default configuration: PTT, key, and CAT enabled; VOX disabled
|
||||||
|
DBGCMD( enablePTT() );
|
||||||
|
DBGCMD( disableVOX() );
|
||||||
|
DBGCMD( enableKey() );
|
||||||
|
DBGCMD( enableCAT() );
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void enablePTT() { pttEnabled = true; }
|
||||||
|
inline void enableVOX() { voxEnabled = true; }
|
||||||
|
inline void enableKey() { keyEnabled = true; }
|
||||||
|
inline void enableCAT() { catEnabled = true; }
|
||||||
|
inline void disablePTT() { pttEnabled = false; }
|
||||||
|
inline void disableVOX() { voxEnabled = false; }
|
||||||
|
inline void disableKey() { keyEnabled = false; }
|
||||||
|
inline void disableCAT() { catEnabled = false; }
|
||||||
|
|
||||||
|
|
||||||
|
inline void catTX() {
|
||||||
|
L_catActive = catActive;
|
||||||
|
catActive = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void catRX() {
|
||||||
|
L_catActive = catActive;
|
||||||
|
catActive = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//======================================================================
|
||||||
|
|
||||||
|
inline bool transmitting() { return isTX; }
|
||||||
|
inline bool receiving() { return !isTX; }
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Check if any of the PTT's have been pressed or released
|
||||||
|
* since the last update. Only one thing is allowed to occur
|
||||||
|
* based on an order of precedence. The highest priority is
|
||||||
|
* to stop transmitting.
|
||||||
|
*
|
||||||
|
* @param cw
|
||||||
|
* True if CW mode is currently active; false otherwise.
|
||||||
|
* Different/faster logic is used in CW mode.
|
||||||
|
*/
|
||||||
|
void update(bool cw = false);
|
||||||
|
|
||||||
|
void end() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
inline void setTX() {
|
||||||
|
digitalWrite(outPin, LOW);
|
||||||
|
isTX = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void setRX() {
|
||||||
|
isTX = false;
|
||||||
|
digitalWrite(outPin, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void updatePTT() {
|
||||||
|
ptt.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool pttPressed() {
|
||||||
|
return ptt.fell();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool pttReleased() {
|
||||||
|
return ptt.rose();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void updateVOX() {
|
||||||
|
L_voxActive = voxActive;
|
||||||
|
voxActive = (digitalRead(voxPin) == LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool voxActivated() {
|
||||||
|
return (L_voxActive != voxActive) && L_voxActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool voxDeactivated() {
|
||||||
|
return (L_voxActive != voxActive) && voxActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void updateKey() {
|
||||||
|
L_keyDown = keyDown;
|
||||||
|
keyDown = (digitalRead(keyPin) == LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool keyPressed() {
|
||||||
|
return (L_keyDown != keyDown) && L_keyDown;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool keyReleased() {
|
||||||
|
return (L_keyDown != keyDown) && keyDown;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool catActivated() {
|
||||||
|
return (L_catActive != catActive) && L_catActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool catDeactivated() {
|
||||||
|
return (L_catActive != catActive) && catActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
UBitxDSP& dsp;
|
||||||
|
|
||||||
|
Bounce ptt;
|
||||||
|
|
||||||
|
int outPin;
|
||||||
|
int pttPin;
|
||||||
|
int voxPin;
|
||||||
|
int keyPin;
|
||||||
|
|
||||||
|
bool isTX = false;
|
||||||
|
|
||||||
|
bool pttEnabled = false;
|
||||||
|
bool voxEnabled = false;
|
||||||
|
bool keyEnabled = false;
|
||||||
|
bool catEnabled = false;
|
||||||
|
|
||||||
|
bool voxActive = false;
|
||||||
|
bool L_voxActive = false;
|
||||||
|
bool keyDown = false;
|
||||||
|
bool L_keyDown = false;
|
||||||
|
bool catActive = false;
|
||||||
|
bool L_catActive = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern UBitxTR TR;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//======================================================================
|
||||||
|
// EOF
|
||||||
|
//======================================================================
|
||||||
@@ -8,8 +8,11 @@ KD8CEC, Ian Lee
|
|||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include "Debug.h"
|
||||||
|
#include "DSP.h"
|
||||||
#include "Nextion.h"
|
#include "Nextion.h"
|
||||||
#include "Sensors.h"
|
#include "Sensors.h"
|
||||||
|
#include "TR.h"
|
||||||
|
|
||||||
//================================================================
|
//================================================================
|
||||||
//COMMUNICATION SECTION
|
//COMMUNICATION SECTION
|
||||||
|
|||||||
@@ -350,6 +350,9 @@ void setup()
|
|||||||
SAMPLE_INTERVAL = round(1000000 * (1.0 / SAMPLE_FREQUENCY));
|
SAMPLE_INTERVAL = round(1000000 * (1.0 / SAMPLE_FREQUENCY));
|
||||||
//calculateCoeff(cwDecodeHz); //Set 750Hz //9 * 50 + 300 = 750Hz
|
//calculateCoeff(cwDecodeHz); //Set 750Hz //9 * 50 + 300 = 750Hz
|
||||||
//Serial1.println("Start...");
|
//Serial1.println("Start...");
|
||||||
|
|
||||||
|
DBGCMD( DSP.begin() );
|
||||||
|
DBGCMD( TR.begin() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -466,6 +469,8 @@ void loop()
|
|||||||
// TODO: debug output (frame skipping / utilization).
|
// TODO: debug output (frame skipping / utilization).
|
||||||
sinceFrameMillis = 0;
|
sinceFrameMillis = 0;
|
||||||
|
|
||||||
|
TR.update();
|
||||||
|
|
||||||
if (isTX) {
|
if (isTX) {
|
||||||
calcVSWR = Sensors.VSWR();
|
calcVSWR = Sensors.VSWR();
|
||||||
scaledVSWR = byte(Sensors.scaledVSWR());
|
scaledVSWR = byte(Sensors.scaledVSWR());
|
||||||
|
|||||||
Reference in New Issue
Block a user