add some comments, order code

This commit is contained in:
TT 2016-11-02 21:08:33 +09:00
parent 6ff0acecdf
commit bc6ce2963c
4 changed files with 67 additions and 27 deletions

View file

@ -120,7 +120,7 @@ CSRC = $(STARTUPSRC) \
$(SHELLSRC) \
$(DSPLIBSRC) \
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) \

23
main.c
View file

@ -67,6 +67,7 @@ static THD_FUNCTION(Thread1, arg)
chMtxLock(&mutex);
scan_lcd();
chMtxUnlock(&mutex);
ui_process();
#endif
}
}
@ -1104,16 +1105,16 @@ int main(void)
//set_frequency(10000000);
while (1)
{
if (SDU1.config->usbp->state == USB_ACTIVE) {
//palSetPad(GPIOC, GPIOC_LED);
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
"shell", NORMALPRIO + 1,
shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
//palClearPad(GPIOC, GPIOC_LED);
}
chThdSleepMilliseconds(1000);
while (1) {
if (SDU1.config->usbp->state == USB_ACTIVE) {
//palSetPad(GPIOC, GPIOC_LED);
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
"shell", NORMALPRIO + 1,
shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
//palClearPad(GPIOC, GPIOC_LED);
}
chThdSleepMilliseconds(1000);
}
}

View file

@ -1,4 +1,7 @@
/*
* tlv320aic3204.c
*/
extern void I2CWrite(int addr, uint8_t d0, uint8_t d1);
typedef struct {
@ -19,9 +22,16 @@ extern void tlv320aic3204_select_in1(void);
extern void tlv320aic3204_select_in3(void);
extern void tlv320aic3204_adc_filter_enable(int enable);
/*
* ui.c
*/
extern void ui_init(void);
extern void ui_process(void);
/*
* dsp.c
*/
// 5ms @ 48kHz
#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) )
/*
* ili9341.c
*/
extern uint16_t spi_buffer[1024];
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_drawstring_5x7(char *str, int x, int y, uint16_t fg, uint16_t bg);
/*
* plot.c
*/
void plot_init(void);
void set_sweep(int32_t start, int stop);
void redraw(void);
#define TRACES_MAX 4
enum {
@ -141,6 +157,9 @@ typedef struct {
int32_t checksum;
} config_t;
/*
* flash.c
*/
#define CONFIG_MAGIC 0x436f4e45 /* 'CoNF' */
extern config_t *active;

46
plot.c
View file

@ -12,9 +12,6 @@ void draw_frequencies(void);
static inline void force_set_markmap(void);
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 OFFSETY 0
#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_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 CELLWIDTH 32
#define CELLHEIGHT 32
/* indicate dirty cells */
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;
@ -64,7 +73,6 @@ int32_t fgrid = 50000000;
int grid_offset;
int grid_width;
void set_sweep(int32_t start, int stop)
{
int32_t gdigit = 100000000;
@ -105,6 +113,11 @@ circle_inout(int x, int y, int r)
return 0;
}
#define POLAR_CENTER_X 146
#define POLAR_CENTER_Y 116
#define POLAR_RADIUS 116
int
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)
{
return log10f(v[0]*v[0] + v[1]*v[1]);
}
/*
* calculate phase[-2:2] of coefficient
*/
float phase(float *v)
{
return 2 * atan2f(v[1], v[0]) / M_PI;
}
/*
* calculate abs(gamma) * 8
*/
float linear(float *v)
{
return - sqrtf(v[0]*v[0] + v[1]*v[1]) * 8;
}
/*
* calculate vswr; (1+gamma)/(1-gamma)
*/
float swr(float *v)
{
float x = sqrtf(v[0]*v[0] + v[1]*v[1]);
@ -394,6 +418,8 @@ mark_cells_from_index(void)
int t;
/* mark cells between each neighber points */
for (t = 0; t < TRACES_MAX; t++) {
if (!trace[t].enabled)
continue;
int x0 = CELL_X(trace_index[t][0]);
int y0 = CELL_Y(trace_index[t][0]);
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
cell_draw_markers(int m, int n, int w, int h)
{