Skip to content

Commit

Permalink
Merged with upstearm tree.
Browse files Browse the repository at this point in the history
  • Loading branch information
AA6KL committed Nov 17, 2019
2 parents 2c2669a + ed85ca1 commit 932be21
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 39 deletions.
15 changes: 10 additions & 5 deletions fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@

static uint16_t reverse_bits(uint16_t x, int n) {
uint16_t result = 0;
for (int i = 0; i < n; i++, x >>= 1)
int i;
for (i = 0; i < n; i++, x >>= 1)
result = (result << 1) | (x & 1U);
return result;
}
Expand All @@ -44,8 +45,10 @@ 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 (uint16_t i = 0; i < n; i++) {
for (i = 0; i < n; i++) {
uint16_t j = reverse_bits(i, levels);
if (j > i) {
float temp = array[i][real];
Expand All @@ -58,11 +61,13 @@ static void fft256(float array[][2], const uint8_t dir) {
}

// Cooley-Tukey decimation-in-time radix-2 FFT
for (uint16_t size = 2; size <= n; size *= 2) {
for (size = 2; size <= n; size *= 2) {
uint16_t halfsize = size / 2;
uint16_t tablestep = n / size;
for (uint16_t i = 0; i < n; i += size) {
for (uint16_t j = i, k = 0; j < i + halfsize; j++, k += tablestep) {
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) {
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
9 changes: 9 additions & 0 deletions ili9341.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,15 @@ ili9341_drawstring_5x7(const char *str, int x, int y, uint16_t fg, uint16_t bg)
}
}

void
ili9341_drawstring_5x7_inv(const char *str, int x, int y, uint16_t fg, uint16_t bg, bool invert)
{
if (invert)
ili9341_drawstring_5x7(str, x, y, bg, fg);
else
ili9341_drawstring_5x7(str, x, y, fg, bg);
}

void
ili9341_drawchar_size(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg, uint8_t size)
{
Expand Down
7 changes: 6 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,8 @@ config_t config = {
.menu_normal_color = 0xffff,
.menu_active_color = 0x7777,
.trace_color = { RGB565(0,255,255), RGB565(255,0,40), RGB565(0,0,255), RGB565(50,255,0) },
.touch_cal = { 693, 605, 124, 171 }, //{ 620, 600, 160, 190 },
// .touch_cal = { 693, 605, 124, 171 }, // 2.4 inch LCD panel
.touch_cal = { 338, 522, 153, 192 }, // 2.8 inch LCD panel
.default_loadcal = 0,
.harmonic_freq_threshold = 300000000,
.checksum = 0
Expand Down Expand Up @@ -850,6 +851,9 @@ void
set_sweep_frequency(int type, int32_t freq)
{
int cal_applied = cal_status & CALSTAT_APPLY;
// negative value indicate overflow, do nothing
if (freq < 0)
return;
switch (type) {
case ST_START:
freq_mode_startstop();
Expand Down Expand Up @@ -1792,6 +1796,7 @@ set_domain_mode(int mode) // accept DOMAIN_FREQ or DOMAIN_TIME
if (mode != (domain_mode & DOMAIN_MODE)) {
domain_mode = (domain_mode & ~DOMAIN_MODE) | (mode & DOMAIN_MODE);
redraw_request |= REDRAW_FREQUENCY;
uistat.lever_mode = LM_MARKER;
}
}

Expand Down
7 changes: 7 additions & 0 deletions nanovna.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ void ili9341_bulk(int x, int y, int w, int h);
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(const char *str, int x, int y, uint16_t fg, uint16_t bg);
void ili9341_drawstring_5x7_inv(const char *str, int x, int y, uint16_t fg, uint16_t bg, bool inv);
void ili9341_drawchar_size(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg, uint8_t size);
void ili9341_drawstring_size(const char *str, int x, int y, uint16_t fg, uint16_t bg, uint8_t size);
void ili9341_drawfont(uint8_t ch, const font_t *font, int x, int y, uint16_t fg, uint16_t bg);
Expand Down Expand Up @@ -397,12 +398,18 @@ void clear_all_config_prop_data(void);
* ui.c
*/

// lever_mode
enum {
LM_MARKER, LM_SEARCH, LM_CENTER, LM_SPAN
};

typedef struct {
int8_t digit; /* 0~5 */
int8_t digit_mode;
int8_t current_trace; /* 0..3 */
uint32_t value; // for editing at numeric input area
uint32_t previous_value;
uint8_t lever_mode;
} uistat_t;

extern uistat_t uistat;
Expand Down
146 changes: 113 additions & 33 deletions ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

uistat_t uistat = {
digit: 6,
current_trace: 0
current_trace: 0,
lever_mode: LM_MARKER
};


Expand Down Expand Up @@ -700,6 +701,7 @@ menu_transform_cb(int item)
} else {
domain_mode = (domain_mode & ~DOMAIN_MODE) | DOMAIN_TIME;
}
uistat.lever_mode = LM_MARKER;
draw_frequencies();
ui_mode_normal();
break;
Expand Down Expand Up @@ -768,6 +770,7 @@ menu_stimulus_cb(int item)
case 2: /* CENTER */
case 3: /* SPAN */
case 4: /* CW */
uistat.lever_mode = item == 3 ? LM_SPAN : LM_CENTER;
status = btn_wait_release();
if (status & EVT_BUTTON_DOWN_LONG) {
ui_mode_numeric(item);
Expand Down Expand Up @@ -816,22 +819,22 @@ menu_marker_op_cb(int item)
break;
case 3: /* MARKERS->SPAN */
{
if (previous_marker == active_marker)
return;
int32_t freq2 = get_marker_frequency(previous_marker);
if (freq2 < 0)
return;
if (freq > freq2) {
freq2 = freq;
freq = get_marker_frequency(previous_marker);
if (previous_marker == -1 || active_marker == previous_marker) {
int32_t center = get_sweep_frequency(ST_CENTER);
int32_t span = center - freq;
if (span < 0) span = -span;
set_sweep_frequency(ST_SPAN, span * 2);
} else {
int32_t freq2 = get_marker_frequency(previous_marker);
if (freq2 < 0)
return;
if (freq > freq2) {
freq2 = freq;
freq = get_marker_frequency(previous_marker);
}
set_sweep_frequency(ST_START, freq);
set_sweep_frequency(ST_STOP, freq2);
}
set_sweep_frequency(ST_START, freq);
set_sweep_frequency(ST_STOP, freq2);
#if 0
int32_t span = (freq - freq2) * 2;
if (span < 0) span = -span;
set_sweep_frequency(ST_SPAN, span);
#endif
}
break;
}
Expand Down Expand Up @@ -869,6 +872,7 @@ menu_marker_search_cb(int item)
break;
}
redraw_marker(active_marker, TRUE);
uistat.lever_mode = LM_SEARCH;
}

void
Expand Down Expand Up @@ -913,6 +917,7 @@ menu_marker_sel_cb(int item)
}
redraw_marker(active_marker, TRUE);
draw_menu();
uistat.lever_mode = LM_MARKER;
}

const menuitem_t menu_calop[] = {
Expand Down Expand Up @@ -1667,6 +1672,92 @@ ui_mode_normal(void)
ui_mode = UI_NORMAL;
}

static void
lever_move_marker(int status)
{
do {
if (active_marker >= 0 && markers[active_marker].enabled) {
if ((status & EVT_DOWN) && markers[active_marker].index > 0) {
markers[active_marker].index--;
markers[active_marker].frequency = frequencies[markers[active_marker].index];
redraw_marker(active_marker, FALSE);
}
if ((status & EVT_UP) && markers[active_marker].index < 100) {
markers[active_marker].index++;
markers[active_marker].frequency = frequencies[markers[active_marker].index];
redraw_marker(active_marker, FALSE);
}
}
status = btn_wait_release();
} while (status != 0);
if (active_marker >= 0)
redraw_marker(active_marker, TRUE);
}

static void
lever_search_marker(int status)
{
if (active_marker >= 0) {
if (status & EVT_DOWN) {
int i = marker_search_left(markers[active_marker].index);
if (i != -1)
markers[active_marker].index = i;
} else if (status & EVT_UP) {
int i = marker_search_right(markers[active_marker].index);
if (i != -1)
markers[active_marker].index = i;
}
redraw_marker(active_marker, TRUE);
}
}

// ex. 10942 -> 10000
// 6791 -> 5000
// 341 -> 200
static uint32_t
step_round(uint32_t v)
{
// decade step
uint32_t x = 1;
for (x = 1; x*10 < v; x *= 10)
;

// 1-2-5 step
if (x * 2 > v)
return x;
else if (x * 5 > v)
return x * 2;
else
return x * 5;
}

static void
lever_zoom_span(int status)
{
uint32_t span = get_sweep_frequency(ST_SPAN);
if (status & EVT_UP) {
span = step_round(span - 1);
set_sweep_frequency(ST_SPAN, span);
} else if (status & EVT_DOWN) {
span = step_round(span + 1);
span = step_round(span * 3);
set_sweep_frequency(ST_SPAN, span);
}
}

static void
lever_move_center(int status)
{
uint32_t center = get_sweep_frequency(ST_CENTER);
uint32_t span = get_sweep_frequency(ST_SPAN);
span = step_round(span / 3);
if (status & EVT_UP) {
set_sweep_frequency(ST_CENTER, center + span);
} else if (status & EVT_DOWN) {
set_sweep_frequency(ST_CENTER, center - span);
}
}

static void
ui_process_normal(void)
{
Expand All @@ -1675,23 +1766,12 @@ ui_process_normal(void)
if (status & EVT_BUTTON_SINGLE_CLICK) {
ui_mode_menu();
} else {
do {
if (active_marker >= 0 && markers[active_marker].enabled) {
if ((status & EVT_DOWN) && markers[active_marker].index > 0) {
markers[active_marker].index--;
markers[active_marker].frequency = frequencies[markers[active_marker].index];
redraw_marker(active_marker, FALSE);
}
if ((status & EVT_UP) && markers[active_marker].index < 100) {
markers[active_marker].index++;
markers[active_marker].frequency = frequencies[markers[active_marker].index];
redraw_marker(active_marker, FALSE);
}
}
status = btn_wait_release();
} while (status != 0);
if (active_marker >= 0)
redraw_marker(active_marker, TRUE);
switch (uistat.lever_mode) {
case LM_MARKER: lever_move_marker(status); break;
case LM_SEARCH: lever_search_marker(status); break;
case LM_CENTER: lever_move_center(status); break;
case LM_SPAN: lever_zoom_span(status); break;
}
}
}
}
Expand Down

0 comments on commit 932be21

Please sign in to comment.