mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Make better use of range_t methods.
This commit is contained in:
parent
ca3b1a2c5a
commit
7519b83379
@ -196,18 +196,16 @@ void MAX2837::set_lpf_rf_bandwidth(const uint32_t bandwidth_minimum) {
|
||||
|
||||
bool MAX2837::set_frequency(const rf::Frequency lo_frequency) {
|
||||
/* TODO: This is a sad implementation. Refactor. */
|
||||
if( lo_frequency < lo::band[0].min ) {
|
||||
return false;
|
||||
} else if( lo_frequency < lo::band[0].max ) {
|
||||
if( lo::band[0].contains(lo_frequency) ) {
|
||||
_map.r.syn_int_div.LOGEN_BSW = 0b00; /* 2300 - 2399.99MHz */
|
||||
_map.r.rxrf_1.LNAband = 0; /* 2.3 - 2.5GHz */
|
||||
} else if( lo_frequency < lo::band[1].max ) {
|
||||
} else if( lo::band[1].contains(lo_frequency) ) {
|
||||
_map.r.syn_int_div.LOGEN_BSW = 0b01; /* 2400 - 2499.99MHz */
|
||||
_map.r.rxrf_1.LNAband = 0; /* 2.3 - 2.5GHz */
|
||||
} else if( lo_frequency < lo::band[2].max ) {
|
||||
} else if( lo::band[2].contains(lo_frequency) ) {
|
||||
_map.r.syn_int_div.LOGEN_BSW = 0b10; /* 2500 - 2599.99MHz */
|
||||
_map.r.rxrf_1.LNAband = 1; /* 2.5 - 2.7GHz */
|
||||
} else if( lo_frequency < lo::band[3].max ) {
|
||||
} else if( lo::band[3].contains(lo_frequency) ) {
|
||||
_map.r.syn_int_div.LOGEN_BSW = 0b11; /* 2600 - 2700Hz */
|
||||
_map.r.rxrf_1.LNAband = 1; /* 2.5 - 2.7GHz */
|
||||
} else {
|
||||
|
@ -50,10 +50,10 @@ enum class Mode {
|
||||
namespace lo {
|
||||
|
||||
constexpr std::array<rf::FrequencyRange, 4> band { {
|
||||
{ .min = 2300000000, .max = 2400000000, },
|
||||
{ .min = 2400000000, .max = 2500000000, },
|
||||
{ .min = 2500000000, .max = 2600000000, },
|
||||
{ .min = 2600000000, .max = 2700000000, },
|
||||
{ 2300000000, 2400000000 },
|
||||
{ 2400000000, 2500000000 },
|
||||
{ 2500000000, 2600000000 },
|
||||
{ 2600000000, 2700000000 },
|
||||
} };
|
||||
|
||||
} /* namespace lo */
|
||||
@ -67,8 +67,8 @@ constexpr int8_t gain_db_max = 40;
|
||||
constexpr int8_t gain_db_step = 8;
|
||||
|
||||
constexpr std::array<rf::FrequencyRange, 2> band { {
|
||||
{ .min = 2300000000, .max = 2500000000, },
|
||||
{ .min = 2500000000, .max = 2700000000, },
|
||||
{ 2300000000, 2500000000 },
|
||||
{ 2500000000, 2700000000 },
|
||||
} };
|
||||
|
||||
} /* namespace lna */
|
||||
|
@ -22,29 +22,14 @@
|
||||
#ifndef __RF_PATH_H__
|
||||
#define __RF_PATH_H__
|
||||
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace rf {
|
||||
|
||||
using Frequency = int64_t;
|
||||
|
||||
struct FrequencyRange {
|
||||
Frequency min;
|
||||
Frequency max;
|
||||
/* TODO: static_assert low < high? */
|
||||
|
||||
bool below_range(const Frequency f) const {
|
||||
return f < min;
|
||||
}
|
||||
|
||||
bool contains(const Frequency f) const {
|
||||
return (f >= min) && (f < max);
|
||||
}
|
||||
|
||||
bool out_of_range(const Frequency f) const {
|
||||
return !contains(f);
|
||||
}
|
||||
};
|
||||
using FrequencyRange = range_t<Frequency>;
|
||||
|
||||
enum class Direction {
|
||||
/* Zero-based, used as index into table */
|
||||
@ -54,20 +39,9 @@ enum class Direction {
|
||||
|
||||
namespace path {
|
||||
|
||||
constexpr FrequencyRange band_low {
|
||||
.min = 0,
|
||||
.max = 2150000000,
|
||||
};
|
||||
|
||||
constexpr FrequencyRange band_high {
|
||||
.min = 2750000000,
|
||||
.max = 7250000000,
|
||||
};
|
||||
|
||||
constexpr FrequencyRange band_mid {
|
||||
.min = band_low.max,
|
||||
.max = band_high.min,
|
||||
};
|
||||
constexpr FrequencyRange band_low { 0, 2150000000 };
|
||||
constexpr FrequencyRange band_high { 2750000000, 7250000000 };
|
||||
constexpr FrequencyRange band_mid { band_low.maximum, band_high.minimum };
|
||||
|
||||
enum class Band {
|
||||
/* Zero-based, used as index into frequency_bands table */
|
||||
@ -94,10 +68,7 @@ private:
|
||||
|
||||
} /* path */
|
||||
|
||||
constexpr FrequencyRange tuning_range {
|
||||
.min = path::band_low.min,
|
||||
.max = path::band_high.max,
|
||||
};
|
||||
constexpr FrequencyRange tuning_range { path::band_low.minimum, path::band_high.maximum };
|
||||
|
||||
} /* rf */
|
||||
|
||||
|
@ -51,10 +51,7 @@ constexpr auto reference_frequency = rffc5072_reference_f;
|
||||
|
||||
namespace vco {
|
||||
|
||||
constexpr rf::FrequencyRange range {
|
||||
.min = 2700000000U,
|
||||
.max = 5400000000U,
|
||||
};
|
||||
constexpr rf::FrequencyRange range { 2700000000, 5400000000 };
|
||||
|
||||
} /* namespace vco */
|
||||
|
||||
@ -66,10 +63,7 @@ constexpr size_t divider_log2_max = 5;
|
||||
constexpr size_t divider_min = 1U << divider_log2_min;
|
||||
constexpr size_t divider_max = 1U << divider_log2_max;
|
||||
|
||||
constexpr rf::FrequencyRange range {
|
||||
.min = vco::range.min / divider_max,
|
||||
.max = vco::range.max / divider_min,
|
||||
};
|
||||
constexpr rf::FrequencyRange range { vco::range.minimum / divider_max, vco::range.maximum / divider_min };
|
||||
|
||||
size_t divider_log2(const rf::Frequency lo_frequency) {
|
||||
/* TODO: Error */
|
||||
|
@ -83,13 +83,11 @@ Config high_band(const rf::Frequency target_frequency) {
|
||||
|
||||
Config create(const rf::Frequency target_frequency) {
|
||||
/* TODO: This is some lame code. */
|
||||
if( target_frequency < rf::path::band_low.min ) {
|
||||
return { };
|
||||
} else if( target_frequency < rf::path::band_low.max ) {
|
||||
if( rf::path::band_low.contains(target_frequency) ) {
|
||||
return low_band(target_frequency);
|
||||
} else if( target_frequency < rf::path::band_mid.max ) {
|
||||
} else if( rf::path::band_mid.contains(target_frequency) ) {
|
||||
return mid_band(target_frequency);
|
||||
} else if( target_frequency < rf::path::band_high.max ) {
|
||||
} else if( rf::path::band_high.contains(target_frequency) ) {
|
||||
return high_band(target_frequency);
|
||||
} else {
|
||||
return { };
|
||||
|
@ -118,13 +118,7 @@ void FrequencyField::on_focus() {
|
||||
}
|
||||
|
||||
rf::Frequency FrequencyField::clamp_value(rf::Frequency value) {
|
||||
if( value > range.max ) {
|
||||
value = range.max;
|
||||
}
|
||||
if( value < range.min ) {
|
||||
value = range.min;
|
||||
}
|
||||
return value;
|
||||
return range.clip(value);
|
||||
}
|
||||
|
||||
/* FrequencyKeypadView ***************************************************/
|
||||
|
@ -31,8 +31,6 @@
|
||||
namespace portapack {
|
||||
namespace persistent_memory {
|
||||
|
||||
using tuned_frequency_range_t = range_t<rf::Frequency>;
|
||||
constexpr tuned_frequency_range_t tuned_frequency_range { rf::tuning_range.min, rf::tuning_range.max };
|
||||
constexpr rf::Frequency tuned_frequency_reset_value { 858750000 };
|
||||
|
||||
using ppb_range_t = range_t<ppb_t>;
|
||||
@ -50,12 +48,12 @@ static_assert(sizeof(data_t) <= 0x100, "Persistent memory structure too large fo
|
||||
static data_t* const data = reinterpret_cast<data_t*>(LPC_BACKUP_REG_BASE);
|
||||
|
||||
rf::Frequency tuned_frequency() {
|
||||
tuned_frequency_range.reset_if_outside(data->tuned_frequency, tuned_frequency_reset_value);
|
||||
rf::tuning_range.reset_if_outside(data->tuned_frequency, tuned_frequency_reset_value);
|
||||
return data->tuned_frequency;
|
||||
}
|
||||
|
||||
void set_tuned_frequency(const rf::Frequency new_value) {
|
||||
data->tuned_frequency = tuned_frequency_range.clip(new_value);
|
||||
data->tuned_frequency = rf::tuning_range.clip(new_value);
|
||||
}
|
||||
|
||||
ppb_t correction_ppb() {
|
||||
|
@ -86,6 +86,20 @@ struct range_t {
|
||||
value = reset_value;
|
||||
}
|
||||
}
|
||||
|
||||
bool below_range(const T& value) const {
|
||||
return value < minimum;
|
||||
}
|
||||
|
||||
bool contains(const T& value) const {
|
||||
// TODO: Subtle gotcha here! Range test doesn't include maximum!
|
||||
return (value >= minimum) && (value < maximum);
|
||||
}
|
||||
|
||||
bool out_of_range(const T& value) const {
|
||||
// TODO: Subtle gotcha here! Range test in contains() doesn't include maximum!
|
||||
return !contains(value);
|
||||
}
|
||||
};
|
||||
|
||||
namespace std {
|
||||
|
Loading…
Reference in New Issue
Block a user