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);
161 wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL);
162 hbox->Add(fgs, 1, wxALL | wxEXPAND, 15);
163 this->SetSizer(hbox);
166 setConfig(initialConfig);
171 BoardPanel::getConfig() const
175 // Try and keep unknown/unused fields as-is to support newer firmware
177 memcpy(&config, &myConfig, sizeof(config));
180 (myParityCtrl->IsChecked() ? S2S_CFG_ENABLE_PARITY : 0) |
181 (myUnitAttCtrl->IsChecked() ? S2S_CFG_ENABLE_UNIT_ATTENTION : 0) |
182 (myScsi2Ctrl->IsChecked() ? S2S_CFG_ENABLE_SCSI2 : 0) |
183 (mySelLatchCtrl->IsChecked() ? S2S_CFG_ENABLE_SEL_LATCH : 0) |
184 (myMapLunsCtrl->IsChecked() ? S2S_CFG_MAP_LUNS_TO_IDS : 0);
186 config.flags6 = (myTermCtrl->IsChecked() ? S2S_CFG_ENABLE_TERMINATOR : 0);
188 config.startupDelay = CtrlGetValue<unsigned int>(myStartDelayCtrl).first;
189 config.selectionDelay = CtrlGetValue<unsigned int>(mySelDelayCtrl).first;
190 config.scsiSpeed = myScsiSpeedCtrl->GetSelection();
195 BoardPanel::setConfig(const S2S_BoardCfg& config)
197 memcpy(&myConfig, &config, sizeof(config));
199 myParityCtrl->SetValue(config.flags & S2S_CFG_ENABLE_PARITY);
200 myUnitAttCtrl->SetValue(config.flags & S2S_CFG_ENABLE_UNIT_ATTENTION);
201 myScsi2Ctrl->SetValue(config.flags & S2S_CFG_ENABLE_SCSI2);
202 myTermCtrl->SetValue(config.flags6 & S2S_CFG_ENABLE_TERMINATOR);
203 mySelLatchCtrl->SetValue(config.flags & S2S_CFG_ENABLE_SEL_LATCH);
204 myMapLunsCtrl->SetValue(config.flags & S2S_CFG_MAP_LUNS_TO_IDS);
207 std::stringstream conv;
208 conv << static_cast<unsigned int>(config.startupDelay);
209 myStartDelayCtrl->ChangeValue(conv.str());
212 std::stringstream conv;
213 conv << static_cast<unsigned int>(config.selectionDelay);
214 mySelDelayCtrl->ChangeValue(conv.str());
216 myScsiSpeedCtrl->SetSelection(config.scsiSpeed);