Skip to content

Commit

Permalink
added status register form for 95xxx, 25xxx chips
Browse files Browse the repository at this point in the history
  • Loading branch information
bigbigmdm committed Mar 25, 2024
1 parent ef9facc commit d8b79c5
Show file tree
Hide file tree
Showing 26 changed files with 2,566 additions and 1,210 deletions.
3 changes: 3 additions & 0 deletions IMSProg_programmer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ commands.cpp
dialogsp.cpp
dialogrp.cpp
dialogsfdp.cpp
dialogsr.cpp
searchdialog.cpp
dialoginfo.cpp
bitbang_microwire.c
Expand All @@ -89,6 +90,7 @@ commands.h
dialogsp.h
dialogrp.h
dialogsfdp.h
dialogsr.h
dialoginfo.h
searchdialog.h
bitbang_microwire.h
Expand All @@ -112,6 +114,7 @@ mainwindow.ui
dialogsp.ui
dialogrp.ui
dialogsfdp.ui
dialogsr.ui
dialoginfo.ui
searchdialog.ui
dialogabout.ui
Expand Down
9 changes: 6 additions & 3 deletions IMSProg_programmer/IMSProg.pro
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ SOURCES += \
timer.c \
dialogabout.cpp \
dialoginfo.cpp \
dialogsfdp.cpp
dialogsfdp.cpp \
dialogsr.cpp

HEADERS += \
mainwindow.h \
Expand Down Expand Up @@ -75,7 +76,8 @@ HEADERS += \
types.h \
dialogabout.h \
dialoginfo.h \
dialogsfdp.h
dialogsfdp.h \
dialogsr.h

FORMS += \
mainwindow.ui \
Expand All @@ -84,7 +86,8 @@ FORMS += \
searchdialog.ui \
dialogabout.ui \
dialoginfo.ui \
dialogsfdp.ui
dialogsfdp.ui \
dialogsr.ui

TRANSLATIONS += language/chipProgrammer_ru_RU.ts \
language/chipProgrammer_es_ES.ts \
Expand Down
2 changes: 1 addition & 1 deletion IMSProg_programmer/dialogabout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ DialogAbout::DialogAbout(QWidget *parent) :
ui->label_7->setTextFormat(Qt::RichText);
ui->label_7->setTextInteractionFlags(Qt::TextBrowserInteraction);
ui->label_7->setOpenExternalLinks(true);
ui->label_8->setText("V1.3.2");
ui->label_8->setText("V1.3.3");
}

DialogAbout::~DialogAbout()
Expand Down
147 changes: 147 additions & 0 deletions IMSProg_programmer/dialogsr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* Copyright (C) 2023 - 2024 Mikhail Medvedev <e-ink-reader@yandex.ru>
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "dialogsr.h"
#include "ui_dialogsr.h"
#include <QValidator>
#include <QRegExp>
#include "unistd.h"
#include <QDebug>

DialogSR::DialogSR(QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogSR)
{
ui->setupUi(this);
setLineEditFilter();
}

DialogSR::~DialogSR()
{
delete ui;
}

void DialogSR::on_pushButton_read_clicked()
{
//READING STATUS REGISTER
uint8_t *buf;
int retval;
int stCH341 = 0;
buf = (uint8_t *)malloc(2);
stCH341 = ch341a_spi_init();
if (stCH341 == 0)
{
SPI_CONTROLLER_Chip_Select_Low();
SPI_CONTROLLER_Write_One_Byte(0x05);
retval = SPI_CONTROLLER_Read_NByte(buf,1,SPI_CONTROLLER_SPEED_SINGLE);
qDebug() << "retval=" << retval;
SPI_CONTROLLER_Chip_Select_High();
usleep(1);
if (retval)
{
QMessageBox::about(this, tr("Error"), tr("Error reading register!"));
return;
}
ui->lineEdit_sr07->setText(QString::number(((buf[0] & 128) >> 7)));
ui->lineEdit_sr06->setText(QString::number(((buf[0] & 64) >> 6)));
ui->lineEdit_sr05->setText(QString::number(((buf[0] & 32) >> 5)));
ui->lineEdit_sr04->setText(QString::number(((buf[0] & 16) >> 4)));
ui->lineEdit_sr03->setText(QString::number(((buf[0] & 8) >> 3)));
ui->lineEdit_sr02->setText(QString::number(((buf[0] & 4) >> 2)));
ui->lineEdit_sr01->setText(QString::number(((buf[0] & 2) >> 1)));
ui->lineEdit_sr00->setText(QString::number((buf[0] & 1)));
ch341a_spi_shutdown();
}
else QMessageBox::about(this, tr("Error"), tr("Programmer CH341a is not connected!"));
}

