Skip to content

Commit 67e333c

Browse files
committed
Starting to interface with the devices a bit.
1 parent f770ed7 commit 67e333c

File tree

8 files changed

+190
-5
lines changed

8 files changed

+190
-5
lines changed

src/ftdi/abstract-ftd2xx-win32.cc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,44 @@
1717
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
1818
***************************************************************************/
1919

20+
#ifdef _WIN32
21+
22+
#define WIN32_LEAN_AND_MEAN
23+
#include "ftd2xx.h"
2024
#include "ftdi/abstract.h"
25+
26+
static std::vector<PCSX::FTDI::Device> s_devices;
27+
28+
void PCSX::FTDI::DeviceList::scan() {
29+
FT_STATUS status;
30+
DWORD numDevs = 0;
31+
32+
s_devices.clear();
33+
status = FT_CreateDeviceInfoList(&numDevs);
34+
35+
if (status != FT_OK || numDevs == 0) return;
36+
37+
FT_DEVICE_LIST_INFO_NODE* nodes = new FT_DEVICE_LIST_INFO_NODE[numDevs];
38+
39+
status = FT_GetDeviceInfoList(nodes, &numDevs);
40+
41+
if (status == FT_OK && numDevs != 0) {
42+
s_devices.resize(numDevs);
43+
for (DWORD i = 0; i < numDevs; i++) {
44+
const FT_DEVICE_LIST_INFO_NODE* n = nodes + i;
45+
s_devices[i].m_locked = n->Flags & FT_FLAGS_OPENED;
46+
s_devices[i].m_highSpeed = n->Flags & FT_FLAGS_HISPEED;
47+
s_devices[i].m_vendorID = (n->ID >> 16) & 0xffff;
48+
s_devices[i].m_deviceID = n->ID & 0xffff;
49+
s_devices[i].m_type = n->Type;
50+
s_devices[i].m_serial = n->SerialNumber;
51+
s_devices[i].m_description = n->Description;
52+
}
53+
}
54+
55+
delete[] nodes;
56+
}
57+
58+
const std::vector<PCSX::FTDI::Device>& PCSX::FTDI::DeviceList::get() { return s_devices; }
59+
60+
#endif

src/ftdi/abstract.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,46 @@
1818
***************************************************************************/
1919

2020
#pragma once
21+
22+
#include <stdint.h>
23+
24+
#include <string>
25+
#include <vector>
26+
27+
namespace PCSX {
28+
29+
namespace FTDI {
30+
31+
class DeviceList;
32+
class Device {
33+
public:
34+
bool isLocked() const { return m_locked; }
35+
bool isHighSpeed() const { return m_highSpeed; }
36+
uint16_t getVendorID() const { return m_vendorID; }
37+
uint16_t getDeviceID() const { return m_deviceID; }
38+
uint32_t getType() const { return m_type; }
39+
const std::string& getSerial() const { return m_serial; }
40+
const std::string& getDescription() const { return m_description; }
41+
42+
private:
43+
bool m_locked = false;
44+
bool m_highSpeed = false;
45+
uint16_t m_vendorID = 0;
46+
uint16_t m_deviceID = 0;
47+
uint32_t m_type = 0;
48+
std::string m_serial = "";
49+
std::string m_description = "";
50+
void* m_handle = nullptr;
51+
52+
friend class DeviceList;
53+
};
54+
55+
class DeviceList {
56+
public:
57+
static void scan();
58+
static const std::vector<Device>& get();
59+
};
60+
61+
} // namespace FTDI
62+
63+
} // namespace PCSX

src/gui/gui.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ void PCSX::GUI::endFrame() {
465465
ImGui::MenuItem(_("Show ImGui Demo"), nullptr, &m_showDemo);
466466
ImGui::Separator();
467467
ImGui::MenuItem(_("About"), nullptr, &m_showAbout);
468+
ImGui::MenuItem(_("FTDI"), nullptr, &m_showFTDI);
468469
ImGui::EndMenu();
469470
}
470471
ImGui::Separator();
@@ -572,6 +573,10 @@ void PCSX::GUI::endFrame() {
572573
m_breakpoints.draw(_("Breakpoints"));
573574
}
574575

576+
if (m_showFTDI) {
577+
m_ftdi.draw(_("FTDI"));
578+
}
579+
575580
about();
576581
biosCounters();
577582
interruptsScaler();

src/gui/gui.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,17 @@
2424

2525
#include <string>
2626

27-
#include "flags.h"
28-
29-
#include "imgui.h"
30-
#include "imgui_memory_editor/imgui_memory_editor.h"
31-
3227
#include "core/system.h"
28+
#include "flags.h"
3329
#include "gui/widgets/assembly.h"
3430
#include "gui/widgets/breakpoints.h"
3531
#include "gui/widgets/filedialog.h"
32+
#include "gui/widgets/ftdi.h"
3633
#include "gui/widgets/log.h"
3734
#include "gui/widgets/registers.h"
3835
#include "gui/widgets/vram-viewer.h"
36+
#include "imgui.h"
37+
#include "imgui_memory_editor/imgui_memory_editor.h"
3938
#include "main/settings.h"
4039

4140
#if defined(__MACOSX__)
@@ -132,6 +131,7 @@ class GUI final {
132131
bool m_showDemo = false;
133132
bool m_showAbout = false;
134133
bool m_showInterruptsScaler = false;
134+
bool m_showFTDI = false;
135135
Widgets::Log m_log = {settings.get<ShowLog>().value};
136136
struct MemoryEditorWrapper {
137137
MemoryEditorWrapper() {
@@ -173,6 +173,8 @@ class GUI final {
173173
Widgets::VRAMViewer m_clutVRAMviewer;
174174
Widgets::VRAMViewer m_VRAMviewers[4];
175175

176+
Widgets::FTDI m_ftdi = {m_showFTDI};
177+
176178
uv_loop_t m_loop;
177179
};
178180

src/gui/widgets/ftdi.cc

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/***************************************************************************
2+
* Copyright (C) 2020 PCSX-Redux authors *
3+
* *
4+
* This program is free software; you can redistribute it and/or modify *
5+
* it under the terms of the GNU General Public License as published by *
6+
* the Free Software Foundation; either version 2 of the License, or *
7+
* (at your option) any later version. *
8+
* *
9+
* This program is distributed in the hope that it will be useful, *
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12+
* GNU General Public License for more details. *
13+
* *
14+
* You should have received a copy of the GNU General Public License *
15+
* along with this program; if not, write to the *
16+
* Free Software Foundation, Inc., *
17+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
18+
***************************************************************************/
19+
20+
#include "gui/widgets/ftdi.h"
21+
22+
#include "core/system.h"
23+
#include "ftdi/abstract.h"
24+
25+
void PCSX::Widgets::FTDI::draw(const char* title) {
26+
if (!ImGui::Begin(title, &m_show)) {
27+
ImGui::End();
28+
return;
29+
}
30+
31+
if (ImGui::Button(_("Scan"))) ::PCSX::FTDI::DeviceList::scan();
32+
33+
auto& devices = ::PCSX::FTDI::DeviceList::get();
34+
35+
ImGui::Text((std::to_string(devices.size()) + " devices detected").c_str());
36+
ImGui::Separator();
37+
for (auto& d : devices) {
38+
ImGui::Text("Vendor Id: %04x", d.getVendorID());
39+
ImGui::Text("Device Id: %04x", d.getDeviceID());
40+
ImGui::Text("Type: %i", d.getType());
41+
ImGui::Text("Serial: %s", d.getSerial().c_str());
42+
ImGui::Text("Description: %s", d.getDescription().c_str());
43+
ImGui::Text("Locked: %s", d.isLocked() ? "true" : "false");
44+
ImGui::Text("High Speed: %s", d.isHighSpeed() ? "true" : "false");
45+
ImGui::Separator();
46+
}
47+
48+
ImGui::End();
49+
}

src/gui/widgets/ftdi.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/***************************************************************************
2+
* Copyright (C) 2020 PCSX-Redux authors *
3+
* *
4+
* This program is free software; you can redistribute it and/or modify *
5+
* it under the terms of the GNU General Public License as published by *
6+
* the Free Software Foundation; either version 2 of the License, or *
7+
* (at your option) any later version. *
8+
* *
9+
* This program is distributed in the hope that it will be useful, *
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12+
* GNU General Public License for more details. *
13+
* *
14+
* You should have received a copy of the GNU General Public License *
15+
* along with this program; if not, write to the *
16+
* Free Software Foundation, Inc., *
17+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
18+
***************************************************************************/
19+
20+
#pragma once
21+
22+
#include <stdarg.h>
23+
24+
#include "imgui.h"
25+
26+
namespace PCSX {
27+
namespace Widgets {
28+
29+
class FTDI {
30+
public:
31+
FTDI(bool& show) : m_show(show) {}
32+
void draw(const char* title);
33+
34+
bool& m_show;
35+
};
36+
37+
} // namespace Widgets
38+
} // namespace PCSX

vsprojects/gui/gui.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
<ClCompile Include="..\..\src\gui\widgets\assembly.cc" />
143143
<ClCompile Include="..\..\src\gui\widgets\breakpoints.cc" />
144144
<ClCompile Include="..\..\src\gui\widgets\filedialog.cc" />
145+
<ClCompile Include="..\..\src\gui\widgets\ftdi.cc" />
145146
<ClCompile Include="..\..\src\gui\widgets\log.cc" />
146147
<ClCompile Include="..\..\src\gui\widgets\registers.cc" />
147148
<ClCompile Include="..\..\src\gui\widgets\vram-viewer.cc" />
@@ -151,6 +152,7 @@
151152
<ClInclude Include="..\..\src\gui\widgets\assembly.h" />
152153
<ClInclude Include="..\..\src\gui\widgets\breakpoints.h" />
153154
<ClInclude Include="..\..\src\gui\widgets\filedialog.h" />
155+
<ClInclude Include="..\..\src\gui\widgets\ftdi.h" />
154156
<ClInclude Include="..\..\src\gui\widgets\log.h" />
155157
<ClInclude Include="..\..\src\gui\widgets\registers.h" />
156158
<ClInclude Include="..\..\src\gui\widgets\vram-viewer.h" />

vsprojects/gui/gui.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
<ClCompile Include="..\..\src\gui\widgets\vram-viewer.cc">
4343
<Filter>Source Files\widgets</Filter>
4444
</ClCompile>
45+
<ClCompile Include="..\..\src\gui\widgets\ftdi.cc">
46+
<Filter>Source Files\widgets</Filter>
47+
</ClCompile>
4548
</ItemGroup>
4649
<ItemGroup>
4750
<ClInclude Include="..\..\src\gui\gui.h">
@@ -68,6 +71,9 @@
6871
<ClInclude Include="..\..\src\gui\widgets\vram-viewer.h">
6972
<Filter>Header Files\widgets</Filter>
7073
</ClInclude>
74+
<ClInclude Include="..\..\src\gui\widgets\ftdi.h">
75+
<Filter>Header Files\widgets</Filter>
76+
</ClInclude>
7177
</ItemGroup>
7278
<ItemGroup>
7379
<None Include="packages.config" />

0 commit comments

Comments
 (0)