diff --git a/NANOVNA_STM32_F072/board.h b/NANOVNA_STM32_F072/board.h index 863367b..48a7507 100644 --- a/NANOVNA_STM32_F072/board.h +++ b/NANOVNA_STM32_F072/board.h @@ -122,8 +122,8 @@ * PA13 - SWDIO (alternate 0). * PA14 - SWCLK (alternate 0). */ -#define VAL_GPIOA_MODER (PIN_MODE_INPUT(0U) | \ - PIN_MODE_INPUT(1U) | \ +#define VAL_GPIOA_MODER (PIN_MODE_ANALOG(0U) | \ + PIN_MODE_ANALOG(1U) | \ PIN_MODE_INPUT(2U) | \ PIN_MODE_INPUT(3U) | \ PIN_MODE_INPUT(4U) | \ @@ -131,8 +131,8 @@ PIN_MODE_ANALOG(GPIOA_XP) | \ PIN_MODE_ANALOG(GPIOA_YP) | \ PIN_MODE_ALTERNATE(GPIOA_MCO) | \ - PIN_MODE_INPUT(9U) | \ - PIN_MODE_OUTPUT(GPIOA_USB_DISC) | \ + PIN_MODE_ANALOG(9U) | \ + PIN_MODE_ANALOG(GPIOA_USB_DISC) | \ PIN_MODE_INPUT(GPIOA_USB_DM) | \ PIN_MODE_INPUT(GPIOA_USB_DP) | \ PIN_MODE_ALTERNATE(GPIOA_JTMS) | \ @@ -163,15 +163,15 @@ PIN_OSPEED_2M(6) | \ PIN_OSPEED_2M(7) | \ PIN_OSPEED_100M(GPIOA_MCO) | \ - PIN_OSPEED_100M(9) | \ - PIN_OSPEED_100M(10) | \ + PIN_OSPEED_2M(9) | \ + PIN_OSPEED_2M(10) | \ PIN_OSPEED_100M(GPIOA_USB_DM) | \ PIN_OSPEED_100M(GPIOA_USB_DP) | \ PIN_OSPEED_100M(GPIOA_JTMS) | \ PIN_OSPEED_100M(GPIOA_JTCK) | \ PIN_OSPEED_100M(GPIOA_LCD_RESET)) -#define VAL_GPIOA_PUPDR ( PIN_PUPDR_PULLDOWN(0) | \ - PIN_PUPDR_PULLDOWN(1) | \ +#define VAL_GPIOA_PUPDR ( PIN_PUPDR_FLOATING(0) | \ + PIN_PUPDR_FLOATING(1) | \ PIN_PUPDR_PULLDOWN(2) | \ PIN_PUPDR_PULLDOWN(3) | \ PIN_PUPDR_PULLDOWN(4) | \ @@ -179,8 +179,8 @@ PIN_PUPDR_FLOATING(6) | \ PIN_PUPDR_FLOATING(7) | \ PIN_PUPDR_PULLUP(GPIOA_MCO) | \ - PIN_PUPDR_PULLUP(9) | \ - PIN_PUPDR_PULLUP(GPIOA_USB_DISC) | \ + PIN_PUPDR_FLOATING(9) | \ + PIN_PUPDR_FLOATING(GPIOA_USB_DISC) | \ PIN_PUPDR_FLOATING(GPIOA_USB_DM) | \ PIN_PUPDR_FLOATING(GPIOA_USB_DP) | \ PIN_PUPDR_PULLDOWN(GPIOA_JTMS) | \ diff --git a/adc.c b/adc.c index d48d73e..5123d20 100644 --- a/adc.c +++ b/adc.c @@ -167,3 +167,59 @@ OSAL_IRQ_HANDLER(STM32_ADC1_HANDLER) OSAL_IRQ_EPILOGUE(); } + +#if 1 +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 diff --git a/main.c b/main.c index 39908b4..621cc03 100644 --- a/main.c +++ b/main.c @@ -2365,6 +2365,7 @@ static const VNAShellCommand commands[] = { "o", cmd_o, 0 }, { "d", cmd_d, 0 }, { "f", cmd_f, 0 }, +// { "g", cmd_g, 0 }, #ifdef __ULTRA_SA__ { "x", cmd_x, 0 }, #endif @@ -2647,20 +2648,52 @@ int main(void) chThdSleepMilliseconds(500); +#if 0 + palSetPadMode(GPIOA, 9, PAL_MODE_INPUT_ANALOG); + palSetPadMode(GPIOA, 10, PAL_MODE_OUTPUT_PUSHPULL); + int s; + + adc_stop(); + + // 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 + + + while (1) { +// palSetPad(GPIOA, 10); +// shell_printf("%d\n\r", adc_single_read(ADC_CHSELR_CHSEL9)); +// palClearPad(GPIOA, 10); + shell_printf("%d\n\r", adc_single_read(ADC_TOUCH_X)); + } +#endif + + #if 0 /* * UART initialize */ uartStart(&UARTD1, &uart_cfg_1); - +again: uartStartSend(&UARTD1, 1, "H"); + uint8_t buf[10]; uartStartReceive(&UARTD1, 1, buf); +goto again; #endif #if 0 + again: + palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(1)); // USART1 TX. palSetPadMode(GPIOA,10, PAL_MODE_ALTERNATE(1)); // USART1 RX. + uint8_t buf[10]; sdStart(&SD1,&default_config); osalThreadSleepMilliseconds(10); @@ -2677,7 +2710,7 @@ int main(void) sdReadTimeout(&SD1,buf,10,TIME_IMMEDIATE); sdReadTimeout(&SD1,buf,10, 10); int i = sdReadTimeout(&SD1,buf,10,TIME_IMMEDIATE); - +goto again; #endif #ifdef __ULTRA_SA__ ADF4351_Setup(); diff --git a/sa_cmd.c b/sa_cmd.c index 06eadee..d012b3d 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -374,6 +374,23 @@ VNA_SHELL_FUNCTION(cmd_d) dirty = true; } +#if 0 +extern int16_t adc_buf_read(uint16_t *result, uint32_t count); + +VNA_SHELL_FUNCTION(cmd_g) +{ + (void) argc; + (void) argv; + int32_t a = my_atoi(argv[0]); + systime_t start_of_read = chVTGetSystemTimeX(); + adc_buf_read(spi_buffer, 256); + systime_t time_of_read = chVTGetSystemTimeX() - start_of_read; + shell_printf("Time: %d\r\n", time_of_read); + for (int i=0;i<20;i++) + shell_printf("[%d] = %d\r\n", (int)i, (int)(spi_buffer[i])); +} +#endif + VNA_SHELL_FUNCTION(cmd_a) { diff --git a/sa_core.c b/sa_core.c index 2eb2220..f7ae35b 100644 --- a/sa_core.c +++ b/sa_core.c @@ -2135,6 +2135,13 @@ sweep_again: // stay in sweep loop when output mo } // } while (MODE_OUTPUT(setting.mode) && setting.modulation != MO_NONE); // Never exit sweep loop while in output mode with modulation +#if 0 + extern int16_t adc_buf_read(uint32_t chsel, uint16_t *result, uint32_t count); + trace[TRACE_STORED].enabled = true; + adc_buf_read(ADC_CHSELR_CHSEL10, spi_buffer, 290); + for (int i=0;i<290;i++) + stored_t[i] = (spi_buffer[i]/44.0) - 100.0; +#endif //---------------- in Linearity measurement the attenuation has to be adapted ------------------ diff --git a/ui.c b/ui.c index 23745c7..04f5954 100644 --- a/ui.c +++ b/ui.c @@ -23,6 +23,7 @@ #include "nanovna.h" //#include #include +#include uistat_t uistat = { digit: 6, @@ -1803,16 +1804,64 @@ draw_menu_buttons(const menuitem_t *menu) ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT, DEFAULT_BG_COLOR); } +static systime_t prev_touch_time = 0; +static int prev_touch_button = -1; + + static void menu_select_touch(int i) { selection = i; draw_menu(); +#if 1 // drag values + const menuitem_t *menu = menu_stack[menu_current_level]; + + if (menu_is_form(menu) && MT_MASK(menu[i].type) == MT_KEYPAD){ + int touch_x, touch_y; + touch_position(&touch_x, &touch_y); + systime_t dt = 0; + while (touch_check() != EVT_TOUCH_RELEASED) { + systime_t ticks = chVTGetSystemTimeX(); + if (prev_touch_button != i) { // new button, initialize + prev_touch_time = ticks; + prev_touch_button = i; + } + dt = ticks - prev_touch_time; + + if (dt > BUTTON_DOWN_LONG_TICKS) { + int v = menu[i].data; + int old_keypad_mode = keypad_mode; + keypad_mode = v; + fetch_numeric_target(); + float m = 1.0; + if (touch_x < LCD_WIDTH/2 - 10) { + m = 1/pow(10, ((LCD_WIDTH/2 - 10) - touch_x)/1000.0); + } else if (touch_x > LCD_WIDTH/2 + 10) { + m = pow(10, (touch_x - (LCD_WIDTH/2 + 10))/1000.0); + } + uistat.value *= m; + set_numeric_value(); +// selection = -1; + draw_menu(); + keypad_mode = old_keypad_mode; + return; + } + } + if (dt > BUTTON_DOWN_LONG_TICKS) { + selection = -1; + draw_menu(); + return; + } + prev_touch_button = -1; + } else +#endif + touch_wait_release(); selection = -1; menu_invoke(i); } + static void menu_apply_touch(void) { @@ -1829,14 +1878,18 @@ menu_apply_touch(void) continue; } int active_button_start; - if (menu[i].type & MT_FORM) + if (menu[i].type & MT_FORM) { active_button_start = (LCD_WIDTH - MENU_FORM_WIDTH)/2; - else +// active_button_stop = LCD_WIDTH - active_button_start; + } else { active_button_start = LCD_WIDTH - MENU_BUTTON_WIDTH; - - if (y < touch_y && touch_y < y+MENU_BUTTON_HEIGHT && active_button_start < touch_x) { - menu_select_touch(i); - return; +// active_button_stop = LCD_WIDTH; + } + if (y < touch_y && touch_y < y+MENU_BUTTON_HEIGHT) { + if (touch_x > active_button_start) { + menu_select_touch(i); + return; + } } y += MENU_BUTTON_HEIGHT; }