mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-08-31 03:49:04 +00:00
Praline rssi (#3127)
This commit is contained in:
@@ -182,20 +182,24 @@ void MAX2831::set_mode(const Mode mode) {
|
||||
case Mode::Shutdown:
|
||||
gpio_max2831_rx_enable.write(0); /* RXTX=0 */
|
||||
gpio_max283x_enable.write(0); /* ENABLE=0 */
|
||||
set_rssi_mux(0);
|
||||
break;
|
||||
case Mode::Standby:
|
||||
gpio_max2831_rx_enable.write(1); /* RXTX=1 */
|
||||
gpio_max283x_enable.write(0); /* ENABLE=0 */
|
||||
set_rssi_mux(0);
|
||||
break;
|
||||
case Mode::Transmit:
|
||||
case Mode::Tx_Calibration:
|
||||
gpio_max2831_rx_enable.write(1); /* RXTX=1 for TX */
|
||||
gpio_max283x_enable.write(1); /* ENABLE=1 */
|
||||
set_rssi_mux(2); // transmit power
|
||||
break;
|
||||
case Mode::Receive:
|
||||
case Mode::Rx_Calibration:
|
||||
gpio_max2831_rx_enable.write(0); /* RXTX=0 for RX */
|
||||
gpio_max283x_enable.write(1); /* ENABLE=1 */
|
||||
set_rssi_mux(1); // RSSI
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -475,5 +479,39 @@ void MAX2831::write(const address_t reg_num, const reg_t value) {
|
||||
}
|
||||
}
|
||||
|
||||
void MAX2831::set_rssi_mux(const uint8_t mode) {
|
||||
/* RSSI MUX allows switching the RSSI output between different internal signals.
|
||||
* 0 = disable mux
|
||||
* 1 = RSSI
|
||||
* 2 = TX_POWER
|
||||
* 3 = TEMP
|
||||
*/
|
||||
uint16_t mux_val = 0;
|
||||
|
||||
// Select the appropriate constant based on the input mode.
|
||||
if (mode == 0) {
|
||||
mux_val = 0;
|
||||
} else {
|
||||
// Select the appropriate constant based on the input mode.
|
||||
switch (mode) {
|
||||
case 3:
|
||||
mux_val = REG8_RSSI_MUX_TEMP;
|
||||
break;
|
||||
case 2:
|
||||
mux_val = REG8_RSSI_MUX_TX_POWER;
|
||||
break;
|
||||
case 1:
|
||||
default:
|
||||
mux_val = REG8_RSSI_MUX_RSSI;
|
||||
break;
|
||||
}
|
||||
mux_val |= REG8_RSSI_EN;
|
||||
}
|
||||
|
||||
set_reg_field(8, REG8_RSSI_MUX_MASK | REG8_RSSI_EN, mux_val);
|
||||
flush_reg(8);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace max2831
|
||||
#endif
|
||||
|
||||
@@ -151,6 +151,7 @@ constexpr uint16_t REG8_RSSI_MUX_MASK = 0x0300; /* D9:D8 */
|
||||
constexpr uint16_t REG8_RSSI_MUX_RSSI = (0 << REG8_RSSI_MUX_SHIFT);
|
||||
constexpr uint16_t REG8_RSSI_MUX_TEMP = (1 << REG8_RSSI_MUX_SHIFT);
|
||||
constexpr uint16_t REG8_RSSI_MUX_TX_POWER = (2 << REG8_RSSI_MUX_SHIFT);
|
||||
constexpr uint16_t REG8_RSSI_EN = (1 << 10);
|
||||
|
||||
constexpr uint16_t REG8_RXVGA_GAIN_SPI_EN_SHIFT = 12;
|
||||
constexpr uint16_t REG8_RXVGA_GAIN_SPI_EN = (1 << REG8_RXVGA_GAIN_SPI_EN_SHIFT);
|
||||
@@ -213,6 +214,8 @@ class MAX2831 : public MAX283x {
|
||||
reg_t read(const address_t reg_num) override;
|
||||
void write(const address_t reg_num, const reg_t value) override;
|
||||
|
||||
void set_rssi_mux(const uint8_t mode);
|
||||
|
||||
private:
|
||||
spi::arbiter::Target& _target;
|
||||
Mode _mode{Mode::Standby};
|
||||
|
||||
@@ -46,17 +46,17 @@ RSSI::RSSI(
|
||||
void RSSI::paint(Painter& painter) {
|
||||
const auto r = screen_rect();
|
||||
|
||||
/* RSSI scaling based on transceiver output voltage range.
|
||||
* MAX2837 (HackRF One): 0.4V to 2.2V
|
||||
* MAX2831 (HackRF Pro): 0.5V to 2.0V (similar enough to use same scaling)
|
||||
*/
|
||||
constexpr int rssi_sample_range = 256;
|
||||
// constexpr float rssi_voltage_min = 0.4;
|
||||
constexpr float rssi_voltage_min = 0.4;
|
||||
#ifdef PRALINE
|
||||
constexpr float rssi_voltage_max = 2.4;
|
||||
#else
|
||||
constexpr float rssi_voltage_max = 2.2;
|
||||
// constexpr int raw_min = rssi_sample_range * rssi_voltage_min / adc_voltage_max;
|
||||
constexpr int raw_min = 0;
|
||||
#endif
|
||||
|
||||
constexpr float adc_voltage_max = 3.3;
|
||||
constexpr int raw_max = rssi_sample_range * rssi_voltage_max / adc_voltage_max;
|
||||
constexpr int raw_min = (rssi_sample_range * rssi_voltage_min) / adc_voltage_max;
|
||||
constexpr int raw_max = (int)(((rssi_sample_range * rssi_voltage_max) / adc_voltage_max) + 0.5f);
|
||||
constexpr int raw_delta = raw_max - raw_min;
|
||||
|
||||
if (!vertical_rssi_enabled) {
|
||||
@@ -117,7 +117,6 @@ void RSSI::paint(Painter& painter) {
|
||||
const Rect r_db{r.left() + x_db, r.top(), 1, r.height()};
|
||||
|
||||
if (db_) painter.fill_rectangle(r_db, Color::green());
|
||||
|
||||
} else {
|
||||
// vertical bottom to top level meters
|
||||
const range_t<int> y_avg_range{0, r.height() - 1};
|
||||
@@ -226,7 +225,6 @@ void RSSI::on_statistics_update(const RSSIStatistics& statistics) {
|
||||
min_ = statistics.min;
|
||||
avg_ = statistics.accumulator / statistics.count;
|
||||
max_ = statistics.max;
|
||||
|
||||
if (peak_enabled) {
|
||||
peak_duration_ = peak_duration_ + 100;
|
||||
if (max_ > peak_) {
|
||||
@@ -434,25 +432,38 @@ void RSSIGraph::paint(Painter& painter) {
|
||||
void RSSIGraph::add_values(int16_t rssi_min, int16_t rssi_avg, int16_t rssi_max, int16_t db) {
|
||||
const auto r = screen_rect();
|
||||
|
||||
/* RSSI scaling based on transceiver output voltage range.
|
||||
* MAX2837 (HackRF One): 0.4V to 2.2V
|
||||
* MAX2831 (HackRF Pro): 0.4V to 2.4V
|
||||
*/
|
||||
|
||||
constexpr int rssi_sample_range = 256;
|
||||
// constexpr float rssi_voltage_min = 0.4;
|
||||
constexpr float rssi_voltage_min = 0.4;
|
||||
#ifdef PRALINE
|
||||
constexpr float rssi_voltage_max = 2.4;
|
||||
#else
|
||||
constexpr float rssi_voltage_max = 2.2;
|
||||
// constexpr int raw_min = rssi_sample_range * rssi_voltage_min / adc_voltage_max;
|
||||
constexpr int raw_min = 0;
|
||||
#endif
|
||||
|
||||
constexpr float adc_voltage_max = 3.3;
|
||||
constexpr int raw_max = rssi_sample_range * rssi_voltage_max / adc_voltage_max;
|
||||
constexpr int raw_min = (rssi_sample_range * rssi_voltage_min) / adc_voltage_max;
|
||||
constexpr int raw_max = (int)(((rssi_sample_range * rssi_voltage_max) / adc_voltage_max) + 0.5f);
|
||||
constexpr int raw_delta = raw_max - raw_min;
|
||||
|
||||
// vertical bottom to top level meters
|
||||
// y_avg
|
||||
const range_t<int> y_avg_range{0, r.height() - 1};
|
||||
const int16_t y_avg = y_avg_range.clip((rssi_avg - raw_min) * r.height() / raw_delta);
|
||||
// y_min
|
||||
const range_t<int> y_min_range{0, y_avg};
|
||||
const int16_t y_min = y_min_range.clip((rssi_min - raw_min) * r.height() / raw_delta);
|
||||
const range_t<int> y_max_range{y_avg + 1, r.height() - 1};
|
||||
// y_max
|
||||
const range_t<int> y_max_range{y_avg, r.height() - 1};
|
||||
const int16_t y_max = y_max_range.clip((rssi_max - raw_min) * r.height() / raw_delta);
|
||||
// range
|
||||
const range_t<int> db_range{-80, 10};
|
||||
int16_t db_ = db_range.clip(db);
|
||||
db_ = db_ - 10;
|
||||
db_ -= 10;
|
||||
db_ = db_ * r.height() / 90;
|
||||
db_ = r.height() + db_;
|
||||
|
||||
@@ -529,12 +540,6 @@ bool RSSI::on_touch(const TouchEvent event) {
|
||||
}
|
||||
|
||||
void RSSI::set_db(int16_t db) {
|
||||
#ifdef PRALINE
|
||||
/* Add a +30dB global boost to align 40MHz/1.2V VCM data
|
||||
with the UI's existing display scale. */
|
||||
db_ = db + 30;
|
||||
#else
|
||||
db_ = db;
|
||||
#endif
|
||||
}
|
||||
} /* namespace ui */
|
||||
|
||||
@@ -64,18 +64,11 @@ class RSSI : public Widget {
|
||||
void set_db(int16_t db);
|
||||
|
||||
private:
|
||||
#ifdef PRALINE
|
||||
// Changed from int8_t to uint8_t:
|
||||
uint8_t min_ = 0;
|
||||
uint8_t avg_ = 0;
|
||||
uint8_t max_ = 0;
|
||||
uint8_t peak_ = 0;
|
||||
#else
|
||||
int8_t min_ = 0;
|
||||
int8_t avg_ = 0;
|
||||
int8_t max_ = 0;
|
||||
int8_t peak_ = 0;
|
||||
#endif
|
||||
|
||||
size_t peak_duration_ = 0;
|
||||
int16_t db_ = 0;
|
||||
bool instant_exec_{false};
|
||||
|
||||
Reference in New Issue
Block a user