00001 #include "gpiowidget.h"
00002
00003 GpioWidget::GpioWidget(QWidget* parent, base::Board* brd) :
00004 SubWidget(parent),
00005 fGPIO(brd)
00006 {
00007 setupUi(this);
00008
00009 QGridLayout* grid = new QGridLayout(GPIOgroup);
00010
00011 fScaleDownCombo = 0;
00012
00013 for (int gpio=0;gpio<base::NumGpio;gpio++) {
00014 fSyncRateCombo[gpio] = 0;
00015 fRisingChk[gpio] = 0;
00016 fFallingChk[gpio] = 0;
00017 fThrottledChk[gpio] = 0;
00018 fAdditionalChk[gpio] = 0;
00019 fAlternateChk[gpio] = 0;
00020
00021
00022 grid->addWidget(new QLabel(base::Gpio::name(gpio), this), gpio, 0);
00023
00024
00025 if (gpio==0) {
00026 fScaleDownCombo = new QComboBox(this);
00027
00028 double period = 16.384;
00029 const char* lbl = "mus";
00030 for (int n=0;n<22;n++) {
00031 fScaleDownCombo->addItem(QString("%1: %2 %3").arg(n).arg(period, 4, 'f', 2).arg(lbl), n);
00032 period *= 2;
00033 if (period>1000.) {
00034 period = period / 1000.;
00035 if (strcmp(lbl, "ms")==0) lbl = "s"; else lbl = "ms";
00036 }
00037 }
00038
00039 grid->addWidget(fScaleDownCombo, gpio, 1);
00040 } else {
00041 fRisingChk[gpio] = new QCheckBox((gpio<3 ? "enabled" : "rising"), this);
00042 grid->addWidget(fRisingChk[gpio], gpio, 1);
00043 QObject::connect(fRisingChk[gpio], SIGNAL(clicked(bool)), this, SLOT(setMask()));
00044 }
00045
00046
00047 if (gpio<3) {
00048 fSyncRateCombo[gpio] = new QComboBox(this);
00049 fSyncRateCombo[gpio]->addItem("Baud", 0);
00050 fSyncRateCombo[gpio]->addItem("62.5 MHz", 8);
00051 fSyncRateCombo[gpio]->addItem("50 MHz", 10);
00052 fSyncRateCombo[gpio]->addItem("31.25 MHz", 16);
00053 fSyncRateCombo[gpio]->addItem("25 MHz", 20);
00054 fSyncRateCombo[gpio]->addItem("20 Mhz", 25);
00055 fSyncRateCombo[gpio]->addItem("12.5 Mhz", 40);
00056 fSyncRateCombo[gpio]->addItem("10 Mhz", 50);
00057 fSyncRateCombo[gpio]->addItem(" 5 Mhz", 100);
00058 fSyncRateCombo[gpio]->addItem(" 1 Mhz", 500);
00059 grid->addWidget(fSyncRateCombo[gpio], gpio, 2);
00060 } else {
00061 fFallingChk[gpio] = new QCheckBox("falling", this);
00062 grid->addWidget(fFallingChk[gpio], gpio, 2);
00063 QObject::connect(fFallingChk[gpio], SIGNAL(clicked(bool)), this, SLOT(setMask()));
00064 }
00065
00066
00067 if (gpio==0) {
00068 grid->addWidget(new QLabel("---", this), gpio, 3);
00069 } else {
00070 fThrottledChk[gpio] = new QCheckBox("throttled", this);
00071 grid->addWidget(fThrottledChk[gpio], gpio, 3);
00072 QObject::connect(fThrottledChk[gpio], SIGNAL(clicked(bool)), this, SLOT(setMask()));
00073 }
00074
00075
00076 if (gpio==0 || gpio==3 || gpio==4) {
00077 grid->addWidget(new QLabel("---", this), gpio, 4);
00078 } else {
00079 const char* text = "loop-back";
00080 QString tooltip;
00081 if (gpio==5) { text = "TP-in"; tooltip = "This enables usage of AUX2 as external test-trigger (test-pulse) input"; }
00082 if (gpio==6) text = "THR-in";
00083 fAdditionalChk[gpio] = new QCheckBox(text, this);
00084 fAdditionalChk[gpio]->setToolTip(tooltip);
00085 grid->addWidget(fAdditionalChk[gpio], gpio, 4);
00086 QObject::connect(fAdditionalChk[gpio], SIGNAL(clicked(bool)), this, SLOT(setMask()));
00087 }
00088
00089
00090 if (gpio==4 || gpio==5 || gpio==6) {
00091 QString tooltip;
00092 const char* lbl = "Alter";
00093 if (gpio==4) lbl = "TP-mon";
00094 if (gpio==5) tooltip = "This enables usage of internal pulse generator as input of nXYTER test-trigger (test-pulse) input, TP-in should also be selected";
00095 if (gpio==6) lbl = "THR-loop";
00096 fAlternateChk[gpio] = new QCheckBox(lbl, this);
00097 fAlternateChk[gpio]->setToolTip(tooltip);
00098 grid->addWidget(fAlternateChk[gpio], gpio, 5);
00099 QObject::connect(fAlternateChk[gpio], SIGNAL(clicked(bool)), this, SLOT(setMask()));
00100 } else {
00101 grid->addWidget(new QLabel("---", this), gpio, 5);
00102 }
00103
00104 }
00105
00106 QObject::connect(fScaleDownCombo, SIGNAL(activated(int)), this, SLOT(sync0scaleactivated(int)));
00107 QObject::connect(fSyncRateCombo[0], SIGNAL(activated(int)), this, SLOT(sync0rateactivated(int)));
00108 QObject::connect(fSyncRateCombo[1], SIGNAL(activated(int)), this, SLOT(sync1rateactivated(int)));
00109 QObject::connect(fSyncRateCombo[2], SIGNAL(activated(int)), this, SLOT(sync2rateactivated(int)));
00110
00111 getSubConfig();
00112 }
00113
00114 bool GpioWidget::getSubConfig()
00115 {
00116 uint32_t mask(0), scale(0);
00117
00118 fGPIO.getSyncScale(scale);
00119 fGPIO.getConfig(mask);
00120
00121 GPIOgroup->setTitle(QString("GPIO 0x%1").arg(mask, 8, 16, QLatin1Char('0')));
00122
00123 fScaleDownCombo->setCurrentIndex(scale);
00124
00125 for (int gpio=1;gpio<base::NumGpio;gpio++) {
00126 bool additional(false), throttled(false), falling(false);
00127 bool rising(false), altin(false);
00128
00129 base::Gpio::unpackConfig(mask, gpio+1, rising, falling, throttled, additional, altin);
00130
00131 if (fRisingChk[gpio]) fRisingChk[gpio]->setCheckState(rising ? Qt::Checked : Qt::Unchecked);
00132 if (fFallingChk[gpio]) fFallingChk[gpio]->setCheckState(falling ? Qt::Checked : Qt::Unchecked);
00133 if (fThrottledChk[gpio]) fThrottledChk[gpio]->setCheckState(throttled ? Qt::Checked : Qt::Unchecked);
00134 if (fAdditionalChk[gpio]) fAdditionalChk[gpio]->setCheckState(additional ? Qt::Checked : Qt::Unchecked);
00135 if (fAlternateChk[gpio]) fAlternateChk[gpio]->setCheckState(altin ? Qt::Checked : Qt::Unchecked);
00136 }
00137
00138 for (int sync=0;sync<3;sync++) {
00139 if (fSyncRateCombo[sync]==0) continue;
00140
00141 uint32_t ratediv;
00142 fGPIO.getSyncBaud(sync+1, ratediv);
00143 int indx = fSyncRateCombo[sync]->findData(ratediv);
00144
00145 if (indx>=0) fSyncRateCombo[sync]->setCurrentIndex(indx);
00146 else fSyncRateCombo[sync]->setCurrentIndex(0);
00147 }
00148
00149 return true;
00150 }
00151
00152 bool GpioWidget::setSubConfig()
00153 {
00154 setMask();
00155
00156 fGPIO.setSyncScale(fScaleDownCombo->currentIndex());
00157
00158 for (int sync=0;sync<3;sync++)
00159 setSyncRate(sync);
00160
00161 return true;
00162 }
00163
00164 uint32_t GpioWidget::getMaskValue()
00165 {
00166 uint32_t mask(0);
00167
00168 for (int gpio=1;gpio<base::NumGpio;gpio++) {
00169 bool additional(false), throttled(false), falling(false);
00170 bool rising(false), altin(false);
00171
00172 if (fRisingChk[gpio]) rising = fRisingChk[gpio]->checkState() == Qt::Checked;
00173 if (fFallingChk[gpio]) falling = fFallingChk[gpio]->checkState() == Qt::Checked;
00174 if (fThrottledChk[gpio]) throttled = fThrottledChk[gpio]->checkState() == Qt::Checked;
00175 if (fAdditionalChk[gpio]) additional = fAdditionalChk[gpio]->checkState() == Qt::Checked;
00176 if (fAlternateChk[gpio]) altin = fAlternateChk[gpio]->checkState() == Qt::Checked;
00177
00178 base::Gpio::packConfig(mask, gpio+1, rising, falling, throttled, additional, altin);
00179 }
00180
00181 return mask;
00182
00183 }
00184
00185
00186 void GpioWidget::setMask()
00187 {
00188 uint32_t mask = getMaskValue();
00189
00190 GPIOgroup->setTitle(QString("GPIO 0x%1").arg(mask, 8, 16, QLatin1Char('0')));
00191
00192 fGPIO.setConfig(mask);
00193 }
00194
00195
00196 void GpioWidget::setSyncRate(int sync)
00197 {
00198 if (fSyncRateCombo[sync]==0) return;
00199
00200 uint32_t ratediv = fSyncRateCombo[sync]->itemData(fSyncRateCombo[sync]->currentIndex()).toUInt();
00201
00202 if (ratediv>0)
00203 fGPIO.setSyncBaud(sync+1, ratediv);
00204 }
00205
00206
00207 void GpioWidget::sync0scaleactivated(int indx)
00208 {
00209 fGPIO.setSyncScale(indx);
00210 }
00211
00212 void GpioWidget::sync0rateactivated(int)
00213 {
00214 setSyncRate(0);
00215 }
00216
00217 void GpioWidget::sync1rateactivated(int)
00218 {
00219 setSyncRate(1);
00220 }
00221
00222 void GpioWidget::sync2rateactivated(int)
00223 {
00224 setSyncRate(2);
00225 }
00226
00227 bool GpioWidget::fillCmdFile(FILE* f)
00228 {
00229 uint32_t mask = getMaskValue();
00230
00231 fprintf(f, "\n// GPIO settings\n");
00232
00233 fprintf(f,"// mask = 0x%08x\n", mask);
00234
00235 for (int gpio=0;gpio<base::NumGpio;gpio++) {
00236 bool additional(false), throttled(false), falling(false);
00237 bool rising(false), altin(false);
00238 unsigned ratediv = 0;
00239
00240 if (fSyncRateCombo[gpio]) ratediv = fSyncRateCombo[gpio]->itemData(fSyncRateCombo[gpio]->currentIndex()).toUInt();
00241 if (fRisingChk[gpio]) rising = fRisingChk[gpio]->checkState() == Qt::Checked;
00242 if (fFallingChk[gpio]) falling = fFallingChk[gpio]->checkState() == Qt::Checked;
00243 if (fThrottledChk[gpio]) throttled = fThrottledChk[gpio]->checkState() == Qt::Checked;
00244 if (fAdditionalChk[gpio]) additional = fAdditionalChk[gpio]->checkState() == Qt::Checked;
00245 if (fAlternateChk[gpio]) altin = fAlternateChk[gpio]->checkState() == Qt::Checked;
00246
00247 char sbuf[100];
00248 switch (ratediv) {
00249 case 0: strcpy(sbuf,""); break;
00250 case 8: strcpy(sbuf,",baud=62.5"); break;
00251 default: sprintf(sbuf, ",baud=%u", 500/ratediv); break;
00252 }
00253
00254 if (gpio==0)
00255 fprintf(f, "setsyncm %d%s\n", fScaleDownCombo->currentIndex(), sbuf);
00256 else
00257 if ((gpio==1) || (gpio==2))
00258 fprintf(f, "setsyncs %d,%d,thr=%d%s,loop=%d\n",
00259 gpio-1, rising ? 1 : 0, throttled ? 1 : 0, sbuf, additional ? 1 : 0);
00260 else
00261 fprintf(f, "setaux %d,re=%d,fe=%d,thr=%d,ext=%d,alt=%d\n",
00262 gpio-3, rising ? 1 : 0, falling ? 1:0, throttled ? 1 : 0, additional ? 1 : 0, altin ? 1 : 0);
00263 }
00264
00265 return true;
00266 }