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 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 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
    AttributeType serial_name;
34
    igui_->getWidgetsAttribute("Serial", &serial_name);
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::slotPostInit(AttributeType *cfg) {
83
    if (uart_) {
84
        /* To avoid double registration */
85
        return;
86
    }
87
    uart_ = static_cast<ISerial *>
88
        (RISCV_get_service_iface((*cfg)["Serial"].to_string(), IFACE_SERIAL));
89
    if (uart_) {
90
        uart_->registerRawListener(static_cast<IRawListener *>(this));
91
    }
92
}
93
 
94
void UartEditor::slotUpdateByData() {
95
    if (!strOutput_.size()) {
96
        return;
97
    }
98
 
99
    RISCV_mutex_lock(&mutexStr_);
100
    moveCursor(QTextCursor::End);
101
    QTextCursor cursor = textCursor();
102
    cursor.insertText(strOutput_);
103
    strOutput_.clear();
104
    RISCV_mutex_unlock(&mutexStr_);
105
 
106
    verticalScrollBar()->setValue(verticalScrollBar()->maximum());
107
}
108
 
109
char UartEditor::keyevent2char(QKeyEvent *e) {
110
    wchar_t w1[8];
111
    char s1[8];
112
    int w1_sz = e->text().toWCharArray(w1);
113
    wcstombs(s1, w1, w1_sz);
114
    return s1[0];
115
}
116
 
117
}  // namespace debugger

powered by: WebSVN 2.1.0

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