Initial transmit support. Internal microphone working. Capacitive touch sensors working. Currently touch TOUCH1 to transmit, waterfall changes color and shows the filtered output that should be transmitted (except that it's MUCH noisier than it looks, due, I think to DSP issues.)

This commit is contained in:
Michael Colton 2014-10-06 11:03:34 -06:00
parent 7f0b21569c
commit d04d7845cf
9 changed files with 7416 additions and 7236 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -16,35 +16,48 @@
#include "stm32f4xx_hal_rcc.h"
__IO uint16_t uhADCxConvertedValue;
__IO uint16_t uhADCxConvertedValue1;
__IO uint16_t uhADCxConvertedValue2;
__IO uint16_t uhADCxConvertedValue3;
uint8_t adcConfigured;
uint16_t sampleIndex;
volatile uint8_t sampleRun;
/* Definition for ADCx clock resources */
#define ADCx ADC1
#define ADCx_CLK_ENABLE() __ADC1_CLK_ENABLE();
#define ADC_RX_Q ADC3
#define ADC_RX_I ADC2
#define ADC_MIC ADC1
#define ADCx_CLK_ENABLE() __ADC1_CLK_ENABLE()
#define ADCx_CHANNEL_GPIO_CLK_ENABLE() __GPIOA_CLK_ENABLE()
#define ADCx_FORCE_RESET() __ADC_FORCE_RESET()
#define ADCx_RELEASE_RESET() __ADC_RELEASE_RESET()
/* Definition for ADCx Channel Pin */
#define ADCx_CHANNEL_PIN GPIO_PIN_3
#define ADCx_CHANNEL_GPIO_PORT GPIOA
//#define ADC_RX-Q_PIN GPIO_PIN_3
//#define ADCx_CHANNEL_GPIO_PORT GPIOA
/* Definition for ADCx's Channel */
#define ADCx_CHANNEL ADC_CHANNEL_3
#define ADC_RX_Q_CHANNEL ADC_CHANNEL_3
#define ADC_RX_I_CHANNEL ADC_CHANNEL_6
#define ADC_MIC_CHANNEL ADC_CHANNEL_9
#define ADC_LIPO_VOLTAGE ADC_CHANNEL_15
#define ADC_VNA_PHASE ADC_CHANNEL_7
#define ADC_VNA_MAGNITUTDE ADC_CHANNEL_14
/* Definition for ADCx's NVIC */
#define ADCx_IRQn ADC_IRQn
ADC_HandleTypeDef AdcHandle;
ADC_HandleTypeDef AdcHandle1;
ADC_HandleTypeDef AdcHandle2;
ADC_HandleTypeDef AdcHandle3;
ADC_ChannelConfTypeDef sConfig1;
ADC_ChannelConfTypeDef sConfig2;
ADC_ChannelConfTypeDef sConfig3;
uint8_t wrongThings;

View File

@ -102,7 +102,7 @@
extern const Gpio_Pin dac1;
extern const Gpio_Pin dac2;
extern const Gpio_Pin REF_CLOCK_DISABLE;
extern const Gpio_Pin REF_CLOCK_ENABLE;
extern const Gpio_Pin DDS_FSEL;
extern const Gpio_Pin DDS_PSEL;
extern const Gpio_Pin RX_MUX;
@ -123,7 +123,19 @@
extern const Gpio_Pin IN_AMP_ENABLE;
extern const Gpio_Pin DAC_MUX;
extern const Gpio_Pin AUDIO_AMP_NSHTDWN;
extern const Gpio_Pin EARPHONE_NOT_INSERTED;
extern const Gpio_Pin SIDETONE; //Should be a timer pin.
extern const Gpio_Pin MIC_IN;
extern const Gpio_Pin MIC_SWITCH;
extern const Gpio_Pin PREAMP_POWER;
extern const Gpio_Pin MIC_BUTTON;
extern const Gpio_Pin TOUCH1;
extern const Gpio_Pin TOUCH2;
extern const Gpio_Pin KEY1;
extern const Gpio_Pin KEY2;
// extern const Gpio_Pin NC_1;
// extern const Gpio_Pin DAC_SWITCHES;

View File

@ -3,7 +3,7 @@
void initAdc()
{
uhADCxConvertedValue = 0;
uhADCxConvertedValue1 = 0;
uhADCxConvertedValue2 = 0;
adcConfigured = 0;
sampleIndex = 0;
@ -13,27 +13,30 @@ void initAdc()
__ADC1_CLK_ENABLE();
__ADC2_CLK_ENABLE();
__GPIOA_CLK_ENABLE(); //PA1 and PA2
__ADC3_CLK_ENABLE();
__GPIOA_CLK_ENABLE();
__GPIOB_CLK_ENABLE();
__GPIOC_CLK_ENABLE();
__ADC_FORCE_RESET();
__ADC_RELEASE_RESET();
AdcHandle.Instance = ADCx;
AdcHandle1.Instance = ADC1;
AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;
AdcHandle.Init.Resolution = ADC_RESOLUTION12b;
AdcHandle.Init.ScanConvMode = DISABLE;
AdcHandle.Init.ContinuousConvMode = ENABLE;
AdcHandle.Init.DiscontinuousConvMode = DISABLE;
AdcHandle.Init.NbrOfDiscConversion = 0;
AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1;
AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;
AdcHandle.Init.NbrOfConversion = 1;
AdcHandle.Init.DMAContinuousRequests = DISABLE;
AdcHandle.Init.EOCSelection = DISABLE;
AdcHandle1.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;
AdcHandle1.Init.Resolution = ADC_RESOLUTION12b;
AdcHandle1.Init.ScanConvMode = DISABLE;
AdcHandle1.Init.ContinuousConvMode = ENABLE;
AdcHandle1.Init.DiscontinuousConvMode = DISABLE;
AdcHandle1.Init.NbrOfDiscConversion = 0;
AdcHandle1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
AdcHandle1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1;
AdcHandle1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
AdcHandle1.Init.NbrOfConversion = 1;
AdcHandle1.Init.DMAContinuousRequests = DISABLE;
AdcHandle1.Init.EOCSelection = DISABLE;
if(HAL_ADC_Init(&AdcHandle) != HAL_OK)
if(HAL_ADC_Init(&AdcHandle1) != HAL_OK)
{
/* Initiliazation Error */
//Error_Handler();
@ -61,19 +64,43 @@ void initAdc()
wrongThings++;
}
AdcHandle3.Instance = ADC3;
sConfig1.Channel = ADCx_CHANNEL;
AdcHandle3.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;
AdcHandle3.Init.Resolution = ADC_RESOLUTION12b;
AdcHandle3.Init.ScanConvMode = DISABLE;
AdcHandle3.Init.ContinuousConvMode = ENABLE;
AdcHandle3.Init.DiscontinuousConvMode = DISABLE;
AdcHandle3.Init.NbrOfDiscConversion = 0;
AdcHandle3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
AdcHandle3.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1;
AdcHandle3.Init.DataAlign = ADC_DATAALIGN_RIGHT;
AdcHandle3.Init.NbrOfConversion = 1;
AdcHandle3.Init.DMAContinuousRequests = DISABLE;
AdcHandle3.Init.EOCSelection = DISABLE;
if(HAL_ADC_Init(&AdcHandle3) != HAL_OK)
{
/* Initiliazation Error */
//Error_Handler();
wrongThings++;
}
sConfig1.Channel = ADC_MIC_CHANNEL;
sConfig1.Rank = 1;
sConfig1.SamplingTime = ADC_SAMPLETIME_3CYCLES;
sConfig1.Offset = 0;
sConfig2.Channel = ADC_CHANNEL_6;
sConfig2.Channel = ADC_RX_I_CHANNEL;
sConfig2.Rank = 1;
sConfig2.SamplingTime = ADC_SAMPLETIME_3CYCLES;
sConfig2.Offset = 0;
sConfig3.Channel = ADC_RX_Q_CHANNEL;
sConfig3.Rank = 1;
sConfig3.SamplingTime = ADC_SAMPLETIME_3CYCLES;
sConfig3.Offset = 0;
if(HAL_ADC_ConfigChannel(&AdcHandle, &sConfig1) != HAL_OK)
if(HAL_ADC_ConfigChannel(&AdcHandle1, &sConfig1) != HAL_OK)
{
/* Channel Configuration Error */
//Error_Handler();
@ -86,26 +113,37 @@ void initAdc()
//Error_Handler();
wrongThings++;
}
if(HAL_ADC_ConfigChannel(&AdcHandle3, &sConfig3) != HAL_OK)
{
/* Channel Configuration Error */
//Error_Handler();
wrongThings++;
}
}
void adcGetConversion()
{
HAL_ADC_PollForConversion(&AdcHandle, 10);
HAL_ADC_PollForConversion(&AdcHandle1, 10);
HAL_ADC_PollForConversion(&AdcHandle2, 10);
HAL_ADC_PollForConversion(&AdcHandle3, 10);
/* Check if the continous conversion of regular channel is finished */
if(HAL_ADC_GetState(&AdcHandle) == HAL_ADC_STATE_EOC_REG && HAL_ADC_GetState(&AdcHandle2) == HAL_ADC_STATE_EOC_REG)
if(HAL_ADC_GetState(&AdcHandle1) == HAL_ADC_STATE_EOC_REG
&& HAL_ADC_GetState(&AdcHandle2) == HAL_ADC_STATE_EOC_REG
&& HAL_ADC_GetState(&AdcHandle3) == HAL_ADC_STATE_EOC_REG)
{
/*##-5- Get the converted value of regular channel ########################*/
uhADCxConvertedValue = HAL_ADC_GetValue(&AdcHandle);
uhADCxConvertedValue1 = HAL_ADC_GetValue(&AdcHandle1);
uhADCxConvertedValue2 = HAL_ADC_GetValue(&AdcHandle2);
uhADCxConvertedValue3 = HAL_ADC_GetValue(&AdcHandle3);
}
}
void adcStartConversion()
{
if(HAL_ADC_Start(&AdcHandle) != HAL_OK)
if(HAL_ADC_Start(&AdcHandle1) != HAL_OK)
{
/* Start Conversation Error */
//Error_Handler();
@ -118,10 +156,17 @@ void initAdc()
//Error_Handler();
wrongThings++;
}
if(HAL_ADC_Start(&AdcHandle3) != HAL_OK)
{
/* Start Conversation Error */
//Error_Handler();
wrongThings++;
}
}
//__IO uint16_t uhADCxConvertedValue = 0;
//__IO uint16_t uhADCxConvertedValue1 = 0;
/**
@ -134,7 +179,7 @@ void initAdc()
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* AdcHandle)
{
/* Get the converted value of regular channel */
uhADCxConvertedValue = HAL_ADC_GetValue(AdcHandle);
uhADCxConvertedValue1 = HAL_ADC_GetValue(AdcHandle);
}

