OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [gui_plugin/] [PeriphWidgets/] [UartEditor.cpp] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 sergeykhbr
#include "UartEditor.h"
2
#include "moc_UartEditor.h"
3
 
4
#include <QtWidgets/QScrollBar>
5
#include <memory>
6
 
7
namespace debugger {
8
 
9
UartEditor::UartEditor(IGui *igui, QWidget *parent) : QPlainTextEdit(parent) {
10
    igui_ = igui;
11
    uart_ = 0;
12
 
13
    clear();
14
    QFont font("Courier");
15
    font.setStyleHint(QFont::Monospace);
16
    font.setPointSize(8);
17
    font.setFixedPitch(true);
18
    setFont(font);
19
 
20
    ensureCursorVisible();
21
 
22
    /** Set background color */
23
    QPalette p = palette();
24
    p.setColor(QPalette::Active, QPalette::Base, Qt::lightGray);
25
    p.setColor(QPalette::Inactive, QPalette::Base, Qt::lightGray);
26
    setPalette(p);
27
 
28
    /** */
29
    RISCV_mutex_init(&mutexStr_);
30
    prevSymb_ = 0;
31
 
32
    connect(this, SIGNAL(signalNewData()), this, SLOT(slotUpdateByData()));
33
    const AttributeType *cfg = igui_->getpConfig();
34
    const AttributeType &serial_name = (*cfg)["Serial"];
35
    if (serial_name.is_string()) {
36
        uart_ = static_cast<ISerial *>
37
            (RISCV_get_service_iface(serial_name.to_string(), IFACE_SERIAL));
38
        if (uart_) {
39
            uart_->registerRawListener(static_cast<IRawListener *>(this));
40
        }
41
    }
42
}
43
 
44
UartEditor::~UartEditor() {
45
    if (uart_) {
46
        uart_->unregisterRawListener(static_cast<IRawListener *>(this));
47
    }
48
    RISCV_mutex_destroy(&mutexStr_);
49
}
50
 
51
void UartEditor::keyPressEvent(QKeyEvent *e) {
52
    char symb = keyevent2char(e);
53
    if (uart_) {
54
        uart_->writeData(&symb, 1);
55
    }
56
}
57
 
58
void UartEditor::closeEvent(QCloseEvent *event_) {
59
    AttributeType tmp;
60
    emit signalClose(this, tmp);
61
    event_->accept();
62
}
63
 
64
void UartEditor::updateData(const char *buf, int buflen) {
65
    RISCV_mutex_lock(&mutexStr_);
66
    while (buflen--) {
67
        // Zephyr kernel scan symbol '\n' and after it adds the extra
68
        // symbol '\r', which I'm removing here.
69
        if (prevSymb_ == '\n' && buf[0] == '\r') {
70
            buf++;
71
            continue;
72
        }
73
        strOutput_ += buf[0];
74
        prevSymb_ = buf[0];
75
        buf++;
76
    }
77
    RISCV_mutex_unlock(&mutexStr_);
78
 
79
    emit signalNewData();
80
}
81
 
82
void UartEditor::slotUpdateByData() {
83
    if (!strOutput_.size()) {
84
        return;
85
    }
86
 
87
    RISCV_mutex_lock(&mutexStr_);
88
    moveCursor(QTextCursor::End);
89
    QTextCursor cursor = textCursor();
90
    cursor.insertText(strOutput_);
91
    strOutput_.clear();
92
    RISCV_mutex_unlock(&mutexStr_);
93
 
94
    verticalScrollBar()->setValue(verticalScrollBar()->maximum());
95
}
96
 
97
char UartEditor::keyevent2char(QKeyEvent *e) {
98
    wchar_t w1[8];
99
    char s1[8];
100
    int w1_sz = e->text().toWCharArray(w1);
101
    wcstombs(s1, w1, w1_sz);
102
    return s1[0];
103
}
104
 
105
}  // namespace debugger

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.