mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-08-22 07:29:03 +00:00
Compare commits
39 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ed834e3553 | |||
| ce08d93ae2 | |||
| 13fd1b1f3b | |||
| d04c781ada | |||
| 24605777a6 | |||
| b5ac792853 | |||
| 44c319dcc6 | |||
| a442971b81 | |||
| 8b5adb6bc1 | |||
| c3add0ce84 | |||
| 8725b01995 | |||
| 936e8279f9 | |||
| 6193023c8f | |||
| 1800939833 | |||
| 2f48fc2ef9 | |||
| 918ec0574f | |||
| 1139b22141 | |||
| 7598c25fc8 | |||
| 0f6a9277a8 | |||
| 6a8650d484 | |||
| 46d9e02684 | |||
| 367479d163 | |||
| bbbf5a37c8 | |||
| b2ad1fa979 | |||
| 998be5ba09 | |||
| 9e8d279298 | |||
| fd03bb800c | |||
| f80c28cde7 | |||
| b7e5bedf4b | |||
| 994e426d1e | |||
| c5bf0d94f9 | |||
| 8ad9ada015 | |||
| e854261124 | |||
| 0370b4eb55 | |||
| 5eef5b4e31 | |||
| 61d9c051de | |||
| 5ea1bff1e6 | |||
| bc035cff6a | |||
| f2c008602d |
@@ -1 +1 @@
|
||||
v1.9.0
|
||||
v1.9.1
|
||||
|
||||
@@ -1 +1 @@
|
||||
v1.9.1
|
||||
v2.0.0
|
||||
|
||||
+3
-2
@@ -55,7 +55,7 @@ CMakeFiles/
|
||||
# Debugging
|
||||
.gdbinit*
|
||||
|
||||
# Editor/IDE files
|
||||
# Editor/ IDE files
|
||||
*.sublime-project
|
||||
*.sublime-workspace
|
||||
.vscode
|
||||
@@ -68,8 +68,9 @@ CMakeFiles/
|
||||
.DS_Store
|
||||
/firmware/CMakeCache.txt
|
||||
|
||||
# Python env
|
||||
# Python env/ venv
|
||||
env/
|
||||
venv/
|
||||
|
||||
# Other
|
||||
*.bak
|
||||
|
||||
@@ -44,7 +44,7 @@ if(cpp20_supported)
|
||||
else()
|
||||
set(USE_CPPOPT "-std=c++17")
|
||||
endif()
|
||||
set(USE_CPPOPT "${USE_CPPOPT} -flto -fno-rtti -fno-exceptions -Weffc++ -Wuninitialized -Wno-volatile")
|
||||
set(USE_CPPOPT "${USE_CPPOPT} -fno-rtti -fno-exceptions -Weffc++ -Wuninitialized -Wno-volatile")
|
||||
|
||||
# Enable this if you want the linker to remove unused code and data
|
||||
set(USE_LINK_GC yes)
|
||||
@@ -52,7 +52,7 @@ set(USE_LINK_GC yes)
|
||||
# Linker extra options here.
|
||||
set(USE_LDOPT)
|
||||
|
||||
# Enable this if you want link time optimizations (LTO)
|
||||
# Enable this if you want link time optimizations (LTO) - this flag affects chibios only
|
||||
set(USE_LTO no)
|
||||
|
||||
# If enabled, this option allows to compile the application in THUMB mode.
|
||||
@@ -293,7 +293,7 @@ set(CPPSRC
|
||||
# apps/ui_jammer.cpp
|
||||
# apps/ui_keyfob.cpp
|
||||
# apps/ui_lcr.cpp
|
||||
apps/ui_level.cpp
|
||||
apps/ui_level.cpp
|
||||
apps/ui_looking_glass_app.cpp
|
||||
apps/ui_mictx.cpp
|
||||
apps/ui_modemsetup.cpp
|
||||
@@ -304,7 +304,7 @@ set(CPPSRC
|
||||
apps/ui_pocsag_tx.cpp
|
||||
apps/ui_rds.cpp
|
||||
apps/ui_recon_settings.cpp
|
||||
apps/ui_recon.cpp
|
||||
apps/ui_recon.cpp
|
||||
apps/ui_remote.cpp
|
||||
apps/ui_scanner.cpp
|
||||
apps/ui_sd_over_usb.cpp
|
||||
@@ -347,10 +347,12 @@ set(CPPSRC
|
||||
${HACKRF_CPLD_DATA_CPP}
|
||||
ui_external_items_menu_loader.cpp
|
||||
view_factory_base.cpp
|
||||
|
||||
${EXTCPPSRC}
|
||||
)
|
||||
|
||||
set_source_files_properties(${CPPSRC} PROPERTIES COMPILE_FLAGS -flto) # Add lto flag to the non-external sources only
|
||||
|
||||
list (APPEND CPPSRC ${EXTCPPSRC}) # Append external sources after setting lto flag to internal ones
|
||||
|
||||
# C sources to be compiled in ARM mode regardless of the global setting.
|
||||
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
|
||||
# option that results in lower performance and larger code size.
|
||||
|
||||
@@ -64,9 +64,9 @@ static std::string mmsi(
|
||||
|
||||
static std::string mid(
|
||||
const ais::MMSI& mmsi) {
|
||||
std::database db;
|
||||
database db;
|
||||
std::string mid_code = "";
|
||||
std::database::MidDBRecord mid_record = {};
|
||||
database::MidDBRecord mid_record = {};
|
||||
int return_code = 0;
|
||||
|
||||
// Try getting the country name from mids.db using MID code for given MMSI
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -51,7 +52,7 @@ void SoundBoardView::stop() {
|
||||
|
||||
void SoundBoardView::handle_replay_thread_done(const uint32_t return_code) {
|
||||
stop();
|
||||
// progressbar.set_value(0);
|
||||
progressbar.set_value(0);
|
||||
|
||||
if (return_code == ReplayThread::END_OF_FILE) {
|
||||
if (check_random.value()) {
|
||||
@@ -89,6 +90,7 @@ void SoundBoardView::start_tx(const uint32_t id) {
|
||||
|
||||
uint32_t tone_key_index = options_tone_key.selected_index();
|
||||
uint32_t sample_rate;
|
||||
uint8_t bits_per_sample;
|
||||
|
||||
stop();
|
||||
|
||||
@@ -99,11 +101,12 @@ void SoundBoardView::start_tx(const uint32_t id) {
|
||||
|
||||
playing_id = id;
|
||||
|
||||
// progressbar.set_max(reader->sample_count());
|
||||
progressbar.set_max(reader->sample_count());
|
||||
|
||||
// button_play.set_bitmap(&bitmap_stop);
|
||||
|
||||
sample_rate = reader->sample_rate();
|
||||
bits_per_sample = reader->bits_per_sample();
|
||||
|
||||
replay_thread = std::make_unique<ReplayThread>(
|
||||
std::move(reader),
|
||||
@@ -120,7 +123,7 @@ void SoundBoardView::start_tx(const uint32_t id) {
|
||||
transmitter_model.channel_bandwidth(),
|
||||
0, // Gain is unused
|
||||
8, // shift_bits_s16, default 8 bits, but also unused
|
||||
8, // bits per sample
|
||||
bits_per_sample,
|
||||
TONES_F2D(tone_key_frequency(tone_key_index), TONES_SAMPLERATE),
|
||||
false, // AM
|
||||
false, // DSB
|
||||
@@ -146,8 +149,7 @@ void SoundBoardView::start_tx(const uint32_t id) {
|
||||
}*/
|
||||
|
||||
void SoundBoardView::on_tx_progress(const uint32_t progress) {
|
||||
(void)progress; // avoid warning
|
||||
// progressbar.set_value(progress);
|
||||
progressbar.set_value(progress);
|
||||
}
|
||||
|
||||
void SoundBoardView::on_select_entry() {
|
||||
@@ -172,7 +174,7 @@ void SoundBoardView::refresh_list() {
|
||||
|
||||
if (entry_extension == ".WAV") {
|
||||
if (reader->open(u"/WAV/" + entry.path().native())) {
|
||||
if ((reader->channels() == 1) && (reader->bits_per_sample() == 8)) {
|
||||
if ((reader->channels() == 1) && ((reader->bits_per_sample() == 8) || (reader->bits_per_sample() == 16))) {
|
||||
// sounds[c].ms_duration = reader->ms_duration();
|
||||
// sounds[c].path = u"WAV/" + entry.path().native();
|
||||
if (count >= (page - 1) * 100 && count < page * 100) {
|
||||
@@ -211,7 +213,7 @@ void SoundBoardView::refresh_list() {
|
||||
|
||||
for (size_t n = 0; n < file_list.size(); n++) {
|
||||
menu_view.add_item({file_list[n].string().substr(0, 30),
|
||||
ui::Color::white(),
|
||||
ui::Color::dark_magenta(),
|
||||
nullptr,
|
||||
[this](KeyEvent) {
|
||||
on_select_entry();
|
||||
@@ -238,7 +240,7 @@ SoundBoardView::SoundBoardView(
|
||||
&options_tone_key,
|
||||
//&text_title,
|
||||
//&text_duration,
|
||||
//&progressbar,
|
||||
&progressbar,
|
||||
&field_volume,
|
||||
&text_volume_disabled,
|
||||
&page_info,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -103,7 +104,7 @@ class SoundBoardView : public View {
|
||||
"<="};
|
||||
|
||||
Text page_info{
|
||||
{0, 30 * 8 - 4, 30 * 8, 16}};
|
||||
{0, 29 * 8, 30 * 8, 16}};
|
||||
|
||||
MenuView menu_view{
|
||||
{0, 0, 240, 175},
|
||||
@@ -142,9 +143,8 @@ class SoundBoardView : public View {
|
||||
6,
|
||||
"Random"};
|
||||
|
||||
// ProgressBar progressbar {
|
||||
// { 0 * 8, 30 * 8 - 4, 30 * 8, 16 }
|
||||
// };
|
||||
ProgressBar progressbar{
|
||||
{0 * 8, 31 * 8 + 2, 30 * 8, 4}};
|
||||
|
||||
TransmitterView tx_view{
|
||||
16 * 16,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2017 Furrtek
|
||||
* Copyright (C) 2023 Kyle Reed
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -127,8 +128,8 @@ ADSBRxAircraftDetailsView::ADSBRxAircraftDetailsView(
|
||||
text_icao_address.set(entry.icao_str);
|
||||
|
||||
// Try getting the aircraft information from icao24.db
|
||||
std::database db{};
|
||||
std::database::AircraftDBRecord aircraft_record;
|
||||
database db{};
|
||||
database::AircraftDBRecord aircraft_record;
|
||||
auto return_code = db.retrieve_aircraft_record(&aircraft_record, entry.icao_str);
|
||||
switch (return_code) {
|
||||
case DATABASE_RECORD_FOUND:
|
||||
@@ -199,6 +200,10 @@ ADSBRxAircraftDetailsView::ADSBRxAircraftDetailsView(
|
||||
}
|
||||
break;
|
||||
|
||||
case DATABASE_RECORD_NOT_FOUND:
|
||||
// Defaults should be filled by the constructor
|
||||
break;
|
||||
|
||||
case DATABASE_NOT_FOUND:
|
||||
text_manufacturer.set("No icao24.db file");
|
||||
break;
|
||||
@@ -233,24 +238,6 @@ ADSBRxDetailsView::ADSBRxDetailsView(
|
||||
&button_aircraft_details,
|
||||
&button_see_map});
|
||||
|
||||
// The following won't change for a given airborne aircraft.
|
||||
// Try getting the airline's name from airlines.db.
|
||||
// NB: Only works once callsign has been read and won't be updated.
|
||||
std::database db;
|
||||
std::database::AirlinesDBRecord airline_record;
|
||||
std::string airline_code = entry_.callsign.substr(0, 3);
|
||||
auto return_code = db.retrieve_airline_record(&airline_record, airline_code);
|
||||
|
||||
switch (return_code) {
|
||||
case DATABASE_RECORD_FOUND:
|
||||
text_airline.set(airline_record.airline);
|
||||
text_country.set(airline_record.country);
|
||||
break;
|
||||
case DATABASE_NOT_FOUND:
|
||||
text_airline.set("No airlines.db file");
|
||||
break;
|
||||
}
|
||||
|
||||
text_icao_address.set(entry_.icao_str);
|
||||
|
||||
button_aircraft_details.on_select = [this, &nav](Button&) {
|
||||
@@ -330,6 +317,31 @@ void ADSBRxDetailsView::on_orientation(const OrientationDataMessage* msg) {
|
||||
}
|
||||
|
||||
void ADSBRxDetailsView::refresh_ui() {
|
||||
// The following won't change for a given airborne aircraft.
|
||||
// Try getting the airline's name from airlines.db.
|
||||
if (!airline_checked && !entry_.callsign.empty()) {
|
||||
airline_checked = true;
|
||||
|
||||
database db;
|
||||
database::AirlinesDBRecord airline_record;
|
||||
std::string airline_code = entry_.callsign.substr(0, 3);
|
||||
auto return_code = db.retrieve_airline_record(&airline_record, airline_code);
|
||||
|
||||
switch (return_code) {
|
||||
case DATABASE_RECORD_FOUND:
|
||||
text_airline.set(airline_record.airline);
|
||||
text_country.set(airline_record.country);
|
||||
break;
|
||||
case DATABASE_RECORD_NOT_FOUND:
|
||||
// text_airline.set("-"); // It's what it is constructed with
|
||||
// text_country.set("-"); // It's what it is constructed with
|
||||
break;
|
||||
case DATABASE_NOT_FOUND:
|
||||
text_airline.set("No airlines.db file");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
auto age = entry_.age;
|
||||
if (age < 60)
|
||||
text_last_seen.set(to_string_dec_uint(age) + " seconds ago");
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2017 Furrtek
|
||||
* Copyright (C) 2023 Kyle Reed
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -280,6 +281,7 @@ class ADSBRxDetailsView : public View {
|
||||
// NB: Keeping a copy so that it doesn't end up dangling
|
||||
// if removed from the recent entries list.
|
||||
AircraftRecentEntry entry_{AircraftRecentEntry::invalid_key};
|
||||
bool airline_checked{false};
|
||||
|
||||
Labels labels{
|
||||
{{0 * 8, 1 * 16}, "ICAO:", Color::light_grey()},
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -322,6 +323,11 @@ bool ControlsSwitchesWidget::on_key(const KeyEvent key) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ControlsSwitchesWidget::on_encoder(const EncoderEvent delta) {
|
||||
last_delta = delta;
|
||||
return true;
|
||||
}
|
||||
|
||||
void ControlsSwitchesWidget::paint(Painter& painter) {
|
||||
const auto pos = screen_pos();
|
||||
|
||||
@@ -404,6 +410,8 @@ void ControlsSwitchesWidget::paint(Painter& painter) {
|
||||
|
||||
switches_event >>= 1;
|
||||
}
|
||||
|
||||
painter.draw_string({5 * 8, 12 * 16}, Styles::light_grey, to_string_dec_int(last_delta, 3));
|
||||
}
|
||||
|
||||
void ControlsSwitchesWidget::on_frame_sync() {
|
||||
@@ -449,6 +457,17 @@ DebugPeripheralsMenuView::DebugPeripheralsMenuView(NavigationView& nav) {
|
||||
set_max_rows(2); // allow wider buttons
|
||||
}
|
||||
|
||||
/* DebugReboot **********************************************/
|
||||
|
||||
DebugReboot::DebugReboot(NavigationView& nav) {
|
||||
(void)nav;
|
||||
|
||||
LPC_RGU->RESET_CTRL[0] = (1 << 0);
|
||||
|
||||
while (1)
|
||||
__WFE();
|
||||
}
|
||||
|
||||
/* DebugMenuView *********************************************************/
|
||||
|
||||
DebugMenuView::DebugMenuView(NavigationView& nav) {
|
||||
@@ -464,6 +483,7 @@ DebugMenuView::DebugMenuView(NavigationView& nav) {
|
||||
{"Peripherals", ui::Color::dark_cyan(), &bitmap_icon_peripherals, [&nav]() { nav.push<DebugPeripheralsMenuView>(); }},
|
||||
{"Pers. Memory", ui::Color::dark_cyan(), &bitmap_icon_memory, [&nav]() { nav.push<DebugPmemView>(); }},
|
||||
//{ "Radio State", ui::Color::white(), nullptr, [&nav](){ nav.push<NotImplementedView>(); } },
|
||||
{"Reboot", ui::Color::dark_cyan(), &bitmap_icon_setup, [&nav]() { nav.push<DebugReboot>(); }},
|
||||
{"SD Card", ui::Color::dark_cyan(), &bitmap_icon_sdcard, [&nav]() { nav.push<SDCardDebugView>(); }},
|
||||
{"Temperature", ui::Color::dark_cyan(), &bitmap_icon_temperature, [&nav]() { nav.push<TemperatureView>(); }},
|
||||
{"Touch Test", ui::Color::dark_cyan(), &bitmap_icon_notepad, [&nav]() { nav.push<DebugScreenTest>(); }},
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -251,18 +252,21 @@ class ControlsSwitchesWidget : public Widget {
|
||||
Rect parent_rect)
|
||||
: Widget{parent_rect},
|
||||
key_event_mask(0),
|
||||
long_press_key_event_mask{0} {
|
||||
long_press_key_event_mask{0},
|
||||
last_delta{0} {
|
||||
set_focusable(true);
|
||||
}
|
||||
|
||||
void on_show() override;
|
||||
bool on_key(const KeyEvent key) override;
|
||||
bool on_encoder(const EncoderEvent delta) override;
|
||||
|
||||
void paint(Painter& painter) override;
|
||||
|
||||
private:
|
||||
uint8_t key_event_mask;
|
||||
uint8_t long_press_key_event_mask;
|
||||
EncoderEvent last_delta;
|
||||
|
||||
MessageHandlerRegistration message_handler_frame_sync{
|
||||
Message::ID::DisplayFrameSync,
|
||||
@@ -284,6 +288,7 @@ class DebugControlsView : public View {
|
||||
private:
|
||||
Labels labels{
|
||||
{{8 * 8, 1 * 16}, "Controls State", Color::white()},
|
||||
{{0 * 8, 11 * 16}, "Dial:", Color::grey()},
|
||||
{{0 * 8, 14 * 16}, "Long-Press Mode:", Color::grey()}};
|
||||
|
||||
ControlsSwitchesWidget switches_widget{
|
||||
@@ -419,6 +424,11 @@ class DebugPeripheralsMenuView : public BtnGridView {
|
||||
std::string title() const override { return "Peripherals"; };
|
||||
};
|
||||
|
||||
class DebugReboot : public BtnGridView {
|
||||
public:
|
||||
DebugReboot(NavigationView& nav);
|
||||
};
|
||||
|
||||
class DebugMenuView : public BtnGridView {
|
||||
public:
|
||||
DebugMenuView(NavigationView& nav);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Bernd Herzog
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Bernd Herzog
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Kyle Reed
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Kyle Reed
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyleft (ↄ) 2022 NotPike
|
||||
* Copyright (C) 2023 Kyle Reed, zxkmm
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -389,7 +390,7 @@ PlaylistView::PlaylistView(
|
||||
ensure_directory(u"PLAYLIST");
|
||||
waterfall.show_audio_spectrum_view(false);
|
||||
|
||||
field_frequency.set_value(100'000'000);
|
||||
field_frequency.set_value(transmitter_model.target_frequency());
|
||||
field_frequency.on_change = [this](rf::Frequency f) {
|
||||
if (current())
|
||||
current()->metadata.center_frequency = f;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2023 Kyle Reed, zxkmm
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -56,7 +57,7 @@ class PlaylistView : public View {
|
||||
NavigationView& nav_;
|
||||
TxRadioState radio_state_{};
|
||||
app_settings::SettingsManager settings_{
|
||||
"tx_playlist", app_settings::Mode::TX};
|
||||
"tx_replay", app_settings::Mode::TX};
|
||||
|
||||
// More header == less spectrum view.
|
||||
static constexpr ui::Dim header_height = 6 * 16;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2018 Furrtek
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2018 Furrtek
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2023 gullradriel, Nilorea Studio Inc.
|
||||
* Copyright (C) 2023 Kyle Reed
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
* Copyleft (ɔ) 2024 zxkmm under GPL license
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -42,6 +44,7 @@ namespace fs = std::filesystem;
|
||||
|
||||
#include "string_format.hpp"
|
||||
#include "ui_styles.hpp"
|
||||
#include "ui_font_fixed_8x16.hpp"
|
||||
#include "cpld_update.hpp"
|
||||
#include "config_mode.hpp"
|
||||
|
||||
@@ -81,6 +84,7 @@ SetDateTimeView::SetDateTimeView(
|
||||
&field_second,
|
||||
&text_weekday,
|
||||
&text_day_of_year,
|
||||
&text_in_dst_range,
|
||||
&checkbox_dst_enable,
|
||||
&options_dst_start_which,
|
||||
&options_dst_start_weekday,
|
||||
@@ -100,18 +104,25 @@ SetDateTimeView::SetDateTimeView(
|
||||
options_dst_start_month.set_options(month_options);
|
||||
options_dst_end_month.set_options(month_options);
|
||||
|
||||
const auto dst_changed_fn = [this](size_t, uint32_t) {
|
||||
handle_date_field_update();
|
||||
};
|
||||
|
||||
const auto date_changed_fn = [this](int32_t) {
|
||||
auto weekday = rtc_time::day_of_week(field_year.value(), field_month.value(), field_day.value());
|
||||
auto doy = rtc_time::day_of_year(field_year.value(), field_month.value(), field_day.value());
|
||||
bool valid_date = (field_day.value() <= rtc_time::days_per_month(field_year.value(), field_month.value()));
|
||||
text_weekday.set(valid_date ? weekday_options[weekday].first : "-");
|
||||
text_day_of_year.set(valid_date ? to_string_dec_uint(doy, 3) : "-");
|
||||
handle_date_field_update();
|
||||
};
|
||||
|
||||
field_year.on_change = date_changed_fn;
|
||||
field_month.on_change = date_changed_fn;
|
||||
field_day.on_change = date_changed_fn;
|
||||
|
||||
options_dst_start_which.on_change = dst_changed_fn;
|
||||
options_dst_start_weekday.on_change = dst_changed_fn;
|
||||
options_dst_start_month.on_change = dst_changed_fn;
|
||||
options_dst_end_which.on_change = dst_changed_fn;
|
||||
options_dst_end_weekday.on_change = dst_changed_fn;
|
||||
options_dst_end_month.on_change = dst_changed_fn;
|
||||
|
||||
rtc::RTC datetime;
|
||||
rtc_time::now(datetime);
|
||||
SetDateTimeModel model{
|
||||
@@ -146,6 +157,17 @@ void SetDateTimeView::form_init(const SetDateTimeModel& model) {
|
||||
}
|
||||
|
||||
SetDateTimeModel SetDateTimeView::form_collect() {
|
||||
return {
|
||||
.year = static_cast<uint16_t>(field_year.value()),
|
||||
.month = static_cast<uint8_t>(field_month.value()),
|
||||
.day = static_cast<uint8_t>(field_day.value()),
|
||||
.hour = static_cast<uint8_t>(field_hour.value()),
|
||||
.minute = static_cast<uint8_t>(field_minute.value()),
|
||||
.second = static_cast<uint8_t>(field_second.value()),
|
||||
.dst = dst_collect()};
|
||||
}
|
||||
|
||||
pmem::dst_config_t SetDateTimeView::dst_collect() {
|
||||
pmem::dst_config_t dst;
|
||||
dst.b.dst_enabled = static_cast<uint8_t>(checkbox_dst_enable.value());
|
||||
dst.b.start_which = static_cast<uint8_t>(options_dst_start_which.selected_index_value());
|
||||
@@ -154,14 +176,16 @@ SetDateTimeModel SetDateTimeView::form_collect() {
|
||||
dst.b.end_which = static_cast<uint8_t>(options_dst_end_which.selected_index_value());
|
||||
dst.b.end_weekday = static_cast<uint8_t>(options_dst_end_weekday.selected_index_value());
|
||||
dst.b.end_month = static_cast<uint8_t>(options_dst_end_month.selected_index_value());
|
||||
return {
|
||||
.year = static_cast<uint16_t>(field_year.value()),
|
||||
.month = static_cast<uint8_t>(field_month.value()),
|
||||
.day = static_cast<uint8_t>(field_day.value()),
|
||||
.hour = static_cast<uint8_t>(field_hour.value()),
|
||||
.minute = static_cast<uint8_t>(field_minute.value()),
|
||||
.second = static_cast<uint8_t>(field_second.value()),
|
||||
.dst = dst};
|
||||
return dst;
|
||||
}
|
||||
|
||||
void SetDateTimeView::handle_date_field_update() {
|
||||
auto weekday = rtc_time::day_of_week(field_year.value(), field_month.value(), field_day.value());
|
||||
auto doy = rtc_time::day_of_year(field_year.value(), field_month.value(), field_day.value());
|
||||
bool valid_date = (field_day.value() <= rtc_time::days_per_month(field_year.value(), field_month.value()));
|
||||
text_weekday.set(valid_date ? weekday_options[weekday].first : "-");
|
||||
text_day_of_year.set(valid_date ? to_string_dec_uint(doy, 3) : "-");
|
||||
text_in_dst_range.set(checkbox_dst_enable.value() && rtc_time::dst_test_date_range(field_year.value(), doy, dst_collect()) ? "DST" : "");
|
||||
}
|
||||
|
||||
/* SetRadioView ******************************************/
|
||||
@@ -293,6 +317,7 @@ SetUIView::SetUIView(NavigationView& nav) {
|
||||
&toggle_bias_tee,
|
||||
&toggle_clock,
|
||||
&toggle_mute,
|
||||
&toggle_fake_brightness,
|
||||
&toggle_sd_card,
|
||||
&button_save,
|
||||
&button_cancel});
|
||||
@@ -326,6 +351,7 @@ SetUIView::SetUIView(NavigationView& nav) {
|
||||
toggle_clock.set_value(!pmem::ui_hide_clock());
|
||||
toggle_speaker.set_value(!pmem::ui_hide_speaker());
|
||||
toggle_mute.set_value(!pmem::ui_hide_mute());
|
||||
toggle_fake_brightness.set_value(!pmem::ui_hide_fake_brightness());
|
||||
toggle_sd_card.set_value(!pmem::ui_hide_sd_card());
|
||||
|
||||
button_save.on_select = [&nav, this](Button&) {
|
||||
@@ -352,6 +378,7 @@ SetUIView::SetUIView(NavigationView& nav) {
|
||||
pmem::set_ui_hide_clock(!toggle_clock.value());
|
||||
pmem::set_ui_hide_speaker(!toggle_speaker.value());
|
||||
pmem::set_ui_hide_mute(!toggle_mute.value());
|
||||
pmem::set_ui_hide_fake_brightness(!toggle_fake_brightness.value());
|
||||
pmem::set_ui_hide_sd_card(!toggle_sd_card.value());
|
||||
send_system_refresh();
|
||||
|
||||
@@ -586,6 +613,8 @@ SetPersistentMemoryView::SetPersistentMemoryView(NavigationView& nav) {
|
||||
[this](bool choice) {
|
||||
if (choice) {
|
||||
pmem::cache::defaults();
|
||||
// Refresh status bar
|
||||
send_system_refresh();
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -655,13 +684,16 @@ void SetQRCodeView::focus() {
|
||||
SetEncoderDialView::SetEncoderDialView(NavigationView& nav) {
|
||||
add_children({&labels,
|
||||
&field_encoder_dial_sensitivity,
|
||||
&field_encoder_rate_multiplier,
|
||||
&button_save,
|
||||
&button_cancel});
|
||||
|
||||
field_encoder_dial_sensitivity.set_by_value(pmem::config_encoder_dial_sensitivity());
|
||||
field_encoder_dial_sensitivity.set_by_value(pmem::encoder_dial_sensitivity());
|
||||
field_encoder_rate_multiplier.set_value(pmem::encoder_rate_multiplier());
|
||||
|
||||
button_save.on_select = [&nav, this](Button&) {
|
||||
pmem::set_encoder_dial_sensitivity(field_encoder_dial_sensitivity.selected_index_value());
|
||||
pmem::set_encoder_rate_multiplier(field_encoder_rate_multiplier.value());
|
||||
nav.pop();
|
||||
};
|
||||
|
||||
@@ -726,6 +758,81 @@ void SetConfigModeView::focus() {
|
||||
button_save.focus();
|
||||
}
|
||||
|
||||
/* SetFakeBrightnessView ************************************/
|
||||
|
||||
SetFakeBrightnessView::SetFakeBrightnessView(NavigationView& nav) {
|
||||
add_children({&labels,
|
||||
&field_fake_brightness,
|
||||
&button_save,
|
||||
&button_cancel,
|
||||
&checkbox_brightness_switch});
|
||||
|
||||
field_fake_brightness.set_by_value(pmem::fake_brightness_level());
|
||||
checkbox_brightness_switch.set_value(pmem::apply_fake_brightness());
|
||||
|
||||
button_save.on_select = [&nav, this](Button&) {
|
||||
pmem::set_apply_fake_brightness(checkbox_brightness_switch.value());
|
||||
pmem::set_fake_brightness_level(field_fake_brightness.selected_index_value());
|
||||
send_system_refresh();
|
||||
nav.pop();
|
||||
};
|
||||
|
||||
button_cancel.on_select = [&nav, this](Button&) {
|
||||
nav.pop();
|
||||
};
|
||||
}
|
||||
|
||||
void SetFakeBrightnessView::focus() {
|
||||
button_save.focus();
|
||||
}
|
||||
|
||||
/* SetMenuColorView ************************************/
|
||||
|
||||
void SetMenuColorView::paint_sample() {
|
||||
Color c = Color(field_red_level.value(), field_green_level.value(), field_blue_level.value());
|
||||
button_sample.set_bg_color(c);
|
||||
}
|
||||
|
||||
SetMenuColorView::SetMenuColorView(NavigationView& nav) {
|
||||
add_children({&labels,
|
||||
&button_sample,
|
||||
&field_red_level,
|
||||
&field_green_level,
|
||||
&field_blue_level,
|
||||
&button_save,
|
||||
&button_cancel});
|
||||
|
||||
button_sample.set_focusable(false);
|
||||
|
||||
Color c = pmem::menu_color();
|
||||
field_red_level.set_value(c.r());
|
||||
field_green_level.set_value(c.g());
|
||||
field_blue_level.set_value(c.b());
|
||||
paint_sample();
|
||||
|
||||
const auto color_changed_fn = [this](int32_t) {
|
||||
paint_sample();
|
||||
};
|
||||
field_red_level.on_change = color_changed_fn;
|
||||
field_green_level.on_change = color_changed_fn;
|
||||
field_blue_level.on_change = color_changed_fn;
|
||||
|
||||
button_save.on_select = [&nav, this](Button&) {
|
||||
Color c = Color(field_red_level.value(), field_green_level.value(), field_blue_level.value());
|
||||
pmem::set_menu_color(c);
|
||||
send_system_refresh();
|
||||
nav.pop();
|
||||
};
|
||||
|
||||
button_cancel.on_select = [&nav, this](Button&) {
|
||||
nav.pop();
|
||||
};
|
||||
}
|
||||
|
||||
void SetMenuColorView::focus() {
|
||||
button_save.focus();
|
||||
}
|
||||
|
||||
/* SettingsMenuView **************************************/
|
||||
|
||||
SettingsMenuView::SettingsMenuView(NavigationView& nav) {
|
||||
@@ -746,6 +853,8 @@ SettingsMenuView::SettingsMenuView(NavigationView& nav) {
|
||||
{"SD Card", ui::Color::dark_cyan(), &bitmap_icon_sdcard, [&nav]() { nav.push<SetSDCardView>(); }},
|
||||
{"User Interface", ui::Color::dark_cyan(), &bitmap_icon_options_ui, [&nav]() { nav.push<SetUIView>(); }},
|
||||
{"QR Code", ui::Color::dark_cyan(), &bitmap_icon_qr_code, [&nav]() { nav.push<SetQRCodeView>(); }},
|
||||
{"Brightness", ui::Color::dark_cyan(), &bitmap_icon_brightness, [&nav]() { nav.push<SetFakeBrightnessView>(); }},
|
||||
{"Menu Color", ui::Color::dark_cyan(), &bitmap_icon_brightness, [&nav]() { nav.push<SetMenuColorView>(); }},
|
||||
});
|
||||
set_max_rows(2); // allow wider buttons
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2023 gullradriel, Nilorea Studio Inc.
|
||||
* Copyright (C) 2023 Kyle Reed
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
* Copyleft (ɔ) 2024 zxkmm under GPL license
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -126,6 +128,9 @@ class SetDateTimeView : public View {
|
||||
Text text_day_of_year{
|
||||
{26 * 8, 6 * 16, 3 * 8, 16},
|
||||
""};
|
||||
Text text_in_dst_range{
|
||||
{17 * 8, 7 * 16, 3 * 8, 16},
|
||||
""};
|
||||
|
||||
Checkbox checkbox_dst_enable{
|
||||
{2 * 8, 9 * 16},
|
||||
@@ -171,6 +176,8 @@ class SetDateTimeView : public View {
|
||||
|
||||
void form_init(const SetDateTimeModel& model);
|
||||
SetDateTimeModel form_collect();
|
||||
portapack::persistent_memory::dst_config_t dst_collect();
|
||||
void handle_date_field_update();
|
||||
};
|
||||
|
||||
struct SetFrequencyCorrectionModel {
|
||||
@@ -315,39 +322,43 @@ class SetUIView : public View {
|
||||
};
|
||||
|
||||
ImageToggle toggle_camera{
|
||||
{7 * 8, 14 * 16 + 2, 16, 16},
|
||||
{6 * 8, 14 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_camera};
|
||||
|
||||
ImageToggle toggle_sleep{
|
||||
{9 * 8, 14 * 16 + 2, 16, 16},
|
||||
{8 * 8, 14 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_sleep};
|
||||
|
||||
ImageToggle toggle_stealth{
|
||||
{11 * 8, 14 * 16 + 2, 16, 16},
|
||||
{10 * 8, 14 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_stealth};
|
||||
|
||||
ImageToggle toggle_converter{
|
||||
{13 * 8, 14 * 16 + 2, 16, 16},
|
||||
{12 * 8, 14 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_upconvert};
|
||||
|
||||
ImageToggle toggle_bias_tee{
|
||||
{15 * 8, 14 * 16 + 2, 16, 16},
|
||||
{14 * 8, 14 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_biast_off};
|
||||
|
||||
ImageToggle toggle_clock{
|
||||
{17 * 8, 14 * 16 + 2, 8, 16},
|
||||
{16 * 8, 14 * 16 + 2, 8, 16},
|
||||
&bitmap_icon_clk_ext};
|
||||
|
||||
ImageToggle toggle_mute{
|
||||
{18 * 8, 14 * 16 + 2, 16, 16},
|
||||
{17 * 8, 14 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_speaker_and_headphones_mute};
|
||||
|
||||
ImageToggle toggle_speaker{
|
||||
{20 * 8, 14 * 16 + 2, 16, 16},
|
||||
{19 * 8, 14 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_speaker_mute};
|
||||
|
||||
ImageToggle toggle_fake_brightness{
|
||||
{21 * 8, 14 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_brightness};
|
||||
|
||||
ImageToggle toggle_sd_card{
|
||||
{22 * 8, 14 * 16 + 2, 16, 16},
|
||||
{23 * 8, 14 * 16 + 2, 16, 16},
|
||||
&bitmap_sd_card_ok};
|
||||
|
||||
Button button_save{
|
||||
@@ -545,6 +556,7 @@ class SetQRCodeView : public View {
|
||||
};
|
||||
|
||||
using portapack::persistent_memory::encoder_dial_sensitivity;
|
||||
using portapack::persistent_memory::encoder_rate_multiplier;
|
||||
|
||||
class SetEncoderDialView : public View {
|
||||
public:
|
||||
@@ -556,18 +568,30 @@ class SetEncoderDialView : public View {
|
||||
|
||||
private:
|
||||
Labels labels{
|
||||
{{1 * 8, 1 * 16}, "Adjusts how many steps to", Color::light_grey()},
|
||||
{{1 * 8, 2 * 16}, "change the encoder value.", Color::light_grey()},
|
||||
{{2 * 8, 4 * 16}, "Dial sensitivity:", Color::light_grey()},
|
||||
{{1 * 8, 1 * 16}, "Adjusts sensitivity to dial", Color::light_grey()},
|
||||
{{1 * 8, 2 * 16}, "rotation position (number of", Color::light_grey()},
|
||||
{{1 * 8, 3 * 16}, "steps per full rotation):", Color::light_grey()},
|
||||
{{2 * 8, 5 * 16}, "Dial sensitivity:", Color::light_grey()},
|
||||
{{1 * 8, 8 * 16}, "Adjusts sensitivity to dial", Color::light_grey()},
|
||||
{{1 * 8, 9 * 16}, "rotation rate (default 1", Color::light_grey()},
|
||||
{{1 * 8, 10 * 16}, "means no rate dependency):", Color::light_grey()},
|
||||
{{3 * 8, 12 * 16}, "Rate multiplier:", Color::light_grey()},
|
||||
};
|
||||
|
||||
OptionsField field_encoder_dial_sensitivity{
|
||||
{20 * 8, 4 * 16},
|
||||
{20 * 8, 5 * 16},
|
||||
6,
|
||||
{{"LOW", encoder_dial_sensitivity::DIAL_SENSITIVITY_LOW},
|
||||
{"NORMAL", encoder_dial_sensitivity::DIAL_SENSITIVITY_NORMAL},
|
||||
{"HIGH", encoder_dial_sensitivity::DIAL_SENSITIVITY_HIGH}}};
|
||||
|
||||
NumberField field_encoder_rate_multiplier{
|
||||
{20 * 8, 12 * 16},
|
||||
2,
|
||||
{1, 15},
|
||||
1,
|
||||
' '};
|
||||
|
||||
Button button_save{
|
||||
{2 * 8, 16 * 16, 12 * 8, 32},
|
||||
"Save"};
|
||||
@@ -667,6 +691,104 @@ class SetConfigModeView : public View {
|
||||
};
|
||||
};
|
||||
|
||||
using portapack::persistent_memory::fake_brightness_level_options;
|
||||
|
||||
class SetFakeBrightnessView : public View {
|
||||
public:
|
||||
SetFakeBrightnessView(NavigationView& nav);
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "Brightness"; };
|
||||
|
||||
private:
|
||||
Labels labels{
|
||||
{{1 * 8, 1 * 16}, "Limits screen brightness", Color::light_grey()},
|
||||
{{1 * 8, 2 * 16}, "(has a small performance", Color::light_grey()},
|
||||
{{1 * 8, 3 * 16}, "impact when enabled).", Color::light_grey()},
|
||||
{{2 * 8, 8 * 16}, "Brightness:", Color::light_grey()},
|
||||
};
|
||||
|
||||
OptionsField field_fake_brightness{
|
||||
{20 * 8, 8 * 16},
|
||||
6,
|
||||
{{"12.5%", fake_brightness_level_options::BRIGHTNESS_12p5},
|
||||
{"25%", fake_brightness_level_options::BRIGHTNESS_25},
|
||||
{"50%", fake_brightness_level_options::BRIGHTNESS_50}}};
|
||||
|
||||
Checkbox checkbox_brightness_switch{
|
||||
{1 * 8, 5 * 16},
|
||||
16,
|
||||
"Enable brightness adjust"};
|
||||
|
||||
Button button_save{
|
||||
{2 * 8, 16 * 16, 12 * 8, 32},
|
||||
"Save"};
|
||||
|
||||
Button button_cancel{
|
||||
{16 * 8, 16 * 16, 12 * 8, 32},
|
||||
"Cancel",
|
||||
};
|
||||
};
|
||||
|
||||
class SetMenuColorView : public View {
|
||||
public:
|
||||
SetMenuColorView(NavigationView& nav);
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "Menu Color"; };
|
||||
|
||||
private:
|
||||
void paint_sample();
|
||||
|
||||
Labels labels{
|
||||
{{3 * 8, 1 * 16}, "Menu Button Color Scheme", Color::light_grey()},
|
||||
{{2 * 8, 8 * 16}, "Red Level:", Color::light_grey()},
|
||||
{{2 * 8, 9 * 16}, "Green Level:", Color::light_grey()},
|
||||
{{2 * 8, 10 * 16}, "Blue Level:", Color::light_grey()},
|
||||
};
|
||||
|
||||
NewButton button_sample{
|
||||
{8 * 8, 4 * 16, 14 * 8, 3 * 16},
|
||||
"New Color",
|
||||
&bitmap_icon_brightness,
|
||||
};
|
||||
|
||||
NumberField field_red_level{
|
||||
{15 * 8, 8 * 16},
|
||||
3,
|
||||
{8, 248},
|
||||
8,
|
||||
' ',
|
||||
};
|
||||
|
||||
NumberField field_green_level{
|
||||
{15 * 8, 9 * 16},
|
||||
3,
|
||||
{8, 248},
|
||||
8,
|
||||
' ',
|
||||
};
|
||||
|
||||
NumberField field_blue_level{
|
||||
{15 * 8, 10 * 16},
|
||||
3,
|
||||
{8, 248},
|
||||
8,
|
||||
' ',
|
||||
};
|
||||
|
||||
Button button_save{
|
||||
{2 * 8, 16 * 16, 12 * 8, 32},
|
||||
"Save"};
|
||||
|
||||
Button button_cancel{
|
||||
{16 * 8, 16 * 16, 12 * 8, 32},
|
||||
"Cancel",
|
||||
};
|
||||
};
|
||||
|
||||
class SettingsMenuView : public BtnGridView {
|
||||
public:
|
||||
SettingsMenuView(NavigationView& nav);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Kyle Reed
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Kyle Reed
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Kyle Reed
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -26,6 +27,8 @@
|
||||
#include "log_file.hpp"
|
||||
#include "string_format.hpp"
|
||||
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@@ -424,6 +427,9 @@ TextEditorView::TextEditorView(NavigationView& nav)
|
||||
&text_size,
|
||||
});
|
||||
|
||||
text_position.set_style(&Styles::bg_dark_blue);
|
||||
text_size.set_style(&Styles::bg_dark_blue);
|
||||
|
||||
viewer.set_font_zoom(enable_zoom);
|
||||
|
||||
viewer.on_select = [this]() {
|
||||
@@ -550,6 +556,8 @@ void TextEditorView::open_file(const fs::path& path) {
|
||||
viewer.set_file(*file_);
|
||||
}
|
||||
|
||||
portapack::persistent_memory::set_apply_fake_brightness(false); // work around to resolve the display issue in notepad app. not elegant i know, so TODO.
|
||||
|
||||
refresh_ui();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Kyle Reed
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2017 Furrtek
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -38,9 +39,24 @@ void ViewWavView::update_scale(int32_t new_scale) {
|
||||
}
|
||||
|
||||
void ViewWavView::refresh_waveform() {
|
||||
// NB: We can't read from the file to update the waveform when playback is in progress, so defer til playback done.
|
||||
// (This only happens if the user messes with position or scale fields while playback is occurring)
|
||||
if (playback_in_progress) {
|
||||
waveform_update_needed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t bits_per_sample = wav_reader->bits_per_sample();
|
||||
|
||||
for (size_t i = 0; i < 240; i++) {
|
||||
wav_reader->data_seek(position + (i * scale));
|
||||
wav_reader->read(&waveform_buffer[i], sizeof(int16_t));
|
||||
if (bits_per_sample == 8) {
|
||||
uint8_t sample;
|
||||
wav_reader->read(&sample, 1);
|
||||
waveform_buffer[i] = (sample - 0x80) * 256;
|
||||
} else {
|
||||
wav_reader->read(&waveform_buffer[i], 2);
|
||||
}
|
||||
}
|
||||
|
||||
waveform.set_dirty();
|
||||
@@ -73,13 +89,29 @@ void ViewWavView::paint(Painter& painter) {
|
||||
painter.draw_vline({(Coord)i, 11 * 16}, 8, spectrum_rgb2_lut[amplitude_buffer[i] << 1]);
|
||||
}
|
||||
|
||||
void ViewWavView::on_pos_changed() {
|
||||
position = (field_pos_seconds.value() * wav_reader->sample_rate()) + field_pos_samples.value();
|
||||
void ViewWavView::on_pos_time_changed() {
|
||||
position = (uint64_t)((field_pos_seconds.value() * 1000) + field_pos_milliseconds.value()) * wav_reader->sample_rate() / 1000;
|
||||
field_pos_milliseconds.set_range(0, ((uint32_t)field_pos_seconds.value() == wav_reader->ms_duration() / 1000) ? wav_reader->ms_duration() % 1000 : 999);
|
||||
if (!updating_position) {
|
||||
updating_position = true; // prevent recursion
|
||||
field_pos_samples.set_value(position);
|
||||
updating_position = false;
|
||||
}
|
||||
refresh_waveform();
|
||||
}
|
||||
|
||||
void ViewWavView::on_pos_sample_changed() {
|
||||
position = field_pos_samples.value();
|
||||
if (!updating_position) {
|
||||
updating_position = true; // prevent recursion
|
||||
field_pos_seconds.set_value(field_pos_samples.value() / wav_reader->sample_rate());
|
||||
field_pos_milliseconds.set_value((field_pos_samples.value() * 1000ull / wav_reader->sample_rate()) % 1000);
|
||||
updating_position = false;
|
||||
}
|
||||
refresh_waveform();
|
||||
}
|
||||
|
||||
void ViewWavView::load_wav(std::filesystem::path file_path) {
|
||||
int16_t sample;
|
||||
uint32_t average;
|
||||
|
||||
wav_file_path = file_path;
|
||||
@@ -91,18 +123,27 @@ void ViewWavView::load_wav(std::filesystem::path file_path) {
|
||||
wav_reader->rewind();
|
||||
|
||||
text_samplerate.set(to_string_dec_uint(wav_reader->sample_rate()) + "Hz");
|
||||
text_bits_per_sample.set(to_string_dec_uint(wav_reader->bits_per_sample(), 2));
|
||||
text_title.set(wav_reader->title());
|
||||
|
||||
// Fill amplitude buffer, world's worst downsampling
|
||||
uint64_t skip = wav_reader->sample_count() / (240 * subsampling_factor);
|
||||
uint8_t bits_per_sample = wav_reader->bits_per_sample();
|
||||
|
||||
for (size_t i = 0; i < 240; i++) {
|
||||
average = 0;
|
||||
|
||||
for (size_t s = 0; s < subsampling_factor; s++) {
|
||||
wav_reader->data_seek(((i * subsampling_factor) + s) * skip);
|
||||
wav_reader->read(&sample, 2);
|
||||
average += (abs(sample) >> 8);
|
||||
if (bits_per_sample == 8) {
|
||||
uint8_t sample;
|
||||
wav_reader->read(&sample, 1);
|
||||
average += sample / 2;
|
||||
} else {
|
||||
int16_t sample;
|
||||
wav_reader->read(&sample, 2);
|
||||
average += (abs(sample) >> 8);
|
||||
}
|
||||
}
|
||||
|
||||
amplitude_buffer[i] = average / subsampling_factor;
|
||||
@@ -118,6 +159,10 @@ void ViewWavView::reset_controls() {
|
||||
field_pos_samples.set_value(0);
|
||||
field_cursor_a.set_value(0);
|
||||
field_cursor_b.set_value(0);
|
||||
field_pos_seconds.set_range(0, wav_reader->ms_duration() / 1000);
|
||||
field_pos_milliseconds.set_range(0, (wav_reader->ms_duration() < 1000) ? wav_reader->ms_duration() % 1000 : 999);
|
||||
field_pos_samples.set_range(0, wav_reader->sample_count() - 1);
|
||||
field_scale.set_range(1, std::min(99999ul, wav_reader->sample_count() / 240));
|
||||
}
|
||||
|
||||
bool ViewWavView::is_active() {
|
||||
@@ -142,6 +187,13 @@ void ViewWavView::handle_replay_thread_done(const uint32_t return_code) {
|
||||
|
||||
if (return_code == ReplayThread::READ_ERROR)
|
||||
file_error();
|
||||
|
||||
// Playback complete - now it's safe to update waveform view
|
||||
playback_in_progress = false;
|
||||
if (waveform_update_needed) {
|
||||
waveform_update_needed = false;
|
||||
refresh_waveform();
|
||||
}
|
||||
}
|
||||
|
||||
void ViewWavView::set_ready() {
|
||||
@@ -154,6 +206,7 @@ void ViewWavView::file_error() {
|
||||
|
||||
void ViewWavView::start_playback() {
|
||||
uint32_t sample_rate;
|
||||
uint8_t bits_per_sample;
|
||||
|
||||
auto reader = std::make_unique<WAVFileReader>();
|
||||
|
||||
@@ -164,9 +217,12 @@ void ViewWavView::start_playback() {
|
||||
return;
|
||||
}
|
||||
|
||||
playback_in_progress = true;
|
||||
|
||||
button_play.set_bitmap(&bitmap_stop);
|
||||
|
||||
sample_rate = reader->sample_rate();
|
||||
bits_per_sample = reader->bits_per_sample();
|
||||
|
||||
progressbar.set_max(reader->sample_count());
|
||||
|
||||
@@ -180,24 +236,26 @@ void ViewWavView::start_playback() {
|
||||
});
|
||||
|
||||
baseband::set_audiotx_config(
|
||||
1536000 / 20, // Rate of sending progress updates
|
||||
0, // Transmit BW = 0 = not transmitting
|
||||
0, // Gain - unused
|
||||
8, // shift_bits_s16, default 8 bits - unused
|
||||
16, // bits per sample
|
||||
0, // tone key disabled
|
||||
false, // AM
|
||||
false, // DSB
|
||||
false, // USB
|
||||
false // LSB
|
||||
1536000 / 20, // Rate of sending progress updates
|
||||
0, // Transmit BW = 0 = not transmitting
|
||||
0, // Gain - unused
|
||||
8, // shift_bits_s16, default 8 bits - unused
|
||||
bits_per_sample, // bits_per_sample
|
||||
0, // tone key disabled
|
||||
false, // AM
|
||||
false, // DSB
|
||||
false, // USB
|
||||
false // LSB
|
||||
);
|
||||
baseband::set_sample_rate(sample_rate);
|
||||
transmitter_model.set_sampling_rate(1536000);
|
||||
|
||||
audio::output::start();
|
||||
}
|
||||
|
||||
void ViewWavView::on_playback_progress(const uint32_t progress) {
|
||||
progressbar.set_value(progress);
|
||||
field_pos_samples.set_value(progress);
|
||||
}
|
||||
|
||||
ViewWavView::ViewWavView(
|
||||
@@ -211,11 +269,13 @@ ViewWavView::ViewWavView(
|
||||
&text_samplerate,
|
||||
&text_title,
|
||||
&text_duration,
|
||||
&text_bits_per_sample,
|
||||
&button_open,
|
||||
&button_play,
|
||||
&waveform,
|
||||
&progressbar,
|
||||
&field_pos_seconds,
|
||||
&field_pos_milliseconds,
|
||||
&field_pos_samples,
|
||||
&field_scale,
|
||||
&field_cursor_a,
|
||||
@@ -234,8 +294,8 @@ ViewWavView::ViewWavView(
|
||||
file_error();
|
||||
return;
|
||||
}
|
||||
if ((wav_reader->channels() != 1) || (wav_reader->bits_per_sample() != 16)) {
|
||||
nav_.display_modal("Error", "Wrong format.\nWav viewer only accepts\n16-bit mono files.");
|
||||
if ((wav_reader->channels() != 1) || ((wav_reader->bits_per_sample() != 8) && (wav_reader->bits_per_sample() != 16))) {
|
||||
nav_.display_modal("Error", "Wrong format.\nWav viewer only accepts\n8 or 16-bit mono files.");
|
||||
return;
|
||||
}
|
||||
load_wav(file_path);
|
||||
@@ -257,10 +317,13 @@ ViewWavView::ViewWavView(
|
||||
update_scale(value);
|
||||
};
|
||||
field_pos_seconds.on_change = [this](int32_t) {
|
||||
on_pos_changed();
|
||||
on_pos_time_changed();
|
||||
};
|
||||
field_pos_milliseconds.on_change = [this](int32_t) {
|
||||
on_pos_time_changed();
|
||||
};
|
||||
field_pos_samples.on_change = [this](int32_t) {
|
||||
on_pos_changed();
|
||||
on_pos_sample_changed();
|
||||
};
|
||||
|
||||
field_cursor_a.on_change = [this](int32_t v) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2017 Furrtek
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -49,7 +50,8 @@ class ViewWavView : public View {
|
||||
void update_scale(int32_t new_scale);
|
||||
void refresh_waveform();
|
||||
void refresh_measurements();
|
||||
void on_pos_changed();
|
||||
void on_pos_time_changed();
|
||||
void on_pos_sample_changed();
|
||||
void load_wav(std::filesystem::path file_path);
|
||||
void reset_controls();
|
||||
bool is_active();
|
||||
@@ -74,30 +76,37 @@ class ViewWavView : public View {
|
||||
int32_t scale{1};
|
||||
uint64_t ns_per_pixel{};
|
||||
uint64_t position{};
|
||||
bool updating_position{false};
|
||||
bool playback_in_progress{false};
|
||||
bool waveform_update_needed{false};
|
||||
|
||||
Labels labels{
|
||||
{{0 * 8, 0 * 16}, "File:", Color::light_grey()},
|
||||
{{0 * 8, 1 * 16}, "Samplerate:", Color::light_grey()},
|
||||
{{2 * 8, 1 * 16}, "-bit mono", Color::light_grey()},
|
||||
{{0 * 8, 2 * 16}, "Title:", Color::light_grey()},
|
||||
{{0 * 8, 3 * 16}, "Duration:", Color::light_grey()},
|
||||
{{0 * 8, 12 * 16}, "Position: s Scale:", Color::light_grey()},
|
||||
{{0 * 8, 13 * 16}, "Cursor A:", Color::dark_cyan()},
|
||||
{{0 * 8, 14 * 16}, "Cursor B:", Color::dark_magenta()},
|
||||
{{0 * 8, 15 * 16}, "Delta:", Color::light_grey()},
|
||||
{{0 * 8, 12 * 16}, "Position: . s Scale:", Color::light_grey()},
|
||||
{{0 * 8, 13 * 16}, " Sample:", Color::light_grey()},
|
||||
{{0 * 8, 14 * 16}, "Cursor A:", Color::dark_cyan()},
|
||||
{{0 * 8, 15 * 16}, "Cursor B:", Color::dark_magenta()},
|
||||
{{0 * 8, 16 * 16}, "Delta:", Color::light_grey()},
|
||||
{{24 * 8, 18 * 16}, "Vol:", Color::light_grey()}};
|
||||
|
||||
Text text_filename{
|
||||
{5 * 8, 0 * 16, 12 * 8, 16},
|
||||
{5 * 8, 0 * 16, 18 * 8, 16},
|
||||
""};
|
||||
Text text_samplerate{
|
||||
{11 * 8, 1 * 16, 8 * 8, 16},
|
||||
{12 * 8, 1 * 16, 10 * 8, 16},
|
||||
""};
|
||||
Text text_title{
|
||||
{6 * 8, 2 * 16, 18 * 8, 16},
|
||||
{6 * 8, 2 * 16, 17 * 8, 16},
|
||||
""};
|
||||
Text text_duration{
|
||||
{9 * 8, 3 * 16, 18 * 8, 16},
|
||||
{9 * 8, 3 * 16, 20 * 8, 16},
|
||||
""};
|
||||
Text text_bits_per_sample{
|
||||
{0 * 8, 1 * 16, 2 * 8, 16},
|
||||
"16"};
|
||||
Button button_open{
|
||||
{24 * 8, 8, 6 * 8, 2 * 16},
|
||||
"Open"};
|
||||
@@ -118,36 +127,38 @@ class ViewWavView : public View {
|
||||
Color::white()};
|
||||
|
||||
ProgressBar progressbar{
|
||||
{0 * 8, 11 * 16, 30 * 8, 8}};
|
||||
{0 * 8, 11 * 16, 30 * 8, 4}};
|
||||
|
||||
NumberField field_pos_seconds{
|
||||
{9 * 8, 12 * 16},
|
||||
4,
|
||||
{0, 0},
|
||||
1,
|
||||
' ',
|
||||
true};
|
||||
NumberField field_pos_milliseconds{
|
||||
{14 * 8, 12 * 16},
|
||||
3,
|
||||
{0, 999},
|
||||
1,
|
||||
' '};
|
||||
'0',
|
||||
true};
|
||||
NumberField field_pos_samples{
|
||||
{14 * 8, 12 * 16},
|
||||
6,
|
||||
{0, 999999},
|
||||
1,
|
||||
'0'};
|
||||
NumberField field_scale{
|
||||
{28 * 8, 12 * 16},
|
||||
2,
|
||||
{1, 40},
|
||||
1,
|
||||
' '};
|
||||
|
||||
NumberField field_cursor_a{
|
||||
{9 * 8, 13 * 16},
|
||||
3,
|
||||
{0, 239},
|
||||
9,
|
||||
{0, 0},
|
||||
1,
|
||||
'0',
|
||||
true};
|
||||
NumberField field_scale{
|
||||
{25 * 8, 12 * 16},
|
||||
5,
|
||||
{1, 1},
|
||||
1,
|
||||
' ',
|
||||
true};
|
||||
|
||||
NumberField field_cursor_b{
|
||||
NumberField field_cursor_a{
|
||||
{9 * 8, 14 * 16},
|
||||
3,
|
||||
{0, 239},
|
||||
@@ -155,8 +166,16 @@ class ViewWavView : public View {
|
||||
' ',
|
||||
true};
|
||||
|
||||
NumberField field_cursor_b{
|
||||
{9 * 8, 15 * 16},
|
||||
3,
|
||||
{0, 239},
|
||||
1,
|
||||
' ',
|
||||
true};
|
||||
|
||||
Text text_delta{
|
||||
{7 * 8, 15 * 16, 30 * 8, 16},
|
||||
{7 * 8, 16 * 16, 30 * 8, 16},
|
||||
"-"};
|
||||
|
||||
MessageHandlerRegistration message_handler_replay_thread_error{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -5759,6 +5759,44 @@ static constexpr Bitmap bitmap_icon_thermometer{
|
||||
{16, 16},
|
||||
bitmap_icon_thermometer_data};
|
||||
|
||||
static constexpr uint8_t bitmap_icon_brightness_data[] = {
|
||||
0x00,
|
||||
0x00,
|
||||
0x80,
|
||||
0x01,
|
||||
0x80,
|
||||
0x01,
|
||||
0x08,
|
||||
0x10,
|
||||
0xC0,
|
||||
0x03,
|
||||
0xE0,
|
||||
0x07,
|
||||
0xF0,
|
||||
0x0F,
|
||||
0xF6,
|
||||
0x6F,
|
||||
0xF6,
|
||||
0x6F,
|
||||
0xF0,
|
||||
0x0F,
|
||||
0xE0,
|
||||
0x07,
|
||||
0xC0,
|
||||
0x03,
|
||||
0x08,
|
||||
0x10,
|
||||
0x80,
|
||||
0x01,
|
||||
0x80,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
static constexpr Bitmap bitmap_icon_brightness{
|
||||
{16, 16},
|
||||
bitmap_icon_brightness_data};
|
||||
|
||||
} /* namespace ui */
|
||||
|
||||
#endif /*__BITMAP_HPP__*/
|
||||
|
||||
@@ -25,14 +25,12 @@
|
||||
#include "file.hpp"
|
||||
#include <cstring>
|
||||
|
||||
namespace std {
|
||||
|
||||
int database::retrieve_mid_record(MidDBRecord* record, std::string search_term) {
|
||||
file_path = "AIS/mids.db";
|
||||
index_item_length = 4;
|
||||
record_length = 32;
|
||||
|
||||
result = std::database::retrieve_record(file_path, index_item_length, record_length, record, search_term);
|
||||
result = retrieve_record(file_path, index_item_length, record_length, record, search_term);
|
||||
|
||||
return (result);
|
||||
}
|
||||
@@ -42,7 +40,7 @@ int database::retrieve_airline_record(AirlinesDBRecord* record, std::string sear
|
||||
index_item_length = 4;
|
||||
record_length = 64;
|
||||
|
||||
result = std::database::retrieve_record(file_path, index_item_length, record_length, record, search_term);
|
||||
result = retrieve_record(file_path, index_item_length, record_length, record, search_term);
|
||||
|
||||
return (result);
|
||||
}
|
||||
@@ -52,12 +50,15 @@ int database::retrieve_aircraft_record(AircraftDBRecord* record, std::string sea
|
||||
index_item_length = 7;
|
||||
record_length = 146;
|
||||
|
||||
result = std::database::retrieve_record(file_path, index_item_length, record_length, record, search_term);
|
||||
result = retrieve_record(file_path, index_item_length, record_length, record, search_term);
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
int database::retrieve_record(std::string file_path, int index_item_length, int record_length, void* record, std::string search_term) {
|
||||
if (search_term.empty())
|
||||
return DATABASE_RECORD_NOT_FOUND;
|
||||
|
||||
auto result = db_file.open(file_path);
|
||||
if (!result.is_valid()) {
|
||||
number_of_records = (db_file.size() / (index_item_length + record_length)); // determine number of records in file
|
||||
@@ -91,5 +92,3 @@ int database::retrieve_record(std::string file_path, int index_item_length, int
|
||||
} else
|
||||
return (DATABASE_NOT_FOUND);
|
||||
}
|
||||
|
||||
} /* namespace std */
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
|
||||
#include "file.hpp"
|
||||
|
||||
namespace std {
|
||||
class database {
|
||||
public:
|
||||
#define DATABASE_RECORD_FOUND 0 // record found in database
|
||||
@@ -62,9 +61,9 @@ class database {
|
||||
int retrieve_aircraft_record(AircraftDBRecord* record, std::string search_term);
|
||||
|
||||
private:
|
||||
string file_path = ""; // path inclusing filename
|
||||
int index_item_length = 0; // length of index item
|
||||
int record_length = 0; // length of record
|
||||
std::string file_path = ""; // path inclusing filename
|
||||
int index_item_length = 0; // length of index item
|
||||
int record_length = 0; // length of record
|
||||
|
||||
File db_file{};
|
||||
int number_of_records = 0;
|
||||
@@ -77,6 +76,5 @@ class database {
|
||||
|
||||
int retrieve_record(std::string file_path, int index_item_length, int record_length, void* record, std::string search_term);
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
#endif /*__DATABASE_H__*/
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2023 Bernd Herzog
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2023 Bernd Herzog
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -44,6 +44,8 @@ using namespace lpc43xx;
|
||||
|
||||
#include "ui_navigation.hpp"
|
||||
|
||||
static int delayed_error = 0;
|
||||
|
||||
extern "C" {
|
||||
|
||||
CH_IRQ_HANDLER(M4Core_IRQHandler) {
|
||||
@@ -161,6 +163,10 @@ void EventDispatcher::dispatch(const eventmask_t events) {
|
||||
}
|
||||
|
||||
if (events & EVT_MASK_RTC_TICK) {
|
||||
// delay error message by 2 seconds to wait for LCD being ready
|
||||
if (portapack::init_error != nullptr && ++delayed_error > 1)
|
||||
draw_guru_meditation(CORTEX_M4, portapack::init_error);
|
||||
|
||||
handle_rtc_tick();
|
||||
}
|
||||
|
||||
|
||||
+22
-20
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
Copyright (C) 2023 Bernd Herzog
|
||||
Copyright (C) 2024 Mark Thompson
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -16,22 +17,27 @@
|
||||
|
||||
MEMORY
|
||||
{
|
||||
/* external apps: regions can't overlap so addresses are corrected after build */
|
||||
ram_external_app_pacman (rwx) : org = 0xEEE90000, len = 32k
|
||||
ram_external_app_afsk_rx (rwx) : org = 0xEEEA0000, len = 32k
|
||||
ram_external_app_calculator (rwx) : org = 0xEEEB0000, len = 32k
|
||||
ram_external_app_font_viewer(rwx) : org = 0xEEEC0000, len = 32k
|
||||
ram_external_app_blespam(rwx) : org = 0xEEED0000, len = 32k
|
||||
ram_external_app_analogtv(rwx) : org = 0xEEEE0000, len = 32k
|
||||
ram_external_app_nrf_rx(rwx) : org = 0xEEEF0000, len = 32k
|
||||
ram_external_app_coasterp(rwx) : org = 0xEEF00000, len = 32k
|
||||
ram_external_app_lge(rwx) : org = 0xEEF10000, len = 32k
|
||||
ram_external_app_lcr(rwx) : org = 0xEEF20000, len = 32k
|
||||
ram_external_app_jammer(rwx) : org = 0xEEF30000, len = 32k
|
||||
ram_external_app_gpssim(rwx) : org = 0xEEF40000, len = 32k
|
||||
ram_external_app_spainter(rwx) : org = 0xEEF50000, len = 32k
|
||||
ram_external_app_keyfob(rwx) : org = 0xEEF60000, len = 32k
|
||||
ram_external_app_tetris(rwx) : org = 0xEEF70000, len = 32k
|
||||
/*
|
||||
* External apps: regions can't overlap so addresses are corrected after build.
|
||||
* Picking uncommon address values for search & replace in binaries (no false positives) - 0xADB00000-0xADEF0000 seems to be good.
|
||||
* Also need to consider processor memory map - reading 0xADxxxxxx generates a fault which may be better than unexpected behavior.
|
||||
* External app address ranges below must match those in python file "external_app_info.py".
|
||||
*/
|
||||
ram_external_app_pacman (rwx) : org = 0xADB00000, len = 32k
|
||||
ram_external_app_afsk_rx (rwx) : org = 0xADB10000, len = 32k
|
||||
ram_external_app_calculator (rwx) : org = 0xADB20000, len = 32k
|
||||
ram_external_app_font_viewer(rwx) : org = 0xADB30000, len = 32k
|
||||
ram_external_app_blespam(rwx) : org = 0xADB40000, len = 32k
|
||||
ram_external_app_analogtv(rwx) : org = 0xADB50000, len = 32k
|
||||
ram_external_app_nrf_rx(rwx) : org = 0xADB60000, len = 32k
|
||||
ram_external_app_coasterp(rwx) : org = 0xADB70000, len = 32k
|
||||
ram_external_app_lge(rwx) : org = 0xADB80000, len = 32k
|
||||
ram_external_app_lcr(rwx) : org = 0xADB90000, len = 32k
|
||||
ram_external_app_jammer(rwx) : org = 0xADBA0000, len = 32k
|
||||
ram_external_app_gpssim(rwx) : org = 0xADBB0000, len = 32k
|
||||
ram_external_app_spainter(rwx) : org = 0xADBC0000, len = 32k
|
||||
ram_external_app_keyfob(rwx) : org = 0xADBD0000, len = 32k
|
||||
ram_external_app_tetris(rwx) : org = 0xADBE0000, len = 32k
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
@@ -60,7 +66,6 @@ SECTIONS
|
||||
*(*ui*external_app*font_viewer*);
|
||||
} > ram_external_app_font_viewer
|
||||
|
||||
|
||||
.external_app_blespam : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_blespam.application_information));
|
||||
@@ -91,14 +96,12 @@ SECTIONS
|
||||
*(*ui*external_app*lge*);
|
||||
} > ram_external_app_lge
|
||||
|
||||
|
||||
.external_app_lcr : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_lcr.application_information));
|
||||
*(*ui*external_app*lcr*);
|
||||
} > ram_external_app_lcr
|
||||
|
||||
|
||||
.external_app_jammer : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_jammer.application_information));
|
||||
@@ -111,7 +114,6 @@ SECTIONS
|
||||
*(*ui*external_app*gpssim*);
|
||||
} > ram_external_app_gpssim
|
||||
|
||||
|
||||
.external_app_spainter : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_spainter.application_information));
|
||||
|
||||
+22
-7
@@ -13,8 +13,6 @@ namespace ui::external_app::pacman {
|
||||
#include "playfield.hpp"
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
Playfield _game;
|
||||
|
||||
PacmanView::PacmanView(NavigationView& nav)
|
||||
: nav_(nav) {
|
||||
add_children({&dummy});
|
||||
@@ -26,19 +24,36 @@ void PacmanView::focus() {
|
||||
|
||||
void PacmanView::paint(Painter& painter) {
|
||||
(void)painter;
|
||||
static Playfield _game;
|
||||
static bool wait_for_button_release{false};
|
||||
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
_game.Init();
|
||||
}
|
||||
|
||||
auto switches_raw = swizzled_switches() & ((1 << (int)Switch::Right) | (1 << (int)Switch::Left) | (1 << (int)Switch::Down) | (1 << (int)Switch::Up) | (1 << (int)Switch::Sel) | (1 << (int)Switch::Dfu));
|
||||
auto switches_debounced = get_switches_state().to_ulong();
|
||||
|
||||
but_RIGHT = (switches_debounced & 0x01) == 0x01;
|
||||
but_LEFT = (switches_debounced & 0x02) == 0x02;
|
||||
but_DOWN = (switches_debounced & 0x04) == 0x04;
|
||||
but_UP = (switches_debounced & 0x08) == 0x08;
|
||||
but_A = (switches_debounced & 0x10) == 0x10;
|
||||
// For the Select (Start/Pause) button, wait for release to avoid repeat
|
||||
uint8_t buttons_to_wait_for = (1 << (int)Switch::Sel);
|
||||
if (wait_for_button_release) {
|
||||
if ((switches_debounced & buttons_to_wait_for) == 0)
|
||||
wait_for_button_release = false;
|
||||
switches_debounced &= ~buttons_to_wait_for;
|
||||
} else {
|
||||
if (switches_debounced & buttons_to_wait_for)
|
||||
wait_for_button_release = true;
|
||||
}
|
||||
|
||||
// For the directional buttons, use the raw inputs for fastest response time
|
||||
but_RIGHT = (switches_raw & (1 << (int)Switch::Right)) != 0;
|
||||
but_LEFT = (switches_raw & (1 << (int)Switch::Left)) != 0;
|
||||
but_DOWN = (switches_raw & (1 << (int)Switch::Down)) != 0;
|
||||
but_UP = (switches_raw & (1 << (int)Switch::Up)) != 0;
|
||||
|
||||
// For the pause button, use the debounced input to avoid glitches, and OR in the value to make sure that we don't clear it before it's seen
|
||||
but_A |= (switches_debounced & (1 << (int)Switch::Sel)) != 0;
|
||||
|
||||
_game.Step();
|
||||
}
|
||||
|
||||
+30
-22
@@ -56,35 +56,43 @@ static const Color pp_colors[] = {
|
||||
Color::black(),
|
||||
};
|
||||
|
||||
class SPI_TFT_ILI9341 {
|
||||
public:
|
||||
SPI_TFT_ILI9341(int, int, int, int, int, int, std::string) { (void)0; };
|
||||
// NB: ELIMINATED SPI_TFT_ILI9341 DISPLAY CLASS DUE TO GLOBAL OBJECT INITIALIZATION ISSUE WITH EXTERNAL APPS
|
||||
|
||||
void claim(__FILE* x) { (void)x; };
|
||||
static void claim(__FILE* x) {
|
||||
(void)x;
|
||||
};
|
||||
|
||||
void cls() {
|
||||
painter.fill_rectangle({0, 0, portapack::display.width(), portapack::display.height()}, Color::black());
|
||||
};
|
||||
static void cls() {
|
||||
painter.fill_rectangle({0, 0, portapack::display.width(), portapack::display.height()}, Color::black());
|
||||
};
|
||||
|
||||
void background(int color) { bg_color = color; };
|
||||
void foreground(int color) { fg_color = color; };
|
||||
static void background(int color) {
|
||||
bg_color = color;
|
||||
};
|
||||
|
||||
void locate(int x, int y) {
|
||||
x_pos = x;
|
||||
y_pos = y;
|
||||
};
|
||||
void set_orientation(int x) { (void)x; };
|
||||
void set_font(unsigned char* x) { (void)x; };
|
||||
static void foreground(int color) {
|
||||
fg_color = color;
|
||||
};
|
||||
|
||||
void fillrect(int x1, int y1, int x2, int y2, int color) {
|
||||
painter.fill_rectangle({x1, y1, x2 - x1, y2 - y1}, pp_colors[color]);
|
||||
};
|
||||
static void locate(int x, int y) {
|
||||
x_pos = x;
|
||||
y_pos = y;
|
||||
};
|
||||
|
||||
void rect(int x1, int y1, int x2, int y2, int color) {
|
||||
painter.draw_rectangle({x1, y1, x2 - x1, y2 - y1}, pp_colors[color]);
|
||||
};
|
||||
static void set_orientation(int x) {
|
||||
(void)x;
|
||||
};
|
||||
|
||||
private:
|
||||
static void set_font(unsigned char* x) {
|
||||
(void)x;
|
||||
};
|
||||
|
||||
static void fillrect(int x1, int y1, int x2, int y2, int color) {
|
||||
painter.fill_rectangle({x1, y1, x2 - x1, y2 - y1}, pp_colors[color]);
|
||||
};
|
||||
|
||||
static void rect(int x1, int y1, int x2, int y2, int color) {
|
||||
painter.draw_rectangle({x1, y1, x2 - x1, y2 - y1}, pp_colors[color]);
|
||||
};
|
||||
|
||||
static void printf(std::string str) {
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ static bool but_DOWN;
|
||||
static bool but_SELECT;
|
||||
|
||||
//
|
||||
// AnalogIn Class -- DID NOT WORK BECAUSE INITIALIZER CODE WON'T EXECUTE -- hacked original code module instead
|
||||
// AnalogIn Class -- DID NOT WORK DUE TO GLOBAL OBJECT INITIALIZER ISSUE WITH EXTERNAL APPS -- hacked original code module instead
|
||||
//
|
||||
// dp9 = joystick rotate button --> select button
|
||||
// dp10 = joystick y --> up & down buttons
|
||||
|
||||
+79
-109
@@ -4,9 +4,15 @@
|
||||
|
||||
// clang-format off
|
||||
|
||||
//////// PORTAPACK CHANGES HIGHLIGHTED
|
||||
//////// HACKED FOR PORTAPACK -- CHANGES HIGHLIGHTED
|
||||
int main();
|
||||
void pause_game();
|
||||
void Initialize(unsigned char c);
|
||||
void DeleteFigure();
|
||||
void DrawFigure();
|
||||
bool InCollisionDown(char delta);
|
||||
bool InCollisionLeft();
|
||||
bool InCollisionRight();
|
||||
//////// PORTAPACK
|
||||
|
||||
#include "mbed.h"
|
||||
@@ -15,32 +21,29 @@ void pause_game();
|
||||
|
||||
#define dp23 P0_0
|
||||
|
||||
//////// PORTAPACK - DISABLED MOST CLASSES DUE TO GLOBAL OBJECT INITIALIZER ISSUE WITH EXTERNAL APPS:
|
||||
//deklaracija display-a
|
||||
SPI_TFT_ILI9341 display(dp2, dp1, dp6, dp24, dp23, dp25, "TFT");
|
||||
|
||||
//////// PORTAPACK - DISABLED ANALOGIN CLASS DUE TO OBJECT INITIALIZER CODE NOT RUNNING:
|
||||
//SPI_TFT_ILI9341 display(dp2, dp1, dp6, dp24, dp23, dp25, "TFT");
|
||||
//
|
||||
//analogni ulazi za joystick
|
||||
// AnalogIn VRx(dp11);
|
||||
// AnalogIn VRy(dp10);
|
||||
//
|
||||
// AnalogIn random(dp13); //analogni ulaz za generisanje random vrijednosti
|
||||
//////// PORTAPACK
|
||||
|
||||
//taster na joysticku za rotaciju
|
||||
InterruptIn taster(dp9);
|
||||
|
||||
//////// PORTAPACK - DISABLED ANALOGIN CLASS DUE TO OBJECT INITIALIZER CODE NOT RUNNING:
|
||||
// AnalogIn random(dp13); //analogni ulaz za generisanje random vrijednosti
|
||||
//////// PORTAPACK
|
||||
|
||||
//ticker za spustanje figure
|
||||
//timer za debouncing tastera na joysticku
|
||||
Ticker game, joystick;
|
||||
Timer debounceTaster;
|
||||
|
||||
|
||||
unsigned char level = 0; //mora biti tipa usigned char jer inače se može desiti da level bude manji od 0, a i da ne trošimo memoriju
|
||||
const float delays[4] = {1.2, 0.7, 0.4, 0.25}; //svakih koliko se spusti jedan red, ovo provjeriti da li je presporo ili prebrzo, ovisi o levelu
|
||||
|
||||
//////// PORTAPACK - UNNEEDED JOYSTICK HYSTERESIS VARIABLES
|
||||
//////// PORTAPACK - DELETED UNNEEDED JOYSTICK HYSTERESIS VARIABLES
|
||||
//char leftBoundary = 1, rightBoundary = 5, downBoundary = 1, upBoundary = 5;// sada je ovo tipa char
|
||||
//////// PORTAPACK
|
||||
|
||||
@@ -49,7 +52,6 @@ bool firstTime = true; //ako je prvi put, figura se crta u Tickeru
|
||||
bool gameStarted = false;
|
||||
unsigned char nextFigure = 1; //ovo je sad globalna varijabla, da bi mogli unaprijed generisati sljedeću figuru radi prikaza
|
||||
|
||||
|
||||
//white - no figure
|
||||
//I - BLUE
|
||||
//O - YELLOW
|
||||
@@ -69,81 +71,70 @@ short figuresY[7][4] = {{0,1,2,3}, {1,0,0,1}, {1,1,2,0}, {0,1,1,2}, {0,1,1,2}, {
|
||||
unsigned int GenerateRandomSeed() {
|
||||
//////// PORTAPACK - USE RTC FOR SEED
|
||||
return LPC_RTC->CTIME0;
|
||||
// unsigned int randomNumber = 0;
|
||||
// for(int i = 0; i <= 32; i += 2) {
|
||||
// randomNumber += ((random.read_u16() % 3) << i);
|
||||
// wait_us(10);
|
||||
// }
|
||||
// return randomNumber;
|
||||
//////// PORTAPACK
|
||||
}
|
||||
|
||||
void Init() {
|
||||
//ovo su zajedničke osobine za sve prikaze na display-u
|
||||
//nikad se ne mijenjaju i pozvat ćemo je jednom prije petlje
|
||||
display.claim(stdout);
|
||||
display.set_orientation(2); // 2 ili 0, zavisi kako okrenemo display, provjerit ćemo na labu kako nam je najlakše povezat
|
||||
display.set_font((unsigned char*) Arial12x12);
|
||||
claim(stdout);
|
||||
set_orientation(2); // 2 ili 0, zavisi kako okrenemo display, provjerit ćemo na labu kako nam je najlakše povezat
|
||||
set_font((unsigned char*) Arial12x12);
|
||||
}
|
||||
|
||||
|
||||
void ShowScore() {
|
||||
//pomocna funkcija za prikazivanje score-a
|
||||
display.fillrect(165, 20, 235, 50, White); //popunimo pravugaonik da obrišemo stari score
|
||||
display.locate(200, 35); //valjda je na sredini pravougaonika
|
||||
fillrect(165, 20, 235, 50, White); //popunimo pravugaonik da obrišemo stari score
|
||||
locate(200, 35); //valjda je na sredini pravougaonika
|
||||
printf("%d", score);
|
||||
}
|
||||
|
||||
void ShowNextFigure() {
|
||||
//prikaz sljedeće figure koristeći pomoćnu varijablu nextFigure
|
||||
display.fillrect(165, 70, 235, 120, White);
|
||||
fillrect(165, 70, 235, 120, White);
|
||||
int upperLeftX = 176, upperLeftY = 83;
|
||||
for(int i = 0; i < 4; i++) {
|
||||
int x = upperLeftX + DIMENSION_NEXT * figuresY[nextFigure - 1][i], y = upperLeftY + DIMENSION_NEXT * figuresX[nextFigure - 1][i];
|
||||
display.fillrect(x, y, x + DIMENSION_NEXT, y + DIMENSION_NEXT, colors[nextFigure]);
|
||||
display.rect(x, y, x + DIMENSION_NEXT, y + DIMENSION_NEXT, Black);
|
||||
fillrect(x, y, x + DIMENSION_NEXT, y + DIMENSION_NEXT, colors[nextFigure]);
|
||||
rect(x, y, x + DIMENSION_NEXT, y + DIMENSION_NEXT, Black);
|
||||
}
|
||||
}
|
||||
|
||||
//funkcija za crtanje cursora za odabir levela
|
||||
void DrawCursor(int color, unsigned char lev) {
|
||||
display.fillrect(60, lev * 70 + 50, 72, lev * 70 + 50 + 12, color);
|
||||
fillrect(60, lev * 70 + 50, 72, lev * 70 + 50 + 12, color);
|
||||
}
|
||||
|
||||
// PORTAPACK - ADDED EXTRA LEVEL:
|
||||
void ShowLevelMenu() {
|
||||
//ovdje inicijalizujemo display
|
||||
display.cls(); // brišemo prethodno
|
||||
display.background(Black);
|
||||
display.foreground(White);
|
||||
display.locate(80, 50);
|
||||
cls(); // brišemo prethodno
|
||||
background(Black);
|
||||
foreground(White);
|
||||
locate(80, 50);
|
||||
printf("LEVEL 1");
|
||||
display.locate(80, 120);
|
||||
locate(80, 120);
|
||||
printf("LEVEL 2");
|
||||
display.locate(80, 190);
|
||||
locate(80, 190);
|
||||
printf("LEVEL 3");
|
||||
display.locate(80, 260);
|
||||
locate(80, 260);
|
||||
printf("LEVEL 4");
|
||||
DrawCursor(White, level);
|
||||
}
|
||||
//////// PORTAPACK
|
||||
|
||||
//////// PORTAPACK - KLUDGED FOR BUTTONS VS JOYSTICK:
|
||||
//////// PORTAPACK - USE BUTTONS VS JOYSTICK:
|
||||
void ReadJoystickForLevel(){
|
||||
unsigned char old = level;
|
||||
if(but_UP){
|
||||
// upBoundary = 4;
|
||||
(level == 0) ? level = 3 : level--;
|
||||
}
|
||||
else if(but_DOWN){
|
||||
//ne radi ona prethodna varijanta jer % vraća i negastivni rezultat
|
||||
//to što ne koristimo unsigned tip ne pomaže jer će doći do overflow-a
|
||||
// downBoundary = 2;
|
||||
level = (level + 1) % 4;
|
||||
}
|
||||
else {
|
||||
// downBoundary = 1;
|
||||
// upBoundary = 5;
|
||||
}
|
||||
DrawCursor(Black, old); //na prethodni level popunimo bojom pozadine
|
||||
DrawCursor(White, level); //na novi level popunimo bijelom bojom - pozadina je crna
|
||||
//koristio sam fillrect, jer njega svakako moramo koristiti, jer možda budemo morali da brišemo fillcircle iz biblioteke
|
||||
@@ -169,11 +160,11 @@ main();
|
||||
|
||||
void StartGame()
|
||||
{
|
||||
display.cls(); // brišemo ShowLevelMenu
|
||||
display.background(White);
|
||||
display.foreground(Black);
|
||||
display.fillrect(0, 0, 160, 320, White);
|
||||
display.fillrect(160, 0, 240, 320, Black); //dio za prikazivanje rezultata će biti crni pravougaonik, a tabla je bijeli
|
||||
cls(); // brišemo ShowLevelMenu
|
||||
background(White);
|
||||
foreground(Black);
|
||||
fillrect(0, 0, 160, 320, White);
|
||||
fillrect(160, 0, 240, 320, Black); //dio za prikazivanje rezultata će biti crni pravougaonik, a tabla je bijeli
|
||||
ShowScore();
|
||||
}
|
||||
|
||||
@@ -206,34 +197,34 @@ void PutBorders(short x, short y) {
|
||||
for(int i = x - 1; i <= x + 1; i++) {
|
||||
for(int j = y - 1; j <= y + 1; j++) {
|
||||
if(i < 0 || i > 9 || j < 0 || j > 19 || board[j][i] == 0) continue;
|
||||
display.rect(i * DIMENSION, j * DIMENSION, (i + 1) * DIMENSION, (j + 1) * DIMENSION, Black);
|
||||
rect(i * DIMENSION, j * DIMENSION, (i + 1) * DIMENSION, (j + 1) * DIMENSION, Black);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Tetromino{
|
||||
private:
|
||||
//////// PORTAPACK - ELIMINATED CLASSES DUE TO GLOBAL OBJECT INITIALIZATION ISSUE WITH EXTERNAL APPS:
|
||||
//class Tetromino{
|
||||
//private:
|
||||
short X[4];
|
||||
short Y[4];
|
||||
short boardX, boardY;
|
||||
unsigned char colorIndex;//dodao sam colorIndex zasad, jer nema drugog načina da popunimo matricu sa indeksima boja
|
||||
//ovo je najbezbolnija varijanta što se memorije tiče
|
||||
public:
|
||||
Tetromino(){
|
||||
//////// PORTAPACK - NOTE - DEFAULT INITIALIZER CODE DOESN'T GET EXECUTED FOR SOME REASON:
|
||||
unsigned char r = rand() % 7 + 1;
|
||||
Initialize(r);
|
||||
//public:
|
||||
// Tetromino(){
|
||||
// unsigned char r = rand() % 7 + 1;
|
||||
// Initialize(r);
|
||||
// }
|
||||
|
||||
void Tetromino(unsigned char c) {
|
||||
Initialize(c);
|
||||
}
|
||||
|
||||
Tetromino(unsigned char colorIndex) {
|
||||
Initialize(colorIndex);
|
||||
}
|
||||
|
||||
void Initialize(unsigned char colorIndex) {
|
||||
Tetromino::colorIndex = colorIndex;
|
||||
void Initialize(unsigned char c) {
|
||||
colorIndex = c;
|
||||
boardX = 0;
|
||||
boardY = 4; //3,4 ili 5 najbolje da vidimo kad imamo display
|
||||
copyCoordinates(X, Y, colorIndex - 1);
|
||||
copyCoordinates(X, Y, c - 1);
|
||||
}
|
||||
|
||||
void Rotate(){
|
||||
@@ -266,13 +257,9 @@ public:
|
||||
//stavio sam 16 za početak, možemo se opet skontati na labu
|
||||
//ovo pretpostavlja da nema margina, mogu se lagano dodati uz neku konstantu kao offset
|
||||
int upperLeftX = (boardX + X[i]) * DIMENSION, upperLeftY = (boardY + Y[i]) * DIMENSION;
|
||||
display.fillrect( upperLeftY, upperLeftX, upperLeftY + DIMENSION, upperLeftX + DIMENSION, colors[colorIndex]);
|
||||
fillrect( upperLeftY, upperLeftX, upperLeftY + DIMENSION, upperLeftX + DIMENSION, colors[colorIndex]);
|
||||
//ovo boji granice blokova u crno, možemo skloniti ako ti se ne sviđa
|
||||
|
||||
//////// PORTAPACK - HIDE DEFAULT WHITE BLOCK (ALTERNATE KLUDGE FOR TETRONIMO INITIALIZATION CODE NOT RUNNING AT CONSTRUCTION)
|
||||
if (colorIndex != White)
|
||||
//////// PORTAPACK
|
||||
display.rect( upperLeftY, upperLeftX, upperLeftY + DIMENSION, upperLeftX + DIMENSION, Black);
|
||||
rect( upperLeftY, upperLeftX, upperLeftY + DIMENSION, upperLeftX + DIMENSION, Black);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,7 +267,7 @@ if (colorIndex != White)
|
||||
for(int i = 0; i < 4; i++) {
|
||||
//ista logika kao u DrawFigure, samo popunjavamo sve blokove sa bijelim pravougaonicima
|
||||
short upperLeftX = (boardX + X[i]) * DIMENSION, upperLeftY = (boardY + Y[i]) * DIMENSION;
|
||||
display.fillrect( upperLeftY, upperLeftX, upperLeftY + DIMENSION, upperLeftX + DIMENSION, White);
|
||||
fillrect( upperLeftY, upperLeftX, upperLeftY + DIMENSION, upperLeftX + DIMENSION, White);
|
||||
PutBorders(upperLeftY, upperLeftX);
|
||||
}
|
||||
}
|
||||
@@ -295,9 +282,6 @@ if (colorIndex != White)
|
||||
}
|
||||
|
||||
bool MoveDown(char delta = 1){
|
||||
//////// PORTAPACK - MOVE DEFAULT WHITE BLOCK TO BOTTOM IMMEDIATELY (ALTERNATE KLUDGE FOR TETRONIMO INITIALIZATION CODE NOT RUNNING AT CONSTRUCTION)
|
||||
if (colorIndex == White) delta = 19;
|
||||
//////// PORTAPACK
|
||||
if(!InCollisionDown(delta)){
|
||||
DeleteFigure();
|
||||
boardX+=delta;
|
||||
@@ -384,34 +368,23 @@ if (colorIndex == White) delta = 19;
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
// };
|
||||
|
||||
// Tetromino currentTetromino;
|
||||
|
||||
Tetromino currentTetromino;
|
||||
|
||||
//////// PORTAPACK - KLUDGED FOR BUTTONS VS JOYSTICK:
|
||||
//////// PORTAPACK - USE BUTTONS VS JOYSTICK, AND ADDED PAUSE FEATURE:
|
||||
void ReadJoystickForFigure() {
|
||||
if(but_LEFT) {
|
||||
// leftBoundary = 2;
|
||||
currentTetromino.MoveLeft();
|
||||
MoveLeft();
|
||||
}
|
||||
else if(but_RIGHT) {
|
||||
// rightBoundary = 4;
|
||||
currentTetromino.MoveRight();
|
||||
MoveRight();
|
||||
}
|
||||
else if(but_UP) {
|
||||
// downBoundary = 2;
|
||||
pause_game();
|
||||
pause_game();
|
||||
}
|
||||
else if(but_DOWN) {
|
||||
// upBoundary = 4;
|
||||
currentTetromino.SoftDrop();
|
||||
}
|
||||
else {
|
||||
// leftBoundary = 1;
|
||||
// rightBoundary = 5;
|
||||
// downBoundary = 1;
|
||||
// upBoundary = 5;
|
||||
SoftDrop();
|
||||
}
|
||||
}
|
||||
//////// PORTAPACK
|
||||
@@ -460,10 +433,10 @@ void UpdateBoard()
|
||||
board[i][j] = board[i - numberOfLines][j];
|
||||
board[i - numberOfLines][j] = 0;
|
||||
short tmp = i - numberOfLines;
|
||||
display.fillrect( j * DIMENSION,i * DIMENSION, (j + 1) * DIMENSION , (i + 1) * DIMENSION , colors[board[i][j]]); // bojimo novi blok
|
||||
display.fillrect( j * DIMENSION, tmp * DIMENSION,(j + 1) * DIMENSION, (tmp + 1) * DIMENSION , White);
|
||||
fillrect( j * DIMENSION,i * DIMENSION, (j + 1) * DIMENSION , (i + 1) * DIMENSION , colors[board[i][j]]); // bojimo novi blok
|
||||
fillrect( j * DIMENSION, tmp * DIMENSION,(j + 1) * DIMENSION, (tmp + 1) * DIMENSION , White);
|
||||
if(board[i][j] != 0)
|
||||
display.rect( j * DIMENSION,i * DIMENSION, (j + 1) * DIMENSION , (i + 1) * DIMENSION , Black);
|
||||
rect( j * DIMENSION,i * DIMENSION, (j + 1) * DIMENSION , (i + 1) * DIMENSION , Black);
|
||||
}
|
||||
}
|
||||
score += UpdateScore(numberOfLines);
|
||||
@@ -480,26 +453,23 @@ bool IsOver() {
|
||||
|
||||
void ShowGameOverScreen() {
|
||||
//////// PORTAPACK - SKIP CLS
|
||||
// display.cls();
|
||||
// display.background(Black);
|
||||
// display.foreground(White);
|
||||
display.background(White);
|
||||
display.foreground(Black);
|
||||
// cls();
|
||||
// background(Black);
|
||||
// foreground(White);
|
||||
background(White);
|
||||
foreground(Black);
|
||||
//////// PORTAPACK
|
||||
display.locate(60, 120);
|
||||
locate(60, 120);
|
||||
printf("GAME OVER");
|
||||
display.locate(40, 150);
|
||||
locate(40, 150);
|
||||
printf("YOUR SCORE IS %d", score);
|
||||
wait(5); //ovaj prikaz traje 3s (možemo mijenjati) a nakon toga se ponovo prikazuje meni sa levelima
|
||||
}
|
||||
|
||||
void InitGame() {
|
||||
if(firstTime) {
|
||||
//////// PORTAPACK - NOTE - ATTEMPTED WORKAROUND FOR SKIPPED INITIALIZER CODE - BUT ANY OF THESE CRASHES FIRMWARE AT POWER-UP EVEN IF THERE'S NO TETRIS APP INSTALLED:
|
||||
// currentTetromino = Tetromino(rand() % 7 + 1); // TEST #1
|
||||
// currentTetromino.Initialize(rand() % 7 + 1); // TEST #2
|
||||
//////// PORTAPACK
|
||||
currentTetromino.DrawFigure();
|
||||
Tetromino(rand() % 7 + 1);
|
||||
DrawFigure();
|
||||
nextFigure = rand() % 7 + 1;
|
||||
ShowNextFigure();
|
||||
firstTime = false;
|
||||
@@ -508,13 +478,13 @@ void InitGame() {
|
||||
|
||||
void PlayGame(){
|
||||
InitGame();
|
||||
if(!currentTetromino.MoveDown()){
|
||||
currentTetromino.OnAttached();
|
||||
if(!MoveDown()){
|
||||
OnAttached();
|
||||
UpdateBoard();
|
||||
ShowScore();
|
||||
|
||||
currentTetromino = Tetromino(nextFigure);
|
||||
currentTetromino.DrawFigure();
|
||||
Tetromino(nextFigure);
|
||||
DrawFigure();
|
||||
nextFigure = rand() % 7 + 1;
|
||||
ShowNextFigure();
|
||||
if(IsOver()) {
|
||||
@@ -531,7 +501,7 @@ void PlayGame(){
|
||||
void OnTasterPressed(){
|
||||
if(debounceTaster.read_ms() > 200) {
|
||||
if(gameStarted){
|
||||
currentTetromino.Rotate();
|
||||
Rotate();
|
||||
}
|
||||
else{
|
||||
joystick.detach();
|
||||
@@ -568,7 +538,7 @@ return 0;
|
||||
void pause_game() {
|
||||
game.detach();
|
||||
joystick.detach();
|
||||
display.locate(180, 200);
|
||||
locate(180, 200);
|
||||
printf("PAUSED");
|
||||
while ((get_switches_state().to_ulong() & 0x10) == 0); // wait for SELECT button to resume
|
||||
printf(" ");
|
||||
|
||||
@@ -1,3 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* 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_tetris.hpp"
|
||||
|
||||
namespace ui::external_app::tetris {
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
|
||||
#include "utility.hpp"
|
||||
|
||||
#include "portapack.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
|
||||
uint8_t Debounce::state() {
|
||||
uint8_t v = state_to_report_;
|
||||
simulated_pulse_ = false;
|
||||
@@ -154,19 +157,35 @@ uint8_t EncoderDebounce::state() {
|
||||
return state_;
|
||||
}
|
||||
|
||||
uint8_t EncoderDebounce::rotation_rate() {
|
||||
return last_rotation_rate_;
|
||||
}
|
||||
|
||||
// Returns TRUE if encoder position phase bits changed (after debouncing)
|
||||
bool EncoderDebounce::feed(const uint8_t phase_bits) {
|
||||
history_ = (history_ << 2) | phase_bits;
|
||||
|
||||
// Has input been constant for 4 ticks? (phase_bits * 01010101b should be 0x00, 0x55, 0xAA, or 0xFF)
|
||||
if (history_ == (phase_bits * 0x55)) {
|
||||
// If both inputs have been stable for the last 4 ticks, history_ should equal 0x00, 0x55, 0xAA, or 0xFF.
|
||||
uint8_t expected_stable_history = phase_bits * 0b01010101;
|
||||
|
||||
// But, checking for equal seems to cause issues with at least 1 user's encoder, so we're treating the input
|
||||
// as "stable" if at least ONE input bit is consistent for 4 ticks...
|
||||
uint8_t diff = (history_ ^ expected_stable_history);
|
||||
if (((diff & 0b01010101) == 0) || ((diff & 0b10101010) == 0)) {
|
||||
// Has the debounced input value changed?
|
||||
if (state_ != phase_bits) {
|
||||
state_ = phase_bits;
|
||||
|
||||
// Rate multiplier is for larger delta increments when dial is rotated rapidly.
|
||||
last_rotation_rate_ = rotation_rate_downcounter_;
|
||||
rotation_rate_downcounter_ = portapack::persistent_memory::encoder_rate_multiplier();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Unstable input, or no change
|
||||
// Unstable input, or no change.
|
||||
// Decrement rotation rate detector once per timer tick.
|
||||
if (rotation_rate_downcounter_ > 1)
|
||||
rotation_rate_downcounter_--;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -70,10 +71,15 @@ class EncoderDebounce {
|
||||
|
||||
uint8_t state(); // returns debounced phase bits from encoder
|
||||
|
||||
uint8_t rotation_rate(); // returns last rotation rate
|
||||
|
||||
private:
|
||||
uint8_t history_{0}; // shift register of previous reads from encoder
|
||||
|
||||
uint8_t state_{0}; // actual encoder output state (after debounce logic)
|
||||
|
||||
uint8_t last_rotation_rate_{1};
|
||||
uint8_t rotation_rate_downcounter_{1}; // down-counter to estimate rotation speed
|
||||
};
|
||||
|
||||
#endif /*__DEBOUNCE_H__*/
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -63,7 +64,7 @@ int_fast8_t Encoder::update(const uint_fast8_t phase_bits) {
|
||||
|
||||
// Require 2 state changes in same direction to register movement -- for additional level of contact switch debouncing
|
||||
if (direction == prev_direction) {
|
||||
if ((sensitivity_map[portapack::persistent_memory::config_encoder_dial_sensitivity()] & (1 << state)) == 0)
|
||||
if ((sensitivity_map[portapack::persistent_memory::encoder_dial_sensitivity()] & (1 << state)) == 0)
|
||||
return 0;
|
||||
return direction;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* copyleft (ɔ) 2023 zxkmm under GPL license
|
||||
* Copyright (C) 2023 u-foka
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* copyleft (ɔ) 2023 zxkmm under GPL license
|
||||
* Copyright (C) 2023 u-foka
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -27,8 +28,10 @@ bool WAVFileReader::open(const std::filesystem::path& path) {
|
||||
size_t i = 0;
|
||||
char ch;
|
||||
const uint8_t tag_INAM[4] = {'I', 'N', 'A', 'M'};
|
||||
char title_buffer[32];
|
||||
uint32_t riff_size, data_end, title_size;
|
||||
const uint8_t tag_data[4] = {'d', 'a', 't', 'a'};
|
||||
struct data_t data_header;
|
||||
char title_buffer[32]{0};
|
||||
uint32_t riff_size, inam_search_start, title_size;
|
||||
size_t search_limit = 0;
|
||||
|
||||
// Already open ?
|
||||
@@ -37,19 +40,42 @@ bool WAVFileReader::open(const std::filesystem::path& path) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Reinitialize to avoid old data when switching files
|
||||
title_string = "";
|
||||
sample_rate_ = 0;
|
||||
bytes_per_sample = 0;
|
||||
|
||||
auto error = file_.open(path);
|
||||
|
||||
if (!error.is_valid()) {
|
||||
file_.read((void*)&header, sizeof(header)); // Read header (RIFF and WAVE)
|
||||
if (!file_.read((void*)&header, sizeof(header)).is_ok()) // Read header (RIFF and WAVE)
|
||||
return false;
|
||||
|
||||
riff_size = header.cksize + 8;
|
||||
data_start = header.fmt.cksize + 28;
|
||||
data_size_ = header.data.cksize;
|
||||
data_end = data_start + data_size_ + 1;
|
||||
// Assuming here that RIFF & WAV & fmt chunk ID's are all correct...
|
||||
riff_size = 8 + header.cksize;
|
||||
|
||||
// check for the "data" chunk ID
|
||||
if (memcmp(header.data.ckID, tag_data, 4) == 0) {
|
||||
data_start = 20 + header.fmt.cksize + 8;
|
||||
data_size_ = header.data.cksize;
|
||||
inam_search_start = data_start + data_size_;
|
||||
} else {
|
||||
// data header wasn't where we guessed; skip over one unexpected chunk (perhaps LIST/INFO/INAM)
|
||||
inam_search_start = 20 + header.fmt.cksize;
|
||||
file_.seek(20 + header.fmt.cksize + 8 + header.data.cksize);
|
||||
if (!file_.read((void*)&data_header, sizeof(data_header)).is_ok())
|
||||
return false;
|
||||
|
||||
if (memcmp(data_header.ckID, tag_data, 4) == 0) {
|
||||
data_start = 20 + header.fmt.cksize + 8 + header.data.cksize + 8;
|
||||
data_size_ = data_header.cksize;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
// Look for INAM (title) tag
|
||||
if (data_end < riff_size) {
|
||||
file_.seek(data_end);
|
||||
if (inam_search_start < riff_size) {
|
||||
file_.seek(inam_search_start);
|
||||
while (file_.read((void*)&ch, 1).is_ok()) {
|
||||
if (ch == tag_INAM[i++]) {
|
||||
if (i == 4) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -166,7 +167,7 @@ static bool encoder_update(const uint8_t raw) {
|
||||
}
|
||||
|
||||
static bool encoder_read() {
|
||||
auto delta = encoder.update(encoder_debounce.state());
|
||||
auto delta = encoder.update(encoder_debounce.state()) * encoder_debounce.rotation_rate();
|
||||
|
||||
if (injected_encoder > 0) {
|
||||
if (injected_encoder == 1) delta = -1;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -162,6 +162,8 @@ static void event_loop() {
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
first_if.init(); /* To avoid initial short Ant_DC_Bias pulse ,we need quick set up GP01_RFF507X =1 */
|
||||
|
||||
if (config_mode_should_enter()) {
|
||||
config_mode_clear();
|
||||
config_mode_run();
|
||||
@@ -169,25 +171,30 @@ int main(void) {
|
||||
|
||||
config_mode_set();
|
||||
|
||||
first_if.init(); /* To avoid initial short Ant_DC_Bias pulse ,we need quick set up GP01_RFF507X =1 */
|
||||
if (portapack::init()) {
|
||||
portapack::display.init();
|
||||
config_mode_clear();
|
||||
switch (portapack::init()) {
|
||||
case portapack::init_status_t::INIT_HACKRF_CPLD_FAILED:
|
||||
portapack::init_error = "HACKRF CPLD FAILED";
|
||||
[[fallthrough]];
|
||||
|
||||
// sdcStart(&SDCD1, nullptr); // Commented out as now happens in portapack.cpp
|
||||
case portapack::init_status_t::INIT_SUCCESS:
|
||||
|
||||
// controls_init(); // Commented out as now happens in portapack.cpp
|
||||
lcd_frame_sync_configure();
|
||||
rtc_interrupt_enable();
|
||||
config_mode_clear();
|
||||
|
||||
event_loop();
|
||||
lcd_frame_sync_configure();
|
||||
rtc_interrupt_enable();
|
||||
|
||||
sdcDisconnect(&SDCD1);
|
||||
sdcStop(&SDCD1);
|
||||
event_loop();
|
||||
|
||||
portapack::shutdown();
|
||||
} else {
|
||||
config_mode_clear();
|
||||
sdcDisconnect(&SDCD1);
|
||||
sdcStop(&SDCD1);
|
||||
|
||||
portapack::shutdown();
|
||||
break;
|
||||
|
||||
case portapack::init_status_t::INIT_NO_PORTAPACK:
|
||||
case portapack::init_status_t::INIT_PORTAPACK_CPLD_FAILED:
|
||||
config_mode_clear();
|
||||
break;
|
||||
}
|
||||
|
||||
m4_init(portapack::spi_flash::image_tag_hackrf, portapack::memory::map::m4_code_hackrf, true);
|
||||
|
||||
+201
-131
@@ -28,6 +28,7 @@
|
||||
#include "hackrf_hal.hpp"
|
||||
#include "hackrf_gpio.hpp"
|
||||
using namespace hackrf::one;
|
||||
#include "jtag_target_gpio.hpp"
|
||||
|
||||
#include "clock_manager.hpp"
|
||||
#include "event_m0.hpp"
|
||||
@@ -50,9 +51,12 @@ using asahi_kasei::ak4951::AK4951;
|
||||
#include "file.hpp"
|
||||
#include "sd_card.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "bitmap.hpp"
|
||||
|
||||
namespace portapack {
|
||||
|
||||
const char* init_error = nullptr;
|
||||
|
||||
portapack::IO io{
|
||||
portapack::gpio_dir,
|
||||
portapack::gpio_lcd_rdx,
|
||||
@@ -172,50 +176,21 @@ constexpr I2CConfig i2c_config_fast_clock{
|
||||
enum class PortaPackModel {
|
||||
R1_20150901,
|
||||
R2_20170522,
|
||||
AGM,
|
||||
AUTODETECT,
|
||||
};
|
||||
|
||||
static bool save_config(int8_t value) {
|
||||
persistent_memory::set_config_cpld(value);
|
||||
if (sd_card::status() == sd_card::Status::Mounted) {
|
||||
ensure_directory("/hardware");
|
||||
File file;
|
||||
auto sucess = file.create("/hardware/settings.txt");
|
||||
if (!sucess.is_valid()) {
|
||||
file.write_line(to_string_dec_uint(value));
|
||||
}
|
||||
}
|
||||
portapack::persistent_memory::cache::persist();
|
||||
return true;
|
||||
}
|
||||
|
||||
int read_file(std::string name) {
|
||||
std::string return_string = "";
|
||||
File file;
|
||||
auto success = file.open(name);
|
||||
|
||||
if (!success.is_valid()) {
|
||||
char one_char[1];
|
||||
for (size_t pointer = 0; pointer < file.size(); pointer++) {
|
||||
file.seek(pointer);
|
||||
file.read(one_char, 1);
|
||||
return_string += one_char[0];
|
||||
}
|
||||
return std::stoi(return_string);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int load_config() {
|
||||
static Optional<int> config_value;
|
||||
if (!config_value.is_valid()) {
|
||||
int8_t value = portapack::persistent_memory::config_cpld();
|
||||
if ((value <= 0 || value >= 5) && sd_card::status() == sd_card::Status::Mounted) {
|
||||
int data = read_file("/hardware/settings.txt");
|
||||
if (data != -1) {
|
||||
config_value = data;
|
||||
}
|
||||
} else {
|
||||
config_value = value;
|
||||
}
|
||||
config_value = value;
|
||||
}
|
||||
return config_value.value();
|
||||
}
|
||||
@@ -224,39 +199,49 @@ static PortaPackModel portapack_model() {
|
||||
static Optional<PortaPackModel> model;
|
||||
|
||||
if (!model.is_valid()) {
|
||||
const auto switches_state = get_switches_state();
|
||||
// Only save config if no other multi key boot action is triggered (like pmem reset)
|
||||
if (switches_state.count() == 1) {
|
||||
if (switches_state[(size_t)ui::KeyEvent::Up]) {
|
||||
jtag::GPIOTarget target{
|
||||
portapack::gpio_cpld_tck,
|
||||
portapack::gpio_cpld_tms,
|
||||
portapack::gpio_cpld_tdi,
|
||||
portapack::gpio_cpld_tdo};
|
||||
jtag::JTAG jtag{target};
|
||||
portapack::cpld::CPLD cpld{jtag};
|
||||
|
||||
cpld.reset();
|
||||
cpld.run_test_idle();
|
||||
uint32_t idcode = cpld.get_idcode();
|
||||
if (idcode == 0x25610) {
|
||||
model = PortaPackModel::AGM;
|
||||
} else {
|
||||
const auto switches_state = swizzled_switches();
|
||||
// chDbgPanic(to_string_hex((uint32_t)switches_state.count(), 8).c_str());
|
||||
// Only save config if no other multi key boot action is triggered (like pmem reset)
|
||||
if (((switches_state >> (size_t)ui::KeyEvent::Up) & 1) == 1) {
|
||||
save_config(1);
|
||||
// model = PortaPackModel::R2_20170522; // Commented these out as they should be set down below anyway
|
||||
} else if (switches_state[(size_t)ui::KeyEvent::Down]) {
|
||||
} else if (((switches_state >> (size_t)ui::KeyEvent::Down) & 1) == 1) {
|
||||
save_config(2);
|
||||
// model = PortaPackModel::R1_20150901;
|
||||
} else if (switches_state[(size_t)ui::KeyEvent::Left]) {
|
||||
} else if (((switches_state >> (size_t)ui::KeyEvent::Left) & 1) == 1) {
|
||||
save_config(3);
|
||||
// model = PortaPackModel::R1_20150901;
|
||||
} else if (switches_state[(size_t)ui::KeyEvent::Right]) {
|
||||
} else if (((switches_state >> (size_t)ui::KeyEvent::Right) & 1) == 1) {
|
||||
save_config(4);
|
||||
// model = PortaPackModel::R2_20170522;
|
||||
} else if (switches_state[(size_t)ui::KeyEvent::Select]) {
|
||||
} else if (((switches_state >> (size_t)ui::KeyEvent::Select) & 1) == 1) {
|
||||
save_config(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (load_config() == 1) {
|
||||
model = PortaPackModel::R2_20170522;
|
||||
} else if (load_config() == 2) {
|
||||
model = PortaPackModel::R1_20150901;
|
||||
} else if (load_config() == 3) {
|
||||
model = PortaPackModel::R1_20150901;
|
||||
} else if (load_config() == 4) {
|
||||
model = PortaPackModel::R2_20170522;
|
||||
} else {
|
||||
if (audio_codec_wm8731.detected()) {
|
||||
model = PortaPackModel::R1_20150901; // H1R1
|
||||
if (load_config() == 1) {
|
||||
model = PortaPackModel::R2_20170522;
|
||||
} else if (load_config() == 2) {
|
||||
model = PortaPackModel::R1_20150901;
|
||||
} else if (load_config() == 3) {
|
||||
model = PortaPackModel::R1_20150901;
|
||||
} else if (load_config() == 4) {
|
||||
model = PortaPackModel::R2_20170522;
|
||||
} else {
|
||||
model = PortaPackModel::R2_20170522; // H1R2, H2, H2+
|
||||
model = PortaPackModel::AUTODETECT;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -343,6 +328,129 @@ static void shutdown_base() {
|
||||
clock_manager.shutdown();
|
||||
}
|
||||
|
||||
static void set_cpu_clock_speed() {
|
||||
/* Incantation from LPC43xx UM10503 section 12.2.1.1, to bring the M4
|
||||
* core clock speed to the 110 - 204MHz range.
|
||||
*/
|
||||
|
||||
/* Step into the 90-110MHz M4 clock range */
|
||||
/* OG:
|
||||
* Fclkin = 40M
|
||||
* /N=2 = 20M = PFDin
|
||||
* Fcco = PFDin * (M=10) = 200M
|
||||
* r9:
|
||||
* Fclkin = 10M
|
||||
* /N=1 = 10M = PFDin
|
||||
* Fcco = PFDin * (M=20) = 200M
|
||||
* Fclk = Fcco / (2*(P=1)) = 100M
|
||||
*/
|
||||
cgu::pll1::ctrl({
|
||||
.pd = 1,
|
||||
.bypass = 0,
|
||||
.fbsel = 0,
|
||||
.direct = 0,
|
||||
.psel = 0,
|
||||
.autoblock = 1,
|
||||
.nsel = hackrf_r9 ? 0UL : 1UL,
|
||||
.msel = hackrf_r9 ? 19UL : 9UL,
|
||||
.clk_sel = cgu::CLK_SEL::GP_CLKIN,
|
||||
});
|
||||
|
||||
cgu::pll1::enable();
|
||||
while (!cgu::pll1::is_locked())
|
||||
;
|
||||
|
||||
set_clock_config(clock_config_pll1_step);
|
||||
|
||||
/* Delay >50us at 90-110MHz clock speed */
|
||||
volatile uint32_t delay = 1400;
|
||||
while (delay--)
|
||||
;
|
||||
|
||||
set_clock_config(clock_config_pll1);
|
||||
|
||||
/* Remove /2P divider from PLL1 output to achieve full speed */
|
||||
cgu::pll1::direct();
|
||||
}
|
||||
|
||||
static void draw_splash_screen_icon(int16_t n, const ui::Bitmap& bitmap) {
|
||||
ui::Painter painter;
|
||||
|
||||
painter.draw_bitmap(
|
||||
{portapack::display.width() / 2 - 8 - 40 + (n * 20), portapack::display.height() / 2 - 8 + 40},
|
||||
bitmap,
|
||||
ui::Color::white(),
|
||||
ui::Color::black());
|
||||
}
|
||||
|
||||
static bool is_portapack_present() {
|
||||
systime_t timeout = 50;
|
||||
uint8_t wm8731_reset_command[] = {0x0f, 0x00};
|
||||
if (i2c0.transmit(0x1a /* wm8731 */, wm8731_reset_command, 2, timeout) == false) {
|
||||
audio_codec_ak4951.reset();
|
||||
uint8_t ak4951_init_command[] = {0x00, 0x00};
|
||||
i2c0.transmit(0x12 /* ak4951 */, ak4951_init_command, 2, timeout);
|
||||
chThdSleepMilliseconds(10);
|
||||
if (i2c0.transmit(0x12 /* ak4951 */, ak4951_init_command, 2, timeout) == false) {
|
||||
shutdown_base();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool check_portapack_cpld() {
|
||||
switch (portapack_model()) {
|
||||
case PortaPackModel::AUTODETECT: {
|
||||
portapack::cpld::CpldUpdateStatus result = portapack::cpld::update_autodetect(
|
||||
portapack::cpld::rev_20150901::config, portapack::cpld::rev_20170522::config);
|
||||
if (result != portapack::cpld::CpldUpdateStatus::Success) {
|
||||
shutdown_base();
|
||||
return false;
|
||||
}
|
||||
} break;
|
||||
|
||||
case PortaPackModel::R1_20150901:
|
||||
case PortaPackModel::R2_20170522: {
|
||||
portapack::cpld::CpldUpdateStatus result = portapack::cpld::update_if_necessary(portapack_cpld_config());
|
||||
if (result == portapack::cpld::CpldUpdateStatus::Program_failed) {
|
||||
chThdSleepMilliseconds(10);
|
||||
// Mode left (R1) and right (R2,H2,H2+) bypass going into hackrf mode after failing CPLD update
|
||||
// Mode center (autodetect), up (R1) and down (R2,H2,H2+) will go into hackrf mode after failing CPLD update
|
||||
if (load_config() != 3 /* left */ && load_config() != 4 /* right */) {
|
||||
shutdown_base();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
case PortaPackModel::AGM:
|
||||
// the AGM devices are always factory flashed. so do nothing
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void initialize_boot_splash_screen() {
|
||||
ui::Painter painter;
|
||||
portapack::display.init();
|
||||
|
||||
painter.fill_rectangle(
|
||||
{0, 0, portapack::display.width(), portapack::display.height()},
|
||||
ui::Color::black());
|
||||
|
||||
chThdSleepMilliseconds(17);
|
||||
portapack::backlight()->on();
|
||||
|
||||
painter.draw_bitmap(
|
||||
{portapack::display.width() / 2 - 40, portapack::display.height() / 2 - 8},
|
||||
ui::bitmap_titlebar_image,
|
||||
ui::Color::white(),
|
||||
ui::Color::black());
|
||||
}
|
||||
|
||||
/* Clock scheme after exiting bootloader in SPIFI mode:
|
||||
*
|
||||
* XTAL_OSC = powered down
|
||||
@@ -389,28 +497,29 @@ static void shutdown_base() {
|
||||
* everything else = IRC
|
||||
*/
|
||||
|
||||
bool init() {
|
||||
init_status_t init() {
|
||||
set_idivc_base_clocks(cgu::CLK_SEL::IDIVC);
|
||||
|
||||
i2c0.start(i2c_config_boot_clock);
|
||||
|
||||
// Keeping this here for now incase we need to revert
|
||||
// if( !portapack::cpld::update_if_necessary(portapack_cpld_config()) ) {
|
||||
// shutdown_base();
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// if( !hackrf::cpld::load_sram() ) {
|
||||
// chSysHalt();
|
||||
// }
|
||||
chThdSleepMilliseconds(100);
|
||||
|
||||
configure_pins_portapack();
|
||||
|
||||
portapack::io.init();
|
||||
persistent_memory::cache::init();
|
||||
|
||||
const auto switches_state = swizzled_switches() & (~(0xC0 | 0x80));
|
||||
bool lcd_fast_setup = switches_state == 0 && portapack::display.read_display_status();
|
||||
|
||||
if (lcd_fast_setup) {
|
||||
initialize_boot_splash_screen();
|
||||
} else {
|
||||
if (check_portapack_cpld() == false)
|
||||
return init_status_t::INIT_PORTAPACK_CPLD_FAILED;
|
||||
}
|
||||
|
||||
/* Cache some configuration data from persistent memory. */
|
||||
persistent_memory::cache::init();
|
||||
rtc_time::dst_init();
|
||||
chThdSleepMilliseconds(10);
|
||||
|
||||
@@ -423,48 +532,10 @@ bool init() {
|
||||
set_clock_config(clock_config_irc);
|
||||
cgu::pll1::disable();
|
||||
|
||||
/* Incantation from LPC43xx UM10503 section 12.2.1.1, to bring the M4
|
||||
* core clock speed to the 110 - 204MHz range.
|
||||
*/
|
||||
set_cpu_clock_speed();
|
||||
|
||||
/* Step into the 90-110MHz M4 clock range */
|
||||
/* OG:
|
||||
* Fclkin = 40M
|
||||
* /N=2 = 20M = PFDin
|
||||
* Fcco = PFDin * (M=10) = 200M
|
||||
* r9:
|
||||
* Fclkin = 10M
|
||||
* /N=1 = 10M = PFDin
|
||||
* Fcco = PFDin * (M=20) = 200M
|
||||
* Fclk = Fcco / (2*(P=1)) = 100M
|
||||
*/
|
||||
cgu::pll1::ctrl({
|
||||
.pd = 1,
|
||||
.bypass = 0,
|
||||
.fbsel = 0,
|
||||
.direct = 0,
|
||||
.psel = 0,
|
||||
.autoblock = 1,
|
||||
.nsel = hackrf_r9 ? 0UL : 1UL,
|
||||
.msel = hackrf_r9 ? 19UL : 9UL,
|
||||
.clk_sel = cgu::CLK_SEL::GP_CLKIN,
|
||||
});
|
||||
|
||||
cgu::pll1::enable();
|
||||
while (!cgu::pll1::is_locked())
|
||||
;
|
||||
|
||||
set_clock_config(clock_config_pll1_step);
|
||||
|
||||
/* Delay >50us at 90-110MHz clock speed */
|
||||
volatile uint32_t delay = 1400;
|
||||
while (delay--)
|
||||
;
|
||||
|
||||
set_clock_config(clock_config_pll1);
|
||||
|
||||
/* Remove /2P divider from PLL1 output to achieve full speed */
|
||||
cgu::pll1::direct();
|
||||
if (lcd_fast_setup)
|
||||
draw_splash_screen_icon(0, ui::bitmap_icon_memory);
|
||||
|
||||
usb_serial.initialize();
|
||||
|
||||
@@ -472,18 +543,11 @@ bool init() {
|
||||
chThdSleepMilliseconds(10);
|
||||
|
||||
/* Check if portapack is attached by checking if any of the two audio chips is present. */
|
||||
systime_t timeout = 50;
|
||||
uint8_t wm8731_reset_command[] = {0x0f, 0x00};
|
||||
if (i2c0.transmit(0x1a /* wm8731 */, wm8731_reset_command, 2, timeout) == false) {
|
||||
audio_codec_ak4951.reset();
|
||||
uint8_t ak4951_init_command[] = {0x00, 0x00};
|
||||
i2c0.transmit(0x12 /* ak4951 */, ak4951_init_command, 2, timeout);
|
||||
chThdSleepMilliseconds(10);
|
||||
if (i2c0.transmit(0x12 /* ak4951 */, ak4951_init_command, 2, timeout) == false) {
|
||||
shutdown_base();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (lcd_fast_setup == false && is_portapack_present() == false)
|
||||
return init_status_t::INIT_NO_PORTAPACK;
|
||||
|
||||
if (lcd_fast_setup)
|
||||
draw_splash_screen_icon(1, ui::bitmap_icon_remote);
|
||||
|
||||
touch::adc::init();
|
||||
controls_init();
|
||||
@@ -499,20 +563,19 @@ bool init() {
|
||||
|
||||
chThdSleepMilliseconds(10);
|
||||
|
||||
portapack::cpld::CpldUpdateStatus result = portapack::cpld::update_if_necessary(portapack_cpld_config());
|
||||
if (result == portapack::cpld::CpldUpdateStatus::Program_failed) {
|
||||
chThdSleepMilliseconds(10);
|
||||
// Mode left (R1) and right (R2,H2,H2+) bypass going into hackrf mode after failing CPLD update
|
||||
// Mode center (autodetect), up (R1) and down (R2,H2,H2+) will go into hackrf mode after failing CPLD update
|
||||
if (load_config() != 3 /* left */ && load_config() != 4 /* right */) {
|
||||
shutdown_base();
|
||||
return false;
|
||||
}
|
||||
if (lcd_fast_setup)
|
||||
draw_splash_screen_icon(2, ui::bitmap_icon_sd);
|
||||
|
||||
init_status_t return_code = init_status_t::INIT_SUCCESS;
|
||||
if (!hackrf::cpld::load_sram()) {
|
||||
if (lcd_fast_setup)
|
||||
chDbgPanic("HACKRF CPLD FAILED");
|
||||
|
||||
return_code = init_status_t::INIT_HACKRF_CPLD_FAILED;
|
||||
}
|
||||
|
||||
if (!hackrf::cpld::load_sram()) {
|
||||
chSysHalt();
|
||||
}
|
||||
if (lcd_fast_setup)
|
||||
draw_splash_screen_icon(3, ui::bitmap_icon_hackrf);
|
||||
|
||||
chThdSleepMilliseconds(10); // This delay seems to solve white noise audio issues
|
||||
|
||||
@@ -523,7 +586,14 @@ bool init() {
|
||||
|
||||
audio::init(portapack_audio_codec());
|
||||
|
||||
return true;
|
||||
if (lcd_fast_setup)
|
||||
draw_splash_screen_icon(4, ui::bitmap_icon_speaker);
|
||||
else {
|
||||
portapack::display.init();
|
||||
portapack::backlight()->on();
|
||||
}
|
||||
|
||||
return return_code;
|
||||
}
|
||||
|
||||
void shutdown(const bool leave_screen_on) {
|
||||
|
||||
@@ -41,6 +41,15 @@
|
||||
* guardrails on setting properties. */
|
||||
namespace portapack {
|
||||
|
||||
enum class init_status_t {
|
||||
INIT_SUCCESS,
|
||||
INIT_NO_PORTAPACK,
|
||||
INIT_PORTAPACK_CPLD_FAILED,
|
||||
INIT_HACKRF_CPLD_FAILED,
|
||||
};
|
||||
|
||||
extern const char* init_error;
|
||||
|
||||
extern portapack::IO io;
|
||||
|
||||
extern lcd::ILI9341 display;
|
||||
@@ -65,7 +74,7 @@ extern TemperatureLogger temperature_logger;
|
||||
void set_antenna_bias(const bool v);
|
||||
bool get_antenna_bias();
|
||||
|
||||
bool init();
|
||||
init_status_t init();
|
||||
void shutdown(const bool leave_screen_on = false);
|
||||
|
||||
void setEventDispatcherToUSBSerial(EventDispatcher* evt);
|
||||
|
||||
@@ -116,8 +116,9 @@ void set_direction(const rf::Direction new_direction) {
|
||||
/* TODO: Refactor all the various "Direction" enumerations into one. */
|
||||
/* TODO: Only make changes if direction changes, but beware of clock enabling. */
|
||||
|
||||
// Prevents ghosting when switching back to RX from TX mode.
|
||||
hackrf::cpld::load_sram_no_verify();
|
||||
// That below code line , was used to prevent RX interf ghosting when switching back to RX from any TX mode, but in recent code. it seems not necessary.
|
||||
// Deleting that load_sram_no_verify() (or the original , load_sram() ), solves random TX swap I/Q problem in H1R1 , others OK- (and no side effects to all).
|
||||
// hackrf::cpld::load_sram_no_verify(); // After commit "removed the use of the hackrf cpld eeprom #1732", in a H1R1, Mic App wrong SSB TX with random USB/LSB change.
|
||||
|
||||
direction = new_direction;
|
||||
|
||||
|
||||
@@ -21,9 +21,10 @@
|
||||
*/
|
||||
|
||||
#include "rtc_time.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
|
||||
using namespace lpc43xx;
|
||||
using namespace portapack;
|
||||
|
||||
namespace pmem = portapack::persistent_memory;
|
||||
|
||||
namespace rtc_time {
|
||||
@@ -77,8 +78,10 @@ rtc::RTC dst_adjust_returned_time(rtc::RTC& datetime) {
|
||||
if (doy != dst_current_doy) {
|
||||
if (datetime.year() != dst_current_year)
|
||||
dst_update_date_range(datetime.year(), doy);
|
||||
else
|
||||
dst_check_date_range(doy);
|
||||
else {
|
||||
dst_current_doy = doy;
|
||||
dst_in_range = dst_check_date_range(doy, dst_start_doy, dst_end_doy);
|
||||
}
|
||||
}
|
||||
|
||||
// Not in DST date range
|
||||
@@ -105,15 +108,13 @@ rtc::RTC dst_adjust_returned_time(rtc::RTC& datetime) {
|
||||
}
|
||||
|
||||
// Check if current date is within the DST range (called when date changes)
|
||||
void dst_check_date_range(uint16_t doy) {
|
||||
dst_current_doy = doy;
|
||||
|
||||
bool dst_check_date_range(uint16_t doy, uint16_t start_doy, uint16_t end_doy) {
|
||||
// Check if date is within DST range
|
||||
// (note that dates are reversed in Southern hemisphere because Summer starts in December)
|
||||
if (dst_start_doy <= dst_end_doy)
|
||||
dst_in_range = ((doy >= dst_start_doy) && (doy < dst_end_doy));
|
||||
if (start_doy <= end_doy)
|
||||
return ((doy >= start_doy) && (doy < end_doy));
|
||||
else
|
||||
dst_in_range = ((doy >= dst_start_doy) || (doy < dst_end_doy));
|
||||
return ((doy >= start_doy) || (doy < end_doy));
|
||||
}
|
||||
|
||||
// Update DST parameters (called at power-up, when year changes, or DST settings are changed)
|
||||
@@ -125,12 +126,20 @@ void dst_update_date_range(uint16_t year, uint16_t doy) {
|
||||
dst_start_doy = day_of_year_of_nth_weekday(dst_current_year, dst.b.start_month, dst.b.start_which, dst.b.start_weekday);
|
||||
dst_end_doy = day_of_year_of_nth_weekday(dst_current_year, dst.b.end_month, dst.b.end_which, dst.b.end_weekday);
|
||||
|
||||
dst_check_date_range(doy);
|
||||
dst_current_doy = doy;
|
||||
dst_in_range = dst_check_date_range(doy, dst_start_doy, dst_end_doy);
|
||||
} else {
|
||||
dst_in_range = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Test date range for display purposes only when setting Time
|
||||
bool dst_test_date_range(uint16_t year, uint16_t doy, pmem::dst_config_t dst) {
|
||||
uint16_t start_doy = day_of_year_of_nth_weekday(year, dst.b.start_month, dst.b.start_which, dst.b.start_weekday);
|
||||
uint16_t end_doy = day_of_year_of_nth_weekday(year, dst.b.end_month, dst.b.end_which, dst.b.end_weekday);
|
||||
return dst_check_date_range(doy, start_doy, end_doy);
|
||||
}
|
||||
|
||||
// Set RTC clock.
|
||||
// If the user has enabled DST, the time entered and passed to this function is interpreted as having been adjusted for DST.
|
||||
// When DST functionality is enabled in pmem, the value stored in the RTC hardware is non-DST time, and we only fudge the time when read.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -25,7 +26,7 @@
|
||||
#include "signal.hpp"
|
||||
|
||||
#include "lpc43xx_cpp.hpp"
|
||||
using namespace lpc43xx;
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
|
||||
namespace rtc_time {
|
||||
|
||||
@@ -45,8 +46,9 @@ rtc::RTC now(rtc::RTC& out_datetime);
|
||||
/* Daylight Savings Time functions */
|
||||
void dst_init();
|
||||
rtc::RTC dst_adjust_returned_time(rtc::RTC& datetime);
|
||||
void dst_check_date_range(uint16_t doy);
|
||||
bool dst_check_date_range(uint16_t doy, uint16_t start_doy, uint16_t end_doy);
|
||||
void dst_update_date_range(uint16_t year, uint16_t doy);
|
||||
bool dst_test_date_range(uint16_t year, uint16_t doy, portapack::persistent_memory::dst_config_t dst);
|
||||
uint8_t days_per_month(uint16_t year, uint8_t month);
|
||||
uint8_t current_day_of_week();
|
||||
uint8_t day_of_week(uint16_t year, uint8_t month, uint8_t day);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2017 Furrtek
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2017 Furrtek
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2019 Elia Yehuda (z4ziggy)
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -126,6 +127,7 @@ void BtnGridView::add_item(GridItem new_item) {
|
||||
|
||||
void BtnGridView::update_items() {
|
||||
size_t i = 0;
|
||||
Color bg_color = portapack::persistent_memory::menu_color();
|
||||
|
||||
if ((menu_items.size()) > (displayed_max + offset)) {
|
||||
more = true;
|
||||
@@ -146,6 +148,7 @@ void BtnGridView::update_items() {
|
||||
item->set_text(menu_items[i + offset].text);
|
||||
item->set_bitmap(menu_items[i + offset].bitmap);
|
||||
item->set_color(menu_items[i + offset].color);
|
||||
item->set_bg_color(bg_color);
|
||||
item->on_select = menu_items[i + offset].on_select;
|
||||
item->set_dirty();
|
||||
}
|
||||
@@ -170,15 +173,19 @@ bool BtnGridView::set_highlighted(int32_t new_value) {
|
||||
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();
|
||||
set_dirty();
|
||||
// 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();
|
||||
} else if ((uint32_t)new_value < offset) {
|
||||
// Shift BtnGridView down
|
||||
highlighted_item = new_value;
|
||||
offset = (new_value / rows_) * rows_;
|
||||
update_items();
|
||||
set_dirty();
|
||||
// no need to set_dirty() here since all buttons have been repainted
|
||||
} else {
|
||||
// Just update highlight
|
||||
highlighted_item = new_value;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2017 Furrtek
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2017 Furrtek
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -86,6 +86,12 @@ const Style Styles::bg_blue{
|
||||
.foreground = Color::white(),
|
||||
};
|
||||
|
||||
const Style Styles::bg_dark_blue{
|
||||
.font = font::fixed_8x16,
|
||||
.background = Color::dark_blue(),
|
||||
.foreground = Color::white(),
|
||||
};
|
||||
|
||||
const Style Styles::light_grey{
|
||||
.font = font::fixed_8x16,
|
||||
.background = Color::black(),
|
||||
|
||||
@@ -58,6 +58,9 @@ class Styles {
|
||||
/* Blue background. */
|
||||
static const Style bg_blue;
|
||||
|
||||
/* Dark blue background. */
|
||||
static const Style bg_dark_blue;
|
||||
|
||||
/* Light grey foreground. */
|
||||
static const Style light_grey;
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2024 u-foka
|
||||
* Copyleft (ɔ) 2024 zxkmm under GPL license
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -327,6 +329,15 @@ SystemStatusView::SystemStatusView(
|
||||
refresh();
|
||||
};
|
||||
|
||||
button_fake_brightness.on_select = [this](ImageButton&) {
|
||||
set_dirty();
|
||||
pmem::toggle_fake_brightness_level();
|
||||
refresh();
|
||||
if (nullptr != parent()) {
|
||||
parent()->set_dirty(); // The parent of NavigationView shal be the SystemView
|
||||
}
|
||||
};
|
||||
|
||||
button_bias_tee.on_select = [this](ImageButton&) {
|
||||
this->on_bias_tee();
|
||||
};
|
||||
@@ -369,6 +380,8 @@ void SystemStatusView::refresh() {
|
||||
// Display "Disable speaker" icon only if AK4951 Codec which has separate speaker/headphone control
|
||||
if (audio::speaker_disable_supported() && !pmem::ui_hide_speaker()) status_icons.add(&toggle_speaker);
|
||||
|
||||
if (!pmem::ui_hide_fake_brightness()) status_icons.add(&button_fake_brightness);
|
||||
|
||||
if (!pmem::ui_hide_sd_card()) status_icons.add(&sd_card_status_view);
|
||||
status_icons.update_layout();
|
||||
|
||||
@@ -390,6 +403,9 @@ void SystemStatusView::refresh() {
|
||||
button_converter.set_bitmap(pmem::config_updown_converter() ? &bitmap_icon_downconvert : &bitmap_icon_upconvert);
|
||||
button_converter.set_foreground(pmem::config_converter() ? Color::red() : Color::light_grey());
|
||||
|
||||
// Fake Brightness
|
||||
button_fake_brightness.set_foreground(pmem::apply_fake_brightness() ? Color::green() : Color::light_grey());
|
||||
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2024 u-foka
|
||||
* Copyleft (ɔ) 2024 zxkmm under GPL license
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -264,6 +266,12 @@ class SystemStatusView : public View {
|
||||
Color::light_grey(),
|
||||
Color::dark_grey()};
|
||||
|
||||
ImageButton button_fake_brightness{
|
||||
{0, 0, 2 * 8, 1 * 16},
|
||||
&bitmap_icon_brightness,
|
||||
Color::green(),
|
||||
Color::dark_grey()};
|
||||
|
||||
SDCardStatusView sd_card_status_view{
|
||||
{0, 0 * 16, 2 * 8, 1 * 16}};
|
||||
|
||||
|
||||
@@ -199,7 +199,7 @@ static void cmd_screenframe(BaseSequentialStream* chp, int argc, char* argv[]) {
|
||||
std::array<ui::ColorRGB888, ui::screen_width> row;
|
||||
portapack::display.read_pixels({0, i, ui::screen_width, 1}, row);
|
||||
for (int px = 0; px < ui::screen_width; px += 5) {
|
||||
char buffer[5 * 3 * 2];
|
||||
char buffer[5 * 3 * 2 + 1];
|
||||
sprintf(buffer, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", row[px].r, row[px].g, row[px].b, row[px + 1].r, row[px + 1].g, row[px + 1].b, row[px + 2].r, row[px + 2].g, row[px + 2].b, row[px + 3].r, row[px + 3].g, row[px + 3].b, row[px + 4].r, row[px + 4].g, row[px + 4].b);
|
||||
fillOBuffer(&((SerialUSBDriver*)chp)->oqueue, (const uint8_t*)buffer, 5 * 3 * 2);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -30,7 +30,8 @@
|
||||
void AudioTXProcessor::execute(const buffer_c8_t& buffer) {
|
||||
if (!configured) return;
|
||||
|
||||
int32_t audio_sample_m;
|
||||
buffer_s16_t audio_buffer{audio_data, AUDIO_OUTPUT_BUFFER_SIZE, sampling_rate};
|
||||
int16_t audio_sample_s16;
|
||||
|
||||
// Zero-order hold (poop)
|
||||
for (size_t i = 0; i < buffer.count; i++) {
|
||||
@@ -46,15 +47,16 @@ void AudioTXProcessor::execute(const buffer_c8_t& buffer) {
|
||||
|
||||
if (bytes_per_sample == 1) {
|
||||
sample = audio_sample - 0x80;
|
||||
audio_sample_m = sample * 256;
|
||||
audio_sample_s16 = sample * 256;
|
||||
} else {
|
||||
audio_sample_m = audio_sample;
|
||||
audio_sample_s16 = (int16_t)audio_sample;
|
||||
sample = audio_sample_s16 / 256;
|
||||
}
|
||||
|
||||
// Output to speaker too
|
||||
if (!tone_key_enabled) {
|
||||
uint32_t imod32 = i & (AUDIO_OUTPUT_BUFFER_SIZE - 1);
|
||||
audio_data[imod32] = audio_sample_m;
|
||||
audio_data[imod32] = audio_sample_s16;
|
||||
if (imod32 == (AUDIO_OUTPUT_BUFFER_SIZE - 1))
|
||||
audio_output.write_unprocessed(audio_buffer);
|
||||
}
|
||||
@@ -133,6 +135,7 @@ void AudioTXProcessor::replay_config(const ReplayConfigMessage& message) {
|
||||
|
||||
void AudioTXProcessor::sample_rate_config(const SampleRateConfigMessage& message) {
|
||||
resample_inc = (((uint64_t)message.sample_rate) << 16) / baseband_fs; // 16.16 fixed point message.sample_rate
|
||||
sampling_rate = message.sample_rate;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
@@ -51,11 +51,10 @@ class AudioTXProcessor : public BasebandProcessor {
|
||||
uint32_t audio_sample{};
|
||||
int32_t sample{0}, delta{};
|
||||
int8_t re{0}, im{0};
|
||||
int8_t bytes_per_sample{1};
|
||||
int16_t audio_sample_s16{};
|
||||
uint8_t bytes_per_sample{1};
|
||||
uint32_t sampling_rate{48000};
|
||||
|
||||
int16_t audio_data[AUDIO_OUTPUT_BUFFER_SIZE];
|
||||
buffer_s16_t audio_buffer{audio_data, AUDIO_OUTPUT_BUFFER_SIZE, 48000};
|
||||
AudioOutput audio_output{};
|
||||
|
||||
size_t progress_interval_samples = 0, progress_samples = 0;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "hackrf_gpio.hpp"
|
||||
#include "portapack_hal.hpp"
|
||||
#include "portapack.hpp"
|
||||
|
||||
#include "jtag_target_gpio.hpp"
|
||||
#include "cpld_max5.hpp"
|
||||
@@ -30,11 +31,15 @@
|
||||
#include "portapack_cpld_data.hpp"
|
||||
#include "hackrf_cpld_data.hpp"
|
||||
|
||||
#include "crc.hpp"
|
||||
|
||||
#define REV_20150901_CHECKSUM 0xE0EF80FB
|
||||
#define REV_20170522_CHECKSUM 0xD1BEB722
|
||||
|
||||
namespace portapack {
|
||||
namespace cpld {
|
||||
|
||||
CpldUpdateStatus update_if_necessary(
|
||||
const Config config) {
|
||||
CpldUpdateStatus update_if_necessary(const Config config) {
|
||||
jtag::GPIOTarget target{
|
||||
portapack::gpio_cpld_tck,
|
||||
portapack::gpio_cpld_tms,
|
||||
@@ -87,6 +92,121 @@ CpldUpdateStatus update_if_necessary(
|
||||
return ok ? CpldUpdateStatus::Success : CpldUpdateStatus::Program_failed;
|
||||
}
|
||||
|
||||
static CpldUpdateStatus enter_maintenance_mode(CPLD& cpld) {
|
||||
/* Unknown state */
|
||||
cpld.reset();
|
||||
cpld.run_test_idle();
|
||||
|
||||
/* Run-Test/Idle */
|
||||
if (!cpld.idcode_ok()) {
|
||||
return CpldUpdateStatus::Idcode_check_failed;
|
||||
}
|
||||
|
||||
cpld.sample();
|
||||
cpld.bypass();
|
||||
cpld.enable();
|
||||
|
||||
/* If silicon ID doesn't match, there's a serious problem. Leave CPLD
|
||||
* in passive state.
|
||||
*/
|
||||
if (!cpld.silicon_id_ok()) {
|
||||
return CpldUpdateStatus::Silicon_id_check_failed;
|
||||
}
|
||||
|
||||
return CpldUpdateStatus::Success;
|
||||
}
|
||||
|
||||
static void exit_maintenance_mode(CPLD& cpld) {
|
||||
cpld.disable();
|
||||
cpld.bypass();
|
||||
|
||||
/* Initiate SRAM reload from flash we just programmed. */
|
||||
cpld.sample();
|
||||
cpld.clamp();
|
||||
cpld.disable();
|
||||
}
|
||||
|
||||
static uint32_t get_firmware_crc(CPLD& cpld) {
|
||||
CRC<32> crc{0x04c11db7, 0xffffffff, 0xffffffff};
|
||||
cpld.prepare_read(0x0000);
|
||||
|
||||
for (size_t i = 0; i < 3328; i++) {
|
||||
uint16_t data = cpld.read();
|
||||
crc.process_byte((data >> 0) & 0xff);
|
||||
crc.process_byte((data >> 8) & 0xff);
|
||||
crc.process_byte((data >> 16) & 0xff);
|
||||
crc.process_byte((data >> 24) & 0xff);
|
||||
}
|
||||
|
||||
cpld.prepare_read(0x0001);
|
||||
|
||||
for (size_t i = 0; i < 512; i++) {
|
||||
uint16_t data = cpld.read();
|
||||
crc.process_byte((data >> 0) & 0xff);
|
||||
crc.process_byte((data >> 8) & 0xff);
|
||||
crc.process_byte((data >> 16) & 0xff);
|
||||
crc.process_byte((data >> 24) & 0xff);
|
||||
}
|
||||
|
||||
return crc.checksum();
|
||||
}
|
||||
|
||||
CpldUpdateStatus update_autodetect(const Config config_rev_20150901, const Config config_rev_20170522) {
|
||||
jtag::GPIOTarget target{
|
||||
portapack::gpio_cpld_tck,
|
||||
portapack::gpio_cpld_tms,
|
||||
portapack::gpio_cpld_tdi,
|
||||
portapack::gpio_cpld_tdo};
|
||||
jtag::JTAG jtag{target};
|
||||
CPLD cpld{jtag};
|
||||
|
||||
if (portapack::display.read_display_status())
|
||||
return CpldUpdateStatus::Success; // LCD is ready
|
||||
|
||||
CpldUpdateStatus result = enter_maintenance_mode(cpld);
|
||||
if (result != CpldUpdateStatus::Success)
|
||||
return result;
|
||||
|
||||
uint32_t checksum = get_firmware_crc(cpld);
|
||||
|
||||
if (checksum == REV_20170522_CHECKSUM) {
|
||||
// H2 firmware present
|
||||
if (!cpld.program(config_rev_20150901.block_0, config_rev_20150901.block_1))
|
||||
return CpldUpdateStatus::Program_failed;
|
||||
} else if (checksum == REV_20150901_CHECKSUM) {
|
||||
// H1 firmware present
|
||||
if (!cpld.program(config_rev_20170522.block_0, config_rev_20170522.block_1))
|
||||
return CpldUpdateStatus::Program_failed;
|
||||
} else {
|
||||
// no firmware present
|
||||
if (!cpld.program(config_rev_20150901.block_0, config_rev_20150901.block_1))
|
||||
return CpldUpdateStatus::Program_failed;
|
||||
}
|
||||
|
||||
exit_maintenance_mode(cpld);
|
||||
|
||||
if (portapack::display.read_display_status())
|
||||
return CpldUpdateStatus::Success; // LCD is ready
|
||||
|
||||
if (checksum != REV_20150901_CHECKSUM && checksum != REV_20170522_CHECKSUM) {
|
||||
// try the other one
|
||||
CpldUpdateStatus result = enter_maintenance_mode(cpld);
|
||||
|
||||
if (result != CpldUpdateStatus::Success)
|
||||
return result;
|
||||
|
||||
if (!cpld.program(config_rev_20170522.block_0, config_rev_20170522.block_1))
|
||||
return CpldUpdateStatus::Program_failed;
|
||||
|
||||
exit_maintenance_mode(cpld);
|
||||
|
||||
if (portapack::display.read_display_status())
|
||||
return CpldUpdateStatus::Success; // LCD is ready
|
||||
}
|
||||
|
||||
return CpldUpdateStatus::Program_failed;
|
||||
}
|
||||
|
||||
} /* namespace cpld */
|
||||
} /* namespace portapack */
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ enum class CpldUpdateStatus {
|
||||
Program_failed = 3
|
||||
};
|
||||
|
||||
CpldUpdateStatus update_if_necessary(
|
||||
const Config config);
|
||||
CpldUpdateStatus update_if_necessary(const Config config);
|
||||
CpldUpdateStatus update_autodetect(const Config config_rev_20150901, const Config config_rev_20170522);
|
||||
|
||||
} /* namespace cpld */
|
||||
} /* namespace portapack */
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -84,6 +84,17 @@ void lcd_wake() {
|
||||
lcd_display_on();
|
||||
}
|
||||
|
||||
uint32_t lcd_read_display_status() {
|
||||
io.lcd_data_write_command_and_data(0x09, {});
|
||||
io.lcd_read_word();
|
||||
|
||||
uint32_t value2 = io.lcd_read_word();
|
||||
uint32_t value3 = io.lcd_read_word();
|
||||
uint32_t value4 = io.lcd_read_word();
|
||||
uint32_t value5 = io.lcd_read_word();
|
||||
return value5 + (value4 << 8) + (value3 << 16) + (value2 << 24);
|
||||
}
|
||||
|
||||
void lcd_init() {
|
||||
// LCDs are configured for IM[2:0] = 001
|
||||
// 8080-I system, 16-bit parallel bus
|
||||
@@ -260,6 +271,25 @@ void lcd_vertical_scrolling_start_address(
|
||||
|
||||
} // namespace
|
||||
|
||||
bool ILI9341::read_display_status() {
|
||||
lcd_reset();
|
||||
uint32_t display_status = lcd_read_display_status();
|
||||
|
||||
/* This tries to validate the display_status.
|
||||
* The value could vary from device to device, so we are less specific here.
|
||||
* 0xFFFFFEFF was seen when the display was not reachable
|
||||
* 0x00610000 was seen when the display was reachable
|
||||
*/
|
||||
|
||||
if (display_status > 0x0E000000ULL)
|
||||
return false;
|
||||
|
||||
if (display_status < 0x00000100ULL)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ILI9341::init() {
|
||||
lcd_reset();
|
||||
lcd_init();
|
||||
|
||||
@@ -42,6 +42,8 @@ class ILI9341 {
|
||||
ILI9341(ILI9341&&) = delete;
|
||||
void operator=(const ILI9341&) = delete;
|
||||
|
||||
bool read_display_status();
|
||||
|
||||
void init();
|
||||
void shutdown();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyleft (ɔ) 2024 zxkmm under GPL license
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -20,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "portapack_io.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
|
||||
#include "lpc43xx_cpp.hpp"
|
||||
using namespace lpc43xx;
|
||||
@@ -75,6 +77,14 @@ void IO::reference_oscillator(const bool enable) {
|
||||
io_write(1, io_reg);
|
||||
}
|
||||
|
||||
bool IO::get_dark_cover() {
|
||||
return portapack::persistent_memory::apply_fake_brightness();
|
||||
}
|
||||
|
||||
uint8_t IO::get_brightness() {
|
||||
return portapack::persistent_memory::fake_brightness_level();
|
||||
}
|
||||
|
||||
uint32_t IO::io_update(const TouchPinsConfig write_value) {
|
||||
/* Very touchy code to save context of PortaPack data bus while the
|
||||
* resistive touch pin drive is changed. Order of operations is
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyleft (ɔ) 2024 zxkmm under GPL license
|
||||
* Copyright (C) 2024 u-foka
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -30,6 +32,8 @@
|
||||
#include "gpio.hpp"
|
||||
#include "ui.hpp"
|
||||
|
||||
// #include "portapack_persistent_memory.hpp"
|
||||
|
||||
namespace portapack {
|
||||
|
||||
class IO {
|
||||
@@ -141,7 +145,10 @@ class IO {
|
||||
}
|
||||
}
|
||||
|
||||
void lcd_write_pixel(const ui::Color pixel) {
|
||||
void lcd_write_pixel(ui::Color pixel) {
|
||||
if (get_dark_cover()) {
|
||||
darken_color(pixel, get_brightness()); // Darken the pixel color
|
||||
}
|
||||
lcd_write_data(pixel.v);
|
||||
}
|
||||
|
||||
@@ -149,13 +156,19 @@ class IO {
|
||||
return lcd_read_data();
|
||||
}
|
||||
|
||||
void lcd_write_pixels(const ui::Color pixel, size_t n) {
|
||||
void lcd_write_pixels(ui::Color pixel, size_t n) {
|
||||
if (get_dark_cover()) {
|
||||
darken_color(pixel, get_brightness()); // Darken the pixel color
|
||||
}
|
||||
while (n--) {
|
||||
lcd_write_data(pixel.v);
|
||||
}
|
||||
}
|
||||
|
||||
void lcd_write_pixels_unrolled8(const ui::Color pixel, size_t n) {
|
||||
void lcd_write_pixels_unrolled8(ui::Color pixel, size_t n) {
|
||||
if (get_dark_cover()) {
|
||||
darken_color(pixel, get_brightness()); // Darken the pixel color
|
||||
}
|
||||
auto v = pixel.v;
|
||||
n >>= 3;
|
||||
while (n--) {
|
||||
@@ -203,6 +216,10 @@ class IO {
|
||||
return switches_raw;
|
||||
}
|
||||
|
||||
bool get_dark_cover();
|
||||
uint8_t get_brightness();
|
||||
// TODO: cache the value ^^ & ^ to increaase performance, need a trigger cuz init doesn't work. And since the constructor is constexpr, we can't use with in class var to cache it. maybe cache from outside somewhere and pass it here as argument.
|
||||
|
||||
uint32_t io_update(const TouchPinsConfig write_value);
|
||||
|
||||
uint32_t lcd_te() {
|
||||
@@ -314,6 +331,61 @@ class IO {
|
||||
addr(1); /* Set up for data phase (most likely after a command) */
|
||||
}
|
||||
|
||||
void darken_color(ui::Color& pixel, uint8_t darken_level_shift) {
|
||||
// TODO: 1. do we need edge control?
|
||||
// currently didn't see and issue without edge control
|
||||
// but maybe hurts screen hardware without one?
|
||||
|
||||
// TODO: 2. de-color mode for accessibility
|
||||
// TODO: 3. high contrast mode for accessibility
|
||||
|
||||
uint16_t r = (pixel.v >> 11) & 0x1F; // Extract red
|
||||
uint16_t g = (pixel.v >> 5) & 0x3F; // Extract green
|
||||
uint16_t b = pixel.v & 0x1F; // Extract blue
|
||||
|
||||
r = r >> darken_level_shift; // Darken red
|
||||
g = g >> darken_level_shift; // Darken green
|
||||
b = b >> darken_level_shift; // Darken blue
|
||||
|
||||
pixel.v = (r << 11) | (g << 5) | b; // Combine back to color, check UI::color for the color layout
|
||||
}
|
||||
|
||||
// void high_contrast(ui::Color& pixel, size_t contrast_level_shift) { // TODO
|
||||
// uint16_t r = (pixel.v >> 11) & 0x1F;
|
||||
// uint16_t g = (pixel.v >> 5) & 0x3F;
|
||||
// uint16_t b = pixel.v & 0x1F;
|
||||
//
|
||||
// if ((r << contrast_level_shift) > 0x1F) { // should be slightly smaller, need more obverse...
|
||||
// r = 0x1F;
|
||||
// } else {
|
||||
// r = r << contrast_level_shift;
|
||||
// }
|
||||
//
|
||||
// if ((g << contrast_level_shift) > 0x3F) { // same as above
|
||||
// g = 0x3F;
|
||||
// } else {
|
||||
// g = g << contrast_level_shift;
|
||||
// }
|
||||
//
|
||||
// if ((b << contrast_level_shift) > 0x1F) { // same as above
|
||||
// b = 0x1F;
|
||||
// } else {
|
||||
// b = b << contrast_level_shift;
|
||||
// }
|
||||
//
|
||||
// pixel.v = (r << 11) | (g << 5) | b;
|
||||
// }
|
||||
//
|
||||
// void gray_scale(ui::Color& pixel) { // TODO: the blackwhite not looks right....
|
||||
// uint16_t r = (pixel.v >> 11) & 0x1F;
|
||||
// uint16_t g = (pixel.v >> 5) & 0x3F;
|
||||
// uint16_t b = pixel.v & 0x1F;
|
||||
//
|
||||
// uint16_t average = (r + g + b) / 3;
|
||||
//
|
||||
// pixel.v = (average << 11) | (average << 5) | average;
|
||||
// }
|
||||
|
||||
void lcd_write_data(const uint32_t value) __attribute__((always_inline)) {
|
||||
// NOTE: Assumes and DIR=0 and ADDR=1 from command phase.
|
||||
data_write_high(value); /* Drive high byte */
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -30,6 +31,7 @@
|
||||
#include "memory_map.hpp"
|
||||
#include "portapack.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "ui.hpp"
|
||||
#include "ui_styles.hpp"
|
||||
#include "ui_painter.hpp"
|
||||
#include "ui_flash_utility.hpp"
|
||||
@@ -45,6 +47,7 @@
|
||||
#include <hal.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace ui;
|
||||
|
||||
namespace portapack {
|
||||
namespace persistent_memory {
|
||||
@@ -106,7 +109,7 @@ struct ui_config_t {
|
||||
bool hide_clock : 1;
|
||||
bool clock_show_date : 1;
|
||||
bool clkout_enabled : 1;
|
||||
bool UNUSED_1 : 1;
|
||||
bool apply_fake_brightness : 1;
|
||||
bool stealth_mode : 1;
|
||||
bool config_login : 1;
|
||||
bool config_splash : 1;
|
||||
@@ -127,13 +130,13 @@ struct ui_config2_t {
|
||||
bool hide_sd_card : 1;
|
||||
|
||||
bool hide_mute : 1;
|
||||
bool hide_fake_brightness : 1;
|
||||
bool UNUSED_1 : 1;
|
||||
bool UNUSED_2 : 1;
|
||||
bool UNUSED_3 : 1;
|
||||
bool UNUSED_4 : 1;
|
||||
bool UNUSED_5 : 1;
|
||||
bool UNUSED_6 : 1;
|
||||
bool UNUSED_7 : 1;
|
||||
|
||||
uint8_t PLACEHOLDER_2;
|
||||
uint8_t PLACEHOLDER_3;
|
||||
@@ -223,7 +226,14 @@ struct data_t {
|
||||
|
||||
// Rotary encoder dial sensitivity (encoder.cpp/hpp)
|
||||
uint16_t encoder_dial_sensitivity : 4;
|
||||
uint16_t UNUSED_8 : 12;
|
||||
|
||||
// fake brightness level (not switch, switch is in another place)
|
||||
uint16_t fake_brightness_level : 4;
|
||||
|
||||
// Encoder rotation rate multiplier for larger increments when rotated rapidly
|
||||
uint16_t encoder_rate_multiplier : 4;
|
||||
|
||||
uint16_t UNUSED : 4;
|
||||
|
||||
// Headphone volume in centibels.
|
||||
int16_t headphone_volume_cb;
|
||||
@@ -240,6 +250,11 @@ struct data_t {
|
||||
// Daylight savings time
|
||||
dst_config_t dst_config;
|
||||
|
||||
// Menu Color Scheme
|
||||
Color menu_color;
|
||||
|
||||
uint16_t UNUSED_16;
|
||||
|
||||
constexpr data_t()
|
||||
: structure_version(data_structure_version_enum::VERSION_CURRENT),
|
||||
target_frequency(target_frequency_reset_value),
|
||||
@@ -288,12 +303,17 @@ struct data_t {
|
||||
frequency_tx_correction(0),
|
||||
|
||||
encoder_dial_sensitivity(DIAL_SENSITIVITY_NORMAL),
|
||||
UNUSED_8(0),
|
||||
fake_brightness_level(BRIGHTNESS_50),
|
||||
encoder_rate_multiplier(1),
|
||||
UNUSED(0),
|
||||
|
||||
headphone_volume_cb(-600),
|
||||
misc_config(),
|
||||
ui_config2(),
|
||||
config_mode_storage(CONFIG_MODE_NORMAL_VALUE),
|
||||
dst_config() {
|
||||
dst_config(),
|
||||
menu_color(Color::grey()),
|
||||
UNUSED_16() {
|
||||
}
|
||||
};
|
||||
|
||||
@@ -395,11 +415,13 @@ void defaults() {
|
||||
cached_backup_ram = backup_ram_t();
|
||||
|
||||
// If the desired default is 0/false, then no need to set it here (buffer is initialized to 0)
|
||||
// NB: This function is only called when pmem is reset; also see firmware upgrade handling below.
|
||||
set_config_backlight_timer(backlight_config_t{});
|
||||
set_config_splash(true);
|
||||
set_config_disable_external_tcxo(false);
|
||||
set_encoder_dial_sensitivity(DIAL_SENSITIVITY_NORMAL);
|
||||
set_config_speaker_disable(true); // Disable AK4951 speaker by default (in case of OpenSourceSDRLab H2)
|
||||
set_menu_color(Color::grey());
|
||||
|
||||
// Default values for recon app.
|
||||
set_recon_autosave_freqs(false);
|
||||
@@ -422,13 +444,15 @@ void defaults() {
|
||||
}
|
||||
|
||||
void init() {
|
||||
const auto switches_state = get_switches_state();
|
||||
const auto switches_state = swizzled_switches();
|
||||
|
||||
// ignore for valid check
|
||||
auto config_mode_backup = config_mode_storage_direct();
|
||||
set_config_mode_storage_direct(CONFIG_MODE_NORMAL_VALUE);
|
||||
|
||||
if (!(switches_state[(size_t)ui::KeyEvent::Left] && switches_state[(size_t)ui::KeyEvent::Right]) && backup_ram->is_valid()) {
|
||||
if (!(((switches_state >> (size_t)ui::KeyEvent::Left & 1) == 1) &&
|
||||
((switches_state >> (size_t)ui::KeyEvent::Right & 1) == 1)) &&
|
||||
backup_ram->is_valid()) {
|
||||
// Copy valid persistent data into cache.
|
||||
cached_backup_ram = *backup_ram;
|
||||
|
||||
@@ -444,6 +468,10 @@ void init() {
|
||||
defaults();
|
||||
}
|
||||
set_config_mode_storage_direct(config_mode_backup);
|
||||
|
||||
// Firmware upgrade handling - adjust newly defined fields where 0 is an invalid default
|
||||
if (fake_brightness_level() == 0) set_fake_brightness_level(BRIGHTNESS_50);
|
||||
if (menu_color().v == 0) set_menu_color(Color::grey());
|
||||
}
|
||||
|
||||
void persist() {
|
||||
@@ -619,6 +647,10 @@ bool stealth_mode() {
|
||||
return data->ui_config.stealth_mode;
|
||||
}
|
||||
|
||||
bool apply_fake_brightness() {
|
||||
return data->ui_config.apply_fake_brightness;
|
||||
}
|
||||
|
||||
bool config_login() {
|
||||
return data->ui_config.config_login;
|
||||
}
|
||||
@@ -718,6 +750,10 @@ void set_config_backlight_timer(const backlight_config_t& new_value) {
|
||||
data->ui_config.enable_backlight_timeout = static_cast<uint8_t>(new_value.timeout_enabled());
|
||||
}
|
||||
|
||||
void set_apply_fake_brightness(const bool v) {
|
||||
data->ui_config.apply_fake_brightness = v;
|
||||
}
|
||||
|
||||
uint32_t pocsag_last_address() {
|
||||
return data->pocsag_last_address;
|
||||
}
|
||||
@@ -874,6 +910,9 @@ bool ui_hide_clock() {
|
||||
bool ui_hide_sd_card() {
|
||||
return data->ui_config2.hide_sd_card;
|
||||
}
|
||||
bool ui_hide_fake_brightness() {
|
||||
return data->ui_config2.hide_fake_brightness;
|
||||
}
|
||||
|
||||
void set_ui_hide_speaker(bool v) {
|
||||
data->ui_config2.hide_speaker = v;
|
||||
@@ -904,6 +943,9 @@ void set_ui_hide_clock(bool v) {
|
||||
void set_ui_hide_sd_card(bool v) {
|
||||
data->ui_config2.hide_sd_card = v;
|
||||
}
|
||||
void set_ui_hide_fake_brightness(bool v) {
|
||||
data->ui_config2.hide_fake_brightness = v;
|
||||
}
|
||||
|
||||
/* Converter */
|
||||
bool config_converter() {
|
||||
@@ -954,13 +996,20 @@ void set_config_freq_rx_correction(uint32_t v) {
|
||||
}
|
||||
|
||||
// Rotary encoder dial settings
|
||||
|
||||
uint8_t config_encoder_dial_sensitivity() {
|
||||
uint8_t encoder_dial_sensitivity() {
|
||||
return data->encoder_dial_sensitivity;
|
||||
}
|
||||
void set_encoder_dial_sensitivity(uint8_t v) {
|
||||
data->encoder_dial_sensitivity = v;
|
||||
}
|
||||
uint8_t encoder_rate_multiplier() {
|
||||
uint8_t v = data->encoder_rate_multiplier;
|
||||
if (v == 0) v = 1; // minimum value is 1; treat 0 the same as 1
|
||||
return v;
|
||||
}
|
||||
void set_encoder_rate_multiplier(uint8_t v) {
|
||||
data->encoder_rate_multiplier = v;
|
||||
}
|
||||
|
||||
// Recovery mode magic value storage
|
||||
static data_t* data_direct_access = reinterpret_cast<data_t*>(memory::map::backup_ram.base());
|
||||
@@ -994,6 +1043,34 @@ void set_config_dst(dst_config_t v) {
|
||||
rtc_time::dst_init();
|
||||
}
|
||||
|
||||
// Fake brightness level (switch is in another place)
|
||||
uint8_t fake_brightness_level() {
|
||||
return data->fake_brightness_level;
|
||||
}
|
||||
void set_fake_brightness_level(uint8_t v) {
|
||||
data->fake_brightness_level = v;
|
||||
}
|
||||
|
||||
// Cycle through 4 brightness options: disabled -> enabled/50% -> enabled/25% -> enabled/12.5% -> disabled
|
||||
void toggle_fake_brightness_level() {
|
||||
bool fbe = apply_fake_brightness();
|
||||
|
||||
if ((!fbe) || (data->fake_brightness_level >= BRIGHTNESS_12p5)) {
|
||||
set_apply_fake_brightness(!fbe);
|
||||
data->fake_brightness_level = BRIGHTNESS_50;
|
||||
} else {
|
||||
data->fake_brightness_level++;
|
||||
}
|
||||
}
|
||||
|
||||
// Menu Color Scheme
|
||||
Color menu_color() {
|
||||
return data->menu_color;
|
||||
}
|
||||
void set_menu_color(Color v) {
|
||||
data->menu_color = v;
|
||||
}
|
||||
|
||||
// PMem to sdcard settings
|
||||
|
||||
bool should_use_sdcard_for_pmem() {
|
||||
@@ -1095,10 +1172,12 @@ bool debug_dump() {
|
||||
pmem_dump_file.write_line("frequency_rx_correction: " + to_string_dec_uint(data->frequency_rx_correction));
|
||||
pmem_dump_file.write_line("frequency_tx_correction: " + to_string_dec_uint(data->frequency_tx_correction));
|
||||
pmem_dump_file.write_line("encoder_dial_sensitivity: " + to_string_dec_uint(data->encoder_dial_sensitivity));
|
||||
// pmem_dump_file.write_line("UNUSED_8: " + to_string_dec_uint(data->UNUSED_8));
|
||||
pmem_dump_file.write_line("encoder_rate_multiplier: " + to_string_dec_uint(data->encoder_rate_multiplier));
|
||||
pmem_dump_file.write_line("headphone_volume_cb: " + to_string_dec_int(data->headphone_volume_cb));
|
||||
pmem_dump_file.write_line("config_mode_storage: 0x" + to_string_hex(data->config_mode_storage, 8));
|
||||
pmem_dump_file.write_line("dst_config: 0x" + to_string_hex((uint32_t)data->dst_config.v, 8));
|
||||
pmem_dump_file.write_line("fake_brightness_level: " + to_string_dec_uint(data->fake_brightness_level));
|
||||
pmem_dump_file.write_line("menu_color: 0x" + to_string_hex(data->menu_color.v, 4));
|
||||
|
||||
// ui_config bits
|
||||
const auto backlight_timer = portapack::persistent_memory::config_backlight_timer();
|
||||
@@ -1113,6 +1192,7 @@ bool debug_dump() {
|
||||
pmem_dump_file.write_line("ui_config hide_clock: " + to_string_dec_uint(data->ui_config.hide_clock));
|
||||
pmem_dump_file.write_line("ui_config clock_with_date: " + to_string_dec_uint(data->ui_config.clock_show_date));
|
||||
pmem_dump_file.write_line("ui_config clkout_enabled: " + to_string_dec_uint(data->ui_config.clkout_enabled));
|
||||
pmem_dump_file.write_line("ui_config apply_fake_brightness: " + to_string_dec_uint(data->ui_config.apply_fake_brightness));
|
||||
pmem_dump_file.write_line("ui_config stealth_mode: " + to_string_dec_uint(data->ui_config.stealth_mode));
|
||||
pmem_dump_file.write_line("ui_config config_login: " + to_string_dec_uint(data->ui_config.config_login));
|
||||
pmem_dump_file.write_line("ui_config config_splash: " + to_string_dec_uint(data->ui_config.config_splash));
|
||||
@@ -1127,6 +1207,7 @@ bool debug_dump() {
|
||||
pmem_dump_file.write_line("ui_config2 hide_clock: " + to_string_dec_uint(data->ui_config2.hide_clock));
|
||||
pmem_dump_file.write_line("ui_config2 hide_sd_card: " + to_string_dec_uint(data->ui_config2.hide_sd_card));
|
||||
pmem_dump_file.write_line("ui_config2 hide_mute: " + to_string_dec_uint(data->ui_config2.hide_mute));
|
||||
pmem_dump_file.write_line("ui_config2 hide_fake_brightness: " + to_string_dec_uint(data->ui_config2.hide_fake_brightness));
|
||||
|
||||
// misc_config bits
|
||||
pmem_dump_file.write_line("misc_config config_audio_mute: " + to_string_dec_int(config_audio_mute()));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -33,6 +34,7 @@
|
||||
#include "serializer.hpp"
|
||||
#include "volume.hpp"
|
||||
#include "config_mode.hpp"
|
||||
#include "ui.hpp"
|
||||
|
||||
// persistent memory from/to sdcard flag file
|
||||
#define PMEM_FILEFLAG u"/SETTINGS/PMEM_FILEFLAG"
|
||||
@@ -45,6 +47,7 @@
|
||||
|
||||
using namespace modems;
|
||||
using namespace serializer;
|
||||
using namespace ui;
|
||||
|
||||
namespace portapack {
|
||||
|
||||
@@ -132,6 +135,12 @@ typedef union {
|
||||
} dst_config_t;
|
||||
static_assert(sizeof(dst_config_t) == sizeof(uint32_t));
|
||||
|
||||
enum fake_brightness_level_options {
|
||||
BRIGHTNESS_50 = 1,
|
||||
BRIGHTNESS_25 = 2,
|
||||
BRIGHTNESS_12p5 = 3, // 12p5 is 12.5
|
||||
};
|
||||
|
||||
namespace cache {
|
||||
|
||||
/* Set values in cache to sensible defaults. */
|
||||
@@ -240,8 +249,11 @@ void set_config_audio_mute(bool v);
|
||||
void set_config_speaker_disable(bool v);
|
||||
void set_config_backlight_timer(const backlight_config_t& new_value);
|
||||
void set_disable_touchscreen(bool v);
|
||||
uint8_t config_encoder_dial_sensitivity();
|
||||
|
||||
uint8_t encoder_dial_sensitivity();
|
||||
void set_encoder_dial_sensitivity(uint8_t v);
|
||||
uint8_t encoder_rate_multiplier();
|
||||
void set_encoder_rate_multiplier(uint8_t v);
|
||||
|
||||
uint32_t config_mode_storage_direct();
|
||||
void set_config_mode_storage_direct(uint32_t v);
|
||||
@@ -263,6 +275,18 @@ uint16_t clkout_freq();
|
||||
dst_config_t config_dst();
|
||||
void set_config_dst(dst_config_t v);
|
||||
|
||||
/* Fake brightness */
|
||||
// switch (if do color change):
|
||||
bool apply_fake_brightness();
|
||||
void set_apply_fake_brightness(const bool v);
|
||||
// level (color change level):
|
||||
uint8_t fake_brightness_level();
|
||||
void set_fake_brightness_level(uint8_t v);
|
||||
void toggle_fake_brightness_level();
|
||||
|
||||
Color menu_color();
|
||||
void set_menu_color(Color v);
|
||||
|
||||
/* Recon app */
|
||||
bool recon_autosave_freqs();
|
||||
bool recon_autostart_recon();
|
||||
@@ -306,6 +330,7 @@ bool ui_hide_camera();
|
||||
bool ui_hide_sleep();
|
||||
bool ui_hide_bias_tee();
|
||||
bool ui_hide_clock();
|
||||
bool ui_hide_fake_brightness();
|
||||
bool ui_hide_sd_card();
|
||||
void set_ui_hide_speaker(bool v);
|
||||
void set_ui_hide_mute(bool v);
|
||||
@@ -315,6 +340,7 @@ void set_ui_hide_camera(bool v);
|
||||
void set_ui_hide_sleep(bool v);
|
||||
void set_ui_hide_bias_tee(bool v);
|
||||
void set_ui_hide_clock(bool v);
|
||||
void set_ui_hide_fake_brightness(bool v);
|
||||
void set_ui_hide_sd_card(bool v);
|
||||
|
||||
// sd persisting settings
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2023 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
||||
@@ -78,6 +78,18 @@ struct Color {
|
||||
((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3))} {
|
||||
}
|
||||
|
||||
uint8_t r() {
|
||||
return (uint8_t)((v >> 8) & 0xf8);
|
||||
}
|
||||
|
||||
uint8_t g() {
|
||||
return (uint8_t)((v >> 3) & 0xfc);
|
||||
}
|
||||
|
||||
uint8_t b() {
|
||||
return (uint8_t)((v << 3) & 0xf8);
|
||||
}
|
||||
|
||||
uint8_t to_greyscale() {
|
||||
uint32_t r = (v >> 8) & 0xf8;
|
||||
uint32_t g = (v >> 3) & 0xfc;
|
||||
|
||||
@@ -1290,6 +1290,11 @@ void NewButton::set_color(Color color) {
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
void NewButton::set_bg_color(Color color) {
|
||||
bg_color_ = color;
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
void NewButton::set_vertical_center(bool value) {
|
||||
vertical_center_ = value;
|
||||
set_dirty();
|
||||
@@ -1343,7 +1348,7 @@ Style NewButton::paint_style() {
|
||||
s.background = style().foreground;
|
||||
s.foreground = Color::black();
|
||||
} else {
|
||||
s.background = Color::grey();
|
||||
s.background = bg_color_;
|
||||
s.foreground = style().foreground;
|
||||
}
|
||||
|
||||
|
||||
@@ -504,6 +504,7 @@ class NewButton : public Widget {
|
||||
void set_bitmap(const Bitmap* bitmap);
|
||||
void set_text(const std::string value);
|
||||
void set_color(Color value);
|
||||
void set_bg_color(Color value);
|
||||
void set_vertical_center(bool value);
|
||||
std::string text() const;
|
||||
const Bitmap* bitmap();
|
||||
@@ -522,6 +523,7 @@ class NewButton : public Widget {
|
||||
protected:
|
||||
virtual Style paint_style();
|
||||
Color color_;
|
||||
Color bg_color_{Color::light_grey()};
|
||||
|
||||
private:
|
||||
std::string text_;
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 292 B |
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
#
|
||||
# Copyright (C) 2024 Mark Thompson
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
import sys
|
||||
from external_app_info import maximum_application_size
|
||||
from external_app_info import external_apps_address_start
|
||||
from external_app_info import external_apps_address_end
|
||||
|
||||
usage_message = """
|
||||
PortaPack ROM image checker for possible shared external code addresses
|
||||
|
||||
Usage: <command> <input-file>
|
||||
"""
|
||||
|
||||
def read_image(path):
|
||||
f = open(path, 'rb')
|
||||
data = f.read()
|
||||
f.close()
|
||||
return data
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print(usage_message)
|
||||
sys.exit(-1)
|
||||
|
||||
image = read_image(sys.argv[1])
|
||||
image = bytearray(image)
|
||||
|
||||
for i in range(0, len(image), 4):
|
||||
snippet = image[i:i+4]
|
||||
val = int.from_bytes(snippet, byteorder='little')
|
||||
offset = val & 0xFFFF
|
||||
if (val >= external_apps_address_start) and (val < external_apps_address_end) and ((val & 0xFFFF) < maximum_application_size):
|
||||
print ("External code address", hex(val),"at offset", hex(i),"in", sys.argv[1])
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#
|
||||
# Copyright (C) 2023 Bernd Herzog
|
||||
# Copyright (C) 2024 Mark Thompson
|
||||
#
|
||||
# This file is part of PortaPack.
|
||||
#
|
||||
@@ -25,6 +26,9 @@ import os
|
||||
import sys
|
||||
import struct
|
||||
import subprocess
|
||||
from external_app_info import maximum_application_size
|
||||
from external_app_info import external_apps_address_start
|
||||
from external_app_info import external_apps_address_end
|
||||
|
||||
usage_message = """
|
||||
PortaPack external app image creator
|
||||
@@ -34,8 +38,6 @@ See firmware/application/CMakeLists.txt > COMMAND ${EXPORT_EXTERNAL_APP_IMAGES}
|
||||
Usage: <command> <project source dir> <binary dir> <cmake objcopy path> <list of external image prefixes>
|
||||
"""
|
||||
|
||||
maximum_application_size = 32*1024
|
||||
|
||||
if len(sys.argv) < 4:
|
||||
print(usage_message)
|
||||
sys.exit(-1)
|
||||
@@ -51,7 +53,7 @@ def write_image(data, path):
|
||||
f.write(data)
|
||||
f.close()
|
||||
|
||||
def patch_image(image_data, search_address, replace_address):
|
||||
def patch_image(path, image_data, search_address, replace_address):
|
||||
if (len(image_data) % 4) != 0:
|
||||
print("file size not divideable by 4")
|
||||
sys.exit(-1)
|
||||
@@ -62,8 +64,8 @@ def patch_image(image_data, search_address, replace_address):
|
||||
snippet = image_data[x*4:4*(x+1)]
|
||||
val = int.from_bytes(snippet, byteorder='little')
|
||||
|
||||
# in firmware/application/external/external.ld the origin is set to something like search_address=0xEEE90000
|
||||
# if the value is above the search_address and inside a 40kb window (maximum size of an app) we replace it
|
||||
# in firmware/application/external/external.ld the origin is set to something like search_address=0xADB00000
|
||||
# if the value is above the search_address and inside a 32kb window (maximum size of an app) we replace it
|
||||
# with replace_address=(0x1008000 + m4 size) where the app will actually be located. The reason we do this instead just
|
||||
# using the right address in external.ld is gcc does not permit to use the same memory range multiple times.
|
||||
if val > search_address and (val - search_address) < maximum_application_size:
|
||||
@@ -74,7 +76,9 @@ def patch_image(image_data, search_address, replace_address):
|
||||
external_application_image += new_snippet
|
||||
else:
|
||||
external_application_image += snippet
|
||||
|
||||
if (val >= external_apps_address_start) and (val < external_apps_address_end) and ((val & 0xFFFF) < maximum_application_size):
|
||||
print ("WARNING: External code address", hex(val), "at offset", hex(x*4), "in", path)
|
||||
|
||||
return external_application_image
|
||||
|
||||
project_source_dir = sys.argv[1] #/portapack-mayhem/firmware/application
|
||||
@@ -90,7 +94,7 @@ for external_image_prefix in sys.argv[4:]:
|
||||
|
||||
# COMMAND ${CMAKE_OBJCOPY} -v -O binary ${PROJECT_NAME}.elf ${PROJECT_NAME}_ext_pacman.bin --only-section=.external_app_pacman
|
||||
himg = "{}/external_app_{}.himg".format(binary_dir, external_image_prefix)
|
||||
subprocess.run([cmake_objcopy, "-v", "-O", "binary", "{}/application.elf".format(binary_dir), himg, "--only-section=.external_app_{}".format(external_image_prefix)])
|
||||
subprocess.run([cmake_objcopy, "-v", "-O", "binary", "{}/application.elf".format(binary_dir), himg, "--only-section=.external_app_{}".format(external_image_prefix)])
|
||||
|
||||
external_application_image = read_image(himg)
|
||||
|
||||
@@ -101,7 +105,7 @@ for external_image_prefix in sys.argv[4:]:
|
||||
if (chunk_data[0] == 0 and chunk_data[1] == 0 and chunk_data[2] == 0 and chunk_data[3] == 0):
|
||||
replace_address = 0x10080000
|
||||
search_address = int.from_bytes(external_application_image[externalAppEntry_header_position:externalAppEntry_header_position+4], byteorder='little') & 0xFFFF0000
|
||||
external_application_image = patch_image(external_application_image, search_address, replace_address)
|
||||
external_application_image = patch_image(himg, external_application_image, search_address, replace_address)
|
||||
external_application_image[memory_location_header_position:memory_location_header_position+4] = replace_address.to_bytes(4, byteorder='little')
|
||||
|
||||
checksum = 0
|
||||
@@ -126,7 +130,7 @@ for external_image_prefix in sys.argv[4:]:
|
||||
|
||||
replace_address = 0x10080000 + len(m4_image)
|
||||
search_address = int.from_bytes(external_application_image[externalAppEntry_header_position:externalAppEntry_header_position+4], byteorder='little') & 0xFFFF0000
|
||||
external_application_image = patch_image(external_application_image, search_address, replace_address)
|
||||
external_application_image = patch_image(himg, external_application_image, search_address, replace_address)
|
||||
|
||||
external_application_image[memory_location_header_position:memory_location_header_position+4] = replace_address.to_bytes(4, byteorder='little')
|
||||
external_application_image[m4_app_offset_header_position:m4_app_offset_header_position+4] = app_image_len.to_bytes(4, byteorder='little')
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
#
|
||||
# Copyright (C) 2024 Mark Thompson
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# external app address ranges below must match those in linker file "external.ld"
|
||||
maximum_application_size = 32*1024
|
||||
external_apps_address_start = 0xADB00000
|
||||
external_apps_address_end = 0xADF00000
|
||||
@@ -30,7 +30,7 @@ usage_message = """
|
||||
Usage: <directory>
|
||||
"""
|
||||
|
||||
if len(sys.argv) < 1:
|
||||
if len(sys.argv) < 2:
|
||||
print(usage_message)
|
||||
sys.exit(-1)
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user