├── .github
└── FUNDING.yml
├── .gitignore
├── LICENSE
├── README.md
└── pico_xbox_wheel_adapter
├── pico_xbox_wheel_adapter.ino
├── wheel_ids.h
├── wheel_reports.h
├── xid.c
├── xid.h
├── xid_driver.c
├── xid_driver.h
├── xid_wheel.c
├── xid_wheel.h
├── xinput_host.c
└── xinput_host.h
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: sonik_br # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
13 | polar: # Replace with a single Polar username
14 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
15 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Ll]og/
33 | [Ll]ogs/
34 |
35 | # Visual Studio 2015/2017 cache/options directory
36 | .vs/
37 | # Uncomment if you have tasks that create the project's static files in wwwroot
38 | #wwwroot/
39 |
40 | # Visual Studio 2017 auto generated files
41 | Generated\ Files/
42 |
43 | # MSTest test Results
44 | [Tt]est[Rr]esult*/
45 | [Bb]uild[Ll]og.*
46 |
47 | # NUnit
48 | *.VisualState.xml
49 | TestResult.xml
50 | nunit-*.xml
51 |
52 | # Build Results of an ATL Project
53 | [Dd]ebugPS/
54 | [Rr]eleasePS/
55 | dlldata.c
56 |
57 | # Benchmark Results
58 | BenchmarkDotNet.Artifacts/
59 |
60 | # .NET Core
61 | project.lock.json
62 | project.fragment.lock.json
63 | artifacts/
64 |
65 | # ASP.NET Scaffolding
66 | ScaffoldingReadMe.txt
67 |
68 | # StyleCop
69 | StyleCopReport.xml
70 |
71 | # Files built by Visual Studio
72 | *_i.c
73 | *_p.c
74 | *_h.h
75 | *.ilk
76 | *.meta
77 | *.obj
78 | *.iobj
79 | *.pch
80 | *.pdb
81 | *.ipdb
82 | *.pgc
83 | *.pgd
84 | *.rsp
85 | *.sbr
86 | *.tlb
87 | *.tli
88 | *.tlh
89 | *.tmp
90 | *.tmp_proj
91 | *_wpftmp.csproj
92 | *.log
93 | *.tlog
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.)
298 | *.vbp
299 |
300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project)
301 | *.dsw
302 | *.dsp
303 |
304 | # Visual Studio 6 technical files
305 | *.ncb
306 | *.aps
307 |
308 | # Visual Studio LightSwitch build output
309 | **/*.HTMLClient/GeneratedArtifacts
310 | **/*.DesktopClient/GeneratedArtifacts
311 | **/*.DesktopClient/ModelManifest.xml
312 | **/*.Server/GeneratedArtifacts
313 | **/*.Server/ModelManifest.xml
314 | _Pvt_Extensions
315 |
316 | # Paket dependency manager
317 | .paket/paket.exe
318 | paket-files/
319 |
320 | # FAKE - F# Make
321 | .fake/
322 |
323 | # CodeRush personal settings
324 | .cr/personal
325 |
326 | # Python Tools for Visual Studio (PTVS)
327 | __pycache__/
328 | *.pyc
329 |
330 | # Cake - Uncomment if you are using it
331 | # tools/**
332 | # !tools/packages.config
333 |
334 | # Tabs Studio
335 | *.tss
336 |
337 | # Telerik's JustMock configuration file
338 | *.jmconfig
339 |
340 | # BizTalk build output
341 | *.btp.cs
342 | *.btm.cs
343 | *.odx.cs
344 | *.xsd.cs
345 |
346 | # OpenCover UI analysis results
347 | OpenCover/
348 |
349 | # Azure Stream Analytics local run output
350 | ASALocalRun/
351 |
352 | # MSBuild Binary and Structured Log
353 | *.binlog
354 |
355 | # NVidia Nsight GPU debugger configuration file
356 | *.nvuser
357 |
358 | # MFractors (Xamarin productivity tool) working folder
359 | .mfractor/
360 |
361 | # Local History for Visual Studio
362 | .localhistory/
363 |
364 | # Visual Studio History (VSHistory) files
365 | .vshistory/
366 |
367 | # BeatPulse healthcheck temp database
368 | healthchecksdb
369 |
370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
371 | MigrationBackup/
372 |
373 | # Ionide (cross platform F# VS Code tools) working folder
374 | .ionide/
375 |
376 | # Fody - auto-generated XML schema
377 | FodyWeavers.xsd
378 |
379 | # VS Code files for those working on multiple tools
380 | .vscode/*
381 | !.vscode/settings.json
382 | !.vscode/tasks.json
383 | !.vscode/launch.json
384 | !.vscode/extensions.json
385 | *.code-workspace
386 |
387 | # Local History for Visual Studio Code
388 | .history/
389 |
390 | # Windows Installer files from build outputs
391 | *.cab
392 | *.msi
393 | *.msix
394 | *.msm
395 | *.msp
396 |
397 | # JetBrains Rider
398 | *.sln.iml
399 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # xid_wheel_adapter
2 | A DIY adapter that can receive input from a logitech wheel and output as an (original/classic) Xbox (XID) wheel.
3 |
4 | As a bonus it will also make some xbox/xinput controllers work on the original xbox. Console will still see it as a wheel but most games will work.
5 |
6 | Supports rumble.
7 |
8 | ### PRs are welcome!
9 | There's some stuff that still needs to be added and some QoL improvements. Would also like to map rumble to some kind of FFB effect.
10 | Let me know if you can help.
11 |
12 | ## Supported devices
13 | * WingMan Formula GP (no rumble)
14 | * WingMan Formula Force GP (GT Force)
15 | * Driving Force
16 | * Driving Force Pro (GT Force Pro)
17 | * Driving Force GT
18 | * G25 Racing Wheel
19 | * G27 Racing Wheel
20 | * G29 Racing Wheel
21 | * G920 (XBOX) (no rumble)
22 | * Speed Force Wireless
23 |
24 | ## Mapping
25 | | Wheel | Xbox |
26 | |------------|-------------------|
27 | | Dpad | Dpad |
28 | | Wheel axis | Left stick X |
29 | | Gas axis | Right trigger |
30 | | Brake axis | Left trigger |
31 | | Select | Back |
32 | | Start | Start |
33 | | Cross, L1 | A |
34 | | Circle | B |
35 | | Square, R1 | X |
36 | | Triangle | Y |
37 | | L2 | Black |
38 | | R2 | White |
39 | | L3 | Left Stick click |
40 | | R3 | Right Stick click |
41 |
42 | It will map the paddle shifters as:
43 | Left paddle = A button (gear down)
44 | Right paddle = X button (gear up)
45 |
46 | Most xbox games uses this configuration. Seems to be the mode used by the Mad Catz MC2 Wheel.
47 |
48 | Notes:
49 | * Speed Force Wireless and Formula GP have less buttons than required by xbox.
50 | * Sometimes the adapter does not detect the G920 (XBOX). Connecting it to the adapter first, then to the console, seems to work all the time.
51 |
52 | ## Building
53 | Requires a Raspberry Pi Pico (RP2040) board and a USB Type-A port for input.
54 |
55 | Check the wiring guidance [here](https://github.com/sekigon-gonnoc/Pico-PIO-USB/discussions/7).
56 |
57 | USB Pins can be changed. Just need to set them in code.
58 |
59 | Define the `D+` pin on sketch. `D-` will be `D+` + 1.
60 |
61 | Required configuration are on the main sketch file as `PIN_USB_HOST_DP`
62 |
63 | Firmware builds under Arduino IDE.
64 |
65 | Required libs. Install using Arduino IDE.
66 |
67 | [arduino-pico (3.7.2)](https://github.com/earlephilhower/arduino-pico#installing-via-arduino-boards-manager)
68 | [Pico-PIO-USB (0.5.3)](https://github.com/sekigon-gonnoc/Pico-PIO-USB)
69 | [Adafruit_TinyUSB_Arduino (3.1.3)](https://github.com/adafruit/Adafruit_TinyUSB_Arduino)
70 |
71 | Configure IDE as:
72 | * Board: Raspberry Pi Pico
73 | * CPU Speed: 120MHz
74 | * USB Stack: Adafruit TinyUSB
75 |
76 | It's also needed to insert `#define CFG_TUH_XINPUT 1` on `tusb_config.h` on your Adafruit_TinyUSB_Arduino installed folder
77 |
78 | ## Ready to use binaries
79 | Don't want to build from source? Check the releases page.
80 |
81 | ## Credits
82 | Logitech USB input code from my other project.
83 | [lgff_wheel_adapter](https://github.com/sonik-br/lgff_wheel_adapter)
84 |
85 | Xbox (XINPUT/XID) input/output [ogx360_t4](https://github.com/Ryzee119/ogx360_t4) from Ryzee119.
86 |
87 | The [XID docs](https://xboxdevwiki.net/Xbox_Input_Devices) from xboxdevwiki.
88 |
89 | ## Disclaimer
90 |
91 | Code and wiring directions are provided to you 'as is' and without any warranties. Use at your own risk.
--------------------------------------------------------------------------------
/pico_xbox_wheel_adapter/pico_xbox_wheel_adapter.ino:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Racing Wheel to Xbox (XID) Adapter
3 | * By Matheus Fraguas (sonik-br)
4 | * https://github.com/sonik-br/xid_wheel_adapter
5 | *
6 | * It will also double as a genetic XINPUT adapter to XID
7 | *******************************************************************************/
8 |
9 | #include "pio_usb.h"
10 | #include "Adafruit_TinyUSB.h"
11 | #include "xinput_host.h"
12 | #include "xid.h"
13 | #include "xid_driver.h"
14 | #include "wheel_ids.h"
15 | #include "wheel_reports.h"
16 |
17 | // USB D+ pin
18 | // D- must be DP +1
19 | #define PIN_USB_HOST_DP 0
20 |
21 |
22 | #ifndef CFG_TUH_XINPUT
23 | #error CFG_TUH_XINPUT not enabled. define it at tusb_config.h
24 | #endif
25 |
26 | const uint8_t wheel_8bits = 0;
27 | const uint8_t wheel_10bits = 1;
28 | const uint8_t wheel_14bits = 2;
29 | const uint8_t wheel_16bits = 3;
30 |
31 | // report to hold input from any wheel
32 | generic_report_t generic_report;
33 |
34 | enum init_stage_status {
35 | CONFIGURING_DONGLE,
36 | SENDING_CMDS,
37 | READY
38 | };
39 |
40 | uint8_t mounted_dev = 0;
41 | uint8_t mounted_instance = 0;
42 | bool mounted_is_xinput = false;
43 | uint8_t mode_step = 0;
44 | uint8_t dongle_step = 0;
45 | init_stage_status init_stage = SENDING_CMDS;
46 | bool wheel_supports_cmd = false;
47 |
48 | USB_XboxWheel_InReport_t xpad_data;
49 |
50 | uint8_t xinput_out_rhport = 0;
51 | bool tud_xinput_ready();
52 |
53 | class Adafruit_USBD_XInput : public Adafruit_USBD_Interface {
54 | public:
55 | Adafruit_USBD_XInput();
56 | bool begin(void);
57 | virtual uint16_t getInterfaceDescriptor(uint8_t itfnum, uint8_t *buf, uint16_t bufsize);
58 | };
59 |
60 | Adafruit_USBD_XInput::Adafruit_USBD_XInput() { }
61 |
62 | bool Adafruit_USBD_XInput::begin(void) {
63 | if (!TinyUSBDevice.addInterface(*this)) {
64 | return false;
65 | }
66 |
67 | //TinyUSBDevice.setID(0x045E, 0x0289);
68 | TinyUSBDevice.setDeviceVersion(0x0100);
69 | TinyUSBDevice.setVersion(0x0110);
70 |
71 | return true;
72 | }
73 |
74 |
75 | uint16_t Adafruit_USBD_XInput::getInterfaceDescriptor(uint8_t itfnum_deprecated, uint8_t *buf, uint16_t bufsize) {
76 | uint8_t itfnum = 0;
77 | uint8_t ep_in = 0;
78 | uint8_t ep_out = 0;
79 |
80 | // null buffer is used to get the length of descriptor only
81 | if (buf) {
82 | itfnum = TinyUSBDevice.allocInterface(1);
83 | ep_out = TinyUSBDevice.allocEndpoint(TUSB_DIR_OUT);
84 | ep_in = TinyUSBDevice.allocEndpoint(TUSB_DIR_IN);
85 | }
86 |
87 | const uint8_t desc[] = { TUD_XID_WHEEL_DESCRIPTOR(itfnum, ep_out, ep_in) };
88 | const uint16_t len = sizeof(desc);
89 |
90 | if (bufsize < len)
91 | return 0;
92 |
93 | memcpy(buf, desc, len);
94 | return len;
95 | }
96 |
97 |
98 | Adafruit_USBH_Host USBHost;
99 |
100 | Adafruit_USBD_XInput *_xinput;
101 |
102 | void set_led(bool value) {
103 | #ifdef LED_BUILTIN
104 | gpio_put(LED_BUILTIN, value);
105 | #endif
106 | }
107 |
108 | void setup() {
109 | rp2040.enableDoubleResetBootloader();
110 | Serial.end();
111 |
112 | //Configure led pin
113 | #ifdef LED_BUILTIN
114 | gpio_init(LED_BUILTIN);
115 | gpio_set_dir(LED_BUILTIN, 1);
116 | gpio_put(LED_BUILTIN, LOW);
117 | #endif
118 |
119 |
120 | uint32_t cpu_hz = clock_get_hz(clk_sys);
121 | if ( cpu_hz != 120000000UL && cpu_hz != 240000000UL ) {
122 | while ( !Serial ) delay(10); // wait for native usb
123 | Serial.printf("Error: CPU Clock = %u, PIO USB require CPU clock must be multiple of 120 Mhz\r\n", cpu_hz);
124 | Serial.printf("Change your CPU Clock to either 120 or 240 Mhz in Menu->CPU Speed \r\n", cpu_hz);
125 | while (1) delay(1);
126 | }
127 |
128 | _xinput = new Adafruit_USBD_XInput();
129 |
130 | _xinput->begin();
131 | // while( !TinyUSBDevice.mounted() ) delay(1);
132 |
133 | memset(&xpad_data, 0x00, sizeof(xpad_data));
134 | xpad_data.bLength = sizeof(xpad_data);
135 |
136 |
137 | pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
138 | pio_cfg.pin_dp = PIN_USB_HOST_DP;
139 |
140 | #if defined(ARDUINO_RASPBERRY_PI_PICO_W)
141 | /* https://github.com/sekigon-gonnoc/Pico-PIO-USB/issues/46 */
142 | pio_cfg.sm_tx = 3;
143 | pio_cfg.sm_rx = 2;
144 | pio_cfg.sm_eop = 3;
145 | pio_cfg.pio_rx_num = 0;
146 | pio_cfg.pio_tx_num = 1;
147 | pio_cfg.tx_ch = 9;
148 | #endif /* ARDUINO_RASPBERRY_PI_PICO_W */
149 |
150 | USBHost.configure_pio_usb(1, &pio_cfg);
151 |
152 | // run host stack on controller (rhport) 1
153 | USBHost.begin(1);
154 | }
155 |
156 | void loop() {
157 | USBHost.task();
158 |
159 | uint8_t index = xid_get_index_by_type(0, XID_TYPE_WHEEL);
160 | static USB_XboxWheel_InReport_t last_xpad_data {0x00};
161 |
162 | if (memcmp(&last_xpad_data, &xpad_data, sizeof(xpad_data))) {
163 | memcpy(&last_xpad_data, &xpad_data, sizeof(xpad_data));
164 | if (xid_send_report_ready(index))
165 | {
166 | if (!xid_send_report(index, &xpad_data, sizeof(xpad_data))) {
167 | TU_LOG1("[USBD] Error sending OUT report\r\n");
168 | }
169 | }
170 | }
171 |
172 | USB_XboxWheel_OutReport_t xpad_rumble;
173 | static uint16_t old_rumble_l = 0;
174 | static uint16_t old_rumble_r = 0;
175 | if (xid_get_report(index, &xpad_rumble, sizeof(xpad_rumble))) {
176 | bool update_needed = false;
177 | if (xpad_rumble.lValue != old_rumble_l || xpad_rumble.rValue != old_rumble_r) {
178 | old_rumble_l = xpad_rumble.lValue;
179 | old_rumble_r = xpad_rumble.rValue;
180 | update_needed = true;
181 | }
182 | if (update_needed) {
183 | uint8_t l_rumble, r_rumble;
184 | l_rumble = xpad_rumble.lValue >> 8;
185 | r_rumble = xpad_rumble.rValue >> 8;
186 |
187 | //XBONE have rumble values of 0-100;
188 | if (mounted_is_xinput) {
189 | l_rumble = (uint32_t)l_rumble * 100 / 0xFF;
190 | r_rumble = (uint32_t)r_rumble * 100 / 0xFF;
191 |
192 | if (mounted_dev != 0)
193 | tuh_xinput_set_rumble(mounted_dev, mounted_instance, l_rumble, r_rumble, true);
194 | }
195 | }
196 | }
197 |
198 | // wheel connected
199 | if (mounted_dev && !mounted_is_xinput) {
200 | static uint32_t last_millis = 0;
201 |
202 | if (init_stage == CONFIGURING_DONGLE) { // initialize wii wireless dongle. todo check if command was success
203 | const uint8_t dongle_cmd_init_comm[] = { 0xAF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
204 | const uint8_t dongle_cmd_change_addr[] = { 0xB2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
205 | static uint8_t dongle_buffer[8] { 0x0 };
206 |
207 | if (last_millis == 0) { // force an initial delay
208 | last_millis = millis();
209 | } else if (millis() - last_millis > 200) { // delay commands. the dongle needs a longer delay than usual
210 | if (dongle_step == 0) {
211 | memcpy(dongle_buffer, dongle_cmd_init_comm, sizeof(dongle_buffer));
212 | if(tuh_hid_set_report(mounted_dev, mounted_instance, 0, HID_REPORT_TYPE_FEATURE, dongle_buffer, sizeof(dongle_buffer))) {
213 | ++dongle_step;
214 | }
215 | } else if(dongle_step == 1) {
216 | memcpy(dongle_buffer, dongle_cmd_change_addr, sizeof(dongle_buffer));
217 | dongle_buffer[1] = random(0, 255); // random address
218 | dongle_buffer[2] = random(0, 255);
219 | if(tuh_hid_set_report(mounted_dev, mounted_instance, 0, HID_REPORT_TYPE_FEATURE, dongle_buffer, sizeof(dongle_buffer))) {
220 | ++dongle_step;
221 | }
222 | } else {
223 | init_stage = SENDING_CMDS;
224 | }
225 | last_millis = millis();
226 | }
227 | } else if (init_stage == SENDING_CMDS) {
228 | // rumble command from logitech profiler
229 | const uint8_t cmd_mode[] = {
230 | 0x83, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // stop force
231 | 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // stop force
232 | 0xfe, 0x0d, 0x0c, 0x0c, 0x80, 0x00, 0x00, //default spring values
233 | 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //default spring on
234 | 0xf5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //default spring off
235 | //0xfe, 0x0d, 0x0c, 0x0c, 0x80, 0x00, 0x00, //default spring values
236 | //0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //default spring on
237 | 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //stop force
238 | 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //stop force
239 | 0xfe, 0x0d, 0x0c, 0x0c, 0x80, 0x00, 0x00, //default spring values
240 | 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 //default spring on
241 | //0xf5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 //default spring off
242 | };
243 | const uint8_t mode_cmd_length = 7;
244 | const uint8_t cmd_count = sizeof(cmd_mode) / mode_cmd_length;
245 |
246 | if (last_millis == 0) { // force an initial delay
247 | last_millis = millis();
248 | } else if (millis() - last_millis > 20) { // delay commands
249 | if (!wheel_supports_cmd) // skip commands
250 | mode_step = 255;
251 | if (mode_step < cmd_count) {
252 | if (tuh_hid_send_report(mounted_dev, mounted_instance, 0, &cmd_mode[7*(mode_step)], 7)) {
253 | ++mode_step;
254 | }
255 | }
256 | // after all initialization commands are sent, disconnect/reconnect the device to force host re-enumeration
257 | if (mode_step >= cmd_count) {
258 | last_millis == 0;
259 | init_stage = READY; // set next stage
260 |
261 | // no mode change was sent. wheel must be in native mode now. starts receiving inputs!
262 | tuh_hid_receive_report(mounted_dev, mounted_instance);
263 | return;
264 | }
265 | last_millis = millis();
266 | }
267 | } else { //ready to use
268 | // apply rumble effect
269 | const uint8_t rumble_min = 60;
270 | const uint8_t rumble_max = 90;
271 | const uint8_t force_update_interval_disable = 8;
272 | const uint8_t force_update_interval_slow = 48;
273 | const uint8_t force_update_interval_medium = 32;
274 | const uint8_t force_update_interval_fast = 16;
275 |
276 | static uint8_t rumble_force = rumble_min; // 1 to 127. 1 is maximum force
277 | static uint32_t last_rumble = 0;
278 | static bool last_rumble_direction = true;
279 | static uint8_t force_update_interval = force_update_interval_disable;
280 |
281 | static bool rumble_slow = false;
282 | static bool rumble_fast = false;
283 |
284 |
285 | rumble_slow = old_rumble_l >> 8;
286 | rumble_fast = old_rumble_r >> 8;
287 | uint8_t temp_force = max(xpad_rumble.lValue >> 8, xpad_rumble.rValue >> 8);
288 | rumble_force = map(temp_force, 0, 255, rumble_max, rumble_min); // 1 to 127. 1 is maximum force
289 |
290 | if (rumble_slow && rumble_fast)
291 | force_update_interval = force_update_interval_medium;
292 | else if (rumble_slow)
293 | force_update_interval = force_update_interval_slow;
294 | else if (rumble_fast)
295 | force_update_interval = force_update_interval_fast;
296 |
297 | static uint8_t cmd_buffer[7] { 0x00 };
298 | static uint8_t last_cmd_buffer[7] { 0x00 };
299 |
300 | if (rumble_slow || rumble_fast) {
301 | if (millis() - last_rumble > force_update_interval) {
302 | cmd_buffer[0] = 0x11; // download and play on slot 1
303 | cmd_buffer[1] = 0x08; // variable
304 | cmd_buffer[2] = (last_rumble_direction = !last_rumble_direction) ? -rumble_force: +rumble_force;
305 | cmd_buffer[3] = 0x80;
306 | // cmd_buffer[4] = 0x00;
307 | // cmd_buffer[5] = 0x00;
308 | // cmd_buffer[6] = 0x00;
309 | last_rumble = millis();
310 | }
311 | } else {
312 | if (millis() - last_rumble > force_update_interval_disable) {
313 | cmd_buffer[0] = 0x13; // stop
314 | cmd_buffer[1] = 0x00;
315 | cmd_buffer[2] = 0x00;
316 | cmd_buffer[3] = 0x00;
317 | // cmd_buffer[4] = 0x00;
318 | // cmd_buffer[5] = 0x00;
319 | // cmd_buffer[6] = 0x00;
320 | last_rumble = millis();
321 | }
322 | }
323 |
324 | // send command to device
325 | if (memcmp(last_cmd_buffer, cmd_buffer, sizeof(cmd_buffer))) {
326 | tuh_hid_send_report(mounted_dev, mounted_instance, 0, cmd_buffer, sizeof(cmd_buffer));
327 | memcpy(last_cmd_buffer, cmd_buffer, sizeof(cmd_buffer));
328 | }
329 |
330 | } // end if ready to use
331 | } // end if is a wheel
332 | }// end loop
333 |
334 |
335 | //usbh_class_driver_t const* usbh_app_driver_get_cb(uint8_t* driver_count){
336 | const usbh_class_driver_t *usbh_app_driver_get_cb(uint8_t *driver_count) {
337 | *driver_count = 1;
338 | return &usbh_xinput_driver;
339 | }
340 |
341 |
342 | void map_input(uint8_t const* report) {
343 | uint16_t vid, pid;
344 | tuh_vid_pid_get(mounted_dev, &vid, &pid);
345 |
346 | if (pid == pid_df) { // Driving Force. most logitech wheels will start in this mode
347 |
348 | // map the received report to the generic report
349 | df_report_t* input_report = (df_report_t*)report;
350 |
351 | generic_report.wheel_precision = wheel_10bits;
352 | generic_report.pedals_precision_16bits = false;
353 |
354 | generic_report.wheel_10 = input_report->wheel;
355 | generic_report.gasPedal_8 = input_report->gasPedal;
356 | generic_report.brakePedal_8 = input_report->brakePedal;
357 |
358 | generic_report.hat = input_report->hat;
359 | generic_report.cross = input_report->cross;
360 | generic_report.square = input_report->square;
361 | generic_report.circle = input_report->circle;
362 | generic_report.triangle = input_report->triangle;
363 | generic_report.R1 = input_report->R1;
364 | generic_report.L1 = input_report->L1;
365 | generic_report.R2 = input_report->R2;
366 | generic_report.L2 = input_report->L2;
367 | generic_report.R3 = input_report->R3;
368 | generic_report.L3 = input_report->L3;
369 | generic_report.select = input_report->select;
370 | generic_report.start = input_report->start;
371 |
372 | } else if (pid == pid_dfp) { // Driving Force Pro UNTESTED
373 |
374 | // map the received report to the generic report
375 | dfp_report_t* input_report = (dfp_report_t*)report;
376 |
377 | generic_report.wheel_precision = wheel_14bits;
378 | generic_report.pedals_precision_16bits = false;
379 |
380 | generic_report.wheel_14 = input_report->wheel;
381 | generic_report.gasPedal_8 = input_report->gasPedal;
382 | generic_report.brakePedal_8 = input_report->brakePedal;
383 |
384 | generic_report.hat = input_report->hat;
385 | generic_report.cross = input_report->cross;
386 | generic_report.square = input_report->square;
387 | generic_report.circle = input_report->circle;
388 | generic_report.triangle = input_report->triangle;
389 | generic_report.R1 = input_report->R1;
390 | generic_report.L1 = input_report->L1;
391 | generic_report.R2 = input_report->R2;
392 | generic_report.L2 = input_report->L2;
393 | generic_report.R3 = input_report->R3;
394 | generic_report.L3 = input_report->L3;
395 | generic_report.select = input_report->select;
396 | generic_report.start = input_report->start;
397 | generic_report.gear_minus = input_report->gear_minus;
398 | generic_report.gear_plus = input_report->gear_plus;
399 |
400 | } else if (pid == pid_dfgt) { // Driving Force GT
401 |
402 | // map the received report to the generic report
403 | dfgt_report_t* input_report = (dfgt_report_t*)report;
404 |
405 | generic_report.wheel_precision = wheel_14bits;
406 | generic_report.pedals_precision_16bits = false;
407 |
408 | generic_report.wheel_14 = input_report->wheel;
409 | generic_report.gasPedal_8 = input_report->gasPedal;
410 | generic_report.brakePedal_8 = input_report->brakePedal;
411 |
412 | generic_report.hat = input_report->hat;
413 | generic_report.cross = input_report->cross;
414 | generic_report.square = input_report->square;
415 | generic_report.circle = input_report->circle;
416 | generic_report.triangle = input_report->triangle;
417 | generic_report.R1 = input_report->R1;
418 | generic_report.L1 = input_report->L1;
419 | generic_report.R2 = input_report->R2;
420 | generic_report.L2 = input_report->L2;
421 | generic_report.R3 = input_report->R3;
422 | generic_report.L3 = input_report->L3;
423 | generic_report.select = input_report->select;
424 | generic_report.start = input_report->start;
425 | generic_report.gear_minus = input_report->gear_minus;
426 | generic_report.gear_plus = input_report->gear_plus;
427 | generic_report.dial_cw = input_report->dial_cw;
428 | generic_report.dial_ccw = input_report->dial_ccw;
429 | generic_report.enter = input_report->enter;
430 | generic_report.plus = input_report->plus;
431 | generic_report.minus = input_report->minus;
432 | generic_report.horn = input_report->horn;
433 | generic_report.PS = input_report->PS;
434 |
435 | } else if (pid == pid_g25) { // G25
436 |
437 | // map the received report to output report
438 | g25_report_t* input_report = (g25_report_t*)report;
439 |
440 | generic_report.wheel_precision = wheel_14bits;
441 | generic_report.pedals_precision_16bits = false;
442 |
443 | generic_report.wheel_14 = input_report->wheel;
444 | generic_report.gasPedal_8 = input_report->gasPedal;
445 | generic_report.brakePedal_8 = input_report->brakePedal;
446 | generic_report.clutchPedal_8 = input_report->clutchPedal;
447 |
448 | generic_report.hat = input_report->hat;
449 | generic_report.cross = input_report->cross;
450 | generic_report.square = input_report->square;
451 | generic_report.circle = input_report->circle;
452 | generic_report.triangle = input_report->triangle;
453 | generic_report.R1 = input_report->R1;
454 | generic_report.L1 = input_report->L1;
455 | generic_report.R2 = input_report->R2;
456 | generic_report.L2 = input_report->L2;
457 | generic_report.R3 = input_report->R3;
458 | generic_report.L3 = input_report->L3;
459 | generic_report.select = input_report->select;
460 | generic_report.start = input_report->start;
461 | generic_report.shifter_x = input_report->shifter_x;
462 | generic_report.shifter_y = input_report->shifter_y;
463 | generic_report.shifter_1 = input_report->shifter_1;
464 | generic_report.shifter_2 = input_report->shifter_2;
465 | generic_report.shifter_3 = input_report->shifter_3;
466 | generic_report.shifter_4 = input_report->shifter_4;
467 | generic_report.shifter_5 = input_report->shifter_5;
468 | generic_report.shifter_6 = input_report->shifter_6;
469 | generic_report.shifter_r = input_report->shifter_r;
470 | generic_report.shifter_stick_down = input_report->shifter_stick_down;
471 |
472 | } else if (pid == pid_g27) { // G27
473 |
474 | // map the received report to output report
475 | g27_report_t* input_report = (g27_report_t*)report;
476 |
477 | generic_report.wheel_precision = wheel_14bits;
478 | generic_report.pedals_precision_16bits = false;
479 |
480 | generic_report.wheel_14 = input_report->wheel;
481 | generic_report.gasPedal_8 = input_report->gasPedal;
482 | generic_report.brakePedal_8 = input_report->brakePedal;
483 | generic_report.clutchPedal_8 = input_report->clutchPedal;
484 |
485 | generic_report.hat = input_report->hat;
486 | generic_report.cross = input_report->cross;
487 | generic_report.square = input_report->square;
488 | generic_report.circle = input_report->circle;
489 | generic_report.triangle = input_report->triangle;
490 | generic_report.R1 = input_report->R1;
491 | generic_report.L1 = input_report->L1;
492 | generic_report.R2 = input_report->R2;
493 | generic_report.L2 = input_report->L2;
494 | generic_report.R3 = input_report->R3;
495 | generic_report.L3 = input_report->L3;
496 | generic_report.R4 = input_report->R4;
497 | generic_report.L4 = input_report->L4;
498 | generic_report.R5 = input_report->R5;
499 | generic_report.L5 = input_report->L5;
500 | generic_report.select = input_report->select;
501 | generic_report.start = input_report->start;
502 | generic_report.shifter_x = input_report->shifter_x;
503 | generic_report.shifter_y = input_report->shifter_y;
504 | generic_report.shifter_1 = input_report->shifter_1;
505 | generic_report.shifter_2 = input_report->shifter_2;
506 | generic_report.shifter_3 = input_report->shifter_3;
507 | generic_report.shifter_4 = input_report->shifter_4;
508 | generic_report.shifter_5 = input_report->shifter_5;
509 | generic_report.shifter_6 = input_report->shifter_6;
510 | generic_report.shifter_r = input_report->shifter_r;
511 | generic_report.shifter_stick_down = input_report->shifter_stick_down;
512 |
513 | } else if (pid == pid_g29) { // G29
514 |
515 | // map the received report to output report
516 | g29_report_t* input_report = (g29_report_t*)report;
517 |
518 | generic_report.wheel_precision = wheel_16bits;
519 | generic_report.pedals_precision_16bits = false;
520 |
521 | generic_report.wheel_16 = input_report->wheel;
522 | generic_report.gasPedal_8 = input_report->gasPedal;
523 | generic_report.brakePedal_8 = input_report->brakePedal;
524 | generic_report.clutchPedal_8 = input_report->clutchPedal;
525 |
526 | generic_report.hat = input_report->hat;
527 | generic_report.cross = input_report->cross;
528 | generic_report.square = input_report->square;
529 | generic_report.circle = input_report->circle;
530 | generic_report.triangle = input_report->triangle;
531 | generic_report.R1 = input_report->R1;
532 | generic_report.L1 = input_report->L1;
533 | generic_report.R2 = input_report->R2;
534 | generic_report.L2 = input_report->L2;
535 | generic_report.select = input_report->share;
536 | generic_report.start = input_report->options;
537 | generic_report.R3 = input_report->R3;
538 | generic_report.L3 = input_report->L3;
539 | generic_report.shifter_1 = input_report->shifter_1;
540 | generic_report.shifter_2 = input_report->shifter_2;
541 | generic_report.shifter_3 = input_report->shifter_3;
542 | generic_report.shifter_4 = input_report->shifter_4;
543 | generic_report.shifter_5 = input_report->shifter_5;
544 | generic_report.shifter_6 = input_report->shifter_6;
545 | generic_report.shifter_r = input_report->shifter_r;
546 | generic_report.plus = input_report->plus;
547 | generic_report.minus = input_report->minus;
548 | generic_report.dial_cw = input_report->dial_cw;
549 | generic_report.dial_ccw = input_report->dial_ccw;
550 | generic_report.enter = input_report->enter;
551 | generic_report.PS = input_report->PS;
552 | generic_report.shifter_x = input_report->shifter_x;
553 | generic_report.shifter_y = input_report->shifter_y;
554 | generic_report.shifter_stick_down = input_report->shifter_stick_down;
555 |
556 | } else if (pid == pid_fgp) { // Formula GP
557 |
558 | // map the received report to output report
559 | fgp_report_t* input_report = (fgp_report_t*)report;
560 |
561 | generic_report.wheel_precision = wheel_8bits;
562 | generic_report.pedals_precision_16bits = false;
563 |
564 | generic_report.wheel_8 = input_report->wheel;
565 | generic_report.gasPedal_8 = input_report->gasPedal;
566 | generic_report.brakePedal_8 = input_report->brakePedal;
567 |
568 | generic_report.hat = 0x8;
569 | generic_report.cross = input_report->cross;
570 | generic_report.square = input_report->square;
571 | generic_report.circle = input_report->circle;
572 | generic_report.triangle = input_report->triangle;
573 | generic_report.R1 = input_report->R1;
574 | generic_report.L1 = input_report->L1;
575 |
576 | } else if (pid == pid_ffgp) { // Formula Force GP
577 |
578 | // map the received report to output report
579 | ffgp_report_t* input_report = (ffgp_report_t*)report;
580 |
581 | generic_report.wheel_precision = wheel_10bits;
582 | generic_report.pedals_precision_16bits = false;
583 |
584 | generic_report.wheel_10 = input_report->wheel;
585 | generic_report.gasPedal_8 = input_report->gasPedal;
586 | generic_report.brakePedal_8 = input_report->brakePedal;
587 |
588 | generic_report.cross = input_report->cross;
589 | generic_report.square = input_report->square;
590 | generic_report.circle = input_report->circle;
591 | generic_report.triangle = input_report->triangle;
592 | generic_report.R1 = input_report->R1;
593 | generic_report.L1 = input_report->L1;
594 |
595 | } else if (pid == pid_sfw) { // Speed Force Wireless
596 |
597 | // map the received report to output report
598 | sfw_report_t* input_report = (sfw_report_t*)report;
599 |
600 | generic_report.wheel_precision = wheel_10bits;
601 | generic_report.pedals_precision_16bits = false;
602 |
603 | if (input_report->hat_u) {
604 | if (input_report->hat_l)
605 | generic_report.hat = 0x7;
606 | else if (input_report->hat_r)
607 | generic_report.hat = 0x1;
608 | else
609 | generic_report.hat = 0x0;
610 | } else if (input_report->hat_d) {
611 | if (input_report->hat_l)
612 | generic_report.hat = 0x5;
613 | else if (input_report->hat_r)
614 | generic_report.hat = 0x3;
615 | else
616 | generic_report.hat = 0x4;
617 | } else if (input_report->hat_l) {
618 | generic_report.hat = 0x6;
619 | } else if (input_report->hat_r) {
620 | generic_report.hat = 0x2;
621 | } else {
622 | generic_report.hat = 0x8;
623 | }
624 |
625 | generic_report.wheel_10 = input_report->wheel;
626 | generic_report.gasPedal_8 = input_report->gasPedal;
627 | generic_report.brakePedal_8 = input_report->brakePedal;
628 |
629 | generic_report.cross = input_report->b;
630 | generic_report.square = input_report->one;
631 | generic_report.circle = input_report->a;
632 | generic_report.triangle = input_report->two;
633 | generic_report.select = input_report->minus;
634 | generic_report.start = input_report->plus;
635 | generic_report.PS = input_report->home;
636 | }
637 | }
638 |
639 | void map_output() {
640 | // shift axis values
641 |
642 | int16_t wheel = 0;
643 | uint8_t gas;
644 | uint8_t brake;
645 |
646 | if (generic_report.wheel_precision == wheel_8bits) {
647 | wheel = map(generic_report.wheel_8, 0, UINT8_MAX, INT16_MIN, INT16_MAX);
648 | } else if (generic_report.wheel_precision == wheel_10bits) {
649 | wheel = map(generic_report.wheel_10, 0, 1023UL, INT16_MIN, INT16_MAX);
650 | } else if (generic_report.wheel_precision == wheel_14bits) {
651 | wheel = map(generic_report.wheel_14, 0, 16383UL, INT16_MIN, INT16_MAX);
652 | } else { // wheel_16bits
653 | wheel = map(generic_report.wheel_16, 0, UINT16_MAX, INT16_MIN, INT16_MAX);
654 | }
655 |
656 | if (generic_report.pedals_precision_16bits) {
657 | gas = generic_report.gasPedal_16 >> 8;
658 | brake = generic_report.brakePedal_16 >> 8;
659 | } else {
660 | gas = generic_report.gasPedal_8;
661 | brake = generic_report.brakePedal_8;
662 | }
663 |
664 | xpad_data.dButtons = 0;
665 |
666 | switch (generic_report.hat) {
667 | case 0x0:
668 | xpad_data.dButtons |= XID_DUP;
669 | break;
670 | case 0x1:
671 | xpad_data.dButtons |= XID_DUP;
672 | xpad_data.dButtons |= XID_DRIGHT;
673 | break;
674 | case 0x2:
675 | xpad_data.dButtons |= XID_DRIGHT;
676 | break;
677 | case 0x3:
678 | xpad_data.dButtons |= XID_DDOWN;
679 | xpad_data.dButtons |= XID_DRIGHT;
680 | break;
681 | case 0x4:
682 | xpad_data.dButtons |= XID_DDOWN;
683 | break;
684 | case 0x5:
685 | xpad_data.dButtons |= XID_DDOWN;
686 | xpad_data.dButtons |= XID_DLEFT;
687 | break;
688 | case 0x6:
689 | xpad_data.dButtons |= XID_DLEFT;
690 | break;
691 | case 0x7:
692 | xpad_data.dButtons |= XID_DUP;
693 | xpad_data.dButtons |= XID_DLEFT;
694 | break;
695 | default:
696 | break;
697 | }
698 |
699 | if (generic_report.start) xpad_data.dButtons |= XID_START;
700 | if (generic_report.select) xpad_data.dButtons |= XID_BACK;
701 | if (generic_report.L3) xpad_data.dButtons |= XID_LS;
702 | if (generic_report.R3) xpad_data.dButtons |= XID_RS;
703 |
704 | xpad_data.A = (generic_report.cross || generic_report.L1) ? 0xFF : 0; // gear down
705 | xpad_data.B = (generic_report.circle) ? 0xFF : 0;
706 | xpad_data.X = (generic_report.square || generic_report.R1) ? 0xFF : 0; // gear up
707 | xpad_data.Y = (generic_report.triangle) ? 0xFF : 0;
708 |
709 | xpad_data.BLACK = (generic_report.L2) ? 0xFF : 0;
710 | xpad_data.WHITE = (generic_report.R2) ? 0xFF : 0;
711 | xpad_data.L = ~brake;
712 | xpad_data.R = ~gas;
713 |
714 | xpad_data.leftStickX = wheel;
715 | xpad_data.leftStickY = 0;
716 |
717 | xpad_data.rightStickX = 0;
718 | xpad_data.rightStickY = 0;
719 | }
720 |
721 |
722 |
723 |
724 |
725 | void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t idx, uint8_t const* report_desc, uint16_t desc_len) {
726 | uint16_t vid;
727 | uint16_t pid;
728 | tuh_vid_pid_get(dev_addr, &vid, &pid);
729 |
730 | if ((vid == 0x046d) && ((pid & 0xff00) == 0xc200)) { // device is a logitech wheel
731 | set_led(HIGH);
732 |
733 | mode_step = 0;
734 | dongle_step = 0;
735 |
736 | wheel_supports_cmd = (pid != pid_fgp); // Formula GP
737 | // set next stage
738 | if (pid_sfw == pid)
739 | init_stage = CONFIGURING_DONGLE;
740 | else
741 | init_stage = SENDING_CMDS;
742 |
743 | mounted_dev = dev_addr;
744 | mounted_instance = idx;
745 | mounted_is_xinput = false;
746 |
747 | memset(&generic_report, 0, sizeof(generic_report));
748 | //tuh_hid_receive_report(dev_addr, idx);
749 | }
750 | }
751 |
752 | void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t idx) {
753 | set_led(LOW);
754 | mounted_dev = 0;
755 | mode_step = 0;
756 | dongle_step = 0;
757 | init_stage = SENDING_CMDS;
758 | }
759 |
760 | void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t idx, uint8_t const* report, uint16_t len) {
761 |
762 | // safe check
763 | if (len > 0 && dev_addr == mounted_dev && idx == mounted_instance) {
764 | // map the received report to generic_output
765 | map_input(report);
766 |
767 | // now map the generic_output to the output_mode
768 | map_output();
769 | }
770 |
771 | // receive next report
772 | tuh_hid_receive_report(dev_addr, idx);
773 | }
774 |
775 |
776 | void tuh_xinput_report_received_cb(uint8_t dev_addr, uint8_t instance, xinputh_interface_t const* xid_itf, uint16_t len) {
777 | const xinput_gamepad_t *p = &xid_itf->pad;
778 |
779 | if (xid_itf->last_xfer_result == XFER_RESULT_SUCCESS) {
780 |
781 | if (xid_itf->connected && xid_itf->new_pad_data) {
782 | xpad_data.dButtons = 0;
783 | if (p->wButtons & XINPUT_GAMEPAD_DPAD_UP) xpad_data.dButtons |= XID_DUP;
784 | if (p->wButtons & XINPUT_GAMEPAD_DPAD_DOWN) xpad_data.dButtons |= XID_DDOWN;
785 | if (p->wButtons & XINPUT_GAMEPAD_DPAD_LEFT) xpad_data.dButtons |= XID_DLEFT;
786 | if (p->wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) xpad_data.dButtons |= XID_DRIGHT;
787 | if (p->wButtons & XINPUT_GAMEPAD_START) xpad_data.dButtons |= XID_START;
788 | if (p->wButtons & XINPUT_GAMEPAD_BACK) xpad_data.dButtons |= XID_BACK;
789 | if (p->wButtons & XINPUT_GAMEPAD_LEFT_THUMB) xpad_data.dButtons |= XID_LS;
790 | if (p->wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) xpad_data.dButtons |= XID_RS;
791 |
792 | xpad_data.A = (p->wButtons & XINPUT_GAMEPAD_A) ? 0xFF : 0;
793 | xpad_data.B = (p->wButtons & XINPUT_GAMEPAD_B) ? 0xFF : 0;
794 | xpad_data.X = (p->wButtons & XINPUT_GAMEPAD_X) ? 0xFF : 0;
795 | xpad_data.Y = (p->wButtons & XINPUT_GAMEPAD_Y) ? 0xFF : 0;
796 |
797 | xpad_data.BLACK = (p->wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) ? 0xFF : 0;
798 | xpad_data.WHITE = (p->wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) ? 0xFF : 0;
799 | xpad_data.L = p->bLeftTrigger;
800 | xpad_data.R = p->bRightTrigger;
801 |
802 | xpad_data.leftStickX = p->sThumbLX;
803 | xpad_data.leftStickY = p->sThumbLY;
804 |
805 | xpad_data.rightStickX = p->sThumbRX;
806 | xpad_data.rightStickY = p->sThumbRY;
807 |
808 | uint16_t PID, VID;
809 | tuh_vid_pid_get(dev_addr, &VID, &PID);
810 | if (VID == 0x046d && PID == 0xc261) { // Logitech G920
811 | // limit the wheel rotation value
812 | const int16_t wheel_max = 7000L;
813 | const int16_t wheel_min = -wheel_max;
814 |
815 | int16_t wheel = p->sThumbLX;
816 | if (wheel > wheel_max)
817 | wheel = wheel_max;
818 | else if (wheel < wheel_min)
819 | wheel = wheel_min;
820 |
821 | xpad_data.leftStickX = map(wheel, wheel_min, wheel_max, INT16_MIN, INT16_MAX);
822 |
823 | // map the paddle shifters
824 | if (p->wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER)
825 | xpad_data.A = 0xFF;
826 | if (p->wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER)
827 | xpad_data.B = 0xFF;
828 |
829 | // clear those
830 | xpad_data.BLACK = 0;
831 | xpad_data.WHITE = 0;
832 | }
833 |
834 | }
835 | }
836 |
837 | tuh_xinput_receive_report(dev_addr, instance);
838 | }
839 |
840 | void tuh_xinput_mount_cb(uint8_t dev_addr, uint8_t instance, const xinputh_interface_t *xinput_itf) {
841 | set_led(HIGH);
842 | uint16_t PID, VID;
843 | tuh_vid_pid_get(dev_addr, &VID, &PID);
844 |
845 | // If this is a Xbox 360 Wireless controller we need to wait for a connection packet
846 | // on the in pipe before setting LEDs etc. So just start getting data until a controller is connected.
847 | if (xinput_itf->type == XBOX360_WIRELESS && xinput_itf->connected == false) {
848 | tuh_xinput_receive_report(dev_addr, instance);
849 | return;
850 | }
851 | tuh_xinput_set_led(dev_addr, instance, 0, true);
852 | tuh_xinput_set_led(dev_addr, instance, 1, true);
853 | tuh_xinput_set_rumble(dev_addr, instance, 0, 0, true);
854 | tuh_xinput_receive_report(dev_addr, instance);
855 | mounted_dev = dev_addr;
856 | mounted_instance = instance;
857 | mounted_is_xinput = true;
858 | }
859 |
860 | void tuh_xinput_umount_cb(uint8_t dev_addr, uint8_t instance) {
861 | set_led(LOW);
862 | mounted_dev = 0;
863 | }
864 |
865 |
866 | const usbd_class_driver_t *usbd_app_driver_get_cb(uint8_t *driver_count) {
867 | *driver_count = *driver_count + 1;
868 | return xid_get_driver();
869 | }
870 |
871 | bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request) {
872 | bool ret = false;
873 | ret |= xid_get_driver()->control_xfer_cb(rhport, stage, request);
874 | return ret;
875 | }
876 |
--------------------------------------------------------------------------------
/pico_xbox_wheel_adapter/wheel_ids.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | const uint16_t pid_fgp = 0xc20e;
4 | const uint16_t pid_ffgp = 0xc293;
5 | const uint16_t pid_df = 0xc294;
6 | const uint16_t pid_momo = 0xc295;
7 | const uint16_t pid_dfp = 0xc298;
8 | const uint16_t pid_g25 = 0xc299;
9 | const uint16_t pid_dfgt = 0xc29a;
10 | const uint16_t pid_g27 = 0xc29b;
11 | const uint16_t pid_g29 = 0xc24f;
12 | const uint16_t pid_sfw = 0xc29c;
13 |
--------------------------------------------------------------------------------
/pico_xbox_wheel_adapter/wheel_reports.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | // generic report
4 | typedef struct TU_ATTR_PACKED {
5 | uint8_t hat : 4;
6 | uint8_t cross : 1;
7 | uint8_t square : 1;
8 | uint8_t circle : 1;
9 | uint8_t triangle : 1;
10 |
11 | uint8_t R1 : 1;
12 | uint8_t L1 : 1;
13 | uint8_t R2 : 1;
14 | uint8_t L2 : 1;
15 | uint8_t R3 : 1;
16 | uint8_t L3 : 1;
17 | uint8_t R4 : 1;
18 | uint8_t L4 : 1;
19 |
20 | uint8_t R5 : 1;
21 | uint8_t L5 : 1;
22 | uint8_t select : 1;
23 | uint8_t start : 1;
24 | uint8_t horn : 1;
25 | uint8_t gear_plus : 1;
26 | uint8_t gear_minus : 1;
27 | uint8_t enter : 1;
28 |
29 | uint8_t shifter_1 : 1;
30 | uint8_t shifter_2 : 1;
31 | uint8_t shifter_3 : 1;
32 | uint8_t shifter_4 : 1;
33 | uint8_t shifter_5 : 1;
34 | uint8_t shifter_6 : 1;
35 | uint8_t shifter_r : 1;
36 | uint8_t shifter_stick_down : 1;
37 |
38 | uint8_t shifter_x;
39 | uint8_t shifter_y;
40 |
41 | uint8_t wheel_8;
42 | uint8_t gasPedal_8;
43 | uint8_t brakePedal_8;
44 | uint8_t clutchPedal_8;
45 |
46 | uint16_t gasPedal_16;
47 | uint16_t brakePedal_16;
48 | uint16_t clutchPedal_16;
49 |
50 | uint16_t wheel_16 : 16;
51 |
52 | uint16_t wheel_14 : 14;
53 | uint8_t dial_cw : 1;
54 | uint8_t dial_ccw : 1;
55 |
56 | uint16_t wheel_10 : 10;
57 | uint8_t PS : 1;
58 | uint8_t plus : 1;
59 | uint8_t minus : 1;
60 |
61 | uint8_t pedals_precision_16bits : 1; // pedals uses 16bits?
62 | //wheel_precision wheel_precision : 2; // wheel precision enum
63 | uint8_t wheel_precision : 2; // wheel precision
64 |
65 | } generic_report_t;
66 |
67 |
68 | // WingMan Formula GP
69 | typedef struct TU_ATTR_PACKED {
70 | uint8_t wheel;
71 |
72 | uint8_t : 2; // padding? alwats zero
73 | uint8_t L1 : 1;
74 | uint8_t R1 : 1;
75 | //no idea if the button mapping is correct.
76 | uint8_t square : 1; //top left. label X. GT3: rear view
77 | uint8_t triangle : 1; //top right. label Y. GT3: ebrakePedal
78 | uint8_t cross : 1; //lower left. label A. GT3: pause
79 | uint8_t circle : 1; //lower right. label B. GT3: reverse
80 |
81 | uint8_t pedals; // combined pedals?
82 | uint8_t gasPedal;
83 | uint8_t brakePedal;
84 | } fgp_report_t;
85 |
86 | // WingMan Formula Force GP (GT Force)
87 | typedef struct TU_ATTR_PACKED {
88 | uint16_t wheel : 10;
89 | uint8_t L1 : 1;
90 | uint8_t R1 : 1;
91 | //no idea if the button mapping is correct. labels are aligned with what shows on logitech tester
92 | uint8_t square : 1; //label X. GT3: rear view
93 | uint8_t triangle : 1; //label Y. GT3: ebrakePedal
94 | uint8_t cross : 1; //label A. GT3: pause
95 | uint8_t circle : 1; //label B. GT3: reverse
96 |
97 | uint8_t : 8; // unknown
98 | uint8_t pedals; // combined pedals?
99 | uint8_t gasPedal;
100 | uint8_t brakePedal;
101 | uint8_t : 8; // unknown
102 | } ffgp_report_t;
103 |
104 | // Driving Force
105 | typedef struct TU_ATTR_PACKED {
106 | uint16_t wheel : 10;
107 | uint8_t cross : 1;
108 | uint8_t square : 1;
109 | uint8_t circle : 1;
110 | uint8_t triangle : 1;
111 | uint8_t R1 : 1;
112 | uint8_t L1 : 1;
113 |
114 | uint8_t R2 : 1;
115 | uint8_t L2 : 1;
116 | uint8_t select : 1;
117 | uint8_t start : 1;
118 | uint8_t R3 : 1;
119 | uint8_t L3 : 1;
120 | uint8_t pedal_connected : 1; // not sure
121 | uint8_t power_connected : 1; //not sure
122 |
123 | uint8_t pedals; // combined pedals
124 | uint8_t hat : 4;
125 | uint8_t : 1; // allways 0
126 | uint8_t calibated : 1; //not sure (or ready to use?)
127 | uint8_t : 1; // allways 0
128 | uint8_t unknown : 1; // allways 1
129 | uint8_t gasPedal;
130 | uint8_t brakePedal;
131 | } df_report_t;
132 |
133 | // Driving Force Pro (GT Force Pro)
134 | typedef struct TU_ATTR_PACKED {
135 | uint16_t wheel : 14;
136 | uint8_t cross : 1;
137 | uint8_t square : 1;
138 |
139 | uint8_t circle : 1;
140 | uint8_t triangle : 1;
141 | uint8_t R1 : 1;
142 | uint8_t L1 : 1;
143 | uint8_t R2 : 1;
144 | uint8_t L2 : 1;
145 | uint8_t select : 1;
146 | uint8_t start : 1;
147 |
148 | uint8_t R3 : 1;
149 | uint8_t L3 : 1;
150 | uint8_t gear_plus : 1;
151 | uint8_t gear_minus : 1;
152 | uint8_t hat : 4;
153 |
154 | uint8_t pedals; //combined pedals
155 | uint8_t gasPedal;
156 | uint8_t brakePedal;
157 |
158 | uint8_t pedal_connected : 1;
159 | uint8_t power_connected : 1;
160 | uint8_t : 1; // always 0
161 | uint8_t calibated : 1; //not sure (or ready to use?)
162 | uint8_t unknown : 4; //always 1
163 | } dfp_report_t;
164 |
165 | // Driving Force GT
166 | typedef struct TU_ATTR_PACKED {
167 | uint8_t hat : 4;
168 | uint8_t cross : 1;
169 | uint8_t square : 1;
170 | uint8_t circle : 1;
171 | uint8_t triangle : 1;
172 |
173 | uint8_t R1 : 1;
174 | uint8_t L1 : 1;
175 | uint8_t R2 : 1;
176 | uint8_t L2 : 1;
177 | uint8_t select : 1;
178 | uint8_t start : 1;
179 | uint8_t R3 : 1;
180 | uint8_t L3 : 1;
181 |
182 | uint8_t gear_plus : 1;
183 | uint8_t gear_minus : 1;
184 | uint8_t enter : 1;
185 | uint8_t plus : 1;
186 | uint8_t dial_cw : 1;
187 | uint8_t dial_ccw : 1;
188 | uint8_t minus : 1;
189 | uint8_t horn : 1;
190 |
191 | uint8_t PS : 1;
192 | uint8_t pedal_connected : 1;
193 | uint8_t power_connected : 1;
194 | uint8_t calibated : 1; //not sure (or ready to use?)
195 | uint8_t unknown: 4; //always 0x5?
196 |
197 | uint16_t wheel : 16; //looks to be 14 bits. what could be the two other bits?
198 | uint8_t gasPedal;
199 | uint8_t brakePedal;
200 | } dfgt_report_t;
201 |
202 | //G25 Racing Wheel
203 | typedef struct TU_ATTR_PACKED {
204 | uint8_t hat : 4;
205 | uint8_t cross : 1;
206 | uint8_t square : 1;
207 | uint8_t circle : 1;
208 | uint8_t triangle : 1;
209 |
210 | uint8_t R1 : 1;
211 | uint8_t L1 : 1;
212 | uint8_t R2 : 1;
213 | uint8_t L2 : 1;
214 |
215 | uint8_t select : 1;
216 | uint8_t start : 1;
217 | uint8_t R3 : 1;
218 | uint8_t L3 : 1;
219 |
220 | uint8_t shifter_1 : 1;
221 | uint8_t shifter_2 : 1;
222 | uint8_t shifter_3 : 1;
223 | uint8_t shifter_4 : 1;
224 | uint8_t shifter_5 : 1;
225 | uint8_t shifter_6 : 1;
226 | uint8_t shifter_r : 1;
227 | uint8_t : 1; // shifter mode? 0 = H, 1 = Sequential
228 |
229 | uint8_t pedal_disconnected : 1;
230 | uint8_t power_connected : 1; //(power or calibrated? , not sure)
231 | uint16_t wheel : 14; // test!
232 |
233 | uint8_t gasPedal;
234 | uint8_t brakePedal;
235 | uint8_t clutchPedal;
236 |
237 | uint8_t shifter_x;
238 | uint8_t shifter_y;
239 |
240 | uint8_t shifter : 1;
241 | uint8_t unknown : 1; //always 1
242 | uint8_t : 1; //always 0
243 | uint8_t shifter_stick_down : 1;
244 | uint8_t : 1; //always 0
245 | uint8_t : 1; //always 0
246 | uint8_t : 1; //always 0
247 | uint8_t : 1; //always 0
248 |
249 | } g25_report_t;
250 |
251 | //G27 Racing Wheel
252 | typedef struct TU_ATTR_PACKED {
253 | uint8_t hat : 4;
254 | uint8_t cross : 1;
255 | uint8_t square : 1;
256 | uint8_t circle : 1;
257 | uint8_t triangle : 1;
258 |
259 | uint8_t R1 : 1;
260 | uint8_t L1 : 1;
261 | uint8_t R2 : 1;
262 | uint8_t L2 : 1;
263 | uint8_t select : 1;
264 | uint8_t start : 1;
265 | uint8_t R3 : 1;
266 | uint8_t L3 : 1;
267 |
268 | uint8_t shifter_1 : 1;
269 | uint8_t shifter_2 : 1;
270 | uint8_t shifter_3 : 1;
271 | uint8_t shifter_4 : 1;
272 | uint8_t shifter_5 : 1;
273 | uint8_t shifter_6 : 1;
274 | uint8_t R4 : 1;
275 | uint8_t R5 : 1;
276 |
277 | uint8_t L4 : 1;
278 | uint8_t L5 : 1;
279 | uint16_t wheel : 14;
280 |
281 | uint8_t gasPedal;
282 | uint8_t brakePedal;
283 | uint8_t clutchPedal;
284 |
285 | uint8_t shifter_x;
286 | uint8_t shifter_y;
287 |
288 | uint8_t shifter_r : 1;
289 | uint8_t pedal_disconnected : 1;
290 | uint8_t calibrated : 1; // not sure
291 | uint8_t shifter_connected : 1;
292 | uint8_t unknown: 1; //always 1
293 | uint8_t : 1; //always 0
294 | uint8_t shifter_stick_down : 1;
295 | uint8_t : 1; // always 0
296 |
297 | } g27_report_t;
298 |
299 | //G29 Racing Wheel (PS3/PS4 switch set to "PS3")
300 | typedef struct TU_ATTR_PACKED {
301 | // byte 1: hat/buttons
302 | uint8_t hat : 4;
303 | uint8_t cross : 1;
304 | uint8_t square : 1;
305 | uint8_t circle : 1;
306 | uint8_t triangle : 1;
307 |
308 | uint8_t R1 : 1;
309 | uint8_t L1 : 1;
310 | uint8_t R2 : 1;
311 | uint8_t L2 : 1;
312 | uint8_t share : 1;
313 | uint8_t options : 1;
314 | uint8_t R3 : 1;
315 | uint8_t L3 : 1;
316 |
317 | uint8_t shifter_1 : 1;
318 | uint8_t shifter_2 : 1;
319 | uint8_t shifter_3 : 1;
320 | uint8_t shifter_4 : 1;
321 | uint8_t shifter_5 : 1;
322 | uint8_t shifter_6 : 1;
323 | uint8_t shifter_r : 1;
324 | uint8_t plus : 1;
325 |
326 | uint8_t minus : 1;
327 | uint8_t dial_cw : 1;
328 | uint8_t dial_ccw : 1;
329 | uint8_t enter : 1;
330 | uint8_t PS : 1;
331 | uint8_t : 3; // unknown
332 |
333 | uint16_t wheel : 16;
334 |
335 | uint8_t gasPedal;
336 | uint8_t brakePedal;
337 | uint8_t clutchPedal;
338 |
339 | uint8_t shifter_x;
340 | uint8_t shifter_y;
341 |
342 | uint8_t : 6; // unknown
343 | uint8_t shifter_stick_down : 1;
344 | uint8_t : 1; // unknown
345 |
346 | } g29_report_t;
347 |
348 | //Speed Force Wireless (WII)
349 | typedef struct TU_ATTR_PACKED {
350 | uint16_t wheel : 10;
351 | uint8_t : 2; // vendor. allways 0x2
352 | uint8_t hat_l : 1;
353 | uint8_t hat_r : 1;
354 | uint8_t hat_d : 1;
355 | uint8_t hat_u : 1;
356 |
357 | uint8_t plus : 1;
358 | uint8_t two : 1;
359 | uint8_t one : 1;
360 | uint8_t b : 1;
361 | uint8_t a : 1;
362 | uint8_t minus : 1;
363 | uint8_t home : 1;
364 | uint8_t connected : 1; // 0 when not connecded? or not paired?
365 |
366 | uint8_t gasPedal; // right paddle (released 0xff, pressed 0x00)
367 | uint8_t brakePedal; // left paddle (released 0xff, pressed 0x00)
368 | } sfw_report_t;
369 |
--------------------------------------------------------------------------------
/pico_xbox_wheel_adapter/xid.c:
--------------------------------------------------------------------------------
1 | #include "xid.h"
2 |
3 | bool wheel_control_xfer(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request, xid_interface_t *p_xid);
4 |
5 | #define MAX_XIDS (XID_WHEEL)
6 |
7 | CFG_TUSB_MEM_SECTION static xid_interface_t _xid_itf[MAX_XIDS];
8 |
9 | static inline int8_t get_index_by_itfnum(uint8_t itf_num)
10 | {
11 | for (uint8_t i = 0; i < MAX_XIDS; i++)
12 | {
13 | if (itf_num == _xid_itf[i].itf_num)
14 | return i;
15 | }
16 | return -1;
17 | }
18 |
19 | static inline int8_t get_index_by_ep_addr(uint8_t ep_addr)
20 | {
21 | for (uint8_t i = 0; i < MAX_XIDS; i++)
22 | {
23 | if (ep_addr == _xid_itf[i].ep_in)
24 | return i;
25 |
26 | if (ep_addr == _xid_itf[i].ep_out)
27 | return i;
28 | }
29 | return -1;
30 | }
31 |
32 | static inline xid_interface_t *find_available_interface()
33 | {
34 | for (uint8_t i = 0; i < MAX_XIDS; i++)
35 | {
36 | if (_xid_itf[i].ep_in == 0)
37 | return &_xid_itf[i];
38 | }
39 | return NULL;
40 | }
41 |
42 | static void xid_init(void)
43 | {
44 | tu_memclr(_xid_itf, sizeof(_xid_itf));
45 | for (uint8_t i = 0; i < MAX_XIDS; i++)
46 | {
47 | _xid_itf[i].type = (i < (XID_WHEEL)) ? XID_TYPE_WHEEL : 0xFF;
48 | }
49 | }
50 |
51 | static void xid_reset(uint8_t rhport)
52 | {
53 | xid_init();
54 | }
55 |
56 | static uint16_t xid_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len)
57 | {
58 | TU_VERIFY(itf_desc->bInterfaceClass == XID_INTERFACE_CLASS, 0);
59 | TU_VERIFY(itf_desc->bInterfaceSubClass == XID_INTERFACE_SUBCLASS, 0);
60 |
61 | xid_interface_t *p_xid = find_available_interface();
62 | TU_ASSERT(p_xid != NULL, 0);
63 |
64 | uint16_t const drv_len = (p_xid->type == XID_TYPE_WHEEL) ? TUD_XID_WHEEL_DESC_LEN : 0;
65 | TU_ASSERT(max_len >= drv_len, 0);
66 |
67 | p_xid->itf_num = itf_desc->bInterfaceNumber;
68 | p_xid->rhport = rhport;
69 |
70 | tusb_desc_endpoint_t *ep_desc;
71 | ep_desc = (tusb_desc_endpoint_t *)tu_desc_next(itf_desc);
72 | if (tu_desc_type(ep_desc) == TUSB_DESC_ENDPOINT)
73 | {
74 | usbd_edpt_open(rhport, ep_desc);
75 | (ep_desc->bEndpointAddress & 0x80) ? (p_xid->ep_in = ep_desc->bEndpointAddress) :
76 | (p_xid->ep_out = ep_desc->bEndpointAddress);
77 | }
78 |
79 | TU_VERIFY(itf_desc->bNumEndpoints >= 2, drv_len);
80 | ep_desc = (tusb_desc_endpoint_t *)tu_desc_next(ep_desc);
81 | if (tu_desc_type(ep_desc) == TUSB_DESC_ENDPOINT)
82 | {
83 | usbd_edpt_open(rhport, ep_desc);
84 | (ep_desc->bEndpointAddress & 0x80) ? (p_xid->ep_in = ep_desc->bEndpointAddress) :
85 | (p_xid->ep_out = ep_desc->bEndpointAddress);
86 | }
87 |
88 | return drv_len;
89 | }
90 |
91 | int8_t xid_get_index_by_type(uint8_t type_index, xid_type_t type)
92 | {
93 | uint8_t _type_index = 0;
94 | for (uint8_t i = 0; i < MAX_XIDS; i++)
95 | {
96 | if (_xid_itf[i].type == type)
97 | {
98 | if (_type_index == type_index)
99 | return i;
100 | _type_index++;
101 | }
102 | }
103 | return -1;
104 | }
105 |
106 | bool xid_get_report(uint8_t index, void *report, uint16_t len)
107 | {
108 | TU_VERIFY(index < MAX_XIDS, false);
109 | TU_VERIFY(_xid_itf[index].ep_out != 0, false);
110 | TU_VERIFY(len < XID_MAX_PACKET_SIZE, false);
111 |
112 | memcpy(report, _xid_itf[index].out, len);
113 |
114 | //Queue request on out endpoint
115 | //Most games send to control pipe, but some send to out pipe. THPSX2 atleast
116 | if (tud_ready() && !usbd_edpt_busy(_xid_itf[index].rhport, _xid_itf[index].ep_out))
117 | {
118 | usbd_edpt_xfer(_xid_itf[index].rhport, _xid_itf[index].ep_out, _xid_itf[index].ep_out_buff, len);
119 | }
120 | return true;
121 | }
122 |
123 | bool xid_send_report_ready(uint8_t index)
124 | {
125 | TU_VERIFY(index < MAX_XIDS, false);
126 | TU_VERIFY(_xid_itf[index].ep_in != 0, false);
127 | return (tud_ready() && !usbd_edpt_busy(_xid_itf[index].rhport, _xid_itf[index].ep_in));
128 | }
129 | bool xid_send_report(uint8_t index, void *report, uint16_t len)
130 | {
131 | TU_VERIFY(len < XID_MAX_PACKET_SIZE, false);
132 | TU_VERIFY(index < MAX_XIDS, false);
133 | TU_VERIFY(_xid_itf[index].ep_in != 0, false);
134 | TU_VERIFY(xid_send_report_ready(index), false);
135 |
136 | if (tud_suspended())
137 | tud_remote_wakeup();
138 |
139 | //Maintain a local copy of the report
140 | memcpy(_xid_itf[index].in, report, len);
141 |
142 | //Send it to the host
143 | return usbd_edpt_xfer(_xid_itf[index].rhport, _xid_itf[index].ep_in, _xid_itf[index].in, len);
144 | }
145 |
146 | static bool xid_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
147 | {
148 | (void)rhport;
149 | uint8_t index = get_index_by_ep_addr(ep_addr);
150 |
151 | TU_VERIFY(result == XFER_RESULT_SUCCESS, true);
152 | TU_VERIFY(index != -1, true);
153 | TU_VERIFY(xferred_bytes < XID_MAX_PACKET_SIZE, true);
154 |
155 | if (ep_addr == _xid_itf[index].ep_out)
156 | {
157 | memcpy(_xid_itf[index].out, _xid_itf[index].ep_out_buff, MIN(xferred_bytes, sizeof( _xid_itf[index].ep_out_buff)));
158 | }
159 |
160 | return true;
161 | }
162 |
163 | bool xid_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request)
164 | {
165 | TU_VERIFY(request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_INTERFACE);
166 |
167 | uint8_t index = get_index_by_itfnum((uint8_t)request->wIndex);
168 | TU_VERIFY(index != -1, false);
169 |
170 | bool ret = false;
171 |
172 | //Get HID Report
173 | if (request->bmRequestType == 0xA1 && request->bRequest == 0x01 && request->wValue == 0x0100)
174 | {
175 | if (stage == CONTROL_STAGE_SETUP)
176 | {
177 | TU_LOG1("Sending HID report on control pipe for index %02x\n", request->wIndex);
178 | tud_control_xfer(rhport, request, _xid_itf[index].in, MIN(request->wLength, sizeof(_xid_itf[index].in)));
179 | }
180 | return true;
181 | }
182 |
183 | //Set HID Report (Rumble)
184 | if (request->bmRequestType == 0x21 && request->bRequest == 0x09 && request->wValue == 0x0200 && request->wLength == 0x06)
185 | {
186 | if (stage == CONTROL_STAGE_SETUP)
187 | {
188 | //Host is sending a rumble command to control pipe. Queue receipt.
189 | tud_control_xfer(rhport, request, _xid_itf[index].ep_out_buff, MIN(request->wLength, sizeof(_xid_itf[index].ep_out_buff)));
190 | }
191 | else if (stage == CONTROL_STAGE_ACK)
192 | {
193 | //Receipt complete. Copy data to rumble struct
194 | TU_LOG1("Got HID report from control pipe for index %02x\n", request->wIndex);
195 | memcpy(_xid_itf[index].out, _xid_itf[index].ep_out_buff, MIN(request->wLength, sizeof(_xid_itf[index].out)));
196 | }
197 | return true;
198 | }
199 |
200 | switch (_xid_itf[index].type)
201 | {
202 | case XID_TYPE_WHEEL:
203 | ret = wheel_control_xfer(rhport, stage, request, &_xid_itf[index]);
204 | break;
205 | default:
206 | break;
207 | }
208 |
209 | if (ret == false)
210 | {
211 | TU_LOG1("STALL: wIndex: %02x bmRequestType: %02x, bRequest: %02x, wValue: %04x\n",
212 | request->wIndex,
213 | request->bmRequestType,
214 | request->bRequest,
215 | request->wValue);
216 | return false;
217 | }
218 |
219 | return true;
220 | }
221 |
222 | static const usbd_class_driver_t xid_driver =
223 | {
224 | #if CFG_TUSB_DEBUG >= 2
225 | .name = "XID DRIVER",
226 | #endif
227 | .init = xid_init,
228 | .reset = xid_reset,
229 | .open = xid_open,
230 | .control_xfer_cb = xid_control_xfer_cb,
231 | .xfer_cb = xid_xfer_cb,
232 | .sof = NULL
233 | };
234 |
235 | const usbd_class_driver_t *xid_get_driver()
236 | {
237 | return &xid_driver;
238 | }
239 |
--------------------------------------------------------------------------------
/pico_xbox_wheel_adapter/xid.h:
--------------------------------------------------------------------------------
1 | #ifndef XID_H_
2 | #define XID_H_
3 |
4 | #ifdef __cplusplus
5 | extern "C"
6 | {
7 | #endif
8 |
9 | #include
10 | #include
11 | #include
12 | #include "xid_wheel.h"
13 |
14 | #define XID_WHEEL 1
15 |
16 | #define XID_INTERFACE_CLASS 0x58
17 | #define XID_INTERFACE_SUBCLASS 0x42
18 | #define XID_MAX_PACKET_SIZE 32
19 |
20 | typedef enum
21 | {
22 | XID_TYPE_WHEEL,
23 | } xid_type_t;
24 |
25 | typedef struct
26 | {
27 | uint8_t itf_num;
28 | xid_type_t type;
29 | uint8_t ep_in;
30 | uint8_t ep_out;
31 | uint8_t rhport;
32 | CFG_TUSB_MEM_ALIGN uint8_t ep_out_buff[XID_MAX_PACKET_SIZE];
33 | CFG_TUSB_MEM_ALIGN uint8_t in[XID_MAX_PACKET_SIZE];
34 | CFG_TUSB_MEM_ALIGN uint8_t out[XID_MAX_PACKET_SIZE];
35 | } xid_interface_t;
36 |
37 | int8_t xid_get_index_by_type(uint8_t type_index, xid_type_t type);
38 | bool xid_get_report(uint8_t index, void *report, uint16_t len);
39 | bool xid_send_report_ready(uint8_t index);
40 | bool xid_send_report(uint8_t index, void *report, uint16_t len);
41 | const usbd_class_driver_t *xid_get_driver();
42 |
43 | #ifdef __cplusplus
44 | }
45 | #endif
46 |
47 | #endif //XID_H_
48 |
--------------------------------------------------------------------------------
/pico_xbox_wheel_adapter/xid_driver.c:
--------------------------------------------------------------------------------
1 | #include "xid.h"
2 | #include "xid_driver.h"
3 |
4 | uint8_t *xremote_get_rom()
5 | {
6 | return NULL;
7 | }
8 |
--------------------------------------------------------------------------------
/pico_xbox_wheel_adapter/xid_driver.h:
--------------------------------------------------------------------------------
1 | #ifndef XID_DRIVER_H_
2 | #define XID_DRIVER_H_
3 |
4 | #ifdef __cplusplus
5 | extern "C"
6 | {
7 | #endif
8 |
9 | #include
10 | #include
11 | #include
12 | #include "xid.h"
13 |
14 | #ifdef __cplusplus
15 | }
16 | #endif
17 |
18 | #endif //XID_DRIVER_H_
19 |
--------------------------------------------------------------------------------
/pico_xbox_wheel_adapter/xid_wheel.c:
--------------------------------------------------------------------------------
1 | #include "xid_driver.h"
2 |
3 | bool wheel_control_xfer(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request, xid_interface_t *p_xid)
4 | {
5 | if (request->bmRequestType == 0xC1 && request->bRequest == 0x06 && request->wValue == 0x4200)
6 | {
7 | if (stage == CONTROL_STAGE_SETUP)
8 | {
9 | TU_LOG1("Sending WHEEL_DESC_XID\n");
10 | tud_control_xfer(rhport, request, (void *)WHEEL_DESC_XID, sizeof(WHEEL_DESC_XID));
11 | }
12 | return true;
13 | }
14 | else if (request->bmRequestType == 0xC1 && request->bRequest == 0x01 && request->wValue == 0x0100)
15 | {
16 | if (stage == CONTROL_STAGE_SETUP)
17 | {
18 | TU_LOG1("Sending WHEEL_CAPABILITIES_IN\n");
19 | tud_control_xfer(rhport, request, (void *)WHEEL_CAPABILITIES_IN, sizeof(WHEEL_CAPABILITIES_IN));
20 | }
21 | return true;
22 | }
23 | else if (request->bmRequestType == 0xC1 && request->bRequest == 0x01 && request->wValue == 0x0200)
24 | {
25 | if (stage == CONTROL_STAGE_SETUP)
26 | {
27 | TU_LOG1("Sending WHEEL_CAPABILITIES_OUT\n");
28 | tud_control_xfer(rhport, request, (void *)WHEEL_CAPABILITIES_OUT, sizeof(WHEEL_CAPABILITIES_OUT));
29 | }
30 | return true;
31 | }
32 | return false;
33 | }
34 |
--------------------------------------------------------------------------------
/pico_xbox_wheel_adapter/xid_wheel.h:
--------------------------------------------------------------------------------
1 | #ifndef XID_WHEEL_H_
2 | #define XID_WHEEL_H_
3 |
4 | #ifdef __cplusplus
5 | extern "C"
6 | {
7 | #endif
8 |
9 | #include
10 | #include
11 |
12 | #define TUD_XID_WHEEL_DESC_LEN (9+7+7)
13 |
14 | /* Digital Button Masks */
15 | #define XID_DUP (1 << 0)
16 | #define XID_DDOWN (1 << 1)
17 | #define XID_DLEFT (1 << 2)
18 | #define XID_DRIGHT (1 << 3)
19 | #define XID_START (1 << 4)
20 | #define XID_BACK (1 << 5)
21 | #define XID_LS (1 << 6)
22 | #define XID_RS (1 << 7)
23 |
24 | typedef struct __attribute__((packed))
25 | {
26 | uint8_t zero;
27 | uint8_t bLength;
28 | uint8_t dButtons;
29 | uint8_t reserved;
30 | uint8_t A;
31 | uint8_t B;
32 | uint8_t X;
33 | uint8_t Y;
34 | uint8_t BLACK;
35 | uint8_t WHITE;
36 | uint8_t L;
37 | uint8_t R;
38 | int16_t leftStickX;
39 | int16_t leftStickY;
40 | int16_t rightStickX;
41 | int16_t rightStickY;
42 | } USB_XboxWheel_InReport_t;
43 |
44 | typedef struct __attribute__((packed))
45 | {
46 | uint8_t zero;
47 | uint8_t bLength;
48 | uint16_t lValue;
49 | uint16_t rValue;
50 | } USB_XboxWheel_OutReport_t;
51 |
52 | #define TUD_XID_WHEEL_DESC_LEN (9+7+7)
53 |
54 | #define TUD_XID_WHEEL_DESCRIPTOR(_itfnum, _epout, _epin) \
55 | /* Interface */\
56 | 9, TUSB_DESC_INTERFACE, _itfnum, 0, 2, XID_INTERFACE_CLASS, XID_INTERFACE_SUBCLASS, 0x00, 0x00,\
57 | /* Endpoint In */\
58 | 7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(32), 4, \
59 | /* Endpoint Out */\
60 | 7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(32), 4
61 |
62 | static const uint8_t WHEEL_DESC_XID[] = {
63 | 0x10, // Length
64 | 0x42, // Descriptor Type
65 | 0x00, 0x01, // BCD XID
66 | 0x01, // Type: GameController
67 | 0x10, // SubType: Steering wheel
68 | 0x14, // Max Input Report Size
69 | 0x06, // Max Output Report Size
70 | 0xFF, 0xFF, // Alternate ID 0
71 | 0xFF, 0xFF, // Alternate ID 1
72 | 0xFF, 0xFF, // Alternate ID 2
73 | 0xFF, 0xFF // Alternate ID 3
74 | };
75 |
76 | static const uint8_t WHEEL_CAPABILITIES_IN[] = {
77 | 0x00, // ReportID
78 | 0x14, // Length
79 | 0xFF, // Digital Buttons (RightStick,LeftStick,Back,Start,Right,Left,Down,Up)
80 | 0x00, // Lightgun Flags
81 | 0xFF, // A
82 | 0xFF, // B
83 | 0xFF, // X
84 | 0xFF, // Y
85 | 0xFF, // Black
86 | 0xFF, // White
87 | 0xFF, // Left Trigger
88 | 0xFF, // Right Trigger
89 | 0xFF, 0xFF, // Left Stick X
90 | 0xFF, 0xFF, // Left Stick Y
91 | 0xFF, 0xFF, // Right Stick X
92 | 0xFF, 0xFF // Right Stick X
93 | };
94 |
95 | static const uint8_t WHEEL_CAPABILITIES_OUT[] = {
96 | 0x00, // ReportID
97 | 0x06, // Length
98 | 0xFF, 0xFF, //Left Actuator Strength
99 | 0xFF, 0xFF //Right Actuator Strength
100 | };
101 |
102 | #ifdef __cplusplus
103 | }
104 | #endif
105 |
106 | #endif
107 |
--------------------------------------------------------------------------------
/pico_xbox_wheel_adapter/xinput_host.c:
--------------------------------------------------------------------------------
1 | // Copyright 2020, Ryan Wendland, usb64
2 | // SPDX-License-Identifier: MIT
3 |
4 | #include "tusb_option.h"
5 |
6 | #if (TUSB_OPT_HOST_ENABLED && CFG_TUH_XINPUT)
7 |
8 | #include "host/usbh.h"
9 | #include "host/usbh_pvt.h"
10 | #include "xinput_host.h"
11 |
12 | #pragma GCC diagnostic push
13 | #pragma GCC diagnostic ignored "-Wunused-const-variable"
14 |
15 | //Wired 360 commands
16 | static const uint8_t xbox360_wired_rumble[] = {0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
17 | static const uint8_t xbox360_wired_led[] = {0x01, 0x03, 0x00};
18 |
19 | //Xbone one
20 | #define GIP_CMD_ACK 0x01
21 | #define GIP_CMD_ANNOUNCE 0x02
22 | #define GIP_CMD_IDENTIFY 0x04
23 | #define GIP_CMD_POWER 0x05
24 | #define GIP_CMD_AUTHENTICATE 0x06
25 | #define GIP_CMD_VIRTUAL_KEY 0x07
26 | #define GIP_CMD_RUMBLE 0x09
27 | #define GIP_CMD_LED 0x0a
28 | #define GIP_CMD_FIRMWARE 0x0c
29 | #define GIP_CMD_INPUT 0x20
30 | #define GIP_SEQ0 0x00
31 | #define GIP_OPT_ACK 0x10
32 | #define GIP_OPT_INTERNAL 0x20
33 | #define GIP_PL_LEN(N) (N)
34 | #define GIP_PWR_ON 0x00
35 | #define GIP_PWR_SLEEP 0x01
36 | #define GIP_PWR_OFF 0x04
37 | #define GIP_PWR_RESET 0x07
38 | #define GIP_LED_ON 0x01
39 | #define BIT(n) (1UL << (n))
40 | #define GIP_MOTOR_R BIT(0)
41 | #define GIP_MOTOR_L BIT(1)
42 | #define GIP_MOTOR_RT BIT(2)
43 | #define GIP_MOTOR_LT BIT(3)
44 | #define GIP_MOTOR_ALL (GIP_MOTOR_R | GIP_MOTOR_L | GIP_MOTOR_RT | GIP_MOTOR_LT)
45 | static const uint8_t xboxone_power_on[] = {GIP_CMD_POWER, GIP_OPT_INTERNAL, GIP_SEQ0, GIP_PL_LEN(1), GIP_PWR_ON};
46 | static const uint8_t xboxone_s_init[] = {GIP_CMD_POWER, GIP_OPT_INTERNAL, GIP_SEQ0, GIP_PL_LEN(15), 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
47 | static const uint8_t xboxone_s_led_init[] = {GIP_CMD_LED, GIP_OPT_INTERNAL, GIP_SEQ0, GIP_PL_LEN(3), 0x00, 0x01, 0x14};
48 | static const uint8_t extra_input_packet_init[] = {0x4d, 0x10, GIP_SEQ0, 0x02, 0x07, 0x00};
49 | static const uint8_t xboxone_pdp_led_on[] = {GIP_CMD_LED, GIP_OPT_INTERNAL, GIP_SEQ0, GIP_PL_LEN(3), 0x00, GIP_LED_ON, 0x14};
50 | static const uint8_t xboxone_pdp_auth[] = {GIP_CMD_AUTHENTICATE, GIP_OPT_INTERNAL, GIP_SEQ0, GIP_PL_LEN(2), 0x01, 0x00};
51 | static const uint8_t xboxone_rumble[] = {GIP_CMD_RUMBLE, 0x00, 0x00, GIP_PL_LEN(9), 0x00, GIP_MOTOR_ALL, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF};
52 |
53 | //Wireless 360 commands
54 | static const uint8_t xbox360w_led[] = {0x00, 0x00, 0x08, 0x40};
55 | //Sending 0x00, 0x00, 0x08, 0x00 will permanently disable rumble until you do this:
56 | static const uint8_t xbox360w_rumble_enable[] = {0x00, 0x00, 0x08, 0x01};
57 | static const uint8_t xbox360w_rumble[] = {0x00, 0x01, 0x0F, 0xC0, 0x00, 0x00};
58 | static const uint8_t xbox360w_inquire_present[] = {0x08, 0x00, 0x0F, 0xC0};
59 | static const uint8_t xbox360w_controller_info[] = {0x00, 0x00, 0x00, 0x40};
60 | static const uint8_t xbox360w_unknown[] = {0x00, 0x00, 0x02, 0x80};
61 | static const uint8_t xbox360w_power_off[] = {0x00, 0x00, 0x08, 0xC0};
62 | static const uint8_t xbox360w_chatpad_init[] = {0x00, 0x00, 0x0C, 0x1B};
63 | static const uint8_t xbox360w_chatpad_keepalive1[] = {0x00, 0x00, 0x0C, 0x1F};
64 | static const uint8_t xbox360w_chatpad_keepalive2[] = {0x00, 0x00, 0x0C, 0x1E};
65 |
66 | //Original Xbox
67 | static const uint8_t xboxog_rumble[] = {0x00, 0x06, 0x00, 0x00, 0x00, 0x00};
68 |
69 | #pragma GCC diagnostic pop
70 |
71 | typedef struct
72 | {
73 | uint8_t inst_count;
74 | xinputh_interface_t instances[CFG_TUH_XINPUT];
75 | } xinputh_device_t;
76 |
77 | static xinputh_device_t _xinputh_dev[CFG_TUH_DEVICE_MAX];
78 |
79 | TU_ATTR_ALWAYS_INLINE static inline xinputh_device_t *get_dev(uint8_t dev_addr)
80 | {
81 | return &_xinputh_dev[dev_addr - 1];
82 | }
83 |
84 | TU_ATTR_ALWAYS_INLINE static inline xinputh_interface_t *get_instance(uint8_t dev_addr, uint8_t instance)
85 | {
86 | return &_xinputh_dev[dev_addr - 1].instances[instance];
87 | }
88 |
89 | static uint8_t get_instance_id_by_epaddr(uint8_t dev_addr, uint8_t ep_addr)
90 | {
91 | for (uint8_t inst = 0; inst < CFG_TUH_XINPUT; inst++)
92 | {
93 | xinputh_interface_t *hid = get_instance(dev_addr, inst);
94 |
95 | if ((ep_addr == hid->ep_in) || (ep_addr == hid->ep_out))
96 | return inst;
97 | }
98 |
99 | return 0xff;
100 | }
101 |
102 | static uint8_t get_instance_id_by_itfnum(uint8_t dev_addr, uint8_t itf)
103 | {
104 | for (uint8_t inst = 0; inst < CFG_TUH_XINPUT; inst++)
105 | {
106 | xinputh_interface_t *hid = get_instance(dev_addr, inst);
107 |
108 | if ((hid->itf_num == itf) && (hid->ep_in || hid->ep_out))
109 | return inst;
110 | }
111 |
112 | return 0xff;
113 | }
114 |
115 | static void wait_for_tx_complete(uint8_t dev_addr, uint8_t ep_out)
116 | {
117 | while (usbh_edpt_busy(dev_addr, ep_out))
118 | tuh_task();
119 | }
120 |
121 | static void xboxone_init( xinputh_interface_t *xid_itf, uint8_t dev_addr, uint8_t instance)
122 | {
123 | uint16_t PID, VID;
124 | tuh_vid_pid_get(dev_addr, &VID, &PID);
125 |
126 | tuh_xinput_send_report(dev_addr, instance, xboxone_power_on, sizeof(xboxone_power_on));
127 | wait_for_tx_complete(dev_addr, xid_itf->ep_out);
128 | tuh_xinput_send_report(dev_addr, instance, xboxone_s_init, sizeof(xboxone_s_init));
129 | wait_for_tx_complete(dev_addr, xid_itf->ep_out);
130 |
131 | if (VID == 0x045e && (PID == 0x0b00))
132 | {
133 | tuh_xinput_send_report(dev_addr, instance, extra_input_packet_init, sizeof(extra_input_packet_init));
134 | wait_for_tx_complete(dev_addr, xid_itf->ep_out);
135 | }
136 |
137 | //Required for PDP aftermarket controllers
138 | if (VID == 0x0e6f)
139 | {
140 | tuh_xinput_send_report(dev_addr, instance, xboxone_pdp_led_on, sizeof(xboxone_pdp_led_on));
141 | wait_for_tx_complete(dev_addr, xid_itf->ep_out);
142 | tuh_xinput_send_report(dev_addr, instance, xboxone_pdp_auth, sizeof(xboxone_pdp_auth));
143 | wait_for_tx_complete(dev_addr, xid_itf->ep_out);
144 | }
145 | }
146 |
147 | bool tuh_xinput_receive_report(uint8_t dev_addr, uint8_t instance)
148 | {
149 | xinputh_interface_t *xid_itf = get_instance(dev_addr, instance);
150 | TU_VERIFY(usbh_edpt_claim(dev_addr, xid_itf->ep_in));
151 |
152 | if ( !usbh_edpt_xfer(dev_addr, xid_itf->ep_in, xid_itf->epin_buf, xid_itf->epin_size) )
153 | {
154 | usbh_edpt_release(dev_addr, xid_itf->ep_in);
155 | return false;
156 | }
157 | return true;
158 | }
159 |
160 | bool tuh_xinput_send_report(uint8_t dev_addr, uint8_t instance, const uint8_t *txbuf, uint16_t len)
161 | {
162 | xinputh_interface_t *xid_itf = get_instance(dev_addr, instance);
163 |
164 | TU_ASSERT(len <= xid_itf->epout_size);
165 | TU_VERIFY(usbh_edpt_claim(dev_addr, xid_itf->ep_out));
166 |
167 | memcpy(xid_itf->epout_buf, txbuf, len);
168 |
169 | if ( !usbh_edpt_xfer(dev_addr, xid_itf->ep_out, xid_itf->epout_buf, len))
170 | {
171 | usbh_edpt_release(dev_addr, xid_itf->ep_out);
172 | return false;
173 | }
174 | return true;
175 | }
176 |
177 | bool tuh_xinput_set_led(uint8_t dev_addr, uint8_t instance, uint8_t quadrant, bool block)
178 | {
179 | xinputh_interface_t *xid_itf = get_instance(dev_addr, instance);
180 | uint8_t txbuf[32];
181 | uint16_t len;
182 | switch (xid_itf->type)
183 | {
184 | case XBOX360_WIRELESS:
185 | memcpy(txbuf, xbox360w_led, sizeof(xbox360w_led));
186 | txbuf[3] = (quadrant == 0) ? 0x40 : (0x40 | (quadrant + 5));
187 | len = sizeof(xbox360w_led);
188 | break;
189 | case XBOX360_WIRED:
190 | memcpy(txbuf, xbox360_wired_led, sizeof(xbox360_wired_led));
191 | txbuf[2] = (quadrant == 0) ? 0 : (quadrant + 5);
192 | len = sizeof(xbox360_wired_led);
193 | break;
194 | default:
195 | return true;
196 | }
197 | bool ret = tuh_xinput_send_report(dev_addr, instance, txbuf, len);
198 | if (block && ret)
199 | {
200 | wait_for_tx_complete(dev_addr, xid_itf->ep_out);
201 | }
202 | return ret;
203 | }
204 |
205 | bool tuh_xinput_set_rumble(uint8_t dev_addr, uint8_t instance, uint8_t lValue, uint8_t rValue, bool block)
206 | {
207 | xinputh_interface_t *xid_itf = get_instance(dev_addr, instance);
208 | uint8_t txbuf[32];
209 | uint16_t len;
210 |
211 | switch (xid_itf->type)
212 | {
213 | case XBOX360_WIRELESS:
214 | memcpy(txbuf, xbox360w_rumble, sizeof(xbox360w_rumble));
215 | txbuf[5] = lValue;
216 | txbuf[6] = rValue;
217 | len = sizeof(xbox360w_rumble);
218 | break;
219 | case XBOX360_WIRED:
220 | memcpy(txbuf, xbox360_wired_rumble, sizeof(xbox360_wired_rumble));
221 | txbuf[3] = lValue;
222 | txbuf[4] = rValue;
223 | len = sizeof(xbox360_wired_rumble);
224 | break;
225 | case XBOXONE:
226 | memcpy(txbuf, xboxone_rumble, sizeof(xboxone_rumble));
227 | txbuf[8] = lValue / 2; // 0 - 128
228 | txbuf[9] = rValue / 2; // 0 - 128
229 | len = sizeof(xboxone_rumble);
230 | break;
231 | case XBOXOG:
232 | memcpy(txbuf, xboxog_rumble, sizeof(xboxog_rumble));
233 | txbuf[2] = lValue;
234 | txbuf[3] = lValue;
235 | txbuf[4] = rValue;
236 | txbuf[5] = rValue;
237 | len = sizeof(xboxog_rumble);
238 | break;
239 | default:
240 | return true;
241 | }
242 | bool ret = tuh_xinput_send_report(dev_addr, instance, txbuf, len);
243 | if (block && ret)
244 | {
245 | wait_for_tx_complete(dev_addr, xid_itf->ep_out);
246 | }
247 | return true;
248 | }
249 |
250 | //--------------------------------------------------------------------+
251 | // USBH API
252 | //--------------------------------------------------------------------+
253 | void xinputh_init(void)
254 | {
255 | tu_memclr(_xinputh_dev, sizeof(_xinputh_dev));
256 | }
257 |
258 | bool xinputh_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *desc_itf, uint16_t max_len)
259 | {
260 | TU_VERIFY(dev_addr <= CFG_TUH_DEVICE_MAX);
261 |
262 | xinput_type_t type = XINPUT_UNKNOWN;
263 | if (desc_itf->bNumEndpoints < 2)
264 | type = XINPUT_UNKNOWN;
265 | else if (desc_itf->bInterfaceSubClass == 0x5D && //Xbox360 wireless bInterfaceSubClass
266 | desc_itf->bInterfaceProtocol == 0x81) //Xbox360 wireless bInterfaceProtocol
267 | type = XBOX360_WIRELESS;
268 | else if (desc_itf->bInterfaceSubClass == 0x5D && //Xbox360 wired bInterfaceSubClass
269 | desc_itf->bInterfaceProtocol == 0x01) //Xbox360 wired bInterfaceProtocol
270 | type = XBOX360_WIRED;
271 | else if (desc_itf->bInterfaceSubClass == 0x47 && //Xbone and SX bInterfaceSubClass
272 | desc_itf->bInterfaceProtocol == 0xD0) //Xbone and SX bInterfaceProtocol
273 | type = XBOXONE;
274 | else if (desc_itf->bInterfaceClass == 0x58 && //XboxOG bInterfaceClass
275 | desc_itf->bInterfaceSubClass == 0x42) //XboxOG bInterfaceSubClass
276 | type = XBOXOG;
277 |
278 | if (type == XINPUT_UNKNOWN)
279 | {
280 | TU_LOG2("XINPUT: Not a valid interface\n");
281 | return false;
282 | }
283 |
284 | TU_LOG2("XINPUT opening Interface %u (addr = %u)\r\n", desc_itf->bInterfaceNumber, dev_addr);
285 |
286 | xinputh_device_t *xinput_dev = get_dev(dev_addr);
287 | TU_ASSERT(xinput_dev->inst_count < CFG_TUH_XINPUT, 0);
288 |
289 | xinputh_interface_t *xid_itf = get_instance(dev_addr, xinput_dev->inst_count);
290 | xid_itf->itf_num = desc_itf->bInterfaceNumber;
291 | xid_itf->type = type;
292 |
293 | //Parse descriptor for all endpoints and open them
294 | uint8_t const *p_desc = (uint8_t const *)desc_itf;
295 | int endpoint = 0;
296 | int pos = 0;
297 | while (endpoint < desc_itf->bNumEndpoints && pos < max_len)
298 | {
299 | if (tu_desc_type(p_desc) != TUSB_DESC_ENDPOINT)
300 | {
301 | pos += tu_desc_len(p_desc);
302 | p_desc = tu_desc_next(p_desc);
303 | continue;
304 | }
305 | tusb_desc_endpoint_t const *desc_ep = (tusb_desc_endpoint_t const *)p_desc;
306 | TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType);
307 | TU_ASSERT(tuh_edpt_open(dev_addr, desc_ep));
308 | if (tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_OUT)
309 | {
310 | xid_itf->ep_out = desc_ep->bEndpointAddress;
311 | xid_itf->epout_size = tu_edpt_packet_size(desc_ep);
312 | }
313 | else
314 | {
315 | xid_itf->ep_in = desc_ep->bEndpointAddress;
316 | xid_itf->epin_size = tu_edpt_packet_size(desc_ep);
317 | }
318 | endpoint++;
319 | pos += tu_desc_len(p_desc);
320 | p_desc = tu_desc_next(p_desc);
321 | }
322 |
323 | xinput_dev->inst_count++;
324 | return true;
325 | }
326 |
327 | bool xinputh_set_config(uint8_t dev_addr, uint8_t itf_num)
328 | {
329 | uint8_t instance = get_instance_id_by_itfnum(dev_addr, itf_num);
330 | xinputh_interface_t *xid_itf = get_instance(dev_addr, instance);
331 | xid_itf->connected = true;
332 |
333 | if (xid_itf->type == XBOX360_WIRELESS)
334 | {
335 | //Wireless controllers may not be connected yet.
336 | xid_itf->connected = false;
337 | tuh_xinput_send_report(dev_addr, instance, xbox360w_inquire_present, sizeof(xbox360w_inquire_present));
338 | wait_for_tx_complete(dev_addr, xid_itf->ep_out);
339 | }
340 | else if (xid_itf->type == XBOX360_WIRED)
341 | {
342 | }
343 | else if (xid_itf->type == XBOXONE)
344 | {
345 | xboxone_init(xid_itf, dev_addr, instance);
346 | }
347 |
348 | if (tuh_xinput_mount_cb)
349 | {
350 | tuh_xinput_mount_cb(dev_addr, instance, xid_itf);
351 | }
352 |
353 | usbh_driver_set_config_complete(dev_addr, xid_itf->itf_num);
354 | return true;
355 | }
356 |
357 | bool xinputh_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
358 | {
359 | uint8_t const dir = tu_edpt_dir(ep_addr);
360 | uint8_t const instance = get_instance_id_by_epaddr(dev_addr, ep_addr);
361 | xinputh_interface_t *xid_itf = get_instance(dev_addr, instance);
362 | xinput_gamepad_t *pad = &xid_itf->pad;
363 | uint8_t *rdata = xid_itf->epin_buf;
364 |
365 | xid_itf->last_xfer_result = result;
366 | xid_itf->last_xferred_bytes = xferred_bytes;
367 |
368 | // On transfer error, bail early but notify the application
369 | if (result != XFER_RESULT_SUCCESS)
370 | {
371 | if (dir == TUSB_DIR_IN)
372 | {
373 | tuh_xinput_report_received_cb(dev_addr, instance, xid_itf, sizeof(xinputh_interface_t));
374 | }
375 | else if (tuh_xinput_report_sent_cb)
376 | {
377 | tuh_xinput_report_sent_cb(dev_addr, instance, xid_itf->epout_buf, xferred_bytes);
378 | }
379 | return false;
380 | }
381 |
382 | if (dir == TUSB_DIR_IN)
383 | {
384 | TU_LOG2("Get Report callback (%u, %u, %u bytes)\r\n", dev_addr, instance, xferred_bytes);
385 | if (xid_itf->type == XBOX360_WIRED)
386 | {
387 | #define GET_USHORT(a) (uint16_t)((a)[1] << 8 | (a)[0])
388 | #define GET_SHORT(a) ((int16_t)GET_USHORT(a))
389 | if (rdata[1] == 0x14)
390 | {
391 | tu_memclr(pad, sizeof(xinput_gamepad_t));
392 | uint16_t wButtons = rdata[3] << 8 | rdata[2];
393 |
394 | //Map digital buttons
395 | if (wButtons & (1 << 0)) pad->wButtons |= XINPUT_GAMEPAD_DPAD_UP;
396 | if (wButtons & (1 << 1)) pad->wButtons |= XINPUT_GAMEPAD_DPAD_DOWN;
397 | if (wButtons & (1 << 2)) pad->wButtons |= XINPUT_GAMEPAD_DPAD_LEFT;
398 | if (wButtons & (1 << 3)) pad->wButtons |= XINPUT_GAMEPAD_DPAD_RIGHT;
399 | if (wButtons & (1 << 4)) pad->wButtons |= XINPUT_GAMEPAD_START;
400 | if (wButtons & (1 << 5)) pad->wButtons |= XINPUT_GAMEPAD_BACK;
401 | if (wButtons & (1 << 6)) pad->wButtons |= XINPUT_GAMEPAD_LEFT_THUMB;
402 | if (wButtons & (1 << 7)) pad->wButtons |= XINPUT_GAMEPAD_RIGHT_THUMB;
403 | if (wButtons & (1 << 8)) pad->wButtons |= XINPUT_GAMEPAD_LEFT_SHOULDER;
404 | if (wButtons & (1 << 9)) pad->wButtons |= XINPUT_GAMEPAD_RIGHT_SHOULDER;
405 | if (wButtons & (1 << 10)) pad->wButtons |= XINPUT_GAMEPAD_GUIDE;
406 | if (wButtons & (1 << 12)) pad->wButtons |= XINPUT_GAMEPAD_A;
407 | if (wButtons & (1 << 13)) pad->wButtons |= XINPUT_GAMEPAD_B;
408 | if (wButtons & (1 << 14)) pad->wButtons |= XINPUT_GAMEPAD_X;
409 | if (wButtons & (1 << 15)) pad->wButtons |= XINPUT_GAMEPAD_Y;
410 |
411 | //Map the left and right triggers
412 | pad->bLeftTrigger = rdata[4];
413 | pad->bRightTrigger = rdata[5];
414 |
415 | //Map analog sticks
416 | pad->sThumbLX = rdata[7] << 8 | rdata[6];
417 | pad->sThumbLY = rdata[9] << 8 | rdata[8];
418 | pad->sThumbRX = rdata[11] << 8 | rdata[10];
419 | pad->sThumbRY = rdata[13] << 8 | rdata[12];
420 |
421 | xid_itf->new_pad_data = true;
422 | }
423 | }
424 | else if (xid_itf->type == XBOX360_WIRELESS)
425 | {
426 | //Connect/Disconnect packet
427 | if (rdata[0] & 0x08)
428 | {
429 | if (rdata[1] != 0x00 && xid_itf->connected == false)
430 | {
431 | TU_LOG2("XINPUT: WIRELESS CONTROLLER CONNECTED\n");
432 | xid_itf->connected = true;
433 | }
434 | else if (rdata[1] == 0x00 && xid_itf->connected == true)
435 | {
436 | TU_LOG2("XINPUT: WIRELESS CONTROLLER DISCONNECTED\n");
437 | xid_itf->connected = false;
438 | }
439 | }
440 |
441 | //Button status packet
442 | if ((rdata[1] & 1) && rdata[5] == 0x13)
443 | {
444 | tu_memclr(pad, sizeof(xinput_gamepad_t));
445 | uint16_t wButtons = rdata[7] << 8 | rdata[6];
446 |
447 | //Map digital buttons
448 | if (wButtons & (1 << 0)) pad->wButtons |= XINPUT_GAMEPAD_DPAD_UP;
449 | if (wButtons & (1 << 1)) pad->wButtons |= XINPUT_GAMEPAD_DPAD_DOWN;
450 | if (wButtons & (1 << 2)) pad->wButtons |= XINPUT_GAMEPAD_DPAD_LEFT;
451 | if (wButtons & (1 << 3)) pad->wButtons |= XINPUT_GAMEPAD_DPAD_RIGHT;
452 | if (wButtons & (1 << 4)) pad->wButtons |= XINPUT_GAMEPAD_START;
453 | if (wButtons & (1 << 5)) pad->wButtons |= XINPUT_GAMEPAD_BACK;
454 | if (wButtons & (1 << 6)) pad->wButtons |= XINPUT_GAMEPAD_LEFT_THUMB;
455 | if (wButtons & (1 << 7)) pad->wButtons |= XINPUT_GAMEPAD_RIGHT_THUMB;
456 | if (wButtons & (1 << 8)) pad->wButtons |= XINPUT_GAMEPAD_LEFT_SHOULDER;
457 | if (wButtons & (1 << 9)) pad->wButtons |= XINPUT_GAMEPAD_RIGHT_SHOULDER;
458 | if (wButtons & (1 << 12)) pad->wButtons |= XINPUT_GAMEPAD_A;
459 | if (wButtons & (1 << 13)) pad->wButtons |= XINPUT_GAMEPAD_B;
460 | if (wButtons & (1 << 14)) pad->wButtons |= XINPUT_GAMEPAD_X;
461 | if (wButtons & (1 << 15)) pad->wButtons |= XINPUT_GAMEPAD_Y;
462 |
463 | //Map the left and right triggers
464 | pad->bLeftTrigger = rdata[8];
465 | pad->bRightTrigger = rdata[9];
466 |
467 | //Map analog sticks
468 | pad->sThumbLX = rdata[11] << 8 | rdata[10];
469 | pad->sThumbLY = rdata[13] << 8 | rdata[12];
470 | pad->sThumbRX = rdata[15] << 8 | rdata[14];
471 | pad->sThumbRY = rdata[17] << 8 | rdata[16];
472 |
473 | xid_itf->new_pad_data = true;
474 | }
475 | }
476 | else if (xid_itf->type == XBOXONE)
477 | {
478 | if (rdata[0] == GIP_CMD_INPUT)
479 | {
480 | //Keep a copy of the guide button state
481 | bool guide_state = (pad->wButtons & XINPUT_GAMEPAD_GUIDE) != 0x0;
482 |
483 | tu_memclr(pad, sizeof(xinput_gamepad_t));
484 | uint16_t wButtons = rdata[5] << 8 | rdata[4];
485 |
486 | //Map digital buttons
487 | if (wButtons & (1 << 8)) pad->wButtons |= XINPUT_GAMEPAD_DPAD_UP;
488 | if (wButtons & (1 << 9)) pad->wButtons |= XINPUT_GAMEPAD_DPAD_DOWN;
489 | if (wButtons & (1 << 10)) pad->wButtons |= XINPUT_GAMEPAD_DPAD_LEFT;
490 | if (wButtons & (1 << 11)) pad->wButtons |= XINPUT_GAMEPAD_DPAD_RIGHT;
491 | if (wButtons & (1 << 2)) pad->wButtons |= XINPUT_GAMEPAD_START;
492 | if (wButtons & (1 << 3)) pad->wButtons |= XINPUT_GAMEPAD_BACK;
493 | if (wButtons & (1 << 14)) pad->wButtons |= XINPUT_GAMEPAD_LEFT_THUMB;
494 | if (wButtons & (1 << 15)) pad->wButtons |= XINPUT_GAMEPAD_RIGHT_THUMB;
495 | if (wButtons & (1 << 12)) pad->wButtons |= XINPUT_GAMEPAD_LEFT_SHOULDER;
496 | if (wButtons & (1 << 13)) pad->wButtons |= XINPUT_GAMEPAD_RIGHT_SHOULDER;
497 | if (wButtons & (1 << 4)) pad->wButtons |= XINPUT_GAMEPAD_A;
498 | if (wButtons & (1 << 5)) pad->wButtons |= XINPUT_GAMEPAD_B;
499 | if (wButtons & (1 << 6)) pad->wButtons |= XINPUT_GAMEPAD_X;
500 | if (wButtons & (1 << 7)) pad->wButtons |= XINPUT_GAMEPAD_Y;
501 | if (rdata[22] && 0x01) pad->wButtons |= XINPUT_GAMEPAD_SHARE;
502 | if (guide_state) pad->wButtons |= XINPUT_GAMEPAD_GUIDE;
503 |
504 | uint16_t PID, VID;
505 | tuh_vid_pid_get(dev_addr, &VID, &PID);
506 | if (VID == 0x046d && PID == 0xc261) {
507 | // Logitech G920
508 | pad->sThumbLX = (rdata[7] << 8 | rdata[6]) - 32768UL; // Wheel
509 | pad->bRightTrigger = (rdata[8] << 8) + rdata[8]; // Gas pedal
510 | pad->bLeftTrigger = (rdata[10] << 8) + rdata[10]; // Brake pedal
511 | //pad->bLeftTrigger = (rdata[12] << 8) + rdata[12]; // Clutch pedal
512 | pad->sThumbLY = 0;
513 | pad->sThumbRX = 0;
514 | pad->sThumbRY = 0;
515 | } else {
516 | //Map the left and right triggers
517 | pad->bLeftTrigger = (rdata[7] << 8 | rdata[6]) >> 2;
518 | pad->bRightTrigger = (rdata[9] << 8 | rdata[8]) >> 2;
519 |
520 | //Map analog sticks
521 | pad->sThumbLX = rdata[11] << 8 | rdata[10];
522 | pad->sThumbLY = rdata[13] << 8 | rdata[12];
523 | pad->sThumbRX = rdata[15] << 8 | rdata[14];
524 | pad->sThumbRY = rdata[17] << 8 | rdata[16];
525 | }
526 |
527 | xid_itf->new_pad_data = true;
528 | }
529 | else if (rdata[0] == GIP_CMD_VIRTUAL_KEY)
530 | {
531 | if (rdata[4] == 0x01 && !(pad->wButtons & XINPUT_GAMEPAD_GUIDE)) {
532 | xid_itf->new_pad_data = true;
533 | pad->wButtons |= XINPUT_GAMEPAD_GUIDE;
534 | }
535 | else if (rdata[4] == 0x00 && (pad->wButtons & XINPUT_GAMEPAD_GUIDE)) {
536 | xid_itf->new_pad_data = true;
537 | pad->wButtons &= ~XINPUT_GAMEPAD_GUIDE;
538 | }
539 | }
540 | else if (rdata[0] == GIP_CMD_ANNOUNCE)
541 | {
542 | xboxone_init(xid_itf, dev_addr, instance);
543 | }
544 | }
545 | else if (xid_itf->type == XBOXOG)
546 | {
547 | if (rdata[1] == 0x14)
548 | {
549 | tu_memclr(pad, sizeof(xinput_gamepad_t));
550 | uint16_t wButtons = rdata[3] << 8 | rdata[2];
551 |
552 | //Map digital buttons
553 | if (wButtons & (1 << 0)) pad->wButtons |= XINPUT_GAMEPAD_DPAD_UP;
554 | if (wButtons & (1 << 1)) pad->wButtons |= XINPUT_GAMEPAD_DPAD_DOWN;
555 | if (wButtons & (1 << 2)) pad->wButtons |= XINPUT_GAMEPAD_DPAD_LEFT;
556 | if (wButtons & (1 << 3)) pad->wButtons |= XINPUT_GAMEPAD_DPAD_RIGHT;
557 | if (wButtons & (1 << 4)) pad->wButtons |= XINPUT_GAMEPAD_START;
558 | if (wButtons & (1 << 5)) pad->wButtons |= XINPUT_GAMEPAD_BACK;
559 | if (wButtons & (1 << 6)) pad->wButtons |= XINPUT_GAMEPAD_LEFT_THUMB;
560 | if (wButtons & (1 << 7)) pad->wButtons |= XINPUT_GAMEPAD_RIGHT_THUMB;
561 |
562 | if (rdata[4] > 0x20) pad->wButtons |= XINPUT_GAMEPAD_A;
563 | if (rdata[5] > 0x20) pad->wButtons |= XINPUT_GAMEPAD_B;
564 | if (rdata[6] > 0x20) pad->wButtons |= XINPUT_GAMEPAD_X;
565 | if (rdata[7] > 0x20) pad->wButtons |= XINPUT_GAMEPAD_Y;
566 | if (rdata[8] > 0x20) pad->wButtons |= XINPUT_GAMEPAD_RIGHT_SHOULDER;
567 | if (rdata[9] > 0x20) pad->wButtons |= XINPUT_GAMEPAD_LEFT_SHOULDER;
568 |
569 | //Map the left and right triggers
570 | pad->bLeftTrigger = rdata[10];
571 | pad->bRightTrigger = rdata[11];
572 |
573 | //Map analog sticks
574 | pad->sThumbLX = rdata[13] << 8 | rdata[12];
575 | pad->sThumbLY = rdata[15] << 8 | rdata[14];
576 | pad->sThumbRX = rdata[17] << 8 | rdata[16];
577 | pad->sThumbRY = rdata[19] << 8 | rdata[18];
578 |
579 | xid_itf->new_pad_data = true;
580 | }
581 | }
582 | if (xid_itf->new_pad_data)
583 | {
584 | tuh_xinput_report_received_cb(dev_addr, instance, xid_itf, sizeof(xinputh_interface_t));
585 | xid_itf->new_pad_data = false;
586 | } else {
587 | tuh_xinput_receive_report(dev_addr, instance);
588 | }
589 | }
590 | else
591 | {
592 | if (tuh_xinput_report_sent_cb)
593 | {
594 | tuh_xinput_report_sent_cb(dev_addr, instance, xid_itf->epout_buf, xferred_bytes);
595 | }
596 | }
597 |
598 | return true;
599 | }
600 |
601 | void xinputh_close(uint8_t dev_addr)
602 | {
603 | TU_VERIFY(dev_addr <= CFG_TUH_DEVICE_MAX, );
604 | xinputh_device_t *xinput_dev = get_dev(dev_addr);
605 |
606 | for (uint8_t inst = 0; inst < xinput_dev->inst_count; inst++)
607 | {
608 | if (tuh_xinput_umount_cb)
609 | {
610 | tuh_xinput_umount_cb(dev_addr, inst);
611 | }
612 | }
613 | tu_memclr(xinput_dev, sizeof(xinputh_device_t));
614 | }
615 |
616 | #ifndef DRIVER_NAME
617 | #if CFG_TUSB_DEBUG >= CFG_TUH_LOG_LEVEL
618 | #define DRIVER_NAME(_name) .name = _name,
619 | #else
620 | #define DRIVER_NAME(_name)
621 | #endif
622 | #endif
623 |
624 | usbh_class_driver_t const usbh_xinput_driver =
625 | {
626 | DRIVER_NAME("XINPUT")
627 | .init = xinputh_init,
628 | .open = xinputh_open,
629 | .set_config = xinputh_set_config,
630 | .xfer_cb = xinputh_xfer_cb,
631 | .close = xinputh_close
632 | };
633 |
634 | #endif
635 |
--------------------------------------------------------------------------------
/pico_xbox_wheel_adapter/xinput_host.h:
--------------------------------------------------------------------------------
1 | // Copyright 2020, Ryan Wendland, usb64
2 | // SPDX-License-Identifier: MIT
3 |
4 | #ifndef _TUSB_XINPUT_HOST_H_
5 | #define _TUSB_XINPUT_HOST_H_
6 |
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 |
11 | #include "host/usbh_pvt.h"
12 |
13 | //--------------------------------------------------------------------+
14 | // Class Driver Configuration
15 | //--------------------------------------------------------------------+
16 |
17 | #ifndef CFG_TUH_XINPUT_EPIN_BUFSIZE
18 | #define CFG_TUH_XINPUT_EPIN_BUFSIZE 64
19 | #endif
20 |
21 | #ifndef CFG_TUH_XINPUT_EPOUT_BUFSIZE
22 | #define CFG_TUH_XINPUT_EPOUT_BUFSIZE 64
23 | #endif
24 |
25 | //XINPUT defines and struct format from
26 | //https://docs.microsoft.com/en-us/windows/win32/api/xinput/ns-xinput-xinput_gamepad
27 | #define XINPUT_GAMEPAD_DPAD_UP 0x0001
28 | #define XINPUT_GAMEPAD_DPAD_DOWN 0x0002
29 | #define XINPUT_GAMEPAD_DPAD_LEFT 0x0004
30 | #define XINPUT_GAMEPAD_DPAD_RIGHT 0x0008
31 | #define XINPUT_GAMEPAD_START 0x0010
32 | #define XINPUT_GAMEPAD_BACK 0x0020
33 | #define XINPUT_GAMEPAD_LEFT_THUMB 0x0040
34 | #define XINPUT_GAMEPAD_RIGHT_THUMB 0x0080
35 | #define XINPUT_GAMEPAD_LEFT_SHOULDER 0x0100
36 | #define XINPUT_GAMEPAD_RIGHT_SHOULDER 0x0200
37 | #define XINPUT_GAMEPAD_GUIDE 0x0400
38 | #define XINPUT_GAMEPAD_SHARE 0x0800
39 | #define XINPUT_GAMEPAD_A 0x1000
40 | #define XINPUT_GAMEPAD_B 0x2000
41 | #define XINPUT_GAMEPAD_X 0x4000
42 | #define XINPUT_GAMEPAD_Y 0x8000
43 | #define MAX_PACKET_SIZE 32
44 |
45 | typedef struct xinput_gamepad
46 | {
47 | uint16_t wButtons;
48 | uint8_t bLeftTrigger;
49 | uint8_t bRightTrigger;
50 | int16_t sThumbLX;
51 | int16_t sThumbLY;
52 | int16_t sThumbRX;
53 | int16_t sThumbRY;
54 | } xinput_gamepad_t;
55 |
56 | typedef enum
57 | {
58 | XINPUT_UNKNOWN = 0,
59 | XBOXONE,
60 | XBOX360_WIRELESS,
61 | XBOX360_WIRED,
62 | XBOXOG
63 | } xinput_type_t;
64 |
65 | typedef struct
66 | {
67 | xinput_type_t type;
68 | xinput_gamepad_t pad;
69 | uint8_t connected;
70 | uint8_t new_pad_data;
71 | uint8_t itf_num;
72 | uint8_t ep_in;
73 | uint8_t ep_out;
74 |
75 | uint16_t epin_size;
76 | uint16_t epout_size;
77 |
78 | uint8_t epin_buf[CFG_TUH_XINPUT_EPIN_BUFSIZE];
79 | uint8_t epout_buf[CFG_TUH_XINPUT_EPOUT_BUFSIZE];
80 |
81 | xfer_result_t last_xfer_result;
82 | uint32_t last_xferred_bytes;
83 | } xinputh_interface_t;
84 |
85 | extern usbh_class_driver_t const usbh_xinput_driver;
86 |
87 | /**
88 | * @brief Callback function called when a report is received from an XInput device.
89 | *
90 | * This function is called when a report is received from the specified XInput device.
91 | *
92 | * @param dev_addr Device address of the XInput device.
93 | * @param instance Instance of the XInput device.
94 | * @param xid_itf Pointer to the xif_itf structure containing the received report data and transfer result
95 | * @param len Length of the received report data.
96 | */
97 | void tuh_xinput_report_received_cb(uint8_t dev_addr, uint8_t instance, xinputh_interface_t const* xid_itf, uint16_t len);
98 |
99 | /**
100 | * @brief Weak callback function called when a report is sent to an XInput device.
101 | *
102 | * This function is a weakly bound callback called when a report is sent to the specified XInput device.
103 | * Implementing this function is optional, and the weak attribute allows it to be overridden if needed.
104 | *
105 | * @param dev_addr Device address of the XInput device.
106 | * @param instance Instance of the XInput device.
107 | * @param report Pointer to the sent report data.
108 | * @param len Length of the sent report data.
109 | */
110 | TU_ATTR_WEAK void tuh_xinput_report_sent_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len);
111 |
112 | /**
113 | * @brief Weak callback function called when an XInput device is unmounted.
114 | *
115 | * This function is a weakly bound callback called when an XInput device is unmounted.
116 | * Implementing this function is optional, and the weak attribute allows it to be overridden if needed.
117 | *
118 | * @param dev_addr Device address of the unmounted XInput device.
119 | * @param instance Instance of the unmounted XInput device.
120 | */
121 | TU_ATTR_WEAK void tuh_xinput_umount_cb(uint8_t dev_addr, uint8_t instance);
122 |
123 | /**
124 | * @brief Weak callback function called when an XInput device is mounted.
125 | *
126 | * This function is a weakly bound callback called when an XInput device is mounted.
127 | * Implementing this function is optional, and the weak attribute allows it to be overridden if needed.
128 | *
129 | * @param dev_addr Device address of the mounted XInput device.
130 | * @param instance Instance of the mounted XInput device.
131 | * @param xinput_itf Pointer to the XInput interface information.
132 | */
133 | TU_ATTR_WEAK void tuh_xinput_mount_cb(uint8_t dev_addr, uint8_t instance, const xinputh_interface_t *xinput_itf);
134 |
135 | /**
136 | * @brief Receive a report from an XInput device.
137 | *
138 | * This function attempts to receive a report from the specified XInput device.
139 | *
140 | * @param dev_addr Device address of the XInput device.
141 | * @param instance Instance of the XInput device.
142 | * @return True if the report is received successfully, false otherwise.
143 | */
144 | bool tuh_xinput_receive_report(uint8_t dev_addr, uint8_t instance);
145 |
146 | /**
147 | * @brief Send a report to an XInput device.
148 | *
149 | * This function attempts to send a report to the specified XInput device. This is a non blocking function.
150 | * tuh_xinput_report_sent_cb() is called when the transfer is completed.
151 | *
152 | * @param dev_addr Device address of the XInput device.
153 | * @param instance Instance of the XInput device.
154 | * @param txbuf Pointer to the data to be sent.
155 | * @param len Length of the data to be sent.
156 | * @return True if the report is sent successfully, false otherwise.
157 | */
158 | bool tuh_xinput_send_report(uint8_t dev_addr, uint8_t instance, const uint8_t *txbuf, uint16_t len);
159 |
160 | /**
161 | * @brief Set LED status on an XInput device. (Applicated to Xbox 360 controllers only)
162 | *
163 | * This function sets the LED status on the specified XInput device for the specified quadrant.
164 | *
165 | * @param dev_addr Device address of the XInput device.
166 | * @param instance Instance of the XInput device.
167 | * @param quadrant Quadrant of the LED to set.
168 | * @param block Indicates whether the operation should be blocking.
169 | * @return True if LED status is set successfully, false otherwise.
170 | */
171 | bool tuh_xinput_set_led(uint8_t dev_addr, uint8_t instance, uint8_t quadrant, bool block);
172 |
173 | /**
174 | * @brief Set rumble values on an XInput device.
175 | *
176 | * This function sets the rumble values on the specified XInput device for left and right motors.
177 | *
178 | * @param dev_addr Device address of the XInput device.
179 | * @param instance Instance of the XInput device.
180 | * @param lValue Intensity of the left motor rumble (0 to 255)
181 | * @param rValue Intensity of the right motor rumble. (0 to 255)
182 | * @param block Indicates whether the operation should be blocking.
183 | * @return True if rumble values are set successfully, false otherwise.
184 | */
185 | bool tuh_xinput_set_rumble(uint8_t dev_addr, uint8_t instance, uint8_t lValue, uint8_t rValue, bool block);
186 |
187 | #ifdef __cplusplus
188 | }
189 | #endif
190 |
191 | #endif /* _TUSB_XINPUT_HOST_H_ */
192 |
--------------------------------------------------------------------------------