Skip to content

Commit

Permalink
nanovna-h F303,ui优化
Browse files Browse the repository at this point in the history
  • Loading branch information
hugen79 committed Dec 8, 2019
1 parent 2427307 commit ae2dad0
Show file tree
Hide file tree
Showing 17 changed files with 1,951 additions and 1,947 deletions.
153 changes: 153 additions & 0 deletions .cproject

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>NanoVNA_AA6KL</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>
1 change: 1 addition & 0 deletions NANOVNA_STM32_F303/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#define GPIOA_LEVER1 1
#define GPIOA_LEVER2 2
#define GPIOA_PUSH 3
#define GPIOA_VBUS 4
#define GPIOA_DAC2 5
#define GPIOA_XP 6
#define GPIOA_YP 7
Expand Down
4 changes: 4 additions & 0 deletions NanoVNA_DAP.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface cmsis-dap
transport select swd
source [find target/stm32f3x.cfg]
adapter_khz 8000
13 changes: 8 additions & 5 deletions adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void adc_init(void)

uint16_t adc_single_read(ADC_TypeDef *adc, uint32_t chsel)
{
/* ADC setup */
/* ADC setup */
#ifdef NANOVNA_F303
adcStart(&ADCD2, NULL);
adcgrpcfgXY.sqr[0] = ADC_SQR1_SQ1_N(chsel);
Expand All @@ -148,12 +148,12 @@ uint16_t adc_single_read(ADC_TypeDef *adc, uint32_t chsel)

return adc->DR;
#endif
(void)adc;
}

int16_t adc_vbat_read(ADC_TypeDef *adc)
{
#define ADC_FULL_SCALE 3300
#define VBAT_DIODE_VF 160
#define VREFINT_CAL (*((uint16_t*)0x1FFFF7BA))
float vbat = 0;
float vrefint = 0;
Expand All @@ -177,13 +177,13 @@ int16_t adc_vbat_read(ADC_TypeDef *adc)
return -1;
}

return vbat_raw + VBAT_DIODE_VF;

return vbat_raw + config.vbat_offset;
(void)adc;
}

void adc_start_analog_watchdogd(ADC_TypeDef *adc, uint32_t chsel)
{
uint32_t cfgr1;
// uint32_t cfgr1;

#ifdef NANOVNA_F303
adcStart(&ADCD2, NULL);
Expand Down Expand Up @@ -213,6 +213,7 @@ void adc_start_analog_watchdogd(ADC_TypeDef *adc, uint32_t chsel)
/* ADC conversion start.*/
adc->CR |= ADC_CR_ADSTART;
#endif
(void)adc;
}

void adc_stop(ADC_TypeDef *adc)
Expand Down Expand Up @@ -242,6 +243,7 @@ void adc_stop(ADC_TypeDef *adc)
;*/
}
#endif
(void)adc;
}

void adc_interrupt(ADC_TypeDef *adc)
Expand Down Expand Up @@ -272,6 +274,7 @@ void adc_interrupt(ADC_TypeDef *adc)
handle_touch_interrupt();
}
#endif
(void)adc;
}

OSAL_IRQ_HANDLER(STM32_ADC1_HANDLER)
Expand Down
33 changes: 14 additions & 19 deletions dsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
#include <arm_math.h>
#include "nanovna.h"

#ifdef ENABLED_DUMP
#ifdef __DUMP_CMD__
int16_t samp_buf[SAMPLE_LEN];
int16_t ref_buf[SAMPLE_LEN];
#endif
#endif //__DUMP_CMD__

