mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
add some comments, order code
This commit is contained in:
parent
6ff0acecdf
commit
bc6ce2963c
2
Makefile
2
Makefile
|
|
@ -120,7 +120,7 @@ CSRC = $(STARTUPSRC) \
|
||||||
$(SHELLSRC) \
|
$(SHELLSRC) \
|
||||||
$(DSPLIBSRC) \
|
$(DSPLIBSRC) \
|
||||||
usbcfg.c \
|
usbcfg.c \
|
||||||
main.c si5351.c si5351_low.c tlv320aic3204.c dsp.c plot.c ili9431.c numfont20x24.c Font5x7.c flash.c
|
main.c si5351.c si5351_low.c tlv320aic3204.c dsp.c plot.c ui.c ili9431.c numfont20x24.c Font5x7.c flash.c
|
||||||
|
|
||||||
# $(TESTSRC) \
|
# $(TESTSRC) \
|
||||||
|
|
||||||
|
|
|
||||||
23
main.c
23
main.c
|
|
@ -67,6 +67,7 @@ static THD_FUNCTION(Thread1, arg)
|
||||||
chMtxLock(&mutex);
|
chMtxLock(&mutex);
|
||||||
scan_lcd();
|
scan_lcd();
|
||||||
chMtxUnlock(&mutex);
|
chMtxUnlock(&mutex);
|
||||||
|
ui_process();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1104,16 +1105,16 @@ int main(void)
|
||||||
|
|
||||||
//set_frequency(10000000);
|
//set_frequency(10000000);
|
||||||
|
|
||||||
while (1)
|
while (1) {
|
||||||
{
|
if (SDU1.config->usbp->state == USB_ACTIVE) {
|
||||||
if (SDU1.config->usbp->state == USB_ACTIVE) {
|
//palSetPad(GPIOC, GPIOC_LED);
|
||||||
//palSetPad(GPIOC, GPIOC_LED);
|
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
|
||||||
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
|
"shell", NORMALPRIO + 1,
|
||||||
"shell", NORMALPRIO + 1,
|
shellThread, (void *)&shell_cfg1);
|
||||||
shellThread, (void *)&shell_cfg1);
|
chThdWait(shelltp); /* Waiting termination. */
|
||||||
chThdWait(shelltp); /* Waiting termination. */
|
//palClearPad(GPIOC, GPIOC_LED);
|
||||||
//palClearPad(GPIOC, GPIOC_LED);
|
}
|
||||||
}
|
|
||||||
chThdSleepMilliseconds(1000);
|
chThdSleepMilliseconds(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
23
nanovna.h
23
nanovna.h
|
|
@ -1,4 +1,7 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
* tlv320aic3204.c
|
||||||
|
*/
|
||||||
extern void I2CWrite(int addr, uint8_t d0, uint8_t d1);
|
extern void I2CWrite(int addr, uint8_t d0, uint8_t d1);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
@ -19,9 +22,16 @@ extern void tlv320aic3204_select_in1(void);
|
||||||
extern void tlv320aic3204_select_in3(void);
|
extern void tlv320aic3204_select_in3(void);
|
||||||
extern void tlv320aic3204_adc_filter_enable(int enable);
|
extern void tlv320aic3204_adc_filter_enable(int enable);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ui.c
|
||||||
|
*/
|
||||||
extern void ui_init(void);
|
extern void ui_init(void);
|
||||||
extern void ui_process(void);
|
extern void ui_process(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* dsp.c
|
||||||
|
*/
|
||||||
// 5ms @ 48kHz
|
// 5ms @ 48kHz
|
||||||
#define AUDIO_BUFFER_LEN 96
|
#define AUDIO_BUFFER_LEN 96
|
||||||
|
|
||||||
|
|
@ -45,6 +55,9 @@ int si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strengt
|
||||||
|
|
||||||
#define RGB565(b,r,g) ( (((b)<<8)&0xfc00) | (((r)<<2)&0x03e0) | (((g)>>3)&0x001f) )
|
#define RGB565(b,r,g) ( (((b)<<8)&0xfc00) | (((r)<<2)&0x03e0) | (((g)>>3)&0x001f) )
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ili9341.c
|
||||||
|
*/
|
||||||
extern uint16_t spi_buffer[1024];
|
extern uint16_t spi_buffer[1024];
|
||||||
|
|
||||||
void ili9341_init(void);
|
void ili9341_init(void);
|
||||||
|
|
@ -54,12 +67,15 @@ void ili9341_fill(int x, int y, int w, int h, int color);
|
||||||
void ili9341_drawchar_5x7(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg);
|
void ili9341_drawchar_5x7(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg);
|
||||||
void ili9341_drawstring_5x7(char *str, int x, int y, uint16_t fg, uint16_t bg);
|
void ili9341_drawstring_5x7(char *str, int x, int y, uint16_t fg, uint16_t bg);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* plot.c
|
||||||
|
*/
|
||||||
void plot_init(void);
|
void plot_init(void);
|
||||||
|
|
||||||
|
|
||||||
void set_sweep(int32_t start, int stop);
|
void set_sweep(int32_t start, int stop);
|
||||||
void redraw(void);
|
void redraw(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define TRACES_MAX 4
|
#define TRACES_MAX 4
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|
@ -141,6 +157,9 @@ typedef struct {
|
||||||
int32_t checksum;
|
int32_t checksum;
|
||||||
} config_t;
|
} config_t;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* flash.c
|
||||||
|
*/
|
||||||
#define CONFIG_MAGIC 0x436f4e45 /* 'CoNF' */
|
#define CONFIG_MAGIC 0x436f4e45 /* 'CoNF' */
|
||||||
|
|
||||||
extern config_t *active;
|
extern config_t *active;
|
||||||
|
|
|
||||||
46
plot.c
46
plot.c
|
|
@ -12,9 +12,6 @@ void draw_frequencies(void);
|
||||||
static inline void force_set_markmap(void);
|
static inline void force_set_markmap(void);
|
||||||
void frequency_string(char *buf, size_t len, uint32_t freq);
|
void frequency_string(char *buf, size_t len, uint32_t freq);
|
||||||
|
|
||||||
uint16_t markmap[2][8];
|
|
||||||
uint16_t current_mappage = 0;
|
|
||||||
|
|
||||||
#define OFFSETX 15
|
#define OFFSETX 15
|
||||||
#define OFFSETY 0
|
#define OFFSETY 0
|
||||||
#define WIDTH 291
|
#define WIDTH 291
|
||||||
|
|
@ -31,6 +28,9 @@ trace_t trace[TRACES_MAX] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#define CELLWIDTH 32
|
||||||
|
#define CELLHEIGHT 32
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CELL_X0[27:31] cell position
|
* CELL_X0[27:31] cell position
|
||||||
* CELL_Y0[22:26]
|
* CELL_Y0[22:26]
|
||||||
|
|
@ -53,8 +53,17 @@ uint32_t trace_index[TRACES_MAX][101];
|
||||||
|
|
||||||
#define CELL_P(i, x, y) (((((x)&0x03e0UL)<<22) | (((y)&0x03e0UL)<<17)) == ((i)&0xffc00000UL))
|
#define CELL_P(i, x, y) (((((x)&0x03e0UL)<<22) | (((y)&0x03e0UL)<<17)) == ((i)&0xffc00000UL))
|
||||||
|
|
||||||
#define CELLWIDTH 32
|
/* indicate dirty cells */
|
||||||
#define CELLHEIGHT 32
|
uint16_t markmap[2][8];
|
||||||
|
uint16_t current_mappage = 0;
|
||||||
|
|
||||||
|
|
||||||
|
marker_t markers[4] = {
|
||||||
|
{ 1, 30 }, { 0, 40 }, { 0, 60 }, { 0, 80 }
|
||||||
|
};
|
||||||
|
|
||||||
|
int active_marker = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int32_t fstart = 0;
|
int32_t fstart = 0;
|
||||||
|
|
@ -64,7 +73,6 @@ int32_t fgrid = 50000000;
|
||||||
int grid_offset;
|
int grid_offset;
|
||||||
int grid_width;
|
int grid_width;
|
||||||
|
|
||||||
|
|
||||||
void set_sweep(int32_t start, int stop)
|
void set_sweep(int32_t start, int stop)
|
||||||
{
|
{
|
||||||
int32_t gdigit = 100000000;
|
int32_t gdigit = 100000000;
|
||||||
|
|
@ -105,6 +113,11 @@ circle_inout(int x, int y, int r)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define POLAR_CENTER_X 146
|
||||||
|
#define POLAR_CENTER_Y 116
|
||||||
|
#define POLAR_RADIUS 116
|
||||||
|
|
||||||
int
|
int
|
||||||
smith_grid(int x, int y)
|
smith_grid(int x, int y)
|
||||||
{
|
{
|
||||||
|
|
@ -194,22 +207,33 @@ draw_on_strut(int v0, int d, int color)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* calculate log10(abs(gamma))
|
||||||
|
*/
|
||||||
float logmag(float *v)
|
float logmag(float *v)
|
||||||
{
|
{
|
||||||
return log10f(v[0]*v[0] + v[1]*v[1]);
|
return log10f(v[0]*v[0] + v[1]*v[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* calculate phase[-2:2] of coefficient
|
||||||
|
*/
|
||||||
float phase(float *v)
|
float phase(float *v)
|
||||||
{
|
{
|
||||||
return 2 * atan2f(v[1], v[0]) / M_PI;
|
return 2 * atan2f(v[1], v[0]) / M_PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* calculate abs(gamma) * 8
|
||||||
|
*/
|
||||||
float linear(float *v)
|
float linear(float *v)
|
||||||
{
|
{
|
||||||
return - sqrtf(v[0]*v[0] + v[1]*v[1]) * 8;
|
return - sqrtf(v[0]*v[0] + v[1]*v[1]) * 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* calculate vswr; (1+gamma)/(1-gamma)
|
||||||
|
*/
|
||||||
float swr(float *v)
|
float swr(float *v)
|
||||||
{
|
{
|
||||||
float x = sqrtf(v[0]*v[0] + v[1]*v[1]);
|
float x = sqrtf(v[0]*v[0] + v[1]*v[1]);
|
||||||
|
|
@ -394,6 +418,8 @@ mark_cells_from_index(void)
|
||||||
int t;
|
int t;
|
||||||
/* mark cells between each neighber points */
|
/* mark cells between each neighber points */
|
||||||
for (t = 0; t < TRACES_MAX; t++) {
|
for (t = 0; t < TRACES_MAX; t++) {
|
||||||
|
if (!trace[t].enabled)
|
||||||
|
continue;
|
||||||
int x0 = CELL_X(trace_index[t][0]);
|
int x0 = CELL_X(trace_index[t][0]);
|
||||||
int y0 = CELL_Y(trace_index[t][0]);
|
int y0 = CELL_Y(trace_index[t][0]);
|
||||||
int m0 = x0 >> 5;
|
int m0 = x0 >> 5;
|
||||||
|
|
@ -595,12 +621,6 @@ draw_marker(int w, int h, int x, int y, int c, int ch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
marker_t markers[4] = {
|
|
||||||
{ 1, 30 }, { 0, 40 }, { 0, 60 }, { 0, 80 }
|
|
||||||
};
|
|
||||||
|
|
||||||
int active_marker = 0;
|
|
||||||
|
|
||||||
void
|
void
|
||||||
cell_draw_markers(int m, int n, int w, int h)
|
cell_draw_markers(int m, int n, int w, int h)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue