Browse Source

Update i2c/com_linux/ft232_qt

master
Ivan Olenichev 3 years ago
parent
commit
8897ae5ea0
  1. 2
      com_linux/com_linux/com_linux.pro.user
  2. 152
      com_linux/com_linux/lattice_com_reign.cpp
  3. 8
      com_linux/com_linux/lattice_com_reign.h
  4. 42
      com_linux/com_linux/lattice_com_reign.ui
  5. 1
      ft232_qt/ft232_qt.pro
  6. 2
      ft232_qt/ft232_qt.pro.user
  7. 202
      ft232_qt/ft232_reign.cpp
  8. 29
      ft232_qt/ft232_reign.h
  9. 248
      ft232_qt/ft232_reign.ui
  10. 4
      ft232_qt/i2c.c
  11. BIN
      i2c_keyboard/.sconsign.dblite
  12. 15627
      i2c_keyboard/hardware.asc
  13. BIN
      i2c_keyboard/hardware.bin
  14. 4394
      i2c_keyboard/hardware.blif
  15. BIN
      i2c_keyboard/i2c_kbd_alt.bin
  16. 4520
      i2c_keyboard/i2c_kbd_alt.blif
  17. 15878
      i2c_keyboard/i2c_kbd_alt.ex
  18. 15479
      i2c_keyboard/i2c_kbd_alt.txt
  19. 267
      i2c_keyboard/matrix_kbd.v
  20. 15
      i2c_keyboard/ram.v
  21. 236
      i2c_keyboard/top.v
  22. 4
      i2c_keyboard/uart.v

2
com_linux/com_linux/com_linux.pro.user

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.0.2, 2018-10-07T17:13:05. -->
<!-- Written by QtCreator 4.0.2, 2018-11-04T03:28:24. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

152
com_linux/com_linux/lattice_com_reign.cpp

@ -9,8 +9,8 @@ lattice_com_reign::lattice_com_reign(QWidget *parent) :
{
ui->setupUi(this);
log = "";
on_com_reflseh_clicked();
tmr.setInterval(100);
on_com_reflesh_clicked();
tmr.setInterval(200);
tmr.setSingleShot(false);
//tmr.setTimerType();
QObject::connect(&tmr, SIGNAL(timeout()), this, SLOT (com_data_received()));
@ -18,7 +18,8 @@ lattice_com_reign::lattice_com_reign(QWidget *parent) :
QWidget* widgets_unlocked[] = { ui->com_tx };
for (int i = 0; i < sizeof(widgets_unlocked)/sizeof(QWidget*); i++)
widgets_unlocked[i]->setEnabled(com.isOpen());
tmr.start(1);
tmr.start(200);
i2c_data.clear();
}
lattice_com_reign::~lattice_com_reign()
@ -26,15 +27,21 @@ lattice_com_reign::~lattice_com_reign()
delete ui;
}
void lattice_com_reign::on_com_reflseh_clicked()
void lattice_com_reign::on_com_reflesh_clicked()
{
com_list = QSerialPortInfo::availablePorts();
for (int i = 0; i < com_list.length(); i++) {
if (com_list.at(i).portName() == "ttyUSB0")
com_list.removeAt(i);
//toLog ("COM: " + com_list.at(i).portName() + ", DESC: " + com_list.at(i).description());
//if (com_list.at(i).portName() == "ttyUSB0")
// com_list.removeAt(i);
}
QObject::disconnect(ui->com_list, SIGNAL(currentIndexChanged(int)), this, SLOT(on_com_list_currentIndexChanged(int)));
for (int i = ui->com_list->count(); i >=0; i--)
ui->com_list->removeItem(i);
for (int i = 0; i < com_list.length(); i++)
ui->com_list->addItem(com_list.at(i).portName());
QObject::connect(ui->com_list, SIGNAL(currentIndexChanged(int)), this, SLOT(on_com_list_currentIndexChanged(int)));
ui->com_list->setToolTip(com_list.at(ui->com_list->currentIndex()).description());
}
void lattice_com_reign::on_com_list_currentIndexChanged(int index)
@ -87,28 +94,80 @@ void lattice_com_reign::on_com_tx_clicked()
void lattice_com_reign::com_data_received()
{
static int last_com_lines[3] = { 0, 0, 0 };
static int com_lines[3];
ui->time->setText(QTime::currentTime().toString("HH:mm:ss"));
if (com.isOpen() == false)
return;
QByteArray bytes_read = com.readAll();
QString i2c_data_str = "";
QString com_outs_now = "CTS ";/*
if (com.isRequestToSend()) com_outs_now = com_outs_now + "1, DTR ";
else com_outs_now = com_outs_now + "0, DTR ";
if (com.isDataTerminalReady()) com_outs_now = com_outs_now + "1";
else com_outs_now = com_outs_now + "0";*/
int pinout = com.pinoutSignals();
#if 0
if (pinout & (QSerialPort::ClearToSendSignal)) com_outs_now = com_outs_now + "1, DSR ";
else com_outs_now = com_outs_now + "0, DSR ";
else com_outs_now = com_outs_now + "0, DSR ";
if (pinout & (QSerialPort::DataSetReadySignal)) com_outs_now = com_outs_now + "1, DCD ";
else com_outs_now = com_outs_now + "0, DCD ";
else com_outs_now = com_outs_now + "0, DCD ";
if (pinout & (QSerialPort::DataCarrierDetectSignal)) com_outs_now = com_outs_now + "1";
else com_outs_now = com_outs_now + "0";
if (com_outs_now != com_outs) {
else com_outs_now = com_outs_now + "0";
#else
com_lines[0] = 0; com_lines[1] = 0; com_lines[2] = 0;
if (pinout & (QSerialPort::ClearToSendSignal)) com_lines[0] = 1;
if (pinout & (QSerialPort::DataSetReadySignal)) com_lines[1] = 1;
if (pinout & (QSerialPort::DataCarrierDetectSignal)) com_lines[2] = 1;
//if ()
#endif
/*if (com_outs_now != com_outs) {
com_outs = com_outs_now;
toLog(com_outs);
}*/
if (bytes_read.length() == 0) {
if (i2c_data.length() != 0) {
if (i2c_data.length() >= 3) {
if (((i2c_data.at(2) == 0x0A) && (i2c_data.at(3) == 0)) || ((i2c_data.at(2) == 0x1E) && (i2c_data.at(3) == 0)) \
|| ((i2c_data.at(2) == 0x05) && (i2c_data.at(3) == 1)) || ((i2c_data.at(2) == 0) && (i2c_data.at(3) == 0)))
i2c_data_str = "I2C DATA TO HOST: ";
else
i2c_data_str = "I2C DATA FROM HOST: ";
}
else
i2c_data_str = "I2C DATA FROM HOST: ";
for (int i = 0; i < i2c_data.length(); i++)
i2c_data_str = i2c_data_str + QString::number(i2c_data.at(i) & 0xFF, 16) + " ";
i2c_data.clear();
toLog (i2c_data_str);
}
ui->read_progress->setText("");
return;
}
for (int i = 0; i < bytes_read.length(); i++) {
//toLog ("RECEIVED BYTE " + QString::number(((int)(bytes_read.at(i)) & 0xFF), 16));// + ", PINOUT " + QString::number(pinout, 16));
i2c_data.push_back(bytes_read.at(i));
if (i2c_data.length() > 2) {
if (((i2c_data.at(i2c_data.length() - 1) & 0xFF) == 0xFF) && ((i2c_data.at(i2c_data.length() - 2) & 0xFF) == 0xFF)) {
if (i2c_data.length() >= 3) {
if (((i2c_data.at(2) == 0x0A) && (i2c_data.at(3) == 0)) || ((i2c_data.at(2) == 0x1E) && (i2c_data.at(3) == 0)) \
|| ((i2c_data.at(2) == 0x05) && (i2c_data.at(3) == 1)) || ((i2c_data.at(2) == 0) && (i2c_data.at(3) == 0)))
i2c_data_str = "I2C DATA TO HOST: ";
else
i2c_data_str = "I2C DATA FROM HOST: ";
}
else
i2c_data_str = "I2C DATA FROM HOST: ";
for (int i = 0; i < (i2c_data.length() - 2); i++)
i2c_data_str = i2c_data_str + QString::number(i2c_data.at(i) & 0xFF, 16) + " ";
i2c_data.clear();
i2c_data.push_back(0xFF); i2c_data.push_back(0xFF);
toLog (i2c_data_str);
}
//qDebug ("I2C DATA LEN %d, LAST DATA %d %d", i2c_data.length(), i2c_data.at(i2c_data.length() - 1), i2c_data.at(i2c_data.length() - 2));
}
ui->read_progress->setText("Reading " + QString::number(i2c_data.length()));
}
for (int i = 0; i < bytes_read.length(); i++)
toLog ("RECEIVED BYTE " + QString::number(((int)(bytes_read.at(i)) & 0xFF), 16) + ", PINOUT " + QString::number(pinout, 16));
}
void lattice_com_reign::on_clear_log_clicked()
@ -116,3 +175,72 @@ void lattice_com_reign::on_clear_log_clicked()
log = "";
ui->log->setText("LOG\n\n" + log);
}
#if 0
/*
* Scan a report descriptor before the device is added to the bus.
* Sets device groups and other properties that determine what driver
* to load.
*/
int lattice_com_reign::hid_scan_report(__u8* stt, __u8* stp)//(struct hid_device *hid)
{
struct hid_parser parser;//struct hid_parser *parser;
struct hid_item item;
__u8 *start = stt;//hid->dev_rdesc;
__u8 *end = stp;//start + hid->dev_rsize;
static int (*dispatch_type[])(struct hid_parser *parser,
struct hid_item *item) = {
hid_scan_main,
hid_parser_global,
hid_parser_local,
hid_parser_reserved
};
//parser = vzalloc(sizeof(struct hid_parser));
//if (!parser)
// return -ENOMEM;
parser.device = hid;
//hid->group = HID_GROUP_GENERIC;
/*
* The parsing is simpler than the one in hid_open_report() as we should
* be robust against hid errors. Those errors will be raised by
* hid_open_report() anyway.
*/
while ((start = fetch_item(start, end, &item)) != NULL)
dispatch_type[item.type](&parser, &item);
/*
* Handle special flags set during scanning.
*/
if ((parser.scan_flags & HID_SCAN_FLAG_MT_WIN_8) &&
(hid->group == HID_GROUP_MULTITOUCH))
hid->group = HID_GROUP_MULTITOUCH_WIN_8;
/*
* Vendor specific handlings
*/
#if 0
switch (hid->vendor) {
case USB_VENDOR_ID_WACOM:
hid->group = HID_GROUP_WACOM;
break;
case USB_VENDOR_ID_SYNAPTICS:
if (hid->group == HID_GROUP_GENERIC)
if ((parser->scan_flags & HID_SCAN_FLAG_VENDOR_SPECIFIC)
&& (parser->scan_flags & HID_SCAN_FLAG_GD_POINTER))
/*
* hid-rmi should take care of them,
* not hid-generic
*/
hid->group = HID_GROUP_RMI;
break;
}
#endif
//kfree(parser->collection_stack);
//vfree(parser);
return 0;
}
#endif

8
com_linux/com_linux/lattice_com_reign.h

@ -8,6 +8,8 @@
#include <qtimer.h>
#define __u8 unsigned char
namespace Ui {
class lattice_com_reign;
}
@ -23,7 +25,7 @@ public:
private slots:
void toLog (QString str);
void on_com_reflseh_clicked();
void on_com_reflesh_clicked();
void on_com_list_currentIndexChanged(int index);
@ -33,6 +35,8 @@ private slots:
void on_clear_log_clicked();
//int hid_scan_report(__u8* stt, __u8* stp);//struct hid_device *hid);
protected slots:
void com_data_received();
@ -45,6 +49,8 @@ private:
QString com_outs;
QTimer tmr;
QVector <char> i2c_data;
};
#endif // LATTICE_COM_REIGN_H

42
com_linux/com_linux/lattice_com_reign.ui

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>588</width>
<width>915</width>
<height>492</height>
</rect>
</property>
@ -125,13 +125,51 @@
<string>CLR</string>
</property>
</widget>
<widget class="QLabel" name="read_progress">
<property name="geometry">
<rect>
<x>150</x>
<y>56</y>
<width>131</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Reading...</string>
</property>
</widget>
<widget class="QGraphicsView" name="graphicsView">
<property name="geometry">
<rect>
<x>620</x>
<y>130</y>
<width>256</width>
<height>192</height>
</rect>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="backgroundBrush">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>49</green>
<blue>199</blue>
</color>
</brush>
</property>
<property name="interactive">
<bool>true</bool>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>588</width>
<width>915</width>
<height>25</height>
</rect>
</property>

1
ft232_qt/ft232_qt.pro

@ -5,6 +5,7 @@
#-------------------------------------------------
QT += core gui
QT += serialport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

2
ft232_qt/ft232_qt.pro.user

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.0.2, 2018-11-01T21:22:44. -->
<!-- Written by QtCreator 4.0.2, 2018-11-18T03:29:48. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

202
ft232_qt/ft232_reign.cpp

