├── .gitignore
├── LICENSE
├── README.md
├── images
├── 2devices.jpg
├── IMG_20210329_161906_1.jpg
└── lla
└── test_usb
├── CMakeLists.txt
├── Makefile
├── README.md
├── main
├── CMakeLists.txt
├── component.mk
├── usb_host.c
├── usb_host.h
└── usb_test.c
├── sdkconfig
└── sdkconfig.old
/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Object files
5 | *.o
6 | *.ko
7 | *.obj
8 | *.elf
9 |
10 | # Linker output
11 | *.ilk
12 | *.map
13 | *.exp
14 |
15 | # Precompiled Headers
16 | *.gch
17 | *.pch
18 |
19 | # Libraries
20 | *.lib
21 | *.a
22 | *.la
23 | *.lo
24 |
25 | # Shared objects (inc. Windows DLLs)
26 | *.dll
27 | *.so
28 | *.so.*
29 | *.dylib
30 |
31 | # Executables
32 | *.exe
33 | *.out
34 | *.app
35 | *.i*86
36 | *.x86_64
37 | *.hex
38 |
39 | # Debug files
40 | *.dSYM/
41 | *.su
42 | *.idb
43 | *.pdb
44 |
45 | # Kernel Module Compile Results
46 | *.mod*
47 | *.cmd
48 | .tmp_versions/
49 | modules.order
50 | Module.symvers
51 | Mkfile.old
52 | dkms.conf
53 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU AFFERO GENERAL PUBLIC LICENSE
2 | Version 3, 19 November 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 Affero General Public License is a free, copyleft license for
11 | software and other kinds of works, specifically designed to ensure
12 | cooperation with the community in the case of network server software.
13 |
14 | The licenses for most software and other practical works are designed
15 | to take away your freedom to share and change the works. By contrast,
16 | our General Public Licenses are intended to guarantee your freedom to
17 | share and change all versions of a program--to make sure it remains free
18 | software for all its users.
19 |
20 | When we speak of free software, we are referring to freedom, not
21 | price. Our General Public Licenses are designed to make sure that you
22 | have the freedom to distribute copies of free software (and charge for
23 | them if you wish), that you receive source code or can get it if you
24 | want it, that you can change the software or use pieces of it in new
25 | free programs, and that you know you can do these things.
26 |
27 | Developers that use our General Public Licenses protect your rights
28 | with two steps: (1) assert copyright on the software, and (2) offer
29 | you this License which gives you legal permission to copy, distribute
30 | and/or modify the software.
31 |
32 | A secondary benefit of defending all users' freedom is that
33 | improvements made in alternate versions of the program, if they
34 | receive widespread use, become available for other developers to
35 | incorporate. Many developers of free software are heartened and
36 | encouraged by the resulting cooperation. However, in the case of
37 | software used on network servers, this result may fail to come about.
38 | The GNU General Public License permits making a modified version and
39 | letting the public access it on a server without ever releasing its
40 | source code to the public.
41 |
42 | The GNU Affero General Public License is designed specifically to
43 | ensure that, in such cases, the modified source code becomes available
44 | to the community. It requires the operator of a network server to
45 | provide the source code of the modified version running there to the
46 | users of that server. Therefore, public use of a modified version, on
47 | a publicly accessible server, gives the public access to the source
48 | code of the modified version.
49 |
50 | An older license, called the Affero General Public License and
51 | published by Affero, was designed to accomplish similar goals. This is
52 | a different license, not a version of the Affero GPL, but Affero has
53 | released a new version of the Affero GPL which permits relicensing under
54 | this license.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | TERMS AND CONDITIONS
60 |
61 | 0. Definitions.
62 |
63 | "This License" refers to version 3 of the GNU Affero General Public License.
64 |
65 | "Copyright" also means copyright-like laws that apply to other kinds of
66 | works, such as semiconductor masks.
67 |
68 | "The Program" refers to any copyrightable work licensed under this
69 | License. Each licensee is addressed as "you". "Licensees" and
70 | "recipients" may be individuals or organizations.
71 |
72 | To "modify" a work means to copy from or adapt all or part of the work
73 | in a fashion requiring copyright permission, other than the making of an
74 | exact copy. The resulting work is called a "modified version" of the
75 | earlier work or a work "based on" the earlier work.
76 |
77 | A "covered work" means either the unmodified Program or a work based
78 | on the Program.
79 |
80 | To "propagate" a work means to do anything with it that, without
81 | permission, would make you directly or secondarily liable for
82 | infringement under applicable copyright law, except executing it on a
83 | computer or modifying a private copy. Propagation includes copying,
84 | distribution (with or without modification), making available to the
85 | public, and in some countries other activities as well.
86 |
87 | To "convey" a work means any kind of propagation that enables other
88 | parties to make or receive copies. Mere interaction with a user through
89 | a computer network, with no transfer of a copy, is not conveying.
90 |
91 | An interactive user interface displays "Appropriate Legal Notices"
92 | to the extent that it includes a convenient and prominently visible
93 | feature that (1) displays an appropriate copyright notice, and (2)
94 | tells the user that there is no warranty for the work (except to the
95 | extent that warranties are provided), that licensees may convey the
96 | work under this License, and how to view a copy of this License. If
97 | the interface presents a list of user commands or options, such as a
98 | menu, a prominent item in the list meets this criterion.
99 |
100 | 1. Source Code.
101 |
102 | The "source code" for a work means the preferred form of the work
103 | for making modifications to it. "Object code" means any non-source
104 | form of a work.
105 |
106 | A "Standard Interface" means an interface that either is an official
107 | standard defined by a recognized standards body, or, in the case of
108 | interfaces specified for a particular programming language, one that
109 | is widely used among developers working in that language.
110 |
111 | The "System Libraries" of an executable work include anything, other
112 | than the work as a whole, that (a) is included in the normal form of
113 | packaging a Major Component, but which is not part of that Major
114 | Component, and (b) serves only to enable use of the work with that
115 | Major Component, or to implement a Standard Interface for which an
116 | implementation is available to the public in source code form. A
117 | "Major Component", in this context, means a major essential component
118 | (kernel, window system, and so on) of the specific operating system
119 | (if any) on which the executable work runs, or a compiler used to
120 | produce the work, or an object code interpreter used to run it.
121 |
122 | The "Corresponding Source" for a work in object code form means all
123 | the source code needed to generate, install, and (for an executable
124 | work) run the object code and to modify the work, including scripts to
125 | control those activities. However, it does not include the work's
126 | System Libraries, or general-purpose tools or generally available free
127 | programs which are used unmodified in performing those activities but
128 | which are not part of the work. For example, Corresponding Source
129 | includes interface definition files associated with source files for
130 | the work, and the source code for shared libraries and dynamically
131 | linked subprograms that the work is specifically designed to require,
132 | such as by intimate data communication or control flow between those
133 | subprograms and other parts of the work.
134 |
135 | The Corresponding Source need not include anything that users
136 | can regenerate automatically from other parts of the Corresponding
137 | Source.
138 |
139 | The Corresponding Source for a work in source code form is that
140 | same work.
141 |
142 | 2. Basic Permissions.
143 |
144 | All rights granted under this License are granted for the term of
145 | copyright on the Program, and are irrevocable provided the stated
146 | conditions are met. This License explicitly affirms your unlimited
147 | permission to run the unmodified Program. The output from running a
148 | covered work is covered by this License only if the output, given its
149 | content, constitutes a covered work. This License acknowledges your
150 | rights of fair use or other equivalent, as provided by copyright law.
151 |
152 | You may make, run and propagate covered works that you do not
153 | convey, without conditions so long as your license otherwise remains
154 | in force. You may convey covered works to others for the sole purpose
155 | of having them make modifications exclusively for you, or provide you
156 | with facilities for running those works, provided that you comply with
157 | the terms of this License in conveying all material for which you do
158 | not control copyright. Those thus making or running the covered works
159 | for you must do so exclusively on your behalf, under your direction
160 | and control, on terms that prohibit them from making any copies of
161 | your copyrighted material outside their relationship with you.
162 |
163 | Conveying under any other circumstances is permitted solely under
164 | the conditions stated below. Sublicensing is not allowed; section 10
165 | makes it unnecessary.
166 |
167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168 |
169 | No covered work shall be deemed part of an effective technological
170 | measure under any applicable law fulfilling obligations under article
171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172 | similar laws prohibiting or restricting circumvention of such
173 | measures.
174 |
175 | When you convey a covered work, you waive any legal power to forbid
176 | circumvention of technological measures to the extent such circumvention
177 | is effected by exercising rights under this License with respect to
178 | the covered work, and you disclaim any intention to limit operation or
179 | modification of the work as a means of enforcing, against the work's
180 | users, your or third parties' legal rights to forbid circumvention of
181 | technological measures.
182 |
183 | 4. Conveying Verbatim Copies.
184 |
185 | You may convey verbatim copies of the Program's source code as you
186 | receive it, in any medium, provided that you conspicuously and
187 | appropriately publish on each copy an appropriate copyright notice;
188 | keep intact all notices stating that this License and any
189 | non-permissive terms added in accord with section 7 apply to the code;
190 | keep intact all notices of the absence of any warranty; and give all
191 | recipients a copy of this License along with the Program.
192 |
193 | You may charge any price or no price for each copy that you convey,
194 | and you may offer support or warranty protection for a fee.
195 |
196 | 5. Conveying Modified Source Versions.
197 |
198 | You may convey a work based on the Program, or the modifications to
199 | produce it from the Program, in the form of source code under the
200 | terms of section 4, provided that you also meet all of these conditions:
201 |
202 | a) The work must carry prominent notices stating that you modified
203 | it, and giving a relevant date.
204 |
205 | b) The work must carry prominent notices stating that it is
206 | released under this License and any conditions added under section
207 | 7. This requirement modifies the requirement in section 4 to
208 | "keep intact all notices".
209 |
210 | c) You must license the entire work, as a whole, under this
211 | License to anyone who comes into possession of a copy. This
212 | License will therefore apply, along with any applicable section 7
213 | additional terms, to the whole of the work, and all its parts,
214 | regardless of how they are packaged. This License gives no
215 | permission to license the work in any other way, but it does not
216 | invalidate such permission if you have separately received it.
217 |
218 | d) If the work has interactive user interfaces, each must display
219 | Appropriate Legal Notices; however, if the Program has interactive
220 | interfaces that do not display Appropriate Legal Notices, your
221 | work need not make them do so.
222 |
223 | A compilation of a covered work with other separate and independent
224 | works, which are not by their nature extensions of the covered work,
225 | and which are not combined with it such as to form a larger program,
226 | in or on a volume of a storage or distribution medium, is called an
227 | "aggregate" if the compilation and its resulting copyright are not
228 | used to limit the access or legal rights of the compilation's users
229 | beyond what the individual works permit. Inclusion of a covered work
230 | in an aggregate does not cause this License to apply to the other
231 | parts of the aggregate.
232 |
233 | 6. Conveying Non-Source Forms.
234 |
235 | You may convey a covered work in object code form under the terms
236 | of sections 4 and 5, provided that you also convey the
237 | machine-readable Corresponding Source under the terms of this License,
238 | in one of these ways:
239 |
240 | a) Convey the object code in, or embodied in, a physical product
241 | (including a physical distribution medium), accompanied by the
242 | Corresponding Source fixed on a durable physical medium
243 | customarily used for software interchange.
244 |
245 | b) Convey the object code in, or embodied in, a physical product
246 | (including a physical distribution medium), accompanied by a
247 | written offer, valid for at least three years and valid for as
248 | long as you offer spare parts or customer support for that product
249 | model, to give anyone who possesses the object code either (1) a
250 | copy of the Corresponding Source for all the software in the
251 | product that is covered by this License, on a durable physical
252 | medium customarily used for software interchange, for a price no
253 | more than your reasonable cost of physically performing this
254 | conveying of source, or (2) access to copy the
255 | Corresponding Source from a network server at no charge.
256 |
257 | c) Convey individual copies of the object code with a copy of the
258 | written offer to provide the Corresponding Source. This
259 | alternative is allowed only occasionally and noncommercially, and
260 | only if you received the object code with such an offer, in accord
261 | with subsection 6b.
262 |
263 | d) Convey the object code by offering access from a designated
264 | place (gratis or for a charge), and offer equivalent access to the
265 | Corresponding Source in the same way through the same place at no
266 | further charge. You need not require recipients to copy the
267 | Corresponding Source along with the object code. If the place to
268 | copy the object code is a network server, the Corresponding Source
269 | may be on a different server (operated by you or a third party)
270 | that supports equivalent copying facilities, provided you maintain
271 | clear directions next to the object code saying where to find the
272 | Corresponding Source. Regardless of what server hosts the
273 | Corresponding Source, you remain obligated to ensure that it is
274 | available for as long as needed to satisfy these requirements.
275 |
276 | e) Convey the object code using peer-to-peer transmission, provided
277 | you inform other peers where the object code and Corresponding
278 | Source of the work are being offered to the general public at no
279 | charge under subsection 6d.
280 |
281 | A separable portion of the object code, whose source code is excluded
282 | from the Corresponding Source as a System Library, need not be
283 | included in conveying the object code work.
284 |
285 | A "User Product" is either (1) a "consumer product", which means any
286 | tangible personal property which is normally used for personal, family,
287 | or household purposes, or (2) anything designed or sold for incorporation
288 | into a dwelling. In determining whether a product is a consumer product,
289 | doubtful cases shall be resolved in favor of coverage. For a particular
290 | product received by a particular user, "normally used" refers to a
291 | typical or common use of that class of product, regardless of the status
292 | of the particular user or of the way in which the particular user
293 | actually uses, or expects or is expected to use, the product. A product
294 | is a consumer product regardless of whether the product has substantial
295 | commercial, industrial or non-consumer uses, unless such uses represent
296 | the only significant mode of use of the product.
297 |
298 | "Installation Information" for a User Product means any methods,
299 | procedures, authorization keys, or other information required to install
300 | and execute modified versions of a covered work in that User Product from
301 | a modified version of its Corresponding Source. The information must
302 | suffice to ensure that the continued functioning of the modified object
303 | code is in no case prevented or interfered with solely because
304 | modification has been made.
305 |
306 | If you convey an object code work under this section in, or with, or
307 | specifically for use in, a User Product, and the conveying occurs as
308 | part of a transaction in which the right of possession and use of the
309 | User Product is transferred to the recipient in perpetuity or for a
310 | fixed term (regardless of how the transaction is characterized), the
311 | Corresponding Source conveyed under this section must be accompanied
312 | by the Installation Information. But this requirement does not apply
313 | if neither you nor any third party retains the ability to install
314 | modified object code on the User Product (for example, the work has
315 | been installed in ROM).
316 |
317 | The requirement to provide Installation Information does not include a
318 | requirement to continue to provide support service, warranty, or updates
319 | for a work that has been modified or installed by the recipient, or for
320 | the User Product in which it has been modified or installed. Access to a
321 | network may be denied when the modification itself materially and
322 | adversely affects the operation of the network or violates the rules and
323 | protocols for communication across the network.
324 |
325 | Corresponding Source conveyed, and Installation Information provided,
326 | in accord with this section must be in a format that is publicly
327 | documented (and with an implementation available to the public in
328 | source code form), and must require no special password or key for
329 | unpacking, reading or copying.
330 |
331 | 7. Additional Terms.
332 |
333 | "Additional permissions" are terms that supplement the terms of this
334 | License by making exceptions from one or more of its conditions.
335 | Additional permissions that are applicable to the entire Program shall
336 | be treated as though they were included in this License, to the extent
337 | that they are valid under applicable law. If additional permissions
338 | apply only to part of the Program, that part may be used separately
339 | under those permissions, but the entire Program remains governed by
340 | this License without regard to the additional permissions.
341 |
342 | When you convey a copy of a covered work, you may at your option
343 | remove any additional permissions from that copy, or from any part of
344 | it. (Additional permissions may be written to require their own
345 | removal in certain cases when you modify the work.) You may place
346 | additional permissions on material, added by you to a covered work,
347 | for which you have or can give appropriate copyright permission.
348 |
349 | Notwithstanding any other provision of this License, for material you
350 | add to a covered work, you may (if authorized by the copyright holders of
351 | that material) supplement the terms of this License with terms:
352 |
353 | a) Disclaiming warranty or limiting liability differently from the
354 | terms of sections 15 and 16 of this License; or
355 |
356 | b) Requiring preservation of specified reasonable legal notices or
357 | author attributions in that material or in the Appropriate Legal
358 | Notices displayed by works containing it; or
359 |
360 | c) Prohibiting misrepresentation of the origin of that material, or
361 | requiring that modified versions of such material be marked in
362 | reasonable ways as different from the original version; or
363 |
364 | d) Limiting the use for publicity purposes of names of licensors or
365 | authors of the material; or
366 |
367 | e) Declining to grant rights under trademark law for use of some
368 | trade names, trademarks, or service marks; or
369 |
370 | f) Requiring indemnification of licensors and authors of that
371 | material by anyone who conveys the material (or modified versions of
372 | it) with contractual assumptions of liability to the recipient, for
373 | any liability that these contractual assumptions directly impose on
374 | those licensors and authors.
375 |
376 | All other non-permissive additional terms are considered "further
377 | restrictions" within the meaning of section 10. If the Program as you
378 | received it, or any part of it, contains a notice stating that it is
379 | governed by this License along with a term that is a further
380 | restriction, you may remove that term. If a license document contains
381 | a further restriction but permits relicensing or conveying under this
382 | License, you may add to a covered work material governed by the terms
383 | of that license document, provided that the further restriction does
384 | not survive such relicensing or conveying.
385 |
386 | If you add terms to a covered work in accord with this section, you
387 | must place, in the relevant source files, a statement of the
388 | additional terms that apply to those files, or a notice indicating
389 | where to find the applicable terms.
390 |
391 | Additional terms, permissive or non-permissive, may be stated in the
392 | form of a separately written license, or stated as exceptions;
393 | the above requirements apply either way.
394 |
395 | 8. Termination.
396 |
397 | You may not propagate or modify a covered work except as expressly
398 | provided under this License. Any attempt otherwise to propagate or
399 | modify it is void, and will automatically terminate your rights under
400 | this License (including any patent licenses granted under the third
401 | paragraph of section 11).
402 |
403 | However, if you cease all violation of this License, then your
404 | license from a particular copyright holder is reinstated (a)
405 | provisionally, unless and until the copyright holder explicitly and
406 | finally terminates your license, and (b) permanently, if the copyright
407 | holder fails to notify you of the violation by some reasonable means
408 | prior to 60 days after the cessation.
409 |
410 | Moreover, your license from a particular copyright holder is
411 | reinstated permanently if the copyright holder notifies you of the
412 | violation by some reasonable means, this is the first time you have
413 | received notice of violation of this License (for any work) from that
414 | copyright holder, and you cure the violation prior to 30 days after
415 | your receipt of the notice.
416 |
417 | Termination of your rights under this section does not terminate the
418 | licenses of parties who have received copies or rights from you under
419 | this License. If your rights have been terminated and not permanently
420 | reinstated, you do not qualify to receive new licenses for the same
421 | material under section 10.
422 |
423 | 9. Acceptance Not Required for Having Copies.
424 |
425 | You are not required to accept this License in order to receive or
426 | run a copy of the Program. Ancillary propagation of a covered work
427 | occurring solely as a consequence of using peer-to-peer transmission
428 | to receive a copy likewise does not require acceptance. However,
429 | nothing other than this License grants you permission to propagate or
430 | modify any covered work. These actions infringe copyright if you do
431 | not accept this License. Therefore, by modifying or propagating a
432 | covered work, you indicate your acceptance of this License to do so.
433 |
434 | 10. Automatic Licensing of Downstream Recipients.
435 |
436 | Each time you convey a covered work, the recipient automatically
437 | receives a license from the original licensors, to run, modify and
438 | propagate that work, subject to this License. You are not responsible
439 | for enforcing compliance by third parties with this License.
440 |
441 | An "entity transaction" is a transaction transferring control of an
442 | organization, or substantially all assets of one, or subdividing an
443 | organization, or merging organizations. If propagation of a covered
444 | work results from an entity transaction, each party to that
445 | transaction who receives a copy of the work also receives whatever
446 | licenses to the work the party's predecessor in interest had or could
447 | give under the previous paragraph, plus a right to possession of the
448 | Corresponding Source of the work from the predecessor in interest, if
449 | the predecessor has it or can get it with reasonable efforts.
450 |
451 | You may not impose any further restrictions on the exercise of the
452 | rights granted or affirmed under this License. For example, you may
453 | not impose a license fee, royalty, or other charge for exercise of
454 | rights granted under this License, and you may not initiate litigation
455 | (including a cross-claim or counterclaim in a lawsuit) alleging that
456 | any patent claim is infringed by making, using, selling, offering for
457 | sale, or importing the Program or any portion of it.
458 |
459 | 11. Patents.
460 |
461 | A "contributor" is a copyright holder who authorizes use under this
462 | License of the Program or a work on which the Program is based. The
463 | work thus licensed is called the contributor's "contributor version".
464 |
465 | A contributor's "essential patent claims" are all patent claims
466 | owned or controlled by the contributor, whether already acquired or
467 | hereafter acquired, that would be infringed by some manner, permitted
468 | by this License, of making, using, or selling its contributor version,
469 | but do not include claims that would be infringed only as a
470 | consequence of further modification of the contributor version. For
471 | purposes of this definition, "control" includes the right to grant
472 | patent sublicenses in a manner consistent with the requirements of
473 | this License.
474 |
475 | Each contributor grants you a non-exclusive, worldwide, royalty-free
476 | patent license under the contributor's essential patent claims, to
477 | make, use, sell, offer for sale, import and otherwise run, modify and
478 | propagate the contents of its contributor version.
479 |
480 | In the following three paragraphs, a "patent license" is any express
481 | agreement or commitment, however denominated, not to enforce a patent
482 | (such as an express permission to practice a patent or covenant not to
483 | sue for patent infringement). To "grant" such a patent license to a
484 | party means to make such an agreement or commitment not to enforce a
485 | patent against the party.
486 |
487 | If you convey a covered work, knowingly relying on a patent license,
488 | and the Corresponding Source of the work is not available for anyone
489 | to copy, free of charge and under the terms of this License, through a
490 | publicly available network server or other readily accessible means,
491 | then you must either (1) cause the Corresponding Source to be so
492 | available, or (2) arrange to deprive yourself of the benefit of the
493 | patent license for this particular work, or (3) arrange, in a manner
494 | consistent with the requirements of this License, to extend the patent
495 | license to downstream recipients. "Knowingly relying" means you have
496 | actual knowledge that, but for the patent license, your conveying the
497 | covered work in a country, or your recipient's use of the covered work
498 | in a country, would infringe one or more identifiable patents in that
499 | country that you have reason to believe are valid.
500 |
501 | If, pursuant to or in connection with a single transaction or
502 | arrangement, you convey, or propagate by procuring conveyance of, a
503 | covered work, and grant a patent license to some of the parties
504 | receiving the covered work authorizing them to use, propagate, modify
505 | or convey a specific copy of the covered work, then the patent license
506 | you grant is automatically extended to all recipients of the covered
507 | work and works based on it.
508 |
509 | A patent license is "discriminatory" if it does not include within
510 | the scope of its coverage, prohibits the exercise of, or is
511 | conditioned on the non-exercise of one or more of the rights that are
512 | specifically granted under this License. You may not convey a covered
513 | work if you are a party to an arrangement with a third party that is
514 | in the business of distributing software, under which you make payment
515 | to the third party based on the extent of your activity of conveying
516 | the work, and under which the third party grants, to any of the
517 | parties who would receive the covered work from you, a discriminatory
518 | patent license (a) in connection with copies of the covered work
519 | conveyed by you (or copies made from those copies), or (b) primarily
520 | for and in connection with specific products or compilations that
521 | contain the covered work, unless you entered into that arrangement,
522 | or that patent license was granted, prior to 28 March 2007.
523 |
524 | Nothing in this License shall be construed as excluding or limiting
525 | any implied license or other defenses to infringement that may
526 | otherwise be available to you under applicable patent law.
527 |
528 | 12. No Surrender of Others' Freedom.
529 |
530 | If conditions are imposed on you (whether by court order, agreement or
531 | otherwise) that contradict the conditions of this License, they do not
532 | excuse you from the conditions of this License. If you cannot convey a
533 | covered work so as to satisfy simultaneously your obligations under this
534 | License and any other pertinent obligations, then as a consequence you may
535 | not convey it at all. For example, if you agree to terms that obligate you
536 | to collect a royalty for further conveying from those to whom you convey
537 | the Program, the only way you could satisfy both those terms and this
538 | License would be to refrain entirely from conveying the Program.
539 |
540 | 13. Remote Network Interaction; Use with the GNU General Public License.
541 |
542 | Notwithstanding any other provision of this License, if you modify the
543 | Program, your modified version must prominently offer all users
544 | interacting with it remotely through a computer network (if your version
545 | supports such interaction) an opportunity to receive the Corresponding
546 | Source of your version by providing access to the Corresponding Source
547 | from a network server at no charge, through some standard or customary
548 | means of facilitating copying of software. This Corresponding Source
549 | shall include the Corresponding Source for any work covered by version 3
550 | of the GNU General Public License that is incorporated pursuant to the
551 | following paragraph.
552 |
553 | Notwithstanding any other provision of this License, you have
554 | permission to link or combine any covered work with a work licensed
555 | under version 3 of the GNU General Public License into a single
556 | combined work, and to convey the resulting work. The terms of this
557 | License will continue to apply to the part which is the covered work,
558 | but the work with which it is combined will remain governed by version
559 | 3 of the GNU General Public License.
560 |
561 | 14. Revised Versions of this License.
562 |
563 | The Free Software Foundation may publish revised and/or new versions of
564 | the GNU Affero General Public License from time to time. Such new versions
565 | will be similar in spirit to the present version, but may differ in detail to
566 | address new problems or concerns.
567 |
568 | Each version is given a distinguishing version number. If the
569 | Program specifies that a certain numbered version of the GNU Affero General
570 | Public License "or any later version" applies to it, you have the
571 | option of following the terms and conditions either of that numbered
572 | version or of any later version published by the Free Software
573 | Foundation. If the Program does not specify a version number of the
574 | GNU Affero General Public License, you may choose any version ever published
575 | by the Free Software Foundation.
576 |
577 | If the Program specifies that a proxy can decide which future
578 | versions of the GNU Affero General Public License can be used, that proxy's
579 | public statement of acceptance of a version permanently authorizes you
580 | to choose that version for the Program.
581 |
582 | Later license versions may give you additional or different
583 | permissions. However, no additional obligations are imposed on any
584 | author or copyright holder as a result of your choosing to follow a
585 | later version.
586 |
587 | 15. Disclaimer of Warranty.
588 |
589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597 |
598 | 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608 | SUCH DAMAGES.
609 |
610 | 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
620 |
621 | How to Apply These Terms to Your New Programs
622 |
623 | If you develop a new program, and you want it to be of the greatest
624 | possible use to the public, the best way to achieve this is to make it
625 | free software which everyone can redistribute and change under these terms.
626 |
627 | To do so, attach the following notices to the program. It is safest
628 | to attach them to the start of each source file to most effectively
629 | state the exclusion of warranty; and each file should have at least
630 | the "copyright" line and a pointer to where the full notice is found.
631 |
632 |
633 | Copyright (C)
634 |
635 | This program is free software: you can redistribute it and/or modify
636 | it under the terms of the GNU Affero General Public License as published
637 | by the Free Software Foundation, either version 3 of the License, or
638 | (at your option) any later version.
639 |
640 | This program is distributed in the hope that it will be useful,
641 | but WITHOUT ANY WARRANTY; without even the implied warranty of
642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643 | GNU Affero General Public License for more details.
644 |
645 | You should have received a copy of the GNU Affero General Public License
646 | along with this program. If not, see .
647 |
648 | Also add information on how to contact you by electronic and paper mail.
649 |
650 | If your software can interact with users remotely through a computer
651 | network, you should also make sure that it provides a way for users to
652 | get its source. For example, if your program is a web application, its
653 | interface could display a "Source" link that leads users to an archive
654 | of the code. There are many ways you could offer source, and different
655 | solutions will be better for different programs; see section 13 for the
656 | specific requirements.
657 |
658 | You should also get your employer (if you work as a programmer) or school,
659 | if any, to sign a "copyright disclaimer" for the program, if necessary.
660 | For more information on this, and how to apply and follow the GNU AGPL, see
661 | .
662 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # esp8266_usb_soft_host
2 |
3 | Test for esp8266 usb host . Works with ESP-IDF v3.4 80MHz and 160MHz. WorkInProgress
4 |
5 | 
6 |
7 | Test run with mouse & combined mouse & keyboard , $3 CY7C68013A logic analyser and amazing program https://sigrok.org/wiki/PulseView
8 | 
9 |
10 |
--------------------------------------------------------------------------------
/images/2devices.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sdima1357/esp8266_usb_soft_host/1f567c0b92943ad320aa490c5177e1a8576b9496/images/2devices.jpg
--------------------------------------------------------------------------------
/images/IMG_20210329_161906_1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sdima1357/esp8266_usb_soft_host/1f567c0b92943ad320aa490c5177e1a8576b9496/images/IMG_20210329_161906_1.jpg
--------------------------------------------------------------------------------
/images/lla:
--------------------------------------------------------------------------------
1 | 2devices.jpg
2 | IMG_20210329_161906_1.jpg
3 | lla
4 |
--------------------------------------------------------------------------------
/test_usb/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # The following lines of boilerplate have to be in your project's
2 | # CMakeLists in this exact order for cmake to work correctly
3 | cmake_minimum_required(VERSION 3.5)
4 |
5 | include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6 | project(hello-world)
--------------------------------------------------------------------------------
/test_usb/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a
3 | # project subdirectory.
4 | #
5 |
6 | PROJECT_NAME := hello-world
7 |
8 | include $(IDF_PATH)/make/project.mk
9 |
10 |
--------------------------------------------------------------------------------
/test_usb/README.md:
--------------------------------------------------------------------------------
1 | # Hello World Example
2 |
3 | Starts a FreeRTOS task to print "Hello World"
4 |
5 | See the README.md file in the upper level 'examples' directory for more information about examples.
6 |
--------------------------------------------------------------------------------
/test_usb/main/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | idf_component_register(SRCS "hello_world_main.c"
2 | INCLUDE_DIRS "")
--------------------------------------------------------------------------------
/test_usb/main/component.mk:
--------------------------------------------------------------------------------
1 | #
2 | # "main" pseudo-component makefile.
3 | #
4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
5 |
6 |
--------------------------------------------------------------------------------
/test_usb/main/usb_host.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include "freertos/FreeRTOS.h"
9 | #include "freertos/task.h"
10 | #include "esp_system.h"
11 | #include "esp_spi_flash.h"
12 | #include "esp8266/eagle_soc.h"
13 | #include "esp8266/pin_mux_register.h"
14 | #include "esp8266/gpio_struct.h"
15 | #include "esp_clk.h"
16 | #include "driver/gpio.h"
17 | #include "esp_heap_caps.h"
18 | #include
19 | int lt;
20 | //~ #include "driver/gpio.h"
21 | //~ #include "sdkconfig.h"
22 | //~ #include "driver/timer.h"
23 | //~ #include "soc/soc.h"
24 | //~ #include "soc/rtc.h"
25 | //~ #include
26 | //~ #include "esp_heap_caps.h"
27 | /*******************************
28 | * warning!!!: any copy of this code or his part must include this:
29 | * "The original was written by Dima Samsonov @ Israel sdima1357@gmail.com on 3/2021" *
30 | * Copyright (C) 2021 Dmitry Samsonov *
31 | ********************************/
32 |
33 | #include "usb_host.h"
34 |
35 | #define T_START 0b00000001
36 | #define T_ACK 0b01001011
37 | #define T_NACK 0b01011010
38 | #define T_SOF 0b10100101
39 | #define T_SETUP 0b10110100
40 | #define T_DATA0 0b11000011
41 | #define T_DATA1 0b11010010
42 | #define T_DATA2 0b11100001
43 | #define T_OUT 0b10000111
44 | #define T_IN 0b10010110
45 |
46 | #define T_ERR 0b00111100
47 | #define T_PRE 0b00111100
48 | #define T_NYET 0b01101001
49 | #define T_STALL 0b01111000
50 |
51 | // local non std
52 | #define T_NEED_ACK 0b01111011
53 | #define T_CHK_ERR 0b01111111
54 |
55 | #define USB_LS_K 0
56 | #define USB_LS_J 1
57 | #define USB_LS_S 2
58 |
59 | //most counters- uint_8t : so prevents overflow...
60 |
61 | #define DEF_BUFF_SIZE 0x100
62 |
63 | // somethins short like ACK
64 | #define SMALL_NO_DATA 36
65 |
66 |
67 | ///cpufreq (must be 240) /8 count = 30MHz convinient number for measure 1.5MHz of low speed USB
68 | //#pragma GCC optimize ("-O2")
69 | inline uint8_t _getCycleCount8d4(void) {
70 | uint32_t ccount;
71 | __asm__ __volatile__("rsr %0,ccount":"=a" (ccount));
72 | return ccount>>2;
73 | }
74 | //#pragma GCC optimize ("-O2")
75 | inline uint32_t _getCycleCount32(void) {
76 | uint32_t ccount;
77 | __asm__ __volatile__("rsr %0,ccount":"=a" (ccount));
78 | return ccount;
79 | }
80 |
81 |
82 | //timing calibrations which depends CPU_FREQ, calibrated in initPins()
83 |
84 | int TRANSMIT_TIME_DELAY = 110; //delay each bit transmit
85 | int TIME_MULT = 25; //received time factor delta clocks* TIME_MULT/TIME_SCALE
86 | int TM_OUT = 64; //receive time out no activity on bus
87 | #define TIME_SCALE (1024)
88 |
89 | //#define TEST
90 | #ifdef TEST
91 | #define TOUT 1000
92 | #else
93 | #define TOUT (TM_OUT)
94 | #endif
95 |
96 |
97 |
98 | #define SET_I {GPIO.enable_w1tc = RD_MASK; }
99 | #define SET_O { GPIO.enable_w1ts = RD_MASK; }
100 |
101 | #define SE_J { *snd[1][0] = (1 << DM_PIN);*snd[1][1] = (1 << DP_PIN); }
102 | #define SE_0 { GPIO.out_w1tc= RD_MASK; }
103 |
104 | //#define READ_BOTH_PINS (((GPIO.in&(0x3*(1<>(DP_PIN))<<8)
105 | #define READ_BOTH_PINS ((GPIO.in&RD_MASK)>>RD_SHIFT)
106 |
107 | //must be setup ech time with setPins
108 | uint16_t DP_PIN;
109 | uint16_t DM_PIN;
110 |
111 | uint16_t DM_PIN_M;
112 | uint16_t DP_PIN_M;
113 | uint16_t BOTH_PINS;
114 |
115 | uint16_t M_ONE;
116 | uint16_t P_ONE;
117 | uint16_t RD_MASK;
118 | uint16_t RD_SHIFT;
119 | //end must be setup ech time with setPins
120 |
121 |
122 | // temporary used insize lowlevel
123 | uint8_t received_NRZI_buffer_bytesCnt;
124 | uint16_t received_NRZI_buffer[DEF_BUFF_SIZE];
125 |
126 | uint8_t transmit_bits_buffer_store_cnt;
127 |
128 |
129 | //uint8_t transmit_bits_buffer_store[DEF_BUFF_SIZE];
130 | // share same memory as received_NRZI_buffer
131 | uint8_t* transmit_bits_buffer_store = (uint8_t*)&received_NRZI_buffer[0];
132 |
133 |
134 | uint8_t transmit_NRZI_buffer_cnt;
135 | uint8_t transmit_NRZI_buffer[DEF_BUFF_SIZE];
136 |
137 | uint8_t decoded_receive_buffer_head;
138 | uint8_t decoded_receive_buffer_tail;
139 | uint8_t decoded_receive_buffer[DEF_BUFF_SIZE];
140 | // end temporary used insize lowlevel
141 |
142 | #if 0
143 | #define TNOP1 { __asm__ __volatile__(" nop"); }
144 | #define TNOP2 {TNOP1 TNOP1}
145 | #define TNOP4 {TNOP2 TNOP2}
146 | #define TNOP8 {TNOP4 TNOP4}
147 | #define TNOP16 {TNOP8 TNOP8}
148 | #define TNOP32 {TNOP16 TNOP16}
149 | #define TNOP64 {TNOP32 TNOP32}
150 |
151 |
152 | //__volatile__ void dummy0(){printf("dummy0");}
153 | __volatile__ void cpuDelayB()
154 | {
155 | TNOP64;
156 | TNOP64;
157 | TNOP64;
158 | TNOP64;
159 | // __asm__ __volatile__(" nop");
160 |
161 | // tick = DWT->CYCCNT + tick;
162 | // while((DWT->CYCCNT - tick)&0x80000000u);
163 | }
164 | //__volatile__ void dummy1(){printf("dummy1");}
165 |
166 | //typedef void *pfnc(uint32_t);
167 |
168 |
169 | volatile void (*delay_pntA)() = &cpuDelayB;
170 |
171 | #define cpuDelay(x) {(*delay_pntA)();}
172 | #if 0
173 | void cpuDelay(uint32_t tick)
174 | {
175 | //uint8_t* pnt = (uint8_t*)&cpuDelay;
176 | //void (*delay_pnt)() = (&cpuDelayB)+((256-tick)*2);
177 | (*delay_pntA)();
178 | }
179 | #endif
180 | void setDelay(uint32_t tick)
181 | {
182 | delay_pntA = (&cpuDelayB)+((256-tick)*2);
183 | }
184 | #endif
185 | #if 1
186 | #if 1
187 | //#define MALLOC_CAP_EXEC (1 << 0)
188 | void (*delay_pntA)() =NULL;
189 | #define cpuDelay(x) {(*delay_pntA)();}
190 | void setDelay(uint8_t ticks)
191 | {
192 | // opcodes of void test_delay() {__asm__ (" nop"); __asm__ (" nop"); __asm__ (" nop"); ...}
193 | //3d f0 0d f0 00 // one nop
194 | //3d f0 3d f0 0d f0 00 // one nop
195 | int MAX_DELAY_CODE_SIZE = 0x280;
196 | uint8_t* pntS;
197 | // it can't execute but can read & write
198 | if(!delay_pntA)
199 | {
200 | pntS = malloc(MAX_DELAY_CODE_SIZE);
201 | }
202 | else
203 | {
204 | pntS = heap_caps_realloc(delay_pntA, MAX_DELAY_CODE_SIZE, MALLOC_CAP_8BIT);
205 | }
206 | uint8_t* pnt = (uint8_t*)pntS;
207 | //put head of delay procedure
208 | //~ *pnt++ = 0x36;
209 | //~ *pnt++ = 0x41;
210 | //~ *pnt++ = 0;
211 | for(int k=0;k0x8000000u);
246 | }
247 | #endif
248 | #endif
249 | void del1()
250 | {
251 | __asm__ __volatile__(" nop");
252 | }
253 | void del2()
254 | {
255 | __asm__ __volatile__(" nop");
256 | __asm__ __volatile__(" nop");
257 | }
258 | void del3()
259 | {
260 | __asm__ __volatile__(" nop");
261 | __asm__ __volatile__(" nop");
262 | __asm__ __volatile__(" nop");
263 | }
264 |
265 |
266 | typedef __packed struct
267 | {
268 | uint8_t cmd;
269 | uint8_t addr;
270 | uint8_t eop;
271 |
272 | uint8_t dataCmd;
273 | uint8_t bmRequestType;
274 | uint8_t bmRequest;
275 | uint16_t wValue;
276 | uint16_t wIndex;
277 | uint16_t wLen;
278 | }Req;
279 | enum DeviceState { NOT_ATTACHED,ATTACHED,POWERED,DEFAULT,ADDRESS,
280 | PARSE_CONFIG,PARSE_CONFIG1,PARSE_CONFIG2,PARSE_CONFIG3,
281 | POST_ATTACHED,RESET_COMPLETE,POWERED_COMPLETE,DEFAULT_COMPL} ;
282 |
283 | enum CallbackCmd {CB_CHECK,CB_RESET,CB_WAIT0,CB_POWER,CB_TICK,CB_2,CB_2Ack,CB_3,CB_4,CB_5,CB_6,CB_7,CB_8,CB_9,CB_WAIT1} ;
284 |
285 | //Req rq;
286 | typedef struct
287 | {
288 | int isValid;
289 | int selfNum;
290 | int epCount;
291 | int cnt;
292 | uint32_t DP;
293 | uint32_t DM;
294 | enum CallbackCmd cb_Cmd;
295 | enum DeviceState fsm_state;
296 | uint16_t wires_last_state;
297 | sDevDesc desc;
298 | sCfgDesc cfg;
299 | Req rq;
300 |
301 | int counterNAck;
302 | int counterAck;
303 |
304 | uint8_t descrBuffer[DEF_BUFF_SIZE];
305 | uint8_t descrBufferLen;
306 |
307 | int bComplete;
308 | int in_data_flip_flop;
309 | int cmdTimeOut;
310 | uint32_t ufPrintDesc;
311 | int numb_reps_errors_allowed;
312 |
313 | uint8_t acc_decoded_resp[DEF_BUFF_SIZE];
314 | uint8_t acc_decoded_resp_counter;
315 |
316 | int asckedReceiveBytes;
317 | int transmitL1Bytes;
318 | uint8_t transmitL1[DEF_BUFF_SIZE];
319 |
320 | //~ uint8_t Resp0[DEF_BUFF_SIZE];
321 | //~ uint8_t R0Bytes;
322 | //~ uint8_t Resp1[DEF_BUFF_SIZE];
323 | //~ uint8_t R1Bytes;
324 |
325 | int bAcked;
326 |
327 | } sUsbContStruct;
328 |
329 | sUsbContStruct * current;
330 |
331 | void parseImmed(sUsbContStruct * pcurrent)
332 | {
333 | static sCfgDesc cfg;
334 | static sIntfDesc sIntf;
335 | static HIDDescriptor hid[4];
336 | static sEPDesc epd;
337 | static int cfgCount = 0;
338 | static int sIntfCount = 0;
339 | static int hidCount = 0;
340 |
341 | int pos = 0;
342 | #define STDCLASS 0x00
343 | #define HIDCLASS 0x03
344 | #define HUBCLASS 0x09 /* bDeviceClass, bInterfaceClass */
345 | pcurrent->epCount = 0;
346 | while(posdescrBufferLen-2)
347 |
348 | {
349 | uint8_t len = pcurrent->descrBuffer[pos];
350 | uint8_t type = pcurrent->descrBuffer[pos+1];
351 | if(len==0)
352 | {
353 | //printf("pos = %02x type = %02x cfg.wLength = %02x pcurrent->acc_decoded_resp_counter = %02x\n ",pos,type,cfg.wLength,pcurrent->acc_decoded_resp_counter);
354 | pos = pcurrent->descrBufferLen;
355 | }
356 | if(pos+len<=pcurrent->descrBufferLen)
357 | {
358 | if(type == 0x2)
359 | {
360 | memcpy(&cfg,&pcurrent->descrBuffer[pos],len);
361 |
362 | }
363 | else if (type == 0x4)
364 | {
365 | memcpy(&sIntf,&pcurrent->descrBuffer[pos],len);
366 | }
367 | else if (type == 0x21)
368 | {
369 |
370 | hidCount++;
371 | int i = hidCount-1;
372 | memcpy(&hid[i],&pcurrent->descrBuffer[pos],len);
373 | }
374 | else if (type == 0x5)
375 | {
376 | pcurrent->epCount++;
377 | memcpy(&epd,&pcurrent->descrBuffer[pos],len);
378 | }
379 | }
380 | pos+=len;
381 | }
382 | }
383 |
384 |
385 |
386 |
387 |
388 | // received data from ep0,ep1!!!!
389 | //uint8_t current->Resp0[DEF_BUFF_SIZE];
390 | //uint8_t current->R0Bytes;
391 | //uint8_t current->Resp1[DEF_BUFF_SIZE];
392 | //uint8_t current->R1Bytes;
393 |
394 |
395 |
396 | uint32_t * snd[4][2] = {
397 | {&GPIO.out_w1tc,&GPIO.out_w1ts},
398 | {&GPIO.out_w1ts,&GPIO.out_w1tc},
399 | {&GPIO.out_w1tc,&GPIO.out_w1tc},
400 | {&GPIO.out_w1tc,&GPIO.out_w1tc}
401 | } ;
402 |
403 |
404 | #ifdef WR_SIMULTA
405 | uint32_t sndA[4] = {0,0,0,0};
406 | #endif
407 |
408 |
409 |
410 |
411 | void restart()
412 | {
413 | transmit_NRZI_buffer_cnt = 0;
414 | }
415 |
416 | void decoded_receive_buffer_clear()
417 | {
418 | decoded_receive_buffer_tail = decoded_receive_buffer_head;
419 | }
420 |
421 | void decoded_receive_buffer_put(uint8_t val)
422 | {
423 | decoded_receive_buffer[decoded_receive_buffer_head] = val;
424 | decoded_receive_buffer_head++;
425 | }
426 |
427 | uint8_t decoded_receive_buffer_get()
428 | {
429 | return decoded_receive_buffer[decoded_receive_buffer_tail++];
430 | }
431 |
432 | uint8_t decoded_receive_buffer_size()
433 | {
434 | return (uint8_t )(decoded_receive_buffer_head-decoded_receive_buffer_tail);
435 | }
436 |
437 | uint8_t cal5()
438 | {
439 | uint8_t crcb;
440 | uint8_t rem;
441 |
442 | crcb = 0b00101;
443 | rem = 0b11111;
444 |
445 | for(int k=16;k>4)&1;
448 | rem = (rem<<1)&0b11111;
449 |
450 | if(rb^(transmit_bits_buffer_store[k]&1))
451 | {
452 | rem ^= crcb;
453 | }
454 | }
455 | return (~rem)&0b11111;
456 | }
457 | uint32_t cal16()
458 | {
459 | uint32_t crcb;
460 | uint32_t rem;
461 |
462 | crcb = 0b1000000000000101;
463 | rem = 0b1111111111111111;
464 |
465 | for(int k=16;k>15)&1;
468 | rem = (rem<<1)&0b1111111111111111;
469 |
470 | if(rb^(transmit_bits_buffer_store[k]&1))
471 | {
472 | rem ^= crcb;
473 | }
474 | }
475 | return (~rem)&0b1111111111111111;
476 | }
477 | void seB(int bit)
478 | {
479 | transmit_bits_buffer_store[transmit_bits_buffer_store_cnt++] = bit;
480 | }
481 |
482 | void pu_MSB(uint16_t msg,int N)
483 | {
484 | for(int k=0;k>i)&1;
562 | }
563 | return res;
564 | }
565 | uint16_t rev16(uint16_t j)
566 | {
567 | uint16_t res = 0;
568 | for(int i=0;i<16;i++)
569 | {
570 | res<<=1;
571 | res|=(j>>i)&1;
572 | }
573 | return res;
574 | }
575 | #ifdef DEBUG_ALL
576 | uint16_t debug_buff[0x100];
577 | #endif
578 |
579 | int parse_received_NRZI_buffer()
580 | {
581 |
582 | if(!received_NRZI_buffer_bytesCnt) return 0;
583 |
584 | uint32_t crcb;
585 | uint32_t rem;
586 |
587 | crcb = 0b1000000000000101;
588 | rem = 0b1111111111111111;
589 |
590 | int res = 0;
591 | int cntOnes = 0;
592 |
593 | int terr = 0;
594 | uint8_t current_res = 0xfe;
595 | uint16_t prev = received_NRZI_buffer[0];
596 | int start = -1;
597 | uint8_t prev_smb = M_ONE;
598 | #ifdef DEBUG_ALL
599 | debug_buff[0] = received_NRZI_buffer_bytesCnt;
600 | uint8_t rcnt = 1;
601 | debug_buff[received_NRZI_buffer_bytesCnt] = 0xff;
602 | #endif
603 | for(int i = 1;i>8;
610 | int tm = (curr&0xff);
611 | //debug_buff[i] = tm | (smb<<8);
612 | if( tm<2 || (smb == 0) )
613 | {
614 | //terr+=tm<4?tm : 4;
615 | terr+=tm;
616 | }
617 | else
618 | {
619 | //terr = 0;
620 | int delta = ((((curr+terr)&0xff))*TIME_MULT+TIME_SCALE/2)/TIME_SCALE;
621 |
622 | for(int k=0;k=0)
644 | {
645 | start+=incc;
646 | }
647 | if(current_res==0x1 && start<0 )
648 | {
649 | start = 0;
650 | }
651 | if( (start&0x7) == 0 && incc)
652 | {
653 | if(start==8)
654 | {
655 | res = current_res;
656 | }
657 | #ifdef DEBUG_ALL
658 | debug_buff[rcnt++] = current_res;
659 | #endif
660 | decoded_receive_buffer_put(current_res);
661 | if(start>8)
662 | {
663 | for(int bt =0;bt<8;bt++)
664 | {
665 | int rb = (rem>>15)&1;
666 | rem = (rem<<1)&0b1111111111111111;
667 | if(rb^((current_res>>(7-bt))&1))
668 | {
669 | rem ^= crcb;
670 | }
671 | }
672 | }
673 | }
674 |
675 | }
676 |
677 | prev_smb = smb;
678 | }
679 | terr = 0;
680 | }
681 | }
682 | #ifdef DEBUG_ALL
683 | debug_buff[rcnt++] = 0xff;
684 | #endif
685 | rem &=0b1111111111111111;
686 | if (rem==0b1111111111111111)
687 | {
688 | return res;
689 | }
690 | if(rem==0x800d)
691 | {
692 | return T_NEED_ACK;
693 | }
694 | else
695 | {
696 | return T_CHK_ERR;
697 | }
698 | }
699 |
700 |
701 |
702 | //#define WR_SIMULTA
703 | //#pragma GCC optimize ("-O2")
704 | #pragma GCC optimize ("-O2")
705 | void sendOnly()
706 | {
707 | uint8_t k;
708 | SET_O;
709 | #ifdef WR_SIMULTA
710 | uint32_t out_base = GPIO.out;
711 | sndA[0] = (out_base | DP) &~DM;
712 | sndA[1] = (out_base | DM) &~DP;
713 | sndA[2] = (out_base )&~(DP | DM);
714 | sndA[3] = out_base | (DM | DP);
715 | #endif
716 | for(k=0;k=160MHz .
737 | void sendRecieveNParse()
738 | {
739 | uint8_t locRec = 0;
740 | uint32_t val = 0xff;//DM_GPIO_Port->IDR&(0x3*DP_Pin);
741 | uint32_t nval = 0xff;
742 | int32_t act = TOUT;
743 | // portDISABLE_INTERRUPTS();
744 | sendOnly();
745 | while(act>0 && (val||nval) )
746 | {
747 | val = nval;
748 | nval = READ_BOTH_PINS;
749 | received_NRZI_buffer[locRec] = _getCycleCount8d8() | nval;
750 | if(val!=nval)
751 | {
752 | locRec++;
753 | act = TOUT;
754 | }
755 | else act--;
756 |
757 | //~ int flag = val!=nval;
758 | //~ locRec += flag;
759 | //~ act = (flag)?TOUT:(act-1);
760 | }
761 | // portENABLE_INTERRUPTS();
762 | received_NRZI_buffer_bytesCnt = locRec;
763 | }
764 | #pragma GCC optimize ("-Os")
765 | #else
766 | // dangerous option, but faster and works with low cpu freq ~80MHz . If we have noise on bus it can overflow received_NRZI_buffer[]
767 | int flagR3 = 1;
768 | //#pragma GCC optimize ("-O2")
769 | //#define WR_SIMULTAA 1
770 | #pragma GCC optimize ("-O2")
771 | void sendRecieveNParse()
772 | {
773 | register uint32_t R3;
774 | register uint32_t R4;// = READ_BOTH_PINS;
775 | register uint16_t *STORE = received_NRZI_buffer;
776 | //portENTER_CRITICAL();
777 | #if 1
778 | sendOnly();
779 | #else
780 | uint8_t k;
781 | SET_O;
782 | #ifdef WR_SIMULTA
783 | uint32_t out_base = GPIO.out;
784 | sndA[0] = (out_base | DP) &~DM;
785 | sndA[1] = (out_base | DM) &~DP;
786 | sndA[2] = (out_base )&~(DP | DM);
787 | sndA[3] = out_base | (DM | DP);
788 | #endif
789 | for(k=0;kcb_Cmd==CB_CHECK)
960 | {
961 | SET_O;
962 | SE_0;
963 | SET_I;
964 | SE_J;
965 | cpuDelay(TRANSMIT_TIME_DELAY);
966 | cpuDelay(TRANSMIT_TIME_DELAY);
967 | cpuDelay(TRANSMIT_TIME_DELAY);
968 | cpuDelay(TRANSMIT_TIME_DELAY);
969 | cpuDelay(TRANSMIT_TIME_DELAY);
970 | cpuDelay(TRANSMIT_TIME_DELAY);
971 | cpuDelay(TRANSMIT_TIME_DELAY);
972 | cpuDelay(TRANSMIT_TIME_DELAY);
973 | cpuDelay(TRANSMIT_TIME_DELAY);
974 | cpuDelay(TRANSMIT_TIME_DELAY);
975 | current->wires_last_state = READ_BOTH_PINS>>8;
976 | if(current->wires_last_state==M_ONE)
977 | {
978 | // low speed
979 | }
980 | else if(current->wires_last_state==P_ONE)
981 | {
982 | //high speed
983 | }
984 | else if(current->wires_last_state==0x00)
985 | {
986 | // not connected
987 | }
988 | else if(current->wires_last_state== (M_ONE + P_ONE) )
989 | {
990 | //????
991 | }
992 | current->bComplete = 1;
993 | }
994 | else if (current->cb_Cmd==CB_RESET)
995 | {
996 | SOF();
997 | //sendRecieveNParse();
998 | cpuDelay(TRANSMIT_TIME_DELAY);
999 |
1000 | SET_O;
1001 | SE_0;
1002 | current->cmdTimeOut = 31;
1003 | current->cb_Cmd = CB_WAIT0;
1004 | }
1005 | else if (current->cb_Cmd==CB_WAIT0)
1006 | {
1007 | if(current->cmdTimeOut>0)
1008 | {
1009 | current->cmdTimeOut--;
1010 | }
1011 | else
1012 | {
1013 | //sendRecieveNParse();
1014 | current->bComplete = 1;
1015 | }
1016 | }
1017 | else if (current->cb_Cmd==CB_WAIT1)
1018 | {
1019 | SOF();
1020 | if(current->cmdTimeOut>0)
1021 | {
1022 | current->cmdTimeOut--;
1023 | }
1024 | else
1025 | {
1026 | SET_O;
1027 | SE_0;
1028 | SET_I;
1029 | SE_J;
1030 | SET_I;
1031 | cpuDelay(TRANSMIT_TIME_DELAY);
1032 | cpuDelay(TRANSMIT_TIME_DELAY);
1033 | cpuDelay(TRANSMIT_TIME_DELAY);
1034 | cpuDelay(TRANSMIT_TIME_DELAY);
1035 | cpuDelay(TRANSMIT_TIME_DELAY);
1036 | cpuDelay(TRANSMIT_TIME_DELAY);
1037 | cpuDelay(TRANSMIT_TIME_DELAY);
1038 | cpuDelay(TRANSMIT_TIME_DELAY);
1039 | cpuDelay(TRANSMIT_TIME_DELAY);
1040 | cpuDelay(TRANSMIT_TIME_DELAY);
1041 | current->wires_last_state = READ_BOTH_PINS>>8;
1042 | current->bComplete = 1;
1043 | }
1044 | }
1045 | else if (current->cb_Cmd==CB_POWER)
1046 | {
1047 |
1048 | // for TEST
1049 | #ifdef TEST
1050 | SOF();
1051 | sendRecieve();
1052 | SOF();
1053 | SOF();
1054 | #else
1055 | SET_O;
1056 | SE_J;
1057 | SET_I;
1058 | current->cmdTimeOut = 2;
1059 | current->cb_Cmd = CB_WAIT1;
1060 | #endif
1061 | }
1062 | else if (current->cb_Cmd==CB_TICK)
1063 | {
1064 | SOF();
1065 | current->bComplete = 1;
1066 | }
1067 | else if(current->cb_Cmd==CB_3)
1068 | {
1069 | SOF();
1070 | pu_Addr(current->rq.cmd,current->rq.addr,current->rq.eop);
1071 | pu_Cmd(current->rq.dataCmd, current->rq.bmRequestType, current->rq.bmRequest,current->rq.wValue, current->rq.wIndex, current->rq.wLen);
1072 | int res = sendRecieve();
1073 | if(res==T_ACK)
1074 | {
1075 | current->cb_Cmd=CB_4;
1076 | current->numb_reps_errors_allowed = 8;
1077 | return ;
1078 | }
1079 | else
1080 | {
1081 | current->numb_reps_errors_allowed--;
1082 | if(current->numb_reps_errors_allowed>0)
1083 | {
1084 | return ;
1085 | }
1086 | else
1087 | {
1088 | current->cb_Cmd=CB_TICK;
1089 | current->bComplete = 1;
1090 | }
1091 | }
1092 | }
1093 | else if(current->cb_Cmd==CB_4)
1094 | {
1095 | SOF();
1096 | pu_Addr(T_OUT,current->rq.addr,current->rq.eop);
1097 | //reB();
1098 | pu_MSB(T_START,8);
1099 | pu_MSB(T_DATA1,8);//setup
1100 | for(int k=0;ktransmitL1Bytes;k++)
1101 | {
1102 | pu_LSB(current->transmitL1[k],8);
1103 | }
1104 | pu_MSB(cal16(),16);
1105 | repack();
1106 | sendRecieveNParse();
1107 | pu_Addr(T_IN,current->rq.addr,current->rq.eop);
1108 | //setup
1109 | sendRecieveNParse();
1110 | if(received_NRZI_buffer_bytesCntSMALL_NO_DATA/4)
1111 | {
1112 | ACK();
1113 | }
1114 | else
1115 | {
1116 | current->numb_reps_errors_allowed--;
1117 | if(current->numb_reps_errors_allowed>0)
1118 | {
1119 | return ;
1120 | }
1121 | else
1122 | {
1123 |
1124 | }
1125 |
1126 | }
1127 | current->cb_Cmd=CB_TICK;
1128 | current->bComplete = 1;
1129 | }
1130 | else if(current->cb_Cmd==CB_5)
1131 | {
1132 | SOF();
1133 | pu_Addr(current->rq.cmd,current->rq.addr,current->rq.eop);
1134 | pu_Cmd(current->rq.dataCmd, current->rq.bmRequestType, current->rq.bmRequest,current->rq.wValue, current->rq.wIndex, current->rq.wLen);
1135 | sendRecieveNParse();
1136 | //int res = sendRecieve(current->asckedReceiveBytes>8?8:current->asckedReceiveBytes);
1137 | int res = parse_received_NRZI_buffer();
1138 | if(res==T_ACK)
1139 | {
1140 | current->cb_Cmd = CB_6;
1141 | current->in_data_flip_flop = 1;
1142 | current->numb_reps_errors_allowed = 4;
1143 | current->counterAck ++;
1144 | return ;
1145 | }
1146 | else
1147 | {
1148 | //SOF();
1149 | current->counterNAck ++;
1150 | current->numb_reps_errors_allowed--;
1151 | if(current->numb_reps_errors_allowed>0)
1152 | {
1153 | // current->cb_Cmd = CB_TICK;
1154 | current->acc_decoded_resp_counter = 0;
1155 | return ;
1156 | }
1157 | else
1158 | {
1159 | current->cb_Cmd = CB_TICK;
1160 | current->bComplete = 1;
1161 | }
1162 | }
1163 | }
1164 | else if(current->cb_Cmd==CB_6)
1165 | {
1166 | SOF();
1167 | pu_Addr(T_IN,current->rq.addr,current->rq.eop);
1168 | //setup
1169 | sendRecieveNParse();
1170 | // if receive something ??
1171 | if(current->asckedReceiveBytes==0 && current->acc_decoded_resp_counter==0 && received_NRZI_buffer_bytesCntSMALL_NO_DATA/4 )
1172 | {
1173 | ACK();
1174 | //printf("received_NRZI_buffer_bytesCnt=%d!!!\n",received_NRZI_buffer_bytesCnt);
1175 | current->cb_Cmd = CB_TICK;
1176 | current->bAcked = 1;
1177 | current->bComplete = 1;
1178 | return ;
1179 | }
1180 | int res = parse_received_NRZI_buffer();
1181 | if(res == T_NEED_ACK)
1182 | {
1183 | //SOF();
1184 | if(decoded_receive_buffer_size()>2)
1185 | {
1186 |
1187 | decoded_receive_buffer_get();
1188 | uint8_t sval = decoded_receive_buffer_get();
1189 | if((current->in_data_flip_flop&1)==1)
1190 | {
1191 | if(sval==T_DATA1)
1192 | {
1193 |
1194 | }
1195 | else
1196 | {
1197 | current->cb_Cmd = CB_7;
1198 | return ;
1199 | }
1200 | }
1201 | else
1202 | {
1203 | if(sval==T_DATA0)
1204 | {
1205 |
1206 | }
1207 | else
1208 | {
1209 | current->cb_Cmd = CB_7;
1210 | return ;
1211 | }
1212 | }
1213 | current->in_data_flip_flop++;
1214 | int bytes =decoded_receive_buffer_size()-2;
1215 | for(int kk=0;kkacc_decoded_resp[current->acc_decoded_resp_counter] = rev8(decoded_receive_buffer_get());
1218 | current->acc_decoded_resp_counter++;
1219 | current->asckedReceiveBytes--;
1220 | }
1221 | //while(decoded_receive_buffer_size()) {decoded_receive_buffer_get();}
1222 | if(bytes<=0)
1223 | {
1224 | //printf("zero!!\n");
1225 | current->acc_decoded_resp_counter = 0;
1226 | current->asckedReceiveBytes = 0;
1227 | current->cb_Cmd = CB_TICK;
1228 | current->bComplete = 1;
1229 | }
1230 | else
1231 | {
1232 | current->cb_Cmd = CB_7;
1233 | return ;
1234 | }
1235 | }
1236 | else
1237 | {
1238 | current->acc_decoded_resp_counter = 0;
1239 | current->asckedReceiveBytes = 0;
1240 | current->cb_Cmd = CB_TICK;
1241 | current->bComplete = 1;
1242 | return ;
1243 | }
1244 | }
1245 | else
1246 | {
1247 | current->numb_reps_errors_allowed--;
1248 | if(current->numb_reps_errors_allowed>0)
1249 | {
1250 | return ;
1251 | }
1252 | else
1253 | {
1254 | current->cb_Cmd = CB_TICK;
1255 | current->bComplete = 1;
1256 | }
1257 | }
1258 |
1259 | }
1260 | else if(current->cb_Cmd==CB_7)
1261 | {
1262 | SOF();
1263 | pu_Addr(T_IN,current->rq.addr,current->rq.eop);
1264 | //setup
1265 | sendRecieveNParse();
1266 | ACK();
1267 | if(current->asckedReceiveBytes>0)
1268 | {
1269 | current->cb_Cmd = CB_6;
1270 | return ;
1271 | }
1272 | current->cb_Cmd = CB_8;
1273 | }
1274 | else if(current->cb_Cmd==CB_8)
1275 | {
1276 | SOF();
1277 | pu_Addr(T_OUT,current->rq.addr,current->rq.eop);
1278 | pu_ShortCmd(T_DATA1);
1279 | sendOnly();
1280 | current->cb_Cmd = CB_TICK;
1281 | current->bComplete = 1;
1282 | }
1283 | else if(current->cb_Cmd==CB_2Ack)
1284 | {
1285 | SOF();
1286 | pu_Addr(T_IN,current->rq.addr,current->rq.eop);
1287 | //setup
1288 | sendRecieveNParse();
1289 | if(received_NRZI_buffer_bytesCntcb_Cmd = CB_TICK;
1293 | current->bComplete = 1;
1294 | //printf("received_NRZI_buffer_bytesCnt = %d\n",prec);
1295 | return ;
1296 | }
1297 | //ACK();
1298 | ACK();
1299 | current->cb_Cmd = CB_TICK;
1300 | current->bComplete = 1;
1301 | }
1302 | else if(current->cb_Cmd==CB_2)
1303 | {
1304 | SOF();
1305 | pu_Addr(T_IN,current->rq.addr,current->rq.eop);
1306 | //setup
1307 | sendRecieveNParse();
1308 | if(received_NRZI_buffer_bytesCntcb_Cmd = CB_TICK;
1312 | current->bComplete = 1;
1313 | //printf("received_NRZI_buffer_bytesCnt = %d\n",prec);
1314 | return ;
1315 | }
1316 | //ACK();
1317 | //ACK();
1318 | int res = parse_received_NRZI_buffer();
1319 | if(res==T_NEED_ACK)
1320 | {
1321 | if(decoded_receive_buffer_size()>2)
1322 | {
1323 | decoded_receive_buffer_get();
1324 | decoded_receive_buffer_get();
1325 | int bytes =decoded_receive_buffer_size()-2;
1326 | for(int kk=0;kkacc_decoded_resp[current->acc_decoded_resp_counter] = rev8(decoded_receive_buffer_get());
1329 | current->acc_decoded_resp_counter++;
1330 | current->asckedReceiveBytes--;
1331 | }
1332 | }
1333 | current->asckedReceiveBytes = 0;
1334 | current->cb_Cmd=CB_2Ack;
1335 | return ;
1336 | }
1337 | else
1338 | {
1339 | current->numb_reps_errors_allowed--;
1340 | if(current->numb_reps_errors_allowed>0)
1341 | {
1342 | return ;
1343 | }
1344 | else
1345 | {
1346 | current->cb_Cmd = CB_TICK;
1347 | current->bComplete = 1;
1348 | }
1349 | }
1350 | current->cb_Cmd = CB_TICK;
1351 | current->bComplete = 1;
1352 | current->asckedReceiveBytes = 0;
1353 | }
1354 |
1355 |
1356 | }
1357 |
1358 |
1359 | void Request(uint8_t cmd, uint8_t addr,uint8_t eop,
1360 | uint8_t dataCmd,uint8_t bmRequestType, uint8_t bmRequest,uint16_t wValue,uint16_t wIndex,uint16_t wLen,uint16_t waitForBytes)
1361 | {
1362 | current->rq.cmd = cmd;
1363 | current->rq.addr = addr;
1364 | current->rq.eop = eop;
1365 | current->rq.dataCmd = dataCmd;
1366 | current->rq.bmRequestType = bmRequestType;
1367 | current->rq.bmRequest = bmRequest;
1368 | current->rq.wValue = wValue;
1369 | current->rq.wIndex = wIndex;
1370 | current->rq.wLen = wLen;
1371 |
1372 | current->numb_reps_errors_allowed = 4;
1373 | current->asckedReceiveBytes = waitForBytes;
1374 | current->acc_decoded_resp_counter = 0;
1375 | current->bAcked = 0;
1376 | // if(cmd==T_SETUP)
1377 | // {
1378 | current->cb_Cmd = CB_5;
1379 | // }
1380 | // HAL_Delay(1);
1381 | }
1382 |
1383 | void RequestSend(uint8_t cmd, uint8_t addr,uint8_t eop,
1384 | uint8_t dataCmd,uint8_t bmRequestType, uint8_t bmRequest,uint16_t wValue,uint16_t wIndex,uint16_t wLen,uint16_t transmitL1Bytes,uint8_t* data)
1385 | {
1386 | current->rq.cmd = cmd;
1387 | current->rq.addr = addr;
1388 | current->rq.eop = eop;
1389 | current->rq.dataCmd = dataCmd;
1390 | current->rq.bmRequestType = bmRequestType;
1391 | current->rq.bmRequest = bmRequest;
1392 | current->rq.wValue = wValue;
1393 | current->rq.wIndex = wIndex;
1394 | current->rq.wLen = wLen;
1395 | current->transmitL1Bytes = transmitL1Bytes;
1396 | for(int k=0;ktransmitL1Bytes;k++)
1397 | {
1398 | current->transmitL1[k] = data[k];
1399 | }
1400 | current->numb_reps_errors_allowed = 4;
1401 | current->acc_decoded_resp_counter = 0;
1402 | // if(cmd==T_SETUP)
1403 | // {
1404 | current->cb_Cmd = CB_3;
1405 | // }
1406 | }
1407 |
1408 | void RequestIn(uint8_t cmd, uint8_t addr,uint8_t eop,uint16_t waitForBytes)
1409 | {
1410 | current->rq.cmd = cmd;
1411 | current->rq.addr = addr;
1412 | current->rq.eop = eop;
1413 | current->numb_reps_errors_allowed = 4;
1414 | current->asckedReceiveBytes = waitForBytes;
1415 | current->acc_decoded_resp_counter = 0;
1416 | current->cb_Cmd = CB_2;
1417 | }
1418 |
1419 |
1420 |
1421 | void fsm_Mashine()
1422 | {
1423 | if(!current->bComplete) return;
1424 | current->bComplete = 0;
1425 |
1426 |
1427 |
1428 | if(current->fsm_state == 0)
1429 | {
1430 | current->epCount = 0;
1431 | current->cb_Cmd = CB_CHECK;
1432 | current->fsm_state = 1;
1433 | }
1434 | if(current->fsm_state == 1)
1435 | {
1436 | if(current->wires_last_state==M_ONE)
1437 | // if(1)
1438 | {
1439 | current->cmdTimeOut = 100+current->selfNum*73;
1440 | //current->cmdTimeOut = 100;
1441 | current->cb_Cmd = CB_WAIT0;
1442 | current->fsm_state = 2;
1443 | }
1444 | else
1445 | {
1446 | current->fsm_state = 0;
1447 | current->cb_Cmd = CB_CHECK;
1448 | }
1449 | }
1450 | else if(current->fsm_state==2)
1451 | {
1452 | current->cb_Cmd = CB_RESET;
1453 | current->fsm_state = 3;
1454 | }
1455 | else if(current->fsm_state==3)
1456 | {
1457 | current->cb_Cmd = CB_POWER;
1458 | #ifdef TEST
1459 | current->fsm_state = 3;
1460 | #else
1461 | current->fsm_state = 4;
1462 | #endif
1463 | }
1464 | else if(current->fsm_state==4)
1465 | {
1466 | Request(T_SETUP,ZERO_USB_ADDRESS,0b0000,T_DATA0,0x80,0x6,0x0100,0x0000,0x0012,0x0012);
1467 | current->fsm_state = 5;
1468 | }
1469 | else if(current->fsm_state==5)
1470 | {
1471 | if(current->acc_decoded_resp_counter==0x12)
1472 | {
1473 | memcpy(¤t->desc,current->acc_decoded_resp,0x12);
1474 | current->ufPrintDesc |= 1;
1475 | Request(T_SETUP,ZERO_USB_ADDRESS,0b0000,T_DATA0,0x00,0x5,0x0000+ASSIGNED_USB_ADDRESS,0x0000,0x0000,0x0000);
1476 | current->fsm_state = 6;
1477 | }
1478 | else
1479 | {
1480 | if(current->numb_reps_errors_allowed<=0)
1481 | {
1482 | current->fsm_state = 0;
1483 | return;
1484 | }
1485 | current->fsm_state = 4;
1486 | }
1487 | #if 1
1488 | #else
1489 | current->fsm_state = 0;
1490 | #endif
1491 | }
1492 | else if(current->fsm_state==6)
1493 | {
1494 | current->cmdTimeOut = 5;
1495 | current->cb_Cmd = CB_WAIT1;
1496 | current->fsm_state = 7;
1497 | }
1498 |
1499 | else if(current->fsm_state==7)
1500 | {
1501 | Request(T_SETUP,ASSIGNED_USB_ADDRESS,0b0000,T_DATA0,0x80,0x6,0x0200,0x0000,0x0009,0x0009);
1502 | current->fsm_state = 8;
1503 | }
1504 | else if(current->fsm_state==8)
1505 | {
1506 | if(current->acc_decoded_resp_counter==0x9)
1507 | {
1508 | memcpy(¤t->cfg,current->acc_decoded_resp,0x9);
1509 | current->ufPrintDesc |= 2;
1510 | Request(T_SETUP,ASSIGNED_USB_ADDRESS,0b0000,T_DATA0,0x80,0x6,0x0200,0x0000,current->cfg.wLength,current->cfg.wLength);
1511 | current->fsm_state = 9;
1512 | }
1513 | else
1514 | {
1515 | current->fsm_state = 0;
1516 | return ;
1517 | }
1518 | }
1519 | else if(current->fsm_state==9)
1520 | {
1521 | if(current->acc_decoded_resp_counter==current->cfg.wLength)
1522 | {
1523 | current->ufPrintDesc |= 4;
1524 | current->descrBufferLen = current->acc_decoded_resp_counter;
1525 | memcpy(current->descrBuffer,current->acc_decoded_resp,current->descrBufferLen);
1526 | parseImmed(current);
1527 | current->cmdTimeOut = 25;
1528 | current->cb_Cmd = CB_WAIT1;
1529 | current->fsm_state = 94;
1530 | }
1531 | else
1532 | {
1533 | current->cmdTimeOut = 5;
1534 | current->cb_Cmd = CB_WAIT1;
1535 | current->fsm_state = 7;
1536 | }
1537 | }
1538 | else if(current->fsm_state==94)
1539 | {
1540 | // config interfaces??
1541 | //printf("set configuration 1\n");
1542 | Request(T_SETUP,ASSIGNED_USB_ADDRESS,0b0000,T_DATA0,0x00,0x9,0x0001,0x0000,0x0000,0x0000);
1543 | current->fsm_state = 96;
1544 | }
1545 | else if(current->fsm_state==96)
1546 | {
1547 | // config interfaces??
1548 | if(current->bAcked)
1549 | {
1550 | Request(T_SETUP,ASSIGNED_USB_ADDRESS,0b0000,T_DATA0,0x21,0xa,0x0000,0x0000,0x0000,0x0000);
1551 | current->fsm_state = 99;
1552 | }
1553 | else
1554 | {
1555 | current->cmdTimeOut = 3;
1556 | current->cb_Cmd = CB_WAIT1;
1557 | current->fsm_state = 0;
1558 | }
1559 | }
1560 | else if(current->fsm_state==99)
1561 | {
1562 | //uint8_t cmd0 = current->cnt&0x20?0x7:0x0;
1563 | //current->cnt++;
1564 | //uint8_t cmd1 = current->cnt&0x20?0x7:0x0;
1565 | //printf(" 3 LEDs enable/disable on keyboard \n");
1566 | if(current->bAcked)
1567 | {
1568 | uint8_t cmd1 = 0;
1569 | RequestSend(T_SETUP,ASSIGNED_USB_ADDRESS,0b0000,T_DATA0,0x21,0x9,0x0200,0x0000,0x0001,0x0001,&cmd1);
1570 | current->fsm_state = 100;
1571 | }
1572 | else
1573 | {
1574 | current->cmdTimeOut = 3;
1575 | current->cb_Cmd = CB_WAIT1;
1576 | current->fsm_state = 0;
1577 | }
1578 | }
1579 | else if(current->fsm_state==100)
1580 | {
1581 | led(0);
1582 | RequestIn(T_IN, ASSIGNED_USB_ADDRESS,1,8);
1583 | current->fsm_state = 101;
1584 | }
1585 | else if(current->fsm_state==101)
1586 | {
1587 | if(current->acc_decoded_resp_counter>=1)
1588 | {
1589 | usbMess(current->selfNum*4+0,current->acc_decoded_resp_counter,current->acc_decoded_resp);
1590 | // current->ufPrintDesc |= 8;
1591 | //~ current->R0Bytes= current->acc_decoded_resp_counter;
1592 | //~ memcpy(current->Resp0,current->acc_decoded_resp,current->R0Bytes);
1593 |
1594 | led(1);
1595 | //gpio_set_level(B23_GPIO, 1);
1596 | }
1597 | //~ RequestIn(T_IN, ASSIGNED_USB_ADDRESS,2,8);
1598 | //~ current->fsm_state = 102;
1599 | if(current->epCount>=2)
1600 | {
1601 | RequestIn(T_IN, ASSIGNED_USB_ADDRESS,2,8);
1602 | current->fsm_state = 102;
1603 | }
1604 | else
1605 | {
1606 | current->cmdTimeOut = 3;
1607 | current->cb_Cmd = CB_WAIT1;
1608 | current->fsm_state = 104;
1609 | }
1610 | }
1611 | else if(current->fsm_state==102)
1612 | {
1613 | if(current->acc_decoded_resp_counter>=1)
1614 | {
1615 | usbMess(current->selfNum*4+1,current->acc_decoded_resp_counter,current->acc_decoded_resp);
1616 | //current->ufPrintDesc |= 16;
1617 | //current->R1Bytes= current->acc_decoded_resp_counter;
1618 | //memcpy(current->Resp1,current->acc_decoded_resp,current->R0Bytes);
1619 | led(1);
1620 | }
1621 | if(current->epCount>=3)
1622 | {
1623 | RequestIn(T_IN, ASSIGNED_USB_ADDRESS,3,8);
1624 | current->fsm_state = 103;
1625 | }
1626 | else
1627 | {
1628 | current->cmdTimeOut = 3;
1629 | current->cb_Cmd = CB_WAIT1;
1630 | current->fsm_state = 104;
1631 | }
1632 | }
1633 | else if(current->fsm_state==103)
1634 | {
1635 | if(current->acc_decoded_resp_counter>=1)
1636 | {
1637 | usbMess(current->selfNum*4+2,current->acc_decoded_resp_counter,current->acc_decoded_resp);
1638 | //current->ufPrintDesc |= 16;
1639 | //current->R1Bytes= current->acc_decoded_resp_counter;
1640 | //memcpy(current->Resp1,current->acc_decoded_resp,current->R0Bytes);
1641 | led(1);
1642 | }
1643 | current->cmdTimeOut = 2;
1644 | current->cb_Cmd = CB_WAIT1;
1645 | current->fsm_state = 104;
1646 | }
1647 | else if (current->fsm_state==104)
1648 | {
1649 | current->cmdTimeOut = 4;
1650 | current->cb_Cmd = CB_WAIT1;
1651 | #ifdef DEBUG_REPEAT
1652 | static int rcnt =0;
1653 | rcnt++; //
1654 | if( (rcnt&0xff)==0 || (current->wires_last_state!=M_ONE))
1655 | #else
1656 | if(current->wires_last_state!=M_ONE)
1657 | #endif
1658 | {
1659 | current->fsm_state = 0;
1660 | return ;
1661 | }
1662 | current->fsm_state = 100;
1663 | }
1664 | else
1665 | {
1666 | current->cmdTimeOut = 2;
1667 | current->cb_Cmd = CB_WAIT1;
1668 | current->fsm_state = 0;
1669 | }
1670 | }
1671 |
1672 |
1673 | void setPins(int DPPin,int DMPin)
1674 | {
1675 | DP_PIN = DPPin;
1676 | DM_PIN = DMPin;
1677 | int diff = DPPin - DMPin;
1678 | if(abs(diff)>7)
1679 | {
1680 | printf("PIN DIFFERENCE MUST BE LESS 8!\n");
1681 | exit(1);
1682 | }
1683 | int MIN_PIN = (DPPin=0)
1690 | {
1691 | RD_SHIFT = DIFF;
1692 | M_ONE = 1<<(DM_PIN-MIN_PIN);//<7||diff==0)
1708 | {
1709 | return 0;
1710 | }
1711 | if( dp<8 || dp>31) return 0;
1712 | if( dm<8 || dm>31) return 0;
1713 | //p
1714 | return 1;
1715 | }
1716 | #include
1717 | int64_t get_system_time_us();
1718 |
1719 | float testDelay6(float freq_MHz)
1720 | {
1721 | // 6 bits must take 4.0 uSec
1722 | #define SEND_BITS 120
1723 | #define REPS 40
1724 | float res = 1;
1725 | transmit_NRZI_buffer_cnt = 0;
1726 | {
1727 | for(int k=0;kDP = DP0;
1804 | current->DM = DM0;
1805 | }
1806 | else if(k==1)
1807 | {
1808 | current->DP = DP1;
1809 | current->DM = DM1;
1810 | }
1811 | else if(k==2)
1812 | {
1813 | current->DP = DP2;
1814 | current->DM = DM2;
1815 | }
1816 | else if(k==3)
1817 | {
1818 | current->DP = DP3;
1819 | current->DM = DM3;
1820 | }
1821 | current->isValid = 0;
1822 | if(checkPins(current->DP,current->DM))
1823 | {
1824 | printf("pins %d %d is OK!\n",current->DP,current->DM);
1825 | current->selfNum = k;
1826 | current->in_data_flip_flop = 0;
1827 | current->bComplete = 1;
1828 | current->cmdTimeOut = 0;
1829 | current->ufPrintDesc =0;
1830 | current->cb_Cmd = CB_CHECK;
1831 | current->fsm_state = 0;
1832 | current->wires_last_state = 0;
1833 | current->counterNAck = 0;
1834 | current->counterAck = 0;
1835 | current->epCount = 0;
1836 |
1837 | gpio_config_t io_conf;
1838 | io_conf.intr_type = GPIO_INTR_DISABLE;
1839 | io_conf.pin_bit_mask = (1<DP) | (1<DM);
1840 | io_conf.pull_down_en = 0;
1841 | io_conf.pull_up_en = 0;
1842 | io_conf.mode = GPIO_MODE_INPUT;
1843 | gpio_config(&io_conf);
1844 |
1845 | //~ gpio_pad_select_gpio(current->DP);
1846 | //~ gpio_set_direction(current->DP, GPIO_MODE_INPUT);
1847 | //~ gpio_pulldown_en(current->DP);
1848 |
1849 | //~ gpio_pad_select_gpio(current->DM);
1850 | //~ gpio_set_direction(current->DM, GPIO_MODE_INPUT);
1851 | //~ gpio_pulldown_en(current->DM);
1852 | current->isValid = 1;
1853 |
1854 | // TEST
1855 | setPins(current->DP,current->DM);
1856 |
1857 | if(!calibrated)
1858 | {
1859 | //calibrate delay divide 2
1860 | #define DELAY_CORR 2
1861 | int uTime = 255-DELAY_CORR;
1862 | int dTime = 0;
1863 |
1864 | uint32_t freq_mhz = esp_clk_cpu_freq()/1000000;
1865 | //~ rtc_cpu_freq_config_t out_config;
1866 |
1867 | //~ rtc_clk_cpu_freq_get_config(&out_config);
1868 |
1869 | //uint32_t freq = rtc_clk_cpu_freq_value(rtc_clk_cpu_freq_get());
1870 | printf("cpu freq = %d MHz\n",freq_mhz);
1871 |
1872 | TM_OUT = freq_mhz/2;
1873 |
1874 | // 8 - func divided clock to 8, 1.5 - MHz USB LS
1875 | TIME_MULT = (int)(TIME_SCALE/(freq_mhz/4/1.5)+0.5);
1876 | printf("TIME_MULT = %d \n",TIME_MULT);
1877 |
1878 | int TRANSMIT_TIME_DELAY_OPT = 0;
1879 | TRANSMIT_TIME_DELAY = TRANSMIT_TIME_DELAY_OPT;
1880 | printf("D=%4d ",TRANSMIT_TIME_DELAY);
1881 | setDelay(TRANSMIT_TIME_DELAY);
1882 | float cS_opt = testDelay6(freq_mhz);
1883 | #define OPT_TIME (4.00f)
1884 | for(int p=0;p<9;p++)
1885 | {
1886 | TRANSMIT_TIME_DELAY = (uTime+dTime)/2;
1887 | printf("D=%4d ",TRANSMIT_TIME_DELAY);
1888 | setDelay(TRANSMIT_TIME_DELAY);
1889 | float cS = testDelay6(freq_mhz);
1890 | if(fabsf(OPT_TIME-cS)DP,current->DM);
1971 | }
1972 |
1973 | }
1974 | }
1975 |
1976 | void usb_process()
1977 | {
1978 | for(int k=0;kisValid)
1982 | {
1983 | setPins(current->DP,current->DM);
1984 | timerCallBack();
1985 | fsm_Mashine();
1986 | }
1987 | }
1988 | }
1989 | void printState()
1990 | {
1991 |
1992 | static int cntl = 0;
1993 | cntl++;
1994 | int ref = cntl%NUM_USB;
1995 | sUsbContStruct * pcurrent = ¤t_usb[ref];
1996 | if(!pcurrent->isValid) return ;
1997 | if((cntl%200)cb_Cmd = %d state = %d epCount = %d",cntl%NUM_USB,flagR3,pcurrent->counterAck,pcurrent->counterNAck,pcurrent->wires_last_state,pcurrent->cb_Cmd,pcurrent->fsm_state,pcurrent->epCount);
2000 | #ifdef DEBUG_ALL
2001 | for(int k=0;k<20;k++)
2002 | {
2003 | printf("%04x ", debug_buff[k]);
2004 | }
2005 | #endif
2006 | printf("\n");
2007 | }
2008 | //~ for(int k=0;k<0x14;k++)
2009 | //~ {
2010 | //~ if(cntl &1 )
2011 | //~ {
2012 | //~ printf("%04x ",prn(tr[k],0));
2013 | //~ }
2014 | //~ else
2015 | //~ {
2016 | //~ printf("%04x ",pr[k]);
2017 | //~ }
2018 | //~ }
2019 | //~ printf("\n");
2020 | if(pcurrent->ufPrintDesc&1)
2021 | {
2022 | pcurrent->ufPrintDesc &= ~(uint32_t)1;
2023 | //~ printf("desc.bcdUSB = %02x\n",pcurrent->desc.bcdUSB);
2024 | //~ printf("desc.bDeviceClass = %02x\n",pcurrent->desc.bDeviceClass);
2025 | //~ printf("desc.bDeviceSubClass = %02x\n",pcurrent->desc.bDeviceSubClass);
2026 | //~ printf("desc.bDeviceProtocol = %02x\n",pcurrent->desc.bDeviceProtocol);
2027 | //~ printf("desc.bMaxPacketSize0 = %02x\n",pcurrent->desc.bMaxPacketSize0);
2028 | //~ printf("desc.idVendor = %02x\n",pcurrent->desc.idVendor);
2029 | //~ printf("desc.idProduct = %02x\n",pcurrent->desc.idProduct);
2030 | printf("desc.bcdDevice = %02x\n",pcurrent->desc.bcdDevice);
2031 | printf("desc.iManufacturer = %02x\n",pcurrent->desc.iManufacturer);
2032 | printf("desc.iProduct = %02x\n",pcurrent->desc.iProduct);
2033 | //printf("desc.iSerialNumber = %02x\n",pcurrent->desc.iSerialNumber);
2034 | printf("desc.bNumConfigurations = %02x\n",pcurrent->desc.bNumConfigurations);
2035 | }
2036 | if(pcurrent->ufPrintDesc&2)
2037 | {
2038 | pcurrent->ufPrintDesc &= ~(uint32_t)2;
2039 | printf("cfg.bLength = %02x\n",pcurrent->cfg.bLength);
2040 | //printf("cfg.bType = %02x\n",pcurrent->cfg.bType);
2041 | printf("cfg.wLength = %02x\n",pcurrent->cfg.wLength);
2042 | printf("cfg.bNumIntf = %02x\n",pcurrent->cfg.bNumIntf);
2043 | //~ printf("cfg.bCV = %02x\n",pcurrent->cfg.bCV);
2044 | //~ printf("cfg.bIndex = %02x\n",pcurrent->cfg.bIndex);
2045 | //~ printf("cfg.bAttr = %02x\n",pcurrent->cfg.bAttr);
2046 | //~ printf("cfg.bMaxPower = %d\n",pcurrent->cfg.bMaxPower);
2047 | }
2048 | //~ if(pcurrent->ufPrintDesc&8)
2049 | //~ {
2050 | //~ pcurrent->ufPrintDesc &= ~(uint32_t)8;
2051 | //~ printf("in0 :");
2052 | //~ for(int k=0;kR0Bytes;k++)
2053 | //~ {
2054 | //~ printf("%02x ",pcurrent->Resp0[k]);
2055 | //~ }
2056 | //~ printf("\n");
2057 | //~ }
2058 | //~ if(pcurrent->ufPrintDesc&16)
2059 | //~ {
2060 | //~ pcurrent->ufPrintDesc &= ~(uint32_t)16;
2061 | //~ printf("in1 :");
2062 | //~ for(int k=0;kR1Bytes;k++)
2063 | //~ {
2064 | //~ printf("%02x ",pcurrent->Resp1[k]);
2065 | //~ }
2066 | //~ printf("\n");
2067 | //~ }
2068 |
2069 | if(pcurrent->ufPrintDesc&4)
2070 | {
2071 | pcurrent->ufPrintDesc &= ~(uint32_t)4;
2072 | sCfgDesc lcfg;
2073 | sIntfDesc sIntf;
2074 | HIDDescriptor hid[4];
2075 | sEPDesc epd;
2076 | int cfgCount = 0;
2077 | int sIntfCount = 0;
2078 | int hidCount = 0;
2079 |
2080 | int pos = 0;
2081 | #define STDCLASS 0x00
2082 | #define HIDCLASS 0x03
2083 | #define HUBCLASS 0x09 /* bDeviceClass, bInterfaceClass */
2084 | printf("clear epCount %d self = %d %d\n",pcurrent->epCount,pcurrent->selfNum,pcurrent->descrBufferLen);
2085 | //pcurrent->epCount = 0;
2086 | while(posdescrBufferLen-2)
2087 | {
2088 | uint8_t len = pcurrent->descrBuffer[pos];
2089 | uint8_t type = pcurrent->descrBuffer[pos+1];
2090 | if(len==0)
2091 | {
2092 | //printf("pos = %02x type = %02x cfg.wLength = %02x pcurrent->acc_decoded_resp_counter = %02x\n ",pos,type,cfg.wLength,pcurrent->acc_decoded_resp_counter);
2093 | pos = pcurrent->descrBufferLen;
2094 | }
2095 | if(pos+len<=pcurrent->descrBufferLen)
2096 | {
2097 | printf("\n");
2098 | if(type == 0x2)
2099 | {
2100 | sCfgDesc cfg;
2101 | memcpy(&cfg,&pcurrent->descrBuffer[pos],len);
2102 | //printf("cfg.bLength = %02x\n",cfg.bLength);
2103 | //printf("cfg.bType = %02x\n",cfg.bType);
2104 |
2105 | printf("cfg.wLength = %02x\n",cfg.wLength);
2106 | printf("cfg.bNumIntf = %02x\n",cfg.bNumIntf);
2107 | printf("cfg.bCV = %02x\n",cfg.bCV);
2108 | //printf("cfg.bIndex = %02x\n",cfg.bIndex);
2109 | //printf("cfg.bAttr = %02x\n",cfg.bAttr);
2110 | printf("cfg.bMaxPower = %d\n",cfg.bMaxPower);
2111 |
2112 | }
2113 | else if (type == 0x4)
2114 | {
2115 | sIntfDesc sIntf;
2116 | memcpy(&sIntf,&pcurrent->descrBuffer[pos],len);
2117 | //printf("sIntf.bLength = %02x\n",sIntf.bLength);
2118 | //printf("sIntf.bType = %02x\n",sIntf.bType);
2119 | //~ printf("sIntf.iNum = %02x\n",sIntf.iNum);
2120 | //~ printf("sIntf.iAltString = %02x\n",sIntf.iAltString);
2121 | //~ printf("sIntf.bEndPoints = %02x\n",sIntf.bEndPoints);
2122 | //~ printf("sIntf.iClass = %02x\n",sIntf.iClass);
2123 | //~ printf("sIntf.iSub = %02x\n",sIntf.iSub);
2124 | //~ printf("sIntf.iProto = %d\n",sIntf.iProto);
2125 | //~ printf("sIntf.iIndex = %d\n",sIntf.iIndex);
2126 |
2127 | }
2128 | else if (type == 0x21)
2129 | {
2130 |
2131 | hidCount++;
2132 | int i = hidCount-1;
2133 | memcpy(&hid[i],&pcurrent->descrBuffer[pos],len);
2134 | //printf("hid.bLength = %02x\n",hid[i].bLength);
2135 | //printf("hid.bDescriptorType = %02x\n",hid[i].bDescriptorType);
2136 | printf("hid.bcdHID = %02x\n",hid[i].bcdHID);
2137 | //~ printf("hid.bCountryCode = %02x\n",hid[i].bCountryCode);
2138 | //~ printf("hid.bNumDescriptors = %02x\n",hid[i].bNumDescriptors);
2139 | //~ printf("hid.bReportDescriptorType = %02x\n",hid[i].bReportDescriptorType);
2140 | //~ printf("hid.wItemLengthH = %02x\n",hid[i].wItemLengthH);
2141 | //~ printf("hid.wItemLengthL = %02x\n",hid[i].wItemLengthL);
2142 | }
2143 | else if (type == 0x5)
2144 | {
2145 | //pcurrent->epCount++;
2146 | printf("pcurrent->epCount = %d\n",pcurrent->epCount);
2147 | sEPDesc epd;
2148 | memcpy(&epd,&pcurrent->descrBuffer[pos],len);
2149 | //printf("epd.bLength = %02x\n",epd.bLength);
2150 | //printf("epd.bType = %02x\n",epd.bType);
2151 | printf("epd.bEPAdd = %02x\n",epd.bEPAdd);
2152 | printf("epd.bAttr = %02x\n",epd.bAttr);
2153 | printf("epd.wPayLoad = %02x\n",epd.wPayLoad);
2154 | printf("epd.bInterval = %02x\n",epd.bInterval);
2155 | }
2156 | }
2157 | pos+=len;
2158 | }
2159 | }
2160 |
2161 | }
2162 |
--------------------------------------------------------------------------------
/test_usb/main/usb_host.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef USB_HOST_H
3 | #define USB_HOST_H
4 |
5 |
6 |
7 | #define TIMER_DIVIDER 2 // Hardware timer clock divider
8 | #define TIMER_SCALE (TIMER_BASE_CLK / TIMER_DIVIDER) // convert counter value to seconds
9 | #define TIMER_INTERVAL0_SEC (0.001) // sample test interval for the first timer
10 |
11 |
12 | // non configured device - must be zero
13 | #define ZERO_USB_ADDRESS 0
14 |
15 | // any number less 127, but no zero
16 | #define ASSIGNED_USB_ADDRESS 3
17 |
18 |
19 |
20 | void printState();
21 | void usb_process();
22 | void usbMess(uint8_t src,uint8_t len,uint8_t *data);
23 | void led(int on_off);
24 |
25 | #define NUM_USB 4
26 | void initStates( int DP0,int DM0,int DP1,int DM1,int DP2,int DM2,int DP3,int DM3);
27 |
28 | typedef __packed struct
29 | {
30 | uint8_t bLength;
31 | uint8_t bDescriptorType;
32 | uint16_t bcdUSB;
33 | uint8_t bDeviceClass;
34 | uint8_t bDeviceSubClass;
35 | uint8_t bDeviceProtocol;
36 | uint8_t bMaxPacketSize0;
37 | uint16_t idVendor;
38 | uint16_t idProduct;
39 | uint16_t bcdDevice;
40 | uint8_t iManufacturer;
41 | uint8_t iProduct;
42 | uint8_t iSerialNumber;
43 | uint8_t bNumConfigurations;
44 | } sDevDesc;
45 |
46 | typedef __packed struct
47 | {
48 | uint8_t bLength;
49 | uint8_t bType;
50 | uint16_t wLength;
51 | uint8_t bNumIntf;
52 | uint8_t bCV;
53 | uint8_t bIndex;
54 | uint8_t bAttr;
55 | uint8_t bMaxPower;
56 | } sCfgDesc;
57 | typedef __packed struct
58 | {
59 | uint8_t bLength;
60 | uint8_t bType;
61 | uint8_t iNum;
62 | uint8_t iAltString;
63 | uint8_t bEndPoints;
64 | uint8_t iClass;
65 | uint8_t iSub;
66 | uint8_t iProto;
67 | uint8_t iIndex;
68 | } sIntfDesc;
69 | typedef __packed struct
70 | {
71 | uint8_t bLength;
72 | uint8_t bType;
73 | uint8_t bEPAdd;
74 | uint8_t bAttr;
75 | uint16_t wPayLoad; /* low-speed this must be 0x08 */
76 | uint8_t bInterval;
77 | } sEPDesc;
78 |
79 | typedef __packed struct
80 | {
81 | uint8_t bLength;
82 | uint8_t bDescriptorType;
83 | uint16_t bcdHID;
84 | uint8_t bCountryCode;
85 | uint8_t bNumDescriptors;
86 | uint8_t bReportDescriptorType;
87 | uint8_t wItemLengthL;
88 | uint8_t wItemLengthH;
89 | } HIDDescriptor;
90 |
91 | typedef __packed struct
92 | {
93 | uint8_t bLength;
94 | uint8_t bType;
95 | uint16_t wLang;
96 | } sStrDesc;
97 |
98 |
99 |
100 | #endif
101 |
--------------------------------------------------------------------------------
/test_usb/main/usb_test.c:
--------------------------------------------------------------------------------
1 | /* Hello World Example
2 |
3 | This example code is in the Public Domain (or CC0 licensed, at your option.)
4 |
5 | Unless required by applicable law or agreed to in writing, this
6 | software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
7 | CONDITIONS OF ANY KIND, either express or implied.
8 | */
9 | #include
10 | #include "freertos/FreeRTOS.h"
11 | #include "freertos/task.h"
12 | #include "freertos/queue.h"
13 |
14 | #include "esp_system.h"
15 | #include "esp_spi_flash.h"
16 | #include
17 | #include "esp8266/eagle_soc.h"
18 | #include "esp8266/pin_mux_register.h"
19 | #include "esp8266/gpio_struct.h"
20 | #include "esp_clk.h"
21 | #include "driver/gpio.h"
22 |
23 | #define DP_P 12
24 | #define DM_P 14
25 | #define DP_P1 15
26 | #define DM_P1 13
27 | #define DP_P2 -1
28 | #define DM_P2 -1
29 | #define DP_P3 -1
30 | #define DM_P3 -1
31 | #define BLINK_GPIO 16
32 | #include "usb_host.h"
33 |
34 | void led(int on_fff)
35 | {
36 | // gpio_set_level(BLINK_GPIO, on_fff);
37 | gpio_set_level(BLINK_GPIO, !on_fff);
38 | //GPIO16
39 | }
40 |
41 | int64_t get_system_time_us() {
42 | struct timeval tv;
43 | gettimeofday(&tv, NULL);
44 | return (tv.tv_sec * 1000000LL + (tv.tv_usec ));
45 | }
46 | struct USBMessage
47 | {
48 | uint8_t src;
49 | uint8_t len;
50 | uint8_t data[0x8];
51 | };
52 |
53 | static xQueueHandle usb_mess_Que = NULL;
54 |
55 | void usbMess(uint8_t src,uint8_t len,uint8_t *data)
56 | {
57 | struct USBMessage msg;
58 | msg.src = src;
59 | msg.len = len<0x8?len:0x8;
60 | for(int k=0;k