diff --git a/nanovna.h b/nanovna.h index e57cccc..a4f79b9 100644 --- a/nanovna.h +++ b/nanovna.h @@ -865,6 +865,15 @@ int plot_printf(char *str, int, const char *fmt, ...); #define define_to_STR(x) STR1(x) // sa_core.c + +typedef uint8_t deviceRSSI_t; +typedef int16_t pureRSSI_t; + +// RSSI values conversion macrp +#define DEVICE_TO_PURE_RSSI(rssi) ((rssi)<<4) +#define float_TO_PURE_RSSI(rssi) ((rssi)*32.0) +#define PURE_TO_float(rssi) ((rssi)/32.0) + int get_waterfall(void); void toggle_tracking(void); void calibrate(void); diff --git a/sa_core.c b/sa_core.c index b43b739..76ee3fd 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1275,7 +1275,7 @@ static const int am_modulation[5] = { 4,0,1,5,7 }; // 5 step AM modulat static const int nfm_modulation[5] = { 0, 2, 1, -1, -2}; // 5 step narrow FM modulation static const int wfm_modulation[5] = { 0, 190, 118, -118, -190 }; // 5 step wide FM modulation -char age[POINTS_COUNT]; +deviceRSSI_t age[POINTS_COUNT]; static float old_a = -150; static float correct_RSSI; @@ -1400,7 +1400,7 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M } // -------------------------------- Acquisition loop for one requested frequency covering spur avoidance and vbwsteps ------------------------ - int16_t RSSI = (-150)*32; + pureRSSI_t RSSI = float_TO_PURE_RSSI(-150.0); int t = 0; do { int offs = 0,sm; @@ -1547,7 +1547,7 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M SI4432_Fill(MODE_SELECT(setting.mode), 0); } #endif - int16_t pureRSSI; + pureRSSI_t pureRSSI; // if ( i < 3) // shell_printf("%d %.3f %.3f %.1f\r\n", i, local_IF/1000000.0, lf/1000000.0, subRSSI); @@ -1564,10 +1564,10 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M if (i == 0 && setting.frequency_step == 0 && setting.trigger != T_AUTO) { // if in zero span mode and wait for trigger to happen and NOT in trigger mode register uint16_t t_mode; - uint16_t trigger_lvl; + pureRSSI_t trigger_lvl; uint16_t data_level = T_LEVEL_UNDEF; // Calculate trigger level - trigger_lvl = (setting.trigger_level - correct_RSSI) * 32; + trigger_lvl = float_TO_PURE_RSSI(setting.trigger_level - correct_RSSI); if (setting.trigger_direction == T_UP) t_mode = T_UP_MASK; @@ -1577,7 +1577,7 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M if (setting.sweep_time_us >= 100*ONE_MS_TIME) additional_delay = 20; SI4432_Sel = MODE_SELECT(setting.mode); do{ // wait for trigger to happen - pureRSSI = SI4432_Read_Byte(SI4432_REG_RSSI)<<4; + pureRSSI = DEVICE_TO_PURE_RSSI((deviceRSSI_t)SI4432_Read_Byte(SI4432_REG_RSSI)); if (break_on_operation && operation_requested) // allow aborting a wait for trigger return 0; // abort @@ -1602,7 +1602,7 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M pureRSSI = SI4432_RSSI(lf, MODE_SELECT(setting.mode)); // Get RSSI, either from pre-filled buffer #ifdef __SPUR__ - static int16_t spur_RSSI = -1; + static pureRSSI_t spur_RSSI = -1; if (setting.spur == 1) { if(spur_RSSI == -1) { // If first spur pass spur_RSSI = pureRSSI; // remember measure RSSI @@ -1620,7 +1620,7 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M if (break_on_operation && operation_requested) // break subscanning if requested break; // abort } while (t < vbwSteps); // till all sub steps done - return(RSSI/32.0) + correct_RSSI; // add correction + return PURE_TO_float(RSSI) + correct_RSSI; // add correction } #define MAX_MAX 4 diff --git a/si4432.c b/si4432.c index 029bea8..dc71229 100644 --- a/si4432.c +++ b/si4432.c @@ -82,7 +82,7 @@ static uint8_t shiftIn(void) return value>>GPIO_SPI2_SDO; } -static inline void shiftInBuf(uint16_t sel, uint8_t addr, uint8_t *buf, uint16_t size, uint16_t delay) { +static inline void shiftInBuf(uint16_t sel, uint8_t addr, deviceRSSI_t *buf, uint16_t size, uint16_t delay) { uint8_t i = 0; do{ uint32_t value = addr; @@ -392,7 +392,7 @@ int SI4432_step_delay = 1500; //extern int setting.repeat; #ifdef __FAST_SWEEP__ -extern char age[POINTS_COUNT]; +extern deviceRSSI_t age[POINTS_COUNT]; static int buf_index = 0; static bool buf_read = false; @@ -432,7 +432,7 @@ void SI4432_Fill(int s, int start) my_microsecond_delay(t); } while(1); #else - shiftInBuf(sel, SI4432_REG_RSSI, (uint8_t *)&age[start], sweep_points - start, t); + shiftInBuf(sel, SI4432_REG_RSSI, &age[start], sweep_points - start, t); #endif // __enable_irq(); setting.measure_sweep_time_us = (chVTGetSystemTimeX() - measure)*100; @@ -448,10 +448,10 @@ float getSI4432_RSSI_correction(void){ return SI4432_RSSI_correction; }; -int16_t SI4432_RSSI(uint32_t i, int s) +pureRSSI_t SI4432_RSSI(uint32_t i, int s) { (void) i; - int32_t RSSI_RAW; + pureRSSI_t RSSI_RAW; (void) i; // SEE DATASHEET PAGE 61 #ifdef USE_SI4463 // Not used!!!!!!! @@ -464,7 +464,7 @@ int16_t SI4432_RSSI(uint32_t i, int s) if (buf_read) { if (buf_index == sweep_points-1) buf_read = false; - return (unsigned char)age[buf_index++]<<4; + return DEVICE_TO_PURE_RSSI(age[buf_index++]); } #endif SI4432_Sel = s; @@ -485,7 +485,7 @@ int16_t SI4432_RSSI(uint32_t i, int s) i = setting.repeat; RSSI_RAW = 0; do{ - RSSI_RAW += ((unsigned int)SI4432_Read_Byte(SI4432_REG_RSSI))<<4; + RSSI_RAW += DEVICE_TO_PURE_RSSI((deviceRSSI_t)SI4432_Read_Byte(SI4432_REG_RSSI)); if (--i == 0) break; my_microsecond_delay(100); }while(1); @@ -495,7 +495,8 @@ int16_t SI4432_RSSI(uint32_t i, int s) // if (MODE_INPUT(setting.mode) && RSSI_RAW == 0) // SI4432_Init(); #ifdef __SIMULATION__ - RSSI_RAW = Simulated_SI4432_RSSI(i,s)<<4; +#error "Fixme!!! add correct simulation in pureRSSI_t type" + RSSI_RAW = Simulated_SI4432_RSSI(i,s); #endif //STOP_PROFILE // Serial.println(dBm,2); diff --git a/si4432.h b/si4432.h index 9337e75..ff0367c 100644 --- a/si4432.h +++ b/si4432.h @@ -115,7 +115,7 @@ void SI4432_Receive(void); void SI4432_Init(void); void SI4432_Drive(int); float getSI4432_RSSI_correction(void); -int16_t SI4432_RSSI(uint32_t i, int s); +pureRSSI_t SI4432_RSSI(uint32_t i, int s); #ifdef __SIMULATION__ float Simulated_SI4432_RSSI(uint32_t i, int s); #endif