mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-09-14 18:43:01 +00:00
Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a0179117b1 | |||
| ad577a1c66 | |||
| b9958a689b | |||
| 3d8bc308ee | |||
| 9ca36394d0 | |||
| f489d43259 | |||
| 6b663894b0 | |||
| b8ca356ce3 | |||
| 3a54b112ec | |||
| b013e68b17 | |||
| b2bf0f2459 | |||
| 56adca3bf6 | |||
| cd7c412aa4 | |||
| 16c4c28584 | |||
| 10d17fa7ce | |||
| e63f54c0a2 | |||
| b09efb4d3c | |||
| bfbbacd43c | |||
| 065d01b591 | |||
| b197a4b1de | |||
| 85eaa9d800 | |||
| 1ad092f341 | |||
| 0fe51fa7e3 | |||
| 4cc2ba690b | |||
| abee022000 | |||
| 430c8e5e79 | |||
| 7ea3eec016 | |||
| eb524f7110 | |||
| 3413d71bb3 | |||
| c64dddf5cc | |||
| 3d56bccd49 | |||
| 705e4f125f | |||
| 363b27efe8 | |||
| f8ed7489c9 | |||
| 0685fb7a9f | |||
| 6498f5a1b2 | |||
| 77f747aab2 |
@@ -83,5 +83,3 @@ venv/
|
||||
# generated bitmap arr file
|
||||
# TODO: generate bitmap during build, since we use python during build anyway, lemme know if this is a bad idea @zxkmm
|
||||
/firmware/tools/bitmap.hpp
|
||||
# flashsize is generated by cmake
|
||||
/firmware/flashsize.h
|
||||
|
||||
@@ -58,9 +58,6 @@ else()
|
||||
math(EXPR FLASH_BYTES_LIMIT_SIZE "${FLASH_MB_LIMIT_SIZE} * 1024 * 1024")
|
||||
endif()
|
||||
|
||||
#generate h files
|
||||
configure_file(flashsize.h.in ${CMAKE_CURRENT_SOURCE_DIR}/firmware/flashsize.h)
|
||||
|
||||
option(USE_CCACHE "Enable ccache, please keep an eye on this because sometimes it's not quite stable and generated unusable binary" OFF)
|
||||
|
||||
project(portapack-h1)
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
This is a fork of the [Havoc](https://github.com/furrtek/portapack-havoc/) firmware, which itself was a fork of the [PortaPack](https://github.com/sharebrained/portapack-hackrf) firmware, an add-on for the [HackRF](http://greatscottgadgets.com/hackrf/). A fork is a derivate, in this case one that has extra features and fixes when compared to the older versions.
|
||||
|
||||
[<img src="https://github.com/user-attachments/assets/dea337ab-fb64-4a2a-b419-69afd272e815" height="310">](https://github.com/portapack-mayhem/mayhem-firmware/wiki/PortaPack-Versions#new-h4m-mayhem-edition)
|
||||
[<img src="https://camo.githubusercontent.com/5c1f1da0688240ac7b2ccca0c8dbfd1d73f2540741ad8b1828ba4d5ea68af248/68747470733a2f2f6769746875622d70726f64756374696f6e2d757365722d61737365742d3632313064662e73332e616d617a6f6e6177732e636f6d2f343339333937392f3239353533323731382d38653562363631632d663934362d346365652d386232642d3061363135663737313566342e706e67" height="310">](https://github.com/portapack-mayhem/mayhem-firmware/wiki/PortaPack-Versions#h2m-mayhem-edition)
|
||||
[<img src="https://camo.githubusercontent.com/c1f7dd1e7672324f60a513f0de23de76da6a669e63896a9de535d8c8093fc3c7/68747470733a2f2f7261772e6769746875622e636f6d2f7368617265627261696e65642f706f7274617061636b2d6861636b72662f6d61737465722f646f632f696d616765732f68617264776172652f706f7274617061636b5f68315f6f7065726174696e672e6a7067" height="310">]([https://github.com/portapack-mayhem/mayhem-firmware/wiki/PortaPack-Versions#h2m-mayhem-edition](https://github.com/portapack-mayhem/mayhem-firmware/wiki/PortaPack-Versions#h1r1r2))
|
||||
[<img src="https://github-production-user-asset-6210df.s3.amazonaws.com/4393979/295532718-8e5b661c-f946-4cee-8b2d-0a615f7715f4.png" height="310">](https://github.com/portapack-mayhem/mayhem-firmware/wiki/PortaPack-Versions#h2m-mayhem-edition)
|
||||
|
||||
|
||||
# What is this?
|
||||
|
||||
@@ -28,9 +28,9 @@ This repository expands upon the previous work by many people and aims to consta
|
||||
## What to buy?
|
||||
|
||||
<!---not direct to h4m but to opensourcesdrlab https://share.hackrf.app/TUOLYI--->
|
||||
:heavy_check_mark:  The fabulous H4M [complete](https://share.hackrf.app/9UMBN5) or [upgrade](https://share.hackrf.app/30CQ55), featuring numerous improvements and accessories. Sold by our friends at [OpenSourceSDRLab](https://share.hackrf.app/99SAMT). Join their giveaways on discord (check the badge on top). _EU customers_ can purchase via [Lab401](https://share.hackrf.app/0CI2CR).
|
||||
:heavy_check_mark:  The fabulous H4M [complete](https://share.hackrf.app/DF2BZS) or [upgrade](https://share.hackrf.app/OCSJYI), featuring numerous improvements and accessories. Sold by our friends at [OpenSourceSDRLab](https://share.hackrf.app/99SAMT). Join their giveaways on discord (check the badge on top). _EU customers_ can purchase via [Lab401](https://share.hackrf.app/0CI2CR).
|
||||
|
||||
:heavy_check_mark: A recommended one is this [PortaPack H2](https://www.ebay.com/itm/116382397447), that includes everything you need with the plastic case "inspired" on [this](https://github.com/portapack-mayhem/mayhem-firmware/wiki/3d-printed-enclosure).
|
||||
:heavy_check_mark: A recommended one is this [PortaPack H2](https://share.hackrf.app/QT5JMB), that includes everything you need with the plastic case "inspired" on [this](https://github.com/portapack-mayhem/mayhem-firmware/wiki/3d-printed-enclosure).
|
||||
|
||||
:heavy_check_mark: Some individuals lean towards the [H2 with a metal enclosure](https://share.hackrf.app/24T3TO), but its advantages remain debated. Share your insights on our [wiki](https://github.com/portapack-mayhem/mayhem-firmware/wiki/Hardware-overview).
|
||||
|
||||
|
||||
+5
-2
@@ -15,8 +15,11 @@
|
||||
# - Get a shell inside the build image to
|
||||
# inspect problems: ./dockerize.sh shell
|
||||
# - Give additional parameters to the container:
|
||||
# ./dockerize.sh -j10
|
||||
# ./dockerize.sh ninja -j10
|
||||
# Additional parameters to make: ./dockerize.sh -j10
|
||||
# Use ninja instead of make: ./dockerize.sh ninja -j10
|
||||
# Addotopnal CMake parameters: ./dockerize.sh -DBOARD=PRALINE
|
||||
# Change the default build directory: ./dockerize.sh -B build-alt
|
||||
# (Alternatively --workdir works as well)
|
||||
# - Use a different dockerfile:
|
||||
# ./dockerize.sh build dockerfile-other
|
||||
# - Use a different cpu architecture:
|
||||
|
||||
+33
-26
@@ -48,43 +48,50 @@ if(NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_EQUAL ${EXPECTED_GCC_VERSION})
|
||||
set(GCC_VERSION_MISMATCH 1)
|
||||
endif()
|
||||
|
||||
#generate h files
|
||||
configure_file(flashsize.h.in flashsize.h)
|
||||
add_compile_options(-include ${CMAKE_CURRENT_BINARY_DIR}/flashsize.h)
|
||||
|
||||
add_subdirectory(application)
|
||||
add_subdirectory(baseband)
|
||||
add_subdirectory(standalone)
|
||||
add_subdirectory(test)
|
||||
|
||||
# NOTE: Dependencies break if the .bin files aren't included in DEPENDS. WTF, CMake?
|
||||
add_custom_command(
|
||||
OUTPUT ${FIRMWARE_FILENAME}
|
||||
COMMAND ${MAKE_SPI_IMAGE} ${application_BINARY_DIR}/application.bin ${baseband_BINARY_DIR}/baseband.img ${FIRMWARE_FILENAME} ${FLASH_BYTES_LIMIT_SIZE}
|
||||
DEPENDS baseband application ${MAKE_SPI_IMAGE}
|
||||
${baseband_BINARY_DIR}/baseband.img ${application_BINARY_DIR}/application.bin
|
||||
VERBATIM
|
||||
)
|
||||
if(BOARD STREQUAL "PRALINE")
|
||||
math(EXPR PRALINE_FINAL_SIZE "4 * 1024 * 1024")
|
||||
set(PRALINE_FPGA_BIN ${CMAKE_CURRENT_SOURCE_DIR}/../hackrf/firmware/fpga/build/praline_fpga.bin)
|
||||
set(APPEND_FPGA_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/tools/append_fpga_bitstream.py)
|
||||
|
||||
# NOTE: Dependencies break if the .bin files aren't included in DEPENDS. WTF, CMake?
|
||||
add_custom_command(
|
||||
OUTPUT ${FIRMWARE_FILENAME}
|
||||
COMMAND ${MAKE_SPI_IMAGE} ${application_BINARY_DIR}/application.bin ${baseband_BINARY_DIR}/baseband.img ${FIRMWARE_FILENAME} ${FLASH_BYTES_LIMIT_SIZE}
|
||||
# PRALINE: Append FPGA bitstream to firmware at offset 0x380000
|
||||
# The base firmware is 3.5MB, FPGA bitstream gets appended at the end of it, final size is 4MB
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "Appending PRALINE FPGA bitstream to firmware..."
|
||||
COMMAND python3 ${APPEND_FPGA_SCRIPT} ${FIRMWARE_FILENAME} ${PRALINE_FPGA_BIN} ${FIRMWARE_FILENAME}.tmp ${PRALINE_FINAL_SIZE}
|
||||
COMMAND ${CMAKE_COMMAND} -E rename ${FIRMWARE_FILENAME}.tmp ${FIRMWARE_FILENAME}
|
||||
DEPENDS baseband application ${MAKE_SPI_IMAGE}
|
||||
${baseband_BINARY_DIR}/baseband.img ${application_BINARY_DIR}/application.bin
|
||||
${PRALINE_FPGA_BIN} ${APPEND_FPGA_SCRIPT}
|
||||
VERBATIM
|
||||
)
|
||||
else() # Sadly this part had to be duplicated (or at least I couldn't find a better way to do it)
|
||||
# NOTE: Dependencies break if the .bin files aren't included in DEPENDS. WTF, CMake?
|
||||
add_custom_command(
|
||||
OUTPUT ${FIRMWARE_FILENAME}
|
||||
COMMAND ${MAKE_SPI_IMAGE} ${application_BINARY_DIR}/application.bin ${baseband_BINARY_DIR}/baseband.img ${FIRMWARE_FILENAME} ${FLASH_BYTES_LIMIT_SIZE}
|
||||
DEPENDS baseband application ${MAKE_SPI_IMAGE}
|
||||
${baseband_BINARY_DIR}/baseband.img ${application_BINARY_DIR}/application.bin
|
||||
VERBATIM
|
||||
)
|
||||
endif()
|
||||
|
||||
add_custom_target(
|
||||
firmware
|
||||
DEPENDS ${FIRMWARE_FILENAME} ${HACKRF_FIRMWARE_DFU_FILENAME} ${HACKRF_FIRMWARE_FILENAME}
|
||||
)
|
||||
|
||||
# PRALINE: Append FPGA bitstream to firmware at offset 0x180000
|
||||
# The base firmware is 1MB, FPGA goes at 1MB offset, final size is 2MB
|
||||
if(BOARD STREQUAL "PRALINE")
|
||||
math(EXPR PRALINE_FINAL_SIZE "4 * 1024 * 1024")
|
||||
set(PRALINE_FPGA_BIN ${CMAKE_CURRENT_SOURCE_DIR}/../hackrf/firmware/fpga/build/praline_fpga.bin)
|
||||
set(APPEND_FPGA_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/tools/append_fpga_bitstream.py)
|
||||
add_custom_command(
|
||||
TARGET firmware POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "Appending PRALINE FPGA bitstream to firmware..."
|
||||
COMMAND python3 ${APPEND_FPGA_SCRIPT} ${FIRMWARE_FILENAME} ${PRALINE_FPGA_BIN} ${FIRMWARE_FILENAME}.tmp ${PRALINE_FINAL_SIZE}
|
||||
COMMAND ${CMAKE_COMMAND} -E rename ${FIRMWARE_FILENAME}.tmp ${FIRMWARE_FILENAME}
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "PRALINE firmware with FPGA bitstream created:"
|
||||
COMMAND ls -la ${FIRMWARE_FILENAME}
|
||||
COMMENT "Appending PRALINE FPGA bitstream"
|
||||
VERBATIM
|
||||
)
|
||||
endif()
|
||||
|
||||
if(${GCC_VERSION_MISMATCH})
|
||||
set(COMPILER_MISMATCH_MESSAGE "WARNING: Compiler version mismatch, please use the official compiler version ${EXPECTED_GCC_VERSION} when sharing builds! Current compiler version: ${CMAKE_CXX_COMPILER_VERSION}")
|
||||
message(${COMPILER_MISMATCH_MESSAGE})
|
||||
|
||||
@@ -258,6 +258,7 @@ set(CPPSRC
|
||||
ook_file.cpp
|
||||
ui_baseband_stats_view.cpp
|
||||
ui_navigation.cpp
|
||||
ui_notifications.cpp
|
||||
ui_record_view.cpp
|
||||
ui_sd_card_status_view.cpp
|
||||
ui/ui_alphanum.cpp
|
||||
@@ -304,7 +305,6 @@ set(CPPSRC
|
||||
apps/ui_mictx.cpp
|
||||
apps/ui_modemsetup.cpp
|
||||
apps/ui_playlist.cpp
|
||||
apps/ui_pocsag_tx.cpp
|
||||
apps/ui_rds.cpp
|
||||
apps/ui_recon_settings.cpp
|
||||
apps/ui_recon.cpp
|
||||
|
||||
@@ -199,6 +199,58 @@ SPECOptionsView::SPECOptionsView(
|
||||
view->set_spec_iq_phase_calibration_value(view->get_spec_iq_phase_calibration_value()); // initialize iq_phase_calibration in radio
|
||||
}
|
||||
|
||||
/* PralineOptionsView *******************************************************/
|
||||
|
||||
#ifdef PRALINE
|
||||
PralineOptionsView::PralineOptionsView(Rect parent_rect, const Style* style) {
|
||||
set_parent_rect(parent_rect);
|
||||
add_children({&label_sr, &options_sr, &label_dc, &options_dc,
|
||||
&label_qi, &options_qi, &label_qs, &options_qs,
|
||||
&label_dec, &options_dec});
|
||||
|
||||
// 1. READ the current state from hardware
|
||||
fpga_reg_1 = radio::debug::fpga::register_read(1);
|
||||
uint32_t fpga_reg_2 = radio::debug::fpga::register_read(2);
|
||||
|
||||
// 2. INITIALIZE UI WIDGETS based on read bits
|
||||
options_dc.set_by_value((fpga_reg_1 & 0x01) ? 1 : 0); // Bit 0
|
||||
options_qi.set_by_value((fpga_reg_1 & 0x02) ? 1 : 0); // Bit 1
|
||||
options_qs.set_by_value((fpga_reg_1 & 0x04) ? 1 : 0); // Bit 2
|
||||
options_dec.set_by_value(fpga_reg_2);
|
||||
options_sr.set_value(receiver_model.sampling_rate() / 1000);
|
||||
|
||||
options_sr.on_change = [this](int32_t v) { receiver_model.set_sampling_rate(static_cast<uint32_t>(v) * 1000); };
|
||||
options_dc.on_change = [this](size_t, OptionsField::value_t v) {
|
||||
if (v)
|
||||
fpga_reg_1 |= 0x01;
|
||||
else
|
||||
fpga_reg_1 &= ~0x01;
|
||||
update_fpga_ctrl();
|
||||
};
|
||||
|
||||
options_qi.on_change = [this](size_t, OptionsField::value_t v) {
|
||||
if (v)
|
||||
fpga_reg_1 |= 0x02;
|
||||
else
|
||||
fpga_reg_1 &= ~0x02;
|
||||
update_fpga_ctrl();
|
||||
};
|
||||
|
||||
options_qs.on_change = [this](size_t, OptionsField::value_t v) {
|
||||
if (v)
|
||||
fpga_reg_1 |= 0x04;
|
||||
else
|
||||
fpga_reg_1 &= ~0x04;
|
||||
update_fpga_ctrl();
|
||||
};
|
||||
options_dec.on_change = [this](size_t, OptionsField::value_t v) { radio::debug::fpga::register_write(2, v); };
|
||||
}
|
||||
|
||||
void PralineOptionsView::update_fpga_ctrl() {
|
||||
radio::debug::fpga::register_write(1, fpga_reg_1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* AnalogAudioView *******************************************************/
|
||||
|
||||
AnalogAudioView::AnalogAudioView(
|
||||
@@ -217,7 +269,13 @@ AnalogAudioView::AnalogAudioView(
|
||||
&field_volume,
|
||||
&text_ctcss,
|
||||
&record_view,
|
||||
&waterfall});
|
||||
#ifdef PRALINE
|
||||
&waterfall,
|
||||
&button_pro
|
||||
#else
|
||||
&waterfall
|
||||
#endif
|
||||
});
|
||||
|
||||
// Filename Datetime and Frequency
|
||||
record_view.set_filename_date_frequency(true);
|
||||
@@ -256,6 +314,10 @@ AnalogAudioView::AnalogAudioView(
|
||||
field_frequency.set_value(receiver_model.target_frequency() + offset);
|
||||
};
|
||||
|
||||
#ifdef PRALINE
|
||||
button_pro.on_select = [this](Button&) { this->on_show_options_praline(); };
|
||||
#endif
|
||||
|
||||
audio::output::start();
|
||||
|
||||
// This call starts the correct baseband image to run
|
||||
@@ -511,7 +573,11 @@ void AnalogAudioView::update_modulation(ReceiverModel::Mode modulation) {
|
||||
const auto is_wideband_spectrum_mode = (modulation == ReceiverModel::Mode::SpectrumAnalysis);
|
||||
receiver_model.set_modulation(modulation);
|
||||
|
||||
#ifdef PRALINE
|
||||
receiver_model.set_sampling_rate(is_wideband_spectrum_mode ? spec_bw : 3023000);
|
||||
#else
|
||||
receiver_model.set_sampling_rate(is_wideband_spectrum_mode ? spec_bw : 3072000);
|
||||
#endif
|
||||
receiver_model.set_baseband_bandwidth(is_wideband_spectrum_mode ? spec_bw / 2 : 1750000);
|
||||
|
||||
receiver_model.set_hidden_offset(modulation == ReceiverModel::Mode::AMAudioFMApt ? -2200 : 0); // wefax needs to be shifted, see wefax rx app.
|
||||
@@ -553,4 +619,11 @@ void AnalogAudioView::handle_coded_squelch(uint32_t value) {
|
||||
void AnalogAudioView::on_freqchg(int64_t freq) {
|
||||
field_frequency.set_value(freq);
|
||||
}
|
||||
|
||||
#ifdef PRALINE
|
||||
void AnalogAudioView::on_show_options_praline() {
|
||||
set_options_widget(std::make_unique<PralineOptionsView>(options_view_rect, Theme::getInstance()->option_active));
|
||||
}
|
||||
#endif
|
||||
|
||||
} /* namespace ui */
|
||||
|
||||
@@ -37,6 +37,41 @@ namespace ui {
|
||||
|
||||
class AnalogAudioView;
|
||||
|
||||
#ifdef PRALINE
|
||||
class PralineOptionsView : public View {
|
||||
public:
|
||||
PralineOptionsView(Rect parent_rect, const Style* style);
|
||||
|
||||
private:
|
||||
// Layout: SR (Sample Rate), DC (DC Block), QI (Q-Invert), QS (Quarter Shift), D (Decim)
|
||||
Text label_sr{{UI_POS_X(0), UI_POS_Y(0), UI_POS_WIDTH(2), UI_POS_HEIGHT(1)}, "SR"};
|
||||
|
||||
// Parameters: Position, Length (in chars), Range, Step, and default value
|
||||
NumberField options_sr{
|
||||
{UI_POS_X(3), UI_POS_Y(0)},
|
||||
5, // Number of digits to show
|
||||
{0, 40000}, // Range: 0 to 40,000 kHz
|
||||
1, // Step: 1 kHz
|
||||
' ' // Fix: Single quotes for char
|
||||
};
|
||||
|
||||
Text label_dc{{UI_POS_X(8), UI_POS_Y(0), UI_POS_WIDTH(2), UI_POS_HEIGHT(1)}, "DC"};
|
||||
OptionsField options_dc{{UI_POS_X(11), UI_POS_Y(0)}, 2, {{"Of", 0}, {"On", 1}}};
|
||||
|
||||
Text label_qi{{UI_POS_X(14), UI_POS_Y(0), UI_POS_WIDTH(2), UI_POS_HEIGHT(1)}, "QI"};
|
||||
OptionsField options_qi{{UI_POS_X(17), UI_POS_Y(0)}, 2, {{"Of", 0}, {"On", 1}}};
|
||||
|
||||
Text label_qs{{UI_POS_X(20), UI_POS_Y(0), UI_POS_WIDTH(2), UI_POS_HEIGHT(1)}, "QS"};
|
||||
OptionsField options_qs{{UI_POS_X(23), UI_POS_Y(0)}, 2, {{"Of", 0}, {"On", 1}}};
|
||||
|
||||
Text label_dec{{UI_POS_X(26), UI_POS_Y(0), UI_POS_WIDTH(1), UI_POS_HEIGHT(1)}, "D"};
|
||||
OptionsField options_dec{{UI_POS_X(28), UI_POS_Y(0)}, 2, {{" 1", 0}, {" 2", 1}, {" 4", 2}, {" 8", 3}, {"16", 4}}};
|
||||
|
||||
uint8_t fpga_reg_1{0x00}; // Tracks DC, QI, QS bits
|
||||
void update_fpga_ctrl();
|
||||
};
|
||||
#endif
|
||||
|
||||
class AMOptionsView : public View {
|
||||
public:
|
||||
AMOptionsView(AnalogAudioView* view, Rect parent_rect, const Style* style);
|
||||
@@ -222,6 +257,11 @@ class AnalogAudioView : public View {
|
||||
uint8_t get_previous_zoom_option();
|
||||
void set_previous_zoom_option(uint8_t zoom);
|
||||
|
||||
#ifdef PRALINE
|
||||
Button button_pro{{UI_POS_X(12), UI_POS_Y(2), UI_POS_WIDTH(3), UI_POS_HEIGHT(1)}, "PRO"};
|
||||
void on_show_options_praline();
|
||||
#endif
|
||||
|
||||
private:
|
||||
static constexpr ui::Dim header_height = 3 * 16;
|
||||
|
||||
|
||||
@@ -199,6 +199,7 @@ void BLETxView::send_packet() {
|
||||
generateRandomMacAddress(randomMac);
|
||||
|
||||
char advertisementData[63] = {0};
|
||||
packets[current_packet].advertisementData[62] = '\0';
|
||||
strcpy(advertisementData, packets[current_packet].advertisementData);
|
||||
|
||||
// TODO: Make this a checkbox.
|
||||
@@ -225,7 +226,7 @@ void BLETxView::send_packet() {
|
||||
uint8_t min = 0x00;
|
||||
uint8_t max = 0x0F;
|
||||
|
||||
hexDigit = min + std::rand() % (max - min + 1);
|
||||
hexDigit = min + rand() % (max - min + 1);
|
||||
} break;
|
||||
default:
|
||||
hexDigit = 0;
|
||||
|
||||
@@ -271,10 +271,17 @@ ADSBRxDetailsView::ADSBRxDetailsView(
|
||||
&text_frame_pos_even,
|
||||
&text_frame_pos_odd,
|
||||
&button_aircraft_details,
|
||||
&button_see_map});
|
||||
&button_see_map,
|
||||
&opt_map_list});
|
||||
|
||||
text_icao_address.set(entry_.icao_str);
|
||||
|
||||
opt_map_list.on_change = [this](size_t, uint32_t mf) {
|
||||
map_filter = mf;
|
||||
clear_map_markers(); // reset them
|
||||
pos_history.clear(); // erase the trail
|
||||
};
|
||||
|
||||
button_aircraft_details.on_select = [this, &nav](Button&) {
|
||||
aircraft_details_view_ = nav.push<ADSBRxAircraftDetailsView>(entry_);
|
||||
nav.set_on_pop([this]() {
|
||||
@@ -288,7 +295,7 @@ ADSBRxDetailsView::ADSBRxDetailsView(
|
||||
get_map_tag(entry_),
|
||||
entry_.pos.altitude,
|
||||
GeoPos::alt_unit::FEET,
|
||||
GeoPos::spd_unit::HIDDEN,
|
||||
GeoPos::spd_unit::KNOTS,
|
||||
entry_.pos.latitude,
|
||||
entry_.pos.longitude,
|
||||
entry_.velo.heading);
|
||||
@@ -312,17 +319,107 @@ void ADSBRxDetailsView::update(const AircraftRecentEntry& entry) {
|
||||
// AC Details view is showing, nothing to update.
|
||||
} else if (geomap_view_) {
|
||||
// Map is showing, update the current item.
|
||||
if (map_filter == 1) {
|
||||
// add to map trail history
|
||||
add_map_trail(entry);
|
||||
}
|
||||
geomap_view_->update_tag(get_map_tag(entry_));
|
||||
geomap_view_->update_position(entry.pos.latitude, entry.pos.longitude, entry.velo.heading, entry.pos.altitude, entry.velo.speed);
|
||||
geomap_view_->update_position(entry.pos.latitude, entry.pos.longitude, entry.velo.heading, entry.pos.altitude, entry.get_ground_speed());
|
||||
} else {
|
||||
// Details is showing, update details.
|
||||
refresh_ui();
|
||||
}
|
||||
}
|
||||
|
||||
void ADSBRxDetailsView::get_altitude_color(int32_t alt_ft, uint8_t* r, uint8_t* g, uint8_t* b) {
|
||||
static const struct {
|
||||
int32_t alt;
|
||||
uint8_t r, g, b;
|
||||
} stops[] = {
|
||||
{0, 220, 220, 220}, // 0 ft: White/Grey (Ground)
|
||||
{2000, 255, 255, 0}, // 2k ft: Yellow
|
||||
{10000, 0, 255, 0}, // 10k ft: Green
|
||||
{20000, 0, 255, 255}, // 20k ft: Cyan
|
||||
{30000, 60, 60, 255}, // 30k ft: Blue (Lightened for visibility on Black)
|
||||
{40000, 255, 0, 255} // 40k+ ft: Magenta
|
||||
};
|
||||
if (alt_ft <= stops[0].alt) {
|
||||
*r = stops[0].r;
|
||||
*g = stops[0].g;
|
||||
*b = stops[0].b;
|
||||
return;
|
||||
}
|
||||
const int count = sizeof(stops) / sizeof(stops[0]);
|
||||
if (alt_ft >= stops[count - 1].alt) {
|
||||
*r = stops[count - 1].r;
|
||||
*g = stops[count - 1].g;
|
||||
*b = stops[count - 1].b;
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < count - 1; i++) {
|
||||
if (alt_ft < stops[i + 1].alt) {
|
||||
float t = (float)(alt_ft - stops[i].alt) / (stops[i + 1].alt - stops[i].alt);
|
||||
|
||||
*r = (uint8_t)(stops[i].r + (stops[i + 1].r - stops[i].r) * t);
|
||||
*g = (uint8_t)(stops[i].g + (stops[i + 1].g - stops[i].g) * t);
|
||||
*b = (uint8_t)(stops[i].b + (stops[i + 1].b - stops[i].b) * t);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Fallback: in case no interval matched, default to ground color.
|
||||
*r = stops[0].r;
|
||||
*g = stops[0].g;
|
||||
*b = stops[0].b;
|
||||
}
|
||||
|
||||
void ADSBRxDetailsView::clear_map_markers() {
|
||||
if (geomap_view_)
|
||||
geomap_view_->clear_markers();
|
||||
if (map_filter == 1)
|
||||
refresh_trail_markers(); // re add trail
|
||||
}
|
||||
|
||||
void ADSBRxDetailsView::refresh_trail_markers() {
|
||||
if (!geomap_view_)
|
||||
return;
|
||||
|
||||
geomap_view_->clear_markers();
|
||||
for (const auto& pos : pos_history) {
|
||||
GeoMarker marker{};
|
||||
marker.lon = pos.lon;
|
||||
marker.lat = pos.lat;
|
||||
marker.angle = pos.heading;
|
||||
marker.tag = ""; // No tag for trail points
|
||||
uint8_t r, g, b;
|
||||
get_altitude_color(pos.altitude, &r, &g, &b);
|
||||
marker.color = Color(r, g, b);
|
||||
geomap_view_->store_marker(marker);
|
||||
}
|
||||
}
|
||||
|
||||
void ADSBRxDetailsView::add_map_trail(const AircraftRecentEntry& entry) {
|
||||
if (!geomap_view_)
|
||||
return;
|
||||
if (entry.pos.pos_valid == false)
|
||||
return;
|
||||
|
||||
if (!pos_history.empty()) {
|
||||
const auto& last_pos = pos_history.back();
|
||||
const float THRESH_DEG = 0.009f;
|
||||
const float THRESH_SQ = THRESH_DEG * THRESH_DEG; // 0.00002025f
|
||||
|
||||
float d_lat = entry.pos.latitude - last_pos.lat;
|
||||
float d_lon = entry.pos.longitude - last_pos.lon;
|
||||
if ((d_lat * d_lat) + (d_lon * d_lon) < THRESH_SQ) {
|
||||
return; // Moved less than ~1000m, skip (rough estimate, varies with latitude but good enough for our purposes). This prevents adding too many points when the plane is circling or taxiing.
|
||||
}
|
||||
}
|
||||
|
||||
// Only keep the last 30 positions in the trail.
|
||||
if (pos_history.size() >= 30)
|
||||
pos_history.erase(pos_history.begin());
|
||||
pos_history.push_back({entry.pos.latitude, entry.pos.longitude, entry.velo.heading, entry.pos.altitude});
|
||||
refresh_trail_markers();
|
||||
}
|
||||
|
||||
bool ADSBRxDetailsView::add_map_marker(const AircraftRecentEntry& entry) {
|
||||
@@ -330,11 +427,16 @@ bool ADSBRxDetailsView::add_map_marker(const AircraftRecentEntry& entry) {
|
||||
if (!geomap_view_)
|
||||
return false;
|
||||
|
||||
if (map_filter == 1) return false; // this is the 'only me' option, so skip all others
|
||||
|
||||
GeoMarker marker{};
|
||||
marker.lon = entry.pos.longitude;
|
||||
marker.lat = entry.pos.latitude;
|
||||
marker.angle = entry.velo.heading;
|
||||
marker.tag = get_map_tag(entry);
|
||||
uint8_t r, g, b;
|
||||
get_altitude_color(entry.pos.altitude, &r, &g, &b);
|
||||
marker.color = Color(r, g, b);
|
||||
|
||||
auto markerStored = geomap_view_->store_marker(marker);
|
||||
return markerStored == MARKER_STORED;
|
||||
@@ -651,14 +753,15 @@ void ADSBRxView::refresh_ui() {
|
||||
// Process the entries list.
|
||||
for (const auto& entry : recent) {
|
||||
// Found the entry being shown in details view. Update it.
|
||||
if (entry.key() == detail_key) {
|
||||
if (entry.key() == detail_key) { // we don't add it to the markers, since this is the currently selected and shown in the middle one. This eliminates the "shadow" marker, and saves ram
|
||||
details_view->update(entry);
|
||||
current_updated = true;
|
||||
}
|
||||
|
||||
// NB: current entry also gets a marker so it shows up if map is panned.
|
||||
if (map_needs_update && entry.pos.pos_valid && entry.state <= ADSBAgeState::Recent) {
|
||||
map_needs_update = details_view->add_map_marker(entry);
|
||||
} else {
|
||||
// Add others only
|
||||
// NB: current entry also gets a marker so it shows up if map is panned.
|
||||
if (map_needs_update && entry.pos.pos_valid && entry.state <= ADSBAgeState::Recent) {
|
||||
map_needs_update = details_view->add_map_marker(entry);
|
||||
}
|
||||
}
|
||||
|
||||
// Any work left to do?
|
||||
|
||||
@@ -64,9 +64,9 @@ namespace ui {
|
||||
#define VEL_AIR_SUBSONIC 3
|
||||
#define VEL_AIR_SUPERSONIC 4
|
||||
|
||||
#define O_E_FRAME_TIMEOUT 20 // timeout between odd and even frames
|
||||
#define MARKER_UPDATE_SECONDS_OSM 10 // "other" map marker redraw interval for osm
|
||||
#define MARKER_UPDATE_SECONDS_BIN 5 // "other" map marker redraw interval for bin map
|
||||
#define O_E_FRAME_TIMEOUT 20 // timeout between odd and even frames
|
||||
#define MARKER_UPDATE_SECONDS_OSM 8 // "other" map marker redraw interval for osm
|
||||
#define MARKER_UPDATE_SECONDS_BIN 5 // "other" map marker redraw interval for bin map
|
||||
|
||||
/* Thresholds (in seconds) that define the transition between ages. */
|
||||
struct ADSBAgeLimit {
|
||||
@@ -150,6 +150,19 @@ struct AircraftRecentEntry {
|
||||
age = 0;
|
||||
}
|
||||
|
||||
int32_t get_ground_speed() const {
|
||||
if (velo.valid == false) return 0;
|
||||
if (velo.type == SPD_GND)
|
||||
return velo.speed;
|
||||
else if (velo.type == SPD_IAS) {
|
||||
if (!pos.alt_valid) return velo.speed; // can't correct without altitude, so just return IAS
|
||||
return (int32_t)(velo.speed * (1.0f + (0.02f * (pos.altitude / 1000.0f))));
|
||||
} else if (velo.type == SPD_TAS)
|
||||
return velo.speed; // We don't know the wind speed
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void inc_age(int delta) {
|
||||
age += delta;
|
||||
|
||||
@@ -208,50 +221,50 @@ class ADSBRxAircraftDetailsView : public View {
|
||||
|
||||
private:
|
||||
Labels labels{
|
||||
{{UI_POS_X(0), 1 * 16}, "ICAO:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), 2 * 16}, "Registration:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), 3 * 16}, "Manufacturer:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), 5 * 16}, "Model:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), 7 * 16}, "Type:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), 8 * 16}, "Number of engines:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), 9 * 16}, "Engine type:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), 11 * 16}, "Owner:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), 13 * 16}, "Operator:", Theme::getInstance()->fg_light->foreground}};
|
||||
{{UI_POS_X(0), UI_POS_Y(1)}, "ICAO:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(2)}, "Registration:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(3)}, "Manufacturer:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(5)}, "Model:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(7)}, "Type:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(8)}, "Number of engines:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(9)}, "Engine type:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(11)}, "Owner:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(13)}, "Operator:", Theme::getInstance()->fg_light->foreground}};
|
||||
|
||||
Text text_icao_address{
|
||||
{5 * 8, 1 * 16, 6 * 8, UI_POS_HEIGHT(1)},
|
||||
{UI_POS_X(5), UI_POS_Y(1), 6 * 8, UI_POS_HEIGHT(1)},
|
||||
"-"};
|
||||
|
||||
Text text_registration{
|
||||
{13 * 8, 2 * 16, 8 * 8, UI_POS_HEIGHT(1)},
|
||||
{UI_POS_X(13), UI_POS_Y(2), 8 * 8, UI_POS_HEIGHT(1)},
|
||||
"-"};
|
||||
|
||||
Text text_manufacturer{
|
||||
{UI_POS_X(0), 4 * 16, 19 * 8, UI_POS_HEIGHT(1)},
|
||||
{UI_POS_X(0), UI_POS_Y(4), 19 * 8, UI_POS_HEIGHT(1)},
|
||||
"-"};
|
||||
|
||||
Text text_model{
|
||||
{UI_POS_X(0), 6 * 16, screen_width, UI_POS_HEIGHT(1)},
|
||||
{UI_POS_X(0), UI_POS_Y(6), screen_width, UI_POS_HEIGHT(1)},
|
||||
"-"};
|
||||
|
||||
Text text_type{
|
||||
{5 * 8, 7 * 16, 22 * 8, UI_POS_HEIGHT(1)},
|
||||
{UI_POS_X(5), UI_POS_Y(7), 22 * 8, UI_POS_HEIGHT(1)},
|
||||
"-"};
|
||||
|
||||
Text text_number_of_engines{
|
||||
{18 * 8, 8 * 16, screen_width, UI_POS_HEIGHT(1)},
|
||||
{UI_POS_X(18), UI_POS_Y(8), screen_width, UI_POS_HEIGHT(1)},
|
||||
"-"};
|
||||
|
||||
Text text_engine_type{
|
||||
{UI_POS_X(0), 10 * 16, screen_width, UI_POS_HEIGHT(1)},
|
||||
{UI_POS_X(0), UI_POS_Y(10), screen_width, UI_POS_HEIGHT(1)},
|
||||
"-"};
|
||||
|
||||
Text text_owner{
|
||||
{UI_POS_X(0), 12 * 16, screen_width, UI_POS_HEIGHT(1)},
|
||||
{UI_POS_X(0), UI_POS_Y(12), screen_width, UI_POS_HEIGHT(1)},
|
||||
"-"};
|
||||
|
||||
Text text_operator{
|
||||
{UI_POS_X(0), 14 * 16, screen_width, UI_POS_HEIGHT(1)},
|
||||
{UI_POS_X(0), UI_POS_Y(14), screen_width, UI_POS_HEIGHT(1)},
|
||||
"-"};
|
||||
|
||||
Button button_close{
|
||||
@@ -270,11 +283,14 @@ class ADSBRxDetailsView : public View {
|
||||
void focus() override;
|
||||
void update(const AircraftRecentEntry& entry);
|
||||
|
||||
void get_altitude_color(int32_t alt_ft, uint8_t* r, uint8_t* g, uint8_t* b);
|
||||
/* Calls forwarded to map view if shown. */
|
||||
bool map_active() const { return geomap_view_; }
|
||||
void clear_map_markers();
|
||||
/* Adds a marker for the entry to the map. Returns true on success. */
|
||||
bool add_map_marker(const AircraftRecentEntry& entry);
|
||||
void add_map_trail(const AircraftRecentEntry& entry);
|
||||
void refresh_trail_markers();
|
||||
|
||||
std::string title() const override { return "Details"; }
|
||||
|
||||
@@ -297,57 +313,72 @@ class ADSBRxDetailsView : public View {
|
||||
// if removed from the recent entries list.
|
||||
AircraftRecentEntry entry_{AircraftRecentEntry::invalid_key};
|
||||
bool airline_checked{false};
|
||||
uint8_t map_filter{0}; // 0: all, 1: only this, set by opt_map_list.
|
||||
struct PosHistory {
|
||||
float lat;
|
||||
float lon;
|
||||
uint16_t heading;
|
||||
int32_t altitude;
|
||||
};
|
||||
std::vector<PosHistory> pos_history{};
|
||||
|
||||
Labels labels{
|
||||
{{UI_POS_X(0), 1 * 16}, "ICAO:", Theme::getInstance()->fg_light->foreground},
|
||||
{{13 * 8, 1 * 16}, "Callsign:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), 2 * 16}, "Last seen:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), 3 * 16}, "Airline:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), 5 * 16}, "Country:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), 13 * 16}, "Even position frame:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), 15 * 16}, "Odd position frame:", Theme::getInstance()->fg_light->foreground}};
|
||||
{{UI_POS_X(0), UI_POS_Y(0)}, "ICAO:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(13), UI_POS_Y(0)}, "Callsign:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(1)}, "Last seen:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(2)}, "Airline:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(4)}, "Country:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(7)}, "Map filter:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(13)}, "Even position frame:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(15)}, "Odd position frame:", Theme::getInstance()->fg_light->foreground}};
|
||||
|
||||
Text text_icao_address{
|
||||
{5 * 8, 1 * 16, 6 * 8, UI_POS_HEIGHT(1)},
|
||||
{UI_POS_X(5), UI_POS_Y(0), 6 * 8, UI_POS_HEIGHT(1)},
|
||||
"-"};
|
||||
|
||||
Text text_callsign{
|
||||
{22 * 8, 1 * 16, 8 * 8, UI_POS_HEIGHT(1)},
|
||||
{UI_POS_X(22), UI_POS_Y(0), 8 * 8, UI_POS_HEIGHT(1)},
|
||||
"-"};
|
||||
|
||||
Text text_last_seen{
|
||||
{11 * 8, 2 * 16, 19 * 8, UI_POS_HEIGHT(1)},
|
||||
{UI_POS_X(11), UI_POS_Y(1), 19 * 8, UI_POS_HEIGHT(1)},
|
||||
"-"};
|
||||
|
||||
Text text_airline{
|
||||
{UI_POS_X(0), 4 * 16, screen_width, UI_POS_HEIGHT(1)},
|
||||
{UI_POS_X(0), UI_POS_Y(3), screen_width, UI_POS_HEIGHT(1)},
|
||||
"-"};
|
||||
|
||||
Text text_country{
|
||||
{8 * 8, 5 * 16, 22 * 8, UI_POS_HEIGHT(1)},
|
||||
{UI_POS_X(8), UI_POS_Y(4), 22 * 8, UI_POS_HEIGHT(1)},
|
||||
"-"};
|
||||
|
||||
Text text_infos{
|
||||
{UI_POS_X(0), 6 * 16, screen_width, UI_POS_HEIGHT(1)},
|
||||
{UI_POS_X(0), UI_POS_Y(5), screen_width, UI_POS_HEIGHT(1)},
|
||||
"-"};
|
||||
|
||||
Text text_info2{
|
||||
{UI_POS_X(0), 7 * 16, screen_width, UI_POS_HEIGHT(1)},
|
||||
{UI_POS_X(0), UI_POS_Y(6), screen_width, UI_POS_HEIGHT(1)},
|
||||
"-"};
|
||||
|
||||
Text text_frame_pos_even{
|
||||
{UI_POS_X(0), 14 * 16, screen_width, UI_POS_HEIGHT(1)},
|
||||
{UI_POS_X(0), UI_POS_Y(14), screen_width, UI_POS_HEIGHT(1)},
|
||||
"-"};
|
||||
Text text_frame_pos_odd{
|
||||
{UI_POS_X(0), 16 * 16, screen_width, UI_POS_HEIGHT(1)},
|
||||
{UI_POS_X(0), UI_POS_Y(16), screen_width, UI_POS_HEIGHT(1)},
|
||||
"-"};
|
||||
|
||||
Button button_aircraft_details{
|
||||
{UI_POS_X_CENTER(12) - UI_POS_X(8), UI_POS_Y(9), UI_POS_WIDTH(12), UI_POS_HEIGHT(3)},
|
||||
{UI_POS_X_CENTER(12) - UI_POS_X(8), UI_POS_Y(8), UI_POS_WIDTH(12), UI_POS_HEIGHT(3)},
|
||||
"A/C details"};
|
||||
|
||||
OptionsField opt_map_list{
|
||||
{UI_POS_X_CENTER(12) + UI_POS_X(8), UI_POS_Y(7)},
|
||||
12,
|
||||
{{"All", 0},
|
||||
{"Only this", 1}}};
|
||||
|
||||
Button button_see_map{
|
||||
{UI_POS_X_CENTER(12) + UI_POS_X(8), UI_POS_Y(9), UI_POS_WIDTH(12), UI_POS_HEIGHT(3)},
|
||||
{UI_POS_X_CENTER(12) + UI_POS_X(8), UI_POS_Y(8), UI_POS_WIDTH(12), UI_POS_HEIGHT(3)},
|
||||
"See on map"};
|
||||
|
||||
MessageHandlerRegistration message_handler_gps{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -438,6 +438,113 @@ class RadioDiagnosticsView : public View {
|
||||
"Done"};
|
||||
};
|
||||
|
||||
#ifdef PRALINE
|
||||
/* Praline-Specific Radio Debug View
|
||||
* Monitors Mixer Lock, SPI Bit Depth, and toggles Si5351 CLK5
|
||||
*/
|
||||
class PralineRadioDebugView : public View {
|
||||
public:
|
||||
PralineRadioDebugView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "Pro Radio Debug"; };
|
||||
|
||||
private:
|
||||
void refresh();
|
||||
void toggle_clk5();
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "=== Pro Radio Debug ==="};
|
||||
|
||||
// Mixer Lock (PD_11 / GPIO6[25])
|
||||
Text text_lbl_lock{{0, 24, 124, 16}, "Mix Lock (LD):"};
|
||||
Text text_lock_status{{126, 24, 114, 16}, "---"};
|
||||
|
||||
// Si5351 CLK5 (Mixer Reference)
|
||||
Text text_lbl_clk5{{0, 40, 124, 16}, "Si5351 CLK5(Mix):"};
|
||||
Text text_clk5_status{{126, 40, 114, 16}, "---"};
|
||||
|
||||
// SPI Bus configuration check
|
||||
Text text_lbl_spi{{0, 56, 124, 16}, "SPI Bit Mode:"};
|
||||
Text text_spi_status{{126, 56, 118, 16}, "---"};
|
||||
|
||||
// FPGA DC Block (Reg 1)
|
||||
Text text_lbl_fpga_ctrl{{0, 72, 124, 16}, "FPGA Reg 1:"};
|
||||
Text text_fpga_ctrl{{126, 72, 118, 16}, "---"};
|
||||
|
||||
// VAA Power Rail (P8_1 / GPIO4[1])
|
||||
Text text_lbl_vaa{{0, 88, 124, 16}, "VAA RF Power:"};
|
||||
Text text_vaa_status{{126, 88, 118, 16}, "---"};
|
||||
|
||||
Text text_status_msg{{0, 110, 240, 48}, ""};
|
||||
|
||||
Button button_refresh{{8, 240, 72, 24}, "Refresh"};
|
||||
Button button_toggle_clk5{{88, 240, 72, 24}, "CLK5_T"};
|
||||
Button button_done{{168, 240, 64, 24}, "Done"};
|
||||
};
|
||||
#endif
|
||||
|
||||
/* WFMAudioDebugView ***************************************************/
|
||||
|
||||
#ifdef PRALINE
|
||||
class WFMAudioDebugView : public View {
|
||||
public:
|
||||
WFMAudioDebugView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "WFM Audio Debug"; }
|
||||
|
||||
private:
|
||||
void refresh();
|
||||
|
||||
NavigationView& nav_;
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "=== WFM Audio Debug ==="};
|
||||
|
||||
// Sample rates section
|
||||
Text text_lbl_clk0{{0, 20, 140, 16}, "Si5351 CLK0 Rate:"};
|
||||
Text text_clk0{{150, 20, 90, 16}, "---"};
|
||||
|
||||
Text text_lbl_fpga_dec{{0, 36, 140, 16}, "FPGA Decimation:"};
|
||||
Text text_fpga_dec{{150, 36, 90, 16}, "---"};
|
||||
|
||||
Text text_lbl_post_fpga{{0, 52, 140, 16}, "Post-FPGA Rate:"};
|
||||
Text text_post_fpga{{150, 52, 90, 16}, "---"};
|
||||
|
||||
// MAX2831 section
|
||||
Text text_section1{{0, 72, 240, 16}, "--- MAX2831 LPF ---"};
|
||||
|
||||
Text text_lbl_reg8{{0, 88, 140, 16}, "Reg8 (LPF RX):"};
|
||||
Text text_reg8{{150, 88, 90, 16}, "---"};
|
||||
|
||||
Text text_lbl_lpf_bw{{0, 104, 140, 16}, "LPF Bandwidth:"};
|
||||
Text text_lpf_bw{{150, 104, 90, 16}, "---"};
|
||||
|
||||
// FPGA section
|
||||
Text text_section2{{0, 124, 240, 16}, "--- FPGA Control ---"};
|
||||
|
||||
Text text_lbl_fpga_r1{{0, 140, 140, 16}, "Reg1 (Ctrl):"};
|
||||
Text text_fpga_r1{{150, 140, 90, 16}, "---"};
|
||||
|
||||
Text text_lbl_dc_q{{0, 156, 70, 16}, "DC/Q/QS:"};
|
||||
Text text_dc_q{{72, 156, 168, 16}, "---"};
|
||||
|
||||
// Audio section
|
||||
Text text_section3{{0, 176, 240, 16}, "--- Audio Path ---"};
|
||||
|
||||
Text text_lbl_expected{{0, 192, 96, 16}, "Expctd Aud:"};
|
||||
Text text_expected{{98, 192, 142, 16}, "---"};
|
||||
|
||||
Text text_lbl_deemph{{0, 208, 96, 16}, "D-emph Cfg:"};
|
||||
Text text_deemph{{98, 208, 132, 16}, "---"};
|
||||
|
||||
// Status
|
||||
Text text_status{{0, 228, 240, 16}, "---"};
|
||||
Text text_status2{{0, 244, 240, 16}, "---"};
|
||||
|
||||
Button button_refresh{{10, 268, 70, 24}, "Refresh"};
|
||||
Button button_toggle_q{{90, 268, 70, 24}, "Toggle Q"};
|
||||
Button button_done{{170, 268, 60, 24}, "Done"};
|
||||
};
|
||||
#endif
|
||||
|
||||
/* BasebandStatusView ***************************************************/
|
||||
|
||||
class BasebandStatusView : public View {
|
||||
@@ -643,34 +750,36 @@ class Si5351DebugView : public View {
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
Text text_title{{8, 16, 200, 16}, "Si5351 Clock Generator"};
|
||||
Text text_title{{0, 0, 200, 16}, "Si5351 Clock Generator"};
|
||||
|
||||
Text text_status_label{{8, 40, 80, 16}, "Status Reg:"};
|
||||
Text text_status_value{{96, 40, 144, 16}, ""};
|
||||
Text text_status_label{{0, 16, 80, 16}, "Status Reg:"};
|
||||
Text text_status_value{{96, 16, 144, 16}, ""};
|
||||
|
||||
Text text_pll_a_label{{8, 60, 80, 16}, "PLL A:"};
|
||||
Text text_pll_a_status{{96, 60, 144, 16}, ""};
|
||||
Text text_pll_a_label{{0, 32, 80, 16}, "PLL A:"};
|
||||
Text text_pll_a_status{{96, 32, 144, 16}, ""};
|
||||
|
||||
Text text_pll_b_label{{8, 80, 80, 16}, "PLL B:"};
|
||||
Text text_pll_b_status{{96, 80, 144, 16}, ""};
|
||||
Text text_pll_b_label{{0, 48, 80, 16}, "PLL B:"};
|
||||
Text text_pll_b_status{{96, 48, 144, 16}, ""};
|
||||
|
||||
Text text_sys_init_label{{8, 100, 80, 16}, "SYS_INIT:"};
|
||||
Text text_sys_init_status{{96, 100, 144, 16}, ""};
|
||||
Text text_sys_init_label{{0, 64, 80, 16}, "SYS_INIT:"};
|
||||
Text text_sys_init_status{{96, 64, 144, 16}, ""};
|
||||
|
||||
Text text_xtal_cap_label{{8, 120, 80, 16}, "XTAL Cap:"};
|
||||
Text text_xtal_cap_value{{96, 120, 144, 16}, ""};
|
||||
Text text_xtal_cap_label{{0, 80, 80, 16}, "XTAL Cap:"};
|
||||
Text text_xtal_cap_value{{96, 80, 144, 16}, ""};
|
||||
|
||||
Text text_clk0_label{{8, 150, 72, 16}, "CLK0:"};
|
||||
Text text_clk0_status{{88, 150, 152, 16}, ""};
|
||||
Text text_clk0_label{{0, 96, 48, 16}, "CLK0:"};
|
||||
Text text_clk0_status{{50, 96, 28, 16}, ""};
|
||||
Text text_clk0_freq_value{{80, 96, 160, 16}, ""};
|
||||
Text text_clk0_div_value{{50, 112, 190, 16}, ""};
|
||||
|
||||
Text text_clk0_freq_label{{8, 170, 72, 16}, " Freq:"};
|
||||
Text text_clk0_freq_value{{88, 170, 152, 16}, ""};
|
||||
Text text_clk1_label{{0, 128, 96, 16}, "CLK1 (SCT):"};
|
||||
Text text_clk1_status{{112, 128, 128, 16}, ""};
|
||||
|
||||
Text text_clk0_div_label{{8, 190, 72, 16}, " Div:"};
|
||||
Text text_clk0_div_value{{88, 190, 152, 16}, ""};
|
||||
Text text_clk4_label{{0, 144, 96, 16}, "CLK4 (MAX):"};
|
||||
Text text_clk4_status{{112, 144, 128, 16}, ""};
|
||||
|
||||
Text text_clk1_label{{8, 210, 96, 16}, "CLK1 (SCT):"};
|
||||
Text text_clk1_status{{112, 210, 128, 16}, ""};
|
||||
Text text_clk5_label{{0, 160, 96, 16}, "CLK5 (RFFC):"};
|
||||
Text text_clk5_status{{112, 160, 128, 16}, ""};
|
||||
|
||||
Button button_refresh{{8, 240, 72, 24}, "Refresh"};
|
||||
Button button_reset_pll{{88, 240, 72, 24}, "Reset PLL"};
|
||||
@@ -694,7 +803,7 @@ class SignalPathStatusView : public View {
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "=== Signal Path Status ==="};
|
||||
|
||||
Text text_lbl_max_enable{{0, 20, 1114, 16}, "MAX2831:"};
|
||||
Text text_lbl_max_enable{{0, 20, 114, 16}, "MAX2831:"};
|
||||
Text text_max_enable{{116, 20, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_max_mode{{0, 36, 114, 16}, "RX Mode:"};
|
||||
@@ -748,8 +857,8 @@ class GPIODebugView : public View {
|
||||
// GPIO4 (LPF and RF Amp)
|
||||
Text text_lbl_gpio4{{0, 0, 240, 16}, "Pin Diag: GPIO4 (LPF|Amp|Mix)"};
|
||||
|
||||
Text text_lbl_dir4{{0, 18, 114, 16}, "DIR[4]:"};
|
||||
Text text_dir4{{116, 18, 124, 16}, "---"};
|
||||
Text text_lbl_mixr1{{0, 18, 56, 16}, "MixR1:"};
|
||||
Text text_mixr1{{58, 18, 180, 16}, "---"};
|
||||
|
||||
Text text_lbl_pin4{{0, 36, 114, 16}, "PIN[4] (read):"};
|
||||
Text text_pin4{{116, 36, 124, 16}, "---"};
|
||||
@@ -802,13 +911,11 @@ class RFFC5072StatusView : public View {
|
||||
NavigationView& nav_;
|
||||
void refresh_status();
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "=== RFFC5072 (1st IF) ==="};
|
||||
Text text_status{{0, 0, 240, 16}, "---"};
|
||||
|
||||
Text text_lbl_lock{{0, 16, 114, 16}, "Lock Detect:"};
|
||||
Text text_lock{{116, 16, 124, 16}, "---"};
|
||||
Text text_gpio4{{0, 16, 240, 16}, "---"};
|
||||
|
||||
Text text_lbl_ctrl{{0, 32, 114, 16}, "Control:"};
|
||||
Text text_ctrl{{116, 32, 124, 16}, "---"};
|
||||
Text text_ctrl{{0, 32, 240, 16}, "---"};
|
||||
|
||||
Text text_lbl_enabled{{0, 48, 114, 16}, "Status:"};
|
||||
Text text_enabled{{116, 48, 124, 16}, "---"};
|
||||
@@ -840,12 +947,13 @@ class RFFC5072StatusView : public View {
|
||||
Text text_lbl_calc{{0, 192, 114, 16}, "Calc freq:"};
|
||||
Text text_calc{{116, 192, 124, 16}, "---"};
|
||||
|
||||
Text text_status{{0, 208, 240, 16}, ""};
|
||||
Text text_regs_status{{0, 208, 240, 16}, "---"};
|
||||
|
||||
Text text_lbl_regs_status{{0, 224, 48, 16}, "Regs:"};
|
||||
Text text_regs_status{{50, 224, 190, 16}, "---"};
|
||||
Text text_status2{{0, 224, 240, 16}, ""};
|
||||
Text text_status3{{0, 240, 240, 16}, ""};
|
||||
|
||||
Button button_refresh{{2, 280, 56, 24}, "Rfrsh"};
|
||||
Button button_refresh{{2, 280, 72, 24}, "Refresh"};
|
||||
Button button_force{{98, 280, 60, 24}, "SPI"};
|
||||
Button button_done{{182, 280, 56, 24}, "Done"};
|
||||
};
|
||||
|
||||
@@ -1017,6 +1125,148 @@ class SystemDiagnosticsView : public View {
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef PRALINE
|
||||
/* Si5351MultiSynthDebugView - Debug fractional register values for MS0 */
|
||||
class Si5351MultiSynthDebugView : public View {
|
||||
public:
|
||||
Si5351MultiSynthDebugView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "Si5351 MS0 Debug"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
void refresh();
|
||||
void force_pll_reset();
|
||||
void force_fractional_mode();
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "===MS0 Fractional Debug==="};
|
||||
|
||||
// Clock Control Register 16 (CLK0)
|
||||
Text text_lbl_clk_ctrl{{0, 18, 100, 16}, "CLK0 Ctrl:"};
|
||||
Text text_clk_ctrl{{102, 18, 138, 16}, "---"};
|
||||
|
||||
Text text_lbl_ms_int{{0, 34, 100, 16}, "MS_INT bit:"};
|
||||
Text text_ms_int{{102, 34, 138, 16}, "---"};
|
||||
|
||||
// Raw register values
|
||||
Text text_lbl_raw{{0, 54, 240, 16}, "---Raw Registers (42-49)---"};
|
||||
|
||||
Text text_lbl_r42_43{{0, 70, 80, 16}, "R42-43:"};
|
||||
Text text_r42_43{{82, 70, 158, 16}, "---"};
|
||||
|
||||
Text text_lbl_r44_46{{0, 86, 80, 16}, "R44-46:"};
|
||||
Text text_r44_46{{82, 86, 158, 16}, "---"};
|
||||
|
||||
Text text_lbl_r47_49{{0, 102, 80, 16}, "R47-49:"};
|
||||
Text text_r47_49{{82, 102, 158, 16}, "---"};
|
||||
|
||||
// Decoded values
|
||||
Text text_lbl_decoded{{0, 122, 240, 16}, "---Decoded Values---"};
|
||||
|
||||
Text text_lbl_p1{{0, 138, 48, 16}, "P1:"};
|
||||
Text text_p1{{50, 138, 190, 16}, "---"};
|
||||
|
||||
Text text_lbl_p2{{0, 154, 48, 16}, "P2:"};
|
||||
Text text_p2{{50, 154, 190, 16}, "---"};
|
||||
|
||||
Text text_lbl_p3{{0, 170, 48, 16}, "P3:"};
|
||||
Text text_p3{{50, 170, 190, 16}, "---"};
|
||||
|
||||
Text text_lbl_rdiv{{0, 186, 48, 16}, "R_DIV:"};
|
||||
Text text_rdiv{{50, 186, 190, 16}, "---"};
|
||||
|
||||
// Calculated frequency
|
||||
Text text_lbl_calc{{0, 206, 240, 16}, "---Calculated Output---"};
|
||||
|
||||
Text text_lbl_div{{0, 222, 80, 16}, "MS Div:"};
|
||||
Text text_div{{82, 222, 158, 16}, "---"};
|
||||
|
||||
Text text_lbl_freq{{0, 238, 80, 16}, "CLK0 Out:"};
|
||||
Text text_freq{{82, 238, 158, 16}, "---"};
|
||||
|
||||
// Status
|
||||
Text text_status{{0, 258, 240, 16}, ""};
|
||||
|
||||
Button button_refresh{{2, 280, 56, 24}, "Refresh"};
|
||||
Button button_reset{{62, 280, 56, 24}, "PLL Rst"};
|
||||
Button button_frac{{122, 280, 56, 24}, "Frac"};
|
||||
Button button_done{{182, 280, 56, 24}, "Done"};
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef PRALINE
|
||||
class PralineClockDebugView : public View {
|
||||
public:
|
||||
PralineClockDebugView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "Pro Clock Status"; };
|
||||
|
||||
private:
|
||||
void refresh();
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "=== Pro Clock Dashboard ==="};
|
||||
|
||||
// System Status
|
||||
Text text_lbl_pll{{0, 20, 80, 16}, "PLL Lock:"};
|
||||
Text text_pll_status{{88, 20, 152, 16}, "---"};
|
||||
|
||||
Text text_lbl_afe{{0, 36, 80, 16}, "AFE Rate:"};
|
||||
Text text_afe_rate{{88, 36, 152, 16}, "---"};
|
||||
|
||||
Text text_lbl_n{{0, 52, 80, 16}, "Decim (n):"};
|
||||
Text text_n_val{{88, 52, 152, 16}, "-"};
|
||||
|
||||
// Table Header
|
||||
Text text_header{{0, 72, 240, 16}, "ID mA Mode Phase Stat"};
|
||||
|
||||
// Helper structure to group row widgets for CLK0-CLK5
|
||||
struct ClockRow {
|
||||
Text* id;
|
||||
Text* ma;
|
||||
Text* mode;
|
||||
Text* phase;
|
||||
Text* stat;
|
||||
};
|
||||
std::vector<ClockRow> rows;
|
||||
|
||||
// We define the actual widgets for 6 clocks
|
||||
// Note: Layout uses 16px vertical spacing per row
|
||||
Text t0_id{{0, 88, 24, 16}, "C0:"};
|
||||
Text t0_ma{{32, 88, 24, 16}, "-"};
|
||||
Text t0_mode{{64, 88, 48, 16}, "-"};
|
||||
Text t0_ph{{128, 88, 56, 16}, "-"};
|
||||
Text t0_st{{192, 88, 48, 16}, "-"};
|
||||
Text t1_id{{0, 104, 24, 16}, "C1:"};
|
||||
Text t1_ma{{32, 104, 24, 16}, "-"};
|
||||
Text t1_mode{{64, 104, 48, 16}, "-"};
|
||||
Text t1_ph{{128, 104, 56, 16}, "-"};
|
||||
Text t1_st{{192, 104, 48, 16}, "-"};
|
||||
Text t2_id{{0, 120, 24, 16}, "C2:"};
|
||||
Text t2_ma{{32, 120, 24, 16}, "-"};
|
||||
Text t2_mode{{64, 120, 48, 16}, "-"};
|
||||
Text t2_ph{{128, 120, 56, 16}, "-"};
|
||||
Text t2_st{{192, 120, 48, 16}, "-"};
|
||||
Text t3_id{{0, 136, 24, 16}, "C3:"};
|
||||
Text t3_ma{{32, 136, 24, 16}, "-"};
|
||||
Text t3_mode{{64, 136, 48, 16}, "-"};
|
||||
Text t3_ph{{128, 136, 56, 16}, "-"};
|
||||
Text t3_st{{192, 136, 48, 16}, "-"};
|
||||
Text t4_id{{0, 152, 24, 16}, "C4:"};
|
||||
Text t4_ma{{32, 152, 24, 16}, "-"};
|
||||
Text t4_mode{{64, 152, 48, 16}, "-"};
|
||||
Text t4_ph{{128, 152, 56, 16}, "-"};
|
||||
Text t4_st{{192, 152, 48, 16}, "-"};
|
||||
Text t5_id{{0, 168, 24, 16}, "C5:"};
|
||||
Text t5_ma{{32, 168, 24, 16}, "-"};
|
||||
Text t5_mode{{64, 168, 48, 16}, "-"};
|
||||
Text t5_ph{{128, 168, 56, 16}, "-"};
|
||||
Text t5_st{{192, 168, 48, 16}, "-"};
|
||||
|
||||
Button button_refresh{{8, 260, 100, 24}, "Refresh"};
|
||||
Button button_done{{132, 260, 100, 24}, "Done"};
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
class DebugPeripheralsMenuView : public BtnGridView {
|
||||
|
||||
@@ -46,11 +46,10 @@ bool valid_firmware_file(std::filesystem::path::string_type path) {
|
||||
auto result = firmware_file.open(path.c_str());
|
||||
if (!result.is_valid()) {
|
||||
uint64_t file_size = firmware_file.size();
|
||||
if (portapack::device_type == portapack::DeviceType::DEV_PORTAPACK && file_size > 1 * 1024 * 1024) {
|
||||
// Portapack firmware files must not be larger than 1MB
|
||||
if (file_size > FLASH_ROM_SIZE) {
|
||||
// Firmware file is larger than the flash size for this device
|
||||
return false;
|
||||
}
|
||||
// May need to add a check to portarf and portarf pro too.
|
||||
checksum = 0;
|
||||
for (uint64_t offset = 0; offset < FLASH_ROM_SIZE && offset < file_size; offset += sizeof(read_buffer)) {
|
||||
auto readResult = firmware_file.read(&read_buffer, sizeof(read_buffer));
|
||||
|
||||
@@ -32,8 +32,6 @@
|
||||
#include "untar.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
#include "../../flashsize.h"
|
||||
|
||||
#define FLASH_ROM_SIZE (FLASH_SIZE_MB * 1024 * 1024)
|
||||
#define FLASH_STARTING_ADDRESS 0x00000000
|
||||
#define FLASH_EXPECTED_CHECKSUM 0x00000000
|
||||
|
||||
@@ -304,7 +304,8 @@ class MicTXView : public View {
|
||||
{
|
||||
{" 8k5 ", 0}, // Initial dynamic values when we start Mic App.
|
||||
{" 11k ", 1},
|
||||
{" 16k ", 2},
|
||||
{" 12k5 ", 2},
|
||||
{" 16k ", 3},
|
||||
}};
|
||||
|
||||
NumberField field_squelch{
|
||||
|
||||
@@ -1261,6 +1261,7 @@ size_t ReconView::change_mode(freqman_index_t new_mod) {
|
||||
else
|
||||
v = SPEC_MODULATION;
|
||||
field_mode.set_selected_index(v);
|
||||
return; // Important ! Guru will occur if you don't return when modifying field from within on_change !
|
||||
}
|
||||
last_mode = v;
|
||||
change_mode(v);
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
namespace ui {
|
||||
|
||||
void create_thread(int32_t (*fn)(void*), void* arg, size_t stack_size, int priority) {
|
||||
// TODO: collect memory on terminate, once this is used
|
||||
// TODO: collect memory on terminate, once this is used. This is a HUGE TODO! need to call chThdWait on all of them!
|
||||
chThdCreateFromHeap(NULL, stack_size, priority, fn, arg);
|
||||
}
|
||||
|
||||
|
||||
@@ -334,12 +334,22 @@ void set_rds_data(const uint16_t message_length) {
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_spectrum(const size_t sampling_rate, const size_t trigger) {
|
||||
void set_spectrum(
|
||||
const size_t sampling_rate,
|
||||
const size_t trigger) {
|
||||
const WidebandSpectrumConfigMessage message{
|
||||
sampling_rate, trigger};
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_time_sink(
|
||||
const size_t sampling_rate,
|
||||
const size_t trigger) {
|
||||
const TimeSinkConfigMessage message{
|
||||
sampling_rate, trigger};
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_wefax_config(uint8_t lpm = 120, uint8_t ioc = 0) {
|
||||
const WeFaxRxConfigureMessage message{lpm, ioc};
|
||||
send_message(&message);
|
||||
@@ -473,7 +483,12 @@ void shutdown() {
|
||||
send_message(&message);
|
||||
|
||||
shared_memory.application_queue.reset();
|
||||
|
||||
// Allow time for the shutdown message to be processed and for the baseband
|
||||
// core to stop before starting another image. Otherwise, the M4 may still be
|
||||
// running and cause a crash when the next image is started.
|
||||
#ifdef PRALINE
|
||||
chThdSleepMilliseconds(20);
|
||||
#endif
|
||||
baseband_image_running = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,12 @@ void set_pocsag(int8_t baud_config = -1);
|
||||
void set_adsb();
|
||||
void set_jammer(const bool run, const jammer::JammerType type, const uint32_t speed);
|
||||
void set_rds_data(const uint16_t message_length);
|
||||
void set_spectrum(const size_t sampling_rate, const size_t trigger);
|
||||
void set_spectrum(
|
||||
const size_t sampling_rate,
|
||||
const size_t trigger);
|
||||
void set_time_sink(
|
||||
const size_t sampling_rate,
|
||||
const size_t trigger);
|
||||
void set_siggen_tone(const uint32_t tone);
|
||||
void set_siggen_config(const uint32_t bw, const uint32_t shape, const uint32_t duration);
|
||||
void set_spectrum_painter_config(const uint16_t width, const uint16_t height, bool update, int32_t bw);
|
||||
|
||||
@@ -109,6 +109,15 @@ constexpr si5351::MultisynthFractional si5351_ms_0_20m {
|
||||
};
|
||||
constexpr auto si5351_ms_0_20m_reg = si5351_ms_0_20m.reg(0);
|
||||
*/
|
||||
|
||||
constexpr si5351::MultisynthFractional si5351_ms_0_4m{
|
||||
.f_src = si5351_vco_f, // 800,000,000 Hz
|
||||
.a = 100, // Integer divider 100
|
||||
.b = 0,
|
||||
.c = 1,
|
||||
.r_div = 1 // Final R-divider: 2^1 = 2
|
||||
};
|
||||
|
||||
constexpr si5351::MultisynthFractional si5351_ms_0_8m{
|
||||
.f_src = si5351_vco_f,
|
||||
.a = 50,
|
||||
@@ -237,19 +246,38 @@ constexpr ClockControls si5351c_clock_control_common{{
|
||||
}};
|
||||
|
||||
constexpr ClockControls si5351a_clock_control_common{{
|
||||
#ifndef PRALINE
|
||||
{ClockControl::ClockCurrentDrive::_6mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off},
|
||||
#ifdef PRALINE
|
||||
// CLK0: MAX5864 (ADC) - 4mA, Normal (Standard for Praline sync)
|
||||
{ClockControl::ClockCurrentDrive::_4mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Fractional, ClockControl::ClockPowerDown::Power_On},
|
||||
// CLK1: SCT_CLK (iCE40 FPGA) - 6mA, Inverted (Fixes 30-60Hz Drumming)
|
||||
{ClockControl::ClockCurrentDrive::_6mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Invert, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Fractional, ClockControl::ClockPowerDown::Power_On},
|
||||
// CLK2: LPC43xx MCU - 4mA, Normal (Must be Integer for MCU stability)
|
||||
{ClockControl::ClockCurrentDrive::_4mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_On},
|
||||
// CLK3: CLKOUT SMA Port P1 - 8mA, Normal
|
||||
{ClockControl::ClockCurrentDrive::_8mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_On},
|
||||
// CLK4: MAX2831 reference (40 MHz) - Inverted (Required for mixer lock)
|
||||
{ClockControl::ClockCurrentDrive::_4mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Invert, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_On},
|
||||
// CLK5: RFFC5072 reference (40 MHz) - Inverted (Required for mixer lock)
|
||||
{ClockControl::ClockCurrentDrive::_6mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Invert, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_On},
|
||||
// CLK6: SMA Port P2 - 8mA, Normal
|
||||
{ClockControl::ClockCurrentDrive::_8mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_On},
|
||||
#else
|
||||
{ClockControl::ClockCurrentDrive::_6mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Fractional, ClockControl::ClockPowerDown::Power_Off}, // CLK0: MUST be Fractional for 8 MHz!
|
||||
#endif
|
||||
{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},
|
||||
// CLK4: HackRF r9 - not inverted
|
||||
{ClockControl::ClockCurrentDrive::_2mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off},
|
||||
// CLK5: HackRF r9 - not used
|
||||
{ClockControl::ClockCurrentDrive::_2mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off},
|
||||
// CLK6: Not used
|
||||
{ClockControl::ClockCurrentDrive::_2mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off},
|
||||
#endif
|
||||
// CLK7: Not used
|
||||
{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;
|
||||
}
|
||||
@@ -377,12 +405,35 @@ void ClockManager::init_clock_generator() {
|
||||
#endif
|
||||
|
||||
#ifdef PRALINE
|
||||
/* PRALINE uses Si5351A with:
|
||||
* CLK0 = AFE_CLK (codec/FPGA sample clock)
|
||||
* CLK1 = SCT_CLK (FPGA timing clock at 2x sample rate)
|
||||
* CLK4 = first IF (RFFC5072)
|
||||
* CLK5 = second IF (MAX2831)
|
||||
* Uses PLLA on XTAL only (no CLKIN support).
|
||||
|
||||
/* * Praline HackRF Pro Clock Assignments (800 MHz VCO Configuration)
|
||||
* VCO Frequency: 800,000,000 Hz (Master Reference)
|
||||
* * CLK0: AFE_CLK (MAX5864 Codec & FPGA ADC Interface)
|
||||
* - Initialized to: 4,000,000 Hz (si5351_ms_4m)
|
||||
* - Divider: 100 (Integer), R_DIV: 2 (r_div=1)
|
||||
* - Note: Defines hardware sample rate. Essential for WFM purity.
|
||||
* * CLK1: SCT_CLK (iCE40 FPGA System/Timing Clock)
|
||||
* - Initialized to: 10,000,000 Hz (si5351_ms_10m)
|
||||
* - Divider: 80 (Integer), R_DIV: 1 (r_div=0)
|
||||
* - Note: Timing for SGPIO data bus; scales to 2x SR in wideband modes.
|
||||
* * CLK2: MCU_CLKIN (LPC43xx MCU External Clock Input)
|
||||
* - Initialized to: 10,000,000 Hz (si5351_ms_10m)
|
||||
* - Divider: 80 (Integer), R_DIV: 1 (r_div=0)
|
||||
* - Note: Synchronizes MCU processing to the RF clock tree.
|
||||
* * CLK3: SG_CLK (Switching Regulator/Internal Logic Sync)
|
||||
* - Initialized to: 10,000,000 Hz (si5351_ms_10m)
|
||||
* - Divider: 80 (Integer), R_DIV: 1 (r_div=0)
|
||||
* - Note: Used for internal FPGA logic/gateware synchronization.
|
||||
* * CLK4: P_CLK (Peripheral/Expansion Clock)
|
||||
* - Configured via: si5351c_ms_4_reg
|
||||
* - Note: Routed to expansion headers for external hardware sync.
|
||||
* * CLK5: AUX_CLK (Auxiliary reference for secondary logic)
|
||||
* - Configured via: si5351c_ms_5_reg
|
||||
* - Note: Provides additional timing flexibility for the iCE40 FPGA.
|
||||
* * CLK6/7: Unused / Power-Down
|
||||
* - State: Disabled (si5351a_ms6_7_off_reg)
|
||||
* - Note: Kept OFF to reduce EMI/RFI near the RF front-end.
|
||||
* * CLKOUT: Optional external clock output on the header.
|
||||
*/
|
||||
|
||||
/* Step 1: Write PLL A configuration (800 MHz VCO from 25 MHz XTAL) */
|
||||
@@ -396,25 +447,13 @@ void ClockManager::init_clock_generator() {
|
||||
}
|
||||
|
||||
/* Step 2: Write multisynth configurations using single-byte writes */
|
||||
clock_generator.write_ms_single_byte(0, si5351_ms_0_8m); // MS0 = divider 50, r_div=1 for 8 MHz
|
||||
clock_generator.write_ms_single_byte(1, si5351_ms_16m); // MS1 = divider 50, r_div=0 for 16 MHz
|
||||
|
||||
/* CLK4 and CLK5 - use single-byte writes too */
|
||||
{
|
||||
const auto& ms4_regs = si5351c_ms_4_reg;
|
||||
const uint8_t base_reg = ms4_regs[0];
|
||||
for (size_t i = 1; i < ms4_regs.size(); i++) {
|
||||
clock_generator.write_register(base_reg + i - 1, ms4_regs[i]);
|
||||
}
|
||||
}
|
||||
{
|
||||
const auto& ms5_regs = si5351c_ms_5_reg;
|
||||
const uint8_t base_reg = ms5_regs[0];
|
||||
for (size_t i = 1; i < ms5_regs.size(); i++) {
|
||||
clock_generator.write_register(base_reg + i - 1, ms5_regs[i]);
|
||||
}
|
||||
}
|
||||
clock_generator.write(si5351a_ms6_7_off_reg); // MS6/7 off - short write is OK
|
||||
// These cover all active channels on the Praline board
|
||||
clock_generator.write_ms_single_byte(0, si5351_ms_0_4m); // CLK0: Codec (4 MHz)
|
||||
clock_generator.write_ms_single_byte(1, si5351_ms_10m); // CLK1: FPGA Timing (10 MHz)
|
||||
clock_generator.write_ms_single_byte(2, si5351_ms_10m); // CLK2: MCU Input (10 MHz)
|
||||
clock_generator.write_ms_single_byte(3, si5351_ms_10m); // CLK3: Logic Sync (10 MHz)
|
||||
clock_generator.write_ms_single_byte(4, si5351_ms_40m); // CLK4: First IF (40 MHz)
|
||||
clock_generator.write_ms_single_byte(5, si5351_ms_40m); // CLK5: Second IF (40 MHz)
|
||||
|
||||
/* Step 3: NOW set clock control registers (AFTER multisynths per HackRF reference) */
|
||||
const auto ref_pll = ClockControl::MultiSynthSource::PLLA;
|
||||
@@ -428,7 +467,9 @@ void ClockManager::init_clock_generator() {
|
||||
si5351a_clock_control_common[6].ms_src(ref_pll),
|
||||
si5351a_clock_control_common[7].ms_src(ref_pll),
|
||||
}};
|
||||
clock_generator.set_clock_control(si5351_clock_control);
|
||||
// clock_generator.set_clock_control(si5351_clock_control);
|
||||
// Use single-byte writes instead of multi-byte
|
||||
clock_generator.set_clock_control_single_byte(si5351_clock_control);
|
||||
#else
|
||||
if (hackrf_r9) {
|
||||
const PLLReg pll_reg = (reference.source == ReferenceSource::Xtal)
|
||||
@@ -475,14 +516,8 @@ void ClockManager::init_clock_generator() {
|
||||
: (ref_pll == ClockControl::MultiSynthSource::PLLB)
|
||||
? 0x40
|
||||
: 0x20;
|
||||
#ifndef PRALINE
|
||||
|
||||
while ((clock_generator.device_status() & device_status_mask) != 0);
|
||||
#else
|
||||
uint32_t pll_timeout = 100000;
|
||||
while ((clock_generator.device_status() & device_status_mask) != 0 && pll_timeout > 0) {
|
||||
pll_timeout--;
|
||||
}
|
||||
#endif
|
||||
|
||||
clock_generator.set_clock_control(
|
||||
clock_generator_output_mcu_clkin,
|
||||
@@ -558,11 +593,11 @@ void ClockManager::enable_codec_clocks() {
|
||||
#ifdef PRALINE
|
||||
/* PRALINE: CLK0 (AFE_CLK) for codec/FPGA, CLK1 (SCT_CLK) for FPGA timing.
|
||||
* Reference hackrf_core.c shows PRALINE needs both CLK0 and CLK1. */
|
||||
clock_generator.enable_clock(clock_generator_output_og_codec); /* CLK0 */
|
||||
clock_generator.enable_clock(clock_generator_output_og_cpld); /* CLK1 */
|
||||
clock_generator.enable_clock(clock_generator_output_og_codec); /* CLK0 MAX5864*/
|
||||
clock_generator.enable_clock(clock_generator_output_og_cpld); /* CLK1 iCE40 FPGA*/
|
||||
clock_generator.enable_clock(clock_generator_output_og_sgpio); /* CLK2 LPC43xx*/
|
||||
clock_generator.enable_output_mask(
|
||||
(1U << clock_generator_output_og_codec) |
|
||||
(1U << clock_generator_output_og_cpld));
|
||||
(1U << clock_generator_output_og_codec) | (1U << clock_generator_output_og_cpld) | (1U << clock_generator_output_og_sgpio));
|
||||
#else
|
||||
if (hackrf_r9) {
|
||||
clock_generator.enable_clock(clock_generator_output_r9_sgpio);
|
||||
@@ -590,12 +625,12 @@ void ClockManager::disable_codec_clocks() {
|
||||
* CLKx_DISABLE_STATE.
|
||||
*/
|
||||
#ifdef PRALINE
|
||||
/* PRALINE: CLK0 (AFE_CLK) and CLK1 (SCT_CLK) used for codec/FPGA */
|
||||
/* PRALINE: CLK0 (AFE_CLK), CLK1 (SCT_CLK), and CLK2 MCU used for codec/FPGA */
|
||||
clock_generator.disable_output_mask(
|
||||
(1U << clock_generator_output_og_codec) |
|
||||
(1U << clock_generator_output_og_cpld));
|
||||
(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);
|
||||
#else
|
||||
if (hackrf_r9) {
|
||||
clock_generator.disable_output_mask(1U << clock_generator_output_r9_sgpio);
|
||||
@@ -612,7 +647,7 @@ void ClockManager::disable_codec_clocks() {
|
||||
|
||||
void ClockManager::enable_if_clocks() {
|
||||
#ifdef PRALINE
|
||||
/* PRALINE uses CLK4 (first IF) and CLK5 (second IF) like original HackRF One */
|
||||
/* PRALINE uses CLK5 (first IF) and CLK4 (second IF) */
|
||||
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);
|
||||
@@ -651,23 +686,42 @@ void ClockManager::disable_if_clocks() {
|
||||
|
||||
void ClockManager::set_sampling_frequency(const uint32_t frequency) {
|
||||
#ifdef PRALINE
|
||||
/* PRALINE: CLK0=AFE_CLK runs at sample rate (VCO/divider/2)
|
||||
* CLK1=SCT_CLK runs at 2x sample rate (VCO/divider/1)
|
||||
* Reference: hackrf_core.c sample_rate_frac_set() lines 580-582
|
||||
/*
|
||||
* PRALINE sample rate strategy:
|
||||
* 1. Maximize AFE rate to push Nyquist above MAX2831's 11.6 MHz LPF minimum
|
||||
* 2. Use FPGA decimation to achieve desired output rate
|
||||
* 3. Ensure AFE rate is achievable by Si5351 (clean division from 800 MHz VCO)
|
||||
*/
|
||||
|
||||
/* PRALINE: Match HackRF USB sample_rate_frac_set()
|
||||
* Reference: hackrf_usb radio.c lines 29-91, hackrf_core.c lines 501-685 */
|
||||
constexpr uint32_t MAX_AFE_RATE = 40000000; // Use 40 MHz per GSG reference
|
||||
constexpr uint8_t MAX_N = 5;
|
||||
|
||||
_base_band_frequency = frequency;
|
||||
|
||||
// Set FPGA decimation to 0 (no decimation) for direct passthrough
|
||||
fpga_debug_register_write(2, 0);
|
||||
uint8_t n = 0;
|
||||
uint32_t afe_rate = frequency;
|
||||
|
||||
// Find the largest n where AFE rate stays within limit
|
||||
// Start at n=0 and work up
|
||||
while (n < MAX_N) {
|
||||
uint32_t next_rate = afe_rate << 1;
|
||||
if (next_rate > MAX_AFE_RATE) break;
|
||||
afe_rate = next_rate;
|
||||
n++;
|
||||
}
|
||||
|
||||
_resampling_n = n;
|
||||
|
||||
// Set FPGA RX decimation register
|
||||
fpga_debug_register_write(2, n);
|
||||
radio::invalidate_spi_config();
|
||||
|
||||
// The following was originally from @kitty. Adopting for testing radio.
|
||||
clock_generator.set_ms_frequency(0, frequency * 2, si5351_vco_f, 1); // CLK0: r_div=1 (÷2)
|
||||
clock_generator.set_ms_frequency(1, frequency * 2, si5351_vco_f, 0); // CLK1: r_div=0 (÷1)
|
||||
// Configure Si5351 clocks
|
||||
// CLK0: AFE_CLK (with r_div=1 for ÷2)
|
||||
// CLK1: SCT_CLK (with r_div=0 for ÷1, runs at 2× AFE for FPGA timing)
|
||||
clock_generator.set_ms_frequency(0, afe_rate * 2, si5351_vco_f, 1);
|
||||
clock_generator.set_ms_frequency(1, afe_rate * 2, si5351_vco_f, 0);
|
||||
|
||||
#else
|
||||
/* Codec clock is at sampling frequency, CPLD and SGPIO clocks are at
|
||||
* twice the frequency, and derived from the MS0 synth. So it's only
|
||||
@@ -746,27 +800,37 @@ void ClockManager::start_audio_pll() {
|
||||
* 12MHz * 1024 / 25 = 491.52MHz
|
||||
* MSEL=1024, NSEL=25, PSEL=20
|
||||
*/
|
||||
cgu::pll0audio::ctrl({
|
||||
.pd = 1,
|
||||
.bypass = 0,
|
||||
.directi = 0,
|
||||
.directo = 0,
|
||||
.clken = 0,
|
||||
.frm = 0,
|
||||
.autoblock = 1,
|
||||
.pllfract_req = 0,
|
||||
.sel_ext = 1,
|
||||
.mod_pd = 1,
|
||||
.clk_sel = cgu::CLK_SEL::XTAL,
|
||||
});
|
||||
|
||||
cgu::pll0audio::mdiv({
|
||||
.mdec = 22625UL, // MDEC for MSEL=1024
|
||||
.mdec = 22625UL, // Encoded value for MSEL=1024
|
||||
});
|
||||
cgu::pll0audio::np_div({
|
||||
.pdec = 31, // PSEL=20
|
||||
.ndec = 69, // NDEC for NSEL=25
|
||||
.pdec = 31, // Encoded value for PSEL=20
|
||||
.ndec = 69, // Encoded value for NSEL=25
|
||||
});
|
||||
|
||||
cgu::pll0audio::frac({
|
||||
.pllfract_ctrl = 0,
|
||||
});
|
||||
|
||||
cgu::pll0audio::power_up();
|
||||
|
||||
// Praline Fix: Wait for lock with a safety timeout
|
||||
{
|
||||
uint32_t timeout = 100000;
|
||||
while (!cgu::pll0audio::is_locked() && timeout > 0) {
|
||||
timeout--;
|
||||
}
|
||||
}
|
||||
|
||||
cgu::pll0audio::clock_enable();
|
||||
|
||||
/* Route the 12.288MHz PLL to the Base Audio Clock */
|
||||
// PD = 0 enables the clock; AUTOBLOCK = 1 prevents glitches during clock switching
|
||||
LPC_CGU->BASE_AUDIO_CLK.PD = 0;
|
||||
LPC_CGU->BASE_AUDIO_CLK.AUTOBLOCK = 1;
|
||||
LPC_CGU->BASE_AUDIO_CLK.CLK_SEL = toUType(cgu::CLK_SEL::PLL0AUDIO);
|
||||
|
||||
#else
|
||||
cgu::pll0audio::ctrl({
|
||||
.pd = 1,
|
||||
|
||||
@@ -77,6 +77,8 @@ class ClockManager {
|
||||
void set_reference_ppb(const int32_t ppb);
|
||||
|
||||
#ifdef PRALINE
|
||||
uint8_t get_resampling_n() const { return _resampling_n; }
|
||||
|
||||
// Si5351 diagnostic methods
|
||||
uint8_t si5351_read_status() { return clock_generator.device_status(); }
|
||||
uint8_t si5351_read_register(uint8_t reg) { return clock_generator.read_register(reg); }
|
||||
@@ -112,6 +114,10 @@ class ClockManager {
|
||||
ReferenceSource detect_reference_source();
|
||||
Reference choose_reference();
|
||||
bool loss_of_signal();
|
||||
|
||||
#ifdef PRALINE
|
||||
uint8_t _resampling_n{0}; // Current decimation factor (log2)
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif /*__CLOCK_MANAGER_H__*/
|
||||
|
||||
@@ -256,7 +256,9 @@ ui::Widget* EventDispatcher::touch_widget(ui::Widget* const w, ui::TouchEvent ev
|
||||
if (!w->hidden()) {
|
||||
// To achieve reverse depth ordering (last object drawn is
|
||||
// considered "top"), descend first.
|
||||
for (const auto child : w->children()) {
|
||||
auto& children = w->children();
|
||||
for (auto it = children.rbegin(); it != children.rend(); ++it) { // reverse, bc the lastly added will be "top" if overlaps
|
||||
const auto& child = *it;
|
||||
const auto touched_widget = touch_widget(child, event);
|
||||
if (touched_widget) {
|
||||
return touched_widget;
|
||||
|
||||
+73
-4
@@ -33,6 +33,76 @@ using namespace portapack;
|
||||
|
||||
namespace ui::external_app::acars_rx {
|
||||
|
||||
// ACARS frame field layout (0-based byte offsets):
|
||||
// [0] SOH framing byte (skipped)
|
||||
// [1..7] Aircraft registration (7 chars)
|
||||
// [8] STX framing byte (skipped)
|
||||
// [9..10] Label (2 chars)
|
||||
// [11] Block ID (1 char)
|
||||
// [12..14] Message number (3 chars)
|
||||
// [15..20] Flight ID (6 chars)
|
||||
// [21..N-3] Free-text payload (variable)
|
||||
// [N-2..N-1] CRC-16/CCITT (2 bytes, MSB first, NOT part of payload)
|
||||
//
|
||||
// Minimum valid frame: 21-byte fixed header + 2 CRC bytes = 23 bytes.
|
||||
// (A zero-length payload is legal per spec; we require at least 23 bytes.)
|
||||
static constexpr std::string::size_type kAcarsCrcLen = 2;
|
||||
static constexpr std::string::size_type kAcarsHeaderLen = 21;
|
||||
static constexpr std::string::size_type kAcarsMinLen = kAcarsHeaderLen + kAcarsCrcLen;
|
||||
|
||||
// CRC-16/CCITT: poly 0x1021, init 0x0000, no reflection, no final XOR.
|
||||
// This is the variant used by ACARS (same as XMODEM CRC).
|
||||
static uint16_t acars_crc16(const std::string& data, std::string::size_type len) {
|
||||
uint16_t crc = 0x0000;
|
||||
for (std::string::size_type i = 0; i < len; ++i) {
|
||||
crc ^= static_cast<uint16_t>(static_cast<uint8_t>(data[i])) << 8;
|
||||
for (int bit = 0; bit < 8; ++bit) {
|
||||
if (crc & 0x8000)
|
||||
crc = static_cast<uint16_t>((crc << 1) ^ 0x1021);
|
||||
else
|
||||
crc = static_cast<uint16_t>(crc << 1);
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
AcarsDecoded acars_decode(const std::string& raw) {
|
||||
AcarsDecoded result;
|
||||
if (raw.size() < kAcarsMinLen) {
|
||||
result.txt = "ACARS message too short (" + std::to_string(raw.size()) +
|
||||
" bytes, need " + std::to_string(kAcarsMinLen) + ")";
|
||||
return result;
|
||||
}
|
||||
|
||||
// Verify CRC: computed over everything except the last 2 bytes,
|
||||
// then compared against those 2 bytes (MSB first).
|
||||
const std::string::size_type payload_len = raw.size() - kAcarsCrcLen;
|
||||
const uint16_t computed = acars_crc16(raw, payload_len);
|
||||
const uint16_t received = (static_cast<uint16_t>(static_cast<uint8_t>(raw[raw.size() - 2])) << 8) |
|
||||
static_cast<uint16_t>(static_cast<uint8_t>(raw[raw.size() - 1]));
|
||||
result.crc_ok = (computed == received);
|
||||
|
||||
result.reg = raw.substr(1, 7);
|
||||
result.label = raw.substr(9, 2);
|
||||
result.block_id = raw[11];
|
||||
result.msg_num = raw.substr(12, 3);
|
||||
result.flight_id = raw.substr(15, 6);
|
||||
// Payload sits between end of fixed header and the 2 trailing CRC bytes.
|
||||
if (payload_len > kAcarsHeaderLen)
|
||||
result.txt = raw.substr(kAcarsHeaderLen, payload_len - kAcarsHeaderLen);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string acars_format(const AcarsDecoded& msg) {
|
||||
return std::string("ACARS Decoded Result\nCRC: ") + (msg.crc_ok ? "OK" : "FAIL") +
|
||||
"\nRegistration: " + msg.reg +
|
||||
"\nLabel: " + msg.label +
|
||||
"\nBlockID: " + msg.block_id +
|
||||
"\nMsgNum: " + msg.msg_num +
|
||||
"\nFlightID: " + msg.flight_id +
|
||||
"\nMessage: " + msg.txt;
|
||||
}
|
||||
|
||||
void ACARSLogger::log_str(std::string msg) {
|
||||
log_file.write_entry(msg);
|
||||
}
|
||||
@@ -77,17 +147,16 @@ void ACARSAppView::focus() {
|
||||
|
||||
void ACARSAppView::on_packet(const ACARSPacketMessage* packet) {
|
||||
std::string console_info;
|
||||
|
||||
if (packet->state == 255) {
|
||||
// got a packet, parse it, and display
|
||||
rtc::RTC datetime;
|
||||
rtc_time::now(datetime);
|
||||
// todo parity error recovery
|
||||
console_info = to_string_datetime(datetime, HMS);
|
||||
console_info += ": ";
|
||||
console_info += packet->message;
|
||||
std::string message{packet->message, packet->message + packet->msg_len};
|
||||
AcarsDecoded decoded = acars_decode(message);
|
||||
console_info += acars_format(decoded);
|
||||
console.writeln(console_info);
|
||||
// Log raw data whatever it contains
|
||||
if (logger && logging)
|
||||
logger->log_str(console_info);
|
||||
} else {
|
||||
|
||||
+21
-1
@@ -33,6 +33,26 @@
|
||||
|
||||
namespace ui::external_app::acars_rx {
|
||||
|
||||
// Decoded ACARS message fields extracted from a raw frame.
|
||||
// CRC-16/CCITT (poly 0x1021, init 0x0000) is verified against the two
|
||||
// trailing bytes of the raw frame; crc_ok reflects that result.
|
||||
struct AcarsDecoded {
|
||||
bool crc_ok{false};
|
||||
std::string reg{};
|
||||
std::string label{};
|
||||
std::string flight_id{};
|
||||
std::string msg_num{};
|
||||
char block_id{'\0'};
|
||||
std::string txt{};
|
||||
};
|
||||
|
||||
// Decode a raw ACARS frame: verify CRC-16/CCITT and extract fixed-offset fields.
|
||||
// Returns a partially-filled AcarsDecoded (txt error only) if the frame is too short.
|
||||
AcarsDecoded acars_decode(const std::string& raw);
|
||||
|
||||
// Format a decoded ACARS message for display or logging.
|
||||
std::string acars_format(const AcarsDecoded& msg);
|
||||
|
||||
class ACARSLogger {
|
||||
public:
|
||||
Optional<File::Error> append(const std::filesystem::path& filename) {
|
||||
@@ -106,4 +126,4 @@ class ACARSAppView : public View {
|
||||
|
||||
} // namespace ui::external_app::acars_rx
|
||||
|
||||
#endif /*__ACARS_APP_H__*/
|
||||
#endif /*__ACARS_APP_H__*/
|
||||
|
||||
+83
-83
@@ -1,83 +1,83 @@
|
||||
/*
|
||||
* 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 "ui.hpp"
|
||||
#include "acars_app.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "external_app.hpp"
|
||||
|
||||
namespace ui::external_app::acars_rx {
|
||||
void initialize_app(ui::NavigationView& nav) {
|
||||
nav.push<ACARSAppView>();
|
||||
}
|
||||
} // namespace ui::external_app::acars_rx
|
||||
|
||||
extern "C" {
|
||||
|
||||
__attribute__((section(".external_app.app_acars_rx.application_information"), used)) application_information_t _application_information_acars_rx = {
|
||||
/*.memory_location = */ (uint8_t*)0x00000000,
|
||||
/*.externalAppEntry = */ ui::external_app::acars_rx::initialize_app,
|
||||
/*.header_version = */ CURRENT_HEADER_VERSION,
|
||||
/*.app_version = */ VERSION_MD5,
|
||||
|
||||
/*.app_name = */ "ACARS",
|
||||
/*.bitmap_data = */ {
|
||||
0x80,
|
||||
0x01,
|
||||
0xC0,
|
||||
0x03,
|
||||
0xC0,
|
||||
0x03,
|
||||
0xC0,
|
||||
0x03,
|
||||
0xC0,
|
||||
0x03,
|
||||
0xE0,
|
||||
0x07,
|
||||
0xF8,
|
||||
0x1F,
|
||||
0xFE,
|
||||
0x7F,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xC0,
|
||||
0x03,
|
||||
0xC0,
|
||||
0x03,
|
||||
0xC0,
|
||||
0x03,
|
||||
0xE0,
|
||||
0x07,
|
||||
0xF0,
|
||||
0x0F,
|
||||
0xF8,
|
||||
0x1F,
|
||||
},
|
||||
/*.icon_color = */ ui::Color::orange().v,
|
||||
/*.menu_location = */ app_location_t::RX,
|
||||
/*.desired_menu_position = */ -1,
|
||||
|
||||
/*.m4_app_tag = portapack::spi_flash::image_tag_acars */ {'P', 'A', 'C', 'A'},
|
||||
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
|
||||
};
|
||||
}
|
||||
/*
|
||||
* 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 "ui.hpp"
|
||||
#include "acars_app.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "external_app.hpp"
|
||||
|
||||
namespace ui::external_app::acars_rx {
|
||||
void initialize_app(ui::NavigationView& nav) {
|
||||
nav.push<ACARSAppView>();
|
||||
}
|
||||
} // namespace ui::external_app::acars_rx
|
||||
|
||||
extern "C" {
|
||||
|
||||
__attribute__((section(".external_app.app_acars_rx.application_information"), used)) application_information_t _application_information_acars_rx = {
|
||||
/*.memory_location = */ (uint8_t*)0x00000000,
|
||||
/*.externalAppEntry = */ ui::external_app::acars_rx::initialize_app,
|
||||
/*.header_version = */ CURRENT_HEADER_VERSION,
|
||||
/*.app_version = */ VERSION_MD5,
|
||||
|
||||
/*.app_name = */ "ACARS",
|
||||
/*.bitmap_data = */ {
|
||||
0x80,
|
||||
0x01,
|
||||
0xC0,
|
||||
0x03,
|
||||
0xC0,
|
||||
0x03,
|
||||
0xC0,
|
||||
0x03,
|
||||
0xC0,
|
||||
0x03,
|
||||
0xE0,
|
||||
0x07,
|
||||
0xF8,
|
||||
0x1F,
|
||||
0xFE,
|
||||
0x7F,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xC0,
|
||||
0x03,
|
||||
0xC0,
|
||||
0x03,
|
||||
0xC0,
|
||||
0x03,
|
||||
0xE0,
|
||||
0x07,
|
||||
0xF0,
|
||||
0x0F,
|
||||
0xF8,
|
||||
0x1F,
|
||||
},
|
||||
/*.icon_color = */ ui::Color::orange().v,
|
||||
/*.menu_location = */ app_location_t::RX,
|
||||
/*.desired_menu_position = */ -1,
|
||||
|
||||
/*.m4_app_tag = portapack::spi_flash::image_tag_acars */ {'P', 'A', 'C', 'A'},
|
||||
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
|
||||
};
|
||||
}
|
||||
|
||||
+1
-1
@@ -339,7 +339,7 @@ void AdultToysView::randomizeMac() {
|
||||
}
|
||||
|
||||
void AdultToysView::randomChn() {
|
||||
channel_number = 37 + std::rand() % (39 - 37 + 1);
|
||||
channel_number = 37 + rand() % (39 - 37 + 1);
|
||||
field_frequency.set_value(get_freq_by_channel_number(channel_number));
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ void BlackjackView::paint(Painter& painter) {
|
||||
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
init_deck();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -132,7 +132,7 @@ void BLESpamView::reset() {
|
||||
}
|
||||
|
||||
void BLESpamView::randomChn() {
|
||||
channel_number = 37 + std::rand() % (39 - 37 + 1);
|
||||
channel_number = 37 + rand() % (39 - 37 + 1);
|
||||
field_frequency.set_value(get_freq_by_channel_number(channel_number));
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -655,7 +655,7 @@ void BreakoutView::paint(Painter& painter) {
|
||||
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
init_game();
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -125,7 +125,7 @@ void DinoGameView::paint(Painter& painter) {
|
||||
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
init_game();
|
||||
}
|
||||
}
|
||||
@@ -789,8 +789,8 @@ void DinoGameView::draw_current_score() {
|
||||
|
||||
void DinoGameView::draw_high_score() {
|
||||
auto style = *ui::Theme::getInstance()->fg_light;
|
||||
painter.fill_rectangle({UI_POS_X_RIGHT(90), 28, 90, 18}, Color::black());
|
||||
painter.draw_string({UI_POS_X_RIGHT(90), 30}, style, "HI " + score_to_string(highScore));
|
||||
painter.fill_rectangle({UI_POS_X_RIGHT(10), 28, 90, 18}, Color::black());
|
||||
painter.draw_string({UI_POS_X_RIGHT(10), 30}, style, "HI " + score_to_string(highScore));
|
||||
}
|
||||
|
||||
void DinoGameView::jump() {
|
||||
|
||||
+15
-15
@@ -204,11 +204,11 @@ void spawn_entity(uint8_t type, uint8_t x, uint8_t y) {
|
||||
|
||||
void spawn_random_entity(uint8_t type) {
|
||||
if (num_entities >= MAX_ENTITIES) return;
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
uint8_t spawn_x, spawn_y;
|
||||
do {
|
||||
spawn_x = std::rand() % LEVEL_WIDTH;
|
||||
spawn_y = std::rand() % LEVEL_HEIGHT;
|
||||
spawn_x = rand() % LEVEL_WIDTH;
|
||||
spawn_y = rand() % LEVEL_HEIGHT;
|
||||
} while (get_block_at(spawn_x, spawn_y) == 0xF ||
|
||||
(spawn_x == (uint8_t)player.pos.x && spawn_y == (uint8_t)player.pos.y));
|
||||
|
||||
@@ -227,9 +227,9 @@ void remove_entity(uint8_t index) {
|
||||
bool spawned = false;
|
||||
|
||||
while (!spawned && attempts < 50) {
|
||||
std::srand(LPC_RTC->CTIME0 + attempts);
|
||||
uint8_t spawn_x = std::rand() % LEVEL_WIDTH;
|
||||
uint8_t spawn_y = std::rand() % LEVEL_HEIGHT;
|
||||
srand(LPC_RTC->CTIME0 + attempts);
|
||||
uint8_t spawn_x = rand() % LEVEL_WIDTH;
|
||||
uint8_t spawn_y = rand() % LEVEL_HEIGHT;
|
||||
|
||||
int16_t dx = (int16_t)spawn_x - (int16_t)player.pos.x;
|
||||
int16_t dy = (int16_t)spawn_y - (int16_t)player.pos.y;
|
||||
@@ -270,9 +270,9 @@ void initialize_level() {
|
||||
uint8_t attempts = 0;
|
||||
|
||||
while (initial_enemies < 2 && num_entities < MAX_ENTITIES && attempts < 50) {
|
||||
std::srand(LPC_RTC->CTIME0 + attempts);
|
||||
int8_t offset_x = (std::rand() % 11) - 5;
|
||||
int8_t offset_y = (std::rand() % 11) - 5;
|
||||
srand(LPC_RTC->CTIME0 + attempts);
|
||||
int8_t offset_x = (rand() % 11) - 5;
|
||||
int8_t offset_y = (rand() % 11) - 5;
|
||||
|
||||
if (abs(offset_x) < 3 && abs(offset_y) < 3) {
|
||||
attempts++;
|
||||
@@ -307,10 +307,10 @@ void initialize_level() {
|
||||
|
||||
attempts = 0;
|
||||
while (num_entities < MIN_ENTITIES && attempts < 100) {
|
||||
std::srand(LPC_RTC->CTIME0 + attempts + 100);
|
||||
srand(LPC_RTC->CTIME0 + attempts + 100);
|
||||
|
||||
uint8_t spawn_x = std::rand() % LEVEL_WIDTH;
|
||||
uint8_t spawn_y = std::rand() % LEVEL_HEIGHT;
|
||||
uint8_t spawn_x = rand() % LEVEL_WIDTH;
|
||||
uint8_t spawn_y = rand() % LEVEL_HEIGHT;
|
||||
|
||||
int16_t dx = (int16_t)spawn_x - (int16_t)player.pos.x;
|
||||
int16_t dy = (int16_t)spawn_y - (int16_t)player.pos.y;
|
||||
@@ -1045,7 +1045,7 @@ void DoomView::on_show() {
|
||||
void DoomView::paint(Painter& painter) {
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
scene = 0;
|
||||
up = down = left = right = fired = false;
|
||||
jogging = view_height = 0;
|
||||
@@ -1081,7 +1081,7 @@ void DoomView::paint(Painter& painter) {
|
||||
int hud_y = RENDER_HEIGHT + 5;
|
||||
painter.draw_string({5, hud_y}, style_yellow, "Health: " + std::to_string(player.health));
|
||||
painter.draw_string({UI_POS_X_CENTER(15), hud_y}, style_red, "Kills: " + std::to_string(kills));
|
||||
painter.draw_string({UI_POS_X_RIGHT(80), hud_y}, style_blue, "Ammo: " + std::to_string(player.ammo));
|
||||
painter.draw_string({UI_POS_X_RIGHT(10), hud_y}, style_blue, "Ammo: " + std::to_string(player.ammo));
|
||||
|
||||
prev_velocity_moving = (player.velocity != 0);
|
||||
needs_redraw = false;
|
||||
@@ -1113,7 +1113,7 @@ void DoomView::paint(Painter& painter) {
|
||||
int hud_y = RENDER_HEIGHT + 5;
|
||||
painter.draw_string({5, hud_y}, style_yellow, "Health: " + std::to_string(player.health));
|
||||
painter.draw_string({UI_POS_X_CENTER(15), hud_y}, style_red, "Kills: " + std::to_string(kills));
|
||||
painter.draw_string({UI_POS_X_RIGHT(80), hud_y}, style_blue, "Ammo: " + std::to_string(player.ammo));
|
||||
painter.draw_string({UI_POS_X_RIGHT(10), hud_y}, style_blue, "Ammo: " + std::to_string(player.ammo));
|
||||
|
||||
needs_gun_redraw = false;
|
||||
}
|
||||
|
||||
+14
-4
@@ -113,8 +113,8 @@ set(EXTCPPSRC
|
||||
external/random_password/sha512.cpp
|
||||
|
||||
#acars
|
||||
#external/acars_rx/main.cpp
|
||||
#external/acars_rx/acars_app.cpp
|
||||
external/acars_rx/main.cpp
|
||||
external/acars_rx/acars_app.cpp
|
||||
|
||||
#wefax_rx 192 bytes
|
||||
external/wefax_rx/main.cpp
|
||||
@@ -308,6 +308,14 @@ set(EXTCPPSRC
|
||||
external/rtty_tx/main.cpp
|
||||
external/rtty_tx/ui_rtty_tx.cpp
|
||||
external/rtty_tx/baudot.cpp
|
||||
|
||||
#pocsag_tx
|
||||
external/pocsag_tx/main.cpp
|
||||
external/pocsag_tx/ui_pocsag_tx.cpp
|
||||
|
||||
#time_sink
|
||||
external/time_sink/main.cpp
|
||||
external/time_sink/ui_time_sink.cpp
|
||||
)
|
||||
|
||||
set(EXTAPPLIST
|
||||
@@ -337,7 +345,7 @@ set(EXTAPPLIST
|
||||
sstvtx
|
||||
sstvrx
|
||||
random_password
|
||||
# acars_rx --not working
|
||||
acars_rx
|
||||
wefax_rx
|
||||
noaaapt_rx
|
||||
shoppingcart_lock
|
||||
@@ -382,9 +390,11 @@ set(EXTAPPLIST
|
||||
siggen
|
||||
morse_radio
|
||||
morseradiotx
|
||||
keeloqtx
|
||||
keeloqtx
|
||||
rtty_rx
|
||||
rtty_tx
|
||||
pocsag_tx
|
||||
time_sink
|
||||
)
|
||||
|
||||
# sdusb has type conflicts with PRALINE (HackRF Pro) - add only for non-PRALINE builds
|
||||
|
||||
+15
@@ -98,6 +98,9 @@ MEMORY
|
||||
ram_external_app_rtty_rx (rwx) : org = 0xADF90000, len = 32k
|
||||
ram_external_app_rtty_tx (rwx) : org = 0xADFA0000, len = 32k
|
||||
ram_external_app_tpmstx (rwx) : org = 0xADFB0000, len = 32k
|
||||
ram_external_app_pocsag_tx (rwx) : org = 0xADFC0000, len = 32k
|
||||
ram_external_app_time_sink (rwx) : org = 0xADFD0000, len = 32k
|
||||
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
@@ -552,5 +555,17 @@ SECTIONS
|
||||
KEEP(*(.external_app.app_rtty_tx.application_information));
|
||||
*(*ui*external_app*rtty_tx*);
|
||||
} > ram_external_app_rtty_tx
|
||||
|
||||
.external_app_pocsag_tx : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_pocsag_tx.application_information));
|
||||
*(*ui*external_app*pocsag_tx*);
|
||||
} > ram_external_app_pocsag_tx
|
||||
|
||||
.external_app_time_sink : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_time_sink.application_information));
|
||||
*(*ui*external_app*time_sink*);
|
||||
} > ram_external_app_time_sink
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ Game2048View::Game2048View(NavigationView& nav)
|
||||
|
||||
void Game2048View::on_show() {
|
||||
if (!initialized) {
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
reset_game();
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
@@ -137,6 +137,7 @@ LevelView::LevelView(NavigationView& nav)
|
||||
else
|
||||
v = SPEC_MODULATION;
|
||||
field_mode.set_selected_index(v);
|
||||
return; // Important ! Guru will occur if you don't return when modifying field from within on_change !
|
||||
}
|
||||
last_mode = v;
|
||||
change_mode(v);
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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 "ui.hpp"
|
||||
#include "ui_pocsag_tx.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "external_app.hpp"
|
||||
|
||||
namespace ui::external_app::pocsag_tx {
|
||||
void initialize_app(ui::NavigationView& nav) {
|
||||
nav.push<POCSAGTXView>();
|
||||
}
|
||||
} // namespace ui::external_app::pocsag_tx
|
||||
|
||||
extern "C" {
|
||||
|
||||
__attribute__((section(".external_app.app_pocsag_tx.application_information"), used)) application_information_t _application_information_pocsag_tx = {
|
||||
/*.memory_location = */ (uint8_t*)0x00000000,
|
||||
/*.externalAppEntry = */ ui::external_app::pocsag_tx::initialize_app,
|
||||
/*.header_version = */ CURRENT_HEADER_VERSION,
|
||||
/*.app_version = */ VERSION_MD5,
|
||||
|
||||
/*.app_name = */ "POCSG TX",
|
||||
/*.bitmap_data = */ {
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0xFC,
|
||||
0x3F,
|
||||
0xFE,
|
||||
0x7F,
|
||||
0x02,
|
||||
0x40,
|
||||
0xBA,
|
||||
0x45,
|
||||
0x02,
|
||||
0x40,
|
||||
0xFE,
|
||||
0x7F,
|
||||
0xFE,
|
||||
0x7F,
|
||||
0x92,
|
||||
0x7C,
|
||||
0x92,
|
||||
0x7C,
|
||||
0xFC,
|
||||
0x3F,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
},
|
||||
/*.icon_color = */ ui::Color::green().v,
|
||||
/*.menu_location = */ app_location_t::TX,
|
||||
/*.desired_menu_position = */ -1,
|
||||
|
||||
/*.m4_app_tag = portapack::spi_flash::image_tag_fsktx */ {'P', 'F', 'S', 'K'},
|
||||
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
|
||||
};
|
||||
}
|
||||
+3
-3
@@ -31,7 +31,7 @@
|
||||
using namespace portapack;
|
||||
using namespace pocsag;
|
||||
|
||||
namespace ui {
|
||||
namespace ui::external_app::pocsag_tx {
|
||||
|
||||
#define MAX_POCSAG_LENGTH 80
|
||||
|
||||
@@ -159,7 +159,7 @@ void POCSAGTXView::on_set_text(NavigationView& nav) {
|
||||
POCSAGTXView::POCSAGTXView(
|
||||
NavigationView& nav)
|
||||
: nav_(nav) {
|
||||
baseband::run_image(portapack::spi_flash::image_tag_fsktx);
|
||||
baseband::run_prepared_image(portapack::memory::map::m4_code.base());
|
||||
|
||||
add_children({&labels,
|
||||
&options_bitrate,
|
||||
@@ -205,4 +205,4 @@ POCSAGTXView::POCSAGTXView(
|
||||
};
|
||||
}
|
||||
|
||||
} /* namespace ui */
|
||||
} /* namespace ui::external_app::pocsag_tx */
|
||||
+2
-2
@@ -37,7 +37,7 @@
|
||||
|
||||
using namespace pocsag;
|
||||
|
||||
namespace ui {
|
||||
namespace ui::external_app::pocsag_tx {
|
||||
|
||||
class POCSAGTXView : public View {
|
||||
public:
|
||||
@@ -155,6 +155,6 @@ class POCSAGTXView : public View {
|
||||
}};
|
||||
};
|
||||
|
||||
} /* namespace ui */
|
||||
} /* namespace ui::external_app::pocsag_tx */
|
||||
|
||||
#endif /*__POCSAG_TX_H__*/
|
||||
@@ -239,10 +239,10 @@ void RandomPasswordView::on_freqchg(int64_t freq) {
|
||||
}
|
||||
|
||||
void RandomPasswordView::set_random_freq() {
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
// this is only for seed to visit random freq, the radio is still real random
|
||||
|
||||
auto random_freq = 100000000 + (std::rand() % 900000000); // 100mhz to 1ghz
|
||||
auto random_freq = 100000000 + (rand() % 900000000); // 100mhz to 1ghz
|
||||
receiver_model.set_target_frequency(random_freq);
|
||||
field_frequency.set_value(random_freq);
|
||||
}
|
||||
@@ -297,12 +297,12 @@ void RandomPasswordView::new_password() {
|
||||
/// roll worker
|
||||
for (int i = 0; i < password_length * 2; i += 2) {
|
||||
unsigned int seed = seeds_deque[i];
|
||||
std::srand(seed);
|
||||
srand(seed);
|
||||
uint8_t rollnum = (uint8_t)(seeds_deque[i + 1] % 128);
|
||||
uint8_t nu = 0;
|
||||
for (uint8_t o = 0; o < rollnum; ++o) nu = std::rand();
|
||||
for (uint8_t o = 0; o < rollnum; ++o) nu = rand();
|
||||
nu++;
|
||||
char c = charset[std::rand() % charset.length()];
|
||||
char c = charset[rand() % charset.length()];
|
||||
initial_password += c;
|
||||
}
|
||||
|
||||
|
||||
@@ -461,6 +461,7 @@ ScannerView::ScannerView(
|
||||
else
|
||||
v = WFM_MODULATION;
|
||||
field_mode.set_selected_index(v);
|
||||
return; // Important ! Guru will occur if you don't return when modifying field from within on_change !
|
||||
}
|
||||
last_mode = v;
|
||||
receiver_model.disable();
|
||||
|
||||
+4
-1
@@ -36,8 +36,11 @@ WipeSDView::WipeSDView(NavigationView& nav)
|
||||
}
|
||||
|
||||
WipeSDView::~WipeSDView() {
|
||||
if (thread)
|
||||
if (thread) {
|
||||
chThdTerminate(thread);
|
||||
chThdWait(thread);
|
||||
thread = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void WipeSDView::focus() {
|
||||
|
||||
+1
-1
@@ -221,7 +221,7 @@ void SnakeView::paint(Painter& painter) {
|
||||
(void)painter;
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
init_game();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -605,7 +605,7 @@ void pause_game() {
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::srand(GenerateRandomSeed());
|
||||
srand(GenerateRandomSeed());
|
||||
Init();
|
||||
ShowLevelMenu();
|
||||
joystick.attach(&ReadJoystickForLevel, 0.3);
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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 "ui.hpp"
|
||||
#include "ui_time_sink.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "external_app.hpp"
|
||||
|
||||
namespace ui::external_app::time_sink {
|
||||
void initialize_app(ui::NavigationView& nav) {
|
||||
nav.push<TimeSinkView>();
|
||||
}
|
||||
} // namespace ui::external_app::time_sink
|
||||
extern "C" {
|
||||
|
||||
__attribute__((section(".external_app.app_time_sink.application_information"), used)) application_information_t _application_information_time_sink = {
|
||||
/*.memory_location = */ (uint8_t*)0x00000000,
|
||||
/*.externalAppEntry = */ ui::external_app::time_sink::initialize_app,
|
||||
/*.header_version = */ CURRENT_HEADER_VERSION,
|
||||
/*.app_version = */ VERSION_MD5,
|
||||
|
||||
/*.app_name = */ "Time Sink",
|
||||
/*.bitmap_data = */ {
|
||||
0x18,
|
||||
0x00,
|
||||
0x24,
|
||||
0x00,
|
||||
0x42,
|
||||
0x00,
|
||||
0x42,
|
||||
0x00,
|
||||
0x42,
|
||||
0x00,
|
||||
0x42,
|
||||
0x00,
|
||||
0x81,
|
||||
0x00,
|
||||
0xAB,
|
||||
0x6A,
|
||||
0x80,
|
||||
0x40,
|
||||
0x00,
|
||||
0x21,
|
||||
0x00,
|
||||
0x21,
|
||||
0x00,
|
||||
0x21,
|
||||
0x00,
|
||||
0x21,
|
||||
0x00,
|
||||
0x12,
|
||||
0x00,
|
||||
0x0C,
|
||||
0x00,
|
||||
0x00,
|
||||
},
|
||||
/*.icon_color = */ ui::Color::cyan().v,
|
||||
/*.menu_location = */ app_location_t::RX,
|
||||
/*.desired_menu_position = */ -1,
|
||||
|
||||
/*.m4_app_tag = portapack::spi_flash::image_tag_none */ {'P', 'T', 'S', 'K'},
|
||||
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,352 @@
|
||||
/*
|
||||
* Copyleft zxkmm (>) 2026
|
||||
*
|
||||
* 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_time_sink.hpp"
|
||||
|
||||
#include "baseband_api.hpp"
|
||||
#include "portapack.hpp"
|
||||
#include "ui_spectrum.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using namespace portapack;
|
||||
|
||||
namespace ui::external_app::time_sink {
|
||||
|
||||
TimeSinkWaveformWidget::TimeSinkWaveformWidget(
|
||||
Rect parent_rect,
|
||||
const int16_t* data,
|
||||
size_t length,
|
||||
Color color)
|
||||
: Widget{parent_rect},
|
||||
data_{data},
|
||||
length_{length},
|
||||
color_{color} {
|
||||
reset_cache();
|
||||
}
|
||||
|
||||
void TimeSinkWaveformWidget::set_parent_rect(const Rect new_parent_rect) {
|
||||
Widget::set_parent_rect(new_parent_rect);
|
||||
reset_cache();
|
||||
}
|
||||
|
||||
void TimeSinkWaveformWidget::on_show() {
|
||||
reset_cache();
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
void TimeSinkWaveformWidget::reset_cache() {
|
||||
history_count_ = 0;
|
||||
history_head_ = 0;
|
||||
needs_clear_ = true;
|
||||
}
|
||||
|
||||
void TimeSinkWaveformWidget::set_persistence_frames(uint8_t frames) {
|
||||
const auto clamped = static_cast<uint8_t>(std::clamp<size_t>(
|
||||
frames,
|
||||
1,
|
||||
max_persistence_frames));
|
||||
if (clamped != persistence_frames_) {
|
||||
persistence_frames_ = clamped;
|
||||
reset_cache();
|
||||
set_dirty();
|
||||
}
|
||||
}
|
||||
|
||||
Coord TimeSinkWaveformWidget::sample_to_y(const Rect& r, int16_t sample) const {
|
||||
const int32_t y_center = r.top() + (r.height() / 2);
|
||||
const int32_t y_span = std::max<int32_t>(1, r.height() - 1);
|
||||
const int32_t y = y_center - (static_cast<int32_t>(sample) * y_span) / 65536;
|
||||
return static_cast<Coord>(std::clamp<int32_t>(y, r.top(), r.bottom() - 1));
|
||||
}
|
||||
|
||||
void TimeSinkWaveformWidget::paint(Painter& painter) {
|
||||
const auto r = screen_rect();
|
||||
const auto background = Theme::getInstance()->bg_darkest->background;
|
||||
|
||||
if (!r || !data_ || !length_) {
|
||||
if (needs_clear_) {
|
||||
painter.fill_rectangle_unrolled8(r, background);
|
||||
needs_clear_ = false;
|
||||
}
|
||||
history_count_ = 0;
|
||||
history_head_ = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t columns = std::min<size_t>({
|
||||
length_,
|
||||
max_columns,
|
||||
static_cast<size_t>(r.width()),
|
||||
});
|
||||
if (!columns) {
|
||||
history_count_ = 0;
|
||||
history_head_ = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (needs_clear_) {
|
||||
painter.fill_rectangle_unrolled8(r, background);
|
||||
needs_clear_ = false;
|
||||
history_count_ = 0;
|
||||
history_head_ = 0;
|
||||
}
|
||||
|
||||
for (size_t x = 0; x < columns; ++x) {
|
||||
const size_t src_index = (x * length_) / columns;
|
||||
current_y_[x] = sample_to_y(r, data_[src_index]);
|
||||
}
|
||||
|
||||
// Draw first, then erase stale pixels so the trace never disappears mid-refresh.
|
||||
for (size_t x = 0; x < columns; ++x) {
|
||||
display.draw_pixel(
|
||||
{static_cast<Coord>(r.left() + x), current_y_[x]},
|
||||
color_);
|
||||
}
|
||||
|
||||
if (history_count_ >= persistence_frames_) {
|
||||
const size_t expired_slot = history_head_;
|
||||
|
||||
for (size_t x = 0; x < columns; ++x) {
|
||||
const auto expired_y = history_y_[expired_slot][x];
|
||||
bool keep = (expired_y == current_y_[x]);
|
||||
|
||||
if (!keep) {
|
||||
for (size_t i = 1; i < history_count_; ++i) {
|
||||
const size_t slot = (history_head_ + i) % max_persistence_frames;
|
||||
if (history_y_[slot][x] == expired_y) {
|
||||
keep = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!keep) {
|
||||
display.draw_pixel(
|
||||
{static_cast<Coord>(r.left() + x), expired_y},
|
||||
background);
|
||||
}
|
||||
}
|
||||
|
||||
history_head_ = (history_head_ + 1) % max_persistence_frames;
|
||||
--history_count_;
|
||||
}
|
||||
|
||||
const size_t tail_slot = (history_head_ + history_count_) % max_persistence_frames;
|
||||
std::copy_n(current_y_.begin(), columns, history_y_[tail_slot].begin());
|
||||
++history_count_;
|
||||
}
|
||||
|
||||
TimeSinkView::TimeSinkView(NavigationView& nav)
|
||||
: nav_(nav) {
|
||||
baseband::run_prepared_image(portapack::memory::map::m4_code.base());
|
||||
|
||||
add_children({
|
||||
&labels,
|
||||
&field_frequency,
|
||||
&field_frequency_step,
|
||||
&field_rf_amp,
|
||||
&field_lna,
|
||||
&field_vga,
|
||||
&options_sample_rate,
|
||||
&field_trigger,
|
||||
&options_persistence,
|
||||
&options_trigger_mode,
|
||||
&field_trigger_level,
|
||||
&waveform,
|
||||
});
|
||||
|
||||
field_frequency_step.set_by_value(receiver_model.frequency_step());
|
||||
field_frequency_step.on_change = [this](size_t, OptionsField::value_t v) {
|
||||
receiver_model.set_frequency_step(v);
|
||||
field_frequency.set_step(v);
|
||||
};
|
||||
|
||||
options_sample_rate.set_by_nearest_value(sampling_rate);
|
||||
sampling_rate = options_sample_rate.selected_index_value();
|
||||
options_sample_rate.on_change = [this](size_t, OptionsField::value_t v) {
|
||||
sampling_rate = v;
|
||||
apply_spectrum_config();
|
||||
};
|
||||
|
||||
field_trigger.set_value(trigger);
|
||||
field_trigger.on_change = [this](int32_t v) {
|
||||
trigger = static_cast<uint8_t>(v);
|
||||
apply_spectrum_config();
|
||||
};
|
||||
|
||||
options_persistence.set_by_nearest_value(persistence_frames);
|
||||
persistence_frames = options_persistence.selected_index_value();
|
||||
waveform.set_persistence_frames(persistence_frames);
|
||||
options_persistence.on_change = [this](size_t, OptionsField::value_t v) {
|
||||
persistence_frames = static_cast<uint8_t>(v);
|
||||
waveform.set_persistence_frames(persistence_frames);
|
||||
};
|
||||
|
||||
options_trigger_mode.set_by_nearest_value(trigger_mode);
|
||||
trigger_mode = static_cast<uint8_t>(options_trigger_mode.selected_index_value());
|
||||
options_trigger_mode.on_change = [this](size_t, OptionsField::value_t v) {
|
||||
trigger_mode = static_cast<uint8_t>(v);
|
||||
trigger_lock_valid = false;
|
||||
};
|
||||
|
||||
field_trigger_level.set_value(trigger_level);
|
||||
field_trigger_level.on_change = [this](int32_t v) {
|
||||
trigger_level = v;
|
||||
trigger_lock_valid = false;
|
||||
};
|
||||
|
||||
receiver_model.set_squelch_level(0);
|
||||
receiver_model.enable();
|
||||
apply_spectrum_config();
|
||||
}
|
||||
|
||||
TimeSinkView::~TimeSinkView() {
|
||||
receiver_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
void TimeSinkView::focus() {
|
||||
field_frequency.focus();
|
||||
}
|
||||
|
||||
void TimeSinkView::on_show() {
|
||||
baseband::spectrum_streaming_start();
|
||||
}
|
||||
|
||||
void TimeSinkView::on_hide() {
|
||||
baseband::spectrum_streaming_stop();
|
||||
}
|
||||
|
||||
void TimeSinkView::set_parent_rect(const Rect new_parent_rect) {
|
||||
View::set_parent_rect(new_parent_rect);
|
||||
waveform.set_parent_rect({0, header_height, new_parent_rect.width(), new_parent_rect.height() - header_height});
|
||||
}
|
||||
|
||||
void TimeSinkView::apply_spectrum_config() {
|
||||
receiver_model.set_sampling_rate(sampling_rate);
|
||||
receiver_model.set_baseband_bandwidth(filter_bandwidth_for_sampling_rate(sampling_rate));
|
||||
|
||||
baseband::set_time_sink(
|
||||
sampling_rate,
|
||||
trigger);
|
||||
}
|
||||
|
||||
size_t TimeSinkView::find_stable_trigger_index(const ChannelSpectrum& spectrum) {
|
||||
if (spectrum.db.size() < 2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
TriggerMode mode = TriggerMode::Rising;
|
||||
switch (trigger_mode) {
|
||||
case static_cast<uint8_t>(TriggerMode::Off):
|
||||
mode = TriggerMode::Off;
|
||||
break;
|
||||
case static_cast<uint8_t>(TriggerMode::Rising):
|
||||
mode = TriggerMode::Rising;
|
||||
break;
|
||||
case static_cast<uint8_t>(TriggerMode::Falling):
|
||||
mode = TriggerMode::Falling;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (mode == TriggerMode::Off) {
|
||||
trigger_lock_valid = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
constexpr int32_t hysteresis = 2;
|
||||
const int32_t threshold = std::clamp<int32_t>(
|
||||
128 + trigger_level,
|
||||
hysteresis,
|
||||
255 - hysteresis);
|
||||
const size_t center = spectrum.db.size() / 2;
|
||||
const size_t reference_index = trigger_lock_valid ? trigger_lock_index : center;
|
||||
|
||||
bool found = false;
|
||||
size_t best_index = 0;
|
||||
size_t best_distance = spectrum.db.size();
|
||||
const auto circular_distance = [count = spectrum.db.size()](size_t a, size_t b) -> size_t {
|
||||
const size_t linear =
|
||||
(a > b) ? (a - b) : (b - a);
|
||||
return std::min(linear, count - linear);
|
||||
};
|
||||
|
||||
for (size_t i = 1; i < spectrum.db.size(); ++i) {
|
||||
const int32_t prev = spectrum.db[i - 1];
|
||||
const int32_t curr = spectrum.db[i];
|
||||
|
||||
bool crossing = false;
|
||||
if (mode == TriggerMode::Rising) {
|
||||
crossing =
|
||||
(prev <= (threshold - hysteresis)) &&
|
||||
(curr >= (threshold + hysteresis));
|
||||
} else {
|
||||
crossing =
|
||||
(prev >= (threshold + hysteresis)) &&
|
||||
(curr <= (threshold - hysteresis));
|
||||
}
|
||||
|
||||
if (!crossing) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const size_t distance = circular_distance(i, reference_index);
|
||||
if (!found || (distance < best_distance)) {
|
||||
found = true;
|
||||
best_index = i;
|
||||
best_distance = distance;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
trigger_lock_index = best_index;
|
||||
trigger_lock_valid = true;
|
||||
return best_index;
|
||||
}
|
||||
|
||||
return trigger_lock_valid ? trigger_lock_index : 0;
|
||||
}
|
||||
|
||||
void TimeSinkView::on_channel_spectrum(const ChannelSpectrum& spectrum) {
|
||||
const size_t trigger_index = find_stable_trigger_index(spectrum);
|
||||
const size_t source_count = spectrum.db.size();
|
||||
const size_t window_size = source_count;
|
||||
|
||||
for (size_t x = 0; x < waveform_points; x++) {
|
||||
const size_t offset = (x * window_size) / waveform_points;
|
||||
const size_t src_index =
|
||||
(trigger_index + offset) % source_count;
|
||||
const int32_t centered = static_cast<int32_t>(spectrum.db[src_index]) - 128;
|
||||
const int32_t scaled = centered * 256;
|
||||
waveform_buffer[x] = static_cast<int16_t>(std::clamp<int32_t>(scaled, -32768, 32767));
|
||||
}
|
||||
|
||||
waveform.set_dirty();
|
||||
}
|
||||
|
||||
void TimeSinkView::on_freqchg(int64_t freq) {
|
||||
field_frequency.set_value(freq);
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::time_sink
|
||||
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
* Copyleft zxkmm (>) 2026
|
||||
*
|
||||
* 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_TIME_SINK_APP_H__
|
||||
#define __UI_TIME_SINK_APP_H__
|
||||
|
||||
#include "app_settings.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "message.hpp"
|
||||
#include "radio_state.hpp"
|
||||
#include "ui.hpp"
|
||||
#include "ui_freq_field.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "ui_receiver.hpp"
|
||||
#include "ui_widget.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace ui::external_app::time_sink {
|
||||
|
||||
constexpr size_t time_sink_waveform_points = 240;
|
||||
|
||||
class TimeSinkWaveformWidget : public Widget {
|
||||
public:
|
||||
TimeSinkWaveformWidget(Rect parent_rect, const int16_t* data, size_t length, Color color);
|
||||
TimeSinkWaveformWidget(const TimeSinkWaveformWidget&) = delete;
|
||||
TimeSinkWaveformWidget(TimeSinkWaveformWidget&&) = delete;
|
||||
TimeSinkWaveformWidget& operator=(const TimeSinkWaveformWidget&) = delete;
|
||||
TimeSinkWaveformWidget& operator=(TimeSinkWaveformWidget&&) = delete;
|
||||
|
||||
void set_parent_rect(const Rect new_parent_rect) override;
|
||||
void on_show() override;
|
||||
void paint(Painter& painter) override;
|
||||
void set_persistence_frames(uint8_t frames);
|
||||
|
||||
private:
|
||||
static constexpr size_t max_columns = time_sink_waveform_points;
|
||||
static constexpr size_t max_persistence_frames = 16; // this is sad that we cant have 32 histories in ext app due to memory constraints
|
||||
|
||||
void reset_cache();
|
||||
Coord sample_to_y(const Rect& r, int16_t sample) const;
|
||||
|
||||
const int16_t* data_;
|
||||
size_t length_;
|
||||
Color color_;
|
||||
std::array<Coord, max_columns> current_y_{};
|
||||
std::array<std::array<Coord, max_columns>, max_persistence_frames> history_y_{};
|
||||
size_t history_count_{0};
|
||||
size_t history_head_{0};
|
||||
uint8_t persistence_frames_{1};
|
||||
bool needs_clear_{true};
|
||||
};
|
||||
|
||||
class TimeSinkView : public View {
|
||||
public:
|
||||
TimeSinkView(NavigationView& nav);
|
||||
~TimeSinkView();
|
||||
|
||||
TimeSinkView(const TimeSinkView&) = delete;
|
||||
TimeSinkView(TimeSinkView&&) = delete;
|
||||
TimeSinkView& operator=(const TimeSinkView&) = delete;
|
||||
TimeSinkView& operator=(TimeSinkView&&) = delete;
|
||||
|
||||
std::string title() const override { return "Time Sink"; };
|
||||
void focus() override;
|
||||
void on_show() override;
|
||||
void on_hide() override;
|
||||
void set_parent_rect(const Rect new_parent_rect) override;
|
||||
|
||||
private:
|
||||
enum class TriggerMode : uint8_t {
|
||||
Off = 0,
|
||||
Rising = 1,
|
||||
Falling = 2,
|
||||
};
|
||||
|
||||
static constexpr Dim header_height = 3 * 16;
|
||||
static constexpr size_t waveform_points = time_sink_waveform_points;
|
||||
|
||||
NavigationView& nav_;
|
||||
RxRadioState radio_state_{
|
||||
433'920'000,
|
||||
1'750'000,
|
||||
2'000'000,
|
||||
ReceiverModel::Mode::SpectrumAnalysis};
|
||||
|
||||
uint32_t sampling_rate{2'000'000};
|
||||
uint8_t trigger{0};
|
||||
uint8_t persistence_frames{1};
|
||||
uint8_t trigger_mode{static_cast<uint8_t>(TriggerMode::Rising)};
|
||||
int32_t trigger_level{0};
|
||||
size_t trigger_lock_index{0};
|
||||
bool trigger_lock_valid{false};
|
||||
app_settings::SettingsManager settings_{
|
||||
"rx_time_sink"sv,
|
||||
app_settings::Mode::RX,
|
||||
{
|
||||
{"sampling_rate"sv, &sampling_rate},
|
||||
{"trigger"sv, &trigger},
|
||||
{"persistence_frames"sv, &persistence_frames},
|
||||
{"trigger_mode"sv, &trigger_mode},
|
||||
{"trigger_level"sv, &trigger_level},
|
||||
}};
|
||||
|
||||
int16_t waveform_buffer[waveform_points]{0};
|
||||
ChannelSpectrumFIFO* fifo = nullptr;
|
||||
|
||||
Labels labels{
|
||||
{{UI_POS_X(0), UI_POS_Y(1)}, "SR:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(11), UI_POS_Y(1)}, "DEC:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(2)}, "PST:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(9), UI_POS_Y(2)}, "TRM:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(19), UI_POS_Y(2)}, "LVL:", Theme::getInstance()->fg_light->foreground},
|
||||
};
|
||||
|
||||
RxFrequencyField field_frequency{
|
||||
{UI_POS_X(0), UI_POS_Y(0)},
|
||||
nav_};
|
||||
|
||||
FrequencyStepView field_frequency_step{
|
||||
{10 * 8, UI_POS_Y(0)}};
|
||||
|
||||
RFAmpField field_rf_amp{
|
||||
{16 * 8, UI_POS_Y(0)}};
|
||||
|
||||
LNAGainField field_lna{
|
||||
{18 * 8, UI_POS_Y(0)}};
|
||||
|
||||
VGAGainField field_vga{
|
||||
{21 * 8, UI_POS_Y(0)}};
|
||||
|
||||
OptionsField options_sample_rate{
|
||||
{UI_POS_X(3), UI_POS_Y(1)},
|
||||
6,
|
||||
{
|
||||
{"1.0M ", 1'000'000},
|
||||
{"2.0M ", 2'000'000},
|
||||
{"5.0M ", 5'000'000},
|
||||
{"10.0M ", 10'000'000},
|
||||
{"20.0M ", 20'000'000},
|
||||
}};
|
||||
|
||||
NumberField field_trigger{
|
||||
{UI_POS_X(17), UI_POS_Y(1)},
|
||||
3,
|
||||
{0, 128},
|
||||
1,
|
||||
' '};
|
||||
|
||||
OptionsField options_persistence{
|
||||
{UI_POS_X(3), UI_POS_Y(2)},
|
||||
3,
|
||||
{
|
||||
{"1 ", 1},
|
||||
{"2 ", 2},
|
||||
{"4 ", 4},
|
||||
{"8 ", 8},
|
||||
{"16 ", 16},
|
||||
}};
|
||||
|
||||
OptionsField options_trigger_mode{
|
||||
{UI_POS_X(13), UI_POS_Y(2)},
|
||||
4,
|
||||
{
|
||||
{"Off ", static_cast<int32_t>(TriggerMode::Off)},
|
||||
{"Rise", static_cast<int32_t>(TriggerMode::Rising)},
|
||||
{"Fall", static_cast<int32_t>(TriggerMode::Falling)},
|
||||
}};
|
||||
|
||||
NumberField field_trigger_level{
|
||||
{UI_POS_X(23), UI_POS_Y(2)},
|
||||
4,
|
||||
{-127, 127},
|
||||
1,
|
||||
' '};
|
||||
|
||||
TimeSinkWaveformWidget waveform{
|
||||
{0, header_height, screen_width, screen_height - header_height},
|
||||
waveform_buffer,
|
||||
waveform_points,
|
||||
Theme::getInstance()->fg_light->foreground};
|
||||
|
||||
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 spectrum{};
|
||||
bool has_spectrum = false;
|
||||
while (fifo->out(spectrum)) {
|
||||
has_spectrum = true;
|
||||
}
|
||||
if (has_spectrum) {
|
||||
this->on_channel_spectrum(spectrum);
|
||||
}
|
||||
}
|
||||
}};
|
||||
|
||||
MessageHandlerRegistration message_handler_freqchg{
|
||||
Message::ID::FreqChangeCommand,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const FreqChangeCommandMessage*>(p);
|
||||
this->on_freqchg(message->freq);
|
||||
}};
|
||||
|
||||
void apply_spectrum_config();
|
||||
size_t find_stable_trigger_index(const ChannelSpectrum& spectrum);
|
||||
void on_channel_spectrum(const ChannelSpectrum& spectrum);
|
||||
void on_freqchg(int64_t freq);
|
||||
};
|
||||
|
||||
} // namespace ui::external_app::time_sink
|
||||
|
||||
#endif // __UI_TIME_SINK_APP_H__
|
||||
@@ -161,7 +161,7 @@ Optional<File::Error> File::sync() {
|
||||
|
||||
File::Result<std::string> File::read_file(const std::filesystem::path& filename) {
|
||||
constexpr size_t buffer_size = 0x80;
|
||||
char* buffer[buffer_size];
|
||||
char buffer[buffer_size];
|
||||
|
||||
File f;
|
||||
auto error = f.open(filename);
|
||||
@@ -205,6 +205,7 @@ static std::filesystem::path find_last_ordinal_match(
|
||||
const std::filesystem::path& pattern,
|
||||
pattern_range range) {
|
||||
auto last_match = std::filesystem::path();
|
||||
if (range.start == std::string::npos || range.end == std::string::npos || range.start > range.end) return last_match;
|
||||
auto can_increment = [range](const auto& path) {
|
||||
for (auto i = range.start; i <= range.end; ++i)
|
||||
if (!isdigit(path.native()[i]))
|
||||
@@ -230,7 +231,7 @@ static std::filesystem::path increment_filename_ordinal(
|
||||
const std::filesystem::path& path,
|
||||
pattern_range range) {
|
||||
auto name = path.filename().native();
|
||||
|
||||
if (range.start == std::string::npos || range.end == std::string::npos || range.start > range.end) return {name};
|
||||
for (auto i = range.end; i >= range.start; --i) {
|
||||
auto& c = name[i];
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ class BufferLineReader {
|
||||
std::strncpy(&it.line_data_[offset], buf, len);
|
||||
offset += len;
|
||||
|
||||
if (len < buf_size)
|
||||
if (len < buf_size || buf[len - 1] == '\n')
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,8 @@ options_t freqman_bandwidths[6] = {
|
||||
// NFM
|
||||
{"8k5", 0},
|
||||
{"11k", 1},
|
||||
{"16k", 2},
|
||||
{"12k5", 2},
|
||||
{"16k", 3},
|
||||
},
|
||||
{
|
||||
// WFM
|
||||
|
||||
@@ -84,8 +84,7 @@ void Gradient::step(int16_t index, int16_t r, int16_t g, int16_t b) {
|
||||
int16_t new_r = prev_r * y + r * x;
|
||||
int16_t new_g = prev_g * y + g * x;
|
||||
int16_t new_b = prev_b * y + b * x;
|
||||
|
||||
lut[i] = ui::Color(new_r, new_g, new_b);
|
||||
if (i <= 255) lut[i] = ui::Color(new_r, new_g, new_b);
|
||||
}
|
||||
|
||||
prev_index = index;
|
||||
|
||||
@@ -38,20 +38,21 @@ using namespace hackrf::one;
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
// Global debug tracking for MAX2831
|
||||
struct max2831_debug_t {
|
||||
uint32_t requested_freq_mhz;
|
||||
uint32_t calculated_n;
|
||||
uint32_t calculated_frac;
|
||||
bool set_frequency_called;
|
||||
bool frequency_valid;
|
||||
};
|
||||
extern "C" max2831_debug_t max2831_debug_info = {0, 0, 0, false, false};
|
||||
|
||||
namespace max2831 {
|
||||
|
||||
using namespace max283x;
|
||||
|
||||
static MAX2831Info max2831_info = {0, 0, 0, false, false};
|
||||
|
||||
MAX2831Info get_max2831_info() {
|
||||
return {
|
||||
max2831_info.requested_freq_mhz,
|
||||
max2831_info.calculated_n,
|
||||
max2831_info.calculated_frac,
|
||||
max2831_info.set_frequency_called,
|
||||
max2831_info.frequency_valid};
|
||||
}
|
||||
|
||||
/*
|
||||
* MAX2831 uses 9-bit SPI transfers.
|
||||
* An 18-bit word is sent as two 9-bit transfers:
|
||||
@@ -342,9 +343,6 @@ void MAX2831::set_lpf_rf_bandwidth_rx(const uint32_t bandwidth_minimum) {
|
||||
_desired_lpf_bw = bandwidth_minimum;
|
||||
#ifdef PRALINE
|
||||
uint32_t actual_bw = bandwidth_minimum;
|
||||
if (actual_bw < 22000000) {
|
||||
actual_bw = 22000000; // Never go below 15 MHz, set by choosing 22.6 MHz bandwidth
|
||||
}
|
||||
|
||||
_desired_lpf_bw = actual_bw;
|
||||
if (_mode == Mode::Receive || _mode == Mode::Rx_Calibration) {
|
||||
@@ -378,20 +376,20 @@ bool MAX2831::set_frequency(const rf::Frequency lo_frequency) {
|
||||
*/
|
||||
|
||||
/* MAX2831 supports 2.3-2.6 GHz */
|
||||
// if (lo_frequency < 2300000000ULL || lo_frequency > 2600000000ULL) {
|
||||
// if (lo_frequency < MAX2831_MIN_LO_FREQUENCY_HZ || lo_frequency > MAX2831_MAX_LO_FREQUENCY_HZ) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
bool valid = (lo_frequency >= 2300000000ULL && lo_frequency <= 2600000000ULL);
|
||||
bool valid = (lo_frequency >= MAX2831_MIN_LO_FREQUENCY_HZ && lo_frequency <= MAX2831_MAX_LO_FREQUENCY_HZ);
|
||||
|
||||
// TRACK REQUEST IMMEDIATELY
|
||||
max2831_debug_info.requested_freq_mhz = lo_frequency / 1000000;
|
||||
max2831_debug_info.set_frequency_called = true;
|
||||
max2831_debug_info.frequency_valid = valid;
|
||||
max2831_info.requested_freq_mhz = lo_frequency / 1000000;
|
||||
max2831_info.set_frequency_called = true;
|
||||
max2831_info.frequency_valid = valid;
|
||||
|
||||
if (!valid) {
|
||||
max2831_debug_info.calculated_n = 0;
|
||||
max2831_debug_info.calculated_frac = 0;
|
||||
max2831_info.calculated_n = 0;
|
||||
max2831_info.calculated_frac = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -414,8 +412,8 @@ bool MAX2831::set_frequency(const rf::Frequency lo_frequency) {
|
||||
}
|
||||
|
||||
// TRACK CALCULATED VALUES
|
||||
max2831_debug_info.calculated_n = div_int;
|
||||
max2831_debug_info.calculated_frac = div_frac;
|
||||
max2831_info.calculated_n = div_int;
|
||||
max2831_info.calculated_frac = div_frac;
|
||||
|
||||
/* Write order matters - matches GSG reference */
|
||||
/* REG 3: SYN_INT (bits 7:0) and SYN_FRAC_LO (bits 13:8) */
|
||||
|
||||
@@ -38,6 +38,21 @@ namespace max2831 {
|
||||
|
||||
using namespace max283x;
|
||||
|
||||
// Global debug tracking for MAX2831
|
||||
struct MAX2831Info {
|
||||
uint32_t requested_freq_mhz;
|
||||
uint32_t calculated_n;
|
||||
uint32_t calculated_frac;
|
||||
bool set_frequency_called;
|
||||
bool frequency_valid;
|
||||
};
|
||||
|
||||
MAX2831Info get_max2831_info();
|
||||
|
||||
/* minumum and maximum lo_frequencies supported by max2831 */
|
||||
constexpr rf::Frequency MAX2831_MIN_LO_FREQUENCY_HZ = 2300000000LL;
|
||||
constexpr rf::Frequency MAX2831_MAX_LO_FREQUENCY_HZ = 2600000000LL;
|
||||
|
||||
/* MAX2831 has 16 registers, each containing 14 bits of data */
|
||||
constexpr size_t reg_count = 16;
|
||||
|
||||
|
||||
@@ -65,7 +65,11 @@ constexpr halrtcnt_t ticks_during_reset = (base_m4_clk_f * seconds_during_reset
|
||||
constexpr float seconds_after_reset = 5.0e-6;
|
||||
constexpr halrtcnt_t ticks_after_reset = (base_m4_clk_f * seconds_after_reset + 1);
|
||||
|
||||
#ifdef PRALINE
|
||||
constexpr rf::Frequency reference_frequency = 40000000ULL;
|
||||
#else
|
||||
constexpr auto reference_frequency = rffc5072_reference_f;
|
||||
#endif
|
||||
|
||||
namespace vco {
|
||||
|
||||
@@ -114,31 +118,9 @@ constexpr size_t divider_min = 1U << divider_log2_min;
|
||||
constexpr size_t divider_max = 1U << divider_log2_max;
|
||||
|
||||
constexpr size_t divider_log2(const rf::Frequency vco_frequency) {
|
||||
#ifdef PRALINE
|
||||
// PRALINE FIX: Avoid N register overflow (9-bit max = 511)
|
||||
// With 40 MHz reference:
|
||||
// - For VCO=5400 MHz, presc=÷2: N = (5400×2)/40 = 270 ✓
|
||||
// - For VCO=5400 MHz, presc=÷4: N = (5400×4)/40 = 540 ✗ OVERFLOW!
|
||||
//
|
||||
// Maximum safe VCO for ÷4 prescaler:
|
||||
// N_max = 511, so VCO_max = (511 × 40) / 4 = 5110 MHz
|
||||
//
|
||||
// Use ÷4 only if VCO < 5110 MHz AND VCO > 3200 MHz
|
||||
// Use ÷2 for VCO >= 5110 MHz to avoid overflow
|
||||
|
||||
constexpr rf::Frequency overflow_threshold = 5110000000ULL; // Max VCO for ÷4
|
||||
constexpr rf::Frequency min_presc4_freq = 3200000000ULL; // Min VCO for ÷4
|
||||
|
||||
if ((vco_frequency > min_presc4_freq) && (vco_frequency < overflow_threshold)) {
|
||||
return divider_log2_max; // ÷4 prescaler
|
||||
} else {
|
||||
return divider_log2_min; // ÷2 prescaler
|
||||
}
|
||||
#else
|
||||
return (vco_frequency > (prescaler::divider_min * prescaler::max_frequency))
|
||||
? prescaler::divider_log2_max
|
||||
: prescaler::divider_log2_min;
|
||||
#endif
|
||||
}
|
||||
|
||||
} /* namespace prescaler */
|
||||
@@ -161,11 +143,7 @@ struct SynthConfig {
|
||||
|
||||
const size_t prescaler_divider_log2 = prescaler::divider_log2(vco_frequency);
|
||||
|
||||
#ifndef PRALINE
|
||||
const uint64_t prescaled_lo_q24 = vco_frequency << (24 - prescaler_divider_log2);
|
||||
#else
|
||||
const uint64_t prescaled_lo_q24 = vco_frequency << (24 + prescaler_divider_log2);
|
||||
#endif
|
||||
const uint64_t n_divider_q24 = prescaled_lo_q24 / reference_frequency;
|
||||
|
||||
#ifdef PRALINE
|
||||
@@ -197,11 +175,9 @@ struct SynthConfig {
|
||||
*/
|
||||
|
||||
void RFFC507x::init() {
|
||||
#ifndef PRALINE
|
||||
gpio_rffc5072_resetx.set();
|
||||
gpio_rffc5072_resetx.output();
|
||||
reset();
|
||||
#endif
|
||||
|
||||
_bus.init();
|
||||
|
||||
@@ -213,12 +189,10 @@ void RFFC507x::reset() {
|
||||
/* TODO: Is RESETB pin ignored if sdi_ctrl.sipin=1? Programming guide
|
||||
* description of sdi_ctrl.sipin suggests the pin is not ignored.
|
||||
*/
|
||||
#ifndef PRALINE
|
||||
gpio_rffc5072_resetx.clear();
|
||||
halPolledDelay(ticks_during_reset);
|
||||
gpio_rffc5072_resetx.set();
|
||||
halPolledDelay(ticks_after_reset);
|
||||
#endif
|
||||
}
|
||||
|
||||
void RFFC507x::flush() {
|
||||
@@ -291,6 +265,7 @@ void RFFC507x::set_frequency(const rf::Frequency lo_frequency) {
|
||||
const SynthConfig synth_config = SynthConfig::calculate(lo_frequency);
|
||||
|
||||
#ifdef PRALINE
|
||||
|
||||
// Calculate VCO frequency from LO frequency and divider
|
||||
const size_t lo_divider = 1U << synth_config.lo_divider_log2; // 2^lodiv_log2
|
||||
const rf::Frequency vco_freq = lo_frequency * lo_divider;
|
||||
|
||||
@@ -373,6 +373,16 @@ class Si5351 {
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef PRALINE
|
||||
void set_clock_control_single_byte(const ClockControls& clock_control) {
|
||||
_clock_control = clock_control;
|
||||
// Use single-byte writes for PRALINE (multi-byte I2C fails)
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
write_register(Register::CLKControl_Base + i, _clock_control[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool plla_loss_of_signal() {
|
||||
return (device_status() >> 5) & 1;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,8 @@ struct header_t {
|
||||
struct tags_t {
|
||||
constexpr tags_t(
|
||||
const std::string& title_str) {
|
||||
strcpy(title, title_str.c_str());
|
||||
strncpy(title, title_str.c_str(), sizeof(title) - 1);
|
||||
title[sizeof(title) - 1] = '\0';
|
||||
cksize = sizeof(tags_t) - 8;
|
||||
}
|
||||
|
||||
|
||||
Executable → Regular
+18
-1
@@ -91,7 +91,7 @@ Continuous (Fox-oring)
|
||||
// TODO: ADS-B draw trajectory + GPS coordinates + scale, and playback
|
||||
// TODO: RDS multiple groups (sequence)
|
||||
// TODO: Use ModalMessageView confirmation for TX ?
|
||||
// TODO: Use msgpack for settings, lists... on sd card
|
||||
// TODO: Use msgpack for settings, lists... on sd card. and make it safe, since now it has a lot of oob potentials
|
||||
|
||||
// Multimon-style stuff:
|
||||
// TODO: DMR detector
|
||||
@@ -145,6 +145,21 @@ Continuous (Fox-oring)
|
||||
rffc507x::RFFC507x first_if;
|
||||
ui::SystemView* system_view_ptr;
|
||||
|
||||
static uint32_t random_seed_state = 123456789;
|
||||
extern "C" int rand(void) {
|
||||
random_seed_state ^= random_seed_state << 13;
|
||||
random_seed_state ^= random_seed_state >> 17;
|
||||
random_seed_state ^= random_seed_state << 5;
|
||||
return (int)(random_seed_state & 0x7FFFFFFF);
|
||||
}
|
||||
extern "C" void srand(unsigned int seed) {
|
||||
if (seed == 0) {
|
||||
random_seed_state = 123456789;
|
||||
} else {
|
||||
random_seed_state = seed;
|
||||
}
|
||||
}
|
||||
|
||||
static void event_loop() {
|
||||
static ui::Context context;
|
||||
static ui::SystemView system_view{
|
||||
@@ -166,7 +181,9 @@ static void event_loop() {
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
#ifndef PRALINE // Do not perform quick set up of GP01_RFF507X = 1 for PRALINE
|
||||
first_if.init(); /* To avoid initial short Ant_DC_Bias pulse ,we need quick set up GP01_RFF507X =1 */
|
||||
#endif
|
||||
|
||||
if (config_mode_should_enter()) {
|
||||
config_mode_clear();
|
||||
|
||||
@@ -56,11 +56,13 @@ using asahi_kasei::ak4951::AK4951;
|
||||
#include "i2cdevmanager.hpp"
|
||||
#include "battery.hpp"
|
||||
|
||||
#ifndef PRALINE
|
||||
extern "C" {
|
||||
#include "platform_detect.h"
|
||||
}
|
||||
|
||||
#ifdef PRALINE
|
||||
#include "fpga_bridge.h"
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace portapack {
|
||||
|
||||
@@ -549,18 +551,22 @@ static void initialize_boot_splash_screen() {
|
||||
*/
|
||||
|
||||
init_status_t init() {
|
||||
#ifdef PRALINE
|
||||
/* 1. HOLD FPGA IN RESET (Active Low) */
|
||||
// P5_2 is GPIO2[11] (FPGA CRESET)
|
||||
palClearPad(GPIO2, 11);
|
||||
#endif
|
||||
|
||||
set_idivc_base_clocks(cgu::CLK_SEL::IDIVC);
|
||||
|
||||
i2c0.start(i2c_config_boot_clock);
|
||||
|
||||
chThdSleepMilliseconds(100);
|
||||
|
||||
#ifndef PRALINE
|
||||
detect_hardware_platform();
|
||||
finalize_detect_hardware_platform();
|
||||
|
||||
chThdSleepMilliseconds(100);
|
||||
#endif
|
||||
|
||||
configure_pins_portapack();
|
||||
|
||||
@@ -622,6 +628,27 @@ init_status_t init() {
|
||||
clock_manager.enable_if_clocks();
|
||||
clock_manager.enable_codec_clocks();
|
||||
|
||||
#ifdef PRALINE
|
||||
chThdSleepMilliseconds(20);
|
||||
|
||||
// This function returns LD_SUCCESS (0) if the FPGA confirms the bitstream
|
||||
// Call fpga_bridge_init and continue boot regardless of result
|
||||
// (Watchdog was resetting device when we halted with while(1))
|
||||
int load_result = fpga_bridge_init();
|
||||
(void)load_result; // Ignore result for now, just let boot continue
|
||||
|
||||
/* RELEASE FPGA RESET */
|
||||
// FPGA wakes up and latches the stable 40MHz CLK1
|
||||
// P5_2 is GPIO2[11] (FPGA CRESET)
|
||||
palSetPad(GPIO2, 11);
|
||||
|
||||
// Allow FPGA and related logic a brief stabilization period without busy-waiting
|
||||
chThdSleepMilliseconds(10);
|
||||
|
||||
// Keep LEDs off after FPGA load
|
||||
LPC_GPIO->SET[2] = (1 << 1) | (1 << 2) | (1 << 8);
|
||||
#endif
|
||||
|
||||
radio::init();
|
||||
|
||||
sdcStart(&SDCD1, nullptr);
|
||||
@@ -641,9 +668,6 @@ init_status_t init() {
|
||||
|
||||
return_code = init_status_t::INIT_HACKRF_CPLD_FAILED;
|
||||
}
|
||||
#else
|
||||
// HackRF Pro (PRALINE) uses FPGA - already loaded in board.cpp __early_init()
|
||||
// via fpga_bridge_init(), so nothing to do here
|
||||
#endif
|
||||
|
||||
if (lcd_fast_setup)
|
||||
|
||||
@@ -32,10 +32,11 @@
|
||||
extern "C" {
|
||||
#include "fpga_bridge.h"
|
||||
}
|
||||
#else
|
||||
#include "baseband_cpld.hpp"
|
||||
#endif
|
||||
|
||||
#include "max5864.hpp"
|
||||
#include "baseband_cpld.hpp"
|
||||
|
||||
#include "tuning.hpp"
|
||||
|
||||
@@ -78,6 +79,15 @@ static constexpr SPIConfig ssp_config_max283x = {
|
||||
CR0_CLOCKRATE(ssp_scr(ssp1_pclk_f, ssp1_cpsr, max283x_spi_f) + 3) | CR0_FRFSPI | CR0_DSS9BIT,
|
||||
.cpsr = ssp1_cpsr,
|
||||
};
|
||||
|
||||
static max283x::MAX283x* transceiver = nullptr;
|
||||
|
||||
void set_rx_buff_vcm(const size_t v) {
|
||||
if (transceiver) {
|
||||
transceiver->set_rx_buff_vcm(v);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
/* MAX2837/MAX2839 use 16-bit SPI transfers */
|
||||
static constexpr SPIConfig ssp_config_max283x = {
|
||||
@@ -116,9 +126,10 @@ max2837::MAX2837 second_if_max2837{ssp1_target_max283x};
|
||||
max2839::MAX2839 second_if_max2839{ssp1_target_max283x};
|
||||
#ifdef PRALINE
|
||||
max2831::MAX2831 second_if_max2831{ssp1_target_max283x};
|
||||
#else
|
||||
static baseband::CPLD baseband_cpld;
|
||||
#endif
|
||||
static max5864::MAX5864 baseband_codec{ssp1_target_max5864};
|
||||
static baseband::CPLD baseband_cpld;
|
||||
|
||||
// load_sram() is called at boot in portapack.cpp, including verify CPLD part, so default direction is Receive
|
||||
static rf::Direction direction{rf::Direction::Receive};
|
||||
@@ -145,25 +156,43 @@ void init() {
|
||||
? (max283x::MAX283x*)&second_if_max2839
|
||||
: (max283x::MAX283x*)&second_if_max2837;
|
||||
#endif
|
||||
|
||||
rf_path.init();
|
||||
first_if.init();
|
||||
second_if->init();
|
||||
baseband_codec.init();
|
||||
#ifndef PRALINE
|
||||
/* HackRF One uses CPLD for Q inversion control.
|
||||
* PRALINE uses FPGA and the pin (P2_3) is used for LCD_TE on H4M. */
|
||||
baseband_cpld.init();
|
||||
#else
|
||||
|
||||
#ifdef PRALINE
|
||||
|
||||
/* Praline-Specific Bus and Gateware Configuration */
|
||||
|
||||
// SYNC SGPIO TO FPGA CLOCK:
|
||||
// Configure all 16 SGPIO slices to use the external clock (SGPIO8)
|
||||
// provided by the FPGA. This allows the MCU to stay at 40MHz
|
||||
// while the data bus scales to the RF sample rate.
|
||||
// Bit 2:1 of SGPIO_MUX_CFG = 01 (External clock from SGPIO8)
|
||||
// SYNC SGPIO TO FPGA CLOCK WITH FALLING EDGE LATCH
|
||||
for (int i = 0; i < 16; i++) {
|
||||
// (1 << 1) = External clock from SGPIO8
|
||||
// (1 << 3) = Sample on the FALLING edge of the clock
|
||||
LPC_SGPIO->SGPIO_MUX_CFG[i] = (1 << 1) | (1 << 3);
|
||||
}
|
||||
|
||||
/* Initialize FPGA registers - DC_BLOCK must be enabled for RX */
|
||||
// debug::fpga::init();
|
||||
fpga_debug_register_write(1, 0x01); // DC_BLOCK=1, QUARTER_SHIFT=0, Q_INVERT=0
|
||||
fpga_debug_register_write(2, 0x00); // RX_DECIM=0 (no decimation for testing)
|
||||
// These FPGA registers control DC_BLOCK, Q-Inv, QUARTER SHIFT, and Decimation.
|
||||
fpga_debug_register_write(1, 0x00); // DC_BLOCK=1, QUARTER_SHIFT=0, Q_INVERT=0
|
||||
fpga_debug_register_write(2, 0x00); // RX_DECIM=No Decim
|
||||
fpga_debug_register_write(3, 0x00); // TX_CTRL=0
|
||||
fpga_debug_register_write(4, 0x00); // TX_INTRP=0
|
||||
fpga_debug_register_write(5, 0x00); // TX_PSTEP=0
|
||||
|
||||
ssp1_arbiter.invalidate();
|
||||
chThdSleepMilliseconds(10); // Let FPGA registers settle
|
||||
#else
|
||||
/* HackRF One uses CPLD for Q inversion control.
|
||||
* PRALINE uses FPGA and the pin (P2_3) is used for LCD_TE on H4M. */
|
||||
baseband_cpld.init();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -202,19 +231,20 @@ void set_direction(const rf::Direction new_direction) {
|
||||
*/
|
||||
baseband_invert = false;
|
||||
}
|
||||
#ifndef PRALINE
|
||||
baseband_cpld.set_invert(mixer_invert ^ baseband_invert);
|
||||
#else
|
||||
// TEST: Force baseband invert for Praline (like r9)
|
||||
// baseband_invert = (direction == rf::Direction::Receive);
|
||||
|
||||
// Praline: Control Q inversion via FPGA register
|
||||
uint8_t ctrl_reg = 0x01; // DC_BLOCK enabled
|
||||
if (mixer_invert ^ baseband_invert) {
|
||||
ctrl_reg |= 0x02; // Set Q_INVERT bit
|
||||
#ifdef PRALINE
|
||||
|
||||
// Q inversion controlled by GPIO0[13] (SGPIO12), not FPGA register
|
||||
bool q_invert = mixer_invert ^ baseband_invert;
|
||||
if (q_invert) {
|
||||
LPC_GPIO->SET[0] = (1 << 13); // SGPIO12 = 1 (Q inverted)
|
||||
} else {
|
||||
LPC_GPIO->CLR[0] = (1 << 13); // SGPIO12 = 0 (Q normal)
|
||||
}
|
||||
fpga_debug_register_write(1, ctrl_reg);
|
||||
|
||||
ssp1_arbiter.invalidate();
|
||||
#else
|
||||
baseband_cpld.set_invert(mixer_invert ^ baseband_invert);
|
||||
#endif
|
||||
|
||||
second_if->set_mode((direction == rf::Direction::Transmit) ? max283x::Mode::Transmit : max283x::Mode::Receive);
|
||||
@@ -261,6 +291,10 @@ bool set_tuning_frequency(const rf::Frequency frequency) {
|
||||
if (tuning_config.first_lo_frequency) {
|
||||
first_if.set_frequency(tuning_config.first_lo_frequency);
|
||||
first_if.enable();
|
||||
#ifdef PRALINE
|
||||
first_if.flush(); // Force register write with reference clock present
|
||||
chThdSleepMilliseconds(10); // Allow PLL to settle
|
||||
#endif
|
||||
}
|
||||
|
||||
// Program second local oscillator frequency into MAX283x
|
||||
@@ -268,19 +302,20 @@ bool set_tuning_frequency(const rf::Frequency frequency) {
|
||||
|
||||
rf_path.set_band(tuning_config.rf_path_band);
|
||||
mixer_invert = tuning_config.mixer_invert;
|
||||
#ifndef PRALINE
|
||||
baseband_cpld.set_invert(mixer_invert ^ baseband_invert);
|
||||
#else
|
||||
// TEST: Force baseband invert for Praline (like r9)
|
||||
// baseband_invert = (direction == rf::Direction::Receive);
|
||||
|
||||
// PRALINE: Update FPGA Q inversion when tuning changes
|
||||
uint8_t ctrl_reg = 0x01; // DC_BLOCK enabled
|
||||
if (mixer_invert ^ baseband_invert) {
|
||||
ctrl_reg |= 0x02; // Set Q_INVERT bit
|
||||
#ifdef PRALINE
|
||||
|
||||
// Q inversion controlled by GPIO0[13] (SGPIO12), not FPGA register
|
||||
bool q_invert = mixer_invert ^ baseband_invert;
|
||||
if (q_invert) {
|
||||
LPC_GPIO->SET[0] = (1 << 13); // SGPIO12 = 1 (Q inverted)
|
||||
} else {
|
||||
LPC_GPIO->CLR[0] = (1 << 13); // SGPIO12 = 0 (Q normal)
|
||||
}
|
||||
fpga_debug_register_write(1, ctrl_reg);
|
||||
|
||||
ssp1_arbiter.invalidate();
|
||||
#else
|
||||
baseband_cpld.set_invert(mixer_invert ^ baseband_invert);
|
||||
#endif
|
||||
|
||||
return result_second_if;
|
||||
@@ -350,20 +385,6 @@ void set_rx_max283x_iq_phase_calibration(const size_t v) {
|
||||
second_if->set_rx_LO_iq_phase_calibration(v);
|
||||
}
|
||||
|
||||
/*void enable(Configuration configuration) {
|
||||
configure(configuration);
|
||||
}
|
||||
|
||||
void configure(Configuration configuration) {
|
||||
set_tuning_frequency(configuration.tuning_frequency);
|
||||
set_rf_amp(configuration.rf_amp);
|
||||
set_lna_gain(configuration.lna_gain);
|
||||
set_vga_gain(configuration.vga_gain);
|
||||
set_baseband_rate(configuration.baseband_rate);
|
||||
set_baseband_filter_bandwidth(configuration.baseband_filter_bandwidth);
|
||||
set_direction(configuration.direction);
|
||||
}*/
|
||||
|
||||
void disable() {
|
||||
set_antenna_bias(false);
|
||||
baseband_codec.set_mode(max5864::Mode::Shutdown);
|
||||
@@ -457,27 +478,6 @@ TuningInfo get_tuning_info() {
|
||||
|
||||
namespace second_if {
|
||||
|
||||
#ifdef PRALINE
|
||||
extern "C" {
|
||||
extern struct max2831_debug_t {
|
||||
uint32_t requested_freq_mhz;
|
||||
uint32_t calculated_n;
|
||||
uint32_t calculated_frac;
|
||||
bool set_frequency_called;
|
||||
bool frequency_valid;
|
||||
} max2831_debug_info;
|
||||
}
|
||||
|
||||
MAX2831Info get_max2831_info() {
|
||||
return {
|
||||
max2831_debug_info.requested_freq_mhz,
|
||||
max2831_debug_info.calculated_n,
|
||||
max2831_debug_info.calculated_frac,
|
||||
max2831_debug_info.set_frequency_called,
|
||||
max2831_debug_info.frequency_valid};
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t register_read(const size_t register_number) {
|
||||
return radio::second_if->read(register_number);
|
||||
}
|
||||
@@ -521,7 +521,7 @@ void register_write(const size_t register_number, uint32_t value) {
|
||||
void init() {
|
||||
// Initialize FPGA registers after bitstream load
|
||||
// DC_BLOCK (bit 0) must be enabled for RX to work
|
||||
fpga_debug_register_write(1, 0x01); // CTRL: DC_BLOCK=1
|
||||
fpga_debug_register_write(1, 0x00); // CTRL: DC_BLOCK=1
|
||||
fpga_debug_register_write(2, 0x00); // RX_DECIM: no decimation
|
||||
fpga_debug_register_write(3, 0x00); // TX_CTRL: NCO disabled
|
||||
fpga_debug_register_write(4, 0x00); // TX_INTRP: no interpolation
|
||||
|
||||
@@ -64,6 +64,7 @@ void disable();
|
||||
|
||||
#ifdef PRALINE
|
||||
void invalidate_spi_config();
|
||||
void set_rx_buff_vcm(const size_t v);
|
||||
#endif
|
||||
|
||||
namespace debug {
|
||||
@@ -95,17 +96,6 @@ TuningInfo get_tuning_info();
|
||||
|
||||
namespace second_if {
|
||||
|
||||
#ifdef PRALINE
|
||||
struct MAX2831Info {
|
||||
uint32_t requested_freq_mhz;
|
||||
uint32_t calculated_n;
|
||||
uint32_t calculated_frac;
|
||||
bool set_frequency_called;
|
||||
bool frequency_valid;
|
||||
};
|
||||
MAX2831Info get_max2831_info();
|
||||
#endif
|
||||
|
||||
uint32_t register_read(const size_t register_number);
|
||||
void register_write(const size_t register_number, uint32_t value);
|
||||
|
||||
|
||||
@@ -34,12 +34,6 @@
|
||||
#include "dsp_iir_config.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#ifdef PRALINE
|
||||
extern "C" {
|
||||
#include "fpga_bridge.h"
|
||||
}
|
||||
#endif
|
||||
|
||||
using namespace hackrf::one;
|
||||
using namespace portapack;
|
||||
|
||||
@@ -63,9 +57,10 @@ static constexpr std::array<baseband::AMConfig, 12> am_configs{{
|
||||
{taps_6k0_narrow_decim_1, taps_6k0_decim_2, taps_2k6_usb_wefax_channel, AMConfigureMessage::Modulation::SSB_FM, apt_audio_12k_lpf_1500hz_config, (int)AMConfigureMessage::Zoom_waterfall::ZOOM_x_2}, // SSB USB+FM to demod. Subcarrier FM Audio Tones to get APT Weather Fax with waterfall zoom x 2 (we need taps_6k0_narrow_decim_1 to minimize aliasing)
|
||||
}};
|
||||
|
||||
static constexpr std::array<baseband::NBFMConfig, 3> nbfm_configs{{
|
||||
static constexpr std::array<baseband::NBFMConfig, 4> nbfm_configs{{
|
||||
{taps_4k25_decim_0, taps_4k25_decim_1, taps_4k25_channel, 2500},
|
||||
{taps_11k0_decim_0, taps_11k0_decim_1, taps_11k0_channel, 2500},
|
||||
{taps_12k5_decim_0, taps_12k5_decim_1, taps_12k5_channel, 2500},
|
||||
{taps_16k0_decim_0, taps_16k0_decim_1, taps_16k0_channel, 5000},
|
||||
}};
|
||||
|
||||
@@ -247,6 +242,14 @@ void ReceiverModel::set_normalized_headphone_volume(uint8_t v) {
|
||||
void ReceiverModel::enable() {
|
||||
enabled_ = true;
|
||||
radio::set_direction(rf::Direction::Receive);
|
||||
|
||||
#ifdef PRALINE
|
||||
/* Anchor the Common Mode Voltage (VCM) to 1.2V.
|
||||
* This stabilizes the electrical floor of the I/Q signals.
|
||||
*/
|
||||
radio::set_rx_buff_vcm(1);
|
||||
#endif
|
||||
|
||||
update_tuning_frequency();
|
||||
update_antenna_bias();
|
||||
update_rf_amp();
|
||||
@@ -311,17 +314,6 @@ void ReceiverModel::update_tuning_frequency() {
|
||||
// TODO: use positive offset if freq < offset.
|
||||
if (enabled_) {
|
||||
radio::set_tuning_frequency(target_frequency() + hidden_offset + tuning_offset());
|
||||
|
||||
#ifdef PRALINE
|
||||
/* Praline: Must re-apply baseband filter after frequency change
|
||||
* Reference: hackrf_usb radio.c radio_set_frequency()
|
||||
*
|
||||
* Different frequency ranges may use different quarter-shift modes,
|
||||
* which affects the required LPF bandwidth. For now we just
|
||||
* recalculate the filter to be safe.
|
||||
*/
|
||||
update_baseband_bandwidth();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,20 +325,47 @@ void ReceiverModel::set_hidden_offset(rf::Frequency offset) {
|
||||
void ReceiverModel::update_baseband_bandwidth() {
|
||||
if (enabled_) {
|
||||
#ifdef PRALINE
|
||||
/* Praline: LPF bandwidth calculation
|
||||
* Reference: hackrf_usb radio.c radio_set_filter()
|
||||
/*
|
||||
* PRALINE LPF bandwidth calculation from GSG hackrf_usb radio.c
|
||||
*
|
||||
* LPF = (sample_rate * 3) / 8
|
||||
* Plus additional offset if quarter-shift is enabled (not implemented yet)
|
||||
* The LPF should be set to capture the desired signal bandwidth
|
||||
* while the FPGA decimation filter handles anti-aliasing.
|
||||
*
|
||||
* For most modes: LPF = (output_sample_rate * 3) / 8
|
||||
* For quarter-shift: add offset for shifted spectrum
|
||||
*
|
||||
* Note: MAX2831 minimum LPF is 11.6 MHz, so for narrow sample rates
|
||||
* the hardware limit applies and FPGA filter does the real work.
|
||||
*/
|
||||
uint32_t lpf_bandwidth = (sampling_rate() * 3) / 8;
|
||||
|
||||
// For now, quarter-shift is disabled, so no offset added
|
||||
// When quarter-shift is implemented:
|
||||
// if (quarter_shift_enabled) {
|
||||
// uint32_t offset = (sampling_rate() << decimation_n) / 8;
|
||||
// lpf_bandwidth += offset * 2;
|
||||
// }
|
||||
uint32_t sample_rate = sampling_rate();
|
||||
uint8_t resampling_n = portapack::clock_manager.get_resampling_n();
|
||||
uint32_t afe_rate = sample_rate << resampling_n;
|
||||
|
||||
// Base LPF: enough to capture desired bandwidth
|
||||
uint32_t lpf_bandwidth = (sample_rate * 3) / 8;
|
||||
|
||||
// Check if quarter-shift is enabled (FPGA register 1, bits 2-3)
|
||||
uint32_t fpga_ctrl = radio::debug::fpga::register_read(1);
|
||||
uint8_t quarter_shift = (fpga_ctrl >> 2) & 0x03;
|
||||
|
||||
if (quarter_shift != 0) {
|
||||
// Quarter-shift moves spectrum by AFE_rate/4, need wider LPF
|
||||
uint32_t offset = afe_rate / 8;
|
||||
lpf_bandwidth += offset * 2;
|
||||
}
|
||||
|
||||
// For best anti-alias performance, also consider AFE Nyquist
|
||||
// If our calculated LPF is below MAX2831 minimum, it doesn't matter
|
||||
// But if we can set LPF to just below AFE Nyquist, that's optimal
|
||||
uint32_t afe_nyquist = afe_rate / 2;
|
||||
|
||||
// Use the larger of: signal bandwidth requirement OR Nyquist protection
|
||||
// (but MAX2831 driver will clamp to its available settings anyway)
|
||||
if (lpf_bandwidth < afe_nyquist) {
|
||||
// Set LPF close to Nyquist for maximum alias rejection
|
||||
lpf_bandwidth = (afe_nyquist * 9) / 10; // 90% of Nyquist
|
||||
}
|
||||
|
||||
radio::set_baseband_filter_bandwidth_rx(lpf_bandwidth);
|
||||
#else
|
||||
@@ -365,6 +384,12 @@ void ReceiverModel::update_sampling_rate() {
|
||||
radio::set_baseband_rate(sampling_rate());
|
||||
}
|
||||
update_tuning_frequency();
|
||||
|
||||
#ifdef PRALINE
|
||||
// GSG reference: re-apply frequency after sample rate change
|
||||
// This reconfigures LPF bandwidth based on new decimation
|
||||
update_baseband_bandwidth();
|
||||
#endif
|
||||
}
|
||||
|
||||
void ReceiverModel::update_lna() {
|
||||
|
||||
@@ -108,9 +108,10 @@ void resetFilteredEntries(ContainerType& entries, KeySelector keySelector) {
|
||||
auto it = entries.begin();
|
||||
while (it != entries.end()) {
|
||||
if (keySelector(*it)) {
|
||||
entries.erase(it); // Add a new entry to filteredEntries
|
||||
it = entries.erase(it); // Add a new entry to filteredEntries
|
||||
} else {
|
||||
++it; // Move to the next element, outside of the if block
|
||||
}
|
||||
++it; // Move to the next element, outside of the if block
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,14 +41,14 @@ namespace {
|
||||
*/
|
||||
struct PralineConfig {
|
||||
bool tx_en;
|
||||
bool mix_en_n; // Inverted: 0 = mixer enabled
|
||||
bool mix_bypass; // RF path mixer bypass (GPIO3[2])
|
||||
bool lpf_en;
|
||||
bool rf_amp_en;
|
||||
bool ant_bias_en_n; // Inverted: 0 = bias enabled
|
||||
|
||||
static void gpio_init() {
|
||||
gpio_tx_enable.output();
|
||||
gpio_mix_enable_n.output();
|
||||
gpio_mix_bypass.output();
|
||||
gpio_lpf_enable.output();
|
||||
gpio_rf_amp_enable.output();
|
||||
gpio_ant_bias_disable.output();
|
||||
@@ -56,7 +56,7 @@ struct PralineConfig {
|
||||
|
||||
void apply() const {
|
||||
gpio_tx_enable.write(tx_en);
|
||||
gpio_mix_enable_n.write(mix_en_n);
|
||||
gpio_mix_bypass.write(mix_bypass); // Control RF path mixer
|
||||
gpio_lpf_enable.write(lpf_en);
|
||||
gpio_rf_amp_enable.write(rf_amp_en);
|
||||
gpio_ant_bias_disable.write(ant_bias_en_n);
|
||||
@@ -239,7 +239,7 @@ void Path::init() {
|
||||
/* Set safe initial state: RX mode, mixer enabled, LPF on, amp off, no bias */
|
||||
PralineConfig config = {
|
||||
.tx_en = false,
|
||||
.mix_en_n = false, // Mixer enabled (inverted)
|
||||
.mix_bypass = false, // RF path mixer bypass (GPIO3[2])
|
||||
.lpf_en = true, // LPF on for low band
|
||||
.rf_amp_en = false, // Amp off
|
||||
.ant_bias_en_n = true // Bias off (inverted)
|
||||
@@ -276,7 +276,7 @@ void Path::update() {
|
||||
#ifdef PRALINE
|
||||
/* PRALINE RF path control:
|
||||
* - tx_en: 1 for TX, 0 for RX
|
||||
* - mix_en_n: 0 to enable mixer (inverted), 1 to bypass
|
||||
* - mix_bypass: 0 to enable RF path mixer bypass (GPIO3[2])
|
||||
* - lpf_en: 1 for low band (< 2.4 GHz), 0 for high band
|
||||
* - rf_amp_en: 1 to enable RF amplifier
|
||||
* - ant_bias_en_n: 0 to enable antenna bias (inverted)
|
||||
@@ -294,8 +294,8 @@ void Path::update() {
|
||||
|
||||
config.tx_en = (direction == Direction::Transmit);
|
||||
|
||||
/* Mixer bypass for mid band (2.3-2.7 GHz direct to MAX2831) */
|
||||
config.mix_en_n = (band == Band::Mid); // 1 = bypass (disabled)
|
||||
// RF path mixer bypass: 0=enabled, 1=bypassed
|
||||
config.mix_bypass = (band == Band::Mid);
|
||||
|
||||
/* Move to the final state by turning on required signals. */
|
||||
/* LPF for low band */
|
||||
|
||||
@@ -39,9 +39,17 @@ enum class Direction {
|
||||
|
||||
namespace path {
|
||||
|
||||
#ifdef PRALINE
|
||||
/* PRALINE: MAX2831 direct path is 2320-2740 MHz */
|
||||
constexpr FrequencyRange band_low{0, 2320'000'000};
|
||||
constexpr FrequencyRange band_high{2740'000'000, 7250'000'000};
|
||||
constexpr FrequencyRange band_mid{band_low.maximum, band_high.minimum};
|
||||
#else
|
||||
/* HackRF One: Original band boundaries */
|
||||
constexpr FrequencyRange band_low{0, 2170'000'000};
|
||||
constexpr FrequencyRange band_high{2740'000'000, 7250'000'000};
|
||||
constexpr FrequencyRange band_mid{band_low.maximum, band_high.minimum};
|
||||
#endif
|
||||
|
||||
enum class Band {
|
||||
/* Zero-based, used as index into frequency_bands table */
|
||||
|
||||
@@ -93,6 +93,22 @@ static const char* get_board_revision_string(board_rev_t rev) {
|
||||
return "GSG HackRF R9";
|
||||
case BOARD_REV_GSG_HACKRF1_R10:
|
||||
return "GSG HackRF R10";
|
||||
case BOARD_REV_PRALINE_R0_1:
|
||||
case BOARD_REV_PRALINE_R0_2:
|
||||
case BOARD_REV_PRALINE_R0_3:
|
||||
return "HackRF Pro R0";
|
||||
case BOARD_REV_PRALINE_R1_0:
|
||||
case BOARD_REV_PRALINE_R1_1:
|
||||
case BOARD_REV_PRALINE_R1_2:
|
||||
return "HackRF Pro R1";
|
||||
case BOARD_REV_GSG_PRALINE_R0_1:
|
||||
case BOARD_REV_GSG_PRALINE_R0_2:
|
||||
case BOARD_REV_GSG_PRALINE_R0_3:
|
||||
return "GSG HackRF Pro R0";
|
||||
case BOARD_REV_GSG_PRALINE_R1_0:
|
||||
case BOARD_REV_GSG_PRALINE_R1_1:
|
||||
case BOARD_REV_GSG_PRALINE_R1_2:
|
||||
return "GSG HackRF Pro R1";
|
||||
case BOARD_REV_UNRECOGNIZED:
|
||||
return "Unrecognized";
|
||||
case BOARD_REV_UNDETECTED:
|
||||
@@ -134,6 +150,36 @@ static void cmd_info(BaseSequentialStream* chp, int argc, char* argv[]) {
|
||||
board_rev_t revision = detected_revision();
|
||||
const char* revision_string = get_board_revision_string(revision);
|
||||
chprintf(chp, "HackRF Board Rev: %s\r\n", revision_string);
|
||||
|
||||
// Determine device type string
|
||||
const char* device_str;
|
||||
#ifdef PRALINE
|
||||
device_str = "HackRF Pro";
|
||||
#else
|
||||
if (portapack::device_type == portapack::DEV_PORTARF) {
|
||||
device_str = "PortaRF";
|
||||
} else {
|
||||
device_str = "HackRF One";
|
||||
}
|
||||
#endif
|
||||
chprintf(chp, "Device: %s\r\n", device_str);
|
||||
|
||||
// Flash info: build-time allowed MB, runtime-detected limit, current firmware size
|
||||
// Use explicit uint32_t cast: FLASH_SIZE_LIMIT_MB may be a float (e.g. 3.5 for HPro)
|
||||
uint8_t flash_allowrun;
|
||||
#ifdef PRALINE
|
||||
flash_allowrun = 4; // HackRF Pro
|
||||
#else
|
||||
if (portapack::device_type == portapack::DeviceType::DEV_PORTAPACK) {
|
||||
flash_allowrun = 1; // PortaPack classic
|
||||
} else {
|
||||
flash_allowrun = FLASH_SIZE_MB; // PortaRF
|
||||
}
|
||||
#endif
|
||||
chprintf(chp, "Flash Allowed: %dMB\r\n", (uint32_t)FLASH_SIZE_MB);
|
||||
chprintf(chp, "Flash Runtime: %dMB\r\n", (uint32_t)flash_allowrun);
|
||||
chprintf(chp, "Flash Current: %dMB\r\n", (uint32_t)FLASH_SIZE_LIMIT_MB);
|
||||
|
||||
chprintf(chp, "Reference Source: %s\r\n", portapack::clock_manager.get_source().c_str());
|
||||
chprintf(chp, "Reference Freq: %s\r\n", portapack::clock_manager.get_freq().c_str());
|
||||
#ifdef __DATE__
|
||||
|
||||
@@ -100,7 +100,8 @@ std::string to_string_dec_uint(uint64_t n) {
|
||||
|
||||
std::string to_string_bin(
|
||||
const uint32_t n,
|
||||
const uint8_t l) {
|
||||
uint8_t l) {
|
||||
if (l >= 33) l = 32;
|
||||
char p[33];
|
||||
for (uint8_t c = 0; c < l; c++) {
|
||||
if (n & (1 << (l - 1 - c)))
|
||||
|
||||
@@ -50,7 +50,7 @@ char* to_string_dec_uint(uint64_t n, StringFormatBuffer& buffer, size_t& length)
|
||||
std::string to_string_dec_int(int64_t n);
|
||||
std::string to_string_dec_uint(uint64_t n);
|
||||
|
||||
std::string to_string_bin(const uint32_t n, const uint8_t l = 0);
|
||||
std::string to_string_bin(const uint32_t n, uint8_t l = 0);
|
||||
std::string to_string_dec_uint(const uint32_t n, const int32_t l, const char fill = ' ');
|
||||
std::string to_string_dec_int(const int32_t n, const int32_t l, const char fill = 0);
|
||||
std::string to_string_decimal(float decimal, int8_t precision);
|
||||
|
||||
@@ -32,40 +32,40 @@ namespace ui {
|
||||
|
||||
class ThemeTemplate {
|
||||
public:
|
||||
~ThemeTemplate();
|
||||
Style* bg_lightest;
|
||||
Style* bg_lightest_small;
|
||||
Style* bg_light;
|
||||
Style* bg_medium;
|
||||
Style* bg_dark;
|
||||
Style* bg_darker;
|
||||
virtual ~ThemeTemplate();
|
||||
Style* bg_lightest = nullptr;
|
||||
Style* bg_lightest_small = nullptr;
|
||||
Style* bg_light = nullptr;
|
||||
Style* bg_medium = nullptr;
|
||||
Style* bg_dark = nullptr;
|
||||
Style* bg_darker = nullptr;
|
||||
|
||||
Style* bg_darkest;
|
||||
Style* bg_darkest_small;
|
||||
Style* bg_darkest = nullptr;
|
||||
Style* bg_darkest_small = nullptr;
|
||||
|
||||
Style* bg_important_small;
|
||||
Style* bg_important_small = nullptr;
|
||||
|
||||
Style* error_dark;
|
||||
Style* warning_dark;
|
||||
Style* ok_dark;
|
||||
Style* error_dark = nullptr;
|
||||
Style* warning_dark = nullptr;
|
||||
Style* ok_dark = nullptr;
|
||||
|
||||
Style* fg_dark;
|
||||
Style* fg_medium;
|
||||
Style* fg_light;
|
||||
Style* fg_dark = nullptr;
|
||||
Style* fg_medium = nullptr;
|
||||
Style* fg_light = nullptr;
|
||||
|
||||
Style* fg_red;
|
||||
Style* fg_green;
|
||||
Style* fg_yellow;
|
||||
Style* fg_orange;
|
||||
Style* fg_blue;
|
||||
Style* fg_cyan;
|
||||
Style* fg_darkcyan;
|
||||
Style* fg_magenta;
|
||||
Style* fg_red = nullptr;
|
||||
Style* fg_green = nullptr;
|
||||
Style* fg_yellow = nullptr;
|
||||
Style* fg_orange = nullptr;
|
||||
Style* fg_blue = nullptr;
|
||||
Style* fg_cyan = nullptr;
|
||||
Style* fg_darkcyan = nullptr;
|
||||
Style* fg_magenta = nullptr;
|
||||
|
||||
Style* option_active;
|
||||
Style* option_active = nullptr;
|
||||
|
||||
Color* status_active; // green, the status bar icons when active
|
||||
Color* bg_table_header;
|
||||
Color* status_active = nullptr; // green, the status bar icons when active
|
||||
Color* bg_table_header = nullptr;
|
||||
};
|
||||
|
||||
class ThemeDefault : public ThemeTemplate {
|
||||
|
||||
+104
-13
@@ -31,18 +31,86 @@ Config low_band(const rf::Frequency target_frequency);
|
||||
Config mid_band(const rf::Frequency target_frequency);
|
||||
Config high_band(const rf::Frequency target_frequency);
|
||||
|
||||
// Low band <2170 Mhz:
|
||||
#ifdef PRALINE
|
||||
/*
|
||||
* PRALINE Tuning Configuration
|
||||
* ============================
|
||||
*
|
||||
* Reference: hackrf_usb/common/tune_config.h praline_tune_config_rx[]
|
||||
*
|
||||
* The hackrf_usb firmware uses a table-driven approach where each entry
|
||||
* specifies:
|
||||
* - rf_range_end_mhz: Upper frequency limit for this config
|
||||
* - if_mhz: IF frequency (what MAX2831 tunes to)
|
||||
* - high_lo: true = high-side injection, false = low-side
|
||||
* - shift: FPGA quarter-shift mode (not implemented in Mayhem yet)
|
||||
*
|
||||
* Key insight: The IF frequency varies to keep the RFFC5072 VCO in a
|
||||
* safe operating range (ideally 3500-5000 MHz, avoiding extremes).
|
||||
*
|
||||
* RFFC5072 VCO calculation:
|
||||
* High-side injection: LO = IF + RF, VCO = LO × lodiv
|
||||
* Low-side injection: LO = IF - RF, VCO = LO × lodiv
|
||||
* Where lodiv = 2 for frequencies where VCO > 2700 MHz
|
||||
*
|
||||
* From hackrf_usb tune_config_rx (simplified):
|
||||
* 0-2100 MHz: IF=2375, high_lo=true → VCO = (2375+RF)×2
|
||||
* 2105-2115: IF=2375, high_lo=false → VCO = (2375-RF)×2
|
||||
* 2115-2130: IF=2425, high_lo=false → VCO = (2425-RF)×2
|
||||
* ... (more entries for fine-grained control)
|
||||
* 2320-2580: IF=0 (bypass mode, no mixer)
|
||||
* 2580+: High-pass mode
|
||||
*/
|
||||
|
||||
// Simplified tune_config lookup for Mayhem
|
||||
// Returns the IF frequency in Hz for a given target frequency
|
||||
constexpr rf::Frequency praline_get_if_frequency(const rf::Frequency target_frequency) {
|
||||
const uint32_t freq_mhz = target_frequency / 1'000'000;
|
||||
|
||||
// Based on hackrf_usb tune_config_rx table
|
||||
if (freq_mhz < 2100) {
|
||||
// Most low-band frequencies: use 2375 MHz IF
|
||||
// This keeps VCO around 4750-4950 MHz for FM band
|
||||
return 2375'000'000;
|
||||
} else if (freq_mhz < 2320) {
|
||||
// Transition zone: use varying IF to avoid VCO edges
|
||||
// These frequencies are tricky - near MAX2831 minimum
|
||||
// Use 2425 MHz to give some margin
|
||||
return 2425'000'000;
|
||||
} else {
|
||||
// Bypass mode or high-band - IF not used for mixer
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true for high-side injection, false for low-side
|
||||
constexpr bool praline_use_high_side_injection(const rf::Frequency target_frequency) {
|
||||
const uint32_t freq_mhz = target_frequency / 1'000'000;
|
||||
|
||||
// Based on hackrf_usb tune_config_rx table
|
||||
if (freq_mhz < 2100) {
|
||||
// Standard low-band: high-side injection
|
||||
// LO = IF + RF, mixer inverts spectrum
|
||||
return true;
|
||||
} else if (freq_mhz < 2105) {
|
||||
// Narrow transition: still high-side
|
||||
return true;
|
||||
} else if (freq_mhz < 2320) {
|
||||
// Near MAX2831 minimum: use low-side injection
|
||||
// LO = IF - RF, no spectrum inversion
|
||||
return false;
|
||||
} else {
|
||||
// Bypass/high-band - doesn't matter, mixer bypassed
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif // PRALINE
|
||||
|
||||
// Low band <2170 Mhz (HackRF One) or <2320 MHz (PRALINE):
|
||||
constexpr rf::Frequency low_band_second_lo_frequency(const rf::Frequency target_frequency) {
|
||||
#ifdef PRALINE
|
||||
// Praline-specific formula for MAX2831 (2.3-2.6 GHz range)
|
||||
// Use a fixed second_lo that:
|
||||
// 1. Falls in MAX2831's sweet spot (2.3-2.6 GHz)
|
||||
// 2. Gives RFFC5072 a VCO frequency in its range (2700-5400 MHz)
|
||||
|
||||
// For most low-band frequencies, use 2500 MHz as second_lo
|
||||
// This gives RFFC5072 plenty of headroom
|
||||
(void)target_frequency; // Unused in fixed formula
|
||||
return 2500'000'000;
|
||||
// Use the tune_config lookup for PRALINE
|
||||
return praline_get_if_frequency(target_frequency);
|
||||
#else
|
||||
return 2650'000'000 - (target_frequency / 7);
|
||||
#endif
|
||||
@@ -50,18 +118,36 @@ constexpr rf::Frequency low_band_second_lo_frequency(const rf::Frequency target_
|
||||
|
||||
Config low_band(const rf::Frequency target_frequency) {
|
||||
const rf::Frequency second_lo_frequency = low_band_second_lo_frequency(target_frequency);
|
||||
|
||||
#ifdef PRALINE
|
||||
rf::Frequency first_lo_frequency;
|
||||
bool mixer_invert;
|
||||
|
||||
if (praline_use_high_side_injection(target_frequency)) {
|
||||
// High-side injection: LO = IF + RF
|
||||
first_lo_frequency = second_lo_frequency + target_frequency;
|
||||
mixer_invert = true;
|
||||
} else {
|
||||
// Low-side injection: LO = IF - RF
|
||||
first_lo_frequency = second_lo_frequency - target_frequency;
|
||||
mixer_invert = false;
|
||||
}
|
||||
|
||||
return {first_lo_frequency, second_lo_frequency, rf::path::Band::Low, mixer_invert};
|
||||
#else
|
||||
const rf::Frequency first_lo_frequency = target_frequency + second_lo_frequency;
|
||||
const bool mixer_invert = true;
|
||||
return {first_lo_frequency, second_lo_frequency, rf::path::Band::Low, mixer_invert};
|
||||
#endif
|
||||
}
|
||||
|
||||
// Mid band 2170-2740 Mhz:
|
||||
// Mid band 2170-2740 Mhz (HackRF One) or 2320-2580 MHz (PRALINE):
|
||||
Config mid_band(const rf::Frequency target_frequency) {
|
||||
#ifdef PRALINE
|
||||
// For Praline with MAX2831 (2.3-2.6 GHz range)
|
||||
// Frequencies 2170-2300 MHz need upconversion since they're below MAX2831 minimum
|
||||
if (target_frequency < 2300'000'000) {
|
||||
// Treat as low band
|
||||
// Treat as low band - need mixer
|
||||
return low_band(target_frequency);
|
||||
}
|
||||
// Frequencies 2300-2600 MHz can go direct (no RFFC5072)
|
||||
@@ -84,11 +170,16 @@ Config mid_band(const rf::Frequency target_frequency) {
|
||||
#endif
|
||||
}
|
||||
|
||||
// High band >2740 Mhz:
|
||||
// High band >2740 Mhz (HackRF One) or >2580 MHz (PRALINE):
|
||||
constexpr rf::Frequency high_band_second_lo_frequency(const rf::Frequency target_frequency) {
|
||||
#ifdef PRALINE
|
||||
// Praline formula tuned for MAX2831 (2.3-2.6 GHz range)
|
||||
// Keep second_lo in MAX2831's range while allowing RFFC5072 to work
|
||||
//
|
||||
// For high-band, we use LOW-side injection: LO = RF - IF
|
||||
// So IF should be chosen to keep LO (and thus VCO) in a good range
|
||||
//
|
||||
// Based on hackrf_usb tune_config_tx patterns:
|
||||
if (target_frequency < 3600'000'000)
|
||||
return 2400'000'000 + ((target_frequency - 2740'000'000) / 4);
|
||||
else if (target_frequency < 5100'000'000)
|
||||
|
||||
@@ -92,7 +92,7 @@ void BMPViewer::get_line(ui::Color* line, uint32_t bx, uint32_t by, uint32_t cnt
|
||||
for (uint32_t x = 0; x < cnt; x++) {
|
||||
uint32_t targetx = (zoom < 0) ? bx + x * -1 * zoom : bx + x / zoom; // on zoom out could probably avg the pixels, or apply some smoothing, but this is way faster.
|
||||
if (last_targetx == targetx) {
|
||||
line[x] = line[x - 1];
|
||||
if (x > 0) line[x] = line[x - 1];
|
||||
continue;
|
||||
}
|
||||
last_targetx = targetx;
|
||||
@@ -123,7 +123,7 @@ void BMPViewer::paint(Painter& painter) {
|
||||
last_by = by;
|
||||
portapack::display.draw_pixels({rect.left(), rect.top() + y, d_width, 1}, line, d_width);
|
||||
}
|
||||
delete line;
|
||||
delete[] line;
|
||||
}
|
||||
|
||||
int8_t BMPViewer::get_zoom() {
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
|
||||
#include "ui_btngrid.hpp"
|
||||
#include "rtc_time.hpp"
|
||||
#include "sd_card.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
namespace ui {
|
||||
|
||||
@@ -42,19 +44,12 @@ BtnGridView::BtnGridView(
|
||||
}
|
||||
button_pgup.set_focusable(false);
|
||||
button_pgup.on_select = [this](Button&) {
|
||||
if (arrow_up_enabled) {
|
||||
if (((int64_t)highlighted_item - displayed_max) > 0)
|
||||
set_highlighted(highlighted_item - displayed_max);
|
||||
else
|
||||
set_highlighted(0);
|
||||
}
|
||||
page_up();
|
||||
};
|
||||
|
||||
button_pgdown.set_focusable(false);
|
||||
button_pgdown.on_select = [this](Button&) {
|
||||
if (arrow_down_enabled) {
|
||||
set_highlighted(highlighted_item + displayed_max);
|
||||
}
|
||||
page_down();
|
||||
};
|
||||
|
||||
button_pgup.set_style(Theme::getInstance()->bg_darkest_small);
|
||||
@@ -143,6 +138,7 @@ void BtnGridView::clear() {
|
||||
// clear vector and release memory, not using swap since it's causing capture to glitch/fault
|
||||
menu_items.clear();
|
||||
|
||||
// TODO(u-foka): Clean up my mess, move this somewhere to clear memory when the view is not visible, but not to be confused with clearing the menu items...
|
||||
for (auto& item : menu_item_views)
|
||||
remove_child(item.get());
|
||||
|
||||
@@ -186,6 +182,13 @@ void BtnGridView::insert_item(const GridItem& new_item, size_t position, bool in
|
||||
}
|
||||
|
||||
void BtnGridView::show_hide_arrows() {
|
||||
// if there are no menu items, disable both arrows and avoid size-1 underflow
|
||||
if (menu_items.empty()) {
|
||||
set_arrow_up_enabled(false);
|
||||
set_arrow_down_enabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (highlighted_item == 0) {
|
||||
set_arrow_up_enabled(false);
|
||||
} else {
|
||||
@@ -198,6 +201,15 @@ void BtnGridView::show_hide_arrows() {
|
||||
}
|
||||
}
|
||||
|
||||
void BtnGridView::reload_items() {
|
||||
menu_items.clear();
|
||||
on_populate();
|
||||
set_highlighted(highlighted_item, true);
|
||||
show_hide_arrows();
|
||||
|
||||
set_dirty(); // Redraw the now potentially empty space as well
|
||||
}
|
||||
|
||||
void BtnGridView::update_items() {
|
||||
size_t i = 0;
|
||||
|
||||
@@ -237,9 +249,20 @@ void BtnGridView::show_arrows_enabled(bool enabled) {
|
||||
}
|
||||
}
|
||||
|
||||
bool BtnGridView::set_highlighted(int32_t new_value) {
|
||||
bool BtnGridView::set_highlighted(int32_t new_value, bool force_update) {
|
||||
int32_t item_count = (int32_t)menu_items.size();
|
||||
|
||||
// nothing to highlight when the list is empty
|
||||
if (item_count == 0) {
|
||||
highlighted_item = 0;
|
||||
offset = 0;
|
||||
show_hide_arrows();
|
||||
if (force_update) {
|
||||
update_items();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (new_value < 0)
|
||||
return false;
|
||||
|
||||
@@ -247,13 +270,15 @@ bool BtnGridView::set_highlighted(int32_t new_value) {
|
||||
new_value = item_count - 1;
|
||||
}
|
||||
|
||||
bool needs_update = false;
|
||||
|
||||
if (((uint32_t)new_value > offset) && ((new_value - offset) >= displayed_max)) {
|
||||
// Shift BtnGridView up
|
||||
highlighted_item = new_value;
|
||||
// rounding up new offset to next multiple of rows
|
||||
offset = new_value - displayed_max + rows_;
|
||||
offset -= (offset % rows_);
|
||||
update_items();
|
||||
needs_update = true;
|
||||
// refresh whole screen (display flickers) only if scrolling last row up and a blank button is needed at the bottom
|
||||
if ((new_value + rows_ >= item_count) && (item_count % rows_) != 0)
|
||||
set_dirty();
|
||||
@@ -261,15 +286,32 @@ bool BtnGridView::set_highlighted(int32_t new_value) {
|
||||
// Shift BtnGridView down
|
||||
highlighted_item = new_value;
|
||||
offset = (new_value / rows_) * rows_;
|
||||
update_items();
|
||||
needs_update = true;
|
||||
// no need to set_dirty() here since all buttons have been repainted
|
||||
} else {
|
||||
// Just update highlight
|
||||
highlighted_item = new_value;
|
||||
}
|
||||
|
||||
if (visible())
|
||||
item_view(highlighted_item - offset)->focus();
|
||||
// Normalize offset to show maximum items when count decreased
|
||||
if (offset + displayed_max > item_count && item_count > 0) {
|
||||
if (item_count >= displayed_max) {
|
||||
offset = item_count - displayed_max;
|
||||
} else {
|
||||
offset = 0;
|
||||
}
|
||||
needs_update = true;
|
||||
}
|
||||
|
||||
if (needs_update || force_update) {
|
||||
update_items();
|
||||
}
|
||||
|
||||
if (visible()) {
|
||||
size_t idx = highlighted_item - offset;
|
||||
if (idx < menu_item_views.size())
|
||||
item_view(idx)->focus();
|
||||
}
|
||||
|
||||
show_hide_arrows();
|
||||
|
||||
@@ -281,7 +323,11 @@ uint32_t BtnGridView::highlighted_index() {
|
||||
}
|
||||
|
||||
void BtnGridView::on_focus() {
|
||||
item_view(highlighted_item - offset)->focus();
|
||||
if (!menu_items.empty()) {
|
||||
size_t idx = highlighted_item - offset;
|
||||
if (idx < menu_item_views.size())
|
||||
item_view(idx)->focus();
|
||||
}
|
||||
}
|
||||
|
||||
void BtnGridView::on_blur() {
|
||||
@@ -292,12 +338,18 @@ void BtnGridView::on_blur() {
|
||||
}
|
||||
|
||||
void BtnGridView::on_show() {
|
||||
on_populate();
|
||||
View::on_show();
|
||||
set_highlighted(highlighted_item);
|
||||
|
||||
sd_card_status_signal_token = sd_card::status_signal += [this](const sd_card::Status /*status*/) {
|
||||
this->reload_items();
|
||||
};
|
||||
|
||||
reload_items();
|
||||
}
|
||||
|
||||
void BtnGridView::on_hide() {
|
||||
sd_card::status_signal -= sd_card_status_signal_token;
|
||||
|
||||
View::on_hide();
|
||||
clear();
|
||||
set_arrow_up_enabled(false);
|
||||
@@ -319,8 +371,10 @@ bool BtnGridView::on_key(const KeyEvent key) {
|
||||
return set_highlighted(highlighted_item - 1);
|
||||
|
||||
case KeyEvent::Select:
|
||||
if (menu_items[highlighted_item].on_select) {
|
||||
menu_items[highlighted_item].on_select();
|
||||
if (!menu_items.empty() && highlighted_item < menu_items.size()) {
|
||||
if (menu_items[highlighted_item].on_select) {
|
||||
menu_items[highlighted_item].on_select();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -370,4 +424,80 @@ bool BtnGridView::blacklisted_app(GridItem new_item) {
|
||||
return std::search(blacklist_ptr.get(), blacklist_ptr.get() + blacklist_len, app_name.begin(), app_name.end()) < blacklist_ptr.get() + blacklist_len;
|
||||
}
|
||||
|
||||
void BtnGridView::page_up() {
|
||||
if (arrow_up_enabled) {
|
||||
size_t item_count = menu_items.size();
|
||||
if (item_count == 0)
|
||||
return;
|
||||
|
||||
size_t new_offset;
|
||||
if (offset > displayed_max) {
|
||||
new_offset = offset - displayed_max;
|
||||
} else {
|
||||
new_offset = 0;
|
||||
}
|
||||
|
||||
// If we can't move further, just move highlight to start
|
||||
if (new_offset == offset) {
|
||||
set_highlighted(0);
|
||||
return;
|
||||
}
|
||||
|
||||
bool was_visible = (highlighted_item >= new_offset && highlighted_item < new_offset + displayed_max);
|
||||
|
||||
offset = new_offset;
|
||||
update_items();
|
||||
|
||||
if (was_visible) {
|
||||
if (visible()) {
|
||||
size_t idx = highlighted_item - offset;
|
||||
if (idx < menu_item_views.size())
|
||||
item_view(idx)->focus();
|
||||
}
|
||||
} else {
|
||||
// focus last item on the new page (clamp to last item overall)
|
||||
size_t last_on_page = std::min(new_offset + displayed_max, item_count) - 1;
|
||||
set_highlighted((int)last_on_page);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BtnGridView::page_down() {
|
||||
if (arrow_down_enabled) {
|
||||
size_t item_count = menu_items.size();
|
||||
if (item_count == 0)
|
||||
return;
|
||||
|
||||
size_t max_offset;
|
||||
if (item_count > displayed_max) {
|
||||
max_offset = item_count - displayed_max;
|
||||
} else {
|
||||
max_offset = 0;
|
||||
}
|
||||
size_t new_offset = std::min(offset + displayed_max, max_offset);
|
||||
|
||||
// If we can't move further, just move highlight to last
|
||||
if (new_offset == offset) {
|
||||
set_highlighted((int)(item_count - 1));
|
||||
return;
|
||||
}
|
||||
|
||||
bool was_visible = (highlighted_item >= new_offset && highlighted_item < new_offset + displayed_max);
|
||||
|
||||
offset = new_offset;
|
||||
update_items();
|
||||
|
||||
if (was_visible) {
|
||||
if (visible()) {
|
||||
size_t idx = highlighted_item - offset;
|
||||
if (idx < menu_item_views.size())
|
||||
item_view(idx)->focus();
|
||||
}
|
||||
} else {
|
||||
// focus first item on the new page
|
||||
set_highlighted((int)new_offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} /* namespace ui */
|
||||
|
||||
@@ -71,7 +71,7 @@ class BtnGridView : public View {
|
||||
bool show_arrows{true}; // flag used to hide arrows in main menu
|
||||
void show_arrows_enabled(bool enabled);
|
||||
|
||||
bool set_highlighted(int32_t new_value);
|
||||
bool set_highlighted(int32_t new_value, bool force_update = false);
|
||||
uint32_t highlighted_index();
|
||||
|
||||
void set_parent_rect(const Rect new_parent_rect) override;
|
||||
@@ -88,11 +88,15 @@ class BtnGridView : public View {
|
||||
bool on_encoder(const EncoderEvent event) override;
|
||||
bool blacklisted_app(GridItem new_item);
|
||||
|
||||
void reload_items();
|
||||
void update_items();
|
||||
void set_btn_height_fixed(uint8_t h) {
|
||||
button_h = h;
|
||||
}
|
||||
|
||||
void page_up();
|
||||
void page_down();
|
||||
|
||||
protected:
|
||||
virtual void on_populate() = 0;
|
||||
|
||||
@@ -116,6 +120,7 @@ class BtnGridView : public View {
|
||||
size_t displayed_max{0};
|
||||
size_t highlighted_item{0};
|
||||
size_t offset{0};
|
||||
SignalToken sd_card_status_signal_token{};
|
||||
};
|
||||
|
||||
} /* namespace ui */
|
||||
|
||||
@@ -265,7 +265,7 @@ void GeoMap::map_read_line_bin(ui::Color* buffer, uint16_t pixels) {
|
||||
|
||||
void GeoMap::draw_markers(Painter& painter) {
|
||||
for (int i = 0; i < markerListLen; ++i) {
|
||||
draw_marker_item(painter, markerList[i], Color::blue(), Color::blue(), Color::magenta());
|
||||
draw_marker_item(painter, markerList[i], markerList[i].color, markerList[i].color, Color::black());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -826,7 +826,7 @@ void GeoMap::update_my_position(float lat, float lon, int32_t altitude) {
|
||||
my_pos.lat = lat;
|
||||
my_pos.lon = lon;
|
||||
my_altitude = altitude;
|
||||
redraw_map = is_changed;
|
||||
redraw_map |= is_changed;
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
@@ -876,8 +876,10 @@ void GeoMapView::update_position(float lat, float lon, uint16_t angle, int32_t a
|
||||
geopos.set_report_change(true);
|
||||
|
||||
geomap.set_angle(angle);
|
||||
if (is_changed) geomap.move(lon_, lat_);
|
||||
geomap.set_dirty();
|
||||
if (is_changed) {
|
||||
geomap.move(lon_, lat_);
|
||||
geomap.set_dirty();
|
||||
}
|
||||
}
|
||||
|
||||
void GeoMapView::update_tag(const std::string tag) {
|
||||
|
||||
@@ -62,13 +62,14 @@ struct GeoMarker {
|
||||
float lon{0};
|
||||
uint16_t angle{0};
|
||||
std::string tag{""};
|
||||
Color color{Color::blue()};
|
||||
|
||||
GeoMarker& operator=(GeoMarker& rhs) {
|
||||
GeoMarker& operator=(const GeoMarker& rhs) {
|
||||
lat = rhs.lat;
|
||||
lon = rhs.lon;
|
||||
angle = rhs.angle;
|
||||
tag = rhs.tag;
|
||||
|
||||
color = rhs.color;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -132,8 +132,8 @@ namespace ui {
|
||||
|
||||
gridItem.on_select = [&nav, appInfo, i]() {
|
||||
auto dev2 = (i2cdev::I2cDev_PPmod*)i2cdev::I2CDevManager::get_dev_by_model(I2C_DEVMDL::I2CDECMDL_PPMOD);
|
||||
dev2->lockDevice();
|
||||
if (dev2) {
|
||||
dev2->lockDevice();
|
||||
// auto app_image = reinterpret_cast<uint8_t*>(portapack::memory::map::m4_code.end() - appInfo->binary_size);
|
||||
auto app_image = reinterpret_cast<uint8_t*>(portapack::memory::map::local_sram_0.base());
|
||||
uint8_t errorcnt = 0;
|
||||
|
||||
@@ -45,11 +45,8 @@
|
||||
#include "ui_mictx.hpp"
|
||||
|
||||
#include "ui_playlist.hpp"
|
||||
#include "ui_pocsag_tx.hpp"
|
||||
#include "ui_rds.hpp"
|
||||
#include "ui_recon.hpp"
|
||||
// #include "ui_scanner.hpp"
|
||||
// #include "ui_sd_over_usb.hpp"
|
||||
#include "ui_search.hpp"
|
||||
#include "ui_settings.hpp"
|
||||
#include "ui_sonde.hpp"
|
||||
@@ -64,7 +61,6 @@
|
||||
|
||||
#include "ais_app.hpp"
|
||||
#include "analog_audio_app.hpp"
|
||||
// #include "ble_comm_app.hpp"
|
||||
#include "ble_rx_app.hpp"
|
||||
#include "ble_tx_app.hpp"
|
||||
#include "capture_app.hpp"
|
||||
@@ -136,7 +132,6 @@ const NavigationView::AppList NavigationView::appList = {
|
||||
{"aprstx", "APRS TX", TX, ui::Color::green(), &bitmap_icon_aprs, new ViewFactory<APRSTXView>()},
|
||||
{"bletx", "BLE Tx", TX, ui::Color::green(), &bitmap_icon_btle, new ViewFactory<BLETxView>()},
|
||||
{"ooktx", "OOK", TX, ui::Color::yellow(), &bitmap_icon_remote, new ViewFactory<EncodersView>()},
|
||||
{"pocsagtx", "POCSAG TX", TX, ui::Color::green(), &bitmap_icon_pocsag, new ViewFactory<POCSAGTXView>()},
|
||||
{"rdstx", "RDS", TX, ui::Color::green(), &bitmap_icon_rds, new ViewFactory<RDSView>()},
|
||||
{"touchtune", "TouchTune", TX, ui::Color::green(), &bitmap_icon_touchtunes, new ViewFactory<TouchTunesView>()},
|
||||
/* TRX ********************************************************************/
|
||||
@@ -146,7 +141,6 @@ const NavigationView::AppList NavigationView::appList = {
|
||||
{"freqman", "Freq. Manager", UTILITIES, Color::green(), &bitmap_icon_freqman, new ViewFactory<FrequencyManagerView>()},
|
||||
{"iqtrim", "IQ Trim", UTILITIES, Color::orange(), &bitmap_icon_trim, new ViewFactory<IQTrimView>()},
|
||||
{"notepad", "Notepad", UTILITIES, Color::dark_cyan(), &bitmap_icon_notepad, new ViewFactory<TextEditorView>()},
|
||||
//{nullptr, "SD Over USB", UTILITIES, Color::yellow(), &bitmap_icon_hackrf, new ViewFactory<SdOverUsbView>()},
|
||||
{nullptr, "Debug", UTILITIES, Color::light_grey(), &bitmap_icon_debug, new ViewFactory<DebugMenuView>()},
|
||||
//{"testapp", "Test App", UTILITIES, Color::dark_grey(), nullptr, new ViewFactory<TestView>()},
|
||||
// Dangerous apps.
|
||||
@@ -777,8 +771,6 @@ void add_apps(NavigationView& nav, BtnGridView& grid, app_location_t loc) {
|
||||
true);
|
||||
}
|
||||
};
|
||||
|
||||
grid.update_items();
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
@@ -795,7 +787,7 @@ void add_external_items(NavigationView& nav, app_location_t location, BtnGridVie
|
||||
"Check SD card\n"
|
||||
"Update SD card content\n");
|
||||
}},
|
||||
error_tile_pos);
|
||||
error_tile_pos, true);
|
||||
} else {
|
||||
std::sort(externalItems.begin(), externalItems.end(), [](const auto &a, const auto &b)
|
||||
{
|
||||
@@ -810,8 +802,6 @@ void add_external_items(NavigationView& nav, app_location_t location, BtnGridVie
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
grid.update_items();
|
||||
}
|
||||
}
|
||||
// clang-format on
|
||||
@@ -830,7 +820,8 @@ ReceiversMenuView::ReceiversMenuView(NavigationView& nav)
|
||||
void ReceiversMenuView::on_populate() {
|
||||
bool return_icon = pmem::show_gui_return_icon();
|
||||
if (return_icon) {
|
||||
add_item({"..", Theme::getInstance()->fg_light->foreground, &bitmap_icon_previous, [this]() { nav_.pop(); }});
|
||||
add_item({"..", Theme::getInstance()->fg_light->foreground, &bitmap_icon_previous, [this]() { nav_.pop(); }},
|
||||
true);
|
||||
}
|
||||
add_apps(nav_, *this, RX);
|
||||
add_external_items(nav_, app_location_t::RX, *this, return_icon ? 1 : 0);
|
||||
@@ -919,14 +910,15 @@ SystemMenuView::SystemMenuView(NavigationView& nav)
|
||||
}
|
||||
|
||||
void SystemMenuView::on_populate() {
|
||||
if (!verify_sdcard_format()) {
|
||||
add_item({"SDCard Error", Theme::getInstance()->error_dark->foreground, nullptr, [this]() {
|
||||
nav_.display_modal("Error", "SD Card is not exFAT/FAT32");
|
||||
}});
|
||||
}
|
||||
add_apps(nav_, *this, HOME);
|
||||
add_external_items(nav_, app_location_t::HOME, *this, 0);
|
||||
add_item({"HackRF", Theme::getInstance()->fg_cyan->foreground, &bitmap_icon_hackrf, [this]() { hackrf_mode(nav_); }});
|
||||
if (!verify_sdcard_format()) { // Moved to the end... after sd status change event, fstype wasn't populated fast enough..
|
||||
insert_item({"SDCard Error", Theme::getInstance()->error_dark->foreground, nullptr, [this]() {
|
||||
nav_.display_modal("Error", "SD Card is not exFAT/FAT32");
|
||||
}},
|
||||
0, true);
|
||||
}
|
||||
}
|
||||
|
||||
/* SystemView ************************************************************/
|
||||
@@ -976,6 +968,8 @@ SystemView::SystemView(
|
||||
|
||||
navigation_view.push<SystemMenuView>();
|
||||
|
||||
add_child(¬ification_view);
|
||||
|
||||
if (pmem::config_splash()) {
|
||||
navigation_view.push<SplashScreenView>();
|
||||
}
|
||||
@@ -1061,20 +1055,10 @@ SplashScreenView::SplashScreenView(NavigationView& nav)
|
||||
};
|
||||
}
|
||||
|
||||
uint32_t SplashScreenView::myrand(uint32_t* state) {
|
||||
uint32_t x = *state;
|
||||
x ^= x << 13;
|
||||
x ^= x >> 17;
|
||||
x ^= x << 5;
|
||||
*state = x;
|
||||
return x;
|
||||
}
|
||||
|
||||
void SplashScreenView::get_random_splash_file(std::filesystem::path& path) {
|
||||
path = u"";
|
||||
|
||||
uint32_t rng_state = LPC_RTC->CTIME0;
|
||||
if (rng_state == 0) rng_state = 0xABBACAFE;
|
||||
srand(LPC_RTC->CTIME0);
|
||||
|
||||
DIR dir;
|
||||
FILINFO fno;
|
||||
@@ -1096,7 +1080,7 @@ void SplashScreenView::get_random_splash_file(std::filesystem::path& path) {
|
||||
(ext[3] == 'P' || ext[3] == 'p')) {
|
||||
valid_count++;
|
||||
// Reservoir Sampling:
|
||||
if (((rng_state = myrand(&rng_state)) % valid_count) == 0) {
|
||||
if ((rand() % valid_count) == 0) {
|
||||
path = splash_dir / fno.fname;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#include "ui_audio.hpp"
|
||||
#include "ui_sd_card_status_view.hpp"
|
||||
#include "ui_dfu_menu.hpp"
|
||||
|
||||
#include "ui_notifications.hpp"
|
||||
#include "bitmap.hpp"
|
||||
#include "ui_bmpview.hpp"
|
||||
#include "ff.h"
|
||||
@@ -366,7 +366,6 @@ class SplashScreenView : public View {
|
||||
Button button_done{
|
||||
{screen_width, 0, 1, 1},
|
||||
""};
|
||||
uint32_t myrand(uint32_t* state);
|
||||
void get_random_splash_file(std::filesystem::path& path);
|
||||
};
|
||||
|
||||
@@ -447,11 +446,12 @@ class SystemView : public View {
|
||||
private:
|
||||
uint8_t overlay_active{0};
|
||||
|
||||
NavigationView navigation_view{};
|
||||
SystemStatusView status_view{navigation_view};
|
||||
InformationView info_view{navigation_view};
|
||||
NotificationView notification_view{navigation_view};
|
||||
DfuMenu overlay{navigation_view};
|
||||
DfuMenu2 overlay2{navigation_view};
|
||||
NavigationView navigation_view{};
|
||||
Context& context_;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
#include "ui_notifications.hpp"
|
||||
|
||||
#include "ui_navigation.hpp"
|
||||
|
||||
extern ui::SystemView* system_view_ptr;
|
||||
|
||||
namespace ui {
|
||||
|
||||
NotificationEntryView::NotificationEntryView(const NotificationEntry& entry, NotificationView* notifhandler)
|
||||
: entry_(entry), notifhandler_(notifhandler) {
|
||||
add_children({&background, &border, &title_text, &message_text, &close_button});
|
||||
border.set_outline(true);
|
||||
if (entry_.icon != NOTIF_ICON_NONE) {
|
||||
add_child(&icon_image);
|
||||
icon_image.set_parent_rect({UI_POS_X(0) + 2, UI_POS_Y(1), UI_POS_WIDTH(2), UI_POS_HEIGHT(1)});
|
||||
message_text.set_parent_rect({UI_POS_X(2) + 2, UI_POS_Y(1), UI_POS_WIDTH_REMAINING(6) - 2, UI_POS_HEIGHT(2)});
|
||||
if (entry_.icon == NOTIF_ICON_MESSAGE) {
|
||||
icon_image.set_bitmap(&bitmap_icon_pocsag);
|
||||
}
|
||||
|
||||
} else {
|
||||
message_text.set_parent_rect({UI_POS_X(1), UI_POS_Y(1), UI_POS_WIDTH_REMAINING(5) - 1, UI_POS_HEIGHT(2)});
|
||||
}
|
||||
title_text.set_style(Theme::getInstance()->bg_dark);
|
||||
title_text.set(entry_.title);
|
||||
message_text.set_style(Theme::getInstance()->bg_darkest);
|
||||
message_text.set(entry_.message);
|
||||
|
||||
close_button.on_select = [this](Button&) {
|
||||
if (notifhandler_) {
|
||||
notifhandler_->remove_notification(entry_.id);
|
||||
}
|
||||
};
|
||||
|
||||
message_text.on_select = [this](Text&) {
|
||||
if (!entry_.source_app.empty() && notifhandler_) {
|
||||
notifhandler_->open_notification(entry_.source_app);
|
||||
// notifhandler_->remove_notification(entry_.id);
|
||||
}
|
||||
};
|
||||
title_text.on_select = message_text.on_select;
|
||||
}
|
||||
|
||||
NotificationView::NotificationView(NavigationView& nav)
|
||||
: nav_(nav) {
|
||||
signal_token_tick_second = rtc_time::signal_tick_second += [this]() {
|
||||
this->on_tick_second();
|
||||
};
|
||||
}
|
||||
|
||||
NotificationView::~NotificationView() {
|
||||
rtc_time::signal_tick_second -= signal_token_tick_second;
|
||||
}
|
||||
|
||||
void NotificationView::on_tick_second() {
|
||||
bool changed = false;
|
||||
for (size_t i = 0; i < notification_views_.size();) {
|
||||
if (notification_views_[i]->entry()->increase_time(1000)) {
|
||||
notification_views_.erase(notification_views_.begin() + i);
|
||||
changed = true;
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
rearrange_notifications();
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationView::rearrange_notifications() {
|
||||
size_t count = children().size();
|
||||
while (children().size() > 0) {
|
||||
remove_child(children().back());
|
||||
}
|
||||
|
||||
const int entry_height = UI_POS_HEIGHT(3) + 1;
|
||||
int index = 0;
|
||||
|
||||
for (auto& view_ptr : notification_views_) {
|
||||
view_ptr->set_parent_rect({UI_POS_X(0),
|
||||
(Coord)(UI_POS_Y(0) + (index * entry_height)),
|
||||
UI_POS_MAXWIDTH,
|
||||
entry_height});
|
||||
add_child(view_ptr.get());
|
||||
index++;
|
||||
}
|
||||
|
||||
set_parent_rect({UI_POS_X(0), UI_POS_Y(0), UI_POS_MAXWIDTH, (Coord)(notification_views_.size() * entry_height)});
|
||||
set_dirty();
|
||||
if (count != children().size()) {
|
||||
// refresh screen!!!
|
||||
system_view_ptr->set_dirty();
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationView::add_notification(NotificationEntry& entry) {
|
||||
if (notification_views_.size() >= max_notifications) {
|
||||
notification_views_.erase(notification_views_.begin());
|
||||
}
|
||||
|
||||
entry.id = ++curr_not_id;
|
||||
notification_views_.push_back(std::make_unique<NotificationEntryView>(entry, this));
|
||||
|
||||
rearrange_notifications();
|
||||
}
|
||||
|
||||
void NotificationView::remove_notification(uint16_t id) {
|
||||
bool found = false;
|
||||
size_t found_index = 0;
|
||||
|
||||
for (size_t i = 0; i < notification_views_.size(); i++) {
|
||||
if (notification_views_[i]->id() == id) {
|
||||
found = true;
|
||||
found_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
notification_views_.erase(notification_views_.begin() + found_index);
|
||||
rearrange_notifications();
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationView::open_notification(std::string app_name) {
|
||||
if (app_name.empty()) return;
|
||||
nav_.StartAppByName(app_name.c_str());
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
@@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "ui.hpp"
|
||||
#include "ui_widget.hpp"
|
||||
#include "signal.hpp"
|
||||
#include "rtc_time.hpp"
|
||||
#include "event_m0.hpp"
|
||||
|
||||
namespace ui {
|
||||
|
||||
class NotificationView;
|
||||
class NavigationView;
|
||||
|
||||
enum notification_icon_t : uint8_t {
|
||||
NOTIF_ICON_NONE = 0,
|
||||
NOTIF_ICON_MESSAGE
|
||||
};
|
||||
|
||||
class NotificationEntry {
|
||||
public:
|
||||
std::string source_app{};
|
||||
std::string title{};
|
||||
std::string message{};
|
||||
notification_icon_t icon = NOTIF_ICON_NONE;
|
||||
uint16_t timeout = 10000;
|
||||
uint16_t id = 0;
|
||||
|
||||
NotificationEntry() = default;
|
||||
NotificationEntry(const std::string& source_app, const std::string& title, const std::string& message, notification_icon_t icon = NOTIF_ICON_NONE, uint16_t timeout = 10000, uint16_t id = 0)
|
||||
: source_app(source_app), title(title), message(message), icon(icon), timeout(timeout), id(id) {}
|
||||
|
||||
static NotificationEntry build(const std::string& source_app, const std::string& title, const std::string& message, notification_icon_t icon = NOTIF_ICON_NONE, uint16_t timeout = 10000) {
|
||||
return NotificationEntry{source_app, title, message, icon, timeout, 0};
|
||||
}
|
||||
|
||||
bool increase_time(uint16_t delta) {
|
||||
current_time += delta;
|
||||
return (current_time >= timeout);
|
||||
}
|
||||
|
||||
private:
|
||||
uint16_t current_time = 0;
|
||||
};
|
||||
|
||||
class NotificationEntryView : public View {
|
||||
public:
|
||||
NotificationEntryView(const NotificationEntry& entry, NotificationView* notifhandler);
|
||||
|
||||
NotificationEntryView(const NotificationEntryView&) = delete;
|
||||
NotificationEntryView& operator=(const NotificationEntryView&) = delete;
|
||||
|
||||
ui::Rectangle background{{1, 1, UI_POS_MAXWIDTH - 2, UI_POS_HEIGHT(3) - 2}, Theme::getInstance()->bg_darkest->background};
|
||||
ui::Rectangle border{{0, 0, UI_POS_MAXWIDTH, UI_POS_HEIGHT(3) + 1}, Theme::getInstance()->bg_light->background};
|
||||
ui::Text title_text{{UI_POS_X(0) + 1, UI_POS_Y(0) + 1, UI_POS_WIDTH_REMAINING(4) - 3, UI_POS_HEIGHT(1)}, ""};
|
||||
ui::Text message_text{{UI_POS_X(1), UI_POS_Y(1), UI_POS_WIDTH_REMAINING(5) - 1, UI_POS_HEIGHT(2)}, ""};
|
||||
ui::Image icon_image{}; // 16*16 bitmap
|
||||
ui::Button close_button{{UI_POS_X_RIGHT(4) - 2, UI_POS_Y(0) + 1, UI_POS_WIDTH(4), UI_POS_HEIGHT(2)}, "X"};
|
||||
|
||||
uint16_t id() const { return entry_.id; }
|
||||
NotificationEntry* entry() { return &entry_; }
|
||||
|
||||
private:
|
||||
NotificationEntry entry_;
|
||||
NotificationView* notifhandler_;
|
||||
};
|
||||
|
||||
class NotificationView : public View {
|
||||
public:
|
||||
NotificationView(NavigationView& nav);
|
||||
~NotificationView();
|
||||
|
||||
void add_notification(NotificationEntry& entry);
|
||||
void remove_notification(uint16_t id);
|
||||
void open_notification(std::string app_name);
|
||||
|
||||
private:
|
||||
void on_tick_second();
|
||||
void rearrange_notifications();
|
||||
|
||||
NavigationView& nav_;
|
||||
|
||||
// Changed to unique_ptr to handle non-copyable Views safely
|
||||
std::vector<std::unique_ptr<NotificationEntryView>> notification_views_{};
|
||||
|
||||
SignalToken signal_token_tick_second{};
|
||||
|
||||
uint16_t curr_not_id = 0;
|
||||
constexpr static uint8_t max_notifications = 4;
|
||||
|
||||
MessageHandlerRegistration message_handler_notifs{
|
||||
Message::ID::NotificationData, [this](Message* const p) {
|
||||
const auto message = static_cast<const NotificationDataMessage*>(p);
|
||||
NotificationEntry entry = NotificationEntry::build(message->source_app, message->title, message->message, static_cast<notification_icon_t>(message->icon), message->timeout);
|
||||
this->add_notification(entry);
|
||||
}};
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
@@ -105,26 +105,23 @@ static void cmd_sd_over_usb(BaseSequentialStream* chp, int argc, char* argv[]) {
|
||||
(void)chp;
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
ui::Painter painter;
|
||||
painter.fill_rectangle(
|
||||
{0, 0, portapack::display.width(), portapack::display.height()},
|
||||
Theme::getInstance()->fg_yellow->background);
|
||||
|
||||
painter.draw_bitmap(
|
||||
{portapack::display.width() / 2 - 8, portapack::display.height() / 2 - 8},
|
||||
ui::bitmap_icon_hackrf,
|
||||
Theme::getInstance()->fg_yellow->foreground,
|
||||
Theme::getInstance()->fg_yellow->background);
|
||||
|
||||
sdcDisconnect(&SDCD1);
|
||||
sdcStop(&SDCD1);
|
||||
|
||||
m4_request_shutdown();
|
||||
chThdSleepMilliseconds(50);
|
||||
portapack::shutdown(true);
|
||||
m4_init(portapack::spi_flash::image_tag_usb_sd, portapack::memory::map::m4_code, false);
|
||||
m0_halt();
|
||||
auto evtd = getEventDispatcherInstance();
|
||||
if (!evtd) return;
|
||||
auto top_widget = evtd->getTopWidget();
|
||||
if (!top_widget) return;
|
||||
auto nav = static_cast<ui::SystemView*>(top_widget)->get_navigation_view();
|
||||
if (!nav) return;
|
||||
nav->home(false);
|
||||
std::string appwithpath = "/" + apps_dir.string() + "/";
|
||||
appwithpath += "sdusb.ppma";
|
||||
bool ret = ui::ExternalItemsMenuLoader::run_external_app(*nav, path_from_string8((char*)appwithpath.c_str()));
|
||||
if (ret) {
|
||||
chprintf(chp, "ok\r\n");
|
||||
} else {
|
||||
chprintf(chp, "Failed to start SD over USB\r\n");
|
||||
}
|
||||
evtd->wait_finish_frame();
|
||||
evtd->emulateKeyboard('\n');
|
||||
}
|
||||
|
||||
bool strEndsWith(const std::u16string& str, const std::u16string& suffix) {
|
||||
@@ -1144,7 +1141,7 @@ static void cmd_gotenv(BaseSequentialStream* chp, int argc, char* argv[]) {
|
||||
uint16_t light = 0;
|
||||
if (argc > 1) humi = atof(argv[1]);
|
||||
if (argc > 2) pressure = atof(argv[2]);
|
||||
if (argc > 3) light = strtol(argv[0], NULL, 10);
|
||||
if (argc > 3) light = strtol(argv[3], NULL, 10);
|
||||
EnvironmentDataMessage msg{temp, humi, pressure};
|
||||
EventDispatcher::send_message(msg);
|
||||
// compatibility:
|
||||
@@ -1386,22 +1383,76 @@ static void cmd_getres(BaseSequentialStream* chp, int argc, char* argv[]) {
|
||||
static void cmd_getflash(BaseSequentialStream* chp, int argc, char* argv[]) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
uint8_t allowrun = FLASH_SIZE_MB;
|
||||
// FLASH_SIZE_LIMIT_MB may be a float (e.g. 3.5 for HPro), always cast explicitly.
|
||||
uint8_t allowrun;
|
||||
#ifdef PRALINE
|
||||
allowrun = 4; // HackRF Pro
|
||||
#else
|
||||
if (portapack::device_type == portapack::DeviceType::DEV_PORTAPACK) {
|
||||
allowrun = 1;
|
||||
allowrun = 1; // PortaPack classic
|
||||
} else {
|
||||
allowrun = FLASH_SIZE_MB; // PortaRF
|
||||
}
|
||||
std::string res = "ALLOWEDFW:" + to_string_dec_uint(FLASH_SIZE_MB) + "\r\nALLOWEDRUNTIME:" + to_string_dec_uint(allowrun) + "\r\nCURRENT:" + to_string_dec_uint(FLASH_SIZE_LIMIT_MB) + "\r\nok\r\n";
|
||||
#endif
|
||||
std::string res = "ALLOWEDFW:" + to_string_dec_uint((uint32_t)FLASH_SIZE_MB) + "\r\nALLOWEDRUNTIME:" + to_string_dec_uint((uint32_t)allowrun) + "\r\nCURRENT:" + to_string_dec_uint((uint32_t)FLASH_SIZE_LIMIT_MB) + "\r\nok\r\n";
|
||||
chprintf(chp, res.c_str());
|
||||
}
|
||||
|
||||
static void cmd_getdevtype(BaseSequentialStream* chp, int argc, char* argv[]) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
std::string res = portapack::device_type == portapack::DeviceType::DEV_PORTARF ? "PORTARF" : "PORTAPACK";
|
||||
std::string res;
|
||||
#ifdef PRALINE
|
||||
res = "HPRO";
|
||||
#else
|
||||
if (portapack::device_type == portapack::DeviceType::DEV_PORTARF) {
|
||||
res = "PORTARF";
|
||||
} else {
|
||||
res = "PORTAPACK";
|
||||
}
|
||||
#endif
|
||||
res += "\r\nok\r\n";
|
||||
chprintf(chp, res.c_str());
|
||||
}
|
||||
|
||||
static void cmd_notification(BaseSequentialStream* chp, int argc, char* argv[]) {
|
||||
const char* usage = "usage: notif <iconindex> [appname]\r\n";
|
||||
if (argc < 1) {
|
||||
chprintf(chp, usage);
|
||||
return;
|
||||
}
|
||||
int iconindex = atoi(argv[0]);
|
||||
std::string appname = (argc > 1) ? argv[1] : "";
|
||||
chprintf(chp, "Send title, and a <CR>\r\n");
|
||||
std::string title{};
|
||||
uint8_t msg[1]{0};
|
||||
do {
|
||||
size_t bytes_read = chSequentialStreamRead(chp, &msg[0], 1);
|
||||
if (bytes_read != 1)
|
||||
break;
|
||||
if (msg[0] == '\r') // end of title
|
||||
break;
|
||||
if (msg[0] == '\n') continue;
|
||||
title += (char)msg[0];
|
||||
} while (title.size() < 48);
|
||||
std::string message{};
|
||||
chprintf(chp, "Send message, and a <CR>\r\n");
|
||||
do {
|
||||
size_t bytes_read = chSequentialStreamRead(chp, &msg[0], 1);
|
||||
if (bytes_read != 1)
|
||||
break;
|
||||
if (msg[0] == '\r') // end of message
|
||||
break;
|
||||
if (msg[0] == '\n') continue;
|
||||
message += (char)msg[0];
|
||||
} while (message.size() < 298);
|
||||
|
||||
NotificationDataMessage msgn{appname.c_str(), title.c_str(), message.c_str(), (uint8_t)iconindex};
|
||||
EventDispatcher::send_message(msgn);
|
||||
|
||||
chprintf(chp, "ok\r\n");
|
||||
}
|
||||
|
||||
static const ShellCommand commands[] = {
|
||||
{"reboot", cmd_reboot},
|
||||
{"dfu", cmd_dfu},
|
||||
@@ -1440,6 +1491,7 @@ static const ShellCommand commands[] = {
|
||||
{"getres", cmd_getres},
|
||||
{"getflash", cmd_getflash},
|
||||
{"getdevtype", cmd_getdevtype},
|
||||
{"notif", cmd_notification},
|
||||
{NULL, NULL}};
|
||||
|
||||
static const ShellConfig shell_cfg1 = {
|
||||
|
||||
@@ -148,7 +148,11 @@ void cmd_sd_open(BaseSequentialStream* chp, int argc, char* argv[]) {
|
||||
auto path = path_from_string8((char*)full_fn_from_args(argc, argv).c_str());
|
||||
shell_file = new File();
|
||||
auto error = shell_file->open(path, false, true);
|
||||
if (report_on_error(chp, error)) return;
|
||||
if (report_on_error(chp, error)) {
|
||||
delete shell_file;
|
||||
shell_file = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
chprintf(chp, "ok\r\n");
|
||||
}
|
||||
|
||||
@@ -467,6 +467,7 @@ set(MODE_CPPSRC
|
||||
)
|
||||
DeclareTargets(PSPE wideband_spectrum)
|
||||
|
||||
|
||||
### WFM Audio
|
||||
|
||||
set(MODE_CPPSRC
|
||||
@@ -705,6 +706,13 @@ set(MODE_CPPSRC
|
||||
)
|
||||
DeclareTargets(PMRT morsetx)
|
||||
|
||||
### Time Sink
|
||||
|
||||
set(MODE_CPPSRC
|
||||
proc_time_sink.cpp
|
||||
)
|
||||
DeclareTargets(PTSK time_sink)
|
||||
|
||||
set(MODE_CPPSRC
|
||||
sd_over_usb/proc_sd_over_usb.cpp
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ So include here the .hpp, and add a new element to the protos vector in the cons
|
||||
|
||||
class SubCarProtos : public FProtoListGeneral {
|
||||
public:
|
||||
SubCarProtos(const SubCarProtos&) { SubCarProtos(); }; // won't use, but makes compiler happy
|
||||
SubCarProtos& operator=(const SubCarProtos&) { return *this; } // won't use, but makes compiler happy
|
||||
SubCarProtos(const SubCarProtos&) = delete;
|
||||
SubCarProtos& operator=(const SubCarProtos&) = delete;
|
||||
SubCarProtos() {
|
||||
// add protos
|
||||
protos[FPC_SUZUKI] = new FProtoSubCarSuzuki();
|
||||
|
||||
@@ -62,8 +62,8 @@ So include here the .hpp, and add a new element to the protos vector in the cons
|
||||
|
||||
class SubGhzDProtos : public FProtoListGeneral {
|
||||
public:
|
||||
SubGhzDProtos(const SubGhzDProtos&) { SubGhzDProtos(); }; // won't use, but makes compiler happy
|
||||
SubGhzDProtos& operator=(const SubGhzDProtos&) { return *this; } // won't use, but makes compiler happy
|
||||
SubGhzDProtos(const SubGhzDProtos&) = delete;
|
||||
SubGhzDProtos& operator=(const SubGhzDProtos&) = delete;
|
||||
SubGhzDProtos() {
|
||||
// add protos
|
||||
protos[FPS_PRINCETON] = new FProtoSubGhzDPrinceton();
|
||||
|
||||
@@ -41,8 +41,8 @@ So include here the .hpp, and add a new element to the protos vector in the cons
|
||||
|
||||
class WeatherProtos : public FProtoListGeneral {
|
||||
public:
|
||||
WeatherProtos(const WeatherProtos&) { WeatherProtos(); }; // won't use, but makes compiler happy
|
||||
WeatherProtos& operator=(const WeatherProtos&) { return *this; } // won't use, but makes compiler happy
|
||||
WeatherProtos(const WeatherProtos&) = delete;
|
||||
WeatherProtos& operator=(const WeatherProtos&) = delete;
|
||||
WeatherProtos() {
|
||||
// add protos
|
||||
protos[FPW_NexusTH] = new FProtoWeatherNexusTH();
|
||||
|
||||
@@ -195,7 +195,7 @@ void BTLETxProcessor::scramble(char* bit_in, int num_bit, int channel_number, ch
|
||||
void BTLETxProcessor::disp_bit_in_hex(char* bit, int num_bit) {
|
||||
int i, a;
|
||||
|
||||
for (i = 0; i < num_bit; i = i + 8) {
|
||||
for (i = 0; i + 7 < num_bit; i = i + 8) {
|
||||
a = bit[i] + bit[i + 1] * 2 + bit[i + 2] * 4 + bit[i + 3] * 8 + bit[i + 4] * 16 + bit[i + 5] * 32 + bit[i + 6] * 64 + bit[i + 7] * 128;
|
||||
|
||||
data_message.is_data = true;
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
#include "debug.hpp"
|
||||
#include "portapack_shared_memory.hpp"
|
||||
|
||||
#include "../flashsize.h"
|
||||
|
||||
#define PAGE_LEN 256U
|
||||
#define NUM_PAGES (4096U * FLASH_SIZE_MB)
|
||||
|
||||
|
||||
@@ -101,6 +101,10 @@ void MicTXProcessor::on_message(const Message* const msg) {
|
||||
|
||||
switch (msg->id) {
|
||||
case Message::ID::AudioTXConfig:
|
||||
if (modulator) {
|
||||
delete modulator;
|
||||
modulator = NULL;
|
||||
}
|
||||
if (fm_enabled) {
|
||||
dsp::modulate::FM* fm = new dsp::modulate::FM();
|
||||
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyleft zxkmm (>) 2026
|
||||
*
|
||||
* 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 "proc_time_sink.hpp"
|
||||
|
||||
#include "event_m4.hpp"
|
||||
#include "portapack_shared_memory.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
void TimeSinkProcessor::execute(const buffer_c8_t& buffer) {
|
||||
// 2048 complex8_t samples per buffer.
|
||||
// 102.4us per buffer. 20480 instruction cycles per buffer.
|
||||
|
||||
if (!configured) {
|
||||
return;
|
||||
}
|
||||
|
||||
execute_time_domain(buffer);
|
||||
}
|
||||
|
||||
void TimeSinkProcessor::execute_time_domain(const buffer_c8_t& buffer) {
|
||||
if (!time_streaming || buffer.count == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (phase < trigger) {
|
||||
phase++;
|
||||
return;
|
||||
}
|
||||
|
||||
phase = 0;
|
||||
|
||||
if (time_domain_request_update) {
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t stride = std::max<size_t>(1, buffer.count / time_domain_spectrum.db.size());
|
||||
time_domain_spectrum.sampling_rate = buffer.sampling_rate / stride;
|
||||
time_domain_spectrum.channel_filter_low_frequency = 0;
|
||||
time_domain_spectrum.channel_filter_high_frequency = 0;
|
||||
time_domain_spectrum.channel_filter_transition = 0;
|
||||
|
||||
for (size_t i = 0; i < time_domain_spectrum.db.size(); i++) {
|
||||
const size_t sample_index = std::min(i * stride, buffer.count - 1);
|
||||
const int32_t normalized = std::clamp<int32_t>(
|
||||
static_cast<int32_t>(buffer.p[sample_index].real()) + 128,
|
||||
0,
|
||||
255);
|
||||
time_domain_spectrum.db[i] = static_cast<uint8_t>(normalized);
|
||||
}
|
||||
|
||||
time_domain_request_update = true;
|
||||
EventDispatcher::events_flag(EVT_MASK_SPECTRUM);
|
||||
}
|
||||
|
||||
void TimeSinkProcessor::set_time_streaming_state(const SpectrumStreamingConfigMessage& message) {
|
||||
if (message.mode == SpectrumStreamingConfigMessage::Mode::Running) {
|
||||
time_streaming = true;
|
||||
ChannelSpectrumConfigMessage fifo_message{&fifo};
|
||||
shared_memory.application_queue.push(fifo_message);
|
||||
} else {
|
||||
time_streaming = false;
|
||||
time_domain_request_update = false;
|
||||
fifo.reset_in();
|
||||
}
|
||||
}
|
||||
|
||||
void TimeSinkProcessor::update_time_domain() {
|
||||
if (time_streaming && time_domain_request_update) {
|
||||
fifo.in(time_domain_spectrum);
|
||||
}
|
||||
|
||||
time_domain_request_update = false;
|
||||
}
|
||||
|
||||
void TimeSinkProcessor::on_message(const Message* const msg) {
|
||||
switch (msg->id) {
|
||||
case Message::ID::UpdateSpectrum:
|
||||
update_time_domain();
|
||||
break;
|
||||
|
||||
case Message::ID::SpectrumStreamingConfig:
|
||||
set_time_streaming_state(*reinterpret_cast<const SpectrumStreamingConfigMessage*>(msg));
|
||||
break;
|
||||
|
||||
case Message::ID::TimeSinkConfig: {
|
||||
const auto& message = *reinterpret_cast<const TimeSinkConfigMessage*>(msg);
|
||||
baseband_fs = message.sampling_rate;
|
||||
trigger = message.trigger;
|
||||
baseband_thread.set_sampling_rate(baseband_fs);
|
||||
phase = 0;
|
||||
time_domain_request_update = false;
|
||||
configured = true;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
EventDispatcher event_dispatcher{std::make_unique<TimeSinkProcessor>()};
|
||||
event_dispatcher.run();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyleft zxkmm (>) 2026
|
||||
*
|
||||
* 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 __PROC_TIME_SINK_H__
|
||||
#define __PROC_TIME_SINK_H__
|
||||
|
||||
#include "baseband_processor.hpp"
|
||||
#include "baseband_thread.hpp"
|
||||
|
||||
#include "message.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
class TimeSinkProcessor : public BasebandProcessor {
|
||||
public:
|
||||
void execute(const buffer_c8_t& buffer) override;
|
||||
void on_message(const Message* const message) override;
|
||||
|
||||
private:
|
||||
bool configured = false;
|
||||
size_t baseband_fs = 20000000;
|
||||
|
||||
void execute_time_domain(const buffer_c8_t& buffer);
|
||||
void set_time_streaming_state(const SpectrumStreamingConfigMessage& message);
|
||||
void update_time_domain();
|
||||
ChannelSpectrum time_domain_spectrum{};
|
||||
ChannelSpectrum fifo_data[1 << ChannelSpectrumConfigMessage::fifo_k]{};
|
||||
ChannelSpectrumFIFO fifo{fifo_data, ChannelSpectrumConfigMessage::fifo_k};
|
||||
|
||||
size_t phase = 0, trigger = 127;
|
||||
bool time_streaming = false;
|
||||
volatile bool time_domain_request_update = false;
|
||||
|
||||
/* NB: Threads should be the last members in the class definition. */
|
||||
BasebandThread baseband_thread{baseband_fs, this, baseband::Direction::Receive};
|
||||
};
|
||||
|
||||
#endif /*__PROC_TIME_SINK_H__*/
|
||||
@@ -24,13 +24,6 @@
|
||||
// Declare wrapper function. board.cpp to avoid conflicting gpio_t definitions.
|
||||
bool hackrf_r9;
|
||||
|
||||
// Declare the bridge function (no need to include HackRF headers here)
|
||||
#ifdef PRALINE
|
||||
extern "C" {
|
||||
int fpga_bridge_init(void);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HAL_USE_PAL || defined(__DOXYGEN__)
|
||||
/**
|
||||
* @brief PAL setup.
|
||||
@@ -61,7 +54,11 @@ const PALConfig pal_default_config = {
|
||||
.P = {
|
||||
{ // GPIO0
|
||||
.data
|
||||
#ifdef PRALINE
|
||||
= (0 << 15) // P1_20: CLKIN_CTRL - start low
|
||||
#else
|
||||
= (1 << 15) // P1_20: CS_XCVR
|
||||
#endif
|
||||
| (1 << 14) // P2_10: AMP_BYPASS
|
||||
| (0 << 13) // P1_18: SGPIO12, HOST_Q_INVERT
|
||||
| (0 << 12) // P1_17: SGPIO11, HOST_DIRECTION
|
||||
@@ -79,8 +76,12 @@ const PALConfig pal_default_config = {
|
||||
| (1 << 0) // P0_0: SGPIO0, HOST_DATA0
|
||||
,
|
||||
.dir
|
||||
#ifdef PRALINE
|
||||
= (1 << 15) // P1_20: CLKIN_CTRL - output
|
||||
#else
|
||||
= (1 << 15) // P1_20: CS_XCVR
|
||||
| (1 << 14) // P2_10: AMP_BYPASS
|
||||
#endif
|
||||
| (1 << 14) // P2_10: AMP_BYPASS
|
||||
| (1 << 13) // P1_18: SGPIO12, HOST_Q_INVERT
|
||||
| (0 << 12) // P1_17: SGPIO11, HOST_DIRECTION
|
||||
| (0 << 11) // P1_4: SSP1_MOSI
|
||||
@@ -137,7 +138,11 @@ const PALConfig pal_default_config = {
|
||||
.data
|
||||
= (0 << 15) // P5_6: TX_AMP
|
||||
| (1 << 14) // P5_5: MIXER_RESETX, 10K PU
|
||||
#ifdef PRALINE
|
||||
| (0 << 13) // P5_4: MIXER_ENX, 10K PU
|
||||
#else
|
||||
| (1 << 13) // P5_4: MIXER_ENX, 10K PU
|
||||
#endif
|
||||
| (1 << 12) // P5_3: RX_MIX_BP
|
||||
| (0 << 11) // P5_2: TX_MIX_BP
|
||||
| (0 << 10) // P5_1: LP
|
||||
@@ -154,11 +159,19 @@ const PALConfig pal_default_config = {
|
||||
,
|
||||
.dir
|
||||
= (1 << 15) // P5_6: TX_AMP
|
||||
| (1 << 14) // P5_5: MIXER_RESETX, 10K PU
|
||||
| (1 << 13) // P5_4: MIXER_ENX, 10K PU
|
||||
#ifdef PRALINE
|
||||
| (0 << 14) // P5_5: MIXER_RESETX, 10K PU
|
||||
| (1 << 13) // P5_4: MIXER_ENX - OUTPUT (MCU controlled)
|
||||
| (0 << 12) // P5_3: RX_MIX_BP - unused on PRALINE
|
||||
| (0 << 11) // P5_2: FPGA_CRESET - INPUT initially
|
||||
| (0 << 10) // P5_1: FPGA_SPI_CS - INPUT initially
|
||||
#else
|
||||
| (1 << 14) // P5_5: MIXER_RESETX, 10K PU
|
||||
| (1 << 13) // P5_4: MIXER_ENX, 10K PU
|
||||
| (1 << 12) // P5_3: RX_MIX_BP
|
||||
| (1 << 11) // P5_2: TX_MIX_BP
|
||||
| (1 << 10) // P5_1: LP
|
||||
#endif
|
||||
| (0 << 9) // P5_0: Varies by revision, float until detection
|
||||
| (1 << 8) // P6_12: LED3 (TX)
|
||||
| (1 << 7) // P5_7: CS_AD
|
||||
@@ -306,7 +319,13 @@ 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) */
|
||||
|
||||
#ifdef PRALINE
|
||||
{ 2, 6, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=1, .ezi=0, .zif=1 } }, /* TRIGGER_OUT / MIX_EN_N_R1_0: GPIO5[6] - PRALINE */
|
||||
#else
|
||||
/* HackRF One RFFC5072 SPI pins */
|
||||
{ 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) */
|
||||
#endif
|
||||
{ 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) */
|
||||
@@ -319,8 +338,16 @@ const PALConfig pal_default_config = {
|
||||
{ 5, 4, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* MIXER_ENX/P32: 10K PU, 33pF, RFFC5072.ENX(I) */
|
||||
{ 5, 5, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* MIXER_RESETX/P33: 10K PU, 33pF, RFFC5072.RESETX(I) */
|
||||
{ 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) */
|
||||
#ifdef PRALINE
|
||||
/* PRALINE RFFC5072 SPI pins - different from HackRF One */
|
||||
{ 5, 7, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* P5_7: GPIO2[7], RFFC5072 CS */
|
||||
{ 9, 5, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=0, .ehs=1, .ezi=0, .zif=0 } }, /* P9_5: GPIO5[18], RFFC5072 SCLK */
|
||||
{ 9, 2, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=0, .ehs=1, .ezi=1, .zif=0 } }, /* P9_2: GPIO4[14], RFFC5072 SDATA (bidirectional) */
|
||||
#else
|
||||
/* HackRF One RFFC5072 SPI pins - NOT used on PRALINE */
|
||||
{ 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) */
|
||||
#endif
|
||||
{ 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) */
|
||||
|
||||
@@ -346,7 +373,9 @@ const PALConfig pal_default_config = {
|
||||
{ 6, 1, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* CPLD_TCK: PortaPack CPLD.TCK(I) */
|
||||
{ 6, 2, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* CPLD_TDI: PortaPack CPLD.TDI(I), I2S0_RX_SDA(O) */
|
||||
{ 6, 5, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* CPLD_TMS: HackRF CPLD.TMS(I) */
|
||||
#ifndef PRALINE
|
||||
{ 9, 5, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=0, .ehs=0, .ezi=1, .zif=0 } }, /* CPLD_TDO: HackRF CPLD.TDO(O) */
|
||||
#endif
|
||||
|
||||
/* PortaPack CPLD */
|
||||
{ 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) */
|
||||
@@ -870,40 +899,55 @@ extern "C" void boardInit(void) {
|
||||
LPC_SCU->SFSP[6][7] = 0xF4; /* SCU_GPIO_FAST | FUNCTION4 */
|
||||
LPC_GPIO->DIR[5] |= (1 << 15);
|
||||
LPC_GPIO->CLR[5] = (1 << 15); /* Clear = enable 3.3V aux */
|
||||
{ volatile uint32_t delay = 100000; while(delay--); }
|
||||
{ volatile uint32_t delay = 200000; while(delay--); }
|
||||
|
||||
/* Enable 1.2V for FPGA - P8_7 = GPIO4[7], active high */
|
||||
LPC_SCU->SFSP[8][7] = 0x10;
|
||||
LPC_GPIO->DIR[4] |= (1 << 7);
|
||||
LPC_GPIO->SET[4] = (1 << 7);
|
||||
{ volatile uint32_t delay = 100000; while(delay--); }
|
||||
{ volatile uint32_t delay = 200000; while(delay--); }
|
||||
|
||||
/* Enable VAA for RF - P8_1 = GPIO4[1], active low */
|
||||
LPC_SCU->SFSP[8][1] = 0x10;
|
||||
LPC_GPIO->DIR[4] |= (1 << 1);
|
||||
LPC_GPIO->CLR[4] = (1 << 1);
|
||||
{ volatile uint32_t delay = 100000; while(delay--); }
|
||||
{ volatile uint32_t delay = 200000; while(delay--); }
|
||||
|
||||
/* Configure RFFC5072 pins for PRALINE */
|
||||
/* P9_2 = GPIO4[14] RFFC5072 data (SCU_GPIO_FAST | FUNCTION0 = 0xF0) */
|
||||
LPC_SCU->SFSP[9][2] = 0xF0;
|
||||
/* P9_5 = GPIO5[18] RFFC5072 clock (SCU_GPIO_FAST | FUNCTION4 = 0xF4) */
|
||||
LPC_SCU->SFSP[9][5] = 0xF4;
|
||||
LPC_GPIO->DIR[5] |= (1 << 18); /* Clock as output */
|
||||
/* Set GPIO directions for RFFC5072 SPI pins */
|
||||
/* P5_7 = GPIO2[7] RFFC5072 CS */
|
||||
LPC_GPIO->SET[2] = (1 << 7); /* CS high (deselected) */
|
||||
LPC_GPIO->DIR[2] |= (1 << 7); /* CS as output */
|
||||
|
||||
/* P9_5 = GPIO5[18] RFFC5072 SCLK */
|
||||
LPC_GPIO->CLR[5] = (1 << 18); /* CLK low */
|
||||
LPC_GPIO->DIR[5] |= (1 << 18); /* CLK as output */
|
||||
|
||||
/* P9_2 = GPIO4[14] RFFC5072 DATA (bidirectional) */
|
||||
LPC_GPIO->DIR[4] |= (1 << 14); /* DATA as output initially */
|
||||
|
||||
/* P2_6 = GPIO5[6] TRIGGER_OUT / MIX_EN_N_R1_0 (PRALINE R1.0 mixer bypass) */
|
||||
/* SCU configured in PAL array above with mode=4 */
|
||||
LPC_GPIO->CLR[5] = (1 << 6); /* Default low (mixer enabled) */
|
||||
LPC_GPIO->DIR[5] |= (1 << 6); /* Output */
|
||||
{ volatile uint32_t delay = 200000; while(delay--); }
|
||||
|
||||
/* Configure Port D pins for PRALINE (use SFSPD registers) */
|
||||
/* PD_14 = GPIO6[28] MAX2831 chip select */
|
||||
LPC_SCU->SFSPD[14] = 0xF4; /* SCU_GPIO_FAST | FUNCTION4 */
|
||||
LPC_GPIO->SET[6] = (1 << 28); /* CS high (inactive) */
|
||||
LPC_GPIO->DIR[6] |= (1 << 28); /* Output */
|
||||
|
||||
/* PD_15 = GPIO6[29] MAX2831 RXHP control */
|
||||
LPC_SCU->SFSPD[15] = 0xF4; /* SCU_GPIO_FAST | FUNCTION4 */
|
||||
LPC_GPIO->CLR[6] = (1 << 29); /* RXHP low = 100 Hz HPF */
|
||||
LPC_GPIO->DIR[6] |= (1 << 29); /* Output */
|
||||
|
||||
/* PD_16 = GPIO6[30] MAX5864 chip select */
|
||||
LPC_SCU->SFSPD[16] = 0xF4; /* SCU_GPIO_FAST | FUNCTION4 */
|
||||
LPC_GPIO->SET[6] |= (1 << 30); /* CS high (inactive) */
|
||||
LPC_GPIO->DIR[6] |= (1 << 30); /* Output */
|
||||
{ volatile uint32_t delay = 200000; while(delay--); }
|
||||
|
||||
/* Configure Port E pins for MAX2831 control (use SFSPE registers) */
|
||||
/* PE_1 = GPIO7[1] MAX2831 ENABLE */
|
||||
@@ -914,6 +958,7 @@ extern "C" void boardInit(void) {
|
||||
LPC_SCU->SFSPE[2] = 0xF4; /* SCU_GPIO_FAST | FUNCTION4 */
|
||||
LPC_GPIO->CLR[7] = (1 << 2); /* Start in shutdown mode */
|
||||
LPC_GPIO->DIR[7] |= (1 << 2); /* Output */
|
||||
{ volatile uint32_t delay = 200000; while(delay--); }
|
||||
|
||||
/* Configure Port 6 pins for RF path control */
|
||||
/* P6_3 = GPIO3[2] Mixer enable (inverted: 0 = mixer ON) */
|
||||
@@ -924,6 +969,7 @@ extern "C" void boardInit(void) {
|
||||
LPC_SCU->SFSP[6][5] = 0xF0; /* SCU_GPIO_FAST | FUNCTION0 */
|
||||
LPC_GPIO->CLR[3] = (1 << 4); /* TX off by default (RX mode) */
|
||||
LPC_GPIO->DIR[3] |= (1 << 4); /* Output */
|
||||
{ volatile uint32_t delay = 200000; while(delay--); }
|
||||
|
||||
/* Configure Port A pins for RF path control */
|
||||
/* PA_1 = GPIO4[8] LPF enable */
|
||||
@@ -934,21 +980,30 @@ extern "C" void boardInit(void) {
|
||||
LPC_SCU->SFSP[0xA][2] = 0xF0; /* SCU_GPIO_FAST | FUNCTION0 */
|
||||
LPC_GPIO->CLR[4] = (1 << 9); /* RF amp off by default */
|
||||
LPC_GPIO->DIR[4] |= (1 << 9); /* Output */
|
||||
{ volatile uint32_t delay = 200000; while(delay--); }
|
||||
|
||||
/* Configure RFFC5072 control pins for PRALINE */
|
||||
/* P5_4 = GPIO2[13] RFFC5072 ENX (active low: 0=enabled) */
|
||||
LPC_SCU->SFSP[5][4] = 0xF0; /* FUNCTION0 (GPIO), no pulls */
|
||||
LPC_GPIO->DIR[2] &= ~(1 << 13); /* ENX: INPUT (let FPGA control) */
|
||||
|
||||
/* P5_5 = GPIO2[14] RFFC5072 RESETX - FPGA controlled, MCU should not touch */
|
||||
LPC_SCU->SFSP[5][5] = 0xF0; /* FUNCTION0 (GPIO), no pulls */
|
||||
LPC_GPIO->DIR[2] &= ~(1 << 14); /* RESETX: INPUT (let FPGA control) */
|
||||
|
||||
/* P5_4 = GPIO2[13] RFFC5072 ENX - SPI chip select (managed by SPI driver) */
|
||||
LPC_SCU->SFSP[5][4] = 0x10; /* FUNCTION0 (GPIO), pull-up, slow mode (matches HackRF USB) */
|
||||
LPC_GPIO->DIR[2] |= (1 << 13); /* ENX: OUTPUT */
|
||||
LPC_GPIO->SET[2] = (1 << 13); /* ENX = 1 (deselected initially) */
|
||||
{ volatile uint32_t delay = 200000; while(delay--); }
|
||||
|
||||
/* P5_5 = GPIO2[14] RFFC5072 RESETX (active high: 1=running) */
|
||||
LPC_SCU->SFSP[5][5] = 0x10; /* FUNCTION0 (GPIO), pull-up, slow mode (matches HackRF USB) */
|
||||
LPC_GPIO->DIR[2] |= (1 << 14); /* RESETX: OUTPUT */
|
||||
LPC_GPIO->SET[2] = (1 << 14); /* RESETX = 1 (RUNNING) */
|
||||
{ volatile uint32_t delay = 200000; while(delay--); }
|
||||
|
||||
/* Ensure RESETX is stable */
|
||||
for (volatile int i = 0; i < 10; i++) {
|
||||
LPC_GPIO->W2[14] = 1;
|
||||
}
|
||||
|
||||
/* PD_11 = GPIO6[25] RFFC5072 Lock Detect (input) */
|
||||
LPC_SCU->SFSP[0xD][11] = 0xF0; /* FUNCTION0 (GPIO), no pulls */
|
||||
|
||||
/* Small delay for signals to stabilize */
|
||||
for (volatile int i = 0; i < 10000; i++) {}
|
||||
LPC_SCU->SFSPD[11] = 0x10; /* FUNCTION0 (GPIO), pull-up (matches HackRF USB) */
|
||||
LPC_GPIO->DIR[6] &= ~(1 << 25); /* LD: INPUT */
|
||||
{ volatile uint32_t delay = 200000; while(delay--); }
|
||||
|
||||
/* Configure PRALINE-specific SGPIO pins for FPGA sample interface.
|
||||
* These override the HackRF One pin config from pins_setup.
|
||||
@@ -968,6 +1023,7 @@ extern "C" void boardInit(void) {
|
||||
LPC_SCU->SFSP[8][2] = 0xF4; /* SCU_GPIO_FAST | func 4 */
|
||||
/* SGPIO11 = P1_17 function 6 (HOST_DIRECTION - output to FPGA, tells FPGA TX vs RX) */
|
||||
LPC_SCU->SFSP[1][17] = 0xF6; /* SCU_GPIO_FAST | func 6 */
|
||||
{ volatile uint32_t delay = 200000; while(delay--); }
|
||||
|
||||
/* SGPIO data pins (SGPIO0-7) - all 8 bits required for sample data */
|
||||
LPC_SCU->SFSP[0][0] = 0xF3; /* SGPIO0: P0_0 function 3, HOST_DATA0 */
|
||||
@@ -978,14 +1034,10 @@ extern "C" void boardInit(void) {
|
||||
LPC_SCU->SFSP[6][6] = 0xF2; /* SGPIO5: P6_6 function 2, HOST_DATA5 */
|
||||
LPC_SCU->SFSP[2][2] = 0xF0; /* SGPIO6: P2_2 function 0, HOST_DATA6 */
|
||||
LPC_SCU->SFSP[1][0] = 0xF6; /* SGPIO7: P1_0 function 6, HOST_DATA7 */
|
||||
{ volatile uint32_t delay = 200000; while(delay--); }
|
||||
|
||||
/* NOTE: P9_5 is RFFC5072 mixer clock (SCU_MIXER_SCLK), NOT SGPIO!
|
||||
* Do NOT override P9_5 here. */
|
||||
|
||||
// Trigger FPGA bitstream loading via fpga bridge
|
||||
// Attempt to load the FPGA bitstream
|
||||
// This function returns LD_SUCCESS (0) if the FPGA confirms the bitstream
|
||||
// Use LEDs to check if initi is successful.
|
||||
// Trigger FPGA bitstream loading via fpga bridge in portapack.cpp
|
||||
// Use LEDs to check if boardInit initialization is successful.
|
||||
|
||||
// Setup LED pin directions
|
||||
// LED1 (USB) = GPIO2[1], LED2 (RX) = GPIO2[2], LED3 (TX) = GPIO2[8]
|
||||
@@ -994,14 +1046,8 @@ extern "C" void boardInit(void) {
|
||||
// Turn off all LEDs to start
|
||||
// PRALINE LEDs are active-low: SET (HIGH) = OFF, CLR (LOW) = ON
|
||||
LPC_GPIO->SET[2] = (1 << 1) | (1 << 2) | (1 << 8);
|
||||
{ volatile uint32_t delay = 200000; while(delay--); }
|
||||
|
||||
// Call fpga_bridge_init and continue boot regardless of result
|
||||
// (Watchdog was resetting device when we halted with while(1))
|
||||
int load_result = fpga_bridge_init();
|
||||
(void)load_result; // Ignore result for now, just let boot continue
|
||||
|
||||
// Keep LEDs off after FPGA load
|
||||
LPC_GPIO->SET[2] = (1 << 1) | (1 << 2) | (1 << 8);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
// Check if PRALINE was passed from CMake
|
||||
#ifdef PRALINE
|
||||
#warning "Building for HackRF_PRO with FPGA."
|
||||
|
||||
// Necessary headers
|
||||
#include "lz4_blk.h"
|
||||
@@ -297,7 +296,6 @@
|
||||
|
||||
// Cached register values for debug reads (since reads may require mode switch)
|
||||
static uint8_t fpga_reg_cache[6] = {0, 0x01, 0x00, 0x00, 0x00, 0x00};
|
||||
static uint8_t fpga_reg_cache_valid = 0;
|
||||
|
||||
// Public function to read FPGA register (callable from C++ application code)
|
||||
// Switches SPI mode, reads register, switches back
|
||||
|
||||
@@ -213,6 +213,24 @@ CpldUpdateStatus update_autodetect(const Config config_rev_20150901, const Confi
|
||||
namespace hackrf {
|
||||
namespace cpld {
|
||||
|
||||
#ifdef PRALINE
|
||||
|
||||
/* PRALINE has no HackRF CPLD - stub these functions out */
|
||||
bool load_sram() {
|
||||
return true;
|
||||
}
|
||||
void load_sram_no_verify() {
|
||||
return;
|
||||
}
|
||||
bool verify_eeprom() {
|
||||
return true;
|
||||
}
|
||||
void init_from_eeprom() {
|
||||
return;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static jtag::GPIOTarget jtag_target_hackrf() {
|
||||
return {
|
||||
hackrf::one::gpio_cpld_tck,
|
||||
@@ -262,5 +280,7 @@ void init_from_eeprom() {
|
||||
hackrf_cpld.init_from_eeprom();
|
||||
}
|
||||
|
||||
#endif // PRALINE
|
||||
|
||||
} /* namespace cpld */
|
||||
} /* namespace hackrf */
|
||||
|
||||
@@ -278,6 +278,37 @@ constexpr fir_taps_real<32> taps_11k0_channel{
|
||||
}},
|
||||
};
|
||||
|
||||
// NBFM 12K5F3E emission type /////////////////////////////////////////////
|
||||
|
||||
// IFIR image-reject filter: fs=3072000, pass=6250, stop=342250, decim=8, fout=384000
|
||||
constexpr fir_taps_real<24> taps_12k5_decim_0{
|
||||
.low_frequency_normalized = -6250.0f / 3072000.0f,
|
||||
.high_frequency_normalized = 6250.0f / 3072000.0f,
|
||||
.transition_normalized = 336000.0f / 3072000.0f,
|
||||
.taps = {{42, 108, 226, 412, 672, 1004, 1391, 1807, 2211, 2565, 2828, 2969,
|
||||
2969, 2828, 2565, 2211, 1807, 1391, 1004, 672, 412, 226, 108, 42}},
|
||||
};
|
||||
|
||||
// IFIR prototype filter: fs=384000, pass=6250, stop=42500, decim=8, fout=48000
|
||||
constexpr fir_taps_real<32> taps_12k5_decim_1{
|
||||
.low_frequency_normalized = -6250.0f / 384000.0f,
|
||||
.high_frequency_normalized = 6250.0f / 384000.0f,
|
||||
.transition_normalized = 36250.0f / 384000.0f,
|
||||
.taps = {{-38, -85, -162, -245, -315, -338, -275, -85, 255, 752, 1378, 2088,
|
||||
2807, 3452, 3939, 4202, 4202, 3939, 3452, 2807, 2088, 1378, 752, 255,
|
||||
-85, -275, -338, -315, -245, -162, -85, -38}},
|
||||
};
|
||||
|
||||
// Channel filter: fs=48000, pass=6250, stop=9250, decim=1, fout=48000
|
||||
constexpr fir_taps_real<32> taps_12k5_channel{
|
||||
.low_frequency_normalized = -6250.0f / 48000.0f,
|
||||
.high_frequency_normalized = 6250.0f / 48000.0f,
|
||||
.transition_normalized = 3000.0f / 48000.0f,
|
||||
.taps = {{-75, -362, -712, -908, -592, 268, 1324, 1720, 684, -1522, -3541, -3385,
|
||||
342, 7150, 14642, 19541, 19541, 14642, 7150, 342, -3385, -3541, -1522, 684,
|
||||
1720, 1324, 268, -592, -908, -712, -362, -75}},
|
||||
};
|
||||
|
||||
// NBFM 8K50F3E emission type /////////////////////////////////////////////
|
||||
|
||||
// IFIR image-reject filter: fs=3072000, pass=4250, stop=340250, decim=8, fout=384000
|
||||
|
||||
@@ -52,7 +52,12 @@ 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];
|
||||
#ifdef PRALINE
|
||||
constexpr GPIO gpio_mix_bypass = gpio[GPIO3_2]; // P6_3: PRALINE RF path mixer bypass inverted
|
||||
constexpr GPIO gpio_mix_en_n_r1_0 = gpio[GPIO5_6]; // P2_6: R1.0 board mixer bypass
|
||||
#else
|
||||
constexpr GPIO gpio_mix_bypass = gpio[GPIO5_16];
|
||||
#endif
|
||||
constexpr GPIO gpio_not_mix_bypass = gpio[GPIO1_0];
|
||||
|
||||
constexpr GPIO gpio_og_rx = gpio[GPIO5_5];
|
||||
@@ -68,8 +73,15 @@ constexpr GPIO gpio_amp_bypass = gpio[GPIO0_14];
|
||||
constexpr GPIO gpio_not_rx_amp_pwr = gpio[GPIO1_12];
|
||||
constexpr GPIO gpio_not_tx_amp_pwr = gpio[GPIO3_5];
|
||||
|
||||
constexpr GPIO gpio_rffc5072_resetx = gpio[GPIO2_14];
|
||||
#ifdef PRALINE
|
||||
// PRALINE: GPIO2[13] is SPI CS only, FPGA controls ENX/RESETX
|
||||
constexpr GPIO gpio_rffc5072_select = gpio[GPIO2_13]; // P5_4: SPI CS (ENX)
|
||||
constexpr GPIO gpio_rffc5072_resetx = gpio[GPIO2_14]; // P5_5: LPC43xx controls directly
|
||||
#else
|
||||
constexpr GPIO gpio_rffc5072_select = gpio[GPIO2_13];
|
||||
constexpr GPIO gpio_rffc5072_resetx = gpio[GPIO2_14];
|
||||
#endif
|
||||
|
||||
#ifdef PRALINE
|
||||
constexpr GPIO gpio_rffc5072_clock = gpio[GPIO5_18];
|
||||
constexpr GPIO gpio_rffc5072_data = gpio[GPIO4_14];
|
||||
@@ -103,8 +115,8 @@ constexpr GPIO gpio_max2839_rxtx = gpio[GPIO2_5];
|
||||
#endif
|
||||
|
||||
#ifdef PRALINE
|
||||
constexpr GPIO gpio_max5864_select = gpio[GPIO6_30];
|
||||
constexpr GPIO gpio_fpga_select = gpio[GPIO2_10]; // FPGA SPI CS (P5_1)
|
||||
constexpr GPIO gpio_max5864_select = gpio[GPIO6_30]; // PD_16: PRALINE MAX5864 CS
|
||||
constexpr GPIO gpio_fpga_select = gpio[GPIO2_10]; // FPGA SPI CS (P5_1)
|
||||
#else
|
||||
constexpr GPIO gpio_max5864_select = gpio[GPIO2_7];
|
||||
#endif
|
||||
@@ -118,8 +130,8 @@ constexpr GPIO gpio_1v2_enable = gpio[GPIO4_7]; // 1V2 enable (P8_7)
|
||||
constexpr GPIO gpio_3v3aux_disable = gpio[GPIO5_15]; // 3V3 aux disable (P6_7)
|
||||
|
||||
// PRALINE RF path control
|
||||
constexpr GPIO gpio_tx_enable = gpio[GPIO3_4]; // TX enable (P6_5)
|
||||
constexpr GPIO gpio_mix_enable_n = gpio[GPIO3_2]; // Mixer enable inverted (P6_3)
|
||||
constexpr GPIO gpio_tx_enable = gpio[GPIO3_4]; // TX enable (P6_5)
|
||||
// constexpr GPIO gpio_mix_enable_n = gpio[GPIO3_2]; // Mixer enable inverted (P6_3)
|
||||
constexpr GPIO gpio_lpf_enable = gpio[GPIO4_8]; // LPF enable (PA_1)
|
||||
constexpr GPIO gpio_rf_amp_enable = gpio[GPIO4_9]; // RF amp enable (PA_2)
|
||||
constexpr GPIO gpio_ant_bias_disable = gpio[GPIO1_12]; // Antenna bias disable (P2_12)
|
||||
@@ -144,9 +156,17 @@ constexpr GPIO gpio_trigger_out = gpio[GPIO5_6]; // Trigger output (P2_6)
|
||||
constexpr GPIO gpio_pps_out = gpio[GPIO5_5]; // PPS output (P2_5)
|
||||
#endif
|
||||
|
||||
#ifdef PRALINE
|
||||
/* PRALINE has no HackRF CPLD. These pins are used for RFFC5072 and TX_EN instead.
|
||||
* Dummy assignments here allow cpld_update.cpp to compile; the functions
|
||||
* that use them are never called on PRALINE. */
|
||||
constexpr GPIO gpio_cpld_tdo = gpio[GPIO3_0]; // dummy: reuse TCK pin
|
||||
constexpr GPIO gpio_cpld_tms = gpio[GPIO3_1]; // dummy: reuse TDI pin
|
||||
#else
|
||||
constexpr GPIO gpio_cpld_tdo = gpio[GPIO5_18];
|
||||
constexpr GPIO gpio_cpld_tck = gpio[GPIO3_0];
|
||||
constexpr GPIO gpio_cpld_tms = gpio[GPIO3_4];
|
||||
#endif
|
||||
constexpr GPIO gpio_cpld_tck = gpio[GPIO3_0];
|
||||
constexpr GPIO gpio_cpld_tdi = gpio[GPIO3_1];
|
||||
|
||||
constexpr GPIO gpio_r9_clkin_en = gpio[GPIO5_15];
|
||||
|
||||
@@ -205,7 +205,7 @@ uint16_t I2cDev::read16_1(uint8_t reg) {
|
||||
}
|
||||
uint32_t I2cDev::read24_1(uint8_t reg) {
|
||||
uint8_t buffer[3];
|
||||
i2c_read(®, 1, buffer, 2);
|
||||
i2c_read(®, 1, buffer, 3);
|
||||
return uint32_t(buffer[0]) << 16 | uint32_t(buffer[1]) << 8 | uint32_t(buffer[2]);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
using namespace lpc43xx;
|
||||
|
||||
#include "utility.hpp"
|
||||
#include "../flashsize.h"
|
||||
|
||||
namespace portapack {
|
||||
namespace memory {
|
||||
|
||||
@@ -154,6 +154,8 @@ class Message {
|
||||
MorseTXkey = 96,
|
||||
StreamTXConfiguration = 97,
|
||||
RTTYData = 98,
|
||||
NotificationData = 99,
|
||||
TimeSinkConfig = 100,
|
||||
MAX
|
||||
};
|
||||
|
||||
@@ -308,6 +310,20 @@ class WidebandSpectrumConfigMessage : public Message {
|
||||
size_t trigger{0};
|
||||
};
|
||||
|
||||
class TimeSinkConfigMessage : public Message {
|
||||
public:
|
||||
constexpr TimeSinkConfigMessage(
|
||||
size_t sampling_rate,
|
||||
size_t trigger)
|
||||
: Message{ID::TimeSinkConfig},
|
||||
sampling_rate{sampling_rate},
|
||||
trigger{trigger} {
|
||||
}
|
||||
|
||||
size_t sampling_rate{0};
|
||||
size_t trigger{0};
|
||||
};
|
||||
|
||||
struct AudioSpectrum {
|
||||
std::array<uint8_t, 128> db{{0}};
|
||||
// uint32_t sampling_rate { 0 };
|
||||
@@ -1793,4 +1809,33 @@ class RTTYDataMessage : public Message {
|
||||
static constexpr uint16_t max_len = 490;
|
||||
};
|
||||
|
||||
class NotificationDataMessage : public Message {
|
||||
public:
|
||||
constexpr NotificationDataMessage(const char* source_app, const char* title, const char* message, uint8_t icon = 0, uint16_t timeout = 10000)
|
||||
: Message{ID::NotificationData},
|
||||
icon(icon),
|
||||
timeout(timeout) {
|
||||
if (source_app) {
|
||||
size_t len = std::min(strlen(source_app), (size_t)19);
|
||||
memcpy(this->source_app, source_app, len);
|
||||
this->source_app[len] = '\0';
|
||||
}
|
||||
if (title) {
|
||||
size_t len = std::min(strlen(title), (size_t)49);
|
||||
memcpy(this->title, title, len);
|
||||
this->title[len] = '\0';
|
||||
}
|
||||
if (message) {
|
||||
size_t len = std::min(strlen(message), (size_t)299);
|
||||
memcpy(this->message, message, len);
|
||||
this->message[len] = '\0';
|
||||
}
|
||||
}
|
||||
char source_app[20]{0}; // source application name, null-terminated, max 19 chars + null
|
||||
char title[50]{0}; // title, null-terminated, max 49 chars + null
|
||||
char message[300]{0}; // message, null-terminated, max 299 chars + null
|
||||
uint8_t icon = 0;
|
||||
uint16_t timeout = 10000;
|
||||
};
|
||||
|
||||
#endif /*__MESSAGE_H__*/
|
||||
|
||||
@@ -41,7 +41,7 @@ size_t morse_encode(std::string& message, const uint32_t time_unit_ms, const uin
|
||||
|
||||
i = 0;
|
||||
for (char& ch : message) {
|
||||
if (i > 256) return 0; // Message too long
|
||||
if (i >= 256) return 0; // Message too long
|
||||
|
||||
if ((ch >= 'a') && (ch <= 'z')) // Make uppercase
|
||||
ch -= 32;
|
||||
|
||||
@@ -96,6 +96,7 @@ constexpr image_tag_t image_tag_sonde{'P', 'S', 'O', 'N'};
|
||||
constexpr image_tag_t image_tag_tpms{'P', 'T', 'P', 'M'};
|
||||
constexpr image_tag_t image_tag_wfm_audio{'P', 'W', 'F', 'M'};
|
||||
constexpr image_tag_t image_tag_wideband_spectrum{'P', 'S', 'P', 'E'};
|
||||
constexpr image_tag_t image_tag_time_sink{'P', 'T', 'S', 'K'};
|
||||
constexpr image_tag_t image_tag_test{'P', 'T', 'S', 'T'};
|
||||
|
||||
constexpr image_tag_t image_tag_adsb_tx{'P', 'A', 'D', 'T'};
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user