Skip to content

Commit

Permalink
Audio Beep Test (Debug) external app (#2023)
Browse files Browse the repository at this point in the history
  • Loading branch information
NotherNgineer committed Mar 22, 2024
1 parent 692644d commit ba4290c
Show file tree
Hide file tree
Showing 9 changed files with 368 additions and 2 deletions.
82 changes: 82 additions & 0 deletions firmware/application/external/audio_test/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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.hpp"
#include "ui_audio_test.hpp"
#include "ui_navigation.hpp"
#include "external_app.hpp"

namespace ui::external_app::audio_test {
void initialize_app(ui::NavigationView& nav) {
nav.push<AudioTestView>();
}
} // namespace ui::external_app::audio_test

extern "C" {

__attribute__((section(".external_app.app_audio_test.application_information"), used)) application_information_t _application_information_audio_test = {
/*.memory_location = */ (uint8_t*)0x00000000,
/*.externalAppEntry = */ ui::external_app::audio_test::initialize_app,
/*.header_version = */ CURRENT_HEADER_VERSION,
/*.app_version = */ VERSION_MD5,

/*.app_name = */ "Audio Test",
/*.bitmap_data = */ {
0x00,
0x00,
0x40,
0x10,
0x60,
0x20,
0x70,
0x44,
0x78,
0x48,
0x7F,
0x91,
0x7F,
0x92,
0x7F,
0x92,
0x7F,
0x92,
0x7F,
0x92,
0x7F,
0x92,
0x7F,
0x91,
0x78,
0x48,
0x70,
0x44,
0x60,
0x20,
0x40,
0x10,
},
/*.icon_color = */ ui::Color::cyan().v,
/*.menu_location = */ app_location_t::DEBUG,

/*.m4_app_tag = portapack::spi_flash::image_tag_none */ {'P', 'A', 'B', 'P'},
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
};
}
82 changes: 82 additions & 0 deletions firmware/application/external/audio_test/ui_audio_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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_audio_test.hpp"
#include "baseband_api.hpp"
#include "audio.hpp"
#include "portapack.hpp"

using namespace portapack;

namespace ui {

AudioTestView::AudioTestView(NavigationView& nav)
: nav_{nav} {
baseband::run_prepared_image(portapack::memory::map::m4_code.base()); // proc_audio_beep baseband is external too

add_children({&labels,
&field_frequency,
&field_duration,
&field_volume,
&toggle_speaker});

field_frequency.set_value(1000);
field_frequency.on_change = [this](int32_t v) {
(void)v;
update_audio_beep();
};

field_duration.set_value(100);
field_duration.on_change = [this](int32_t v) {
(void)v;
update_audio_beep();
};

toggle_speaker.on_change = [this](bool v) {
beep = v;
update_audio_beep();
};

field_volume.set_value(0);
field_volume.set_value(80);

audio::set_rate(audio::Rate::Hz_24000);
audio::output::start();
}

AudioTestView::~AudioTestView() {
receiver_model.disable();
baseband::shutdown();
audio::output::stop();
}

void AudioTestView::focus() {
field_frequency.focus();
}

void AudioTestView::update_audio_beep() {
if (beep)
baseband::request_audio_beep(field_frequency.value(), field_duration.value());
else
baseband::request_beep_stop();
}

} /* namespace ui */
83 changes: 83 additions & 0 deletions firmware/application/external/audio_test/ui_audio_test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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.
*/

#ifndef __UI_AUDIO_TEST_H__
#define __UI_AUDIO_TEST_H__

#include "ui_navigation.hpp"
#include "ui_receiver.hpp"

namespace ui {

class AudioTestView : public View {
public:
AudioTestView(NavigationView& nav);
~AudioTestView();
AudioTestView(const AudioTestView& other) = delete;
AudioTestView& operator=(const AudioTestView& other) = delete;

void focus() override;
void update_audio_beep();

std::string title() const override { return "Audio Test"; };

private:
NavigationView& nav_;
bool beep{false};

Labels labels{
{{7 * 8, 3 * 16}, "Audio Beep Test", Color::light_grey()},
{{0 * 8, 6 * 16}, "Frequency (Hz):", Color::light_grey()},
{{0 * 8, 8 * 16}, "Duration (ms):", Color::light_grey()},
{{0 * 8, 10 * 16}, "Volume:", Color::light_grey()}};

NumberField field_frequency{
{16 * 8, 6 * 16},
5,
{100, 24000},
100,
' ',
true};

NumberField field_duration{
{16 * 8, 8 * 16},
5,
{0, 60000},
50,
' ',
true};

AudioVolumeField field_volume{
{19 * 8, 10 * 16}};

ImageToggle toggle_speaker{
{19 * 8, 12 * 16, 2 * 8, 1 * 16},
&bitmap_icon_speaker_mute,
&bitmap_icon_speaker,
Color::light_grey(),
Color::dark_grey(),
Color::green(),
Color::dark_grey()};
};

} /* namespace ui */

#endif /*__UI_AUDIO_TEST_H__*/
4 changes: 4 additions & 0 deletions firmware/application/external/external.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ set(EXTCPPSRC
external/foxhunt/ui_foxhunt_rx.cpp
external/foxhunt/ui_foxhunt_rx.hpp

#audio_test
external/audio_test/main.cpp
external/audio_test/ui_audio_test.cpp
)

set(EXTAPPLIST
Expand All @@ -93,4 +96,5 @@ set(EXTAPPLIST
tetris
extsensors
foxhunt_rx
audio_test
)
7 changes: 6 additions & 1 deletion firmware/application/external/external.ld
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ MEMORY
ram_external_app_tetris(rwx) : org = 0xADBE0000, len = 32k
ram_external_app_extsensors(rwx) : org = 0xADBF0000, len = 32k
ram_external_app_foxhunt_rx(rwx) : org = 0xADC00000, len = 32k
ram_external_app_audio_test(rwx) : org = 0xADC10000, len = 32k
}

SECTIONS
Expand Down Expand Up @@ -146,6 +147,10 @@ SECTIONS
*(*ui*external_app*foxhunt_rx*);
} > ram_external_app_foxhunt_rx


