mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-23 15:07:29 +00:00
SSTV transmit beta (320x256 24bpp Scottie 2 only)
This commit is contained in:
@@ -387,6 +387,13 @@ set(MODE_CPPSRC
|
||||
)
|
||||
DeclareTargets(PREP replay)
|
||||
|
||||
### SSTV TX
|
||||
|
||||
set(MODE_CPPSRC
|
||||
proc_sstvtx.cpp
|
||||
)
|
||||
DeclareTargets(PSTX sstvtx)
|
||||
|
||||
### Tones
|
||||
|
||||
set(MODE_CPPSRC
|
||||
|
166
firmware/baseband/proc_sstvtx.cpp
Normal file
166
firmware/baseband/proc_sstvtx.cpp
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
*
|
||||
* 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_sstvtx.hpp"
|
||||
#include "sine_table_int8.hpp"
|
||||
#include "event_m4.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// This is called at 3072000/2048 = 1500Hz
|
||||
void SSTVTXProcessor::execute(const buffer_c8_t& buffer) {
|
||||
|
||||
if (!configured) return;
|
||||
|
||||
for (size_t i = 0; i < buffer.count; i++) {
|
||||
|
||||
if (!sample_count) {
|
||||
|
||||
// This FSM is a mess. It seems to do a lot where it shouldn't (I/Q loop),
|
||||
// but it actually doesn't do much. Used for sequencing the different parts
|
||||
// of the scanline. Todo: simplify !
|
||||
|
||||
if (state == STATE_CALIBRATION) {
|
||||
// Once per scanline
|
||||
tone_delta = calibration_sequence[substep].first;
|
||||
sample_count = calibration_sequence[substep].second;
|
||||
if (substep == 2) {
|
||||
substep = 0;
|
||||
state = STATE_VIS;
|
||||
} else
|
||||
substep++;
|
||||
} else if (state == STATE_VIS) {
|
||||
// Once per scanline
|
||||
if (substep == 10) {
|
||||
current_scanline = &scanline_buffer[buffer_flip];
|
||||
buffer_flip ^= 1;
|
||||
if (asked == false) {
|
||||
// Ask application for a new scanline
|
||||
shared_memory.application_queue.push(sig_message);
|
||||
asked = true;
|
||||
}
|
||||
if (current_scanline->start_tone.duration) {
|
||||
state = STATE_START;
|
||||
tone_delta = current_scanline->start_tone.frequency;
|
||||
sample_count = current_scanline->start_tone.duration;
|
||||
} else {
|
||||
state = STATE_PIXELS;
|
||||
tone_delta = current_scanline->gap_tone.frequency;
|
||||
sample_count = current_scanline->gap_tone.duration;
|
||||
}
|
||||
} else {
|
||||
tone_delta = vis_code_sequence[substep];
|
||||
sample_count = SSTV_MS2S(30); // VIS code bit is 30ms
|
||||
substep++;
|
||||
}
|
||||
} else if (state == STATE_START) {
|
||||
// Once per scanline, optional
|
||||
state = STATE_PIXELS;
|
||||
tone_delta = current_scanline->gap_tone.frequency;
|
||||
sample_count = current_scanline->gap_tone.duration;
|
||||
} else if (state == STATE_PIXELS) {
|
||||
// Many times per scanline
|
||||
pixel_luma = current_scanline->luma[pixel_index];
|
||||
|
||||
pixel_index++;
|
||||
|
||||
tone_delta = SSTV_F2D(1500 + ((pixel_luma * 800) / 256));
|
||||
|
||||
sample_count = pixel_duration;
|
||||
|
||||
if (pixel_index >= 320) {
|
||||
// Scanline done, (dirty) state jump
|
||||
pixel_index = 0;
|
||||
state = STATE_VIS;
|
||||
substep = 10;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sample_count--;
|
||||
}
|
||||
|
||||
tone_sample = (sine_table_i8[(tone_phase & 0xFF000000U) >> 24]);
|
||||
tone_phase += tone_delta;
|
||||
|
||||
// FM
|
||||
delta = tone_sample * fm_delta;
|
||||
|
||||
phase += delta;
|
||||
sphase = phase + (64 << 24);
|
||||
|
||||
re = (sine_table_i8[(sphase & 0xFF000000U) >> 24]);
|
||||
im = (sine_table_i8[(phase & 0xFF000000U) >> 24]);
|
||||
|
||||
buffer.p[i] = {re, im};
|
||||
}
|
||||
}
|
||||
|
||||
void SSTVTXProcessor::on_message(const Message* const msg) {
|
||||
const auto message = *reinterpret_cast<const SSTVConfigureMessage*>(msg);
|
||||
|
||||
switch(msg->id) {
|
||||
case Message::ID::SSTVConfigure:
|
||||
pixel_duration = message.pixel_duration;
|
||||
|
||||
if (!pixel_duration) {
|
||||
configured = false;
|
||||
return;
|
||||
}
|
||||
|
||||
vis_code = message.vis_code;
|
||||
|
||||
// VIS code:
|
||||
// 1200
|
||||
// 00011101 (0=1300, 1=1100)
|
||||
// 1200
|
||||
vis_code_sequence[0] = SSTV_VIS_SS;
|
||||
for (uint32_t c = 0; c < 8; c++) {
|
||||
vis_code_sequence[c + 1] = ((vis_code << c) & 0x80) ? SSTV_VIS_ONE : SSTV_VIS_ZERO;
|
||||
}
|
||||
vis_code_sequence[9] = SSTV_VIS_SS;
|
||||
|
||||
fm_delta = 9000 * (0xFFFFFFULL / 3072000); // Fixed for now
|
||||
|
||||
pixel_index = 0;
|
||||
sample_count = 0;
|
||||
tone_phase = 0;
|
||||
state = STATE_CALIBRATION;
|
||||
substep = 0;
|
||||
|
||||
configured = true;
|
||||
break;
|
||||
|
||||
case Message::ID::FIFOData:
|
||||
memcpy(&scanline_buffer[buffer_flip], static_cast<const FIFODataMessage*>(msg)->data, sizeof(sstv_scanline));
|
||||
asked = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
EventDispatcher event_dispatcher { std::make_unique<SSTVTXProcessor>() };
|
||||
event_dispatcher.run();
|
||||
return 0;
|
||||
}
|
87
firmware/baseband/proc_sstvtx.hpp
Normal file
87
firmware/baseband/proc_sstvtx.hpp
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __PROC_SSTV_TX_H__
|
||||
#define __PROC_SSTV_TX_H__
|
||||
|
||||
#include "portapack_shared_memory.hpp"
|
||||
#include "baseband_processor.hpp"
|
||||
#include "baseband_thread.hpp"
|
||||
#include "sstv.hpp"
|
||||
|
||||
using namespace sstv;
|
||||
|
||||
class SSTVTXProcessor : public BasebandProcessor {
|
||||
public:
|
||||
void execute(const buffer_c8_t& buffer) override;
|
||||
|
||||
void on_message(const Message* const p) override;
|
||||
|
||||
private:
|
||||
|
||||
// 1900 300ms
|
||||
// 1200 10ms
|
||||
// 1900 300ms
|
||||
const std::pair<uint32_t, uint32_t> calibration_sequence[3] = {
|
||||
{ SSTV_F2D(1900), SSTV_MS2S(300) },
|
||||
{ SSTV_F2D(1200), SSTV_MS2S(10) },
|
||||
{ SSTV_F2D(1900), SSTV_MS2S(300) }
|
||||
};
|
||||
|
||||
enum state_t {
|
||||
STATE_CALIBRATION = 0,
|
||||
STATE_VIS,
|
||||
STATE_START,
|
||||
STATE_PIXELS
|
||||
};
|
||||
|
||||
state_t state { };
|
||||
|
||||
bool configured { false };
|
||||
|
||||
BasebandThread baseband_thread { 3072000, this, NORMALPRIO + 20, baseband::Direction::Transmit };
|
||||
|
||||
uint32_t vis_code_sequence[10] { };
|
||||
sstv_scanline scanline_buffer[2] { };
|
||||
uint8_t buffer_flip { 0 }, substep { 0 };
|
||||
|
||||
uint8_t vis_code { };
|
||||
uint32_t pixel_duration { };
|
||||
|
||||
sstv_scanline * current_scanline { };
|
||||
|
||||
uint8_t pixel_luma { };
|
||||
uint32_t fm_delta { 0 };
|
||||
uint32_t tone_phase { 0 };
|
||||
uint32_t tone_delta { 0 };
|
||||
uint32_t pixel_index { 0 };
|
||||
uint32_t sample_count { 0 };
|
||||
uint32_t phase { 0 }, sphase { 0 };
|
||||
int32_t tone_sample { 0 }, delta { 0 };
|
||||
int8_t re { 0 }, im { 0 };
|
||||
|
||||
bool asked { false };
|
||||
|
||||
RequestSignalMessage sig_message { RequestSignalMessage::Signal::FillRequest };
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user