1 // Copyright (C) 2015 Michael McMaster <michael@codesrc.com>
3 // This file is part of SCSI2SD.
5 // SCSI2SD is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // SCSI2SD is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with SCSI2SD. If not, see <http://www.gnu.org/licenses/>.
18 // For compilers that support precompilation, includes "wx/wx.h".
19 #include <wx/wxprec.h>
24 #include <wx/wrapsizer.h>
26 #include "ConfigUtil.hh"
27 #include "BoardPanel.hh"
35 using namespace SCSI2SD
;
39 template<typename IntType
, class WXCTRL
> std::pair
<IntType
, bool>
40 CtrlGetValue(WXCTRL
* ctrl
)
43 std::stringstream conv
;
44 conv
<< ctrl
->GetValue();
46 return std::make_pair(value
, static_cast<bool>(conv
));
51 BoardPanel::BoardPanel(wxWindow
* parent
, const S2S_BoardCfg
& initialConfig
) :
54 myDelayValidator(new wxIntegerValidator
<uint8_t>)
56 wxFlexGridSizer
*fgs
= new wxFlexGridSizer(13, 2, 9, 25);
58 fgs
->Add(new wxStaticText(this, wxID_ANY
, wxT("")));
63 _("Enable SCSI terminator"));
64 myTermCtrl
->SetToolTip(_("Enable active terminator. Both ends of the SCSI chain must be terminated."));
67 fgs
->Add(new wxStaticText(this, wxID_ANY
, _("SCSI Speed Limit")));
69 wxT("No limit (safe)"),
70 wxT("Async, 1.5MB/s"),
71 wxT("Async, 3.3MB/s"),
75 wxT("Turbo (less reliable)")};
83 sizeof(speeds
) / sizeof(wxString
),
86 myScsiSpeedCtrl
->SetToolTip(_("Limit SCSI interface speed"));
87 fgs
->Add(myScsiSpeedCtrl
);
89 fgs
->Add(new wxStaticText(this, wxID_ANY
, _("Startup Delay (seconds)")));
99 myStartDelayCtrl
->SetToolTip(_("Extra delay on power on, normally set to 0"));
100 fgs
->Add(myStartDelayCtrl
);
103 fgs
->Add(new wxStaticText(this, wxID_ANY
, _("SCSI Selection Delay (ms, 255 = auto)")));
113 mySelDelayCtrl
->SetToolTip(_("Delay before responding to SCSI selection. SCSI1 hosts usually require 1ms delay, however some require no delay"));
114 fgs
->Add(mySelDelayCtrl
);
116 fgs
->Add(new wxStaticText(this, wxID_ANY
, wxT("")));
122 myParityCtrl
->SetToolTip(_("Enable to require valid SCSI parity bits when receiving data. Some hosts don't provide parity. SCSI2SD always outputs valid parity bits."));
123 fgs
->Add(myParityCtrl
);
125 fgs
->Add(new wxStaticText(this, wxID_ANY
, wxT("")));
130 _("Enable Unit Attention"));
131 myUnitAttCtrl
->SetToolTip(_("Enable this to inform the host of changes after hot-swapping SD cards. Causes problems with Mac Plus."));
132 fgs
->Add(myUnitAttCtrl
);
134 fgs
->Add(new wxStaticText(this, wxID_ANY
, wxT("")));
139 _("Enable SCSI2 Mode"));
140 myScsi2Ctrl
->SetToolTip(_("Enable high-performance mode. May cause problems with SASI/SCSI1 hosts."));
141 fgs
->Add(myScsi2Ctrl
);
143 fgs
->Add(new wxStaticText(this, wxID_ANY
, wxT("")));
148 _("Respond to short SCSI selection pulses"));
149 mySelLatchCtrl
->SetToolTip(_("Respond to very short duration selection attempts. This supports non-standard hardware, but is generally safe to enable. Required for Philips P2000C."));
150 fgs
->Add(mySelLatchCtrl
);
152 fgs
->Add(new wxStaticText(this, wxID_ANY
, wxT("")));
157 _("Map LUNS to SCSI IDs"));
158 myMapLunsCtrl
->SetToolTip(_("Treat LUNS as IDs instead. Supports multiple drives on XEBEC S1410 SASI Bridge"));
159 fgs
->Add(myMapLunsCtrl
);
162 fgs
->Add(new wxStaticText(this, wxID_ANY
, wxT("")));
167 _("Enable Blind Writes"));
168 myBlindWriteCtrl
->SetToolTip(_("Enable writing to the SD card before all the SCSI data has been received."));
169 fgs
->Add(myBlindWriteCtrl
);
171 wxBoxSizer
* hbox
= new wxBoxSizer(wxHORIZONTAL
);
172 hbox
->Add(fgs
, 1, wxALL
| wxEXPAND
, 15);
173 this->SetSizer(hbox
);
176 setConfig(initialConfig
);
181 BoardPanel::getConfig() const
185 // Try and keep unknown/unused fields as-is to support newer firmware
187 memcpy(&config
, &myConfig
, sizeof(config
));
190 (myParityCtrl
->IsChecked() ? S2S_CFG_ENABLE_PARITY
: 0) |
191 (myUnitAttCtrl
->IsChecked() ? S2S_CFG_ENABLE_UNIT_ATTENTION
: 0) |
192 (myScsi2Ctrl
->IsChecked() ? S2S_CFG_ENABLE_SCSI2
: 0) |
193 (mySelLatchCtrl
->IsChecked() ? S2S_CFG_ENABLE_SEL_LATCH
: 0) |
194 (myMapLunsCtrl
->IsChecked() ? S2S_CFG_MAP_LUNS_TO_IDS
: 0);
196 config
.flags6
= (myTermCtrl
->IsChecked() ? S2S_CFG_ENABLE_TERMINATOR
: 0);
197 config
.flags6
= (myBlindWriteCtrl
->IsChecked() ? S2S_CFG_ENABLE_BLIND_WRITES
: 0);
199 config
.startupDelay
= CtrlGetValue
<unsigned int>(myStartDelayCtrl
).first
;
200 config
.selectionDelay
= CtrlGetValue
<unsigned int>(mySelDelayCtrl
).first
;
201 config
.scsiSpeed
= myScsiSpeedCtrl
->GetSelection();
206 BoardPanel::setConfig(const S2S_BoardCfg
& config
)
208 memcpy(&myConfig
, &config
, sizeof(config
));
210 myParityCtrl
->SetValue(config
.flags
& S2S_CFG_ENABLE_PARITY
);
211 myUnitAttCtrl
->SetValue(config
.flags
& S2S_CFG_ENABLE_UNIT_ATTENTION
);
212 myScsi2Ctrl
->SetValue(config
.flags
& S2S_CFG_ENABLE_SCSI2
);
213 myTermCtrl
->SetValue(config
.flags6
& S2S_CFG_ENABLE_TERMINATOR
);
214 myBlindWriteCtrl
->SetValue(config
.flags6
& S2S_CFG_ENABLE_BLIND_WRITES
);
215 mySelLatchCtrl
->SetValue(config
.flags
& S2S_CFG_ENABLE_SEL_LATCH
);
216 myMapLunsCtrl
->SetValue(config
.flags
& S2S_CFG_MAP_LUNS_TO_IDS
);
219 std::stringstream conv
;
220 conv
<< static_cast<unsigned int>(config
.startupDelay
);
221 myStartDelayCtrl
->ChangeValue(conv
.str());
224 std::stringstream conv
;
225 conv
<< static_cast<unsigned int>(config
.selectionDelay
);
226 mySelDelayCtrl
->ChangeValue(conv
.str());
228 myScsiSpeedCtrl
->SetSelection(config
.scsiSpeed
);