diff --git a/.vscode/settings.json b/.vscode/settings.json
index 34b1ece..6142323 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -87,6 +87,5 @@
"qserialportinfo": "cpp",
"qmessagebox": "cpp"
},
- "files.autoGuessEncoding": true,
- "files.encoding": "gbk",
+ "files.autoGuessEncoding": false,
}
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 40ccb3c..94a46c9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -32,6 +32,8 @@ set(PROJECT_SOURCES
src/camera_light_src_timing_controller/clst_controler.cpp
src/camera_light_src_timing_controller/qt_serial_datachannel.cpp
+ src/camera_light_src_timing_controller/clst_controler_sig_type.cpp
+
zaf_protocol/zaf_ecode.c
zaf_protocol/zaf_protocol.c
# libxsync/src/xsync_v2.cpp
diff --git a/README.md b/README.md
index db6e597..f281ef8 100644
--- a/README.md
+++ b/README.md
@@ -1,17 +1,7 @@
```
-Timecode测试
-端口:19903
-协议:UDP
-消息 :01 00 00 00 05 02 08 00
-解析结果:08:25:00:01
-
-xync测试
-端口:13014
-协议:UDP
-消息 :
-F0 00 20 00 00 00 00 FF 00 00 F0 42 17 00 00 00 E1 FF FF FF 01 00 00 00 78 00 00 00 00 00 00 00 E6 00 00 00 00 00 00 00 00 00 00 00 80 00 00 00 00 00 00 00
-
-
-
-
-```
\ No newline at end of file
+TODO:
+ 1. 显示FPGA版本号
+ 2. 显示STM32版本号
+ 3. 显示PC软件版本号
+ 4. 修改窗口名称
+```
diff --git a/mainwindow.cpp b/mainwindow.cpp
index 7324e5e..7abc9ad 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -9,7 +9,6 @@
#include "./ui_mainwindow.h"
#include "camera_light_src_timing_controller/qt_serial_datachannel.hpp"
#include "logger.hpp"
-#include "xsync_regs.hpp"
using namespace iflytop;
using namespace clst;
@@ -29,9 +28,9 @@ static const char *fmt(const char *fmt, ...) {
}
static const uint32_t str2int(QString str) {
- // 如果0x开头,按16进制转换
- // 如果0b开头,按2进制转换
- // 否则按10进制转换
+ // 如果0x开头,??16进制转换
+ // 如果0b开头,??2进制转换
+ // 否则??10进制转换
// 去除掉str中_
str.remove("_");
@@ -77,6 +76,41 @@ void MainWindow::doinui_slot(QFunction func) {
if (func.get()) func.get()();
}
+void MainWindow::updatePage() {
+ {
+ float Freq;
+ uint32_t PluseCnt;
+ uint32_t SeqCtrlPluseCntMax;
+
+ Freq = ui->InterClk_Freq_Text->text().toFloat();
+ PluseCnt = ui->InterClk_PluseCnt_Text->text().toUInt();
+ SeqCtrlPluseCntMax = ui->InterClk_SeqCtrlPluseCntMax_Text->text().toUInt();
+
+ DO(m_clstc->InterClk_setFreq(Freq));
+ DO(m_clstc->InterClk_setPluseCnt(PluseCnt));
+ DO(m_clstc->InterClk_setSeqCtrlPluseCntMax(SeqCtrlPluseCntMax));
+ }
+}
+
+void MainWindow::refreshPage() {
+ {
+ float Freq;
+ uint32_t PluseCnt;
+ uint32_t SeqCtrlPluseCntMax;
+ float TriOutSignalFreq;
+
+ DO(m_clstc->InterClk_getFreq(Freq));
+ DO(m_clstc->InterClk_getPluseCnt(PluseCnt));
+ DO(m_clstc->InterClk_getSeqCtrlPluseCntMax(SeqCtrlPluseCntMax));
+ DO(m_clstc->InterClk_readTriOutSignalFreq(TriOutSignalFreq));
+
+ ui->InterClk_Freq_Text->setText(QString::number(Freq, 'f', 2));
+ ui->InterClk_PluseCnt_Text->setText(QString::number(PluseCnt));
+ ui->InterClk_SeqCtrlPluseCntMax_Text->setText(QString::number(SeqCtrlPluseCntMax));
+ ui->InterClk_TriOutSignalFreq_Text->setText(QString::number(TriOutSignalFreq, 'f', 2));
+ }
+}
+
void MainWindow::constructUI() {
/*******************************************************************************
* serialPortCB *
@@ -87,7 +121,7 @@ void MainWindow::constructUI() {
}
/*******************************************************************************
- * 波特率填充 *
+ * 波特率填?? *
*******************************************************************************/
ui->serialBaudrateCB->addItem("9600");
ui->serialBaudrateCB->addItem("14400");
@@ -122,7 +156,7 @@ void MainWindow::constructUI() {
G_QTDataChannel.setStopBits(QSerialPort::OneStop);
if (!G_QTDataChannel.open()) {
- QMessageBox::about(NULL, "提示", "串口无法打开,串口不存在或已被占用");
+ QMessageBox::about(NULL, "提示", "串口无法打开,串口不存在或已被占??");
return;
}
ui->serialOpenKey->setText("关闭");
@@ -143,7 +177,12 @@ void MainWindow::constructUI() {
* 刷新页面 *
*******************************************************************************/
connect(ui->refreshPageKey, &QPushButton::clicked, this, [=](bool check) { //
+ refreshPage();
+ });
+ connect(ui->UpdateCfg_Key, &QPushButton::clicked, this, [=](bool check) { //
+ updatePage();
+ refreshPage();
});
/*******************************************************************************
@@ -151,7 +190,7 @@ void MainWindow::constructUI() {
*******************************************************************************/
connect(ui->storageConfigKey, &QPushButton::clicked, this, [=](bool check) { //
DO(m_clstc->storageConfigs());
- ui->informationBrowser->setText("保存配置");
+ ui->informationBrowser->setText("保存配置成功");
});
/*******************************************************************************
@@ -159,7 +198,7 @@ void MainWindow::constructUI() {
*******************************************************************************/
connect(ui->rebootDeviceKey, &QPushButton::clicked, this, [=](bool check) { //
DO(m_clstc->reboot());
- ui->informationBrowser->setText("重启设备");
+ ui->informationBrowser->setText("重启设备成功");
});
/*******************************************************************************
@@ -167,11 +206,11 @@ void MainWindow::constructUI() {
*******************************************************************************/
connect(ui->factoryResetKey, &QPushButton::clicked, this, [=](bool check) { //
DO(m_clstc->factoryReset());
- ui->informationBrowser->setText("恢复出厂设置");
+ ui->informationBrowser->setText("恢复出厂设置成功");
});
/*******************************************************************************
- * 寄存器操作 *
+ * 寄存器操?? *
*******************************************************************************/
ui->RegAdd->setText("0x00000000");
@@ -180,7 +219,7 @@ void MainWindow::constructUI() {
uint32_t value = 0;
DO(m_clstc->reg_read(addr, value, 100));
ui->regReadbakVal->setText(fmt("0x%08X", value));
- ui->informationBrowser->setText(fmt("读0x%04x成功", addr));
+ ui->informationBrowser->setText(fmt("读取0x%04x成功", addr));
});
connect(ui->regWriteKey, &QPushButton::clicked, this, [=](bool check) { //
@@ -189,7 +228,17 @@ void MainWindow::constructUI() {
uint32_t readkbak = 0;
DO(m_clstc->reg_write(addr, value, readkbak, 100));
ui->regReadbakVal->setText(fmt("0x%04x", readkbak));
- ui->informationBrowser->setText(fmt("写0x%04x成功", addr));
+ ui->informationBrowser->setText(fmt("写入0x%08x成功", addr));
+ });
+
+ connect(ui->InterClk_trigger_Key, &QPushButton::clicked, this, [=](bool check) { //
+ DO(m_clstc->InterClk_trigger());
+ ui->informationBrowser->setText(fmt("触发成功"));
+ refreshPage();
+ });
+ connect(ui->InterClk_stop_Key, &QPushButton::clicked, this, [=](bool check) { //
+ DO(m_clstc->InterClk_stop());
+ ui->informationBrowser->setText(fmt("停止触发成功"));
});
}
diff --git a/mainwindow.h b/mainwindow.h
index c928469..415233e 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -73,6 +73,8 @@ class MainWindow : public QMainWindow {
MainWindow(QWidget *parent = nullptr);
~MainWindow();
+ void refreshPage();
+ void updatePage();
private slots:
/**
diff --git a/mainwindow.ui b/mainwindow.ui
index 4f8c37d..36697e5 100644
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -17,7 +17,7 @@
- MainWindow
+ 相机光源和时序控制器
@@ -228,6 +228,13 @@
-
+
+
+ 提交配置
+
+
+
+ -
保存配置
@@ -428,21 +435,204 @@
- 0
+ 1
+
+
+ true
- 触发源配置
+ 外部触发源配置
+
+
+
+
+ 内部触发源配置
+
+
+
+ 20
+ 10
+ 300
+ 191
+
+
+
+
+ 300
+ 200
+
+
+
+ 内部触发源配置
+
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+ 0
+ 25
+
+
+
+
+ 16777215
+ 25
+
+
+
+ 触发时钟(HZ)
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 0
+ 25
+
+
+
+
+ 16777215
+ 25
+
+
+
+ 触发脉冲数量(0等于无限)
+
+
+
+ -
+
+
+
+ 0
+ 25
+
+
+
+
+ -
+
+
+
+ 0
+ 25
+
+
+
+
+ -
+
+
+ 触发
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 0
+ 25
+
+
+
+
+ 16777215
+ 25
+
+
+
+ 顺序触发模式最大计数
+
+
+
+ -
+
+
+
+ 0
+ 25
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 0
+ 25
+
+
+
+
+ 16777215
+ 25
+
+
+
+ 输出频率探测(HZ)
+
+
+
+ -
+
+
+
+ 0
+ 25
+
+
+
+
+ -
+
+
+ 停止
+
+
+
+
+
- 光源配置
+ 光源时序配置
- 相机驱动配置
+ 快门时序配置
diff --git a/src/camera_light_src_timing_controller/clst_controler.cpp b/src/camera_light_src_timing_controller/clst_controler.cpp
index 92645eb..c6dbb16 100644
--- a/src/camera_light_src_timing_controller/clst_controler.cpp
+++ b/src/camera_light_src_timing_controller/clst_controler.cpp
@@ -9,8 +9,12 @@ using namespace clst;
#define TAG "CLSTControler"
-#define PACKET_LEN(__packet) (sizeof(zaf_packet_header_t) + __packet->ndata * 4 + 3)
-
+#define PACKET_LEN(__packet) (sizeof(zaf_packet_header_t) + (__packet->ndata) * sizeof(uint32_t) + 1 /*checksum*/ + 2 /*tail*/)
+#define DO_CMD(exptr) \
+ { \
+ zaf_error_code_t ecode = exptr; \
+ if (ecode != kaf_ec_success) return ecode; \
+ }
CLSTControler *CLSTControler::ins() {
static CLSTControler *ins = nullptr;
if (ins == nullptr) {
@@ -70,7 +74,7 @@ void CLSTControler::processRxData(uint8_t *rx, uint32_t rxlen) {
* 1. findHeader
* 2. processRx
*
- * ָ:
+ * 测试指令:
* 5A 5A 02 00 01 00 01 00 01 00 01 00 00 00 06 A5 A5
*
*/
@@ -177,8 +181,6 @@ zaf_error_code_t CLSTControler::sendPacket(zaf_packet_header_t *packet, uint32_t
return kaf_ec_overtime;
}
-#define PACKET_LEN(__packet) (sizeof(zaf_packet_header_t) + (__packet->ndata) * sizeof(uint32_t) + 1 /*checksum*/ + 2 /*tail*/)
-
zaf_error_code_t CLSTControler::reg_write(uint32_t regadd, uint32_t regvalue, uint32_t ®backvalue, int32_t overtime_ms) { //
lock_guard lock(m_tx_lock);
@@ -212,6 +214,12 @@ zaf_error_code_t CLSTControler::reg_write(uint32_t regadd, uint32_t regvalue, ui
regbackvalue = rxpacket->data[1];
return kaf_ec_success;
}
+uint32_t CLSTControler::reg_read_v2(uint32_t regadd) {
+ uint32_t regvalue = 0;
+ reg_read(regadd, regvalue, 30);
+ return regvalue;
+}
+
zaf_error_code_t CLSTControler::reg_read(uint32_t regadd, uint32_t ®value, int32_t overtime_ms) {
lock_guard lock(m_tx_lock);
@@ -279,7 +287,7 @@ zaf_error_code_t CLSTControler::factoryReset() {
txdata[txpacklen - 2] = PACKET_TAIL & 0xFF;
txdata[txpacklen - 1] = (PACKET_TAIL >> 8) & 0xFF;
- zaf_error_code_t ecode = sendPacket(txpacket, txpacklen, 100);
+ zaf_error_code_t ecode = sendPacket(txpacket, txpacklen, 1500);
if (ecode != kaf_ec_success) return ecode;
return kaf_ec_success;
@@ -335,8 +343,300 @@ zaf_error_code_t CLSTControler::storageConfigs() {
txdata[txpacklen - 2] = PACKET_TAIL & 0xFF;
txdata[txpacklen - 1] = (PACKET_TAIL >> 8) & 0xFF;
- zaf_error_code_t ecode = sendPacket(txpacket, txpacklen, 100);
+ zaf_error_code_t ecode = sendPacket(txpacket, txpacklen, 1500);
if (ecode != kaf_ec_success) return ecode;
return kaf_ec_success;
}
+
+zaf_error_code_t CLSTControler::readFreq(uint32_t reg, float &freqfloat) {
+ uint32_t freq_cnt = 0;
+ DO_CMD(reg_read(reg, freq_cnt, 30));
+ if (freq_cnt == 0) {
+ freqfloat = 0;
+ }
+
+ if (freq_cnt != 0) {
+ uint32_t freq_1000x = ((1.0 / (freq_cnt * 1.0 / (100 * 1000 * 1000))) * 1000 + 0.5); //+0.5???c++ ??????????????????
+ // ZLOGI(TAG, "freq_10x %f", freq_10x);
+ freqfloat = freq_1000x / 1000.0;
+ } else {
+ freqfloat = 0;
+ }
+ if (freqfloat < 0.05) {
+ freqfloat = 0;
+ }
+
+ return kaf_ec_success;
+}
+
+/*******************************************************************************
+ * ???? *
+ *******************************************************************************/
+zaf_error_code_t CLSTControler::InterClk_setFreq(float freq) { //
+ DO_CMD(InterClk_stop());
+ ZLOGI(TAG, "InterClk_setFreq %f", freq);
+ double T = 1.0 / freq;
+ double T_ns = T * 1000 * 1000 * 1000;
+ double cnt = T_ns / 10 + 0.5; // 100MHZ <=> 10ns
+
+ uint32_t cnt_u32 = uint32_t(cnt);
+ ZLOGI(TAG, "InterClk_setFreq %f %d", freq, cnt_u32);
+
+ return reg_write(kreg_internal_clk_freq_cnt, cnt_u32);
+}
+zaf_error_code_t CLSTControler::InterClk_setPluseCnt(uint32_t cnt) { //
+ return reg_write(kreg_internal_clk_pluse_cnt, cnt);
+}
+zaf_error_code_t CLSTControler::InterClk_setSeqCtrlPluseCntMax(uint32_t cnt) { //
+ if (cnt == 0) return kaf_ec_param_error;
+ return reg_write(kreg_internal_clk_tri_sequential_control_pluse_cnt_max, cnt - 1);
+}
+
+zaf_error_code_t CLSTControler::InterClk_getFreq(float &freq) { //
+ return readFreq(kreg_internal_clk_freq_cnt, freq);
+}
+zaf_error_code_t CLSTControler::InterClk_getPluseCnt(uint32_t &cnt) { //
+ return reg_read(kreg_internal_clk_pluse_cnt, cnt);
+}
+zaf_error_code_t CLSTControler::InterClk_getSeqCtrlPluseCntMax(uint32_t &cnt) { //
+ DO_CMD(reg_read(kreg_internal_clk_tri_sequential_control_pluse_cnt_max, cnt));
+ cnt++;
+ return kaf_ec_success;
+}
+zaf_error_code_t CLSTControler::InterClk_readTriOutSignalFreq(float &freq) { //
+ return readFreq(kreg_internal_clk_tri_out_signal_freq, freq);
+}
+zaf_error_code_t CLSTControler::InterClk_trigger() { //
+ return reg_write(kreg_internal_clk_ctrl, 1);
+}
+zaf_error_code_t CLSTControler::InterClk_stop() { //
+ return reg_write(kreg_internal_clk_ctrl, 0);
+}
+/*******************************************************************************
+ * TTL????? *
+ *******************************************************************************/
+// kreg_trigger_in1_module
+// kreg_trigger_in1_src_slect
+// kreg_trigger_in1_fileter_coefficient
+// kreg_trigger_in1_freq_detect_bias
+// kreg_trigger_in1_mode
+// kreg_trigger_in1_trigger_mode_trigger_edge
+// kreg_trigger_in1_trigger_mode_freq_division
+// kreg_trigger_in1_trigger_mode_freq_multiplication
+// kreg_trigger_in1_sequential_control_pluse_cnt_max
+// kreg_trigger_in1_in_signal_freq
+// kreg_trigger_in1_out_signal_freq
+
+zaf_error_code_t CLSTControler::TriInX_setSrcSelect(int32_t index, ExtTriggerSrcType src) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ return reg_write(kreg_trigger_in1_src_slect + (index - 1) * 32, src.getVal());
+}
+zaf_error_code_t CLSTControler::TriInX_setFileterCoefficient(int32_t index, uint32_t coefficient) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ return reg_write(kreg_trigger_in1_fileter_coefficient + (index - 1) * 32, coefficient);
+}
+zaf_error_code_t CLSTControler::TriInX_setFreqDetectBias(int32_t index, uint32_t bias) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ return reg_write(kreg_trigger_in1_freq_detect_bias + (index - 1) * 32, bias);
+}
+zaf_error_code_t CLSTControler::TriInX_setMode(int32_t index, SigProcessMode mode) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ return reg_write(kreg_trigger_in1_mode + (index - 1) * 32, mode.getVal());
+}
+zaf_error_code_t CLSTControler::TriInX_setTriggerModeTriggerEdge(int32_t index, TriggerEdge edge) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ return reg_write(kreg_trigger_in1_trigger_mode_trigger_edge + (index - 1) * 32, edge);
+}
+zaf_error_code_t CLSTControler::TriInX_setTriggerModeFreqDivision(int32_t index, uint32_t division) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ return reg_write(kreg_trigger_in1_trigger_mode_freq_division + (index - 1) * 32, division);
+}
+zaf_error_code_t CLSTControler::TriInX_setTriggerModeFreqMultiplication(int32_t index, uint32_t multiplication) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ return reg_write(kreg_trigger_in1_trigger_mode_freq_multiplication + (index - 1) * 32, multiplication);
+}
+zaf_error_code_t CLSTControler::TriInX_setSequentialControlPluseCntMax(int32_t index, uint32_t cnt) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ return reg_write(kreg_trigger_in1_sequential_control_pluse_cnt_max + (index - 1) * 32, cnt);
+}
+
+zaf_error_code_t CLSTControler::TriInX_getSrcSelect(int32_t index, ExtTriggerSrcType &src) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ uint32_t val;
+ DO_CMD(reg_read(kreg_trigger_in1_src_slect + (index - 1) * 32, val));
+ src = ExtTriggerSrcType(val);
+ return kaf_ec_success;
+}
+zaf_error_code_t CLSTControler::TriInX_getFileterCoefficient(int32_t index, uint32_t &coefficient) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ return reg_read(kreg_trigger_in1_fileter_coefficient + (index - 1) * 32, coefficient);
+}
+zaf_error_code_t CLSTControler::TriInX_getFreqDetectBias(int32_t index, uint32_t &bias) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ return reg_read(kreg_trigger_in1_freq_detect_bias + (index - 1) * 32, bias);
+}
+zaf_error_code_t CLSTControler::TriInX_getMode(int32_t index, SigProcessMode &mode) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ uint32_t reakbak = 0;
+ DO_CMD(reg_read(kreg_trigger_in1_mode + (index - 1) * 32, reakbak));
+ mode = SigProcessMode(reakbak);
+ return kaf_ec_success;
+}
+zaf_error_code_t CLSTControler::TriInX_getTriggerModeTriggerEdge(int32_t index, TriggerEdge &edge) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ uint32_t val;
+ DO_CMD(reg_read(kreg_trigger_in1_trigger_mode_trigger_edge + (index - 1) * 32, val));
+ edge = TriggerEdge(val);
+ return kaf_ec_success;
+}
+zaf_error_code_t CLSTControler::TriInX_getTriggerModeFreqDivision(int32_t index, uint32_t &division) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ return reg_read(kreg_trigger_in1_trigger_mode_freq_division + (index - 1) * 32, division);
+}
+zaf_error_code_t CLSTControler::TriInX_getTriggerModeFreqMultiplication(int32_t index, uint32_t &multiplication) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ return reg_read(kreg_trigger_in1_trigger_mode_freq_multiplication + (index - 1) * 32, multiplication);
+}
+
+zaf_error_code_t CLSTControler::TriInX_readInSignalFreq(int32_t index, float &freq) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ return readFreq(kreg_trigger_in1_in_signal_freq + (index - 1) * 32, freq);
+}
+zaf_error_code_t CLSTControler::TriInX_readOutSignalFreq(int32_t index, float &freq) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ return readFreq(kreg_trigger_in1_out_signal_freq + (index - 1) * 32, freq);
+ return kaf_ec_success;
+}
+
+/*******************************************************************************
+ * ???? *
+ *******************************************************************************/
+
+zaf_error_code_t CLSTControler::LightSrcX_setTriSrc(int32_t index, InternalSig src) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ return reg_write(kreg_light_ctrol_module1_source_select + (index - 1) * 32, src);
+}
+zaf_error_code_t CLSTControler::LightSrcX_setTriggerModePluseWidth(int32_t index, uint32_t width) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ return reg_write(kreg_light_ctrol_module1_trigger_mode_pluse_width + (index - 1) * 32, width * 10); // 0.1us
+}
+zaf_error_code_t CLSTControler::LightSrcX_setTriggerModeFirstPluseOffset(int32_t index, uint32_t offset) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ return reg_write(kreg_light_ctrol_module1_trigger_mode_first_pluse_offset + (index - 1) * 32, offset * 10); // 0.1us
+}
+zaf_error_code_t CLSTControler::LightSrcX_setLightIntensityDuty(int32_t index, float duty) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+
+ uint32_t freqcnt = 0;
+ DO_CMD(reg_read(kreg_light_ctrol_module1_light_driver_freq_cnt + (index - 1) * 32, freqcnt));
+
+ uint32_t cnt = freqcnt * (duty / 100.0);
+ return kaf_ec_success;
+}
+zaf_error_code_t CLSTControler::LightSrcX_setLightDriverFreq(int32_t index, float freq) { //
+
+ double T = 1.0 / freq;
+ double T_ns = T * 1000 * 1000 * 1000;
+ double cnt = T_ns / 10 + 0.5; // 100MHZ <=> 10ns
+
+ uint32_t cnt_u32 = uint32_t(cnt);
+ return reg_write(kreg_light_ctrol_module1_light_driver_freq_cnt + (index - 1) * 32, cnt_u32);
+}
+
+zaf_error_code_t CLSTControler::LightSrcX_getTriSrc(int32_t index, InternalSig &src) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ uint32_t val;
+ DO_CMD(reg_read(kreg_light_ctrol_module1_source_select + (index - 1) * 32, val));
+ src = InternalSig(val);
+ return kaf_ec_success;
+}
+zaf_error_code_t CLSTControler::LightSrcX_getTriggerModePluseWidth(int32_t index, uint32_t &width) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ uint32_t val;
+ DO_CMD(reg_read(kreg_light_ctrol_module1_trigger_mode_pluse_width + (index - 1) * 32, val));
+ width = val / 10;
+ return kaf_ec_success;
+}
+zaf_error_code_t CLSTControler::LightSrcX_getTriggerModeFirstPluseOffset(int32_t index, uint32_t &offset) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ uint32_t val;
+ DO_CMD(reg_read(kreg_light_ctrol_module1_trigger_mode_first_pluse_offset + (index - 1) * 32, val));
+ offset = val / 10;
+ return kaf_ec_success;
+}
+zaf_error_code_t CLSTControler::LightSrcX_getLightIntensityDuty(int32_t index, float &duty) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ uint32_t freqcnt = 0;
+ DO_CMD(reg_read(kreg_light_ctrol_module1_light_driver_freq_cnt + (index - 1) * 32, freqcnt));
+
+ uint32_t cnt = 0;
+ DO_CMD(reg_read(kreg_light_ctrol_module1_light_intensity_cnt + (index - 1) * 32, cnt));
+
+ duty = (cnt * 100.0 / freqcnt);
+ return kaf_ec_success;
+}
+zaf_error_code_t CLSTControler::LightSrcX_getLightDriverFreq(int32_t index, float &freq) { //
+ return readFreq(kreg_light_ctrol_module1_light_driver_freq_cnt + (index - 1) * 32, freq);
+}
+
+zaf_error_code_t CLSTControler::LightSrcX_readLightSrcErrorState(int32_t index, uint32_t &state) { //
+ if (index < 1 || index > 4) return kaf_ec_param_error;
+ return reg_read(kreg_light_ctrol_module1_light_src_error_state + (index - 1) * 32, state);
+}
+zaf_error_code_t CLSTControler::LightSrcX_readInSigFreqDetect(int32_t index, float &freq) { //
+ return readFreq(kreg_light_ctrol_module1_in_sig_freq_detect + (index - 1) * 32, freq);
+}
+zaf_error_code_t CLSTControler::LightSrcX_readOutSigFreqDetect(int32_t index, float &freq) { //
+ return readFreq(kreg_light_ctrol_module1_out_sig_freq_detect + (index - 1) * 32, freq);
+}
+
+/*******************************************************************************
+ * *
+ *******************************************************************************/
+
+zaf_error_code_t CLSTControler::ShutterX_setOutputCtrlMode(int32_t index, SigProcessMode mode) { //
+ return reg_write(kreg_ttl_output_module1_output_ctrl_mode + (index - 1) * 32, mode);
+}
+zaf_error_code_t CLSTControler::ShutterX_setLtEnBind(int32_t index, uint32_t lt_en_sig_index, uint32_t state) { //
+ uint32_t readbak_state = 0;
+ DO_CMD(reg_read(kreg_ttl_output_module1_lt_en_bind + (index - 1) * 32, readbak_state));
+ if (state == 1) {
+ readbak_state |= (1 << lt_en_sig_index);
+ } else {
+ readbak_state &= ~(1 << lt_en_sig_index);
+ }
+ DO_CMD(reg_write(kreg_ttl_output_module1_lt_en_bind + (index - 1) * 32, readbak_state));
+ return kaf_ec_success;
+}
+zaf_error_code_t CLSTControler::ShutterX_setLtEnOffset(int32_t index, uint32_t offset) { //
+ return reg_write(kreg_ttl_output_module1_lt_en_offset + (index - 1) * 32, offset * 10); // 0.1us
+}
+zaf_error_code_t CLSTControler::ShutterX_setInSigSelect(int32_t index, InternalSig sig) { //
+ return reg_write(kreg_ttl_output_module1_in_sig_select + (index - 1) * 32, sig);
+}
+
+zaf_error_code_t CLSTControler::ShutterX_getOutputCtrlMode(int32_t index, SigProcessMode &mode) { //
+ uint32_t val;
+ DO_CMD(reg_read(kreg_ttl_output_module1_output_ctrl_mode + (index - 1) * 32, val));
+ mode = SigProcessMode(val);
+ return kaf_ec_success;
+}
+zaf_error_code_t CLSTControler::ShutterX_getLtEnBind(int32_t index, uint32_t lt_en_sig_index, uint32_t &state) { //
+ uint32_t readbak_state = 0;
+ DO_CMD(reg_read(kreg_ttl_output_module1_lt_en_bind + (index - 1) * 32, readbak_state));
+ state = (readbak_state >> lt_en_sig_index) & 0x01;
+ return kaf_ec_success;
+}
+zaf_error_code_t CLSTControler::ShutterX_getLtEnOffset(int32_t index, uint32_t &offset) { //
+ uint32_t val;
+ DO_CMD(reg_read(kreg_ttl_output_module1_lt_en_offset + (index - 1) * 32, val));
+ offset = val / 10;
+ return kaf_ec_success;
+}
+zaf_error_code_t CLSTControler::ShutterX_getInSigSelect(int32_t index, InternalSig &sig) { //
+ uint32_t val;
+ DO_CMD(reg_read(kreg_ttl_output_module1_in_sig_select + (index - 1) * 32, val));
+ sig = InternalSig(val);
+ return kaf_ec_success;
+}
\ No newline at end of file
diff --git a/src/camera_light_src_timing_controller/clst_controler.hpp b/src/camera_light_src_timing_controller/clst_controler.hpp
index dbd0c1a..21174ec 100644
--- a/src/camera_light_src_timing_controller/clst_controler.hpp
+++ b/src/camera_light_src_timing_controller/clst_controler.hpp
@@ -12,6 +12,7 @@
#include
#include
+#include "clst_controler_sig_type.hpp"
#include "zaf_protocol/zaf_protocol.h"
#define SDK_VERSION 1
@@ -76,15 +77,96 @@ class CLSTControler {
zaf_error_code_t reboot();
zaf_error_code_t storageConfigs();
+ void initDevice();
+
public:
- zaf_error_code_t reg_write(uint32_t regadd, uint32_t regvalue, uint32_t ®backvalue, int32_t overtime_ms);
- zaf_error_code_t reg_read(uint32_t regadd, uint32_t ®value, int32_t overtime_ms);
+ zaf_error_code_t reg_write(uint32_t regadd, uint32_t regvalue, uint32_t ®backvalue, int32_t overtime_ms = 30);
+ zaf_error_code_t reg_write(uint32_t regadd, uint32_t regvalue) {
+ uint32_t regbackvalue;
+ return reg_write(regadd, regvalue, regbackvalue, 30);
+ }
+ zaf_error_code_t reg_read(uint32_t regadd, uint32_t ®value, int32_t overtime_ms = 30);
+ uint32_t reg_read_v2(uint32_t regadd);
public:
+ /*******************************************************************************
+ * 内部触发源 *
+ *******************************************************************************/
+ zaf_error_code_t InterClk_setFreq(float freq);
+ zaf_error_code_t InterClk_setPluseCnt(uint32_t cnt);
+ zaf_error_code_t InterClk_setSeqCtrlPluseCntMax(uint32_t cnt);
+
+ zaf_error_code_t InterClk_getFreq(float &freq);
+ zaf_error_code_t InterClk_getPluseCnt(uint32_t &cnt);
+ zaf_error_code_t InterClk_getSeqCtrlPluseCntMax(uint32_t &cnt);
+
+ zaf_error_code_t InterClk_readTriOutSignalFreq(float &freq);
+
+ zaf_error_code_t InterClk_trigger();
+ zaf_error_code_t InterClk_stop();
+
+ /*******************************************************************************
+ * TTL外部触发源 *
+ *******************************************************************************/
+ zaf_error_code_t TriInX_setSrcSelect(int32_t index, ExtTriggerSrcType src); // 0
+ zaf_error_code_t TriInX_setFileterCoefficient(int32_t index, uint32_t coefficient);
+ zaf_error_code_t TriInX_setFreqDetectBias(int32_t index, uint32_t bias);
+ zaf_error_code_t TriInX_setMode(int32_t index, SigProcessMode mode);
+ zaf_error_code_t TriInX_setTriggerModeTriggerEdge(int32_t index, TriggerEdge edge);
+ zaf_error_code_t TriInX_setTriggerModeFreqDivision(int32_t index, uint32_t division);
+ zaf_error_code_t TriInX_setTriggerModeFreqMultiplication(int32_t index, uint32_t multiplication);
+ zaf_error_code_t TriInX_setSequentialControlPluseCntMax(int32_t index, uint32_t cnt);
+
+ zaf_error_code_t TriInX_getSrcSelect(int32_t index, ExtTriggerSrcType &src);
+ zaf_error_code_t TriInX_getFileterCoefficient(int32_t index, uint32_t &coefficient);
+ zaf_error_code_t TriInX_getFreqDetectBias(int32_t index, uint32_t &bias);
+ zaf_error_code_t TriInX_getMode(int32_t index, SigProcessMode &mode);
+ zaf_error_code_t TriInX_getTriggerModeTriggerEdge(int32_t index, TriggerEdge &edge);
+ zaf_error_code_t TriInX_getTriggerModeFreqDivision(int32_t index, uint32_t &division);
+ zaf_error_code_t TriInX_getTriggerModeFreqMultiplication(int32_t index, uint32_t &multiplication);
+
+ zaf_error_code_t TriInX_readInSignalFreq(int32_t index, float &freq);
+ zaf_error_code_t TriInX_readOutSignalFreq(int32_t index, float &freq);
+
+ /*******************************************************************************
+ * 光源控制 *
+ *******************************************************************************/
+ zaf_error_code_t LightSrcX_setTriSrc(int32_t index, InternalSig src);
+ zaf_error_code_t LightSrcX_setTriggerModePluseWidth(int32_t index, uint32_t width);
+ zaf_error_code_t LightSrcX_setTriggerModeFirstPluseOffset(int32_t index, uint32_t offset);
+ zaf_error_code_t LightSrcX_setLightIntensityDuty(int32_t index, float duty);
+ zaf_error_code_t LightSrcX_setLightDriverFreq(int32_t index, float freq);
+
+ zaf_error_code_t LightSrcX_getTriSrc(int32_t index, InternalSig &src);
+ zaf_error_code_t LightSrcX_getTriggerModePluseWidth(int32_t index, uint32_t &width);
+ zaf_error_code_t LightSrcX_getTriggerModeFirstPluseOffset(int32_t index, uint32_t &offset);
+ zaf_error_code_t LightSrcX_getLightIntensityDuty(int32_t index, float &duty);
+ zaf_error_code_t LightSrcX_getLightDriverFreq(int32_t index, float &freq);
+
+ zaf_error_code_t LightSrcX_readLightSrcErrorState(int32_t index, uint32_t &state);
+ zaf_error_code_t LightSrcX_readInSigFreqDetect(int32_t index, float &freq);
+ zaf_error_code_t LightSrcX_readOutSigFreqDetect(int32_t index, float &freq);
+
+ /*******************************************************************************
+ * 快门控制 *
+ *******************************************************************************/
+
+ zaf_error_code_t ShutterX_setOutputCtrlMode(int32_t index, SigProcessMode mode);
+ zaf_error_code_t ShutterX_setLtEnBind(int32_t index, uint32_t lt_en_sig_index, uint32_t state);
+ zaf_error_code_t ShutterX_setLtEnOffset(int32_t index, uint32_t offset);
+ zaf_error_code_t ShutterX_setInSigSelect(int32_t index, InternalSig sig);
+
+ zaf_error_code_t ShutterX_getOutputCtrlMode(int32_t index, SigProcessMode &mode);
+ zaf_error_code_t ShutterX_getLtEnBind(int32_t index, uint32_t lt_en_sig_index, uint32_t &state);
+ zaf_error_code_t ShutterX_getLtEnOffset(int32_t index, uint32_t &offset);
+ zaf_error_code_t ShutterX_getInSigSelect(int32_t index, InternalSig &sig);
+
+ private:
void processRxData(uint8_t *rx, uint32_t rxlen);
void processRxPacket(zaf_packet_header_t *packet);
zaf_error_code_t sendPacket(zaf_packet_header_t *packet, uint32_t len, uint32_t overtime);
+ zaf_error_code_t readFreq(uint32_t reg, float &freq);
};
} // namespace clst
diff --git a/src/camera_light_src_timing_controller/clst_controler_sig_type.cpp b/src/camera_light_src_timing_controller/clst_controler_sig_type.cpp
new file mode 100644
index 0000000..2d87637
--- /dev/null
+++ b/src/camera_light_src_timing_controller/clst_controler_sig_type.cpp
@@ -0,0 +1,57 @@
+#include "clst_controler_sig_type.hpp"
+
+using namespace iflytop;
+using namespace clst;
+
+map ExtTriggerSrcType::emap = {
+ {"OPTOCOUPLER_INPUT", OPTOCOUPLER_INPUT}, //
+ {"DIFF_INPUT", DIFF_INPUT}, //
+};
+
+map TriggerEdge::emap = {
+ {"RISING", RISING}, //
+ {"FALLING", FALLING}, //
+ {"BOTH", BOTH} //
+};
+
+map SigProcessMode::emap = {
+ {"TRIGGER_MODE", TRIGGER_MODE}, //
+ {"TRANSPARENT_MODE", TRANSPARENT_MODE}, //
+ {"BIND_MODE", BIND_MODE} //
+
+};
+
+map InternalSig::emap = {
+ {"LOGIC0", LOGIC0}, //
+ {"LOGIC1", LOGIC1}, //
+
+ {"INTERNAL_TRIGGER", INTERNAL_TRIGGER}, //
+ {"INTERNAL_TRIGGER_I1", INTERNAL_TRIGGER_I1}, //
+ {"INTERNAL_TRIGGER_I2", INTERNAL_TRIGGER_I2}, //
+ {"INTERNAL_TRIGGER_I3", INTERNAL_TRIGGER_I3}, //
+ {"INTERNAL_TRIGGER_I4", INTERNAL_TRIGGER_I4}, //
+
+ {"EXT_TRIGGER_1", EXT_TRIGGER_1}, //
+ {"EXT_TRIGGER_1_I1", EXT_TRIGGER_1_I1}, //
+ {"EXT_TRIGGER_1_I2", EXT_TRIGGER_1_I2}, //
+ {"EXT_TRIGGER_1_I3", EXT_TRIGGER_1_I3}, //
+ {"EXT_TRIGGER_1_I4", EXT_TRIGGER_1_I4}, //
+
+ {"EXT_TRIGGER_2", EXT_TRIGGER_2}, //
+ {"EXT_TRIGGER_2_I1", EXT_TRIGGER_2_I1}, //
+ {"EXT_TRIGGER_2_I2", EXT_TRIGGER_2_I2}, //
+ {"EXT_TRIGGER_2_I3", EXT_TRIGGER_2_I3}, //
+ {"EXT_TRIGGER_2_I4", EXT_TRIGGER_2_I4}, //
+
+ {"EXT_TRIGGER_3", EXT_TRIGGER_3}, //
+ {"EXT_TRIGGER_3_I1", EXT_TRIGGER_3_I1}, //
+ {"EXT_TRIGGER_3_I2", EXT_TRIGGER_3_I2}, //
+ {"EXT_TRIGGER_3_I3", EXT_TRIGGER_3_I3}, //
+ {"EXT_TRIGGER_3_I4", EXT_TRIGGER_3_I4}, //
+
+ {"EXT_TRIGGER_4", EXT_TRIGGER_4}, //
+ {"EXT_TRIGGER_4_I1", EXT_TRIGGER_4_I1}, //
+ {"EXT_TRIGGER_4_I2", EXT_TRIGGER_4_I2}, //
+ {"EXT_TRIGGER_4_I3", EXT_TRIGGER_4_I3}, //
+ {"EXT_TRIGGER_4_I4", EXT_TRIGGER_4_I4}, //
+};
\ No newline at end of file
diff --git a/src/camera_light_src_timing_controller/clst_controler_sig_type.hpp b/src/camera_light_src_timing_controller/clst_controler_sig_type.hpp
new file mode 100644
index 0000000..1859e5b
--- /dev/null
+++ b/src/camera_light_src_timing_controller/clst_controler_sig_type.hpp
@@ -0,0 +1,169 @@
+#pragma once
+#include
+#include
+#include
+#include
+#include