This commit is contained in:
furrtek 2016-01-31 09:34:24 +01:00
parent 29ec87a9ad
commit 44638e504b
166 changed files with 8700 additions and 3967 deletions

View file

@ -23,32 +23,14 @@
#include "hal.h"
#include "utility.hpp"
#include <algorithm>
#include <utility>
namespace portapack {
namespace persistent_memory {
/* TODO: This is widely applicable. Factor this to somewhere useful. */
template<class T>
struct range_t {
const T minimum;
const T maximum;
const T& clip(const T& value) const {
return std::max(std::min(value, maximum), minimum);
}
void reset_if_outside(T& value, const T& reset_value) const {
if( (value < minimum ) ||
(value > maximum ) ) {
value = reset_value;
}
}
};
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>;
@ -93,12 +75,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() {