mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-15 03:47:42 +00:00
Config mode (#1433)
* Allow code to run without a token * Reverted submodule change by mistake * WIP force tcxo * Added check to hide if not an R9 * Fixed comments * Updated name * Fixed crashing on TCXO switching * Fixed the reboot issue * Updated boot order * Cleaned up comments * added new recovery mode * added IO * implemented cpld mode change * whitespace change * renamed config mode * inverted logic * removed r9 dependency * added disable external tcxo option to config mode * fixed CLKIN detection for r9 * integrated tcxo setting into clock selection Co-authored-by @jLynx
This commit is contained in:
@@ -316,6 +316,7 @@ set(CPPSRC
|
||||
# ui_replay_view.cpp
|
||||
# ui_script.cpp
|
||||
ui_sd_card_debug.cpp
|
||||
config_mode.cpp
|
||||
${CPLD_20150901_DATA_CPP}
|
||||
${CPLD_20170522_DATA_CPP}
|
||||
${HACKRF_CPLD_DATA_CPP}
|
||||
|
@@ -169,6 +169,8 @@ SetRadioView::SetRadioView(
|
||||
&button_save,
|
||||
&button_cancel});
|
||||
|
||||
add_children({&disable_external_tcxo});
|
||||
|
||||
SetFrequencyCorrectionModel model{
|
||||
static_cast<int8_t>(pmem::correction_ppb() / 1000), 0};
|
||||
|
||||
@@ -221,10 +223,13 @@ SetRadioView::SetRadioView(
|
||||
send_system_refresh();
|
||||
};
|
||||
|
||||
disable_external_tcxo.set_value(pmem::config_disable_external_tcxo());
|
||||
|
||||
button_save.on_select = [this, &nav](Button&) {
|
||||
const auto model = this->form_collect();
|
||||
pmem::set_correction_ppb(model.ppm * 1000);
|
||||
pmem::set_clkout_freq(model.freq);
|
||||
pmem::set_config_disable_external_tcxo(disable_external_tcxo.value());
|
||||
clock_manager.enable_clock_output(pmem::clkout_enabled());
|
||||
nav.pop();
|
||||
};
|
||||
|
@@ -185,6 +185,11 @@ class SetRadioView : public View {
|
||||
5,
|
||||
"Turn on bias voltage"};
|
||||
|
||||
Checkbox disable_external_tcxo{
|
||||
{18, 14 * 16},
|
||||
5,
|
||||
"Disable external TCXO"};
|
||||
|
||||
Button button_save{
|
||||
{2 * 8, 16 * 16, 12 * 8, 32},
|
||||
"Save"};
|
||||
|
@@ -325,12 +325,18 @@ uint32_t ClockManager::measure_gp_clkin_frequency() {
|
||||
}
|
||||
|
||||
bool ClockManager::loss_of_signal() {
|
||||
return hackrf_r9
|
||||
? clock_generator.plla_loss_of_signal()
|
||||
: clock_generator.clkin_loss_of_signal();
|
||||
if (hackrf_r9) {
|
||||
const auto frequency = measure_gp_clkin_frequency();
|
||||
return (frequency < 9850000) || (frequency > 10150000);
|
||||
} else {
|
||||
return clock_generator.clkin_loss_of_signal();
|
||||
}
|
||||
}
|
||||
|
||||
ClockManager::ReferenceSource ClockManager::detect_reference_source() {
|
||||
if (portapack::persistent_memory::config_disable_external_tcxo())
|
||||
return ReferenceSource::Xtal;
|
||||
|
||||
if (loss_of_signal()) {
|
||||
// No external reference. Turn on PortaPack reference (if present).
|
||||
portapack_tcxo_enable();
|
||||
|
127
firmware/application/config_mode.cpp
Normal file
127
firmware/application/config_mode.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Bernd Herzog
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "config_mode.hpp"
|
||||
#include "core_control.hpp"
|
||||
#include "hackrf_gpio.hpp"
|
||||
#include "portapack_hal.hpp"
|
||||
|
||||
void config_mode_blink_until_dfu();
|
||||
|
||||
void config_mode_set() {
|
||||
portapack::persistent_memory::set_config_mode_storage(CONFIG_MODE_GUARD_VALUE);
|
||||
}
|
||||
|
||||
bool config_mode_should_enter() {
|
||||
return portapack::persistent_memory::config_mode_storage() == CONFIG_MODE_GUARD_VALUE;
|
||||
}
|
||||
|
||||
void config_mode_clear() {
|
||||
portapack::persistent_memory::set_config_mode_storage(CONFIG_MODE_NORMAL_VALUE);
|
||||
}
|
||||
|
||||
uint32_t blink_patterns[] = {
|
||||
0x00000000, // 0 Off
|
||||
0xFFFFFFFF, // 1 On
|
||||
0xF0F0F0F0, // 2 blink fast
|
||||
0x00FF00FF, // 3 blink slow
|
||||
0xFFF3FFF3 // 4 inverse blink slow
|
||||
};
|
||||
|
||||
void config_mode_run() {
|
||||
configure_pins_portapack();
|
||||
portapack::gpio_dfu.input();
|
||||
|
||||
config_mode_blink_until_dfu();
|
||||
|
||||
auto last_dfu_btn = portapack::gpio_dfu.read();
|
||||
portapack::persistent_memory::cache::init();
|
||||
|
||||
int32_t counter = 0;
|
||||
int8_t blink_pattern_value = portapack::persistent_memory::config_cpld() +
|
||||
(portapack::persistent_memory::config_disable_external_tcxo() ? 5 : 0);
|
||||
|
||||
while (true) {
|
||||
auto dfu_btn = portapack::gpio_dfu.read();
|
||||
auto dfu_clicked = last_dfu_btn == true && dfu_btn == false;
|
||||
last_dfu_btn = dfu_btn;
|
||||
|
||||
if (dfu_clicked) {
|
||||
int8_t value = portapack::persistent_memory::config_cpld() +
|
||||
(portapack::persistent_memory::config_disable_external_tcxo() ? 5 : 0);
|
||||
|
||||
blink_pattern_value = value = (value + 1) % 10;
|
||||
|
||||
portapack::persistent_memory::set_config_cpld(value % 5);
|
||||
portapack::persistent_memory::set_config_disable_external_tcxo((value / 5) == 1);
|
||||
|
||||
portapack::persistent_memory::cache::persist();
|
||||
}
|
||||
|
||||
auto tx_blink_pattern = blink_patterns[blink_pattern_value % 5];
|
||||
auto rx_blink_pattern = blink_patterns[blink_pattern_value / 5];
|
||||
|
||||
auto tx_value = ((tx_blink_pattern >> ((counter >> 0) & 31)) & 0x1) == 0x1;
|
||||
if (tx_value) {
|
||||
hackrf::one::led_tx.on();
|
||||
} else {
|
||||
hackrf::one::led_tx.off();
|
||||
}
|
||||
|
||||
auto rx_value = ((rx_blink_pattern >> ((counter >> 0) & 31)) & 0x1) == 0x1;
|
||||
if (rx_value) {
|
||||
hackrf::one::led_rx.on();
|
||||
} else {
|
||||
hackrf::one::led_rx.off();
|
||||
}
|
||||
|
||||
chThdSleepMilliseconds(100);
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
void config_mode_blink_until_dfu() {
|
||||
while (true) {
|
||||
hackrf::one::led_tx.on();
|
||||
hackrf::one::led_rx.on();
|
||||
hackrf::one::led_usb.on();
|
||||
chThdSleepMilliseconds(10);
|
||||
|
||||
hackrf::one::led_tx.off();
|
||||
hackrf::one::led_rx.off();
|
||||
hackrf::one::led_usb.off();
|
||||
chThdSleepMilliseconds(115);
|
||||
|
||||
auto dfu_btn = portapack::gpio_dfu.read();
|
||||
if (dfu_btn)
|
||||
break;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
chThdSleepMilliseconds(10);
|
||||
|
||||
auto dfu_btn = portapack::gpio_dfu.read();
|
||||
if (!dfu_btn)
|
||||
break;
|
||||
}
|
||||
|
||||
chThdSleepMilliseconds(10);
|
||||
}
|
37
firmware/application/config_mode.hpp
Normal file
37
firmware/application/config_mode.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Bernd Herzog
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __CONFIG_MODE_H__
|
||||
#define __CONFIG_MODE_H__
|
||||
|
||||
#include "ch.h"
|
||||
|
||||
#include "portapack.hpp"
|
||||
#include "portapack_shared_memory.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
|
||||
void config_mode_set();
|
||||
bool config_mode_should_enter();
|
||||
void config_mode_clear();
|
||||
|
||||
void config_mode_run();
|
||||
|
||||
#endif /* __CONFIG_MODE_H__ */
|
@@ -115,6 +115,7 @@ Continuous (Fox-oring)
|
||||
|
||||
#include "portapack.hpp"
|
||||
#include "portapack_shared_memory.hpp"
|
||||
#include "config_mode.hpp"
|
||||
|
||||
#include "message_queue.hpp"
|
||||
|
||||
@@ -161,9 +162,17 @@ static void event_loop() {
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
if (config_mode_should_enter()) {
|
||||
config_mode_clear();
|
||||
config_mode_run();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
// sdcStart(&SDCD1, nullptr); // Commented out as now happens in portapack.cpp
|
||||
|
||||
|
@@ -408,6 +408,10 @@ bool init() {
|
||||
|
||||
portapack::io.init();
|
||||
|
||||
/* Cache some configuration data from persistent memory. */
|
||||
persistent_memory::cache::init();
|
||||
chThdSleepMilliseconds(10);
|
||||
|
||||
clock_manager.init_clock_generator();
|
||||
|
||||
i2c0.stop();
|
||||
@@ -467,9 +471,6 @@ bool init() {
|
||||
controls_init();
|
||||
chThdSleepMilliseconds(10);
|
||||
|
||||
/* Cache some configuration data from persistent memory. */
|
||||
persistent_memory::cache::init();
|
||||
|
||||
clock_manager.set_reference_ppb(persistent_memory::correction_ppb());
|
||||
clock_manager.enable_if_clocks();
|
||||
clock_manager.enable_codec_clocks();
|
||||
|
Reference in New Issue
Block a user