TINYSA3 and TINYSA4 merged

Removed_REF_marker v1.2
erikkaashoek 5 years ago
parent 42fd2b713b
commit c3e9c8aaf2

@ -14,13 +14,13 @@
</extensions> </extensions>
</storageModule> </storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0"> <storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration buildProperties="" id="cdt.managedbuild.toolchain.gnu.cross.base.1338786050" name="Default" parent="org.eclipse.cdt.build.core.emptycfg"> <configuration artifactName="${ProjName}" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.cross.base.1338786050" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="cdt.managedbuild.toolchain.gnu.cross.base.1338786050.599957159" name="/" resourcePath=""> <folderInfo id="cdt.managedbuild.toolchain.gnu.cross.base.1338786050.599957159" name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.cross.base.654236020" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.base"> <toolChain id="cdt.managedbuild.toolchain.gnu.cross.base.654236020" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.base">
<option id="cdt.managedbuild.option.gnu.cross.prefix.2020618933" name="Prefix" superClass="cdt.managedbuild.option.gnu.cross.prefix"/> <option id="cdt.managedbuild.option.gnu.cross.prefix.2020618933" name="Prefix" superClass="cdt.managedbuild.option.gnu.cross.prefix"/>
<option id="cdt.managedbuild.option.gnu.cross.path.2061765984" name="Path" superClass="cdt.managedbuild.option.gnu.cross.path"/> <option id="cdt.managedbuild.option.gnu.cross.path.2061765984" name="Path" superClass="cdt.managedbuild.option.gnu.cross.path"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.912403626" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/> <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.912403626" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
<builder id="cdt.managedbuild.builder.gnu.cross.571430866" managedBuildOn="false" name="Gnu Make Builder.Default" superClass="cdt.managedbuild.builder.gnu.cross"/> <builder id="cdt.managedbuild.builder.gnu.cross.571430866" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="cdt.managedbuild.builder.gnu.cross"/>
<tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.636372948" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler"> <tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.636372948" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.102930183" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.102930183" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool> </tool>
@ -44,20 +44,81 @@
</storageModule> </storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration> </cconfiguration>
<cconfiguration id="cdt.managedbuild.toolchain.gnu.cross.base.1338786050.2017311615">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.cross.base.1338786050.2017311615" moduleId="org.eclipse.cdt.core.settings" name="tinySA4">
<macros>
<stringMacro name="TARGET" type="VALUE_TEXT" value="F303"/>
</macros>
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.cross.base.1338786050.2017311615" name="tinySA4" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="cdt.managedbuild.toolchain.gnu.cross.base.1338786050.2017311615." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.cross.base.1464107576" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.base">
<option id="cdt.managedbuild.option.gnu.cross.prefix.903091728" name="Prefix" superClass="cdt.managedbuild.option.gnu.cross.prefix"/>
<option id="cdt.managedbuild.option.gnu.cross.path.1331588387" name="Path" superClass="cdt.managedbuild.option.gnu.cross.path"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.1658396186" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
<builder arguments="TARGET=&quot;F303&quot;" command="make" id="cdt.managedbuild.builder.gnu.cross.972545419" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="cdt.managedbuild.builder.gnu.cross"/>
<tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.1120267824" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.693059642" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.cross.cpp.compiler.1546937688" name="Cross G++ Compiler" superClass="cdt.managedbuild.tool.gnu.cross.cpp.compiler">
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.771075410" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.cross.c.linker.434303317" name="Cross GCC Linker" superClass="cdt.managedbuild.tool.gnu.cross.c.linker"/>
<tool id="cdt.managedbuild.tool.gnu.cross.cpp.linker.857564561" name="Cross G++ Linker" superClass="cdt.managedbuild.tool.gnu.cross.cpp.linker">
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1423234842" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="cdt.managedbuild.tool.gnu.cross.archiver.1911579971" name="Cross GCC Archiver" superClass="cdt.managedbuild.tool.gnu.cross.archiver"/>
<tool id="cdt.managedbuild.tool.gnu.cross.assembler.459870016" name="Cross GCC Assembler" superClass="cdt.managedbuild.tool.gnu.cross.assembler">
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1088579964" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="tinySA.null.1080671039" name="tinySA"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope" versionNumber="2">
<configuration configurationName="tinySA4">
<resource resourceType="PROJECT" workspacePath="/tinySA"/>
</configuration>
<configuration configurationName="Default">
<resource resourceType="PROJECT" workspacePath="/tinySA"/>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
<buildTargets/>
</storageModule> </storageModule>
<storageModule moduleId="scannerConfiguration"> <storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="0.632494471"> <scannerConfigBuildInfo instanceId="0.632494471">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"/> <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"/>
</scannerConfigBuildInfo> </scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.cross.base.1338786050.2017311615;cdt.managedbuild.toolchain.gnu.cross.base.1338786050.2017311615.;cdt.managedbuild.tool.gnu.cross.cpp.compiler.1546937688;cdt.managedbuild.tool.gnu.cpp.compiler.input.771075410">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.cross.base.1338786050.2017311615;cdt.managedbuild.toolchain.gnu.cross.base.1338786050.2017311615.;cdt.managedbuild.tool.gnu.cross.c.compiler.1120267824;cdt.managedbuild.tool.gnu.c.compiler.input.693059642">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="0.1682776706"> <scannerConfigBuildInfo instanceId="0.1682776706">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"/> <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"/>
</scannerConfigBuildInfo> </scannerConfigBuildInfo>
</storageModule> </storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="tinySA.null.1080671039" name="tinySA"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
</cproject> </cproject>

@ -12,4 +12,16 @@
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
</extension> </extension>
</configuration> </configuration>
<configuration id="cdt.managedbuild.toolchain.gnu.cross.base.1338786050.2017311615" name="tinySA4">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="1944045455541829" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
</extension>
</configuration>
</project> </project>

@ -6,15 +6,16 @@
#Build target #Build target
ifeq ($(TARGET),) ifeq ($(TARGET),)
TARGET = F072 TARGET = F072
else
TARGET=F303
endif endif
TARGET=F303
# Compiler options here. # Compiler options here.
ifeq ($(USE_OPT),) ifeq ($(USE_OPT),)
ifeq ($(TARGET),F303) ifeq ($(TARGET),F303)
USE_OPT = -Og -fno-inline-small-functions -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs -fstack-usage -std=c11 USE_OPT = -Og -fno-inline-small-functions -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs -fstack-usage -std=c11
else else
USE_OPT = -Og -fno-inline-small-functions -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs -fstack-usage -std=c11 USE_OPT = -Og -fno-inline-small-functions -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs -fstack-usage -fsingle-precision-constant
endif endif
endif endif
@ -98,24 +99,29 @@ endif
# #
# Define project name here # Define project name here
ifeq ($(TARGET),F303)
PROJECT = tinySA4 PROJECT = tinySA4
else
PROJECT = tinySA
endif
# Imported source files and paths # Imported source files and paths
#CHIBIOS = ../ChibiOS-RT #CHIBIOS = ../ChibiOS-RT
CHIBIOS = ChibiOS CHIBIOS = ChibiOS
PROJ = . PROJ = .
# Startup files. # Startup files.
# HAL-OSAL files (optional).
ifeq ($(TARGET),F303) ifeq ($(TARGET),F303)
include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f3xx.mk include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f3xx.mk
include $(CHIBIOS)/os/hal/hal.mk include $(CHIBIOS)/os/hal/hal.mk
include $(CHIBIOS)/os/hal/ports/STM32/STM32F3xx/platform.mk include $(CHIBIOS)/os/hal/ports/STM32/STM32F3xx/platform.mk
include NANOVNA_STM32_F303/board.mk include NANOVNA_STM32_F303/board.mk
else else
include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f0xx.mk include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f0xx.mk
include $(CHIBIOS)/os/hal/hal.mk # HAL-OSAL files (optional).
include $(CHIBIOS)/os/hal/ports/STM32/STM32F0xx/platform.mk include $(CHIBIOS)/os/hal/hal.mk
include NANOVNA_STM32_F072/board.mk include $(CHIBIOS)/os/hal/ports/STM32/STM32F0xx/platform.mk
include NANOVNA_STM32_F072/board.mk
endif endif
include $(CHIBIOS)/os/hal/osal/rt/osal.mk include $(CHIBIOS)/os/hal/osal/rt/osal.mk
@ -132,6 +138,7 @@ include $(CHIBIOS)/os/hal/lib/streams/streams.mk
#include $(CHIBIOS)/os/various/shell/shell.mk #include $(CHIBIOS)/os/various/shell/shell.mk
# Define linker script file here # Define linker script file here
#LDSCRIPT= $(STARTUPLD)/STM32F072xB.ld
ifeq ($(TARGET),F303) ifeq ($(TARGET),F303)
LDSCRIPT= STM32F303xC.ld LDSCRIPT= STM32F303xC.ld
else else
@ -140,6 +147,7 @@ endif
# C sources that can be compiled in ARM or THUMB mode depending on the global # C sources that can be compiled in ARM or THUMB mode depending on the global
# setting. # setting.
ifeq ($(TARGET),F303)
CSRC = $(STARTUPSRC) \ CSRC = $(STARTUPSRC) \
$(KERNSRC) \ $(KERNSRC) \
$(PORTSRC) \ $(PORTSRC) \
@ -151,7 +159,19 @@ CSRC = $(STARTUPSRC) \
FatFs/ff.c \ FatFs/ff.c \
FatFs/ffunicode.c \ FatFs/ffunicode.c \
usbcfg.c \ usbcfg.c \
main.c plot.c ui.c ili9341.c tlv320aic3204.c si5351.c numfont20x22.c Font5x7.c Font10x14.c flash.c adc.c si4432.c Font7x13b.c rtc.c main.c plot.c ui.c ili9341.c tlv320aic3204.c si5351.c numfont20x22.c Font5x7.c Font10x14.c flash.c adc_F303.c si4468.c Font7x13b.c rtc.c
else
CSRC = $(STARTUPSRC) \
$(KERNSRC) \
$(PORTSRC) \
$(OSALSRC) \
$(HALSRC) \
$(PLATFORMSRC) \
$(BOARDSRC) \
$(STREAMSSRC) \
usbcfg.c \
main.c plot.c ui.c ili9341.c numfont20x22.c Font5x7.c Font10x14.c flash.c adc.c si4432.c Font7x13b.c
endif
# C++ sources that can be compiled in ARM or THUMB mode depending on the global # C++ sources that can be compiled in ARM or THUMB mode depending on the global
# setting. # setting.
@ -238,14 +258,14 @@ CPPWARN = -Wall -Wextra -Wundef
# List all user C define here, like -D_DEBUG=1 # List all user C define here, like -D_DEBUG=1
ifeq ($(TARGET),F303) ifeq ($(TARGET),F303)
UDEFS = -DARM_MATH_CM4 -DVERSION=\"$(VERSION)\" -DTINYSA_F303 -D__FPU_PRESENT -D__FPU_USED -DST7796S UDEFS = -DARM_MATH_CM4 -DVERSION=\"$(VERSION)\" -DTINYSA_F303 -D__FPU_PRESENT -D__FPU_USED -DST7796S -DTINYSA4
#Enable if install external 32.768kHz clock quartz on PC14 and PC15 pins on STM32 CPU #Enable if install external 32.768kHz clock quartz on PC14 and PC15 pins on STM32 CPU
#UDEFS+= -DVNA_USE_LSE #UDEFS+= -DVNA_USE_LSE
# Use R as usb pullup # Use R as usb pullup
UDEFS+= -DUSB_DP_R_VDD UDEFS+= -DUSB_DP_R_VDD
#-DCH_DBG_STATISTICS #-DCH_DBG_STATISTICS
else else
UDEFS = -DARM_MATH_CM0 -DVERSION=\"$(VERSION)\" UDEFS = -DSHELL_CMD_TEST_ENABLED=FALSE -DSHELL_CMD_MEM_ENABLED=FALSE -DARM_MATH_CM0 -DVERSION=\"$(VERSION)\"
endif endif
# Define ASM defines here # Define ASM defines here

210
adc.c