@ -12,7 +12,8 @@ QString last_write_data = "00";
QString hex_values[16] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" };
int tmr_on = 0;
bool tmr_on = false;
bool out = false;
ft232_reign::ft232_reign(QWidget *parent) :
QMainWindow(parent),
@ -25,6 +26,10 @@ ft232_reign::ft232_reign(QWidget *parent) :
tmr->setSingleShot(false);
tmr->start();
QObject::connect(tmr, SIGNAL(timeout ()), this, SLOT(tmr_fxn()));
on_reflesh_com_clicked();
on_com_int_line_currentIndexChanged(ui->com_int_line->currentIndex());
i2c_hid_descr[10] = 2;
i2c_hid_descr[11] = 0;
}
ft232_reign::~ft232_reign()
@ -39,8 +44,8 @@ void ft232_reign::on_pushButton_clicked()
//char desc[1024], serial[1024];
//i2c_open_index_port (0, desc, serial);
//if (bitbang_open (0, 1, 0) == 0)
// tmr_on = 1;
if (bitbang_open (0, 1, 255) == 0)
tmr_on = 1;
}
void ft232_reign::on_pushButton_2_clicked()
@ -50,15 +55,6 @@ void ft232_reign::on_pushButton_2_clicked()
//tmr_on = 0;
}
void ft232_reign::tmr_fxn()
{
//if (tmr_on == 0)
// return;
//char rd[10];
//bitbang_read(rd);
//qDebug ("Reading from FTDI bitbang: %x, %x, %x, %x", rd[0], rd[1], rd[2], rd[3]);
}
void ft232_reign::toLog(QString info)
{
log = QTime::currentTime().toString("HH:mm:ss") + "\t" + info + "\n" + log;
@ -214,3 +210,185 @@ void ft232_reign::on_read_input_report_cmd_clicked()
toLog ("------------------------------------------");
}
void ft232_reign::on_reflesh_com_clicked()
{
com_list = QSerialPortInfo::availablePorts();
//QObject::disconnect(ui->com_list, SIGNAL(currentIndexChanged(int)), this, SLOT(on_com_list_currentIndexChanged(int)));
for (int i = ui->com_list->count(); i >=0; i--)
ui->com_list->removeItem(i);
for (int i = 0; i < com_list.length(); i++)
ui->com_list->addItem(com_list.at(i).portName());
//if (com_list.length() > 0) {
//QObject::connect(ui->com_list, SIGNAL(currentIndexChanged(int)), this, SLOT(on_com_list_currentIndexChanged(int)));
if (ui->com_list->currentIndex() >= 0)
ui->com_list->setToolTip(com_list.at(ui->com_list->currentIndex()).description());
//}
}
void ft232_reign::on_com_list_currentIndexChanged(int index)
{
if (index >= 0)
ui->com_list->setToolTip(com_list.at(index).description());
}
void ft232_reign::on_com_connect_clicked()
{
QWidget* widgets_locked[] = { ui->com_list, ui->reflesh_com };
QWidget* widgets_unlocked[] = { ui->com_int_line, ui->en_int_evt, ui->label_int };
if (ui->com_connect->text() == "Connect") {
com.setPortName(com_list.at(ui->com_list->currentIndex()).portName());
if (com.open(QSerialPort::ReadWrite)) {
com.setParity(QSerialPort::NoParity);
com.setDataBits(QSerialPort::Data8);
com.setStopBits(QSerialPort::OneStop);
com.setFlowControl(QSerialPort::NoFlowControl);
com.setBaudRate(921600);
ui->com_connect->setText("Disconnect");
toLog ("COM " + com.portName() + " OPENED OK");
tmr_on = true;
}
else
toLog ("COM " + com.portName() + " OPEN ERROR");
}
else {
com.close();
toLog ("COM " + com.portName() + " CLOSED");
ui->com_connect->setText("Connect");
tmr_on = false;
}
for (int i = 0; i < sizeof(widgets_locked)/sizeof(QWidget*); i++)
widgets_locked[i]->setEnabled(!com.isOpen());
for (int i = 0; i < sizeof(widgets_unlocked)/sizeof(QWidget*); i++)
widgets_unlocked[i]->setEnabled(com.isOpen());
}
void ft232_reign::on_com_int_line_currentIndexChanged(int index)
{
switch (index) {
case 0: int_mask = QSerialPort::DataSetReadySignal; break;
case 1: int_mask = QSerialPort::DataCarrierDetectSignal; break;
case 2: int_mask = QSerialPort::ClearToSendSignal; break; }
qDebug ("COM INT MASK %u", int_mask);
}
void ft232_reign::tmr_fxn()
{
if (tmr_on == false)
return;
int inputs = com.pinoutSignals();
if (((inputs & int_mask) != 0) && (out == false)) {
out = true;
ui->label_int->setText("INT ON (GND)");
}
else if (((inputs & int_mask) == 0) && (out == true)) {
out = false;
ui->label_int->setText("INT OFF (+3.3)");
}
if (out == true) {
if (ui->en_int_evt->isChecked()) {
on_read_input_report_int_clicked();
if ((data[0] == 0) && (data[1] == 0)) {
on_read_i2c_hid_desc_clicked();
on_read_hid_report_desc_clicked();
on_write_output_report_reg_clicked();
}
}
}
/*if (out != ui->int_line->isChecked()) {
if (out)
//ui->int_line->setCheckable(true);
//ui->int_line->setChecked(out);
//ui->int_line->setCheckable(false);
}*/
//qDebug ("COM LINES STATE: %u", inputs);
/*if (tmr_on == 0)
return;
char rd[10];
bitbang_read(rd);
qDebug ("Reading from FTDI bitbang: %x, %x, %x, %x", rd[0], rd[1], rd[2], rd[3]);*/
}
void ft232_reign::on_write_output_report_reg_clicked()
{
//if ((I2C_INPUT_DATA[0] == 5) && (I2C_INPUT_DATA[1] == 0)
// && (I2C_INPUT_DATA[2] == 32) && (I2C_INPUT_DATA[3] == 3)
// && (I2C_INPUT_DATA[4] == 6) && (I2C_INPUT_DATA[5] == 0)
// && (I2C_INPUT_DATA[6] == 1) && (I2C_INPUT_DATA[7] == 0)) begin
char data_led = 0;
if (ui->NUM->isChecked()) data_led = data_led | 1;
if (ui->CAPS->isChecked()) data_led = data_led | 2;
if (ui->SCROOL->isChecked()) data_led = data_led | 4;
toLog ("WRITING OUTPUT REPORT (TO OUTPUT ADRESS)");
ui->i2c_length->setValue(5);
QString reg = hex_values[(i2c_hid_descr[12]>>4) & 0xF] + hex_values[(i2c_hid_descr[12]>>0) & 0xF] + " " + \
hex_values[(i2c_hid_descr[13]>>4) & 0xF] + hex_values[(i2c_hid_descr[13]>>0) & 0xF];
reg = reg + " 01 00 "; // DATA LEN - 1
reg = reg + hex_values[(data_led>>4) & 0xF] + hex_values[(data_led>>0) & 0xF];
ui->i2c_write_data->setText(reg);
on_i2c_write_clicked();
toLog ("------------------------------------------");
}
void ft232_reign::on_NUM_toggled(bool checked)
{
on_write_output_report_reg_clicked();
}
void ft232_reign::on_CAPS_clicked()
{
on_write_output_report_reg_clicked();
}
void ft232_reign::on_SCROOL_clicked()
{
on_write_output_report_reg_clicked();
}
void ft232_reign::on_cmd_reset_clicked()
{
//if ((I2C_INPUT_DATA[0] == 5) && (I2C_INPUT_DATA[1] == 0) && (I2C_INPUT_DATA[2] == 0) && (I2C_INPUT_DATA[3] == 1))
toLog ("WRITING RESET COMMAND");
ui->i2c_length->setValue(4);
QString reg = hex_values[(i2c_hid_descr[16]>>4) & 0xF] + hex_values[(i2c_hid_descr[16]>>0) & 0xF] + " " + \
hex_values[(i2c_hid_descr[17]>>4) & 0xF] + hex_values[(i2c_hid_descr[17]>>0) & 0xF];
reg = reg + " 00 01"; // COMMAND OPCODE - 1 (RESET), OTHER FIELDS - ZERO
ui->i2c_write_data->setText(reg);
on_i2c_write_clicked();
toLog ("------------------------------------------");
}
void ft232_reign::on_write_output_report_cmd_clicked()
{
char data_led = 0;
if (ui->NUM->isChecked()) data_led = data_led | 1;
if (ui->CAPS->isChecked()) data_led = data_led | 2;
if (ui->SCROOL->isChecked()) data_led = data_led | 4;
toLog ("WRITING OUTPUT REPORT (COMMAND)");
ui->i2c_length->setValue(9);
QString reg = hex_values[(i2c_hid_descr[16]>>4) & 0xF] + hex_values[(i2c_hid_descr[16]>>0) & 0xF] + " " + \
hex_values[(i2c_hid_descr[17]>>4) & 0xF] + hex_values[(i2c_hid_descr[17]>>0) & 0xF];
reg = reg + " 20 03 "; // DATA LEN - 1
reg = reg + hex_values[(i2c_hid_descr[18]>>4) & 0xF] + hex_values[(i2c_hid_descr[18]>>0) & 0xF] + " " + \
hex_values[(i2c_hid_descr[19]>>4) & 0xF] + hex_values[(i2c_hid_descr[19]>>0) & 0xF];
reg = reg + " 01 00 ";
reg = reg + hex_values[(data_led>>4) & 0xF] + hex_values[(data_led>>0) & 0xF];
ui->i2c_write_data->setText(reg);
on_i2c_write_clicked();
toLog ("------------------------------------------");
}
void ft232_reign::on_read_input_report_reg_clicked()
{
toLog ("READING INPUT REPORT (ADRESS)");
ui->i2c_length->setValue(2);
QString reg = hex_values[(i2c_hid_descr[8]>>4) & 0xF] + hex_values[(i2c_hid_descr[8]>>0) & 0xF] + " " + \
hex_values[(i2c_hid_descr[9]>>4) & 0xF] + hex_values[(i2c_hid_descr[9]>>0) & 0xF];
ui->i2c_write_data->setText(reg);
on_i2c_write_clicked();
QThread::msleep(100);
ui->i2c_length->setValue((i2c_hid_descr[10] & 0xFF) + (i2c_hid_descr[11] & 0xFF) * 256);
on_i2c_read_clicked();
toLog ("------------------------------------------");
}

