mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-05 14:35:23 +00:00
WIP: device synchronization
This commit is contained in:
parent
047f6ce981
commit
58918f81c1
90 changed files with 8970 additions and 310 deletions
73
Software/VNA_embedded/Application/Trigger.cpp
Normal file
73
Software/VNA_embedded/Application/Trigger.cpp
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
#include "Trigger.hpp"
|
||||
|
||||
#include "Drivers/Exti.hpp"
|
||||
#include "main.h"
|
||||
#include "HW_HAL.hpp"
|
||||
#include "Communication/Protocol.hpp"
|
||||
#include "Hardware.hpp"
|
||||
|
||||
static Trigger::Mode mode;
|
||||
static Trigger::CallbackISR callback = nullptr;
|
||||
|
||||
void Trigger::Init(CallbackISR cb) {
|
||||
mode = Mode::Off;
|
||||
callback = cb;
|
||||
Exti::SetCallback(FPGA_TRIGGER_OUT_GPIO_Port, FPGA_TRIGGER_OUT_Pin, Exti::EdgeType::Both, Exti::Pull::Down, [](void*){
|
||||
STM::DispatchToInterrupt(callback);
|
||||
}, nullptr);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
void vApplicationIdleHook() {
|
||||
if(mode == Trigger::Mode::ExtRef) {
|
||||
STM::DispatchToInterrupt([](){
|
||||
Trigger::SetInput(HW::Ref::available());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Trigger::SetMode(Mode m) {
|
||||
if(mode == m) {
|
||||
// already in the correct mdoe
|
||||
return;
|
||||
}
|
||||
if(mode == Mode::ExtRef) {
|
||||
// reset reference to default settings
|
||||
HWHAL::Si5351.Disable(HWHAL::SiChannel::ReferenceOut);
|
||||
}
|
||||
mode = m;
|
||||
if(mode == Mode::ExtRef) {
|
||||
// Disable the external reference
|
||||
Protocol::ReferenceSettings s;
|
||||
s.AutomaticSwitch = 0;
|
||||
s.ExtRefOuputFreq = 0;
|
||||
s.UseExternalRef = 0;
|
||||
HW::Ref::set(s);
|
||||
HW::Ref::update();
|
||||
|
||||
HWHAL::Si5351.SetCLK(HWHAL::SiChannel::ReferenceOut, 10000000, Si5351C::PLL::A);
|
||||
if(GetOutput()) {
|
||||
HWHAL::Si5351.Enable(HWHAL::SiChannel::ReferenceOut);
|
||||
} else {
|
||||
HWHAL::Si5351.Disable(HWHAL::SiChannel::ReferenceOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
Trigger::Mode Trigger::GetMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
void Trigger::SetInput(bool high) {
|
||||
if(high) {
|
||||
FPGA_TRIGGER_IN_GPIO_Port->BSRR = FPGA_TRIGGER_IN_Pin;
|
||||
} else {
|
||||
FPGA_TRIGGER_IN_GPIO_Port->BSRR = FPGA_TRIGGER_IN_Pin << 16;
|
||||
}
|
||||
}
|
||||
bool Trigger::GetOutput() {
|
||||
return FPGA_TRIGGER_OUT_GPIO_Port->IDR & FPGA_TRIGGER_OUT_Pin;
|
||||
}
|
||||
bool Trigger::GetInput() {
|
||||
return FPGA_TRIGGER_IN_GPIO_Port->IDR & FPGA_TRIGGER_IN_Pin;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue