From 9a4ea2dceef1915830e4c5f03e2c11378265c140 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Mon, 18 Nov 2024 21:15:36 +0300 Subject: [PATCH] Add Trigger pin option (set pin in low state on trigger event in band: PB13 Pin 1 for band 1 PA14 Pin 2 for band 2 PA9 Pin 3 for band 3 (on enable USART pins redefined to USART mode) PA10 Pin 4 for band 4 (on enable USART pins redefined to USART mode) --- NANOVNA_STM32_F303/board.h | 5 +++ main.c | 4 ++ nanovna.h | 5 ++- sa_core.c | 79 +++++++++++++++++++++++++++++++++++++- ui.c | 22 ++++++++++- 5 files changed, 112 insertions(+), 3 deletions(-) diff --git a/NANOVNA_STM32_F303/board.h b/NANOVNA_STM32_F303/board.h index 6c1432b..1b665f5 100644 --- a/NANOVNA_STM32_F303/board.h +++ b/NANOVNA_STM32_F303/board.h @@ -81,6 +81,11 @@ #define GPIO_PE_SEL 15 #define LINE_PE_SEL PAL_LINE(GPIOA,GPIO_PE_SEL) +#define LINE_PINOUT_1 PAL_LINE(GPIOB,13) // PB13 Pin 1 +#define LINE_PINOUT_2 PAL_LINE(GPIOB,14) // PA14 Pin 2 +#define LINE_PINOUT_3 PAL_LINE(GPIOA, 9) // PA9 Pin 3 +#define LINE_PINOUT_4 PAL_LINE(GPIOA,10) // PA10 Pin 4 + #define GPIOB_XN 0 #define GPIOB_YN 1 #define GPIO_LCD_RESET 2 diff --git a/main.c b/main.c index 157fb0f..2b383b1 100644 --- a/main.c +++ b/main.c @@ -2596,6 +2596,9 @@ void shell_update_speed(void){ } void shell_reset_console(void){ +#ifdef __TRIGGER_PINS__ + initPinOutTrigger(); // pinout use USART Rx / Tx pins, reconfigure it +#endif // Reset I/O queue over USB (for USB need also connect/disconnect) if (usb_IsActive()){ if (config._mode & _MODE_SERIAL) @@ -2642,6 +2645,7 @@ static void shell_init_connection(void) { * Set I/O stream (SDU1 or SD1) for shell */ PREPARE_STREAM; + shell_reset_console(); } #else diff --git a/nanovna.h b/nanovna.h index 24aedc2..ef5e88b 100644 --- a/nanovna.h +++ b/nanovna.h @@ -114,6 +114,7 @@ #define __NOISE_FIGURE__ #define __VBW__ #define __SWEEP_RESTART__ +#define __TRIGGER_PINS__ // Set output pins in HIGH state on trigger event (depend from band trigger different pins) // #define DIRECT_CORRECTION // Not enough space for config in one flash page. #define DB_PER_DEGREE_BELOW 0.056 #define DB_PER_DEGREE_ABOVE 0.069 @@ -1337,7 +1338,9 @@ typedef struct setting systime_t measure_sweep_time_us; systime_t actual_sweep_time_us; systime_t additional_step_delay_us; - +#ifdef __TRIGGER_PINS__ + systime_t pinout_time_s; +#endif uint32_t trigger_grid; // freq_t *correction_frequency; diff --git a/sa_core.c b/sa_core.c index 67e38b9..a950c07 100644 --- a/sa_core.c +++ b/sa_core.c @@ -607,6 +607,9 @@ void reset_settings(int m) setting.bands[i].level = 0; } #endif +#ifdef __TRIGGER_PINS__ + setting.pinout_time_s = 30; +#endif #ifdef __ULTRA__ ultra_start = (config.ultra_start == ULTRA_AUTO ? ULTRA_THRESHOLD : config.ultra_start); #endif @@ -4978,6 +4981,79 @@ void reset_band(void) { } #endif +#ifdef __TRIGGER_PINS__ +//============================================================================================================= +// Trigger Pin control +//============================================================================================================= +#define PINOUT_MAX 4 // Pin count +// Active pins (defined in NANOVNA_STM32_F303\board.h) +static const uint32_t pinout_lines[PINOUT_MAX] = { + LINE_PINOUT_1, + LINE_PINOUT_2, + LINE_PINOUT_3, + LINE_PINOUT_4, +//LINE_PINOUT_5, +//LINE_PINOUT_6, +//LINE_PINOUT_7, +//LINE_PINOUT_8, +}; +// Active pin delay after trigger (get from config) +#define ACTIVE_PINOUT_TIME_S setting.pinout_time_s +static systime_t pinout_timers[PINOUT_MAX]; // Timers count after trigger +static uint16_t active_pins; // Active pins + +void initPinOutTrigger(void) { + active_pins = 0; + for(uint32_t band = 0; band < ARRAY_COUNT(pinout_lines); band++) { + uint32_t pal = pinout_lines[band]; + palSetPadMode(PAL_PORT(pal), PAL_PAD(pal), PAL_MODE_OUTPUT_PUSHPULL); + palClearLine(pal); + } +#ifdef __USE_SERIAL_CONSOLE__ + if (config._mode & _MODE_SERIAL) { // Setup pads for USART if serial connection active + palSetPadMode(GPIO_UART_TX_PORT, GPIO_UART_TX, PAL_MODE_ALTERNATE(7)); + palSetPadMode(GPIO_UART_RX_PORT, GPIO_UART_RX, PAL_MODE_ALTERNATE(7)); + } +#endif +} + +// Trigger activate in band (in multi band mode) or in 0 +static void startPinout(uint16_t band) { + if (band >= ARRAY_COUNT(pinout_lines)) return; + systime_t r_time = chVTGetSystemTimeX(); // get system time + if (!(active_pins & (1<=0) { uistat.freq_value = markers[active_marker].frequency; @@ -5886,6 +5900,12 @@ set_numeric_value(void) setting.trigger_grid = (uistat.value + 0.5/(float)CH_CFG_ST_FREQUENCY)* CH_CFG_ST_FREQUENCY; // US2ST(uistat.value*1000000.0) ; completed = true; break; +#ifdef __TRIGGER_PINS__ + case KM_PIN_TRIGGER_TIME: + setting.pinout_time_s = uistat.value; + completed = true; + break; +#endif case KM_GRIDLINES: set_gridlines(uistat.value); break;