void DialogSR::on_pushButton_write_clicked()
{
//READING STATUS REGISTER
uint8_t r0 = 0;
int stCH341 = 0;
stCH341 = ch341a_spi_init();
if (stCH341 == 0)
{
if (QString::compare(ui->lineEdit_sr07->text(), "0", Qt::CaseInsensitive)) r0 = r0 + 128;
if (QString::compare(ui->lineEdit_sr06->text(), "0", Qt::CaseInsensitive)) r0 = r0 + 64;
if (QString::compare(ui->lineEdit_sr05->text(), "0", Qt::CaseInsensitive)) r0 = r0 + 32;
if (QString::compare(ui->lineEdit_sr04->text(), "0", Qt::CaseInsensitive)) r0 = r0 + 16;
if (QString::compare(ui->lineEdit_sr03->text(), "0", Qt::CaseInsensitive)) r0 = r0 + 8;
if (QString::compare(ui->lineEdit_sr02->text(), "0", Qt::CaseInsensitive)) r0 = r0 + 4;
if (QString::compare(ui->lineEdit_sr01->text(), "0", Qt::CaseInsensitive)) r0 = r0 + 2;
if (QString::compare(ui->lineEdit_sr00->text(), "0", Qt::CaseInsensitive)) r0 = r0 + 1;
//Writing status registers
SPI_CONTROLLER_Chip_Select_Low();
SPI_CONTROLLER_Write_One_Byte(0x06);
SPI_CONTROLLER_Chip_Select_High();
usleep(1);

SPI_CONTROLLER_Chip_Select_Low();
SPI_CONTROLLER_Write_One_Byte(0x01);
SPI_CONTROLLER_Write_One_Byte(r0);
SPI_CONTROLLER_Chip_Select_High();
usleep(1);

SPI_CONTROLLER_Chip_Select_Low();
SPI_CONTROLLER_Write_One_Byte(0x04);
SPI_CONTROLLER_Chip_Select_High();
usleep(1);

ch341a_spi_shutdown();
}
else QMessageBox::about(this, tr("Error"), tr("Programmer CH341a is not connected!"));
}

void DialogSR::setLineEditFilter()
{
QRegExp reHex( "[0-1]{1}" );
QRegExpValidator *validator = new QRegExpValidator(reHex, this);
ui->lineEdit_sr00->setValidator(validator);
ui->lineEdit_sr01->setValidator(validator);
ui->lineEdit_sr02->setValidator(validator);
ui->lineEdit_sr03->setValidator(validator);
ui->lineEdit_sr04->setValidator(validator);
ui->lineEdit_sr05->setValidator(validator);
ui->lineEdit_sr06->setValidator(validator);
ui->lineEdit_sr07->setValidator(validator);
}

void DialogSR::setChipType(const uint chipType)
{
switch (chipType)
{

case 3:
ui->label_20->setText("/RDY");
ui->label_19->setText("WEN");
ui->label_13->setText("WPEN");
break;

case 4:
ui->label_20->setText("WIP");
ui->label_19->setText("WEL");
ui->label_13->setText("SRWD");
break;

default:
break;
}
}

void DialogSR::closeEvent(QCloseEvent* event)
{
emit closeRequestHasArrived();
QWidget::closeEvent(event);
}
50 changes: 50 additions & 0 deletions IMSProg_programmer/dialogsr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2023 - 2024 Mikhail Medvedev <e-ink-reader@yandex.ru>
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef DIALOGSR_H
#define DIALOGSR_H

#include <QDialog>
#include <QMessageBox>
extern "C" {
#include "ch341a_spi.h"
#include "spi_controller.h"
}
namespace Ui {
class DialogSR;
}

class DialogSR : public QDialog
{
Q_OBJECT

public:
explicit DialogSR(QWidget *parent = nullptr);
void setChipType(const uint chipType);
void closeEvent(QCloseEvent* event);
~DialogSR();

private slots:
void on_pushButton_read_clicked();
void on_pushButton_write_clicked();

signals:
void closeRequestHasArrived();

private:
Ui::DialogSR *ui;
void setLineEditFilter();
};

#endif // DIALOGSR_H
Loading

0 comments on commit d8b79c5

Please sign in to comment.