Fixed mic tx not working the first time it was entered

Fixed SD card FAT wipe (buffer size too big)
Cleared some warnings from ADSB rx
Updated binary
This commit is contained in:
furrtek 2018-02-01 11:17:51 +00:00
parent 441a266dc4
commit 57c759627d
17 changed files with 75 additions and 76 deletions

View File

@ -23,20 +23,16 @@
#include "ui_mictx.hpp" #include "ui_mictx.hpp"
#include "baseband_api.hpp" #include "baseband_api.hpp"
#include "hackrf_gpio.hpp"
#include "audio.hpp" #include "audio.hpp"
#include "tonesets.hpp" #include "tonesets.hpp"
#include "portapack.hpp" #include "portapack_hal.hpp"
#include "pins.hpp"
#include "string_format.hpp" #include "string_format.hpp"
#include "irq_controls.hpp" #include "irq_controls.hpp"
#include "portapack_shared_memory.hpp"
#include <cstring> #include <cstring>
using namespace tonekey; using namespace tonekey;
using namespace portapack; using namespace portapack;
using namespace hackrf::one;
namespace ui { namespace ui {
@ -58,7 +54,7 @@ void MicTXView::configure_baseband() {
baseband::set_audiotx_data( baseband::set_audiotx_data(
sampling_rate / 20, // Update vu-meter at 20Hz sampling_rate / 20, // Update vu-meter at 20Hz
transmitting ? transmitter_model.channel_bandwidth() : 0, transmitting ? transmitter_model.channel_bandwidth() : 0,
mic_gain_x10, mic_gain,
TONES_F2D(tone_key_frequency(tone_key_index)), TONES_F2D(tone_key_frequency(tone_key_index)),
0.2 // 20% mix 0.2 // 20% mix
); );
@ -68,8 +64,11 @@ void MicTXView::set_tx(bool enable) {
if (enable) { if (enable) {
transmitting = true; transmitting = true;
configure_baseband(); configure_baseband();
gpio_tx.write(1); transmitter_model.set_rf_amp(true);
led_tx.on(); transmitter_model.enable();
portapack::pin_i2s0_rx_sda.mode(3); // This is already done in audio::init but gets changed by the CPLD overlay reprogramming
//gpio_tx.write(1);
//led_tx.on();
} else { } else {
if (transmitting && rogerbeep_enabled) { if (transmitting && rogerbeep_enabled) {
baseband::request_beep(); baseband::request_beep();
@ -77,8 +76,10 @@ void MicTXView::set_tx(bool enable) {
} else { } else {
transmitting = false; transmitting = false;
configure_baseband(); configure_baseband();
gpio_tx.write(0); transmitter_model.set_rf_amp(false);
led_tx.off(); transmitter_model.disable();
//gpio_tx.write(0);
//led_tx.off();
} }
} }
} }
@ -128,7 +129,7 @@ MicTXView::MicTXView(
NavigationView& nav NavigationView& nav
) )
{ {
pins[P6_2].mode(3); // Set P6_2 pin function to I2S0_RX_SDA portapack::pin_i2s0_rx_sda.mode(3); // This is already done in audio::init but gets changed by the CPLD overlay reprogramming
baseband::run_image(portapack::spi_flash::image_tag_mic_tx); baseband::run_image(portapack::spi_flash::image_tag_mic_tx);
@ -154,7 +155,7 @@ MicTXView::MicTXView(
options_tone_key.set_selected_index(0); options_tone_key.set_selected_index(0);
options_gain.on_change = [this](size_t, int32_t v) { options_gain.on_change = [this](size_t, int32_t v) {
mic_gain_x10 = v; mic_gain = v / 10.0;
configure_baseband(); configure_baseband();
}; };
options_gain.set_selected_index(1); // x1.0 options_gain.set_selected_index(1); // x1.0
@ -206,11 +207,9 @@ MicTXView::MicTXView(
}; };
field_va_decay.set_value(1000); field_va_decay.set_value(1000);
// Run baseband as soon as the app starts to get audio levels without transmitting (rf amp off)
transmitter_model.set_sampling_rate(sampling_rate); transmitter_model.set_sampling_rate(sampling_rate);
transmitter_model.set_rf_amp(true); transmitter_model.set_rf_amp(false);
transmitter_model.set_baseband_bandwidth(1750000); transmitter_model.set_baseband_bandwidth(1750000);
transmitter_model.enable();
set_tx(false); set_tx(false);
@ -219,6 +218,7 @@ MicTXView::MicTXView(
} }
MicTXView::~MicTXView() { MicTXView::~MicTXView() {
audio::input::stop();
transmitter_model.disable(); transmitter_model.disable();
baseband::shutdown(); baseband::shutdown();
} }

View File

@ -24,10 +24,8 @@
#define __UI_MICTX_H__ #define __UI_MICTX_H__
#include "ui.hpp" #include "ui.hpp"
#include "hal.h"
#include "ui_widget.hpp" #include "ui_widget.hpp"
#include "ui_navigation.hpp" #include "ui_navigation.hpp"
#include "ui_font_fixed_8x16.hpp"
#include "ui_receiver.hpp" #include "ui_receiver.hpp"
#include "transmitter_model.hpp" #include "transmitter_model.hpp"
#include "tone_key.hpp" #include "tone_key.hpp"
@ -73,7 +71,7 @@ private:
bool va_enabled { }; bool va_enabled { };
bool rogerbeep_enabled { }; bool rogerbeep_enabled { };
uint32_t tone_key_index { }; uint32_t tone_key_index { };
uint32_t mic_gain_x10 { 10 }; float mic_gain { 1.0 };
uint32_t audio_level { 0 }; uint32_t audio_level { 0 };
uint32_t va_level { }; uint32_t va_level { };
uint32_t attack_ms { }; uint32_t attack_ms { };

View File

@ -24,6 +24,8 @@
namespace ui { namespace ui {
Thread* WipeSDView::thread { nullptr };
WipeSDView::WipeSDView(NavigationView& nav) : nav_ (nav) { WipeSDView::WipeSDView(NavigationView& nav) : nav_ (nav) {
add_children({ add_children({
&text_info, &text_info,
@ -33,28 +35,24 @@ WipeSDView::WipeSDView(NavigationView& nav) : nav_ (nav) {
} }
WipeSDView::~WipeSDView() { WipeSDView::~WipeSDView() {
if (thread) chThdTerminate(thread); if (thread)
chThdTerminate(thread);
} }
Thread* WipeSDView::thread { nullptr };
void WipeSDView::focus() { void WipeSDView::focus() {
BlockDeviceInfo block_device_info; BlockDeviceInfo block_device_info;
dummy.focus(); dummy.focus();
if (!confirmed) { if (!confirmed) {
nav_.push<ModalMessageView>("Warning !", "Wipe first 32MB of SD card\n(filesystem included) ?", YESCANCEL, [this](bool choice) { nav_.push<ModalMessageView>("Warning !", "Wipe FAT of SD card ?", YESCANCEL, [this](bool choice) {
if (choice) if (choice)
confirmed = true; confirmed = true;
} }
); );
} else { } else {
if (sdcGetInfo(&SDCD1, &block_device_info) == CH_SUCCESS) { if (sdcGetInfo(&SDCD1, &block_device_info) == CH_SUCCESS) {
blocks = 32; // Only erase first 32MB (block_device_info.blk_size * uint64_t(block_device_info.blk_num)) / (1024 * 1024); thread = chThdCreateFromHeap(NULL, 2048, NORMALPRIO, WipeSDView::static_fn, this);
progress.set_max(blocks);
thread = chThdCreateFromHeap(NULL, 2048, NORMALPRIO + 10, WipeSDView::static_fn, this);
} else { } else {
nav_.pop(); // Just silently abort for now nav_.pop(); // Just silently abort for now
} }

View File

@ -25,6 +25,7 @@
#include "ui_widget.hpp" #include "ui_widget.hpp"
#include "ui_navigation.hpp" #include "ui_navigation.hpp"
#include "string_format.hpp"
#include "ff.h" #include "ff.h"
#include <cstdint> #include <cstdint>
@ -37,13 +38,12 @@ public:
~WipeSDView(); ~WipeSDView();
void focus() override; void focus() override;
std::string title() const override { return "SD card wipe"; }; std::string title() const override { return "Wipe FAT"; };
private: private:
NavigationView& nav_; NavigationView& nav_;
bool confirmed = false; bool confirmed = false;
uint32_t blocks { 0 };
static Thread* thread; static Thread* thread;
static msg_t static_fn(void* arg) { static msg_t static_fn(void* arg) {
@ -53,21 +53,24 @@ private:
} }
void run() { void run() {
uint32_t n, b;
lfsr_word_t v = 1; lfsr_word_t v = 1;
const auto buffer = std::make_unique<std::array<uint8_t, 16384>>(); //DIR d;
const auto buffer = std::make_unique<std::array<uint8_t, 512>>();
for (b = 0; b < blocks; b++) { //f_opendir(&d, (TCHAR*)u"");
progress.set_value(b);
uint32_t count = 512; //sd_card::fs.n_fats * sd_card::fs.fsize;
progress.set_max(count);
for (uint32_t c = 0; c < count; c++) {
progress.set_value(c);
lfsr_fill(v, lfsr_fill(v,
reinterpret_cast<lfsr_word_t*>(buffer->data()), reinterpret_cast<lfsr_word_t*>(buffer->data()),
sizeof(*buffer.get()) / sizeof(lfsr_word_t)); sizeof(*buffer.get()) / sizeof(lfsr_word_t));
// 1MB if (disk_write(sd_card::fs.drv, buffer->data(), sd_card::fs.fatbase + c, 1) != RES_OK)
for (n = 0; n < 64; n++) { break;
if (disk_write(sd_card::fs.drv, buffer->data(), n + (b * 64), 16384 / 512) != RES_OK) nav_.pop();
}
} }
nav_.pop(); nav_.pop();
} }

View File

@ -220,6 +220,7 @@ void init(audio::Codec* const codec) {
void shutdown() { void shutdown() {
audio_codec->reset(); audio_codec->reset();
input::stop();
output::stop(); output::stop();
} }

View File

@ -152,12 +152,12 @@ void kill_afsk() {
send_message(&message); send_message(&message);
} }
void set_audiotx_data(const uint32_t divider, const uint32_t bw, const uint32_t gain_x10, void set_audiotx_data(const uint32_t divider, const float deviation_hz, const float audio_gain,
const uint32_t tone_key_delta, const float tone_key_mix_weight) { const uint32_t tone_key_delta, const float tone_key_mix_weight) {
const AudioTXConfigMessage message { const AudioTXConfigMessage message {
divider, divider,
bw, deviation_hz,
gain_x10, audio_gain,
tone_key_delta, tone_key_delta,
tone_key_mix_weight tone_key_mix_weight
}; };

View File

@ -60,7 +60,7 @@ void set_tones_config(const uint32_t bw, const uint32_t pre_silence, const uint1
const bool dual_tone, const bool audio_out); const bool dual_tone, const bool audio_out);
void kill_tone(); void kill_tone();
void set_sstv_data(const uint8_t vis_code, const uint32_t pixel_duration); void set_sstv_data(const uint8_t vis_code, const uint32_t pixel_duration);
void set_audiotx_data(const uint32_t divider, const uint32_t bw, const uint32_t gain_x10, void set_audiotx_data(const uint32_t divider, const float deviation_hz, const float audio_gain,
const uint32_t tone_key_delta, const float tone_key_mix_weight); const uint32_t tone_key_delta, const float tone_key_mix_weight);
void set_fifo_data(const int8_t * data); void set_fifo_data(const int8_t * data);
void set_pitch_rssi(int32_t avg, bool enabled); void set_pitch_rssi(int32_t avg, bool enabled);

View File

@ -97,7 +97,7 @@ void AudioOutput::on_block(
} }
bool AudioOutput::is_squelched() { bool AudioOutput::is_squelched() {
return ~audio_present; return !audio_present;
} }
void AudioOutput::fill_audio_buffer(const buffer_f32_t& audio, const bool send_to_fifo) { void AudioOutput::fill_audio_buffer(const buffer_f32_t& audio, const bool send_to_fifo) {

View File

@ -34,8 +34,9 @@ void ADSBRXProcessor::execute(const buffer_c8_t& buffer) {
int8_t re, im; int8_t re, im;
float mag; float mag;
uint32_t c; uint32_t c;
uint8_t level, bit, byte; uint8_t level, bit, byte { };
bool confidence, first_in_window, last_in_window; //bool confidence;
bool first_in_window, last_in_window;
// This is called at 2M/2048 = 977Hz // This is called at 2M/2048 = 977Hz
// One pulse = 500ns = 2 samples // One pulse = 500ns = 2 samples
@ -62,10 +63,6 @@ void ADSBRXProcessor::execute(const buffer_c8_t& buffer) {
if ((prev_mag < threshold_low) && (mag < threshold_low)) { if ((prev_mag < threshold_low) && (mag < threshold_low)) {
// Both under window, silence. // Both under window, silence.
if (null_count > 3) { if (null_count > 3) {
//text_debug_b.set("Bits:" + bits.substr(0, 25));
//text_debug_c.set("Hex:" + hex_str.substr(0, 26));
//text_debug_d.set("DF=" + to_string_dec_uint(frame.get_DF()) + " ICAO=" + to_string_hex(frame.get_ICAO_address(), 6));
const ADSBFrameMessage message(frame); const ADSBFrameMessage message(frame);
shared_memory.application_queue.push(message); shared_memory.application_queue.push(message);
@ -73,7 +70,7 @@ void ADSBRXProcessor::execute(const buffer_c8_t& buffer) {
} else } else
null_count++; null_count++;
confidence = false; //confidence = false;
if (prev_mag > mag) if (prev_mag > mag)
bit = 1; bit = 1;
else else
@ -87,13 +84,13 @@ void ADSBRXProcessor::execute(const buffer_c8_t& buffer) {
last_in_window = ((mag >= threshold_low) && (mag <= threshold_high)); last_in_window = ((mag >= threshold_low) && (mag <= threshold_high));
if ((first_in_window && !last_in_window) || (!first_in_window && last_in_window)) { if ((first_in_window && !last_in_window) || (!first_in_window && last_in_window)) {
confidence = true; //confidence = true;
if (prev_mag > mag) if (prev_mag > mag)
bit = 1; bit = 1;
else else
bit = 0; bit = 0;
} else { } else {
confidence = false; //confidence = false;
if (prev_mag > mag) if (prev_mag > mag)
bit = 1; bit = 1;
else else

View File

@ -50,8 +50,8 @@ private:
ADSBFrame frame { }; ADSBFrame frame { };
bool configured { false }; bool configured { false };
float prev_mag { 0 }; float prev_mag { 0 };
float threshold, threshold_low, threshold_high; float threshold { }, threshold_low { }, threshold_high { };
size_t null_count, bit_count, sample_count; size_t null_count { 0 }, bit_count { 0 }, sample_count { 0 };
std::pair<float, uint8_t> shifter[ADSB_PREAMBLE_LENGTH]; std::pair<float, uint8_t> shifter[ADSB_PREAMBLE_LENGTH];
bool decoding { }; bool decoding { };
bool preamble { }, active { }; bool preamble { }, active { };

View File

@ -74,7 +74,7 @@ void AudioTXProcessor::on_message(const Message* const msg) {
switch(msg->id) { switch(msg->id) {
case Message::ID::AudioTXConfig: case Message::ID::AudioTXConfig:
fm_delta = message.fm_delta * (0xFFFFFFULL / 1536000); fm_delta = message.deviation_hz * (0xFFFFFFULL / baseband_fs);
divider = message.divider; divider = message.divider;
as = 0; as = 0;

View File

@ -35,9 +35,11 @@ public:
void on_message(const Message* const msg) override; void on_message(const Message* const msg) override;
private: private:
static constexpr size_t baseband_fs = 1536000U;
bool configured = false; bool configured = false;
BasebandThread baseband_thread { 1536000, this, NORMALPRIO + 20, baseband::Direction::Transmit }; BasebandThread baseband_thread { baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Transmit };
int8_t audio_fifo_data[2048] { }; int8_t audio_fifo_data[2048] { };
FIFO<int8_t> audio_fifo = { audio_fifo_data, 11 }; // 43ms @ 48000Hz FIFO<int8_t> audio_fifo = { audio_fifo_data, 11 }; // 43ms @ 48000Hz

View File

@ -21,9 +21,9 @@
*/ */
#include "proc_mictx.hpp" #include "proc_mictx.hpp"
#include "tonesets.hpp"
#include "portapack_shared_memory.hpp" #include "portapack_shared_memory.hpp"
#include "sine_table_int8.hpp" #include "sine_table_int8.hpp"
#include "tonesets.hpp"
#include "event_m4.hpp" #include "event_m4.hpp"
#include <cstdint> #include <cstdint>
@ -40,7 +40,7 @@ void MicTXProcessor::execute(const buffer_c8_t& buffer){
if (!play_beep) { if (!play_beep) {
sample = audio_buffer.p[i >> 6] >> 8; // 1536000 / 64 = 24000 sample = audio_buffer.p[i >> 6] >> 8; // 1536000 / 64 = 24000
sample = (sample * (int32_t)gain_x10) / 10; sample *= audio_gain;
power_acc += (sample < 0) ? -sample : sample; // Power average for UI vu-meter power_acc += (sample < 0) ? -sample : sample; // Power average for UI vu-meter
@ -60,7 +60,6 @@ void MicTXProcessor::execute(const buffer_c8_t& buffer){
if (beep_index == BEEP_TONES_NB) { if (beep_index == BEEP_TONES_NB) {
configured = false; configured = false;
fm_delta = 0; // Zero-out the IQ output for the rest of the buffer
shared_memory.application_queue.push(txprogress_message); shared_memory.application_queue.push(txprogress_message);
} else { } else {
beep_gen.configure(beep_deltas[beep_index], 1.0); beep_gen.configure(beep_deltas[beep_index], 1.0);
@ -74,14 +73,14 @@ void MicTXProcessor::execute(const buffer_c8_t& buffer){
sample = tone_gen.process(sample); sample = tone_gen.process(sample);
// FM // FM
if (fm_delta) { if (configured) {
delta = sample * fm_delta; delta = sample * fm_delta;
phase += delta; phase += delta;
sphase = phase + (64 << 24); sphase = phase >> 24;
re = (sine_table_i8[(sphase & 0xFF000000U) >> 24]); re = (sine_table_i8[(sphase + 64) & 255]);
im = (sine_table_i8[(phase & 0xFF000000U) >> 24]); im = (sine_table_i8[sphase]);
} else { } else {
re = 0; re = 0;
im = 0; im = 0;
@ -97,8 +96,9 @@ void MicTXProcessor::on_message(const Message* const msg) {
switch(msg->id) { switch(msg->id) {
case Message::ID::AudioTXConfig: case Message::ID::AudioTXConfig:
fm_delta = config_message.fm_delta * (0xFFFFFFULL / baseband_fs); fm_delta = config_message.deviation_hz * (0xFFFFFFUL / baseband_fs);
gain_x10 = config_message.gain_x10;
audio_gain = config_message.audio_gain;
divider = config_message.divider; divider = config_message.divider;
power_acc_count = 0; power_acc_count = 0;

View File

@ -51,7 +51,7 @@ private:
ToneGen tone_gen { }; ToneGen tone_gen { };
ToneGen beep_gen { }; ToneGen beep_gen { };
uint32_t divider { }, gain_x10 { }; uint32_t divider { }, audio_gain { };
uint64_t power_acc { 0 }; uint64_t power_acc { 0 };
uint32_t power_acc_count { 0 }; uint32_t power_acc_count { 0 };
bool play_beep { false }; bool play_beep { false };

View File

@ -765,22 +765,22 @@ class AudioTXConfigMessage : public Message {
public: public:
constexpr AudioTXConfigMessage( constexpr AudioTXConfigMessage(
const uint32_t divider, const uint32_t divider,
const uint32_t fm_delta, const float deviation_hz,
const uint32_t gain_x10, const float audio_gain,
const uint32_t tone_key_delta, const uint32_t tone_key_delta,
const float tone_key_mix_weight const float tone_key_mix_weight
) : Message { ID::AudioTXConfig }, ) : Message { ID::AudioTXConfig },
divider(divider), divider(divider),
fm_delta(fm_delta), deviation_hz(deviation_hz),
gain_x10(gain_x10), audio_gain(audio_gain),
tone_key_delta(tone_key_delta), tone_key_delta(tone_key_delta),
tone_key_mix_weight(tone_key_mix_weight) tone_key_mix_weight(tone_key_mix_weight)
{ {
} }
const uint32_t divider; const uint32_t divider;
const uint32_t fm_delta; const float deviation_hz;
const uint32_t gain_x10; const float audio_gain;
const uint32_t tone_key_delta; const uint32_t tone_key_delta;
const float tone_key_mix_weight; const float tone_key_mix_weight;
}; };

View File

@ -70,14 +70,14 @@ struct Color {
return { 255, 0, 0 }; return { 255, 0, 0 };
} }
static constexpr Color dark_red() { static constexpr Color dark_red() {
return { 191, 0, 0 }; return { 159, 0, 0 };
} }
static constexpr Color orange() { static constexpr Color orange() {
return { 255, 175, 0 }; return { 255, 175, 0 };
} }
static constexpr Color dark_orange() { static constexpr Color dark_orange() {
return { 191, 88, 0 }; return { 191, 95, 0 };
} }
static constexpr Color yellow() { static constexpr Color yellow() {
@ -91,7 +91,7 @@ struct Color {
return { 0, 255, 0 }; return { 0, 255, 0 };
} }
static constexpr Color dark_green() { static constexpr Color dark_green() {
return { 0, 191, 0 }; return { 0, 159, 0 };
} }
static constexpr Color blue() { static constexpr Color blue() {

Binary file not shown.