View File

@ -79,7 +79,7 @@ const Gpio_Pin dac1 = { GPIOA, GPIO_PIN_4 };
const Gpio_Pin dac2 = { GPIOA, GPIO_PIN_5 };
const Gpio_Pin REF_CLOCK_DISABLE = { GPIOC, GPIO_PIN_2 };
const Gpio_Pin REF_CLOCK_ENABLE = { GPIOC, GPIO_PIN_2 };
const Gpio_Pin DDS_FSEL = { GPIOA, GPIO_PIN_1 };
const Gpio_Pin DDS_PSEL = { GPIOA, GPIO_PIN_2 };
const Gpio_Pin RX_MUX = { GPIOB, GPIO_PIN_15 };
@ -99,6 +99,22 @@ const Gpio_Pin GAIN_POT_NSS = { GPIOB , GPIO_PIN_10};
const Gpio_Pin DAC_MUX = { GPIOD, GPIO_PIN_8 };
const Gpio_Pin AUDIO_AMP_NSHTDWN = { GPIOD, GPIO_PIN_9 };
const Gpio_Pin EARPHONE_NOT_INSERTED= { GPIOB, GPIO_PIN_0 };
const Gpio_Pin SIDETONE = { GPIOD, GPIO_PIN_12 }; //Should be a timer pin.
const Gpio_Pin MIC_IN = { GPIOB, GPIO_PIN_1 };
const Gpio_Pin MIC_SWITCH = { GPIOD, GPIO_PIN_14 };
const Gpio_Pin PREAMP_POWER = { GPIOD, GPIO_PIN_13 };
const Gpio_Pin TOUCH1 = { GPIOC, GPIO_PIN_6 };
const Gpio_Pin TOUCH2 = { GPIOC, GPIO_PIN_7 };
const Gpio_Pin KEY1 = { GPIOD, GPIO_PIN_10 };
const Gpio_Pin KEY2 = { GPIOD, GPIO_PIN_11 };
//const Gpio_Pin MIC_BUTTON = { GPIOD, GPIO_PIN_12 };;//FORGOT TO CONNECT IT TO THE MCU!
//const Gpio_Pin IN_AMP_ENABLE = { GPIO, GPIO_PIN_ }; //FORGOT TO CONNECT IT TO THE MCU!
//const Gpio_Pin NC_1 = { GPIOC, GPIO_Pin_0 }; // this is the Closure Sensor Pin near the 3v3 regulator, fyi
@ -394,12 +410,12 @@ void hal_setupPins(void)
HAL_GPIO_Init(dac1.port, &gpioInitStructure);
gpioInitStructure.Pin = REF_CLOCK_DISABLE.pin;
gpioInitStructure.Pin = REF_CLOCK_ENABLE.pin;
gpioInitStructure.Mode = GPIO_MODE_OUTPUT_PP;
gpioInitStructure.Speed = GPIO_SPEED_LOW;
gpioInitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(REF_CLOCK_DISABLE.port, &gpioInitStructure);
HAL_GPIO_WritePin(REF_CLOCK_DISABLE.port, REF_CLOCK_DISABLE.pin, 1);
HAL_GPIO_Init(REF_CLOCK_ENABLE.port, &gpioInitStructure);
HAL_GPIO_WritePin(REF_CLOCK_ENABLE.port, REF_CLOCK_ENABLE.pin, 1);
gpioInitStructure.Pin = DDS_FSEL.pin;
gpioInitStructure.Mode = GPIO_MODE_OUTPUT_PP;
@ -420,14 +436,14 @@ void hal_setupPins(void)
gpioInitStructure.Speed = GPIO_SPEED_LOW;
gpioInitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(RX_MUX.port, &gpioInitStructure);
HAL_GPIO_WritePin(RX_MUX.port, RX_MUX.pin, 0); //Active Low
HAL_GPIO_WritePin(RX_MUX.port, RX_MUX.pin, 1); //Active Low
gpioInitStructure.Pin = TX_MUX.pin;
gpioInitStructure.Mode = GPIO_MODE_OUTPUT_PP;
gpioInitStructure.Speed = GPIO_SPEED_LOW;
gpioInitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(TX_MUX.port, &gpioInitStructure);
HAL_GPIO_WritePin(TX_MUX.port, TX_MUX.pin, 1); //Active Low
HAL_GPIO_WritePin(TX_MUX.port, TX_MUX.pin, 0); //Active Low
gpioInitStructure.Pin = TX_RF_SWITCH_A.pin;
gpioInitStructure.Mode = GPIO_MODE_OUTPUT_PP;
@ -469,7 +485,73 @@ void hal_setupPins(void)
gpioInitStructure.Speed = GPIO_SPEED_LOW;
gpioInitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(DAC_MUX.port, &gpioInitStructure);
HAL_GPIO_WritePin(DAC_MUX.port, DAC_MUX.pin, 0); //0 = speaker/earphone. Speaker doesn't seem to work, btw...
HAL_GPIO_WritePin(DAC_MUX.port, DAC_MUX.pin, 1); //0 = speaker/earphone. Speaker doesn't seem to work, btw...
gpioInitStructure.Pin = EARPHONE_NOT_INSERTED.pin;
gpioInitStructure.Mode = GPIO_MODE_ANALOG;
gpioInitStructure.Speed = GPIO_SPEED_LOW;
gpioInitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(EARPHONE_NOT_INSERTED.port, &gpioInitStructure);
HAL_GPIO_WritePin(EARPHONE_NOT_INSERTED.port, EARPHONE_NOT_INSERTED.pin, 0);
gpioInitStructure.Pin = AUDIO_AMP_NSHTDWN.pin;
gpioInitStructure.Mode = GPIO_MODE_OUTPUT_PP;
gpioInitStructure.Speed = GPIO_SPEED_LOW;
gpioInitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(AUDIO_AMP_NSHTDWN.port, &gpioInitStructure);
HAL_GPIO_WritePin(AUDIO_AMP_NSHTDWN.port, AUDIO_AMP_NSHTDWN.pin, 1);
gpioInitStructure.Pin = SIDETONE.pin;
gpioInitStructure.Mode = GPIO_MODE_ANALOG; //For now, or when not in use.
gpioInitStructure.Speed = GPIO_SPEED_LOW;
gpioInitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(SIDETONE.port, &gpioInitStructure);
HAL_GPIO_WritePin(SIDETONE.port, SIDETONE.pin, 0);
gpioInitStructure.Pin = MIC_IN.pin;
gpioInitStructure.Mode = GPIO_MODE_ANALOG;
gpioInitStructure.Speed = GPIO_SPEED_LOW;
gpioInitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(MIC_IN.port, &gpioInitStructure);
gpioInitStructure.Pin = MIC_SWITCH.pin;
gpioInitStructure.Mode = GPIO_MODE_OUTPUT_PP;
gpioInitStructure.Speed = GPIO_SPEED_LOW;
gpioInitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(MIC_SWITCH.port, &gpioInitStructure);
HAL_GPIO_WritePin(MIC_SWITCH.port, MIC_SWITCH.pin, 1); //1 = Internal Mic
gpioInitStructure.Pin = PREAMP_POWER.pin;
gpioInitStructure.Mode = GPIO_MODE_OUTPUT_PP;
gpioInitStructure.Speed = GPIO_SPEED_LOW;
gpioInitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(PREAMP_POWER.port, &gpioInitStructure);
HAL_GPIO_WritePin(PREAMP_POWER.port, PREAMP_POWER.pin, 1); //1 = ON!
gpioInitStructure.Pin = KEY1.pin;
gpioInitStructure.Mode = GPIO_MODE_INPUT;
gpioInitStructure.Speed = GPIO_SPEED_LOW;
gpioInitStructure.Pull = GPIO_PULLUP;
HAL_GPIO_Init(KEY1.port, &gpioInitStructure);
gpioInitStructure.Pin = KEY2.pin;
gpioInitStructure.Mode = GPIO_MODE_INPUT;
gpioInitStructure.Speed = GPIO_SPEED_LOW;
gpioInitStructure.Pull = GPIO_PULLUP;
HAL_GPIO_Init(KEY2.port, &gpioInitStructure);
gpioInitStructure.Pin = TOUCH1.pin;
gpioInitStructure.Mode = GPIO_MODE_INPUT;
gpioInitStructure.Speed = GPIO_SPEED_LOW;
gpioInitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(TOUCH1.port, &gpioInitStructure);
gpioInitStructure.Pin = TOUCH2.pin;
gpioInitStructure.Mode = GPIO_MODE_INPUT;
gpioInitStructure.Speed = GPIO_SPEED_LOW;
gpioInitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(TOUCH2.port, &gpioInitStructure);
// Power Switch
// gpioInitStructure.GPIO_Pin = POWER_SWITCH.pin;

