mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-09-14 18:43:01 +00:00
Compare commits
72 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dd8538b8bf | |||
| 03c9b4aba7 | |||
| 56526a5710 | |||
| 2d9fe6cf8a | |||
| 4ec444688f | |||
| 2e4a86d7ec | |||
| 92b622deac | |||
| 2457ba016f | |||
| 4a6c76cc47 | |||
| ce23c7d882 | |||
| 7eba8fd49b | |||
| bfdf7660b6 | |||
| b83f43793c | |||
| ed1c2e1c03 | |||
| caba16a549 | |||
| 5318542021 | |||
| 93f966bdcd | |||
| 7b5f138dfb | |||
| 149cd755ca | |||
| 63d0201b71 | |||
| cf19408784 | |||
| f882de5eff | |||
| 49bda24079 | |||
| a1705dd9d4 | |||
| 155543e5d5 | |||
| 62b9fa2b6a | |||
| f5427d7fdc | |||
| b8c1e8c4a6 | |||
| 7a0d02cb83 | |||
| c23f03c074 | |||
| cfdd12d8a6 | |||
| d1ab93f644 | |||
| f7df4f3575 | |||
| ad4cfe5a44 | |||
| 8db44d1a92 | |||
| 37cfcb0d5c | |||
| 6a61b9528e | |||
| ab58f368b5 | |||
| 023ee2a6f5 | |||
| b6011a777b | |||
| 37494500b2 | |||
| f42812c6b4 | |||
| a7acb37a56 | |||
| 69df16d6e2 | |||
| e2620f1a33 | |||
| f6a4cc26ee | |||
| 3d248647c9 | |||
| 3c13161273 | |||
| f0b4914186 | |||
| 037fc098ef | |||
| 988404df9c | |||
| f5deae56cf | |||
| e526061d13 | |||
| daf63de55f | |||
| 778111d466 | |||
| 00b75eacda | |||
| ef151e243b | |||
| 567fee1d98 | |||
| b549d3a4f1 | |||
| 86203f090f | |||
| 19fed78b7f | |||
| c0532aeafa | |||
| c8774e82d9 | |||
| 62ee23a314 | |||
| 70551ef155 | |||
| 91074e5b4e | |||
| 5f95cec5f4 | |||
| 66ba6442b1 | |||
| 7e20cea6d7 | |||
| 65217856c0 | |||
| 5117538b49 | |||
| 362c208078 |
@@ -0,0 +1 @@
|
||||
build
|
||||
@@ -53,4 +53,3 @@ addons:
|
||||
- sed
|
||||
- cmake
|
||||
- dfu-util
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
version: '3.9'
|
||||
|
||||
services:
|
||||
portapack-mayhem-dev:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: dockerfile-nogit-alpine
|
||||
volumes:
|
||||
- ".:/havoc"
|
||||
@@ -0,0 +1,9 @@
|
||||
version: '3.9'
|
||||
|
||||
services:
|
||||
portapack-mayhem-dev:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: dockerfile-alpine
|
||||
volumes:
|
||||
- "./bin:/havocbin"
|
||||
+7
-7
@@ -24,9 +24,9 @@ RUN curl https://bootstrap.pypa.io/pip/3.4/get-pip.py -o get-pip.py && \
|
||||
#Fetch additional dependencies from Python 2.x pip
|
||||
RUN pip install pyyaml
|
||||
RUN rm -rf /usr/bin/python && \
|
||||
rm -rf /usr/bin/pip && \
|
||||
ln -s /usr/bin/python3 /usr/bin/python && \
|
||||
ln -s /usr/bin/pip3 /usr/bin/pip
|
||||
rm -rf /usr/bin/pip && \
|
||||
ln -s /usr/bin/python3 /usr/bin/python && \
|
||||
ln -s /usr/bin/pip3 /usr/bin/pip
|
||||
|
||||
ENV LANG C.UTF-8
|
||||
ENV LC_ALL C.UTF-8
|
||||
@@ -37,12 +37,12 @@ RUN mkdir /opt/build && cd /opt/build && \
|
||||
wget -O gcc-arm-none-eabi $ARMBINURL && \
|
||||
mkdir armbin && \
|
||||
tar --strip=1 -xjvf gcc-arm-none-eabi -C armbin
|
||||
|
||||
|
||||
#Set environment variable so compiler knows where the toolchain lives
|
||||
ENV PATH=$PATH:/opt/build/armbin/bin
|
||||
|
||||
CMD cd /havocsrc && \
|
||||
mkdir build && cd build && \
|
||||
cmake .. && make firmware && \
|
||||
cp /portapack-havoc/firmware/portapack-h1-havoc.bin /havocbin
|
||||
mkdir build && cd build && \
|
||||
cmake .. && make firmware && \
|
||||
cp /portapack-havoc/firmware/portapack-h1-havoc.bin /havocbin
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# Download base image.
|
||||
FROM alpine:edge
|
||||
|
||||
# Download ARM toolkit.
|
||||
RUN apk add --no-cache gcc-arm-none-eabi gcc
|
||||
|
||||
# Create volume /havocbin for compiled firmware binaries
|
||||
VOLUME /havocbin
|
||||
|
||||
# Copy build context (repository root) to /havocsrc
|
||||
COPY ./ /havocsrc
|
||||
|
||||
# Fetch dependencies from APK
|
||||
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
|
||||
RUN apk update -U
|
||||
RUN apk add --no-cache git tar wget cmake curl bzip2 make
|
||||
RUN apk add --no-cache dfu-util ccache icu-data-full
|
||||
RUN apk add --no-cache python3 py3-pip py3-yaml
|
||||
RUN apk add --no-cache py3-pyyaml-env-tag
|
||||
RUN apk add --no-cache g++ gcc clang clang-static clang-dev llvm-dev llvm-static
|
||||
|
||||
ENV LANG C.UTF-8
|
||||
ENV LC_ALL C.UTF-8
|
||||
|
||||
CMD cd /havocsrc && \
|
||||
mkdir build && cd build && \
|
||||
cmake .. && make firmware && \
|
||||
cp /portapack-havoc/firmware/portapack-h1-havoc.bin /havocbin
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ RUN curl https://bootstrap.pypa.io/pip/3.4/get-pip.py -o get-pip.py && \
|
||||
#Fetch additional dependencies from Python 3.x pip
|
||||
RUN pip install pyyaml
|
||||
RUN ln -s /usr/bin/python3 /usr/bin/python && \
|
||||
ln -s /usr/bin/pip3 /usr/bin/pip
|
||||
ln -s /usr/bin/pip3 /usr/bin/pip
|
||||
|
||||
ENV LANG C.UTF-8
|
||||
ENV LC_ALL C.UTF-8
|
||||
@@ -38,4 +38,4 @@ RUN mkdir ~/bin && cd ~/bin && \
|
||||
for tool in gcc g++ cpp c++;do ln -s $(which ccache) arm-none-eabi-$tool;done
|
||||
|
||||
CMD cd .. && cd build && \
|
||||
cmake .. && make firmware
|
||||
cmake .. && make firmware
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
FROM alpine:edge
|
||||
|
||||
# Download ARM toolkit.
|
||||
RUN apk add --no-cache gcc-arm-none-eabi gcc
|
||||
|
||||
# Create volume /havoc/bin for compiled firmware binaries
|
||||
VOLUME /havoc
|
||||
WORKDIR /havoc/firmware
|
||||
|
||||
# Fetch dependencies from APK
|
||||
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
|
||||
RUN apk update -U
|
||||
RUN apk add --no-cache git tar wget cmake curl bzip2 make
|
||||
RUN apk add --no-cache dfu-util ccache icu-data-full
|
||||
RUN apk add --no-cache python3 py3-pip py3-yaml
|
||||
RUN apk add --no-cache py3-pyyaml-env-tag
|
||||
RUN apk add --no-cache g++ gcc clang clang-static clang-dev llvm-dev llvm-static
|
||||
|
||||
ENV LANG C.UTF-8
|
||||
ENV LC_ALL C.UTF-8
|
||||
|
||||
# Configure CCACHE
|
||||
RUN mkdir ~/bin && cd ~/bin && \
|
||||
for tool in gcc g++ cpp c++;do ln -s $(which ccache) arm-none-eabi-$tool;done
|
||||
|
||||
CMD cd .. && cd build && \
|
||||
cmake .. && make firmware
|
||||
@@ -103,6 +103,7 @@ set(CSRC
|
||||
${PLATFORMSRC}
|
||||
${BOARDSRC}
|
||||
${FATFSSRC}
|
||||
firmware_info.c
|
||||
)
|
||||
|
||||
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
|
||||
@@ -124,7 +125,7 @@ set(CPPSRC
|
||||
${COMMON}/cpld_max5.cpp
|
||||
${COMMON}/cpld_update.cpp
|
||||
${COMMON}/cpld_xilinx.cpp
|
||||
${COMMON}/debug.cpp
|
||||
debug.cpp
|
||||
${COMMON}/ert_packet.cpp
|
||||
${COMMON}/event.cpp
|
||||
${COMMON}/gcc.cpp
|
||||
@@ -193,6 +194,7 @@ set(CPPSRC
|
||||
hw/debounce.cpp
|
||||
hw/encoder.cpp
|
||||
hw/max2837.cpp
|
||||
hw/max2839.cpp
|
||||
hw/max5864.cpp
|
||||
hw/rffc507x.cpp
|
||||
hw/rffc507x_spi.cpp
|
||||
@@ -272,6 +274,7 @@ set(CPPSRC
|
||||
apps/soundboard_app.cpp
|
||||
apps/ui_recon.cpp
|
||||
apps/ui_recon_settings.cpp
|
||||
apps/ui_level.cpp
|
||||
apps/tpms_app.cpp
|
||||
apps/tpms_app.cpp
|
||||
protocols/aprs.cpp
|
||||
|
||||
@@ -166,7 +166,7 @@ public:
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "AIS Boats RX"; };
|
||||
std::string title() const override { return "AIS RX"; };
|
||||
|
||||
private:
|
||||
static constexpr uint32_t initial_target_frequency = 162025000;
|
||||
|
||||
@@ -129,24 +129,26 @@ AnalogAudioView::AnalogAudioView(
|
||||
&waterfall
|
||||
});
|
||||
|
||||
// Set on_change before initialising the field
|
||||
field_frequency.on_change = [this](rf::Frequency f) {
|
||||
this->on_tuning_frequency_changed(f);
|
||||
};
|
||||
|
||||
// load app settings
|
||||
auto rc = settings.load("rx_audio", &app_settings);
|
||||
if(rc == SETTINGS_OK) {
|
||||
field_lna.set_value(app_settings.lna);
|
||||
field_vga.set_value(app_settings.vga);
|
||||
receiver_model.set_rf_amp(app_settings.rx_amp);
|
||||
field_frequency.set_value(app_settings.rx_frequency);
|
||||
// field_frequency.set_value(app_settings.rx_frequency);
|
||||
receiver_model.set_configuration_without_init(static_cast<ReceiverModel::Mode>(app_settings.modulation), app_settings.step, app_settings.am_config_index, app_settings.nbfm_config_index, app_settings.wfm_config_index, app_settings.squelch);
|
||||
}
|
||||
else field_frequency.set_value(receiver_model.tuning_frequency());
|
||||
field_frequency.set_value(receiver_model.tuning_frequency());
|
||||
|
||||
//Filename Datetime and Frequency
|
||||
record_view.set_filename_date_frequency(true);
|
||||
|
||||
field_frequency.set_step(receiver_model.frequency_step());
|
||||
field_frequency.on_change = [this](rf::Frequency f) {
|
||||
this->on_tuning_frequency_changed(f);
|
||||
};
|
||||
field_frequency.on_edit = [this, &nav]() {
|
||||
// TODO: Provide separate modal method/scheme?
|
||||
auto new_view = nav.push<FrequencyKeypadView>(receiver_model.tuning_frequency());
|
||||
|
||||
@@ -57,6 +57,10 @@ AnalogTvView::AnalogTvView(
|
||||
&tv
|
||||
});
|
||||
|
||||
// Set on_change before initialising the field
|
||||
field_frequency.on_change = [this](rf::Frequency f) {
|
||||
this->on_tuning_frequency_changed(f);
|
||||
};
|
||||
|
||||
// load app settings
|
||||
auto rc = settings.load("rx_tv", &app_settings);
|
||||
@@ -70,9 +74,6 @@ AnalogTvView::AnalogTvView(
|
||||
|
||||
|
||||
field_frequency.set_step(receiver_model.frequency_step());
|
||||
field_frequency.on_change = [this](rf::Frequency f) {
|
||||
this->on_tuning_frequency_changed(f);
|
||||
};
|
||||
field_frequency.on_edit = [this, &nav]() {
|
||||
// TODO: Provide separate modal method/scheme?
|
||||
auto new_view = nav.push<FrequencyKeypadView>(receiver_model.tuning_frequency());
|
||||
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "Analog TV RX"; };
|
||||
std::string title() const override { return "AnalogTV RX"; };
|
||||
|
||||
private:
|
||||
static constexpr ui::Dim header_height = 3 * 16;
|
||||
|
||||
@@ -125,7 +125,7 @@ public:
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "ERT Meter RX"; };
|
||||
std::string title() const override { return "ERT RX"; };
|
||||
|
||||
private:
|
||||
ERTRecentEntries recent { };
|
||||
|
||||
@@ -77,6 +77,11 @@ POCSAGAppView::POCSAGAppView(NavigationView& nav) {
|
||||
&console
|
||||
});
|
||||
|
||||
// Set on_change before initialising the field
|
||||
field_frequency.on_change = [this](rf::Frequency f) {
|
||||
update_freq(f);
|
||||
};
|
||||
|
||||
// load app settings
|
||||
auto rc = settings.load("rx_pocsag", &app_settings);
|
||||
if(rc == SETTINGS_OK) {
|
||||
@@ -94,9 +99,6 @@ POCSAGAppView::POCSAGAppView(NavigationView& nav) {
|
||||
receiver_model.enable();
|
||||
|
||||
field_frequency.set_step(receiver_model.frequency_step());
|
||||
field_frequency.on_change = [this](rf::Frequency f) {
|
||||
update_freq(f);
|
||||
};
|
||||
field_frequency.on_edit = [this, &nav]() {
|
||||
// TODO: Provide separate modal method/scheme?
|
||||
auto new_view = nav.push<FrequencyKeypadView>(receiver_model.tuning_frequency());
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "Soundboard TX"; };
|
||||
std::string title() const override { return "Soundbrd TX"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
@@ -102,8 +102,8 @@ public:
|
||||
void paint(Painter&) override { };
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "TPMS Cars RX"; };
|
||||
|
||||
std::string title() const override { return "TPMS RX"; };
|
||||
|
||||
private:
|
||||
static constexpr uint32_t initial_target_frequency = 315000000;
|
||||
|
||||
@@ -46,10 +46,10 @@ void RecentEntriesTable<AircraftRecentEntries>::draw(
|
||||
auto entry_age = entry.age;
|
||||
|
||||
// Color decay for flights not being updated anymore
|
||||
if (entry_age < ADSB_DECAY_A) {
|
||||
if (entry_age < ADSB_CURRENT) {
|
||||
aged_color = 0x10;
|
||||
target_color = Color::green();
|
||||
} else if (entry_age < ADSB_DECAY_B) {
|
||||
} else if (entry_age < ADSB_RECENT) {
|
||||
aged_color = 0x07;
|
||||
target_color = Color::light_grey();
|
||||
} else {
|
||||
@@ -59,21 +59,13 @@ void RecentEntriesTable<AircraftRecentEntries>::draw(
|
||||
|
||||
std::string entry_string = "\x1B";
|
||||
entry_string += aged_color;
|
||||
#if false
|
||||
entry_string += to_string_hex(entry.ICAO_address, 6) + " " +
|
||||
entry.callsign + " " +
|
||||
(entry.hits <= 999 ? to_string_dec_uint(entry.hits, 4) : "999+") + " " +
|
||||
entry.time_string;
|
||||
#else
|
||||
// SBT
|
||||
entry_string +=
|
||||
(entry.callsign[0]!=' ' ? entry.callsign + " " : to_string_hex(entry.ICAO_address, 6) + " ") +
|
||||
to_string_dec_uint((unsigned int)((entry.pos.altitude+50)/100),4) +
|
||||
(entry.callsign[0]!=' ' ? entry.callsign + " " : entry.icaoStr + " ") +
|
||||
to_string_dec_uint((unsigned int)(entry.pos.altitude/100),4) +
|
||||
to_string_dec_uint((unsigned int)entry.velo.speed,4) +
|
||||
to_string_dec_uint((unsigned int)(entry.amp>>9),4) + " " +
|
||||
(entry.hits <= 999 ? to_string_dec_uint(entry.hits, 3) + " " : "1k+ ") +
|
||||
to_string_dec_uint(entry.age, 4);
|
||||
#endif
|
||||
|
||||
painter.draw_string(
|
||||
target_rect.location(),
|
||||
@@ -124,8 +116,6 @@ ADSBRxAircraftDetailsView::ADSBRxAircraftDetailsView(
|
||||
});
|
||||
|
||||
std::unique_ptr<ADSBLogger> logger { };
|
||||
//update(entry_copy);
|
||||
|
||||
|
||||
icao_code = to_string_hex(entry_copy.ICAO_address, 6);
|
||||
text_icao_address.set(to_string_hex(entry_copy.ICAO_address, 6));
|
||||
@@ -225,7 +215,10 @@ void ADSBRxDetailsView::update(const AircraftRecentEntry& entry) {
|
||||
text_frame_pos_odd.set(to_string_hex_array(entry_copy.frame_pos_odd.get_raw_data(), 14));
|
||||
|
||||
if (send_updates)
|
||||
{
|
||||
geomap_view->update_tag(trimr(entry.callsign[0]!=' ' ? entry.callsign : to_string_hex(entry.ICAO_address, 6)));
|
||||
geomap_view->update_position(entry_copy.pos.latitude, entry_copy.pos.longitude, entry_copy.velo.heading, entry_copy.pos.altitude);
|
||||
}
|
||||
}
|
||||
|
||||
ADSBRxDetailsView::~ADSBRxDetailsView() {
|
||||
@@ -277,19 +270,14 @@ ADSBRxDetailsView::ADSBRxDetailsView(
|
||||
text_icao_address.set(to_string_hex(entry_copy.ICAO_address, 6));
|
||||
|
||||
button_aircraft_details.on_select = [this, &nav](Button&) {
|
||||
//detailed_entry_key = entry.key();
|
||||
aircraft_details_view = nav.push<ADSBRxAircraftDetailsView>(
|
||||
entry_copy,
|
||||
[this]() {
|
||||
send_updates = false;
|
||||
});
|
||||
aircraft_details_view = nav.push<ADSBRxAircraftDetailsView>(entry_copy, [this]() { send_updates = false;});
|
||||
send_updates = false;
|
||||
};
|
||||
|
||||
button_see_map.on_select = [this, &nav](Button&) {
|
||||
if (!send_updates) { // Prevent recursively launching the map
|
||||
geomap_view = nav.push<GeoMapView>(
|
||||
entry_copy.callsign,
|
||||
trimr(entry_copy.callsign[0]!=' ' ? entry_copy.callsign : entry_copy.icaoStr),
|
||||
entry_copy.pos.altitude,
|
||||
GeoPos::alt_unit::FEET,
|
||||
entry_copy.pos.latitude,
|
||||
@@ -309,6 +297,7 @@ void ADSBRxView::focus() {
|
||||
}
|
||||
|
||||
ADSBRxView::~ADSBRxView() {
|
||||
receiver_model.set_tuning_frequency(prevFreq); // Restore previous frequency on exit
|
||||
|
||||
// save app settings
|
||||
settings.save("rx_adsb", &app_settings);
|
||||
@@ -326,8 +315,6 @@ AircraftRecentEntry ADSBRxView::find_or_create_entry(uint32_t ICAO_address) {
|
||||
// If not found
|
||||
if (it == std::end(recent)){
|
||||
recent.emplace_front(ICAO_address); // Add it
|
||||
truncate_entries(recent); // Truncate the list
|
||||
sort_entries_by_state();
|
||||
it = find(recent, ICAO_address); // Find it again
|
||||
}
|
||||
return *it;
|
||||
@@ -342,6 +329,21 @@ void ADSBRxView::replace_entry(AircraftRecentEntry & entry)
|
||||
entry);
|
||||
}
|
||||
|
||||
void ADSBRxView::remove_old_entries()
|
||||
{
|
||||
auto it = recent.rbegin();
|
||||
auto end = recent.rend();
|
||||
while (it != end)
|
||||
{
|
||||
if (it->age_state>=4) {
|
||||
std::advance(it, 1);
|
||||
recent.erase( it.base() );
|
||||
} else {
|
||||
break; // stop looking because the list is sorted
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ADSBRxView::sort_entries_by_state()
|
||||
{
|
||||
// Sorting List pn age_state using lambda function as comparator
|
||||
@@ -349,8 +351,8 @@ void ADSBRxView::sort_entries_by_state()
|
||||
}
|
||||
|
||||
void ADSBRxView::on_frame(const ADSBFrameMessage * message) {
|
||||
logger = std::make_unique<ADSBLogger>();
|
||||
rtc::RTC datetime;
|
||||
std::string str_timestamp;
|
||||
std::string callsign;
|
||||
std::string str_info;
|
||||
std::string logentry;
|
||||
@@ -365,16 +367,16 @@ void ADSBRxView::on_frame(const ADSBFrameMessage * message) {
|
||||
entry.reset_age();
|
||||
if (entry.hits==0)
|
||||
{
|
||||
entry.amp = message->amp;
|
||||
entry.amp = message->amp; // Store amplitude on first hit
|
||||
} else {
|
||||
entry.amp = ((entry.amp*15)+message->amp)>>4;
|
||||
entry.amp = ((entry.amp*15)+message->amp)>>4; // Update smoothed amplitude on updates
|
||||
}
|
||||
str_timestamp = to_string_datetime(datetime, HMS);
|
||||
entry.set_time_string(str_timestamp);
|
||||
|
||||
entry.inc_hit();
|
||||
logentry += to_string_hex_array(frame.get_raw_data(), 14) + " ";
|
||||
logentry += "ICAO:" + to_string_hex(ICAO_address, 6) + " ";
|
||||
if (logger) {
|
||||
logentry += to_string_hex_array(frame.get_raw_data(), 14) + " ";
|
||||
logentry += "ICAO:" + entry.icaoStr + " ";
|
||||
}
|
||||
|
||||
if (frame.get_DF() == DF_ADSB) {
|
||||
uint8_t msg_type = frame.get_msg_type();
|
||||
@@ -385,7 +387,9 @@ void ADSBRxView::on_frame(const ADSBFrameMessage * message) {
|
||||
if ((msg_type >= AIRCRAFT_ID_L) && (msg_type <= AIRCRAFT_ID_H)) {
|
||||
callsign = decode_frame_id(frame);
|
||||
entry.set_callsign(callsign);
|
||||
logentry+=callsign+" ";
|
||||
if (logger) {
|
||||
logentry+=callsign+" ";
|
||||
}
|
||||
}
|
||||
// 9:
|
||||
// 18: { // Extended squitter/non-transponder
|
||||
@@ -400,30 +404,33 @@ void ADSBRxView::on_frame(const ADSBFrameMessage * message) {
|
||||
" Lat:" + to_string_decimal(entry.pos.latitude, 2) +
|
||||
" Lon:" + to_string_decimal(entry.pos.longitude, 2);
|
||||
|
||||
// printing the coordinates in the log file with more
|
||||
// resolution, as we are not constrained by screen
|
||||
// real estate there:
|
||||
|
||||
std::string log_info = "Alt:" + to_string_dec_int(entry.pos.altitude) +
|
||||
" Lat:" + to_string_decimal(entry.pos.latitude, 7) +
|
||||
" Lon:" + to_string_decimal(entry.pos.longitude, 7);
|
||||
|
||||
entry.set_info_string(str_info);
|
||||
logentry+=log_info + " ";
|
||||
|
||||
if (logger) {
|
||||
// printing the coordinates in the log file with more
|
||||
// resolution, as we are not constrained by screen
|
||||
// real estate there:
|
||||
|
||||
std::string log_info = "Alt:" + to_string_dec_int(entry.pos.altitude) +
|
||||
" Lat:" + to_string_decimal(entry.pos.latitude, 7) +
|
||||
" Lon:" + to_string_decimal(entry.pos.longitude, 7);
|
||||
logentry+=log_info + " ";
|
||||
}
|
||||
|
||||
}
|
||||
} else if(msg_type == AIRBORNE_VEL && msg_sub >= VEL_GND_SUBSONIC && msg_sub <= VEL_AIR_SUPERSONIC){
|
||||
entry.set_frame_velo(frame);
|
||||
logentry += "Type:" + to_string_dec_uint(msg_sub) +
|
||||
" Hdg:" + to_string_dec_uint(entry.velo.heading) +
|
||||
" Spd: "+ to_string_dec_int(entry.velo.speed);
|
||||
if (logger) {
|
||||
logentry += "Type:" + to_string_dec_uint(msg_sub) +
|
||||
" Hdg:" + to_string_dec_uint(entry.velo.heading) +
|
||||
" Spd: "+ to_string_dec_int(entry.velo.speed);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
replace_entry(entry);
|
||||
} // frame.get_DF() == DF_ADSB
|
||||
|
||||
replace_entry(entry);
|
||||
|
||||
logger = std::make_unique<ADSBLogger>();
|
||||
if (logger) {
|
||||
logger->append(u"adsb.txt");
|
||||
// will log each frame in format:
|
||||
@@ -433,20 +440,69 @@ void ADSBRxView::on_frame(const ADSBFrameMessage * message) {
|
||||
}
|
||||
}
|
||||
|
||||
void ADSBRxView::on_tick_second() {
|
||||
// Decay and refresh if needed
|
||||
for (auto& entry : recent) {
|
||||
entry.inc_age();
|
||||
|
||||
if (details_view) {
|
||||
if (send_updates && (entry.key() == detailed_entry_key)) // Check if the ICAO address match
|
||||
details_view->update(entry);
|
||||
void ADSBRxView::on_tick_second() {
|
||||
if (recent.size() <= 16){ // Not many entries update everything (16 is one screen full)
|
||||
updateDetailsAndMap(1);
|
||||
updateRecentEntries();
|
||||
} else if (updateState==0) { // Even second
|
||||
updateState = 1;
|
||||
updateDetailsAndMap(2);
|
||||
} else { // Odd second only performed when there are many entries
|
||||
updateState = 0;
|
||||
updateRecentEntries();
|
||||
}
|
||||
}
|
||||
|
||||
void ADSBRxView::updateDetailsAndMap(int ageStep) {
|
||||
ui::GeoMarker marker;
|
||||
bool storeNewMarkers = false;
|
||||
|
||||
// Sort and truncate the entries, grouped, newest group first
|
||||
sort_entries_by_state();
|
||||
truncate_entries(recent);
|
||||
remove_old_entries();
|
||||
|
||||
// Calculate if it is time to update markers
|
||||
if (send_updates && details_view && details_view->geomap_view) {
|
||||
ticksSinceMarkerRefresh += ageStep;
|
||||
if (ticksSinceMarkerRefresh >= MARKER_UPDATE_SECONDS) { // Update other aircraft every few seconds
|
||||
storeNewMarkers = true;
|
||||
ticksSinceMarkerRefresh=0;
|
||||
}
|
||||
} else {
|
||||
ticksSinceMarkerRefresh = MARKER_UPDATE_SECONDS; // Send the markers as soon as the geoview exists
|
||||
}
|
||||
|
||||
// Sort the list if it is being displayed
|
||||
if (!send_updates) {
|
||||
sort_entries_by_state();
|
||||
// Increment age, and pass updates to the details and map
|
||||
const bool otherMarkersCanBeSent = send_updates && storeNewMarkers && details_view && details_view->geomap_view; // Save retesting all of this
|
||||
MapMarkerStored markerStored = MARKER_NOT_STORED;
|
||||
if (otherMarkersCanBeSent) {details_view->geomap_view->clear_markers();}
|
||||
// Loop through all entries
|
||||
for (auto& entry : recent) {
|
||||
entry.inc_age(ageStep);
|
||||
|
||||
// Only if there is a details view
|
||||
if (send_updates && details_view) {
|
||||
if (entry.key() == detailed_entry_key) // Check if the ICAO address match
|
||||
{
|
||||
details_view->update(entry);
|
||||
}
|
||||
// Store if the view is present and the list isn't full
|
||||
else if (otherMarkersCanBeSent && (markerStored != MARKER_LIST_FULL) && entry.pos.valid && (entry.age_state<=2))
|
||||
{
|
||||
marker.lon = entry.pos.longitude;
|
||||
marker.lat = entry.pos.latitude;
|
||||
marker.angle = entry.velo.heading;
|
||||
marker.tag = trimr(entry.callsign[0]!=' ' ? entry.callsign : entry.icaoStr);
|
||||
markerStored = details_view->geomap_view->store_marker(marker);
|
||||
}
|
||||
}
|
||||
} // Loop through all entries, if only to update the age
|
||||
}
|
||||
|
||||
void ADSBRxView::updateRecentEntries() {
|
||||
// Redraw the list of aircraft
|
||||
if (!send_updates){
|
||||
recent_entries_view.set_dirty();
|
||||
}
|
||||
}
|
||||
@@ -492,7 +548,7 @@ ADSBRxView::ADSBRxView(NavigationView& nav) {
|
||||
on_tick_second();
|
||||
};
|
||||
|
||||
prevFreq = receiver_model.tuning_frequency();
|
||||
prevFreq = receiver_model.tuning_frequency(); // Store previous frequency on creation
|
||||
|
||||
baseband::set_adsb();
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "ui_receiver.hpp"
|
||||
#include "ui_geomap.hpp"
|
||||
#include "ui_font_fixed_8x16.hpp"
|
||||
#include "string_format.hpp"
|
||||
|
||||
#include "file.hpp"
|
||||
#include "database.hpp"
|
||||
@@ -39,9 +40,9 @@ using namespace adsb;
|
||||
|
||||
namespace ui {
|
||||
|
||||
#define ADSB_DECAY_A 10 // In seconds
|
||||
#define ADSB_DECAY_B 30
|
||||
#define ADSB_DECAY_C 60 // Can be used for removing old entries, RecentEntries already caps to 64
|
||||
#define ADSB_CURRENT 10 // Seconds
|
||||
#define ADSB_RECENT 30 // Seconds
|
||||
#define ADSB_REMOVE 300 // Used for removing old entries
|
||||
|
||||
#define AIRCRAFT_ID_L 1 // aircraft ID message type (lowest type id)
|
||||
#define AIRCRAFT_ID_H 4 // aircraft ID message type (highest type id)
|
||||
@@ -83,14 +84,15 @@ struct AircraftRecentEntry {
|
||||
ADSBFrame frame_pos_even { };
|
||||
ADSBFrame frame_pos_odd { };
|
||||
|
||||
std::string icaoStr {" "};
|
||||
std::string callsign { " " };
|
||||
std::string time_string { "" };
|
||||
std::string info_string { "" };
|
||||
|
||||
AircraftRecentEntry(
|
||||
const uint32_t ICAO_address
|
||||
) : ICAO_address { ICAO_address }
|
||||
{
|
||||
this->icaoStr = to_string_hex(ICAO_address, 6);
|
||||
}
|
||||
|
||||
Key key() const {
|
||||
@@ -125,23 +127,20 @@ struct AircraftRecentEntry {
|
||||
info_string = new_info_string;
|
||||
}
|
||||
|
||||
void set_time_string(std::string& new_time_string) {
|
||||
time_string = new_time_string;
|
||||
}
|
||||
|
||||
void reset_age() {
|
||||
age = 0;
|
||||
}
|
||||
|
||||
void inc_age() {
|
||||
age++;
|
||||
if (age < ADSB_DECAY_A)
|
||||
{
|
||||
void inc_age(int delta) {
|
||||
age+=delta;
|
||||
if (age < ADSB_CURRENT){
|
||||
age_state = pos.valid ? 0 : 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
age_state = (age < ADSB_DECAY_B) ? 2 : 3;
|
||||
} else if(age < ADSB_RECENT){
|
||||
age_state = 2;
|
||||
} else if(age < ADSB_REMOVE){
|
||||
age_state = 3;
|
||||
} else{
|
||||
age_state = 4;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -273,10 +272,10 @@ public:
|
||||
|
||||
std::database::AirlinesDBRecord airline_record = {};
|
||||
|
||||
GeoMapView* geomap_view { nullptr };
|
||||
private:
|
||||
AircraftRecentEntry entry_copy { 0 };
|
||||
std::function<void(void)> on_close_ { };
|
||||
GeoMapView* geomap_view { nullptr };
|
||||
ADSBRxAircraftDetailsView* aircraft_details_view { nullptr };
|
||||
bool send_updates { false };
|
||||
std::database db = { };
|
||||
@@ -364,6 +363,7 @@ public:
|
||||
std::string title() const override { return "ADS-B RX"; };
|
||||
|
||||
void replace_entry(AircraftRecentEntry & entry);
|
||||
void remove_old_entries();
|
||||
AircraftRecentEntry find_or_create_entry(uint32_t ICAO_address);
|
||||
void sort_entries_by_state();
|
||||
|
||||
@@ -372,24 +372,23 @@ private:
|
||||
std::unique_ptr<ADSBLogger> logger { };
|
||||
void on_frame(const ADSBFrameMessage * message);
|
||||
void on_tick_second();
|
||||
int updateState = { 0 };
|
||||
void updateRecentEntries();
|
||||
void updateDetailsAndMap(int ageStep);
|
||||
|
||||
#define MARKER_UPDATE_SECONDS (5)
|
||||
int ticksSinceMarkerRefresh { MARKER_UPDATE_SECONDS-1 };
|
||||
// app save settings
|
||||
std::app_settings settings { };
|
||||
std::app_settings::AppSettings app_settings { };
|
||||
|
||||
const RecentEntriesColumns columns { {
|
||||
#if false
|
||||
{ "ICAO", 6 },
|
||||
{ "Callsign", 9 },
|
||||
{ "Hits", 4 },
|
||||
{ "Time", 8 }
|
||||
#else
|
||||
{ "ICAO/Call", 9 },
|
||||
{ "Lvl", 3 },
|
||||
{ "Spd", 3 },
|
||||
{ "Amp", 3 },
|
||||
{ "Hit", 3 },
|
||||
{ "Age", 4 }
|
||||
#endif
|
||||
} };
|
||||
AircraftRecentEntries recent { };
|
||||
RecentEntriesView<RecentEntries<AircraftRecentEntry>> recent_entries_view { columns, recent };
|
||||
|
||||
@@ -207,7 +207,7 @@ void ADSBSquawkView::collect_frames(const uint32_t ICAO_address, std::vector<ADS
|
||||
ADSBFrame temp_frame;
|
||||
(void)ICAO_address;
|
||||
|
||||
encode_frame_squawk(temp_frame, field_squawk.value_dec_u32());
|
||||
encode_frame_squawk(temp_frame, field_squawk.concatenate_4_octal_u16());
|
||||
|
||||
frame_list.emplace_back(temp_frame);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "AFSK RX (beta)"; };
|
||||
std::string title() const override { return "AFSK RX"; };
|
||||
|
||||
private:
|
||||
void on_data(uint32_t value, bool is_data);
|
||||
|
||||
@@ -179,7 +179,7 @@ public:
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "BHT Xy/EP TX"; };
|
||||
std::string title() const override { return "BHT TX"; };
|
||||
|
||||
private:
|
||||
// app save settings
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "BurgerPgr TX"; };
|
||||
std::string title() const override { return "BurgerPgrTX"; };
|
||||
|
||||
private:
|
||||
enum tx_modes {
|
||||
|
||||
@@ -322,17 +322,19 @@ void DebugControlsView::focus() {
|
||||
/* DebugPeripheralsMenuView **********************************************/
|
||||
|
||||
DebugPeripheralsMenuView::DebugPeripheralsMenuView(NavigationView& nav) {
|
||||
const char * max283x = hackrf_r9 ? "MAX2839" : "MAX2837";
|
||||
const char * si5351x = hackrf_r9 ? "Si5351A" : "Si5351C";
|
||||
add_items({
|
||||
{ "RFFC5072", ui::Color::dark_cyan(), &bitmap_icon_peripherals_details, [&nav](){ nav.push<RegistersView>(
|
||||
"RFFC5072", RegistersWidgetConfig { 31, 16 },
|
||||
[](const size_t register_number) { return radio::debug::first_if::register_read(register_number); }
|
||||
); } },
|
||||
{ "MAX2837", ui::Color::dark_cyan(), &bitmap_icon_peripherals_details, [&nav](){ nav.push<RegistersView>(
|
||||
"MAX2837", RegistersWidgetConfig { 32, 10 },
|
||||
{ max283x, ui::Color::dark_cyan(), &bitmap_icon_peripherals_details, [&nav, max283x](){ nav.push<RegistersView>(
|
||||
max283x, RegistersWidgetConfig { 32, 10 },
|
||||
[](const size_t register_number) { return radio::debug::second_if::register_read(register_number); }
|
||||
); } },
|
||||
{ "Si5351C", ui::Color::dark_cyan(), &bitmap_icon_peripherals_details, [&nav](){ nav.push<RegistersView>(
|
||||
"Si5351C", RegistersWidgetConfig { 96, 8 },
|
||||
{ si5351x, ui::Color::dark_cyan(), &bitmap_icon_peripherals_details, [&nav, si5351x](){ nav.push<RegistersView>(
|
||||
si5351x, RegistersWidgetConfig { 96, 8 },
|
||||
[](const size_t register_number) { return portapack::clock_generator.read_register(register_number); }
|
||||
); } },
|
||||
{ audio::debug::codec_name(), ui::Color::dark_cyan(), &bitmap_icon_peripherals_details, [&nav](){ nav.push<RegistersView>(
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include "ui_navigation.hpp"
|
||||
|
||||
#include "rffc507x.hpp"
|
||||
#include "max2837.hpp"
|
||||
#include "portapack.hpp"
|
||||
|
||||
#include <functional>
|
||||
|
||||
@@ -156,6 +156,8 @@ void EncodersConfigView::generate_frame() {
|
||||
for (auto c : encoder_def->word_format) {
|
||||
if (c == 'S')
|
||||
frame_fragments += encoder_def->sync;
|
||||
else if (!c)
|
||||
break;
|
||||
else
|
||||
frame_fragments += encoder_def->bit_format[symfield_word.get_sym(i++)];
|
||||
}
|
||||
@@ -252,7 +254,8 @@ void EncodersView::start_tx(const bool scan) {
|
||||
scan_width = view_scan.field_length.value();
|
||||
samples_per_bit =
|
||||
((view_scan.bit_length_10.value() * 10 + view_scan.bit_length.value()) * OOK_SAMPLERATE) / 1000000UL;
|
||||
const uint32_t seq_len = ((1 << (scan_width - 1)) * 2) * ((uint64_t) samples_per_bit) / 2048UL;
|
||||
constexpr auto sym_len = 4;
|
||||
const uint32_t seq_len = ((1 << (scan_width - 1)) * 2) * ((uint64_t) samples_per_bit) * sym_len / 2048UL;
|
||||
progressbar.set_max(seq_len);
|
||||
repeat_min = seq_len;
|
||||
} else {
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
void load_directory_contents(const std::filesystem::path& dir_path);
|
||||
std::filesystem::path get_selected_path();
|
||||
|
||||
std::string title() const override { return "File manager"; };
|
||||
std::string title() const override { return "Fileman"; };
|
||||
|
||||
protected:
|
||||
NavigationView& nav_;
|
||||
|
||||
@@ -87,7 +87,7 @@ class FrequencySaveView : public FreqManBaseView {
|
||||
public:
|
||||
FrequencySaveView(NavigationView& nav, const rf::Frequency value);
|
||||
|
||||
std::string title() const override { return "Save frequency"; };
|
||||
std::string title() const override { return "Save freq."; };
|
||||
|
||||
private:
|
||||
std::string desc_buffer { };
|
||||
@@ -126,7 +126,7 @@ public:
|
||||
|
||||
FrequencyLoadView(NavigationView& nav);
|
||||
|
||||
std::string title() const override { return "Load frequency"; };
|
||||
std::string title() const override { return "Load freq."; };
|
||||
|
||||
private:
|
||||
void refresh_widgets(const bool v);
|
||||
@@ -137,7 +137,7 @@ public:
|
||||
FrequencyManagerView(NavigationView& nav);
|
||||
~FrequencyManagerView();
|
||||
|
||||
std::string title() const override { return "Freq. manager"; };
|
||||
std::string title() const override { return "Freqman"; };
|
||||
|
||||
private:
|
||||
std::string desc_buffer { };
|
||||
|
||||
@@ -0,0 +1,308 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2018 Furrtek
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "ui_level.hpp"
|
||||
#include "ui_fileman.hpp"
|
||||
#include "file.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
using portapack::memory::map::backup_ram;
|
||||
|
||||
namespace ui {
|
||||
|
||||
bool LevelView::check_sd_card()
|
||||
{
|
||||
return (sd_card::status() == sd_card::Status::Mounted) ? true : false;
|
||||
}
|
||||
|
||||
void LevelView::focus() {
|
||||
button_frequency.focus();
|
||||
}
|
||||
|
||||
LevelView::~LevelView() {
|
||||
|
||||
// save app settings
|
||||
app_settings.lna = field_lna.value();
|
||||
app_settings.vga = field_vga.value();
|
||||
app_settings.rx_amp = field_rf_amp.value();
|
||||
|
||||
settings.save("level", &app_settings);
|
||||
|
||||
receiver_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
LevelView::LevelView( NavigationView& nav) : nav_ { nav } {
|
||||
|
||||
add_children( {
|
||||
&labels,
|
||||
&field_lna,
|
||||
&field_vga,
|
||||
&field_rf_amp,
|
||||
&field_volume,
|
||||
&field_bw,
|
||||
&field_mode,
|
||||
&step_mode,
|
||||
&rssi_resolution,
|
||||
&button_frequency,
|
||||
&text_ctcss,
|
||||
&freq_stats_rssi,
|
||||
&freq_stats_db,
|
||||
&audio_mode,
|
||||
&peak_mode,
|
||||
&rssi,
|
||||
&rssi_graph
|
||||
} );
|
||||
|
||||
rssi.set_vertical_rssi( true );
|
||||
|
||||
field_volume.on_change = [this](int32_t v) { this->on_headphone_volume_changed(v); };
|
||||
field_volume.set_value((receiver_model.headphone_volume() - audio::headphone::volume_range().max).decibel() + 99);
|
||||
|
||||
// Level directory
|
||||
if( check_sd_card() ) { // Check to see if SD Card is mounted
|
||||
make_new_directory( u"/LEVEL" );
|
||||
sd_card_mounted = true ;
|
||||
}
|
||||
|
||||
change_mode(NFM_MODULATION); //Start on AM
|
||||
field_mode.set_by_value(NFM_MODULATION); //Reflect the mode into the manual selector
|
||||
|
||||
//HELPER: Pre-setting a manual range, based on stored frequency
|
||||
freq = persistent_memory::tuned_frequency();
|
||||
receiver_model.set_tuning_frequency( freq );
|
||||
button_frequency.set_text( "<" + to_string_short_freq( freq ) + " MHz>" );
|
||||
|
||||
// load auto common app settings
|
||||
if( sd_card_mounted )
|
||||
{
|
||||
auto rc = settings.load("level", &app_settings);
|
||||
if(rc == SETTINGS_OK) {
|
||||
field_lna.set_value(app_settings.lna);
|
||||
field_vga.set_value(app_settings.vga);
|
||||
field_rf_amp.set_value(app_settings.rx_amp);
|
||||
receiver_model.set_rf_amp(app_settings.rx_amp);
|
||||
}
|
||||
}
|
||||
|
||||
button_frequency.on_select = [this, &nav](ButtonWithEncoder& button) {
|
||||
auto new_view = nav_.push<FrequencyKeypadView>(freq);
|
||||
new_view->on_changed = [this, &button](rf::Frequency f) {
|
||||
freq = f ;
|
||||
receiver_model.set_tuning_frequency( f ); // Retune to actual freq
|
||||
button_frequency.set_text( "<" + to_string_short_freq( freq ) + " MHz>" );
|
||||
};
|
||||
};
|
||||
|
||||
button_frequency.on_change = [this]() {
|
||||
int64_t def_step = freqman_entry_get_step_value( step_mode.selected_index() );
|
||||
freq = freq + ( button_frequency.get_encoder_delta() * def_step );
|
||||
if( freq < 1 )
|
||||
{
|
||||
freq = 1 ;
|
||||
}
|
||||
if( freq > ( MAX_UFREQ - def_step ) )
|
||||
{
|
||||
freq = MAX_UFREQ ;
|
||||
}
|
||||
button_frequency.set_encoder_delta( 0 );
|
||||
|
||||
receiver_model.set_tuning_frequency( freq ); // Retune to actual freq
|
||||
button_frequency.set_text( "<" + to_string_short_freq( freq ) + " MHz>" );
|
||||
};
|
||||
|
||||
field_mode.on_change = [this](size_t, OptionsField::value_t v) {
|
||||
if( v != -1 )
|
||||
{
|
||||
receiver_model.disable();
|
||||
baseband::shutdown();
|
||||
change_mode(v);
|
||||
if( audio_mode.selected_index() != 0 )
|
||||
{
|
||||
audio::output::start();
|
||||
}
|
||||
receiver_model.enable();
|
||||
}
|
||||
};
|
||||
|
||||
rssi_resolution.on_change = [this](size_t, OptionsField::value_t v) {
|
||||
if( v != -1 )
|
||||
{
|
||||
rssi_graph.set_nb_columns( v );
|
||||
}
|
||||
};
|
||||
|
||||
audio_mode.on_change = [this](size_t, OptionsField::value_t v) {
|
||||
if( v == 0 )
|
||||
{
|
||||
audio::output::stop();
|
||||
}
|
||||
else if( v == 1 )
|
||||
{
|
||||
audio::output::start();
|
||||
this->on_headphone_volume_changed( (receiver_model.headphone_volume() - audio::headphone::volume_range().max).decibel() + 99 );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
peak_mode.on_change = [this](size_t, OptionsField::value_t v) {
|
||||
if( v == 0 )
|
||||
{
|
||||
rssi.set_peak( false , 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
rssi.set_peak( true , v );
|
||||
}
|
||||
};
|
||||
|
||||
// default peak value
|
||||
peak_mode.set_selected_index(3);
|
||||
rssi_resolution.set_selected_index(1);
|
||||
//FILL STEP OPTIONS
|
||||
freqman_set_modulation_option( field_mode );
|
||||
freqman_set_step_option_short( step_mode );
|
||||
freq_stats_rssi.set_style(&style_white);
|
||||
freq_stats_db.set_style(&style_white);
|
||||
}
|
||||
|
||||
void LevelView::on_headphone_volume_changed(int32_t v) {
|
||||
const auto new_volume = volume_t::decibel(v - 99) + audio::headphone::volume_range().max;
|
||||
receiver_model.set_headphone_volume(new_volume);
|
||||
}
|
||||
|
||||
|
||||
void LevelView::on_statistics_update(const ChannelStatistics& statistics) {
|
||||
static int last_max_db = -1000 ;
|
||||
static int last_min_rssi = -1000 ;
|
||||
static int last_avg_rssi = -1000 ;
|
||||
static int last_max_rssi = -1000 ;
|
||||
|
||||
rssi_graph.add_values( rssi.get_min() , rssi.get_avg() , rssi.get_max() , statistics.max_db );
|
||||
|
||||
bool refresh_db = false ;
|
||||
bool refresh_rssi = false ;
|
||||
|
||||
if( last_max_db != statistics.max_db )
|
||||
{
|
||||
refresh_db = true ;
|
||||
}
|
||||
if( last_min_rssi != rssi.get_min() || last_avg_rssi != rssi.get_avg() || last_max_rssi != rssi.get_max() )
|
||||
{
|
||||
refresh_rssi = true ;
|
||||
}
|
||||
if( refresh_db )
|
||||
{
|
||||
last_max_db = statistics.max_db ;
|
||||
freq_stats_db.set( "Power: "+to_string_dec_int( statistics.max_db )+" db" );
|
||||
}
|
||||
if( refresh_rssi )
|
||||
{
|
||||
last_min_rssi = rssi.get_min();
|
||||
last_avg_rssi = rssi.get_avg();
|
||||
last_max_rssi = rssi.get_max();
|
||||
freq_stats_rssi.set( "RSSI: "+to_string_dec_int( rssi.get_min() )+"/"+to_string_dec_int( rssi.get_avg() )+"/"+to_string_dec_int( rssi.get_max() )+",dt: "+to_string_dec_int( rssi.get_delta() ) );
|
||||
}
|
||||
} /* on_statistic_updates */
|
||||
|
||||
size_t LevelView::change_mode( freqman_index_t new_mod ) {
|
||||
|
||||
field_bw.on_change = [this](size_t n, OptionsField::value_t) { (void)n; };
|
||||
|
||||
switch( new_mod ) {
|
||||
case AM_MODULATION:
|
||||
freqman_set_bandwidth_option( new_mod , field_bw );
|
||||
//bw DSB (0) default
|
||||
field_bw.set_selected_index(0);
|
||||
baseband::run_image(portapack::spi_flash::image_tag_am_audio);
|
||||
receiver_model.set_modulation(ReceiverModel::Mode::AMAudio);
|
||||
receiver_model.set_am_configuration(field_bw.selected_index());
|
||||
field_bw.on_change = [this](size_t n, OptionsField::value_t) { receiver_model.set_am_configuration(n); };
|
||||
receiver_model.set_sampling_rate(3072000); receiver_model.set_baseband_bandwidth(1750000);
|
||||
text_ctcss.set(" ");
|
||||
break;
|
||||
case NFM_MODULATION:
|
||||
freqman_set_bandwidth_option( new_mod , field_bw );
|
||||
//bw 16k (2) default
|
||||
field_bw.set_selected_index(2);
|
||||
baseband::run_image(portapack::spi_flash::image_tag_nfm_audio);
|
||||
receiver_model.set_modulation(ReceiverModel::Mode::NarrowbandFMAudio);
|
||||
receiver_model.set_nbfm_configuration(field_bw.selected_index());
|
||||
field_bw.on_change = [this](size_t n, OptionsField::value_t) { receiver_model.set_nbfm_configuration(n); };
|
||||
receiver_model.set_sampling_rate(3072000); receiver_model.set_baseband_bandwidth(1750000);
|
||||
break;
|
||||
case WFM_MODULATION:
|
||||
freqman_set_bandwidth_option( new_mod , field_bw );
|
||||
//bw 200k (0) only/default
|
||||
field_bw.set_selected_index(0);
|
||||
baseband::run_image(portapack::spi_flash::image_tag_wfm_audio);
|
||||
receiver_model.set_modulation(ReceiverModel::Mode::WidebandFMAudio);
|
||||
receiver_model.set_wfm_configuration(field_bw.selected_index());
|
||||
field_bw.on_change = [this](size_t n, OptionsField::value_t) { receiver_model.set_wfm_configuration(n); };
|
||||
receiver_model.set_sampling_rate(3072000); receiver_model.set_baseband_bandwidth(1750000);
|
||||
text_ctcss.set(" ");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return step_mode.selected_index();
|
||||
}
|
||||
|
||||
|
||||
void LevelView::handle_coded_squelch(const uint32_t value) {
|
||||
static int32_t last_idx = -1 ;
|
||||
|
||||
float diff, min_diff = value;
|
||||
size_t min_idx { 0 };
|
||||
size_t c;
|
||||
|
||||
if( field_mode.selected_index() != NFM_MODULATION )
|
||||
{
|
||||
text_ctcss.set(" ");
|
||||
return ;
|
||||
}
|
||||
|
||||
// Find nearest match
|
||||
for (c = 0; c < tone_keys.size(); c++) {
|
||||
diff = abs(((float)value / 100.0) - tone_keys[c].second);
|
||||
if (diff < min_diff) {
|
||||
min_idx = c;
|
||||
min_diff = diff;
|
||||
}
|
||||
}
|
||||
|
||||
// Arbitrary confidence threshold
|
||||
if( last_idx < 0 || (unsigned)last_idx != min_idx )
|
||||
{
|
||||
last_idx = min_idx ;
|
||||
if (min_diff < 40)
|
||||
text_ctcss.set("T: "+tone_keys[min_idx].first);
|
||||
else
|
||||
text_ctcss.set(" ");
|
||||
}
|
||||
}
|
||||
|
||||
} /* namespace ui */
|
||||
@@ -0,0 +1,241 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2018 Furrtek
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _UI_LEVEL
|
||||
#define _UI_LEVEL
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "receiver_model.hpp"
|
||||
#include "ui_receiver.hpp"
|
||||
#include "ui_font_fixed_8x16.hpp"
|
||||
#include "freqman.hpp"
|
||||
#include "analog_audio_app.hpp"
|
||||
#include "audio.hpp"
|
||||
#include "ui_mictx.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "ui_spectrum.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "file.hpp"
|
||||
#include "app_settings.hpp"
|
||||
|
||||
|
||||
namespace ui {
|
||||
|
||||
class LevelView : public View {
|
||||
public:
|
||||
LevelView(NavigationView& nav);
|
||||
~LevelView();
|
||||
|
||||
void focus() override;
|
||||
|
||||
void big_display_freq( int64_t f );
|
||||
|
||||
const Style style_grey { // level
|
||||
.font = font::fixed_8x16,
|
||||
.background = Color::black(),
|
||||
.foreground = Color::grey(),
|
||||
};
|
||||
|
||||
const Style style_white { // level
|
||||
.font = font::fixed_8x16,
|
||||
.background = Color::black(),
|
||||
.foreground = Color::white(),
|
||||
};
|
||||
|
||||
const Style style_yellow { //Found signal
|
||||
.font = font::fixed_8x16,
|
||||
.background = Color::black(),
|
||||
.foreground = Color::yellow(),
|
||||
};
|
||||
|
||||
const Style style_green { //Found signal
|
||||
.font = font::fixed_8x16,
|
||||
.background = Color::black(),
|
||||
.foreground = Color::green(),
|
||||
};
|
||||
|
||||
const Style style_red { //erasing freq
|
||||
.font = font::fixed_8x16,
|
||||
.background = Color::black(),
|
||||
.foreground = Color::red(),
|
||||
};
|
||||
|
||||
const Style style_blue { // quick level, wait == 0
|
||||
.font = font::fixed_8x16,
|
||||
.background = Color::black(),
|
||||
.foreground = Color::blue(),
|
||||
};
|
||||
|
||||
std::string title() const override { return "Level"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
size_t change_mode( freqman_index_t mod_type);
|
||||
void on_statistics_update(const ChannelStatistics& statistics);
|
||||
void set_display_freq( int64_t freq );
|
||||
bool check_sd_card();
|
||||
|
||||
int32_t db { 0 };
|
||||
long long int MAX_UFREQ = { 7200000000 }; // maximum usable freq
|
||||
bool sd_card_mounted = false ;
|
||||
rf::Frequency freq = { 0 } ;
|
||||
|
||||
Labels labels
|
||||
{
|
||||
{ { 0 * 8 , 0 * 16 }, "LNA: VGA: AMP: VOL: ", Color::light_grey() },
|
||||
{ { 0 * 8 , 1 * 16 }, "BW: MODE: S: ", Color::light_grey() },
|
||||
};
|
||||
|
||||
LNAGainField field_lna {
|
||||
{ 4 * 8, 0 * 16 }
|
||||
};
|
||||
|
||||
VGAGainField field_vga {
|
||||
{ 11 * 8, 0 * 16 }
|
||||
};
|
||||
|
||||
RFAmpField field_rf_amp {
|
||||
{ 18 * 8, 0 * 16 }
|
||||
};
|
||||
|
||||
NumberField field_volume {
|
||||
{ 24 * 8, 0 * 16 },
|
||||
2,
|
||||
{ 0, 99 },
|
||||
1,
|
||||
' ',
|
||||
};
|
||||
|
||||
OptionsField field_bw {
|
||||
{ 3 * 8, 1 * 16 },
|
||||
6,
|
||||
{ }
|
||||
};
|
||||
|
||||
OptionsField field_mode {
|
||||
{ 15 * 8, 1 * 16 },
|
||||
3,
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
OptionsField step_mode {
|
||||
{ 16 * 8, 2 * 16 + 4 },
|
||||
12,
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
RSSIGraph rssi_graph { // 240x320 =>
|
||||
{ 0 , 5 * 16 + 4 , 240 - 5 * 8 , 216 },
|
||||
};
|
||||
|
||||
RSSI rssi { // 240x320 =>
|
||||
{ 240 - 5 * 8 , 5 * 16 + 4 , 5 * 8 , 216 },
|
||||
};
|
||||
|
||||
|
||||
ButtonWithEncoder button_frequency {
|
||||
{ 0 * 8 , 2 * 16 + 8 , 15 * 8 , 1 * 8 },
|
||||
""
|
||||
};
|
||||
|
||||
OptionsField audio_mode {
|
||||
{ 21 * 8, 1 * 16 },
|
||||
9,
|
||||
{
|
||||
{"audio off", 0},
|
||||
{"audio on",1}
|
||||
//{"tone on", 2},
|
||||
//{"tone off", 2},
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Text text_ctcss {
|
||||
{ 22 * 8, 3 * 16 + 4 , 14 * 8, 1 * 8 },
|
||||
""
|
||||
};
|
||||
|
||||
// RSSI: XX/XX/XXX,dt: XX
|
||||
Text freq_stats_rssi {
|
||||
{ 0 * 8 , 3 * 16 + 4 , 22 * 8, 16 },
|
||||
};
|
||||
|
||||
Text freq_stats_db {
|
||||
{ 0 * 8 , 4 * 16 + 4 , 15 * 8, 16 },
|
||||
};
|
||||
|
||||
|
||||
OptionsField peak_mode {
|
||||
{ 40 + 10 * 8, 4 * 16 + 4 },
|
||||
10,
|
||||
{
|
||||
{"peak:none", 0},
|
||||
{"peak:0.25s",250},
|
||||
{"peak:0.5s",500},
|
||||
{"peak:1s",1000},
|
||||
{"peak:3s",3000},
|
||||
{"peak:5s",5000},
|
||||
{"peak:10s",10000},
|
||||
}
|
||||
};
|
||||
OptionsField rssi_resolution {
|
||||
{ 44 + 20 * 8, 4 * 16 + 4},
|
||||
4,
|
||||
{
|
||||
{"16x", 16},
|
||||
{"32x", 32},
|
||||
{"64x", 64},
|
||||
{"128x", 128},
|
||||
{"240x", 240},
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void handle_coded_squelch(const uint32_t value);
|
||||
void on_headphone_volume_changed(int32_t v);
|
||||
|
||||
MessageHandlerRegistration message_handler_coded_squelch {
|
||||
Message::ID::CodedSquelch,
|
||||
[this](const Message* const p) {
|
||||
const auto message = *reinterpret_cast<const CodedSquelchMessage*>(p);
|
||||
this->handle_coded_squelch(message.value);
|
||||
}
|
||||
};
|
||||
|
||||
MessageHandlerRegistration message_handler_stats {
|
||||
Message::ID::ChannelStatistics,
|
||||
[this](const Message* const p) {
|
||||
this->on_statistics_update(static_cast<const ChannelStatisticsMessage*>(p)->statistics);
|
||||
}
|
||||
};
|
||||
// app save settings
|
||||
std::app_settings settings { };
|
||||
std::app_settings::AppSettings app_settings { };
|
||||
};
|
||||
|
||||
} /* namespace ui */
|
||||
|
||||
#endif
|
||||
@@ -22,315 +22,393 @@
|
||||
|
||||
#include "ui_looking_glass_app.hpp"
|
||||
|
||||
|
||||
using namespace portapack;
|
||||
|
||||
namespace ui
|
||||
{
|
||||
|
||||
void GlassView::focus() {
|
||||
field_marker.focus();
|
||||
}
|
||||
|
||||
GlassView::~GlassView() {
|
||||
receiver_model.set_sampling_rate(3072000); // Just a hack to avoid hanging other apps
|
||||
receiver_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
void GlassView::on_lna_changed(int32_t v_db) {
|
||||
receiver_model.set_lna(v_db);
|
||||
}
|
||||
|
||||
void GlassView::on_vga_changed(int32_t v_db) {
|
||||
receiver_model.set_vga(v_db);
|
||||
}
|
||||
|
||||
void GlassView::add_spectrum_pixel(Color color)
|
||||
{
|
||||
spectrum_row[pixel_index++] = color;
|
||||
if (pixel_index == 240) //got an entire waterfall line
|
||||
{
|
||||
const auto draw_y = display.scroll(1); //Scroll 1 pixel down
|
||||
display.draw_pixels( {{0, draw_y}, {240, 1}}, spectrum_row); //new line at top
|
||||
pixel_index = 0; //Start New cascade line
|
||||
}
|
||||
}
|
||||
|
||||
//Apparently, the spectrum object returns an array of 256 bins
|
||||
//Each having the radio signal power for it's corresponding frequency slot
|
||||
void GlassView::on_channel_spectrum(const ChannelSpectrum &spectrum)
|
||||
{
|
||||
baseband::spectrum_streaming_stop();
|
||||
|
||||
// Convert bins of this spectrum slice into a representative max_power and when enough, into pixels
|
||||
// Spectrum.db has 256 bins. Center 12 bins are ignored (DC spike is blanked) Leftmost and rightmost 2 bins are ignored
|
||||
// All things said and done, we actually need 240 of those bins:
|
||||
for(uint8_t bin = 0; bin < 240; bin++)
|
||||
void GlassView::focus()
|
||||
{
|
||||
if (bin < 120) {
|
||||
if (spectrum.db[134 + bin] > max_power)
|
||||
max_power = spectrum.db[134 + bin];
|
||||
}
|
||||
else
|
||||
field_marker.focus();
|
||||
}
|
||||
|
||||
GlassView::~GlassView()
|
||||
{
|
||||
receiver_model.set_sampling_rate(3072000); // Just a hack to avoid hanging other apps
|
||||
receiver_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
void GlassView::on_lna_changed(int32_t v_db)
|
||||
{
|
||||
receiver_model.set_lna(v_db);
|
||||
}
|
||||
|
||||
void GlassView::on_vga_changed(int32_t v_db)
|
||||
{
|
||||
receiver_model.set_vga(v_db);
|
||||
}
|
||||
|
||||
void GlassView::add_spectrum_pixel(Color color)
|
||||
{
|
||||
spectrum_row[pixel_index++] = color;
|
||||
if (pixel_index == 240) // got an entire waterfall line
|
||||
{
|
||||
if (spectrum.db[bin - 118] > max_power)
|
||||
max_power = spectrum.db[bin - 118];
|
||||
display.draw_pixels({{0, display.scroll(1)}, {240, 1}}, spectrum_row); // new line at top, one less var, speedier
|
||||
pixel_index = 0; // Start New cascade line
|
||||
}
|
||||
}
|
||||
|
||||
bins_Hz_size += each_bin_size; //add this bin Hz count into the "pixel fulfilled bag of Hz"
|
||||
// Apparently, the spectrum object returns an array of 256 bins
|
||||
// Each having the radio signal power for it's corresponding frequency slot
|
||||
void GlassView::on_channel_spectrum(const ChannelSpectrum &spectrum)
|
||||
{
|
||||
baseband::spectrum_streaming_stop();
|
||||
|
||||
if (bins_Hz_size >= marker_pixel_step) //new pixel fullfilled
|
||||
// Convert bins of this spectrum slice into a representative max_power and when enough, into pixels
|
||||
// Spectrum.db has 256 bins. Center 12 bins are ignored (DC spike is blanked) Leftmost and rightmost 2 bins are ignored
|
||||
// All things said and done, we actually need 240 of those bins:
|
||||
for (uint8_t bin = 0; bin < 240; bin++)
|
||||
{
|
||||
if (min_color_power < max_power)
|
||||
add_spectrum_pixel(spectrum_rgb3_lut[max_power]); //Pixel will represent max_power
|
||||
else
|
||||
add_spectrum_pixel(0); //Filtered out, show black
|
||||
|
||||
max_power = 0;
|
||||
|
||||
if (!pixel_index) //Received indication that a waterfall line has been completed
|
||||
if (bin < 120)
|
||||
{
|
||||
bins_Hz_size = 0; //Since this is an entire pixel line, we don't carry "Pixels into next bin"
|
||||
break;
|
||||
} else {
|
||||
bins_Hz_size -= marker_pixel_step; //reset bins size, but carrying the eventual excess Hz into next pixel
|
||||
if (spectrum.db[134 + bin] > max_power) // 134
|
||||
max_power = spectrum.db[134 + bin];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (spectrum.db[bin - 118] > max_power) // 118
|
||||
max_power = spectrum.db[bin - 118];
|
||||
}
|
||||
|
||||
bins_Hz_size += each_bin_size; // add this bin Hz count into the "pixel fulfilled bag of Hz"
|
||||
|
||||
if (bins_Hz_size >= marker_pixel_step) // new pixel fullfilled
|
||||
{
|
||||
if (min_color_power < max_power)
|
||||
add_spectrum_pixel(spectrum_rgb3_lut[max_power]); // Pixel will represent max_power
|
||||
else
|
||||
add_spectrum_pixel(0); // Filtered out, show black
|
||||
|
||||
max_power = 0;
|
||||
|
||||
if (!pixel_index) // Received indication that a waterfall line has been completed
|
||||
{
|
||||
bins_Hz_size = 0; // Since this is an entire pixel line, we don't carry "Pixels into next bin"
|
||||
f_center = f_center_ini; // Start a new sweep
|
||||
radio::set_tuning_frequency(f_center); // tune rx for this new slice directly, faster than using persistent memory saving
|
||||
chThdSleepMilliseconds(10);
|
||||
baseband::spectrum_streaming_start(); // Do the RX
|
||||
return;
|
||||
}
|
||||
bins_Hz_size -= marker_pixel_step; // reset bins size, but carrying the eventual excess Hz into next pixel
|
||||
}
|
||||
}
|
||||
|
||||
f_center += LOOKING_GLASS_SLICE_WIDTH; // Move into the next bandwidth slice NOTE: spectrum.sampling_rate = LOOKING_GLASS_SLICE_WIDTH
|
||||
radio::set_tuning_frequency(f_center); // tune rx for this new slice directly, faster than using persistent memory saving
|
||||
chThdSleepMilliseconds(5);
|
||||
|
||||
// receiver_model.set_tuning_frequency(f_center); //tune rx for this slice
|
||||
baseband::spectrum_streaming_start(); // Do the RX
|
||||
}
|
||||
|
||||
if (pixel_index)
|
||||
f_center += LOOKING_GLASS_SLICE_WIDTH; //Move into the next bandwidth slice NOTE: spectrum.sampling_rate = LOOKING_GLASS_SLICE_WIDTH
|
||||
else
|
||||
f_center = f_center_ini; //Start a new sweep
|
||||
|
||||
receiver_model.set_tuning_frequency(f_center); //tune rx for this slice
|
||||
baseband::spectrum_streaming_start(); //Do the RX
|
||||
}
|
||||
|
||||
void GlassView::on_hide()
|
||||
{
|
||||
baseband::spectrum_streaming_stop();
|
||||
display.scroll_disable();
|
||||
}
|
||||
|
||||
void GlassView::on_show()
|
||||
{
|
||||
display.scroll_set_area( 109, 319); //Restart scroll on the correct coordinates
|
||||
baseband::spectrum_streaming_start();
|
||||
}
|
||||
|
||||
void GlassView::on_range_changed()
|
||||
{
|
||||
f_min = field_frequency_min.value();
|
||||
f_max = field_frequency_max.value();
|
||||
search_span = f_max - f_min;
|
||||
|
||||
field_marker.set_range(f_min, f_max); //Move the marker between range
|
||||
field_marker.set_value(f_min + (search_span / 2)); //Put MARKER AT MIDDLE RANGE
|
||||
text_range.set(to_string_dec_uint(search_span));
|
||||
|
||||
f_min = (f_min)*MHZ_DIV; //Transpose into full frequency realm
|
||||
f_max = (f_max)*MHZ_DIV;
|
||||
search_span = search_span * MHZ_DIV;
|
||||
|
||||
marker_pixel_step = search_span / 240; //Each pixel value in Hz
|
||||
text_marker_pm.set(to_string_dec_uint((marker_pixel_step / X2_MHZ_DIV) + 1)); // Give idea of +/- marker precision
|
||||
|
||||
int32_t marker_step = marker_pixel_step / MHZ_DIV;
|
||||
if (!marker_step)
|
||||
field_marker.set_step(1); //in case selected range is less than 240 (pixels)
|
||||
else
|
||||
field_marker.set_step(marker_step); //step needs to be a pixel wide.
|
||||
|
||||
f_center_ini = f_min + (LOOKING_GLASS_SLICE_WIDTH / 2); //Initial center frequency for sweep
|
||||
f_center_ini += LOOKING_GLASS_SLICE_WIDTH; //euquiq: Why do I need to move the center ???!!! (shift needed for marker accuracy)
|
||||
|
||||
PlotMarker(field_marker.value()); //Refresh marker on screen
|
||||
|
||||
f_center = f_center_ini; //Reset sweep into first slice
|
||||
pixel_index = 0; //reset pixel counter
|
||||
max_power = 0;
|
||||
bins_Hz_size = 0; //reset amount of Hz filled up by pixels
|
||||
|
||||
baseband::set_spectrum(LOOKING_GLASS_SLICE_WIDTH, field_trigger.value());
|
||||
receiver_model.set_tuning_frequency(f_center_ini); //tune rx for this slice
|
||||
}
|
||||
|
||||
void GlassView::PlotMarker(rf::Frequency fpos)
|
||||
{
|
||||
int64_t pos = fpos * MHZ_DIV;
|
||||
pos -= f_min;
|
||||
pos = pos / marker_pixel_step; //Real pixel
|
||||
|
||||
portapack::display.fill_rectangle({0, 100, 240, 8}, Color::black()); //Clear old marker and whole marker rectangle btw
|
||||
portapack::display.fill_rectangle({(int16_t)pos - 2, 100, 5, 3}, Color::red()); //Red marker middle
|
||||
portapack::display.fill_rectangle({(int16_t)pos - 1, 103, 3, 3}, Color::red()); //Red marker middle
|
||||
portapack::display.fill_rectangle({(int16_t)pos, 106, 1, 2}, Color::red()); //Red marker middle
|
||||
}
|
||||
|
||||
GlassView::GlassView(
|
||||
NavigationView &nav) : nav_(nav)
|
||||
{
|
||||
baseband::run_image(portapack::spi_flash::image_tag_wideband_spectrum);
|
||||
|
||||
add_children({&labels,
|
||||
&field_frequency_min,
|
||||
&field_frequency_max,
|
||||
&field_lna,
|
||||
&field_vga,
|
||||
&text_range,
|
||||
&filter_config,
|
||||
&field_rf_amp,
|
||||
&range_presets,
|
||||
&field_marker,
|
||||
&text_marker_pm,
|
||||
&field_trigger
|
||||
});
|
||||
|
||||
load_Presets(); //Load available presets from TXT files (or default)
|
||||
|
||||
field_frequency_min.set_value(presets_db[0].min); //Defaults to first preset
|
||||
field_frequency_min.on_change = [this](int32_t v) {
|
||||
if (v >= field_frequency_max.value())
|
||||
field_frequency_max.set_value(v + 240);
|
||||
this->on_range_changed();
|
||||
};
|
||||
|
||||
field_frequency_max.set_value(presets_db[0].max); //Defaults to first preset
|
||||
field_frequency_max.on_change = [this](int32_t v) {
|
||||
if (v <= field_frequency_min.value())
|
||||
field_frequency_min.set_value(v - 240);
|
||||
this->on_range_changed();
|
||||
};
|
||||
|
||||
field_lna.set_value(receiver_model.lna());
|
||||
field_lna.on_change = [this](int32_t v) {
|
||||
this->on_lna_changed(v);
|
||||
};
|
||||
|
||||
field_vga.set_value(receiver_model.vga());
|
||||
field_vga.on_change = [this](int32_t v_db) {
|
||||
this->on_vga_changed(v_db);
|
||||
};
|
||||
|
||||
filter_config.set_selected_index(0);
|
||||
filter_config.on_change = [this](size_t n, OptionsField::value_t v) {
|
||||
(void)n;
|
||||
min_color_power = v;
|
||||
};
|
||||
|
||||
range_presets.on_change = [this](size_t n, OptionsField::value_t v) {
|
||||
(void)n;
|
||||
field_frequency_min.set_value(presets_db[v].min,false);
|
||||
field_frequency_max.set_value(presets_db[v].max,false);
|
||||
this->on_range_changed();
|
||||
};
|
||||
|
||||
field_marker.on_change = [this](int32_t v) {
|
||||
PlotMarker(v); //Refresh marker on screen
|
||||
};
|
||||
|
||||
field_marker.on_select = [this](NumberField&) {
|
||||
f_center = field_marker.value();
|
||||
f_center = f_center * MHZ_DIV;
|
||||
receiver_model.set_tuning_frequency(f_center); //Center tune rx in marker freq.
|
||||
receiver_model.set_frequency_step(MHZ_DIV); // Preset a 1 MHz frequency step into RX -> AUDIO
|
||||
nav_.pop();
|
||||
nav_.push<AnalogAudioView>(); //Jump into audio view
|
||||
};
|
||||
|
||||
field_trigger.set_value(32); //Defaults to 32, as normal triggering resolution
|
||||
field_trigger.on_change = [this](int32_t v) {
|
||||
baseband::set_spectrum(LOOKING_GLASS_SLICE_WIDTH, v);
|
||||
};
|
||||
|
||||
display.scroll_set_area( 109, 319);
|
||||
baseband::set_spectrum(LOOKING_GLASS_SLICE_WIDTH, field_trigger.value()); //trigger:
|
||||
// Discord User jteich: WidebandSpectrum::on_message to set the trigger value. In WidebandSpectrum::execute ,
|
||||
// it keeps adding the output of the fft to the buffer until "trigger" number of calls are made,
|
||||
//at which time it pushes the buffer up with channel_spectrum.feed
|
||||
|
||||
on_range_changed();
|
||||
|
||||
receiver_model.set_modulation(ReceiverModel::Mode::SpectrumAnalysis);
|
||||
receiver_model.set_sampling_rate(LOOKING_GLASS_SLICE_WIDTH); //20mhz
|
||||
receiver_model.set_baseband_bandwidth(LOOKING_GLASS_SLICE_WIDTH); // possible values: 1.75/2.5/3.5/5/5.5/6/7/8/9/10/12/14/15/20/24/28MHz
|
||||
receiver_model.set_squelch_level(0);
|
||||
receiver_model.enable();
|
||||
}
|
||||
|
||||
void GlassView::load_Presets() {
|
||||
File presets_file; //LOAD /WHIPCALC/ANTENNAS.TXT from microSD
|
||||
auto result = presets_file.open("LOOKINGGLASS/PRESETS.TXT");
|
||||
presets_db.clear(); //Start with fresh db
|
||||
if (result.is_valid()) {
|
||||
presets_Default(); //There is no txt, store a default range
|
||||
} else {
|
||||
|
||||
std::string line; //There is a txt file
|
||||
char one_char[1]; //Read it char by char
|
||||
for (size_t pointer=0; pointer < presets_file.size();pointer++) {
|
||||
presets_file.seek(pointer);
|
||||
presets_file.read(one_char, 1);
|
||||
if ((int)one_char[0] > 31) { //ascii space upwards
|
||||
line += one_char[0]; //Add it to the textline
|
||||
}
|
||||
else if (one_char[0] == '\n') { //New Line
|
||||
txtline_process(line); //make sense of this textline
|
||||
line.clear(); //Ready for next textline
|
||||
}
|
||||
}
|
||||
if (line.length() > 0) txtline_process(line); //Last line had no newline at end ?
|
||||
if (!presets_db.size()) presets_Default(); //no antenna on txt, use default
|
||||
void GlassView::on_hide()
|
||||
{
|
||||
baseband::spectrum_streaming_stop();
|
||||
display.scroll_disable();
|
||||
}
|
||||
|
||||
populate_Presets();
|
||||
}
|
||||
void GlassView::on_show()
|
||||
{
|
||||
display.scroll_set_area(109, 319); // Restart scroll on the correct coordinates
|
||||
baseband::spectrum_streaming_start();
|
||||
}
|
||||
|
||||
void GlassView::txtline_process(std::string& line)
|
||||
{
|
||||
if (line.find("#") != std::string::npos) return; //Line is just a comment
|
||||
void GlassView::on_range_changed()
|
||||
{
|
||||
f_min = field_frequency_min.value();
|
||||
f_max = field_frequency_max.value();
|
||||
search_span = f_max - f_min;
|
||||
|
||||
size_t comma = line.find(","); //Get first comma position
|
||||
if (comma == std::string::npos) return; //No comma at all
|
||||
field_marker.set_range(f_min, f_max); // Move the marker between range
|
||||
field_marker.set_value(f_min + (search_span / 2)); // Put MARKER AT MIDDLE RANGE
|
||||
text_range.set(to_string_dec_uint(search_span));
|
||||
|
||||
size_t previous = 0;
|
||||
preset_entry new_preset;
|
||||
f_min = (f_min)*MHZ_DIV; // Transpose into full frequency realm
|
||||
f_max = (f_max)*MHZ_DIV;
|
||||
search_span = search_span * MHZ_DIV;
|
||||
|
||||
new_preset.min = std::stoi(line.substr(0,comma));
|
||||
if (!new_preset.min) return; //No frequency!
|
||||
|
||||
previous = comma + 1;
|
||||
comma = line.find(",",previous); //Search for next delimiter
|
||||
if (comma == std::string::npos) return; //No comma at all
|
||||
marker_pixel_step = search_span / 240; // Each pixel value in Hz
|
||||
text_marker_pm.set(to_string_dec_uint((marker_pixel_step / X2_MHZ_DIV) + 1)); // Give idea of +/- marker precision
|
||||
|
||||
new_preset.max = std::stoi(line.substr(previous,comma - previous));
|
||||
if (!new_preset.max) return; //No frequency!
|
||||
int32_t marker_step = marker_pixel_step / MHZ_DIV;
|
||||
if (!marker_step)
|
||||
field_marker.set_step(1); // in case selected range is less than 240 (pixels)
|
||||
else
|
||||
field_marker.set_step(marker_step); // step needs to be a pixel wide.
|
||||
|
||||
new_preset.label = line.substr(comma + 1);
|
||||
if (new_preset.label.size() == 0) return; //No label ?
|
||||
|
||||
presets_db.push_back(new_preset); //Add this preset.
|
||||
}
|
||||
f_center_ini = f_min + (LOOKING_GLASS_SLICE_WIDTH / 2); // Initial center frequency for sweep
|
||||
|
||||
void GlassView::populate_Presets()
|
||||
{
|
||||
using option_t = std::pair<std::string, int32_t>;
|
||||
using options_t = std::vector<option_t>;
|
||||
options_t entries;
|
||||
PlotMarker(field_marker.value()); // Refresh marker on screen
|
||||
|
||||
for (preset_entry preset : presets_db)
|
||||
{ //go thru all available presets
|
||||
entries.emplace_back(preset.label,entries.size());
|
||||
f_center = f_center_ini; // Reset sweep into first slice
|
||||
pixel_index = 0; // reset pixel counter
|
||||
max_power = 0;
|
||||
bins_Hz_size = 0; // reset amount of Hz filled up by pixels
|
||||
|
||||
baseband::set_spectrum(LOOKING_GLASS_SLICE_WIDTH, field_trigger.value());
|
||||
receiver_model.set_tuning_frequency(f_center_ini); // tune rx for this slice
|
||||
}
|
||||
|
||||
void GlassView::PlotMarker(rf::Frequency pos)
|
||||
{
|
||||
pos = pos * MHZ_DIV;
|
||||
pos -= f_min;
|
||||
pos = pos / marker_pixel_step; // Real pixel
|
||||
|
||||
portapack::display.fill_rectangle({0, 100, 240, 8}, Color::black()); // Clear old marker and whole marker rectangle btw
|
||||
portapack::display.fill_rectangle({(int)pos - 2, 100, 5, 3}, Color::red()); // Red marker top
|
||||
portapack::display.fill_rectangle({(int)pos - 1, 103, 3, 3}, Color::red()); // Red marker middle
|
||||
portapack::display.fill_rectangle({(int)pos, 106, 1, 2}, Color::red()); // Red marker bottom
|
||||
}
|
||||
|
||||
GlassView::GlassView(
|
||||
NavigationView &nav) : nav_(nav)
|
||||
{
|
||||
baseband::run_image(portapack::spi_flash::image_tag_wideband_spectrum);
|
||||
|
||||
add_children({&labels,
|
||||
&field_frequency_min,
|
||||
&field_frequency_max,
|
||||
&field_lna,
|
||||
&field_vga,
|
||||
&text_range,
|
||||
&steps_config,
|
||||
&filter_config,
|
||||
&field_rf_amp,
|
||||
&range_presets,
|
||||
&field_marker,
|
||||
&text_marker_pm,
|
||||
&field_trigger});
|
||||
|
||||
load_Presets(); // Load available presets from TXT files (or default)
|
||||
|
||||
field_frequency_min.set_value(presets_db[0].min); // Defaults to first preset
|
||||
field_frequency_min.set_step( steps );
|
||||
field_frequency_min.on_change = [this](int32_t v)
|
||||
{
|
||||
int32_t steps_ = steps ;
|
||||
if( steps_ < 24 )
|
||||
steps_ = 24 ;
|
||||
if( v > 7200 - steps_ )
|
||||
{
|
||||
v = 7200 - steps_ ;
|
||||
field_frequency_min.set_value( v );
|
||||
}
|
||||
if (v >= (field_frequency_max.value() - steps_ ) )
|
||||
field_frequency_max.set_value( v + steps_ );
|
||||
this->on_range_changed();
|
||||
};
|
||||
|
||||
field_frequency_min.on_select = [this, &nav](NumberField& field) {
|
||||
auto new_view = nav_.push<FrequencyKeypadView>(field_frequency_min.value()*1000000);
|
||||
new_view->on_changed = [this, &field](rf::Frequency f) {
|
||||
int32_t freq = f / 1000000 ;
|
||||
int32_t steps_ = steps ;
|
||||
if( steps_ < 24 )
|
||||
steps_ = 24 ;
|
||||
if( freq > (7200 - steps_ ) )
|
||||
freq= 7200 - steps_ ;
|
||||
field_frequency_min.set_value( freq );
|
||||
if( field_frequency_max.value() < ( freq + steps_ ) )
|
||||
field_frequency_max.set_value( freq + steps_ );
|
||||
this->on_range_changed();
|
||||
};
|
||||
};
|
||||
|
||||
field_frequency_max.set_value(presets_db[0].max); // Defaults to first preset
|
||||
field_frequency_max.set_step( steps );
|
||||
field_frequency_max.on_change = [this](int32_t v)
|
||||
{
|
||||
int32_t steps_ = steps ;
|
||||
if( steps_ < 24 )
|
||||
steps_ = 24 ;
|
||||
if( v < steps_ )
|
||||
{
|
||||
v = steps_ ;
|
||||
field_frequency_max.set_value( v );
|
||||
}
|
||||
if (v < (field_frequency_min.value() + steps_) )
|
||||
field_frequency_min.set_value(v - steps_);
|
||||
this->on_range_changed();
|
||||
};
|
||||
|
||||
field_frequency_max.on_select = [this, &nav](NumberField& field) {
|
||||
auto new_view = nav_.push<FrequencyKeypadView>(field_frequency_max.value()*1000000);
|
||||
new_view->on_changed = [this, &field](rf::Frequency f) {
|
||||
int32_t steps_ = steps ;
|
||||
if( steps_ < 24 )
|
||||
steps_ = 24 ;
|
||||
int32_t freq = f / 1000000 ;
|
||||
if( freq < 24 )
|
||||
freq = 24 ;
|
||||
field_frequency_max.set_value( freq );
|
||||
if( field_frequency_min.value() > ( freq - steps) )
|
||||
field_frequency_min.set_value( freq - steps );
|
||||
this->on_range_changed();
|
||||
};
|
||||
};
|
||||
|
||||
field_lna.set_value(receiver_model.lna());
|
||||
field_lna.on_change = [this](int32_t v)
|
||||
{
|
||||
this->on_lna_changed(v);
|
||||
};
|
||||
|
||||
field_vga.set_value(receiver_model.vga());
|
||||
field_vga.on_change = [this](int32_t v_db)
|
||||
{
|
||||
this->on_vga_changed(v_db);
|
||||
};
|
||||
|
||||
steps_config.set_selected_index(3); //default of 250 Mhz steps
|
||||
steps_config.on_change = [this](size_t n, OptionsField::value_t v)
|
||||
{
|
||||
(void)n;
|
||||
field_frequency_min.set_step( v );
|
||||
field_frequency_max.set_step( v );
|
||||
steps = v ;
|
||||
};
|
||||
|
||||
range_presets.on_change = [this](size_t n, OptionsField::value_t v)
|
||||
{
|
||||
(void)n;
|
||||
field_frequency_min.set_value(presets_db[v].min, false);
|
||||
field_frequency_max.set_value(presets_db[v].max, false);
|
||||
this->on_range_changed();
|
||||
};
|
||||
|
||||
field_marker.on_change = [this](int32_t v)
|
||||
{
|
||||
PlotMarker(v); // Refresh marker on screen
|
||||
};
|
||||
|
||||
field_marker.on_select = [this](NumberField &)
|
||||
{
|
||||
f_center = field_marker.value();
|
||||
f_center = f_center * MHZ_DIV;
|
||||
receiver_model.set_tuning_frequency(f_center); // Center tune rx in marker freq.
|
||||
receiver_model.set_frequency_step(MHZ_DIV); // Preset a 1 MHz frequency step into RX -> AUDIO
|
||||
nav_.pop();
|
||||
nav_.push<AnalogAudioView>(); // Jump into audio view
|
||||
};
|
||||
|
||||
field_trigger.set_value(32); // Defaults to 32, as normal triggering resolution
|
||||
field_trigger.on_change = [this](int32_t v)
|
||||
{
|
||||
baseband::set_spectrum(LOOKING_GLASS_SLICE_WIDTH, v);
|
||||
};
|
||||
|
||||
display.scroll_set_area(109, 319);
|
||||
baseband::set_spectrum(LOOKING_GLASS_SLICE_WIDTH, field_trigger.value()); // trigger:
|
||||
// Discord User jteich: WidebandSpectrum::on_message to set the trigger value. In WidebandSpectrum::execute ,
|
||||
// it keeps adding the output of the fft to the buffer until "trigger" number of calls are made,
|
||||
// at which time it pushes the buffer up with channel_spectrum.feed
|
||||
|
||||
on_range_changed();
|
||||
|
||||
receiver_model.set_modulation(ReceiverModel::Mode::SpectrumAnalysis);
|
||||
receiver_model.set_sampling_rate(LOOKING_GLASS_SLICE_WIDTH); // 20mhz
|
||||
receiver_model.set_baseband_bandwidth(LOOKING_GLASS_SLICE_WIDTH); // possible values: 1.75/2.5/3.5/5/5.5/6/7/8/9/10/12/14/15/20/24/28MHz
|
||||
receiver_model.set_squelch_level(0);
|
||||
receiver_model.enable();
|
||||
}
|
||||
|
||||
void GlassView::load_Presets()
|
||||
{
|
||||
File presets_file; // LOAD /WHIPCALC/ANTENNAS.TXT from microSD
|
||||
auto result = presets_file.open("LOOKINGGLASS/PRESETS.TXT");
|
||||
presets_db.clear(); // Start with fresh db
|
||||
if (result.is_valid())
|
||||
{
|
||||
presets_Default(); // There is no txt, store a default range
|
||||
}
|
||||
range_presets.set_options(entries);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string line; // There is a txt file
|
||||
char one_char[1]; // Read it char by char
|
||||
for (size_t pointer = 0; pointer < presets_file.size(); pointer++)
|
||||
{
|
||||
presets_file.seek(pointer);
|
||||
presets_file.read(one_char, 1);
|
||||
if ((int)one_char[0] > 31)
|
||||
{ // ascii space upwards
|
||||
line += one_char[0]; // Add it to the textline
|
||||
}
|
||||
else if (one_char[0] == '\n')
|
||||
{ // New Line
|
||||
txtline_process(line); // make sense of this textline
|
||||
line.clear(); // Ready for next textline
|
||||
}
|
||||
}
|
||||
if (line.length() > 0)
|
||||
txtline_process(line); // Last line had no newline at end ?
|
||||
if (!presets_db.size())
|
||||
presets_Default(); // no antenna on txt, use default
|
||||
}
|
||||
populate_Presets();
|
||||
}
|
||||
|
||||
void GlassView::presets_Default()
|
||||
{
|
||||
void GlassView::txtline_process(std::string &line)
|
||||
{
|
||||
if (line.find("#") != std::string::npos)
|
||||
return; // Line is just a comment
|
||||
|
||||
size_t comma = line.find(","); // Get first comma position
|
||||
if (comma == std::string::npos)
|
||||
return; // No comma at all
|
||||
|
||||
size_t previous = 0;
|
||||
preset_entry new_preset;
|
||||
|
||||
new_preset.min = std::stoi(line.substr(0, comma));
|
||||
if (!new_preset.min)
|
||||
return; // No frequency!
|
||||
|
||||
previous = comma + 1;
|
||||
comma = line.find(",", previous); // Search for next delimiter
|
||||
if (comma == std::string::npos)
|
||||
return; // No comma at all
|
||||
|
||||
new_preset.max = std::stoi(line.substr(previous, comma - previous));
|
||||
if (!new_preset.max)
|
||||
return; // No frequency!
|
||||
|
||||
new_preset.label = line.substr(comma + 1);
|
||||
if (new_preset.label.size() == 0)
|
||||
return; // No label ?
|
||||
|
||||
presets_db.push_back(new_preset); // Add this preset.
|
||||
}
|
||||
|
||||
void GlassView::populate_Presets()
|
||||
{
|
||||
using option_t = std::pair<std::string, int32_t>;
|
||||
using options_t = std::vector<option_t>;
|
||||
options_t entries;
|
||||
|
||||
for (preset_entry preset : presets_db)
|
||||
{ // go thru all available presets
|
||||
entries.emplace_back(preset.label, entries.size());
|
||||
}
|
||||
range_presets.set_options(entries);
|
||||
}
|
||||
|
||||
void GlassView::presets_Default()
|
||||
{
|
||||
presets_db.clear();
|
||||
presets_db.push_back({2320, 2560, "DEFAULT WIFI 2.4GHz"});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,187 +1,202 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2020 euquiq
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2020 euquiq
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "portapack.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "receiver_model.hpp"
|
||||
#include "ui_widget.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "ui_receiver.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "analog_audio_app.hpp"
|
||||
#include "spectrum_color_lut.hpp"
|
||||
#ifndef _UI_GLASS
|
||||
#define _UI_GLASS
|
||||
|
||||
namespace ui
|
||||
{
|
||||
#define LOOKING_GLASS_SLICE_WIDTH 20000000 // Each slice bandwidth 20 MHz
|
||||
#define MHZ_DIV 1000000
|
||||
#define X2_MHZ_DIV 2000000
|
||||
#include "ui.hpp"
|
||||
#include "portapack.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "receiver_model.hpp"
|
||||
#include "ui_widget.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "ui_receiver.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "analog_audio_app.hpp"
|
||||
#include "spectrum_color_lut.hpp"
|
||||
|
||||
class GlassView : public View
|
||||
{
|
||||
public:
|
||||
GlassView(NavigationView &nav);
|
||||
namespace ui
|
||||
{
|
||||
#define LOOKING_GLASS_SLICE_WIDTH 20000000 // Each slice bandwidth 20 MHz
|
||||
#define MHZ_DIV 1000000
|
||||
#define X2_MHZ_DIV 2000000
|
||||
|
||||
GlassView( const GlassView &);
|
||||
GlassView& operator=(const GlassView &nav);
|
||||
class GlassView : public View
|
||||
{
|
||||
public:
|
||||
GlassView(NavigationView &nav);
|
||||
|
||||
~GlassView();
|
||||
std::string title() const override { return "Looking Glass"; };
|
||||
GlassView( const GlassView &);
|
||||
GlassView& operator=(const GlassView &nav);
|
||||
|
||||
void on_show() override;
|
||||
void on_hide() override;
|
||||
void focus() override;
|
||||
~GlassView();
|
||||
std::string title() const override { return "LookingGlass"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
void on_show() override;
|
||||
void on_hide() override;
|
||||
void focus() override;
|
||||
|
||||
struct preset_entry
|
||||
{
|
||||
rf::Frequency min{};
|
||||
rf::Frequency max{};
|
||||
std::string label{};
|
||||
};
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
std::vector<preset_entry> presets_db{};
|
||||
|
||||
void on_channel_spectrum(const ChannelSpectrum& spectrum);
|
||||
void do_timers();
|
||||
void on_range_changed();
|
||||
void on_lna_changed(int32_t v_db);
|
||||
void on_vga_changed(int32_t v_db);
|
||||
void add_spectrum_pixel(Color color);
|
||||
void PlotMarker(rf::Frequency pos);
|
||||
void load_Presets();
|
||||
void txtline_process(std::string& line);
|
||||
void populate_Presets();
|
||||
void presets_Default();
|
||||
|
||||
rf::Frequency f_min { 0 }, f_max { 0 };
|
||||
rf::Frequency search_span { 0 };
|
||||
rf::Frequency f_center { 0 };
|
||||
rf::Frequency f_center_ini { 0 };
|
||||
rf::Frequency marker_pixel_step { 0 };
|
||||
rf::Frequency each_bin_size { LOOKING_GLASS_SLICE_WIDTH / 240 };
|
||||
rf::Frequency bins_Hz_size { 0 };
|
||||
uint8_t min_color_power { 0 };
|
||||
uint32_t pixel_index { 0 };
|
||||
std::array<Color, 240> spectrum_row = { 0 };
|
||||
ChannelSpectrumFIFO* fifo { nullptr };
|
||||
uint8_t max_power = 0;
|
||||
|
||||
Labels labels{
|
||||
{{0, 0}, "MIN: MAX: LNA VGA ", Color::light_grey()},
|
||||
{{0, 1 * 16}, " RANGE: FILTER: AMP:", Color::light_grey()},
|
||||
{{0, 2 * 16}, "PRESET:", Color::light_grey()},
|
||||
{{0, 3 * 16}, "MARKER: MHz +/- MHz", Color::light_grey()},
|
||||
{{0, 4 * 16}, "RESOLUTION: (fft trigger)", Color::light_grey()}
|
||||
};
|
||||
|
||||
NumberField field_frequency_min {
|
||||
{ 4 * 8, 0 * 16 },
|
||||
4,
|
||||
{ 0, 6960 },
|
||||
240,
|
||||
' '
|
||||
};
|
||||
|
||||
NumberField field_frequency_max {
|
||||
{ 13 * 8, 0 * 16 },
|
||||
4,
|
||||
{ 240, 7200 },
|
||||
240,
|
||||
' '
|
||||
};
|
||||
|
||||
LNAGainField field_lna {
|
||||
{ 21 * 8, 0 * 16 }
|
||||
};
|
||||
|
||||
VGAGainField field_vga {
|
||||
{ 27 * 8, 0 * 16 }
|
||||
};
|
||||
|
||||
Text text_range{
|
||||
{7 * 8, 1 * 16, 4 * 8, 16},
|
||||
""};
|
||||
|
||||
OptionsField filter_config{
|
||||
{19 * 8, 1 * 16},
|
||||
4,
|
||||
struct preset_entry
|
||||
{
|
||||
{"OFF ", 0},
|
||||
{"MID ", 118}, //85 +25 (110) + a bit more to kill all blue
|
||||
{"HIGH", 202}, //168 + 25 (193)
|
||||
}};
|
||||
rf::Frequency min{};
|
||||
rf::Frequency max{};
|
||||
std::string label{};
|
||||
};
|
||||
|
||||
RFAmpField field_rf_amp{
|
||||
{29 * 8, 1 * 16}};
|
||||
std::vector<preset_entry> presets_db{};
|
||||
|
||||
OptionsField range_presets{
|
||||
{7 * 8, 2 * 16},
|
||||
20,
|
||||
{
|
||||
{" NONE (WIFI 2.4GHz)", 0},
|
||||
}};
|
||||
void on_channel_spectrum(const ChannelSpectrum& spectrum);
|
||||
void do_timers();
|
||||
void on_range_changed();
|
||||
void on_lna_changed(int32_t v_db);
|
||||
void on_vga_changed(int32_t v_db);
|
||||
void add_spectrum_pixel(Color color);
|
||||
void PlotMarker(rf::Frequency pos);
|
||||
void load_Presets();
|
||||
void txtline_process(std::string& line);
|
||||
void populate_Presets();
|
||||
void presets_Default();
|
||||
|
||||
NumberField field_marker{
|
||||
{7 * 8, 3 * 16},
|
||||
4,
|
||||
{0, 7200},
|
||||
25,
|
||||
' '};
|
||||
rf::Frequency f_min { 0 }, f_max { 0 };
|
||||
rf::Frequency search_span { 0 };
|
||||
rf::Frequency f_center { 0 };
|
||||
rf::Frequency f_center_ini { 0 };
|
||||
rf::Frequency marker_pixel_step { 0 };
|
||||
rf::Frequency each_bin_size { LOOKING_GLASS_SLICE_WIDTH / 240 };
|
||||
rf::Frequency bins_Hz_size { 0 };
|
||||
uint8_t min_color_power { 0 };
|
||||
uint32_t pixel_index { 0 };
|
||||
std::array<Color, 240> spectrum_row = { 0 };
|
||||
ChannelSpectrumFIFO* fifo { nullptr };
|
||||
uint8_t max_power = 0;
|
||||
int32_t steps = 250 ; // default of 250 Mhz steps
|
||||
|
||||
Text text_marker_pm{
|
||||
{20 * 8, 3 * 16, 2 * 8, 16},
|
||||
""};
|
||||
Labels labels{
|
||||
{{0, 0}, "MIN: MAX: LNA VGA ", Color::light_grey()},
|
||||
{{0, 1 * 16}, " RANGE: FILTER: AMP:", Color::light_grey()},
|
||||
{{0, 2 * 16}, "PRESET:", Color::light_grey()},
|
||||
{{0, 3 * 16}, "MARKER: MHz +/- MHz", Color::light_grey()},
|
||||
{{0, 4 * 16}, "RESOLUTION: STEPS:", Color::light_grey()}
|
||||
};
|
||||
|
||||
NumberField field_trigger{
|
||||
{11 * 8, 4 * 16},
|
||||
3,
|
||||
{2, 128},
|
||||
2,
|
||||
' '};
|
||||
NumberField field_frequency_min {
|
||||
{ 4 * 8, 0 * 16 },
|
||||
4,
|
||||
{ 0, 7199 },
|
||||
1, // number of steps by encoder delta
|
||||
' '
|
||||
};
|
||||
|
||||
NumberField field_frequency_max {
|
||||
{ 13 * 8, 0 * 16 },
|
||||
4,
|
||||
{ 1, 7200 },
|
||||
1, // number of steps by encoder delta
|
||||
' '
|
||||
};
|
||||
|
||||
LNAGainField field_lna {
|
||||
{ 21 * 8, 0 * 16 }
|
||||
};
|
||||
|
||||
VGAGainField field_vga {
|
||||
{ 27 * 8, 0 * 16 }
|
||||
};
|
||||
|
||||
Text text_range{
|
||||
{7 * 8, 1 * 16, 4 * 8, 16},
|
||||
""};
|
||||
|
||||
OptionsField steps_config{
|
||||
{ 22 * 8, 4 * 16},
|
||||
4,
|
||||
{
|
||||
{"1", 1},
|
||||
{"50", 50},
|
||||
{"100", 100},
|
||||
{"250", 250},
|
||||
{"500", 500},
|
||||
{"1000", 1000},
|
||||
}};
|
||||
|
||||
OptionsField filter_config{
|
||||
{19 * 8, 1 * 16},
|
||||
4,
|
||||
{
|
||||
{"OFF ", 0},
|
||||
{"MID ", 118}, //85 +25 (110) + a bit more to kill all blue
|
||||
{"HIGH", 202}, //168 + 25 (193)
|
||||
}};
|
||||
|
||||
RFAmpField field_rf_amp{
|
||||
{29 * 8, 1 * 16}};
|
||||
|
||||
OptionsField range_presets{
|
||||
{7 * 8, 2 * 16},
|
||||
20,
|
||||
{
|
||||
{" NONE (WIFI 2.4GHz)", 0},
|
||||
}};
|
||||
|
||||
NumberField field_marker{
|
||||
{7 * 8, 3 * 16},
|
||||
4,
|
||||
{0, 7200},
|
||||
25,
|
||||
' '};
|
||||
|
||||
Text text_marker_pm{
|
||||
{20 * 8, 3 * 16, 2 * 8, 16},
|
||||
""};
|
||||
|
||||
NumberField field_trigger{
|
||||
{11 * 8, 4 * 16},
|
||||
3,
|
||||
{2, 128},
|
||||
2,
|
||||
' '};
|
||||
|
||||
|
||||
MessageHandlerRegistration message_handler_spectrum_config {
|
||||
Message::ID::ChannelSpectrumConfig,
|
||||
[this](const Message* const p) {
|
||||
const auto message = *reinterpret_cast<const ChannelSpectrumConfigMessage*>(p);
|
||||
this->fifo = message.fifo;
|
||||
}
|
||||
};
|
||||
MessageHandlerRegistration message_handler_frame_sync {
|
||||
Message::ID::DisplayFrameSync,
|
||||
[this](const Message* const) {
|
||||
if( this->fifo ) {
|
||||
ChannelSpectrum channel_spectrum;
|
||||
while( fifo->out(channel_spectrum) ) {
|
||||
this->on_channel_spectrum(channel_spectrum);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
MessageHandlerRegistration message_handler_spectrum_config {
|
||||
Message::ID::ChannelSpectrumConfig,
|
||||
[this](const Message* const p) {
|
||||
const auto message = *reinterpret_cast<const ChannelSpectrumConfigMessage*>(p);
|
||||
this->fifo = message.fifo;
|
||||
}
|
||||
};
|
||||
MessageHandlerRegistration message_handler_frame_sync {
|
||||
Message::ID::DisplayFrameSync,
|
||||
[this](const Message* const) {
|
||||
if( this->fifo ) {
|
||||
ChannelSpectrum channel_spectrum;
|
||||
while( fifo->out(channel_spectrum) ) {
|
||||
this->on_channel_spectrum(channel_spectrum);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -57,13 +57,13 @@ static msg_t ookthread_fn(void * arg) {
|
||||
v = (symbol < 2) ? 1 : 0; // TX on for dot or dash, off for pause
|
||||
delay = morse_symbols[symbol];
|
||||
|
||||
gpio_tx.write(v);
|
||||
gpio_og_tx.write(v);
|
||||
arg_c->on_tx_progress(i, false);
|
||||
|
||||
chThdSleepMilliseconds(delay * arg_c->time_unit_ms);
|
||||
}
|
||||
|
||||
gpio_tx.write(0); // Ensure TX is off
|
||||
gpio_og_tx.write(0); // Ensure TX is off
|
||||
arg_c->on_tx_progress(0, true);
|
||||
chThdExit(0);
|
||||
|
||||
|
||||
@@ -524,15 +524,21 @@ namespace ui {
|
||||
if(frequency_list[index].description.size() > 0) desc_cycle.set( frequency_list[index].description ); //Show new description
|
||||
}
|
||||
big_display.set_style(&style_white);
|
||||
if( !userpause )
|
||||
button_pause.set_text("<PAUSE>");
|
||||
else
|
||||
button_pause.set_text("<RESUME>");
|
||||
}
|
||||
else if( freq_lock == 1 && recon_lock_nb_match != 1 )
|
||||
{
|
||||
//STARTING LOCK FREQ
|
||||
big_display.set_style(&style_yellow);
|
||||
button_pause.set_text("<SKPLCK>");
|
||||
}
|
||||
else if( index < 1000 && freq_lock >= recon_thread -> get_lock_nb_match() )
|
||||
{
|
||||
big_display.set_style( &style_green);
|
||||
button_pause.set_text("<UNLOCK>");
|
||||
|
||||
//FREQ IS STRONG: GREEN and recon will pause when on_statistics_update()
|
||||
if( (!scanner_mode) && autosave && last_freq != freq ) {
|
||||
@@ -660,6 +666,7 @@ namespace ui {
|
||||
&field_lock_wait,
|
||||
&button_recon_setup,
|
||||
&button_scanner_mode,
|
||||
&button_looking_glass,
|
||||
&file_name,
|
||||
&rssi,
|
||||
&text_cycle,
|
||||
@@ -875,6 +882,21 @@ namespace ui {
|
||||
nav_.push<AnalogAudioView>();
|
||||
};
|
||||
|
||||
button_looking_glass.on_select = [this](Button&) {
|
||||
recon_thread->stop();
|
||||
nav_.pop();
|
||||
nav_.push<GlassView>();
|
||||
};
|
||||
|
||||
|
||||
rssi.set_focusable(true);
|
||||
rssi.set_peak( true , 1000 );
|
||||
rssi.on_select = [this](RSSI&) {
|
||||
recon_thread->stop();
|
||||
nav_.pop();
|
||||
nav_.push<LevelView>();
|
||||
};
|
||||
|
||||
button_mic_app.on_select = [this](Button&) {
|
||||
recon_thread->stop();
|
||||
nav_.pop();
|
||||
@@ -1091,7 +1113,7 @@ namespace ui {
|
||||
show_max(); /* display step information */
|
||||
text_cycle.set( "MANUAL SEARCH" );
|
||||
button_scanner_mode.set_style( &style_white );
|
||||
button_scanner_mode.set_text( "M-SEARCH" );
|
||||
button_scanner_mode.set_text( "MSEARCH" );
|
||||
file_name.set_style( &style_white );
|
||||
file_name.set( "USE: MANUAL RANGE" );
|
||||
|
||||
@@ -1653,7 +1675,7 @@ namespace ui {
|
||||
|
||||
void ReconView::user_pause() {
|
||||
timer = 0 ; // Will trigger a recon_resume() on_statistics_update, also advancing to next freq.
|
||||
button_pause.set_text("<RESUME>"); //PAUSED, show resume
|
||||
//button_pause.set_text("<RESUME>"); //PAUSED, show resume
|
||||
userpause=true;
|
||||
continuous_lock=false;
|
||||
recon_pause();
|
||||
@@ -1661,7 +1683,7 @@ namespace ui {
|
||||
|
||||
void ReconView::user_resume() {
|
||||
timer = 0 ; // Will trigger a recon_resume() on_statistics_update, also advancing to next freq.
|
||||
button_pause.set_text("<PAUSE>"); //Show button for pause
|
||||
//button_pause.set_text("<PAUSE>"); //Show button for pause
|
||||
userpause=false; // Resume recon
|
||||
continuous_lock=false;
|
||||
recon_resume();
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#include "analog_audio_app.hpp"
|
||||
#include "audio.hpp"
|
||||
#include "ui_mictx.hpp"
|
||||
#include "ui_level.hpp"
|
||||
#include "ui_looking_glass_app.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "string_format.hpp"
|
||||
@@ -264,7 +266,7 @@ namespace ui {
|
||||
};
|
||||
|
||||
RSSI rssi {
|
||||
{ 0 * 16, 2 * 16, 15 * 16, 8 },
|
||||
{ 0 * 16, 2 * 16, 240 - 4 * 8 , 16 },
|
||||
};
|
||||
|
||||
Text text_cycle {
|
||||
@@ -276,7 +278,7 @@ namespace ui {
|
||||
};
|
||||
|
||||
Text desc_cycle {
|
||||
{0, 4 * 16, 240, 16 },
|
||||
{0, 4 * 16, 240 , 16 },
|
||||
};
|
||||
|
||||
/* BigFrequency big_display { //Show frequency in glamour
|
||||
@@ -285,32 +287,36 @@ namespace ui {
|
||||
}; */
|
||||
|
||||
Text big_display { //Show frequency in text mode
|
||||
{ 0, 5 * 16 , 28 * 8, 16 },
|
||||
{ 0, 5 * 16 , 21 * 8, 16 },
|
||||
};
|
||||
|
||||
Text freq_stats { //Show frequency stats in text mode
|
||||
{ 0, 6 * 16 , 28 * 8, 16 },
|
||||
{ 0, 6 * 16 , 21 * 8, 16 },
|
||||
};
|
||||
|
||||
Text text_timer { //Show frequency stats in text mode
|
||||
{ 0, 7 * 16 , 28 * 8, 16 },
|
||||
{ 0, 7 * 16 , 21 * 8, 16 },
|
||||
};
|
||||
|
||||
Button button_recon_setup {
|
||||
{ 25 * 8 , 2 * 16 + 8 , 4 * 8, 28 },
|
||||
{ 240 - 4 * 8 , 2 * 16 , 4 * 8, 28 },
|
||||
"OPT"
|
||||
};
|
||||
|
||||
Button button_looking_glass {
|
||||
{ 240 - 5 * 8 , 6 * 16 - 4 , 5 * 8, 28 },
|
||||
"GLASS"
|
||||
};
|
||||
|
||||
Button button_scanner_mode {
|
||||
{ 21 * 8 , 8 * 16 , 9 * 8, 28 },
|
||||
{ 240 - 8 * 8 , 8 * 16 , 8 * 8, 28 },
|
||||
"RECON"
|
||||
};
|
||||
|
||||
Text file_name { //Show file used
|
||||
{ 0 , 8 * 16 + 4 , 20 * 8, 16 },
|
||||
{ 0 , 8 * 16 + 6 , 21 * 8, 16 },
|
||||
};
|
||||
|
||||
|
||||
ButtonWithEncoder button_manual_start {
|
||||
{ 0 * 8, 11 * 16, 11 * 8, 28 },
|
||||
""
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
~WipeSDView();
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "Wipe SD Card"; };
|
||||
std::string title() const override { return "Wipe sdcard"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
@@ -38,6 +38,8 @@ using namespace portapack;
|
||||
#include "ui_font_fixed_8x16.hpp"
|
||||
#include "cpld_update.hpp"
|
||||
|
||||
#include "freqman.hpp"
|
||||
|
||||
namespace ui {
|
||||
|
||||
SetDateTimeView::SetDateTimeView(
|
||||
@@ -144,6 +146,8 @@ SetRadioView::SetRadioView(
|
||||
}
|
||||
|
||||
add_children({
|
||||
&check_hamitup,
|
||||
&button_hamitup_freq,
|
||||
&check_clkout,
|
||||
&field_clkout_freq,
|
||||
&labels_clkout_khz,
|
||||
@@ -168,6 +172,28 @@ SetRadioView::SetRadioView(
|
||||
EventDispatcher::send_message(message);
|
||||
};
|
||||
|
||||
check_hamitup.set_value(portapack::persistent_memory::config_hamitup());
|
||||
check_hamitup.on_select = [this](Checkbox&, bool v) {
|
||||
portapack::persistent_memory::set_config_hamitup(v);
|
||||
// Retune to take hamitup change in account
|
||||
receiver_model.set_tuning_frequency( portapack::persistent_memory::tuned_frequency() );
|
||||
//Refresh status bar with/out UP!
|
||||
StatusRefreshMessage message { };
|
||||
EventDispatcher::send_message(message);
|
||||
};
|
||||
|
||||
button_hamitup_freq.set_text( to_string_short_freq( portapack::persistent_memory::config_hamitup_freq() ) + "MHz");
|
||||
|
||||
button_hamitup_freq.on_select = [this, &nav](Button& button) {
|
||||
auto new_view = nav.push<FrequencyKeypadView>(portapack::persistent_memory::config_hamitup_freq() );
|
||||
new_view->on_changed = [this, &button](rf::Frequency f) {
|
||||
portapack::persistent_memory::set_config_hamitup_freq( f );
|
||||
// Retune to take hamitup change in account
|
||||
receiver_model.set_tuning_frequency( portapack::persistent_memory::tuned_frequency() );
|
||||
button_hamitup_freq.set_text( "<" + to_string_short_freq( f ) + " MHz>" );
|
||||
};
|
||||
};
|
||||
|
||||
field_clkout_freq.set_value(portapack::persistent_memory::clkout_freq());
|
||||
value_freq_step.set_style(&style_text);
|
||||
|
||||
@@ -376,13 +402,13 @@ SettingsMenuView::SettingsMenuView(NavigationView& nav) {
|
||||
add_items( { { "..", ui::Color::light_grey(),&bitmap_icon_previous, [&nav](){ nav.pop(); } } } );
|
||||
}
|
||||
add_items({
|
||||
{ "Audio", ui::Color::dark_cyan(), &bitmap_icon_speaker, [&nav](){ nav.push<SetAudioView>(); } },
|
||||
{ "Radio", ui::Color::dark_cyan(), &bitmap_icon_options_radio, [&nav](){ nav.push<SetRadioView>(); } },
|
||||
{ "User Interface", ui::Color::dark_cyan(), &bitmap_icon_options_ui, [&nav](){ nav.push<SetUIView>(); } },
|
||||
{ "Date/Time", ui::Color::dark_cyan(), &bitmap_icon_options_datetime, [&nav](){ nav.push<SetDateTimeView>(); } },
|
||||
{ "Calibration", ui::Color::dark_cyan(), &bitmap_icon_options_touch, [&nav](){ nav.push<TouchCalibrationView>(); } },
|
||||
{ "App Settings", ui::Color::dark_cyan(), &bitmap_icon_setup, [&nav](){ nav.push<SetAppSettingsView>(); } },
|
||||
{ "QR Code", ui::Color::dark_cyan(), &bitmap_icon_qr_code, [&nav](){ nav.push<SetQRCodeView>(); } }
|
||||
{ "Audio", ui::Color::dark_cyan(), &bitmap_icon_speaker, [&nav](){ nav.push<SetAudioView>(); } },
|
||||
{ "Radio", ui::Color::dark_cyan(), &bitmap_icon_options_radio, [&nav](){ nav.push<SetRadioView>(); } },
|
||||
{ "User Interface", ui::Color::dark_cyan(), &bitmap_icon_options_ui, [&nav](){ nav.push<SetUIView>(); } },
|
||||
{ "Date/Time", ui::Color::dark_cyan(), &bitmap_icon_options_datetime, [&nav](){ nav.push<SetDateTimeView>(); } },
|
||||
{ "Calibration", ui::Color::dark_cyan(), &bitmap_icon_options_touch, [&nav](){ nav.push<TouchCalibrationView>(); } },
|
||||
{ "App Settings", ui::Color::dark_cyan(), &bitmap_icon_setup, [&nav](){ nav.push<SetAppSettingsView>(); } },
|
||||
{ "QR Code", ui::Color::dark_cyan(), &bitmap_icon_qr_code, [&nav](){ nav.push<SetQRCodeView>(); } }
|
||||
});
|
||||
set_max_rows(2); // allow wider buttons
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public:
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "Radio settings"; };
|
||||
std::string title() const override { return "Radio"; };
|
||||
|
||||
private:
|
||||
const Style style_text {
|
||||
@@ -154,7 +154,7 @@ private:
|
||||
{ { 6 * 8, 4 * 16 }, "PPM", Color::light_grey() },
|
||||
};
|
||||
|
||||
Checkbox check_clkout {
|
||||
Checkbox check_clkout {
|
||||
{ 18, (6 * 16 - 4) },
|
||||
13,
|
||||
"Enable CLKOUT"
|
||||
@@ -193,11 +193,21 @@ private:
|
||||
};
|
||||
|
||||
Checkbox check_bias {
|
||||
{ 28, 13 * 16 },
|
||||
{ 18, 12 * 16 },
|
||||
5,
|
||||
"Turn on bias voltage"
|
||||
};
|
||||
|
||||
Checkbox check_hamitup {
|
||||
{ 18, 14 * 16},
|
||||
7,
|
||||
"HamItUp"
|
||||
};
|
||||
Button button_hamitup_freq {
|
||||
{ 240 - 15 * 8 , 14 * 16 , 15 * 8 , 24 },
|
||||
"",
|
||||
};
|
||||
|
||||
Button button_save {
|
||||
{ 2 * 8, 16 * 16, 12 * 8, 32 },
|
||||
"Save"
|
||||
@@ -219,7 +229,7 @@ public:
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "UI settings"; };
|
||||
std::string title() const override { return "UI"; };
|
||||
|
||||
private:
|
||||
|
||||
@@ -299,7 +309,7 @@ public:
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "App Settings"; };
|
||||
std::string title() const override { return "AppSettings"; };
|
||||
|
||||
private:
|
||||
|
||||
@@ -332,7 +342,7 @@ public:
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "Audio settings"; };
|
||||
std::string title() const override { return "Audio"; };
|
||||
|
||||
private:
|
||||
Labels labels {
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "Radiosonde RX"; };
|
||||
std::string title() const override { return "Radiosnd RX"; };
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
void focus() override;
|
||||
void paint(Painter&) override;
|
||||
|
||||
std::string title() const override { return "SSTV TX (beta)"; };
|
||||
std::string title() const override { return "SSTV TX"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
@@ -110,7 +110,7 @@ public:
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "TouchTunes TX"; };
|
||||
std::string title() const override { return "TouchTunes"; };
|
||||
|
||||
private:
|
||||
uint32_t scan_button_index { };
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace ui
|
||||
public:
|
||||
WhipCalcView(NavigationView &nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "Antenna length"; };
|
||||
std::string title() const override { return "Ant. length"; };
|
||||
|
||||
private:
|
||||
const double speed_of_light_mps = 299792458.0; // m/s
|
||||
|
||||
@@ -307,7 +307,7 @@ void run_image(const portapack::spi_flash::image_tag_t image_tag) {
|
||||
|
||||
creg::m4txevent::clear();
|
||||
|
||||
m4_init(image_tag, portapack::memory::map::m4_code);
|
||||
m4_init(image_tag, portapack::memory::map::m4_code, false);
|
||||
baseband_image_running = true;
|
||||
|
||||
creg::m4txevent::enable();
|
||||
|
||||
+2255
-2233
File diff suppressed because it is too large
Load Diff
@@ -41,12 +41,18 @@ constexpr si5351::Inputs si5351_inputs {
|
||||
static_assert(si5351_inputs.f_xtal == si5351_xtal_f, "XTAL output frequency wrong");
|
||||
static_assert(si5351_inputs.f_clkin_out() == si5351_clkin_f, "CLKIN output frequency wrong");
|
||||
|
||||
constexpr si5351::PLLInputSource::Type si5351_pll_input_sources {
|
||||
constexpr si5351::PLLInputSource::Type si5351c_pll_input_sources {
|
||||
si5351::PLLInputSource::PLLA_Source_XTAL
|
||||
| si5351::PLLInputSource::PLLB_Source_CLKIN
|
||||
| si5351::PLLInputSource::CLKIN_Div1
|
||||
};
|
||||
|
||||
constexpr si5351::PLLInputSource::Type si5351a_pll_input_sources {
|
||||
si5351::PLLInputSource::PLLA_Source_XTAL
|
||||
| si5351::PLLInputSource::PLLB_Source_XTAL
|
||||
| si5351::PLLInputSource::CLKIN_Div1
|
||||
};
|
||||
|
||||
constexpr si5351::PLL si5351_pll_xtal_25m {
|
||||
.f_in = si5351_inputs.f_xtal,
|
||||
.a = 32,
|
||||
@@ -61,7 +67,8 @@ constexpr si5351::PLL si5351_pll_clkin_10m {
|
||||
.b = 0,
|
||||
.c = 1,
|
||||
};
|
||||
constexpr auto si5351_pll_b_clkin_reg = si5351_pll_clkin_10m.reg(1);
|
||||
constexpr auto si5351c_pll_b_clkin_reg = si5351_pll_clkin_10m.reg(1);
|
||||
constexpr auto si5351a_pll_a_clkin_reg = si5351_pll_clkin_10m.reg(0);
|
||||
|
||||
static_assert(si5351_pll_xtal_25m.f_vco() == si5351_vco_f, "PLL XTAL frequency wrong");
|
||||
static_assert(si5351_pll_xtal_25m.p1() == 3584, "PLL XTAL P1 wrong");
|
||||
@@ -98,7 +105,7 @@ constexpr si5351::MultisynthFractional si5351_ms_0_8m {
|
||||
.c = 1,
|
||||
.r_div = 1,
|
||||
};
|
||||
constexpr auto si5351_ms_0_8m_reg = si5351_ms_0_8m.reg(clock_generator_output_codec);
|
||||
constexpr auto si5351c_ms_0_8m_reg = si5351_ms_0_8m.reg(clock_generator_output_og_codec);
|
||||
|
||||
constexpr si5351::MultisynthFractional si5351_ms_group {
|
||||
.f_src = si5351_vco_f,
|
||||
@@ -107,8 +114,17 @@ constexpr si5351::MultisynthFractional si5351_ms_group {
|
||||
.c = 1,
|
||||
.r_div = 0,
|
||||
};
|
||||
constexpr auto si5351_ms_1_group_reg = si5351_ms_group.reg(clock_generator_output_cpld);
|
||||
constexpr auto si5351_ms_2_group_reg = si5351_ms_group.reg(clock_generator_output_sgpio);
|
||||
constexpr auto si5351c_ms_1_group_reg = si5351_ms_group.reg(clock_generator_output_og_cpld);
|
||||
constexpr auto si5351c_ms_2_group_reg = si5351_ms_group.reg(clock_generator_output_og_sgpio);
|
||||
|
||||
constexpr si5351::MultisynthFractional si5351_ms_16m {
|
||||
.f_src = si5351_vco_f,
|
||||
.a = 50,
|
||||
.b = 0,
|
||||
.c = 1,
|
||||
.r_div = 0,
|
||||
};
|
||||
constexpr auto si5351a_ms_1_sgpio_16m_reg = si5351_ms_16m.reg(clock_generator_output_r9_sgpio);
|
||||
|
||||
constexpr si5351::MultisynthFractional si5351_ms_10m {
|
||||
.f_src = si5351_vco_f,
|
||||
@@ -117,7 +133,8 @@ constexpr si5351::MultisynthFractional si5351_ms_10m {
|
||||
.c = 1,
|
||||
.r_div = 0,
|
||||
};
|
||||
constexpr auto si5351_ms_3_10m_reg = si5351_ms_10m.reg(3);
|
||||
constexpr auto si5351c_ms_3_10m_reg = si5351_ms_10m.reg(3);
|
||||
constexpr auto si5351a_ms_2_mcu_10m_reg = si5351_ms_10m.reg(clock_generator_output_r9_mcu_clkin);
|
||||
|
||||
constexpr si5351::MultisynthFractional si5351_ms_40m {
|
||||
.f_src = si5351_vco_f,
|
||||
@@ -128,10 +145,11 @@ constexpr si5351::MultisynthFractional si5351_ms_40m {
|
||||
};
|
||||
|
||||
constexpr auto si5351_ms_rffc5072 = si5351_ms_40m;
|
||||
constexpr auto si5351_ms_max2837 = si5351_ms_40m;
|
||||
constexpr auto si5351_ms_max283x = si5351_ms_40m;
|
||||
|
||||
constexpr auto si5351_ms_4_reg = si5351_ms_rffc5072.reg(clock_generator_output_first_if);
|
||||
constexpr auto si5351_ms_5_reg = si5351_ms_max2837.reg(clock_generator_output_second_if);
|
||||
constexpr auto si5351c_ms_4_reg = si5351_ms_rffc5072.reg(clock_generator_output_og_first_if);
|
||||
constexpr auto si5351c_ms_5_reg = si5351_ms_max283x.reg(clock_generator_output_og_second_if);
|
||||
constexpr auto si5351a_ms_0_if_40m_reg = si5351_ms_40m.reg(clock_generator_output_r9_if);
|
||||
|
||||
static_assert(si5351_ms_10m.f_out() == 10000000, "MS 10MHz f_out wrong");
|
||||
static_assert(si5351_ms_10m.p1() == 9728, "MS 10MHz p1 wrong");
|
||||
@@ -139,14 +157,8 @@ static_assert(si5351_ms_10m.p2() == 0, "MS 10MHz p2 wrong");
|
||||
static_assert(si5351_ms_10m.p3() == 1, "MS 10MHz p3 wrong");
|
||||
|
||||
static_assert(si5351_ms_rffc5072.f_out() == rffc5072_reference_f, "RFFC5072 reference f_out wrong");
|
||||
// static_assert(si5351_ms_50m.p1() == 2048, "MS 50MHz P1 wrong");
|
||||
// static_assert(si5351_ms_50m.p2() == 0, "MS 50MHz P2 wrong");
|
||||
// static_assert(si5351_ms_50m.p3() == 1, "MS 50MHz P3 wrong");
|
||||
|
||||
static_assert(si5351_ms_max2837.f_out() == max2837_reference_f, "MAX2837 reference f_out wrong");
|
||||
// static_assert(si5351_ms_50m.p1() == 2048, "MS 40MHz P1 wrong");
|
||||
// static_assert(si5351_ms_50m.p2() == 0, "MS 40MHz P2 wrong");
|
||||
// static_assert(si5351_ms_50m.p3() == 1, "MS 40MHz P3 wrong");
|
||||
static_assert(si5351_ms_max283x.f_out() == max283x_reference_f, "MAX283x reference f_out wrong");
|
||||
|
||||
constexpr si5351::MultisynthInteger si5351_ms_int_off {
|
||||
.f_src = si5351_vco_f,
|
||||
@@ -154,40 +166,60 @@ constexpr si5351::MultisynthInteger si5351_ms_int_off {
|
||||
.r_div = 0,
|
||||
};
|
||||
|
||||
constexpr si5351::MultisynthInteger si5351_ms_int_mcu_clkin {
|
||||
constexpr si5351::MultisynthInteger si5351_ms_int_40m {
|
||||
.f_src = si5351_vco_f,
|
||||
.a = 20,
|
||||
.r_div = 0,
|
||||
};
|
||||
|
||||
constexpr auto si5351_ms6_7_off_mcu_clkin_reg = si5351::ms6_7_reg(si5351_ms_int_off, si5351_ms_int_mcu_clkin);
|
||||
constexpr si5351::MultisynthInteger si5351_ms_int_10m {
|
||||
.f_src = si5351_vco_f,
|
||||
.a = 80,
|
||||
.r_div = 0,
|
||||
};
|
||||
|
||||
constexpr auto si5351c_ms_int_mcu_clkin = si5351_ms_int_40m;
|
||||
constexpr auto si5351a_ms_int_mcu_clkin = si5351_ms_int_10m;
|
||||
|
||||
constexpr auto si5351c_ms6_7_off_mcu_clkin_reg = si5351::ms6_7_reg(si5351_ms_int_off, si5351c_ms_int_mcu_clkin);
|
||||
constexpr auto si5351a_ms6_7_off_reg = si5351::ms6_7_reg(si5351_ms_int_off, si5351_ms_int_off);
|
||||
|
||||
static_assert(si5351_ms_int_off.f_out() == 3137254, "MS int off f_out wrong");
|
||||
static_assert(si5351_ms_int_off.p1() == 255, "MS int off P1 wrong");
|
||||
|
||||
static_assert(si5351_ms_int_mcu_clkin.f_out() == mcu_clkin_f, "MS int MCU CLKIN f_out wrong");
|
||||
// static_assert(si5351_ms_int_mcu_clkin.p1() == 20, "MS int MCU CLKIN P1 wrong");
|
||||
static_assert(si5351c_ms_int_mcu_clkin.f_out() == mcu_clkin_og_f, "MS int MCU CLKIN OG f_out wrong");
|
||||
static_assert(si5351a_ms_int_mcu_clkin.f_out() == mcu_clkin_r9_f, "MS int MCU CLKIN r9 f_out wrong");
|
||||
|
||||
using namespace si5351;
|
||||
|
||||
static constexpr ClockControl::MultiSynthSource get_reference_clock_generator_pll(const ClockManager::ReferenceSource reference_source) {
|
||||
static constexpr ClockControl::MultiSynthSource get_si5351c_reference_clock_generator_pll(const ClockManager::ReferenceSource reference_source) {
|
||||
return (reference_source == ClockManager::ReferenceSource::Xtal)
|
||||
? ClockControl::MultiSynthSource::PLLA
|
||||
: ClockControl::MultiSynthSource::PLLB
|
||||
;
|
||||
}
|
||||
|
||||
constexpr ClockControls si5351_clock_control_common { {
|
||||
{ ClockControl::ClockCurrentDrive::_8mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, get_reference_clock_generator_pll(ClockManager::ReferenceSource::Xtal), ClockControl::MultiSynthMode::Fractional, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_2mA, ClockControl::ClockSource::MS_Group, ClockControl::ClockInvert::Invert, get_reference_clock_generator_pll(ClockManager::ReferenceSource::Xtal), ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_2mA, ClockControl::ClockSource::MS_Group, ClockControl::ClockInvert::Normal, get_reference_clock_generator_pll(ClockManager::ReferenceSource::Xtal), ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_8mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, get_reference_clock_generator_pll(ClockManager::ReferenceSource::Xtal), ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_6mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Invert, get_reference_clock_generator_pll(ClockManager::ReferenceSource::Xtal), ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_4mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, get_reference_clock_generator_pll(ClockManager::ReferenceSource::Xtal), ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_2mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, get_reference_clock_generator_pll(ClockManager::ReferenceSource::Xtal), ClockControl::MultiSynthMode::Fractional, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_2mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, get_reference_clock_generator_pll(ClockManager::ReferenceSource::Xtal), ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off },
|
||||
constexpr ClockControls si5351c_clock_control_common { {
|
||||
{ ClockControl::ClockCurrentDrive::_8mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, get_si5351c_reference_clock_generator_pll(ClockManager::ReferenceSource::Xtal), ClockControl::MultiSynthMode::Fractional, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_2mA, ClockControl::ClockSource::MS_Group, ClockControl::ClockInvert::Invert, get_si5351c_reference_clock_generator_pll(ClockManager::ReferenceSource::Xtal), ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_2mA, ClockControl::ClockSource::MS_Group, ClockControl::ClockInvert::Normal, get_si5351c_reference_clock_generator_pll(ClockManager::ReferenceSource::Xtal), ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_8mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, get_si5351c_reference_clock_generator_pll(ClockManager::ReferenceSource::Xtal), ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_6mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Invert, get_si5351c_reference_clock_generator_pll(ClockManager::ReferenceSource::Xtal), ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_4mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, get_si5351c_reference_clock_generator_pll(ClockManager::ReferenceSource::Xtal), ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_2mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, get_si5351c_reference_clock_generator_pll(ClockManager::ReferenceSource::Xtal), ClockControl::MultiSynthMode::Fractional, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_2mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, get_si5351c_reference_clock_generator_pll(ClockManager::ReferenceSource::Xtal), ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off },
|
||||
} };
|
||||
|
||||
constexpr ClockControls si5351a_clock_control_common { {
|
||||
{ ClockControl::ClockCurrentDrive::_6mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_4mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Fractional, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_8mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_2mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_2mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_2mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_2mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off },
|
||||
{ ClockControl::ClockCurrentDrive::_2mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off },
|
||||
} };
|
||||
ClockManager::Reference ClockManager::get_reference() const {
|
||||
return reference;
|
||||
}
|
||||
@@ -212,11 +244,25 @@ void ClockManager::init_clock_generator() {
|
||||
clock_generator.reset();
|
||||
clock_generator.set_crystal_internal_load_capacitance(CrystalInternalLoadCapacitance::XTAL_CL_8pF);
|
||||
clock_generator.enable_fanout();
|
||||
clock_generator.set_pll_input_sources(si5351_pll_input_sources);
|
||||
clock_generator.set_pll_input_sources(hackrf_r9
|
||||
? si5351a_pll_input_sources
|
||||
: si5351c_pll_input_sources);
|
||||
|
||||
auto si5351_clock_control_common = hackrf_r9
|
||||
? si5351a_clock_control_common
|
||||
: si5351c_clock_control_common;
|
||||
|
||||
auto clock_generator_output_mcu_clkin = hackrf_r9
|
||||
? clock_generator_output_r9_mcu_clkin
|
||||
: clock_generator_output_og_mcu_clkin;
|
||||
|
||||
clock_generator.set_clock_control(
|
||||
clock_generator_output_mcu_clkin,
|
||||
si5351_clock_control_common[clock_generator_output_mcu_clkin].clk_src(ClockControl::ClockSource::CLKIN).clk_pdn(ClockControl::ClockPowerDown::Power_On)
|
||||
si5351_clock_control_common[clock_generator_output_mcu_clkin]
|
||||
.clk_src(hackrf_r9
|
||||
? ClockControl::ClockSource::Xtal
|
||||
: ClockControl::ClockSource::CLKIN)
|
||||
.clk_pdn(ClockControl::ClockPowerDown::Power_On)
|
||||
);
|
||||
clock_generator.enable_output(clock_generator_output_mcu_clkin);
|
||||
|
||||
@@ -224,7 +270,10 @@ void ClockManager::init_clock_generator() {
|
||||
|
||||
clock_generator.disable_output(clock_generator_output_mcu_clkin);
|
||||
|
||||
const auto ref_pll = get_reference_clock_generator_pll(reference.source);
|
||||
const auto ref_pll = hackrf_r9
|
||||
? ClockControl::MultiSynthSource::PLLA
|
||||
: get_si5351c_reference_clock_generator_pll(reference.source);
|
||||
|
||||
const ClockControls si5351_clock_control = ClockControls { {
|
||||
si5351_clock_control_common[0].ms_src(ref_pll),
|
||||
si5351_clock_control_common[1].ms_src(ref_pll),
|
||||
@@ -237,21 +286,35 @@ void ClockManager::init_clock_generator() {
|
||||
} };
|
||||
clock_generator.set_clock_control(si5351_clock_control);
|
||||
|
||||
clock_generator.write(si5351_pll_a_xtal_reg);
|
||||
clock_generator.write(si5351_pll_b_clkin_reg);
|
||||
clock_generator.write(si5351_ms_0_8m_reg);
|
||||
clock_generator.write(si5351_ms_1_group_reg);
|
||||
clock_generator.write(si5351_ms_2_group_reg);
|
||||
clock_generator.write(si5351_ms_3_10m_reg);
|
||||
clock_generator.write(si5351_ms_4_reg);
|
||||
clock_generator.write(si5351_ms_5_reg);
|
||||
clock_generator.write(si5351_ms6_7_off_mcu_clkin_reg);
|
||||
if (hackrf_r9) {
|
||||
const PLLReg pll_reg = (reference.source == ReferenceSource::Xtal)
|
||||
? si5351_pll_a_xtal_reg
|
||||
: si5351a_pll_a_clkin_reg;
|
||||
clock_generator.write(pll_reg);
|
||||
clock_generator.write(si5351a_ms_0_if_40m_reg);
|
||||
clock_generator.write(si5351a_ms_1_sgpio_16m_reg);
|
||||
clock_generator.write(si5351a_ms_2_mcu_10m_reg);
|
||||
clock_generator.write(si5351a_ms6_7_off_reg);
|
||||
} else {
|
||||
clock_generator.write(si5351_pll_a_xtal_reg);
|
||||
clock_generator.write(si5351c_pll_b_clkin_reg);
|
||||
clock_generator.write(si5351c_ms_0_8m_reg);
|
||||
clock_generator.write(si5351c_ms_1_group_reg);
|
||||
clock_generator.write(si5351c_ms_2_group_reg);
|
||||
clock_generator.write(si5351c_ms_3_10m_reg);
|
||||
clock_generator.write(si5351c_ms_4_reg);
|
||||
clock_generator.write(si5351c_ms_5_reg);
|
||||
clock_generator.write(si5351c_ms6_7_off_mcu_clkin_reg);
|
||||
}
|
||||
|
||||
clock_generator.reset_plls();
|
||||
|
||||
// Wait for both PLLs to lock.
|
||||
// TODO: Disable the unused PLL?
|
||||
const uint8_t device_status_mask = (ref_pll == ClockControl::MultiSynthSource::PLLB) ? 0x40 : 0x20;
|
||||
// Wait for PLL(s) to lock.
|
||||
uint8_t device_status_mask = hackrf_r9
|
||||
? 0x20
|
||||
: (ref_pll == ClockControl::MultiSynthSource::PLLB)
|
||||
? 0x40
|
||||
: 0x20;
|
||||
while((clock_generator.device_status() & device_status_mask) != 0);
|
||||
|
||||
clock_generator.set_clock_control(
|
||||
@@ -268,12 +331,18 @@ uint32_t ClockManager::measure_gp_clkin_frequency() {
|
||||
return get_frequency_monitor_measurement_in_hertz();
|
||||
}
|
||||
|
||||
bool ClockManager::loss_of_signal() {
|
||||
return hackrf_r9
|
||||
? clock_generator.plla_loss_of_signal()
|
||||
: clock_generator.clkin_loss_of_signal();
|
||||
}
|
||||
|
||||
ClockManager::ReferenceSource ClockManager::detect_reference_source() {
|
||||
if( clock_generator.clkin_loss_of_signal() ) {
|
||||
if(loss_of_signal()) {
|
||||
// No external reference. Turn on PortaPack reference (if present).
|
||||
portapack_tcxo_enable();
|
||||
|
||||
if( clock_generator.clkin_loss_of_signal() ) {
|
||||
if(loss_of_signal()) {
|
||||
// No PortaPack reference was detected. Choose the HackRF crystal as the reference.
|
||||
return ReferenceSource::Xtal;
|
||||
} else {
|
||||
@@ -285,6 +354,11 @@ ClockManager::ReferenceSource ClockManager::detect_reference_source() {
|
||||
}
|
||||
|
||||
ClockManager::Reference ClockManager::choose_reference() {
|
||||
if (hackrf_r9) {
|
||||
gpio_r9_clkin_en.write(1);
|
||||
volatile uint32_t delay = 240000 + 24000;
|
||||
while(delay--);
|
||||
}
|
||||
const auto detected_reference = detect_reference_source();
|
||||
|
||||
if( (detected_reference == ReferenceSource::External) ||
|
||||
@@ -296,8 +370,12 @@ ClockManager::Reference ClockManager::choose_reference() {
|
||||
}
|
||||
}
|
||||
|
||||
if (hackrf_r9) {
|
||||
gpio_r9_clkin_en.write(0);
|
||||
}
|
||||
|
||||
portapack_tcxo_disable();
|
||||
return { ReferenceSource::Xtal, 10000000 };
|
||||
return { ReferenceSource::Xtal, 25000000 };
|
||||
}
|
||||
|
||||
void ClockManager::shutdown() {
|
||||
@@ -305,18 +383,26 @@ void ClockManager::shutdown() {
|
||||
}
|
||||
|
||||
void ClockManager::enable_codec_clocks() {
|
||||
clock_generator.enable_clock(clock_generator_output_codec);
|
||||
clock_generator.enable_clock(clock_generator_output_cpld);
|
||||
clock_generator.enable_clock(clock_generator_output_sgpio);
|
||||
if (hackrf_r9) {
|
||||
clock_generator.enable_clock(clock_generator_output_r9_sgpio);
|
||||
} else {
|
||||
clock_generator.enable_clock(clock_generator_output_og_codec);
|
||||
clock_generator.enable_clock(clock_generator_output_og_cpld);
|
||||
clock_generator.enable_clock(clock_generator_output_og_sgpio);
|
||||
}
|
||||
/* Turn on all outputs at the same time. This probably doesn't ensure
|
||||
* their phase relationships. For example, clocks that output frequencies
|
||||
* in a 2:1 relationship may start with the slower clock high or low?
|
||||
*/
|
||||
clock_generator.enable_output_mask(
|
||||
(1U << clock_generator_output_codec)
|
||||
| (1U << clock_generator_output_cpld)
|
||||
| (1U << clock_generator_output_sgpio)
|
||||
);
|
||||
if (hackrf_r9) {
|
||||
clock_generator.enable_output_mask(1U << clock_generator_output_r9_sgpio);
|
||||
} else {
|
||||
clock_generator.enable_output_mask(
|
||||
(1U << clock_generator_output_og_codec)
|
||||
| (1U << clock_generator_output_og_cpld)
|
||||
| (1U << clock_generator_output_og_sgpio)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void ClockManager::disable_codec_clocks() {
|
||||
@@ -324,34 +410,45 @@ void ClockManager::disable_codec_clocks() {
|
||||
* be enabled for the output to come to rest at the state specified by
|
||||
* CLKx_DISABLE_STATE.
|
||||
*/
|
||||
clock_generator.disable_output_mask(
|
||||
(1U << clock_generator_output_codec)
|
||||
| (1U << clock_generator_output_cpld)
|
||||
| (1U << clock_generator_output_sgpio)
|
||||
);
|
||||
clock_generator.disable_clock(clock_generator_output_codec);
|
||||
clock_generator.disable_clock(clock_generator_output_cpld);
|
||||
clock_generator.disable_clock(clock_generator_output_sgpio);
|
||||
if (hackrf_r9) {
|
||||
clock_generator.disable_output_mask(1U << clock_generator_output_r9_sgpio);
|
||||
clock_generator.disable_clock(clock_generator_output_r9_sgpio);
|
||||
} else {
|
||||
clock_generator.disable_output_mask(
|
||||
(1U << clock_generator_output_og_codec)
|
||||
| (1U << clock_generator_output_og_cpld)
|
||||
| (1U << clock_generator_output_og_sgpio)
|
||||
);
|
||||
clock_generator.disable_clock(clock_generator_output_og_codec);
|
||||
clock_generator.disable_clock(clock_generator_output_og_cpld);
|
||||
clock_generator.disable_clock(clock_generator_output_og_sgpio);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ClockManager::enable_first_if_clock() {
|
||||
clock_generator.enable_clock(clock_generator_output_first_if);
|
||||
clock_generator.enable_output_mask(1U << clock_generator_output_first_if);
|
||||
void ClockManager::enable_if_clocks() {
|
||||
if (hackrf_r9) {
|
||||
clock_generator.enable_clock(clock_generator_output_r9_if);
|
||||
clock_generator.enable_output_mask(1U << clock_generator_output_r9_if);
|
||||
} else {
|
||||
clock_generator.enable_clock(clock_generator_output_og_first_if);
|
||||
clock_generator.enable_output_mask(1U << clock_generator_output_og_first_if);
|
||||
clock_generator.enable_clock(clock_generator_output_og_second_if);
|
||||
clock_generator.enable_output_mask(1U << clock_generator_output_og_second_if);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ClockManager::disable_first_if_clock() {
|
||||
clock_generator.disable_output_mask(1U << clock_generator_output_first_if);
|
||||
clock_generator.disable_clock(clock_generator_output_first_if);
|
||||
}
|
||||
|
||||
void ClockManager::enable_second_if_clock() {
|
||||
clock_generator.enable_clock(clock_generator_output_second_if);
|
||||
clock_generator.enable_output_mask(1U << clock_generator_output_second_if);
|
||||
}
|
||||
|
||||
void ClockManager::disable_second_if_clock() {
|
||||
clock_generator.disable_output_mask(1U << clock_generator_output_second_if);
|
||||
clock_generator.disable_clock(clock_generator_output_second_if);
|
||||
void ClockManager::disable_if_clocks() {
|
||||
if (hackrf_r9) {
|
||||
clock_generator.disable_output_mask(1U << clock_generator_output_r9_if);
|
||||
clock_generator.disable_clock(clock_generator_output_r9_if);
|
||||
} else {
|
||||
clock_generator.disable_output_mask(1U << clock_generator_output_og_first_if);
|
||||
clock_generator.disable_clock(clock_generator_output_og_first_if);
|
||||
clock_generator.disable_output_mask(1U << clock_generator_output_og_second_if);
|
||||
clock_generator.disable_clock(clock_generator_output_og_second_if);
|
||||
}
|
||||
}
|
||||
|
||||
void ClockManager::set_sampling_frequency(const uint32_t frequency) {
|
||||
@@ -360,14 +457,21 @@ void ClockManager::set_sampling_frequency(const uint32_t frequency) {
|
||||
* necessary to change the MS0 synth frequency, and ensure the output
|
||||
* is divided by two.
|
||||
*/
|
||||
clock_generator.set_ms_frequency(clock_generator_output_codec, frequency * 2, si5351_vco_f, 1);
|
||||
if (hackrf_r9) {
|
||||
clock_generator.set_ms_frequency(clock_generator_output_r9_sgpio, frequency * 2, si5351_vco_f, 0);
|
||||
} else {
|
||||
clock_generator.set_ms_frequency(clock_generator_output_og_codec, frequency * 2, si5351_vco_f, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void ClockManager::set_reference_ppb(const int32_t ppb) {
|
||||
/* NOTE: This adjustment only affects PLLA, which is derived from the 25MHz crystal.
|
||||
* It is assumed an external clock coming in to PLLB is sufficiently accurate as to not need adjustment.
|
||||
/* NOTE: This adjustment only affects PLLA when it is derived from the 25MHz crystal.
|
||||
* It is assumed an external clock coming in to CLKIN/PLLB is sufficiently accurate as to not need adjustment.
|
||||
* TODO: Revisit the above policy. It may be good to allow adjustment of the external reference too.
|
||||
*/
|
||||
if (hackrf_r9 && reference.source != ReferenceSource::Xtal) {
|
||||
return;
|
||||
}
|
||||
constexpr uint32_t pll_multiplier = si5351_pll_xtal_25m.a;
|
||||
constexpr uint32_t denominator = 1000000 / pll_multiplier;
|
||||
const uint32_t new_a = (ppb >= 0) ? pll_multiplier : (pll_multiplier - 1);
|
||||
@@ -425,11 +529,13 @@ void ClockManager::start_audio_pll() {
|
||||
|
||||
/* For 40MHz clock source, 48kHz audio rate, 256Fs MCLK:
|
||||
* Fout=12.288MHz, Fcco=491.52MHz
|
||||
* PSEL=20, NSEL=125, MSEL=768
|
||||
* OG: PSEL=20, NSEL=125, MSEL=768
|
||||
* PDEC=31, NDEC=45, MDEC=30542
|
||||
* r9: PSEL=20, NSEL=125, MSEL=3072
|
||||
* PDEC=31, NDEC=45, MDEC=8308
|
||||
*/
|
||||
cgu::pll0audio::mdiv({
|
||||
.mdec = 30542,
|
||||
.mdec = hackrf_r9 ? 8308UL : 30542UL,
|
||||
});
|
||||
cgu::pll0audio::np_div({
|
||||
.pdec = 31,
|
||||
@@ -467,18 +573,25 @@ void ClockManager::stop_audio_pll() {
|
||||
|
||||
void ClockManager::enable_clock_output(bool enable) {
|
||||
if(enable) {
|
||||
clock_generator.enable_output(clock_generator_output_clkout);
|
||||
clock_generator.enable_output(clock_generator_output_og_clkout);
|
||||
if(portapack::persistent_memory::clkout_freq() < 1000) {
|
||||
clock_generator.set_ms_frequency(clock_generator_output_clkout, portapack::persistent_memory::clkout_freq() * 128000, si5351_vco_f, 7);
|
||||
clock_generator.set_ms_frequency(clock_generator_output_og_clkout, portapack::persistent_memory::clkout_freq() * 128000, si5351_vco_f, 7);
|
||||
} else {
|
||||
clock_generator.set_ms_frequency(clock_generator_output_clkout, portapack::persistent_memory::clkout_freq() * 1000, si5351_vco_f, 0);
|
||||
clock_generator.set_ms_frequency(clock_generator_output_og_clkout, portapack::persistent_memory::clkout_freq() * 1000, si5351_vco_f, 0);
|
||||
}
|
||||
} else {
|
||||
clock_generator.disable_output(clock_generator_output_clkout);
|
||||
clock_generator.disable_output(clock_generator_output_og_clkout);
|
||||
}
|
||||
|
||||
auto si5351_clock_control_common = hackrf_r9
|
||||
? si5351a_clock_control_common
|
||||
: si5351c_clock_control_common;
|
||||
const auto ref_pll = hackrf_r9
|
||||
? ClockControl::MultiSynthSource::PLLA
|
||||
: get_si5351c_reference_clock_generator_pll(reference.source);
|
||||
|
||||
if(enable)
|
||||
clock_generator.set_clock_control(clock_generator_output_clkout, si5351_clock_control_common[clock_generator_output_clkout].ms_src(get_reference_clock_generator_pll(reference.source)).clk_pdn(ClockControl::ClockPowerDown::Power_On));
|
||||
clock_generator.set_clock_control(clock_generator_output_og_clkout, si5351_clock_control_common[clock_generator_output_og_clkout].ms_src(ref_pll).clk_pdn(ClockControl::ClockPowerDown::Power_On));
|
||||
else
|
||||
clock_generator.set_clock_control(clock_generator_output_clkout, ClockControl::power_off());
|
||||
clock_generator.set_clock_control(clock_generator_output_og_clkout, ClockControl::power_off());
|
||||
}
|
||||
|
||||
@@ -65,11 +65,8 @@ public:
|
||||
void enable_codec_clocks();
|
||||
void disable_codec_clocks();
|
||||
|
||||
void enable_first_if_clock();
|
||||
void disable_first_if_clock();
|
||||
|
||||
void enable_second_if_clock();
|
||||
void disable_second_if_clock();
|
||||
void enable_if_clocks();
|
||||
void disable_if_clocks();
|
||||
|
||||
void set_sampling_frequency(const uint32_t frequency);
|
||||
|
||||
@@ -99,6 +96,7 @@ private:
|
||||
|
||||
ReferenceSource detect_reference_source();
|
||||
Reference choose_reference();
|
||||
bool loss_of_signal();
|
||||
};
|
||||
|
||||
#endif/*__CLOCK_MANAGER_H__*/
|
||||
|
||||
@@ -38,7 +38,7 @@ using namespace lpc43xx;
|
||||
* I suppose I could force M4MEMMAP to an invalid memory reason which would
|
||||
* cause an exception and effectively halt the M4. But that feels gross.
|
||||
*/
|
||||
void m4_init(const portapack::spi_flash::image_tag_t image_tag, const portapack::memory::region_t to) {
|
||||
void m4_init(const portapack::spi_flash::image_tag_t image_tag, const portapack::memory::region_t to, const bool full_reset) {
|
||||
const portapack::spi_flash::chunk_t* chunk = reinterpret_cast<const portapack::spi_flash::chunk_t*>(portapack::spi_flash::images.base());
|
||||
while(chunk->tag) {
|
||||
if( chunk->tag == image_tag ) {
|
||||
@@ -50,8 +50,11 @@ void m4_init(const portapack::spi_flash::image_tag_t image_tag, const portapack:
|
||||
*/
|
||||
LPC_CREG->M4MEMMAP = to.base();
|
||||
|
||||
/* Reset M4 core */
|
||||
LPC_RGU->RESET_CTRL[0] = (1 << 13);
|
||||
/* Reset M4 core and optionally all peripherals */
|
||||
LPC_RGU->RESET_CTRL[0] = (full_reset) ?
|
||||
(1 << 1) // PERIPH_RST
|
||||
: (1 << 13) // M4_RST
|
||||
;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "memory_map.hpp"
|
||||
#include "spi_image.hpp"
|
||||
|
||||
void m4_init(const portapack::spi_flash::image_tag_t image_tag, const portapack::memory::region_t to);
|
||||
void m4_init(const portapack::spi_flash::image_tag_t image_tag, const portapack::memory::region_t to, const bool full_reset);
|
||||
void m4_request_shutdown();
|
||||
|
||||
void m0_halt();
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2023 Bernd Herzog
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "debug.hpp"
|
||||
|
||||
#include <ch.h>
|
||||
#include <hal.h>
|
||||
#include <string>
|
||||
|
||||
#include "ui_painter.hpp"
|
||||
#include "portapack.hpp"
|
||||
#include "ui_font_fixed_8x16.hpp"
|
||||
#include "string_format.hpp"
|
||||
|
||||
void runtime_error(LED);
|
||||
std::string number_to_hex_string(uint32_t);
|
||||
void draw_line(int32_t, const char *, regarm_t);
|
||||
static bool error_shown = false;
|
||||
|
||||
void draw_guru_meditation_header(uint8_t source, const char *hint) {
|
||||
ui::Painter painter;
|
||||
ui::Style style_default {
|
||||
.font = ui::font::fixed_8x16,
|
||||
.background = ui::Color::black(),
|
||||
.foreground = ui::Color::white()
|
||||
};
|
||||
|
||||
painter.fill_rectangle(
|
||||
{ 0, 0, portapack::display.width(), portapack::display.height() },
|
||||
ui::Color::red()
|
||||
);
|
||||
|
||||
constexpr int border = 8;
|
||||
painter.fill_rectangle(
|
||||
{ border, border, portapack::display.width() - (border * 2), portapack::display.height() - (border * 2) },
|
||||
ui::Color::black()
|
||||
);
|
||||
|
||||
// NOTE: in situations like a hard fault it seems not possible to write strings longer than 16 characters.
|
||||
painter.draw_string({ 48, 24 }, style_default, "M? Guru");
|
||||
painter.draw_string({ 48 + 8*8, 24 }, style_default, "Meditation");
|
||||
|
||||
if (source == CORTEX_M0)
|
||||
painter.draw_string({ 48 + 8, 24 }, style_default, "0");
|
||||
|
||||
if (source == CORTEX_M4)
|
||||
painter.draw_string({ 48 + 8, 24 }, style_default, "4");
|
||||
|
||||
painter.draw_string({ 15, 55 }, style_default, "Hint: ");
|
||||
painter.draw_string({ 15 + 8*8, 55 }, style_default, hint);
|
||||
}
|
||||
|
||||
void draw_guru_meditation(uint8_t source, const char *hint) {
|
||||
if(error_shown == false){
|
||||
error_shown = true;
|
||||
draw_guru_meditation_header(source, hint);
|
||||
}
|
||||
|
||||
if (source == CORTEX_M0)
|
||||
runtime_error(hackrf::one::led_rx);
|
||||
|
||||
if (source == CORTEX_M4)
|
||||
runtime_error(hackrf::one::led_tx);
|
||||
}
|
||||
|
||||
void draw_guru_meditation(uint8_t source, const char *hint, struct extctx *ctxp, uint32_t cfsr = 0) {
|
||||
if(error_shown == false)
|
||||
{
|
||||
error_shown = true;
|
||||
draw_guru_meditation_header(source, hint);
|
||||
|
||||
if (ctxp != nullptr) {
|
||||
int i = 0;
|
||||
draw_line(80 + i++ * 20, "r0:", ctxp->r0);
|
||||
draw_line(80 + i++ * 20, "r1:", ctxp->r1);
|
||||
draw_line(80 + i++ * 20, "r2:", ctxp->r2);
|
||||
draw_line(80 + i++ * 20, "r3:", ctxp->r3);
|
||||
draw_line(80 + i++ * 20, "r12:", ctxp->r12);
|
||||
|
||||
// NOTE: run for M0
|
||||
// # arm-none-eabi-gdb --batch --eval-command="x/8i 0x<link_register_value_here>" firmware/application/application.elf
|
||||
// or for M4
|
||||
// # arm-none-eabi-gdb --batch --eval-command="x/8i 0x<link_register_value_here>" firmware/baseband/<image_name_here>.elf
|
||||
// to see whats causing the fault.
|
||||
draw_line(80 + i++ * 20, "lr:", ctxp->lr_thd);
|
||||
draw_line(80 + i++ * 20, "pc:", ctxp->pc);
|
||||
|
||||
// see SCB_CFSR_* in libopencm3/cm3/scb.h for details
|
||||
if (cfsr != 0)
|
||||
draw_line(80 + i++ * 20, "cfsr:", (void *)cfsr);
|
||||
}
|
||||
}
|
||||
|
||||
if (source == CORTEX_M0)
|
||||
runtime_error(hackrf::one::led_rx);
|
||||
|
||||
if (source == CORTEX_M4)
|
||||
runtime_error(hackrf::one::led_tx);
|
||||
}
|
||||
|
||||
void draw_line(int32_t y_offset, const char *label, regarm_t value){
|
||||
ui::Painter painter;
|
||||
ui::Style style_default {
|
||||
.font = ui::font::fixed_8x16,
|
||||
.background = ui::Color::black(),
|
||||
.foreground = ui::Color::white()
|
||||
};
|
||||
|
||||
painter.draw_string({ 15, y_offset }, style_default, label);
|
||||
painter.draw_string({ 15 + 8*8, y_offset }, style_default, to_string_hex((uint32_t)value, 8));
|
||||
}
|
||||
|
||||
void runtime_error(LED led) {
|
||||
led.off();
|
||||
|
||||
while(true) {
|
||||
volatile size_t n = 1000000U;
|
||||
while(n--);
|
||||
led.toggle();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
#if CH_DBG_ENABLED
|
||||
void port_halt(void) {
|
||||
port_disable();
|
||||
|
||||
if (dbg_panic_msg == nullptr)
|
||||
dbg_panic_msg = "system halted";
|
||||
|
||||
draw_guru_meditation(CORTEX_M0, dbg_panic_msg);
|
||||
}
|
||||
#endif
|
||||
|
||||
CH_IRQ_HANDLER(MemManageVector) {
|
||||
#if CH_DBG_ENABLED
|
||||
chDbgPanic("MemManage");
|
||||
#else
|
||||
chSysHalt();
|
||||
#endif
|
||||
}
|
||||
|
||||
CH_IRQ_HANDLER(BusFaultVector) {
|
||||
#if CH_DBG_ENABLED
|
||||
chDbgPanic("BusFault");
|
||||
#else
|
||||
chSysHalt();
|
||||
#endif
|
||||
}
|
||||
|
||||
CH_IRQ_HANDLER(UsageFaultVector) {
|
||||
#if CH_DBG_ENABLED
|
||||
chDbgPanic("UsageFault");
|
||||
#else
|
||||
chSysHalt();
|
||||
#endif
|
||||
}
|
||||
|
||||
CH_IRQ_HANDLER(HardFaultVector) {
|
||||
#if CH_DBG_ENABLED
|
||||
CH_IRQ_PROLOGUE();
|
||||
struct extctx *ctxp;
|
||||
port_lock_from_isr();
|
||||
|
||||
if ((uint32_t)_saved_lr & 0x04)
|
||||
ctxp = (struct extctx *)__get_PSP();
|
||||
else
|
||||
ctxp = (struct extctx *)__get_MSP();
|
||||
|
||||
port_disable();
|
||||
|
||||
auto stack_space_left = get_free_stack_space();
|
||||
if (stack_space_left < 16)
|
||||
draw_guru_meditation(CORTEX_M0, "Stack Overflow", ctxp);
|
||||
|
||||
draw_guru_meditation(CORTEX_M0, "Hard Fault", ctxp);
|
||||
|
||||
CH_IRQ_EPILOGUE();
|
||||
#else
|
||||
chSysHalt();
|
||||
#endif
|
||||
}
|
||||
|
||||
} /* extern "C" */
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2023 Bernd Herzog
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -22,4 +23,21 @@
|
||||
#ifndef __DEBUG_H__
|
||||
#define __DEBUG_H__
|
||||
|
||||
#include "hackrf_gpio.hpp"
|
||||
|
||||
extern void draw_guru_meditation(uint8_t, const char *);
|
||||
extern void draw_guru_meditation(uint8_t, const char *, struct extctx *, uint32_t);
|
||||
|
||||
extern uint32_t __process_stack_base__;
|
||||
extern uint32_t __process_stack_end__;
|
||||
#define CRT0_STACKS_FILL_PATTERN 0x55555555
|
||||
|
||||
inline uint32_t get_free_stack_space(){
|
||||
uint32_t *p;
|
||||
for (p = &__process_stack_base__; *p == CRT0_STACKS_FILL_PATTERN && p < &__process_stack_end__; p++);
|
||||
auto stack_space_left = p - &__process_stack_base__;
|
||||
|
||||
return stack_space_left;
|
||||
}
|
||||
|
||||
#endif/*__DEBUG_H__*/
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "portapack.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
#include "debug.hpp"
|
||||
|
||||
#include "sd_card.hpp"
|
||||
#include "rtc_time.hpp"
|
||||
@@ -141,37 +142,14 @@ eventmask_t EventDispatcher::wait() {
|
||||
|
||||
void EventDispatcher::dispatch(const eventmask_t events) {
|
||||
if( shared_memory.m4_panic_msg[0] != 0 ) {
|
||||
halt = true;
|
||||
}
|
||||
|
||||
if( halt ) {
|
||||
if( shared_memory.m4_panic_msg[0] != 0 ) {
|
||||
painter.fill_rectangle(
|
||||
{ 0, 0, portapack::display.width(), portapack::display.height() },
|
||||
ui::Color::red()
|
||||
);
|
||||
|
||||
constexpr int border = 8;
|
||||
painter.fill_rectangle(
|
||||
{ border, border, portapack::display.width() - (border * 2), portapack::display.height() - (border * 2) },
|
||||
ui::Color::black()
|
||||
);
|
||||
|
||||
painter.draw_string({ 48, 24 }, top_widget->style(), "M4 Guru Meditation");
|
||||
|
||||
shared_memory.m4_panic_msg[sizeof(shared_memory.m4_panic_msg) - 1] = 0;
|
||||
const std::string message = shared_memory.m4_panic_msg;
|
||||
const int x_offset = (portapack::display.width() - (message.size() * 8)) / 2;
|
||||
constexpr int y_offset = (portapack::display.height() - 16) / 2;
|
||||
painter.draw_string(
|
||||
{ x_offset, y_offset },
|
||||
top_widget->style(),
|
||||
message
|
||||
);
|
||||
|
||||
shared_memory.m4_panic_msg[0] = 0;
|
||||
}
|
||||
return;
|
||||
if (shared_memory.bb_data.data[0] == 0)
|
||||
draw_guru_meditation(CORTEX_M4, shared_memory.m4_panic_msg);
|
||||
else
|
||||
draw_guru_meditation(
|
||||
CORTEX_M4,
|
||||
shared_memory.m4_panic_msg,
|
||||
(struct extctx *)&shared_memory.bb_data.data[8],
|
||||
*(uint32_t *)&shared_memory.bb_data.data[4]);
|
||||
}
|
||||
|
||||
if( events & EVT_MASK_APPLICATION ) {
|
||||
|
||||
@@ -98,7 +98,6 @@ private:
|
||||
static bool is_running;
|
||||
bool sd_card_present = false;
|
||||
static bool display_sleep;
|
||||
bool halt = false;
|
||||
bool in_key_event = false;
|
||||
|
||||
eventmask_t wait();
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#include "../../hackrf/firmware/common/firmware_info.h"
|
||||
#include "../../hackrf/firmware/common/platform_detect.h"
|
||||
|
||||
#define SUPPORTED_PLATFORM (PLATFORM_HACKRF1_OG | PLATFORM_HACKRF1_R9)
|
||||
#define DFU_MODE_VALUE 0
|
||||
|
||||
__attribute__((section(".firmware_info"))) const struct firmware_info_t firmware_info = {
|
||||
.magic = "HACKRFFW",
|
||||
.struct_version = 1,
|
||||
.dfu_mode = DFU_MODE_VALUE,
|
||||
.supported_platform = SUPPORTED_PLATFORM,
|
||||
.version_string = VERSION_STRING,
|
||||
};
|
||||
@@ -51,6 +51,8 @@ options_t freqman_entry_bandwidths[ 4 ] = {
|
||||
};
|
||||
|
||||
options_t freqman_entry_steps = {
|
||||
{ "0.1KHz " , 100 },
|
||||
{ "1KHz " , 1000 },
|
||||
{ "5KHz (SA AM)" , 5000 },
|
||||
{ "6.25KHz(NFM)" , 6250 },
|
||||
{ "8.33KHz(AIR)" , 8330 },
|
||||
@@ -68,6 +70,8 @@ options_t freqman_entry_steps = {
|
||||
};
|
||||
|
||||
options_t freqman_entry_steps_short = {
|
||||
{ "0.1KHz" , 100 },
|
||||
{ "1KHz" , 1000 },
|
||||
{ "5KHz" , 5000 },
|
||||
{ "6.25KHz" , 6250 },
|
||||
{ "8.33KHz" , 8330 },
|
||||
|
||||
@@ -32,8 +32,12 @@ using namespace hackrf::one;
|
||||
|
||||
namespace max2837 {
|
||||
|
||||
using namespace max283x;
|
||||
|
||||
namespace lna {
|
||||
|
||||
using namespace max283x::lna;
|
||||
|
||||
constexpr std::array<uint8_t, 8> lookup_8db_steps {
|
||||
0b111, 0b011, 0b110, 0b010,
|
||||
0b100, 0b000, 0b000, 0b000
|
||||
@@ -48,6 +52,8 @@ static uint_fast8_t gain_ordinal(const int8_t db) {
|
||||
|
||||
namespace vga {
|
||||
|
||||
using namespace max283x::vga;
|
||||
|
||||
static uint_fast8_t gain_ordinal(const int8_t db) {
|
||||
const auto db_sat = gain_db_range.clip(db);
|
||||
return ((db_sat >> 1) & 0b11111) ^ 0b11111;
|
||||
@@ -57,6 +63,8 @@ static uint_fast8_t gain_ordinal(const int8_t db) {
|
||||
|
||||
namespace tx {
|
||||
|
||||
using namespace max283x::tx;
|
||||
|
||||
static uint_fast8_t gain_ordinal(const int8_t db) {
|
||||
const auto db_sat = gain_db_range.clip(db);
|
||||
uint8_t value = db_sat & 0x0f;
|
||||
@@ -69,6 +77,8 @@ static uint_fast8_t gain_ordinal(const int8_t db) {
|
||||
|
||||
namespace filter {
|
||||
|
||||
using namespace max283x::filter;
|
||||
|
||||
static uint_fast8_t bandwidth_ordinal(const uint32_t bandwidth) {
|
||||
/* Determine filter setting that will provide bandwidth greater than or
|
||||
* equal to requested bandwidth.
|
||||
@@ -84,13 +94,13 @@ static uint_fast8_t bandwidth_ordinal(const uint32_t bandwidth) {
|
||||
constexpr float seconds_for_temperature_sense_adc_conversion = 30.0e-6;
|
||||
constexpr halrtcnt_t ticks_for_temperature_sense_adc_conversion = (base_m4_clk_f * seconds_for_temperature_sense_adc_conversion + 1);
|
||||
|
||||
constexpr uint32_t reference_frequency = max2837_reference_f;
|
||||
constexpr uint32_t reference_frequency = max283x_reference_f;
|
||||
constexpr uint32_t pll_factor = 1.0 / (4.0 / 3.0 / reference_frequency) + 0.5;
|
||||
|
||||
void MAX2837::init() {
|
||||
set_mode(Mode::Shutdown);
|
||||
|
||||
gpio_max2837_enable.output();
|
||||
gpio_max283x_enable.output();
|
||||
gpio_max2837_rxenable.output();
|
||||
gpio_max2837_txenable.output();
|
||||
|
||||
@@ -140,10 +150,30 @@ void MAX2837::init() {
|
||||
set_mode(Mode::Standby);
|
||||
}
|
||||
|
||||
enum class Mask {
|
||||
Enable = 0b001,
|
||||
RxEnable = 0b010,
|
||||
TxEnable = 0b100,
|
||||
Shutdown = 0b000,
|
||||
Standby = Enable,
|
||||
Receive = Enable | RxEnable,
|
||||
Transmit = Enable | TxEnable,
|
||||
};
|
||||
|
||||
Mask mode_mask(const Mode mode) {
|
||||
switch (mode) {
|
||||
case Mode::Standby: return Mask::Standby;
|
||||
case Mode::Receive: return Mask::Receive;
|
||||
case Mode::Transmit: return Mask::Transmit;
|
||||
default: return Mask::Shutdown;
|
||||
}
|
||||
}
|
||||
|
||||
void MAX2837::set_mode(const Mode mode) {
|
||||
gpio_max2837_enable.write(toUType(mode) & toUType(Mode::Mask_Enable));
|
||||
gpio_max2837_rxenable.write(toUType(mode) & toUType(Mode::Mask_RxEnable));
|
||||
gpio_max2837_txenable.write(toUType(mode) & toUType(Mode::Mask_TxEnable));
|
||||
Mask mask = mode_mask(mode);
|
||||
gpio_max283x_enable.write(toUType(mask) & toUType(Mask::Enable));
|
||||
gpio_max2837_rxenable.write(toUType(mask) & toUType(Mask::RxEnable));
|
||||
gpio_max2837_txenable.write(toUType(mask) & toUType(Mask::TxEnable));
|
||||
}
|
||||
|
||||
void MAX2837::flush() {
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#ifndef __MAX2837_H__
|
||||
#define __MAX2837_H__
|
||||
|
||||
#include "max283x.hpp"
|
||||
#include "gpio.hpp"
|
||||
#include "spi_arbiter.hpp"
|
||||
|
||||
@@ -29,99 +30,11 @@
|
||||
#include <array>
|
||||
|
||||
#include "dirty_registers.hpp"
|
||||
#include "rf_path.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
namespace max2837 {
|
||||
|
||||
enum class Mode {
|
||||
Mask_Enable = 0b001,
|
||||
Mask_RxEnable = 0b010,
|
||||
Mask_TxEnable = 0b100,
|
||||
|
||||
Shutdown = 0b000,
|
||||
Standby = Mask_Enable,
|
||||
Receive = Mask_Enable | Mask_RxEnable,
|
||||
Transmit = Mask_Enable | Mask_TxEnable,
|
||||
};
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
namespace lo {
|
||||
|
||||
constexpr std::array<rf::FrequencyRange, 4> band { {
|
||||
{ 2300000000, 2400000000 },
|
||||
{ 2400000000, 2500000000 },
|
||||
{ 2500000000, 2600000000 },
|
||||
{ 2600000000, 2700000000 },
|
||||
} };
|
||||
|
||||
} /* namespace lo */
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
namespace lna {
|
||||
|
||||
constexpr range_t<int8_t> gain_db_range { 0, 40 };
|
||||
constexpr int8_t gain_db_step = 8;
|
||||
|
||||
constexpr std::array<rf::FrequencyRange, 2> band { {
|
||||
{ 2300000000, 2500000000 },
|
||||
{ 2500000000, 2700000000 },
|
||||
} };
|
||||
|
||||
} /* namespace lna */
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
namespace vga {
|
||||
|
||||
constexpr range_t<int8_t> gain_db_range { 0, 62 };
|
||||
constexpr int8_t gain_db_step = 2;
|
||||
|
||||
} /* namespace vga */
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
namespace tx {
|
||||
|
||||
constexpr range_t<int8_t> gain_db_range { 0, 47 };
|
||||
constexpr int8_t gain_db_step = 1;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
namespace filter {
|
||||
|
||||
constexpr std::array<uint32_t, 16> bandwidths {
|
||||
/* Assumption: these values are in ascending order */
|
||||
1750000,
|
||||
2500000, /* Some documentation says 2.25MHz */
|
||||
3500000,
|
||||
5000000,
|
||||
5500000,
|
||||
6000000,
|
||||
7000000,
|
||||
8000000,
|
||||
9000000,
|
||||
10000000,
|
||||
12000000,
|
||||
14000000,
|
||||
15000000,
|
||||
20000000,
|
||||
24000000,
|
||||
28000000,
|
||||
};
|
||||
|
||||
constexpr auto bandwidth_minimum = bandwidths[0];
|
||||
constexpr auto bandwidth_maximum = bandwidths[bandwidths.size() - 1];
|
||||
|
||||
} /* namespace filter */
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
using reg_t = uint16_t;
|
||||
using address_t = uint8_t;
|
||||
using namespace max283x;
|
||||
|
||||
constexpr size_t reg_count = 32;
|
||||
|
||||
@@ -826,7 +739,7 @@ constexpr RegisterMap initial_register_values { Register_Type {
|
||||
},
|
||||
} };
|
||||
|
||||
class MAX2837 {
|
||||
class MAX2837 : public MAX283x {
|
||||
public:
|
||||
constexpr MAX2837(
|
||||
spi::arbiter::Target& target
|
||||
@@ -834,13 +747,13 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void init();
|
||||
void set_mode(const Mode mode);
|
||||
void init() override;
|
||||
void set_mode(const Mode mode) override;
|
||||
|
||||
void set_tx_vga_gain(const int_fast8_t db);
|
||||
void set_lna_gain(const int_fast8_t db);
|
||||
void set_vga_gain(const int_fast8_t db);
|
||||
void set_lpf_rf_bandwidth(const uint32_t bandwidth_minimum);
|
||||
void set_tx_vga_gain(const int_fast8_t db) override;
|
||||
void set_lna_gain(const int_fast8_t db) override;
|
||||
void set_vga_gain(const int_fast8_t db) override;
|
||||
void set_lpf_rf_bandwidth(const uint32_t bandwidth_minimum) override;
|
||||
#if 0
|
||||
void rx_cal() {
|
||||
_map.r.spi_en.EN_SPI = 1;
|
||||
@@ -882,16 +795,16 @@ public:
|
||||
}
|
||||
#endif
|
||||
|
||||
bool set_frequency(const rf::Frequency lo_frequency);
|
||||
bool set_frequency(const rf::Frequency lo_frequency) override;
|
||||
|
||||
void set_rx_lo_iq_calibration(const size_t v);
|
||||
void set_rx_lo_iq_calibration(const size_t v) override;
|
||||
void set_rx_bias_trim(const size_t v);
|
||||
void set_vco_bias(const size_t v);
|
||||
void set_rx_buff_vcm(const size_t v);
|
||||
void set_rx_buff_vcm(const size_t v) override;
|
||||
|
||||
reg_t temp_sense();
|
||||
reg_t temp_sense() override;
|
||||
|
||||
reg_t read(const address_t reg_num);
|
||||
reg_t read(const address_t reg_num) override;
|
||||
|
||||
private:
|
||||
spi::arbiter::Target& _target;
|
||||
|
||||
@@ -0,0 +1,354 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2023 Great Scott Gadgets
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "max2839.hpp"
|
||||
|
||||
#include "hackrf_hal.hpp"
|
||||
#include "hackrf_gpio.hpp"
|
||||
using namespace hackrf::one;
|
||||
|
||||
#include "ch.h"
|
||||
#include "hal.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace max2839 {
|
||||
|
||||
namespace lna {
|
||||
|
||||
using namespace max283x::lna;
|
||||
|
||||
constexpr std::array<uint8_t, 8> lookup_8db_steps {
|
||||
0b11, 0b11, 0b10, 0b10,
|
||||
0b01, 0b00, 0b00, 0b00
|
||||
};
|
||||
|
||||
static uint_fast8_t gain_ordinal(const int8_t db) {
|
||||
const auto db_sat = gain_db_range.clip(db);
|
||||
return lna::lookup_8db_steps[(db_sat >> 3) & 7];
|
||||
}
|
||||
|
||||
} /* namespace lna */
|
||||
|
||||
namespace vga {
|
||||
|
||||
using namespace max283x::vga;
|
||||
|
||||
constexpr range_t<int8_t> gain_db_range_internal { 0, 63 };
|
||||
|
||||
static uint_fast8_t gain_ordinal(const int8_t db) {
|
||||
const auto db_sat = gain_db_range_internal.clip(db);
|
||||
return (db_sat & 0b111111) ^ 0b111111;
|
||||
}
|
||||
|
||||
} /* namespace vga */
|
||||
|
||||
namespace tx {
|
||||
|
||||
using namespace max283x::tx;
|
||||
|
||||
static uint_fast8_t gain_ordinal(const int8_t db) {
|
||||
const auto db_sat = gain_db_range.clip(db);
|
||||
return 47 - db_sat;
|
||||
}
|
||||
|
||||
} /* namespace tx */
|
||||
|
||||
namespace filter {
|
||||
|
||||
using namespace max283x::filter;
|
||||
|
||||
static uint_fast8_t bandwidth_ordinal(const uint32_t bandwidth) {
|
||||
/* Determine filter setting that will provide bandwidth greater than or
|
||||
* equal to requested bandwidth.
|
||||
*/
|
||||
return std::lower_bound(bandwidths.cbegin(), bandwidths.cend(), bandwidth) - bandwidths.cbegin();
|
||||
}
|
||||
|
||||
} /* namespace filter */
|
||||
|
||||
/* Empirical testing indicates about 25us is necessary to get a valid
|
||||
* temperature sense conversion from the ADC.
|
||||
*/
|
||||
constexpr float seconds_for_temperature_sense_adc_conversion = 30.0e-6;
|
||||
constexpr halrtcnt_t ticks_for_temperature_sense_adc_conversion = (base_m4_clk_f * seconds_for_temperature_sense_adc_conversion + 1);
|
||||
|
||||
constexpr uint32_t reference_frequency = max283x_reference_f;
|
||||
constexpr uint32_t pll_factor = 1.0 / (4.0 / 3.0 / reference_frequency) + 0.5;
|
||||
|
||||
static int_fast8_t requested_rx_lna_gain = 0;
|
||||
static int_fast8_t requested_rx_vga_gain = 0;
|
||||
|
||||
void MAX2839::init() {
|
||||
set_mode(Mode::Shutdown);
|
||||
|
||||
gpio_max283x_enable.output();
|
||||
gpio_max2839_rxtx.output();
|
||||
|
||||
_map.r.rxrf_1.MIMOmode = 1; /* enable RXINB */
|
||||
|
||||
_map.r.pa_drv.TXVGA_GAIN_SPI_EN = 1;
|
||||
_map.r.tx_gain.TXVGA_GAIN_SPI = 0x00;
|
||||
|
||||
_map.r.hpfsm_3.HPC_STOP = 1; /* 1kHz */
|
||||
|
||||
_map.r.rxrf_2.LNAgain_SPI_EN = 1; /* control LNA gain from SPI */
|
||||
_map.r.lpf_vga_1.L = 0b000;
|
||||
_map.r.lpf_vga_2.L = 0b000;
|
||||
|
||||
_map.r.rx_top_1.VGAgain_SPI_EN = 1; /* control VGA gain from SPI */
|
||||
_map.r.lpf_vga_1.VGA = 0b000000;
|
||||
_map.r.lpf_vga_2.VGA = 0b010101;
|
||||
|
||||
_map.r.lpf_vga_2.BUFF_VCM = 0b11; /* maximum RX output common-mode voltage */
|
||||
|
||||
_map.r.lpf_vga_1.ModeCtrl = 0b01; /* Rx LPF */
|
||||
_map.r.lpf.FT = 0b0000; /* 1.75 MHz LPF */
|
||||
|
||||
_map.r.spi_en.EN_SPI = 1; /* enable chip functions when ENABLE pin set */
|
||||
|
||||
_map.r.lo_gen.LOGEN_2GM = 0;
|
||||
|
||||
_map.r.rssi_vga.RSSI_MODE = 1; /* RSSI independent of RXHP */
|
||||
|
||||
/*
|
||||
* There are two LNA band settings, but we only use one of them.
|
||||
* Switching to the other one doesn't make the overall spectrum any
|
||||
* flatter but adds a surprise step in the middle.
|
||||
*/
|
||||
_map.r.rxrf_1.LNAband = 0; /* 2.3 - 2.5GHz */
|
||||
|
||||
_dirty.set();
|
||||
flush();
|
||||
|
||||
set_mode(Mode::Standby);
|
||||
}
|
||||
|
||||
enum class Mask {
|
||||
Enable = 0b01,
|
||||
RxTx = 0b10,
|
||||
Shutdown = 0b00,
|
||||
Standby = RxTx,
|
||||
Receive = Enable | RxTx,
|
||||
Transmit = Enable,
|
||||
};
|
||||
|
||||
Mask mode_mask(const Mode mode) {
|
||||
switch (mode) {
|
||||
case Mode::Standby: return Mask::Standby;
|
||||
case Mode::Receive: return Mask::Receive;
|
||||
case Mode::Transmit: return Mask::Transmit;
|
||||
default: return Mask::Shutdown;
|
||||
}
|
||||
}
|
||||
|
||||
void MAX2839::set_mode(const Mode mode) {
|
||||
Mask mask = mode_mask(mode);
|
||||
gpio_max283x_enable.write(toUType(mask) & toUType(Mask::Enable));
|
||||
gpio_max2839_rxtx.write(toUType(mask) & toUType(Mask::RxTx));
|
||||
}
|
||||
|
||||
void MAX2839::flush() {
|
||||
if( _dirty ) {
|
||||
for(size_t n=0; n<reg_count; n++) {
|
||||
if( _dirty[n] ) {
|
||||
write(n, _map.w[n]);
|
||||
}
|
||||
}
|
||||
_dirty.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void MAX2839::flush_one(const Register reg) {
|
||||
const auto reg_num = toUType(reg);
|
||||
write(reg_num, _map.w[reg_num]);
|
||||
_dirty.clear(reg_num);
|
||||
}
|
||||
|
||||
void MAX2839::write(const address_t reg_num, const reg_t value) {
|
||||
uint16_t t = (0U << 15) | (reg_num << 10) | (value & 0x3ffU);
|
||||
_target.transfer(&t, 1);
|
||||
}
|
||||
|
||||
reg_t MAX2839::read(const address_t reg_num) {
|
||||
uint16_t t = (1U << 15) | (reg_num << 10);
|
||||
_target.transfer(&t, 1U);
|
||||
return t & 0x3ffU;
|
||||
}
|
||||
|
||||
void MAX2839::write(const Register reg, const reg_t value) {
|
||||
write(toUType(reg), value);
|
||||
}
|
||||
|
||||
reg_t MAX2839::read(const Register reg) {
|
||||
return read(toUType(reg));
|
||||
}
|
||||
|
||||
void MAX2839::set_tx_vga_gain(const int_fast8_t db) {
|
||||
_map.r.tx_gain.TXVGA_GAIN_SPI = tx::gain_ordinal(db);
|
||||
_dirty[Register::TX_GAIN] = 1;
|
||||
flush();
|
||||
}
|
||||
|
||||
/*
|
||||
* MAX2839 gain rain ranges differ slightly from MAX2837's but are close
|
||||
* enough that it makes sense to emulate MAX2837 gain ranges for a consistent
|
||||
* user experience.
|
||||
*/
|
||||
void MAX2839::configure_rx_gain() {
|
||||
/* Apply MAX2837 restrictions to requested gain settings. */
|
||||
int_fast8_t lna_gain = lna::gain_db_range.clip(requested_rx_lna_gain);
|
||||
lna_gain &= 0x38;
|
||||
int_fast8_t vga_gain = vga::gain_db_range.clip(requested_rx_vga_gain);
|
||||
vga_gain &= 0x3e;
|
||||
|
||||
/*
|
||||
* MAX2839 has lower full-scale RX output voltage than MAX2837, so we
|
||||
* adjust the VGA (baseband) gain to compensate.
|
||||
*/
|
||||
vga_gain += 3;
|
||||
|
||||
/*
|
||||
* If that adjustment puts VGA gain out of range, use LNA gain to
|
||||
* compensate. MAX2839 VGA gain can be any number from 0 through 63.
|
||||
*/
|
||||
if (vga_gain > 63) {
|
||||
if (lna_gain <= 32) {
|
||||
vga_gain -= 8;
|
||||
lna_gain += 8;
|
||||
} else {
|
||||
vga_gain = 63;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* MAX2839 lacks max-24 dB (16 dB) and max-40 dB (0 dB) LNA gain
|
||||
* settings, so we use VGA gain to compensate.
|
||||
*/
|
||||
if (lna_gain == 0) {
|
||||
lna_gain = 8;
|
||||
vga_gain = (vga_gain >= 8) ? vga_gain - 8 : 0;
|
||||
}
|
||||
if (lna_gain == 16) {
|
||||
if (vga_gain > 32) {
|
||||
vga_gain -= 8;
|
||||
lna_gain += 8;
|
||||
} else {
|
||||
vga_gain += 8;
|
||||
lna_gain -= 8;
|
||||
}
|
||||
}
|
||||
|
||||
_map.r.lpf_vga_2.L = lna::gain_ordinal(lna_gain);
|
||||
_dirty[Register::RXRF_2] = 1;
|
||||
_map.r.lpf_vga_2.VGA = vga::gain_ordinal(vga_gain);
|
||||
_dirty[Register::LPF_VGA_2] = 1;
|
||||
flush();
|
||||
}
|
||||
|
||||
void MAX2839::set_lna_gain(const int_fast8_t db) {
|
||||
requested_rx_lna_gain = db;
|
||||
configure_rx_gain();
|
||||
}
|
||||
|
||||
void MAX2839::set_vga_gain(const int_fast8_t db) {
|
||||
requested_rx_vga_gain = db;
|
||||
configure_rx_gain();
|
||||
}
|
||||
|
||||
void MAX2839::set_lpf_rf_bandwidth(const uint32_t bandwidth_minimum) {
|
||||
_map.r.lpf.FT = filter::bandwidth_ordinal(bandwidth_minimum);
|
||||
_dirty[Register::LPF] = 1;
|
||||
flush();
|
||||
}
|
||||
|
||||
bool MAX2839::set_frequency(const rf::Frequency lo_frequency) {
|
||||
/* TODO: This is a sad implementation. Refactor. */
|
||||
if( lo::band[0].contains(lo_frequency) ) {
|
||||
_map.r.syn_int_div.LOGEN_BSW = 0b00; /* 2300 - 2399.99MHz */
|
||||
} else if( lo::band[1].contains(lo_frequency) ) {
|
||||
_map.r.syn_int_div.LOGEN_BSW = 0b01; /* 2400 - 2499.99MHz */
|
||||
} else if( lo::band[2].contains(lo_frequency) ) {
|
||||
_map.r.syn_int_div.LOGEN_BSW = 0b10; /* 2500 - 2599.99MHz */
|
||||
} else if( lo::band[3].contains(lo_frequency) ) {
|
||||
_map.r.syn_int_div.LOGEN_BSW = 0b11; /* 2600 - 2700Hz */
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
_dirty[Register::SYN_INT_DIV] = 1;
|
||||
|
||||
const uint64_t div_q20 = (lo_frequency * (1 << 20)) / pll_factor;
|
||||
|
||||
_map.r.syn_int_div.SYN_INTDIV = div_q20 >> 20;
|
||||
_dirty[Register::SYN_INT_DIV] = 1;
|
||||
_map.r.syn_fr_div_2.SYN_FRDIV_19_10 = (div_q20 >> 10) & 0x3ff;
|
||||
_dirty[Register::SYN_FR_DIV_2] = 1;
|
||||
/* flush to commit high FRDIV first, as low FRDIV commits the change */
|
||||
flush();
|
||||
|
||||
_map.r.syn_fr_div_1.SYN_FRDIV_9_0 = (div_q20 & 0x3ff);
|
||||
_dirty[Register::SYN_FR_DIV_1] = 1;
|
||||
flush();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MAX2839::set_rx_lo_iq_calibration(const size_t v) {
|
||||
_map.r.rxrf_2.RX_IQERR_SPI_EN = 1;
|
||||
_dirty[Register::RXRF_2] = 1;
|
||||
_map.r.rxrf_1.iqerr_trim = v;
|
||||
_dirty[Register::RXRF_1] = 1;
|
||||
flush();
|
||||
}
|
||||
|
||||
void MAX2839::set_rx_buff_vcm(const size_t v) {
|
||||
_map.r.lpf_vga_2.BUFF_VCM = v;
|
||||
_dirty[Register::LPF_VGA_2] = 1;
|
||||
flush();
|
||||
}
|
||||
|
||||
reg_t MAX2839::temp_sense() {
|
||||
if( !_map.r.rx_top_2.ts_en ) {
|
||||
_map.r.rx_top_2.ts_en = 1;
|
||||
flush_one(Register::RX_TOP_2);
|
||||
|
||||
chThdSleepMilliseconds(1);
|
||||
}
|
||||
|
||||
_map.r.rx_top_2.ts_adc_trigger = 1;
|
||||
flush_one(Register::RX_TOP_2);
|
||||
|
||||
halPolledDelay(ticks_for_temperature_sense_adc_conversion);
|
||||
|
||||
/*
|
||||
* Things look very similar to MAX2837, so this probably works, but the
|
||||
* MAX2839 data sheet does not describe the TEMP_SENSE register contents.
|
||||
*/
|
||||
const auto value = read(Register::TEMP_SENSE);
|
||||
|
||||
_map.r.rx_top_2.ts_adc_trigger = 0;
|
||||
flush_one(Register::RX_TOP_2);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,688 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2023 Great Scott Gadgets
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __MAX2839_H__
|
||||
#define __MAX2839_H__
|
||||
|
||||
#include "max283x.hpp"
|
||||
#include "gpio.hpp"
|
||||
#include "spi_arbiter.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <array>
|
||||
|
||||
#include "dirty_registers.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
namespace max2839 {
|
||||
|
||||
using namespace max283x;
|
||||
|
||||
constexpr size_t reg_count = 32;
|
||||
|
||||
enum class Register : address_t {
|
||||
RXENABLE = 0,
|
||||
RXRF_1 = 1,
|
||||
RXRF_2 = 2,
|
||||
RXRF_LPF = 3,
|
||||
LPF = 4,
|
||||
LPF_VGA_1 = 5,
|
||||
LPF_VGA_2 = 6,
|
||||
RSSI_VGA = 7,
|
||||
RX_TOP_1 = 8,
|
||||
RX_TOP_2 = 9,
|
||||
TX_TOP_1 = 10,
|
||||
TEMP_SENSE = 11,
|
||||
HPFSM_1 = 12,
|
||||
HPFSM_2 = 13,
|
||||
HPFSM_3 = 14,
|
||||
HPFSM_4 = 15,
|
||||
SPI_EN = 16,
|
||||
SYN_FR_DIV_1 = 17,
|
||||
SYN_FR_DIV_2 = 18,
|
||||
SYN_INT_DIV = 19,
|
||||
SYN_CFG_1 = 20,
|
||||
SYN_CFG_2 = 21,
|
||||
VAS_CFG = 22,
|
||||
LO_MISC = 23,
|
||||
XTAL_CFG = 24,
|
||||
VCO_CFG = 25,
|
||||
LO_GEN = 26,
|
||||
PA_DRV = 27,
|
||||
PA_DAC = 28,
|
||||
TX_GAIN = 29,
|
||||
TX_LO_IQ = 30,
|
||||
TX_DC_CORR = 31,
|
||||
};
|
||||
|
||||
struct RXENABLE_Type {
|
||||
reg_t RESERVED0 : 10;
|
||||
reg_t RESERVED1 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(RXENABLE_Type) == sizeof(reg_t), "RXENABLE_Type wrong size");
|
||||
|
||||
struct RXRF_1_Type {
|
||||
reg_t LNAband : 1;
|
||||
reg_t RESERVED0 : 1;
|
||||
reg_t MIMOmode : 1;
|
||||
reg_t iqerr_trim : 5;
|
||||
reg_t RESERVED1 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(RXRF_1_Type) == sizeof(reg_t), "RXRF_1_Type wrong size");
|
||||
|
||||
struct RXRF_2_Type {
|
||||
reg_t LNAgain_SPI_EN : 1;
|
||||
reg_t RESERVED0 : 1;
|
||||
reg_t RX_IQERR_SPI_EN : 1;
|
||||
reg_t RESERVED1 : 7;
|
||||
reg_t RESERVED2 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(RXRF_2_Type) == sizeof(reg_t), "RXRF_2_Type wrong size");
|
||||
|
||||
struct RXRF_LPF_Type {
|
||||
reg_t RESERVED0 : 10;
|
||||
reg_t RESERVED1 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(RXRF_LPF_Type) == sizeof(reg_t), "RXRF_LPF_Type wrong size");
|
||||
|
||||
struct LPF_Type {
|
||||
reg_t RESERVED0 : 2;
|
||||
reg_t dF : 2;
|
||||
reg_t RESERVED1 : 2;
|
||||
reg_t FT : 4;
|
||||
reg_t RESERVED2 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(LPF_Type) == sizeof(reg_t), "LPF_Type wrong size");
|
||||
|
||||
struct LPF_VGA_1_Type {
|
||||
reg_t L : 2;
|
||||
reg_t VGA : 6;
|
||||
reg_t ModeCtrl : 2;
|
||||
reg_t RESERVED0 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(LPF_VGA_1_Type) == sizeof(reg_t), "LPF_VGA_1_Type wrong size");
|
||||
|
||||
struct LPF_VGA_2_Type {
|
||||
reg_t L : 2;
|
||||
reg_t VGA : 6;
|
||||
reg_t BUFF_VCM : 2;
|
||||
reg_t RESERVED0 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(LPF_VGA_2_Type) == sizeof(reg_t), "LPF_VGA_2_Type wrong size");
|
||||
|
||||
struct RSSI_VGA_Type {
|
||||
reg_t RESERVED0 : 1;
|
||||
reg_t RSSI_MUX : 1;
|
||||
reg_t RSSI_MODE : 1;
|
||||
reg_t RESERVED1 : 4;
|
||||
reg_t RXBB_OUT_SEL : 1;
|
||||
reg_t RESERVED2 : 1;
|
||||
reg_t RSSI_INPUT : 1;
|
||||
reg_t RESERVED3 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(RSSI_VGA_Type) == sizeof(reg_t), "RSSI_VGA_Type wrong size");
|
||||
|
||||
struct RX_TOP_1_Type {
|
||||
reg_t RESERVED0 : 1;
|
||||
reg_t VGAgain_SPI_EN : 1;
|
||||
reg_t LPF_MODE_SEL : 1;
|
||||
reg_t RESERVED1 : 7;
|
||||
reg_t RESERVED2 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(RX_TOP_1_Type) == sizeof(reg_t), "RX_TOP_1_Type wrong size");
|
||||
|
||||
struct RX_TOP_2_Type {
|
||||
reg_t ts_adc_trigger : 1;
|
||||
reg_t ts_en : 1;
|
||||
reg_t RESERVED0 : 1;
|
||||
reg_t DOUT_DRVH : 1;
|
||||
reg_t DOUT_CSB_SEL : 1;
|
||||
reg_t DOUT_SEL : 3;
|
||||
reg_t RESERVED1 : 2;
|
||||
reg_t RESERVED2 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(RX_TOP_2_Type) == sizeof(reg_t), "RX_TOP_2_Type wrong size");
|
||||
|
||||
struct TX_TOP_1_Type {
|
||||
reg_t TXCAL_GAIN : 2;
|
||||
reg_t TXCAL_V2I_FILT : 3;
|
||||
reg_t RESERVED1 : 5;
|
||||
reg_t RESERVED2 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(TX_TOP_1_Type) == sizeof(reg_t), "TX_TOP_1_Type wrong size");
|
||||
|
||||
struct TEMP_SENSE_Type {
|
||||
reg_t RESERVED0 : 10;
|
||||
reg_t RESERVED1 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(TEMP_SENSE_Type) == sizeof(reg_t), "TEMP_SENSE_Type wrong size");
|
||||
|
||||
struct HPFSM_1_Type {
|
||||
reg_t HPC_10M : 2;
|
||||
reg_t HPC_10M_GAIN : 2;
|
||||
reg_t HPC_600k : 3;
|
||||
reg_t HPC_600k_GAIN : 3;
|
||||
reg_t RESERVED0 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(HPFSM_1_Type) == sizeof(reg_t), "HPFSM_1_Type wrong size");
|
||||
|
||||
struct HPFSM_2_Type {
|
||||
reg_t HPC_100k : 2;
|
||||
reg_t HPC_100k_GAIN : 2;
|
||||
reg_t HPC_30k : 2;
|
||||
reg_t HPC_30k_GAIN : 2;
|
||||
reg_t HPC_1k : 2;
|
||||
reg_t RESERVED0 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(HPFSM_2_Type) == sizeof(reg_t), "HPFSM_2_Type wrong size");
|
||||
|
||||
struct HPFSM_3_Type {
|
||||
reg_t HPC_1k_B7B6 : 2;
|
||||
reg_t HPC_DELAY : 2;
|
||||
reg_t HPC_STOP : 2;
|
||||
reg_t HPC_STOP_M2 : 2;
|
||||
reg_t HPC_RXGAIN_EN : 1;
|
||||
reg_t TXGATE_EN : 1;
|
||||
reg_t RESERVED0 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(HPFSM_3_Type) == sizeof(reg_t), "HPFSM_3_Type wrong size");
|
||||
|
||||
struct HPFSM_4_Type {
|
||||
reg_t HPC_DIVH : 1;
|
||||
reg_t RESERVED0 : 5;
|
||||
reg_t HPC_SEQ_BYP : 1;
|
||||
reg_t RESERVED1 : 2;
|
||||
reg_t HPC_MODE : 1;
|
||||
reg_t RESERVED2 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(HPFSM_4_Type) == sizeof(reg_t), "HPFSM_4_Type wrong size");
|
||||
|
||||
struct SPI_EN_Type {
|
||||
reg_t EN_SPI : 1;
|
||||
reg_t CAL_SPI : 1;
|
||||
reg_t RESERVED0 : 4;
|
||||
reg_t PADAC_SPI_EN : 1;
|
||||
reg_t PADAC_TX_EN : 1;
|
||||
reg_t RESERVED1 : 2;
|
||||
reg_t RESERVED2 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(SPI_EN_Type) == sizeof(reg_t), "SPI_EN_Type wrong size");
|
||||
|
||||
struct SYN_FR_DIV_1_Type {
|
||||
reg_t SYN_FRDIV_9_0 : 10;
|
||||
reg_t RESERVED0 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(SYN_FR_DIV_1_Type) == sizeof(reg_t), "SYN_FR_DIV_1_Type wrong size");
|
||||
|
||||
struct SYN_FR_DIV_2_Type {
|
||||
reg_t SYN_FRDIV_19_10 : 10;
|
||||
reg_t RESERVED0 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(SYN_FR_DIV_2_Type) == sizeof(reg_t), "SYN_FR_DIV_2_Type wrong size");
|
||||
|
||||
struct SYN_INT_DIV_Type {
|
||||
reg_t SYN_INTDIV : 8;
|
||||
reg_t LOGEN_BSW : 2;
|
||||
reg_t RESERVED0 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(SYN_INT_DIV_Type) == sizeof(reg_t), "SYN_INT_DIV_Type wrong size");
|
||||
|
||||
struct SYN_CFG_1_Type {
|
||||
reg_t RESERVED0 : 1;
|
||||
reg_t SYN_REF_DIV_RATIO : 2;
|
||||
reg_t RESERVED1 : 2;
|
||||
reg_t SYN_CLOCKOUT_DRIVE : 1;
|
||||
reg_t RESERVED2 : 4;
|
||||
reg_t RESERVED3 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(SYN_CFG_1_Type) == sizeof(reg_t), "SYN_CFG_1_Type wrong size");
|
||||
|
||||
struct SYN_CFG_2_Type {
|
||||
reg_t RESERVED0 : 10;
|
||||
reg_t RESERVED1 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(SYN_CFG_2_Type) == sizeof(reg_t), "SYN_CFG_2_Type wrong size");
|
||||
|
||||
struct VAS_CFG_Type {
|
||||
reg_t VAS_MODE : 1;
|
||||
reg_t VAS_RELOCK_SEL : 1;
|
||||
reg_t VAS_DIV : 3;
|
||||
reg_t VAS_DLY : 2;
|
||||
reg_t VAS_TRIG_EN : 1;
|
||||
reg_t RESERVED0 : 2;
|
||||
reg_t RESERVED1 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(VAS_CFG_Type) == sizeof(reg_t), "VAS_CFG_Type wrong size");
|
||||
|
||||
struct LO_MISC_Type {
|
||||
reg_t VAS_SPI : 5;
|
||||
reg_t XTAL_BIAS_SEL : 2;
|
||||
reg_t RESERVED0 : 3;
|
||||
reg_t RESERVED1 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(LO_MISC_Type) == sizeof(reg_t), "LO_MISC_Type wrong size");
|
||||
|
||||
struct XTAL_CFG_Type {
|
||||
reg_t XTAL_FTUNE : 7;
|
||||
reg_t RESERVED0 : 1;
|
||||
reg_t XTAL_CLKOUT_DIV : 1;
|
||||
reg_t XTAL_CORE_EN : 1;
|
||||
reg_t RESERVED1 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(XTAL_CFG_Type) == sizeof(reg_t), "XTAL_CFG_Type wrong size");
|
||||
|
||||
struct VCO_CFG_Type {
|
||||
reg_t RESERVED0 : 10;
|
||||
reg_t RESERVED1 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(VCO_CFG_Type) == sizeof(reg_t), "VCO_CFG_Type wrong size");
|
||||
|
||||
struct LO_GEN_Type {
|
||||
reg_t RESERVED0 : 3;
|
||||
reg_t LOGEN_2GM : 1;
|
||||
reg_t RESERVED1 : 2;
|
||||
reg_t VAS_TST : 4;
|
||||
reg_t RESERVED2 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(LO_GEN_Type) == sizeof(reg_t), "LO_GEN_Type wrong size");
|
||||
|
||||
struct PA_DRV_Type {
|
||||
reg_t TXLO_IQ_SPI : 6;
|
||||
reg_t TXLO_IQ_SPI_EN : 1;
|
||||
reg_t TXVGA_GAIN_SPI_EN : 1;
|
||||
reg_t TX_DCCORR_SPI_EN : 1;
|
||||
reg_t RESERVED0 : 1;
|
||||
reg_t RESERVED1 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(PA_DRV_Type) == sizeof(reg_t), "PA_DRV_Type wrong size");
|
||||
|
||||
struct PA_DAC_Type {
|
||||
reg_t PADAC_BIAS : 6;
|
||||
reg_t PADAC_DLY : 4;
|
||||
reg_t RESERVED0 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(PA_DAC_Type) == sizeof(reg_t), "PA_DAC_Type wrong size");
|
||||
|
||||
struct TX_GAIN_Type {
|
||||
reg_t TXVGA_GAIN_SPI : 6;
|
||||
reg_t RESERVED0 : 4;
|
||||
reg_t RESERVED1 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(TX_GAIN_Type) == sizeof(reg_t), "TX_GAIN_Type wrong size");
|
||||
|
||||
struct TX_LO_IQ_Type {
|
||||
reg_t TX_DCCORR_I : 6;
|
||||
reg_t RESERVED0 : 2;
|
||||
reg_t PADAC_IV : 1;
|
||||
reg_t PADAC_VMODE : 1;
|
||||
reg_t RESERVED1 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(TX_LO_IQ_Type) == sizeof(reg_t), "TX_LO_IQ_Type wrong size");
|
||||
|
||||
struct TX_DC_CORR_Type {
|
||||
reg_t TX_DCCORR_Q : 6;
|
||||
reg_t RESERVED0 : 3;
|
||||
reg_t PADAC_DIVH : 1;
|
||||
reg_t RESERVED1 : 6;
|
||||
};
|
||||
|
||||
static_assert(sizeof(TX_DC_CORR_Type) == sizeof(reg_t), "TX_DC_CORR_Type wrong size");
|
||||
|
||||
struct Register_Type {
|
||||
RXENABLE_Type rxenable; /* 0 */
|
||||
RXRF_1_Type rxrf_1;
|
||||
RXRF_2_Type rxrf_2;
|
||||
RXRF_LPF_Type rxrf_lpf_1;
|
||||
LPF_Type lpf; /* 4 */
|
||||
LPF_VGA_1_Type lpf_vga_1;
|
||||
LPF_VGA_2_Type lpf_vga_2;
|
||||
RSSI_VGA_Type rssi_vga;
|
||||
RX_TOP_1_Type rx_top_1; /* 8 */
|
||||
RX_TOP_2_Type rx_top_2;
|
||||
TX_TOP_1_Type tx_top_1;
|
||||
TEMP_SENSE_Type temp_sense;
|
||||
HPFSM_1_Type hpfsm_1; /* 12 */
|
||||
HPFSM_2_Type hpfsm_2;
|
||||
HPFSM_3_Type hpfsm_3;
|
||||
HPFSM_4_Type hpfsm_4;
|
||||
SPI_EN_Type spi_en; /* 16 */
|
||||
SYN_FR_DIV_1_Type syn_fr_div_1;
|
||||
SYN_FR_DIV_2_Type syn_fr_div_2;
|
||||
SYN_INT_DIV_Type syn_int_div;
|
||||
SYN_CFG_1_Type syn_cfg_1; /* 20 */
|
||||
SYN_CFG_2_Type syn_cfg_2;
|
||||
VAS_CFG_Type vas_cfg;
|
||||
LO_MISC_Type lo_misc;
|
||||
XTAL_CFG_Type xtal_cfg; /* 24 */
|
||||
VCO_CFG_Type vco_cfg;
|
||||
LO_GEN_Type lo_gen;
|
||||
PA_DRV_Type pa_drv;
|
||||
PA_DAC_Type pa_dac; /* 28 */
|
||||
TX_GAIN_Type tx_gain;
|
||||
TX_LO_IQ_Type tx_lo_iq;
|
||||
TX_DC_CORR_Type tx_dc_corr;
|
||||
};
|
||||
|
||||
static_assert(sizeof(Register_Type) == reg_count * sizeof(reg_t), "Register_Type wrong size");
|
||||
|
||||
struct RegisterMap {
|
||||
constexpr RegisterMap(
|
||||
Register_Type values
|
||||
) : r(values)
|
||||
{
|
||||
}
|
||||
|
||||
union {
|
||||
Register_Type r;
|
||||
std::array<reg_t, reg_count> w;
|
||||
};
|
||||
};
|
||||
|
||||
static_assert(sizeof(RegisterMap) == reg_count * sizeof(reg_t), "RegisterMap type wrong size");
|
||||
|
||||
constexpr RegisterMap initial_register_values { Register_Type {
|
||||
/* settings recommended by MAX2839 data sheet */
|
||||
.rxenable = { /* 0 */
|
||||
.RESERVED0 = 0,
|
||||
.RESERVED1 = 0,
|
||||
},
|
||||
.rxrf_1 = { /* 1 */
|
||||
.LNAband = 0,
|
||||
.RESERVED0 = 0,
|
||||
.MIMOmode = 1,
|
||||
.iqerr_trim = 0b000001,
|
||||
.RESERVED1 = 0,
|
||||
},
|
||||
.rxrf_2 = { /* 2 */
|
||||
.LNAgain_SPI_EN = 0,
|
||||
.RESERVED0 = 0,
|
||||
.RX_IQERR_SPI_EN = 0,
|
||||
.RESERVED1 = 0b0010000,
|
||||
.RESERVED2 = 0,
|
||||
},
|
||||
.rxrf_lpf_1 = { /* 3 */
|
||||
.RESERVED0 = 0b0110111001,
|
||||
.RESERVED1 = 0,
|
||||
},
|
||||
.lpf = { /* 4 */
|
||||
.RESERVED0 = 0b10,
|
||||
.dF = 0b01,
|
||||
.RESERVED1 = 0b10,
|
||||
.FT = 0b1111,
|
||||
.RESERVED2 = 0,
|
||||
},
|
||||
.lpf_vga_1 = { /* 5 */
|
||||
.L = 0b00,
|
||||
.VGA = 0b000000,
|
||||
.ModeCtrl = 0b01,
|
||||
.RESERVED0 = 0,
|
||||
},
|
||||
.lpf_vga_2 = { /* 6 */
|
||||
.L = 0b00,
|
||||
.VGA = 0b000000,
|
||||
.BUFF_VCM = 0b00,
|
||||
.RESERVED0 = 0,
|
||||
},
|
||||
.rssi_vga = { /* 7 */
|
||||
.RESERVED0 = 0,
|
||||
.RSSI_MUX = 0,
|
||||
.RSSI_MODE = 0,
|
||||
.RESERVED1 = 0b0001,
|
||||
.RXBB_OUT_SEL = 0,
|
||||
.RESERVED2 = 0,
|
||||
.RSSI_INPUT = 1,
|
||||
.RESERVED3 = 0,
|
||||
},
|
||||
.rx_top_1 = { /* 8 */
|
||||
.RESERVED0 = 0,
|
||||
.VGAgain_SPI_EN = 0,
|
||||
.LPF_MODE_SEL = 0,
|
||||
.RESERVED1 = 0b1000100,
|
||||
.RESERVED2 = 0,
|
||||
},
|
||||
.rx_top_2 = { /* 9 */
|
||||
.ts_adc_trigger = 0,
|
||||
.ts_en = 0,
|
||||
.RESERVED0 = 0,
|
||||
.DOUT_DRVH = 1,
|
||||
.DOUT_CSB_SEL = 1,
|
||||
.DOUT_SEL = 0b000,
|
||||
.RESERVED1 = 0b00,
|
||||
.RESERVED2 = 0,
|
||||
},
|
||||
.tx_top_1 = { /* 10 */
|
||||
.TXCAL_GAIN = 0b00,
|
||||
.TXCAL_V2I_FILT = 0b011,
|
||||
.RESERVED1 = 0b00000,
|
||||
.RESERVED2 = 0,
|
||||
},
|
||||
.temp_sense = { /* 11 */
|
||||
.RESERVED0 = 0b0000000100,
|
||||
.RESERVED1 = 0,
|
||||
},
|
||||
.hpfsm_1 = { /* 12 */
|
||||
.HPC_10M = 0b11,
|
||||
.HPC_10M_GAIN = 0b11,
|
||||
.HPC_600k = 0b100,
|
||||
.HPC_600k_GAIN = 0b100,
|
||||
.RESERVED0 = 0,
|
||||
},
|
||||
.hpfsm_2 = { /* 13 */
|
||||
.HPC_100k = 0b00,
|
||||
.HPC_100k_GAIN = 0b00,
|
||||
.HPC_30k = 0b01,
|
||||
.HPC_30k_GAIN = 0b01,
|
||||
.HPC_1k = 0b01,
|
||||
.RESERVED0 = 0,
|
||||
},
|
||||
.hpfsm_3 = { /* 14 */
|
||||
.HPC_1k_B7B6 = 0b01,
|
||||
.HPC_DELAY = 0b01,
|
||||
.HPC_STOP = 0b00,
|
||||
.HPC_STOP_M2 = 0b11,
|
||||
.HPC_RXGAIN_EN = 1,
|
||||
.TXGATE_EN = 1,
|
||||
.RESERVED0 = 0,
|
||||
},
|
||||
.hpfsm_4 = { /* 15 */
|
||||
.HPC_DIVH = 1,
|
||||
.RESERVED0 = 0b00000,
|
||||
.HPC_SEQ_BYP = 0,
|
||||
.RESERVED1 = 0b00,
|
||||
.HPC_MODE = 1,
|
||||
.RESERVED2 = 0,
|
||||
},
|
||||
.spi_en = { /* 16 */
|
||||
.EN_SPI = 0,
|
||||
.CAL_SPI = 0,
|
||||
.RESERVED0 = 0b0111,
|
||||
.PADAC_SPI_EN = 0,
|
||||
.PADAC_TX_EN = 0,
|
||||
.RESERVED1 = 0b00,
|
||||
.RESERVED2 = 0,
|
||||
},
|
||||
.syn_fr_div_1 = { /* 17 */
|
||||
.SYN_FRDIV_9_0 = 0b0101010101,
|
||||
.RESERVED0 = 0,
|
||||
},
|
||||
.syn_fr_div_2 = { /* 18 */
|
||||
.SYN_FRDIV_19_10 = 0b0101010101,
|
||||
.RESERVED0 = 0,
|
||||
},
|
||||
.syn_int_div = { /* 19 */
|
||||
.SYN_INTDIV = 0b01010011,
|
||||
.LOGEN_BSW = 0b01,
|
||||
.RESERVED0 = 0,
|
||||
},
|
||||
.syn_cfg_1 = { /* 20 */
|
||||
.RESERVED0 = 1,
|
||||
.SYN_REF_DIV_RATIO = 0b00,
|
||||
.RESERVED1 = 0b01,
|
||||
.SYN_CLOCKOUT_DRIVE = 0,
|
||||
.RESERVED2 = 0b1001,
|
||||
.RESERVED3 = 0,
|
||||
},
|
||||
.syn_cfg_2 = { /* 21 */
|
||||
.RESERVED0 = 0b0000101101,
|
||||
.RESERVED1 = 0,
|
||||
},
|
||||
.vas_cfg = { /* 22 */
|
||||
.VAS_MODE = 1,
|
||||
.VAS_RELOCK_SEL = 0,
|
||||
.VAS_DIV = 0b010,
|
||||
.VAS_DLY = 0b01,
|
||||
.VAS_TRIG_EN = 1,
|
||||
.RESERVED0 = 0b01,
|
||||
.RESERVED1 = 0,
|
||||
},
|
||||
.lo_misc = { /* 23 */
|
||||
.VAS_SPI = 0b01111,
|
||||
.XTAL_BIAS_SEL = 0b10,
|
||||
.RESERVED0 = 0b100,
|
||||
.RESERVED1 = 0,
|
||||
},
|
||||
.xtal_cfg = { /* 24 */
|
||||
.XTAL_FTUNE = 0b0000000,
|
||||
.RESERVED0 = 1,
|
||||
.XTAL_CLKOUT_DIV = 1,
|
||||
.XTAL_CORE_EN = 0,
|
||||
.RESERVED1 = 0,
|
||||
},
|
||||
.vco_cfg = { /* 25 */
|
||||
.RESERVED0 = 0b0000000000,
|
||||
.RESERVED1 = 0,
|
||||
},
|
||||
.lo_gen = { /* 26 */
|
||||
.RESERVED0 = 0b000,
|
||||
.LOGEN_2GM = 0,
|
||||
.RESERVED1 = 0b00,
|
||||
.VAS_TST = 0b1111,
|
||||
.RESERVED2 = 0,
|
||||
},
|
||||
.pa_drv = { /* 27 */
|
||||
.TXLO_IQ_SPI = 0b000000,
|
||||
.TXLO_IQ_SPI_EN = 0,
|
||||
.TXVGA_GAIN_SPI_EN = 0,
|
||||
.TX_DCCORR_SPI_EN = 0,
|
||||
.RESERVED0 = 1,
|
||||
.RESERVED1 = 0,
|
||||
},
|
||||
.pa_dac = { /* 28 */
|
||||
.PADAC_BIAS = 0b000000,
|
||||
.PADAC_DLY = 0b0011,
|
||||
.RESERVED0 = 0,
|
||||
},
|
||||
.tx_gain = { /* 29 */
|
||||
.TXVGA_GAIN_SPI = 0b111111,
|
||||
.RESERVED0 = 0b0000,
|
||||
.RESERVED1 = 0,
|
||||
},
|
||||
.tx_lo_iq = { /* 30 */
|
||||
.TX_DCCORR_I = 0b000000,
|
||||
.RESERVED0 = 0b00,
|
||||
.PADAC_IV = 1,
|
||||
.PADAC_VMODE = 1,
|
||||
.RESERVED1 = 0,
|
||||
},
|
||||
.tx_dc_corr = { /* 31 */
|
||||
.TX_DCCORR_Q = 0b000000,
|
||||
.RESERVED0 = 0b101,
|
||||
.PADAC_DIVH = 1,
|
||||
.RESERVED1 = 0,
|
||||
},
|
||||
} };
|
||||
|
||||
class MAX2839 : public MAX283x {
|
||||
public:
|
||||
constexpr MAX2839(
|
||||
spi::arbiter::Target& target
|
||||
) : _target(target)
|
||||
{
|
||||
}
|
||||
|
||||
void init() override;
|
||||
void set_mode(const Mode mode) override;
|
||||
|
||||
void set_tx_vga_gain(const int_fast8_t db) override;
|
||||
void set_lna_gain(const int_fast8_t db) override;
|
||||
void set_vga_gain(const int_fast8_t db) override;
|
||||
void set_lpf_rf_bandwidth(const uint32_t bandwidth_minimum) override;
|
||||
bool set_frequency(const rf::Frequency lo_frequency) override;
|
||||
void set_rx_lo_iq_calibration(const size_t v) override;
|
||||
void set_rx_buff_vcm(const size_t v) override;
|
||||
|
||||
reg_t temp_sense() override;
|
||||
|
||||
reg_t read(const address_t reg_num) override;
|
||||
|
||||
private:
|
||||
spi::arbiter::Target& _target;
|
||||
|
||||
RegisterMap _map { initial_register_values };
|
||||
DirtyRegisters<Register, reg_count> _dirty { };
|
||||
|
||||
void flush_one(const Register reg);
|
||||
|
||||
void write(const address_t reg_num, const reg_t value);
|
||||
|
||||
void write(const Register reg, const reg_t value);
|
||||
reg_t read(const Register reg);
|
||||
|
||||
void flush();
|
||||
|
||||
void configure_rx_gain();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif/*__MAX2839_H__*/
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Great Scott Gadgets
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __MAX283X_H__
|
||||
#define __MAX283X_H__
|
||||
|
||||
#include "rf_path.hpp"
|
||||
|
||||
namespace max283x {
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
namespace lo {
|
||||
|
||||
constexpr std::array<rf::FrequencyRange, 4> band { {
|
||||
{ 2300000000, 2400000000 },
|
||||
{ 2400000000, 2500000000 },
|
||||
{ 2500000000, 2600000000 },
|
||||
{ 2600000000, 2700000000 },
|
||||
} };
|
||||
|
||||
} /* namespace lo */
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
namespace lna {
|
||||
|
||||
constexpr range_t<int8_t> gain_db_range { 0, 40 };
|
||||
constexpr int8_t gain_db_step = 8;
|
||||
|
||||
constexpr std::array<rf::FrequencyRange, 2> band { {
|
||||
{ 2300000000, 2500000000 },
|
||||
{ 2500000000, 2700000000 },
|
||||
} };
|
||||
|
||||
} /* namespace lna */
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
namespace vga {
|
||||
|
||||
constexpr range_t<int8_t> gain_db_range { 0, 62 };
|
||||
constexpr int8_t gain_db_step = 2;
|
||||
|
||||
} /* namespace vga */
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
namespace tx {
|
||||
|
||||
constexpr range_t<int8_t> gain_db_range { 0, 47 };
|
||||
constexpr int8_t gain_db_step = 1;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
namespace filter {
|
||||
|
||||
constexpr std::array<uint32_t, 16> bandwidths {
|
||||
/* Assumption: these values are in ascending order */
|
||||
1750000,
|
||||
2500000, /* Some documentation says 2.25MHz */
|
||||
3500000,
|
||||
5000000,
|
||||
5500000,
|
||||
6000000,
|
||||
7000000,
|
||||
8000000,
|
||||
9000000,
|
||||
10000000,
|
||||
12000000,
|
||||
14000000,
|
||||
15000000,
|
||||
20000000,
|
||||
24000000,
|
||||
28000000,
|
||||
};
|
||||
|
||||
constexpr auto bandwidth_minimum = bandwidths[0];
|
||||
constexpr auto bandwidth_maximum = bandwidths[bandwidths.size() - 1];
|
||||
|
||||
} /* namespace filter */
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
enum Mode {
|
||||
Shutdown,
|
||||
Standby,
|
||||
Receive,
|
||||
Transmit,
|
||||
};
|
||||
|
||||
using reg_t = uint16_t;
|
||||
using address_t = uint8_t;
|
||||
|
||||
class MAX283x {
|
||||
public:
|
||||
virtual ~MAX283x() = default;
|
||||
|
||||
virtual void init();
|
||||
virtual void set_mode(const Mode mode);
|
||||
|
||||
virtual void set_tx_vga_gain(const int_fast8_t db);
|
||||
virtual void set_lna_gain(const int_fast8_t db);
|
||||
virtual void set_vga_gain(const int_fast8_t db);
|
||||
virtual void set_lpf_rf_bandwidth(const uint32_t bandwidth_minimum);
|
||||
|
||||
virtual bool set_frequency(const rf::Frequency lo_frequency);
|
||||
|
||||
virtual void set_rx_lo_iq_calibration(const size_t v);
|
||||
virtual void set_rx_buff_vcm(const size_t v);
|
||||
|
||||
virtual reg_t temp_sense();
|
||||
|
||||
virtual reg_t read(const address_t reg_num);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif/*__MAX283X_H__*/
|
||||
@@ -372,6 +372,10 @@ public:
|
||||
while(device_status() & 0x80);
|
||||
}
|
||||
|
||||
bool plla_loss_of_signal() {
|
||||
return (device_status() >> 5) & 1;
|
||||
}
|
||||
|
||||
bool clkin_loss_of_signal() {
|
||||
return (device_status() >> 4) & 1;
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ int main(void) {
|
||||
portapack::shutdown();
|
||||
}
|
||||
|
||||
m4_init(portapack::spi_flash::image_tag_hackrf, portapack::memory::map::m4_code_hackrf);
|
||||
m4_init(portapack::spi_flash::image_tag_hackrf, portapack::memory::map::m4_code_hackrf, true);
|
||||
m0_halt();
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -381,8 +381,9 @@ static void shutdown_base() {
|
||||
*
|
||||
* PLL0USB = powered down
|
||||
* PLL0AUDIO = GP_CLKIN, Fcco=491.52 MHz, Fout=12.288 MHz
|
||||
* PLL1 = GP_CLKIN * 10 = 200 MHz
|
||||
*
|
||||
* PLL1 =
|
||||
* OG: GP_CLKIN * 10 = 200 MHz
|
||||
* r9: GP_CLKIN * 20 = 200 MHz
|
||||
* IDIVA = IRC / 1 = 12 MHz
|
||||
* IDIVB = PLL1 / 2 = 100 MHz
|
||||
* IDIVC = PLL1 / 1 = 200 MHz
|
||||
@@ -432,9 +433,14 @@ bool init() {
|
||||
*/
|
||||
|
||||
/* Step into the 90-110MHz M4 clock range */
|
||||
/* Fclkin = 40M
|
||||
* /N=2 = 20M = PFDin
|
||||
* Fcco = PFDin * (M=10) = 200M
|
||||
/* OG:
|
||||
* Fclkin = 40M
|
||||
* /N=2 = 20M = PFDin
|
||||
* Fcco = PFDin * (M=10) = 200M
|
||||
* r9:
|
||||
* Fclkin = 10M
|
||||
* /N=1 = 10M = PFDin
|
||||
* Fcco = PFDin * (M=20) = 200M
|
||||
* Fclk = Fcco / (2*(P=1)) = 100M
|
||||
*/
|
||||
cgu::pll1::ctrl({
|
||||
@@ -444,8 +450,8 @@ bool init() {
|
||||
.direct = 0,
|
||||
.psel = 0,
|
||||
.autoblock = 1,
|
||||
.nsel = 1,
|
||||
.msel = 9,
|
||||
.nsel = hackrf_r9 ? 0UL : 1UL,
|
||||
.msel = hackrf_r9 ? 19UL : 9UL,
|
||||
.clk_sel = cgu::CLK_SEL::GP_CLKIN,
|
||||
});
|
||||
|
||||
@@ -474,8 +480,7 @@ bool init() {
|
||||
chThdSleepMilliseconds(10);
|
||||
|
||||
clock_manager.set_reference_ppb(persistent_memory::correction_ppb());
|
||||
clock_manager.enable_first_if_clock();
|
||||
clock_manager.enable_second_if_clock();
|
||||
clock_manager.enable_if_clocks();
|
||||
clock_manager.enable_codec_clocks();
|
||||
radio::init();
|
||||
|
||||
|
||||
@@ -28,12 +28,12 @@
|
||||
#define __ENCODERS_H__
|
||||
|
||||
namespace encoders {
|
||||
|
||||
|
||||
#define ENC_TYPES_COUNT 14
|
||||
#define OOK_SAMPLERATE 2280000U
|
||||
|
||||
|
||||
#define ENCODER_UM3750 8
|
||||
|
||||
|
||||
size_t make_bitstream(std::string& fragments);
|
||||
void bitstream_append(size_t& bitstream_length, uint32_t bit_count, uint32_t bits);
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace encoders {
|
||||
150000, 2,
|
||||
0
|
||||
},
|
||||
|
||||
|
||||
// PT2260-R4
|
||||
{
|
||||
"2260-R4",
|
||||
@@ -77,7 +77,7 @@ namespace encoders {
|
||||
150000, 2,
|
||||
0
|
||||
},
|
||||
|
||||
|
||||
// PT2262
|
||||
{
|
||||
"2262 ",
|
||||
@@ -89,7 +89,7 @@ namespace encoders {
|
||||
20000, 4,
|
||||
0
|
||||
},
|
||||
|
||||
|
||||
// 16-bit ?
|
||||
{
|
||||
"16-bit ",
|
||||
@@ -101,7 +101,7 @@ namespace encoders {
|
||||
25000, 50,
|
||||
0 // ?
|
||||
},
|
||||
|
||||
|
||||
// RT1527
|
||||
{
|
||||
"1527 ",
|
||||
@@ -111,9 +111,9 @@ namespace encoders {
|
||||
24, "SAAAAAAAAAAAAAAAAAAAADDDD",
|
||||
"10000000000000000000000000000000",
|
||||
100000, 4,
|
||||
10 // ?
|
||||
0
|
||||
},
|
||||
|
||||
|
||||
// HK526E
|
||||
{
|
||||
"526E ",
|
||||
@@ -125,7 +125,7 @@ namespace encoders {
|
||||
20000, 4,
|
||||
10 // ?
|
||||
},
|
||||
|
||||
|
||||
// HT12E
|
||||
{
|
||||
"12E ",
|
||||
@@ -137,7 +137,7 @@ namespace encoders {
|
||||
3000, 4,
|
||||
10 // ?
|
||||
},
|
||||
|
||||
|
||||
// VD5026 13 bits ?
|
||||
{
|
||||
"5026 ",
|
||||
@@ -149,7 +149,7 @@ namespace encoders {
|
||||
100000, 4,
|
||||
10 // ?
|
||||
},
|
||||
|
||||
|
||||
// UM3750
|
||||
{
|
||||
"UM3750 ",
|
||||
@@ -161,7 +161,7 @@ namespace encoders {
|
||||
100000, 4,
|
||||
(3 * 12) - 6 // Compensates for pause delay bug in proc_ook
|
||||
},
|
||||
|
||||
|
||||
// UM3758
|
||||
{
|
||||
"UM3758 ",
|
||||
@@ -173,7 +173,7 @@ namespace encoders {
|
||||
160000, 4,
|
||||
10 // ?
|
||||
},
|
||||
|
||||
|
||||
// BA5104
|
||||
{
|
||||
"BA5104 ",
|
||||
@@ -185,7 +185,7 @@ namespace encoders {
|
||||
455000, 4,
|
||||
10 // ?
|
||||
},
|
||||
|
||||
|
||||
// MC145026
|
||||
{
|
||||
"145026 ",
|
||||
@@ -197,7 +197,7 @@ namespace encoders {
|
||||
455000, 2,
|
||||
2
|
||||
},
|
||||
|
||||
|
||||
// HT6*** TODO: Add individual variations
|
||||
{
|
||||
"HT6*** ",
|
||||
@@ -209,7 +209,7 @@ namespace encoders {
|
||||
80000, 3,
|
||||
10 // ?
|
||||
},
|
||||
|
||||
|
||||
// TC9148
|
||||
{
|
||||
"TC9148 ",
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "rffc507x.hpp"
|
||||
#include "max2837.hpp"
|
||||
#include "max2839.hpp"
|
||||
#include "max5864.hpp"
|
||||
#include "baseband_cpld.hpp"
|
||||
|
||||
@@ -39,6 +40,7 @@ using namespace hackrf::one;
|
||||
#include "cpld_update.hpp"
|
||||
|
||||
#include "portapack.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
|
||||
namespace radio {
|
||||
|
||||
@@ -52,12 +54,12 @@ static constexpr uint32_t ssp_scr(
|
||||
return static_cast<uint8_t>(pclk_f / cpsr / spi_f - 1);
|
||||
}
|
||||
|
||||
static constexpr SPIConfig ssp_config_max2837 = {
|
||||
static constexpr SPIConfig ssp_config_max283x = {
|
||||
.end_cb = NULL,
|
||||
.ssport = gpio_max2837_select.port(),
|
||||
.sspad = gpio_max2837_select.pad(),
|
||||
.ssport = gpio_max283x_select.port(),
|
||||
.sspad = gpio_max283x_select.pad(),
|
||||
.cr0 =
|
||||
CR0_CLOCKRATE(ssp_scr(ssp1_pclk_f, ssp1_cpsr, max2837_spi_f))
|
||||
CR0_CLOCKRATE(ssp_scr(ssp1_pclk_f, ssp1_cpsr, max283x_spi_f))
|
||||
| CR0_FRFSPI
|
||||
| CR0_DSS16BIT
|
||||
,
|
||||
@@ -78,9 +80,9 @@ static constexpr SPIConfig ssp_config_max5864 = {
|
||||
|
||||
static spi::arbiter::Arbiter ssp1_arbiter(portapack::ssp1);
|
||||
|
||||
static spi::arbiter::Target ssp1_target_max2837 {
|
||||
static spi::arbiter::Target ssp1_target_max283x {
|
||||
ssp1_arbiter,
|
||||
ssp_config_max2837
|
||||
ssp_config_max283x
|
||||
};
|
||||
|
||||
static spi::arbiter::Target ssp1_target_max5864 {
|
||||
@@ -90,16 +92,27 @@ static spi::arbiter::Target ssp1_target_max5864 {
|
||||
|
||||
static rf::path::Path rf_path;
|
||||
rffc507x::RFFC507x first_if;
|
||||
max2837::MAX2837 second_if { ssp1_target_max2837 };
|
||||
max283x::MAX283x *second_if;
|
||||
max2837::MAX2837 second_if_max2837 { ssp1_target_max283x };
|
||||
max2839::MAX2839 second_if_max2839 { ssp1_target_max283x };
|
||||
static max5864::MAX5864 baseband_codec { ssp1_target_max5864 };
|
||||
static baseband::CPLD baseband_cpld;
|
||||
|
||||
static rf::Direction direction { rf::Direction::Receive };
|
||||
static bool baseband_invert = false;
|
||||
static bool mixer_invert = false;
|
||||
|
||||
void init() {
|
||||
if (hackrf_r9) {
|
||||
gpio_r9_not_ant_pwr.write(1);
|
||||
gpio_r9_not_ant_pwr.output();
|
||||
}
|
||||
rf_path.init();
|
||||
first_if.init();
|
||||
second_if.init();
|
||||
second_if = hackrf_r9
|
||||
? (max283x::MAX283x *) &second_if_max2839
|
||||
: (max283x::MAX283x *) &second_if_max2837;
|
||||
second_if->init();
|
||||
baseband_codec.init();
|
||||
baseband_cpld.init();
|
||||
}
|
||||
@@ -121,7 +134,30 @@ void set_direction(const rf::Direction new_direction) {
|
||||
|
||||
direction = new_direction;
|
||||
|
||||
second_if.set_mode((direction == rf::Direction::Transmit) ? max2837::Mode::Transmit : max2837::Mode::Receive);
|
||||
if (hackrf_r9) {
|
||||
/*
|
||||
* HackRF One r9 inverts analog baseband only for RX. Previous hardware
|
||||
* revisions inverted analog baseband for neither direction because of
|
||||
* compensation in the CPLD. If we ever simplify the CPLD to handle RX
|
||||
* and TX the same way, we will need to update this baseband_invert
|
||||
* logic.
|
||||
*/
|
||||
baseband_invert = (direction == rf::Direction::Receive);
|
||||
} else {
|
||||
/*
|
||||
* Analog baseband is inverted in RX but not TX. The RX inversion is
|
||||
* corrected by the CPLD, but future hardware or CPLD changes may
|
||||
* change this for either or both directions. For a given hardware+CPLD
|
||||
* platform, baseband inversion is set here for RX and/or TX. Spectrum
|
||||
* inversion resulting from the mixer is tracked separately according
|
||||
* to the tuning configuration. We ask the CPLD to apply a correction
|
||||
* for the total inversion.
|
||||
*/
|
||||
baseband_invert = false;
|
||||
}
|
||||
baseband_cpld.set_invert(mixer_invert ^ baseband_invert);
|
||||
|
||||
second_if->set_mode((direction == rf::Direction::Transmit) ? max283x::Mode::Transmit : max283x::Mode::Receive);
|
||||
rf_path.set_direction(direction);
|
||||
|
||||
baseband_codec.set_mode((direction == rf::Direction::Transmit) ? max5864::Mode::Transmit : max5864::Mode::Receive);
|
||||
@@ -133,7 +169,11 @@ void set_direction(const rf::Direction new_direction) {
|
||||
}
|
||||
|
||||
bool set_tuning_frequency(const rf::Frequency frequency) {
|
||||
const auto tuning_config = tuning::config::create(frequency);
|
||||
rf::Frequency final_frequency = frequency ;
|
||||
if( portapack::persistent_memory::config_hamitup() ) {
|
||||
final_frequency = frequency + portapack::persistent_memory::config_hamitup_freq();
|
||||
}
|
||||
const auto tuning_config = tuning::config::create(final_frequency);
|
||||
if( tuning_config.is_valid() ) {
|
||||
first_if.disable();
|
||||
|
||||
@@ -142,10 +182,11 @@ bool set_tuning_frequency(const rf::Frequency frequency) {
|
||||
first_if.enable();
|
||||
}
|
||||
|
||||
const auto result_second_if = second_if.set_frequency(tuning_config.second_lo_frequency);
|
||||
const auto result_second_if = second_if->set_frequency(tuning_config.second_lo_frequency);
|
||||
|
||||
rf_path.set_band(tuning_config.rf_path_band);
|
||||
baseband_cpld.set_invert(tuning_config.baseband_invert);
|
||||
mixer_invert = tuning_config.mixer_invert;
|
||||
baseband_cpld.set_invert(mixer_invert ^ baseband_invert);
|
||||
|
||||
return result_second_if;
|
||||
} else {
|
||||
@@ -165,19 +206,19 @@ void set_rf_amp(const bool rf_amp) {
|
||||
}
|
||||
|
||||
void set_lna_gain(const int_fast8_t db) {
|
||||
second_if.set_lna_gain(db);
|
||||
second_if->set_lna_gain(db);
|
||||
}
|
||||
|
||||
void set_vga_gain(const int_fast8_t db) {
|
||||
second_if.set_vga_gain(db);
|
||||
second_if->set_vga_gain(db);
|
||||
}
|
||||
|
||||
void set_tx_gain(const int_fast8_t db) {
|
||||
second_if.set_tx_vga_gain(db);
|
||||
second_if->set_tx_vga_gain(db);
|
||||
}
|
||||
|
||||
void set_baseband_filter_bandwidth(const uint32_t bandwidth_minimum) {
|
||||
second_if.set_lpf_rf_bandwidth(bandwidth_minimum);
|
||||
second_if->set_lpf_rf_bandwidth(bandwidth_minimum);
|
||||
}
|
||||
|
||||
void set_baseband_rate(const uint32_t rate) {
|
||||
@@ -186,13 +227,17 @@ void set_baseband_rate(const uint32_t rate) {
|
||||
|
||||
void set_antenna_bias(const bool on) {
|
||||
/* Pull MOSFET gate low to turn on antenna bias. */
|
||||
first_if.set_gpo1(on ? 0 : 1);
|
||||
if (hackrf_r9) {
|
||||
gpio_r9_not_ant_pwr.write(on ? 0 : 1);
|
||||
} else {
|
||||
first_if.set_gpo1(on ? 0 : 1);
|
||||
}
|
||||
}
|
||||
|
||||
void disable() {
|
||||
set_antenna_bias(false);
|
||||
baseband_codec.set_mode(max5864::Mode::Shutdown);
|
||||
second_if.set_mode(max2837::Mode::Standby);
|
||||
second_if->set_mode(max2837::Mode::Standby);
|
||||
first_if.disable();
|
||||
set_rf_amp(false);
|
||||
|
||||
@@ -227,11 +272,11 @@ uint32_t register_read(const size_t register_number) {
|
||||
namespace second_if {
|
||||
|
||||
uint32_t register_read(const size_t register_number) {
|
||||
return radio::second_if.read(register_number);
|
||||
return radio::second_if->read(register_number);
|
||||
}
|
||||
|
||||
uint8_t temp_sense() {
|
||||
return radio::second_if.temp_sense() & 0x1f;
|
||||
return radio::second_if->temp_sense() & 0x1f;
|
||||
}
|
||||
|
||||
} /* namespace second_if */
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include "message.hpp"
|
||||
#include "rf_path.hpp"
|
||||
#include "max2837.hpp"
|
||||
#include "max283x.hpp"
|
||||
#include "volume.hpp"
|
||||
|
||||
class ReceiverModel {
|
||||
@@ -94,7 +94,7 @@ private:
|
||||
bool enabled_ { false };
|
||||
bool rf_amp_ { false };
|
||||
int32_t lna_gain_db_ { 32 };
|
||||
uint32_t baseband_bandwidth_ { max2837::filter::bandwidth_minimum };
|
||||
uint32_t baseband_bandwidth_ { max283x::filter::bandwidth_minimum };
|
||||
int32_t vga_gain_db_ { 32 };
|
||||
int32_t tx_gain_db_ { 47 };
|
||||
Mode mode_ { Mode::NarrowbandFMAudio };
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include "rf_path.hpp"
|
||||
#include "platform.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <initializer_list>
|
||||
@@ -34,14 +35,12 @@ namespace path {
|
||||
|
||||
namespace {
|
||||
|
||||
using GPIOs = std::array<GPIO, 13>;
|
||||
using GPIOs = std::array<GPIO, 11>;
|
||||
|
||||
/* TODO: ARM GCC 4.8 2014q3 doesn't like this array inside struct Config.
|
||||
* No idea why.
|
||||
*/
|
||||
constexpr GPIOs gpios {
|
||||
gpio_tx,
|
||||
gpio_rx,
|
||||
gpio_mix_bypass,
|
||||
gpio_not_mix_bypass,
|
||||
gpio_tx_mix_bp,
|
||||
@@ -122,15 +121,39 @@ struct Config {
|
||||
}
|
||||
|
||||
static void gpio_init() {
|
||||
for(auto gpio : gpios) {
|
||||
if (hackrf_r9) {
|
||||
gpio_r9_rx.output();
|
||||
} else {
|
||||
gpio_og_tx.output();
|
||||
gpio_og_rx.output();
|
||||
}
|
||||
for (auto gpio : gpios) {
|
||||
gpio.output();
|
||||
}
|
||||
}
|
||||
|
||||
void apply() const {
|
||||
/* NOTE: Assumes order in gpios[] and Config bitfield match. */
|
||||
for(size_t n=0; n<gpios.size(); n++) {
|
||||
gpios[n].write((*this)[n]);
|
||||
/* NOTE: Assumes order in gpios[] and Config bitfield match,
|
||||
* after the 'tx' and 'rx' fields which are handled specially. */
|
||||
for (size_t n = 0; n < gpios.size() + 2; n++) {
|
||||
bool value = (*this)[n];
|
||||
switch (n) {
|
||||
case 0:
|
||||
if (!hackrf_r9) {
|
||||
gpio_og_tx.write(value);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (hackrf_r9) {
|
||||
gpio_r9_rx.write(value);
|
||||
} else {
|
||||
gpio_og_rx.write(value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
gpios[n - 2].write(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -39,8 +39,8 @@ enum class Direction {
|
||||
|
||||
namespace path {
|
||||
|
||||
constexpr FrequencyRange band_low { 0, 2150000000 };
|
||||
constexpr FrequencyRange band_high { 2750000000, 7250000000 };
|
||||
constexpr FrequencyRange band_low { 0, 2170000000 };
|
||||
constexpr FrequencyRange band_high { 2740000000, 7250000000 };
|
||||
constexpr FrequencyRange band_mid { band_low.maximum, band_high.minimum };
|
||||
|
||||
enum class Band {
|
||||
|
||||
@@ -281,262 +281,262 @@ const std::array<ui::Color, 256> spectrum_rgb2_lut { {
|
||||
} };
|
||||
|
||||
const std::array<ui::Color, 256> spectrum_rgb3_lut { {
|
||||
{ 0x00, 0x00, 0x02 },
|
||||
{ 0x00, 0x00, 0x04 },
|
||||
{ 0x00, 0x00, 0x05 },
|
||||
{ 0x00, 0x00, 0x07 },
|
||||
{ 0x00, 0x00, 0x0a },
|
||||
{ 0x00, 0x00, 0x0c },
|
||||
{ 0x00, 0x00, 0x0e },
|
||||
{ 0x00, 0x00, 0x10 },
|
||||
{ 0x00, 0x00, 0x13 },
|
||||
{ 0x00, 0x00, 0x15 },
|
||||
{ 0x00, 0x00, 0x17 },
|
||||
{ 0x00, 0x00, 0x19 },
|
||||
{ 0x00, 0x00, 0x1b },
|
||||
{ 0x00, 0x00, 0x1d },
|
||||
{ 0x00, 0x00, 0x1f },
|
||||
{ 0x00, 0x00, 0x21 },
|
||||
{ 0x00, 0x00, 0x24 },
|
||||
{ 0x00, 0x00, 0x25 },
|
||||
{ 0x00, 0x00, 0x28 },
|
||||
{ 0x00, 0x00, 0x29 },
|
||||
{ 0x00, 0x00, 0x2c },
|
||||
{ 0x00, 0x00, 0x2e },
|
||||
{ 0x00, 0x00, 0x30 },
|
||||
{ 0x00, 0x00, 0x33 },
|
||||
{ 0x00, 0x00, 0x35 },
|
||||
{ 0x00, 0x00, 0x37 },
|
||||
{ 0x00, 0x00, 0x39 },
|
||||
{ 0x00, 0x00, 0x3b },
|
||||
{ 0x00, 0x00, 0x3d },
|
||||
{ 0x00, 0x00, 0x3f },
|
||||
{ 0x00, 0x00, 0x41 },
|
||||
{ 0x00, 0x00, 0x43 },
|
||||
{ 0x00, 0x00, 0x46 },
|
||||
{ 0x00, 0x00, 0x48 },
|
||||
{ 0x00, 0x00, 0x4a },
|
||||
{ 0x00, 0x00, 0x4c },
|
||||
{ 0x00, 0x00, 0x4e },
|
||||
{ 0x00, 0x00, 0x50 },
|
||||
{ 0x00, 0x00, 0x53 },
|
||||
{ 0x00, 0x00, 0x55 },
|
||||
{ 0x00, 0x00, 0x56 },
|
||||
{ 0x00, 0x00, 0x59 },
|
||||
{ 0x00, 0x00, 0x5b },
|
||||
{ 0x00, 0x00, 0x5d },
|
||||
{ 0x00, 0x00, 0x5f },
|
||||
{ 0x00, 0x00, 0x62 },
|
||||
{ 0x00, 0x00, 0x63 },
|
||||
{ 0x00, 0x00, 0x66 },
|
||||
{ 0x00, 0x00, 0x68 },
|
||||
{ 0x00, 0x00, 0x6a },
|
||||
{ 0x00, 0x00, 0x6c },
|
||||
{ 0x00, 0x00, 0x6e },
|
||||
{ 0x00, 0x00, 0x70 },
|
||||
{ 0x00, 0x00, 0x73 },
|
||||
{ 0x00, 0x00, 0x75 },
|
||||
{ 0x00, 0x00, 0x77 },
|
||||
{ 0x00, 0x00, 0x79 },
|
||||
{ 0x00, 0x00, 0x7b },
|
||||
{ 0x00, 0x00, 0x7d },
|
||||
{ 0x00, 0x00, 0x7f },
|
||||
{ 0x00, 0x00, 0x82 },
|
||||
{ 0x00, 0x00, 0x84 },
|
||||
{ 0x00, 0x00, 0x86 },
|
||||
{ 0x00, 0x00, 0x88 },
|
||||
{ 0x00, 0x00, 0x8a },
|
||||
{ 0x00, 0x00, 0x8c },
|
||||
{ 0x00, 0x00, 0x8e },
|
||||
{ 0x00, 0x00, 0x91 },
|
||||
{ 0x00, 0x00, 0x93 },
|
||||
{ 0x00, 0x00, 0x95 },
|
||||
{ 0x00, 0x00, 0x97 },
|
||||
{ 0x00, 0x00, 0x99 },
|
||||
{ 0x00, 0x00, 0x9b },
|
||||
{ 0x00, 0x00, 0x9d },
|
||||
{ 0x00, 0x00, 0x9f },
|
||||
{ 0x00, 0x00, 0xa2 },
|
||||
{ 0x00, 0x00, 0xa4 },
|
||||
{ 0x00, 0x00, 0xa6 },
|
||||
{ 0x00, 0x00, 0xa8 },
|
||||
{ 0x00, 0x00, 0xaa },
|
||||
{ 0x00, 0x00, 0xac },
|
||||
{ 0x00, 0x00, 0xae },
|
||||
{ 0x00, 0x00, 0xb1 },
|
||||
{ 0x00, 0x00, 0xb3 },
|
||||
{ 0x00, 0x00, 0xb5 },
|
||||
{ 0x00, 0x00, 0xb7 },
|
||||
{ 0x00, 0x00, 0xb9 },
|
||||
{ 0x00, 0x00, 0xbb },
|
||||
{ 0x00, 0x00, 0xbd },
|
||||
{ 0x00, 0x00, 0xbf },
|
||||
{ 0x00, 0x00, 0xc2 },
|
||||
{ 0x00, 0x00, 0xc4 },
|
||||
{ 0x00, 0x00, 0xc6 },
|
||||
{ 0x00, 0x00, 0xc8 },
|
||||
{ 0x00, 0x00, 0xca },
|
||||
{ 0x00, 0x00, 0xcc },
|
||||
{ 0x00, 0x00, 0xce },
|
||||
{ 0x00, 0x00, 0xd1 },
|
||||
{ 0x00, 0x00, 0xd3 },
|
||||
{ 0x00, 0x00, 0xd5 },
|
||||
{ 0x00, 0x00, 0xd7 },
|
||||
{ 0x00, 0x00, 0xd9 },
|
||||
{ 0x00, 0x00, 0xdb },
|
||||
{ 0x00, 0x00, 0xdd },
|
||||
{ 0x00, 0x00, 0xdf },
|
||||
{ 0x00, 0x00, 0xe2 },
|
||||
{ 0x00, 0x00, 0xe4 },
|
||||
{ 0x00, 0x00, 0xe6 },
|
||||
{ 0x00, 0x00, 0xe8 },
|
||||
{ 0x00, 0x00, 0xea },
|
||||
{ 0x00, 0x00, 0xec },
|
||||
{ 0x00, 0x00, 0xee },
|
||||
{ 0x00, 0x00, 0xf1 },
|
||||
{ 0x00, 0x00, 0xf3 },
|
||||
{ 0x00, 0x00, 0xf5 },
|
||||
{ 0x00, 0x00, 0xf7 },
|
||||
{ 0x00, 0x00, 0xf9 },
|
||||
{ 0x00, 0x00, 0xfb },
|
||||
{ 0x00, 0x00, 0xfd },
|
||||
{ 0x01, 0x00, 0xfe },
|
||||
{ 0x05, 0x00, 0xfa },
|
||||
{ 0x09, 0x00, 0xf6 },
|
||||
{ 0x0e, 0x00, 0xf2 },
|
||||
{ 0x12, 0x00, 0xed },
|
||||
{ 0x16, 0x00, 0xe9 },
|
||||
{ 0x1b, 0x00, 0xe4 },
|
||||
{ 0x1f, 0x00, 0xe0 },
|
||||
{ 0x24, 0x00, 0xdc },
|
||||
{ 0x27, 0x00, 0xd8 },
|
||||
{ 0x2c, 0x00, 0xd3 },
|
||||
{ 0x30, 0x00, 0xcf },
|
||||
{ 0x35, 0x00, 0xcb },
|
||||
{ 0x39, 0x00, 0xc6 },
|
||||
{ 0x3d, 0x00, 0xc2 },
|
||||
{ 0x42, 0x00, 0xbd },
|
||||
{ 0x46, 0x00, 0xb9 },
|
||||
{ 0x4b, 0x00, 0xb5 },
|
||||
{ 0x4f, 0x00, 0xb0 },
|
||||
{ 0x53, 0x00, 0xac },
|
||||
{ 0x58, 0x00, 0xa7 },
|
||||
{ 0x5c, 0x00, 0xa3 },
|
||||
{ 0x61, 0x00, 0x9f },
|
||||
{ 0x65, 0x00, 0x9a },
|
||||
{ 0x69, 0x00, 0x96 },
|
||||
{ 0x6e, 0x00, 0x91 },
|
||||
{ 0x72, 0x00, 0x8d },
|
||||
{ 0x77, 0x00, 0x89 },
|
||||
{ 0x7b, 0x00, 0x84 },
|
||||
{ 0x7f, 0x00, 0x80 },
|
||||
{ 0x84, 0x00, 0x7b },
|
||||
{ 0x88, 0x00, 0x77 },
|
||||
{ 0x8d, 0x00, 0x73 },
|
||||
{ 0x91, 0x00, 0x6e },
|
||||
{ 0x95, 0x00, 0x6a },
|
||||
{ 0x9a, 0x00, 0x65 },
|
||||
{ 0x9e, 0x00, 0x61 },
|
||||
{ 0xa3, 0x00, 0x5d },
|
||||
{ 0xa7, 0x00, 0x58 },
|
||||
{ 0xab, 0x00, 0x54 },
|
||||
{ 0xb0, 0x00, 0x4f },
|
||||
{ 0xb4, 0x00, 0x4b },
|
||||
{ 0xb9, 0x00, 0x47 },
|
||||
{ 0xbd, 0x00, 0x42 },
|
||||
{ 0xc1, 0x00, 0x3e },
|
||||
{ 0xc6, 0x00, 0x39 },
|
||||
{ 0xca, 0x00, 0x35 },
|
||||
{ 0xcf, 0x00, 0x31 },
|
||||
{ 0xd3, 0x00, 0x2c },
|
||||
{ 0xd7, 0x00, 0x28 },
|
||||
{ 0xdc, 0x00, 0x23 },
|
||||
{ 0xe0, 0x00, 0x1f },
|
||||
{ 0xe5, 0x00, 0x1b },
|
||||
{ 0xe9, 0x00, 0x16 },
|
||||
{ 0xed, 0x00, 0x12 },
|
||||
{ 0xf2, 0x00, 0x0d },
|
||||
{ 0xf6, 0x00, 0x09 },
|
||||
{ 0xfb, 0x00, 0x05 },
|
||||
{ 0xfe, 0x01, 0x01 },
|
||||
{ 0xff, 0x06, 0x00 },
|
||||
{ 0xff, 0x0d, 0x00 },
|
||||
{ 0xff, 0x13, 0x00 },
|
||||
{ 0xff, 0x1a, 0x00 },
|
||||
{ 0xff, 0x20, 0x00 },
|
||||
{ 0xff, 0x26, 0x00 },
|
||||
{ 0xff, 0x2d, 0x00 },
|
||||
{ 0xff, 0x33, 0x00 },
|
||||
{ 0xff, 0x3a, 0x00 },
|
||||
{ 0xff, 0x40, 0x00 },
|
||||
{ 0xff, 0x46, 0x00 },
|
||||
{ 0xff, 0x4d, 0x00 },
|
||||
{ 0xff, 0x53, 0x00 },
|
||||
{ 0xff, 0x59, 0x00 },
|
||||
{ 0xff, 0x60, 0x00 },
|
||||
{ 0xff, 0x66, 0x00 },
|
||||
{ 0xff, 0x6c, 0x00 },
|
||||
{ 0xff, 0x73, 0x00 },
|
||||
{ 0xff, 0x79, 0x00 },
|
||||
{ 0xff, 0x80, 0x00 },
|
||||
{ 0xff, 0x86, 0x00 },
|
||||
{ 0xff, 0x8c, 0x00 },
|
||||
{ 0xff, 0x93, 0x00 },
|
||||
{ 0xff, 0x99, 0x00 },
|
||||
{ 0xff, 0x9f, 0x00 },
|
||||
{ 0xff, 0xa6, 0x00 },
|
||||
{ 0xff, 0xac, 0x00 },
|
||||
{ 0xff, 0xb3, 0x00 },
|
||||
{ 0xff, 0xb9, 0x00 },
|
||||
{ 0xff, 0xbf, 0x00 },
|
||||
{ 0xff, 0xc6, 0x00 },
|
||||
{ 0xff, 0xcc, 0x00 },
|
||||
{ 0xff, 0xd2, 0x00 },
|
||||
{ 0xff, 0xd9, 0x00 },
|
||||
{ 0xff, 0xdf, 0x00 },
|
||||
{ 0xff, 0xe6, 0x00 },
|
||||
{ 0xff, 0xec, 0x00 },
|
||||
{ 0xff, 0xf2, 0x00 },
|
||||
{ 0xff, 0xf9, 0x00 },
|
||||
{ 0xff, 0xfe, 0x01 },
|
||||
{ 0xff, 0xff, 0x06 },
|
||||
{ 0xff, 0xff, 0x0d },
|
||||
{ 0xff, 0xff, 0x14 },
|
||||
{ 0xff, 0xff, 0x1b },
|
||||
{ 0xff, 0xff, 0x21 },
|
||||
{ 0xff, 0xff, 0x28 },
|
||||
{ 0xff, 0xff, 0x2f },
|
||||
{ 0xff, 0xff, 0x35 },
|
||||
{ 0xff, 0xff, 0x3c },
|
||||
{ 0xff, 0xff, 0x42 },
|
||||
{ 0xff, 0xff, 0x49 },
|
||||
{ 0xff, 0xff, 0x4f },
|
||||
{ 0xff, 0xff, 0x56 },
|
||||
{ 0xff, 0xff, 0x5d },
|
||||
{ 0xff, 0xff, 0x63 },
|
||||
{ 0xff, 0xff, 0x6a },
|
||||
{ 0xff, 0xff, 0x71 },
|
||||
{ 0xff, 0xff, 0x77 },
|
||||
{ 0xff, 0xff, 0x7e },
|
||||
{ 0xff, 0xff, 0x84 },
|
||||
{ 0xff, 0xff, 0x8b },
|
||||
{ 0xff, 0xff, 0x92 },
|
||||
{ 0xff, 0xff, 0x98 },
|
||||
{ 0xff, 0xff, 0x9f },
|
||||
{ 0xff, 0xff, 0xa6 },
|
||||
{ 0xff, 0xff, 0xac },
|
||||
{ 0xff, 0xff, 0xb3 },
|
||||
{ 0xff, 0xff, 0xb9 },
|
||||
{ 0xff, 0xff, 0xc0 },
|
||||
{ 0xff, 0xff, 0xc7 },
|
||||
{ 0xff, 0xff, 0xcd },
|
||||
{ 0xff, 0xff, 0xd4 },
|
||||
{ 0xff, 0xff, 0xdb },
|
||||
{ 0xff, 0xff, 0xe1 },
|
||||
{ 0xff, 0xff, 0xe8 },
|
||||
{ 0xff, 0xff, 0xee },
|
||||
{ 0xff, 0xff, 0xf5 },
|
||||
{ 0xff, 0xff, 0xfb }
|
||||
{ 0, 0, 0 },
|
||||
{ 0, 0, 3 },
|
||||
{ 0, 0, 6 },
|
||||
{ 0, 0, 9 },
|
||||
{ 0, 0, 12 },
|
||||
{ 0, 0, 15 },
|
||||
{ 0, 0, 18 },
|
||||
{ 0, 0, 21 },
|
||||
{ 0, 0, 24 },
|
||||
{ 0, 0, 27 },
|
||||
{ 0, 0, 30 },
|
||||
{ 0, 0, 33 },
|
||||
{ 0, 0, 36 },
|
||||
{ 0, 0, 39 },
|
||||
{ 0, 0, 42 },
|
||||
{ 0, 0, 45 },
|
||||
{ 0, 0, 48 },
|
||||
{ 0, 0, 51 },
|
||||
{ 0, 0, 54 },
|
||||
{ 0, 0, 57 },
|
||||
{ 0, 0, 60 },
|
||||
{ 0, 0, 63 },
|
||||
{ 0, 0, 66 },
|
||||
{ 0, 0, 69 },
|
||||
{ 0, 0, 72 },
|
||||
{ 0, 0, 75 },
|
||||
{ 0, 0, 78 },
|
||||
{ 0, 0, 81 },
|
||||
{ 0, 0, 84 },
|
||||
{ 0, 0, 87 },
|
||||
{ 0, 0, 90 },
|
||||
{ 0, 0, 93 },
|
||||
{ 0, 0, 96 },
|
||||
{ 0, 0, 99 },
|
||||
{ 0, 0, 102 },
|
||||
{ 0, 0, 105 },
|
||||
{ 0, 0, 108 },
|
||||
{ 0, 0, 111 },
|
||||
{ 0, 0, 114 },
|
||||
{ 0, 0, 117 },
|
||||
{ 0, 0, 120 },
|
||||
{ 0, 0, 123 },
|
||||
{ 0, 0, 126 },
|
||||
{ 0, 0, 129 },
|
||||
{ 0, 0, 132 },
|
||||
{ 0, 0, 135 },
|
||||
{ 0, 0, 138 },
|
||||
{ 0, 0, 141 },
|
||||
{ 0, 0, 144 },
|
||||
{ 0, 0, 147 },
|
||||
{ 0, 0, 150 },
|
||||
{ 0, 0, 153 },
|
||||
{ 0, 0, 156 },
|
||||
{ 0, 0, 159 },
|
||||
{ 0, 0, 162 },
|
||||
{ 0, 0, 165 },
|
||||
{ 0, 0, 168 },
|
||||
{ 0, 0, 171 },
|
||||
{ 0, 0, 174 },
|
||||
{ 0, 0, 177 },
|
||||
{ 0, 0, 180 },
|
||||
{ 0, 0, 183 },
|
||||
{ 0, 0, 186 },
|
||||
{ 0, 0, 189 },
|
||||
{ 0, 0, 192 },
|
||||
{ 0, 0, 195 },
|
||||
{ 0, 0, 198 },
|
||||
{ 0, 0, 201 },
|
||||
{ 0, 0, 204 },
|
||||
{ 0, 0, 207 },
|
||||
{ 0, 0, 210 },
|
||||
{ 0, 0, 213 },
|
||||
{ 0, 0, 216 },
|
||||
{ 0, 0, 219 },
|
||||
{ 0, 0, 222 },
|
||||
{ 0, 0, 225 },
|
||||
{ 0, 0, 228 },
|
||||
{ 0, 0, 231 },
|
||||
{ 0, 0, 234 },
|
||||
{ 0, 0, 237 },
|
||||
{ 0, 0, 240 },
|
||||
{ 0, 0, 243 },
|
||||
{ 0, 0, 246 },
|
||||
{ 0, 0, 249 },
|
||||
{ 0, 0, 252 },
|
||||
{ 0, 0, 255 },
|
||||
{ 0, 3, 252 },
|
||||
{ 0, 6, 249 },
|
||||
{ 0, 9, 246 },
|
||||
{ 0, 12, 243 },
|
||||
{ 0, 15, 240 },
|
||||
{ 0, 18, 237 },
|
||||
{ 0, 21, 234 },
|
||||
{ 0, 24, 231 },
|
||||
{ 0, 27, 228 },
|
||||
{ 0, 30, 225 },
|
||||
{ 0, 33, 222 },
|
||||
{ 0, 36, 219 },
|
||||
{ 0, 39, 216 },
|
||||
{ 0, 42, 213 },
|
||||
{ 0, 45, 210 },
|
||||
{ 0, 48, 207 },
|
||||
{ 0, 51, 204 },
|
||||
{ 0, 54, 201 },
|
||||
{ 0, 57, 198 },
|
||||
{ 0, 60, 195 },
|
||||
{ 0, 63, 192 },
|
||||
{ 0, 66, 189 },
|
||||
{ 0, 69, 186 },
|
||||
{ 0, 72, 183 },
|
||||
{ 0, 75, 180 },
|
||||
{ 0, 78, 177 },
|
||||
{ 0, 81, 174 },
|
||||
{ 0, 84, 171 },
|
||||
{ 0, 87, 168 },
|
||||
{ 0, 90, 165 },
|
||||
{ 0, 93, 162 },
|
||||
{ 0, 96, 159 },
|
||||
{ 0, 99, 156 },
|
||||
{ 0, 102, 153 },
|
||||
{ 0, 105, 150 },
|
||||
{ 0, 108, 147 },
|
||||
{ 0, 111, 144 },
|
||||
{ 0, 114, 141 },
|
||||
{ 0, 117, 138 },
|
||||
{ 0, 120, 135 },
|
||||
{ 0, 123, 132 },
|
||||
{ 0, 126, 129 },
|
||||
{ 0, 129, 126 },
|
||||
{ 0, 132, 123 },
|
||||
{ 0, 135, 120 },
|
||||
{ 0, 138, 117 },
|
||||
{ 0, 141, 114 },
|
||||
{ 0, 144, 111 },
|
||||
{ 0, 147, 108 },
|
||||
{ 0, 150, 105 },
|
||||
{ 0, 153, 102 },
|
||||
{ 0, 156, 99 },
|
||||
{ 0, 159, 96 },
|
||||
{ 0, 162, 93 },
|
||||
{ 0, 165, 90 },
|
||||
{ 0, 168, 87 },
|
||||
{ 0, 171, 84 },
|
||||
{ 0, 174, 81 },
|
||||
{ 0, 177, 78 },
|
||||
{ 0, 180, 75 },
|
||||
{ 0, 183, 72 },
|
||||
{ 0, 186, 69 },
|
||||
{ 0, 189, 66 },
|
||||
{ 0, 192, 63 },
|
||||
{ 0, 195, 60 },
|
||||
{ 0, 198, 57 },
|
||||
{ 0, 201, 54 },
|
||||
{ 0, 204, 51 },
|
||||
{ 0, 207, 48 },
|
||||
{ 0, 210, 45 },
|
||||
{ 0, 213, 42 },
|
||||
{ 0, 216, 39 },
|
||||
{ 0, 219, 36 },
|
||||
{ 0, 222, 33 },
|
||||
{ 0, 225, 30 },
|
||||
{ 0, 228, 27 },
|
||||
{ 0, 231, 24 },
|
||||
{ 0, 234, 21 },
|
||||
{ 0, 237, 18 },
|
||||
{ 0, 240, 15 },
|
||||
{ 0, 243, 12 },
|
||||
{ 0, 246, 9 },
|
||||
{ 0, 249, 6 },
|
||||
{ 0, 252, 3 },
|
||||
{ 0, 255, 0 },
|
||||
{ 3, 252, 0 },
|
||||
{ 6, 249, 0 },
|
||||
{ 9, 246, 0 },
|
||||
{ 12, 243, 0 },
|
||||
{ 15, 240, 0 },
|
||||
{ 18, 237, 0 },
|
||||
{ 21, 234, 0 },
|
||||
{ 24, 231, 0 },
|
||||
{ 27, 228, 0 },
|
||||
{ 30, 225, 0 },
|
||||
{ 33, 222, 0 },
|
||||
{ 36, 219, 0 },
|
||||
{ 39, 216, 0 },
|
||||
{ 42, 213, 0 },
|
||||
{ 45, 210, 0 },
|
||||
{ 48, 207, 0 },
|
||||
{ 51, 204, 0 },
|
||||
{ 54, 201, 0 },
|
||||
{ 57, 198, 0 },
|
||||
{ 60, 195, 0 },
|
||||
{ 63, 192, 0 },
|
||||
{ 66, 189, 0 },
|
||||
{ 69, 186, 0 },
|
||||
{ 72, 183, 0 },
|
||||
{ 75, 180, 0 },
|
||||
{ 78, 177, 0 },
|
||||
{ 81, 174, 0 },
|
||||
{ 84, 171, 0 },
|
||||
{ 87, 168, 0 },
|
||||
{ 90, 165, 0 },
|
||||
{ 93, 162, 0 },
|
||||
{ 96, 159, 0 },
|
||||
{ 99, 156, 0 },
|
||||
{ 102, 153, 0 },
|
||||
{ 105, 150, 0 },
|
||||
{ 108, 147, 0 },
|
||||
{ 111, 144, 0 },
|
||||
{ 114, 141, 0 },
|
||||
{ 117, 138, 0 },
|
||||
{ 120, 135, 0 },
|
||||
{ 123, 132, 0 },
|
||||
{ 126, 129, 0 },
|
||||
{ 129, 126, 0 },
|
||||
{ 132, 123, 0 },
|
||||
{ 135, 120, 0 },
|
||||
{ 138, 117, 0 },
|
||||
{ 141, 114, 0 },
|
||||
{ 144, 111, 0 },
|
||||
{ 147, 108, 0 },
|
||||
{ 150, 105, 0 },
|
||||
{ 153, 102, 0 },
|
||||
{ 156, 99, 0 },
|
||||
{ 159, 96, 0 },
|
||||
{ 162, 93, 0 },
|
||||
{ 165, 90, 0 },
|
||||
{ 168, 87, 0 },
|
||||
{ 171, 84, 0 },
|
||||
{ 174, 81, 0 },
|
||||
{ 177, 78, 0 },
|
||||
{ 180, 75, 0 },
|
||||
{ 183, 72, 0 },
|
||||
{ 186, 69, 0 },
|
||||
{ 189, 66, 0 },
|
||||
{ 192, 63, 0 },
|
||||
{ 195, 60, 0 },
|
||||
{ 198, 57, 0 },
|
||||
{ 201, 54, 0 },
|
||||
{ 204, 51, 0 },
|
||||
{ 207, 48, 0 },
|
||||
{ 210, 45, 0 },
|
||||
{ 213, 42, 0 },
|
||||
{ 216, 39, 0 },
|
||||
{ 219, 36, 0 },
|
||||
{ 222, 33, 0 },
|
||||
{ 225, 30, 0 },
|
||||
{ 228, 27, 0 },
|
||||
{ 231, 24, 0 },
|
||||
{ 234, 21, 0 },
|
||||
{ 237, 18, 0 },
|
||||
{ 240, 15, 0 },
|
||||
{ 243, 12, 0 },
|
||||
{ 246, 9, 0 },
|
||||
{ 249, 6, 0 },
|
||||
{ 252, 3, 0 },
|
||||
{ 255, 0, 0 },
|
||||
} };
|
||||
|
||||
const std::array<ui::Color, 256> spectrum_rgb4_lut { {
|
||||
|
||||
@@ -255,3 +255,9 @@ double get_decimals(double num, int16_t mult, bool round) {
|
||||
if (num > .5) intnum++; //Round up
|
||||
return intnum;
|
||||
}
|
||||
|
||||
std::string trimr(std::string str)
|
||||
{
|
||||
size_t last = str.find_last_not_of(' ');
|
||||
return (last!=std::string::npos) ? str.substr(0, last+1) : ""; // Remove the trailing spaces
|
||||
}
|
||||
@@ -58,4 +58,7 @@ std::string to_string_FAT_timestamp(const FATTimestamp& timestamp);
|
||||
|
||||
std::string unit_auto_scale(double n, const uint32_t base_nano, uint32_t precision);
|
||||
double get_decimals(double num, int16_t mult, bool round = false); //euquiq added
|
||||
|
||||
std::string trimr(std::string str); // Remove trailing spaces
|
||||
|
||||
#endif/*__STRING_FORMAT_H__*/
|
||||
|
||||
@@ -41,7 +41,7 @@ constexpr rf::Frequency high_band_second_lo_regions_2_and_3(const rf::Frequency
|
||||
|
||||
constexpr rf::Frequency high_band_second_lo_frequency(const rf::Frequency target_frequency) {
|
||||
return (target_frequency < 3600000000)
|
||||
? (2150000000 + (((target_frequency - 2750000000) * 60) / 85))
|
||||
? (2170000000 + (((target_frequency - 2740000000) * 57) / 86))
|
||||
: high_band_second_lo_regions_2_and_3(target_frequency)
|
||||
;
|
||||
}
|
||||
@@ -49,8 +49,8 @@ constexpr rf::Frequency high_band_second_lo_frequency(const rf::Frequency target
|
||||
Config low_band(const rf::Frequency target_frequency) {
|
||||
const rf::Frequency first_lo_frequency = target_frequency + low_band_second_lo_frequency(target_frequency);
|
||||
const rf::Frequency second_lo_frequency = first_lo_frequency - target_frequency;
|
||||
const bool baseband_invert = true;
|
||||
return { first_lo_frequency, second_lo_frequency, rf::path::Band::Low, baseband_invert };
|
||||
const bool mixer_invert = true;
|
||||
return { first_lo_frequency, second_lo_frequency, rf::path::Band::Low, mixer_invert };
|
||||
}
|
||||
|
||||
Config mid_band(const rf::Frequency target_frequency) {
|
||||
@@ -60,8 +60,8 @@ Config mid_band(const rf::Frequency target_frequency) {
|
||||
Config high_band(const rf::Frequency target_frequency) {
|
||||
const rf::Frequency first_lo_frequency = target_frequency - high_band_second_lo_frequency(target_frequency);
|
||||
const rf::Frequency second_lo_frequency = target_frequency - first_lo_frequency;
|
||||
const bool baseband_invert = false;
|
||||
return { first_lo_frequency, second_lo_frequency, rf::path::Band::High, baseband_invert };
|
||||
const bool mixer_invert = false;
|
||||
return { first_lo_frequency, second_lo_frequency, rf::path::Band::High, mixer_invert };
|
||||
}
|
||||
|
||||
} /* namespace */
|
||||
|
||||
@@ -33,7 +33,7 @@ struct Config {
|
||||
) : first_lo_frequency(0),
|
||||
second_lo_frequency(0),
|
||||
rf_path_band(rf::path::Band::Mid),
|
||||
baseband_invert(false)
|
||||
mixer_invert(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -41,11 +41,11 @@ struct Config {
|
||||
rf::Frequency first_lo_frequency,
|
||||
rf::Frequency second_lo_frequency,
|
||||
rf::path::Band rf_path_band,
|
||||
bool baseband_invert
|
||||
bool mixer_invert
|
||||
) : first_lo_frequency(first_lo_frequency),
|
||||
second_lo_frequency(second_lo_frequency),
|
||||
rf_path_band(rf_path_band),
|
||||
baseband_invert(baseband_invert)
|
||||
mixer_invert(mixer_invert)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ struct Config {
|
||||
const rf::Frequency first_lo_frequency;
|
||||
const rf::Frequency second_lo_frequency;
|
||||
const rf::path::Band rf_path_band;
|
||||
const bool baseband_invert;
|
||||
const bool mixer_invert;
|
||||
};
|
||||
|
||||
Config create(const rf::Frequency target_frequency);
|
||||
|
||||
@@ -134,7 +134,7 @@ int32_t GeoPos::altitude() {
|
||||
|
||||
GeoMap::GeoMap(
|
||||
Rect parent_rect
|
||||
) : Widget { parent_rect }
|
||||
) : Widget { parent_rect }, markerListLen(0)
|
||||
{
|
||||
//set_focusable(true);
|
||||
}
|
||||
@@ -144,34 +144,44 @@ void GeoMap::paint(Painter& painter) {
|
||||
std::array<ui::Color, 240> map_line_buffer;
|
||||
const auto r = screen_rect();
|
||||
|
||||
// Ony redraw map if it moved by at least 1 pixel
|
||||
if ((x_pos != prev_x_pos) || (y_pos != prev_y_pos)) {
|
||||
// Ony redraw map if it moved by at least 1 pixel
|
||||
// or the markers list was updated
|
||||
int x_diff = abs(x_pos-prev_x_pos);
|
||||
int y_diff = abs(y_pos-prev_y_pos);
|
||||
if (markerListUpdated || (x_diff>=3) || (y_diff>=3)) {
|
||||
for (line = 0; line < r.height(); line++) {
|
||||
map_file.seek(4 + ((x_pos + (map_width * (y_pos + line))) << 1));
|
||||
map_file.read(map_line_buffer.data(), r.width() << 1);
|
||||
display.draw_pixels({ 0, r.top() + line, r.width(), 1 }, map_line_buffer);
|
||||
}
|
||||
|
||||
prev_x_pos = x_pos;
|
||||
prev_y_pos = y_pos;
|
||||
|
||||
// Draw the other markers
|
||||
for ( int i=0; i<markerListLen; ++i )
|
||||
{
|
||||
GeoMarker & item = markerList[i];
|
||||
double lat_rad = sin(item.lat * pi / 180);
|
||||
int x = (map_width * (item.lon+180)/360) - x_pos;
|
||||
int y = (map_height - ((map_world_lon / 2 * log((1 + lat_rad) / (1 - lat_rad))) - map_offset)) - y_pos; // Offset added for the GUI
|
||||
if ((x>=0) && (x<r.width()) &&
|
||||
(y>10) && (y<r.height()) ) // Dont draw within symbol size of top
|
||||
{
|
||||
ui::Point itemPoint(x,y+r.top());
|
||||
if(y>=32) { // Dont draw text if it would overlap top
|
||||
// Text and symbol
|
||||
draw_marker(painter, itemPoint, item.angle, item.tag, Color::blue(), Color::blue(), Color::magenta() );
|
||||
} else {
|
||||
// Only symbol
|
||||
draw_bearing( itemPoint, item.angle, 10, Color::blue());
|
||||
}
|
||||
}
|
||||
markerListUpdated = false;
|
||||
} // Draw the other markers
|
||||
}
|
||||
//center tag above point
|
||||
if(tag_.find_first_not_of(' ') != tag_.npos){ //only draw tag if we have something other than spaces
|
||||
painter.draw_string(r.center() - Point(((int)tag_.length() * 8 / 2), 2 * 16), style(), tag_);
|
||||
}
|
||||
if (mode_ == PROMPT) {
|
||||
// Cross
|
||||
display.fill_rectangle({ r.center() - Point(16, 1), { 32, 2 } }, Color::red());
|
||||
display.fill_rectangle({ r.center() - Point(1, 16), { 2, 32 } }, Color::red());
|
||||
} else if (angle_ < 360){
|
||||
//if we have a valid angle draw bearing
|
||||
draw_bearing(r.center(), angle_, 10, Color::red());
|
||||
}
|
||||
else {
|
||||
//draw a small cross
|
||||
display.fill_rectangle({ r.center() - Point(8, 1), { 16, 2 } }, Color::red());
|
||||
display.fill_rectangle({ r.center() - Point(1, 8), { 2, 16 } }, Color::red());
|
||||
}
|
||||
|
||||
//Draw the marker in the center
|
||||
draw_marker(painter, r.center(), angle_, tag_, Color::red(), Color::white(), Color::black() );
|
||||
}
|
||||
|
||||
bool GeoMap::on_touch(const TouchEvent event) {
|
||||
@@ -196,10 +206,7 @@ void GeoMap::move(const float lon, const float lat) {
|
||||
x_pos = map_width * (lon_+180)/360 - (map_rect.width() / 2);
|
||||
|
||||
// Latitude calculation based on https://stackoverflow.com/a/10401734/2278659
|
||||
double map_bottom = sin(-85.05 * pi / 180); // Map bitmap only goes from about -85 to 85 lat
|
||||
double lat_rad = sin(lat * pi / 180);
|
||||
double map_world_lon = map_width / (2 * pi);
|
||||
double map_offset = (map_world_lon / 2 * log((1 + map_bottom) / (1 - map_bottom)));
|
||||
y_pos = map_height - ((map_world_lon / 2 * log((1 + lat_rad) / (1 - lat_rad))) - map_offset) - 128; // Offset added for the GUI
|
||||
|
||||
// Cap position
|
||||
@@ -222,7 +229,11 @@ bool GeoMap::init() {
|
||||
|
||||
lon_ratio = 180.0 / map_center_x;
|
||||
lat_ratio = -90.0 / map_center_y;
|
||||
|
||||
|
||||
map_bottom = sin(-85.05 * pi / 180); // Map bitmap only goes from about -85 to 85 lat
|
||||
map_world_lon = map_width / (2 * pi);
|
||||
map_offset = (map_world_lon / 2 * log((1 + map_bottom) / (1 - map_bottom)));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -234,9 +245,9 @@ void GeoMap::draw_bearing(const Point origin, const uint16_t angle, uint32_t siz
|
||||
Point arrow_a, arrow_b, arrow_c;
|
||||
|
||||
for (size_t thickness = 0; thickness < 3; thickness++) {
|
||||
arrow_a = polar_to_point(angle, size) + origin;
|
||||
arrow_b = polar_to_point(angle + 180 - 35, size) + origin;
|
||||
arrow_c = polar_to_point(angle + 180 + 35, size) + origin;
|
||||
arrow_a = fast_polar_to_point((int)angle, size) + origin;
|
||||
arrow_b = fast_polar_to_point((int)(angle + 180 - 35), size) + origin;
|
||||
arrow_c = fast_polar_to_point((int)(angle + 180 + 35), size) + origin;
|
||||
|
||||
display.draw_line(arrow_a, arrow_b, color);
|
||||
display.draw_line(arrow_b, arrow_c, color);
|
||||
@@ -246,6 +257,65 @@ void GeoMap::draw_bearing(const Point origin, const uint16_t angle, uint32_t siz
|
||||
}
|
||||
}
|
||||
|
||||
void GeoMap::draw_marker(Painter& painter, const ui::Point itemPoint, const uint16_t itemAngle, const std::string itemTag,
|
||||
const Color color, const Color fontColor, const Color backColor )
|
||||
{
|
||||
int tagOffset = 10;
|
||||
if (mode_ == PROMPT) {
|
||||
// Cross
|
||||
display.fill_rectangle({ itemPoint - Point(16, 1), { 32, 2 } }, color);
|
||||
display.fill_rectangle({ itemPoint - Point(1, 16), { 2, 32 } }, color);
|
||||
tagOffset = 16;
|
||||
} else if (angle_ < 360){
|
||||
//if we have a valid angle draw bearing
|
||||
draw_bearing( itemPoint, itemAngle, 10, color);
|
||||
tagOffset = 10;
|
||||
}
|
||||
else {
|
||||
//draw a small cross
|
||||
display.fill_rectangle({ itemPoint - Point(8, 1), { 16, 2 } }, color);
|
||||
display.fill_rectangle({ itemPoint - Point(1, 8), { 2, 16 } }, color);
|
||||
tagOffset = 8;
|
||||
}
|
||||
//center tag above point
|
||||
if(itemTag.find_first_not_of(' ') != itemTag.npos){ //only draw tag if we have something other than spaces
|
||||
painter.draw_string( itemPoint - Point(((int)itemTag.length() * 8 / 2), 14 + tagOffset ),
|
||||
style().font, fontColor, backColor, itemTag);
|
||||
}
|
||||
}
|
||||
|
||||
void GeoMap::clear_markers()
|
||||
{
|
||||
markerListLen = 0;
|
||||
}
|
||||
|
||||
MapMarkerStored GeoMap::store_marker(GeoMarker & marker)
|
||||
{
|
||||
MapMarkerStored ret;
|
||||
|
||||
// Check if it could be on screen
|
||||
// Only checking one direction to reduce CPU
|
||||
const auto r = screen_rect();
|
||||
double lat_rad = sin(marker.lat * pi / 180);
|
||||
int x = (map_width * (marker.lon+180)/360) - x_pos;
|
||||
int y = (map_height - ((map_world_lon / 2 * log((1 + lat_rad) / (1 - lat_rad))) - map_offset)) - y_pos; // Offset added for the GUI
|
||||
if (false==((x>=0) && (x<r.width()) && (y>10) && (y<r.height()))) // Dont draw within symbol size of top
|
||||
{
|
||||
ret = MARKER_NOT_STORED;
|
||||
}
|
||||
else if (markerListLen<NumMarkerListElements)
|
||||
{
|
||||
markerList[markerListLen] = marker;
|
||||
markerListLen++;
|
||||
markerListUpdated = true;
|
||||
ret = MARKER_STORED;
|
||||
} else {
|
||||
ret = MARKER_LIST_FULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void GeoMapView::focus() {
|
||||
geopos.focus();
|
||||
|
||||
@@ -269,6 +339,10 @@ void GeoMapView::update_position(float lat, float lon, uint16_t angle, int32_t a
|
||||
geomap.move(lon_, lat_);
|
||||
geomap.set_dirty();
|
||||
}
|
||||
|
||||
void GeoMapView::update_tag(const std::string tag) {
|
||||
geomap.set_tag(tag);
|
||||
}
|
||||
|
||||
void GeoMapView::setup() {
|
||||
add_child(&geomap);
|
||||
@@ -375,4 +449,14 @@ GeoMapView::GeoMapView(
|
||||
};
|
||||
}
|
||||
|
||||
void GeoMapView::clear_markers()
|
||||
{
|
||||
geomap.clear_markers();
|
||||
}
|
||||
|
||||
MapMarkerStored GeoMapView::store_marker(GeoMarker & marker)
|
||||
{
|
||||
return geomap.store_marker(marker);
|
||||
}
|
||||
|
||||
} /* namespace ui */
|
||||
|
||||
@@ -37,6 +37,24 @@ enum GeoMapMode {
|
||||
PROMPT
|
||||
};
|
||||
|
||||
struct GeoMarker {
|
||||
public:
|
||||
float lat {0};
|
||||
float lon {0};
|
||||
uint16_t angle {0};
|
||||
std::string tag {""};
|
||||
|
||||
GeoMarker & operator=(GeoMarker & rhs){
|
||||
lat = rhs.lat;
|
||||
lon = rhs.lon;
|
||||
angle = rhs.angle;
|
||||
tag = rhs.tag;
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class GeoPos : public View {
|
||||
public:
|
||||
enum alt_unit {
|
||||
@@ -112,6 +130,12 @@ private:
|
||||
};
|
||||
};
|
||||
|
||||
enum MapMarkerStored {
|
||||
MARKER_NOT_STORED,
|
||||
MARKER_STORED,
|
||||
MARKER_LIST_FULL
|
||||
};
|
||||
|
||||
class GeoMap : public Widget {
|
||||
public:
|
||||
std::function<void(float, float)> on_move { };
|
||||
@@ -133,20 +157,35 @@ public:
|
||||
angle_ = new_angle;
|
||||
}
|
||||
|
||||
static const int NumMarkerListElements = 30;
|
||||
|
||||
void clear_markers();
|
||||
MapMarkerStored store_marker(GeoMarker & marker);
|
||||
|
||||
private:
|
||||
void draw_bearing(const Point origin, const uint16_t angle, uint32_t size, const Color color);
|
||||
|
||||
void draw_marker(Painter& painter, const ui::Point itemPoint, const uint16_t itemAngle, const std::string itemTag,
|
||||
const Color color = Color::red(), const Color fontColor = Color::white(), const Color backColor = Color::black() );
|
||||
|
||||
GeoMapMode mode_ { };
|
||||
File map_file { };
|
||||
uint16_t map_width { }, map_height { };
|
||||
int32_t map_center_x { }, map_center_y { };
|
||||
float lon_ratio { }, lat_ratio { };
|
||||
double map_bottom { };
|
||||
double map_world_lon { };
|
||||
double map_offset { };
|
||||
|
||||
int32_t x_pos { }, y_pos { };
|
||||
int32_t prev_x_pos { 0xFFFF }, prev_y_pos { 0xFFFF };
|
||||
float lat_ { };
|
||||
float lon_ { };
|
||||
uint16_t angle_ { };
|
||||
std::string tag_ { };
|
||||
|
||||
int markerListLen {0};
|
||||
GeoMarker markerList[NumMarkerListElements];
|
||||
bool markerListUpdated {false};
|
||||
};
|
||||
|
||||
class GeoMapView : public View {
|
||||
@@ -181,6 +220,12 @@ public:
|
||||
|
||||
std::string title() const override { return "Map view"; };
|
||||
|
||||
void clear_markers();
|
||||
MapMarkerStored store_marker(GeoMarker & marker);
|
||||
|
||||
void update_tag(const std::string tag);
|
||||
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ using namespace portapack;
|
||||
|
||||
#include "string_format.hpp"
|
||||
|
||||
#include "max2837.hpp"
|
||||
#include "max283x.hpp"
|
||||
|
||||
namespace ui {
|
||||
|
||||
@@ -334,8 +334,8 @@ LNAGainField::LNAGainField(
|
||||
Point parent_pos
|
||||
) : NumberField {
|
||||
parent_pos, 2,
|
||||
{ max2837::lna::gain_db_range.minimum, max2837::lna::gain_db_range.maximum },
|
||||
max2837::lna::gain_db_step,
|
||||
{ max283x::lna::gain_db_range.minimum, max283x::lna::gain_db_range.maximum },
|
||||
max283x::lna::gain_db_step,
|
||||
' ',
|
||||
}
|
||||
{
|
||||
@@ -359,8 +359,8 @@ VGAGainField::VGAGainField(
|
||||
Point parent_pos
|
||||
) : NumberField {
|
||||
parent_pos, 2,
|
||||
{ max2837::vga::gain_db_range.minimum, max2837::vga::gain_db_range.maximum },
|
||||
max2837::vga::gain_db_step,
|
||||
{ max283x::vga::gain_db_range.minimum, max283x::vga::gain_db_range.maximum },
|
||||
max283x::vga::gain_db_step,
|
||||
' ',
|
||||
}
|
||||
{
|
||||
|
||||
@@ -26,85 +26,371 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
#define abs(x) ((x)>0?(x):-(x))
|
||||
|
||||
namespace ui {
|
||||
|
||||
void RSSI::paint(Painter& painter) {
|
||||
const auto r = screen_rect();
|
||||
RSSI::RSSI(
|
||||
Rect parent_rect,
|
||||
bool instant_exec
|
||||
) : Widget { parent_rect },
|
||||
instant_exec_ { instant_exec }
|
||||
{
|
||||
}
|
||||
|
||||
constexpr int rssi_sample_range = 256;
|
||||
constexpr float rssi_voltage_min = 0.4;
|
||||
constexpr float rssi_voltage_max = 2.2;
|
||||
constexpr float adc_voltage_max = 3.3;
|
||||
constexpr int raw_min = rssi_sample_range * rssi_voltage_min / adc_voltage_max;
|
||||
constexpr int raw_max = rssi_sample_range * rssi_voltage_max / adc_voltage_max;
|
||||
constexpr int raw_delta = raw_max - raw_min;
|
||||
const range_t<int> x_avg_range { 0, r.width() - 1 };
|
||||
const auto x_avg = x_avg_range.clip((avg_ - raw_min) * r.width() / raw_delta);
|
||||
const range_t<int> x_min_range { 0, x_avg };
|
||||
const auto x_min = x_min_range.clip((min_ - raw_min) * r.width() / raw_delta);
|
||||
const range_t<int> x_max_range { x_avg + 1, r.width() };
|
||||
const auto x_max = x_max_range.clip((max_ - raw_min) * r.width() / raw_delta);
|
||||
void RSSI::paint(Painter& painter) {
|
||||
const auto r = screen_rect();
|
||||
|
||||
const Rect r0 { r.left(), r.top(), x_min, r.height() };
|
||||
painter.fill_rectangle(
|
||||
r0,
|
||||
Color::blue()
|
||||
);
|
||||
constexpr int rssi_sample_range = 256;
|
||||
//constexpr float rssi_voltage_min = 0.4;
|
||||
constexpr float rssi_voltage_max = 2.2;
|
||||
constexpr float adc_voltage_max = 3.3;
|
||||
//constexpr int raw_min = rssi_sample_range * rssi_voltage_min / adc_voltage_max;
|
||||
constexpr int raw_min = 0 ;
|
||||
constexpr int raw_max = rssi_sample_range * rssi_voltage_max / adc_voltage_max;
|
||||
constexpr int raw_delta = raw_max - raw_min;
|
||||
|
||||
const Rect r1 { r.left() + x_min, r.top(), x_avg - x_min, r.height() };
|
||||
painter.fill_rectangle(
|
||||
r1,
|
||||
Color::red()
|
||||
);
|
||||
|
||||
const Rect r2 { r.left() + x_avg, r.top(), 1, r.height() };
|
||||
painter.fill_rectangle(
|
||||
r2,
|
||||
Color::white()
|
||||
);
|
||||
if( !vertical_rssi_enabled )
|
||||
{
|
||||
// horizontal left to right level meters
|
||||
const range_t<int> x_avg_range { 0, r.width() - 1 };
|
||||
const int16_t x_avg = x_avg_range.clip((avg_ - raw_min) * r.width() / raw_delta);
|
||||
const range_t<int> x_min_range { 0, x_avg };
|
||||
const int16_t x_min = x_min_range.clip((min_ - raw_min) * r.width() / raw_delta);
|
||||
const range_t<int> x_max_range { x_avg + 1, r.width() - 1 };
|
||||
const int16_t x_max = x_max_range.clip((max_ - raw_min) * r.width() / raw_delta);
|
||||
const int16_t peak = x_max_range.clip((peak_ - raw_min) * r.width() / raw_delta);
|
||||
|
||||
const Rect r3 { r.left() + x_avg + 1, r.top(), x_max - (x_avg + 1), r.height() };
|
||||
painter.fill_rectangle(
|
||||
r3,
|
||||
Color::red()
|
||||
);
|
||||
// x_min
|
||||
const Rect r0 { r.left(), r.top(), x_min, r.height() };
|
||||
painter.fill_rectangle(
|
||||
r0,
|
||||
Color::blue()
|
||||
);
|
||||
|
||||
const Rect r4 { r.left() + x_max, r.top(), r.width() - x_max, r.height() };
|
||||
painter.fill_rectangle(
|
||||
r4,
|
||||
Color::black()
|
||||
);
|
||||
|
||||
if (pitch_rssi_enabled) {
|
||||
baseband::set_pitch_rssi((avg_ - raw_min) * 2000 / raw_delta, true);
|
||||
}
|
||||
}
|
||||
// x_avg
|
||||
const Rect r1 { r.left() + x_min, r.top(), x_avg - x_min, r.height() };
|
||||
painter.fill_rectangle(
|
||||
r1,
|
||||
Color::red()
|
||||
);
|
||||
|
||||
int32_t RSSI::get_min()
|
||||
{
|
||||
return min_ ;
|
||||
}
|
||||
// x_avg middle marker
|
||||
const Rect r2 { r.left() + x_avg, r.top(), 1, r.height() };
|
||||
painter.fill_rectangle(
|
||||
r2,
|
||||
Color::white()
|
||||
);
|
||||
|
||||
int32_t RSSI::get_avg()
|
||||
{
|
||||
return avg_ ;
|
||||
}
|
||||
// x_max
|
||||
const Rect r3 { r.left() + x_avg + 1, r.top(), x_max - (x_avg + 1), r.height() };
|
||||
painter.fill_rectangle(
|
||||
r3,
|
||||
Color::red()
|
||||
);
|
||||
|
||||
int32_t RSSI::get_max()
|
||||
{
|
||||
return max_ ;
|
||||
}
|
||||
// filling last part in black
|
||||
const Rect r4 { r.left() + x_max, r.top(), r.width() - x_max, r.height() };
|
||||
painter.fill_rectangle(
|
||||
r4,
|
||||
Color::black()
|
||||
);
|
||||
|
||||
void RSSI::set_pitch_rssi(bool enabled) {
|
||||
pitch_rssi_enabled = enabled;
|
||||
if (!enabled) baseband::set_pitch_rssi(0, false);
|
||||
}
|
||||
// show green peak value
|
||||
if( peak_enabled )
|
||||
{
|
||||
const Rect r5 { r.left() + peak - 1 , r.top() , 3 , r.height() };
|
||||
painter.fill_rectangle(
|
||||
r5,
|
||||
Color::green()
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// vertical bottom to top level meters
|
||||
const range_t<int> y_avg_range { 0, r.height() - 1 };
|
||||
const int16_t y_avg = y_avg_range.clip((avg_ - raw_min) * r.height() / raw_delta);
|
||||
const range_t<int> y_min_range { 0, y_avg };
|
||||
const int16_t y_min = y_min_range.clip((min_ - raw_min) * r.height() / raw_delta);
|
||||
const range_t<int> y_max_range { y_avg + 1, r.height() - 1 };
|
||||
const int16_t y_max = y_max_range.clip((max_ - raw_min) * r.height() / raw_delta);
|
||||
const range_t<int> peak_range { 0, r.height() - 1 };
|
||||
const int16_t peak = peak_range.clip((peak_ - raw_min) * r.height() / raw_delta);
|
||||
|
||||
void RSSI::on_statistics_update(const RSSIStatistics& statistics) {
|
||||
min_ = statistics.min;
|
||||
avg_ = statistics.accumulator / statistics.count;
|
||||
max_ = statistics.max;
|
||||
set_dirty();
|
||||
}
|
||||
// y_min
|
||||
const Rect r0 { r.left(), r.bottom() - y_min, r.width() , y_min };
|
||||
painter.fill_rectangle(
|
||||
r0,
|
||||
Color::blue()
|
||||
);
|
||||
|
||||
// y_avg
|
||||
const Rect r1 { r.left(), r.bottom() - y_avg , r.width() , y_avg - y_min };
|
||||
painter.fill_rectangle(
|
||||
r1,
|
||||
Color::red()
|
||||
);
|
||||
|
||||
// y_avg middle marker
|
||||
const Rect r2 { r.left(), r.bottom() - y_avg , r.width() , 1 };
|
||||
painter.fill_rectangle(
|
||||
r2,
|
||||
Color::white()
|
||||
);
|
||||
|
||||
// y_max
|
||||
const Rect r3 { r.left(), r.bottom() - y_max , r.width() , y_max - y_avg };
|
||||
//const Rect r3 { r.left(), r.bottom() - y_max , r.width() , y_max - y_avg - 1 };
|
||||
painter.fill_rectangle(
|
||||
r3,
|
||||
Color::red()
|
||||
);
|
||||
|
||||
// fill last part of level in black
|
||||
const Rect r4 { r.left(), r.top() , r.width() , r.height() - y_max };
|
||||
painter.fill_rectangle(
|
||||
r4,
|
||||
Color::black()
|
||||
);
|
||||
|
||||
// show green peak value if enabled
|
||||
if( peak_enabled )
|
||||
{
|
||||
const Rect r5 { r.left(), r.bottom() - peak - 1 , r.width() , 3 };
|
||||
painter.fill_rectangle(
|
||||
r5,
|
||||
Color::green()
|
||||
);
|
||||
}
|
||||
}
|
||||
if (pitch_rssi_enabled) {
|
||||
baseband::set_pitch_rssi((avg_ - raw_min) * 2000 / raw_delta, true);
|
||||
}
|
||||
if( has_focus() || highlighted() )
|
||||
{
|
||||
const Rect r6 { r.left(), r.top(), r.width(), r.height() };
|
||||
painter.draw_rectangle(
|
||||
r6,
|
||||
Color::white()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
int16_t RSSI::get_min()
|
||||
{
|
||||
return min_ ;
|
||||
}
|
||||
|
||||
int16_t RSSI::get_avg()
|
||||
{
|
||||
return avg_ ;
|
||||
}
|
||||
|
||||
int16_t RSSI::get_max()
|
||||
{
|
||||
return max_ ;
|
||||
}
|
||||
|
||||
int16_t RSSI::get_delta()
|
||||
{
|
||||
return max_ - min_ ;
|
||||
}
|
||||
|
||||
|
||||
void RSSI::set_pitch_rssi(bool enabled) {
|
||||
pitch_rssi_enabled = enabled;
|
||||
if (!enabled) baseband::set_pitch_rssi(0, false);
|
||||
}
|
||||
|
||||
void RSSI::set_vertical_rssi(bool enabled) {
|
||||
if( enabled )
|
||||
vertical_rssi_enabled = true ;
|
||||
else
|
||||
vertical_rssi_enabled = false ;
|
||||
}
|
||||
|
||||
void RSSI::set_peak(bool enabled, size_t duration) {
|
||||
peak_enabled = enabled ;
|
||||
peak_duration = duration ;
|
||||
}
|
||||
|
||||
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_ )
|
||||
{
|
||||
peak_ = max_ ;
|
||||
}
|
||||
if( peak_duration_ > peak_duration )
|
||||
{
|
||||
peak_duration_ = 0 ;
|
||||
peak_ = max_ ;
|
||||
}
|
||||
}
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
|
||||
void RSSIGraph::paint(Painter& painter) {
|
||||
const auto r = screen_rect();
|
||||
int16_t size = r.width() / nb_columns ;
|
||||
int16_t top_y_val = 0 ;
|
||||
int16_t width_y = 0 ;
|
||||
|
||||
if( size < 1 )
|
||||
size = 1 ;
|
||||
|
||||
int xpos = r.right() ;
|
||||
for ( int n = 2 ; (unsigned)n <= graph_list.size(); n++) {
|
||||
auto& entry = graph_list[graph_list.size()-n];
|
||||
auto& prev_entry = graph_list[graph_list.size()-(n-1)];
|
||||
|
||||
// black
|
||||
const Rect r0{ xpos - size , r.top() , size , r.height() };
|
||||
painter.fill_rectangle(
|
||||
r0,
|
||||
Color::black());
|
||||
|
||||
// y_max
|
||||
top_y_val = max( entry.rssi_max , prev_entry.rssi_max );
|
||||
width_y = abs( entry.rssi_max - prev_entry.rssi_max );
|
||||
if( width_y == 0 )
|
||||
width_y = 1 ;
|
||||
const Rect r1{ xpos - size , r.bottom() - top_y_val , size , width_y };
|
||||
painter.fill_rectangle(
|
||||
r1,
|
||||
Color::red());
|
||||
|
||||
// y_avg
|
||||
top_y_val = max( entry.rssi_avg , prev_entry.rssi_avg );
|
||||
width_y = abs( entry.rssi_avg - prev_entry.rssi_avg );
|
||||
if( width_y == 0 )
|
||||
width_y = 1 ;
|
||||
const Rect r2{ xpos - size , r.bottom() - top_y_val , size , width_y };
|
||||
painter.fill_rectangle(
|
||||
r2,
|
||||
Color::white());
|
||||
|
||||
// y_min
|
||||
top_y_val = max( entry.rssi_min , prev_entry.rssi_min );
|
||||
width_y = abs( entry.rssi_min - prev_entry.rssi_min );
|
||||
if( width_y == 0 )
|
||||
width_y = 1 ;
|
||||
const Rect r3{ xpos - size , r.bottom() - top_y_val , size , width_y };
|
||||
painter.fill_rectangle(
|
||||
r3,
|
||||
Color::blue());
|
||||
|
||||
// hack to display db
|
||||
top_y_val = max( entry.db , prev_entry.db );
|
||||
width_y = abs( entry.db - prev_entry.db );
|
||||
if( width_y == 0 )
|
||||
width_y = 1 ;
|
||||
const Rect r4{ xpos - size , r.bottom() - top_y_val , size , width_y };
|
||||
painter.fill_rectangle(
|
||||
r4,
|
||||
Color::green());
|
||||
xpos = xpos - size ;
|
||||
}
|
||||
if( xpos > r.left() )
|
||||
{
|
||||
const Rect r5{ r.left() , r.top() , xpos - r.left() , r.height() };
|
||||
painter.fill_rectangle(
|
||||
r5,
|
||||
Color::black());
|
||||
}
|
||||
}
|
||||
|
||||
void RSSIGraph::add_values(int16_t rssi_min, int16_t rssi_avg, int16_t rssi_max, int16_t db )
|
||||
{
|
||||
const auto r = screen_rect();
|
||||
|
||||
constexpr int rssi_sample_range = 256;
|
||||
//constexpr float rssi_voltage_min = 0.4;
|
||||
constexpr float rssi_voltage_max = 2.2;
|
||||
constexpr float adc_voltage_max = 3.3;
|
||||
//constexpr int raw_min = rssi_sample_range * rssi_voltage_min / adc_voltage_max;
|
||||
constexpr int raw_min = 0 ;
|
||||
constexpr int raw_max = rssi_sample_range * rssi_voltage_max / adc_voltage_max;
|
||||
constexpr int raw_delta = raw_max - raw_min;
|
||||
|
||||
// vertical bottom to top level meters
|
||||
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);
|
||||
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 };
|
||||
const int16_t y_max = y_max_range.clip((rssi_max - raw_min) * r.height() / raw_delta);
|
||||
const range_t<int> db_range { -80 , 10 };
|
||||
int16_t db_ = db_range.clip( db );
|
||||
db_ = db_ - 10 ;
|
||||
db_ = db_ * r.height() / 90 ;
|
||||
db_ = r.height() + db_ ;
|
||||
|
||||
graph_list . push_back( { y_min, y_avg, y_max , db_ } );
|
||||
while( graph_list.size() > nb_columns )
|
||||
{
|
||||
graph_list.erase( graph_list.begin() );
|
||||
}
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
void RSSIGraph::set_nb_columns( int16_t nb )
|
||||
{
|
||||
nb_columns = nb ;
|
||||
}
|
||||
|
||||
void RSSI::on_focus() {
|
||||
if( on_highlight )
|
||||
on_highlight(*this);
|
||||
}
|
||||
|
||||
bool RSSI::on_key(const KeyEvent key) {
|
||||
if( key == KeyEvent::Select ) {
|
||||
if( on_select ) {
|
||||
on_select(*this);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if( on_dir ) {
|
||||
return on_dir(*this, key);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RSSI::on_touch(const TouchEvent event) {
|
||||
switch(event.type) {
|
||||
case TouchEvent::Type::Start:
|
||||
set_highlighted(true);
|
||||
set_dirty();
|
||||
if( on_touch_press) {
|
||||
on_touch_press(*this);
|
||||
}
|
||||
if( on_select && instant_exec_ ) {
|
||||
on_select(*this);
|
||||
}
|
||||
return true;
|
||||
case TouchEvent::Type::End:
|
||||
set_highlighted(false);
|
||||
set_dirty();
|
||||
if( on_touch_release) {
|
||||
on_touch_release(*this);
|
||||
}
|
||||
if( on_select && !instant_exec_ ) {
|
||||
on_select(*this);
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} /* namespace ui */
|
||||
|
||||
@@ -25,56 +25,101 @@
|
||||
#include "ui.hpp"
|
||||
#include "ui_widget.hpp"
|
||||
#include "ui_painter.hpp"
|
||||
|
||||
#include "event_m0.hpp"
|
||||
|
||||
#include "message.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace ui {
|
||||
|
||||
class RSSI : public Widget {
|
||||
public:
|
||||
RSSI(
|
||||
const Rect parent_rect
|
||||
) : Widget { parent_rect },
|
||||
min_ { 0 },
|
||||
avg_ { 0 },
|
||||
max_ { 0 }
|
||||
{
|
||||
}
|
||||
class RSSI : public Widget {
|
||||
public:
|
||||
std::function<void(RSSI&)> on_select { };
|
||||
std::function<void(RSSI&)> on_touch_release { }; // Executed when releasing touch, after on_select.
|
||||
std::function<void(RSSI&)> on_touch_press { }; // Executed when touching, before on_select.
|
||||
std::function<bool(RSSI&, KeyEvent)> on_dir { };
|
||||
std::function<void(RSSI&)> on_highlight { };
|
||||
|
||||
void paint(Painter& painter) override;
|
||||
int32_t get_min();
|
||||
int32_t get_avg();
|
||||
int32_t get_max();
|
||||
|
||||
private:
|
||||
int32_t min_;
|
||||
int32_t avg_;
|
||||
int32_t max_;
|
||||
|
||||
bool pitch_rssi_enabled = false;
|
||||
RSSI(Rect parent_rect, bool instant_exec); // instant_exec: Execute on_select when you touching instead of releasing
|
||||
RSSI(
|
||||
Rect parent_rect
|
||||
) : RSSI { parent_rect, false }
|
||||
{
|
||||
}
|
||||
|
||||
MessageHandlerRegistration message_handler_stats {
|
||||
Message::ID::RSSIStatistics,
|
||||
[this](const Message* const p) {
|
||||
this->on_statistics_update(static_cast<const RSSIStatisticsMessage*>(p)->statistics);
|
||||
}
|
||||
};
|
||||
|
||||
MessageHandlerRegistration message_handler_pitch_rssi {
|
||||
Message::ID::PitchRSSIConfigure,
|
||||
[this](const Message* const p) {
|
||||
const auto message = *reinterpret_cast<const PitchRSSIConfigureMessage*>(p);
|
||||
this->set_pitch_rssi(message.enabled);
|
||||
}
|
||||
};
|
||||
RSSI(
|
||||
) : RSSI { { }, { } }
|
||||
{
|
||||
}
|
||||
|
||||
void on_statistics_update(const RSSIStatistics& statistics);
|
||||
void set_pitch_rssi(bool enabled);
|
||||
};
|
||||
int16_t get_min();
|
||||
int16_t get_avg();
|
||||
int16_t get_max();
|
||||
int16_t get_delta();
|
||||
void set_vertical_rssi(bool enabled);
|
||||
void set_peak(bool enabled, size_t duration);
|
||||
|
||||
void paint(Painter& painter) override;
|
||||
void on_focus() override;
|
||||
bool on_key(const KeyEvent key) override;
|
||||
bool on_touch(const TouchEvent event) override;
|
||||
|
||||
private:
|
||||
int16_t min_ = 0;
|
||||
int16_t avg_ = 0;
|
||||
int16_t max_ = 0;
|
||||
int16_t peak_ = 0 ;
|
||||
size_t peak_duration_ = 0 ;
|
||||
bool instant_exec_ { false };
|
||||
|
||||
bool pitch_rssi_enabled = false;
|
||||
bool vertical_rssi_enabled = false; // scale [vertically/from bottom to top]
|
||||
// instead of [horizontally/from left to right]
|
||||
bool peak_enabled = false;
|
||||
size_t peak_duration = 1000; // peak duration in msec before being reset to actual max_rssi
|
||||
|
||||
MessageHandlerRegistration message_handler_stats {
|
||||
Message::ID::RSSIStatistics,
|
||||
[this](const Message* const p) {
|
||||
this->on_statistics_update(static_cast<const RSSIStatisticsMessage*>(p)->statistics);
|
||||
}
|
||||
};
|
||||
|
||||
MessageHandlerRegistration message_handler_pitch_rssi {
|
||||
Message::ID::PitchRSSIConfigure,
|
||||
[this](const Message* const p) {
|
||||
const auto message = *reinterpret_cast<const PitchRSSIConfigureMessage*>(p);
|
||||
this->set_pitch_rssi(message.enabled);
|
||||
}
|
||||
};
|
||||
|
||||
void on_statistics_update(const RSSIStatistics& statistics);
|
||||
void set_pitch_rssi(bool enabled);
|
||||
};
|
||||
|
||||
struct RSSIGraph_entry {
|
||||
int16_t rssi_min { 0 };
|
||||
int16_t rssi_avg { 0 };
|
||||
int16_t rssi_max { 0 };
|
||||
int16_t db { 0 };
|
||||
};
|
||||
|
||||
using RSSIGraphList = std::vector<RSSIGraph_entry>;
|
||||
|
||||
class RSSIGraph : public Widget {
|
||||
public:
|
||||
RSSIGraph(
|
||||
const Rect parent_rect
|
||||
) : Widget { parent_rect }
|
||||
{
|
||||
}
|
||||
void paint(Painter& painter) override;
|
||||
void add_values(int16_t rssi_min, int16_t rssi_avg, int16_t rssi_max, int16_t db );
|
||||
void set_nb_columns( int16_t nb );
|
||||
|
||||
private:
|
||||
uint16_t nb_columns = 16 ;
|
||||
RSSIGraphList graph_list { } ;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
#include "ui_scanner.hpp"
|
||||
#include "ui_search.hpp"
|
||||
#include "ui_recon.hpp"
|
||||
#include "ui_level.hpp"
|
||||
#include "ui_sd_wipe.hpp"
|
||||
#include "ui_settings.hpp"
|
||||
#include "ui_siggen.hpp"
|
||||
@@ -110,6 +111,7 @@ SystemStatusView::SystemStatusView(
|
||||
&button_back,
|
||||
&title,
|
||||
&button_title,
|
||||
&button_hamitup,
|
||||
&button_speaker,
|
||||
&button_stealth,
|
||||
//&button_textentry,
|
||||
@@ -147,6 +149,10 @@ SystemStatusView::SystemStatusView(
|
||||
this->on_title();
|
||||
};
|
||||
|
||||
button_hamitup.on_select = [this](ImageButton&) {
|
||||
this->on_hamitup();
|
||||
};
|
||||
|
||||
button_speaker.on_select = [this](ImageButton&) {
|
||||
this->on_speaker();
|
||||
};
|
||||
@@ -178,6 +184,17 @@ SystemStatusView::SystemStatusView(
|
||||
}
|
||||
|
||||
void SystemStatusView::refresh() {
|
||||
if( portapack::persistent_memory::config_hamitup() )
|
||||
{
|
||||
button_hamitup.set_foreground(Color::red());
|
||||
}
|
||||
else
|
||||
{
|
||||
button_hamitup.set_foreground(Color::light_grey());
|
||||
}
|
||||
// Retune to take hamitup change in account
|
||||
receiver_model.set_tuning_frequency( portapack::persistent_memory::tuned_frequency() );
|
||||
|
||||
if (!portapack::persistent_memory::config_speaker()) {
|
||||
button_speaker.set_foreground(Color::light_grey());
|
||||
button_speaker.set_bitmap(&bitmap_icon_speaker_mute);
|
||||
@@ -186,6 +203,7 @@ void SystemStatusView::refresh() {
|
||||
else {
|
||||
button_speaker.hidden(true);
|
||||
}
|
||||
|
||||
if (portapack::get_antenna_bias()) {
|
||||
button_bias_tee.set_bitmap(&bitmap_icon_biast_on);
|
||||
button_bias_tee.set_foreground(ui::Color::yellow());
|
||||
@@ -201,6 +219,7 @@ void SystemStatusView::refresh() {
|
||||
button_clock_status.set_bitmap(&bitmap_icon_clk_int);
|
||||
// button_bias_tee.set_foreground(ui::Color::green());
|
||||
}
|
||||
|
||||
if(portapack::persistent_memory::clkout_enabled()) {
|
||||
button_clock_status.set_foreground(ui::Color::green());
|
||||
} else {
|
||||
@@ -238,6 +257,20 @@ void SystemStatusView::set_title(const std::string new_value) {
|
||||
}
|
||||
}
|
||||
|
||||
void SystemStatusView::on_hamitup() {
|
||||
if(!portapack::persistent_memory::config_hamitup())
|
||||
{
|
||||
portapack::persistent_memory::set_config_hamitup( true );
|
||||
button_hamitup.set_foreground(Color::red());
|
||||
}
|
||||
else
|
||||
{
|
||||
portapack::persistent_memory::set_config_hamitup( false );
|
||||
button_hamitup.set_foreground(Color::light_grey());
|
||||
}
|
||||
receiver_model.set_tuning_frequency( portapack::persistent_memory::tuned_frequency() ); // Retune
|
||||
}
|
||||
|
||||
void SystemStatusView::on_speaker() {
|
||||
if (!portapack::speaker_mode)
|
||||
{
|
||||
@@ -466,25 +499,26 @@ void NavigationView::focus() {
|
||||
/* ReceiversMenuView *****************************************************/
|
||||
|
||||
ReceiversMenuView::ReceiversMenuView(NavigationView& nav) {
|
||||
if( portapack::persistent_memory::show_gui_return_icon() )
|
||||
{
|
||||
add_items( { { "..", ui::Color::light_grey(),&bitmap_icon_previous , [&nav](){ nav.pop(); } } } );
|
||||
}
|
||||
add_items( {
|
||||
{ "ADS-B", ui::Color::green(), &bitmap_icon_adsb, [&nav](){ nav.push<ADSBRxView>(); }, },
|
||||
//{ "ACARS", ui::Color::yellow(), &bitmap_icon_adsb, [&nav](){ nav.push<ACARSAppView>(); }, },
|
||||
{ "AIS Boats", ui::Color::green(), &bitmap_icon_ais, [&nav](){ nav.push<AISAppView>(); } },
|
||||
{ "AFSK", ui::Color::yellow(), &bitmap_icon_modem, [&nav](){ nav.push<AFSKRxView>(); } },
|
||||
{ "BTLE", ui::Color::yellow(), &bitmap_icon_btle, [&nav](){ nav.push<BTLERxView>(); } },
|
||||
{ "NRF", ui::Color::yellow(), &bitmap_icon_nrf, [&nav](){ nav.push<NRFRxView>(); } },
|
||||
{ "Audio", ui::Color::green(), &bitmap_icon_speaker, [&nav](){ nav.push<AnalogAudioView>(); } },
|
||||
{ "Analog TV", ui::Color::yellow(), &bitmap_icon_sstv, [&nav](){ nav.push<AnalogTvView>(); } },
|
||||
{ "ERT Meter", ui::Color::green(), &bitmap_icon_ert, [&nav](){ nav.push<ERTAppView>(); } },
|
||||
{ "POCSAG", ui::Color::green(), &bitmap_icon_pocsag, [&nav](){ nav.push<POCSAGAppView>(); } },
|
||||
{ "Radiosnde", ui::Color::green(), &bitmap_icon_sonde, [&nav](){ nav.push<SondeView>(); } },
|
||||
{ "TPMS Cars", ui::Color::green(), &bitmap_icon_tpms, [&nav](){ nav.push<TPMSAppView>(); } },
|
||||
{ "Recon", ui::Color::green(), &bitmap_icon_scanner, [&nav](){ nav.push<ReconView>(); } },
|
||||
{ "APRS", ui::Color::green(), &bitmap_icon_aprs, [&nav](){ nav.push<APRSRXView>(); } }
|
||||
if( portapack::persistent_memory::show_gui_return_icon() )
|
||||
{
|
||||
add_items( { { "..", ui::Color::light_grey(),&bitmap_icon_previous , [&nav](){ nav.pop(); } } } );
|
||||
}
|
||||
add_items( {
|
||||
{ "ADS-B", ui::Color::green(), &bitmap_icon_adsb, [&nav](){ nav.push<ADSBRxView>(); }, },
|
||||
//{ "ACARS", ui::Color::yellow(), &bitmap_icon_adsb, [&nav](){ nav.push<ACARSAppView>(); }, },
|
||||
{ "AIS Boats", ui::Color::green(), &bitmap_icon_ais, [&nav](){ nav.push<AISAppView>(); } },
|
||||
{ "AFSK", ui::Color::yellow(), &bitmap_icon_modem, [&nav](){ nav.push<AFSKRxView>(); } },
|
||||
{ "BTLE", ui::Color::yellow(), &bitmap_icon_btle, [&nav](){ nav.push<BTLERxView>(); } },
|
||||
{ "NRF", ui::Color::yellow(), &bitmap_icon_nrf, [&nav](){ nav.push<NRFRxView>(); } },
|
||||
{ "Audio", ui::Color::green(), &bitmap_icon_speaker, [&nav](){ nav.push<AnalogAudioView>(); } },
|
||||
{ "Analog TV", ui::Color::yellow(), &bitmap_icon_sstv, [&nav](){ nav.push<AnalogTvView>(); } },
|
||||
{ "ERT Meter", ui::Color::green(), &bitmap_icon_ert, [&nav](){ nav.push<ERTAppView>(); } },
|
||||
{ "POCSAG", ui::Color::green(), &bitmap_icon_pocsag, [&nav](){ nav.push<POCSAGAppView>(); } },
|
||||
{ "Radiosnde", ui::Color::green(), &bitmap_icon_sonde, [&nav](){ nav.push<SondeView>(); } },
|
||||
{ "TPMS Cars", ui::Color::green(), &bitmap_icon_tpms, [&nav](){ nav.push<TPMSAppView>(); } },
|
||||
{ "Recon", ui::Color::green(), &bitmap_icon_scanner, [&nav](){ nav.push<ReconView>(); } },
|
||||
{ "Level", ui::Color::green(), &bitmap_icon_options_radio, [&nav](){ nav.push<LevelView>(); } },
|
||||
{ "APRS", ui::Color::green(), &bitmap_icon_aprs, [&nav](){ nav.push<APRSRXView>(); } }
|
||||
/*
|
||||
{ "DMR", ui::Color::dark_grey(), &bitmap_icon_dmr, [&nav](){ nav.push<NotImplementedView>(); } },
|
||||
{ "SIGFOX", ui::Color::dark_grey(), &bitmap_icon_fox, [&nav](){ nav.push<NotImplementedView>(); } }, // SIGFRXView
|
||||
@@ -499,30 +533,29 @@ ReceiversMenuView::ReceiversMenuView(NavigationView& nav) {
|
||||
/* TransmittersMenuView **************************************************/
|
||||
|
||||
TransmittersMenuView::TransmittersMenuView(NavigationView& nav) {
|
||||
if( portapack::persistent_memory::show_gui_return_icon() )
|
||||
{
|
||||
add_items( { { "..", ui::Color::light_grey(),&bitmap_icon_previous , [&nav](){ nav.pop(); } } } );
|
||||
}
|
||||
add_items({
|
||||
{ "ADS-B [S]", ui::Color::yellow(), &bitmap_icon_adsb, [&nav](){ nav.push<ADSBTxView>(); } },
|
||||
{ "APRS", ui::Color::green(), &bitmap_icon_aprs, [&nav](){ nav.push<APRSTXView>(); } },
|
||||
{ "BHT Xy/EP", ui::Color::green(), &bitmap_icon_bht, [&nav](){ nav.push<BHTView>(); } },
|
||||
{ "GPS Sim", ui::Color::yellow(), &bitmap_icon_gps_sim, [&nav](){ nav.push<GpsSimAppView>(); } },
|
||||
{ "Jammer", ui::Color::green(), &bitmap_icon_jammer, [&nav](){ nav.push<JammerView>(); } },
|
||||
{ "Key fob", ui::Color::orange(), &bitmap_icon_keyfob, [&nav](){ nav.push<KeyfobView>(); } },
|
||||
{ "LGE tool", ui::Color::yellow(), &bitmap_icon_lge, [&nav](){ nav.push<LGEView>(); } },
|
||||
if( portapack::persistent_memory::show_gui_return_icon() )
|
||||
{
|
||||
add_items( { { "..", ui::Color::light_grey(),&bitmap_icon_previous , [&nav](){ nav.pop(); } } } );
|
||||
}
|
||||
add_items({
|
||||
{ "ADS-B [S]", ui::Color::yellow(), &bitmap_icon_adsb, [&nav](){ nav.push<ADSBTxView>(); } },
|
||||
{ "APRS", ui::Color::green(), &bitmap_icon_aprs, [&nav](){ nav.push<APRSTXView>(); } },
|
||||
{ "BHT Xy/EP", ui::Color::green(), &bitmap_icon_bht, [&nav](){ nav.push<BHTView>(); } },
|
||||
{ "GPS Sim", ui::Color::yellow(), &bitmap_icon_gps_sim, [&nav](){ nav.push<GpsSimAppView>(); } },
|
||||
{ "Jammer", ui::Color::green(), &bitmap_icon_jammer, [&nav](){ nav.push<JammerView>(); } },
|
||||
{ "Key fob", ui::Color::orange(), &bitmap_icon_keyfob, [&nav](){ nav.push<KeyfobView>(); } },
|
||||
{ "LGE tool", ui::Color::yellow(), &bitmap_icon_lge, [&nav](){ nav.push<LGEView>(); } },
|
||||
{ "Morse", ui::Color::green(), &bitmap_icon_morse, [&nav](){ nav.push<MorseView>(); } },
|
||||
{ "BurgerPgr", ui::Color::yellow(), &bitmap_icon_burger, [&nav](){ nav.push<CoasterPagerView>(); } },
|
||||
{ "BurgerPgr", ui::Color::yellow(), &bitmap_icon_burger, [&nav](){ nav.push<CoasterPagerView>(); } },
|
||||
//{ "Nuoptix DTMF", ui::Color::green(), &bitmap_icon_nuoptix, [&nav](){ nav.push<NuoptixView>(); } },
|
||||
{ "OOK", ui::Color::yellow(), &bitmap_icon_remote, [&nav](){ nav.push<EncodersView>(); } },
|
||||
{ "POCSAG", ui::Color::green(), &bitmap_icon_pocsag, [&nav](){ nav.push<POCSAGTXView>(); } },
|
||||
{ "POCSAG", ui::Color::green(), &bitmap_icon_pocsag, [&nav](){ nav.push<POCSAGTXView>(); } },
|
||||
{ "RDS", ui::Color::green(), &bitmap_icon_rds, [&nav](){ nav.push<RDSView>(); } },
|
||||
{ "Soundbrd", ui::Color::green(), &bitmap_icon_soundboard,[&nav](){ nav.push<SoundBoardView>(); } },
|
||||
{ "SSTV", ui::Color::green(), &bitmap_icon_sstv, [&nav](){ nav.push<SSTVTXView>(); } },
|
||||
{ "TEDI/LCR", ui::Color::yellow(), &bitmap_icon_lcr, [&nav](){ nav.push<LCRView>(); } },
|
||||
{ "Soundbrd", ui::Color::green(), &bitmap_icon_soundboard,[&nav](){ nav.push<SoundBoardView>(); } },
|
||||
{ "SSTV", ui::Color::green(), &bitmap_icon_sstv, [&nav](){ nav.push<SSTVTXView>(); } },
|
||||
{ "TEDI/LCR", ui::Color::yellow(), &bitmap_icon_lcr, [&nav](){ nav.push<LCRView>(); } },
|
||||
{ "TouchTune", ui::Color::yellow(), &bitmap_icon_remote, [&nav](){ nav.push<TouchTunesView>(); } },
|
||||
{ "Playlist", ui::Color::yellow(), &bitmap_icon_remote, [&nav](){ nav.push<PlaylistView>(); } },
|
||||
|
||||
{ "Playlist", ui::Color::yellow(), &bitmap_icon_remote, [&nav](){ nav.push<PlaylistView>(); } },
|
||||
//{ "Remote", ui::Color::dark_grey(), &bitmap_icon_remote, [&nav](){ nav.push<RemoteView>(); } },
|
||||
});
|
||||
}
|
||||
@@ -530,10 +563,10 @@ TransmittersMenuView::TransmittersMenuView(NavigationView& nav) {
|
||||
/* UtilitiesMenuView *****************************************************/
|
||||
|
||||
UtilitiesMenuView::UtilitiesMenuView(NavigationView& nav) {
|
||||
if( portapack::persistent_memory::show_gui_return_icon() )
|
||||
{
|
||||
add_items( { { "..", ui::Color::light_grey(),&bitmap_icon_previous , [&nav](){ nav.pop(); } } } );
|
||||
}
|
||||
if( portapack::persistent_memory::show_gui_return_icon() )
|
||||
{
|
||||
add_items( { { "..", ui::Color::light_grey(),&bitmap_icon_previous , [&nav](){ nav.pop(); } } } );
|
||||
}
|
||||
add_items({
|
||||
//{ "Test app", ui::Color::dark_grey(), nullptr, [&nav](){ nav.push<TestView>(); } },
|
||||
{ "Freq. manager", ui::Color::green(), &bitmap_icon_freqman, [&nav](){ nav.push<FrequencyManagerView>(); } },
|
||||
@@ -568,7 +601,7 @@ SystemMenuView::SystemMenuView(NavigationView& nav) {
|
||||
{ "Transmit", ui::Color::cyan(), &bitmap_icon_transmit, [&nav](){ nav.push<TransmittersMenuView>(); } },
|
||||
{ "Capture", ui::Color::red(), &bitmap_icon_capture, [&nav](){ nav.push<CaptureAppView>(); } },
|
||||
{ "Replay", ui::Color::green(), &bitmap_icon_replay, [&nav](){ nav.push<ReplayAppView>(); } },
|
||||
{ "Search", ui::Color::yellow(), &bitmap_icon_search, [&nav](){ nav.push<SearchView>(); } },
|
||||
{ "Search", ui::Color::yellow(), &bitmap_icon_search, [&nav](){ nav.push<SearchView>(); } },
|
||||
{ "Scanner", ui::Color::yellow(), &bitmap_icon_scanner, [&nav](){ nav.push<ScannerView>(); } },
|
||||
{ "Microphone", ui::Color::yellow(), &bitmap_icon_microphone,[&nav](){ nav.push<MicTXView>(); } },
|
||||
{ "Looking Glass", ui::Color::yellow(), &bitmap_icon_looking, [&nav](){ nav.push<GlassView>(); } },
|
||||
|
||||
@@ -142,11 +142,18 @@ namespace ui
|
||||
Color::dark_grey()};
|
||||
|
||||
ImageButton button_speaker{
|
||||
{17 * 8, 0, 2 * 8, 1 * 16},
|
||||
{15 * 8, 0, 2 * 8, 1 * 16},
|
||||
&bitmap_icon_speaker_mute,
|
||||
Color::light_grey(),
|
||||
Color::dark_grey()};
|
||||
|
||||
ImageButton button_hamitup{
|
||||
{17 * 8, 0, 2 * 8, 1 * 16},
|
||||
&bitmap_icon_hamitup,
|
||||
Color::light_grey(),
|
||||
Color::dark_grey()
|
||||
};
|
||||
|
||||
ImageButton button_stealth{
|
||||
{19 * 8, 0, 2 * 8, 1 * 16},
|
||||
&bitmap_icon_stealth,
|
||||
@@ -187,6 +194,7 @@ namespace ui
|
||||
SDCardStatusView sd_card_status_view{
|
||||
{28 * 8, 0 * 16, 2 * 8, 1 * 16}};
|
||||
|
||||
void on_hamitup();
|
||||
void on_speaker();
|
||||
void on_stealth();
|
||||
void on_bias_tee();
|
||||
|
||||
@@ -139,7 +139,7 @@ set(CPPSRC
|
||||
audio_stats_collector.cpp
|
||||
${COMMON}/utility.cpp
|
||||
${COMMON}/chibios_cpp.cpp
|
||||
${COMMON}/debug.cpp
|
||||
debug.cpp
|
||||
${COMMON}/gcc.cpp
|
||||
tone_gen.cpp
|
||||
)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2023 Bernd Herzog
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -26,60 +27,41 @@
|
||||
|
||||
#include "portapack_shared_memory.hpp"
|
||||
|
||||
#if defined(LPC43XX_M0)
|
||||
static void debug_indicate_error_init() {
|
||||
// TODO: Get knowledge of LED GPIO port/bit from shared place.
|
||||
LPC_GPIO->CLR[2] = (1 << 2);
|
||||
}
|
||||
void write_m4_panic_msg(const char *panic_message, struct extctx *ctxp) {
|
||||
if (ctxp == nullptr) {
|
||||
shared_memory.bb_data.data[0] = 0;
|
||||
}
|
||||
else {
|
||||
shared_memory.bb_data.data[0] = 1;
|
||||
*((uint32_t *)&shared_memory.bb_data.data[4]) = SCB->CFSR;
|
||||
memcpy(&shared_memory.bb_data.data[8], ctxp, sizeof(struct extctx));
|
||||
}
|
||||
|
||||
static void debug_indicate_error_update() {
|
||||
// Flash RX (yellow) LED to indicate baseband error.
|
||||
// TODO: Get knowledge of LED GPIO port/bit from shared place.
|
||||
LPC_GPIO->NOT[2] = (1 << 2);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(LPC43XX_M4)
|
||||
static void debug_indicate_error_init() {
|
||||
// TODO: Get knowledge of LED GPIO port/bit from shared place.
|
||||
LPC_GPIO->CLR[2] = (1 << 8);
|
||||
}
|
||||
|
||||
static void debug_indicate_error_update() {
|
||||
// Flash TX (red) LED to indicate baseband error.
|
||||
// TODO: Get knowledge of LED GPIO port/bit from shared place.
|
||||
LPC_GPIO->NOT[2] = (1 << 8);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void runtime_error() {
|
||||
debug_indicate_error_init();
|
||||
|
||||
while(true) {
|
||||
volatile size_t n = 1000000U;
|
||||
while(n--);
|
||||
debug_indicate_error_update();
|
||||
for(size_t i=0; i<sizeof(shared_memory.m4_panic_msg); i++) {
|
||||
if( *panic_message == 0 ) {
|
||||
shared_memory.m4_panic_msg[i] = 0;
|
||||
} else {
|
||||
shared_memory.m4_panic_msg[i] = *(panic_message++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
#if CH_DBG_ENABLED
|
||||
void port_halt(void) {
|
||||
// Copy debug panic message to M0 region.
|
||||
const auto* p = dbg_panic_msg;
|
||||
for(size_t i=0; i<sizeof(shared_memory.m4_panic_msg); i++) {
|
||||
if( *p == 0 ) {
|
||||
shared_memory.m4_panic_msg[i] = 0;
|
||||
} else {
|
||||
shared_memory.m4_panic_msg[i] = *(p++);
|
||||
}
|
||||
}
|
||||
|
||||
port_disable();
|
||||
runtime_error();
|
||||
}
|
||||
|
||||
#if defined(LPC43XX_M4)
|
||||
if (dbg_panic_msg == nullptr)
|
||||
dbg_panic_msg = "system halted";
|
||||
|
||||
write_m4_panic_msg(dbg_panic_msg, nullptr);
|
||||
|
||||
while (true) {
|
||||
HALT_IF_DEBUGGING();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
CH_IRQ_HANDLER(MemManageVector) {
|
||||
#if CH_DBG_ENABLED
|
||||
chDbgPanic("MemManage");
|
||||
@@ -103,6 +85,36 @@ CH_IRQ_HANDLER(UsageFaultVector) {
|
||||
chSysHalt();
|
||||
#endif
|
||||
}
|
||||
|
||||
CH_IRQ_HANDLER(HardFaultVector) {
|
||||
#if CH_DBG_ENABLED
|
||||
regarm_t _saved_lr;
|
||||
asm volatile ("mov %0, lr" : "=r" (_saved_lr) : : "memory");
|
||||
|
||||
struct extctx *ctxp;
|
||||
port_lock_from_isr();
|
||||
|
||||
if ((uint32_t)_saved_lr & 0x04)
|
||||
ctxp = (struct extctx *)__get_PSP();
|
||||
else
|
||||
ctxp = (struct extctx *)__get_MSP();
|
||||
|
||||
volatile uint32_t stack_space_left = get_free_stack_space();
|
||||
if (stack_space_left < 16)
|
||||
write_m4_panic_msg("Stack Overflow", ctxp);
|
||||
|
||||
else write_m4_panic_msg("Hard Fault", ctxp);
|
||||
|
||||
port_disable();
|
||||
|
||||
while (true) {
|
||||
HALT_IF_DEBUGGING();
|
||||
}
|
||||
|
||||
#else
|
||||
chSysHalt();
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __DEBUG_H__
|
||||
#define __DEBUG_H__
|
||||
|
||||
#include <ch.h>
|
||||
|
||||
extern uint32_t __process_stack_base__;
|
||||
extern uint32_t __process_stack_end__;
|
||||
#define CRT0_STACKS_FILL_PATTERN 0x55555555
|
||||
|
||||
inline uint32_t get_free_stack_space(){
|
||||
uint32_t *p;
|
||||
for (p = &__process_stack_base__; *p == CRT0_STACKS_FILL_PATTERN && p < &__process_stack_end__; p++);
|
||||
auto stack_space_left = p - &__process_stack_base__;
|
||||
|
||||
return stack_space_left;
|
||||
}
|
||||
|
||||
#define HALT_IF_DEBUGGING() \
|
||||
do { \
|
||||
if ((*(volatile uint32_t *)0xE000EDF0) & (1 << 0)) { \
|
||||
__asm__ __volatile__("bkpt 1"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif/*__DEBUG_H__*/
|
||||
@@ -45,8 +45,8 @@ void ADSBRXProcessor::execute(const buffer_c8_t& buffer) {
|
||||
for (size_t i = 0; i < buffer.count; i++) {
|
||||
|
||||
// Compute sample's magnitude
|
||||
re = (int32_t)buffer.p[i].real(); // make re float and scale it
|
||||
im = (int32_t)buffer.p[i].imag(); // make re float and scale it
|
||||
re = (int32_t)buffer.p[i].real();
|
||||
im = (int32_t)buffer.p[i].imag();
|
||||
mag = ((uint32_t)(re*re) + (uint32_t)(im*im));
|
||||
|
||||
if (decoding) {
|
||||
@@ -63,7 +63,6 @@ void ADSBRXProcessor::execute(const buffer_c8_t& buffer) {
|
||||
}
|
||||
else
|
||||
{
|
||||
//confidence = true;
|
||||
bit = (prev_mag > mag) ? 1 : 0;
|
||||
}
|
||||
|
||||
@@ -94,7 +93,7 @@ void ADSBRXProcessor::execute(const buffer_c8_t& buffer) {
|
||||
}
|
||||
|
||||
// Continue looking for preamble even if in a packet
|
||||
// switch is new preamble id higher magnitude
|
||||
// switch if new preamble is higher magnitude
|
||||
|
||||
// Shift the preamble
|
||||
for (c = 0; c < (ADSB_PREAMBLE_LENGTH ); c++) { shifter[c] = shifter[c + 1]; }
|
||||
|
||||
@@ -44,57 +44,118 @@ inline void OOKProcessor::write_sample(const buffer_c8_t& buffer, uint8_t bit_va
|
||||
buffer.p[i] = {re, im};
|
||||
}
|
||||
|
||||
inline void OOKProcessor::duval_algo(const buffer_c8_t& buffer) {
|
||||
bool OOKProcessor::scan_init(unsigned int order) {
|
||||
if (order > MAX_DE_BRUIJN_ORDER)
|
||||
return false;
|
||||
|
||||
scan_done = false;
|
||||
scan_progress = 0;
|
||||
|
||||
k = 0;
|
||||
idx = 1;
|
||||
|
||||
duval_symbols = 2; // 2 for binary, 3 for ternary encoders
|
||||
duval_length = 0;
|
||||
duval_bit = 0;
|
||||
duval_sample_bit = 0;
|
||||
duval_symbol = 0;
|
||||
|
||||
memset(v, 0, sizeof(v));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OOKProcessor::scan_encode(const buffer_c8_t& buffer, size_t& buf_ptr) {
|
||||
// encode data: 0 = 1000, 1 = 1110
|
||||
// @TODO: make this user-configurable
|
||||
const uint8_t sym[] = { 0b0001, 0b0111 };
|
||||
constexpr auto symbol_length = 4;
|
||||
|
||||
// iterate over every symbol in the sequence and convert it to bits with required bitrate
|
||||
for (; duval_bit < duval_length; duval_bit++) {
|
||||
auto val = v_tmp[duval_bit];
|
||||
for (; duval_symbol < symbol_length; duval_symbol++) {
|
||||
auto s = sym[val] & (1 << duval_symbol);
|
||||
for (; duval_sample_bit < samples_per_bit; duval_sample_bit++) {
|
||||
if (buf_ptr >= buffer.count) {
|
||||
// buffer is full - continue next time
|
||||
txprogress_message.done = false;
|
||||
txprogress_message.progress = scan_progress++;
|
||||
shared_memory.application_queue.push(txprogress_message);
|
||||
return false;
|
||||
}
|
||||
write_sample(buffer, s, buf_ptr++);
|
||||
}
|
||||
duval_sample_bit = 0;
|
||||
}
|
||||
duval_symbol = 0;
|
||||
}
|
||||
duval_bit = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline size_t OOKProcessor::duval_algo_step() {
|
||||
size_t buf_ptr = 0;
|
||||
const unsigned int w = de_bruijn_length;
|
||||
|
||||
// Duval's algorithm for generating de Bruijn sequence
|
||||
while (idx) {
|
||||
if (w % idx == 0) {
|
||||
for (; k < idx; k++) {
|
||||
size_t available_size = buffer.count - buf_ptr;
|
||||
size_t len = (samples_per_bit > available_size) ? available_size : samples_per_bit;
|
||||
|
||||
for (; bit_ptr < len; bit_ptr++) {
|
||||
write_sample(buffer, v[k], buf_ptr);
|
||||
buf_ptr++;
|
||||
}
|
||||
|
||||
if (buf_ptr == buffer.count) {
|
||||
txprogress_message.done = false;
|
||||
txprogress_message.progress = scan_progress++;
|
||||
shared_memory.application_queue.push(txprogress_message);
|
||||
return;
|
||||
}
|
||||
|
||||
bit_ptr = 0;
|
||||
}
|
||||
|
||||
for (unsigned int k = 0; k < idx; k++)
|
||||
v_tmp[buf_ptr++] = v[k];
|
||||
k = 0;
|
||||
}
|
||||
|
||||
for (unsigned int j = 0; j < w - idx; j++)
|
||||
v[idx + j] = v[j];
|
||||
|
||||
for (idx = w; idx > 0 && v[idx - 1]; idx--) ;
|
||||
for (idx = w; (idx > 0) && (v[idx - 1] >= duval_symbols - 1); idx--) ;
|
||||
|
||||
if (idx)
|
||||
v[idx - 1] = 1;
|
||||
}
|
||||
v[idx - 1]++;
|
||||
|
||||
// clear the buffer in case we have any bytes left
|
||||
if (buf_ptr < buffer.count) {
|
||||
for (size_t i = buf_ptr; i < buffer.count; i++) {
|
||||
buffer.p[i] = {0, 0};
|
||||
if (buf_ptr) {
|
||||
// we fill at most de_bruijn_length number of elements
|
||||
return buf_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (!scan_done) {
|
||||
txprogress_message.done = true;
|
||||
shared_memory.application_queue.push(txprogress_message);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
scan_done = 1;
|
||||
void OOKProcessor::scan_process(const buffer_c8_t& buffer) {
|
||||
size_t buf_ptr = 0;
|
||||
|
||||
// transmit any leftover bits from previous step
|
||||
if (!scan_encode(buffer, buf_ptr))
|
||||
return;
|
||||
|
||||
while (1) {
|
||||
// calculate next chunk of deBruijn sequence
|
||||
duval_length = duval_algo_step();
|
||||
|
||||
if (duval_length == 0) {
|
||||
// last chunk - done
|
||||
if (!scan_done) {
|
||||
txprogress_message.done = true;
|
||||
shared_memory.application_queue.push(txprogress_message);
|
||||
}
|
||||
scan_done = 1;
|
||||
|
||||
// clear the remaining buffer in case we have any bytes left
|
||||
for (size_t i = buf_ptr; i < buffer.count; i++)
|
||||
buffer.p[i] = { 0, 0 };
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
duval_bit = 0;
|
||||
duval_sample_bit = 0;
|
||||
duval_symbol = 0;
|
||||
|
||||
// encode the sequence into required format
|
||||
if (!scan_encode(buffer, buf_ptr))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OOKProcessor::execute(const buffer_c8_t& buffer) {
|
||||
@@ -103,7 +164,7 @@ void OOKProcessor::execute(const buffer_c8_t& buffer) {
|
||||
if (!configured) return;
|
||||
|
||||
if (de_bruijn_length) {
|
||||
duval_algo(buffer);
|
||||
scan_process(buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -175,22 +236,8 @@ void OOKProcessor::on_message(const Message* const p) {
|
||||
}
|
||||
|
||||
if (de_bruijn_length) {
|
||||
if (de_bruijn_length > sizeof(v)) {
|
||||
if (!scan_init(de_bruijn_length))
|
||||
return;
|
||||
}
|
||||
|
||||
if (samples_per_bit > 2048) {
|
||||
// can't handle more than dma::transfer_samples
|
||||
return;
|
||||
}
|
||||
|
||||
k = 0;
|
||||
bit_ptr = 0;
|
||||
idx = 1;
|
||||
scan_done = false;
|
||||
scan_progress = 0;
|
||||
|
||||
memset(v, 0, sizeof(v));
|
||||
} else {
|
||||
samples_per_bit /= 10;
|
||||
}
|
||||
|
||||
@@ -46,9 +46,9 @@ private:
|
||||
uint32_t pause_counter { 0 };
|
||||
uint8_t repeat_counter { 0 };
|
||||
uint8_t s { 0 };
|
||||
uint16_t bit_pos { 0 };
|
||||
uint8_t cur_bit { 0 };
|
||||
uint32_t sample_count { 0 };
|
||||
uint16_t bit_pos { 0 };
|
||||
uint8_t cur_bit { 0 };
|
||||
uint32_t sample_count { 0 };
|
||||
uint32_t tone_phase { 0 }, phase { 0 }, sphase { 0 };
|
||||
int32_t tone_sample { 0 }, sig { 0 }, frq { 0 };
|
||||
|
||||
@@ -56,14 +56,22 @@ private:
|
||||
|
||||
static constexpr auto MAX_DE_BRUIJN_ORDER = 24;
|
||||
uint8_t v[MAX_DE_BRUIJN_ORDER];
|
||||
uint8_t v_tmp[MAX_DE_BRUIJN_ORDER];
|
||||
unsigned int idx { 0 };
|
||||
unsigned int k { 0 };
|
||||
size_t bit_ptr{ 0 };
|
||||
unsigned int duval_symbols { 0 };
|
||||
unsigned int duval_length { 0 };
|
||||
unsigned int duval_bit { 0 };
|
||||
unsigned int duval_sample_bit { 0 };
|
||||
unsigned int duval_symbol { 0 };
|
||||
size_t scan_progress{ 0 };
|
||||
uint8_t scan_done { true };
|
||||
|
||||
size_t duval_algo_step();
|
||||
void scan_process(const buffer_c8_t& buffer);
|
||||
bool scan_init(unsigned int order);
|
||||
bool scan_encode(const buffer_c8_t& buffer, size_t& buf_ptr);
|
||||
void write_sample(const buffer_c8_t& buffer, uint8_t bit_value, size_t i);
|
||||
void duval_algo(const buffer_c8_t& buffer);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -105,22 +105,25 @@ void SpectrumCollector::post_message(const buffer_c16_t& data) {
|
||||
|
||||
template<typename T>
|
||||
static typename T::value_type spectrum_window_none(const T& s, const size_t i) {
|
||||
static_assert(power_of_two(ARRAY_ELEMENTS(s)), "Array number of elements must be power of 2"); // c/m compile error GCC10 , OK for all GCC versions.
|
||||
constexpr size_t length = sizeof(s)/sizeof(s[0]);
|
||||
static_assert(power_of_two(length), "Array length must be power of 2");
|
||||
return s[i];
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
static typename T::value_type spectrum_window_hamming_3(const T& s, const size_t i) {
|
||||
static_assert(power_of_two(ARRAY_ELEMENTS(s)), "Array number of elements must be power of 2"); // c/m compile error GCC10 , OK for all GCC versions.
|
||||
const size_t mask = s.size() - 1; // c/m compile error GCC10 , constexpr->const
|
||||
constexpr size_t length = sizeof(s)/sizeof(s[0]);
|
||||
static_assert((length), "Array length must be power of 2");
|
||||
constexpr size_t mask = length - 1;
|
||||
// Three point Hamming window.
|
||||
return s[i] * 0.54f + (s[(i-1) & mask] + s[(i+1) & mask]) * -0.23f;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
static typename T::value_type spectrum_window_blackman_3(const T& s, const size_t i) {
|
||||
static_assert(power_of_two(ARRAY_ELEMENTS(s)), "Array number of elements must be power of 2"); // c/m compile error GCC10 , OK for all GCC versions.
|
||||
const size_t mask = s.size() - 1; // c/m compile error GCC10 , constexpr->const
|
||||
constexpr size_t length = sizeof(s)/sizeof(s[0]);
|
||||
static_assert(power_of_two(length), "Array length must be power of 2");
|
||||
constexpr size_t mask = length - 1;
|
||||
// Three term Blackman window.
|
||||
constexpr float alpha = 0.42f;
|
||||
constexpr float beta = 0.5f * 0.5f;
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
#include <array>
|
||||
|
||||
bool hackrf_r9;
|
||||
|
||||
#if HAL_USE_PAL || defined(__DOXYGEN__)
|
||||
/**
|
||||
* @brief PAL setup.
|
||||
@@ -56,9 +58,9 @@ const PALConfig pal_default_config = {
|
||||
| (0 << 12) // P1_17: SGPIO11, HOST_DIRECTION
|
||||
| (1 << 11) // P1_4: SSP1_MOSI
|
||||
| (1 << 10) // P1_3: SSP1_MISO
|
||||
| (0 << 9) // P1_2: 10K PD, BOOT1
|
||||
| (1 << 8) // P1_1: 10K PU, BOOT0
|
||||
| (1 << 7) // P2_7: 10K PU, ISP
|
||||
| (0 << 9) // P1_2: Varies by revision, float until detection
|
||||
| (0 << 8) // P1_1: Varies by revision, float until detection
|
||||
| (0 << 7) // P2_7: Varies by revision, float until detection
|
||||
| (0 << 6) // P3_6: SPIFI_MISO
|
||||
| (1 << 5) // P6_6: SGPIO5, HOST_DATA5
|
||||
| (1 << 4) // P1_0: SGPIO7, HOST_DATA7
|
||||
@@ -74,9 +76,9 @@ const PALConfig pal_default_config = {
|
||||
| (0 << 12) // P1_17: SGPIO11, HOST_DIRECTION
|
||||
| (0 << 11) // P1_4: SSP1_MOSI
|
||||
| (0 << 10) // P1_3: SSP1_MISO
|
||||
| (0 << 9) // P1_2: 10K PD, BOOT1
|
||||
| (0 << 8) // P1_1: 10K PU, BOOT0
|
||||
| (0 << 7) // P2_7: 10K PU, ISP
|
||||
| (0 << 9) // P1_2: Varies by revision, float until detection
|
||||
| (0 << 8) // P1_1: Varies by revision, float until detection
|
||||
| (0 << 7) // P2_7: Varies by revision, float until detection
|
||||
| (0 << 6) // P3_6: SPIFI_MISO
|
||||
| (0 << 5) // P6_6: SGPIO5, HOST_DATA5
|
||||
| (0 << 4) // P1_0: SGPIO7, HOST_DATA7
|
||||
@@ -130,12 +132,12 @@ const PALConfig pal_default_config = {
|
||||
| (1 << 12) // P5_3: RX_MIX_BP
|
||||
| (0 << 11) // P5_2: TX_MIX_BP
|
||||
| (0 << 10) // P5_1: LP
|
||||
| (1 << 9) // P5_0: !VAA_ENABLE
|
||||
| (0 << 9) // P5_0: Varies by revision, float until detection
|
||||
| (0 << 8) // P6_12: LED3 (TX)
|
||||
| (1 << 7) // P5_7: CS_AD
|
||||
| (0 << 6) // P4_6: XCVR_EN, 10K PD
|
||||
| (0 << 5) // P4_5: RXENABLE
|
||||
| (0 << 4) // P4_4: TXENABLE
|
||||
| (0 << 4) // P4_4: Varies by revision, float until detection
|
||||
| (1 << 3) // P4_3: SGPIO9, HOST_CAPTURE
|
||||
| (0 << 2) // P4_2: LED2 (RX)
|
||||
| (0 << 1) // P4_1: LED1 (USB)
|
||||
@@ -148,12 +150,12 @@ const PALConfig pal_default_config = {
|
||||
| (1 << 12) // P5_3: RX_MIX_BP
|
||||
| (1 << 11) // P5_2: TX_MIX_BP
|
||||
| (1 << 10) // P5_1: LP
|
||||
| (1 << 9) // P5_0: !VAA_ENABLE
|
||||
| (0 << 9) // P5_0: Varies by revision, float until detection
|
||||
| (1 << 8) // P6_12: LED3 (TX)
|
||||
| (1 << 7) // P5_7: CS_AD
|
||||
| (1 << 6) // P4_6: XCVR_EN, 10K PD
|
||||
| (1 << 5) // P4_5: RXENABLE
|
||||
| (1 << 4) // P4_4: TXENABLE
|
||||
| (0 << 4) // P4_4: Varies by revision, float until detection
|
||||
| (0 << 3) // P4_3: SGPIO9, HOST_CAPTURE
|
||||
| (1 << 2) // P4_2: LED2 (RX)
|
||||
| (1 << 1) // P4_1: LED1 (USB)
|
||||
@@ -170,7 +172,7 @@ const PALConfig pal_default_config = {
|
||||
| (1 << 9) // P7_1: PortaPack GPIO3_9(IO)
|
||||
| (1 << 8) // P7_0: PortaPack GPIO3_8(IO)
|
||||
| (1 << 7) // P6_11: VREGMODE
|
||||
| (0 << 6) // P6_10: EN1V8, 10K PD
|
||||
| (0 << 6) // P6_10: Varies by revision, float until detection
|
||||
| (1 << 5) // P6_9: !TX_AMP_PWR, 10K PU
|
||||
| (1 << 4) // P6_5: HackRF CPLD.TMS(I) (output only when needed, pull-up internal to CPLD when 1V8 present)
|
||||
| (1 << 3) // P6_4: MIXER_SDATA
|
||||
@@ -188,7 +190,7 @@ const PALConfig pal_default_config = {
|
||||
| (0 << 9) // P7_1: PortaPack GPIO3_9(IO)
|
||||
| (0 << 8) // P7_0: PortaPack GPIO3_8(IO)
|
||||
| (1 << 7) // P6_11: VREGMODE
|
||||
| (1 << 6) // P6_10: EN1V8, 10K PD
|
||||
| (0 << 6) // P6_10: Varies by revision, float until detection
|
||||
| (1 << 5) // P6_9: !TX_AMP_PWR, 10K PU
|
||||
| (0 << 4) // P6_5: HackRF CPLD.TMS(I) (output only when needed, pull-up internal to CPLD when 1V8 present)
|
||||
| (0 << 3) // P6_4: MIXER_SDATA
|
||||
@@ -207,17 +209,17 @@ const PALConfig pal_default_config = {
|
||||
.data
|
||||
= (1 << 18) // P9:5: HackRF CPLD.TDO(O) (input with pull up)
|
||||
| (1 << 16) // P6_8: MIX_BYPASS
|
||||
| (0 << 15) // P6_7: TX
|
||||
| (0 << 15) // P6_7: Varies by revision, float until detection
|
||||
| (1 << 14) // P4_10: SGPIO15, CPLD (unused)
|
||||
| (1 << 13) // P4_9: SGPIO14, CPLD (unused)
|
||||
| (0 << 12) // P4_8: SGPIO13, HOST_SYNC_EN
|
||||
| (0 << 12) // P4_8: Varies by revision, float until detection
|
||||
| (1 << 11) // P3_8: SPIFI_CS
|
||||
| (1 << 10) // P3_7: SPIFI_MOSI
|
||||
| (1 << 9) // P3_2: I2S0_RX_SDA
|
||||
| (1 << 8) // P3_1: I2S0_RX_WS
|
||||
| (0 << 7) // P2_8: BOOT2
|
||||
| (0 << 6) // P2_6: MIXER_SCLK
|
||||
| (1 << 5) // P2_5: RX
|
||||
| (0 << 5) // P2_5: Varies by revision, float until detection
|
||||
| (1 << 4) // P2_4: PortaPack LCD_RDX
|
||||
| (0 << 3) // P2_3: PortaPack LCD_TE
|
||||
| (1 << 2) // P2_2: SGPIO6, HOST_DATA6
|
||||
@@ -227,17 +229,17 @@ const PALConfig pal_default_config = {
|
||||
.dir
|
||||
= (0 << 18) // P9_5: HackRF CPLD.TDO(O) (input with pull up)
|
||||
| (1 << 16) // P6_8: MIX_BYPASS
|
||||
| (1 << 15) // P6_7: TX
|
||||
| (0 << 15) // P6_7: Varies by revision, float until detection
|
||||
| (0 << 14) // P4_10: SGPIO15, CPLD (unused)
|
||||
| (0 << 13) // P4_9: SGPIO14, CPLD (unused)
|
||||
| (0 << 12) // P4_8: SGPIO13, HOST_SYNC_EN
|
||||
| (0 << 12) // P4_8: Varies by revision, float until detection
|
||||
| (0 << 11) // P3_8: SPIFI_CS
|
||||
| (0 << 10) // P3_7: SPIFI_MOSI
|
||||
| (0 << 9) // P3_2: I2S0_RX_SDA
|
||||
| (0 << 8) // P3_1: I2S0_RX_WS
|
||||
| (0 << 7) // P2_8: BOOT2
|
||||
| (0 << 6) // P2_6: MIXER_SCLK
|
||||
| (1 << 5) // P2_5: RX
|
||||
| (0 << 5) // P2_5: Varies by revision, float until detection
|
||||
| (0 << 4) // P2_4: PortaPack LCD_RDX
|
||||
| (0 << 3) // P2_3: PortaPack LCD_TE
|
||||
| (0 << 2) // P2_2: SGPIO6, HOST_DATA6
|
||||
@@ -265,8 +267,6 @@ const PALConfig pal_default_config = {
|
||||
{ 6, 12, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* LED3: LED3.A(I) */
|
||||
|
||||
/* Power control */
|
||||
{ 5, 0, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* !VAA_ENABLE: 10K PU, Q3.G(I), power to VAA */
|
||||
{ 6, 10, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* EN1V8/P70: 10K PD, TPS62410.EN2(I), 1V8LED.A(I) */
|
||||
{ 6, 11, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* VREGMODE/P69: TPS62410.MODE/DATA(I) */
|
||||
|
||||
/* HackRF: I2C0 */
|
||||
@@ -297,13 +297,11 @@ const PALConfig pal_default_config = {
|
||||
{ 1, 7, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* !MIX_BYPASS/P35: U1.VCTL1(I), U11.VCTL2(I), U9.V2(I) */
|
||||
{ 1, 19, scu_config_normal_drive_t { .mode=1, .epd=0, .epun=0, .ehs=0, .ezi=0, .zif=0 } }, /* SSP1_SCK/P39: MAX2837.SCLK(I), MAX5864.SCLK(I) */
|
||||
{ 1, 20, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* CS_XCVR/P53: MAX2837.CS(I) */
|
||||
{ 2, 5, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* RX/P43: U7.VCTL1(I), U10.VCTL1(I), U2.VCTL1(I) */
|
||||
{ 2, 6, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* MIXER_SCLK/P31: 33pF, RFFC5072.SCLK(I) */
|
||||
{ 2, 10, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* AMP_BYPASS/P50: U14.V2(I), U12.V2(I) */
|
||||
{ 2, 11, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* RX_AMP/P49: U12.V1(I), U14.V3(I) */
|
||||
{ 2, 12, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* !RX_AMP_PWR/P52: 10K PU, Q1.G(I), power to U13 (RX amp) */
|
||||
{ 4, 0, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* HP/P44: U6.VCTL1(I), U5.VCTL2(I) */
|
||||
{ 4, 4, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* TXENABLE/P55: MAX2837.TXENABLE(I) */
|
||||
{ 4, 5, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* RXENABLE/P56: MAX2837.RXENABLE(I) */
|
||||
{ 4, 6, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* XCVR_EN: 10K PD, MAX2837.ENABLE(I) */
|
||||
{ 5, 1, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* LP/P45: U6.VCTL2(I), U5.VCTL1(I) */
|
||||
@@ -314,7 +312,6 @@ const PALConfig pal_default_config = {
|
||||
{ 5, 6, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* TX_AMP/P48: U12.V3(I), U14.V1(I) */
|
||||
{ 5, 7, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* CS_AD/P54: MAX5864.CS(I) */
|
||||
{ 6, 4, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=0, .ehs=0, .ezi=1, .zif=0 } }, /* MIXER_SDATA/P27: 33pF, RFFC5072.SDATA(IO) */
|
||||
{ 6, 7, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* TX/P42: U7.VCTL2(I), U10.VCTL2(I), U2.VCTL2(I) */
|
||||
{ 6, 8, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* MIX_BYPASS/P34: U1.VCTL2(I), U11.VCTL1(I) */
|
||||
{ 6, 9, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* !TX_AMP_PWR/P51: 10K PU, Q2.G(I), power to U25 (TX amp) */
|
||||
|
||||
@@ -332,7 +329,6 @@ const PALConfig pal_default_config = {
|
||||
{ 1, 14, scu_config_normal_drive_t { .mode=6, .epd=0, .epun=0, .ehs=1, .ezi=0, .zif=0 } }, /* SGPIO10/P78/BANK2F3M8: CPLD.76/HOST_DISABLE(I) */
|
||||
{ 1, 17, scu_config_normal_drive_t { .mode=6, .epd=1, .epun=1, .ehs=1, .ezi=0, .zif=0 } }, /* SGPIO11/P79/BANK2F3M11: CPLD.71/HOST_DIRECTION(I) */
|
||||
{ 1, 18, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* SGPIO12/BANK2F3M12: CPLD.70/HOST_INVERT(I) */
|
||||
{ 4, 8, scu_config_normal_drive_t { .mode=4, .epd=1, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* SGPIO13/BANK2F3M2: CPLD.90/HOST_SYNC_EN(I) */
|
||||
{ 4, 9, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=0, .ehs=0, .ezi=0, .zif=0 } }, /* SGPIO14/BANK2F3M4: CPLD.81/CPLD_P81 */
|
||||
{ 4, 10, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=0, .ehs=0, .ezi=0, .zif=0 } }, /* SGPIO15/BANK2F3M6: CPLD.78/CPLD_P78 */
|
||||
|
||||
@@ -346,14 +342,165 @@ const PALConfig pal_default_config = {
|
||||
{ 1, 5, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=0, .ehs=0, .ezi=1, .zif=0 } }, /* SD_POW: PortaPack CPLD.TDO(O) */
|
||||
{ 1, 8, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=0, .ehs=0, .ezi=0, .zif=0 } }, /* SD_VOLT0: PortaPack CPLD.TMS(I) */
|
||||
|
||||
/* Miscellaneous */
|
||||
{ 6, 0, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=0, .ehs=0, .ezi=0, .zif=0 } }, /* I2S0_RX_MCLK: Unused */
|
||||
{ 15, 4, scu_config_normal_drive_t { .mode=7, .epd=0, .epun=0, .ehs=0, .ezi=0, .zif=0 } }, /* I2S0_RX_SCK: Unused */
|
||||
|
||||
/* Usage of these pins varies by revision, float until detection */
|
||||
{ 1, 1, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } },
|
||||
{ 1, 2, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } },
|
||||
{ 2, 5, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } },
|
||||
{ 2, 7, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } },
|
||||
{ 4, 4, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } },
|
||||
{ 4, 8, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } },
|
||||
{ 5, 0, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } },
|
||||
{ 6, 7, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } },
|
||||
{ 6, 10, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } },
|
||||
}
|
||||
};
|
||||
|
||||
/* Additional GPIO configuration for HackRF OG */
|
||||
static const std::array<gpio_setup_t, 6> gpio_setup_og { {
|
||||
{ // GPIO0
|
||||
.data
|
||||
= (0 << 9) // P1_2: 10K PD, BOOT1
|
||||
| (1 << 8) // P1_1: 10K PU, BOOT0
|
||||
| (1 << 7) // P2_7: 10K PU, ISP
|
||||
,
|
||||
.dir
|
||||
= (0 << 9) // P1_2: 10K PD, BOOT1
|
||||
| (0 << 8) // P1_1: 10K PU, BOOT0
|
||||
| (0 << 7) // P2_7: 10K PU, ISP
|
||||
},
|
||||
{ // GPIO1
|
||||
.data = 0,
|
||||
.dir = 0
|
||||
},
|
||||
{ // GPIO2
|
||||
.data
|
||||
= (1 << 9) // P5_0: !VAA_ENABLE
|
||||
| (0 << 4) // P4_4: TXENABLE
|
||||
,
|
||||
.dir
|
||||
= (1 << 9) // P5_0: !VAA_ENABLE
|
||||
| (1 << 4) // P4_4: TXENABLE
|
||||
},
|
||||
{ // GPIO3
|
||||
.data
|
||||
= (0 << 6) // P6_10: EN1V8, 10K PD
|
||||
,
|
||||
.dir
|
||||
= (1 << 6) // P6_10: EN1V8, 10K PD
|
||||
},
|
||||
{ // GPIO4
|
||||
.data = 0,
|
||||
.dir = 0
|
||||
},
|
||||
{ // GPIO5
|
||||
.data
|
||||
= (0 << 15) // P6_7: TX
|
||||
| (0 << 12) // P4_8: SGPIO13, HOST_SYNC_EN
|
||||
| (1 << 5) // P2_5: RX
|
||||
,
|
||||
.dir
|
||||
= (1 << 15) // P6_7: TX
|
||||
| (0 << 12) // P4_8: SGPIO13, HOST_SYNC_EN
|
||||
| (1 << 5) // P2_5: RX
|
||||
},
|
||||
} };
|
||||
|
||||
/* Additional GPIO configuration for HackRF r9 */
|
||||
static const std::array<gpio_setup_t, 6> gpio_setup_r9 { {
|
||||
{ // GPIO0
|
||||
.data
|
||||
= (0 << 9) // P1_2: 10K PD, BOOT1, CLKOUT_EN
|
||||
| (1 << 8) // P1_1: 10K PU, BOOT0, MCU_CLK_EN
|
||||
| (1 << 7) // P2_7: 10K PU, ISP, RX
|
||||
,
|
||||
.dir
|
||||
= (0 << 9) // P1_2: 10K PD, BOOT1, CLKOUT_EN
|
||||
| (0 << 8) // P1_1: 10K PU, BOOT0, MCU_CLK_EN
|
||||
| (0 << 7) // P2_7: 10K PU, ISP, RX
|
||||
},
|
||||
{ // GPIO1
|
||||
.data = 0,
|
||||
.dir = 0
|
||||
},
|
||||
{ // GPIO2
|
||||
.data
|
||||
= (1 << 9) // P5_0: EN1V8, 10K PD
|
||||
| (1 << 4) // P4_4: !ANT_BIAS
|
||||
,
|
||||
.dir
|
||||
= (1 << 9) // P5_0: EN1V8, 10K PD
|
||||
| (1 << 4) // P4_4: !ANT_BIAS
|
||||
},
|
||||
{ // GPIO3
|
||||
.data
|
||||
= (1 << 6) // P6_10: !VAA_ENABLE
|
||||
,
|
||||
.dir
|
||||
= (1 << 6) // P6_10: !VAA_ENABLE
|
||||
},
|
||||
{ // GPIO4
|
||||
.data = 0,
|
||||
.dir = 0
|
||||
},
|
||||
{ // GPIO5
|
||||
.data
|
||||
= (0 << 15) // P6_7: CLKIN_EN
|
||||
| (0 << 12) // P4_8: CLKIN_DETECT
|
||||
| (0 << 5) // P2_5: HOST_SYNC_EN
|
||||
,
|
||||
.dir
|
||||
= (1 << 15) // P6_7: CLKIN_EN
|
||||
| (0 << 12) // P4_8: CLKIN_DETECT
|
||||
| (0 << 5) // P2_5: HOST_SYNC_EN
|
||||
},
|
||||
} };
|
||||
|
||||
/* Additional SCU configuration for HackRF OG */
|
||||
static const std::array<scu_setup_t, 9> pins_setup_og { {
|
||||
/* Power control */
|
||||
{ 5, 0, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* !VAA_ENABLE: 10K PU, Q3.G(I), power to VAA */
|
||||
{ 6, 10, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* EN1V8/P70: 10K PD, TPS62410.EN2(I), 1V8LED.A(I) */
|
||||
|
||||
/* Radio section control */
|
||||
{ 2, 5, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* RX/P43: U7.VCTL1(I), U10.VCTL1(I), U2.VCTL1(I) */
|
||||
{ 4, 4, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* TXENABLE/P55: MAX2837.TXENABLE(I) */
|
||||
{ 6, 7, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* TX/P42: U7.VCTL2(I), U10.VCTL2(I), U2.VCTL2(I) */
|
||||
|
||||
/* SGPIO for sample transfer interface to HackRF CPLD. */
|
||||
{ 4, 8, scu_config_normal_drive_t { .mode=4, .epd=1, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* SGPIO13/BANK2F3M2: CPLD.90/HOST_SYNC_EN(I) */
|
||||
|
||||
/* Miscellaneous */
|
||||
{ 1, 1, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* P1_1/P74: 10K PU, BOOT0 */
|
||||
{ 1, 2, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* P1_2/P73: 10K PD, BOOT1 */
|
||||
{ 2, 7, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* ISP: 10K PU, Unused */
|
||||
{ 6, 0, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=0, .ehs=0, .ezi=0, .zif=0 } }, /* I2S0_RX_MCLK: Unused */
|
||||
{ 15, 4, scu_config_normal_drive_t { .mode=7, .epd=0, .epun=0, .ehs=0, .ezi=0, .zif=0 } }, /* I2S0_RX_SCK: Unused */
|
||||
}
|
||||
};
|
||||
} };
|
||||
|
||||
/* Additional SCU configuration for HackRF r9 */
|
||||
static const std::array<scu_setup_t, 9> pins_setup_r9 { {
|
||||
/* Power control */
|
||||
{ 6, 10, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* !VAA_ENABLE: 10K PU, Q3.G(I), power to VAA */
|
||||
{ 5, 0, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* EN1V8: 10K PD, TPS62410.EN2(I), 1V8LED.A(I) */
|
||||
|
||||
/* Radio section control */
|
||||
{ 2, 7, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* RX/ISP/P96: U7.VCTL(I), U10.VCTL(I), U2.VCTL(I) */
|
||||
{ 4, 4, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* !ANT_BIAS: 10K PU, Q4.G(I) */
|
||||
|
||||
/* SGPIO for sample transfer interface to HackRF CPLD. */
|
||||
{ 2, 5, scu_config_normal_drive_t { .mode=4, .epd=1, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* BANK2F3M2: CPLD.90/HOST_SYNC_EN(I) */
|
||||
|
||||
/* Clock control */
|
||||
{ 1, 1, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* MCU_CLK_EN/BOOT0: 10K PU, U28.1A(I) */
|
||||
{ 1, 2, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* CLKOUT_EN/BOOT1: 10K PD, U28.2A(I) */
|
||||
{ 6, 7, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* CLKIN_EN: U16.SEL(I), U26.1A(I) */
|
||||
|
||||
/* Miscellaneous */
|
||||
{ 4, 8, scu_config_normal_drive_t { .mode=1, .epd=1, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* CLKIN_DETECT: U26.2Y(O) */
|
||||
} };
|
||||
|
||||
#endif
|
||||
|
||||
static const std::array<scu_setup_t, 26> pins_setup_portapack { {
|
||||
@@ -398,6 +545,14 @@ static const std::array<scu_setup_t, 6> pins_setup_spifi { {
|
||||
{ 3, 8, scu_config_normal_drive_t { .mode=3, .epd=0, .epun=1, .ehs=1, .ezi=1, .zif=1 } }, /* SPIFI_CS/P68: W25Q80BV.CS(I) */
|
||||
} };
|
||||
|
||||
template<size_t N>
|
||||
void setup_gpios(const std::array<gpio_setup_t, N>& pins_setup) {
|
||||
for (size_t i = 0; i < N; i++) {
|
||||
LPC_GPIO->PIN[i] |= pins_setup[i].data;
|
||||
LPC_GPIO->DIR[i] |= pins_setup[i].dir;
|
||||
}
|
||||
}
|
||||
|
||||
static void setup_pin(const scu_setup_t& pin_setup) {
|
||||
LPC_SCU->SFSP[pin_setup.port][pin_setup.pin] = pin_setup.config;
|
||||
}
|
||||
@@ -409,6 +564,19 @@ void setup_pins(const std::array<scu_setup_t, N>& pins_setup) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* HackRF One r9 has a pull-up on GPIO3_6 (P6_10) and a pull-down on GPIO2_9 (P5_0).
|
||||
* HackRF One OG has a pull-down on GPIO3_6 (P6_10) and a pull-up on GPIO2_9 (P5_0).
|
||||
*/
|
||||
static const scu_setup_t pin_setup_detect { 5, 0, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } };
|
||||
|
||||
/* Check resistor on GPIO2_9 (P5_0) to detect HackRF hardware revision. */
|
||||
extern "C" bool detect_hackrf_r9() {
|
||||
setup_pin(pin_setup_detect);
|
||||
LPC_GPIO->DIR[2] &= ~(1 << 9);
|
||||
return LPC_GPIO->W2[9] == 0;
|
||||
}
|
||||
|
||||
static void configure_spifi(void) {
|
||||
setup_pins(pins_setup_spifi);
|
||||
|
||||
@@ -449,7 +617,8 @@ static const motocon_pwm_resources_t motocon_pwm_resources = {
|
||||
};
|
||||
|
||||
static const scu_setup_t pin_setup_vaa_enablex_pwm = { 5, 0, scu_config_normal_drive_t { .mode=1, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } };
|
||||
static const scu_setup_t pin_setup_vaa_enablex_gpio = { 5, 0, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } };
|
||||
static const scu_setup_t pin_setup_vaa_enablex_gpio_og = { 5, 0, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } };
|
||||
static const scu_setup_t pin_setup_vaa_enablex_gpio_r9 = { 6, 10, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } };
|
||||
|
||||
/* VAA powers:
|
||||
* MAX5864 analog section.
|
||||
@@ -467,52 +636,69 @@ void vaa_power_on(void) {
|
||||
*
|
||||
* Controlling timing while running from SPIFI flash is tricky, hence use of a PWM peripheral...
|
||||
*/
|
||||
if (hackrf_r9) {
|
||||
/*
|
||||
* There is enough VCC->VAA leakage prior to VAA activation from IO pins on
|
||||
* HackRF One r9 that slowing down activation like this isn't necessary, but
|
||||
* we do it just in case a different start-up sequence in the future results
|
||||
* in less leakage.
|
||||
*/
|
||||
setup_pin(pin_setup_vaa_enablex_gpio_r9); // P6_10 GPIO3[ 6]: !VAA_ENABLE, 10K PU
|
||||
for (uint32_t i = 0; i < 1000; i++) {
|
||||
LPC_GPIO->W3[6] = 1;
|
||||
LPC_GPIO->W3[6] = 0;
|
||||
}
|
||||
} else {
|
||||
/* Configure and enable MOTOCONPWM peripheral clocks.
|
||||
* Assume IDIVC is running the post-bootloader configuration, outputting 96MHz derived from PLL1.
|
||||
*/
|
||||
base_clock_enable(&motocon_pwm_resources.base);
|
||||
branch_clock_enable(&motocon_pwm_resources.branch);
|
||||
peripheral_reset(&motocon_pwm_resources.reset);
|
||||
|
||||
/* Configure and enable MOTOCONPWM peripheral clocks.
|
||||
* Assume IDIVC is running the post-bootloader configuration, outputting 96MHz derived from PLL1.
|
||||
*/
|
||||
base_clock_enable(&motocon_pwm_resources.base);
|
||||
branch_clock_enable(&motocon_pwm_resources.branch);
|
||||
peripheral_reset(&motocon_pwm_resources.reset);
|
||||
|
||||
/* Combination of pulse duration and duty cycle was arrived at empirically, to keep supply glitching
|
||||
* to +/- 0.15V.
|
||||
*/
|
||||
const uint32_t cycle_period = 256;
|
||||
uint32_t enable_period = 2;
|
||||
LPC_MCPWM->TC2 = 0;
|
||||
LPC_MCPWM->MAT2 = cycle_period - enable_period;
|
||||
LPC_MCPWM->LIM2 = cycle_period;
|
||||
|
||||
/* Switch !VAA_ENABLE pin from GPIO to MOTOCONPWM peripheral output, now that the peripheral is configured. */
|
||||
setup_pin(pin_setup_vaa_enablex_pwm); // P5_0 /GPIO2[ 9]/MCOB2: !VAA_ENABLE, 10K PU
|
||||
|
||||
/* Start the PWM operation. */
|
||||
LPC_MCPWM->CON_SET = (1 << 16);
|
||||
|
||||
/* Wait until VAA rises to approximately 90% of final voltage. */
|
||||
/* Timing assumes we're running immediately after the bootloader: 96 MHz from IRC+PLL1
|
||||
*/
|
||||
while(enable_period < cycle_period) {
|
||||
{ volatile uint32_t delay = 2000; while(delay--); }
|
||||
enable_period <<= 1;
|
||||
/* Combination of pulse duration and duty cycle was arrived at empirically, to keep supply glitching
|
||||
* to +/- 0.15V.
|
||||
*/
|
||||
const uint32_t cycle_period = 256;
|
||||
uint32_t enable_period = 2;
|
||||
LPC_MCPWM->TC2 = 0;
|
||||
LPC_MCPWM->MAT2 = cycle_period - enable_period;
|
||||
LPC_MCPWM->LIM2 = cycle_period;
|
||||
|
||||
/* Switch !VAA_ENABLE pin from GPIO to MOTOCONPWM peripheral output, now that the peripheral is configured. */
|
||||
setup_pin(pin_setup_vaa_enablex_pwm); // P5_0 /GPIO2[ 9]/MCOB2: !VAA_ENABLE, 10K PU
|
||||
|
||||
/* Start the PWM operation. */
|
||||
LPC_MCPWM->CON_SET = (1 << 16);
|
||||
|
||||
/* Wait until VAA rises to approximately 90% of final voltage. */
|
||||
/* Timing assumes we're running immediately after the bootloader: 96 MHz from IRC+PLL1
|
||||
*/
|
||||
while(enable_period < cycle_period) {
|
||||
{ volatile uint32_t delay = 2000; while(delay--); }
|
||||
enable_period <<= 1;
|
||||
LPC_MCPWM->MAT2 = cycle_period - enable_period;
|
||||
}
|
||||
|
||||
/* Hold !VAA_ENABLE active using a GPIO, so we can reclaim and shut down the MOTOCONPWM peripheral. */
|
||||
LPC_GPIO->CLR[2] = (1 << 9); // !VAA_ENABLE
|
||||
LPC_GPIO->DIR[2] |= (1 << 9);
|
||||
setup_pin(pin_setup_vaa_enablex_gpio_og); // P5_0 /GPIO2[ 9]/MCOB2: !VAA_ENABLE, 10K PU
|
||||
|
||||
peripheral_reset(&motocon_pwm_resources.reset);
|
||||
branch_clock_disable(&motocon_pwm_resources.branch);
|
||||
base_clock_disable(&motocon_pwm_resources.base);
|
||||
}
|
||||
|
||||
/* Hold !VAA_ENABLE active using a GPIO, so we can reclaim and shut down the MOTOCONPWM peripheral. */
|
||||
LPC_GPIO->CLR[2] = (1 << 9); // !VAA_ENABLE
|
||||
LPC_GPIO->DIR[2] |= (1 << 9);
|
||||
setup_pin(pin_setup_vaa_enablex_gpio); // P5_0 /GPIO2[ 9]/MCOB2: !VAA_ENABLE, 10K PU
|
||||
|
||||
peripheral_reset(&motocon_pwm_resources.reset);
|
||||
branch_clock_disable(&motocon_pwm_resources.branch);
|
||||
base_clock_disable(&motocon_pwm_resources.base);
|
||||
}
|
||||
|
||||
void vaa_power_off(void) {
|
||||
// TODO: There's a lot of other stuff that must be done to prevent
|
||||
// leakage from +3V3 into VAA.
|
||||
LPC_GPIO->W2[9] = 1;
|
||||
if (hackrf_r9) {
|
||||
LPC_GPIO->W3[6] = 1;
|
||||
} else {
|
||||
LPC_GPIO->W2[9] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -638,12 +824,30 @@ extern "C" void __late_init(void) {
|
||||
* @todo Add your board-specific code, if any.
|
||||
*/
|
||||
extern "C" void boardInit(void) {
|
||||
/* Detect HackRF variant */
|
||||
hackrf_r9 = detect_hackrf_r9();
|
||||
/* Configure variant-dependent pins. */
|
||||
if (hackrf_r9) {
|
||||
setup_gpios(gpio_setup_r9);
|
||||
setup_pins(pins_setup_r9);
|
||||
} else {
|
||||
setup_gpios(gpio_setup_og);
|
||||
setup_pins(pins_setup_og);
|
||||
}
|
||||
vaa_power_on();
|
||||
LPC_GPIO->W3[6] = 1;
|
||||
if (hackrf_r9) {
|
||||
LPC_GPIO->W2[9] = 1;
|
||||
} else {
|
||||
LPC_GPIO->W3[6] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void _default_exit(void) {
|
||||
LPC_GPIO->W3[6] = 0;
|
||||
if (hackrf_r9) {
|
||||
LPC_GPIO->W2[9] = 0;
|
||||
} else {
|
||||
LPC_GPIO->W3[6] = 0;
|
||||
}
|
||||
vaa_power_off();
|
||||
|
||||
chSysDisable();
|
||||
|
||||
@@ -41,6 +41,10 @@ SECTIONS
|
||||
startup : ALIGN(16) SUBALIGN(16)
|
||||
{
|
||||
KEEP(*(vectors))
|
||||
. = ALIGN(0x400);
|
||||
ASSERT(. == 0x400, "Error: attempting to place firmware information section at incorrect location");
|
||||
KEEP(*(.firmware_info));
|
||||
|
||||
} > flash
|
||||
|
||||
constructors : ALIGN(4) SUBALIGN(4)
|
||||
|
||||
+91
-38
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "adsb.hpp"
|
||||
#include "sine_table.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
@@ -29,21 +30,28 @@ namespace adsb {
|
||||
|
||||
void make_frame_adsb(ADSBFrame& frame, const uint32_t ICAO_address) {
|
||||
frame.clear();
|
||||
frame.push_byte((DF_ADSB << 3) | 5); // DF and CA
|
||||
frame.push_byte((DF_ADSB << 3) | 5); // DF=17 and CA
|
||||
frame.push_byte(ICAO_address >> 16);
|
||||
frame.push_byte(ICAO_address >> 8);
|
||||
frame.push_byte(ICAO_address & 0xFF);
|
||||
}
|
||||
|
||||
// Civil aircraft ADS-B message type starts with Dowlink Format (DF=17) and frame is 112 bits long.
|
||||
// All known DF's >=16 are long (112 bits). All known DF's <=15 are short (56 bits).(In this case 112 bits)
|
||||
// Msg structure consists of five main parts :|DF=17 (5 bits)|CA (3 bits)|ICAO (24 bits)|ME (56 bits)|CRC (24 bits)
|
||||
// Aircraft identification and category message structure, the ME (56 bits) = TC,5 bits | CA,3 bits | C1,6 bits | C2,6 bits | C3,6 | C4,6 | C5,6 | C6,6 | C7,6 | C8,6
|
||||
// TC : (1..4) : Aircraft identification Type Code . // TC : 9 to 18: Airbone postion // TC : 19 Airbone velocity .
|
||||
// In this encode_frame_identification function we are using DF = 17 (112 bits long) and TC=4)
|
||||
|
||||
void encode_frame_id(ADSBFrame& frame, const uint32_t ICAO_address, const std::string& callsign) {
|
||||
std::string callsign_formatted(8, '_');
|
||||
uint64_t callsign_coded = 0;
|
||||
uint32_t c, s;
|
||||
char ch;
|
||||
|
||||
make_frame_adsb(frame, ICAO_address);
|
||||
make_frame_adsb(frame, ICAO_address); // Header DF=17 Downlink Format = ADS-B message (frame 112 bits)
|
||||
|
||||
frame.push_byte(TC_IDENT << 3); // No aircraft category
|
||||
frame.push_byte(TC_IDENT << 3); // 5 top bits ME = TC = we use fix 4 , # Type aircraft Identification Category = TC_IDENT = 4,
|
||||
|
||||
// Translate and encode callsign
|
||||
for (c = 0; c < 8; c++) {
|
||||
@@ -100,42 +108,77 @@ std::string decode_frame_id(ADSBFrame& frame) {
|
||||
frame.make_CRC();
|
||||
}*/
|
||||
|
||||
void encode_frame_squawk(ADSBFrame& frame, const uint32_t squawk) {
|
||||
uint32_t squawk_coded;
|
||||
// Mode S services. (Mode Select Beacon System). There are two types of Mode S interrogations: The short (56 bits) . and the long (112 bits )
|
||||
// All known DF's >=16 are long frame msg (112 bits). All known DF's <=15 are short frame msgs (56 bits).(In this case 112 bits)
|
||||
// Identity squawk replies can be DF=5 (Surveillance Identity reply)(56 bits) / DF 21 (Comm-B with Identity reply) (112 bits)
|
||||
// DF 21: Comm-B with identity reply structure = |DF=21(5 bits)|FS (3 bits)|DR (5 bits)|UM (6 bits) |Identity squawk code (13 bits) |MB (56 bits) |CRC (24 bits) (total 112 bits)
|
||||
// Comm-B messages count for a large portion of the Mode S selective interrogation responses.(means, only transmitted information upon selective request)
|
||||
// Comm-B messages protocol supports many different types of msg's (up to 255).The three more popular ones are the following ones:
|
||||
// (a) Mode S ELementary Surveillance (ELS) / (b) Mode S EnHanced Surveillance (EHS) / (c) Meteorological information
|
||||
// Comm-B Data Selector (BDS) is an 8-bit code that determines which information to be included in the MB fields
|
||||
|
||||
void encode_frame_squawk(ADSBFrame& frame, const uint16_t squawk) {
|
||||
uint16_t squawk_coded;
|
||||
uint8_t UM_field=0b111101, FS=0b010, DR=0b00001 ;
|
||||
|
||||
// To be sent those fields, (56 bits). We should store byte by byte into the frame , and It will be transmitted byte to byte same FIFO order.
|
||||
// DF 5 bits 5 DF=21 (5 top bits) Downlink Format
|
||||
// FS 3 bits 0b000, FS (3 bottom bits) (Flight status ) = 000 : no alert, no SPI, aircraft is airborne
|
||||
// DR 5 bits 0b00001 DR (Downlink request) (5 top bits) = 00000 : no downlink request (In surveillance replies, only values 0, 1, 4, and 5 are used.)
|
||||
// UM 6 bits 0b000010 UM (Utility message)= 000000, Utility message (UM): 6 bits, contains transponder communication status information.(IIS + IDS)
|
||||
// Identity_code 13 bits squawk id_code in special interleaved format.
|
||||
// MB 56 bits
|
||||
// CRC partity 24 bits parity checksum , cyclic redundancy chek.
|
||||
|
||||
frame.clear();
|
||||
frame.push_byte( ( DF_EHS_SQUAWK << 3 ) | FS ); // DF=21 (5bits) + FS (3bits, 010 : alert, NO SPI, aircraft is airborne)
|
||||
frame.push_byte(( DR <<3 ) | ( UM_field>>3) ); // DR (5bits, 00001 : downlink request + 3 top bits of UM , let's use 0b111000
|
||||
|
||||
frame.push_byte(DF_EHS_SQUAWK << 3); // DF
|
||||
frame.push_byte(0);
|
||||
|
||||
// 12 11 10 9 8 7 6 5 4 3 2 1 0
|
||||
// 31 30 29 28 27 26 25 24 23 22 21 20 19
|
||||
// D4 B4 D2 B2 D1 B1 __ A4 C4 A2 C2 A1 C1
|
||||
// 12 11 10 9 8 7 6 5 4 3 2 1 0 (Original notes) bit weight position----------------------
|
||||
// 32 31 30 29 28 27 26 25 24 23 22 21 20 (it was wrong , now corrected) bit order inside frame msg
|
||||
// D4 B4 D2 B2 D1 B1 __ A4 C4 A2 C2 A1 C1 standard spec order of the 13 bits, to be sent , each octal digit = 3 bits , (example A=7 binary A4 A2 A0 = 111
|
||||
// ABCD = code (octal, 0000~7777)
|
||||
|
||||
// FEDCBA9876543210
|
||||
// xAAAxBBBxCCCxDDD
|
||||
// x421x421x421x421
|
||||
|
||||
squawk_coded = ((squawk << 10) & 0x1000) | // D4
|
||||
((squawk << 1) & 0x0800) | // B4
|
||||
((squawk << 9) & 0x0400) | // D2
|
||||
((squawk << 0) & 0x0200) | // B2
|
||||
((squawk << 8) & 0x0100) | // D1
|
||||
((squawk >> 1) & 0x0080) | // B1
|
||||
|
||||
((squawk >> 9) & 0x0020) | // A4
|
||||
((squawk >> 2) & 0x0010) | // C4
|
||||
((squawk >> 10) & 0x0008) | // A2
|
||||
((squawk >> 3) & 0x0004) | // C2
|
||||
((squawk >> 11) & 0x0002) | // A1
|
||||
((squawk >> 4) & 0x0001); // C1
|
||||
|
||||
frame.push_byte(squawk_coded >> 5);
|
||||
frame.push_byte(squawk_coded << 3);
|
||||
// FEDCBA9876543210
|
||||
// xAAAxBBBxCCCxDDD 4 x 3 bits (each octal digit)
|
||||
// x421x421x421x421 binary weight of each binary position, example AAA = 7 = 111 -------------------------
|
||||
|
||||
// Additional , expanded notes -------------------------------
|
||||
// Identity squawk code ABCD = code (octal, 0000~7777) , input concatenated squawk : 4 octal digits ,A4 A2 A1-B4 B2 B1-C4 C2 C1-D4 D2 D1.
|
||||
// 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 bit position of the frame msg, (Squawk id is bit 20-32, from C1..D4).
|
||||
// UM4 UM2 UM1 C1 A1 C2 A2 C4 A4 X B1 D1 B2 D2 B4 D4 3 lower bit UM4,UM2,UM1 of the UM (6bits), and we should re-order the 13 bits ABCD changing 12 bit poistion based on std.
|
||||
// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Two bytes , bit position to be send.
|
||||
|
||||
squawk_coded = ( (( UM_field & (0b111)) <<13) | ((squawk << 9) & 0x1000) ) | // C1 It also leaves in the top 3 lower bottom bitd part of UM field.
|
||||
((squawk << 2) & 0x0800) | // A1
|
||||
((squawk << 6) & 0x0400) | // C2
|
||||
((squawk >> 1) & 0x0200) | // A2
|
||||
((squawk << 3) & 0x0100) | // C4
|
||||
((squawk >> 4) & 0x0080) | // A4
|
||||
|
||||
((squawk >> 1) & 0x0020) | // B1
|
||||
((squawk << 4) & 0x0010) | // D1
|
||||
((squawk >> 4) & 0x0008) | // B2
|
||||
((squawk << 1) & 0x0004) | // D2
|
||||
((squawk >> 7) & 0x0002) | // B4
|
||||
((squawk >> 2) & 0x0001); // D4
|
||||
|
||||
frame.push_byte(squawk_coded>>8); // UM4 UM2 UM1 C1 A1 C2 A2 C4 that is the correct order, confirmed with dump1090
|
||||
frame.push_byte(squawk_coded); // A4 X(1) B1 D1 B2 D2 B4 D4 that is the correct order, confirmed with dupm1090
|
||||
|
||||
// DF 21 messages , has 56 bits more after 13 bits of squawk, we should add MB (56 bits)
|
||||
// In this example, we are adding fixed MB = Track and turn report (BDS 5,0) decoding MB example = "F9363D3BBF9CE9" (56 bits)
|
||||
// # -9.7, roll angle (deg)
|
||||
// # 140.273, track angle (deg)
|
||||
// # -0.406, track angle rate (deg/s)
|
||||
// # 476, ground speed (kt)
|
||||
// # 466, TAS (kt)
|
||||
|
||||
frame.push_byte(0xF9);frame.push_byte(0x36);frame.push_byte(0x3D);frame.push_byte(0x3B); // If we deltele those two lines, to send this fixed MB (56 bits),
|
||||
frame.push_byte(0xBF);frame.push_byte(0x9C);frame.push_byte(0xE9); // current fw is padding with 56 x 0's to complete 112 bits msg.
|
||||
|
||||
frame.make_CRC();
|
||||
}
|
||||
}
|
||||
|
||||
float cpr_mod(float a, float b) {
|
||||
return a - (b * floor(a / b));
|
||||
@@ -182,6 +225,13 @@ float cpr_Dlon(float lat, int is_odd) {
|
||||
return 360.0 / cpr_N(lat, is_odd);
|
||||
}
|
||||
|
||||
// An ADS-B frame Civil aircraft message type starts with Dowlink Format (DF=17) and frame is 112 bits long.
|
||||
// All known DF's >=16 are long (112 bits). All known DF's <=15 are short (56 bits). (In this case 112 bits)
|
||||
// Msg structure consists of five main parts :|DF=17 (5 bits)|CA (3 bits)|ICAO (24 bits)|ME (56 bits)|CRC (24 bits)
|
||||
// Airborne position msg struct, the ME (56 bits) = |TC,5 bits| SS, 2 bits | SAF, 1 | ALT, 12 | T, 1 | F, 1 | LAT-CPR, 17 | LON-CPR, 17
|
||||
// TC : (1..4) : Aircraft identification Type Code. // TC : 9 to 18: Airbone postion and altitude // TC : 19 Airbone velocity .
|
||||
// Airborne position message is used to broadcast the position and altitude of the aircraft. It has the Type Code 9–18 and 20–22. (here , we use TC=11)
|
||||
|
||||
void encode_frame_pos(ADSBFrame& frame, const uint32_t ICAO_address, const int32_t altitude,
|
||||
const float latitude, const float longitude, const uint32_t time_parity) {
|
||||
|
||||
@@ -189,7 +239,7 @@ void encode_frame_pos(ADSBFrame& frame, const uint32_t ICAO_address, const int32
|
||||
uint32_t lat, lon;
|
||||
float delta_lat, yz, rlat, delta_lon, xz;
|
||||
|
||||
make_frame_adsb(frame, ICAO_address);
|
||||
make_frame_adsb(frame, ICAO_address); // Header DF=17 (long frame 112 bits)
|
||||
|
||||
frame.push_byte(TC_AIRBORNE_POS << 3); // Bits 2~1: Surveillance Status, bit 0: NICsb
|
||||
|
||||
@@ -302,8 +352,11 @@ adsb_pos decode_frame_pos(ADSBFrame& frame_even, ADSBFrame& frame_odd) {
|
||||
return position;
|
||||
}
|
||||
|
||||
// speed is in knots
|
||||
// vertical rate is in ft/min
|
||||
// An ADS-B frame is 112 bits long. Civil aircraft ADS-B message starts with the Downlink Format ,DF=17.
|
||||
// Msg structure consists of five main parts :|DF=17 (5 bits)|CA (3 bits)|ICAO (24 bits)|ME (56 bits)|CRC (24 bits)
|
||||
// Airborne velocities are all transmitted with Type Code 19 ( TC=19 ) inside ME (56 bits)
|
||||
// [units] : speed is in knots, vertical rate climb / descend is in ft/min
|
||||
|
||||
void encode_frame_velo(ADSBFrame& frame, const uint32_t ICAO_address, const uint32_t speed,
|
||||
const float angle, const int32_t v_rate) {
|
||||
|
||||
@@ -319,7 +372,7 @@ void encode_frame_velo(ADSBFrame& frame, const uint32_t ICAO_address, const uint
|
||||
velo_ew_abs = abs(velo_ew) + 1; // encoding Velo speed EW , when sign Direction is 0 (+): West->East, (-) 1: East->West
|
||||
velo_ns_abs = abs(velo_ns) + 1; // encoding Velo speed NS , when sign Direction is 0 (+): South->North , (-) 1: North->South
|
||||
|
||||
make_frame_adsb(frame, ICAO_address);
|
||||
make_frame_adsb(frame, ICAO_address); // Header DF=17 (long frame 112 bits)
|
||||
|
||||
// Airborne velocities are all transmitted with Type Code 19 ( TC=19, using 5 bits ,TC=19 [Binary: 10011]), the following 3 bits are Subt-type Code ,SC= 1,2,3,4
|
||||
// SC Subtypes code 1 and 2 are used to report ground speeds of aircraft. (SC 3,4 to used to report true airspeed. SC 2,4 are for supersonic aircraft (not used in commercial airline).
|
||||
@@ -369,11 +422,11 @@ adsb_vel decode_frame_velo(ADSBFrame& frame){
|
||||
if(frame_data[5]&0x04) velo_ew *= -1; //check ew direction sign
|
||||
if(frame_data[7]&0x80) velo_ns *= -1; //check ns direction sign
|
||||
|
||||
velo.speed = sqrt(velo_ns*velo_ns + velo_ew*velo_ew);
|
||||
velo.speed = fast_int_magnitude(velo_ns,velo_ew);
|
||||
|
||||
if(velo.speed){
|
||||
//calculate heading in degrees from ew/ns velocities
|
||||
int16_t heading_temp = (int16_t)(atan2(velo_ew,velo_ns) * 180.0 / pi);
|
||||
int16_t heading_temp = (int16_t)(int_atan2(velo_ew,velo_ns)); // Nearest degree
|
||||
// We don't want negative values but a 0-360 scale.
|
||||
if (heading_temp < 0) heading_temp += 360.0;
|
||||
velo.heading = (uint16_t)heading_temp;
|
||||
|
||||
@@ -33,7 +33,8 @@ namespace adsb {
|
||||
|
||||
enum downlink_format {
|
||||
DF_ADSB = 17,
|
||||
DF_EHS_SQUAWK = 21
|
||||
DF_EHS_SQUAWK = 21, // DF 21: Comm-B with identity reply . Mode S enhanced surveillance of squawk + (MB_field = Track and turn report (BDS 5,0)).
|
||||
// Confirmed that it is Detected correctly by dump1090. and sdrangel.
|
||||
};
|
||||
|
||||
enum type_code {
|
||||
@@ -104,7 +105,7 @@ adsb_vel decode_frame_velo(ADSBFrame& frame);
|
||||
|
||||
//void encode_frame_emergency(ADSBFrame& frame, const uint32_t ICAO_address, const uint8_t code);
|
||||
|
||||
void encode_frame_squawk(ADSBFrame& frame, const uint32_t squawk);
|
||||
void encode_frame_squawk(ADSBFrame& frame, const uint16_t squawk);
|
||||
|
||||
} /* namespace adsb */
|
||||
|
||||
|
||||
@@ -28,11 +28,11 @@ namespace baseband {
|
||||
|
||||
void CPLD::init() {
|
||||
set_invert(false);
|
||||
gpio_baseband_invert.output();
|
||||
gpio_q_invert.output();
|
||||
}
|
||||
|
||||
void CPLD::set_invert(const bool invert) {
|
||||
gpio_baseband_invert.write(invert);
|
||||
gpio_q_invert.write(invert);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,11 +26,17 @@
|
||||
#include <ch.h>
|
||||
|
||||
void* operator new(size_t size) {
|
||||
return chHeapAlloc(0x0, size);
|
||||
void *p = chHeapAlloc(0x0, size);
|
||||
if (p == nullptr)
|
||||
chDbgPanic("Out of Memory");
|
||||
return p;
|
||||
}
|
||||
|
||||
void* operator new[](size_t size) {
|
||||
return chHeapAlloc(0x0, size);
|
||||
void *p = chHeapAlloc(0x0, size);
|
||||
if (p == nullptr)
|
||||
chDbgPanic("Out of Memory");
|
||||
return p;
|
||||
}
|
||||
|
||||
void operator delete(void* p) noexcept {
|
||||
|
||||
@@ -197,25 +197,11 @@ struct Pin {
|
||||
|
||||
constexpr Pin(
|
||||
const uint8_t port,
|
||||
const uint8_t pad,
|
||||
const PinConfig initial_config
|
||||
const uint8_t pad
|
||||
) : _pin_port { port },
|
||||
_pin_pad { pad },
|
||||
_initial_config { initial_config }
|
||||
_pin_pad { pad }
|
||||
{
|
||||
}
|
||||
/*
|
||||
constexpr Pin(
|
||||
const Pin& pin
|
||||
) : _pin_port { pin._pin_port },
|
||||
_pin_pad { pin._pin_pad },
|
||||
_initial_config { pin._initial_config }
|
||||
{
|
||||
}
|
||||
*/
|
||||
void init() const {
|
||||
LPC_SCU->SFSP[_pin_port][_pin_pad] = _initial_config;
|
||||
}
|
||||
|
||||
void mode(const uint_fast16_t mode) const {
|
||||
LPC_SCU->SFSP[_pin_port][_pin_pad] =
|
||||
@@ -228,7 +214,6 @@ struct Pin {
|
||||
|
||||
uint8_t _pin_port;
|
||||
uint8_t _pin_pad;
|
||||
uint16_t _initial_config;
|
||||
};
|
||||
|
||||
struct GPIO {
|
||||
|
||||
@@ -38,17 +38,20 @@ constexpr GPIO gpio_led_usb = gpio[GPIO2_1];
|
||||
constexpr GPIO gpio_led_rx = gpio[GPIO2_2];
|
||||
constexpr GPIO gpio_led_tx = gpio[GPIO2_8];
|
||||
|
||||
constexpr GPIO gpio_1v8_enable = gpio[GPIO3_6];
|
||||
constexpr GPIO gpio_og_1v8_enable = gpio[GPIO3_6];
|
||||
constexpr GPIO gpio_r9_1v8_enable = gpio[GPIO2_9];
|
||||
constexpr GPIO gpio_vregmode = gpio[GPIO3_7];
|
||||
constexpr GPIO gpio_vaa_disable = gpio[GPIO2_9];
|
||||
constexpr GPIO gpio_og_vaa_disable = gpio[GPIO2_9];
|
||||
constexpr GPIO gpio_r9_vaa_disable = gpio[GPIO3_6];
|
||||
|
||||
constexpr GPIO gpio_rx_mix_bp = gpio[GPIO2_12];
|
||||
constexpr GPIO gpio_tx_mix_bp = gpio[GPIO2_11];
|
||||
constexpr GPIO gpio_mix_bypass = gpio[GPIO5_16];
|
||||
constexpr GPIO gpio_not_mix_bypass = gpio[GPIO1_0];
|
||||
|
||||
constexpr GPIO gpio_rx = gpio[GPIO5_5];
|
||||
constexpr GPIO gpio_tx = gpio[GPIO5_15];
|
||||
constexpr GPIO gpio_og_rx = gpio[GPIO5_5];
|
||||
constexpr GPIO gpio_og_tx = gpio[GPIO5_15];
|
||||
constexpr GPIO gpio_r9_rx = gpio[GPIO0_7];
|
||||
|
||||
constexpr GPIO gpio_lp = gpio[GPIO2_10];
|
||||
constexpr GPIO gpio_hp = gpio[GPIO2_0];
|
||||
@@ -64,20 +67,26 @@ constexpr GPIO gpio_rffc5072_select = gpio[GPIO2_13];
|
||||
constexpr GPIO gpio_rffc5072_clock = gpio[GPIO5_6];
|
||||
constexpr GPIO gpio_rffc5072_data = gpio[GPIO3_3];
|
||||
|
||||
constexpr GPIO gpio_max2837_select = gpio[GPIO0_15];
|
||||
constexpr GPIO gpio_max2837_enable = gpio[GPIO2_6];
|
||||
constexpr GPIO gpio_max283x_select = gpio[GPIO0_15];
|
||||
constexpr GPIO gpio_max283x_enable = gpio[GPIO2_6];
|
||||
constexpr GPIO gpio_max2837_rxenable = gpio[GPIO2_5];
|
||||
constexpr GPIO gpio_max2837_txenable = gpio[GPIO2_4];
|
||||
constexpr GPIO gpio_max2839_rxtx = gpio[GPIO2_5];
|
||||
|
||||
constexpr GPIO gpio_max5864_select = gpio[GPIO2_7];
|
||||
|
||||
constexpr GPIO gpio_baseband_invert = gpio[GPIO0_13];
|
||||
constexpr GPIO gpio_q_invert = gpio[GPIO0_13];
|
||||
|
||||
constexpr GPIO gpio_cpld_tdo = gpio[GPIO5_18];
|
||||
constexpr GPIO gpio_cpld_tck = gpio[GPIO3_0];
|
||||
constexpr GPIO gpio_cpld_tms = gpio[GPIO3_4];
|
||||
constexpr GPIO gpio_cpld_tdi = gpio[GPIO3_1];
|
||||
|
||||
constexpr GPIO gpio_r9_clkin_en = gpio[GPIO5_15];
|
||||
constexpr GPIO gpio_r9_clkout_en = gpio[GPIO0_9];
|
||||
constexpr GPIO gpio_r9_mcu_clk_en = gpio[GPIO0_8];
|
||||
constexpr GPIO gpio_r9_not_ant_pwr = gpio[GPIO2_4];
|
||||
|
||||
/* LEDs */
|
||||
|
||||
constexpr LED led_usb { gpio_led_usb };
|
||||
|
||||
@@ -47,23 +47,28 @@ constexpr ClockFrequency base_apb3_clk_f = base_m4_clk_f;
|
||||
constexpr ClockFrequency ssp1_pclk_f = base_m4_clk_f;
|
||||
|
||||
constexpr ClockFrequency max5864_spi_f = 20000000U;
|
||||
constexpr ClockFrequency max2837_spi_f = 20000000U;
|
||||
constexpr ClockFrequency max283x_spi_f = 20000000U;
|
||||
|
||||
constexpr ClockFrequency rffc5072_reference_f = 40000000U;
|
||||
constexpr ClockFrequency max2837_reference_f = 40000000U;
|
||||
constexpr ClockFrequency mcu_clkin_f = 40000000U;
|
||||
constexpr ClockFrequency max283x_reference_f = 40000000U;
|
||||
constexpr ClockFrequency mcu_clkin_og_f = 40000000U;
|
||||
constexpr ClockFrequency mcu_clkin_r9_f = 10000000U;
|
||||
|
||||
constexpr uint8_t si5351_i2c_address = 0x60;
|
||||
|
||||
/* Clock Generator */
|
||||
|
||||
constexpr size_t clock_generator_output_codec = 0;
|
||||
constexpr size_t clock_generator_output_cpld = 1;
|
||||
constexpr size_t clock_generator_output_sgpio = 2;
|
||||
constexpr size_t clock_generator_output_clkout = 3;
|
||||
constexpr size_t clock_generator_output_first_if = 4;
|
||||
constexpr size_t clock_generator_output_second_if = 5;
|
||||
constexpr size_t clock_generator_output_mcu_clkin = 7;
|
||||
constexpr size_t clock_generator_output_og_codec = 0;
|
||||
constexpr size_t clock_generator_output_og_cpld = 1;
|
||||
constexpr size_t clock_generator_output_og_sgpio = 2;
|
||||
constexpr size_t clock_generator_output_og_clkout = 3;
|
||||
constexpr size_t clock_generator_output_og_first_if = 4;
|
||||
constexpr size_t clock_generator_output_og_second_if = 5;
|
||||
constexpr size_t clock_generator_output_og_mcu_clkin = 7;
|
||||
|
||||
constexpr size_t clock_generator_output_r9_if = 0;
|
||||
constexpr size_t clock_generator_output_r9_sgpio = 1;
|
||||
constexpr size_t clock_generator_output_r9_mcu_clkin = 2;
|
||||
|
||||
/* ADC0 */
|
||||
|
||||
|
||||
@@ -606,12 +606,35 @@ void ILI9341::draw_bitmap(
|
||||
const ui::Color foreground,
|
||||
const ui::Color background
|
||||
) {
|
||||
lcd_start_ram_write(p, size);
|
||||
// Not a transparent background
|
||||
if (ui::Color::magenta().v!=background.v)
|
||||
{
|
||||
lcd_start_ram_write(p, size);
|
||||
|
||||
const size_t count = size.width() * size.height();
|
||||
for(size_t i=0; i<count; i++) {
|
||||
const auto pixel = pixels[i >> 3] & (1U << (i & 0x7));
|
||||
io.lcd_write_pixel(pixel ? foreground : background);
|
||||
const size_t count = size.width() * size.height();
|
||||
for(size_t i=0; i<count; i++) {
|
||||
const auto pixel = pixels[i >> 3] & (1U << (i & 0x7));
|
||||
io.lcd_write_pixel(pixel ? foreground : background);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int x = p.x();
|
||||
int y = p.y();
|
||||
int maxX = x + size.width();
|
||||
const size_t count = size.width() * size.height();
|
||||
for(size_t i=0; i<count; i++) {
|
||||
const auto pixel = pixels[i >> 3] & (1U << (i & 0x7));
|
||||
if (pixel) {
|
||||
draw_pixel(ui::Point(x,y), foreground);
|
||||
}
|
||||
// Move to the next pixel
|
||||
x++;
|
||||
if (x>=maxX){
|
||||
x = p.x();
|
||||
y++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+86
-86
@@ -40,92 +40,92 @@ enum Pins {
|
||||
CLK0, CLK2,
|
||||
};
|
||||
|
||||
constexpr Pin pins[] = {
|
||||
[P0_0] = { 0, 0, PinConfig::sgpio_inout_fast(3) }, /* SGPIO0/P75/BANK2F3M3: CPLD.89/HOST_DATA0(IO) */
|
||||
[P0_1] = { 0, 1, PinConfig::sgpio_inout_fast(3) }, /* SGPIO1/BANK2F3M5: CPLD.79/HOST_DATA1(IO) */
|
||||
[P1_0] = { 1, 0, PinConfig::sgpio_inout_fast(6) }, /* SGPIO7/P76/BANK2F3M7: CPLD.77/HOST_DATA7(IO) */
|
||||
[P1_1] = { 1, 1, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* P1_1/P74: 10K PU, BOOT0 */
|
||||
[P1_2] = { 1, 2, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* P1_2/P73: 10K PD, BOOT1 */
|
||||
[P1_3] = { 1, 3, { .mode=5, .pd=0, .pu=0, .fast=0, .input=1, .ifilt=1 } }, /* SSP1_MISO/P41: MAX2837.DOUT(O) */
|
||||
[P1_4] = { 1, 4, { .mode=5, .pd=1, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* SSP1_MOSI/P40: MAX2837.DIN(I), MAX5864.DIN(I) */
|
||||
[P1_5] = { 1, 5, { .mode=0, .pd=0, .pu=1, .fast=0, .input=1, .ifilt=1 } }, /* SD_POW: PortaPack CPLD.TDO(O) */
|
||||
[P1_6] = { 1, 6, { .mode=7, .pd=0, .pu=1, .fast=0, .input=1, .ifilt=0 } }, /* SD_CMD: PortaPack SD.CMD(IO) */
|
||||
[P1_7] = { 1, 7, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* !MIX_BYPASS/P35: U1.VCTL1(I), U11.VCTL2(I), U9.V2(I) */
|
||||
[P1_8] = { 1, 8, { .mode=0, .pd=0, .pu=1, .fast=0, .input=0, .ifilt=1 } }, /* SD_VOLT0: PortaPack CPLD.TMS(I) */
|
||||
[P1_9] = { 1, 9, { .mode=7, .pd=0, .pu=1, .fast=0, .input=1, .ifilt=0 } }, /* SD_DAT0: PortaPack SD.DAT0(IO) */
|
||||
[P1_10] = { 1, 10, { .mode=7, .pd=0, .pu=1, .fast=0, .input=1, .ifilt=0 } }, /* SD_DAT1: PortaPack SD.DAT1(IO) */
|
||||
[P1_11] = { 1, 11, { .mode=7, .pd=0, .pu=1, .fast=0, .input=1, .ifilt=0 } }, /* SD_DAT2: PortaPack SD.DAT2(IO) */
|
||||
[P1_12] = { 1, 12, { .mode=7, .pd=0, .pu=1, .fast=0, .input=1, .ifilt=0 } }, /* SD_DAT3: PortaPack SD.DAT3(IO) */
|
||||
[P1_13] = { 1, 13, { .mode=7, .pd=0, .pu=1, .fast=0, .input=1, .ifilt=1 } }, /* SD_CD: PortaPack SD.CD(O) */
|
||||
[P1_14] = { 1, 14, PinConfig::sgpio_out_fast_with_pullup(6) }, /* SGPIO10/P78/BANK2F3M8: CPLD.76/HOST_DISABLE(I) */
|
||||
[P1_15] = { 1, 15, PinConfig::sgpio_inout_fast(2) }, /* SGPIO2/BANK2F3M9: CPLD.74/HOST_DATA2(IO) */
|
||||
[P1_16] = { 1, 16, PinConfig::sgpio_inout_fast(2) }, /* SGPIO3/BANK2F3M10: CPLD.72/HOST_DATA3(IO) */
|
||||
[P1_17] = { 1, 17, PinConfig::sgpio_out_fast_with_pullup(6) }, /* SGPIO11/P79/BANK2F3M11: CPLD.71/HOST_DIRECTION(I) */
|
||||
[P1_18] = { 1, 18, PinConfig::gpio_out_with_pulldown(0) }, /* SGPIO12/BANK2F3M12: CPLD.70/HOST_INVERT(I) */
|
||||
[P1_19] = { 1, 19, { .mode=1, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* SSP1_SCK/P39: MAX2837.SCLK(I), MAX5864.SCLK(I) */
|
||||
[P1_20] = { 1, 20, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* CS_XCVR/P53: MAX2837.CS(I) */
|
||||
[P2_0] = { 2, 0, { .mode=4, .pd=0, .pu=0, .fast=0, .input=1, .ifilt=1 } }, /* U0_TXD: PortaPack P2_0/IO_STBX */
|
||||
[P2_1] = { 2, 1, { .mode=4, .pd=0, .pu=0, .fast=0, .input=1, .ifilt=1 } }, /* U0_RXD: PortaPack P2_1/ADDR */
|
||||
[P2_2] = { 2, 2, PinConfig::sgpio_inout_fast(0) }, /* SGPIO6/BANK2F3M16: CPLD.61/HOST_DATA6(IO) */
|
||||
[P2_3] = { 2, 3, { .mode=4, .pd=0, .pu=0, .fast=0, .input=1, .ifilt=1 } }, /* I2C1_SDA: PortaPack P2_3/LCD_TE */
|
||||
[P2_4] = { 2, 4, { .mode=4, .pd=0, .pu=0, .fast=0, .input=1, .ifilt=1 } }, /* I2C1_SCL: PortaPack P2_4/LCD_RDX */
|
||||
[P2_5] = { 2, 5, { .mode=4, .pd=0, .pu=1, .fast=0, .input=0, .ifilt=1 } }, /* RX/P43: U7.VCTL1(I), U10.VCTL1(I), U2.VCTL1(I) */
|
||||
[P2_6] = { 2, 6, { .mode=4, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* MIXER_SCLK/P31: 33pF, RFFC5072.SCLK(I) */
|
||||
[P2_7] = { 2, 7, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* ISP: 10K PU, Unused */
|
||||
[P2_8] = { 2, 8, { .mode=4, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* P2_8: 10K PD, BOOT2, DFU switch, PortaPack P2_8/<unused> */
|
||||
[P2_9] = { 2, 9, { .mode=0, .pd=0, .pu=0, .fast=0, .input=1, .ifilt=1 } }, /* P2_9: 10K PD, BOOT3, PortaPack P2_9/LCD_WRX */
|
||||
[P2_10] = { 2, 10, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* AMP_BYPASS/P50: U14.V2(I), U12.V2(I) */
|
||||
[P2_11] = { 2, 11, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* RX_AMP/P49: U12.V1(I), U14.V3(I) */
|
||||
[P2_12] = { 2, 12, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* !RX_AMP_PWR/P52: 10K PU, Q1.G(I), power to U13 (RX amp) */
|
||||
[P2_13] = { 2, 13, { .mode=0, .pd=0, .pu=0, .fast=0, .input=1, .ifilt=1 } }, /* P2_13: PortaPack P2_13/DIR */
|
||||
[P3_0] = { 3, 0, { .mode=2, .pd=0, .pu=1, .fast=0, .input=1, .ifilt=1 } }, /* I2S0_TX_SCK: PortaPack I2S0_TX_SCK(I) */
|
||||
[P3_1] = { 3, 1, { .mode=0, .pd=0, .pu=1, .fast=0, .input=1, .ifilt=1 } }, /* I2S0_RX_WS: PortaPack I2S0_TX_WS(I). Input enabled to fold back into RX. */
|
||||
[P3_2] = { 3, 2, { .mode=0, .pd=0, .pu=1, .fast=0, .input=0, .ifilt=1 } }, /* I2S0_RX_SDA: PortaPack I2S0_TX_SDA(I) */
|
||||
[P4_0] = { 4, 0, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* HP/P44: U6.VCTL1(I), U5.VCTL2(I) */
|
||||
[P4_1] = { 4, 1, PinConfig::gpio_led(0) }, /* LED1: LED1.A(I) */
|
||||
[P4_2] = { 4, 2, PinConfig::gpio_led(0) }, /* LED2: LED2.A(I) */
|
||||
[P4_3] = { 4, 3, PinConfig::sgpio_in_fast(7) }, /* SGPIO9/P77/BANK2F3M1: CPLD.91/HOST_CAPTURE(O) */
|
||||
[P4_4] = { 4, 4, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* TXENABLE/P55: MAX2837.TXENABLE(I) */
|
||||
[P4_5] = { 4, 5, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* RXENABLE/P56: MAX2837.RXENABLE(I) */
|
||||
[P4_6] = { 4, 6, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* XCVR_EN: 10K PD, MAX2837.ENABLE(I) */
|
||||
[P4_7] = { 4, 7, { .mode=1, .pd=0, .pu=0, .fast=0, .input=1, .ifilt=0 } }, /* GP_CLKIN/P72/MCU_CLK: SI5351C.CLK7(O) */
|
||||
[P4_8] = { 4, 8, PinConfig::floating_input_with_pull(0, 4) }, /* SGPIO13/BANK2F3M2: CPLD.90/HOST_SYNC_EN(I) */
|
||||
[P4_9] = { 4, 9, PinConfig::floating_input(4) }, /* SGPIO14/BANK2F3M4: CPLD.81(I) */
|
||||
[P4_10] = { 4, 10, PinConfig::floating_input(4) }, /* SGPIO15/BANK2F3M6: CPLD.78(I) */
|
||||
[P5_0] = { 5, 0, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* !VAA_ENABLE: 10K PU, Q3.G(I), power to VAA */
|
||||
[P5_1] = { 5, 1, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* LP/P45: U6.VCTL2(I), U5.VCTL1(I) */
|
||||
[P5_2] = { 5, 2, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* TX_MIX_BP/P46: U9.V1(I) */
|
||||
[P5_3] = { 5, 3, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* RX_MIX_BP/P47: U9.V3(I) */
|
||||
[P5_4] = { 5, 4, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* MIXER_ENX/P32: 10K PU, 33pF, RFFC5072.ENX(I) */
|
||||
[P5_5] = { 5, 5, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* MIXER_RESETX/P33: 10K PU, 33pF, RFFC5072.RESETX(I) */
|
||||
[P5_6] = { 5, 6, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* TX_AMP/P48: U12.V3(I), U14.V1(I) */
|
||||
[P5_7] = { 5, 7, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* CS_AD/P54: MAX5864.CS(I) */
|
||||
[P6_0] = { 6, 0, { .mode=0, .pd=0, .pu=1, .fast=0, .input=0, .ifilt=1 } }, /* I2S0_RX_MCLK: Unused */
|
||||
[P6_1] = { 6, 1, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* CPLD_TCK: CPLD.TCK(I), PortaPack CPLD.TCK(I) */
|
||||
[P6_2] = { 6, 2, { .mode=0, .pd=0, .pu=0, .fast=0, .input=1, .ifilt=1 } }, /* CPLD_TDI: CPLD.TDI(I), PortaPack I2S0_RX_SDA(O), PortaPack CPLD.TDI(I) */
|
||||
[P6_3] = { 6, 3, PinConfig::sgpio_inout_fast(2) }, /* SGPIO4/BANK2F3M14: CPLD.67/HOST_DATA4(IO) */
|
||||
[P6_4] = { 6, 4, { .mode=0, .pd=0, .pu=0, .fast=0, .input=1, .ifilt=1 } }, /* MIXER_SDATA/P27: 33pF, RFFC5072.SDATA(IO) */
|
||||
[P6_5] = { 6, 5, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* CPLD_TMS: CPLD.TMS(I) */
|
||||
[P6_6] = { 6, 6, PinConfig::sgpio_inout_fast(2) }, /* SGPIO5/BANK2F3M15: CPLD.64/HOST_DATA5(IO) */
|
||||
[P6_7] = { 6, 7, { .mode=4, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* TX/P42: U7.VCTL2(I), U10.VCTL2(I), U2.VCTL2(I) */
|
||||
[P6_8] = { 6, 8, { .mode=4, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* MIX_BYPASS/P34: U1.VCTL2(I), U11.VCTL1(I) */
|
||||
[P6_9] = { 6, 9, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* !TX_AMP_PWR/P51: 10K PU, Q2.G(I), power to U25 (TX amp) */
|
||||
[P6_10] = { 6, 10, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* EN1V8/P70: 10K PD, TPS62410.EN2(I), 1V8LED.A(I) */
|
||||
[P6_11] = { 6, 11, { .mode=0, .pd=0, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* VREGMODE/P69: TPS62410.MODE/DATA(I) */
|
||||
[P6_12] = { 6, 12, PinConfig::gpio_led(0) }, /* LED3: LED3.A(I) */
|
||||
[P7_0] = { 7, 0, PinConfig::gpio_inout_with_pulldown(0) }, /* GPIO3_8: PortaPack GPIO3_8(IO) */
|
||||
[P7_1] = { 7, 1, PinConfig::gpio_inout_with_pulldown(0) }, /* GPIO3_9: PortaPack GPIO3_9(IO) */
|
||||
[P7_2] = { 7, 2, PinConfig::gpio_inout_with_pulldown(0) }, /* GPIO3_10: PortaPack GPIO3_10(IO) */
|
||||
[P7_3] = { 7, 3, PinConfig::gpio_inout_with_pulldown(0) }, /* GPIO3_11: PortaPack GPIO3_11(IO) */
|
||||
[P7_4] = { 7, 4, PinConfig::gpio_inout_with_pulldown(0) }, /* GPIO3_12: PortaPack GPIO3_12(IO) */
|
||||
[P7_5] = { 7, 5, PinConfig::gpio_inout_with_pulldown(0) }, /* GPIO3_13: PortaPack GPIO3_13(IO) */
|
||||
[P7_6] = { 7, 6, PinConfig::gpio_inout_with_pulldown(0) }, /* GPIO3_14: PortaPack GPIO3_14(IO) */
|
||||
[P7_7] = { 7, 7, PinConfig::gpio_inout_with_pulldown(0) }, /* GPIO3_15: PortaPack GPIO3_15(IO) */
|
||||
[P9_5] = { 9, 5, { .mode=4, .pd=0, .pu=0, .fast=0, .input=1, .ifilt=1 } }, /* CPLD_TDO: CPLD.TDO(O) */
|
||||
[P9_6] = { 9, 6, PinConfig::sgpio_in_fast(6) }, /* SGPIO8/SGPIO_CLK/P60: SI5351C.CLK2(O) */
|
||||
[PF_4] = { 15, 4, { .mode=7, .pd=0, .pu=1, .fast=0, .input=0, .ifilt=1 } }, /* I2S0_RX_SCK: Unused */
|
||||
[CLK0] = { 24, 0, { .mode=4, .pd=1, .pu=0, .fast=0, .input=1, .ifilt=0 } }, /* SD_CLK: PortaPack SD.CLK, enable input buffer for timing feedback? */
|
||||
[CLK2] = { 24, 2, { .mode=6, .pd=1, .pu=0, .fast=0, .input=0, .ifilt=1 } }, /* I2S0_TX_CLK: PortaPack I2S0_TX_MCLK */
|
||||
constexpr Pin pins[] {
|
||||
[P0_0] = { 0, 0},
|
||||
[P0_1] = { 0, 1},
|
||||
[P1_0] = { 1, 0},
|
||||
[P1_1] = { 1, 1},
|
||||
[P1_2] = { 1, 2},
|
||||
[P1_3] = { 1, 3},
|
||||
[P1_4] = { 1, 4},
|
||||
[P1_5] = { 1, 5},
|
||||
[P1_6] = { 1, 6},
|
||||
[P1_7] = { 1, 7},
|
||||
[P1_8] = { 1, 8},
|
||||
[P1_9] = { 1, 9},
|
||||
[P1_10] = { 1, 10},
|
||||
[P1_11] = { 1, 11},
|
||||
[P1_12] = { 1, 12},
|
||||
[P1_13] = { 1, 13},
|
||||
[P1_14] = { 1, 14},
|
||||
[P1_15] = { 1, 15},
|
||||
[P1_16] = { 1, 16},
|
||||
[P1_17] = { 1, 17},
|
||||
[P1_18] = { 1, 18},
|
||||
[P1_19] = { 1, 19},
|
||||
[P1_20] = { 1, 20},
|
||||
[P2_0] = { 2, 0},
|
||||
[P2_1] = { 2, 1},
|
||||
[P2_2] = { 2, 2},
|
||||
[P2_3] = { 2, 3},
|
||||
[P2_4] = { 2, 4},
|
||||
[P2_5] = { 2, 5},
|
||||
[P2_6] = { 2, 6},
|
||||
[P2_7] = { 2, 7},
|
||||
[P2_8] = { 2, 8},
|
||||
[P2_9] = { 2, 9},
|
||||
[P2_10] = { 2, 10},
|
||||
[P2_11] = { 2, 11},
|
||||
[P2_12] = { 2, 12},
|
||||
[P2_13] = { 2, 13},
|
||||
[P3_0] = { 3, 0},
|
||||
[P3_1] = { 3, 1},
|
||||
[P3_2] = { 3, 2},
|
||||
[P4_0] = { 4, 0},
|
||||
[P4_1] = { 4, 1},
|
||||
[P4_2] = { 4, 2},
|
||||
[P4_3] = { 4, 3},
|
||||
[P4_4] = { 4, 4},
|
||||
[P4_5] = { 4, 5},
|
||||
[P4_6] = { 4, 6},
|
||||
[P4_7] = { 4, 7},
|
||||
[P4_8] = { 4, 8},
|
||||
[P4_9] = { 4, 9},
|
||||
[P4_10] = { 4, 10},
|
||||
[P5_0] = { 5, 0},
|
||||
[P5_1] = { 5, 1},
|
||||
[P5_2] = { 5, 2},
|
||||
[P5_3] = { 5, 3},
|
||||
[P5_4] = { 5, 4},
|
||||
[P5_5] = { 5, 5},
|
||||
[P5_6] = { 5, 6},
|
||||
[P5_7] = { 5, 7},
|
||||
[P6_0] = { 6, 0},
|
||||
[P6_1] = { 6, 1},
|
||||
[P6_2] = { 6, 2},
|
||||
[P6_3] = { 6, 3},
|
||||
[P6_4] = { 6, 4},
|
||||
[P6_5] = { 6, 5},
|
||||
[P6_6] = { 6, 6},
|
||||
[P6_7] = { 6, 7},
|
||||
[P6_8] = { 6, 8},
|
||||
[P6_9] = { 6, 9},
|
||||
[P6_10] = { 6, 10},
|
||||
[P6_11] = { 6, 11},
|
||||
[P6_12] = { 6, 12},
|
||||
[P7_0] = { 7, 0},
|
||||
[P7_1] = { 7, 1},
|
||||
[P7_2] = { 7, 2},
|
||||
[P7_3] = { 7, 3},
|
||||
[P7_4] = { 7, 4},
|
||||
[P7_5] = { 7, 5},
|
||||
[P7_6] = { 7, 6},
|
||||
[P7_7] = { 7, 7},
|
||||
[P9_5] = { 9, 5},
|
||||
[P9_6] = { 9, 6},
|
||||
[PF_4] = { 15, 4},
|
||||
[CLK0] = { 24, 0},
|
||||
[CLK2] = { 24, 2},
|
||||
};
|
||||
|
||||
enum GPIOs {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
extern bool hackrf_r9;
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <cstddef>
|
||||
#include <array>
|
||||
|
||||
#include "platform.hpp"
|
||||
#include "gpio.hpp"
|
||||
#include "ui.hpp"
|
||||
|
||||
|
||||
@@ -288,6 +288,10 @@ struct data_t {
|
||||
// Recon App
|
||||
uint64_t recon_config;
|
||||
|
||||
// HamItUp (+125MHz offset by default, configurable)
|
||||
bool hamitup;
|
||||
int64_t hamitup_freq;
|
||||
|
||||
constexpr data_t() :
|
||||
structure_version(data_structure_version_enum::VERSION_CURRENT),
|
||||
tuned_frequency(tuned_frequency_reset_value),
|
||||
@@ -315,7 +319,9 @@ struct data_t {
|
||||
tone_mix(tone_mix_reset_value),
|
||||
|
||||
hardware_config(0),
|
||||
recon_config(0)
|
||||
recon_config(0),
|
||||
hamitup(0),
|
||||
hamitup_freq(125000000)
|
||||
{
|
||||
}
|
||||
};
|
||||
@@ -399,6 +405,17 @@ namespace cache {
|
||||
|
||||
void defaults() {
|
||||
cached_backup_ram = backup_ram_t();
|
||||
|
||||
// defaults values for recon app
|
||||
set_recon_autosave_freqs( false );
|
||||
set_recon_autostart_recon( true );
|
||||
set_recon_continuous( true );
|
||||
set_recon_clear_output( false );
|
||||
set_recon_load_freqs( true );
|
||||
set_recon_load_ranges( true );
|
||||
set_recon_update_ranges_when_recon( true );
|
||||
set_recon_load_hamradios( true );
|
||||
set_recon_match_mode( 0 );
|
||||
}
|
||||
|
||||
void init() {
|
||||
@@ -722,6 +739,17 @@ void set_recon_load_hamradios(const bool v ){
|
||||
void set_recon_match_mode(const bool v ) {
|
||||
data->recon_config = (data->recon_config & ~0x00800000UL) | (v << 23);
|
||||
}
|
||||
|
||||
bool config_hamitup() {
|
||||
return data->hamitup;
|
||||
}
|
||||
void set_config_hamitup(const bool v ){
|
||||
data-> hamitup = v ;
|
||||
}
|
||||
int64_t config_hamitup_freq() {
|
||||
return data->hamitup_freq ;
|
||||
}
|
||||
void set_config_hamitup_freq(const int64_t v ){
|
||||
data-> hamitup_freq = v ;
|
||||
}
|
||||
} /* namespace persistent_memory */
|
||||
} /* namespace portapack */
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user