29
ft232_qt/ft232_reign.h

@ -4,6 +4,9 @@
#include <QMainWindow>
#include <qtimer.h>
#include <QtSerialPort/qserialport.h>
#include <QtSerialPort/qserialportinfo.h>
namespace Ui {
class ft232_reign;
}
@ -46,9 +49,35 @@ private slots:
void on_read_input_report_cmd_clicked();
void on_reflesh_com_clicked();
void on_com_list_currentIndexChanged(int index);
void on_com_connect_clicked();
void on_com_int_line_currentIndexChanged(int index);
void on_write_output_report_reg_clicked();
void on_NUM_toggled(bool checked);
void on_CAPS_clicked();
void on_SCROOL_clicked();
void on_cmd_reset_clicked();
void on_write_output_report_cmd_clicked();
void on_read_input_report_reg_clicked();
private:
Ui::ft232_reign *ui;
QList<QSerialPortInfo> com_list;
QSerialPort com;
int int_mask;
QString log;
int res;
unsigned char data[1001];

248
ft232_qt/ft232_reign.ui

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>627</width>
<height>671</height>
<width>795</width>
<height>598</height>
</rect>
</property>
<property name="windowTitle">
@ -111,9 +111,9 @@
<property name="geometry">
<rect>
<x>10</x>
<y>210</y>
<width>601</width>
<height>381</height>
<y>250</y>
<width>771</width>
<height>281</height>
</rect>
</property>
</widget>
@ -227,7 +227,7 @@
<property name="geometry">
<rect>
<x>380</x>
<y>130</y>
<y>160</y>
<width>231</width>
<height>27</height>
</rect>
@ -240,7 +240,7 @@
<property name="geometry">
<rect>
<x>380</x>
<y>160</y>
<y>190</y>
<width>231</width>
<height>27</height>
</rect>
@ -249,13 +249,245 @@
<string>Read Input Report (Command)</string>
</property>
</widget>
<widget class="QComboBox" name="com_list">
<property name="geometry">
<rect>
<x>650</x>
<y>0</y>
<width>85</width>
<height>27</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="reflesh_com">
<property name="geometry">
<rect>
<x>750</x>
<y>0</y>
<width>31</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>R</string>
</property>
</widget>
<widget class="QPushButton" name="com_connect">
<property name="geometry">
<rect>
<x>650</x>
<y>50</y>
<width>131</width>
<height>27</height>
</rect>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This com must be in port B (port A is for I2C)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Connect</string>
</property>
</widget>
<widget class="QComboBox" name="com_int_line">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>650</x>
<y>80</y>
<width>131</width>
<height>27</height>
</rect>
</property>
<item>
<property name="text">
<string>DSR (44-BD5)</string>
</property>
</item>
<item>
<property name="text">
<string>DCD (45-BD6)</string>
</property>
</item>
<item>
<property name="text">
<string>CTS (41-BD3)</string>
</property>
</item>
</widget>
<widget class="QPushButton" name="read_input_report_reg">
<property name="geometry">
<rect>
<x>380</x>
<y>220</y>
<width>231</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Read Input Report (From reg)</string>
</property>
</widget>
<widget class="QCheckBox" name="NUM">
<property name="geometry">
<rect>
<x>110</x>
<y>170</y>
<width>71</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>NUM</string>
</property>
</widget>
<widget class="QCheckBox" name="CAPS">
<property name="geometry">
<rect>
<x>190</x>
<y>170</y>
<width>71</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>CAPS</string>
</property>
</widget>
<widget class="QCheckBox" name="SCROOL">
<property name="geometry">
<rect>
<x>270</x>
<y>170</y>
<width>91</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>SCROOL</string>
</property>
</widget>
<widget class="QPushButton" name="write_output_report_cmd">
<property name="geometry">
<rect>
<x>110</x>
<y>220</y>
<width>251</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Write Output Report (Command)</string>
</property>
</widget>
<widget class="QPushButton" name="write_output_report_reg">
<property name="geometry">
<rect>
<x>110</x>
<y>190</y>
<width>251</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Write Output Report (To reg)</string>
</property>
</widget>
<widget class="QPushButton" name="cmd_reset">
<property name="geometry">
<rect>
<x>10</x>
<y>160</y>
<width>81</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Reset</string>
</property>
</widget>
<widget class="QPushButton" name="cmd_sleep">
<property name="geometry">
<rect>
<x>10</x>
<y>190</y>
<width>81</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Pwr Sleep</string>
</property>
</widget>
<widget class="QPushButton" name="cmd_pwr_on">
<property name="geometry">
<rect>
<x>10</x>
<y>220</y>
<width>81</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Pwr On</string>
</property>
</widget>
<widget class="QCheckBox" name="en_int_evt">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>650</x>
<y>110</y>
<width>131</width>
<height>22</height>
</rect>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Enables input report request when Interrupt occurs&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>En. INT event</string>
</property>
</widget>
<widget class="QLabel" name="label_int">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>650</x>
<y>160</y>
<width>121</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>INT ON (GND)</string>
</property>
</widget>
<widget class="QPushButton" name="clr_log">
<property name="geometry">
<rect>
<x>650</x>
<y>186</y>
<width>131</width>
<height>61</height>
</rect>
</property>
<property name="text">
<string>CLEAR LOG</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>627</width>
<width>795</width>
<height>25</height>
</rect>
</property>

