From a95ec1d8cc72c73b6c27476189cd6e44a49b57db Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Fri, 26 Feb 2021 13:00:30 +0100 Subject: [PATCH] Remote desktop --- ili9341.c | 15 +++++++ main.c | 62 ++++++++++++++++++++++++++- nanovna.h | 17 +++++++- sa_core.c | 15 +++++-- si4432.c | 122 ++++++++++++++---------------------------------------- ui.c | 34 +++++++++++++-- ui_sa.c | 20 +++++++++ 7 files changed, 184 insertions(+), 101 deletions(-) diff --git a/ili9341.c b/ili9341.c index c0fff3b..a22bee6 100644 --- a/ili9341.c +++ b/ili9341.c @@ -451,6 +451,14 @@ void ili9341_fill(int x, int y, int w, int h) dmaStreamSetMemory0(dmatx, &background_color); dmaStreamSetMode(dmatx, txdmamode | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD); dmaStreamFlush(w * h); +#ifdef __REMOTE_DESKTOP__ + if (auto_capture) { + send_region("fill", x,y,w,h); + spi_buffer[0] = background_color; + send_buffer((uint8_t *)spi_buffer, 2); + osalThreadSleepMilliseconds(2); + } +#endif } // Copy spi_buffer to region @@ -464,6 +472,13 @@ void ili9341_bulk(int x, int y, int w, int h) dmaStreamSetMode(dmatx, txdmamode | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_MINC); dmaStreamFlush(w * h); +#ifdef __REMOTE_DESKTOP__ + if (auto_capture) { + send_region("bulk", x,y,w,h); + send_buffer((uint8_t *)spi_buffer, w*h*2); + osalThreadSleepMilliseconds(2); + } +#endif } #endif diff --git a/main.c b/main.c index 24d7585..b0903f0 100644 --- a/main.c +++ b/main.c @@ -107,7 +107,7 @@ static int8_t drive_strength = DRIVE_STRENGTH_AUTO; #endif uint8_t sweep_mode = SWEEP_ENABLE; volatile uint8_t redraw_request = 0; // contains REDRAW_XXX flags - +volatile int auto_capture = false; // Version text, displayed in Config->Version menu, also send by info command const char *info_about[]={ BOARD_NAME, @@ -808,6 +808,41 @@ VNA_SHELL_FUNCTION(cmd_dump) } #endif +#ifdef __REMOTE_DESKTOP__ +VNA_SHELL_FUNCTION(cmd_refresh) +{ +// read pixel count at one time (PART*2 bytes required for read buffer) + int m = generic_option_cmd("refresh", "off|on", argc, argv[0]); + if (m>=0) { + auto_capture = m; + } +} + +volatile int mouse_x = 0; +volatile int mouse_y = 0; +volatile int mouse_down = false; + +VNA_SHELL_FUNCTION(cmd_touch) +{ + if (argc == 2){ + mouse_x = (uint32_t)my_atoi(argv[0]); + mouse_y = (uint32_t)my_atoi(argv[1]); + mouse_down = true; + handle_touch_interrupt(); + } +} + +VNA_SHELL_FUNCTION(cmd_release) +{ + if (argc==2) { + mouse_x = (uint32_t)my_atoi(argv[0]); + mouse_y = (uint32_t)my_atoi(argv[1]); + } + mouse_down = false; + handle_touch_interrupt(); +} +#endif + VNA_SHELL_FUNCTION(cmd_capture) { // read pixel count at one time (PART*2 bytes required for read buffer) @@ -828,6 +863,26 @@ VNA_SHELL_FUNCTION(cmd_capture) } } +void send_region(const char *t, int x, int y, int w, int h) +{ + shell_printf("%s\r\n", t); + streamPut(shell_stream, (((uint16_t) x) & 0xff)); + streamPut(shell_stream, (((uint16_t)x>>8) & 0xff)); + streamPut(shell_stream, (((uint16_t) y) & 0xff)); + streamPut(shell_stream, (((uint16_t)y>>8) & 0xff)); + streamPut(shell_stream, (((uint16_t) w) & 0xff)); + streamPut(shell_stream, (((uint16_t)w>>8) & 0xff)); + streamPut(shell_stream, (((uint16_t) h) & 0xff)); + streamPut(shell_stream, (((uint16_t)h>>8) & 0xff)); +} + +void send_buffer(uint8_t * buf, int s) +{ + for (int i = 0; i < s; i++) { + streamPut(shell_stream, *buf++); + } + shell_printf("ch> \r\n"); +} #if 0 VNA_SHELL_FUNCTION(cmd_gamma) { @@ -2389,6 +2444,11 @@ static const VNAShellCommand commands[] = {"edelay" , cmd_edelay , 0}, #endif {"capture" , cmd_capture , CMD_WAIT_MUTEX}, +#ifdef __REMOTE_DESKTOP__ + {"refresh" , cmd_refresh , 0}, + {"touch" , cmd_touch , 0}, + {"release" , cmd_release , 0}, +#endif {"vbat" , cmd_vbat , CMD_WAIT_MUTEX}, // Uses same adc as touch!!!!! #ifdef ENABLE_VBAT_OFFSET_COMMAND {"vbat_offset" , cmd_vbat_offset , 0}, diff --git a/nanovna.h b/nanovna.h index 834955c..63a6118 100644 --- a/nanovna.h +++ b/nanovna.h @@ -51,8 +51,9 @@ #define __SPUR__ // Does spur reduction by shifting IF //#define __USE_SERIAL_CONSOLE__ // Enable serial I/O connection (need enable HAL_USE_SERIAL as TRUE in halconf.h) #define __SINGLE_LETTER__ -#define __NICE_BIG_FONT__ +//#define __NICE_BIG_FONT__ #define __QUASI_PEAK__ +#define __REMOTE_DESKTOP__ #ifdef TINYSA3 #define DEFAULT_IF 433800000 @@ -92,6 +93,13 @@ typedef float measurement_t[TRACES_MAX][POINTS_COUNT]; extern measurement_t measured; #endif +#ifdef __REMOTE_DESKTOP__ +extern volatile int auto_capture; +extern volatile int mouse_x; +extern volatile int mouse_y; +extern volatile int mouse_down; +#endif + #ifdef __VNA__ // Minimum frequency set #define START_MIN 50000 @@ -161,7 +169,10 @@ freq_t get_sweep_frequency(int type); void my_microsecond_delay(int t); float my_atof(const char *p); int shell_printf(const char *fmt, ...); - +#ifdef __REMOTE_DESKTOP__ +void send_region(const char *t, int x, int y, int w, int h); +void send_buffer(uint8_t * buf, int s); +#endif void set_marker_frequency(int m, freq_t f); void toggle_sweep(void); void toggle_mute(void); @@ -282,6 +293,8 @@ void set_measurement(int); // extern int settingSpeed; //extern int setting.step_delay; void sweep_remote(void); +extern int generic_option_cmd( const char *cmd, const char *cmd_list, int argc, char *argv); + #ifdef __AUDIO__ /* * dsp.c diff --git a/sa_core.c b/sa_core.c index 229c4a3..165912b 100644 --- a/sa_core.c +++ b/sa_core.c @@ -3028,8 +3028,12 @@ int validate_signal_within(int i, float margin) if (fabsf(peakLevel-test_case[i].pass) > margin) { return TS_CRITICAL; } + if (setting.measurement == M_PASS_BAND) { + peakFreq = (markers[2].frequency + markers[1].frequency)/2; + markers[0].frequency = peakFreq; + } test_fail_cause[i] = "Frequency "; - if (peakFreq < test_case[i].center * 1000000 - 600000 || test_case[i].center * 1000000 + 600000 < peakFreq ) + if (peakFreq < test_case[i].center * 1000000 - 100000 || test_case[i].center * 1000000 + 100000 < peakFreq ) return TS_FAIL; test_fail_cause[i] = ""; return TS_PASS; @@ -3233,8 +3237,13 @@ common_silent: set_mode(M_LOW); setting.tracking = true; //Sweep BPF setting.auto_IF = false; - setting.frequency_IF = DEFAULT_IF+200000; // Center on SAW filters + setting.frequency_IF = DEFAULT_IF+210000; // Center on SAW filters set_refer_output(2); + markers[1].enabled = M_ENABLED; + markers[1].mtype = M_DELTA; + markers[2].enabled = M_ENABLED; + markers[2].mtype = M_DELTA; + setting.measurement = M_PASS_BAND; goto common; case TP_10MHZ: // 10MHz input set_mode(M_LOW); @@ -3253,7 +3262,7 @@ common_silent: for (int j = 0; j < setting._sweep_points/2 - W2P(test_case[i].width); j++) stored_t[j] = test_case[i].stop; for (int j = setting._sweep_points/2 + W2P(test_case[i].width); j < setting._sweep_points; j++) - stored_t[j] = test_case[i].stop; + stored_t[j] = test_case[i].stop - (i == 6?5:0); for (int j = setting._sweep_points/2 - W2P(test_case[i].width); j < setting._sweep_points/2 + W2P(test_case[i].width); j++) stored_t[j] = test_case[i].pass; break; diff --git a/si4432.c b/si4432.c index ef3ed0f..6cea287 100644 --- a/si4432.c +++ b/si4432.c @@ -223,7 +223,7 @@ void SI4432_Drive(int d) void SI4432_Transmit(int d) { int count = 0; - SI4432_Write_Byte(SI4432_TX_POWER, (uint8_t) (0x18+(d & 7))); + SI4432_Drive(d); if (( SI4432_Read_Byte(SI4432_DEV_STATUS) & 0x03 ) == 2) return; // Already in transmit mode chThdSleepMilliseconds(3); @@ -625,84 +625,40 @@ pureRSSI_t SI4432_RSSI(uint32_t i, int s) return RSSI_RAW; } +static uint8_t SI4432_init_script[] = +{ + SI4432_INT_ENABLE1, 0x0, + SI4432_INT_ENABLE2, 0x0, + SI4432_CLOCK_RECOVERY_GEARSHIFT, 0x00, + SI4432_AGC_OVERRIDE, 0x60, + SI4432_AFC_LOOP_GEARSHIFT_OVERRIDE, 0x00, + SI4432_AFC_TIMING_CONTROL, 0x02, + SI4432_CLOCK_RECOVERY_GEARSHIFT, 0x03, + SI4432_CLOCK_RECOVERY_OFFSET2, 0x01, + SI4432_CLOCK_RECOVERY_OFFSET1, 0x11, + SI4432_CLOCK_RECOVERY_OFFSET0, 0x11, + SI4432_CLOCK_RECOVERY_TIMING_GAIN1, 0x01, + SI4432_CLOCK_RECOVERY_TIMING_GAIN0, 0x13, + SI4432_AFC_LIMITER, 0xFF, + SI4432_DATAACCESS_CONTROL, 0x61, // Disable all packet handling + SI4432_AGC_OVERRIDE, 0x60, // AGC, no LNA, fast gain increment + SI4432_GPIO0_CONF, 0x12, // Normal + SI4432_GPIO1_CONF, 0x15, + SI4432_GPIO2_CONF, 0x1F +}; + void SI4432_Sub_Init(void) { SI4432_Reset(); - - - SI4432_Write_Byte(SI4432_AGC_OVERRIDE, 0x60); //AGC override according to WBS3 - - -#if 0 // Not sure if these add any value - //set VCO and PLL Only for SI4432 V2 - SI4432_Write_Byte(SI4432_FREQ_DEVIATION, 0x1F); //write 0x1F to the Frequency Deviation register - // VCO tuning registers - SI4432_Write_Byte(SI4432_VCO_CURRENT_TRIM, 0x7F); //write 0x7F to the VCO Current Trimming register - SI4432_Write_Byte(SI4432_CHARGEPUMP_OVERRIDE, 0x80); //write 0xD7 to the ChargepumpCurrentTrimmingOverride register - SI4432_Write_Byte(SI4432_DIVIDER_CURRENT_TRIM, 0x40); //write 0x40 to the Divider Current Trimming register -#endif -#if 0 - //set the AGC, BAD FOR PERFORMANCE!!!!!! - SI4432_Write_Byte(0x6A, 0x0B); //write 0x0B to the AGC Override 2 register - //set ADC reference voltage to 0.9V, BAD FOR PERFORMANCE!!!!!! - SI4432_Write_Byte(0x68, 0x04); //write 0x04 to the Deltasigma ADC Tuning 2 register - - SI4432_Write_Byte(0x1F, 0x03); //write 0x03 to the Clock Recovery Gearshift Override register - -#endif - - - SI4432_Write_Byte(SI4432_INT_ENABLE1, 0x0); - SI4432_Write_Byte(SI4432_INT_ENABLE2, 0x0); - // Enable receiver chain -// SI4432_Write_Byte(SI4432_STATE, 0x05); - // Clock Recovery Gearshift Value - SI4432_Write_Byte(SI4432_CLOCK_RECOVERY_GEARSHIFT, 0x00); + uint8_t *p = SI4432_init_script; + while (*p) { + uint8_t r = *p++; + uint8_t v = *p++; + SI4432_Write_Byte (r,v); + } // IF Filter Bandwidth - set_rbw(100) ; -// // Register 0x75 Frequency Band Select -// uint8_t sbsel = 1 ; // recommended setting -// uint8_t hbsel = 0 ; // low bands -// uint8_t fb = 19 ; // 430�439.9 MHz -// uint8_t FBS = (sbsel << 6 ) | (hbsel << 5 ) | fb ; -// SI4432_Write_Byte(SI4432_FREQBAND, FBS) ; -// SI4432_Write_Byte(SI4432_FREQBAND, 0x46) ; - // Register 0x76 Nominal Carrier Frequency - // WE USE 433.92 MHz - // Si443x-Register-Settings_RevB1.xls -// SI4432_Write_Byte(SI4432_FREQCARRIER_H, 0x62) ; -// SI4432_Write_Byte(SI4432_FREQCARRIER_H, 0x00) ; - // Register 0x77 Nominal Carrier Frequency -// SI4432_Write_Byte(SI4432_FREQCARRIER_L, 0x00) ; - // RX MODEM SETTINGS -// SI4432_Write_3_Byte(SI4432_IF_FILTER_BW, 0x81, 0x3C, 0x02) ; // <---------- -// SI4432_Write_Byte(SI4432_IF_FILTER_BW, 0x81) ; // <---------- - SI4432_Write_Byte(SI4432_AFC_LOOP_GEARSHIFT_OVERRIDE, 0x00) ; - SI4432_Write_Byte(SI4432_AFC_TIMING_CONTROL, 0x02) ; - SI4432_Write_Byte(SI4432_CLOCK_RECOVERY_GEARSHIFT, 0x03) ; -// SI4432_Write_Byte(SI4432_CLOCK_RECOVERY_OVERSAMPLING, 0x78) ; // <---------- -// SI4432_Write_3_Byte(SI4432_CLOCK_RECOVERY_OFFSET2, 0x01, 0x11, 0x11) ; // <---------- - SI4432_Write_Byte(SI4432_CLOCK_RECOVERY_OFFSET2, 0x01) ; - SI4432_Write_Byte(SI4432_CLOCK_RECOVERY_OFFSET1, 0x11) ; - SI4432_Write_Byte(SI4432_CLOCK_RECOVERY_OFFSET0, 0x11) ; - SI4432_Write_Byte(SI4432_CLOCK_RECOVERY_TIMING_GAIN1, 0x01) ; - SI4432_Write_Byte(SI4432_CLOCK_RECOVERY_TIMING_GAIN0, 0x13) ; - SI4432_Write_Byte(SI4432_AFC_LIMITER, 0xFF) ; - -// SI4432_Write_3_Byte(0x2C, 0x28, 0x0c, 0x28) ; // <---------- -// SI4432_Write_Byte(Si4432_OOK_COUNTER_VALUE_1, 0x28) ; -// SI4432_Write_Byte(Si4432_OOK_COUNTER_VALUE_2, 0x0C) ; -// SI4432_Write_Byte(Si4432_SLICER_PEAK_HOLD, 0x28) ; - - SI4432_Write_Byte(SI4432_DATAACCESS_CONTROL, 0x61); // Disable all packet handling - - SI4432_Write_Byte(SI4432_AGC_OVERRIDE, 0x60); // AGC, no LNA, fast gain increment - - -// GPIO automatic antenna switching - SI4432_Write_Byte(SI4432_GPIO0_CONF, 0x12) ; // Normal - SI4432_Write_Byte(SI4432_GPIO1_CONF, 0x15) ; +// set_rbw(100) ; // SI4432_Receive(); @@ -738,24 +694,6 @@ void SI4432_Init() SI4432_Sel = SI4432_LO; SI4432_Sub_Init(); //DebugLine("1 init done"); - - SI4432_Sel = SI4432_RX; -// SI4432_Receive();// Enable receiver chain -// SI4432_Write_Byte(Si4432_CRYSTAL_OSC_LOAD_CAP, V0_XTAL_CAPACITANCE);// Tune the crystal -// SI4432_Set_Frequency(433800000); - SI4432_Write_Byte(SI4432_GPIO2_CONF, 0x1F) ; // Set GPIO2 output to ground - - - SI4432_Sel = SI4432_LO; -// SI4432_Write_Byte(Si4432_CRYSTAL_OSC_LOAD_CAP, V1_XTAL_CAPACITANCE);// Tune the crystal -// SI4432_Set_Frequency(443800000); - SI4432_Write_Byte(SI4432_GPIO2_CONF, 0x1F) ; // Set GPIO2 output to ground - - // SI4432_Write_Byte(SI4432_TX_POWER, 0x1C);//Set low power -// SI4432_Transmit(0); - -// SI4432_Write_Byte(SI4432_GPIO2_CONF, 0xC0) ; // Set GPIO2 maximumdrive and clock output -// SI4432_Write_Byte(Si4432_UC_OUTPUT_CLOCK, 0x02) ; // Set 10MHz output } void set_calibration_freq(int freq) diff --git a/ui.c b/ui.c index 3feff6f..a8e9fee 100644 --- a/ui.c +++ b/ui.c @@ -311,8 +311,20 @@ touch_check(void) last_touch_x = x; last_touch_y = y; } +#ifdef __REMOTE_DESKTOP__ + mouse_down = false; + } + if (!stat) { + stat = mouse_down; + if (mouse_down) { + last_touch_x = mouse_x; + last_touch_y = mouse_y; + } + } +#else } -#if 0 // Long press detection +#endif + #if 0 // Long press detection systime_t ticks = chVTGetSystemTimeX(); if (stat && !last_touch_status) { // new button, initialize @@ -435,8 +447,13 @@ touch_draw_test(void) void touch_position(int *x, int *y) { +#ifdef __REMOTE_DESKTOP__ + *x = (mouse_down ? mouse_x : (last_touch_x - config.touch_cal[0]) * 16 / config.touch_cal[2]); + *y = (mouse_down ? mouse_y : (last_touch_y - config.touch_cal[1]) * 16 / config.touch_cal[3]); +#else *x = (last_touch_x - config.touch_cal[0]) * 16 / config.touch_cal[2]; *y = (last_touch_y - config.touch_cal[1]) * 16 / config.touch_cal[3]; +#endif } void @@ -2913,6 +2930,11 @@ void ui_process_touch(void) } static int previous_button_state = 0; +#ifdef __REMOTE_DESKTOP__ +static int previous_mouse_state = 0; +static int previous_mouse_x = 0; +static int previous_mouse_y = 0; +#endif void ui_process(void) @@ -2925,10 +2947,16 @@ ui_process(void) if (operation_requested&OP_LEVER || previous_button_state != button_state) { ui_process_lever(); previous_button_state = button_state; + operation_requested = OP_NONE; } - if (operation_requested&OP_TOUCH) + if (operation_requested&OP_TOUCH +#ifdef __REMOTE_DESKTOP__ + || previous_mouse_state != mouse_down || previous_mouse_x != mouse_x || previous_mouse_y != mouse_y +#endif + ) { ui_process_touch(); - operation_requested = OP_NONE; + operation_requested = OP_NONE; + } } /* Triggered when the button is pressed or released. The LED4 is set to ON.*/ diff --git a/ui_sa.c b/ui_sa.c index 6e90237..0d59fd4 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1327,6 +1327,23 @@ static UI_FUNCTION_ADV_CALLBACK(menu_pause_acb) // draw_cal_status(); } +#ifdef __REMOTE_DESKTOP__ +static UI_FUNCTION_ADV_CALLBACK(menu_send_display_acb) +{ + (void) data; + (void) item; + if (b){ + b->icon = auto_capture ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK; + return; + } + auto_capture = ! auto_capture; +// menu_move_back(); +// ui_mode_normal(); + draw_menu(); +// draw_cal_status(); +} +#endif + static UI_FUNCTION_ADV_CALLBACK(menu_outputmode_acb) { (void) data; @@ -1899,6 +1916,9 @@ static const menuitem_t menu_display[] = { { MT_ADV_CALLBACK,3, "NORMALIZE", menu_storage_acb}, { MT_ADV_CALLBACK,4, "WATER\nFALL", menu_waterfall_acb}, { MT_SUBMENU, 0, "SWEEP\nSETTINGS", menu_sweep_speed}, +#ifdef __REMOTE_DESKTOP__ + { MT_ADV_CALLBACK,0, "SEND\nDISPLAY", menu_send_display_acb}, +#endif // { MT_KEYPAD, KM_SWEEP_TIME, "SWEEP\nTIME", NULL}, { MT_CANCEL, 0, S_LARROW" BACK", NULL },