@ -21,111 +21,79 @@
#include "hal.h" #include "hal.h"
#include "nanovna.h" #include "nanovna.h"
#define ADC_FULL_SCALE 3300
#define F303_ADC_VREF_ALWAYS_ON #define ADC_TR(low, high) (((uint32_t)(high) << 16U) | \
(uint32_t)(low))
#define ADC_CHSELR_VREFINT ADC_CHANNEL_IN18 #define ADC_SMPR_SMP_1P5 0U /**< @brief 14 cycles conversion time */
#define ADC_CHSELR_VBAT ADC_CHANNEL_IN17 #define ADC_SMPR_SMP_239P5 7U /**< @brief 252 cycles conversion time. */
#define ADC_CFGR1_RES_12BIT (0U << 3U)
#define ADC_TOUCH_SMP_TIME ADC_SMPR_SMP_1P5
#define ADC_TOUCH_XY_SMP_TIME ADC_SMPR_SMP_601P5 #define VNA_ADC ADC1
#define ADC_VBAT_SMP_TIME ADC_SMPR_SMP_601P5
#define ADC_GRP_NUM_CHANNELS_VBAT 2
static adcsample_t samplesVBAT[ADC_GRP_NUM_CHANNELS_VBAT];
static adcsample_t samples[1];
static const ADCConversionGroup adcgrpcfgVBAT = {
FALSE,
ADC_GRP_NUM_CHANNELS_VBAT,
NULL,
NULL,
ADC_CFGR_CONT | ADC_CFGR1_RES_12BIT, // CFGR1
ADC_TR(0, 0), // ADC watchdog threshold TR1
{0, ADC_SMPR2_SMP_AN16(ADC_VBAT_SMP_TIME) | ADC_SMPR2_SMP_AN17(ADC_VBAT_SMP_TIME)/*| ADC_SMPR2_SMP_AN18(ADC_VBAT_SMP_TIME)*/}, // SMPR
{ADC_SQR1_SQ1_N(ADC_CHANNEL_IN17) | ADC_SQR1_SQ2_N(ADC_CHANNEL_IN18)/*| ADC_SQR1_SQ3_N(ADC_CHANNEL_IN16)*/, 0, 0, 0} // CHSELR
};
static const ADCConversionGroup adcgrpcfgTouch = {
TRUE, // Enables the circular buffer mode for the group.
1, // Number of the analog channels belonging to the conversion group.
NULL, // adccallback_touch
NULL, // adcerrorcallback_touch
// CFGR
ADC_CFGR_EXTEN_0 // rising edge of external trigger
| ADC_CFGR_EXTSEL_2 // EXT4 0x1000 event (TIM3_TRGO)
| ADC_CFGR_AWD1EN, // Enable Analog watchdog check interrupt
ADC_TR(0, TOUCH_THRESHOLD), // Analog watchdog threshold TR1, interrupt on touch press
{ADC_SMPR1_SMP_AN4(ADC_TOUCH_SMP_TIME), 0}, // SMPR[2]
{ADC_SQR1_SQ1_N(ADC_CHANNEL_IN4), 0, 0, 0} // SQR[4]
};
static ADCConversionGroup adcgrpcfgXY = {
FALSE,
1,
NULL, /* adccallback_touch */
NULL, /* adcerrorcallback_touch */
ADC_CFGR1_RES_12BIT, /* CFGR */
ADC_TR(0, 0), /* TR1 */
{ADC_SMPR1_SMP_AN3(ADC_TOUCH_XY_SMP_TIME) | ADC_SMPR1_SMP_AN4(ADC_TOUCH_XY_SMP_TIME), 0}, /* SMPR[2] */
{ADC_SQR1_SQ1_N(ADC_CHANNEL_IN3), 0, 0, 0} /* SQR[4] */
};
void adc_init(void) void adc_init(void)
{ {
adcStart(&ADCD2, NULL); rccEnableADC1(FALSE);
adcStart(&ADCD1, NULL);
#ifdef F303_ADC_VREF_ALWAYS_ON /* Ensure flag states */
adcSTM32EnableVBAT(&ADCD1); VNA_ADC->IER = 0;
adcSTM32EnableVREF(&ADCD1);
// adcSTM32EnableTS(&ADCD1); /* Calibration procedure.*/
#endif ADC->CCR = 0;
if (VNA_ADC->CR & ADC_CR_ADEN) {
VNA_ADC->CR |= ~ADC_CR_ADDIS; /* Disable ADC */
}
while (VNA_ADC->CR & ADC_CR_ADEN)
;
VNA_ADC->CFGR1 &= ~ADC_CFGR1_DMAEN;
VNA_ADC->CR |= ADC_CR_ADCAL;
while (VNA_ADC->CR & ADC_CR_ADCAL)
;
if (VNA_ADC->ISR & ADC_ISR_ADRDY) {
VNA_ADC->ISR |= ADC_ISR_ADRDY; /* clear ADRDY */
}
/* Enable ADC */
VNA_ADC->CR |= ADC_CR_ADEN;
while (!(VNA_ADC->ISR & ADC_ISR_ADRDY))
;
} }
uint16_t adc_single_read(uint32_t chsel) uint16_t adc_single_read(uint32_t chsel)
{ {
/* ADC setup */ /* ADC setup */
// adcStart(&ADCD2, NULL); VNA_ADC->ISR = VNA_ADC->ISR;
adcgrpcfgXY.sqr[0] = ADC_SQR1_SQ1_N(chsel); VNA_ADC->IER = 0;
adcConvert(&ADCD2, &adcgrpcfgXY, samples, 1); VNA_ADC->TR = ADC_TR(0, 0);
return(samples[0]); VNA_ADC->SMPR = ADC_SMPR_SMP_239P5;
VNA_ADC->CFGR1 = ADC_CFGR1_RES_12BIT;
VNA_ADC->CHSELR = chsel;
uint32_t result = 0;
uint32_t count = 1<<3; // Average count
do{
VNA_ADC->CR |= ADC_CR_ADSTART; // ADC conversion start.
while (VNA_ADC->CR & ADC_CR_ADSTART)
;
result+=VNA_ADC->DR;
}while(--count);
return result>>3;
} }
int16_t adc_vbat_read(void) int16_t adc_vbat_read(void)
{ {
uint16_t VREFINT_CAL = (*((uint16_t*)0x1FFFF7BA)); // 13.9 Temperature sensor and internal reference voltage
uint32_t vbat; // VREFINT_CAL calibrated on 3.3V, need get value in mV
uint32_t vrefint; #define ADC_FULL_SCALE 3300
// const uint16_t V25 = 1750;// when V25=1.41V at ref 3.3V #define VREFINT_CAL (*((uint16_t*)0x1FFFF7BA))
// const uint16_t Avg_Slope = 5; //when avg_slope=4.3mV/C at ref 3.3V adc_stop();
// uint16_t temperature_cal1 = *((uint16_t*) ((uint32_t)0x1FFFF7B8U)); ADC->CCR |= ADC_CCR_VREFEN | ADC_CCR_VBATEN;
// /* Internal temperature sensor, address of parameter TS_CAL1: On STM32F3, // VREFINT == ADC_IN17
// temperature sensor ADC raw data acquired at temperature 25 DegC (tolerance: +-5 DegC), uint32_t vrefint = adc_single_read(ADC_CHSELR_CHSEL17);
// Vref+ = 3.3 V (tolerance: +-10 mV). */ // VBAT == ADC_IN18
// uint16_t temperature_cal2 = *((uint16_t*) ((uint32_t)0x1FFFF7C2U)); // VBATEN enables resiter devider circuit. It consume vbat power.
// /* Internal temperature sensor, address of parameter TS_CAL2: On STM32F3, uint32_t vbat = adc_single_read(ADC_CHSELR_CHSEL18);
// temperature sensor ADC raw data acquired at temperature 110 DegC (tolerance: +-5 DegC), ADC->CCR &= ~(ADC_CCR_VREFEN | ADC_CCR_VBATEN);
// Vref+ = 3.3 V (tolerance: +-10 mV). */ touch_start_watchdog();
// float avg_slope = ((float)(temperature_cal1 - temperature_cal2))/(110-25);
// float ts;
#ifndef F303_ADC_VREF_ALWAYS_ON
adcSTM32EnableVBAT(&ADCD1);
adcSTM32EnableVREF(&ADCD1);
// adcSTM32EnableTS(&ADCD1);
adcConvert(&ADCD1, &adcgrpcfgVBAT, samplesVBAT, ADC_GRP_BUF_DEPTH_VBAT);
adcSTM32DisableVBAT(&ADCD1);
adcSTM32DisableVREF(&ADCD1);
// adcSTM32DisableTS(&ADCD1);
#else
adcConvert(&ADCD1, &adcgrpcfgVBAT, samplesVBAT, sizeof(samplesVBAT)/(sizeof(adcsample_t)*ADC_GRP_NUM_CHANNELS_VBAT));
#endif
vbat = samplesVBAT[0];
vrefint = samplesVBAT[1];
// ts = samplesVBAT[2];
// uint16_t vts = (ADC_FULL_SCALE * VREFINT_CAL * ts / (vrefint * ((1<<12)-1)));
// uint16_t TemperatureC2 = (uint16_t)((V25-ts)/Avg_Slope+25);
// uint16_t TemperatureC = (uint16_t)((V25-ts)/avg_slope+25);
// vbat_raw = (3300 * 2 * vbat / 4095) * (VREFINT_CAL / vrefint) // vbat_raw = (3300 * 2 * vbat / 4095) * (VREFINT_CAL / vrefint)
// uint16_t vbat_raw = (ADC_FULL_SCALE * VREFINT_CAL * (float)vbat * 2 / (vrefint * ((1<<12)-1))); // uint16_t vbat_raw = (ADC_FULL_SCALE * VREFINT_CAL * (float)vbat * 2 / (vrefint * ((1<<12)-1)));
// For speed divide not on 4095, divide on 4096, get little error, but no matter // For speed divide not on 4095, divide on 4096, get little error, but no matter
@ -137,41 +105,61 @@ int16_t adc_vbat_read(void)
return vbat_raw + config.vbat_offset; return vbat_raw + config.vbat_offset;
} }
void adc_start_analog_watchdogd(void) void adc_start_analog_watchdogd(uint32_t chsel)
{ {
// adcStart(&ADCD2, NULL); uint32_t cfgr1;
adcStartConversion(&ADCD2, &adcgrpcfgTouch, samples, 1);
cfgr1 = ADC_CFGR1_RES_12BIT | ADC_CFGR1_AWDEN
| ADC_CFGR1_EXTEN_0 // rising edge of external trigger
| ADC_CFGR1_EXTSEL_0 | ADC_CFGR1_EXTSEL_1; // TRG3 , /* CFGR1 */
/* ADC setup, if it is defined a callback for the analog watch dog then it
is enabled.*/
VNA_ADC->ISR = VNA_ADC->ISR;
VNA_ADC->IER = ADC_IER_AWDIE;
VNA_ADC->TR = ADC_TR(0, TOUCH_THRESHOLD);
VNA_ADC->SMPR = ADC_SMPR_SMP_1P5;
VNA_ADC->CHSELR = chsel;
/* ADC configuration and start.*/
VNA_ADC->CFGR1 = cfgr1;
/* ADC conversion start.*/
VNA_ADC->CR |= ADC_CR_ADSTART;
} }
void adc_stop(void) void adc_stop(void)
{ {
#if 1 if (VNA_ADC->CR & ADC_CR_ADEN) {
adcStopConversion(&ADCD2); if (VNA_ADC->CR & ADC_CR_ADSTART) {
#else VNA_ADC->CR |= ADC_CR_ADSTP;
if (ADC2->CR & ADC_CR_ADEN) { while (VNA_ADC->CR & ADC_CR_ADSTP)
if (ADC2->CR & ADC_CR_ADSTART) {
ADC2->CR |= ADC_CR_ADSTP;
while (ADC2->CR & ADC_CR_ADSTP)
; ;
} }
/* VNA_ADC->CR |= ADC_CR_ADDIS;
while (VNA_ADC->CR & ADC_CR_ADDIS)
;*/
} }
#endif
} }
static inline void adc_interrupt(void) void adc_interrupt(void)
{ {
uint32_t isr = ADC2->ISR; uint32_t isr = VNA_ADC->ISR;
ADC2->ISR = isr; VNA_ADC->ISR = isr;
if (isr & ADC_ISR_OVR) { if (isr & ADC_ISR_OVR) {
// ADC overflow condition, this could happen only if the DMA is unable to read data fast enough. /* ADC overflow condition, this could happen only if the DMA is unable
to read data fast enough.*/
} }
if (isr & ADC_ISR_AWD1) { if (isr & ADC_ISR_AWD) {
/* Analog watchdog error.*/ /* Analog watchdog error.*/
handle_touch_interrupt(); handle_touch_interrupt();
} }
} }
OSAL_IRQ_HANDLER(STM32_ADC2_HANDLER) OSAL_IRQ_HANDLER(STM32_ADC1_HANDLER)
{ {
OSAL_IRQ_PROLOGUE(); OSAL_IRQ_PROLOGUE();
@ -180,7 +168,7 @@ OSAL_IRQ_HANDLER(STM32_ADC2_HANDLER)
OSAL_IRQ_EPILOGUE(); OSAL_IRQ_EPILOGUE();
} }
#if 0 #if 1
uint16_t adc_multi_read(uint32_t chsel, uint16_t *result, uint32_t count) uint16_t adc_multi_read(uint32_t chsel, uint16_t *result, uint32_t count)
{ {
/* ADC setup */ /* ADC setup */

@ -0,0 +1,237 @@
/*
* Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com
* All rights reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* The software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "ch.h"
#include "hal.h"
#include "nanovna.h"
#define ADC_FULL_SCALE 3300
#define F303_ADC_VREF_ALWAYS_ON
#define ADC_CHSELR_VREFINT ADC_CHANNEL_IN18
#define ADC_CHSELR_VBAT ADC_CHANNEL_IN17
#define ADC_TOUCH_SMP_TIME ADC_SMPR_SMP_1P5
#define ADC_TOUCH_XY_SMP_TIME ADC_SMPR_SMP_601P5
#define ADC_VBAT_SMP_TIME ADC_SMPR_SMP_601P5
#define ADC_GRP_NUM_CHANNELS_VBAT 2
static adcsample_t samplesVBAT[ADC_GRP_NUM_CHANNELS_VBAT];
static adcsample_t samples[1];
static const ADCConversionGroup adcgrpcfgVBAT = {
FALSE,
ADC_GRP_NUM_CHANNELS_VBAT,
NULL,
NULL,
ADC_CFGR_CONT | ADC_CFGR1_RES_12BIT, // CFGR1
ADC_TR(0, 0), // ADC watchdog threshold TR1
{0, ADC_SMPR2_SMP_AN16(ADC_VBAT_SMP_TIME) | ADC_SMPR2_SMP_AN17(ADC_VBAT_SMP_TIME)/*| ADC_SMPR2_SMP_AN18(ADC_VBAT_SMP_TIME)*/}, // SMPR
{ADC_SQR1_SQ1_N(ADC_CHANNEL_IN17) | ADC_SQR1_SQ2_N(ADC_CHANNEL_IN18)/*| ADC_SQR1_SQ3_N(ADC_CHANNEL_IN16)*/, 0, 0, 0} // CHSELR
};
static const ADCConversionGroup adcgrpcfgTouch = {
TRUE, // Enables the circular buffer mode for the group.
1, // Number of the analog channels belonging to the conversion group.
NULL, // adccallback_touch
NULL, // adcerrorcallback_touch
// CFGR
ADC_CFGR_EXTEN_0 // rising edge of external trigger
| ADC_CFGR_EXTSEL_2 // EXT4 0x1000 event (TIM3_TRGO)
| ADC_CFGR_AWD1EN, // Enable Analog watchdog check interrupt
ADC_TR(0, TOUCH_THRESHOLD), // Analog watchdog threshold TR1, interrupt on touch press
{ADC_SMPR1_SMP_AN4(ADC_TOUCH_SMP_TIME), 0}, // SMPR[2]
{ADC_SQR1_SQ1_N(ADC_CHANNEL_IN4), 0, 0, 0} // SQR[4]
};
static ADCConversionGroup adcgrpcfgXY = {
FALSE,
1,
NULL, /* adccallback_touch */
NULL, /* adcerrorcallback_touch */
ADC_CFGR1_RES_12BIT, /* CFGR */
ADC_TR(0, 0), /* TR1 */
{ADC_SMPR1_SMP_AN3(ADC_TOUCH_XY_SMP_TIME) | ADC_SMPR1_SMP_AN4(ADC_TOUCH_XY_SMP_TIME), 0}, /* SMPR[2] */
{ADC_SQR1_SQ1_N(ADC_CHANNEL_IN3), 0, 0, 0} /* SQR[4] */
};
void adc_init(void)
{
adcStart(&ADCD2, NULL);
adcStart(&ADCD1, NULL);
#ifdef F303_ADC_VREF_ALWAYS_ON
adcSTM32EnableVBAT(&ADCD1);
adcSTM32EnableVREF(&ADCD1);
// adcSTM32EnableTS(&ADCD1);
#endif
}
uint16_t adc_single_read(uint32_t chsel)
{
/* ADC setup */
// adcStart(&ADCD2, NULL);
adcgrpcfgXY.sqr[0] = ADC_SQR1_SQ1_N(chsel);
adcConvert(&ADCD2, &adcgrpcfgXY, samples, 1);
return(samples[0]);
}
int16_t adc_vbat_read(void)
{
uint16_t VREFINT_CAL = (*((uint16_t*)0x1FFFF7BA));
uint32_t vbat;
uint32_t vrefint;
// const uint16_t V25 = 1750;// when V25=1.41V at ref 3.3V
// const uint16_t Avg_Slope = 5; //when avg_slope=4.3mV/C at ref 3.3V
// uint16_t temperature_cal1 = *((uint16_t*) ((uint32_t)0x1FFFF7B8U));
// /* Internal temperature sensor, address of parameter TS_CAL1: On STM32F3,
// temperature sensor ADC raw data acquired at temperature 25 DegC (tolerance: +-5 DegC),
// Vref+ = 3.3 V (tolerance: +-10 mV). */
// uint16_t temperature_cal2 = *((uint16_t*) ((uint32_t)0x1FFFF7C2U));
// /* Internal temperature sensor, address of parameter TS_CAL2: On STM32F3,
// temperature sensor ADC raw data acquired at temperature 110 DegC (tolerance: +-5 DegC),
// Vref+ = 3.3 V (tolerance: +-10 mV). */
// float avg_slope = ((float)(temperature_cal1 - temperature_cal2))/(110-25);
// float ts;
#ifndef F303_ADC_VREF_ALWAYS_ON
adcSTM32EnableVBAT(&ADCD1);
adcSTM32EnableVREF(&ADCD1);
// adcSTM32EnableTS(&ADCD1);
adcConvert(&ADCD1, &adcgrpcfgVBAT, samplesVBAT, ADC_GRP_BUF_DEPTH_VBAT);
adcSTM32DisableVBAT(&ADCD1);
adcSTM32DisableVREF(&ADCD1);
// adcSTM32DisableTS(&ADCD1);
#else
adcConvert(&ADCD1, &adcgrpcfgVBAT, samplesVBAT, sizeof(samplesVBAT)/(sizeof(adcsample_t)*ADC_GRP_NUM_CHANNELS_VBAT));
#endif
vbat = samplesVBAT[0];
vrefint = samplesVBAT[1];
// ts = samplesVBAT[2];
// uint16_t vts = (ADC_FULL_SCALE * VREFINT_CAL * ts / (vrefint * ((1<<12)-1)));
// uint16_t TemperatureC2 = (uint16_t)((V25-ts)/Avg_Slope+25);
// uint16_t TemperatureC = (uint16_t)((V25-ts)/avg_slope+25);
// vbat_raw = (3300 * 2 * vbat / 4095) * (VREFINT_CAL / vrefint)
// uint16_t vbat_raw = (ADC_FULL_SCALE * VREFINT_CAL * (float)vbat * 2 / (vrefint * ((1<<12)-1)));
// For speed divide not on 4095, divide on 4096, get little error, but no matter
uint16_t vbat_raw = ((ADC_FULL_SCALE * 2 * vbat)>>12) * VREFINT_CAL / vrefint;
if (vbat_raw < 100) {
// maybe D2 is not installed
return -1;
}
return vbat_raw + config.vbat_offset;
}
void adc_start_analog_watchdogd(void)
{
// adcStart(&ADCD2, NULL);
adcStartConversion(&ADCD2, &adcgrpcfgTouch, samples, 1);
}
void adc_stop(void)
{
#if 1
adcStopConversion(&ADCD2);
#else
if (ADC2->CR & ADC_CR_ADEN) {
if (ADC2->CR & ADC_CR_ADSTART) {
ADC2->CR |= ADC_CR_ADSTP;
while (ADC2->CR & ADC_CR_ADSTP)
;
}
}
#endif
}
static inline void adc_interrupt(void)
{
uint32_t isr = ADC2->ISR;
ADC2->ISR = isr;
if (isr & ADC_ISR_OVR) {
// ADC overflow condition, this could happen only if the DMA is unable to read data fast enough.
}
if (isr & ADC_ISR_AWD1) {
/* Analog watchdog error.*/
handle_touch_interrupt();
}
}
OSAL_IRQ_HANDLER(STM32_ADC2_HANDLER)
{
OSAL_IRQ_PROLOGUE();
adc_interrupt();
OSAL_IRQ_EPILOGUE();
}
#if 0
uint16_t adc_multi_read(uint32_t chsel, uint16_t *result, uint32_t count)
{
/* ADC setup */
VNA_ADC->ISR = VNA_ADC->ISR;
VNA_ADC->IER = 0;
VNA_ADC->TR = ADC_TR(0, 0);
VNA_ADC->SMPR = ADC_SMPR_SMP_1P5;
VNA_ADC->CFGR1 = ADC_CFGR1_RES_12BIT;
VNA_ADC->CHSELR = chsel;
// palSetPadMode(GPIOA, 10, PAL_MODE_OUTPUT_PUSHPULL);
do{
#if 0
if (count < 145)
palSetPad(GPIOA, 10);
else
palClearPad(GPIOA, 10);
#endif
VNA_ADC->CR |= ADC_CR_ADSTART; // ADC conversion start.
// while (VNA_ADC->CR & ADC_CR_ADSTART)
while(!(VNA_ADC->ISR & ADC_ISR_EOC));
;
*(result++) =VNA_ADC->DR;
}while(--count);
return count;
}
int16_t adc_buf_read(uint32_t chsel, uint16_t *result, uint32_t count)
{
adc_stop();
#if 0
// drive high to low on Y line (coordinates from left to right)
palSetPad(GPIOB, GPIOB_YN);
palClearPad(GPIOA, GPIOA_YP);
// Set Y line as output
palSetPadMode(GPIOB, GPIOB_YN, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOA, GPIOA_YP, PAL_MODE_OUTPUT_PUSHPULL);
// Set X line as input
palSetPadMode(GPIOB, GPIOB_XN, PAL_MODE_INPUT); // Hi-z mode
palSetPadMode(GPIOA, GPIOA_XP, PAL_MODE_INPUT_ANALOG); // <- ADC_TOUCH_X channel
uint16_t res = adc_multi_read(ADC_TOUCH_X, result, count);
#else
// palSetPadMode(GPIOA, 9, PAL_MODE_INPUT_ANALOG);
uint16_t res = adc_multi_read(chsel, result, count); // ADC_CHSELR_CHSEL9
#endif
touch_start_watchdog();
return res;
}
#endif

