diff --git a/main.c b/main.c index ed519be..0065daa 100644 --- a/main.c +++ b/main.c @@ -104,8 +104,8 @@ static void transform_domain(void); 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; +uint8_t redraw_request = 0; // contains REDRAW_XXX flags +uint8_t auto_capture = false; // Version text, displayed in Config->Version menu, also send by info command const char *info_about[]={ BOARD_NAME, @@ -122,7 +122,7 @@ const char *info_about[]={ 0 // sentinel }; -uint16_t dirty = true; +bool dirty = true; bool completed = false; @@ -845,15 +845,15 @@ VNA_SHELL_FUNCTION(cmd_refresh) } } -volatile int mouse_x = 0; -volatile int mouse_y = 0; -volatile int mouse_down = false; +int16_t mouse_x = 0; +int16_t mouse_y = 0; +uint8_t 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_x = my_atoi(argv[0]); + mouse_y = my_atoi(argv[1]); mouse_down = true; handle_touch_interrupt(); } @@ -862,8 +862,8 @@ VNA_SHELL_FUNCTION(cmd_touch) 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_x = my_atoi(argv[0]); + mouse_y = my_atoi(argv[1]); } mouse_down = false; handle_touch_interrupt(); @@ -2411,7 +2411,7 @@ static const VNAShellCommand commands[] = {"touch" , cmd_touch , 0}, {"release" , cmd_release , 0}, #endif - {"vbat" , cmd_vbat , CMD_WAIT_MUTEX}, // Uses same adc as touch!!!!! + {"vbat" , cmd_vbat , 0}, // Uses same adc as touch!!!!! #ifdef ENABLE_VBAT_OFFSET_COMMAND {"vbat_offset" , cmd_vbat_offset , 0}, #endif diff --git a/nanovna.h b/nanovna.h index 31d8701..e082c4d 100644 --- a/nanovna.h +++ b/nanovna.h @@ -130,10 +130,10 @@ 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; +extern uint8_t auto_capture; +extern int16_t mouse_x; +extern int16_t mouse_y; +extern uint8_t mouse_down; #endif #ifdef __VNA__ @@ -233,7 +233,14 @@ enum { #endif #define MODE_HIGH(x) ((x) == M_HIGH || (x) == M_GENHIGH ) #define MODE_LOW(x) ((x) == M_LOW || (x) == M_GENLOW ) + +#ifdef __SI4432__ +#define MODE_SELECT(x) (MODE_HIGH(x) ? SI4432_LO : SI4432_RX) +#endif +#ifdef __SI4468__ +// Not use mode #define MODE_SELECT(x) (MODE_HIGH(x) ? 1 : 0) +#endif #define SWEEP_ENABLE 0x01 #define SWEEP_ONCE 0x02 @@ -704,7 +711,7 @@ int marker_search_right_min(int from); #define REDRAW_BATTERY (1<<4) #define REDRAW_AREA (1<<5) #define REDRAW_TRIGGER (1<<6) -extern volatile uint8_t redraw_request; +extern uint8_t redraw_request; /* * ili9341.c @@ -1226,6 +1233,7 @@ int plot_printf(char *str, int, const char *fmt, ...); //extern int actualStepDelay; //extern int setting_mode; +#define ARRAY_COUNT(a) (sizeof(a)/sizeof(*(a))) // Speed profile definition #define START_PROFILE systime_t time = chVTGetSystemTimeX(); #define RESTART_PROFILE time = chVTGetSystemTimeX(); diff --git a/plot.c b/plot.c index 28c0bba..8bd610b 100644 --- a/plot.c +++ b/plot.c @@ -1318,8 +1318,10 @@ static void cell_draw_marker_info(int x0, int y0) float level = (actual_t[markers[1].index] + actual_t[markers[2].index])/2.0 - actual_t[markers[0].index]; if (level < -70 || level > 0) break; -// int depth = powf(10.0, 2.0 + (level + 6.02) /20.0 ); - int depth = expf((2.0 + (level + 6.02))*(logf(10.0)/20.0)); +// int depth = powf(10.0, 2.0 + (level + 6.02)/20.0 ); // +// powf(10.0, level/20.0 + 6.02/20.0 + 2.0) +// powf(10.0, level /20.0 ) * powf(10.0, 6.02/20.0 + 2.0); + int depth = expf(level*(logf(10.0)/20.0)) * (powf(10.0, 6.02/20.0 + 2.0)); #endif plot_printf(buf, sizeof buf, "DEPTH: %3d%%", depth); goto show_computed; diff --git a/sa_core.c b/sa_core.c index d25e0a1..52d7176 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1005,10 +1005,11 @@ void auto_set_AGC_LNA(int auto_set, int agc) v = 0x60; // Enable AGC and disable LNA else v = 0x40+agc; // Disable AGC and enable LNA - if (SI4432_old_v[MODE_SELECT(setting.mode)] != v) { + int idx = MODE_SELECT(setting.mode) == SI4432_RX ? 0 : 1; + if (SI4432_old_v[idx] != v) { SI4432_Sel = MODE_SELECT(setting.mode); SI4432_Write_Byte(SI4432_AGC_OVERRIDE, v); - SI4432_old_v[MODE_SELECT(setting.mode)] = v; + SI4432_old_v[idx] = v; } #ifdef __SI4463__ unsigned char v; @@ -1031,7 +1032,8 @@ void set_AGC_LNA(void) { if (S_STATE(setting.agc)) v |= 0x20; if (S_STATE(setting.lna)) v |= 0x10; SI4432_Write_Byte(SI4432_AGC_OVERRIDE, v); - SI4432_old_v[MODE_SELECT(setting.mode)] = v; + int idx = MODE_SELECT(setting.mode) == SI4432_RX ? 0 : 1; + SI4432_old_v[idx] = v; } #endif @@ -1236,7 +1238,60 @@ void set_fast_speedup(int s) dirty = true; } -void calculate_step_delay(void) +// +// Table for auto set sweep step/offset delays from RBW +// +#ifdef __SI4432__ +static const struct { + uint16_t rbw_x10; + uint16_t step_delay; + uint32_t offset_delay; +} step_delay_table[]={ +#if 1 +// RBWx10 step_delay offset_delay + { 1910, 300, 100}, + { 1420, 350, 100}, + { 750, 450, 100}, + { 560, 650, 100}, + { 370, 700, 200}, + { 180, 1100, 300}, + { 90, 1700, 400}, + { 50, 3300, 800}, + { 0, 6400, 1600}, +#else + { 1910, 280, 100}, + { 1420, 350, 100}, + { 750, 450, 100}, + { 560, 650, 100}, + { 370, 700, 100}, + { 180, 1100, 200}, + { 90, 1700, 400}, + { 50, 3300, 400}, + { 0, 6400, 1600}, +#endif +}; +#endif + +#ifdef __SI4463__ +static const struct { + uint16_t rbw_x10; + uint16_t step_delay; + uint16_t offset_delay; + uint16_t spur_div_1000; +} step_delay_table[]={ +// RBWx10 step_delay offset_delay spur_gate (value divided by 1000) + { 6000, 80, 50, 400}, + { 3000, 80, 50, 200}, + { 1000, 100, 100, 100}, + { 300, 400, 120, 100}, + { 100, 400, 120, 100}, + { 30, 900, 300, 100}, + { 10, 3000, 600, 100}, + { 0, 9000, 3000, 100} +}; +#endif + +static void calculate_step_delay(void) { if (setting.step_delay_mode == SD_MANUAL || setting.step_delay != 0) { // The latter part required for selftest 3 SI4432_step_delay = setting.step_delay; @@ -1247,38 +1302,19 @@ void calculate_step_delay(void) if (setting.frequency_step == 0) { // zero span mode, not dependent on selected RBW SI4432_step_delay = 0; } else { + // Search index in table depend from RBW + volatile uint16_t i=0; + for (i=0;i= step_delay_table[i].rbw_x10) + break; #ifdef __SI4432__ -#if 1 // Table for double offset delay - if (actual_rbw_x10 >= 1910) { SI4432_step_delay = 300; SI4432_offset_delay = 100; } - else if (actual_rbw_x10 >= 1420) { SI4432_step_delay = 350; SI4432_offset_delay = 100; } - else if (actual_rbw_x10 >= 750) { SI4432_step_delay = 450; SI4432_offset_delay = 100; } - else if (actual_rbw_x10 >= 560) { SI4432_step_delay = 650; SI4432_offset_delay = 100; } - else if (actual_rbw_x10 >= 370) { SI4432_step_delay = 700; SI4432_offset_delay = 200; } - else if (actual_rbw_x10 >= 180) { SI4432_step_delay = 1100; SI4432_offset_delay = 300; } - else if (actual_rbw_x10 >= 90) { SI4432_step_delay = 1700; SI4432_offset_delay = 400; } - else if (actual_rbw_x10 >= 50) { SI4432_step_delay = 3300; SI4432_offset_delay = 800; } - else { SI4432_step_delay = 6400; SI4432_offset_delay =1600; } -#else - if (actual_rbw_x10 >= 1910) { SI4432_step_delay = 280; SI4432_offset_delay = 100; } - else if (actual_rbw_x10 >= 1420) { SI4432_step_delay = 350; SI4432_offset_delay = 100; } - else if (actual_rbw_x10 >= 750) { SI4432_step_delay = 450; SI4432_offset_delay = 100; } - else if (actual_rbw_x10 >= 560) { SI4432_step_delay = 650; SI4432_offset_delay = 100; } - else if (actual_rbw_x10 >= 370) { SI4432_step_delay = 700; SI4432_offset_delay = 100; } - else if (actual_rbw_x10 >= 180) { SI4432_step_delay = 1100; SI4432_offset_delay = 200; } - else if (actual_rbw_x10 >= 90) { SI4432_step_delay = 1700; SI4432_offset_delay = 400; } - else if (actual_rbw_x10 >= 50) { SI4432_step_delay = 3300; SI4432_offset_delay = 400; } - else { SI4432_step_delay = 6400; SI4432_offset_delay =1600; } -#endif + SI4432_step_delay = step_delay_table[i].step_delay; + SI4432_offset_delay = step_delay_table[i].offset_delay; #endif #ifdef __SI4463__ - if (actual_rbw_x10 >= 6000) { SI4432_step_delay = 80; SI4432_offset_delay = 50; spur_gate = 400000; } - else if (actual_rbw_x10 >= 3000) { SI4432_step_delay = 80; SI4432_offset_delay = 50; spur_gate = 200000; } - else if (actual_rbw_x10 >= 1000) { SI4432_step_delay = 100; SI4432_offset_delay = 100; spur_gate = 100000; } - else if (actual_rbw_x10 >= 300) { SI4432_step_delay = 400; SI4432_offset_delay = 120; spur_gate = 100000; } - else if (actual_rbw_x10 >= 100) { SI4432_step_delay = 400; SI4432_offset_delay = 120; spur_gate = 100000; } - else if (actual_rbw_x10 >= 30) { SI4432_step_delay = 900; SI4432_offset_delay = 300; spur_gate = 100000; } - else if (actual_rbw_x10 >= 10) { SI4432_step_delay = 3000; SI4432_offset_delay = 600; spur_gate = 100000; } - else { SI4432_step_delay = 9000; SI4432_offset_delay =3000; spur_gate = 100000; } + SI4432_step_delay = step_delay_table[i].step_delay; + SI4432_offset_delay = step_delay_table[i].offset_delay; + spur_gate = step_delay_table[i].spur_div_1000 * 1000; #endif if (setting.step_delay_mode == SD_PRECISE) // In precise mode wait twice as long for RSSI to stabilize SI4432_step_delay += (SI4432_step_delay>>2) ; @@ -1290,7 +1326,7 @@ void calculate_step_delay(void) } } -void apply_settings(void) // Ensure all settings in the setting structure are translated to the right HW setup +static void apply_settings(void) // Ensure all settings in the setting structure are translated to the right HW setup { set_switches(setting.mode); #ifdef __PE4302__ @@ -1330,7 +1366,7 @@ static const float correction_value[CORRECTION_POINTS] = static int32_t scaled_correction_multi[CORRECTION_POINTS]; static int32_t scaled_correction_value[CORRECTION_POINTS]; -void calculate_correction(void) +static void calculate_correction(void) { scaled_correction_value[0] = setting.correction_value[0] * (1 << (SCALE_FACTOR)); for (int i = 1; i < CORRECTION_POINTS; i++) { @@ -4225,8 +4261,7 @@ common_silent: draw_cal_status(); } -extern void menu_autosettings_cb(int item); - +extern void menu_autosettings_cb(int item, uint16_t data); int last_spur = 0; int add_spur(int f) @@ -4259,7 +4294,7 @@ void self_test(int test) } reset_settings(M_LOW); // Make sure we are in a defined state in_selftest = true; - menu_autosettings_cb(0); + menu_autosettings_cb(0, 0); for (uint16_t i=0; i < TEST_COUNT; i++) { // All test cases waiting if (test_case[i].kind == TC_END) break; diff --git a/si4432.c b/si4432.c index 930daf8..b645193 100644 --- a/si4432.c +++ b/si4432.c @@ -24,6 +24,8 @@ #include #include "si4432.h" +#define _FAST_SHIFT_ + #pragma GCC push_options #pragma GCC optimize ("O2") @@ -52,71 +54,117 @@ static void shiftOut(uint8_t val) { // SI4432_log(SI4432_Sel); // SI4432_log(val); - uint8_t i = 0; +#ifndef _FAST_SHIFT_ + uint16_t i = 8; do { if (val & 0x80) SPI2_SDI_HIGH; SPI2_CLK_HIGH; SPI2_RESET; val<<=1; - }while((++i) & 0x07); + }while(--i); +#else + if (val & 0x80) SPI2_SDI_HIGH; + SPI2_CLK_HIGH; + SPI2_RESET; + if (val & 0x40) SPI2_SDI_HIGH; + SPI2_CLK_HIGH; + SPI2_RESET; + if (val & 0x20) SPI2_SDI_HIGH; + SPI2_CLK_HIGH; + SPI2_RESET; + if (val & 0x10) SPI2_SDI_HIGH; + SPI2_CLK_HIGH; + SPI2_RESET; + if (val & 0x08) SPI2_SDI_HIGH; + SPI2_CLK_HIGH; + SPI2_RESET; + if (val & 0x04) SPI2_SDI_HIGH; + SPI2_CLK_HIGH; + SPI2_RESET; + if (val & 0x02) SPI2_SDI_HIGH; + SPI2_CLK_HIGH; + SPI2_RESET; + if (val & 0x01) SPI2_SDI_HIGH; + SPI2_CLK_HIGH; + SPI2_RESET; +#endif } static uint8_t shiftIn(void) { uint32_t value = 0; - uint8_t i = 0; +#ifndef _FAST_SHIFT_ + uint16_t i = 8; do { value<<=1; SPI2_CLK_HIGH; value|=SPI2_portSDO; SPI2_CLK_LOW; - }while((++i) & 0x07); + }while(--i); +#else + SPI2_CLK_HIGH; + value|=SPI2_portSDO; + SPI2_CLK_LOW; + value<<=1; + SPI2_CLK_HIGH; + value|=SPI2_portSDO; + SPI2_CLK_LOW; + value<<=1; + SPI2_CLK_HIGH; + value|=SPI2_portSDO; + SPI2_CLK_LOW; + value<<=1; + SPI2_CLK_HIGH; + value|=SPI2_portSDO; + SPI2_CLK_LOW; + value<<=1; + SPI2_CLK_HIGH; + value|=SPI2_portSDO; + SPI2_CLK_LOW; + value<<=1; + SPI2_CLK_HIGH; + value|=SPI2_portSDO; + SPI2_CLK_LOW; + value<<=1; + SPI2_CLK_HIGH; + value|=SPI2_portSDO; + SPI2_CLK_LOW; + value<<=1; + SPI2_CLK_HIGH; + value|=SPI2_portSDO; + SPI2_CLK_LOW; +#endif return value>>GPIO_SPI2_SDO; } static inline void shiftInBuf(uint16_t sel, uint8_t addr, deviceRSSI_t *buf, uint16_t size, uint16_t delay) { - uint8_t i = 0; + int idx = 0; do{ + palClearPad(GPIOC, sel); uint32_t value = addr; - palClearPad(GPIOC, sel); + uint16_t i = 8; do { - if (value & 0x80) - SPI2_SDI_HIGH; + if (value & 0x80) SPI2_SDI_HIGH; SPI2_CLK_HIGH; SPI2_RESET; value<<=1; - }while((++i) & 0x07); + }while(--i); value = 0; + i = 8; do { SPI2_CLK_HIGH; value<<=1; value|=SPI2_portSDO; SPI2_CLK_LOW; - }while((++i) & 0x07); + }while(--i); + buf[idx]=value>>GPIO_SPI2_SDO; palSetPad(GPIOC, sel); - *buf++=value>>GPIO_SPI2_SDO; + if (++idx >=size) return; if (delay) my_microsecond_delay(delay); - }while(--size); -} -#if 0 -static void shiftOutBuf(uint8_t *buf, uint16_t size) { - uint8_t i = 0; - do{ - uint8_t val = *buf++; - do{ - if (val & 0x80) - SPI2_SDI_HIGH; - else - SPI2_SDI_LOW; - val<<=1; - SPI2_CLK_HIGH; - SPI2_CLK_LOW; - }while((++i) & 0x07); - }while(--size); + }while(1); } -#endif #ifdef __SI4432__ #define CS_SI0_HIGH palSetPad(GPIOC, GPIO_RX_SEL) @@ -131,11 +179,22 @@ static void shiftOutBuf(uint8_t *buf, uint16_t size) { const uint16_t SI_nSEL[MAX_SI4432+1] = { GPIO_RX_SEL, GPIO_LO_SEL, 0}; // #3 is dummy!!!!!! -volatile int SI4432_Sel = 0; // currently selected SI4432 +uint16_t SI4432_Sel = GPIO_RX_SEL; // currently selected SI4432 // volatile int SI4432_guard = 0; #ifdef __SI4432_H__ #define SELECT_DELAY 10 + +void SI4432_shiftOutDword(uint32_t buf, uint16_t size) { + palClearPad(GPIOC, SI_nSEL[SI4432_Sel]); + do{ + shiftOut(buf); + buf>>=8; + }while(--size); + palSetPad(GPIOC, SI_nSEL[SI4432_Sel]); +} + +#ifndef SI4432_Write_Byte void SI4432_Write_Byte(uint8_t ADR, uint8_t DATA ) { // if (SI4432_guard) @@ -166,8 +225,10 @@ void SI4432_Write_2_Byte(uint8_t ADR, uint8_t DATA1, uint8_t DATA2) palSetPad(GPIOC, SI_nSEL[SI4432_Sel]); // SI4432_guard = 0; } +#endif -void SI4432_Write_3_Byte(uint8_t ADR, uint8_t DATA1, uint8_t DATA2, uint8_t DATA3 ) +#ifndef SI4432_Write_3_Byte +void SI4432_Write_3_Byte(uint8_t ADR, uint8_t DATA1, uint8_t DATA2, uint8_t DATA3) { // if (SI4432_guard) // while(1) ; @@ -183,8 +244,9 @@ void SI4432_Write_3_Byte(uint8_t ADR, uint8_t DATA1, uint8_t DATA2, uint8_t DATA palSetPad(GPIOC, SI_nSEL[SI4432_Sel]); // SI4432_guard = 0; } +#endif -uint8_t SI4432_Read_Byte( uint8_t ADR ) +uint8_t SI4432_Read_Byte(uint8_t ADR) { uint8_t DATA ; // if (SI4432_guard) @@ -192,15 +254,13 @@ uint8_t SI4432_Read_Byte( uint8_t ADR ) // SI4432_guard = 1; // SPI2_CLK_LOW; palClearPad(GPIOC, SI_nSEL[SI4432_Sel]); - shiftOut( ADR ); + shiftOut(ADR); DATA = shiftIn(); palSetPad(GPIOC, SI_nSEL[SI4432_Sel]); // SI4432_guard = 0; return DATA ; } - - void SI4432_Reset(void) { int count = 0; @@ -260,7 +320,7 @@ typedef struct { int8_t RSSI_correction_x_10; // Correction * 10 uint16_t RBWx10; // RBW * 10 in kHz }RBW_t; // sizeof(RBW_t) = 4 bytes -RBW_t RBW_choices[] = { +static const RBW_t RBW_choices[] = { // BW register corr freq // {IF_BW(0,5,1),0,26}, // {IF_BW(0,5,2),0,28}, @@ -323,8 +383,6 @@ RBW_t RBW_choices[] = { }; -const int SI4432_RBW_count = ((int)(sizeof(RBW_choices)/sizeof(RBW_t))); - static pureRSSI_t SI4432_RSSI_correction = float_TO_PURE_RSSI(-120); uint16_t force_rbw(int i) @@ -336,22 +394,22 @@ uint16_t force_rbw(int i) } uint16_t set_rbw(uint16_t WISH) { - int i; - for (i=0; i < SI4432_RBW_count - 1; i++) + uint16_t i; + for (i=0; i >8) & 0xFF ); @@ -395,7 +453,7 @@ void SI4432_Set_Frequency ( freq_t Freq ) { } else { #endif #if 0 // Do not use multi byte write - SI4432_Write_Byte ( 0x75, Freq_Band ); // Freq band must be written first !!!!!!!!!!!! + SI4432_Write_Byte(SI4432_FREQBAND, Freq_Band ); // Freq band must be written first !!!!!!!!!!!! SI4432_Write_Byte(SI4432_FREQCARRIER_H, (Carrier>>8) & 0xFF ); SI4432_Write_Byte(SI4432_FREQCARRIER_L, Carrier & 0xFF ); #else @@ -413,13 +471,13 @@ void SI4432_Set_Frequency ( freq_t Freq ) { // SI4432_Write_Byte( 0x07, 0x0B); } -int SI4432_step_delay = 1500; +uint32_t SI4432_step_delay = 1500; //extern int setting.repeat; #ifdef __FAST_SWEEP__ extern deviceRSSI_t age[POINTS_COUNT]; -static int buf_index = 0; -static int buf_end = 0; +static uint16_t buf_index = 0; +static uint16_t buf_end = 0; static bool buf_read = false; #if 0 @@ -453,26 +511,16 @@ void SI4432_trigger_fill(int s, uint8_t trigger_lvl, int up_direction, int trigg systime_t measure = chVTGetSystemTimeX(); int waiting = ST_ARMING; // __disable_irq(); - SPI2_CLK_LOW; int i = 0; - - register uint16_t t_mode; + uint16_t t_mode = up_direction ? T_UP_MASK : T_DOWN_MASK; uint16_t data_level = T_LEVEL_UNDEF; - if (up_direction) - t_mode = T_UP_MASK; - else - t_mode = T_DOWN_MASK; do { + if (operation_requested) // allow aborting a wait for trigger + return; // abort palClearPad(GPIOC, sel); shiftOut(SI4432_REG_RSSI); - if (operation_requested) // allow aborting a wait for trigger - return; // abort - // Store data level bitfield (remember only last 2 states) - // T_LEVEL_UNDEF mode bit drop after 2 shifts - rssi = shiftIn(); + age[i++] = rssi = shiftIn(); palSetPad(GPIOC, sel); - age[i] = rssi; - i++; if (i >= sweep_points) i = 0; switch (waiting) { @@ -483,7 +531,9 @@ void SI4432_trigger_fill(int s, uint8_t trigger_lvl, int up_direction, int trigg } break; case ST_WAITING: -#if 1 + // Store data level bitfield (remember only last 2 states) + // T_LEVEL_UNDEF mode bit drop after 2 shifts +#if 0 if (rssi < trigger_lvl) { data_level = ((data_level<<1) | (T_LEVEL_BELOW))&(T_LEVEL_CLEAN); } else { @@ -542,14 +592,15 @@ void SI4432_Fill(int s, int start) systime_t measure = chVTGetSystemTimeX(); // __disable_irq(); #if 1 - SPI2_CLK_LOW; - int i = start; + int stop = sweep_points - start; + int i = 0; + uint8_t *buf = &age[start]; do { palClearPad(GPIOC, sel); shiftOut(SI4432_REG_RSSI); - age[i]=(char)shiftIn(); + buf[i]=shiftIn(); palSetPad(GPIOC, sel); - if (++i >= sweep_points) break; + if (++i >=stop) break; if (t) my_microsecond_delay(t); } while(1); @@ -565,7 +616,7 @@ void SI4432_Fill(int s, int start) #endif #define MINIMUM_WAIT_FOR_RSSI 280 -int SI4432_offset_delay = 300; +uint32_t SI4432_offset_delay = 300; pureRSSI_t getSI4432_RSSI_correction(void){ return SI4432_RSSI_correction; @@ -575,7 +626,6 @@ pureRSSI_t SI4432_RSSI(uint32_t i, int s) { (void) i; int32_t RSSI_RAW; - (void) i; // SEE DATASHEET PAGE 61 #ifdef USE_SI4463 // Not used!!!!!!! if (SI4432_Sel == 2) { @@ -629,7 +679,7 @@ pureRSSI_t SI4432_RSSI(uint32_t i, int s) return RSSI_RAW; } -static uint8_t SI4432_init_script[] = +static const uint8_t SI4432_init_script[] = { SI4432_INT_ENABLE1, 0x0, SI4432_INT_ENABLE2, 0x0, @@ -655,7 +705,7 @@ static uint8_t SI4432_init_script[] = void SI4432_Sub_Init(void) { SI4432_Reset(); - uint8_t *p = SI4432_init_script; + const uint8_t *p = SI4432_init_script; while (*p) { uint8_t r = *p++; uint8_t v = *p++; diff --git a/si4432.h b/si4432.h index 74abb18..3a685f7 100644 --- a/si4432.h +++ b/si4432.h @@ -22,8 +22,8 @@ #define __SI4432_H__ -extern int SI4432_step_delay; -extern int SI4432_offset_delay; +extern uint32_t SI4432_step_delay; +extern uint32_t SI4432_offset_delay; #ifdef __SI4432__ // @@ -109,14 +109,21 @@ extern int SI4432_offset_delay; #define SI4432_FIFO 0x7F -extern volatile int SI4432_Sel; // currently selected SI4432 +extern uint16_t SI4432_Sel; // currently selected SI4432 -extern int SI4432_frequency_changed; -extern int SI4432_offset_changed; +extern uint8_t SI4432_frequency_changed; +extern uint8_t SI4432_offset_changed; -void SI4432_Write_Byte(uint8_t ADR, uint8_t DATA ); -void SI4432_Write_2_Byte(uint8_t ADR, uint8_t DATA1, uint8_t DATA2); -uint8_t SI4432_Read_Byte( uint8_t ADR ); +void SI4432_shiftOutDword(uint32_t buf, uint16_t size); +#define SI4432_Write_Byte(ADR, DATA) {uint32_t temp = (((ADR|0x80)&0xFF)<<0)|(((DATA )&0xFF)<<8); SI4432_shiftOutDword(temp, 2);} +#define SI4432_Write_2_Byte(ADR, DATA1, DATA2) {uint32_t temp = (((ADR|0x80)&0xFF)<<0)|(((DATA1)&0xFF)<<8)|(((DATA2)&0xFF)<<16);SI4432_shiftOutDword(temp, 3);} +#define SI4432_Write_3_Byte(ADR, DATA1, DATA2, DATA3) {uint32_t temp = (((ADR|0x80)&0xFF)<<0)|(((DATA1)&0xFF)<<8)|(((DATA2)&0xFF)<<16)|(((DATA3)&0xFF)<<24);SI4432_shiftOutDword(temp, 4);} + +//void SI4432_Write_Byte(uint8_t ADR, uint8_t DATA); +//void SI4432_Write_2_Byte(uint8_t ADR, uint8_t DATA1, uint8_t DATA2); +//void SI4432_Write_3_Byte(uint8_t ADR, uint8_t DATA1, uint8_t DATA2, uint8_t DATA3 ); + +uint8_t SI4432_Read_Byte(uint8_t ADR); void SI4432_Transmit(int d); void SI4432_Receive(void); @@ -133,7 +140,6 @@ void SI4432_Set_Frequency ( uint32_t Freq ); uint16_t force_rbw(int i); uint16_t set_rbw(uint16_t WISH); -extern const int SI4432_RBW_count; void set_calibration_freq(int freq); #ifdef __FAST_SWEEP__ void SI4432_Fill(int s, int start); diff --git a/si4468.c b/si4468.c index 19916db..34f3c2a 100644 --- a/si4468.c +++ b/si4468.c @@ -483,7 +483,7 @@ void SI4432_Set_Frequency ( freq_t Freq ) { } else { #endif #if 0 // Do not use multi byte write - SI4432_Write_Byte ( 0x75, Freq_Band ); // Freq band must be written first !!!!!!!!!!!! + SI4432_Write_Byte(SI4432_FREQBAND, Freq_Band); // Freq band must be written first !!!!!!!!!!!! SI4432_Write_Byte(SI4432_FREQCARRIER_H, (Carrier>>8) & 0xFF ); SI4432_Write_Byte(SI4432_FREQCARRIER_L, Carrier & 0xFF ); #else diff --git a/ui_sa.c b/ui_sa.c index 5f38745..9a03899 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -589,7 +589,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_store_preset_acb) } -extern int dirty; +extern bool dirty; UI_FUNCTION_CALLBACK(menu_autosettings_cb) { (void)item; @@ -800,7 +800,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_spur_acb) } else { b->param_1.text = "MIRROR\nMASKING"; #ifdef TINYSA4 - b->icon = AUTO_ICON(setting.mirror_masking); // mirror_masking does not yet have an auto mode so this is never an auto icon + b->icon = AUTO_ICON(setting.mirror_masking ? 1 : 0); // mirror_masking does not yet have an auto mode so this is never an auto icon #else b->icon = setting.mirror_masking == 0 ? BUTTON_ICON_NOCHECK : BUTTON_ICON_CHECK; #endif @@ -1408,8 +1408,9 @@ static UI_FUNCTION_ADV_CALLBACK(menu_send_display_acb) return; } auto_capture = ! auto_capture; -// menu_move_back(true); -// draw_cal_status(); + // Update all screen to CPU + if (auto_capture) + redraw_request|=REDRAW_AREA|REDRAW_BATTERY|REDRAW_FREQUENCY|REDRAW_CAL_STATUS; } #endif