4
ft232_qt/i2c.c

@ -126,6 +126,10 @@ int bitbang_open (int index, int port, int mask)
return 3;
}
ftdi_set_bitmode(ftdi, mask, BITMODE_BITBANG);
char buf[1] = {0xFF};
ftdi_write_data(ftdi, buf, 1);
buf[0] = 0x00;
ftdi_write_data(ftdi, buf, 1);
return 0;
}

BIN
i2c_keyboard/.sconsign.dblite

Binary file not shown.

15627
i2c_keyboard/hardware.asc

File diff suppressed because it is too large

BIN
i2c_keyboard/hardware.bin

Binary file not shown.

4394
i2c_keyboard/hardware.blif

File diff suppressed because it is too large

BIN
i2c_keyboard/i2c_kbd_alt.bin

Binary file not shown.

4520
i2c_keyboard/i2c_kbd_alt.blif

File diff suppressed because it is too large

15878
i2c_keyboard/i2c_kbd_alt.ex

File diff suppressed because it is too large

15479
i2c_keyboard/i2c_kbd_alt.txt

File diff suppressed because it is too large

267
i2c_keyboard/matrix_kbd.v

@ -1,4 +1,4 @@
module matrix_kbd (input CLK, input RESET, input FREEZE, inout [15:0] ROWS, input [7:0] COLUMNS, output [7:0] kbd_r0, kbd_r2, kbd_r3, kbd_r4, kbd_r5, kbd_r6, kbd_r7, output INT);
module matrix_kbd (input CLK, input RESET, input FREEZE, inout [15:0] ROWS, input [7:0] COLUMNS, output [7:0] kbd_r0, kbd_r2, kbd_r3, kbd_r4, kbd_r5, kbd_r6, kbd_r7,/*output [63:0] kbd_report,*/ output INT);
// * - ESC (29), 7 - F1 (3A), 4 - F2 (3B), 1 - NUM_LOCK (53)
// 0 - CAPS LOCK (39), 8 - R (15), 5 - BACKSPACE (2A), 2 - ENTER (58)
@ -12,10 +12,13 @@ module matrix_kbd (input CLK, input RESET, input FREEZE, inout [15:0] ROWS, inpu
reg [15:0] row_time = 0;
reg [3:0] row_counter;
//reg [7:0] last_data [3:0];//[31:0] last_data;
reg [7:0] temp;
reg [7:0] i;
//reg [63:0] report;
reg [7:0] report [6:0]; // NO BYTE 2
//reg [5:0] report_free_place;
reg isr;
reg [15:0] ROWS_EN = 0;
@ -31,124 +34,221 @@ module matrix_kbd (input CLK, input RESET, input FREEZE, inout [15:0] ROWS, inpu
reg [8:0] ram_adr;
wire [7:0] ram_rd;
reg [8:0] init_ram_cnt;
always @ (negedge CLK) begin
COLS_SHADOW <= COLUMNS;
end
ram RAM (CLK, ram_wr, ram_adr, temp, ram_adr, ram_rd);//module ram(input clk, wen, input [8:0] addr, input [7:0] wdata, output [7:0] rdata);
ram RAM (CLK, ram_wr, ram_adr, temp, ram_rd);//module ram(input clk, wen, input [8:0] addr, input [7:0] wdata, output [7:0] rdata);
always @ (posedge CLK) begin
if (RESET == 0) begin
for (i = 0; i < 6; i = i + 1)
report[i] = 0;
isr = 0;
init_ram_cnt = 0;
//last_data <= 32'hFFFFFFFF;
//report_free_place <= 6'h3F;
//report <= 0;
end
else begin
if (FREEZE == 0) begin
if (init_ram_cnt < 256) begin
if (row_time == ONE_ROW_TIME) begin
ram_wr = 0;
row_time <= 0;
row_counter = row_counter + 1;
ROWS_EN = 1 << row_counter;
ram_adr = row_counter;
end
else
row_time <= row_time + 1;
// ROW 0 - D, 1 - A, 2 - C, 3 - B
if (row_time == (ROW_STT_PROCESS_TIME - 1))
temp = ram_rd;
if (row_time == (ROW_STT_PROCESS_TIME + ONE_COLUMN_PROCESS_TIME * 7 + 1))
ram_wr = 1;
ram_adr = init_ram_cnt;
temp = 255;
init_ram_cnt = init_ram_cnt + 1;
if (row_time == (ROW_STT_PROCESS_TIME + ONE_COLUMN_PROCESS_TIME * 0/*0*/)) begin
check_column (0);
/*if (COLS_SHADOW[0] != last_data[row_counter*4 + 0]) begin
case (row_counter) 0: kbd_code = 8'h29; 1: kbd_code = 8'h53; 2: kbd_code = 8'h3A; 3: kbd_code = 8'h3B; // ESC, F1-F2, NUM LOCK
default: kbd_code = 1;
endcase
if ((COLS_SHADOW[0] == 0) && (last_data[row_counter*4 + 0] == 1)) is_pressed = 1;
else is_pressed = 0;
end
else kbd_code = 255;
last_data[row_counter*4 + 0] <= COLS_SHADOW[0];*/
end
else if (init_ram_cnt == 256) begin
ram_wr = 0;
init_ram_cnt = init_ram_cnt + 1;
else if (row_time == (ROW_STT_PROCESS_TIME + ONE_COLUMN_PROCESS_TIME * 2/*4*/)) begin
check_column (2);
end
else begin
if (row_time == ONE_ROW_TIME) begin
ram_wr = 0;
row_time <= 0;
row_counter = row_counter + 1;
ROWS_EN = 1 << row_counter;
ram_adr = row_counter;
/*if (COLS_SHADOW[2] != last_data[row_counter*4 + 2]) begin
case (row_counter) 0: kbd_code = 8'h39; 1: kbd_code = 8'h58; 2: kbd_code = 8'h15; 3: kbd_code = 8'h2A; // CAPS LOCK, R, BACKSPACE, ENTER
default: kbd_code = 1;
endcase
if ((COLS_SHADOW[2] == 0) && (last_data[row_counter*4 + 2] == 1)) is_pressed = 1;
else is_pressed = 0;
end
else
row_time <= row_time + 1;
// ROW 0 - D, 1 - A, 2 - C, 3 - B
if (row_time == (ROW_STT_PROCESS_TIME - 1))
temp = ram_rd;
if (row_time == (ROW_STT_PROCESS_TIME + ONE_COLUMN_PROCESS_TIME * 7 + 1))
ram_wr = 1;
if (row_time == (ROW_STT_PROCESS_TIME + ONE_COLUMN_PROCESS_TIME * 0))
check_column (0);
else if (row_time == (ROW_STT_PROCESS_TIME + ONE_COLUMN_PROCESS_TIME * 2))
check_column (2);
else if (row_time == (ROW_STT_PROCESS_TIME + ONE_COLUMN_PROCESS_TIME * 1))
check_column (1);
else if (row_time == (ROW_STT_PROCESS_TIME + ONE_COLUMN_PROCESS_TIME * 3))
check_column (3);
else if (row_time == (ROW_STT_PROCESS_TIME + ONE_COLUMN_PROCESS_TIME * 4))
check_column (4);
else if (row_time == (ROW_STT_PROCESS_TIME + ONE_COLUMN_PROCESS_TIME * 5))
check_column (5);
else if (row_time == (ROW_STT_PROCESS_TIME + ONE_COLUMN_PROCESS_TIME * 6))
check_column (6);
else if (row_time == (ROW_STT_PROCESS_TIME + ONE_COLUMN_PROCESS_TIME * 7))
check_column (7);
else
kbd_code = 255;
// START PACK I2C_HID REPORT
if (kbd_code_hid != 0) begin
if ((kbd_code_hid > 8'hDF) && (kbd_code_hid < 8'hE8)) begin
if (is_pressed)
report [0] = report [0] | (1<<(kbd_code_hid & 8'h07));
else
report [0] <= report [0] & (~(1<<(kbd_code_hid & 8'h07)));
end
else begin
if (is_pressed) begin
isr = 1;
if (report [ 1 ] == 0)
report [ 1 ] <= kbd_code_hid;
else if (report [ 2 ] == 0)
report [ 2 ] <= kbd_code_hid;
else if (report [ 3 ] == 0)
report [ 3 ] <= kbd_code_hid;
else if (report [ 4 ] == 0)
report [ 4 ] <= kbd_code_hid;
else if (report [ 5 ] == 0)
report [ 5 ] <= kbd_code_hid;
else if (report [ 6 ] == 0)
report [ 6 ] <= kbd_code_hid;
else
isr = 0;
else kbd_code = 0;
last_data[row_counter*4 + 2] <= COLS_SHADOW[2];
end*/
else if (row_time == (ROW_STT_PROCESS_TIME + ONE_COLUMN_PROCESS_TIME * 1/*2*/)) begin
check_column (1);
/*
if (COLS_SHADOW[1] != last_data[row_counter*4 + 1]) begin
case (row_counter) 0: kbd_code = 8'hE1; 1: kbd_code = 8'h4C; 2: kbd_code = 8'h06; 3: kbd_code = 8'h19; // LEFT SHIFT, C, V, DELETE
default: kbd_code = 1;
endcase
if ((COLS_SHADOW[1] == 0) && (last_data[row_counter*4 + 1] == 1)) is_pressed = 1;
else is_pressed = 0;
end
else kbd_code = 255;
last_data[row_counter*4 + 1] <= COLS_SHADOW[1];*/
end
else if (row_time == (ROW_STT_PROCESS_TIME + ONE_COLUMN_PROCESS_TIME * 3/*6*/)) //begin
check_column (3);
else if (row_time == (ROW_STT_PROCESS_TIME + ONE_COLUMN_PROCESS_TIME * 4/*6*/))
check_column (4);
else if (row_time == (ROW_STT_PROCESS_TIME + ONE_COLUMN_PROCESS_TIME * 5/*6*/))
check_column (5);
else if (row_time == (ROW_STT_PROCESS_TIME + ONE_COLUMN_PROCESS_TIME * 6/*6*/))
check_column (6);
else if (row_time == (ROW_STT_PROCESS_TIME + ONE_COLUMN_PROCESS_TIME * 7/*6*/))
check_column (7);
/*
if (COLS_SHADOW[3] != last_data[row_counter*4 + 3]) begin
case (row_counter) 0: kbd_code = 8'hE0; 1: kbd_code = 8'hE7; 2: kbd_code = 8'hE2; 3: kbd_code = 8'h2C; // LCTRL, LALT, SPACE, RGUI
default: kbd_code = 1;
endcase
if ((COLS_SHADOW[3] == 0) && (last_data[row_counter*4 + 3] == 1)) is_pressed = 1;
else is_pressed = 0;
end
else kbd_code = 255;
last_data[row_counter*4 + 3] <= COLS_SHADOW[3];
*/
//end
else
kbd_code = 255;
// START PACK I2C_HID REPORT
if (kbd_code_hid != 0 /*kbd_code != 255*/) begin
isr = 1;
//report[15:8] <= 0;
//report[63:56] <= 0;
if ((kbd_code_hid > 8'hDF) && (kbd_code_hid < 8'hE8))/*((kbd_code > 8'hDF) && (kbd_code < 8'hE8))*/ begin
//kbd_code = kbd_code & 8'h07;
if (is_pressed)
//report [7:0] <= report [7:0] | (1<<(kbd_code_hid & 8'h07));//(1<<kbd_code);
report [0] = report [0] | (1<<(kbd_code_hid & 8'h07));//(1<<kbd_code);
else
report [0] <= report [0] & (~(1<<(kbd_code_hid & 8'h07)));//(~(1<<kbd_code));
//report [7:0] <= report [7:0] & (~(1<<(kbd_code_hid & 8'h07)));//(~(1<<kbd_code));
end
else begin
if (is_pressed) begin
/*for (i = 0; i < 4; i = i + 1) begin
if (report_free_place[i] == 1) begin
report [ ((i + 2) * 8 + 7) : ((i + 2) * 8 + 0)] <= kbd_code;
report_free_place[i] = 0;
is_pressed = 0; // NO ERROR DETECTED
end
end
if (report_free_place[0] == 1) begin
report [ ((0 + 2) * 8 + 7) : ((0 + 2) * 8 + 0)] <= kbd_code;
report_free_place[0] = 0;
end*/
if (report [ 1 ] == 0)
report [ 1 ] <= kbd_code_hid;//kbd_code;
else if (report [ 2 ] == 0)
report [ 2 ] <= kbd_code_hid;//kbd_code;
else if (report [ 3 ] == 0)
report [ 3 ] <= kbd_code_hid;//kbd_code;
else if (report [ 4 ] == 0)
report [ 4 ] <= kbd_code_hid;//kbd_code;
else if (report [ 5 ] == 0)
report [ 5 ] <= kbd_code_hid;//kbd_code;
else if (report [ 6 ] == 0)
report [ 6 ] <= kbd_code_hid;//kbd_code;
/*if (report [ 23 : 16 ] == 0)
report [ 23 : 16 ] <= kbd_code_hid;//kbd_code;
else if (report [ 31 : 24 ] == 0)
report [ 31 : 24 ] <= kbd_code_hid;//kbd_code;
else if (report [ 39 : 32 ] == 0)
report [ 39 : 32 ] <= kbd_code_hid;//kbd_code;
else if (report [ 47 : 40 ] == 0)
report [ 47 : 40 ] <= kbd_code_hid;//kbd_code;
else if (report [ 55 : 48 ] == 0)
report [ 55 : 48 ] <= kbd_code_hid;//kbd_code;
else if (report [ 63 : 56 ] == 0)
report [ 63 : 56 ] <= kbd_code_hid;//kbd_code;*/
end
else begin
for (i = 1; i < 7; i = i + 1) begin
if (report [i] == kbd_code_hid/*kbd_code*/) begin
report [i] = 0;
isr = 1;
end
else begin
for (i = 1; i < 7; i = i + 1) begin
//if (report [ ((i + 2) * 8 + 7) : ((i + 2) * 8 + 0)] == kbd_code_hid/*kbd_code*/) begin
//report [ ((i + 2) * 8 + 7) : ((i + 2) * 8 + 0)] <= 0;
if (report [i] == kbd_code_hid/*kbd_code*/) begin
report [i] <= 0;
//report_free_place[i] = 1;
end
end
end
end // END OF KBD CODE SEND ALG
//if (kbd_code == 8'h2C) begin
//if (is_pressed)
// report [15:8] <= kbd_code;
//else
// report [15:8] <= 0;
//end
//else if (kbd_code == 1) begin
// if (is_pressed)
// report [23:16] <= kbd_code;
// else
// report [23:16] <= 0;
//end
end
end // END OF KBD CODE SEND ALG
else
isr <= 0;
/*if (kbd_code != 0) begin
if (is_pressed)
report [7:0] <= kbd_code;
else
isr <= 0;
end
report [7:0] <= 0;
end*/
end
end
end
task check_column;
/*else if (row_time == (ONE_ROW_TIME/2 + 6)) begin
if (COLS_SHADOW[3] != last_data[row_counter*4 + 3]) begin
case (row_counter) 0: kbd_code = 8'hE0; 1: kbd_code = 8'hE7; 2: kbd_code = 8'hE2; 3: kbd_code = 8'h2C; // LCTRL, LALT, SPACE, RGUI
default: kbd_code = 1;
endcase
if ((COLS_SHADOW[3] == 0) && (last_data[row_counter*4 + 3] == 1)) is_pressed = 1;
else is_pressed = 0;
end
else kbd_code = 0;
last_data[row_counter*4 + 3] <= COLS_SHADOW[3];
end*/
task check_column; //(input [2:0] column);
input [2:0] column;
begin
//if (COLS_SHADOW[column] != last_data[row_counter][column]/*[row_counter*8 + column]*/) begin
if (COLS_SHADOW[column] != temp[column]) begin
kbd_code = row_counter*8 + column;
//if ((COLS_SHADOW[column] == 0) && (last_data[row_counter][column]/*[row_counter*8 + column]*/ == 1)) is_pressed = 1;
if ((COLS_SHADOW[column] == 0) && (temp[column] == 1)) is_pressed = 1;
else is_pressed = 0;
end
else kbd_code = 255;
//last_data[row_counter][column]/*[row_counter*8 + column]*/ <= COLS_SHADOW[column];
temp[column] = COLS_SHADOW[column];
end
endtask
//assign kbd_report = report;
assign kbd_r0 = report[0];
assign kbd_r2 = report[1];
assign kbd_r3 = report[2];
@ -157,6 +257,7 @@ module matrix_kbd (input CLK, input RESET, input FREEZE, inout [15:0] ROWS, inpu
assign kbd_r6 = report[5];
assign kbd_r7 = report[6];
assign INT = isr;
//assign ROWS_EN = (1 << row_counter);
SB_RAM40_4K #(
.INIT_0(256'h0000_0001_0001_0001_00E7_0058_004C_0053__0001_0001_0001_0001_00E0_0039_00E1_0029), // ROW 0-1

15
i2c_keyboard/ram.v

@ -1,4 +1,4 @@
module ram(input clk, wen, input [8:0] waddr, input [7:0] wdata, input [8:0] raddr, output [7:0] rdata);
module ram(input clk, wen, input [8:0] addr, input [7:0] wdata, output [7:0] rdata);
reg [7:0] mem [0:255];
reg [7:0] r_data;
reg [7:0] w_data;
@ -6,14 +6,13 @@ module ram(input clk, wen, input [8:0] waddr, input [7:0] wdata, input [8:0] rad
reg last_we;
initial mem[0] = 255;
always @(posedge clk) begin
if (wen) begin //((last_we == 0) && (wen == 1)) begin
//w_data = wdata;
//w_addr = addr;
//mem[w_addr] <= w_data;
mem[waddr] <= wdata;
if ((last_we == 0) && (wen == 1)) begin
w_data = wdata;
w_addr = addr;
mem[w_addr] <= w_data;
end
r_data <= mem[raddr];
//last_we = wen;
r_data <= mem[addr];
last_we = wen;
end
assign rdata = r_data;

236
i2c_keyboard/top.v

@ -12,7 +12,8 @@ module top (input CLK, output LED1, LED2, LED3, LED4, LED5,
//reg [7:0] I2C_TX; // TRANSMITTED TO MASTER
wire [7:0] I2C_TX;
reg [7:0] I2C_TX_DESC;
//reg [7:0] I2C_TX_REPORT;
reg [7:0] I2C_TX_REPORT;
assign I2C_TX = (I2C_TX_DESC & I2C_OUT_DESC_MASK) | (I2C_TX_REPORT & (~I2C_OUT_DESC_MASK));
wire [7:0] I2C_RX; // RECEIVED FROM MASTER
wire I2C_TRANS, I2C_READ, I2C_ACK, I2C_ACK_MSTR_CTRL, I2C_WR;
wire [7:0] I2C_COUNTER;
@ -31,26 +32,14 @@ module top (input CLK, output LED1, LED2, LED3, LED4, LED5,
wire [7:0] kbd_report [6:0];
wire ISR;
reg INT = 1; // INTERRUPT LINE TO HOST
reg [19:0] int_tmr;
reg KBD_FREEZE = 1; // LOGIC REG FOR BLOCK KBD ACTIVITY WHEN I2C IS WORKING
//reg IS_EMPTY_REPORT = 0; // REGISTER FOR CORRECT START (HOST MUST REQUEST EMPTY REGISTER AFTER INTERRUPT. THEN INTERRRUPT SET TO 1)
matrix_kbd KEYBOARD (CLK, RESET, 0 /*KBD_FREEZE*/, KBD_ROWS, KBD_COLUMNS, kbd_report[0], kbd_report[1], kbd_report[2], kbd_report[3], kbd_report[4], kbd_report[5], kbd_report[6], ISR);
descriptors I2C_HID_DESC (CLK, RESET, I2C_WR, I2C_OUTPUT_TYPE[1:0], I2C_COUNTER, I2C_TX_DESC/*, kbd_report*/);
//reg [7:0] ring_report [(8*8-1):0];
reg [7:0] init_ram_cnt;
reg [3:0] ring_wr, ring_rd;
reg [3:0] wr_cnt;
reg report_wr_en;
reg [7:0] report_data_wadr, report_data_radr, report_data_wr;
wire [7:0] report_data_rd;
ram REPORT_DATA (CLK, report_wr_en, report_data_wadr, report_data_wr, report_data_radr, report_data_rd);
assign I2C_TX = (I2C_TX_DESC & I2C_OUT_DESC_MASK) | (/*I2C_TX_REPORT*/report_data_rd & (~I2C_OUT_DESC_MASK));
//parameter MAX_INPUT_LEN = 10;
//reg [7:0] I2C_INPUT_DATA [MAX_INPUT_LEN:0];
parameter MAX_INPUT_LEN = 10;
reg [7:0] I2C_INPUT_DATA [MAX_INPUT_LEN:0];
reg [7:0] temp_output_report;
reg [3:0] i2c_input_data_type; // 0 - UNKNOWN, 1 - I2C_HID_DESC_REQUEST, 2 - HID_REPORT_DESC_REQUEST, 3 - INPUT_REPORT_REQUEST, 4 - OUTPUT_REPORT_SET
// 5 - RESET, 6 - GET_INPUT_REPORT, 7 - SET_OUTPUT_REPORT
@ -59,6 +48,9 @@ module top (input CLK, output LED1, LED2, LED3, LED4, LED5,
reg [7:0] I2C_OUT_DESC_MASK = 0;
reg [7:0] KBD_LED_STATUS = 0;
reg [7:0] ring_report [(8*8-1):0];
reg [2:0] ring_wr, ring_rd;
reg [2:0] wr_cnt;
reg last_wr = 0, last_trans = 0, last_uart_active = 0, last_isr = 0, uart_double_ff = 0;
@ -67,68 +59,26 @@ module top (input CLK, output LED1, LED2, LED3, LED4, LED5,
// RESET LOGIC
rststate <= rststate + !RESET;
if (RESET == 0) begin
I2C_OUTPUT_TYPE = 3;//0;
I2C_OUTPUT_TYPE = 0;
I2C_OUT_DESC_MASK = 0;
KBD_LED_STATUS = 5; // BIT 0 - NUM LOCK, BIT 1 - CAPS LOCK, BIT 2 - SCROOL LOCK
uart_double_ff = 0; last_trans = 0; last_uart_active = 0; last_isr = 0;
KBD_LED_STATUS = 7; // BIT 0 - NUM LOCK, BIT 1 - CAPS LOCK, BIT 2 - SCROOL LOCK
I2C_INPUT_LEN = 0;
INT = 1; int_tmr = 0;
INT = 0;
UART_WR = 0;
ring_wr = 0; ring_rd = 15; wr_cnt = 0;
init_ram_cnt = 0;
//KBD_FREEZE = 1;
//IS_EMPTY_REPORT = 0;
ring_wr = 0;
ring_rd = 0;
wr_cnt = 0;
end
// NOT RESET MODE LOGIC
else begin
if (init_ram_cnt < 170) begin
report_wr_en = 1;
if (init_ram_cnt < 10)
report_data_wadr = 0;
else
report_data_wadr = init_ram_cnt - 10;
report_data_wr = 0;//report_data_adr + 1;
init_ram_cnt = init_ram_cnt + 1;
end
else if (init_ram_cnt == 170) begin
report_wr_en = 0;
init_ram_cnt = init_ram_cnt + 1;
end
else if ((last_isr == 0) && (ISR == 1)/* && (INT == 1)*/) begin // INTERRUPT FROM KEYBOARD
if ((ring_wr + 1) != ring_rd)
ring_wr = ring_wr + 1;
report_wr_en = 1;
report_data_wadr = ring_wr * 10;
report_data_wr = 10;//kbd_report [0];
wr_cnt = 1;
INT = 0;
I2C_OUTPUT_TYPE = 3;
I2C_OUT_DESC_MASK = 8'h00;
last_isr = ISR;
end
else if ((last_isr == 1) && (ISR == 0))
last_isr = ISR;
else if (wr_cnt != 0) begin
if (wr_cnt == 10) begin
wr_cnt = 0;
report_wr_en = 0;
end
else begin
report_data_wadr = ring_wr * 10 + wr_cnt;
if ((wr_cnt == 1) || (wr_cnt == 3))
report_data_wr = 0;
else if (wr_cnt == 2)
report_data_wr = kbd_report [wr_cnt - 2];
else
report_data_wr = kbd_report [wr_cnt - 3];
wr_cnt = wr_cnt + 1;
end
end
else if ((last_wr == 0) && (I2C_WR == 1)) begin // I2C NEW BYTE TX/RX
if ((last_wr == 0) && (I2C_WR == 1)) begin // I2C NEW BYTE TX/RX
I2C_INPUT_LEN = I2C_COUNTER - 1;
if (I2C_READ == 0) begin // I2C_FROM_HOST
if (I2C_READ == 0) begin
/*if (I2C_COUNTER < (MAX_INPUT_LEN + 2))
I2C_INPUT_DATA[I2C_COUNTER - 2] <= I2C_RX;*/
if (I2C_COUNTER == 2) begin
if ((I2C_RX > 5) || (I2C_RX < 1))
@ -166,55 +116,39 @@ module top (input CLK, output LED1, LED2, LED3, LED4,