@ -56,8 +56,16 @@ static char smallPrefix[] = {'m', 0x1d, 'n', 'p', 'f', 'a', 'z', 'y', 0};
#pragma pack(pop) #pragma pack(pop)
#ifdef TINYSA4
typedef uint64_t ulong_t;
typedef int64_t long_t;
#else
typedef uint32_t ulong_t;
typedef int32_t long_t;
#endif
static char *long_to_string_with_divisor(char *p, static char *long_to_string_with_divisor(char *p,
uint64_t num, long_t num,
uint32_t radix, uint32_t radix,
uint32_t precision) { uint32_t precision) {
char *q = p + MAX_FILLER; char *q = p + MAX_FILLER;
@ -84,7 +92,7 @@ static char *long_to_string_with_divisor(char *p,
#define FREQ_PREFIX_SPACE 4 #define FREQ_PREFIX_SPACE 4
static char * static char *
ulong_freq(char *p, uint64_t freq, uint32_t precision) ulong_freq(char *p, long_t freq, uint32_t precision)
{ {
uint8_t flag = FREQ_PSET; uint8_t flag = FREQ_PSET;
flag|= precision == 0 ? FREQ_PREFIX_SPACE : FREQ_NO_SPACE; flag|= precision == 0 ? FREQ_PREFIX_SPACE : FREQ_NO_SPACE;
@ -105,7 +113,7 @@ ulong_freq(char *p, uint64_t freq, uint32_t precision)
// Fast and compact division uint32_t on 10, using shifts, result: // Fast and compact division uint32_t on 10, using shifts, result:
// c = freq % 10 // c = freq % 10
// freq = freq / 10; // freq = freq / 10;
uint64_t c = freq; long_t c = freq;
freq >>= 1; freq >>= 1;
freq += freq >> 1; freq += freq >> 1;
freq += freq >> 4; freq += freq >> 4;
@ -258,7 +266,8 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) {
uint32_t u; uint32_t u;
int32_t l; int32_t l;
float f; float f;
int64_t x; long_t x;
ulong_t ux;
}value; }value;
#if CHPRINTF_USE_FLOAT #if CHPRINTF_USE_FLOAT
char tmpbuf[2*MAX_FILLER + 1]; char tmpbuf[2*MAX_FILLER + 1];
@ -331,14 +340,16 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) {
state|=DEFAULT_PRESCISION; state|=DEFAULT_PRESCISION;
//Get [length] //Get [length]
if (c == 'l' || c == 'L') { if (c == 'l' || c == 'L') {
#ifdef TINYSA4
state|=IS_LONG; // Ignore Long state|=IS_LONG; // Ignore Long
#endif
if (*fmt) if (*fmt)
c = *fmt++; c = *fmt++;
} }
/* #ifdef TINYSA4
else if ((c >= 'A') && (c <= 'Z')) else if ((c >= 'A') && (c <= 'Z'))
state|=IS_LONG; state|=IS_LONG;
*/ #endif
// Parse type // Parse type
switch (c) { switch (c) {
case 'c': case 'c':
@ -358,14 +369,16 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) {
case 'd': case 'd':
case 'I': case 'I':
case 'i': case 'i':
#ifdef TINYSA4
if (state & IS_LONG) if (state & IS_LONG)
value.x = va_arg(ap, int64_t); value.x = va_arg(ap, int64_t);
else else
#endif
value.x = va_arg(ap, int32_t); value.x = va_arg(ap, int32_t);
if (value.x < 0) { if (value.x < 0) {
state|=NEGATIVE; state|=NEGATIVE;
*p++ = '-'; *p++ = '-';
value.x = -value.l; value.x = -value.x;
} }
else if (state & POSITIVE) else if (state & POSITIVE)
*p++ = '+'; *p++ = '+';
@ -373,14 +386,17 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) {
else if (state & PLUS_SPACE) else if (state & PLUS_SPACE)
*p++ = ' '; *p++ = ' ';
#endif #endif
p = long_to_string_with_divisor(p, (int64_t)value.x, 10, 0); p = long_to_string_with_divisor(p, value.x, 10, 0);
break; break;
case 'q': case 'q':
case 'Q':
#ifdef TINYSA4
if (state & IS_LONG) if (state & IS_LONG)
value.x = va_arg(ap, uint64_t); value.ux = va_arg(ap, uint64_t);
else else
value.x = va_arg(ap, uint32_t); #endif
p=ulong_freq(p, value.x, precision); value.ux = va_arg(ap, uint32_t);
p=ulong_freq(p, value.ux, precision);
break; break;
#if CHPRINTF_USE_FLOAT #if CHPRINTF_USE_FLOAT
case 'F': case 'F':
@ -416,11 +432,13 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) {
case 'o': case 'o':
c = 8; c = 8;
unsigned_common: unsigned_common:
#ifdef TINYSA4
if (state & IS_LONG) if (state & IS_LONG)
value.x = va_arg(ap, uint64_t); value.ux = va_arg(ap, uint64_t);
else else
value.x = va_arg(ap, uint32_t); #endif
p = long_to_string_with_divisor(p, value.x, c, 0); value.ux = va_arg(ap, uint32_t);
p = long_to_string_with_divisor(p, value.ux, c, 0);
break; break;
default: default:
*p++ = c; *p++ = c;

@ -317,7 +317,11 @@
* buffers. * buffers.
*/ */
#if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__) #if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__)
#ifdef TINYSA4
#define SERIAL_USB_BUFFERS_SIZE 128 #define SERIAL_USB_BUFFERS_SIZE 128
#else
#define SERIAL_USB_BUFFERS_SIZE 64
#endif
#endif #endif
/** /**

@ -20,28 +20,43 @@
#include "ch.h" #include "ch.h"
#include "hal.h" #include "hal.h"
#include "nanovna.h" #include "nanovna.h"
#ifdef TINYSA4
#include "si4432.h" #include "si4432.h"
#endif
#include "spi.h" #include "spi.h"
// Allow enable DMA for read display data // Allow enable DMA for read display data
#ifdef TINYSA4
#define __USE_DISPLAY_DMA_RX__ #define __USE_DISPLAY_DMA_RX__
#endif
// Pin macros for LCD // Pin macros for LCD
#ifdef TINYSA4
#define LCD_CS_LOW palClearPad(GPIO_LCD_CS_PORT, GPIO_LCD_CS) #define LCD_CS_LOW palClearPad(GPIO_LCD_CS_PORT, GPIO_LCD_CS)
#define LCD_CS_HIGH palSetPad(GPIO_LCD_CS_PORT, GPIO_LCD_CS) #define LCD_CS_HIGH palSetPad(GPIO_LCD_CS_PORT, GPIO_LCD_CS)
#define LCD_RESET_ASSERT palClearPad(GPIO_LCD_RESET_PORT, GPIO_LCD_RESET) #define LCD_RESET_ASSERT palClearPad(GPIO_LCD_RESET_PORT, GPIO_LCD_RESET)
#define LCD_RESET_NEGATE palSetPad(GPIO_LCD_RESET_PORT, GPIO_LCD_RESET) #define LCD_RESET_NEGATE palSetPad(GPIO_LCD_RESET_PORT, GPIO_LCD_RESET)
#define LCD_DC_CMD palClearPad(GPIO_LCD_CD_PORT, GPIO_LCD_CD) #define LCD_DC_CMD palClearPad(GPIO_LCD_CD_PORT, GPIO_LCD_CD)
#define LCD_DC_DATA palSetPad(GPIO_LCD_CD_PORT, GPIO_LCD_CD) #define LCD_DC_DATA palSetPad(GPIO_LCD_CD_PORT, GPIO_LCD_CD)
#else
#define LCD_CS_LOW palClearPad(GPIOB, GPIOB_LCD_CS)
#define LCD_CS_HIGH palSetPad(GPIOB, GPIOB_LCD_CS)
#define LCD_RESET_ASSERT palClearPad(GPIOA, GPIOA_LCD_RESET)
#define LCD_RESET_NEGATE palSetPad(GPIOA, GPIOA_LCD_RESET)
#define LCD_DC_CMD palClearPad(GPIOB, GPIOB_LCD_CD)
#define LCD_DC_DATA palSetPad(GPIOB, GPIOB_LCD_CD)
#endif
#define LCD_SPI SPI1 #define LCD_SPI SPI1
// Set SPI bus speed for LCD // Set SPI bus speed for LCD
#define LCD_SPI_SPEED SPI_BR_DIV2 #define LCD_SPI_SPEED SPI_BR_DIV2
//Not define if need use some as Tx speed //Not define if need use some as Tx speed
#ifdef TINYSA4
#define LCD_SPI_RX_SPEED SPI_BR_DIV4 #define LCD_SPI_RX_SPEED SPI_BR_DIV4
#endif
uint16_t spi_buffer[SPI_BUFFER_SIZE]; uint16_t spi_buffer[SPI_BUFFER_SIZE];
// Default foreground & background colors // Default foreground & background colors
@ -311,6 +326,7 @@ static void spi_init(void)
LCD_SPI->CR1|= SPI_CR1_SPE; //SPI enable LCD_SPI->CR1|= SPI_CR1_SPE; //SPI enable
} }
#ifdef TINYSA4
static uint16_t current_spi_mode; static uint16_t current_spi_mode;
void set_SPI_mode(uint16_t mode){ void set_SPI_mode(uint16_t mode){
if (current_spi_mode == mode) return; if (current_spi_mode == mode) return;
@ -335,14 +351,19 @@ void set_SPI_mode(uint16_t mode){
} }
current_spi_mode = mode; current_spi_mode = mode;
} }
#endif
// Disable inline for this function // Disable inline for this function
static void send_command(uint8_t cmd, uint8_t len, const uint8_t *data) static void send_command(uint8_t cmd, uint8_t len, const uint8_t *data)
{ {
// Uncomment on low speed SPI (possible get here before previous tx complete) // Uncomment on low speed SPI (possible get here before previous tx complete)
// while (SPI_IN_TX_RX(LCD_SPI)) #ifndef TINYSA4
while (SPI_IN_TX_RX(LCD_SPI));
#endif
#ifdef TINYSA4
// while (SPI_IN_TX_RX); // while (SPI_IN_TX_RX);
set_SPI_mode(SPI_MODE_LCD); set_SPI_mode(SPI_MODE_LCD);
#endif
LCD_CS_LOW; LCD_CS_LOW;
LCD_DC_CMD; LCD_DC_CMD;
SPI_WRITE_8BIT(LCD_SPI, cmd); SPI_WRITE_8BIT(LCD_SPI, cmd);
@ -359,6 +380,7 @@ static void send_command(uint8_t cmd, uint8_t len, const uint8_t *data)
//LCD_CS_HIGH; //LCD_CS_HIGH;
} }
#ifdef TINYSA4
static const uint8_t ST7796S_init_seq[] = { static const uint8_t ST7796S_init_seq[] = {
// SW reset // SW reset
ILI9341_SOFTWARE_RESET, 0, ILI9341_SOFTWARE_RESET, 0,
@ -402,6 +424,66 @@ static const uint8_t ST7796S_init_seq[] = {
ILI9341_DISPLAY_ON, 0, ILI9341_DISPLAY_ON, 0,
0 // sentinel 0 // sentinel
}; };
#else
static const uint8_t ili9341_init_seq[] = {
// cmd, len, data...,
// SW reset
ILI9341_SOFTWARE_RESET, 0,
// display off
ILI9341_DISPLAY_OFF, 0,
// Power control B
ILI9341_POWERB, 3, 0x00, 0xC1, 0x30,
// Power on sequence control
ILI9341_POWER_SEQ, 4, 0x64, 0x03, 0x12, 0x81,
// Driver timing control A
ILI9341_DTCA, 3, 0x85, 0x00, 0x78,
// Power control A
ILI9341_POWERA, 5, 0x39, 0x2C, 0x00, 0x34, 0x02,
// Pump ratio control
ILI9341_PUMP_RATIO_CONTROL, 1, 0x20,
// Driver timing control B
ILI9341_DTCB, 2, 0x00, 0x00,
// POWER_CONTROL_1
ILI9341_POWER_CONTROL_1, 1, 0x23,
// POWER_CONTROL_2
ILI9341_POWER_CONTROL_2, 1, 0x10,
// VCOM_CONTROL_1
ILI9341_VCOM_CONTROL_1, 2, 0x3e, 0x28,
// VCOM_CONTROL_2
ILI9341_VCOM_CONTROL_2, 1, 0xBE,
// MEMORY_ACCESS_CONTROL
//ILI9341_MEMORY_ACCESS_CONTROL, 1, 0x48, // portlait
ILI9341_MEMORY_ACCESS_CONTROL, 1, DISPLAY_ROTATION_0, // landscape
// COLMOD_PIXEL_FORMAT_SET : 16 bit pixel
ILI9341_PIXEL_FORMAT_SET, 1, 0x55,
// Frame Rate
ILI9341_FRAME_RATE_CONTROL_1, 2, 0x00, 0x18,
// Gamma Function Disable
ILI9341_3GAMMA_EN, 1, 0x00,
// gamma set for curve 01/2/04/08
ILI9341_GAMMA_SET, 1, 0x01,
// positive gamma correction
ILI9341_POSITIVE_GAMMA_CORRECTION, 15, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00,
// negativ gamma correction
ILI9341_NEGATIVE_GAMMA_CORRECTION, 15, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F,
// Column Address Set
//ILI9341_COLUMN_ADDRESS_SET, 4, 0x00, 0x00, 0x01, 0x3f, // width 320
// Page Address Set
//ILI9341_PAGE_ADDRESS_SET, 4, 0x00, 0x00, 0x00, 0xef, // height 240
// entry mode
ILI9341_ENTRY_MODE_SET, 1, 0x06,
// display function control
ILI9341_DISPLAY_FUNCTION_CONTROL, 3, 0x08, 0x82, 0x27,
// Interface Control (set WEMODE=0)
ILI9341_INTERFACE_CONTROL, 3, 0x00, 0x00, 0x00,
// sleep out
ILI9341_SLEEP_OUT, 0,
// display on
ILI9341_DISPLAY_ON, 0,
0 // sentinel
};
#endif
void ili9341_init(void) void ili9341_init(void)
{ {
@ -411,12 +493,19 @@ void ili9341_init(void)
chThdSleepMilliseconds(10); chThdSleepMilliseconds(10);
LCD_RESET_NEGATE; LCD_RESET_NEGATE;
const uint8_t *p; const uint8_t *p;
for (p = ST7796S_init_seq; *p; ) { #ifdef TINYSA4
p = ST7796S_init_seq;
#else
p = ili9341_init_seq;
#endif
while (*p) {
send_command(p[0], p[1], &p[2]); send_command(p[0], p[1], &p[2]);
p += 2 + p[1]; p += 2 + p[1];
chThdSleepMilliseconds(5); chThdSleepMilliseconds(5);
} }
#ifdef TINYSA4
LCD_CS_HIGH; LCD_CS_HIGH;
#endif
} }
static void ili9341_setWindow(int x, int y, int w, int h){ static void ili9341_setWindow(int x, int y, int w, int h){
@ -518,8 +607,19 @@ void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out)
#endif #endif
// require 8bit dummy clock // require 8bit dummy clock
spi_RxByte(); spi_RxByte();
#ifdef TINYSA4
// receive pixel data to buffer // receive pixel data to buffer
spi_RxBuffer((uint8_t *)out, len * 2); spi_RxBuffer((uint8_t *)out, len * 2);
#else
while (len-- > 0) {
uint8_t r, g, b;
// read data is always 18bit
r = spi_RxByte();
g = spi_RxByte();
b = spi_RxByte();
*out++ = RGB565(r, g, b);
}
#endif
// restore speed if need // restore speed if need
#ifdef LCD_SPI_RX_SPEED #ifdef LCD_SPI_RX_SPEED
SPI_BR_SET(LCD_SPI, LCD_SPI_SPEED); SPI_BR_SET(LCD_SPI, LCD_SPI_SPEED);
@ -534,6 +634,7 @@ void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out)
{ {
uint16_t dummy_tx = 0; uint16_t dummy_tx = 0;
uint8_t *rgbbuf = (uint8_t *)out; uint8_t *rgbbuf = (uint8_t *)out;
#ifdef TINYSA4
uint16_t data_size = len * 2; uint16_t data_size = len * 2;
//uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) }; //uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
//uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) }; //uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
@ -541,7 +642,13 @@ void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out)
uint32_t yy = __REV16(y | ((y + h - 1) << 16)); uint32_t yy = __REV16(y | ((y + h - 1) << 16));
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t *)&xx); send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t *)&xx);
send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t *)&yy); send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t *)&yy);
#else
uint16_t data_size = len * 3;
ili9341_setWindow(x, y ,w, h);
#endif
send_command(ILI9341_MEMORY_READ, 0, NULL); send_command(ILI9341_MEMORY_READ, 0, NULL);
// Init Rx DMA buffer, size, mode (spi and mem data size is 8 bit) // Init Rx DMA buffer, size, mode (spi and mem data size is 8 bit)
dmaStreamSetMemory0(dmarx, rgbbuf); dmaStreamSetMemory0(dmarx, rgbbuf);
dmaStreamSetTransactionSize(dmarx, data_size); dmaStreamSetTransactionSize(dmarx, data_size);
@ -569,6 +676,18 @@ void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out)
SPI_BR_SET(LCD_SPI, LCD_SPI_SPEED); SPI_BR_SET(LCD_SPI, LCD_SPI_SPEED);
#endif #endif
LCD_CS_HIGH; LCD_CS_HIGH;
#ifndef TINYSA4
// Parce recived data
while (len-- > 0) {
uint8_t r, g, b;
// read data is always 18bit
r = rgbbuf[0];
g = rgbbuf[1];
b = rgbbuf[2];
*out++ = RGB565(r, g, b);
rgbbuf += 3;
}
#endif
} }
#endif #endif

@ -1,5 +1,6 @@
/* /*
* *
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option) * the Free Software Foundation; either version 3, or (at your option)
* any later version. * any later version.
@ -124,15 +125,22 @@ const char *info_about[]={
}; };
uint16_t dirty = true; uint16_t dirty = true;
bool completed = false; bool completed = false;
#ifdef TINYSA4
static THD_WORKING_AREA(waThread1, 1124); static THD_WORKING_AREA(waThread1, 1124);
#else
static THD_WORKING_AREA(waThread1, 768);
#endif
static THD_FUNCTION(Thread1, arg) static THD_FUNCTION(Thread1, arg)
{ {
(void)arg; (void)arg;
chRegSetThreadName("sweep"); chRegSetThreadName("sweep");
// ui_process(); #ifndef TINYSA4
ui_process();
#endif
while (1) { while (1) {
// START_PROFILE // START_PROFILE
@ -445,9 +453,9 @@ int set_frequency(freq_t freq)
// Rewrite universal standart str to value functions to more compact // Rewrite universal standart str to value functions to more compact
// //
// Convert string to int32 // Convert string to int32
static int64_t my_atoi(const char *p) static long_t my_atoi(const char *p)
{ {
int64_t value = 0; long_t value = 0;
uint32_t c; uint32_t c;
bool neg = false; bool neg = false;
@ -468,9 +476,9 @@ static int64_t my_atoi(const char *p)
// 0o - for oct radix // 0o - for oct radix
// 0b - for bin radix // 0b - for bin radix
// default dec radix // default dec radix
uint64_t my_atoui(const char *p) freq_t my_atoui(const char *p)
{ {
uint64_t value = 0, radix = 10, c; freq_t value = 0, radix = 10, c;
if (*p == '+') p++; if (*p == '+') p++;
if (*p == '0') { if (*p == '0') {
switch (p[1]) { switch (p[1]) {
@ -739,7 +747,9 @@ void i2s_end_callback(I2SDriver *i2sp, size_t offset, size_t n)
--wait_count; --wait_count;
} else if (wait_count > 0) { } else if (wait_count > 0) {
if (accumerate_count > 0) { if (accumerate_count > 0) {
#ifndef TINYSA4
// dsp_process(p, n); // dsp_process(p, n);
#endif
accumerate_count--; accumerate_count--;
} }
#ifdef ENABLED_DUMP #ifdef ENABLED_DUMP
@ -846,16 +856,17 @@ VNA_SHELL_FUNCTION(cmd_release)
VNA_SHELL_FUNCTION(cmd_capture) VNA_SHELL_FUNCTION(cmd_capture)
{ {
// read pixel count at one time (PART*2 bytes required for read buffer) // read pixel count at one time (PART*2 bytes required for read buffer)
(void)argc;
(void)argv;
int i, y; int i, y;
if (argc == 1) { #ifdef TINYSA4
int m = generic_option_cmd("capture", "off|on", argc, argv[0]);
if (m>=0) {
auto_capture = m;
return;
}
}
#if SPI_BUFFER_SIZE < (2*LCD_WIDTH) #if SPI_BUFFER_SIZE < (2*LCD_WIDTH)
#error "Low size of spi_buffer for cmd_capture" #error "Low size of spi_buffer for cmd_capture"
#endif
#else
#if SPI_BUFFER_SIZE < (3*LCD_WIDTH + 1)
#error "Low size of spi_buffer for cmd_capture"
#endif
#endif #endif
// read 2 row pixel time (read buffer limit by 2/3 + 1 from spi_buffer size) // read 2 row pixel time (read buffer limit by 2/3 + 1 from spi_buffer size)
for (y = 0; y < LCD_HEIGHT; y += 2) { for (y = 0; y < LCD_HEIGHT; y += 2) {
@ -945,33 +956,40 @@ config_t config = {
.harmonic_freq_threshold = 300000000, .harmonic_freq_threshold = 300000000,
#endif #endif
.lcd_palette = LCD_DEFAULT_PALETTE, .lcd_palette = LCD_DEFAULT_PALETTE,
.vbat_offset = 220,
#ifdef TINYSA4 #ifdef TINYSA4
.frequency_IF1 = DEFAULT_IF,
.frequency_IF2 = 0,
.ultra_threshold = 800000000,
#endif #endif
.low_level_offset = 100.0, // Uncalibrated
.high_level_offset = 100.0, // Uncalibrated
.low_level_output_offset = 0.0, // Uncalibrated
.high_level_output_offset = 0.0, // Uncalibrated
#ifdef TINYSA3 #ifdef TINYSA3
.vbat_offset = 500,
.low_level_offset = 100, // Uncalibrated
.high_level_offset = 100, // Uncalibrated
.low_correction_frequency = { 10000, 100000, 200000, 500000, 30000000, 140000000, 200000000, 300000000, 330000000, 350000000 }, .low_correction_frequency = { 10000, 100000, 200000, 500000, 30000000, 140000000, 200000000, 300000000, 330000000, 350000000 },
.low_correction_value = { +6.0, +2.8, +1.6, -0.4, 0.0, -0.4, +0.4, +3.0, +4.0, +8.1 }, .low_correction_value = { +6.0, +2.8, +1.6, -0.4, 0.0, -0.4, +0.4, +3.0, +4.0, +8.1 },
.high_correction_frequency = { 240000000, 280000000, 300000000, 400000000, 500000000, 600000000, 700000000, 800000000, 900000000, 960000000 }, .high_correction_frequency = { 240000000, 280000000, 300000000, 400000000, 500000000, 600000000, 700000000, 800000000, 900000000, 960000000 },
.high_correction_value = { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 }, .high_correction_value = { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 },
.setting_frequency_10mhz = 10000000,
.cor_am = -14,
.cor_wfm = -17,
.cor_nfm = -17,
#endif #endif
#ifdef TINYSA4 #ifdef TINYSA4
.vbat_offset = 220,
.frequency_IF1 = DEFAULT_IF,
.frequency_IF2 = 0,
.ultra_threshold = 800000000,
.low_level_offset = 100.0, // Uncalibrated
.high_level_offset = 100.0, // Uncalibrated
.low_level_output_offset = 0.0, // Uncalibrated
.high_level_output_offset = 0.0, // Uncalibrated
.low_correction_frequency = { 10000, 100000, 200000, 500000, 30000000, 140000000, 200000000, 300000000, 330000000, 350000000 }, .low_correction_frequency = { 10000, 100000, 200000, 500000, 30000000, 140000000, 200000000, 300000000, 330000000, 350000000 },
.low_correction_value = { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 }, .low_correction_value = { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 },
.high_correction_frequency = { 10000, 100000, 200000, 500000, 50000000, 140000000, 200000000, 300000000, 330000000, 350000000 }, .high_correction_frequency = { 10000, 100000, 200000, 500000, 50000000, 140000000, 200000000, 300000000, 330000000, 350000000 },
.high_correction_value = { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 }, .high_correction_value = { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 },
#endif
.setting_frequency_30mhz = 30000000, .setting_frequency_30mhz = 30000000,
.cor_am = -5, .cor_am = -5,
.cor_wfm = -55, .cor_wfm = -55,
.cor_nfm = -55, .cor_nfm = -55,
.ultra = false, .ultra = false,
#endif
.sweep_voltage = 3.3, .sweep_voltage = 3.3,
}; };
@ -1134,7 +1152,7 @@ VNA_SHELL_FUNCTION(cmd_scan)
uint16_t mask = my_atoui(argv[3]); uint16_t mask = my_atoui(argv[3]);
if (mask) { if (mask) {
for (i = 0; i < points; i++) { for (i = 0; i < points; i++) {
if (mask & 1) shell_printf("%Lu ", frequencies[i]); if (mask & 1) shell_printf("%U ", frequencies[i]);
if (mask & 2) shell_printf("%f %f ", value(measured[2][i]), 0.0); if (mask & 2) shell_printf("%f %f ", value(measured[2][i]), 0.0);
if (mask & 4) shell_printf("%f %f ", value(measured[1][i]), 0.0); if (mask & 4) shell_printf("%f %f ", value(measured[1][i]), 0.0);
if (mask & 8) shell_printf("%f %f ", value(measured[0][i]), 0.0); if (mask & 8) shell_printf("%f %f ", value(measured[0][i]), 0.0);
@ -1332,7 +1350,7 @@ get_sweep_frequency(int type)
VNA_SHELL_FUNCTION(cmd_sweep) VNA_SHELL_FUNCTION(cmd_sweep)
{ {
if (argc == 0) { if (argc == 0) {
shell_printf("%Ld %Ld %d\r\n", get_sweep_frequency(ST_START), get_sweep_frequency(ST_STOP), sweep_points); shell_printf("%D %D %d\r\n", get_sweep_frequency(ST_START), get_sweep_frequency(ST_STOP), sweep_points);
return; return;
} else if (argc > 3) { } else if (argc > 3) {
goto usage; goto usage;
@ -2000,7 +2018,7 @@ VNA_SHELL_FUNCTION(cmd_marker)
if (argc == 0) { if (argc == 0) {
for (t = 0; t < MARKERS_MAX; t++) { for (t = 0; t < MARKERS_MAX; t++) {
if (markers[t].enabled) { if (markers[t].enabled) {
shell_printf("%d %d %Ld %f\r\n", t+1, markers[t].index, markers[t].frequency, value(actual_t[markers[t].index])); shell_printf("%d %d %D %f\r\n", t+1, markers[t].index, markers[t].frequency, value(actual_t[markers[t].index]));
} }
} }
return; return;
@ -2017,7 +2035,7 @@ VNA_SHELL_FUNCTION(cmd_marker)
goto usage; goto usage;
if (argc == 1) { if (argc == 1) {
display_marker: display_marker:
shell_printf("%d %d %Ld %.2f\r\n", t+1, markers[t].index, markers[t].frequency, value(actual_t[markers[t].index])); shell_printf("%d %d %D %.2f\r\n", t+1, markers[t].index, markers[t].frequency, value(actual_t[markers[t].index]));
active_marker = t; active_marker = t;
// select active marker // select active marker
markers[t].enabled = TRUE; markers[t].enabled = TRUE;
@ -2085,7 +2103,7 @@ VNA_SHELL_FUNCTION(cmd_frequencies)
(void)argv; (void)argv;
for (i = 0; i < sweep_points; i++) { for (i = 0; i < sweep_points; i++) {
if (frequencies[i] != 0) if (frequencies[i] != 0)
shell_printf("%Lu\r\n", frequencies[i]); shell_printf("%U\r\n", frequencies[i]);
} }
} }
@ -2475,7 +2493,9 @@ static const VNAShellCommand commands[] =
{"color" , cmd_color , 0}, {"color" , cmd_color , 0},
#endif #endif
{ "if", cmd_if, 0 }, { "if", cmd_if, 0 },
#ifdef TINYSA4
{ "if1", cmd_if1, 0 }, { "if1", cmd_if1, 0 },
#endif
{ "attenuate", cmd_attenuate, 0 }, { "attenuate", cmd_attenuate, 0 },
{ "level", cmd_level, 0 }, { "level", cmd_level, 0 },
{ "sweeptime", cmd_sweeptime, 0 }, { "sweeptime", cmd_sweeptime, 0 },
@ -2485,9 +2505,11 @@ static const VNAShellCommand commands[] =
{ "rbw", cmd_rbw, 0 }, { "rbw", cmd_rbw, 0 },
{ "mode", cmd_mode, CMD_WAIT_MUTEX }, { "mode", cmd_mode, CMD_WAIT_MUTEX },
{ "spur", cmd_spur, 0 }, { "spur", cmd_spur, 0 },
#ifdef TINYSA4
{ "lna", cmd_lna, 0 }, { "lna", cmd_lna, 0 },
{ "ultra", cmd_ultra, 0 }, { "ultra", cmd_ultra, 0 },
{ "ultra_start", cmd_ultra_start, CMD_WAIT_MUTEX }, { "ultra_start", cmd_ultra_start, CMD_WAIT_MUTEX },
#endif
{ "load", cmd_load, 0 }, { "load", cmd_load, 0 },
{ "offset", cmd_offset, 0}, { "offset", cmd_offset, 0},
{ "output", cmd_output, 0 }, { "output", cmd_output, 0 },
@ -2783,6 +2805,7 @@ static const I2CConfig i2ccfg = {
.cr2 = 0 .cr2 = 0
}; };
#endif #endif
static DACConfig dac1cfg1 = { static DACConfig dac1cfg1 = {
//init: 2047U, //init: 2047U,
init: 1922U, init: 1922U,
@ -2799,7 +2822,11 @@ static const GPTConfig gpt4cfg = {
void my_microsecond_delay(int t) void my_microsecond_delay(int t)
{ {
#ifdef TINYSA4
if (t>1) gptPolledDelay(&GPTD4, t); // t us delay if (t>1) gptPolledDelay(&GPTD4, t); // t us delay
#else
if (t>1) gptPolledDelay(&GPTD14, t); // t us delay
#endif
} }
#if 0 #if 0
/* /*
@ -2881,7 +2908,11 @@ int main(void)
palClearPad(GPIOB, GPIOA_RF_PWR); palClearPad(GPIOB, GPIOA_RF_PWR);
chThdSleepMilliseconds(200); chThdSleepMilliseconds(200);
#endif #endif
#ifdef TINYSA4
palSetPad(GPIOB, GPIOA_RF_PWR); palSetPad(GPIOB, GPIOA_RF_PWR);
#else
palSetPad(GPIOB, GPIO_RF_PWR);
#endif
chThdSleepMilliseconds(500); chThdSleepMilliseconds(500);
#endif #endif
@ -2919,24 +2950,31 @@ int main(void)
/* /*
* Initiate 1 micro second timer * Initiate 1 micro second timer
*/ */
#ifdef TINYSA4
gptStart(&GPTD4, &gpt4cfg); gptStart(&GPTD4, &gpt4cfg);
gptPolledDelay(&GPTD4, 10); // 10 us delay gptPolledDelay(&GPTD4, 10); // 10 us delay
#else
gptStart(&GPTD14, &gpt4cfg);
gptPolledDelay(&GPTD14, 10); // 10 us delay
#endif
/* restore config */ /* restore config */
config_recall(); config_recall();
#if 1
if (caldata_recall(0) == -1) { if (caldata_recall(0) == -1) {
load_LCD_properties(); load_LCD_properties();
} }
#endif
/* /*
* Init Shell console connection data (after load config for settings) * Init Shell console connection data (after load config for settings)
*/ */
shell_init_connection(); shell_init_connection();
/* restore frequencies and calibration 0 slot properties from flash memory */ #ifdef TINYSA4
dac1cfg1.init = config.dac_value; dac1cfg1.init = config.dac_value;
#else
dac1cfg1.init = 0;
#endif
/* /*
* Starting DAC1 driver, setting up the output pin as analog as suggested * Starting DAC1 driver, setting up the output pin as analog as suggested
* by the Reference Manual. * by the Reference Manual.

@ -14,27 +14,26 @@
limitations under the License. limitations under the License.
*/ */
#ifdef TINYSA_F303
#include "mcuconf_F303.h"
#else
#ifndef MCUCONF_H #ifndef MCUCONF_H
#define MCUCONF_H #define MCUCONF_H
#ifdef TINYSA_F303
/* /*
* STM32F0xx drivers configuration. * STM32F3xx drivers configuration.
* The following settings override the default settings present in * The following settings override the default settings present in
* the various device driver implementation headers. * the various device driver implementation headers.
* Note that the settings for each driver only have effect if the whole * Note that the settings for each driver only have effect if the whole
* driver is enabled in halconf.h. * driver is enabled in halconf.h.
* *
* IRQ priorities: * IRQ priorities:
* 3...0 Lowest...Highest. * 15...0 Lowest...Highest.
* *
* DMA priorities: * DMA priorities:
* 0...3 Lowest...Highest. * 0...3 Lowest...Highest.
*/ */
#define STM32F0xx_MCUCONF #define STM32F3xx_MCUCONF
/* /*
* HAL driver system settings. * HAL driver system settings.
@ -42,26 +41,38 @@
#define STM32_NO_INIT FALSE #define STM32_NO_INIT FALSE
#define STM32_PVD_ENABLE FALSE #define STM32_PVD_ENABLE FALSE
#define STM32_PLS STM32_PLS_LEV0 #define STM32_PLS STM32_PLS_LEV0
#define STM32_HSI_ENABLED TRUE #if 0 // 72MHz
#define STM32_HSI14_ENABLED TRUE #define STM32_HSI_ENABLED FALSE
#define STM32_HSI48_ENABLED TRUE #define STM32_HSE_ENABLED TRUE
#define STM32_SW STM32_SW_PLL
#define STM32_PLLSRC STM32_PLLSRC_HSE
#define STM32_PREDIV_VALUE 1
#define STM32_PLLMUL_VALUE 9
#define STM32_USBPRE STM32_USBPRE_DIV1P5
#else
#define STM32_HSI_ENABLED TRUE // 48MHz
#define STM32_HSE_ENABLED FALSE #define STM32_HSE_ENABLED FALSE
#define STM32_SW STM32_SW_PLL #define STM32_SW STM32_SW_PLL
#define STM32_PLLSRC STM32_PLLSRC_HSI_DIV2 #define STM32_PLLSRC STM32_PLLSRC_HSI
#define STM32_PREDIV_VALUE 1 #define STM32_PREDIV_VALUE 1
#define STM32_PLLMUL_VALUE 12 #define STM32_PLLMUL_VALUE 12 // prediv HSI always 2
#define STM32_USBPRE STM32_USBPRE_DIV1
#endif
#define STM32_HPRE STM32_HPRE_DIV1 #define STM32_HPRE STM32_HPRE_DIV1
#define STM32_PPRE STM32_PPRE_DIV1 #define STM32_PPRE1 STM32_PPRE1_DIV2
#define STM32_ADCSW STM32_ADCSW_HSI14 // Set SPI1 more faster use PPRE2 max speed
#define STM32_ADCPRE STM32_ADCPRE_DIV4 #define STM32_PPRE2 STM32_PPRE2_DIV1
#define STM32_MCOSEL STM32_MCOSEL_PLLDIV2 #define STM32_MCOSEL STM32_MCOSEL_PLLDIV2
#define STM32_ADCPRE STM32_ADCPRE_DIV4 #define STM32_ADC12PRES STM32_ADC12PRES_DIV2
#define STM32_ADCSW STM32_ADCSW_HSI14 //#define STM32_ADC34PRES STM32_ADC34PRES_DIV1
#define STM32_USBSW STM32_USBSW_HSI48
#define STM32_CECSW STM32_CECSW_HSI
//#define STM32_I2C1SW STM32_I2C1SW_HSI
#define STM32_I2C1SW STM32_I2C1SW_SYSCLK
#define STM32_USART1SW STM32_USART1SW_PCLK #define STM32_USART1SW STM32_USART1SW_PCLK
//#define STM32_USART2SW STM32_USART2SW_PCLK
//#define STM32_USART3SW STM32_USART3SW_PCLK
#define STM32_I2C1SW STM32_I2C1SW_SYSCLK
//#define STM32_I2C2SW STM32_I2C2SW_SYSCLK
#define STM32_TIM1SW STM32_TIM1SW_PCLK2
#define STM32_TIM8SW STM32_TIM8SW_PCLK2
#define STM32_USB_CLOCK_REQUIRED TRUE
/* /*
* RTC driver system settings for stm32f303 * RTC driver system settings for stm32f303
@ -84,6 +95,222 @@
#define STM32_LSEDRV (3 << 3) #define STM32_LSEDRV (3 << 3)
#endif #endif
/*
* ADC driver system settings.
*/
#define STM32_ADC_USE_ADC1 TRUE
#define STM32_ADC_USE_ADC2 TRUE
#define STM32_ADC_USE_ADC3 FALSE
#define STM32_ADC_ADC1_DMA_STREAM STM32_DMA_STREAM_ID(1, 1)
#define STM32_ADC_ADC2_DMA_STREAM STM32_DMA_STREAM_ID(2, 1)
//#define STM32_ADC_ADC3_DMA_STREAM STM32_DMA_STREAM_ID(2, 5)
//#define STM32_ADC_ADC4_DMA_STREAM STM32_DMA_STREAM_ID(2, 2)
#define STM32_ADC_ADC12_DMA_PRIORITY 2
//#define STM32_ADC_ADC34_DMA_PRIORITY 2
#define STM32_ADC_ADC12_IRQ_PRIORITY 2
//#define STM32_ADC_ADC34_IRQ_PRIORITY 5
#define STM32_ADC_ADC12_DMA_IRQ_PRIORITY 2
//#define STM32_ADC_ADC34_DMA_IRQ_PRIORITY 5
//#define STM32_ADC_ADC12_CLOCK_MODE ADC_CCR_CKMODE_ADCCK
//#define STM32_ADC_ADC12_CLOCK_MODE ADC_CCR_CKMODE_AHB_DIV2
#define STM32_ADC_ADC12_CLOCK_MODE ADC_CCR_CKMODE_AHB_DIV1
//#define STM32_ADC_ADC34_CLOCK_MODE ADC_CCR_CKMODE_AHB_DIV1
#define STM32_ADC_DUAL_MODE FALSE
/*
* CAN driver system settings.
*/
#define STM32_CAN_USE_CAN1 FALSE
#define STM32_CAN_CAN1_IRQ_PRIORITY 11
/*
* DAC driver system settings.
*/
#define STM32_DAC_DUAL_MODE FALSE
#define STM32_DAC_USE_DAC1_CH1 TRUE
#define STM32_DAC_USE_DAC1_CH2 TRUE
#define STM32_DAC_DAC1_CH1_IRQ_PRIORITY 10
#define STM32_DAC_DAC1_CH2_IRQ_PRIORITY 10
#define STM32_DAC_DAC1_CH1_DMA_PRIORITY 2
#define STM32_DAC_DAC1_CH2_DMA_PRIORITY 2
/*
* EXT driver system settings.
*/
#define STM32_EXT_EXTI0_1_IRQ_PRIORITY 3
#define STM32_EXT_EXTI2_3_IRQ_PRIORITY 3
#define STM32_EXT_EXTI4_15_IRQ_PRIORITY 3
#define STM32_EXT_EXTI16_IRQ_PRIORITY 3
#define STM32_EXT_EXTI17_IRQ_PRIORITY 3
#define STM32_EXT_EXTI21_22_IRQ_PRIORITY 3
#define STM32_DISABLE_EXTI2122_HANDLER TRUE
/*
* GPT driver system settings.
*/
#define STM32_GPT_USE_TIM1 FALSE
#define STM32_GPT_USE_TIM2 FALSE
#define STM32_GPT_USE_TIM3 TRUE
#define STM32_GPT_USE_TIM4 TRUE
#define STM32_GPT_TIM1_IRQ_PRIORITY 2
#define STM32_GPT_TIM2_IRQ_PRIORITY 2
#define STM32_GPT_TIM3_IRQ_PRIORITY 2
#define STM32_GPT_TIM4_IRQ_PRIORITY 2
/*
* I2C driver system settings.
*/
#define STM32_I2C_USE_I2C1 TRUE
#define STM32_I2C_USE_I2C2 FALSE
#define STM32_I2C_BUSY_TIMEOUT 50
#define STM32_I2C_I2C1_IRQ_PRIORITY 3
#define STM32_I2C_I2C2_IRQ_PRIORITY 3
#define STM32_I2C_USE_DMA TRUE
#define STM32_I2C_I2C1_DMA_PRIORITY 1
#define STM32_I2C_I2C2_DMA_PRIORITY 1
#define STM32_I2C_DMA_ERROR_HOOK(i2cp) osalSysHalt("DMA failure")
/*
* I2S driver system settings.
*/
#define STM32_I2S_USE_SPI1 FALSE
#define STM32_I2S_USE_SPI2 TRUE
#define STM32_I2S_SPI1_MODE (STM32_I2S_MODE_MASTER | \
STM32_I2S_MODE_RX)
#define STM32_I2S_SPI2_MODE (STM32_I2S_MODE_SLAVE | \
STM32_I2S_MODE_RX )
#define STM32_I2S_SPI1_IRQ_PRIORITY 2
#define STM32_I2S_SPI2_IRQ_PRIORITY 2
#define STM32_I2S_SPI1_DMA_PRIORITY 1
#define STM32_I2S_SPI2_DMA_PRIORITY 1
#define STM32_I2S_SPI1_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2)
#define STM32_I2S_SPI1_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3)
#define STM32_I2S_SPI2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4)
#define STM32_I2S_SPI2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 5)
#define STM32_I2S_DMA_ERROR_HOOK(i2sp) osalSysHalt("DMA failure")
/*
* ICU driver system settings.
*/
#define STM32_ICU_USE_TIM1 FALSE
#define STM32_ICU_USE_TIM2 FALSE
#define STM32_ICU_USE_TIM3 FALSE
#define STM32_ICU_TIM1_IRQ_PRIORITY 3
#define STM32_ICU_TIM2_IRQ_PRIORITY 3
#define STM32_ICU_TIM3_IRQ_PRIORITY 3
/*
* PWM driver system settings.
*/
#define STM32_PWM_USE_ADVANCED FALSE
#define STM32_PWM_USE_TIM1 FALSE
#define STM32_PWM_USE_TIM2 FALSE
#define STM32_PWM_USE_TIM3 FALSE
#define STM32_PWM_TIM1_IRQ_PRIORITY 3
#define STM32_PWM_TIM2_IRQ_PRIORITY 3
#define STM32_PWM_TIM3_IRQ_PRIORITY 3
/*
* SERIAL driver system settings.
*/
#define STM32_SERIAL_USE_USART1 TRUE
#define STM32_SERIAL_USE_USART2 FALSE
#define STM32_SERIAL_USART1_PRIORITY 3
#define STM32_SERIAL_USART2_PRIORITY 3
/*
* SPI driver system settings.
*/
#define STM32_SPI_USE_SPI1 TRUE
#define STM32_SPI_USE_SPI2 FALSE
#define STM32_SPI_USE_SPI3 FALSE
#define STM32_SPI_SPI1_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2)
#define STM32_SPI_SPI1_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3)
#define STM32_SPI_SPI1_DMA_PRIORITY 1
#define STM32_SPI_SPI2_DMA_PRIORITY 1
#define STM32_SPI_SPI1_IRQ_PRIORITY 2
#define STM32_SPI_SPI2_IRQ_PRIORITY 2
#define STM32_SPI_DMA_ERROR_HOOK(spip) osalSysHalt("DMA failure")
/*
* ST driver system settings.
*/
#define STM32_ST_IRQ_PRIORITY 2
#define STM32_ST_USE_TIMER 2
/*
* UART driver system settings.
*/
#define STM32_UART_USE_USART1 FALSE
#define STM32_UART_USE_USART2 FALSE
#define STM32_UART_USART1_IRQ_PRIORITY 3
#define STM32_UART_USART2_IRQ_PRIORITY 3
#define STM32_UART_USART1_DMA_PRIORITY 0
#define STM32_UART_USART2_DMA_PRIORITY 0
#define STM32_UART_USART3_DMA_PRIORITY 0
#define STM32_UART_DMA_ERROR_HOOK(uartp) osalSysHalt("DMA failure")
/*
* USB driver system settings.
*/
#define STM32_USB_USE_USB1 TRUE
#define STM32_USB_LOW_POWER_ON_SUSPEND FALSE
#define STM32_USB_USB1_LP_IRQ_PRIORITY 3
/*
* WDG driver system settings.
*/
#define STM32_WDG_USE_IWDG FALSE
#else
/*
* STM32F0xx drivers configuration.
* The following settings override the default settings present in
* the various device driver implementation headers.
* Note that the settings for each driver only have effect if the whole
* driver is enabled in halconf.h.
*
* IRQ priorities:
* 3...0 Lowest...Highest.
*
* DMA priorities:
* 0...3 Lowest...Highest.
*/
#define STM32F0xx_MCUCONF
/*
* HAL driver system settings.
*/
#define STM32_NO_INIT FALSE
#define STM32_PVD_ENABLE FALSE
#define STM32_PLS STM32_PLS_LEV0
#define STM32_HSI_ENABLED TRUE
#define STM32_HSI14_ENABLED TRUE
#define STM32_HSI48_ENABLED TRUE
#define STM32_LSI_ENABLED TRUE
#define STM32_HSE_ENABLED FALSE
#define STM32_LSE_ENABLED FALSE
#define STM32_SW STM32_SW_PLL
#define STM32_PLLSRC STM32_PLLSRC_HSI_DIV2
#define STM32_PREDIV_VALUE 1
#define STM32_PLLMUL_VALUE 12
#define STM32_HPRE STM32_HPRE_DIV1
#define STM32_PPRE STM32_PPRE_DIV1
#define STM32_ADCSW STM32_ADCSW_HSI14
#define STM32_ADCPRE STM32_ADCPRE_DIV4
#define STM32_MCOSEL STM32_MCOSEL_PLLDIV2
#define STM32_ADCPRE STM32_ADCPRE_DIV4
#define STM32_ADCSW STM32_ADCSW_HSI14
#define STM32_USBSW STM32_USBSW_HSI48
#define STM32_CECSW STM32_CECSW_HSI
//#define STM32_I2C1SW STM32_I2C1SW_HSI
#define STM32_I2C1SW STM32_I2C1SW_SYSCLK
#define STM32_USART1SW STM32_USART1SW_PCLK
#define STM32_RTCSEL STM32_RTCSEL_LSI
/* /*
* ADC driver system settings. * ADC driver system settings.
*/ */
@ -246,5 +473,6 @@
*/ */
#define STM32_WDG_USE_IWDG FALSE #define STM32_WDG_USE_IWDG FALSE
#endif /* MCUCONF_H */
#endif #endif
#endif /* MCUCONF_H */

@ -17,14 +17,14 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#include "ch.h" #include "ch.h"
#define TINYSA4_PROTO
//#ifdef TINYSA_F303 #ifdef TINYSA_F303
#include "adc_F303.h" #include "adc_F303.h"
#define TINYSA4 // #define TINYSA4
//#else #define TINYSA4_PROTO
//#define TINYSA3 #else
//#endif #define TINYSA3
#endif
// Need enable HAL_USE_SPI in halconf.h // Need enable HAL_USE_SPI in halconf.h
#define __USE_DISPLAY_DMA__ #define __USE_DISPLAY_DMA__
@ -34,11 +34,11 @@
#ifdef TINYSA3 #ifdef TINYSA3
#define __SI4432__ #define __SI4432__
#endif #endif
//#ifdef TINYSA4 #ifdef TINYSA4
#define __SI4463__ #define __SI4463__
#define __SI4468__ #define __SI4468__
#define __ADF4351__ #define __ADF4351__
//#endif #endif
#define __PE4302__ #define __PE4302__
//#define __SIMULATION__ //#define __SIMULATION__
//#define __PIPELINE__ //#define __PIPELINE__
@ -51,16 +51,15 @@
#define __FAST_SWEEP__ // Pre-fill SI4432 RSSI buffer to get fastest sweep in zero span mode #define __FAST_SWEEP__ // Pre-fill SI4432 RSSI buffer to get fastest sweep in zero span mode
// #define __AUDIO__ // #define __AUDIO__
//#define __HAM_BAND__ //#define __HAM_BAND__
//#define __ULTRA__ // Add harmonics mode on low input.
#define __SPUR__ // Does spur reduction by shifting IF #define __SPUR__ // Does spur reduction by shifting IF
//#define __USE_SERIAL_CONSOLE__ // Enable serial I/O connection (need enable HAL_USE_SERIAL as TRUE in halconf.h) //#define __USE_SERIAL_CONSOLE__ // Enable serial I/O connection (need enable HAL_USE_SERIAL as TRUE in halconf.h)
#define __HARMONIC__
#define __SINGLE_LETTER__ #define __SINGLE_LETTER__
#define __NICE_BIG_FONT__ #define __NICE_BIG_FONT__
#define __QUASI_PEAK__ #define __QUASI_PEAK__
#ifdef TINYSA4
#define __HARMONIC__
#define __REMOTE_DESKTOP__ #define __REMOTE_DESKTOP__
#endif
#ifdef TINYSA3 #ifdef TINYSA3
#define DEFAULT_IF 433800000 #define DEFAULT_IF 433800000
@ -103,9 +102,11 @@
#ifdef TINYSA3 #ifdef TINYSA3
typedef uint32_t freq_t; typedef uint32_t freq_t;
typedef int32_t long_t;
#endif #endif
#ifdef TINYSA4 #ifdef TINYSA4
typedef uint64_t freq_t; typedef uint64_t freq_t;
typedef int64_t long_t;
#endif #endif
#define CORRECTION_POINTS 10 // Frequency dependent level correction table entries #define CORRECTION_POINTS 10 // Frequency dependent level correction table entries
@ -197,8 +198,6 @@ void send_buffer(uint8_t * buf, int s);
void set_marker_frequency(int m, freq_t f); void set_marker_frequency(int m, freq_t f);
void toggle_sweep(void); void toggle_sweep(void);
void toggle_mute(void); void toggle_mute(void);
void toggle_extra_lna(void);
void set_extra_lna(int t);
void load_default_properties(void); void load_default_properties(void);
enum { enum {
@ -234,28 +233,20 @@ extern uint8_t sweep_mode;
extern bool completed; extern bool completed;
extern const char *info_about[]; extern const char *info_about[];
// ------------------------------- sa_core.c ----------------------------------
#ifdef TINYSA4 #ifdef TINYSA4
#define SI_DRIVE_STEP 0.5 // Power step per step in drive level void toggle_extra_lna(void);
#define SWITCH_ATTENUATION 34 void set_extra_lna(int t);
//#define POWER_OFFSET -18 // Max level with all enabled #endif
//#define POWER_RANGE 70
#define MAX_DRIVE 16
#define MIN_DRIVE 8
#define SL_GENHIGH_LEVEL_MIN -15
#define SL_GENHIGH_LEVEL_RANGE 9
#define SL_GENLOW_LEVEL_MIN -88
#define SL_GENLOW_LEVEL_RANGE 70
// ------------------------------- sa_core.c ----------------------------------
#else
#define SI_DRIVE_STEP 3 extern int level_min(void);
#define SWITCH_ATTENUATION 30 extern int level_max(void);
#define POWER_OFFSET 15 extern int level_range(void);
#endif
extern const char * const unit_string[]; extern const char * const unit_string[];
extern const int8_t drive_dBm [];
extern uint8_t signal_is_AM; extern uint8_t signal_is_AM;
extern const int reffer_freq[]; extern const int reffer_freq[];
extern freq_t minFreq; extern freq_t minFreq;
@ -268,7 +259,6 @@ void SetPowerGrid(int);
void SetRefLevel(float); void SetRefLevel(float);
void set_refer_output(int); void set_refer_output(int);
void toggle_below_IF(void); void toggle_below_IF(void);
void toggle_ultra(void);
int get_refer_output(void); int get_refer_output(void);
void set_attenuation(float); void set_attenuation(float);
float get_attenuation(void); float get_attenuation(void);
@ -285,12 +275,9 @@ void set_RBW(uint32_t rbw_x10);
void set_lo_drive(int d); void set_lo_drive(int d);
void set_rx_drive(int d); void set_rx_drive(int d);
void set_IF(int f); void set_IF(int f);
void set_IF2(int f);
void set_R(int f);
void set_step_delay(int t); void set_step_delay(int t);
void set_offset_delay(int t); void set_offset_delay(int t);
void set_repeat(int); void set_repeat(int);
void clear_frequency_cache(void);
void set_level_sweep(float); void set_level_sweep(float);
void set_level(float); void set_level(float);
void set_sweep_time_us(uint32_t); void set_sweep_time_us(uint32_t);
@ -302,8 +289,6 @@ void set_spur(int v);
void toggle_spur(void); void toggle_spur(void);
void toggle_mirror_masking(void); void toggle_mirror_masking(void);
#endif #endif
void toggle_high_out_adf4350(void);
extern int high_out_adf4350;
void set_average(int); void set_average(int);
int GetAverage(void); int GetAverage(void);
//extern int setting.average; //extern int setting.average;
@ -332,7 +317,6 @@ void set_attack(int);
void set_noise(int); void set_noise(int);
void toggle_tracking_output(void); void toggle_tracking_output(void);
extern int32_t frequencyExtra; extern int32_t frequencyExtra;
void set_30mhz(freq_t);
void set_modulation(int); void set_modulation(int);
void set_modulation_frequency(int); void set_modulation_frequency(int);
int search_maximum(int m, freq_t center, int span); int search_maximum(int m, freq_t center, int span);
@ -341,9 +325,21 @@ void set_measurement(int);
// extern int settingSpeed; // extern int settingSpeed;
//extern int setting.step_delay; //extern int setting.step_delay;
void sweep_remote(void); void sweep_remote(void);
extern void set_modulo(uint32_t f);
extern int generic_option_cmd( const char *cmd, const char *cmd_list, int argc, char *argv); extern int generic_option_cmd( const char *cmd, const char *cmd_list, int argc, char *argv);
#ifdef TINYSA4
void clear_frequency_cache(void);
void toggle_high_out_adf4350(void);
extern int high_out_adf4350;
void set_30mhz(freq_t);
void toggle_ultra(void);
void set_IF2(int f);
void set_R(int f);
extern void set_modulo(uint32_t f);
extern void fill_spur_table(void); extern void fill_spur_table(void);
#else
void set_10mhz(freq_t);
#endif
#ifdef __AUDIO__ #ifdef __AUDIO__
/* /*
@ -430,9 +426,13 @@ extern uint16_t graph_bottom;
// Menu Button // Menu Button
// Maximum menu buttons count // Maximum menu buttons count
#ifdef TINYSA4
#define MENU_BUTTON_MAX 9 #define MENU_BUTTON_MAX 9
#else
#define MENU_BUTTON_MAX 8
#endif
#define MENU_BUTTON_WIDTH 80 #define MENU_BUTTON_WIDTH 80
#define MENU_BUTTON_HEIGHT (LCD_HEIGHT/9-1) #define MENU_BUTTON_HEIGHT (LCD_HEIGHT/MENU_BUTTON_MAX-1)
#define MENU_BUTTON_BORDER 1 #define MENU_BUTTON_BORDER 1
#define KEYBOARD_BUTTON_BORDER 2 #define KEYBOARD_BUTTON_BORDER 2
#define FORM_BUTTON_BORDER 2 #define FORM_BUTTON_BORDER 2
@ -582,7 +582,11 @@ typedef struct config {
freq_t high_correction_frequency[CORRECTION_POINTS]; freq_t high_correction_frequency[CORRECTION_POINTS];
float high_correction_value[CORRECTION_POINTS]; float high_correction_value[CORRECTION_POINTS];
uint32_t deviceid; uint32_t deviceid;
#ifdef TINYSA4
freq_t setting_frequency_30mhz; freq_t setting_frequency_30mhz;
#else
freq_t setting_frequency_10mhz;
#endif
uint16_t gridlines; uint16_t gridlines;
uint16_t hambands; uint16_t hambands;
@ -590,12 +594,12 @@ typedef struct config {
freq_t frequency_IF1; freq_t frequency_IF1;
freq_t frequency_IF2; freq_t frequency_IF2;
freq_t ultra_threshold; freq_t ultra_threshold;
int8_t ultra;
#endif #endif
int8_t _mode; uint8_t _mode;
int8_t cor_am; int8_t cor_am;
int8_t cor_wfm; int8_t cor_wfm;
int8_t cor_nfm; int8_t cor_nfm;
int8_t ultra;
float sweep_voltage; float sweep_voltage;
uint32_t dummy; uint32_t dummy;
// uint8_t _reserved[22]; // uint8_t _reserved[22];
@ -645,8 +649,8 @@ enum {
}; };
typedef struct { typedef struct {
int8_t enabled; uint8_t enabled;
int8_t mtype; uint8_t mtype;
int16_t index; int16_t index;
freq_t frequency; freq_t frequency;
} marker_t; } marker_t;
@ -708,8 +712,13 @@ extern volatile uint8_t redraw_request;
// Define size of screen buffer in pixels (one pixel 16bit size) // Define size of screen buffer in pixels (one pixel 16bit size)
#define SPI_BUFFER_SIZE (CELLWIDTH*CELLHEIGHT) #define SPI_BUFFER_SIZE (CELLWIDTH*CELLHEIGHT)
#ifdef TINYSA4
#define LCD_WIDTH 480 #define LCD_WIDTH 480
#define LCD_HEIGHT 320 #define LCD_HEIGHT 320
#else
#define LCD_WIDTH 320
#define LCD_HEIGHT 240
#endif
#define LCD_BG_COLOR 0 #define LCD_BG_COLOR 0
#define LCD_FG_COLOR 1 #define LCD_FG_COLOR 1
@ -886,18 +895,19 @@ typedef struct setting
int trigger_mode; int trigger_mode;
int slider_position; int slider_position;
int32_t slider_span; int32_t slider_span;
freq_t *correction_frequency;
float *correction_value;
#ifdef TINYSA4
int extra_lna; int extra_lna;
int ultra; int ultra;
int R; int R;
freq_t *correction_frequency; #endif
float *correction_value;
uint32_t dummy; uint32_t dummy;
uint32_t checksum; // must be last uint32_t checksum; // must be last
}setting_t; }setting_t;
extern setting_t setting; extern setting_t setting;
//extern int setting_frequency_30mhz;
void reset_settings(int m); void reset_settings(int m);
@ -922,7 +932,9 @@ enum { SD_NORMAL, SD_PRECISE, SD_FAST, SD_MANUAL };
extern freq_t frequencies[POINTS_COUNT]; extern freq_t frequencies[POINTS_COUNT];
extern const float unit_scale_value[]; extern const float unit_scale_value[];
extern const char * const unit_scale_text[]; extern const char * const unit_scale_text[];
#ifdef TINYSA4
extern int debug_frequencies; extern int debug_frequencies;
#endif
#if 1 // Still sufficient flash #if 1 // Still sufficient flash
// Flash save area - flash7 : org = 0x0801B000, len = 20k in *.ld file // Flash save area - flash7 : org = 0x0801B000, len = 20k in *.ld file
// 2k - for config save // 2k - for config save
@ -1128,7 +1140,8 @@ void enter_dfu(void);
/* /*
* adc.c * adc.c
*/ */
#define rccEnableWWDG(lp) rccEnableAPB1(RCC_APB1ENR_WWDGEN, lp) #ifdef TINYSA4
#define rccEnableWWDG(lp) rccEnableAPB1(RCC_APB1ENR_WWDGEN, lp)
#define ADC_TOUCH_X ADC_CHANNEL_IN3 #define ADC_TOUCH_X ADC_CHANNEL_IN3
#define ADC_TOUCH_Y ADC_CHANNEL_IN4 #define ADC_TOUCH_Y ADC_CHANNEL_IN4
@ -1137,7 +1150,17 @@ uint16_t adc_single_read(uint32_t chsel);
void adc_start_analog_watchdogd(void); void adc_start_analog_watchdogd(void);
void adc_stop(void); void adc_stop(void);
int16_t adc_vbat_read(void); int16_t adc_vbat_read(void);
#else
#define ADC_TOUCH_X ADC_CHSELR_CHSEL6
#define ADC_TOUCH_Y ADC_CHSELR_CHSEL7
void adc_init(void);
uint16_t adc_single_read(uint32_t chsel);
void adc_start_analog_watchdogd(uint32_t chsel);
void adc_stop(void);
void adc_interrupt(void);
int16_t adc_vbat_read(void);
#endif
/* /*
* misclinous * misclinous
*/ */
@ -1165,7 +1188,11 @@ typedef int16_t pureRSSI_t;
// RSSI values conversion macro // RSSI values conversion macro
// External programm zero level settings (need decrease on this value -) // External programm zero level settings (need decrease on this value -)
#ifdef TINYSA4
#define EXT_ZERO_LEVEL (174)
#else
#define EXT_ZERO_LEVEL (174) #define EXT_ZERO_LEVEL (174)
#endif
#define DEVICE_TO_PURE_RSSI(rssi) ((rssi)<<4) #define DEVICE_TO_PURE_RSSI(rssi) ((rssi)<<4)
#define PURE_TO_DEVICE_RSSI(rssi) ((rssi)>>4) #define PURE_TO_DEVICE_RSSI(rssi) ((rssi)>>4)
#define float_TO_PURE_RSSI(rssi) ((rssi)*32) #define float_TO_PURE_RSSI(rssi) ((rssi)*32)
@ -1204,6 +1231,7 @@ enum {
T_AUTO, T_NORMAL, T_SINGLE, T_DONE, T_UP, T_DOWN, T_MODE, T_PRE, T_POST, T_MID T_AUTO, T_NORMAL, T_SINGLE, T_DONE, T_UP, T_DOWN, T_MODE, T_PRE, T_POST, T_MID
}; };
#ifdef TINYSA4
// si4432.c // si4432.c
extern void ADF4351_mux(int R); extern void ADF4351_mux(int R);
@ -1228,5 +1256,5 @@ extern void si_set_offset(int16_t offset);
extern int SI4463_offset_changed; extern int SI4463_offset_changed;
extern void si_fm_offset(int16_t offset); extern void si_fm_offset(int16_t offset);
#endif
/*EOF*/ /*EOF*/

@ -547,12 +547,12 @@ value(const float v)
return v + LOG_10_SQRT_50_x20_plus90; // 90.0 + 20.0*LOG_10_SQRT_50; return v + LOG_10_SQRT_50_x20_plus90; // 90.0 + 20.0*LOG_10_SQRT_50;
break; break;
case U_VOLT: case U_VOLT:
// return pow(10, (v-30.0)/20.0) * sqrt((float)50.0); // return powf(10, (v-30.0)/20.0) * sqrt((float)50.0);
return pow((float)10.0, (v-(float)30.0)/(float)20.0)*SQRT_50; // Do NOT change pow to powf as this will increase the size return powf((float)10.0, (v-(float)30.0)/(float)20.0)*SQRT_50; // Do NOT change pow to powf as this will increase the size
// return pow(10, v/20.0) * POW_SQRT; //TODO there is an error in this calculation as the outcome is different from the not optimized version // return pow(10, v/20.0) * POW_SQRT; //TODO there is an error in this calculation as the outcome is different from the not optimized version
break; break;
case U_WATT: case U_WATT:
return pow((float)10.0, v/10.0)/1000.0; // Do NOT change pow to powf as this will increase the size return powf((float)10.0, v/10.0)/1000.0; // Do NOT change pow to powf as this will increase the size
break; break;
} }
// case U_DBM: // case U_DBM:
@ -972,7 +972,7 @@ void trace_get_value_string( // Only used at one place
plot_printf(ptr2, sizeof(buf2) - 2, "%3.1f" , (dfreq + 50000) / 1000000.0); plot_printf(ptr2, sizeof(buf2) - 2, "%3.1f" , (dfreq + 50000) / 1000000.0);
} }
#else #else
plot_printf(ptr2, sizeof(buf2) - 2, "%9.5LqHz" , dfreq); plot_printf(ptr2, sizeof(buf2) - 2, "%9.5QHz" , dfreq);
} }
#endif #endif
v = value(coeff[i]); v = value(coeff[i]);
@ -2107,7 +2107,7 @@ static void cell_draw_marker_info(int x0, int y0)
f = markers[2].frequency-markers[1].frequency; f = markers[2].frequency-markers[1].frequency;
else else
f = markers[1].frequency-markers[2].frequency; f = markers[1].frequency-markers[2].frequency;
plot_printf(buf, sizeof buf, "WIDTH: %8.3LqHz", f); plot_printf(buf, sizeof buf, "WIDTH: %8.3QHz", f);
show_computed: show_computed:
j = 3; j = 3;
int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0; int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0;
@ -2128,7 +2128,7 @@ static void cell_draw_marker_info(int x0, int y0)
float level = (actual_t[markers[1].index] + actual_t[markers[2].index])/2.0 - actual_t[markers[0].index]; float level = (actual_t[markers[1].index] + actual_t[markers[2].index])/2.0 - actual_t[markers[0].index];
if (level < -70 || level > 0) if (level < -70 || level > 0)
break; break;
int depth =(int) (pow((float)10.0, 2.0 + (level + 6.02) /20.0)); int depth =(int) (powf((float)10.0, 2.0 + (level + 6.02) /20.0));
#endif #endif
plot_printf(buf, sizeof buf, "DEPTH: %3d%%", depth); plot_printf(buf, sizeof buf, "DEPTH: %3d%%", depth);
goto show_computed; goto show_computed;
@ -2137,7 +2137,7 @@ static void cell_draw_marker_info(int x0, int y0)
if ( markers[2].frequency < dev) if ( markers[2].frequency < dev)
break; break;
dev = ( markers[2].frequency - dev ) >> 1; dev = ( markers[2].frequency - dev ) >> 1;
plot_printf(buf, sizeof buf, "DEVIATION:%6.1LqHz", dev); plot_printf(buf, sizeof buf, "DEVIATION:%6.1QHz", dev);
goto show_computed; goto show_computed;
} else if (setting.measurement == M_THD && markers[0].enabled && (markers[0].index << 5) > sweep_points ) { } else if (setting.measurement == M_THD && markers[0].enabled && (markers[0].index << 5) > sweep_points ) {
int old_unit = setting.unit; int old_unit = setting.unit;
@ -2151,7 +2151,7 @@ static void cell_draw_marker_info(int x0, int y0)
h += index_to_value(markers[1].index); h += index_to_value(markers[1].index);
h_i++; h_i++;
} }
float thd = 100.0 * sqrt(h/p); float thd = 100.0 * sqrtf(h/p);
setting.unit = old_unit; setting.unit = old_unit;
ili9341_set_foreground(marker_color(markers[0].mtype)); ili9341_set_foreground(marker_color(markers[0].mtype));
plot_printf(buf, sizeof buf, "THD: %4.1f%%", thd); plot_printf(buf, sizeof buf, "THD: %4.1f%%", thd);
@ -2273,17 +2273,17 @@ draw_frequencies(void)
if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) { if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) {
#endif #endif
if (FREQ_IS_CW()) { if (FREQ_IS_CW()) {
plot_printf(buf1, sizeof(buf1), " CW %LqHz", get_sweep_frequency(ST_CW)); plot_printf(buf1, sizeof(buf1), " CW %QHz", get_sweep_frequency(ST_CW));
// Show user actual select sweep time? // Show user actual select sweep time?
uint32_t t = setting.actual_sweep_time_us; uint32_t t = setting.actual_sweep_time_us;
plot_printf(buf2, sizeof(buf2), " TIME %.3Fs", (float)t/ONE_SECOND_TIME); plot_printf(buf2, sizeof(buf2), " TIME %.3Fs", (float)t/ONE_SECOND_TIME);
} else if (FREQ_IS_STARTSTOP()) { } else if (FREQ_IS_STARTSTOP()) {
plot_printf(buf1, sizeof(buf1), " START %.3LqHz %5.1LqHz/", get_sweep_frequency(ST_START), grid_span); plot_printf(buf1, sizeof(buf1), " START %.3QHz %5.1QHz/", get_sweep_frequency(ST_START), grid_span);
plot_printf(buf2, sizeof(buf2), " STOP %.3LqHz", get_sweep_frequency(ST_STOP)); plot_printf(buf2, sizeof(buf2), " STOP %.3QHz", get_sweep_frequency(ST_STOP));
} else if (FREQ_IS_CENTERSPAN()) { } else if (FREQ_IS_CENTERSPAN()) {
plot_printf(buf1, sizeof(buf1), " CENTER %.3LqHz %5.1LqHz/", get_sweep_frequency(ST_CENTER), grid_span); plot_printf(buf1, sizeof(buf1), " CENTER %.3QHz %5.1QHz/", get_sweep_frequency(ST_CENTER), grid_span);
plot_printf(buf2, sizeof(buf2), " SPAN %.3LqHz", get_sweep_frequency(ST_SPAN)); plot_printf(buf2, sizeof(buf2), " SPAN %.3QHz", get_sweep_frequency(ST_SPAN));
} }
#ifdef __VNA__ #ifdef __VNA__
} else { } else {

@ -99,13 +99,18 @@ VNA_SHELL_FUNCTION(cmd_spur)
// shell_printf("usage: spur %s\r\n", cmd); // shell_printf("usage: spur %s\r\n", cmd);
// return; // return;
// } // }
#ifdef TINYSA4
int m = generic_option_cmd("spur", "off|on|auto", argc, argv[0]); int m = generic_option_cmd("spur", "off|on|auto", argc, argv[0]);
#else
int m = generic_option_cmd("spur", "off|on", argc, argv[0]);
#endif
if (m>=0) { if (m>=0) {
set_spur(m); set_spur(m);
redraw_request |= REDRAW_CAL_STATUS | REDRAW_AREA; redraw_request |= REDRAW_CAL_STATUS | REDRAW_AREA;
} }
} }
#ifdef TINYSA4
VNA_SHELL_FUNCTION(cmd_lna) VNA_SHELL_FUNCTION(cmd_lna)
{ {
// static const char cmd[] = "off|on"; // static const char cmd[] = "off|on";
@ -135,6 +140,7 @@ VNA_SHELL_FUNCTION(cmd_ultra)
update_min_max_freq(); update_min_max_freq();
} }
} }
#endif
VNA_SHELL_FUNCTION(cmd_output) VNA_SHELL_FUNCTION(cmd_output)
{ {
@ -258,6 +264,15 @@ VNA_SHELL_FUNCTION(cmd_leveloffset)
else else
goto usage; goto usage;
dirty = true; dirty = true;
} else if (argc == 3 && strcmp(argv[1],"output") == 0) {
float v = my_atof(argv[2]);
if (strcmp(argv[0],"low") == 0)
config.low_level_output_offset = v;
else if (strcmp(argv[0],"high") == 0)
config.high_level_output_offset = v;
else
goto usage;
dirty = true;
} else { } else {
usage: usage:
shell_printf("leveloffset [low|high] {output} [<offset>]\r\n"); shell_printf("leveloffset [low|high] {output} [<offset>]\r\n");
@ -293,7 +308,11 @@ VNA_SHELL_FUNCTION(cmd_rbw)
{ {
if (argc != 1) { if (argc != 1) {
usage: usage:
#ifdef TINYSA4
shell_printf("usage: rbw 0.3..600|auto\r\n"); shell_printf("usage: rbw 0.3..600|auto\r\n");
#else
shell_printf("usage: rbw 2..600|auto\r\n");
#endif
return; return;
} }
if (get_str_index(argv[0], "auto|0")>=0) { if (get_str_index(argv[0], "auto|0")>=0) {
@ -301,7 +320,7 @@ VNA_SHELL_FUNCTION(cmd_rbw)
set_RBW(0); set_RBW(0);
} else { } else {
float a = my_atof(argv[0]); float a = my_atof(argv[0]);
if (a < 0.2 || a>900) if (a < 0.2 || a>600)
goto usage; goto usage;
if (setting.rbw_x10 != a*10) if (setting.rbw_x10 != a*10)
set_RBW((int) ( a*10)); set_RBW((int) ( a*10));
@ -312,7 +331,7 @@ VNA_SHELL_FUNCTION(cmd_if)
{ {
if (argc != 1) { if (argc != 1) {
usage: usage:
shell_printf("usage: if {433M..435M}\r\n%qHz\r\n", setting.frequency_IF); shell_printf("usage: if {433M..435M}\r\n%QHz\r\n", setting.frequency_IF);
return; return;
} else { } else {
freq_t a = (freq_t)my_atoi(argv[0]); freq_t a = (freq_t)my_atoi(argv[0]);
@ -323,6 +342,7 @@ VNA_SHELL_FUNCTION(cmd_if)
} }
} }
#ifdef TINYSA4
VNA_SHELL_FUNCTION(cmd_ultra_start) VNA_SHELL_FUNCTION(cmd_ultra_start)
{ {
if (argc != 1) { if (argc != 1) {
@ -350,7 +370,7 @@ VNA_SHELL_FUNCTION(cmd_if1)
config_save(); config_save();
} }
} }
#endif
VNA_SHELL_FUNCTION(cmd_trigger) VNA_SHELL_FUNCTION(cmd_trigger)
{ {
@ -401,7 +421,6 @@ VNA_SHELL_FUNCTION(cmd_selftest)
static int VFO = 0; static int VFO = 0;
#ifdef __ADF4351__
uint32_t xtoi(char *t) uint32_t xtoi(char *t)
{ {
@ -421,6 +440,8 @@ uint32_t xtoi(char *t)
return v; return v;
} }
#ifdef __ADF4351__
VNA_SHELL_FUNCTION(cmd_x) VNA_SHELL_FUNCTION(cmd_x)
{ {
uint32_t reg; uint32_t reg;
@ -478,6 +499,7 @@ VNA_SHELL_FUNCTION(cmd_d)
(void) argc; (void) argc;
(void) argv; (void) argv;
int32_t a = my_atoi(argv[0]); int32_t a = my_atoi(argv[0]);
#ifdef TINYSA4
int32_t d; int32_t d;
if (argc == 2) if (argc == 2)
d = my_atoi(argv[1]); d = my_atoi(argv[1]);
@ -498,6 +520,10 @@ VNA_SHELL_FUNCTION(cmd_d)
} }
// setting.lo_drive=a; // setting.lo_drive=a;
// dirty = true; // dirty = true;
#else
setting.lo_drive=a;
dirty = true;
#endif
} }
#if 0 #if 0
@ -522,7 +548,7 @@ VNA_SHELL_FUNCTION(cmd_a)
{ {
(void)argc; (void)argc;
if (argc != 1) { if (argc != 1) {
shell_printf("a=%Lu\r\n", frequencyStart); shell_printf("a=%U\r\n", frequencyStart);
return; return;
} }
freq_t value = my_atoui(argv[0]); freq_t value = my_atoui(argv[0]);
@ -534,7 +560,7 @@ VNA_SHELL_FUNCTION(cmd_b)
{ {
(void)argc; (void)argc;
if (argc != 1) { if (argc != 1) {
shell_printf("b=%Lu\r\n", frequencyStop); shell_printf("b=%U\r\n", frequencyStop);
return; return;
} }
freq_t value = my_atoui(argv[0]); freq_t value = my_atoui(argv[0]);
@ -588,7 +614,7 @@ VNA_SHELL_FUNCTION(cmd_v)
VNA_SHELL_FUNCTION(cmd_y) VNA_SHELL_FUNCTION(cmd_y)
{ {
if (argc < 1) { if (argc < 1) {
shell_printf("usage: y {addr(0-FF)} [value(0-FF)]+\r\n"); shell_printf("usage: y {addr(0-95)} [value(0-0xFF)]\r\n");
return; return;
} }
#ifdef __SI4432__ #ifdef __SI4432__
@ -700,7 +726,9 @@ VNA_SHELL_FUNCTION(cmd_p)
{ {
(void)argc; (void)argc;
int p = my_atoi(argv[0]); int p = my_atoi(argv[0]);
#ifdef TINYSA4
SI4463_set_output_level(p); SI4463_set_output_level(p);
#endif
return; return;
int a = my_atoi(argv[1]); int a = my_atoi(argv[1]);
if (p==5) if (p==5)
@ -712,6 +740,7 @@ return;
set_refer_output(a); set_refer_output(a);
} }
#ifdef TINYSA4
VNA_SHELL_FUNCTION(cmd_g) VNA_SHELL_FUNCTION(cmd_g)
{ {
(void)argc; (void)argc;
@ -719,6 +748,7 @@ VNA_SHELL_FUNCTION(cmd_g)
int a = my_atoi(argv[1]); int a = my_atoi(argv[1]);
SI4463_set_gpio(p,a); SI4463_set_gpio(p,a);
} }
#endif
VNA_SHELL_FUNCTION(cmd_w) VNA_SHELL_FUNCTION(cmd_w)
{ {
@ -743,7 +773,7 @@ VNA_SHELL_FUNCTION(cmd_correction)
if (argc == 0) { if (argc == 0) {
shell_printf("index frequency value\r\n"); shell_printf("index frequency value\r\n");
for (int i=0; i<CORRECTION_POINTS; i++) { for (int i=0; i<CORRECTION_POINTS; i++) {
shell_printf("%d %Ld %.1f\r\n", i, setting.correction_frequency[i], setting.correction_value[i]); shell_printf("%d %D%.1f\r\n", i, setting.correction_frequency[i], setting.correction_value[i]);
} }
return; return;
} }
@ -764,7 +794,7 @@ VNA_SHELL_FUNCTION(cmd_correction)
setting.correction_frequency[i] = f; setting.correction_frequency[i] = f;
setting.correction_value[i] = v; setting.correction_value[i] = v;
redraw_request|=REDRAW_AREA; // to ensure the change in level will be visible redraw_request|=REDRAW_AREA; // to ensure the change in level will be visible
shell_printf("updated %d to %Ld %.1f\r\n", i, setting.correction_frequency[i], setting.correction_value[i]); shell_printf("updated %d to %D %.1f\r\n", i, setting.correction_frequency[i], setting.correction_value[i]);
} }
VNA_SHELL_FUNCTION(cmd_scanraw) VNA_SHELL_FUNCTION(cmd_scanraw)

File diff suppressed because it is too large Load Diff

1978
si4432.c

File diff suppressed because it is too large Load Diff

@ -22,13 +22,8 @@
#define __SI4432_H__ #define __SI4432_H__
void start_SI4432_SPI_mode(void);
void stop_SI4432_SPI_mode(void);
extern int SI4432_step_delay; extern int SI4432_step_delay;
extern int SI4432_offset_delay; extern int SI4432_offset_delay;
#ifdef __SI4432__ #ifdef __SI4432__
// //
@ -178,8 +173,6 @@ int ADF4351_locked(void);
void ADF4351_enable(int s); void ADF4351_enable(int s);
void ADF4351_enable_aux_out(int s); void ADF4351_enable_aux_out(int s);
#endif #endif
#ifdef __SI4463__ #ifdef __SI4463__

2653
si4468.c

File diff suppressed because it is too large Load Diff

@ -78,8 +78,11 @@
#define SPI_READ_8BIT(spi) *(__IO uint8_t*)(&spi->DR) #define SPI_READ_8BIT(spi) *(__IO uint8_t*)(&spi->DR)
#define SPI_READ_16BIT(spi) *(__IO uint16_t*)(&spi->DR) #define SPI_READ_16BIT(spi) *(__IO uint16_t*)(&spi->DR)
#ifdef TINYSA4
#define SPI_MODE_LCD 0x00 #define SPI_MODE_LCD 0x00
#define SPI_MODE_SD_CARD 0x01 #define SPI_MODE_SD_CARD 0x01
#define SPI_MODE_SI 0x02 #define SPI_MODE_SI 0x02
void set_SPI_mode(uint16_t mode); void set_SPI_mode(uint16_t mode);
void start_SI4432_SPI_mode(void);
void stop_SI4432_SPI_mode(void);
#endif

22
ui.c

@ -284,7 +284,11 @@ void
touch_start_watchdog(void) touch_start_watchdog(void)
{ {
touch_prepare_sense(); touch_prepare_sense();
#ifdef TINYSA4
adc_start_analog_watchdogd(); adc_start_analog_watchdogd();
#else
adc_start_analog_watchdogd(ADC_TOUCH_Y);
#endif
} }
static inline int static inline int
@ -431,15 +435,12 @@ touch_draw_test(void)
do { do {
if (touch_check() == EVT_TOUCH_PRESSED){ if (touch_check() == EVT_TOUCH_PRESSED){
touch_position(&x0, &y0); touch_position(&x0, &y0);
ili9341_line(x0, y0, x0, y0);
do { do {
chThdSleepMilliseconds(50); chThdSleepMilliseconds(50);
touch_position(&x1, &y1); touch_position(&x1, &y1);
if (x0!= x1 || y0 != y1) {
ili9341_line(x0, y0, x1, y1); ili9341_line(x0, y0, x1, y1);
x0 = x1; x0 = x1;
y0 = y1; y0 = y1;
}
} while (touch_check() != EVT_TOUCH_RELEASED); } while (touch_check() != EVT_TOUCH_RELEASED);
} }
}while (!(btn_check() & EVT_BUTTON_SINGLE_CLICK)); }while (!(btn_check() & EVT_BUTTON_SINGLE_CLICK));
@ -459,7 +460,6 @@ touch_position(int *x, int *y)
#endif #endif
} }
void void
show_version(void) show_version(void)
{ {
@ -475,7 +475,7 @@ show_version(void)
do {shift>>=1; y+=5;} while (shift&1); do {shift>>=1; y+=5;} while (shift&1);
ili9341_drawstring(info_about[i++], x, y+=5); ili9341_drawstring(info_about[i++], x, y+=5);
} }
#ifdef TINYSA4
static char buf[96]; static char buf[96];
extern const char *states[]; extern const char *states[];
#define ENABLE_THREADS_COMMAND #define ENABLE_THREADS_COMMAND
@ -503,7 +503,7 @@ extern const char *states[];
#endif #endif
#endif // TINYSA4
while (true) { while (true) {
if (touch_check() == EVT_TOUCH_PRESSED) if (touch_check() == EVT_TOUCH_PRESSED)
@ -881,7 +881,7 @@ static UI_FUNCTION_CALLBACK(menu_marker_op_cb)
{ {
float l = actual_t[markers[active_marker].index]; float l = actual_t[markers[active_marker].index];
float s_max = value(l)/setting.scale; float s_max = value(l)/setting.scale;
user_set_reflevel(setting.scale*(floor(s_max)+2)); user_set_reflevel(setting.scale*(floorf(s_max)+2));
} }
break; break;
#ifdef __VNA__ #ifdef __VNA__
@ -1894,7 +1894,7 @@ draw_menu_buttons(const menuitem_t *menu)
} }
goto draw_divider; goto draw_divider;
} else if (menu[i].data == KM_LOWOUTLEVEL) { } else if (menu[i].data == KM_LOWOUTLEVEL) {
local_slider_positions = ((get_level() - SL_GENLOW_LEVEL_MIN - config.low_level_output_offset ) * (MENU_FORM_WIDTH-8)) / SL_GENLOW_LEVEL_RANGE + OFFSETX+4; local_slider_positions = ((get_level() - level_min()) * (MENU_FORM_WIDTH-8)) / level_range() + OFFSETX+4;
for (int i=0; i <= 4; i++) { for (int i=0; i <= 4; i++) {
ili9341_drawstring(step_text[i], button_start+12 + i * MENU_FORM_WIDTH/5, y+button_height-9); ili9341_drawstring(step_text[i], button_start+12 + i * MENU_FORM_WIDTH/5, y+button_height-9);
} }
@ -1905,7 +1905,7 @@ draw_menu_buttons(const menuitem_t *menu)
draw_slider: draw_slider:
blit8BitWidthBitmap(local_slider_positions - 4, y, 7, 5, slider_bitmap); blit8BitWidthBitmap(local_slider_positions - 4, y, 7, 5, slider_bitmap);
} else if (menu[i].data == KM_HIGHOUTLEVEL) { } else if (menu[i].data == KM_HIGHOUTLEVEL) {
local_slider_positions = ((get_level() - SL_GENHIGH_LEVEL_MIN ) * (MENU_FORM_WIDTH-8)) / SL_GENHIGH_LEVEL_RANGE + OFFSETX+4; local_slider_positions = ((get_level() - level_min() ) * (MENU_FORM_WIDTH-8)) / level_range() + OFFSETX+4;
goto draw_slider; goto draw_slider;
} }
} }
@ -2071,7 +2071,7 @@ menu_select_touch(int i, int pos)
check_frequency_slider(slider_freq); check_frequency_slider(slider_freq);
} }
} else if (menu_is_form(menu) && MT_MASK(menu[i].type) == MT_KEYPAD && keypad == KM_LOWOUTLEVEL) { } else if (menu_is_form(menu) && MT_MASK(menu[i].type) == MT_KEYPAD && keypad == KM_LOWOUTLEVEL) {
uistat.value = setting.offset + ((touch_x - OFFSETX+4) * SL_GENLOW_LEVEL_RANGE ) / (MENU_FORM_WIDTH-8) + SL_GENLOW_LEVEL_MIN + config.low_level_output_offset; uistat.value = setting.offset + ((touch_x - OFFSETX+4) * level_range() ) / (MENU_FORM_WIDTH-8) + level_min() ;
apply_step: apply_step:
set_keypad_value(keypad); set_keypad_value(keypad);
apply: apply:
@ -2080,7 +2080,7 @@ menu_select_touch(int i, int pos)
// } // }
// } else if (MT_MASK(menu[i].type) == MT_ADV_CALLBACK && menu[i].reference == menu_sdrive_acb) { // } else if (MT_MASK(menu[i].type) == MT_ADV_CALLBACK && menu[i].reference == menu_sdrive_acb) {
} else if (menu_is_form(menu) && MT_MASK(menu[i].type) == MT_KEYPAD && keypad == KM_HIGHOUTLEVEL) { } else if (menu_is_form(menu) && MT_MASK(menu[i].type) == MT_KEYPAD && keypad == KM_HIGHOUTLEVEL) {
set_level( (touch_x - OFFSETX+4) *(SL_GENHIGH_LEVEL_RANGE) / (MENU_FORM_WIDTH-8) + SL_GENHIGH_LEVEL_MIN ); set_level( (touch_x - OFFSETX+4) *(level_range()) / (MENU_FORM_WIDTH-8) + level_min() );
goto apply; goto apply;
} }
keypad_mode = old_keypad_mode; keypad_mode = old_keypad_mode;

@ -405,15 +405,22 @@ enum {
KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, // These must be first to share common help text KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, // These must be first to share common help text
KM_REFLEVEL, KM_SCALE, KM_ATTENUATION, KM_REFLEVEL, KM_SCALE, KM_ATTENUATION,
KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_DRIVE, KM_LOWOUTLEVEL, KM_DECAY, KM_NOISE, KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_DRIVE, KM_LOWOUTLEVEL, KM_DECAY, KM_NOISE,
KM_30MHZ, KM_REPEAT, KM_OFFSET, KM_TRIGGER, KM_LEVELSWEEP, KM_SWEEP_TIME, KM_OFFSET_DELAY, #ifdef TINYSA4
KM_30MHZ,
#else
KM_10MHZ,
#endif
KM_REPEAT, KM_OFFSET, KM_TRIGGER, KM_LEVELSWEEP, KM_SWEEP_TIME, KM_OFFSET_DELAY,
KM_FAST_SPEEDUP, KM_GRIDLINES, KM_MARKER, KM_MODULATION, KM_HIGHOUTLEVEL, KM_FAST_SPEEDUP, KM_GRIDLINES, KM_MARKER, KM_MODULATION, KM_HIGHOUTLEVEL,
#ifdef TINYSA4
KM_R,KM_MOD,KM_CP, KM_R,KM_MOD,KM_CP,
#if 1
KM_COR_AM,KM_COR_WFM, KM_COR_NFM, KM_COR_AM,KM_COR_WFM, KM_COR_NFM,
#endif #endif
KM_ATTACK, KM_ATTACK,
#ifdef TINYSA4
KM_IF2, KM_IF2,
KM_LPF, KM_LPF,
#endif
KM_NONE // always at enum end KM_NONE // always at enum end
}; };
@ -436,7 +443,7 @@ static const struct {
{keypads_plusmin , "LEVEL"}, // KM_LOWOUTLEVEL {keypads_plusmin , "LEVEL"}, // KM_LOWOUTLEVEL
{keypads_positive , "DECAY"}, // KM_DECAY {keypads_positive , "DECAY"}, // KM_DECAY
{keypads_positive , "NOISE\nLEVEL"}, // KM_NOISE {keypads_positive , "NOISE\nLEVEL"}, // KM_NOISE
{keypads_freq , "FREQ"}, // KM_30MHz {keypads_freq , "FREQ"}, // KM_30MHz | KM_10MHz
{keypads_positive , "SAMPLE\nREPEAT"}, // KM_REPEA {keypads_positive , "SAMPLE\nREPEAT"}, // KM_REPEA
{keypads_plusmin , "OFFSET"}, // KM_OFFSET {keypads_plusmin , "OFFSET"}, // KM_OFFSET
{keypads_plusmin_unit, "TRIGGER\nLEVEL"}, // KM_TRIGGER {keypads_plusmin_unit, "TRIGGER\nLEVEL"}, // KM_TRIGGER
@ -448,17 +455,19 @@ static const struct {
{keypads_freq , "MARKER\nFREQ"}, // KM_MARKER {keypads_freq , "MARKER\nFREQ"}, // KM_MARKER
{keypads_freq , "MODULATION\nFREQ"}, // KM_MODULATION {keypads_freq , "MODULATION\nFREQ"}, // KM_MODULATION
{keypads_plusmin , "LEVEL"}, // KM_HIGHOUTLEVEL {keypads_plusmin , "LEVEL"}, // KM_HIGHOUTLEVEL
#if 1 #ifdef TINYSA
{keypads_plusmin , "COR\nAM"}, // KM_COR_AM {keypads_plusmin , "COR\nAM"}, // KM_COR_AM
{keypads_plusmin , "COR\nWFM"}, // KM_COR_WFM {keypads_plusmin , "COR\nWFM"}, // KM_COR_WFM
{keypads_plusmin , "COR\nNFM"}, // KM_COR_NFM {keypads_plusmin , "COR\nNFM"}, // KM_COR_NFM
#endif
{keypads_freq , "IF2"}, // KM_IF2 {keypads_freq , "IF2"}, // KM_IF2
{keypads_positive , "R"}, // KM_R {keypads_positive , "R"}, // KM_R
{keypads_positive , "MODULO"}, // KM_MOD {keypads_positive , "MODULO"}, // KM_MOD
{keypads_positive , "CP"}, // KM_CP {keypads_positive , "CP"}, // KM_CP
#endif
{keypads_positive , "ATTACK"}, // KM_ATTACK {keypads_positive , "ATTACK"}, // KM_ATTACK
#ifdef TINYSA4
{keypads_freq , "ULTRA\nSTART"}, // KM_LPF {keypads_freq , "ULTRA\nSTART"}, // KM_LPF
#endif
}; };
#if 0 // Not used #if 0 // Not used
@ -482,12 +491,10 @@ static const menuitem_t menu_top[];
static const menuitem_t menu_reffer[]; static const menuitem_t menu_reffer[];
static const menuitem_t menu_modulation[]; static const menuitem_t menu_modulation[];
static const menuitem_t menu_drive_wide[]; static const menuitem_t menu_drive_wide[];
#ifdef TINYSA4
static const menuitem_t menu_settings3[]; static const menuitem_t menu_settings3[];
static const menuitem_t menu_sweep[];
#ifdef __ULTRA__
static const menuitem_t menu_tophigh[];
static const menuitem_t menu_topultra[];
#endif #endif
static const menuitem_t menu_sweep[];
#define AUTO_ICON(S) (S>=2?BUTTON_ICON_CHECK_AUTO:S) // Depends on order of ICONs!!!!! #define AUTO_ICON(S) (S>=2?BUTTON_ICON_CHECK_AUTO:S) // Depends on order of ICONs!!!!!
@ -543,11 +550,6 @@ static UI_FUNCTION_ADV_CALLBACK(menu_mode_acb)
case 3: case 3:
menu_push_submenu(menu_highoutputmode); menu_push_submenu(menu_highoutputmode);
break; break;
#ifdef __ULTRA__
case 7:
menu_push_submenu(menu_topultra);
break;
#endif
} }
redraw_request |= REDRAW_CAL_STATUS; redraw_request |= REDRAW_CAL_STATUS;
} }
@ -745,40 +747,27 @@ static UI_FUNCTION_ADV_CALLBACK(menu_sreffer_acb){
menu_push_submenu(menu_reffer); menu_push_submenu(menu_reffer);
} }
#ifdef TINYSA4 #ifdef TINYSA3
const int8_t menu_drive_value[]={-38,-35,-33,-30,-27,-24,-21,-19, -7,-4,-2,1,4,7,10,13};
#else
const int8_t menu_drive_value[]={-38,-35,-33,-30,-27,-24,-21,-19, -7,-4,-2,1,4,7,10,13};
#endif
#if 0
static UI_FUNCTION_ADV_CALLBACK(menu_lo_drive_acb) static UI_FUNCTION_ADV_CALLBACK(menu_lo_drive_acb)
{ {
(void)item; (void)item;
if(b){ if(b){
#ifdef TINYSA4 b->param_1.i = drive_dBm[data];
b->param_1.i = data+20;
#else
b->param_1.i = menu_drive_value[data] + (setting.mode==M_GENHIGH ? setting.offset : 0);
#endif
b->icon = data == setting.lo_drive ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP; b->icon = data == setting.lo_drive ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP;
return; return;
} }
//Serial.println(item); //Serial.println(item);
set_lo_drive(data+20); set_lo_drive(data);
menu_move_back(); menu_move_back();
// ui_mode_normal(); // ui_mode_normal();
// draw_cal_status(); // draw_cal_status();
} }
#endif #else
static UI_FUNCTION_ADV_CALLBACK(menu_mixer_drive_acb) static UI_FUNCTION_ADV_CALLBACK(menu_mixer_drive_acb)
{ {
(void)item; (void)item;
if(b){ if(b){
#ifdef TINYSA4
b->param_1.i = data; b->param_1.i = data;
#else
b->param_1.i = menu_drive_value[data] + (setting.mode==M_GENHIGH ? setting.offset : 0);
#endif
b->icon = data == setting.lo_drive ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP; b->icon = data == setting.lo_drive ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP;
return; return;
} }
@ -788,6 +777,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_mixer_drive_acb)
// ui_mode_normal(); // ui_mode_normal();
// draw_cal_status(); // draw_cal_status();
} }
#endif
#if 0 #if 0
static UI_FUNCTION_ADV_CALLBACK(menu_sdrive_acb){ static UI_FUNCTION_ADV_CALLBACK(menu_sdrive_acb){
@ -797,7 +787,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_sdrive_acb){
#ifdef TINYSA4 #ifdef TINYSA4
b->param_1.i = setting.lo_drive; b->param_1.i = setting.lo_drive;
#else #else
b->param_1.i = menu_drive_value[setting.lo_drive] + (setting.mode==M_GENHIGH ? setting.offset : 0); b->param_1.i = drive_dBm[setting.lo_drive] + (setting.mode==M_GENHIGH ? setting.offset : 0);
#endif #endif
return; return;
} }
@ -805,8 +795,6 @@ static UI_FUNCTION_ADV_CALLBACK(menu_sdrive_acb){
} }
#endif #endif
#ifdef __SPUR__ #ifdef __SPUR__
static UI_FUNCTION_ADV_CALLBACK(menu_spur_acb) static UI_FUNCTION_ADV_CALLBACK(menu_spur_acb)
{ {
@ -818,7 +806,11 @@ static UI_FUNCTION_ADV_CALLBACK(menu_spur_acb)
b->icon = AUTO_ICON(setting.spur_removal); b->icon = AUTO_ICON(setting.spur_removal);
} else { } else {
b->param_1.text = "MIRROR\nMASKING"; b->param_1.text = "MIRROR\nMASKING";
#ifdef TINYSA4
b->icon = AUTO_ICON(setting.mirror_masking); b->icon = AUTO_ICON(setting.mirror_masking);
#else
b->icon = setting.mirror_masking == 0 ? BUTTON_ICON_NOCHECK : BUTTON_ICON_CHECK;
#endif
} }
return; return;
} }
@ -831,6 +823,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_spur_acb)
} }
#endif #endif
#ifdef TINYSA4
static UI_FUNCTION_ADV_CALLBACK(menu_extra_lna_acb) static UI_FUNCTION_ADV_CALLBACK(menu_extra_lna_acb)
{ {
(void)data; (void)data;
@ -870,7 +863,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_debug_freq_acb)
// menu_move_back(); // menu_move_back();
ui_mode_normal(); ui_mode_normal();
} }
#endif
static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb) static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb)
{ {
@ -1210,14 +1203,22 @@ static UI_FUNCTION_CALLBACK(menu_marker_delete_cb)
} }
} }
#ifdef TINYSA4
static const uint16_t rbwsel_x10[]={0,3,10,30,100,300,1000,3000,6000}; static const uint16_t rbwsel_x10[]={0,3,10,30,100,300,1000,3000,6000};
static const char* rbwsel_text[]={"auto","300","1k","3k","10k","30k","100k","300k","600k"}; static const char* rbwsel_text[]={"auto","300","1k","3k","10k","30k","100k","300k","600k"};
#else
static const uint16_t rbwsel_x10[]={0,30,100,300,1000,3000,6000};
#endif
static UI_FUNCTION_ADV_CALLBACK(menu_rbw_acb) static UI_FUNCTION_ADV_CALLBACK(menu_rbw_acb)
{ {
(void)item; (void)item;
if (b){ if (b){
#ifdef TINYSA4
b->param_1.text = rbwsel_text[data]; b->param_1.text = rbwsel_text[data];
#else
b->param_1.u = rbwsel_x10[data]/10;
#endif
b->icon = setting.rbw_x10 == rbwsel_x10[data] ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP; b->icon = setting.rbw_x10 == rbwsel_x10[data] ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP;
return; return;
} }
@ -1390,6 +1391,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_settings_below_if_acb){
draw_menu(); draw_menu();
} }
#ifdef TINYSA4
static UI_FUNCTION_ADV_CALLBACK(menu_settings_ultra_acb){ static UI_FUNCTION_ADV_CALLBACK(menu_settings_ultra_acb){
(void)item; (void)item;
(void)data; (void)data;
@ -1403,6 +1405,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_settings_ultra_acb){
toggle_ultra(); toggle_ultra();
draw_menu(); draw_menu();
} }
#endif
static UI_FUNCTION_ADV_CALLBACK(menu_lo_output_acb){ static UI_FUNCTION_ADV_CALLBACK(menu_lo_output_acb){
(void)item; (void)item;
@ -1552,7 +1555,7 @@ static const menuitem_t menu_load_preset[] =
{ MT_CANCEL, 255, S_LARROW" BACK", NULL }, { MT_CANCEL, 255, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel { MT_NONE, 0, NULL, NULL } // sentinel
}; };
#ifdef TINYSA4
static const menuitem_t menu_mixer_drive[] = { static const menuitem_t menu_mixer_drive[] = {
{ MT_ADV_CALLBACK, 3, "%+ddBm", menu_mixer_drive_acb}, { MT_ADV_CALLBACK, 3, "%+ddBm", menu_mixer_drive_acb},
{ MT_ADV_CALLBACK, 2, "%+ddBm", menu_mixer_drive_acb}, { MT_ADV_CALLBACK, 2, "%+ddBm", menu_mixer_drive_acb},
@ -1561,39 +1564,14 @@ static const menuitem_t menu_mixer_drive[] = {
{ MT_CANCEL, 255, S_LARROW" BACK", NULL }, { MT_CANCEL, 255, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel { MT_NONE, 0, NULL, NULL } // sentinel
}; };
#else
#if 0 static const menuitem_t menu_lo_drive[] = {
static const menuitem_t menu_drive_wide3[] = { { MT_ADV_CALLBACK, 15, "%+ddBm", menu_lo_drive_acb},
{ MT_FORM | MT_ADV_CALLBACK, 5, "%+ddBm", menu_lo_drive_acb}, { MT_ADV_CALLBACK, 14, "%+ddBm", menu_lo_drive_acb},
{ MT_FORM | MT_ADV_CALLBACK, 4, "%+ddBm", menu_lo_drive_acb}, { MT_ADV_CALLBACK, 13, "%+ddBm", menu_lo_drive_acb},
{ MT_FORM | MT_ADV_CALLBACK, 3, "%+ddBm", menu_lo_drive_acb}, { MT_ADV_CALLBACK, 12, "%+ddBm", menu_lo_drive_acb},
{ MT_FORM | MT_ADV_CALLBACK, 2, "%+ddBm", menu_lo_drive_acb}, { MT_CANCEL, 255, S_LARROW" BACK", NULL },
{ MT_FORM | MT_ADV_CALLBACK, 1, "%+ddBm", menu_lo_drive_acb}, { MT_NONE, 0, NULL, NULL } // sentinel
{ MT_FORM | MT_ADV_CALLBACK, 0, "%+ddBm", menu_lo_drive_acb},
{ MT_FORM | MT_CANCEL, 255, S_LARROW" BACK", NULL },
{ MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel
};
static const menuitem_t menu_drive_wide2[] = {
{ MT_FORM | MT_ADV_CALLBACK, 10, "%+ddBm", menu_lo_drive_acb},
{ MT_FORM | MT_ADV_CALLBACK, 9, "%+ddBm", menu_lo_drive_acb},
{ MT_FORM | MT_ADV_CALLBACK, 8, "%+ddBm", menu_lo_drive_acb},
{ MT_FORM | MT_ADV_CALLBACK, 7, "%+ddBm", menu_lo_drive_acb},
{ MT_FORM | MT_ADV_CALLBACK, 6, "%+ddBm", menu_lo_drive_acb},
{ MT_FORM | MT_SUBMENU, 255, S_RARROW" MORE", menu_drive_wide3},
{ MT_FORM | MT_CANCEL, 255, S_LARROW" BACK", NULL },
{ MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel
};
static const menuitem_t menu_drive_wide[] = {
{ MT_FORM | MT_ADV_CALLBACK, 15, "%+ddBm", menu_lo_drive_acb},
{ MT_FORM | MT_ADV_CALLBACK, 14, "%+ddBm", menu_lo_drive_acb},
{ MT_FORM | MT_ADV_CALLBACK, 13, "%+ddBm", menu_lo_drive_acb},
{ MT_FORM | MT_ADV_CALLBACK, 12, "%+ddBm", menu_lo_drive_acb},
{ MT_FORM | MT_ADV_CALLBACK, 11, "%+ddBm", menu_lo_drive_acb},
{ MT_FORM | MT_SUBMENU, 255, S_RARROW" MORE", menu_drive_wide2},
{ MT_FORM | MT_CANCEL, 255, S_LARROW" BACK", NULL },
{ MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel
}; };
#endif #endif
@ -1623,7 +1601,9 @@ char center_text[18] = "FREQ: %s";
static const menuitem_t menu_lowoutputmode[] = { static const menuitem_t menu_lowoutputmode[] = {
{ MT_FORM | MT_ADV_CALLBACK, 0, "LOW OUTPUT %s", menu_outputmode_acb}, { MT_FORM | MT_ADV_CALLBACK, 0, "LOW OUTPUT %s", menu_outputmode_acb},
// { MT_FORM | MT_ADV_CALLBACK, 0, "MOD: %s", menu_smodulation_acb}, // { MT_FORM | MT_ADV_CALLBACK, 0, "MOD: %s", menu_smodulation_acb},
#ifdef TINYSA4
{ MT_FORM | MT_SUBMENU, 255, S_RARROW" Settings", menu_settings3}, { MT_FORM | MT_SUBMENU, 255, S_RARROW" Settings", menu_settings3},
#endif
{ MT_FORM | MT_KEYPAD, KM_CENTER, center_text, "10kHz..350MHz"}, { MT_FORM | MT_KEYPAD, KM_CENTER, center_text, "10kHz..350MHz"},
{ MT_FORM | MT_KEYPAD, KM_LOWOUTLEVEL, "LEVEL: %s", low_level_help_text}, { MT_FORM | MT_KEYPAD, KM_LOWOUTLEVEL, "LEVEL: %s", low_level_help_text},
{ MT_FORM | MT_ADV_CALLBACK, 0, "MOD: %s", menu_smodulation_acb}, { MT_FORM | MT_ADV_CALLBACK, 0, "MOD: %s", menu_smodulation_acb},
@ -1638,12 +1618,19 @@ static const menuitem_t menu_lowoutputmode[] = {
static const menuitem_t menu_highoutputmode[] = { static const menuitem_t menu_highoutputmode[] = {
{ MT_FORM | MT_ADV_CALLBACK, 0, "HIGH OUTPUT %s", menu_outputmode_acb}, { MT_FORM | MT_ADV_CALLBACK, 0, "HIGH OUTPUT %s", menu_outputmode_acb},
#ifdef TINYSA4
{ MT_FORM | MT_SUBMENU, 255, S_RARROW" Settings", menu_settings3}, { MT_FORM | MT_SUBMENU, 255, S_RARROW" Settings", menu_settings3},
#endif
{ MT_FORM | MT_KEYPAD, KM_CENTER, center_text, "240MHz..960MHz"}, { MT_FORM | MT_KEYPAD, KM_CENTER, center_text, "240MHz..960MHz"},
// { MT_FORM | MT_ADV_CALLBACK, 0, "LEVEL: %+ddBm", menu_sdrive_acb}, // { MT_FORM | MT_ADV_CALLBACK, 0, "LEVEL: %+ddBm", menu_sdrive_acb},
{ MT_FORM | MT_KEYPAD, KM_HIGHOUTLEVEL, "LEVEL: %s", low_level_help_text /* "-76..-6" */}, { MT_FORM | MT_KEYPAD, KM_HIGHOUTLEVEL, "LEVEL: %s", low_level_help_text /* "-76..-6" */},
{ MT_FORM | MT_ADV_CALLBACK, 0, "MOD: %s", menu_smodulation_acb}, { MT_FORM | MT_ADV_CALLBACK, 0, "MOD: %s", menu_smodulation_acb},
#ifdef TINYSA4
{ MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_sweep_acb}, { MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_sweep_acb},
#else
{ MT_FORM | MT_KEYPAD, KM_SPAN, "SPAN: %s", NULL},
{ MT_FORM | MT_KEYPAD, KM_SWEEP_TIME,"SWEEP TIME: %s", "0..600 seconds"},
#endif
{ MT_FORM | MT_KEYPAD, KM_OFFSET, "EXTERNAL AMP: %s", "-100..+100"}, { MT_FORM | MT_KEYPAD, KM_OFFSET, "EXTERNAL AMP: %s", "-100..+100"},
{ MT_FORM | MT_CANCEL, 0, "MODE", NULL }, { MT_FORM | MT_CANCEL, 0, "MODE", NULL },
{ MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel { MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel
@ -1665,6 +1652,7 @@ static const menuitem_t menu_average[] = {
static const menuitem_t menu_rbw[] = { static const menuitem_t menu_rbw[] = {
{ MT_ADV_CALLBACK, 0, " AUTO", menu_rbw_acb}, { MT_ADV_CALLBACK, 0, " AUTO", menu_rbw_acb},
#ifdef TINYSA4
{ MT_ADV_CALLBACK, 1, "%sHz", menu_rbw_acb}, { MT_ADV_CALLBACK, 1, "%sHz", menu_rbw_acb},
{ MT_ADV_CALLBACK, 2, "%sHz", menu_rbw_acb}, { MT_ADV_CALLBACK, 2, "%sHz", menu_rbw_acb},
{ MT_ADV_CALLBACK, 3, "%sHz", menu_rbw_acb}, { MT_ADV_CALLBACK, 3, "%sHz", menu_rbw_acb},
@ -1673,6 +1661,14 @@ static const menuitem_t menu_rbw[] = {
{ MT_ADV_CALLBACK, 6, "%sHz", menu_rbw_acb}, { MT_ADV_CALLBACK, 6, "%sHz", menu_rbw_acb},
{ MT_ADV_CALLBACK, 7, "%sHz", menu_rbw_acb}, { MT_ADV_CALLBACK, 7, "%sHz", menu_rbw_acb},
{ MT_ADV_CALLBACK, 8, "%sHz", menu_rbw_acb}, { MT_ADV_CALLBACK, 8, "%sHz", menu_rbw_acb},
#else
{ MT_ADV_CALLBACK, 1, "%4dkHz", menu_rbw_acb},
{ MT_ADV_CALLBACK, 2, "%4dkHz", menu_rbw_acb},
{ MT_ADV_CALLBACK, 3, "%4dkHz", menu_rbw_acb},
{ MT_ADV_CALLBACK, 4, "%4dkHz", menu_rbw_acb},
{ MT_ADV_CALLBACK, 5, "%4dkHz", menu_rbw_acb},
{ MT_ADV_CALLBACK, 6, "%4dkHz", menu_rbw_acb},
#endif
{ MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel { MT_NONE, 0, NULL, NULL } // sentinel
}; };
@ -1847,7 +1843,9 @@ static const menuitem_t menu_sweep_points[] = {
{ MT_ADV_CALLBACK, 1, "%3d point", menu_points_acb }, { MT_ADV_CALLBACK, 1, "%3d point", menu_points_acb },
{ MT_ADV_CALLBACK, 2, "%3d point", menu_points_acb }, { MT_ADV_CALLBACK, 2, "%3d point", menu_points_acb },
{ MT_ADV_CALLBACK, 3, "%3d point", menu_points_acb }, { MT_ADV_CALLBACK, 3, "%3d point", menu_points_acb },
#ifdef TINYSA4
{ MT_ADV_CALLBACK, 4, "%3d point", menu_points_acb }, { MT_ADV_CALLBACK, 4, "%3d point", menu_points_acb },
#endif
{ MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel { MT_NONE, 0, NULL, NULL } // sentinel
}; };
@ -1856,32 +1854,29 @@ static const menuitem_t menu_sweep_speed[] =
{ {
{ MT_ADV_CALLBACK, SD_NORMAL, "NORMAL", menu_scanning_speed_acb}, // order must match definition of enum { MT_ADV_CALLBACK, SD_NORMAL, "NORMAL", menu_scanning_speed_acb}, // order must match definition of enum
{ MT_ADV_CALLBACK, SD_PRECISE, "PRECISE", menu_scanning_speed_acb}, { MT_ADV_CALLBACK, SD_PRECISE, "PRECISE", menu_scanning_speed_acb},
#ifdef TINYSA4
{ MT_ADV_CALLBACK, SD_FAST, "FAST", menu_scanning_speed_acb}, { MT_ADV_CALLBACK, SD_FAST, "FAST", menu_scanning_speed_acb},
#else
{ MT_ADV_CALLBACK | MT_LOW,SD_FAST, "FAST", menu_scanning_speed_acb},
#endif
{ MT_KEYPAD, KM_SWEEP_TIME, "SWEEP\nTIME", "0..600s, 0=disable"}, // This must be item 3 to match highlighting { MT_KEYPAD, KM_SWEEP_TIME, "SWEEP\nTIME", "0..600s, 0=disable"}, // This must be item 3 to match highlighting
{ MT_SUBMENU, 0, "SWEEP\nPOINTS", menu_sweep_points}, { MT_SUBMENU, 0, "SWEEP\nPOINTS", menu_sweep_points},
#ifdef TINYSA4
{ MT_KEYPAD, KM_FAST_SPEEDUP,"FAST\nSPEEDUP", "2..20, 0=disable"}, { MT_KEYPAD, KM_FAST_SPEEDUP,"FAST\nSPEEDUP", "2..20, 0=disable"},
#else
{ MT_KEYPAD | MT_LOW,KM_FAST_SPEEDUP,"FAST\nSPEEDUP", "2..20, 0=disable"},
#endif
{ MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel { MT_NONE, 0, NULL, NULL } // sentinel
}; };
static const menuitem_t menu_settings4[] = #ifdef TINYSA4
{ static const menuitem_t menu_settings4[];
{ MT_ADV_CALLBACK, 0, "DEBUG\nFREQ", menu_debug_freq_acb},
#if 1 // only used during development
{ MT_KEYPAD, KM_COR_AM, "COR\nAM", "Enter AM modulation correction"},
{ MT_KEYPAD, KM_COR_WFM, "COR\nWFM", "Enter WFM modulation correction"},
{ MT_KEYPAD, KM_COR_NFM, "COR\nNFM", "Enter NFM modulation correction"},
#endif
#ifdef __HARMONIC__
{ MT_SUBMENU,0, "HARMONIC", menu_harmonic},
#endif #endif
{ MT_SUBMENU, 0, S_RARROW" MORE", menu_settings3},
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
static const menuitem_t menu_settings3[] = static const menuitem_t menu_settings3[] =
{ {
#ifdef TINYSA4
// { MT_KEYPAD, KM_GRIDLINES, "MINIMUM\nGRIDLINES", "Enter minimum horizontal grid divisions"}, // { MT_KEYPAD, KM_GRIDLINES, "MINIMUM\nGRIDLINES", "Enter minimum horizontal grid divisions"},
{ MT_ADV_CALLBACK, 0, "ADF OUT", menu_adf_out_acb}, { MT_ADV_CALLBACK, 0, "ADF OUT", menu_adf_out_acb},
{ MT_KEYPAD, KM_LPF, "ULTRA\nSTART", "Enter ULTRA mode start freq"}, { MT_KEYPAD, KM_LPF, "ULTRA\nSTART", "Enter ULTRA mode start freq"},
@ -1890,15 +1885,37 @@ static const menuitem_t menu_settings3[] =
{ MT_KEYPAD, KM_MOD, "MODULO", "Set MODULO"}, { MT_KEYPAD, KM_MOD, "MODULO", "Set MODULO"},
{ MT_KEYPAD, KM_CP, "CP", "Set CP"}, { MT_KEYPAD, KM_CP, "CP", "Set CP"},
{ MT_ADV_CALLBACK | MT_LOW, 0, "ULTRA\nMODE", menu_settings_ultra_acb}, { MT_ADV_CALLBACK | MT_LOW, 0, "ULTRA\nMODE", menu_settings_ultra_acb},
#ifdef __HAM_BAND__ #ifdef __HAM_BAND__
{ MT_ADV_CALLBACK, 0, "HAM\nBANDS", menu_settings_ham_bands}, { MT_ADV_CALLBACK, 0, "HAM\nBANDS", menu_settings_ham_bands},
#endif #endif
{ MT_SUBMENU, 0, S_RARROW" MORE", menu_settings4}, { MT_SUBMENU, 0, S_RARROW" MORE", menu_settings4},
#else
{ MT_KEYPAD, KM_10MHZ, "CORRECT\nFREQUENCY", "Enter actual l0MHz frequency"},
{ MT_KEYPAD, KM_GRIDLINES, "MINIMUM\nGRIDLINES", "Enter minimum horizontal grid divisions"},
#ifdef __HAM_BAND__
{ MT_ADV_CALLBACK, 0, "HAM\nBANDS", menu_settings_ham_bands},
#endif
#endif // TINYSA4
{ MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel { MT_NONE, 0, NULL, NULL } // sentinel
}; };
#ifdef TINYSA4
static const menuitem_t menu_settings4[] =
{
{ MT_ADV_CALLBACK, 0, "DEBUG\nFREQ", menu_debug_freq_acb},
#if 1 // only used during development
{ MT_KEYPAD, KM_COR_AM, "COR\nAM", "Enter AM modulation correction"},
{ MT_KEYPAD, KM_COR_WFM, "COR\nWFM", "Enter WFM modulation correction"},
{ MT_KEYPAD, KM_COR_NFM, "COR\nNFM", "Enter NFM modulation correction"},
#endif
#ifdef __HARMONIC__
{ MT_SUBMENU,0, "HARMONIC", menu_harmonic},
#endif
{ MT_SUBMENU, 0, S_RARROW" MORE", menu_settings3},
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
#endif
static const menuitem_t menu_settings2[] = static const menuitem_t menu_settings2[] =
{ {
@ -1912,10 +1929,9 @@ static const menuitem_t menu_settings2[] =
#else #else
{ MT_KEYPAD, KM_NOISE, "NOISE\nLEVEL", "2..20 dB"}, { MT_KEYPAD, KM_NOISE, "NOISE\nLEVEL", "2..20 dB"},
#endif #endif
#ifdef __ULTRA__ #ifdef TINYSA4
{ MT_SUBMENU,0, "HARMONIC", menu_harmonic},
#endif
{ MT_KEYPAD, KM_30MHZ, "ACTUAL\n30MHz", "Enter actual l0MHz frequency"}, { MT_KEYPAD, KM_30MHZ, "ACTUAL\n30MHz", "Enter actual l0MHz frequency"},
#endif
{ MT_SUBMENU, 0, S_RARROW" MORE", menu_settings3}, { MT_SUBMENU, 0, S_RARROW" MORE", menu_settings3},
{ MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel { MT_NONE, 0, NULL, NULL } // sentinel
@ -1928,7 +1944,11 @@ static const menuitem_t menu_settings[] =
{ MT_KEYPAD | MT_LOW, KM_IF, "IF FREQ", "0=auto IF"}, { MT_KEYPAD | MT_LOW, KM_IF, "IF FREQ", "0=auto IF"},
{ MT_SUBMENU,0, "SCAN SPEED", menu_scanning_speed}, { MT_SUBMENU,0, "SCAN SPEED", menu_scanning_speed},
{ MT_KEYPAD, KM_REPEAT, "SAMPLE\nREPEAT", "1..100"}, { MT_KEYPAD, KM_REPEAT, "SAMPLE\nREPEAT", "1..100"},
#ifdef TINYSA4
{ MT_SUBMENU | MT_LOW,0, "MIXER\nDRIVE", menu_mixer_drive}, { MT_SUBMENU | MT_LOW,0, "MIXER\nDRIVE", menu_mixer_drive},
#else
{ MT_SUBMENU | MT_LOW,0, "MIXER\nDRIVE", menu_lo_drive},
#endif
{ MT_SUBMENU, 0, S_RARROW" MORE", menu_settings2}, { MT_SUBMENU, 0, S_RARROW" MORE", menu_settings2},
{ MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel { MT_NONE, 0, NULL, NULL } // sentinel
@ -2085,7 +2105,9 @@ static const menuitem_t menu_level[] = {
// { MT_SUBMENU,0, "CALC", menu_average}, // { MT_SUBMENU,0, "CALC", menu_average},
{ MT_SUBMENU, 0, "UNIT", menu_unit}, { MT_SUBMENU, 0, "UNIT", menu_unit},
{ MT_KEYPAD, KM_OFFSET, "EXTERNAL\nAMP",NULL}, { MT_KEYPAD, KM_OFFSET, "EXTERNAL\nAMP",NULL},
#ifdef TINYSA4
{ MT_ADV_CALLBACK | MT_LOW ,0,"LNA", menu_extra_lna_acb}, { MT_ADV_CALLBACK | MT_LOW ,0,"LNA", menu_extra_lna_acb},
#endif
{ MT_SUBMENU, 0, "TRIGGER", menu_trigger}, { MT_SUBMENU, 0, "TRIGGER", menu_trigger},
{ MT_CANCEL, 0, S_LARROW" BACK",NULL }, { MT_CANCEL, 0, S_LARROW" BACK",NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel { MT_NONE, 0, NULL, NULL } // sentinel
@ -2114,28 +2136,10 @@ static const menuitem_t menu_mode[] = {
{ MT_FORM | MT_ADV_CALLBACK | MT_ICON, I_CONNECT+I_GEN, "Cal. output: %s", menu_sreffer_acb}, { MT_FORM | MT_ADV_CALLBACK | MT_ICON, I_CONNECT+I_GEN, "Cal. output: %s", menu_sreffer_acb},
// { MT_SUBMENU, 0, "EXPERT\nCONFIG", menu_settings3}, // { MT_SUBMENU, 0, "EXPERT\nCONFIG", menu_settings3},
#ifdef __ULTRA__
{ MT_FORM | MT_CALLBACK | MT_ICON, I_LOW_INPUT+I_SA, "ULTRA HIGH INPUT",menu_mode_cb},
#endif
// { MT_FORM | MT_CANCEL, 0, S_RARROW" BACK", NULL }, // { MT_FORM | MT_CANCEL, 0, S_RARROW" BACK", NULL },
{ MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel { MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel
}; };
#ifdef __ULTRA__
const menuitem_t menu_topultra[] = {
{ MT_CALLBACK, 0, "RESET", menu_autosettings_cb},
{ MT_SUBMENU, 0, "FREQ", menu_stimulus},
{ MT_SUBMENU, 0, "LEVEL", menu_level},
{ MT_SUBMENU, 0, "DISPLAY", menu_display},
{ MT_SUBMENU, 0, "MARKER", menu_marker},
{ MT_SUBMENU, 0, "MEASURE", menu_measure},
{ MT_SUBMENU, 0, "SETTINGS", menu_settings},
{ MT_CANCEL, 0, "MODE",NULL},
{ MT_NONE, 0, NULL, NULL } // sentinel,
// MENUITEM_CLOSE,
};
#endif
static const menuitem_t menu_top[] = { static const menuitem_t menu_top[] = {
{ MT_SUBMENU, 0, "PRESET", menu_load_preset}, { MT_SUBMENU, 0, "PRESET", menu_load_preset},
{ MT_SUBMENU, 0, "FREQUENCY", menu_stimulus}, { MT_SUBMENU, 0, "FREQUENCY", menu_stimulus},
@ -2230,6 +2234,7 @@ static void fetch_numeric_target(void)
uistat.value = setting.frequency_IF; uistat.value = setting.frequency_IF;
plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0);
break; break;
#ifdef TINYSA4
case KM_IF2: case KM_IF2:
uistat.value = config.frequency_IF2; uistat.value = config.frequency_IF2;
plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0);
@ -2242,6 +2247,7 @@ static void fetch_numeric_target(void)
uistat.value = ADF4350_modulo; uistat.value = ADF4350_modulo;
plot_printf(uistat.text, sizeof uistat.text, "%4d", uistat.value); plot_printf(uistat.text, sizeof uistat.text, "%4d", uistat.value);
break; break;
#endif
case KM_SAMPLETIME: case KM_SAMPLETIME:
uistat.value = setting.step_delay; uistat.value = setting.step_delay;
plot_printf(uistat.text, sizeof uistat.text, "%3dus", ((int32_t)uistat.value)); plot_printf(uistat.text, sizeof uistat.text, "%3dus", ((int32_t)uistat.value));
@ -2257,10 +2263,10 @@ static void fetch_numeric_target(void)
case KM_LOWOUTLEVEL: case KM_LOWOUTLEVEL:
uistat.value = get_level(); // compensation for dB offset during low output mode uistat.value = get_level(); // compensation for dB offset during low output mode
int end_level = ((int32_t)uistat.value)+setting.level_sweep; int end_level = ((int32_t)uistat.value)+setting.level_sweep;
if (end_level < SL_GENLOW_LEVEL_MIN + config.low_level_output_offset) if (end_level < level_min())
end_level = SL_GENLOW_LEVEL_MIN + config.low_level_output_offset; end_level = level_min();
if (end_level > SL_GENLOW_LEVEL_MIN + SL_GENLOW_LEVEL_RANGE + config.low_level_output_offset) if (end_level > level_max())
end_level = SL_GENLOW_LEVEL_MIN + SL_GENLOW_LEVEL_RANGE + config.low_level_output_offset; end_level = level_max();
uistat.value += setting.offset; uistat.value += setting.offset;
end_level += setting.offset; end_level += setting.offset;
if (setting.level_sweep != 0) if (setting.level_sweep != 0)
@ -2283,18 +2289,27 @@ static void fetch_numeric_target(void)
plot_printf(uistat.text, sizeof uistat.text, "%5d", ((int32_t)uistat.value)); plot_printf(uistat.text, sizeof uistat.text, "%5d", ((int32_t)uistat.value));
break; break;
#endif #endif
#ifdef TINYSA4
case KM_LPF: case KM_LPF:
uistat.value = config.ultra_threshold; uistat.value = config.ultra_threshold;
plot_printf(uistat.text, sizeof uistat.text, "%3.6fMHz", uistat.value / 1000000.0); plot_printf(uistat.text, sizeof uistat.text, "%3.6fMHz", uistat.value / 1000000.0);
break; break;
#endif
case KM_NOISE: case KM_NOISE:
uistat.value = setting.noise; uistat.value = setting.noise;
plot_printf(uistat.text, sizeof uistat.text, "%3d", ((int32_t)uistat.value)); plot_printf(uistat.text, sizeof uistat.text, "%3d", ((int32_t)uistat.value));
break; break;
#ifdef TINYSA4
case KM_30MHZ: case KM_30MHZ:
uistat.value = config.setting_frequency_30mhz; uistat.value = config.setting_frequency_30mhz;
plot_printf(uistat.text, sizeof uistat.text, "%3.6fMHz", uistat.value / 1000000.0); plot_printf(uistat.text, sizeof uistat.text, "%3.6fMHz", uistat.value / 1000000.0);
break; break;
#else
case KM_10MHZ:
uistat.value = config.setting_frequency_10mhz;
plot_printf(uistat.text, sizeof uistat.text, "%3.6fMHz", uistat.value / 1000000.0);
break;
#endif
case KM_OFFSET: case KM_OFFSET:
uistat.value = setting.offset; uistat.value = setting.offset;
plot_printf(uistat.text, sizeof uistat.text, "%.1fdB", uistat.value); plot_printf(uistat.text, sizeof uistat.text, "%.1fdB", uistat.value);
@ -2378,6 +2393,7 @@ set_numeric_value(void)
set_IF(uistat.value); set_IF(uistat.value);
// config_save(); // config_save();
break; break;
#ifdef TINYSA4
case KM_IF2: case KM_IF2:
set_IF2(uistat.value); set_IF2(uistat.value);
// config_save(); // config_save();
@ -2393,6 +2409,7 @@ set_numeric_value(void)
ADF4351_CP((int)uistat.value); ADF4351_CP((int)uistat.value);
// config_save(); // config_save();
break; break;
#endif
case KM_SAMPLETIME: case KM_SAMPLETIME:
set_step_delay(uistat.value); set_step_delay(uistat.value);
break; break;
@ -2422,16 +2439,24 @@ set_numeric_value(void)
set_attack(uistat.value); set_attack(uistat.value);
break; break;
#endif #endif
#ifdef TINYSA4
case KM_LPF: case KM_LPF:
config.ultra_threshold = uistat.value; config.ultra_threshold = uistat.value;
config_save(); config_save();
break; break;
#endif
case KM_NOISE: case KM_NOISE:
set_noise(uistat.value); set_noise(uistat.value);
break; break;
#ifdef TINYSA4
case KM_30MHZ: case KM_30MHZ:
set_30mhz(uistat.value); set_30mhz(uistat.value);
break; break;
#else
case KM_10MHZ:
set_10mhz(uistat.value);
break;
#endif
case KM_OFFSET: case KM_OFFSET:
set_offset(uistat.value); set_offset(uistat.value);
break; break;
@ -2459,7 +2484,7 @@ set_numeric_value(void)
case KM_MODULATION: case KM_MODULATION:
set_modulation_frequency((int)uistat.value); set_modulation_frequency((int)uistat.value);
break; break;
#if 1 #ifdef TINYSA4
case KM_COR_AM: case KM_COR_AM:
config.cor_am = -(int)uistat.value; config.cor_am = -(int)uistat.value;
config_save(); config_save();
@ -2778,13 +2803,13 @@ redraw_cal_status:
ili9341_drawstring(buf, x, y); ili9341_drawstring(buf, x, y);
y += YSTEP + YSTEP/2 ; y += YSTEP + YSTEP/2 ;
#endif #endif
#ifdef TINYSA
if (setting.extra_lna){ if (setting.extra_lna){
ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN);
y = add_quick_menu("LNA:ON", x, y, (menuitem_t *)menu_level); y = add_quick_menu("LNA:ON", x, y, (menuitem_t *)menu_level);
y += YSTEP; y += YSTEP;
} }
#endif
// Cal output // Cal output
if (setting.refer >= 0) { if (setting.refer >= 0) {
ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN);
@ -2873,7 +2898,11 @@ redraw_cal_status:
// Version // Version
y += YSTEP + YSTEP/2 ; y += YSTEP + YSTEP/2 ;
#ifdef TINYSA4
strncpy(buf,&VERSION[11], BLEN-1); strncpy(buf,&VERSION[11], BLEN-1);
#else
strncpy(buf,&VERSION[8], BLEN-1);
#endif
ili9341_drawstring(buf, x, y); ili9341_drawstring(buf, x, y);

Loading…
Cancel
Save

Powered by TurnKey Linux.