.external_app_audio_test : ALIGN(4) SUBALIGN(4)
{
KEEP(*(.external_app.app_audio_test.application_information));
*(*ui*external_app*audio_test*);
} > ram_external_app_audio_test

}
7 changes: 6 additions & 1 deletion firmware/baseband/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,6 @@ set(MODE_CPPSRC
)
DeclareTargets(PNRR nrfrx)


### Jammer

set(MODE_CPPSRC
Expand Down Expand Up @@ -645,6 +644,12 @@ set(MODE_CPPSRC
)
DeclareTargets(PTST test)

### Audio Beep

set(MODE_CPPSRC
proc_audio_beep.cpp
)
DeclareTargets(PABP audio_beep)

### HackRF "factory" firmware

Expand Down
63 changes: 63 additions & 0 deletions firmware/baseband/proc_audio_beep.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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 "proc_audio_beep.hpp"
#include "event_m4.hpp"
#include "audio_dma.hpp"

AudioBeepProcessor::AudioBeepProcessor() {
}

void AudioBeepProcessor::execute(const buffer_c8_t& buffer) {
(void)buffer;
}

void AudioBeepProcessor::on_message(const Message* const msg) {
switch (msg->id) {
case Message::ID::RequestSignal:
on_signal_message(*reinterpret_cast<const RequestSignalMessage*>(msg));
break;

case Message::ID::AudioBeep:
on_beep_message(*reinterpret_cast<const AudioBeepMessage*>(msg));
break;

default:
break;
}
}

void AudioBeepProcessor::on_signal_message(const RequestSignalMessage& message) {
if (message.signal == RequestSignalMessage::Signal::BeepStopRequest) {
audio::dma::beep_stop();
}
}

void AudioBeepProcessor::on_beep_message(const AudioBeepMessage& message) {
audio::dma::beep_start(message.freq, AUDIO_SAMPLE_RATE, message.duration_ms);
}

int main() {
audio::dma::init_audio_out();
EventDispatcher event_dispatcher{std::make_unique<AudioBeepProcessor>()};
event_dispatcher.run();
return 0;
}
Loading

0 comments on commit ba4290c

Please sign in to comment.