├── .github
└── workflows
│ └── build.yml
├── LICENSE
├── README.md
├── hardware
├── README.md
├── gerbers
│ ├── spi2par2019_backpack.zip
│ └── spi2par2019_faithful.zip
├── spi2par2019backpack.brd
├── spi2par2019backpack.sch
├── spi2par2019faithful.brd
└── spi2par2019faithful.sch
├── images
├── arduino.jpg
├── boards.jpg
├── gerbers.png
├── ingame_temp.jpg
├── prog1.jpg
├── prog2.jpg
├── prog3.jpg
├── prog4.jpg
├── prog5.jpg
├── prog6.jpg
├── prog7.jpg
├── spi2par_connection.jpg
└── spi2par_connection2.jpg
├── schematic_spi2par2019backpack.pdf
├── schematic_spi2par2019faithful.pdf
├── spi2par2019.ino
├── src
└── SMWire
│ ├── SMWire.cpp
│ ├── SMWire.h
│ └── utility
│ ├── twi.c
│ └── twi.h
├── xboxsmbus.h
└── xeniumspi.h
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 |
3 | on:
4 | push:
5 | branches: [ master ]
6 | pull_request:
7 | branches: [ master ]
8 | workflow_dispatch:
9 |
10 | jobs:
11 | build:
12 | runs-on: ubuntu-latest
13 |
14 | steps:
15 | - name: Checkout repo
16 | uses: actions/checkout@v2
17 |
18 | - name: Set up Arduino CLI
19 | uses: arduino/setup-arduino-cli@v1
20 |
21 | - name: Install platform
22 | run: |
23 | arduino-cli core update-index
24 | arduino-cli core install arduino:avr
25 | arduino-cli lib install LiquidCrystal
26 |
27 | - name: Compile Sketch
28 | run: arduino-cli compile -b arduino:avr:leonardo --warnings "default"
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # spi2par2019
2 | 
3 | ## What is it?
4 | This is a recreation of a legacy Original Xbox adaptor that allowed you to use extremely common and cheap HD44780 compliant character LCD displays with the Xenium modchip SPI interface. The legacy adaptor was called 'spi2par' and has long since been out of production and extremely hard to come by.
5 |
6 | I have never had one either, so this design has been made from the ground up.
7 |
8 | There are two PCB layouts in this repository:
9 |
10 | 1. More faithful to the legacy spi2par design.
11 | 2. An LCD backpack design that takes advantage of the standard pinout of most HD44780 LCD displays to minimise the amount of wiring needed.
12 |
13 | These two layouts are shown in the below photo. The LCD backpack has two pin arrangements so can be used on the two common LCD pin header layouts as shown installed. The intent is to make this as open and easily accessible to anyone with minimal experience in soldering and programming.
14 |
15 |
16 | ## Features
17 | 1. Converts the Xenium SPI interface to HD44780 compliant parallel LCDs. These are extremely cheap and readily available LCD modules.
18 | 2. Software controllable brightness
19 | 3. Software controllable contrast
20 | 4. This feature never existed in the legacy. You can connect two additional wires to the motherboard LPC header, and the board will read fan speed and MB/CPU temperatures directly from the Xbox System Management bus. It will display and update this mid-game. Traditionally the LCD will just pause until you renter the dashboard. Example below:
21 |
22 |
23 |
24 | ## Assembly and Materials Required
25 | There is two ways you can do this. Option 1 is the intended way and has a PCB daughter board to make installation easier.
The second option uses less components but requires more wiring.
26 |
27 | #### Option 1 - Arduino module and PCB adaptor
28 | The standard design
29 |
30 | |Part|Qty | Possible Source|
31 | |--|--|--|
32 | | Ryzee119's spi2par2019 PCB |1| OSHPark (Bit expensive, 3 boards): [spi2par2019backpack](https://oshpark.com/shared_projects/HGCRYTFI) OR
[spi2par2019faithful](https://oshpark.com/shared_projects/7YvM7Fwu)
Or, Download the required zip file from the [Gerbers Folder](https://github.com/Ryzee119/spi2par2019/tree/master/hardware/gerbers) and upload the zip file to their online ordering service. Use the following PCB properties:
`2 layers, 45x30mm, 1.6mm thick, HASL, 1oz copper, no castellated holes`|
33 | | Arduino Pro Micro Leonardo 5V/16Mhz |1| [Any clones will work](https://www.aliexpress.com/item/New-Pro-Micro-for-arduino-ATmega32U4-5V-16MHz-Module-with-2-row-pin-header-For-Leonardo/32768308647.html). Make sure they're the 5V/16Mhz variant. |
34 | | N-Channel MOSFET 2N7002 SOT23 at position Q1| 1 |Find anywhere convenient
[Digikey](https://www.digikey.com.au/short/p4zbn8)
[Aliexpress](https://www.aliexpress.com/item/Free-Shipping-200PCS-2N7002-MOSFET-N-CH-60V-300MA-SOT-23/897983645.html) |
35 | | JST SH1.0 10 pin 1mm connector (To connect to Xenium) | 1 |Digikey: [Connector](https://www.digikey.com.au/product-detail/en/jst-sales-america-inc/SHR-10V-S-B/455-1385-ND/759874) + 3x[Jumpers](https://www.digikey.com.au/product-detail/en/jst-sales-america-inc/ASSHSSH28K152/455-3076-ND/6009452) OR
Aliexpress: [Connector with Jumpers (Get the 10P one)](https://www.aliexpress.com/item/5PCS-100MM-SH-1-0-Wire-Cable-Connector-DIY-SH1-0-JST-2-3-4-5/32952366214.html)|
36 | | General Hook-up Wire 26AWG or so| A metre or two |-|
37 |
38 | #### Option 2 - Arduino module only
39 | No extra PCB required, no backlight control, slightly harder soldering
40 |
41 | |Part|Qty | Possible Source|
42 | |--|--|--|
43 | | Arduino Pro Micro Leonardo 5V/16Mhz |1| [Any clones will work](https://www.aliexpress.com/item/32768308647.html). Make sure they're the 5V/16Mhz variant. |
44 | | JST SH1.0 10 pin 1mm connector (To connect to Xenium) | 1 |Digikey: [Connector](https://www.digikey.com.au/product-detail/en/jst-sales-america-inc/SHR-10V-S-B/455-1385-ND/759874) + 3x[Jumpers](https://www.digikey.com.au/product-detail/en/jst-sales-america-inc/ASSHSSH28K152/455-3076-ND/6009452) OR
Aliexpress: [Connector with Jumpers (Get the 10P one)](https://www.aliexpress.com/item/32952366214.html)|
45 | | General Hook-up Wire 26AWG or so| A metre or two |-|
46 |
47 | ## Programming
48 | 1. Clone this repository to your PC
49 | 2. Download then install the [Arduino IDE](https://www.arduino.cc/en/Main/Software).
50 | 3. Copy `spi2par2019` to your Sketch folder and open the `.ino` file.
51 | 4. Set the Board Type the `Arduino Leonardo` and the comport correctly.
52 | 5. Compile by clicking the tick in the top left.
53 | 5. Confirm it has compiled successfully from the console output.
54 | 6. Connect a MicroUSB cable between the Arduino Module and the PC.
55 | 7. Click the upload button and confirm successful. The LCD backlight should come on but no text will be displayed until connected to a Xenium or the Xbox SMBus.
56 |
57 | ## Installation
58 |
59 |
60 | ## Alternative Installation
61 |
62 |
63 | ## Further Setup
64 | If using XBMC, there appears to be a bug in the way the large text is printed to the LCD screen when used with a Xenium. This can cause the LCD screen to stop working when the screen saver starts.
65 | It is recommended to edit the /system/UserData/LCD.xml file and replace instances of `LCD.TimeWide21` or `LCD.TimeWide22` with something different. Perhaps `LCD.cputemperature` and `LCD.gputemperature` or if you want time, use the standard font (`System.Time`).
66 |
--------------------------------------------------------------------------------
/hardware/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # spi2par2019
4 |
5 | All PCBs have been design using [Autodesk Eagle](https://www.autodesk.com/products/eagle/free-download) software.
6 | This has been released as open source hardware released under the CERN Open Hardware Licence v1.2,
7 |
8 | CERN Open Hardware Licence v1.2
9 |
10 | Preamble
11 |
12 | Through this CERN Open Hardware Licence ("CERN OHL") version 1.2, CERN
13 | wishes to provide a tool to foster collaboration and sharing among
14 | hardware designers. The CERN OHL is copyright CERN. Anyone is welcome
15 | to use the CERN OHL, in unmodified form only, for the distribution of
16 | their own Open Hardware designs. Any other right is reserved. Release
17 | of hardware designs under the CERN OHL does not constitute an
18 | endorsement of the licensor or its designs nor does it imply any
19 | involvement by CERN in the development of such designs.
20 |
21 | 1. Definitions
22 |
23 | In this Licence, the following terms have the following meanings:
24 |
25 | “Licence” means this CERN OHL.
26 |
27 | “Documentation” means schematic diagrams, designs, circuit or circuit
28 | board layouts, mechanical drawings, flow charts and descriptive text,
29 | and other explanatory material that is explicitly stated as being made
30 | available under the conditions of this Licence. The Documentation may
31 | be in any medium, including but not limited to computer files and
32 | representations on paper, film, or any other media.
33 |
34 | “Documentation Location” means a location where the Licensor has
35 | placed Documentation, and which he believes will be publicly
36 | accessible for at least three years from the first communication to
37 | the public or distribution of Documentation.
38 |
39 | “Product” means either an entire, or any part of a, device built using
40 | the Documentation or the modified Documentation.
41 |
42 | “Licensee” means any natural or legal person exercising rights under
43 | this Licence.
44 |
45 | “Licensor” means any natural or legal person that creates or modifies
46 | Documentation and subsequently communicates to the public and/ or
47 | distributes the resulting Documentation under the terms and conditions
48 | of this Licence.
49 |
50 | A Licensee may at the same time be a Licensor, and vice versa.
51 |
52 | Use of the masculine gender includes the feminine and neuter genders
53 | and is employed solely to facilitate reading.
54 |
55 | 2. Applicability
56 |
57 | 2.1. This Licence governs the use, copying, modification,
58 | communication to the public and distribution of the Documentation, and
59 | the manufacture and distribution of Products. By exercising any right
60 | granted under this Licence, the Licensee irrevocably accepts these
61 | terms and conditions.
62 |
63 | 2.2. This Licence is granted by the Licensor directly to the Licensee,
64 | and shall apply worldwide and without limitation in time. The Licensee
65 | may assign his licence rights or grant sub-licences.
66 |
67 | 2.3. This Licence does not extend to software, firmware, or code
68 | loaded into programmable devices which may be used in conjunction with
69 | the Documentation, the modified Documentation or with Products, unless
70 | such software, firmware, or code is explicitly expressed to be subject
71 | to this Licence. The use of such software, firmware, or code is
72 | otherwise subject to the applicable licence terms and conditions.
73 |
74 | 3. Copying, modification, communication to the public and distribution
75 | of the Documentation
76 |
77 | 3.1. The Licensee shall keep intact all copyright and trademarks
78 | notices, all notices referring to Documentation Location, and all
79 | notices that refer to this Licence and to the disclaimer of warranties
80 | that are included in the Documentation. He shall include a copy
81 | thereof in every copy of the Documentation or, as the case may be,
82 | modified Documentation, that he communicates to the public or
83 | distributes.
84 |
85 | 3.2. The Licensee may copy, communicate to the public and distribute
86 | verbatim copies of the Documentation, in any medium, subject to the
87 | requirements specified in section 3.1.
88 |
89 | 3.3. The Licensee may modify the Documentation or any portion thereof
90 | provided that upon modification of the Documentation, the Licensee
91 | shall make the modified Documentation available from a Documentation
92 | Location such that it can be easily located by an original Licensor
93 | once the Licensee communicates to the public or distributes the
94 | modified Documentation under section 3.4, and, where required by
95 | section 4.1, by a recipient of a Product. However, the Licensor shall
96 | not assert his rights under the foregoing proviso unless or until a
97 | Product is distributed.
98 |
99 | 3.4. The Licensee may communicate to the public and distribute the
100 | modified Documentation (thereby in addition to being a Licensee also
101 | becoming a Licensor), always provided that he shall:
102 |
103 | a) comply with section 3.1;
104 |
105 | b) cause the modified Documentation to carry prominent notices stating
106 | that the Licensee has modified the Documentation, with the date and
107 | description of the modifications;
108 |
109 | c) cause the modified Documentation to carry a new Documentation
110 | Location notice if the original Documentation provided for one;
111 |
112 | d) make available the modified Documentation at the same level of
113 | abstraction as that of the Documentation, in the preferred format for
114 | making modifications to it (e.g. the native format of the CAD tool as
115 | applicable), and in the event that format is proprietary, in a format
116 | viewable with a tool licensed under an OSI-approved license if the
117 | proprietary tool can create it; and
118 |
119 | e) license the modified Documentation under the terms and conditions
120 | of this Licence or, where applicable, a later version of this Licence
121 | as may be issued by CERN.
122 |
123 | 3.5. The Licence includes a non-exclusive licence to those patents or
124 | registered designs that are held by, under the control of, or
125 | sub-licensable by the Licensor, to the extent necessary to make use of
126 | the rights granted under this Licence. The scope of this section 3.5
127 | shall be strictly limited to the parts of the Documentation or
128 | modified Documentation created by the Licensor.
129 |
130 | 4. Manufacture and distribution of Products
131 |
132 | 4.1. The Licensee may manufacture or distribute Products always
133 | provided that, where such manufacture or distribution requires a
134 | licence under this Licence the Licensee provides to each recipient of
135 | such Products an easy means of accessing a copy of the Documentation
136 | or modified Documentation, as applicable, as set out in section 3.
137 |
138 | 4.2. The Licensee is invited to inform any Licensor who has indicated
139 | his wish to receive this information about the type, quantity and
140 | dates of production of Products the Licensee has (had) manufactured
141 |
142 | 5. Warranty and liability
143 |
144 | 5.1. DISCLAIMER – The Documentation and any modified Documentation are
145 | provided "as is" and any express or implied warranties, including, but
146 | not limited to, implied warranties of merchantability, of satisfactory
147 | quality, non-infringement of third party rights, and fitness for a
148 | particular purpose or use are disclaimed in respect of the
149 | Documentation, the modified Documentation or any Product. The Licensor
150 | makes no representation that the Documentation, modified
151 | Documentation, or any Product, does or will not infringe any patent,
152 | copyright, trade secret or other proprietary right. The entire risk as
153 | to the use, quality, and performance of a Product shall be with the
154 | Licensee and not the Licensor. This disclaimer of warranty is an
155 | essential part of this Licence and a condition for the grant of any
156 | rights granted under this Licence. The Licensee warrants that it does
157 | not act in a consumer capacity.
158 |
159 | 5.2. LIMITATION OF LIABILITY – The Licensor shall have no liability
160 | for direct, indirect, special, incidental, consequential, exemplary,
161 | punitive or other damages of any character including, without
162 | limitation, procurement of substitute goods or services, loss of use,
163 | data or profits, or business interruption, however caused and on any
164 | theory of contract, warranty, tort (including negligence), product
165 | liability or otherwise, arising in any way in relation to the
166 | Documentation, modified Documentation and/or the use, manufacture or
167 | distribution of a Product, even if advised of the possibility of such
168 | damages, and the Licensee shall hold the Licensor(s) free and harmless
169 | from any liability, costs, damages, fees and expenses, including
170 | claims by third parties, in relation to such use.
171 |
172 | 6. General
173 |
174 | 6.1. Except for the rights explicitly granted hereunder, this Licence
175 | does not imply or represent any transfer or assignment of intellectual
176 | property rights to the Licensee.
177 |
178 | 6.2. The Licensee shall not use or make reference to any of the names
179 | (including acronyms and abbreviations), images, or logos under which
180 | the Licensor is known, save in so far as required to comply with
181 | section 3. Any such permitted use or reference shall be factual and
182 | shall in no event suggest any kind of endorsement by the Licensor or
183 | its personnel of the modified Documentation or any Product, or any
184 | kind of implication by the Licensor or its personnel in the
185 | preparation of the modified Documentation or Product.
186 |
187 | 6.3. CERN may publish updated versions of this Licence which retain
188 | the same general provisions as this version, but differ in detail so
189 | far this is required and reasonable. New versions will be published
190 | with a unique version number.
191 |
192 | 6.4. This Licence shall terminate with immediate effect, upon written
193 | notice and without involvement of a court if the Licensee fails to
194 | comply with any of its terms and conditions, or if the Licensee
195 | initiates legal action against Licensor in relation to this
196 | Licence. Section 5 shall continue to apply.
--------------------------------------------------------------------------------
/hardware/gerbers/spi2par2019_backpack.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ryzee119/spi2par2019/a0c0781838d309e02fc0096ea8454827b0c9742b/hardware/gerbers/spi2par2019_backpack.zip
--------------------------------------------------------------------------------
/hardware/gerbers/spi2par2019_faithful.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ryzee119/spi2par2019/a0c0781838d309e02fc0096ea8454827b0c9742b/hardware/gerbers/spi2par2019_faithful.zip
--------------------------------------------------------------------------------
/hardware/spi2par2019faithful.brd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 | Ryzee119
194 | SMBUS
195 | XENIUM
196 | SPI
197 | Convert Xenium SPI Interface
198 | to HD44780 Compliant Parallel LCD
199 | https://github.com/Ryzee119/spi2par2019
200 | Ryzee119
201 | spi2par2019
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 | Arduino Pro Micro 5V
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 | <b>Single Pads</b><p>
252 | <author>Created by librarian@cadsoft.de</author>
253 |
254 |
255 | <b>SMD PAD</b>
256 |
257 | >VALUE
258 | >NAME
259 |
260 |
261 |
262 |
263 | SMD PAD
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 | <b>Zetex Power MOS FETs, Bridges, Diodes</b><p>
272 | http://www.zetex.com<p>
273 | <author>Created by librarian@cadsoft.de</author>
274 |
275 |
276 | <b>Small Outline Transistor</b>
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 | >VALUE
285 | >NAME
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 | Small Outline Transistor
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 | <b>EAGLE Design Rules</b>
311 | <p>
312 | Die Standard-Design-Rules sind so gewählt, dass sie für
313 | die meisten Anwendungen passen. Sollte ihre Platine
314 | besondere Anforderungen haben, treffen Sie die erforderlichen
315 | Einstellungen hier und speichern die Design Rules unter
316 | einem neuen Namen ab.
317 | <b>EAGLE Design Rules</b>
318 | <p>
319 | The default Design Rules have been set to cover
320 | a wide range of applications. Your particular design
321 | may have different requirements, so please make the
322 | necessary adjustments and save your customized
323 | design rules under a new name.
324 | <b>Elecrow EAGLE Design Rules</b>
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 |
518 |
519 |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 |
528 |
529 |
530 |
531 |
532 |
533 |
534 |
535 |
536 |
537 |
538 |
539 |
540 |
541 |
542 |
543 |
544 |
545 |
546 |
547 |
548 |
549 |
550 |
551 |
552 |
553 |
554 |
555 |
556 |
557 |
558 |
559 |
560 |
561 |
562 |
563 |
564 |
565 |
566 |
567 |
568 |
569 |
570 |
571 |
572 |
573 |
574 |
575 |
576 |
577 |
578 |
579 |
580 |
581 |
582 |
583 |
584 |
585 |
586 |
587 |
588 |
589 |
590 |
591 |
592 |
593 |
594 |
595 |
596 |
597 |
598 |
599 |
600 |
601 |
602 |
603 |
604 |
605 |
606 |
607 |
608 |
609 |
610 |
611 |
612 |
613 |
614 |
615 |
616 |
617 |
618 |
619 |
620 |
621 |
622 |
623 |
624 |
625 |
626 |
627 |
628 |
629 |
630 |
631 |
632 |
633 |
634 |
635 |
636 |
637 |
638 |
639 |
640 |
641 |
642 |
643 |
644 |
645 |
646 |
647 |
648 |
649 |
650 |
651 |
652 |
653 |
654 |
655 |
656 |
657 |
658 |
659 |
660 |
661 |
662 |
663 |
664 |
665 |
666 |
667 |
668 |
669 |
670 |
671 |
672 |
673 |
674 |
675 |
676 |
677 |
678 |
679 |
680 |
681 |
682 |
683 |
684 |
685 |
686 |
687 |
688 |
689 |
690 |
691 |
692 |
693 |
694 |
695 |
696 |
697 |
698 |
699 |
700 |
701 |
702 |
703 |
704 |
705 |
706 |
707 |
708 |
709 |
710 |
711 |
712 |
713 |
714 |
715 |
716 |
717 |
718 |
719 |
720 |
721 |
722 |
723 |
724 |
725 |
726 |
727 |
728 |
729 |
730 |
731 |
732 |
733 |
734 |
735 |
736 |
737 |
738 |
739 |
740 |
741 |
742 |
743 |
744 |
745 |
746 |
747 |
748 |
749 |
750 |
751 |
752 |
753 |
754 |
755 |
756 |
757 |
758 |
759 |
760 |
761 |
762 |
763 |
764 |
765 |
766 |
767 |
768 |
769 |
770 |
771 |
772 |
773 |
774 |
775 |
776 |
777 |
778 |
779 |
780 |
781 |
782 |
783 |
784 |
785 |
786 |
787 |
788 |
789 |
790 |
791 |
792 |
793 |
794 |
795 |
796 |
797 |
798 | Since Version 6.2.2 text objects can contain more than one line,
799 | which will not be processed correctly with this version.
800 |
801 |
802 | Since Version 8.2, EAGLE supports online libraries. The ids
803 | of those online libraries will not be understood (or retained)
804 | with this version.
805 |
806 |
807 | Since Version 8.3, EAGLE supports Fusion synchronisation.
808 | This feature will not be available in this version and saving
809 | the document will break the link to the Fusion PCB feature.
810 |
811 |
812 | Since Version 8.3, EAGLE supports URNs for individual library
813 | assets (packages, symbols, and devices). The URNs of those assets
814 | will not be understood (or retained) with this version.
815 |
816 |
817 | Since Version 8.3, EAGLE supports the association of 3D packages
818 | with devices in libraries, schematics, and board files. Those 3D
819 | packages will not be understood (or retained) with this version.
820 |
821 |
822 |
823 |
--------------------------------------------------------------------------------
/images/arduino.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ryzee119/spi2par2019/a0c0781838d309e02fc0096ea8454827b0c9742b/images/arduino.jpg
--------------------------------------------------------------------------------
/images/boards.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ryzee119/spi2par2019/a0c0781838d309e02fc0096ea8454827b0c9742b/images/boards.jpg
--------------------------------------------------------------------------------
/images/gerbers.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ryzee119/spi2par2019/a0c0781838d309e02fc0096ea8454827b0c9742b/images/gerbers.png
--------------------------------------------------------------------------------
/images/ingame_temp.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ryzee119/spi2par2019/a0c0781838d309e02fc0096ea8454827b0c9742b/images/ingame_temp.jpg
--------------------------------------------------------------------------------
/images/prog1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ryzee119/spi2par2019/a0c0781838d309e02fc0096ea8454827b0c9742b/images/prog1.jpg
--------------------------------------------------------------------------------
/images/prog2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ryzee119/spi2par2019/a0c0781838d309e02fc0096ea8454827b0c9742b/images/prog2.jpg
--------------------------------------------------------------------------------
/images/prog3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ryzee119/spi2par2019/a0c0781838d309e02fc0096ea8454827b0c9742b/images/prog3.jpg
--------------------------------------------------------------------------------
/images/prog4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ryzee119/spi2par2019/a0c0781838d309e02fc0096ea8454827b0c9742b/images/prog4.jpg
--------------------------------------------------------------------------------
/images/prog5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ryzee119/spi2par2019/a0c0781838d309e02fc0096ea8454827b0c9742b/images/prog5.jpg
--------------------------------------------------------------------------------
/images/prog6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ryzee119/spi2par2019/a0c0781838d309e02fc0096ea8454827b0c9742b/images/prog6.jpg
--------------------------------------------------------------------------------
/images/prog7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ryzee119/spi2par2019/a0c0781838d309e02fc0096ea8454827b0c9742b/images/prog7.jpg
--------------------------------------------------------------------------------
/images/spi2par_connection.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ryzee119/spi2par2019/a0c0781838d309e02fc0096ea8454827b0c9742b/images/spi2par_connection.jpg
--------------------------------------------------------------------------------
/images/spi2par_connection2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ryzee119/spi2par2019/a0c0781838d309e02fc0096ea8454827b0c9742b/images/spi2par_connection2.jpg
--------------------------------------------------------------------------------
/schematic_spi2par2019backpack.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ryzee119/spi2par2019/a0c0781838d309e02fc0096ea8454827b0c9742b/schematic_spi2par2019backpack.pdf
--------------------------------------------------------------------------------
/schematic_spi2par2019faithful.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ryzee119/spi2par2019/a0c0781838d309e02fc0096ea8454827b0c9742b/schematic_spi2par2019faithful.pdf
--------------------------------------------------------------------------------
/spi2par2019.ino:
--------------------------------------------------------------------------------
1 | #include "xeniumspi.h"
2 | #include "xboxsmbus.h"
3 | #include "src/SMWire/SMWire.h"
4 | #include
5 |
6 | //Some screens like difference contrast values. So I couldn't really set a good default value
7 | //Play around and adjust to suit your screen. If you have flickering issues, it may help to solder
8 | //an extra electrolytic capacitor between the contrast pin (normally labelled 'V0') and GND.
9 | #define DEFAULT_CONTRAST 100 //0-255. Lower is higher contrast.
10 | #define DEFAULT_BACKLIGHT 255 //0-255. Higher is brighter.
11 | //#define USE_FAHRENHEIT 1 //Uncomment this line to make the in-game temp readouts display in Fahrenheit.
12 |
13 | //Use the following lines to set the LCD display size; currently only displays of 20/16 columns and 4 rows are supported.
14 | //16 column displays will have issues with the dashboard display as these are all expecting 20 column displays.
15 | #define LCD_ROW 4
16 | #define LCD_COL 20
17 |
18 | #if (LCD_COL == 16)
19 | #define tempDisplayF "CPU:%3u%c MB:%3u%c"
20 | #define tempDisplayC "CPU:%3u%c MB:%3u%c"
21 | #define tenEightyI "1080i "
22 | #define sevenTwentyP "720p "
23 | #define fourEightyI "480i "
24 | #define fourEightyP "480p "
25 | #define fanSpeed "FAN: %3u%% "
26 | #else
27 | #define tempDisplayF "CPU:%3u%cF M/B:%3u%cF "
28 | #define tempDisplayC "CPU:%3u%cC M/B:%3u%cC "
29 | #define tenEightyI " 1080i "
30 | #define sevenTwentyP " 720p "
31 | #define fourEightyI " 480i "
32 | #define fourEightyP " 480p "
33 | #define fanSpeed "FAN: %3u%% "
34 |
35 | #endif
36 |
37 |
38 | //HD44780 LCD Setup
39 | const uint8_t rs = 18, en = 8, d4 = 7, d5 = 6, d6 = 5, d7 = 4; //HD44780 compliant LCD display pin numbers
40 | const uint8_t ss_in = 17, miso = 14, mosi = 16, sck = 15, ss_out = A2; //SPI pin numbers, ss_in is the CS for the slave. As Xenium doesn't seem to use CS, ss_out is connected to ss_in on the PCB to manually trigger CS.
41 | const uint8_t i2c_sda = 2, i2c_scl = 3; //i2c pins for SMBus
42 | const uint8_t backlightPin = 10, contrastPin = 9; //Pin nubmers for backlight and contrast. Must be PWM enabled
43 | uint8_t cursorPosCol = 0, cursorPosRow = 0; //Track the position of the cursor
44 | uint8_t wrapping = 0, scrolling = 0; //Xenium spi command toggles for the lcd screen.
45 | LiquidCrystal hd44780(rs, en, d4, d5, d6, d7); //Constructor for the LCD.
46 |
47 |
48 | //SPI Data
49 | int16_t RxQueue[256]; //Input FIFO buffer for raw SPI data from Xenium
50 | uint8_t QueuePos; //Tracks the current position in the FIFO queue that is being processed
51 | uint8_t QueueRxPos; //Tracks the current position in the FIFO queue of the unprocessed input data (raw realtime SPI data)
52 | uint8_t SPIState; //SPI State machine flag to monitor the SPI bus state can = SPI_ACTIVE, SPI_IDLE, SPI_SYNC, SPI_WAIT
53 | uint32_t SPIIdleTimer; //Tracks how long the SPI bus has been idle for
54 |
55 |
56 |
57 | //I2C Bus
58 | uint32_t SMBusTimer; //Timer used to trigger SMBus reads
59 | uint8_t i2cCheckCount = 0; //Tracks what check we're up to of the i2c bus busy state
60 | uint8_t I2C_BUSY_CHECKS = 5; //To ensure we don't interfere with the actual Xbox's SMBus activity, we check the bus for activity for sending.
61 |
62 |
63 | //SPI Bus Receiver Interrupt Routine
64 | ISR (SPI_STC_vect) {
65 | RxQueue[QueueRxPos] = SPDR;
66 | QueueRxPos++; //This is an unsigned 8 bit variable, so will reset back to 0 after 255 automatically
67 | SPIState = SPI_ACTIVE;
68 |
69 | }
70 |
71 | void setup() {
72 | pinMode(ss_out, OUTPUT);
73 | digitalWrite(ss_out, HIGH); //Force SPI CS signal high while we setup
74 | Serial.begin(9600);
75 | delay(5);
76 | for (uint8_t i = 0; i < 8; i++) {
77 | delay(1);
78 | hd44780.createChar(i, &chars[i][0]);
79 | }
80 |
81 | hd44780.begin(LCD_COL, LCD_ROW);
82 | hd44780.noCursor();
83 |
84 | memset(RxQueue, -1, 256);
85 |
86 |
87 | //I put my logic analyser on the Xenium SPI bus to confirm the bus properties.
88 | //The master clocks at ~16kHz. SPI Clock is high when inactive, data is valid on the trailing edge (CPOL/CPHA=1. Also known as SPI mode 3)
89 | SPCR |= _BV(SPE); //Turn on SPI. We don't set the MSTR bit so it's slave.
90 | SPCR |= _BV(SPIE); //Enable to SPI Interrupt Vector
91 | SPCR |= _BV(CPOL); //SPI Clock is high when inactive
92 | SPCR |= _BV(CPHA); //Data is Valid on Clock Trailing Edge
93 |
94 | Wire.begin(0xDD); //Random address that is different from existing bus devices.
95 | TWBR = ((F_CPU / 72000) - 16) / 2; //Change I2C frequency closer to OG Xbox SMBus speed. ~72kHz Not compulsory really, but a safe bet
96 |
97 | analogWrite(backlightPin, DEFAULT_BACKLIGHT); //0-255 Higher number is brighter.
98 | analogWrite(contrastPin, DEFAULT_CONTRAST); //0-255 Lower number is higher contrast
99 |
100 | //Speed up PWM frequency. Gets rid of flickering
101 | TCCR1B &= 0b11111000;
102 | TCCR1B |= (1 << CS00); //Change Timer Prescaler for PWM
103 | hd44780.setCursor(0, 0);
104 |
105 | //delay(250);
106 | uint32_t spiReadyTimer = millis();
107 | bool spiReady = false;
108 |
109 | //Hold until spi bus is ready
110 | while (!spiReady) {
111 | if (digitalRead(sck) == 0) {
112 | spiReadyTimer = millis();
113 | }
114 | //SPI Clock high for 100ms
115 | else if (millis() - spiReadyTimer > 100) {
116 | spiReady = true;
117 | }
118 | }
119 | digitalWrite(ss_out, LOW); //SPI Slave is ready to receive data
120 |
121 | }
122 |
123 |
124 | void loop() {
125 | //SPI to Parallel Conversion State Machine
126 | //One completion of processing command, set the buffer data value to -1
127 | //to indicate processing has been completed.
128 |
129 |
130 | if (QueueRxPos != QueuePos) {
131 | switch (RxQueue[(uint8_t)QueuePos]) {
132 | case -1:
133 | //No action required.
134 | break;
135 |
136 | case XeniumCursorHome:
137 | cursorPosRow = 0;
138 | cursorPosCol = 0;
139 | hd44780.setCursor(cursorPosCol, cursorPosRow);
140 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
141 | break;
142 |
143 | case XeniumHideDisplay:
144 | hd44780.noDisplay();
145 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
146 | break;
147 |
148 | case XeniumShowDisplay:
149 | hd44780.display();
150 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
151 | break;
152 |
153 | case XeniumHideCursor:
154 | hd44780.noCursor();
155 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
156 | break;
157 |
158 | case XeniumShowUnderLineCursor:
159 | case XeniumShowBlockCursor:
160 | case XeniumShowInvertedCursor:
161 | hd44780.cursor();
162 | hd44780.blink();
163 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
164 | break;
165 |
166 | case XeniumBackspace:
167 | if (cursorPosCol > 0) {
168 | cursorPosCol--;
169 | hd44780.setCursor(cursorPosCol, cursorPosRow);
170 | hd44780.print(" ");
171 | hd44780.setCursor(cursorPosCol, cursorPosRow);
172 | }
173 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
174 | break;
175 |
176 | case XeniumLineFeed: //Move Cursor down one row, but keep column
177 | if (cursorPosRow < LCD_ROW - 1) {
178 | cursorPosRow++;
179 | hd44780.setCursor(cursorPosCol, cursorPosRow);
180 | }
181 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
182 | break;
183 |
184 | case XeniumDeleteInPlace: //Delete the character at the current cursor position
185 | hd44780.print(" ");
186 | hd44780.setCursor(cursorPosCol, cursorPosRow);
187 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
188 | break;
189 |
190 | case XeniumFormFeed: //Formfeed just clears the screen and resets the cursor.
191 | hd44780.clear();
192 | cursorPosRow = 0;
193 | cursorPosCol = 0;
194 | hd44780.setCursor(cursorPosCol, cursorPosRow);
195 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
196 | break;
197 |
198 | case XeniumCarriageReturn: //Carriage returns moves the cursor to the start of the current line
199 | cursorPosCol = 0;
200 | hd44780.setCursor(cursorPosCol, cursorPosRow);
201 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
202 | break;
203 |
204 | case XeniumSetCursorPosition: //Sets the row and column of cursor. The following two bytes are the row and column.
205 | if (RxQueue[(uint8_t)(QueuePos + 2)] != -1) {
206 | uint8_t col = RxQueue[(uint8_t)(QueuePos + 1)]; //Column
207 | uint8_t row = RxQueue[(uint8_t)(QueuePos + 2)]; //Row
208 | if (col < LCD_COL && row < LCD_ROW) {
209 | hd44780.setCursor(col, row);
210 | cursorPosCol = col, cursorPosRow = row;
211 | }
212 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
213 | completeCommand(&RxQueue[(uint8_t)(QueuePos + 1)]);
214 | completeCommand(&RxQueue[(uint8_t)(QueuePos + 2)]);
215 | }
216 | break;
217 |
218 | case XeniumSetBacklight:
219 | //The following byte after the backlight command is the brightness value
220 | //Value is 0-100 for the backlight brightness. 0=OFF, 100=ON
221 | //AVR PWM Output is 0-255. We multiply by 2.55 to match AVR PWM range.
222 | if (RxQueue[(uint8_t)(QueuePos + 1)] != -1) { //ensure the command is complete
223 | uint8_t brightness = RxQueue[(uint8_t)(QueuePos + 1)];
224 | if (brightness >= 0 && brightness <= 100) {
225 | analogWrite(backlightPin, (uint8_t)(brightness * 2.55f)); //0-255 for AVR PWM
226 | }
227 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
228 | completeCommand(&RxQueue[(uint8_t)(QueuePos + 1)]);
229 | }
230 | break;
231 |
232 | case XeniumSetContrast:
233 | //The following byte after the contrast command is the contrast value
234 | //Value is 0-100 0=Very Light, 100=Very Dark
235 | //AVR PWM Output is 0-255. We multiply by 2.55 to match AVR PWM range.
236 | if (RxQueue[(uint8_t)(QueuePos + 1)] != -1) { //ensure the command is complete
237 | uint8_t contrastValue = 100 - RxQueue[(uint8_t)(QueuePos + 1)]; //needs to convert to 100-0 instead of 0-100.
238 | if (contrastValue >= 0 && contrastValue <= 100) {
239 | analogWrite(contrastPin, (uint8_t)(contrastValue * 2.55f));
240 | }
241 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
242 | completeCommand(&RxQueue[(uint8_t)(QueuePos + 1)]);
243 | }
244 | break;
245 |
246 | case XeniumReboot:
247 | cursorPosRow = 0;
248 | cursorPosCol = 0;
249 | hd44780.begin(LCD_COL, LCD_ROW);
250 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
251 | break;
252 |
253 | case XeniumCursorMove:
254 | //The following 2 bytes after the initial command is the direction to move the cursor
255 | //offset+1 is always 27, offset+2 is 65,66,67,68 for Up,Down,Right,Left
256 | if (RxQueue[(uint8_t)(QueuePos + 1)] == 27 &&
257 | RxQueue[(uint8_t)(QueuePos + 2)] != -1) {
258 |
259 | switch (RxQueue[(uint8_t)(QueuePos + 2)]) {
260 | case 65: //UP
261 | if (cursorPosRow > 0) cursorPosRow--;
262 | break;
263 | case 66: //DOWN
264 | if (cursorPosRow < (LCD_ROW - 1) ) cursorPosRow++;
265 | break;
266 | case 67: //RIGHT
267 | if (cursorPosCol < (LCD_COL - 1)) cursorPosCol++;
268 | break;
269 | case 68: //LEFT
270 | if (cursorPosCol > 0) cursorPosCol--;
271 | break;
272 | default:
273 | //Error: Invalid cursor direction
274 | break;
275 | }
276 | hd44780.setCursor(cursorPosCol, cursorPosRow);
277 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
278 | completeCommand(&RxQueue[(uint8_t)(QueuePos + 1)]);
279 | completeCommand(&RxQueue[(uint8_t)(QueuePos + 2)]);
280 | }
281 | break;
282 |
283 | //Scrolling and wrapping commands are handled here.
284 | //The flags are toggled, but are not implemented properly yet
285 | //My testing seems to indicates it's not really needed.
286 | case XeniumWrapOff:
287 | wrapping = 0;
288 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
289 | break;
290 |
291 | case XeniumWrapOn:
292 | wrapping = 1;
293 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
294 | break;
295 |
296 | case XeniumScrollOff:
297 | scrolling = 0;
298 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
299 | break;
300 |
301 | case XeniumScrollOn:
302 | scrolling = 1;
303 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
304 | break;
305 |
306 | case 32 ... 255: //Just an ASCII character
307 | if (cursorPosCol < LCD_COL) {
308 | hd44780.setCursor(cursorPosCol, cursorPosRow);
309 | hd44780.write((char)RxQueue[(uint8_t)QueuePos]);
310 | cursorPosCol++;
311 | }
312 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
313 | break;
314 |
315 | //Not implemented. Dont seem to be used anyway.
316 | case XeniumLargeNumber:
317 | case XeniumDrawBarGraph:
318 | case XeniumModuleConfig:
319 | case XeniumCustomCharacter:
320 | default:
321 | //hd44780.setCursor(0, 0);
322 | //Serial.print("Not implemented ");
323 | //Serial.print(RxQueue[(uint8_t)QueuePos], DEC);
324 | //Serial.print("\r\n");
325 | //hd44780.setCursor(cursorPosCol, cursorPosRow);
326 | completeCommand(&RxQueue[(uint8_t)QueuePos]);
327 | break;
328 | }
329 |
330 | if (RxQueue[(uint8_t)QueuePos] == -1) {
331 | QueuePos = (uint8_t)(QueuePos + 1);
332 | }
333 |
334 | }
335 |
336 | /* State machine to monitor the SPI Bus idle state */
337 | /* State machine to monitor the SPI Bus idle state */
338 | //If SPI bus has been idle pulse the CS line to resync the bus.
339 | //Xenium SPI bus doesnt use a Chip select line to resync the bus so this is a bit hacky, but improved reliability
340 | if (SPIState == SPI_ACTIVE) {
341 | SPIState = SPI_IDLE;
342 | SPIIdleTimer = millis();
343 |
344 | } else if (SPIState == SPI_IDLE && (millis() - SPIIdleTimer) > 100) {
345 | SPIState = SPI_SYNC;
346 | digitalWrite(ss_out, HIGH);
347 | SPIIdleTimer = millis();
348 |
349 | } else if (SPIState == SPI_SYNC && (millis() - SPIIdleTimer) > 25) {
350 | digitalWrite(ss_out, LOW);
351 | SPIState = SPI_WAIT;
352 | }
353 |
354 |
355 | /* Read data from Xbox System Management Bus */
356 | //Check that i2cBus is free, it has been atleast 2 seconds since last call,
357 | //and the SPI Bus has been idle for >10 seconds (i.e in a game or app that doesnt support LCD)
358 | if (i2cBusy() == 0 &&
359 | (millis() - SMBusTimer) > 2000 &&
360 | (millis() - SPIIdleTimer) > 10000){
361 |
362 | char rxBuffer[20]; //Raw data received from SMBus
363 | char lineBuffer[LCD_COL]; //Fomatted data for printing to LCD
364 |
365 |
366 | //Read the current fan speed directly from the SMC and print to LCD
367 | if (readSMBus(SMC_ADDRESS, SMC_FANSPEED, &rxBuffer[0], 1) == 0) {
368 | if (rxBuffer[0] >= 0 && rxBuffer[0] <= 50) { //Sanity check. Number should be 0-50
369 | snprintf(lineBuffer, sizeof lineBuffer, "FAN: %3u%% ", rxBuffer[0] * 2);
370 | hd44780.setCursor(0, 2); //Write to 3rd row of hd44780. 0=Row 1, 2=Row 3
371 | hd44780.print(lineBuffer);
372 | }
373 | }
374 |
375 |
376 | //Read Focus Chip to determine video resolution (for Version 1.4 console only)
377 | if (readSMBus(FOCUS_ADDRESS, FOCUS_PID, &rxBuffer[0], 2) == 0) {
378 | uint16_t PID = ((uint16_t)rxBuffer[1]) << 8 | rxBuffer[0];
379 | if (PID == 0xFE05) {
380 | readSMBus(FOCUS_ADDRESS, FOCUS_VIDCNTL, &rxBuffer[0], 2);
381 | uint16_t VID_CNTL0 = ((uint16_t)rxBuffer[1]) << 8 | rxBuffer[0];
382 |
383 | if (VID_CNTL0 & FOCUS_VIDCNTL_VSYNC5_6 && VID_CNTL0 & FOCUS_VIDCNTL_INT_PROG) {
384 | //Must be HDTV, interlaced (1080i)
385 | hd44780.print(tenEightyI);
386 |
387 | } else if (VID_CNTL0 & FOCUS_VIDCNTL_VSYNC5_6 && !(VID_CNTL0 & FOCUS_VIDCNTL_INT_PROG)) {
388 | //Must be HDTV, Progressive 720p
389 | hd44780.print(sevenTwentyP);
390 |
391 | } else if (!(VID_CNTL0 & FOCUS_VIDCNTL_VSYNC5_6) && VID_CNTL0 & FOCUS_VIDCNTL_INT_PROG) {
392 | //Must be SDTV, interlaced 480i
393 | hd44780.print(fourEightyI);
394 |
395 | } else if (!(VID_CNTL0 & FOCUS_VIDCNTL_VSYNC5_6) && !(VID_CNTL0 & FOCUS_VIDCNTL_INT_PROG)) {
396 | //Must be SDTV, Progressive 480p
397 | hd44780.print(fourEightyP);
398 |
399 | } else {
400 | hd44780.print(VID_CNTL0, HEX); //Not sure what it is. Print the code.
401 | }
402 | }
403 |
404 | //Read Conexant Chip to determine video resolution (for Version 1.0 to 1.3 console only)
405 | } else if (readSMBus(CONEX_ADDRESS, CONEX_2E, &rxBuffer[0], 1) == 0) {
406 | if ((uint8_t)(rxBuffer[0] & 3) == 3) {
407 | //Must be 1080i
408 | hd44780.print(tenEightyI);
409 |
410 | } else if ((uint8_t)(rxBuffer[0] & 3) == 2) {
411 | //Must be 720p
412 | hd44780.print(sevenTwentyP);
413 |
414 | } else if ((uint8_t)(rxBuffer[0] & 3) == 1 && rxBuffer[0]&CONEX_2E_HDTV_EN) {
415 | //Must be 480p
416 | hd44780.print(fourEightyP);
417 |
418 | } else {
419 | hd44780.print(fourEightyI);
420 | }
421 |
422 | }
423 |
424 | //Read the CPU and M/B temps
425 | //Try ADM1032
426 | if ((readSMBus(ADM1032_ADDRESS, ADM1032_CPU, &rxBuffer[0], 1) == 0 &&
427 | readSMBus(ADM1032_ADDRESS, ADM1032_MB, &rxBuffer[1], 1) == 0) ||
428 | //If fails, its probably a 1.6. Read SMC instead.
429 | (readSMBus(SMC_ADDRESS, SMC_CPUTEMP, &rxBuffer[0], 1) == 0 &&
430 | readSMBus(SMC_ADDRESS, SMC_BOARDTEMP, &rxBuffer[1], 1) == 0)) {
431 | if (rxBuffer[0] < 200 && rxBuffer[1] < 200 && rxBuffer[0] > 0 && rxBuffer[1] > 0) {
432 | #ifdef USE_FAHRENHEIT
433 | snprintf(lineBuffer, sizeof lineBuffer, tempDisplayF, (uint8_t)((float)rxBuffer[0] * 1.8 + 32.0), (char)223,
434 | (uint8_t)((float)rxBuffer[1] * 1.8 + 32.0), (char)223);
435 | #else
436 | snprintf(lineBuffer, sizeof lineBuffer, tempDisplayC, rxBuffer[0], (char)223, rxBuffer[1], (char)223);
437 | #endif
438 | hd44780.setCursor(0, 3); //Write temperatures to LCD row 3
439 | hd44780.print(lineBuffer);
440 | }
441 | SMBusTimer = millis();
442 | }
443 |
444 | } else if (SPIState != SPI_WAIT) {
445 | SMBusTimer = millis();
446 |
447 | }
448 | }
449 |
450 | /*
451 | Function: Check if the SMBus/I2C bus is busy
452 | ----------------------------
453 | returns: 0 if busy is free, non zero if busy or still checking
454 | */
455 | uint8_t i2cBusy() {
456 | if (digitalRead(i2c_sda) == 0 || digitalRead(i2c_scl) == 0) { //If either the data or clock line is low, the line must be busy
457 | i2cCheckCount = I2C_BUSY_CHECKS;
458 | } else {
459 | i2cCheckCount--; //Bus isn't busy, decrease check counter so we check multiple times to be sure.
460 | }
461 | return i2cCheckCount;
462 | }
463 |
464 | /*
465 | Function: Read the Xbox SMBus
466 | ----------------------------
467 | address: The address of the device on the SMBus
468 | command: The command to send to the device. Normally the register to read from
469 | rx: A pointer to a receive data buffer
470 | len: How many bytes to read
471 | returns: 0 on success, -1 on error.
472 | */
473 | int8_t readSMBus(uint8_t address, uint8_t command, char* rx, uint8_t len) {
474 | Wire.beginTransmission(address);
475 | Wire.write(command);
476 | if (Wire.endTransmission(false) == 0) { //Needs to be false. Send I2c repeated start, dont release bus yet
477 | Wire.requestFrom(address, len);
478 | for (uint8_t i = 0; i < len; i++) {
479 | rx[i] = Wire.read();
480 | }
481 | return 0;
482 | } else {
483 | return -1;
484 | }
485 |
486 | }
487 |
488 | void completeCommand(int16_t* c) {
489 | *c = -1;
490 | }
491 |
--------------------------------------------------------------------------------
/src/SMWire/SMWire.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | TwoWire.cpp - TWI/I2C library for Wiring & Arduino
3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved.
4 |
5 | This library is free software; you can redistribute it and/or
6 | modify it under the terms of the GNU Lesser General Public
7 | License as published by the Free Software Foundation; either
8 | version 2.1 of the License, or (at your option) any later version.
9 |
10 | This library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public
16 | License along with this library; if not, write to the Free Software
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 |
19 | Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts
20 | Modified 2017 by Chuck Todd (ctodd@cableone.net) to correct Unconfigured Slave Mode reboot
21 | */
22 |
23 | extern "C" {
24 | #include
25 | #include
26 | #include
27 | #include "utility/twi.h"
28 | }
29 |
30 | #include "SMWire.h"
31 |
32 | // Initialize Class Variables //////////////////////////////////////////////////
33 |
34 | uint8_t TwoWire::rxBuffer[BUFFER_LENGTH];
35 | uint8_t TwoWire::rxBufferIndex = 0;
36 | uint8_t TwoWire::rxBufferLength = 0;
37 |
38 | uint8_t TwoWire::txAddress = 0;
39 | uint8_t TwoWire::txBuffer[BUFFER_LENGTH];
40 | uint8_t TwoWire::txBufferIndex = 0;
41 | uint8_t TwoWire::txBufferLength = 0;
42 |
43 | uint8_t TwoWire::transmitting = 0;
44 | void (*TwoWire::user_onRequest)(void);
45 | void (*TwoWire::user_onReceive)(int);
46 |
47 | // Constructors ////////////////////////////////////////////////////////////////
48 |
49 | TwoWire::TwoWire()
50 | {
51 | }
52 |
53 | // Public Methods //////////////////////////////////////////////////////////////
54 |
55 | void TwoWire::begin(void)
56 | {
57 | rxBufferIndex = 0;
58 | rxBufferLength = 0;
59 |
60 | txBufferIndex = 0;
61 | txBufferLength = 0;
62 |
63 | twi_init();
64 | twi_attachSlaveTxEvent(onRequestService); // default callback must exist
65 | twi_attachSlaveRxEvent(onReceiveService); // default callback must exist
66 | }
67 |
68 | void TwoWire::begin(uint8_t address)
69 | {
70 | begin();
71 | twi_setAddress(address);
72 | }
73 |
74 | void TwoWire::begin(int address)
75 | {
76 | begin((uint8_t)address);
77 | }
78 |
79 | void TwoWire::end(void)
80 | {
81 | twi_disable();
82 | }
83 |
84 | void TwoWire::setClock(uint32_t clock)
85 | {
86 | twi_setFrequency(clock);
87 | }
88 |
89 | uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint32_t iaddress, uint8_t isize, uint8_t sendStop)
90 | {
91 | if (isize > 0) {
92 | // send internal address; this mode allows sending a repeated start to access
93 | // some devices' internal registers. This function is executed by the hardware
94 | // TWI module on other processors (for example Due's TWI_IADR and TWI_MMR registers)
95 |
96 | beginTransmission(address);
97 |
98 | // the maximum size of internal address is 3 bytes
99 | if (isize > 3){
100 | isize = 3;
101 | }
102 |
103 | // write internal register address - most significant byte first
104 | while (isize-- > 0)
105 | write((uint8_t)(iaddress >> (isize*8)));
106 | endTransmission(false);
107 | }
108 |
109 | // clamp to buffer length
110 | if(quantity > BUFFER_LENGTH){
111 | quantity = BUFFER_LENGTH;
112 | }
113 | // perform blocking read into buffer
114 | uint8_t read = twi_readFrom(address, rxBuffer, quantity, sendStop);
115 | // set rx buffer iterator vars
116 | rxBufferIndex = 0;
117 | rxBufferLength = read;
118 |
119 | return read;
120 | }
121 |
122 | uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop) {
123 | return requestFrom((uint8_t)address, (uint8_t)quantity, (uint32_t)0, (uint8_t)0, (uint8_t)sendStop);
124 | }
125 |
126 | uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity)
127 | {
128 | return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)true);
129 | }
130 |
131 | uint8_t TwoWire::requestFrom(int address, int quantity)
132 | {
133 | return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)true);
134 | }
135 |
136 | uint8_t TwoWire::requestFrom(int address, int quantity, int sendStop)
137 | {
138 | return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)sendStop);
139 | }
140 |
141 | void TwoWire::beginTransmission(uint8_t address)
142 | {
143 | // indicate that we are transmitting
144 | transmitting = 1;
145 | // set address of targeted slave
146 | txAddress = address;
147 | // reset tx buffer iterator vars
148 | txBufferIndex = 0;
149 | txBufferLength = 0;
150 | }
151 |
152 | void TwoWire::beginTransmission(int address)
153 | {
154 | beginTransmission((uint8_t)address);
155 | }
156 |
157 | //
158 | // Originally, 'endTransmission' was an f(void) function.
159 | // It has been modified to take one parameter indicating
160 | // whether or not a STOP should be performed on the bus.
161 | // Calling endTransmission(false) allows a sketch to
162 | // perform a repeated start.
163 | //
164 | // WARNING: Nothing in the library keeps track of whether
165 | // the bus tenure has been properly ended with a STOP. It
166 | // is very possible to leave the bus in a hung state if
167 | // no call to endTransmission(true) is made. Some I2C
168 | // devices will behave oddly if they do not see a STOP.
169 | //
170 | uint8_t TwoWire::endTransmission(uint8_t sendStop)
171 | {
172 | // transmit buffer (blocking)
173 | uint8_t ret = twi_writeTo(txAddress, txBuffer, txBufferLength, 1, sendStop);
174 | // reset tx buffer iterator vars
175 | txBufferIndex = 0;
176 | txBufferLength = 0;
177 | // indicate that we are done transmitting
178 | transmitting = 0;
179 | return ret;
180 | }
181 |
182 | // This provides backwards compatibility with the original
183 | // definition, and expected behaviour, of endTransmission
184 | //
185 | uint8_t TwoWire::endTransmission(void)
186 | {
187 | return endTransmission(true);
188 | }
189 |
190 | // must be called in:
191 | // slave tx event callback
192 | // or after beginTransmission(address)
193 | size_t TwoWire::write(uint8_t data)
194 | {
195 | if(transmitting){
196 | // in master transmitter mode
197 | // don't bother if buffer is full
198 | if(txBufferLength >= BUFFER_LENGTH){
199 | setWriteError();
200 | return 0;
201 | }
202 | // put byte in tx buffer
203 | txBuffer[txBufferIndex] = data;
204 | ++txBufferIndex;
205 | // update amount in buffer
206 | txBufferLength = txBufferIndex;
207 | }else{
208 | // in slave send mode
209 | // reply to master
210 | twi_transmit(&data, 1);
211 | }
212 | return 1;
213 | }
214 |
215 | // must be called in:
216 | // slave tx event callback
217 | // or after beginTransmission(address)
218 | size_t TwoWire::write(const uint8_t *data, size_t quantity)
219 | {
220 | if(transmitting){
221 | // in master transmitter mode
222 | for(size_t i = 0; i < quantity; ++i){
223 | write(data[i]);
224 | }
225 | }else{
226 | // in slave send mode
227 | // reply to master
228 | twi_transmit(data, quantity);
229 | }
230 | return quantity;
231 | }
232 |
233 | // must be called in:
234 | // slave rx event callback
235 | // or after requestFrom(address, numBytes)
236 | int TwoWire::available(void)
237 | {
238 | return rxBufferLength - rxBufferIndex;
239 | }
240 |
241 | // must be called in:
242 | // slave rx event callback
243 | // or after requestFrom(address, numBytes)
244 | int TwoWire::read(void)
245 | {
246 | int value = -1;
247 |
248 | // get each successive byte on each call
249 | if(rxBufferIndex < rxBufferLength){
250 | value = rxBuffer[rxBufferIndex];
251 | ++rxBufferIndex;
252 | }
253 |
254 | return value;
255 | }
256 |
257 | // must be called in:
258 | // slave rx event callback
259 | // or after requestFrom(address, numBytes)
260 | int TwoWire::peek(void)
261 | {
262 | int value = -1;
263 |
264 | if(rxBufferIndex < rxBufferLength){
265 | value = rxBuffer[rxBufferIndex];
266 | }
267 |
268 | return value;
269 | }
270 |
271 | void TwoWire::flush(void)
272 | {
273 | // XXX: to be implemented.
274 | }
275 |
276 | // behind the scenes function that is called when data is received
277 | void TwoWire::onReceiveService(uint8_t* inBytes, int numBytes)
278 | {
279 | // don't bother if user hasn't registered a callback
280 | if(!user_onReceive){
281 | return;
282 | }
283 | // don't bother if rx buffer is in use by a master requestFrom() op
284 | // i know this drops data, but it allows for slight stupidity
285 | // meaning, they may not have read all the master requestFrom() data yet
286 | if(rxBufferIndex < rxBufferLength){
287 | return;
288 | }
289 | // copy twi rx buffer into local read buffer
290 | // this enables new reads to happen in parallel
291 | for(uint8_t i = 0; i < numBytes; ++i){
292 | rxBuffer[i] = inBytes[i];
293 | }
294 | // set rx iterator vars
295 | rxBufferIndex = 0;
296 | rxBufferLength = numBytes;
297 | // alert user program
298 | user_onReceive(numBytes);
299 | }
300 |
301 | // behind the scenes function that is called when data is requested
302 | void TwoWire::onRequestService(void)
303 | {
304 | // don't bother if user hasn't registered a callback
305 | if(!user_onRequest){
306 | return;
307 | }
308 | // reset tx buffer iterator vars
309 | // !!! this will kill any pending pre-master sendTo() activity
310 | txBufferIndex = 0;
311 | txBufferLength = 0;
312 | // alert user program
313 | user_onRequest();
314 | }
315 |
316 | // sets function called on slave write
317 | void TwoWire::onReceive( void (*function)(int) )
318 | {
319 | user_onReceive = function;
320 | }
321 |
322 | // sets function called on slave read
323 | void TwoWire::onRequest( void (*function)(void) )
324 | {
325 | user_onRequest = function;
326 | }
327 |
328 | // Preinstantiate Objects //////////////////////////////////////////////////////
329 |
330 | TwoWire Wire = TwoWire();
331 |
332 |
--------------------------------------------------------------------------------
/src/SMWire/SMWire.h:
--------------------------------------------------------------------------------
1 | /*
2 | TwoWire.h - TWI/I2C library for Arduino & Wiring
3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved.
4 |
5 | This library is free software; you can redistribute it and/or
6 | modify it under the terms of the GNU Lesser General Public
7 | License as published by the Free Software Foundation; either
8 | version 2.1 of the License, or (at your option) any later version.
9 |
10 | This library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public
16 | License along with this library; if not, write to the Free Software
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 |
19 | Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts
20 | */
21 |
22 | #ifndef TwoWire_h
23 | #define TwoWire_h
24 |
25 | #include
26 | #include "Stream.h"
27 |
28 | #define BUFFER_LENGTH 32
29 |
30 | // WIRE_HAS_END means Wire has end()
31 | #define WIRE_HAS_END 1
32 |
33 | class TwoWire : public Stream
34 | {
35 | private:
36 | static uint8_t rxBuffer[];
37 | static uint8_t rxBufferIndex;
38 | static uint8_t rxBufferLength;
39 |
40 | static uint8_t txAddress;
41 | static uint8_t txBuffer[];
42 | static uint8_t txBufferIndex;
43 | static uint8_t txBufferLength;
44 |
45 | static uint8_t transmitting;
46 | static void (*user_onRequest)(void);
47 | static void (*user_onReceive)(int);
48 | static void onRequestService(void);
49 | static void onReceiveService(uint8_t*, int);
50 | public:
51 | TwoWire();
52 | void begin();
53 | void begin(uint8_t);
54 | void begin(int);
55 | void end();
56 | void setClock(uint32_t);
57 | void beginTransmission(uint8_t);
58 | void beginTransmission(int);
59 | uint8_t endTransmission(void);
60 | uint8_t endTransmission(uint8_t);
61 | uint8_t requestFrom(uint8_t, uint8_t);
62 | uint8_t requestFrom(uint8_t, uint8_t, uint8_t);
63 | uint8_t requestFrom(uint8_t, uint8_t, uint32_t, uint8_t, uint8_t);
64 | uint8_t requestFrom(int, int);
65 | uint8_t requestFrom(int, int, int);
66 | virtual size_t write(uint8_t);
67 | virtual size_t write(const uint8_t *, size_t);
68 | virtual int available(void);
69 | virtual int read(void);
70 | virtual int peek(void);
71 | virtual void flush(void);
72 | void onReceive( void (*)(int) );
73 | void onRequest( void (*)(void) );
74 |
75 | inline size_t write(unsigned long n) { return write((uint8_t)n); }
76 | inline size_t write(long n) { return write((uint8_t)n); }
77 | inline size_t write(unsigned int n) { return write((uint8_t)n); }
78 | inline size_t write(int n) { return write((uint8_t)n); }
79 | using Print::write;
80 | };
81 |
82 | extern TwoWire Wire;
83 |
84 | #endif
85 |
86 |
--------------------------------------------------------------------------------
/src/SMWire/utility/twi.c:
--------------------------------------------------------------------------------
1 | /*
2 | twi.c - TWI/I2C library for Wiring & Arduino
3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved.
4 |
5 | This library is free software; you can redistribute it and/or
6 | modify it under the terms of the GNU Lesser General Public
7 | License as published by the Free Software Foundation; either
8 | version 2.1 of the License, or (at your option) any later version.
9 |
10 | This library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public
16 | License along with this library; if not, write to the Free Software
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 |
19 | Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts
20 | */
21 |
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include "Arduino.h" // for digitalWrite
29 |
30 | #ifndef cbi
31 | #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
32 | #endif
33 |
34 | #ifndef sbi
35 | #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
36 | #endif
37 |
38 |
39 | extern uint8_t I2C_BUSY_CHECKS; //Ryzee119
40 | extern uint8_t i2cCheckCount; //Ryzee119
41 |
42 | unsigned char gI2CCheckBusyAfterStop = 0; /* global */
43 |
44 | #include "pins_arduino.h"
45 | #include "twi.h"
46 |
47 | static volatile uint8_t twi_state;
48 | static volatile uint8_t twi_slarw;
49 | static volatile uint8_t twi_sendStop; // should the transaction end with a stop
50 | static volatile uint8_t twi_inRepStart; // in the middle of a repeated start
51 |
52 | static void (*twi_onSlaveTransmit)(void);
53 | static void (*twi_onSlaveReceive)(uint8_t*, int);
54 |
55 | static uint8_t twi_masterBuffer[TWI_BUFFER_LENGTH];
56 | static volatile uint8_t twi_masterBufferIndex;
57 | static volatile uint8_t twi_masterBufferLength;
58 |
59 | static uint8_t twi_txBuffer[TWI_BUFFER_LENGTH];
60 | static volatile uint8_t twi_txBufferIndex;
61 | static volatile uint8_t twi_txBufferLength;
62 |
63 | static uint8_t twi_rxBuffer[TWI_BUFFER_LENGTH];
64 | static volatile uint8_t twi_rxBufferIndex;
65 |
66 | static volatile uint8_t twi_error;
67 |
68 |
69 |
70 | //Ryzee119
71 | static volatile uint32_t twi_toutc;
72 | uint8_t twi_tout(uint8_t ini)
73 | {
74 | if (ini) twi_toutc=0; else twi_toutc++;
75 | if (twi_toutc>=10000UL) {
76 | twi_toutc=0;
77 | twi_init();
78 | return 1;
79 | }
80 | return 0;
81 | }
82 |
83 | /*
84 | * Function twi_init
85 | * Desc readys twi pins and sets twi bitrate
86 | * Input none
87 | * Output none
88 | */
89 | void twi_init(void)
90 | {
91 | // initialize state
92 | twi_state = TWI_READY;
93 | twi_sendStop = true; // default value
94 | twi_inRepStart = false;
95 |
96 | // activate internal pullups for twi.
97 | //digitalWrite(SDA, 1);
98 | //digitalWrite(SCL, 1);
99 |
100 | // initialize twi prescaler and bit rate
101 | cbi(TWSR, TWPS0);
102 | cbi(TWSR, TWPS1);
103 | TWBR = ((F_CPU / TWI_FREQ) - 16) / 2;
104 |
105 | /* twi bit rate formula from atmega128 manual pg 204
106 | SCL Frequency = CPU Clock Frequency / (16 + (2 * TWBR))
107 | note: TWBR should be 10 or higher for master mode
108 | It is 72 for a 16mhz Wiring board with 100kHz TWI */
109 |
110 | // enable twi module, acks, and twi interrupt
111 | TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA);
112 | }
113 |
114 | /*
115 | * Function twi_disable
116 | * Desc disables twi pins
117 | * Input none
118 | * Output none
119 | */
120 | void twi_disable(void)
121 | {
122 | // disable twi module, acks, and twi interrupt
123 | TWCR &= ~(_BV(TWEN) | _BV(TWIE) | _BV(TWEA));
124 |
125 | // deactivate internal pullups for twi.
126 | digitalWrite(SDA, 0);
127 | digitalWrite(SCL, 0);
128 | }
129 |
130 | /*
131 | * Function twi_slaveInit
132 | * Desc sets slave address and enables interrupt
133 | * Input none
134 | * Output none
135 | */
136 | void twi_setAddress(uint8_t address)
137 | {
138 | // set twi slave address (skip over TWGCE bit)
139 | TWAR = address << 1;
140 | }
141 |
142 | /*
143 | * Function twi_setClock
144 | * Desc sets twi bit rate
145 | * Input Clock Frequency
146 | * Output none
147 | */
148 | void twi_setFrequency(uint32_t frequency)
149 | {
150 | TWBR = ((F_CPU / frequency) - 16) / 2;
151 |
152 | /* twi bit rate formula from atmega128 manual pg 204
153 | SCL Frequency = CPU Clock Frequency / (16 + (2 * TWBR))
154 | note: TWBR should be 10 or higher for master mode
155 | It is 72 for a 16mhz Wiring board with 100kHz TWI */
156 | }
157 |
158 | /*
159 | * Function twi_readFrom
160 | * Desc attempts to become twi bus master and read a
161 | * series of bytes from a device on the bus
162 | * Input address: 7bit i2c device address
163 | * data: pointer to byte array
164 | * length: number of bytes to read into array
165 | * sendStop: Boolean indicating whether to send a stop at the end
166 | * Output number of bytes read
167 | */
168 | uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length, uint8_t sendStop)
169 | {
170 | uint8_t i;
171 |
172 | // ensure data will fit into buffer
173 | if(TWI_BUFFER_LENGTH < length){
174 | return 0;
175 | }
176 |
177 | // wait until twi is ready, become master receiver
178 | twi_tout(1);//Ini TimeOut
179 | while(TWI_READY != twi_state){
180 | if (twi_tout(0)) break;
181 | continue;
182 | }
183 | twi_state = TWI_MRX;
184 | twi_sendStop = sendStop;
185 | // reset error state (0xFF.. no error occured)
186 | twi_error = 0xFF;
187 |
188 | // initialize buffer iteration vars
189 | twi_masterBufferIndex = 0;
190 | twi_masterBufferLength = length-1; // This is not intuitive, read on...
191 | // On receive, the previously configured ACK/NACK setting is transmitted in
192 | // response to the received byte before the interrupt is signalled.
193 | // Therefor we must actually set NACK when the _next_ to last byte is
194 | // received, causing that NACK to be sent in response to receiving the last
195 | // expected byte of data.
196 |
197 | // build sla+w, slave device address + w bit
198 | twi_slarw = TW_READ;
199 | twi_slarw |= address << 1;
200 |
201 | if (true == twi_inRepStart) {
202 | // if we're in the repeated start state, then we've already sent the start,
203 | // (@@@ we hope), and the TWI statemachine is just waiting for the address byte.
204 | // We need to remove ourselves from the repeated start state before we enable interrupts,
205 | // since the ISR is ASYNC, and we could get confused if we hit the ISR before cleaning
206 | // up. Also, don't enable the START interrupt. There may be one pending from the
207 | // repeated start that we sent ourselves, and that would really confuse things.
208 | twi_inRepStart = false; // remember, we're dealing with an ASYNC ISR
209 | do {
210 | TWDR = twi_slarw;
211 | } while(TWCR & _BV(TWWC));
212 | TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE); // enable INTs, but not START
213 | }
214 | else
215 | // send start condition
216 | TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTA);
217 |
218 | // wait for read operation to complete
219 | twi_tout(1);//Ini TimeOut
220 | while(TWI_MRX == twi_state){
221 | if (twi_tout(0)) break;
222 | continue;
223 | }
224 |
225 | if (twi_masterBufferIndex < length)
226 | length = twi_masterBufferIndex;
227 |
228 | // copy twi buffer to data
229 | for(i = 0; i < length; ++i){
230 | data[i] = twi_masterBuffer[i];
231 | }
232 |
233 | return length;
234 | }
235 |
236 | /*
237 | * Function twi_writeTo
238 | * Desc attempts to become twi bus master and write a
239 | * series of bytes to a device on the bus
240 | * Input address: 7bit i2c device address
241 | * data: pointer to byte array
242 | * length: number of bytes in array
243 | * wait: boolean indicating to wait for write or not
244 | * sendStop: boolean indicating whether or not to send a stop at the end
245 | * Output 0 .. success
246 | * 1 .. length to long for buffer
247 | * 2 .. address send, NACK received
248 | * 3 .. data send, NACK received
249 | * 4 .. other twi error (lost bus arbitration, bus error, ..)
250 | */
251 | uint8_t twi_writeTo(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait, uint8_t sendStop)
252 | {
253 | uint8_t i;
254 |
255 | // ensure data will fit into buffer
256 | if(TWI_BUFFER_LENGTH < length){
257 | return 1;
258 | }
259 |
260 | // wait until twi is ready, become master transmitter
261 | twi_tout(1);
262 | while(TWI_READY != twi_state){
263 | if (twi_tout(0)) return 5;
264 | continue;
265 | }
266 | twi_state = TWI_MTX;
267 | twi_sendStop = sendStop;
268 | // reset error state (0xFF.. no error occured)
269 | twi_error = 0xFF;
270 |
271 | // initialize buffer iteration vars
272 | twi_masterBufferIndex = 0;
273 | twi_masterBufferLength = length;
274 |
275 | // copy data to twi buffer
276 | for(i = 0; i < length; ++i){
277 | twi_masterBuffer[i] = data[i];
278 | }
279 |
280 | // build sla+w, slave device address + w bit
281 | twi_slarw = TW_WRITE;
282 | twi_slarw |= address << 1;
283 |
284 | // if we're in a repeated start, then we've already sent the START
285 | // in the ISR. Don't do it again.
286 | //
287 | if (true == twi_inRepStart) {
288 | // if we're in the repeated start state, then we've already sent the start,
289 | // (@@@ we hope), and the TWI statemachine is just waiting for the address byte.
290 | // We need to remove ourselves from the repeated start state before we enable interrupts,
291 | // since the ISR is ASYNC, and we could get confused if we hit the ISR before cleaning
292 | // up. Also, don't enable the START interrupt. There may be one pending from the
293 | // repeated start that we sent outselves, and that would really confuse things.
294 | twi_inRepStart = false; // remember, we're dealing with an ASYNC ISR
295 | do {
296 | TWDR = twi_slarw;
297 | } while(TWCR & _BV(TWWC));
298 | TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE); // enable INTs, but not START
299 | }
300 | else
301 | // send start condition
302 | TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE) | _BV(TWSTA); // enable INTs
303 |
304 | // wait for write operation to complete
305 | twi_tout(1);
306 | while(wait && (TWI_MTX == twi_state)){
307 | if (twi_tout(0)) return 6;
308 | continue;
309 | }
310 |
311 | if (twi_error == 0xFF)
312 | return 0; // success
313 | else if (twi_error == TW_MT_SLA_NACK)
314 | return 2; // error: address send, nack received
315 | else if (twi_error == TW_MT_DATA_NACK)
316 | return 3; // error: data send, nack received
317 | else
318 | return 4; // other twi error
319 | }
320 |
321 | /*
322 | * Function twi_transmit
323 | * Desc fills slave tx buffer with data
324 | * must be called in slave tx event callback
325 | * Input data: pointer to byte array
326 | * length: number of bytes in array
327 | * Output 1 length too long for buffer
328 | * 2 not slave transmitter
329 | * 0 ok
330 | */
331 | uint8_t twi_transmit(const uint8_t* data, uint8_t length)
332 | {
333 | uint8_t i;
334 |
335 | // ensure data will fit into buffer
336 | if(TWI_BUFFER_LENGTH < (twi_txBufferLength+length)){
337 | return 1;
338 | }
339 |
340 | // ensure we are currently a slave transmitter
341 | if(TWI_STX != twi_state){
342 | return 2;
343 | }
344 |
345 | // set length and copy data into tx buffer
346 | for(i = 0; i < length; ++i){
347 | twi_txBuffer[twi_txBufferLength+i] = data[i];
348 | }
349 | twi_txBufferLength += length;
350 |
351 | return 0;
352 | }
353 |
354 | /*
355 | * Function twi_attachSlaveRxEvent
356 | * Desc sets function called before a slave read operation
357 | * Input function: callback function to use
358 | * Output none
359 | */
360 | void twi_attachSlaveRxEvent( void (*function)(uint8_t*, int) )
361 | {
362 | twi_onSlaveReceive = function;
363 | }
364 |
365 | /*
366 | * Function twi_attachSlaveTxEvent
367 | * Desc sets function called before a slave write operation
368 | * Input function: callback function to use
369 | * Output none
370 | */
371 | void twi_attachSlaveTxEvent( void (*function)(void) )
372 | {
373 | twi_onSlaveTransmit = function;
374 | }
375 |
376 | /*
377 | * Function twi_reply
378 | * Desc sends byte or readys receive line
379 | * Input ack: byte indicating to ack or to nack
380 | * Output none
381 | */
382 | void twi_reply(uint8_t ack)
383 | {
384 | // transmit master read ready signal, with or without ack
385 | if(ack){
386 | TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT) | _BV(TWEA);
387 | }else{
388 | TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT);
389 | }
390 | }
391 |
392 | /*
393 | * Function twi_stop
394 | * Desc relinquishes bus master status
395 | * Input none
396 | * Output none
397 | */
398 | void twi_stop(void)
399 | {
400 | // send stop condition
401 | TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTO);
402 |
403 | // wait for stop condition to be exectued on bus
404 | // TWINT is not set after a stop condition!
405 | twi_tout(1);
406 | while(TWCR & _BV(TWSTO)){
407 | if (twi_tout(0)) return;
408 | continue;
409 | }
410 |
411 | // update twi state
412 | twi_state = TWI_READY;
413 | }
414 |
415 | /*
416 | * Function twi_releaseBus
417 | * Desc releases bus control
418 | * Input none
419 | * Output none
420 | */
421 | void twi_releaseBus(void)
422 | {
423 | // release bus
424 | TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT);
425 |
426 | // update twi state
427 | twi_state = TWI_READY;
428 | }
429 |
430 | ISR(TWI_vect)
431 | {
432 | switch(TW_STATUS){
433 | // All Master
434 | case TW_START: // sent start condition
435 | case TW_REP_START: // sent repeated start condition
436 | // copy device address and r/w bit to output register and ack
437 | TWDR = twi_slarw;
438 | twi_reply(1);
439 | break;
440 |
441 | // Master Transmitter
442 | case TW_MT_SLA_ACK: // slave receiver acked address
443 | case TW_MT_DATA_ACK: // slave receiver acked data
444 | // if there is data to send, send it, otherwise stop
445 | if(twi_masterBufferIndex < twi_masterBufferLength){
446 | // copy data to output register and ack
447 | TWDR = twi_masterBuffer[twi_masterBufferIndex++];
448 | twi_reply(1);
449 | }else{
450 | if (twi_sendStop)
451 | twi_stop();
452 | else {
453 | twi_inRepStart = true; // we're gonna send the START
454 | // don't enable the interrupt. We'll generate the start, but we
455 | // avoid handling the interrupt until we're in the next transaction,
456 | // at the point where we would normally issue the start.
457 | TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;
458 | twi_state = TWI_READY;
459 | }
460 | }
461 | break;
462 | case TW_MT_SLA_NACK: // address sent, nack received
463 | twi_error = TW_MT_SLA_NACK;
464 | twi_stop();
465 | break;
466 | case TW_MT_DATA_NACK: // data sent, nack received
467 | twi_error = TW_MT_DATA_NACK;
468 | twi_stop();
469 | break;
470 | case TW_MT_ARB_LOST: // lost bus arbitration
471 | twi_error = TW_MT_ARB_LOST;
472 | twi_releaseBus();
473 | break;
474 |
475 | // Master Receiver
476 | case TW_MR_DATA_ACK: // data received, ack sent
477 | // put byte into buffer
478 | twi_masterBuffer[twi_masterBufferIndex++] = TWDR;
479 | case TW_MR_SLA_ACK: // address sent, ack received
480 | // ack if more bytes are expected, otherwise nack
481 | if(twi_masterBufferIndex < twi_masterBufferLength){
482 | twi_reply(1);
483 | }else{
484 | twi_reply(0);
485 | }
486 | break;
487 | case TW_MR_DATA_NACK: // data received, nack sent
488 | // put final byte into buffer
489 | twi_masterBuffer[twi_masterBufferIndex++] = TWDR;
490 | if (twi_sendStop)
491 | twi_stop();
492 | else {
493 | twi_inRepStart = true; // we're gonna send the START
494 | // don't enable the interrupt. We'll generate the start, but we
495 | // avoid handling the interrupt until we're in the next transaction,
496 | // at the point where we would normally issue the start.
497 | TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;
498 | twi_state = TWI_READY;
499 | }
500 | break;
501 | case TW_MR_SLA_NACK: // address sent, nack received
502 | twi_stop();
503 | break;
504 | // TW_MR_ARB_LOST handled by TW_MT_ARB_LOST case
505 |
506 | // Slave Receiver
507 | case TW_SR_SLA_ACK: // addressed, returned ack
508 | case TW_SR_GCALL_ACK: // addressed generally, returned ack
509 | case TW_SR_ARB_LOST_SLA_ACK: // lost arbitration, returned ack
510 | case TW_SR_ARB_LOST_GCALL_ACK: // lost arbitration, returned ack
511 | // enter slave receiver mode
512 | twi_state = TWI_SRX;
513 | // indicate that rx buffer can be overwritten and ack
514 | twi_rxBufferIndex = 0;
515 | twi_reply(1);
516 | break;
517 | case TW_SR_DATA_ACK: // data received, returned ack
518 | case TW_SR_GCALL_DATA_ACK: // data received generally, returned ack
519 | // if there is still room in the rx buffer
520 | if(twi_rxBufferIndex < TWI_BUFFER_LENGTH){
521 | // put byte in buffer and ack
522 | twi_rxBuffer[twi_rxBufferIndex++] = TWDR;
523 | twi_reply(1);
524 | }else{
525 | // otherwise nack
526 | twi_reply(0);
527 | }
528 | break;
529 | case TW_SR_STOP: // stop or repeated start condition received
530 | // ack future responses and leave slave receiver state
531 | twi_releaseBus();
532 | // put a null char after data if there's room
533 | if(twi_rxBufferIndex < TWI_BUFFER_LENGTH){
534 | twi_rxBuffer[twi_rxBufferIndex] = '\0';
535 | }
536 | // callback to user defined callback
537 | twi_onSlaveReceive(twi_rxBuffer, twi_rxBufferIndex);
538 | // since we submit rx buffer to "wire" library, we can reset it
539 | twi_rxBufferIndex = 0;
540 | i2cCheckCount = I2C_BUSY_CHECKS; //Ryzee119
541 | extern unsigned char ;
542 | break;
543 | case TW_SR_DATA_NACK: // data received, returned nack
544 | case TW_SR_GCALL_DATA_NACK: // data received generally, returned nack
545 | // nack back at master
546 | twi_reply(0);
547 | break;
548 |
549 | // Slave Transmitter
550 | case TW_ST_SLA_ACK: // addressed, returned ack
551 | case TW_ST_ARB_LOST_SLA_ACK: // arbitration lost, returned ack
552 | // enter slave transmitter mode
553 | twi_state = TWI_STX;
554 | // ready the tx buffer index for iteration
555 | twi_txBufferIndex = 0;
556 | // set tx buffer length to be zero, to verify if user changes it
557 | twi_txBufferLength = 0;
558 | // request for txBuffer to be filled and length to be set
559 | // note: user must call twi_transmit(bytes, length) to do this
560 | twi_onSlaveTransmit();
561 | // if they didn't change buffer & length, initialize it
562 | if(0 == twi_txBufferLength){
563 | twi_txBufferLength = 1;
564 | twi_txBuffer[0] = 0x00;
565 | }
566 | // transmit first byte from buffer, fall
567 | case TW_ST_DATA_ACK: // byte sent, ack returned
568 | // copy data to output register
569 | TWDR = twi_txBuffer[twi_txBufferIndex++];
570 | // if there is more to send, ack, otherwise nack
571 | if(twi_txBufferIndex < twi_txBufferLength){
572 | twi_reply(1);
573 | }else{
574 | twi_reply(0);
575 | }
576 | break;
577 | case TW_ST_DATA_NACK: // received nack, we are done
578 | case TW_ST_LAST_DATA: // received ack, but we are done already!
579 | // ack future responses
580 | twi_reply(1);
581 | // leave slave receiver state
582 | twi_state = TWI_READY;
583 | break;
584 |
585 | // All
586 | case TW_NO_INFO: // no state information
587 | break;
588 | case TW_BUS_ERROR: // bus error, illegal stop/start
589 | twi_error = TW_BUS_ERROR;
590 | twi_stop();
591 | break;
592 | }
593 | }
594 |
595 |
--------------------------------------------------------------------------------
/src/SMWire/utility/twi.h:
--------------------------------------------------------------------------------
1 | /*
2 | twi.h - TWI/I2C library for Wiring & Arduino
3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved.
4 |
5 | This library is free software; you can redistribute it and/or
6 | modify it under the terms of the GNU Lesser General Public
7 | License as published by the Free Software Foundation; either
8 | version 2.1 of the License, or (at your option) any later version.
9 |
10 | This library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public
16 | License along with this library; if not, write to the Free Software
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 | #ifndef twi_h
21 | #define twi_h
22 |
23 | #include
24 |
25 | //#define ATMEGA8
26 |
27 | #ifndef TWI_FREQ
28 | #define TWI_FREQ 100000L
29 | #endif
30 |
31 | #ifndef TWI_BUFFER_LENGTH
32 | #define TWI_BUFFER_LENGTH 32
33 | #endif
34 |
35 | #define TWI_READY 0
36 | #define TWI_MRX 1
37 | #define TWI_MTX 2
38 | #define TWI_SRX 3
39 | #define TWI_STX 4
40 |
41 | void twi_init(void);
42 | void twi_disable(void);
43 | void twi_setAddress(uint8_t);
44 | void twi_setFrequency(uint32_t);
45 | uint8_t twi_readFrom(uint8_t, uint8_t*, uint8_t, uint8_t);
46 | uint8_t twi_writeTo(uint8_t, uint8_t*, uint8_t, uint8_t, uint8_t);
47 | uint8_t twi_transmit(const uint8_t*, uint8_t);
48 | void twi_attachSlaveRxEvent( void (*)(uint8_t*, int) );
49 | void twi_attachSlaveTxEvent( void (*)(void) );
50 | void twi_reply(uint8_t);
51 | void twi_stop(void);
52 | void twi_releaseBus(void);
53 |
54 | #endif
55 |
56 |
--------------------------------------------------------------------------------
/xboxsmbus.h:
--------------------------------------------------------------------------------
1 | /*
2 | * XBMC LCD Settings
3 | * You can what the LCD prints in XBMC dashboard by editing /system/UserData/LCD.xml file
4 | * Check https://redmine.exotica.org.uk/projects/xbmc4xbox/repository/xbmc4xbox/entry/branches/3.5/xbmc/GUIInfoManager.cpp to see what options are available
5 | *
6 | */
7 |
8 |
9 | /*
10 | * XBOX System Management Controller
11 | * See https://web.archive.org/web/20100708015155/http://www.xbox-linux.org/wiki/PIC
12 | * Note 1: The PIC version can be read from register 0x01 as a 3-character ASCII string. Each time you read that register, the next of the 3 characters is returned.
13 | * "DBG" = DEBUGKIT Green
14 | * "B11" = "DEBUGKIT Green"
15 | * "P01" = "v1.0"
16 | * "P05" = "v1.1"
17 | * "P11" or "1P1" or "11P" = v1.2/v1.3 or v1.4. Need to read Video encoder. If FOCUS_ADDRESS returns valid = V1.4, else v1.2/1,3
18 | * "P2L" or "1P1" or "11P" = v1.6
19 | *
20 | * Note 2: 0x00 SCART
21 | 0x01 HDTV
22 | 0x02 VGA
23 | 0x03 RFU
24 | 0x04 S-Video
25 | 0x05 undefined
26 | 0x06 standard
27 | 0x07 missing/disconnected
28 | */
29 | #define SMC_ADDRESS 0x10
30 | #define SMC_VER 0x01 //PIC version string. Note 1.
31 | #define SMC_TRAY 0x03 //tray state (Tray open=16, Tray closed no disk=64, Tray closed with disk=96, 49=Opening, 97=Eject pressed?, 81=Closing)
32 | #define SMC_AVSTATE 0x04 //A/V Pack state Note 2.
33 | #define SMC_CPUTEMP 0x09 //CPU temperature (°C) //Read from ADM1032 for better update rate
34 | #define SMC_BOARDTEMP 0x0A //board temperature (°C) //Read from ADM1032 for better update rate
35 | #define SMC_FANSPEED 0x10 //current fan speed (0~50) multiply by 2 to get 0-100%
36 |
37 |
38 | /* XBOX ADM1032 System Temperature Monitor (Ref http://xboxdevwiki.net/SMBus)
39 | * https://www.onsemi.com/pub/Collateral/ADM1032-D.PDF
40 | */
41 | #define ADM1032_ADDRESS 0x4C
42 | #define ADM1032_MB 0x00 //°C
43 | #define ADM1032_CPU 0x01 //°C
44 |
45 |
46 | /* XBOX Conexant CX25871 Video Encoder. This chip was used in Xbox versions 1.0 through 1.3
47 | * https://pdf1.alldatasheet.com/datasheet-pdf/view/153349/CONEXANT/CX25871.html See Section 2.4 Reading Registers
48 | * Anything interesting to read from Conexant?
49 | */
50 | #define CONEX_ADDRESS 0x45
51 | #define CONEX_PID 0x00 //Returns 1 byte product ID. Bit 7-5=ID, Bit 4-0 = Version of chip read with readSMBus(CONEX_ADDRESS, CONEX_PID, &rxBuffer, 1)
52 | #define CONEX_A2 0xA2
53 | #define CONEX_A2_NI_OUT (1<<0) //Bit zero of address 0xA2. 0=interlaced, 1=progressive
54 | #define CONEX_2E 0x2E
55 | #define CONEX_2E_HDTV_EN (1<<7) //Bit 7 of address 0x2E. 1 = HDTV output mode enabled.
56 |
57 |
58 | /* XBOX Focus FS453 Video Encoder, This chip was used in Xbox Version 1.4
59 | * https://www.manualslib.com/manual/52885/Focus-Fs453.html
60 | * https://assemblergames.com/attachments/focus-datasheet-pdf-zip.17803/
61 | * Anything interesting to read from Focus chip? See second attachment "2.1 Register Reference Table
62 | * for address offsets
63 | */
64 | #define FOCUS_ADDRESS 0x6A
65 | #define FOCUS_PID 0x32 //Returns a 2 byte product ID. Low byte is first. Read with readSMBus(FOCUS_ADDRESS, FOCUS_PID, &rxBuffer, 2);
66 | /* This is the outputs from VID_CNTL0 register for each mode using component cable
67 | 480P 48 3e = 0100100000111110
68 | 480I 48 c5 = 0100100011000101
69 | 720P 58 2e = 0101100000101110
70 | 1080I 50 ae = 0101000010101110
71 | */
72 | #define FOCUS_VIDCNTL 0x92 //Video Control 0 register
73 | #define FOCUS_VIDCNTL_VSYNC5_6 (1<<12) //Selects HDTV composite vertical sync width parameter. 1=HDTV
74 | #define FOCUS_VIDCNTL_INT_PROG (1<<7) //Interlaced/Progressive. When set =1, input image is interlaced
75 |
76 | /*
77 | * XBOX XCALIBUR For Xbox 1.6. I dont know anything about it?
78 | */
79 | #define XCALIBUR_ADDRESS 0x70
80 |
81 |
82 | /* XBOX EEPROM
83 | * Could read anything stored in EEPROM, but doesnt seem like anything useful for a LCD screen
84 | * See https://web.archive.org/web/20081216023342/http://www.xbox-linux.org/wiki/Xbox_Serial_EEPROM for addresses
85 | * for different info
86 | */
87 | #define EEPROM_ADDRESS 0x54
88 | #define EEPROM_SERIAL 0x34 //Read 12 bytes starting at 0x34.
89 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/xeniumspi.h:
--------------------------------------------------------------------------------
1 | //Based on gathering a few commands using my logic analyser on the Xenium SPI bus, the commands seem to match a screen like this:
2 | //https://www.crystalfontz.com/products/document/3391/CFA634_Series_Data_Sheet_Release_2015-03-30.pdf
3 |
4 | //Xenium SPI Commands
5 | #define XeniumCursorHome 1
6 | #define XeniumHideDisplay 2
7 | #define XeniumShowDisplay 3
8 | #define XeniumHideCursor 4
9 | #define XeniumShowUnderLineCursor 5
10 | #define XeniumShowBlockCursor 6
11 | #define XeniumShowInvertedCursor 7
12 | #define XeniumBackspace 8
13 | #define XeniumModuleConfig 9
14 | #define XeniumLineFeed 10
15 | #define XeniumDeleteInPlace 11
16 | #define XeniumFormFeed 12 //Clears and resets cursor to home
17 | #define XeniumCarriageReturn 13
18 | #define XeniumSetBacklight 14
19 | #define XeniumSetContrast 15
20 | #define XeniumSetCursorPosition 17 ////The following 2 bytes after the set cursor command is column then row0x
21 | #define XeniumDrawBarGraph 18 //Followed up graph index, style, startcol, endcol, length, row
22 | #define XeniumScrollOn 19
23 | #define XeniumScrollOff 20
24 | #define XeniumWrapOn 23
25 | #define XeniumWrapOff 24
26 | #define XeniumCustomCharacter 25
27 | #define XeniumReboot 26
28 | #define XeniumCursorMove 27 //Followed by 91, then Up 65(0x41), Down 66 (0x42), Right 67 (0x43), Left 68 (0x44) for up,down,right,left
29 | #define XeniumLargeNumber 28
30 |
31 | //SPI State Machine
32 | #define SPI_ACTIVE 0
33 | #define SPI_IDLE 1
34 | #define SPI_SYNC 2
35 | #define SPI_WAIT 3
36 |
37 |
38 | byte chars[8][8] = {
39 | {0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Top 10 pixels 0x08
40 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f}, // Bottom 10 pixels 0x09
41 | {0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x1f}, // Normal L 0x0a
42 | {0x1f, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18}, // Top left corner L _ 0x0b
43 | {0x1f, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x1f}, // Forward C 0x0c
44 | {0x1f, 0x1f, 0x03, 0x03, 0x03, 0x03, 0x1f, 0x1f}, // Backward C 0x0d
45 | {0x1f, 0x1f, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}, // 7 0x0e
46 | {0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x1f, 0x1f}, // Backward L 0x0f
47 | };
48 |
--------------------------------------------------------------------------------