├── .gitignore
├── LICENSE
├── README.md
├── images
├── IMG_20210303_184755_1.jpg
└── PulseView.jpg
└── usb_test
├── CMakeLists.txt
├── Makefile
├── main
├── CMakeLists.txt
├── Kconfig.projbuild
├── component.mk
├── usb_host.c
├── usb_host.h
└── usb_test.c
└── sdkconfig
/.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 | # esp32_usb_soft_host
2 | esp32 USB-LS pure software host thru general IO pins. Up to 4 HID devices simultaneously.
3 |
4 | Code is compatible with ESP-IDF version < 5.0, latest: https://github.com/espressif/esp-idf/releases/tag/v4.4.8
5 |
6 | 
7 |
8 | board ~$3 :https://www.aliexpress.com/premium/LOLIN32.html or any of https://www.aliexpress.com/premium/ESP32.html
9 |
10 | usb connectors(for example): https://www.aliexpress.com/item/1005002027124387.html
11 |
12 |
13 | //set right esp32 env for me it:
14 |
15 | >export IDF_PATH=$HOME/esp/esp-idf
16 |
17 | >source $HOME/esp/esp-idf/export.sh
18 |
19 |
20 | //connect the board, build & flash
21 |
22 | >git clone https://github.com/sdima1357/esp32_usb_soft_host
23 |
24 | >cd esp32_usb_soft_host/usb_test/
25 |
26 | > idf.py set-target esp32
27 |
28 | > idf.py menuconfig
29 |
30 | **Please set in Menuconfig->compiler options -> optimization level> O2 ( must be in O2 options. "idf.py set-target esp32" resets it to Og ,I don't know why)**
31 |
32 | > idf.py flash monitor
33 |
34 |
35 | Test run with 3 mouses, $3 CY7C68013A logic analyser and amazing program https://sigrok.org/wiki/PulseView :
36 |
37 | 
38 |
39 | >Tue Aug 31 15:50:48 IDT 2021
40 |
41 | Add esp32c3 support.
42 |
43 | >idf.py set-target esp32c3
44 |
45 | >idf.py menuconfig
46 |
47 | set in:
48 |
49 | Menuconfig->compiler options -> optimization level> O2
50 |
51 | **only for esp32c3: Component config-> ESP System Setting -> Memory protection-> Disable.**
52 |
53 | > idf.py flash monitor
54 |
55 |
56 |
57 | **Warning(disclaimer):
58 | Sorry, but target of this project right now - only research & proof of feasibility. I can't debug hardware which i don't have. Some hardware(devices) may not work, from different reasons. In the case of problem i suggest to check wires & use $3 CY7C68013A logic analyser. Sometimes i can help.**
59 |
--------------------------------------------------------------------------------
/images/IMG_20210303_184755_1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sdima1357/esp32_usb_soft_host/b1837bca54f92e7acbe2c3eff7ae1c6b7b6c91d9/images/IMG_20210303_184755_1.jpg
--------------------------------------------------------------------------------
/images/PulseView.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sdima1357/esp32_usb_soft_host/b1837bca54f92e7acbe2c3eff7ae1c6b7b6c91d9/images/PulseView.jpg
--------------------------------------------------------------------------------
/usb_test/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(usb_test)
--------------------------------------------------------------------------------
/usb_test/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 := usb_test
7 |
8 | include $(IDF_PATH)/make/project.mk
9 |
10 |
--------------------------------------------------------------------------------
/usb_test/main/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(srcs "usb_host.c"
2 | "usb_test.c"
3 | )
4 |
5 |
6 | idf_component_register(SRCS ${srcs}
7 | INCLUDE_DIRS ".")
8 |
9 |
--------------------------------------------------------------------------------
/usb_test/main/Kconfig.projbuild:
--------------------------------------------------------------------------------
1 | menu "Example Configuration"
2 |
3 | config BLINK_GPIO
4 | int "Blink GPIO number"
5 | range 0 34
6 | default 2
7 | help
8 | GPIO number (IOxx) to blink on and off.
9 |
10 | Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to blink.
11 |
12 | GPIOs 35-39 are input-only so cannot be used as outputs.
13 | endmenu
14 |
--------------------------------------------------------------------------------
/usb_test/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 |
--------------------------------------------------------------------------------
/usb_test/main/usb_host.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #include "driver/gpio.h"
10 | #include "sdkconfig.h"
11 | #include "driver/timer.h"
12 | #include "soc/soc.h"
13 | #include "soc/rtc.h"
14 | #include
15 | #include "esp_heap_caps.h"
16 | /*******************************
17 | * warning!!!: any copy of this code or his part must include this:
18 | * "The original was written by Dima Samsonov @ Israel sdima1357@gmail.com on 3/2021" *
19 | * Copyright (C) 2021 Dmitry Samsonov *
20 | ********************************/
21 |
22 | #include "usb_host.h"
23 |
24 | #define T_START 0b00000001
25 | #define T_ACK 0b01001011
26 | #define T_NACK 0b01011010
27 | #define T_SOF 0b10100101
28 | #define T_SETUP 0b10110100
29 | #define T_DATA0 0b11000011
30 | #define T_DATA1 0b11010010
31 | #define T_DATA2 0b11100001
32 | #define T_OUT 0b10000111
33 | #define T_IN 0b10010110
34 |
35 | #define T_ERR 0b00111100
36 | #define T_PRE 0b00111100
37 | #define T_NYET 0b01101001
38 | #define T_STALL 0b01111000
39 |
40 | // local non std
41 | #define T_NEED_ACK 0b01111011
42 | #define T_CHK_ERR 0b01111111
43 |
44 | #define USB_LS_K 0
45 | #define USB_LS_J 1
46 | #define USB_LS_S 2
47 |
48 | //most counters- uint_8t : so prevents overflow...
49 |
50 | #define DEF_BUFF_SIZE 0x100
51 |
52 | // somethins short like ACK
53 | #define SMALL_NO_DATA 36
54 |
55 |
56 | ///cpufreq (must be 240) /8 count = 30MHz convinient number for measure 1.5MHz of low speed USB
57 |
58 | //~ static inline uint32_t _getCycleCount32(void) {
59 | //~ uint32_t ccount;
60 | //~ __asm__ __volatile__("rsr %0,ccount":"=a" (ccount));
61 | //~ return ccount;
62 | //~ }
63 |
64 |
65 | //timing calibrations which depends CPU_FREQ, calibrated in initPins()
66 |
67 | int TRANSMIT_TIME_DELAY = 110; //delay each bit transmit
68 | int TIME_MULT = 25; //received time factor delta clocks* TIME_MULT/TIME_SCALE
69 | int TM_OUT = 64; //receive time out no activity on bus
70 | #define TIME_SCALE (1024)
71 |
72 | //#define TEST
73 | #ifdef TEST
74 | #define TOUT 1000
75 | #else
76 | #define TOUT (TM_OUT)
77 | #endif
78 |
79 |
80 | #include "hal/cpu_hal.h"
81 | #include "hal/gpio_hal.h"
82 | static inline uint32_t _getCycleCount32()
83 | {
84 | uint32_t ccount = cpu_hal_get_cycle_count();
85 | return ccount;
86 | }
87 | static inline uint8_t _getCycleCount8d8(void)
88 | {
89 | uint32_t ccount = cpu_hal_get_cycle_count();
90 | return ccount>>3;
91 | }
92 |
93 |
94 | #if CONFIG_IDF_TARGET_ESP32
95 | #define SET_I { PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[DP_PIN]); PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[DM_PIN]); GPIO.enable_w1tc = (1 << DP_PIN) | (1 << DM_PIN); }
96 | #define SET_O { GPIO.enable_w1ts = (1 << DP_PIN) | (1 << DM_PIN); PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[DP_PIN]); PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[DM_PIN]); }
97 | #define SE_J { *snd[1][0] = (1 << DM_PIN);*snd[1][1] = (1 << DP_PIN); }
98 | #define SE_0 { *snd[2][0] = (1 << DM_PIN);*snd[2][1] = (1 << DP_PIN); }
99 |
100 | #define READ_BOTH_PINS (((GPIO.in&RD_MASK)<<8)>>RD_SHIFT)
101 | uint32_t * snd[4][2] = {
102 | {&GPIO.out_w1tc,&GPIO.out_w1ts},
103 | {&GPIO.out_w1ts,&GPIO.out_w1tc},
104 | {&GPIO.out_w1tc,&GPIO.out_w1tc},
105 | {&GPIO.out_w1tc,&GPIO.out_w1tc}
106 | } ;
107 | #else
108 | #define SET_I { PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[DP_PIN]); PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[DM_PIN]); gpio_ll_output_disable(&GPIO,DM_PIN); gpio_ll_output_disable(&GPIO,DP_PIN);}
109 | #define SET_O { GPIO.enable_w1ts.val = (1 << DP_PIN) | (1 << DM_PIN); PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[DP_PIN]); PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[DM_PIN]); }
110 | #define SE_J { *snd[1][0] = (1 << DM_PIN);*snd[1][1] = (1 << DP_PIN); }
111 | #define SE_0 { *snd[2][0] = (1 << DM_PIN);*snd[2][1] = (1 << DP_PIN); }
112 | #define READ_BOTH_PINS (((GPIO.in.val&RD_MASK)<<8)>>RD_SHIFT)
113 | uint32_t * snd[4][2] = {
114 | {&GPIO.out_w1tc.val,&GPIO.out_w1ts.val},
115 | {&GPIO.out_w1ts.val,&GPIO.out_w1tc.val},
116 | {&GPIO.out_w1tc.val,&GPIO.out_w1tc.val},
117 | {&GPIO.out_w1tc.val,&GPIO.out_w1tc.val}
118 | } ;
119 | #endif
120 |
121 | //must be setup ech time with setPins
122 | uint32_t DP_PIN;
123 | uint32_t DM_PIN;
124 |
125 | uint32_t DM_PIN_M;
126 | uint32_t DP_PIN_M;
127 | uint16_t M_ONE;
128 | uint16_t P_ONE;
129 | uint32_t RD_MASK;
130 | uint32_t RD_SHIFT;
131 | //end must be setup ech time with setPins
132 |
133 |
134 | // temporary used insize lowlevel
135 | volatile uint8_t received_NRZI_buffer_bytesCnt;
136 | uint16_t received_NRZI_buffer[DEF_BUFF_SIZE];
137 |
138 | volatile uint8_t transmit_bits_buffer_store_cnt;
139 |
140 |
141 | //uint8_t transmit_bits_buffer_store[DEF_BUFF_SIZE];
142 | // share same memory as received_NRZI_buffer
143 | uint8_t* transmit_bits_buffer_store = (uint8_t*)&received_NRZI_buffer[0];
144 |
145 |
146 | volatile uint8_t transmit_NRZI_buffer_cnt;
147 | uint8_t transmit_NRZI_buffer[DEF_BUFF_SIZE];
148 |
149 | volatile uint8_t decoded_receive_buffer_head;
150 | volatile uint8_t decoded_receive_buffer_tail;
151 | uint8_t decoded_receive_buffer[DEF_BUFF_SIZE];
152 | // end temporary used insize lowlevel
153 |
154 |
155 |
156 |
157 | #if 1
158 | void (*delay_pntA)() =NULL;
159 | #define cpuDelay(x) {(*delay_pntA)();}
160 |
161 | #if CONFIG_IDF_TARGET_ESP32
162 | void setDelay(uint8_t ticks)
163 | {
164 | // opcodes of void test_delay() {__asm__ (" nop"); __asm__ (" nop"); __asm__ (" nop"); ...}
165 | //36 41 00 3d f0 1d f0 00 // one nop
166 | //36 41 00 3d f0 3d f0 3d f0 3d f0 3d f0 1d f0 00 // five nops
167 | //36 41 00 3d f0 3d f0 3d f0 3d f0 3d f0 3d f0 1d f0 00 00 00 //
168 | int MAX_DELAY_CODE_SIZE = 0x280;
169 | uint8_t* pntS;
170 | // it can't execute but can read & write
171 | if(!delay_pntA)
172 | {
173 | pntS = malloc(MAX_DELAY_CODE_SIZE);
174 | }
175 | else
176 | {
177 | pntS = heap_caps_realloc(delay_pntA, MAX_DELAY_CODE_SIZE, MALLOC_CAP_8BIT);
178 | }
179 | uint8_t* pnt = (uint8_t*)pntS;
180 | //put head of delay procedure
181 | *pnt++ = 0x36;
182 | *pnt++ = 0x41;
183 | *pnt++ = 0;
184 | for(int k=0;k ESP System Setting -> Memory protectiom-> Disable.\n memory prot must be disabled!!!\n delay_pntA = %p\n",delay_pntA);
245 | exit(0);
246 | }
247 | }
248 | #endif
249 | #else
250 | void setDelay(uint32_t tick)
251 | {
252 |
253 | }
254 | inline void cpuDelayNop(uint32_t ticks)
255 | {
256 | for(int k=0;kepCount = 0;
350 | while(posdescrBufferLen-2)
351 |
352 | {
353 | uint8_t len = pcurrent->descrBuffer[pos];
354 | uint8_t type = pcurrent->descrBuffer[pos+1];
355 | if(len==0)
356 | {
357 | //printf("pos = %02x type = %02x cfg.wLength = %02x pcurrent->acc_decoded_resp_counter = %02x\n ",pos,type,cfg.wLength,pcurrent->acc_decoded_resp_counter);
358 | pos = pcurrent->descrBufferLen;
359 | }
360 | if(pos+len<=pcurrent->descrBufferLen)
361 | {
362 | if(type == 0x2)
363 | {
364 | memcpy(&cfg,&pcurrent->descrBuffer[pos],len);
365 |
366 | }
367 | else if (type == 0x4)
368 | {
369 | memcpy(&sIntf,&pcurrent->descrBuffer[pos],len);
370 | }
371 | else if (type == 0x21)
372 | {
373 |
374 | hidCount++;
375 | int i = hidCount-1;
376 | memcpy(&hid[i],&pcurrent->descrBuffer[pos],len);
377 | }
378 | else if (type == 0x5)
379 | {
380 | pcurrent->epCount++;
381 | memcpy(&epd,&pcurrent->descrBuffer[pos],len);
382 | }
383 | }
384 | pos+=len;
385 | }
386 | }
387 |
388 |
389 |
390 |
391 |
392 | // received data from ep0,ep1!!!!
393 | //uint8_t current->Resp0[DEF_BUFF_SIZE];
394 | //uint8_t current->R0Bytes;
395 | //uint8_t current->Resp1[DEF_BUFF_SIZE];
396 | //uint8_t current->R1Bytes;
397 |
398 |
399 |
400 |
401 |
402 | #ifdef WR_SIMULTA
403 | uint32_t sndA[4] = {0,0,0,0};
404 | #endif
405 |
406 |
407 |
408 |
409 | inline void restart()
410 | {
411 | transmit_NRZI_buffer_cnt = 0;
412 | }
413 |
414 | void decoded_receive_buffer_clear()
415 | {
416 | decoded_receive_buffer_tail = decoded_receive_buffer_head;
417 | }
418 |
419 | inline void decoded_receive_buffer_put(uint8_t val)
420 | {
421 | decoded_receive_buffer[decoded_receive_buffer_head] = val;
422 | decoded_receive_buffer_head++;
423 | }
424 |
425 | uint8_t decoded_receive_buffer_get()
426 | {
427 | return decoded_receive_buffer[decoded_receive_buffer_tail++];
428 | }
429 |
430 | uint8_t decoded_receive_buffer_size()
431 | {
432 | return (uint8_t )(decoded_receive_buffer_head-decoded_receive_buffer_tail);
433 | }
434 |
435 | uint8_t cal5()
436 | {
437 | uint8_t crcb;
438 | uint8_t rem;
439 |
440 | crcb = 0b00101;
441 | rem = 0b11111;
442 |
443 | for(int k=16;k>4)&1;
446 | rem = (rem<<1)&0b11111;
447 |
448 | if(rb^(transmit_bits_buffer_store[k]&1))
449 | {
450 | rem ^= crcb;
451 | }
452 | }
453 | return (~rem)&0b11111;
454 | }
455 | uint32_t cal16()
456 | {
457 | uint32_t crcb;
458 | uint32_t rem;
459 |
460 | crcb = 0b1000000000000101;
461 | rem = 0b1111111111111111;
462 |
463 | for(int k=16;k>15)&1;
466 | rem = (rem<<1)&0b1111111111111111;
467 |
468 | if(rb^(transmit_bits_buffer_store[k]&1))
469 | {
470 | rem ^= crcb;
471 | }
472 | }
473 | return (~rem)&0b1111111111111111;
474 | }
475 | inline void seB(int bit)
476 | {
477 | transmit_bits_buffer_store[transmit_bits_buffer_store_cnt++] = bit;
478 | }
479 |
480 | inline void pu_MSB(uint16_t msg,int N)
481 | {
482 | for(int k=0;k>i)&1;
560 | }
561 | return res;
562 | }
563 | uint16_t rev16(uint16_t j)
564 | {
565 | uint16_t res = 0;
566 | for(int i=0;i<16;i++)
567 | {
568 | res<<=1;
569 | res|=(j>>i)&1;
570 | }
571 | return res;
572 | }
573 | #ifdef DEBUG_ALL
574 | uint16_t debug_buff[0x100];
575 | #endif
576 |
577 | int parse_received_NRZI_buffer()
578 | {
579 |
580 | if(!received_NRZI_buffer_bytesCnt) return 0;
581 |
582 | uint32_t crcb;
583 | uint32_t rem;
584 |
585 | crcb = 0b1000000000000101;
586 | rem = 0b1111111111111111;
587 |
588 | int res = 0;
589 | int cntOnes = 0;
590 |
591 | int terr = 0;
592 | uint8_t current_res = 0xfe;
593 | uint16_t prev = received_NRZI_buffer[0];
594 | int start = -1;
595 | uint8_t prev_smb = M_ONE;
596 | #ifdef DEBUG_ALL
597 | debug_buff[0] = received_NRZI_buffer_bytesCnt;
598 | uint8_t rcnt = 1;
599 | debug_buff[received_NRZI_buffer_bytesCnt] = 0xff;
600 | #endif
601 | for(int i = 1;i>8;
608 | int tm = (curr&0xff);
609 | //debug_buff[i] = tm | (smb<<8);
610 | if( tm<2 || (smb == 0) )
611 | {
612 | //terr+=tm<4?tm : 4;
613 | terr+=tm;
614 | }
615 | else
616 | {
617 | //terr = 0;
618 | int delta = ((((curr+terr)&0xff))*TIME_MULT+TIME_SCALE/2)/TIME_SCALE;
619 |
620 | for(int k=0;k=0)
642 | {
643 | start+=incc;
644 | }
645 | if(current_res==0x1 && start<0 )
646 | {
647 | start = 0;
648 | }
649 | if( (start&0x7) == 0 && incc)
650 | {
651 | if(start==8)
652 | {
653 | res = current_res;
654 | }
655 | #ifdef DEBUG_ALL
656 | debug_buff[rcnt++] = current_res;
657 | #endif
658 | decoded_receive_buffer_put(current_res);
659 | if(start>8)
660 | {
661 | for(int bt =0;bt<8;bt++)
662 | {
663 | int rb = (rem>>15)&1;
664 | rem = (rem<<1)&0b1111111111111111;
665 | if(rb^((current_res>>(7-bt))&1))
666 | {
667 | rem ^= crcb;
668 | }
669 | }
670 | }
671 | }
672 |
673 | }
674 |
675 | prev_smb = smb;
676 | }
677 | terr = 0;
678 | }
679 | }
680 | #ifdef DEBUG_ALL
681 | debug_buff[rcnt++] = 0xff;
682 | #endif
683 | rem &=0b1111111111111111;
684 | if (rem==0b1111111111111111)
685 | {
686 | return res;
687 | }
688 | if(rem==0x800d)
689 | {
690 | return T_NEED_ACK;
691 | }
692 | else
693 | {
694 | return T_CHK_ERR;
695 | }
696 | }
697 |
698 |
699 |
700 | //#define WR_SIMULTA
701 | void sendOnly()
702 | {
703 | uint8_t k;
704 | SET_O;
705 | #ifdef WR_SIMULTA
706 | uint32_t out_base = GPIO.out;
707 | sndA[0] = (out_base | DP) &~DM;
708 | sndA[1] = (out_base | DM) &~DP;
709 | sndA[2] = (out_base )&~(DP | DM);
710 | sndA[3] = out_base | (DM | DP);
711 | #endif
712 | for(k=0;k=160MHz .
731 | void sendRecieveNParse()
732 | {
733 | uint8_t locRec = 0;
734 | uint32_t val = 0xff;//DM_GPIO_Port->IDR&(0x3*DP_Pin);
735 | uint32_t nval = 0xff;
736 | int32_t act = TOUT;
737 | // portDISABLE_INTERRUPTS();
738 | sendOnly();
739 | while(act>0 && (val||nval) )
740 | {
741 | val = nval;
742 | nval = READ_BOTH_PINS;
743 | received_NRZI_buffer[locRec] = _getCycleCount8d8() | nval;
744 | if(val!=nval)
745 | {
746 | locRec++;
747 | act = TOUT;
748 | }
749 | else act--;
750 |
751 | //~ int flag = val!=nval;
752 | //~ locRec += flag;
753 | //~ act = (flag)?TOUT:(act-1);
754 | }
755 | // portENABLE_INTERRUPTS();
756 | received_NRZI_buffer_bytesCnt = locRec;
757 | }
758 | #else
759 | // dangerous option, but faster and works with low cpu freq ~80MHz . If we have noise on bus it can overflow received_NRZI_buffer[]
760 | void sendRecieveNParse()
761 | {
762 | register uint32_t R3;
763 | register uint16_t *STORE = received_NRZI_buffer;
764 | //__disable_irq();
765 | sendOnly();
766 | register uint32_t R4;// = READ_BOTH_PINS;
767 |
768 | START:
769 | R4 = READ_BOTH_PINS;
770 | *STORE = R4 | _getCycleCount8d8();
771 | STORE++;
772 | R3 = R4;
773 | //R4 = READ_BOTH_PINS;
774 | //if(R4!=R3) goto START;
775 | if( R3 )
776 | {
777 | for(int k=0;kcb_Cmd==CB_CHECK)
886 | {
887 | SET_I;
888 | current->wires_last_state = READ_BOTH_PINS>>8;
889 | if(current->wires_last_state==M_ONE)
890 | {
891 | // low speed
892 | }
893 | else if(current->wires_last_state==P_ONE)
894 | {
895 | //high speed
896 | }
897 | else if(current->wires_last_state==0x00)
898 | {
899 | // not connected
900 | }
901 | else if(current->wires_last_state== (M_ONE + P_ONE) )
902 | {
903 | //????
904 | }
905 | current->bComplete = 1;
906 | }
907 | else if (current->cb_Cmd==CB_RESET)
908 | {
909 | SOF();
910 | sendRecieveNParse();
911 | SET_O;
912 | SE_0;
913 | current->cmdTimeOut = 31;
914 | current->cb_Cmd = CB_WAIT0;
915 | }
916 | else if (current->cb_Cmd==CB_WAIT0)
917 | {
918 | if(current->cmdTimeOut>0)
919 | {
920 | current->cmdTimeOut--;
921 | }
922 | else
923 | {
924 | //sendRecieveNParse();
925 | current->bComplete = 1;
926 | }
927 | }
928 | else if (current->cb_Cmd==CB_WAIT1)
929 | {
930 | SOF();
931 | if(current->cmdTimeOut>0)
932 | {
933 | current->cmdTimeOut--;
934 | }
935 | else
936 | {
937 | sendRecieveNParse();
938 | current->wires_last_state = READ_BOTH_PINS>>8;
939 | current->bComplete = 1;
940 | }
941 | }
942 | else if (current->cb_Cmd==CB_POWER)
943 | {
944 |
945 | // for TEST
946 | #ifdef TEST
947 | SOF();
948 | sendRecieve();
949 | SOF();
950 | SOF();
951 | #else
952 | SET_O;
953 | SE_J;
954 | SET_I;
955 | current->cmdTimeOut = 2;
956 | current->cb_Cmd = CB_WAIT1;
957 | #endif
958 | }
959 | else if (current->cb_Cmd==CB_TICK)
960 | {
961 | SOF();
962 | current->bComplete = 1;
963 | }
964 | else if(current->cb_Cmd==CB_3)
965 | {
966 | SOF();
967 | pu_Addr(current->rq.cmd,current->rq.addr,current->rq.eop);
968 | pu_Cmd(current->rq.dataCmd, current->rq.bmRequestType, current->rq.bmRequest,current->rq.wValue, current->rq.wIndex, current->rq.wLen);
969 | int res = sendRecieve();
970 | if(res==T_ACK)
971 | {
972 | current->cb_Cmd=CB_4;
973 | current->numb_reps_errors_allowed = 8;
974 | return ;
975 | }
976 | else
977 | {
978 | current->numb_reps_errors_allowed--;
979 | if(current->numb_reps_errors_allowed>0)
980 | {
981 | return ;
982 | }
983 | else
984 | {
985 | current->cb_Cmd=CB_TICK;
986 | current->bComplete = 1;
987 | }
988 | }
989 | }
990 | else if(current->cb_Cmd==CB_4)
991 | {
992 | SOF();
993 | pu_Addr(T_OUT,current->rq.addr,current->rq.eop);
994 | //reB();
995 | pu_MSB(T_START,8);
996 | pu_MSB(T_DATA1,8);//setup
997 | for(int k=0;ktransmitL1Bytes;k++)
998 | {
999 | pu_LSB(current->transmitL1[k],8);
1000 | }
1001 | pu_MSB(cal16(),16);
1002 | repack();
1003 | sendRecieveNParse();
1004 | pu_Addr(T_IN,current->rq.addr,current->rq.eop);
1005 | //setup
1006 | sendRecieveNParse();
1007 | if(received_NRZI_buffer_bytesCntSMALL_NO_DATA/4)
1008 | {
1009 | ACK();
1010 | }
1011 | else
1012 | {
1013 | current->numb_reps_errors_allowed--;
1014 | if(current->numb_reps_errors_allowed>0)
1015 | {
1016 | return ;
1017 | }
1018 | else
1019 | {
1020 |
1021 | }
1022 |
1023 | }
1024 | current->cb_Cmd=CB_TICK;
1025 | current->bComplete = 1;
1026 | }
1027 | else if(current->cb_Cmd==CB_5)
1028 | {
1029 | SOF();
1030 | pu_Addr(current->rq.cmd,current->rq.addr,current->rq.eop);
1031 | pu_Cmd(current->rq.dataCmd, current->rq.bmRequestType, current->rq.bmRequest,current->rq.wValue, current->rq.wIndex, current->rq.wLen);
1032 | sendRecieveNParse();
1033 | //int res = sendRecieve(current->asckedReceiveBytes>8?8:current->asckedReceiveBytes);
1034 | int res = parse_received_NRZI_buffer();
1035 | if(res==T_ACK)
1036 | {
1037 | current->cb_Cmd = CB_6;
1038 | current->in_data_flip_flop = 1;
1039 | current->numb_reps_errors_allowed = 4;
1040 | current->counterAck ++;
1041 | return ;
1042 | }
1043 | else
1044 | {
1045 | //SOF();
1046 | current->counterNAck ++;
1047 | current->numb_reps_errors_allowed--;
1048 | if(current->numb_reps_errors_allowed>0)
1049 | {
1050 | // current->cb_Cmd = CB_TICK;
1051 | current->acc_decoded_resp_counter = 0;
1052 | return ;
1053 | }
1054 | else
1055 | {
1056 | current->cb_Cmd = CB_TICK;
1057 | current->bComplete = 1;
1058 | }
1059 | }
1060 | }
1061 | else if(current->cb_Cmd==CB_6)
1062 | {
1063 | SOF();
1064 | pu_Addr(T_IN,current->rq.addr,current->rq.eop);
1065 | //setup
1066 | sendRecieveNParse();
1067 | // if receive something ??
1068 | if(current->asckedReceiveBytes==0 && current->acc_decoded_resp_counter==0 && received_NRZI_buffer_bytesCntSMALL_NO_DATA/4 )
1069 | {
1070 | ACK();
1071 | //printf("received_NRZI_buffer_bytesCnt=%d!!!\n",received_NRZI_buffer_bytesCnt);
1072 | current->cb_Cmd = CB_TICK;
1073 | current->bComplete = 1;
1074 | return ;
1075 | }
1076 | int res = parse_received_NRZI_buffer();
1077 | if(res == T_NEED_ACK)
1078 | {
1079 | //SOF();
1080 | if(decoded_receive_buffer_size()>2)
1081 | {
1082 |
1083 | decoded_receive_buffer_get();
1084 | uint8_t sval = decoded_receive_buffer_get();
1085 | if((current->in_data_flip_flop&1)==1)
1086 | {
1087 | if(sval==T_DATA1)
1088 | {
1089 |
1090 | }
1091 | else
1092 | {
1093 | current->cb_Cmd = CB_7;
1094 | return ;
1095 | }
1096 | }
1097 | else
1098 | {
1099 | if(sval==T_DATA0)
1100 | {
1101 |
1102 | }
1103 | else
1104 | {
1105 | current->cb_Cmd = CB_7;
1106 | return ;
1107 | }
1108 | }
1109 | current->in_data_flip_flop++;
1110 | int bytes =decoded_receive_buffer_size()-2;
1111 | for(int kk=0;kkacc_decoded_resp[current->acc_decoded_resp_counter] = rev8(decoded_receive_buffer_get());
1114 | current->acc_decoded_resp_counter++;
1115 | current->asckedReceiveBytes--;
1116 | }
1117 | //while(decoded_receive_buffer_size()) {decoded_receive_buffer_get();}
1118 | if(bytes<=0)
1119 | {
1120 | //printf("zero!!\n");
1121 | current->acc_decoded_resp_counter = 0;
1122 | current->asckedReceiveBytes = 0;
1123 | current->cb_Cmd = CB_TICK;
1124 | current->bComplete = 1;
1125 | }
1126 | else
1127 | {
1128 | current->cb_Cmd = CB_7;
1129 | return ;
1130 | }
1131 | }
1132 | else
1133 | {
1134 | current->acc_decoded_resp_counter = 0;
1135 | current->asckedReceiveBytes = 0;
1136 | current->cb_Cmd = CB_TICK;
1137 | current->bComplete = 1;
1138 | return ;
1139 | }
1140 | }
1141 | else
1142 | {
1143 | current->numb_reps_errors_allowed--;
1144 | if(current->numb_reps_errors_allowed>0)
1145 | {
1146 | return ;
1147 | }
1148 | else
1149 | {
1150 | current->cb_Cmd = CB_TICK;
1151 | current->bComplete = 1;
1152 | }
1153 | }
1154 |
1155 | }
1156 | else if(current->cb_Cmd==CB_7)
1157 | {
1158 | SOF();
1159 | pu_Addr(T_IN,current->rq.addr,current->rq.eop);
1160 | //setup
1161 | sendRecieveNParse();
1162 | ACK();
1163 | if(current->asckedReceiveBytes>0)
1164 | {
1165 | current->cb_Cmd = CB_6;
1166 | return ;
1167 | }
1168 | current->cb_Cmd = CB_8;
1169 | }
1170 | else if(current->cb_Cmd==CB_8)
1171 | {
1172 | SOF();
1173 | pu_Addr(T_OUT,current->rq.addr,current->rq.eop);
1174 | pu_ShortCmd(T_DATA1);
1175 | sendOnly();
1176 | current->cb_Cmd = CB_TICK;
1177 | current->bComplete = 1;
1178 | }
1179 | else if(current->cb_Cmd==CB_2Ack)
1180 | {
1181 | SOF();
1182 | pu_Addr(T_IN,current->rq.addr,current->rq.eop);
1183 | //setup
1184 | sendRecieveNParse();
1185 | if(received_NRZI_buffer_bytesCntcb_Cmd = CB_TICK;
1189 | current->bComplete = 1;
1190 | //printf("received_NRZI_buffer_bytesCnt = %d\n",prec);
1191 | return ;
1192 | }
1193 | //ACK();
1194 | ACK();
1195 | current->cb_Cmd = CB_TICK;
1196 | current->bComplete = 1;
1197 | }
1198 | else if(current->cb_Cmd==CB_2)
1199 | {
1200 | SOF();
1201 | pu_Addr(T_IN,current->rq.addr,current->rq.eop);
1202 | //setup
1203 | sendRecieveNParse();
1204 | if(received_NRZI_buffer_bytesCntcb_Cmd = CB_TICK;
1208 | current->bComplete = 1;
1209 | //printf("received_NRZI_buffer_bytesCnt = %d\n",prec);
1210 | return ;
1211 | }
1212 | //ACK();
1213 | //ACK();
1214 | int res = parse_received_NRZI_buffer();
1215 | if(res==T_NEED_ACK)
1216 | {
1217 | if(decoded_receive_buffer_size()>2)
1218 | {
1219 | decoded_receive_buffer_get();
1220 | decoded_receive_buffer_get();
1221 | int bytes =decoded_receive_buffer_size()-2;
1222 | for(int kk=0;kkacc_decoded_resp[current->acc_decoded_resp_counter] = rev8(decoded_receive_buffer_get());
1225 | current->acc_decoded_resp_counter++;
1226 | current->asckedReceiveBytes--;
1227 | }
1228 | }
1229 | current->asckedReceiveBytes = 0;
1230 | current->cb_Cmd=CB_2Ack;
1231 | return ;
1232 | }
1233 | else
1234 | {
1235 | current->numb_reps_errors_allowed--;
1236 | if(current->numb_reps_errors_allowed>0)
1237 | {
1238 | return ;
1239 | }
1240 | else
1241 | {
1242 | current->cb_Cmd = CB_TICK;
1243 | current->bComplete = 1;
1244 | }
1245 | }
1246 | current->cb_Cmd = CB_TICK;
1247 | current->bComplete = 1;
1248 | current->asckedReceiveBytes = 0;
1249 | }
1250 |
1251 |
1252 | }
1253 |
1254 |
1255 | void Request(uint8_t cmd, uint8_t addr,uint8_t eop,
1256 | uint8_t dataCmd,uint8_t bmRequestType, uint8_t bmRequest,uint16_t wValue,uint16_t wIndex,uint16_t wLen,uint16_t waitForBytes)
1257 | {
1258 | current->rq.cmd = cmd;
1259 | current->rq.addr = addr;
1260 | current->rq.eop = eop;
1261 | current->rq.dataCmd = dataCmd;
1262 | current->rq.bmRequestType = bmRequestType;
1263 | current->rq.bmRequest = bmRequest;
1264 | current->rq.wValue = wValue;
1265 | current->rq.wIndex = wIndex;
1266 | current->rq.wLen = wLen;
1267 |
1268 | current->numb_reps_errors_allowed = 4;
1269 | current->asckedReceiveBytes = waitForBytes;
1270 | current->acc_decoded_resp_counter = 0;
1271 | // if(cmd==T_SETUP)
1272 | // {
1273 | current->cb_Cmd = CB_5;
1274 | // }
1275 | // HAL_Delay(1);
1276 | }
1277 |
1278 | void RequestSend(uint8_t cmd, uint8_t addr,uint8_t eop,
1279 | uint8_t dataCmd,uint8_t bmRequestType, uint8_t bmRequest,uint16_t wValue,uint16_t wIndex,uint16_t wLen,uint16_t transmitL1Bytes,uint8_t* data)
1280 | {
1281 | current->rq.cmd = cmd;
1282 | current->rq.addr = addr;
1283 | current->rq.eop = eop;
1284 | current->rq.dataCmd = dataCmd;
1285 | current->rq.bmRequestType = bmRequestType;
1286 | current->rq.bmRequest = bmRequest;
1287 | current->rq.wValue = wValue;
1288 | current->rq.wIndex = wIndex;
1289 | current->rq.wLen = wLen;
1290 | current->transmitL1Bytes = transmitL1Bytes;
1291 | for(int k=0;ktransmitL1Bytes;k++)
1292 | {
1293 | current->transmitL1[k] = data[k];
1294 | }
1295 | current->numb_reps_errors_allowed = 4;
1296 | current->acc_decoded_resp_counter = 0;
1297 | // if(cmd==T_SETUP)
1298 | // {
1299 | current->cb_Cmd = CB_3;
1300 | // }
1301 | }
1302 |
1303 | void RequestIn(uint8_t cmd, uint8_t addr,uint8_t eop,uint16_t waitForBytes)
1304 | {
1305 | current->rq.cmd = cmd;
1306 | current->rq.addr = addr;
1307 | current->rq.eop = eop;
1308 | current->numb_reps_errors_allowed = 4;
1309 | current->asckedReceiveBytes = waitForBytes;
1310 | current->acc_decoded_resp_counter = 0;
1311 | current->cb_Cmd = CB_2;
1312 | }
1313 |
1314 |
1315 |
1316 | void fsm_Mashine()
1317 | {
1318 | if(!current->bComplete) return;
1319 | current->bComplete = 0;
1320 |
1321 |
1322 |
1323 | if(current->fsm_state == 0)
1324 | {
1325 | current->epCount = 0;
1326 | current->cb_Cmd = CB_CHECK;
1327 | current->fsm_state = 1;
1328 | }
1329 | if(current->fsm_state == 1)
1330 | {
1331 | if(current->wires_last_state==M_ONE)
1332 | // if(1)
1333 | {
1334 | current->cmdTimeOut = 100+current->selfNum*73;
1335 | //current->cmdTimeOut = 100;
1336 | current->cb_Cmd = CB_WAIT0;
1337 | current->fsm_state = 2;
1338 | }
1339 | else
1340 | {
1341 | current->fsm_state = 0;
1342 | current->cb_Cmd = CB_CHECK;
1343 | }
1344 | }
1345 | else if(current->fsm_state==2)
1346 | {
1347 | current->cb_Cmd = CB_RESET;
1348 | current->fsm_state = 3;
1349 | }
1350 | else if(current->fsm_state==3)
1351 | {
1352 | current->cb_Cmd = CB_POWER;
1353 | #ifdef TEST
1354 | current->fsm_state = 3;
1355 | #else
1356 | current->fsm_state = 4;
1357 | #endif
1358 | }
1359 | else if(current->fsm_state==4)
1360 | {
1361 | Request(T_SETUP,ZERO_USB_ADDRESS,0b0000,T_DATA0,0x80,0x6,0x0100,0x0000,0x0012,0x0012);
1362 | current->fsm_state = 5;
1363 | }
1364 | else if(current->fsm_state==5)
1365 | {
1366 | if(current->acc_decoded_resp_counter==0x12)
1367 | {
1368 | memcpy(¤t->desc,current->acc_decoded_resp,0x12);
1369 | current->ufPrintDesc |= 1;
1370 | }
1371 | else
1372 | {
1373 | if(current->numb_reps_errors_allowed<=0)
1374 | {
1375 | current->fsm_state = 0;
1376 | return;
1377 | }
1378 | }
1379 | #if 1
1380 | Request(T_SETUP,ZERO_USB_ADDRESS,0b0000,T_DATA0,0x00,0x5,0x0000+ASSIGNED_USB_ADDRESS,0x0000,0x0000,0x0000);
1381 | current->fsm_state = 6;
1382 | #else
1383 | current->fsm_state = 0;
1384 | #endif
1385 | }
1386 | else if(current->fsm_state==6)
1387 | {
1388 | current->cmdTimeOut = 5;
1389 | current->cb_Cmd = CB_WAIT1;
1390 | current->fsm_state = 7;
1391 | }
1392 |
1393 | else if(current->fsm_state==7)
1394 | {
1395 | Request(T_SETUP,ASSIGNED_USB_ADDRESS,0b0000,T_DATA0,0x80,0x6,0x0200,0x0000,0x0009,0x0009);
1396 | current->fsm_state = 8;
1397 | }
1398 | else if(current->fsm_state==8)
1399 | {
1400 | if(current->acc_decoded_resp_counter==0x9)
1401 | {
1402 | memcpy(¤t->cfg,current->acc_decoded_resp,0x9);
1403 | current->ufPrintDesc |= 2;
1404 | Request(T_SETUP,ASSIGNED_USB_ADDRESS,0b0000,T_DATA0,0x80,0x6,0x0200,0x0000,current->cfg.wLength,current->cfg.wLength);
1405 | current->fsm_state = 9;
1406 | }
1407 | else
1408 | {
1409 | current->fsm_state = 0;
1410 | return ;
1411 | }
1412 | }
1413 | else if(current->fsm_state==9)
1414 | {
1415 | if(current->acc_decoded_resp_counter==current->cfg.wLength)
1416 | {
1417 | current->ufPrintDesc |= 4;
1418 | current->descrBufferLen = current->acc_decoded_resp_counter;
1419 | memcpy(current->descrBuffer,current->acc_decoded_resp,current->descrBufferLen);
1420 | parseImmed(current);
1421 | current->fsm_state = 97;
1422 | }
1423 | else
1424 | {
1425 | current->cmdTimeOut = 5;
1426 | current->cb_Cmd = CB_WAIT1;
1427 | current->fsm_state = 7;
1428 | }
1429 | }
1430 | else if(current->fsm_state==97)
1431 | {
1432 | // config interfaces??
1433 | //printf("set configuration 1\n");
1434 | Request(T_SETUP,ASSIGNED_USB_ADDRESS,0b0000,T_DATA0,0x00,0x9,0x0001,0x0000,0x0000,0x0000);
1435 | current->fsm_state = 98;
1436 | }
1437 | else if(current->fsm_state==98)
1438 | {
1439 | // config interfaces??
1440 | Request(T_SETUP,ASSIGNED_USB_ADDRESS,0b0000,T_DATA0,0x21,0xa,0x0000,0x0000,0x0000,0x0000);
1441 | current->fsm_state = 99;
1442 | }
1443 | else if(current->fsm_state==99)
1444 | {
1445 | //uint8_t cmd0 = current->cnt&0x20?0x7:0x0;
1446 | //current->cnt++;
1447 | //uint8_t cmd1 = current->cnt&0x20?0x7:0x0;
1448 | //printf(" 3 LEDs enable/disable on keyboard \n");
1449 | if(current->flags_new!=current->flags)
1450 | {
1451 | current->flags = current->flags_new;
1452 | RequestSend(T_SETUP,ASSIGNED_USB_ADDRESS,0b0000,T_DATA0,0x21,0x9,0x0200,0x0000,0x0001,0x0001,¤t->flags);
1453 | }
1454 | //if(cmd0!=cmd1)
1455 | //{
1456 |
1457 | //}
1458 | //else
1459 | //{
1460 | // current->cmdTimeOut = 1;
1461 | // current->cb_Cmd = CB_WAIT1;
1462 | //}
1463 | current->fsm_state = 100;
1464 | }
1465 | else if(current->fsm_state==100)
1466 | {
1467 | led(0);
1468 | RequestIn(T_IN, ASSIGNED_USB_ADDRESS,1,8);
1469 | current->fsm_state = 101;
1470 | }
1471 | else if(current->fsm_state==101)
1472 | {
1473 | if(current->acc_decoded_resp_counter>=1)
1474 | {
1475 | usbMess(current->selfNum*4+0,current->acc_decoded_resp_counter,current->acc_decoded_resp);
1476 | // current->ufPrintDesc |= 8;
1477 | //~ current->R0Bytes= current->acc_decoded_resp_counter;
1478 | //~ memcpy(current->Resp0,current->acc_decoded_resp,current->R0Bytes);
1479 |
1480 | led(1);
1481 | //gpio_set_level(B23_GPIO, 1);
1482 | }
1483 | //~ RequestIn(T_IN, ASSIGNED_USB_ADDRESS,2,8);
1484 | //~ current->fsm_state = 102;
1485 | if(current->epCount>=2)
1486 | {
1487 | RequestIn(T_IN, ASSIGNED_USB_ADDRESS,2,8);
1488 | current->fsm_state = 102;
1489 | }
1490 | else
1491 | {
1492 | current->cmdTimeOut = 3;
1493 | current->cb_Cmd = CB_WAIT1;
1494 | current->fsm_state = 104;
1495 | }
1496 | }
1497 | else if(current->fsm_state==102)
1498 | {
1499 | if(current->acc_decoded_resp_counter>=1)
1500 | {
1501 | usbMess(current->selfNum*4+1,current->acc_decoded_resp_counter,current->acc_decoded_resp);
1502 | //current->ufPrintDesc |= 16;
1503 | //current->R1Bytes= current->acc_decoded_resp_counter;
1504 | //memcpy(current->Resp1,current->acc_decoded_resp,current->R0Bytes);
1505 | led(1);
1506 | }
1507 | current->cmdTimeOut = 2;
1508 | current->cb_Cmd = CB_WAIT1;
1509 | current->fsm_state = 104;
1510 | }
1511 | else if (current->fsm_state==104)
1512 | {
1513 | current->cmdTimeOut = 4;
1514 | current->cb_Cmd = CB_WAIT1;
1515 | #ifdef DEBUG_REPEAT
1516 | static int rcnt =0;
1517 | rcnt++; //
1518 | if( (rcnt&0xff)==0 || (current->wires_last_state!=M_ONE))
1519 | #else
1520 | if(current->wires_last_state!=M_ONE)
1521 | #endif
1522 | {
1523 | current->fsm_state = 0;
1524 | return ;
1525 | }
1526 | current->fsm_state = 99;
1527 | }
1528 | else
1529 | {
1530 | current->cmdTimeOut = 2;
1531 | current->cb_Cmd = CB_WAIT1;
1532 | current->fsm_state = 0;
1533 | }
1534 | }
1535 |
1536 |
1537 | void setPins(int DPPin,int DMPin)
1538 | {
1539 | DP_PIN = DPPin;
1540 | DM_PIN = DMPin;
1541 | int diff = DPPin - DMPin;
1542 | if(abs(diff)>7)
1543 | {
1544 | printf("PIN DIFFERENCE MUST BE LESS 8!\n");
1545 | exit(1);
1546 | }
1547 | int MIN_PIN = (DPPin7||diff==0)
1563 | {
1564 | return 0;
1565 | }
1566 | return 1;
1567 | }
1568 |
1569 | int64_t get_system_time_us();
1570 |
1571 | float testDelay6(float freq_MHz)
1572 | {
1573 | // 6 bits must take 4.0 uSec
1574 | #define SEND_BITS 120
1575 | #define REPS 40
1576 | float res = 1;
1577 | transmit_NRZI_buffer_cnt = 0;
1578 | {
1579 | for(int k=0;kDP = DP0;
1614 | current->DM = DM0;
1615 | }
1616 | else if(k==1)
1617 | {
1618 | current->DP = DP1;
1619 | current->DM = DM1;
1620 | }
1621 | else if(k==2)
1622 | {
1623 | current->DP = DP2;
1624 | current->DM = DM2;
1625 | }
1626 | else if(k==3)
1627 | {
1628 | current->DP = DP3;
1629 | current->DM = DM3;
1630 | }
1631 | current->isValid = 0;
1632 | if(checkPins(current->DP,current->DM))
1633 | {
1634 | printf("pins %d %d is OK!\n",current->DP,current->DM);
1635 | current->selfNum = k;
1636 | current->flags_new = 0x0;
1637 | current->flags = 0x0;
1638 | current->in_data_flip_flop = 0;
1639 | current->bComplete = 1;
1640 | current->cmdTimeOut = 0;
1641 | current->ufPrintDesc =0;
1642 | current->cb_Cmd = CB_CHECK;
1643 | current->fsm_state = 0;
1644 | current->wires_last_state = 0;
1645 | current->counterNAck = 0;
1646 | current->counterAck = 0;
1647 | current->epCount = 0;
1648 | gpio_pad_select_gpio(current->DP);
1649 | gpio_set_direction(current->DP, GPIO_MODE_OUTPUT);
1650 | gpio_set_level(current->DP, 0);
1651 | gpio_set_direction(current->DP, GPIO_MODE_INPUT);
1652 | gpio_pulldown_en(current->DP);
1653 |
1654 | gpio_pad_select_gpio(current->DM);
1655 | gpio_set_direction(current->DM, GPIO_MODE_OUTPUT);
1656 | gpio_set_level(current->DM, 0);
1657 | gpio_set_direction(current->DM, GPIO_MODE_INPUT);
1658 | gpio_pulldown_en(current->DM);
1659 | current->isValid = 1;
1660 |
1661 | // TEST
1662 | setPins(current->DP,current->DM);
1663 | printf("READ_BOTH_PINS = %04x\n",READ_BOTH_PINS);
1664 | SET_O;
1665 | SE_0;
1666 | SE_J;
1667 | SE_0;
1668 | SET_I;
1669 | printf("READ_BOTH_PINS = %04x\n",READ_BOTH_PINS);
1670 | gpio_set_direction(current->DP, GPIO_MODE_OUTPUT);
1671 | gpio_set_direction(current->DM, GPIO_MODE_OUTPUT);
1672 | printf("READ_BOTH_PINS = %04x\n",READ_BOTH_PINS);
1673 | SET_I;
1674 | printf("READ_BOTH_PINS = %04x\n",READ_BOTH_PINS);
1675 | if(!calibrated)
1676 | {
1677 | //calibrate delay divide 2
1678 | #define DELAY_CORR 2
1679 | int uTime = 255-DELAY_CORR;
1680 | int dTime = 0;
1681 |
1682 | rtc_cpu_freq_config_t out_config;
1683 |
1684 | rtc_clk_cpu_freq_get_config(&out_config);
1685 |
1686 | //uint32_t freq = rtc_clk_cpu_freq_value(rtc_clk_cpu_freq_get());
1687 | printf("cpu freq = %d MHz\n",out_config.freq_mhz);
1688 |
1689 | TM_OUT = out_config.freq_mhz/2;
1690 |
1691 | // 8 - func divided clock to 8, 1.5 - MHz USB LS
1692 | TIME_MULT = (int)(TIME_SCALE/(out_config.freq_mhz/8/1.5)+0.5);
1693 | printf("TIME_MULT = %d \n",TIME_MULT);
1694 |
1695 | int TRANSMIT_TIME_DELAY_OPT = 0;
1696 | TRANSMIT_TIME_DELAY = TRANSMIT_TIME_DELAY_OPT;
1697 | printf("D=%4d ",TRANSMIT_TIME_DELAY);
1698 | setDelay(TRANSMIT_TIME_DELAY);
1699 | float cS_opt = testDelay6(out_config.freq_mhz);
1700 | #define OPT_TIME (4.00f)
1701 | for(int p=0;p<9;p++)
1702 | {
1703 | TRANSMIT_TIME_DELAY = (uTime+dTime)/2;
1704 | printf("D=%4d ",TRANSMIT_TIME_DELAY);
1705 | setDelay(TRANSMIT_TIME_DELAY);
1706 | float cS = testDelay6(out_config.freq_mhz);
1707 | if(fabsf(OPT_TIME-cS)DP,current->DM);
1734 | }
1735 |
1736 | }
1737 | }
1738 | void usbSetFlags(int _usb_num,uint8_t flags)
1739 | {
1740 | if(_usb_num=0)
1741 | {
1742 | current_usb[_usb_num].flags_new = flags;
1743 | }
1744 | }
1745 | uint8_t usbGetFlags(int _usb_num)
1746 | {
1747 | if(_usb_num=0)
1748 | {
1749 | return current_usb[_usb_num].flags;
1750 | }
1751 | return 0;
1752 | }
1753 | void usb_process()
1754 | {
1755 | #if CONFIG_IDF_TARGET_ESP32C3
1756 | cpu_ll_enable_cycle_count();
1757 | #endif
1758 | for(int k=0;kisValid)
1762 | {
1763 | setPins(current->DP,current->DM);
1764 | timerCallBack();
1765 |
1766 | fsm_Mashine();
1767 | }
1768 | }
1769 | }
1770 | void printState()
1771 | {
1772 |
1773 | static int cntl = 0;
1774 | cntl++;
1775 | int ref = cntl%NUM_USB;
1776 | sUsbContStruct * pcurrent = ¤t_usb[ref];
1777 | if(!pcurrent->isValid) return ;
1778 | if((cntl%800)cb_Cmd = %d state = %d epCount = %d",cntl%NUM_USB,pcurrent->counterAck,pcurrent->counterNAck,pcurrent->wires_last_state,pcurrent->cb_Cmd,pcurrent->fsm_state,pcurrent->epCount);
1781 | #ifdef DEBUG_ALL
1782 | for(int k=0;k<20;k++)
1783 | {
1784 | printf("%04x ", debug_buff[k]);
1785 | }
1786 | #endif
1787 | printf("\n");
1788 | }
1789 | //~ for(int k=0;k<0x14;k++)
1790 | //~ {
1791 | //~ if(cntl &1 )
1792 | //~ {
1793 | //~ printf("%04x ",prn(tr[k],0));
1794 | //~ }
1795 | //~ else
1796 | //~ {
1797 | //~ printf("%04x ",pr[k]);
1798 | //~ }
1799 | //~ }
1800 | //~ printf("\n");
1801 | if(pcurrent->ufPrintDesc&1)
1802 | {
1803 | pcurrent->ufPrintDesc &= ~(uint32_t)1;
1804 | //~ printf("desc.bcdUSB = %02x\n",pcurrent->desc.bcdUSB);
1805 | //~ printf("desc.bDeviceClass = %02x\n",pcurrent->desc.bDeviceClass);
1806 | //~ printf("desc.bDeviceSubClass = %02x\n",pcurrent->desc.bDeviceSubClass);
1807 | //~ printf("desc.bDeviceProtocol = %02x\n",pcurrent->desc.bDeviceProtocol);
1808 | //~ printf("desc.bMaxPacketSize0 = %02x\n",pcurrent->desc.bMaxPacketSize0);
1809 | //~ printf("desc.idVendor = %02x\n",pcurrent->desc.idVendor);
1810 | //~ printf("desc.idProduct = %02x\n",pcurrent->desc.idProduct);
1811 | printf("desc.bcdDevice = %02x\n",pcurrent->desc.bcdDevice);
1812 | printf("desc.iManufacturer = %02x\n",pcurrent->desc.iManufacturer);
1813 | printf("desc.iProduct = %02x\n",pcurrent->desc.iProduct);
1814 | printf("desc.iSerialNumber = %02x\n",pcurrent->desc.iSerialNumber);
1815 | printf("desc.bNumConfigurations = %02x\n",pcurrent->desc.bNumConfigurations);
1816 | }
1817 | if(pcurrent->ufPrintDesc&2)
1818 | {
1819 | pcurrent->ufPrintDesc &= ~(uint32_t)2;
1820 | //~ printf("cfg.bLength = %02x\n",cfg.bLength);
1821 | //~ printf("cfg.bType = %02x\n",cfg.bType);
1822 | //~ printf("cfg.wLength = %02x\n",cfg.wLength);
1823 | //~ printf("cfg.bNumIntf = %02x\n",cfg.bNumIntf);
1824 | //~ printf("cfg.bCV = %02x\n",cfg.bCV);
1825 | //~ printf("cfg.bIndex = %02x\n",cfg.bIndex);
1826 | //~ printf("cfg.bAttr = %02x\n",cfg.bAttr);
1827 | //~ printf("cfg.bMaxPower = %d\n",cfg.bMaxPower);
1828 | }
1829 | //~ if(pcurrent->ufPrintDesc&8)
1830 | //~ {
1831 | //~ pcurrent->ufPrintDesc &= ~(uint32_t)8;
1832 | //~ printf("in0 :");
1833 | //~ for(int k=0;kR0Bytes;k++)
1834 | //~ {
1835 | //~ printf("%02x ",pcurrent->Resp0[k]);
1836 | //~ }
1837 | //~ printf("\n");
1838 | //~ }
1839 | //~ if(pcurrent->ufPrintDesc&16)
1840 | //~ {
1841 | //~ pcurrent->ufPrintDesc &= ~(uint32_t)16;
1842 | //~ printf("in1 :");
1843 | //~ for(int k=0;kR1Bytes;k++)
1844 | //~ {
1845 | //~ printf("%02x ",pcurrent->Resp1[k]);
1846 | //~ }
1847 | //~ printf("\n");
1848 | //~ }
1849 |
1850 | if(pcurrent->ufPrintDesc&4)
1851 | {
1852 | pcurrent->ufPrintDesc &= ~(uint32_t)4;
1853 | sCfgDesc lcfg;
1854 | sIntfDesc sIntf;
1855 | HIDDescriptor hid[4];
1856 | sEPDesc epd;
1857 | int cfgCount = 0;
1858 | int sIntfCount = 0;
1859 | int hidCount = 0;
1860 |
1861 | int pos = 0;
1862 | #define STDCLASS 0x00
1863 | #define HIDCLASS 0x03
1864 | #define HUBCLASS 0x09 /* bDeviceClass, bInterfaceClass */
1865 | printf("clear epCount %d self = %d\n",pcurrent->epCount,pcurrent->selfNum);
1866 | //pcurrent->epCount = 0;
1867 | while(posdescrBufferLen-2)
1868 | {
1869 | uint8_t len = pcurrent->descrBuffer[pos];
1870 | uint8_t type = pcurrent->descrBuffer[pos+1];
1871 | if(len==0)
1872 | {
1873 | //printf("pos = %02x type = %02x cfg.wLength = %02x pcurrent->acc_decoded_resp_counter = %02x\n ",pos,type,cfg.wLength,pcurrent->acc_decoded_resp_counter);
1874 | pos = pcurrent->descrBufferLen;
1875 | }
1876 | if(pos+len<=pcurrent->descrBufferLen)
1877 | {
1878 | printf("\n");
1879 | if(type == 0x2)
1880 | {
1881 | sCfgDesc cfg;
1882 | memcpy(&cfg,&pcurrent->descrBuffer[pos],len);
1883 | //printf("cfg.bLength = %02x\n",cfg.bLength);
1884 | //printf("cfg.bType = %02x\n",cfg.bType);
1885 |
1886 | printf("cfg.wLength = %02x\n",cfg.wLength);
1887 | printf("cfg.bNumIntf = %02x\n",cfg.bNumIntf);
1888 | printf("cfg.bCV = %02x\n",cfg.bCV);
1889 | //printf("cfg.bIndex = %02x\n",cfg.bIndex);
1890 | //printf("cfg.bAttr = %02x\n",cfg.bAttr);
1891 | printf("cfg.bMaxPower = %d\n",cfg.bMaxPower);
1892 |
1893 | }
1894 | else if (type == 0x4)
1895 | {
1896 | sIntfDesc sIntf;
1897 | memcpy(&sIntf,&pcurrent->descrBuffer[pos],len);
1898 | //printf("sIntf.bLength = %02x\n",sIntf.bLength);
1899 | //printf("sIntf.bType = %02x\n",sIntf.bType);
1900 | //~ printf("sIntf.iNum = %02x\n",sIntf.iNum);
1901 | //~ printf("sIntf.iAltString = %02x\n",sIntf.iAltString);
1902 | //~ printf("sIntf.bEndPoints = %02x\n",sIntf.bEndPoints);
1903 | //~ printf("sIntf.iClass = %02x\n",sIntf.iClass);
1904 | //~ printf("sIntf.iSub = %02x\n",sIntf.iSub);
1905 | //~ printf("sIntf.iProto = %d\n",sIntf.iProto);
1906 | //~ printf("sIntf.iIndex = %d\n",sIntf.iIndex);
1907 |
1908 | }
1909 | else if (type == 0x21)
1910 | {
1911 |
1912 | hidCount++;
1913 | int i = hidCount-1;
1914 | memcpy(&hid[i],&pcurrent->descrBuffer[pos],len);
1915 | //printf("hid.bLength = %02x\n",hid[i].bLength);
1916 | //printf("hid.bDescriptorType = %02x\n",hid[i].bDescriptorType);
1917 | //~ printf("hid.bcdHID = %02x\n",hid[i].bcdHID);
1918 | //~ printf("hid.bCountryCode = %02x\n",hid[i].bCountryCode);
1919 | //~ printf("hid.bNumDescriptors = %02x\n",hid[i].bNumDescriptors);
1920 | //~ printf("hid.bReportDescriptorType = %02x\n",hid[i].bReportDescriptorType);
1921 | //~ printf("hid.wItemLengthH = %02x\n",hid[i].wItemLengthH);
1922 | //~ printf("hid.wItemLengthL = %02x\n",hid[i].wItemLengthL);
1923 | }
1924 | else if (type == 0x5)
1925 | {
1926 | //pcurrent->epCount++;
1927 | printf("pcurrent->epCount = %d\n",pcurrent->epCount);
1928 | sEPDesc epd;
1929 | memcpy(&epd,&pcurrent->descrBuffer[pos],len);
1930 | //printf("epd.bLength = %02x\n",epd.bLength);
1931 | //printf("epd.bType = %02x\n",epd.bType);
1932 | printf("epd.bEPAdd = %02x\n",epd.bEPAdd);
1933 | printf("epd.bAttr = %02x\n",epd.bAttr);
1934 | printf("epd.wPayLoad = %02x\n",epd.wPayLoad);
1935 | printf("epd.bInterval = %02x\n",epd.bInterval);
1936 | }
1937 | }
1938 | pos+=len;
1939 | }
1940 | }
1941 |
1942 | }
1943 |
--------------------------------------------------------------------------------
/usb_test/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 |
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 | void usbMess(uint8_t src,uint8_t len,uint8_t *data);
28 | void usbSetFlags(int _usb_num,uint8_t flags);
29 | uint8_t usbGetFlags(int _usb_num);
30 |
31 | typedef __packed struct
32 | {
33 | uint8_t bLength;
34 | uint8_t bDescriptorType;
35 | uint16_t bcdUSB;
36 | uint8_t bDeviceClass;
37 | uint8_t bDeviceSubClass;
38 | uint8_t bDeviceProtocol;
39 | uint8_t bMaxPacketSize0;
40 | uint16_t idVendor;
41 | uint16_t idProduct;
42 | uint16_t bcdDevice;
43 | uint8_t iManufacturer;
44 | uint8_t iProduct;
45 | uint8_t iSerialNumber;
46 | uint8_t bNumConfigurations;
47 | } sDevDesc;
48 |
49 | typedef __packed struct
50 | {
51 | uint8_t bLength;
52 | uint8_t bType;
53 | uint16_t wLength;
54 | uint8_t bNumIntf;
55 | uint8_t bCV;
56 | uint8_t bIndex;
57 | uint8_t bAttr;
58 | uint8_t bMaxPower;
59 | } sCfgDesc;
60 | typedef __packed struct
61 | {
62 | uint8_t bLength;
63 | uint8_t bType;
64 | uint8_t iNum;
65 | uint8_t iAltString;
66 | uint8_t bEndPoints;
67 | uint8_t iClass;
68 | uint8_t iSub;
69 | uint8_t iProto;
70 | uint8_t iIndex;
71 | } sIntfDesc;
72 | typedef __packed struct
73 | {
74 | uint8_t bLength;
75 | uint8_t bType;
76 | uint8_t bEPAdd;
77 | uint8_t bAttr;
78 | uint16_t wPayLoad; /* low-speed this must be 0x08 */
79 | uint8_t bInterval;
80 | } sEPDesc;
81 |
82 | typedef __packed struct
83 | {
84 | uint8_t bLength;
85 | uint8_t bDescriptorType;
86 | uint16_t bcdHID;
87 | uint8_t bCountryCode;
88 | uint8_t bNumDescriptors;
89 | uint8_t bReportDescriptorType;
90 | uint8_t wItemLengthL;
91 | uint8_t wItemLengthH;
92 | } HIDDescriptor;
93 |
94 | typedef __packed struct
95 | {
96 | uint8_t bLength;
97 | uint8_t bType;
98 | uint16_t wLang;
99 | } sStrDesc;
100 |
101 |
102 |
103 | #endif
104 |
--------------------------------------------------------------------------------
/usb_test/main/usb_test.c:
--------------------------------------------------------------------------------
1 | /* Blink 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
11 | #include
12 | #include
13 |
14 | #include "freertos/FreeRTOS.h"
15 | #include "freertos/task.h"
16 | #include "driver/gpio.h"
17 | #include "sdkconfig.h"
18 | #include "hal/timer_ll.h"
19 | /* Can run 'make menuconfig' to choose the GPIO to blink,
20 | or you can edit the following line and set a number here.
21 | */
22 | #include "freertos/FreeRTOS.h"
23 | #include "freertos/task.h"
24 | #include "freertos/queue.h"
25 | #include "driver/periph_ctrl.h"
26 | #include "driver/timer.h"
27 | #include "driver/gpio.h"
28 | #include "soc/soc.h"
29 | #include "soc/periph_defs.h"
30 | #include "esp_log.h"
31 |
32 | #include "usb_host.h"
33 | struct USBMessage
34 | {
35 | uint8_t src;
36 | uint8_t len;
37 | uint8_t data[0x8];
38 | };
39 | static xQueueHandle usb_mess_Que = NULL;
40 |
41 | void IRAM_ATTR timer_group0_isr(void *para)
42 | {
43 | timer_group_clr_intr_status_in_isr(TIMER_GROUP_0, TIMER_0);
44 | //taskENTER_CRITICAL();
45 | usb_process();
46 | //taskEXIT_CRITICAL();
47 | timer_group_enable_alarm_in_isr(TIMER_GROUP_0, TIMER_0);
48 | }
49 | void usbMess(uint8_t src,uint8_t len,uint8_t *data)
50 | {
51 | struct USBMessage msg;
52 | msg.src = src;
53 | msg.len = len<0x8?len:0x8;
54 | for(int k=0;k