const int16_t sincos_tbl[48][2] = {
static const int16_t sincos_tbl[48][2] = {
{ 10533, 31029 }, { 27246, 18205 }, { 32698, -2143 }, { 24636, -21605 },
{ 6393, -32138 }, {-14493, -29389 }, {-29389, -14493 }, {-32138, 6393 },
{-21605, 24636 }, { -2143, 32698 }, { 18205, 27246 }, { 31029, 10533 },
Expand All @@ -41,13 +41,12 @@ const int16_t sincos_tbl[48][2] = {
{-24636, -21605 }, {-32698, -2143 }, {-27246, 18205 }, {-10533, 31029 }
};

int32_t acc_samp_s;
int32_t acc_samp_c;
int32_t acc_ref_s;
int32_t acc_ref_c;
static int32_t acc_samp_s;
static int32_t acc_samp_c;
static int32_t acc_ref_s;
static int32_t acc_ref_c;

void
dsp_process(int16_t *capture, size_t length)
void dsp_process(int16_t *capture, size_t length)
{
uint32_t *p = (uint32_t*)capture;
uint32_t len = length / 2;
Expand All @@ -61,10 +60,10 @@ dsp_process(int16_t *capture, size_t length)
uint32_t sr = *p++;
int16_t ref = sr & 0xffff;
int16_t smp = (sr>>16) & 0xffff;
#ifdef ENABLED_DUMP
#ifdef __DUMP_CMD__
ref_buf[i] = ref;
samp_buf[i] = smp;
#endif
#endif //__DUMP_CMD__
int32_t s = sincos_tbl[i][0];
int32_t c = sincos_tbl[i][1];
samp_s += smp * s / 16;
Expand All @@ -85,8 +84,7 @@ dsp_process(int16_t *capture, size_t length)
acc_ref_c = ref_c;
}

void
calculate_gamma(float gamma[2])
void calculate_gamma(float gamma[2])
{
#if 1
// calculate reflection coeff. by samp divide by ref
Expand All @@ -107,22 +105,19 @@ calculate_gamma(float gamma[2])
#endif
}

void
fetch_amplitude(float gamma[2])
void fetch_amplitude(float gamma[2])
{
gamma[0] = acc_samp_s * 1e-9;
gamma[1] = acc_samp_c * 1e-9;
}

void
fetch_amplitude_ref(float gamma[2])
void fetch_amplitude_ref(float gamma[2])
{
gamma[0] = acc_ref_s * 1e-9;
gamma[1] = acc_ref_c * 1e-9;
}

void
reset_dsp_accumerator(void)
void reset_dsp_accumerator(void)
{
acc_ref_s = 0;
acc_ref_c = 0;
Expand Down
16 changes: 5 additions & 11 deletions fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@

#include <math.h>
#include <stdint.h>
#include <arm_math.h>

static uint16_t reverse_bits(uint16_t x, int n) {
uint16_t result = 0;
int i;
for (i = 0; i < n; i++, x >>= 1)
for (int i = 0; i < n; i++, x >>= 1)
result = (result << 1) | (x & 1U);
return result;
}
Expand All @@ -45,10 +43,8 @@ static void fft256(float array[][2], const uint8_t dir) {

const uint8_t real = dir & 1;
const uint8_t imag = ~real & 1;
uint16_t i;
uint16_t size;

for (i = 0; i < n; i++) {
for (uint16_t i = 0; i < n; i++) {
uint16_t j = reverse_bits(i, levels);
if (j > i) {
float temp = array[i][real];
Expand All @@ -61,13 +57,11 @@ static void fft256(float array[][2], const uint8_t dir) {
}

// Cooley-Tukey decimation-in-time radix-2 FFT
for (size = 2; size <= n; size *= 2) {
for (uint16_t size = 2; size <= n; size *= 2) {
uint16_t halfsize = size / 2;
uint16_t tablestep = n / size;
uint16_t i;
for (i = 0; i < n; i += size) {
uint16_t j, k;
for (j = i, k = 0; j < i + halfsize; j++, k += tablestep) {
for (uint16_t i = 0; i < n; i += size) {
for (uint16_t j = i, k = 0; j < i + halfsize; j++, k += tablestep) {
uint16_t l = j + halfsize;
float tpre = array[l][real] * cos(2 * M_PI * k / 256) + array[l][imag] * sin(2 * M_PI * k / 256);
float tpim = -array[l][real] * sin(2 * M_PI * k / 256) + array[l][imag] * cos(2 * M_PI * k / 256);
Expand Down
32 changes: 13 additions & 19 deletions flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ static void flash_erase_page0(uint32_t page_address)
FLASH->CR &= ~FLASH_CR_PER;
}

int flash_erase_page(uint32_t page_address)
static int flash_erase_page(uint32_t page_address)
{
chSysLock();
flash_erase_page0(page_address);
chSysUnlock();
return 0;
}

void flash_program_half_word(uint32_t address, uint16_t data)
static void flash_program_half_word(uint32_t address, uint16_t data)
{
flash_wait_for_last_operation();
FLASH->CR |= FLASH_CR_PG;
Expand All @@ -57,19 +57,18 @@ void flash_program_half_word(uint32_t address, uint16_t data)
FLASH->CR &= ~FLASH_CR_PG;
}

void flash_unlock(void)
static void flash_unlock(void)
{
// unlock sequence
FLASH->KEYR = 0x45670123;
FLASH->KEYR = 0xCDEF89AB;
}


static uint32_t
checksum(const void *start, size_t len)
static uint32_t checksum(const void *start, size_t len)
{
uint32_t *p = (uint32_t*)start;
uint32_t *tail = (uint32_t*)(start + len);
uint32_t *tail = (uint32_t*)((uint8_t*)start + len);
uint32_t value = 0;
while (p < tail)
value ^= *p++;
Expand All @@ -85,8 +84,7 @@ const uint32_t save_config_area = 0x08030000;
const uint32_t save_config_area = 0x08018000;
#endif

int
config_save(void)
int config_save(void)
{
uint16_t *src = (uint16_t*)&config;
uint16_t *dst = (uint16_t*)save_config_area;
Expand All @@ -110,8 +108,7 @@ config_save(void)
return 0;
}

int
config_recall(void)
int config_recall(void)
{
const config_t *src = (const config_t*)save_config_area;
void *dst = &config;
Expand All @@ -137,8 +134,7 @@ uint32_t saveareas[] =
int16_t lastsaveid = 0;


int
caldata_save(int id)
int caldata_save(int id)
{
uint16_t *src = (uint16_t*)&current_props;
uint16_t *dst;
Expand All @@ -155,8 +151,8 @@ caldata_save(int id)
flash_unlock();

/* erase flash pages */
void *p = dst;
void *tail = p + sizeof(properties_t);
uint8_t* p = (uint8_t*)dst;
uint8_t* tail = p + sizeof(properties_t);
while (p < tail) {
flash_erase_page((uint32_t)p);
p += FLASH_PAGESIZE;
Expand All @@ -175,7 +171,6 @@ caldata_save(int id)
return 0;
}

int
caldata_recall(int id)
{
properties_t *src;
Expand All @@ -202,8 +197,7 @@ caldata_recall(int id)
return 0;
}

const properties_t *
caldata_ref(int id)
const properties_t* caldata_ref(int id)
{
const properties_t *src;
if (id < 0 || id >= SAVEAREA_MAX)
Expand All @@ -225,8 +219,8 @@ clear_all_config_prop_data(void)
flash_unlock();

/* erase flash pages */
void *p = (void*)save_config_area;
void *tail = p + save_config_prop_area_size;
uint8_t* p = (uint8_t*)save_config_area;
uint8_t* tail = p + save_config_prop_area_size;
while (p < tail) {
flash_erase_page((uint32_t)p);
p += FLASH_PAGESIZE;
Expand Down
Loading

0 comments on commit ae2dad0

Please sign in to comment.