View File

@ -89,6 +89,8 @@ int ifShift = 0;
float fftMaxMaxMax = 20;
float fftMaxMaxMin = 0.2;
int transmitting = 0;
unsigned int tone = 0;
/** System Clock Configuration
*/
@ -176,7 +178,7 @@ void populateCoeficients(int bandwidth, int sideband, int offset)
fftFilterCoeficient[FFT_BUFFER_SIZE / 2] = 0;
fftFilterCoeficient[FFT_BUFFER_SIZE - 1] = 0;
//return; //Skipping all the later stuff doesn't seem to make a huge difference yet...
return; //Skipping all the later stuff doesn't seem to make a huge difference yet...
//2:
// float x, y;
@ -368,8 +370,9 @@ int isFwd;
//int sampleCounter = 0;
//const int FFT_SIZE = 256;
float observerA, observerB, observerC;
int dcOffset1 = 1539;
int dcOffset2 = 1530;
int dcOffset1 = 1029;
int dcOffset2 = 1535;
int dcOffset3 = 1518;
void captureSamples()
{
@ -381,11 +384,16 @@ int isFwd;
switch (sampleBank)
{
case 0:
if(transmitting == 0)
{
samplesA[sampleIndex*2] = ((uhADCxConvertedValue3 - dcOffset3)/4096.0); // - 2048;
samplesA[sampleIndex*2 + 1] = ((uhADCxConvertedValue2 - dcOffset2)/4096.0); // - 2048;//0.0;
} else {
samplesA[sampleIndex*2] = ((uhADCxConvertedValue1 - dcOffset1)/4096.0); // - 2048;
samplesA[sampleIndex*2 + 1] = ((uhADCxConvertedValue1 - dcOffset1)/4096.0); // - 2048;//0.0;
}
samplesA[sampleIndex*2] = ((uhADCxConvertedValue - dcOffset1)/4096.0); // - 2048;
samplesA[sampleIndex*2 + 1] = ((uhADCxConvertedValue2 - dcOffset2)/4096.0); // - 2048;//0.0;
if(uhADCxConvertedValue > maxAmplitude) maxAmplitude = uhADCxConvertedValue;
if(uhADCxConvertedValue1 > maxAmplitude) maxAmplitude = uhADCxConvertedValue1;
if(uhADCxConvertedValue2 > maxAmplitude) maxAmplitude = uhADCxConvertedValue2;
if(samplesB[sampleIndex*2] > agcLevel) agcLevel = samplesB[sampleIndex*2];
@ -410,11 +418,16 @@ int isFwd;
break;
case 1:
if(transmitting == 0)
{
samplesB[sampleIndex*2] = ((uhADCxConvertedValue3 - dcOffset3)/4096.0); // - 2048;
samplesB[sampleIndex*2 + 1] = ((uhADCxConvertedValue2 - dcOffset2)/4096.0); // - 2048;//0.0;
} else {
samplesB[sampleIndex*2] = ((uhADCxConvertedValue1 - dcOffset1)/4096.0); // - 2048;
samplesB[sampleIndex*2 + 1] = ((uhADCxConvertedValue1 - dcOffset1)/4096.0); // - 2048;//0.0;
}
samplesB[sampleIndex*2] = ((uhADCxConvertedValue - dcOffset1)/4096.0); // - 2048;
samplesB[sampleIndex*2 + 1] = ((uhADCxConvertedValue2 - dcOffset2)/4096.0); // - 2048;//0.0;
if(uhADCxConvertedValue > maxAmplitude) maxAmplitude = uhADCxConvertedValue;
if(uhADCxConvertedValue1 > maxAmplitude) maxAmplitude = uhADCxConvertedValue1;
if(uhADCxConvertedValue2 > maxAmplitude) maxAmplitude = uhADCxConvertedValue2;
if(samplesC[sampleIndex*2] > agcLevel) agcLevel =samplesC[sampleIndex*2];
@ -439,11 +452,16 @@ int isFwd;
break;
case 2:
if(transmitting == 0)
{
samplesC[sampleIndex*2] = ((uhADCxConvertedValue3 - dcOffset3)/4096.0); // - 2048;
samplesC[sampleIndex*2 + 1] = ((uhADCxConvertedValue2 - dcOffset2)/4096.0); // - 2048;//0.0;
} else {
samplesC[sampleIndex*2] = ((uhADCxConvertedValue1 - dcOffset1)/4096.0); // - 2048;
samplesC[sampleIndex*2 + 1] = ((uhADCxConvertedValue1 - dcOffset1)/4096.0); // - 2048;//0.0;
}
samplesC[sampleIndex*2] = ((uhADCxConvertedValue - dcOffset1)/4096.0); // - 2048;
samplesC[sampleIndex*2 + 1] = ((uhADCxConvertedValue2 - dcOffset2)/4096.0); // - 2048;//0.0;
if(uhADCxConvertedValue > maxAmplitude) maxAmplitude = uhADCxConvertedValue;
if(uhADCxConvertedValue1 > maxAmplitude) maxAmplitude = uhADCxConvertedValue1;
if(uhADCxConvertedValue2 > maxAmplitude) maxAmplitude = uhADCxConvertedValue2;
if(samplesA[sampleIndex*2] > agcLevel) agcLevel = samplesA[sampleIndex*2];
@ -654,6 +672,26 @@ main(int argc, char* argv[])
updateDisplay(0);
drawWaterfall();
drawSMeter();
Adafruit_GFX_fillRect(310, 0, 3, 3, !HAL_GPIO_ReadPin(KEY1.port, KEY1.pin) ? ILI9340_RED : ILI9340_BLUE);
Adafruit_GFX_fillRect(310, 4, 3, 3, !HAL_GPIO_ReadPin(KEY2.port, KEY2.pin) ? ILI9340_RED : ILI9340_BLUE);
Adafruit_GFX_fillRect(310, 8, 3, 3, HAL_GPIO_ReadPin(TOUCH1.port, TOUCH1.pin) ? ILI9340_RED : ILI9340_BLUE);
Adafruit_GFX_fillRect(310, 12, 3, 3, HAL_GPIO_ReadPin(TOUCH2.port, TOUCH2.pin) ? ILI9340_RED : ILI9340_BLUE);
if(HAL_GPIO_ReadPin(TOUCH1.port, TOUCH1.pin))
{
transmitting = 1;
HAL_GPIO_WritePin(DAC_MUX.port, DAC_MUX.pin, 1); //0 = speaker/earphone. 1=TX Drivers
HAL_GPIO_WritePin(RX_MUX.port, RX_MUX.pin, 1); //Active Low
HAL_GPIO_WritePin(TX_MUX.port, TX_MUX.pin, 0); //Active Low
tone = 0;
} else {
transmitting = 0;
HAL_GPIO_WritePin(DAC_MUX.port, DAC_MUX.pin, 0); //0 = speaker/earphone. 1=TX Drivers
HAL_GPIO_WritePin(RX_MUX.port, RX_MUX.pin, 0); //Active Low
HAL_GPIO_WritePin(TX_MUX.port, TX_MUX.pin, 1); //Active Low
tone = 0;
}
}
}
@ -895,6 +933,13 @@ void drawWaterfall()
static float mags;
static uint8_t waterfallScanLine = 0;
unsigned short *gradient;
if(transmitting)
gradient = &bitmapIronGradient;
else
gradient = &bitmapWebSdrGradient;
arm_cmplx_mag_f32(samplesDisplay, magnitudes, FFT_SIZE);
float fftMax = 0; //AH! These are being reset each time! Static makes them persistant right? Does it also ensure they are
@ -925,14 +970,14 @@ void drawWaterfall()
{
mags = (log2(magnitudes[i] + 1)) / fftMaxMax * 100; //Log needs to be at least 1 right? We could do a + (1-fftMin) maybe? Worth it?
//mags = magnitudes[i] / fftMaxMax * 32;
Adafruit_ILI9340_drawPixel(waterfallScanLine, (120 - i), bitmapWebSdrGradient[(uint8_t) mags]);
Adafruit_ILI9340_drawPixel(waterfallScanLine, (120 - i), gradient[(uint8_t) mags]);
}
for(i = 135; i < 255; i++)
{
mags = (log2(magnitudes[i] + 1)) / fftMaxMax * 100;
//mags = magnitudes[i] / fftMaxMax * 32;
Adafruit_ILI9340_drawPixel(waterfallScanLine, 359 - (i - 15), bitmapWebSdrGradient[(uint8_t) mags]);
Adafruit_ILI9340_drawPixel(waterfallScanLine, 359 - (i - 15), gradient[(uint8_t) mags]);
}
waterfallScanLine++;
@ -940,6 +985,18 @@ void drawWaterfall()
Adafruit_ILI9340_setVertialScrollStartAddress((/*119 -*/ waterfallScanLine) /*+ 200*/);
}
void fillSamepleWithTone(int tone, float *samples)
{
int i;
for(i = 0; i < FFT_BUFFER_SIZE; i++)
{
samples[i] = 0;
}
samples[tone] = 1;
}
void processStream()
{
if(sampleRun)
@ -947,24 +1004,44 @@ void processStream()
arm_cfft_radix4_instance_f32 fft_inst;
blink_led_on();
if (sampleBankAReady == 1)
{
blink_led_on();
arm_cfft_radix4_init_f32(&fft_inst, FFT_SIZE, 0, 1);
arm_cfft_radix4_f32(&fft_inst, samplesA);
// Calculate magnitude of complex numbers output by the FFT.
if(waterfallBusy != 1)
if(tone == 0)
{
uint16_t i;
for(i = 0; i < FFT_BUFFER_SIZE; i++) samplesDisplay[i] = samplesA[i];
}
arm_cfft_radix4_init_f32(&fft_inst, FFT_SIZE, 0, 1);
applyCoeficient(samplesA, ifShift);
arm_cfft_radix4_f32(&fft_inst, samplesA);
// Calculate magnitude of complex numbers output by the FFT.
if(transmitting == 0)
{
if(waterfallBusy != 1)
{
uint16_t i;
for(i = 0; i < FFT_BUFFER_SIZE; i++) samplesDisplay[i] = samplesA[i];
}
}
applyCoeficient(samplesA, ifShift);
if(transmitting == 1)
{
if(waterfallBusy != 1)
{
uint16_t i;
for(i = 0; i < FFT_BUFFER_SIZE; i++) samplesDisplay[i] = samplesA[i];
}
}
} else {
fillSamepleWithTone(tone, samplesA);
}
arm_cfft_radix4_init_f32(&fft_inst, FFT_SIZE, 1, 1);
arm_cfft_radix4_f32(&fft_inst, samplesA);
if(mode == 2) //Try to demodulate AM
{
arm_cmplx_mag_f32(samplesA, samplesDemod, FFT_SIZE);
@ -980,18 +1057,21 @@ void processStream()
passBandRms = calculateRmsOfSample(samplesA, FFT_BUFFER_SIZE);
sampleBankAReady = 0;
blink_led_off();
}
else if(sampleBankBReady == 1)
{
blink_led_on();
arm_cfft_radix4_init_f32(&fft_inst, FFT_SIZE, 0, 1);
if(tone == 0)
{
arm_cfft_radix4_init_f32(&fft_inst, FFT_SIZE, 0, 1);
arm_cfft_radix4_f32(&fft_inst, samplesB);
// Calculate magnitude of complex numbers output by the FFT.
//arm_cmplx_mag_f32(samplesB, magnitudes, FFT_SIZE);
applyCoeficient(samplesB, ifShift);
arm_cfft_radix4_f32(&fft_inst, samplesB);
// Calculate magnitude of complex numbers output by the FFT.
//arm_cmplx_mag_f32(samplesB, magnitudes, FFT_SIZE);
applyCoeficient(samplesB, ifShift);
} else {
fillSamepleWithTone(tone, samplesB);
}
arm_cfft_radix4_init_f32(&fft_inst, FFT_SIZE, 1, 1);
arm_cfft_radix4_f32(&fft_inst, samplesB);
@ -1011,20 +1091,27 @@ void processStream()
passBandRms = calculateRmsOfSample(samplesB, FFT_BUFFER_SIZE);
sampleBankBReady = 0;
blink_led_off();
}
else if (sampleBankCReady == 1)
{
blink_led_on();
arm_cfft_radix4_init_f32(&fft_inst, FFT_SIZE, 0, 1);
if(tone == 0)
{
arm_cfft_radix4_init_f32(&fft_inst, FFT_SIZE, 0, 1);
arm_cfft_radix4_f32(&fft_inst, samplesC);
// Calculate magnitude of complex numbers output by the FFT.
arm_cfft_radix4_f32(&fft_inst, samplesC);
// Calculate magnitude of complex numbers output by the FFT.
applyCoeficient(samplesC, ifShift);
} else {
fillSamepleWithTone(tone, samplesC);
}
applyCoeficient(samplesC, ifShift);
arm_cfft_radix4_init_f32(&fft_inst, FFT_SIZE, 1, 1);
arm_cfft_radix4_f32(&fft_inst, samplesC);
@ -1043,9 +1130,10 @@ void processStream()
passBandRms = calculateRmsOfSample(samplesC, FFT_BUFFER_SIZE);
sampleBankCReady = 0;
blink_led_off();
}
blink_led_off();
sampleRun = 0;
}