Compare commits
71 Commits
e6b952a2dc
...
136a1da5b3
Author | SHA1 | Date |
---|---|---|
Savanni D'Gerinel | 136a1da5b3 | |
Savanni D'Gerinel | 5c28706133 | |
Savanni D'Gerinel | ade8034b0b | |
Savanni D'Gerinel | a16cb1d54e | |
Savanni D'Gerinel | 6c9dbec322 | |
Savanni D'Gerinel | b15c5edb4d | |
Savanni D'Gerinel | 8d412df7e1 | |
Savanni D'Gerinel | a7af4accc0 | |
Savanni D'Gerinel | 196278a2fe | |
Savanni D'Gerinel | 3e68db14bb | |
Savanni D'Gerinel | 966ef20eca | |
Savanni D'Gerinel | 2acff8d3f5 | |
Savanni D'Gerinel | 7b4429db35 | |
Savanni D'Gerinel | 78cd1908a7 | |
Savanni D'Gerinel | 11436eeb28 | |
Savanni D'Gerinel | bdbb13f67f | |
Savanni D'Gerinel | 7e16faefae | |
Savanni D'Gerinel | 301496cf0e | |
Savanni D'Gerinel | dddf48651a | |
Savanni D'Gerinel | 4b5d5632b9 | |
Savanni D'Gerinel | e19bf772cb | |
Savanni D'Gerinel | cf21388bd8 | |
Savanni D'Gerinel | aefb2184bf | |
Savanni D'Gerinel | ca0847c73d | |
Savanni D'Gerinel | 307617b1b2 | |
Savanni D'Gerinel | 74a1f9f945 | |
Savanni D'Gerinel | fde5db66f7 | |
Savanni D'Gerinel | 4c02e99566 | |
Savanni D'Gerinel | 94efdbb1c3 | |
Savanni D'Gerinel | 4f778b79d3 | |
Savanni D'Gerinel | ef9b444b4d | |
Savanni D'Gerinel | 309475bcbc | |
Savanni D'Gerinel | e287957168 | |
Savanni D'Gerinel | c7b5541109 | |
Savanni D'Gerinel | ce2a2e98b5 | |
Savanni D'Gerinel | e03485b1e5 | |
Savanni D'Gerinel | 221dcd1541 | |
Savanni D'Gerinel | a81d8cec6b | |
Savanni D'Gerinel | c9e0775b4b | |
Savanni D'Gerinel | 762ba275b6 | |
Savanni D'Gerinel | c80db33d02 | |
Savanni D'Gerinel | 53651c161b | |
Savanni D'Gerinel | 6c02253868 | |
Savanni D'Gerinel | 6787d7484e | |
Savanni D'Gerinel | c34886bad5 | |
Savanni D'Gerinel | f76bcb18a2 | |
Savanni D'Gerinel | 7846fa175f | |
Savanni D'Gerinel | b8494551a4 | |
Savanni D'Gerinel | ff6a5b3d70 | |
Savanni D'Gerinel | 4843c547fe | |
Savanni D'Gerinel | 021fd23ab6 | |
Savanni D'Gerinel | 576ad4089e | |
Savanni D'Gerinel | 3ec18f464e | |
Savanni D'Gerinel | 02e0ab5ae0 | |
Savanni D'Gerinel | fffa9b3e89 | |
Savanni D'Gerinel | d86b6c596b | |
Savanni D'Gerinel | b6208b0e6d | |
Savanni D'Gerinel | 6c4055bd0a | |
Savanni D'Gerinel | 0d9ef55b44 | |
Savanni D'Gerinel | 9536b2c2b9 | |
Savanni D'Gerinel | 789f261a47 | |
Savanni D'Gerinel | 65caaa0a50 | |
Savanni D'Gerinel | 5ad6fb8412 | |
Savanni D'Gerinel | 8837ec4cd2 | |
Savanni D'Gerinel | 0e27f675dd | |
Savanni D'Gerinel | 3727225940 | |
Savanni D'Gerinel | a78f1ea129 | |
Savanni D'Gerinel | 1c9a329d7b | |
Savanni D'Gerinel | 059e4eb524 | |
Savanni D'Gerinel | 1f394f20ff | |
Savanni D'Gerinel | 565036547c |
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
@ -0,0 +1,2 @@
|
|||
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
#include "animation.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int bound(int value, uint8_t min, uint8_t max) {
|
||||
if (value > max) {
|
||||
return max;
|
||||
} else if (value < min) {
|
||||
return min;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
time_line_t time_line_new(int t0, int y0, int t1, int y1) {
|
||||
int dt = t1 - t0;
|
||||
int dy = y1 - y0;
|
||||
int de = 2 * dy;
|
||||
|
||||
int inc = dy > 0 ? 1 : dy == 0 ? 0 : -1;
|
||||
int error;
|
||||
|
||||
if (de > 0) {
|
||||
error = de - dt;
|
||||
} else {
|
||||
error = de + dt;
|
||||
}
|
||||
|
||||
return (time_line_t){ .y = y0, .dt = dt, .de = de, .error = error, .inc = inc, .dy = dy, .y0 = y0, .y1 = y1 };
|
||||
}
|
||||
|
||||
int time_line_next(time_line_t *self) {
|
||||
int error = self->error + self->de;
|
||||
|
||||
if (self->de > 0) {
|
||||
while (error >= 0) {
|
||||
self->y += self->inc;
|
||||
error -= 2 * self->dt;
|
||||
}
|
||||
} else {
|
||||
while (error < 0) {
|
||||
self->y += self->inc;
|
||||
error += 2 * self->dt;
|
||||
}
|
||||
}
|
||||
|
||||
if (self->y0 < self->y1) {
|
||||
self->y = bound(self->y, self->y0, self->y1);
|
||||
} else {
|
||||
self->y = bound(self->y, self->y1, self->y0);
|
||||
}
|
||||
|
||||
self->error = error;
|
||||
return self->y;
|
||||
}
|
||||
|
||||
/*
|
||||
time_line_t time_line_new(int t0, int y0, int t1, int y1) {
|
||||
int dt = t1 - t0;
|
||||
int dy = y1 - y0;
|
||||
int inc = dy > 0 ? 1 : dy == 0 ? 0 : -1;
|
||||
int m = 2 * dy;
|
||||
int error = 0;
|
||||
|
||||
if (m > 0) {
|
||||
error = m - dt;
|
||||
} else {
|
||||
error = m + dt;
|
||||
}
|
||||
|
||||
return (time_line_t){ .y = y0, .m = m, .error = error, .inc = inc, .dt = dt };
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
int time_line_next(time_line_t *slope) {
|
||||
slope->error += slope->m;
|
||||
|
||||
if (slope->m > 0) {
|
||||
if (slope->error >= 0) {
|
||||
slope->y += slope->inc;
|
||||
slope->error -= 2 * slope->dt;
|
||||
}
|
||||
} else {
|
||||
if (slope->error <= 0) {
|
||||
slope->y += slope->inc;
|
||||
slope->error += 2 * slope->dt;
|
||||
}
|
||||
}
|
||||
|
||||
return slope->y;
|
||||
}
|
||||
*/
|
||||
|
||||
void time_line_print(time_line_t *self) {
|
||||
printf("y: %d\tde: %d\terror: %d\tinc: %d\t:dt: %d\n", self->y, self->de, self->error, self->inc, self->dt);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef __ANIMATION_H__
|
||||
#define __ANIMATION_H__
|
||||
|
||||
// line_t provides a simplified implementation of Bresenham's line drawing
|
||||
// technique. At this time, it assumes a transition of x = 0 -> 60, and a dy
|
||||
// between -59 and 59. I am not sure I understand Bresenham's algorithm yet,
|
||||
// but I'll need to revisit all of this if I want to expand the boundaries.
|
||||
typedef struct {
|
||||
int y;
|
||||
int de;
|
||||
int error;
|
||||
int inc;
|
||||
int dt;
|
||||
int dy;
|
||||
int y0;
|
||||
int y1;
|
||||
} time_line_t;
|
||||
|
||||
// Construct a new line object. x1 must be greater than x0, and dy must be less than dx.
|
||||
time_line_t time_line_new(int, int, int, int);
|
||||
|
||||
// Calculate the next y value of the line.
|
||||
int time_line_next(time_line_t *);
|
||||
|
||||
// Diagnostic printout of the current state of line_t.
|
||||
void time_line_print(time_line_t *);
|
||||
|
||||
#endif
|
|
@ -1,19 +0,0 @@
|
|||
|
||||
#ifndef __BASE_H__
|
||||
#define __BASE_H__
|
||||
|
||||
typedef struct IO_PIN {
|
||||
volatile uint8_t *port;
|
||||
uint8_t pin;
|
||||
} io_pin_t;
|
||||
|
||||
inline void set_pin(io_pin_t *pin) {
|
||||
*(pin->port) |= 1 << pin->pin;
|
||||
}
|
||||
|
||||
inline void clear_pin(io_pin_t *pin) {
|
||||
*(pin->port) &= 0xff ^ (1 << pin->pin);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of Savanni's AVR library.
|
||||
|
||||
This AVR library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
This AVR library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with this AVR library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __BASE_H__
|
||||
#define __BASE_H__
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <stdbool.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
#define LINE_OUT 1
|
||||
#define LINE_IN 0
|
||||
|
||||
typedef struct DIO {
|
||||
volatile uint8_t *ddr;
|
||||
volatile uint8_t *port;
|
||||
volatile uint8_t *pin;
|
||||
uint8_t addr;
|
||||
} dio_t;
|
||||
|
||||
/*
|
||||
#define DIO(addr) (dio_t){ .ddr = &DDRA, .port = &PORTA, .addr = addr }
|
||||
#define DIO(addr) (dio_t){ .ddr = &DDRB, .port = &PORTB, .addr = addr }
|
||||
#define DIO(addr) (dio_t){ .ddr = &DDRC, .port = &PORTC, .addr = addr }
|
||||
#define DIO(addr) (dio_t){ .ddr = &DDRD, .port = &PORTD, .addr = addr }
|
||||
*/
|
||||
|
||||
inline void dio_set_direction(dio_t *line, int direction) {
|
||||
if (direction == LINE_OUT) {
|
||||
*(line->ddr) |= _BV(line->addr);
|
||||
} else {
|
||||
*(line->ddr) &= ~(_BV(line->addr));
|
||||
}
|
||||
}
|
||||
|
||||
inline void dio_set(dio_t *line, bool value) {
|
||||
if (value) {
|
||||
*(line->port) |= _BV(line->addr);
|
||||
}
|
||||
else {
|
||||
*(line->port) &= ~(_BV(line->addr));
|
||||
}
|
||||
}
|
||||
|
||||
inline uint8_t dio_read(dio_t *line) {
|
||||
return (*(line->pin) & _BV(line->addr)) > 0;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of Savanni's AVR library.
|
||||
|
||||
This AVR library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
This AVR library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with this AVR library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <dio.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
#include "display.h"
|
||||
|
||||
#define ENABLE _BV(5)
|
||||
#define CHARCODE _BV(4)
|
||||
|
||||
void ping(dio_t *light) {
|
||||
dio_set(light, 1);
|
||||
_delay_ms(100);
|
||||
dio_set(light, 0);
|
||||
_delay_ms(100);
|
||||
}
|
||||
|
||||
|
||||
void send_half_code(display_t *disp, uint8_t reg, uint8_t data) {
|
||||
sr_send_msb(&disp->reg, (reg ? CHARCODE : 0) | data << 2);
|
||||
_delay_us(1);
|
||||
sr_send_msb(&disp->reg, (ENABLE | (reg ? CHARCODE : 0) | data) << 2);
|
||||
_delay_us(1);
|
||||
sr_send_msb(&disp->reg, ((reg ? CHARCODE : 0) | data) << 2);
|
||||
_delay_us(1);
|
||||
}
|
||||
|
||||
|
||||
void send_code(display_t *disp, uint8_t reg, uint8_t data) {
|
||||
send_half_code(disp, reg, data >> 4);
|
||||
send_half_code(disp, reg, data & 0xf);
|
||||
}
|
||||
|
||||
void write_instruction(display_t *disp, uint8_t bitcode) {
|
||||
send_code(disp, 0, bitcode);
|
||||
}
|
||||
|
||||
void write_char(display_t *disp, uint8_t bitcode) {
|
||||
send_code(disp, 1, bitcode);
|
||||
_delay_us(100);
|
||||
}
|
||||
|
||||
void display_init(display_t *disp) {
|
||||
sr_initialize(&disp->reg);
|
||||
|
||||
/* Initializing for 4-bit channel */
|
||||
send_half_code(disp, 0, 0b0011);
|
||||
_delay_ms(5);
|
||||
send_half_code(disp, 0, 0b0011);
|
||||
_delay_us(150);
|
||||
send_half_code(disp, 0, 0b0011);
|
||||
_delay_us(100);
|
||||
send_half_code(disp, 0, 0b0010);
|
||||
_delay_us(100);
|
||||
|
||||
/* Function set, 4-bit channel, two lines, 5x10 dots */
|
||||
write_instruction(disp, 0b00101000);
|
||||
_delay_us(100);
|
||||
|
||||
/* display off */
|
||||
write_instruction(disp, 0b00001000);
|
||||
_delay_us(100);
|
||||
|
||||
/* display clear */
|
||||
write_instruction(disp, 0b00000001);
|
||||
_delay_ms(3);
|
||||
|
||||
/* set entry mode */
|
||||
write_instruction(disp, 0b00000110);
|
||||
_delay_us(100);
|
||||
|
||||
/* display on */
|
||||
write_instruction(disp, 0b00001100);
|
||||
_delay_us(100);
|
||||
}
|
||||
|
||||
void display_clear(display_t *disp) {
|
||||
write_instruction(disp, 0b00000001);
|
||||
_delay_us(100);
|
||||
write_instruction(disp, 0b00000010);
|
||||
_delay_us(100);
|
||||
|
||||
}
|
||||
|
||||
void display_enable(display_t *disp) {
|
||||
write_instruction(disp, _BV(5));
|
||||
_delay_us(100);
|
||||
write_instruction(disp, _BV(5) | _BV(3));
|
||||
_delay_us(100);
|
||||
}
|
||||
|
||||
void display_set_location(display_t *disp, size_t row, size_t column) {
|
||||
size_t addr = row * 40 + column;
|
||||
write_instruction(disp, 0b10000000 | addr);
|
||||
_delay_us(100);
|
||||
}
|
||||
|
||||
void display_write_message(display_t *disp, const char *msg) {
|
||||
for (size_t i = 0; msg[i] != 0; i++) {
|
||||
write_char(disp, msg[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void display_write_bit_pattern(display_t *disp, const uint8_t pattern) {
|
||||
char msg[16];
|
||||
sprintf(msg, "* ");
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
if (pattern & _BV(i)) {
|
||||
display_write_message(disp, "1");
|
||||
} else {
|
||||
display_write_message(disp, "0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of Savanni's AVR library.
|
||||
|
||||
This AVR library is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
Lumeto is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* This library covers a three-wire diagnostic display board.
|
||||
*
|
||||
* Hardware:
|
||||
* 74HC595 shift register
|
||||
* Adafruit HD44780 LCD
|
||||
*
|
||||
* Input pins:
|
||||
* SDI -- Serial data in. This leads to the 74HC595, pin 14 (A).
|
||||
* CLK -- Clock pulse. One bit will be shifted into the device on each rising
|
||||
* edge. This leads to the 74HC595, pin 11 (Shift Clock).
|
||||
* LS -- Latch pulse. All data in the shift register will be sent to the
|
||||
* output on a rising edge. This leads to the 74HC595, pin 12 (Latch Clock);
|
||||
*
|
||||
* 74HC595 -> HD44780
|
||||
* Qc -> D4
|
||||
* Qd -> D5
|
||||
* Qe -> D6
|
||||
* Qf -> D7
|
||||
* Qg -> RS
|
||||
* Qh -> E
|
||||
*
|
||||
* I use the 4-wire protocol of the HD44780. This means that two of the shift
|
||||
* register pins are used for the RS and E control pins of the LCD.
|
||||
*/
|
||||
|
||||
#ifndef __DISPLAY_H__
|
||||
#define __DISPLAY_H__
|
||||
|
||||
#include <shift_register.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct DISPLAY {
|
||||
shift_register_t reg;
|
||||
/*
|
||||
gpio_t register_select;
|
||||
gpio_t enable;
|
||||
*/
|
||||
} display_t;
|
||||
|
||||
void display_init(display_t *);
|
||||
|
||||
void display_clear(display_t *);
|
||||
|
||||
void display_enable(display_t *);
|
||||
|
||||
void display_set_location(display_t *, size_t, size_t);
|
||||
|
||||
void display_write_message(display_t *, const char *);
|
||||
|
||||
void display_write_bit_pattern(display_t *, const uint8_t);
|
||||
|
||||
#endif
|
||||
|
|
@ -2,11 +2,11 @@
|
|||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1649944829,
|
||||
"narHash": "sha256-wjOgLfjCdyoRamMOrVJceeDJk4LvJsQOxBoT3k16/7Q=",
|
||||
"lastModified": 1659446231,
|
||||
"narHash": "sha256-hekabNdTdgR/iLsgce5TGWmfIDZ86qjPhxDg/8TlzhE=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "2f06b87f64bc06229e05045853e0876666e1b023",
|
||||
"rev": "eabc38219184cc3e04a974fe31857d8e0eac098d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
330
flake.nix
330
flake.nix
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
description = "Wearables";
|
||||
description = "AVR";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "nixpkgs/nixos-21.11";
|
||||
|
@ -9,44 +9,301 @@
|
|||
let
|
||||
version = builtins.string 0 8 self.lastModifiedDate;
|
||||
supportedSystems = [ "x86_64-linux" "avr-none" ];
|
||||
in
|
||||
mcu_cflags = { mcu, chip_select, f_cpu }: ''-O -finline-functions -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Werror -Wstrict-prototypes -DF_CPU=${f_cpu} -std=gnu99 -D__${chip_select}__=1 -mmcu=${mcu}'';
|
||||
|
||||
attiny85 = { mcu = "attiny85"; chip_select = "AVR_ATtiny85"; f_cpu = "8000000"; };
|
||||
atmega32u4 = { mcu = "atmega32u4"; chip_select = "AVR_ATmega32u4"; f_cpu = "8000000"; };
|
||||
|
||||
mkLibrary = { pkgs, gcc, cflags, pname, psrc, pbuildInputs ? [] }:
|
||||
pkgs.stdenv.mkDerivation rec {
|
||||
name = pname;
|
||||
src = psrc;
|
||||
|
||||
buildInputs = pbuildInputs;
|
||||
|
||||
include_dirs = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}/include") buildInputs);
|
||||
object_files = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs);
|
||||
|
||||
dontUnpack = true;
|
||||
dontConfigure = true;
|
||||
|
||||
buildPhase = ''
|
||||
for source in ${src}/*.c; do
|
||||
if [ -e $source ]; then
|
||||
${gcc} ${cflags} ${include_dirs} -c $source
|
||||
fi
|
||||
done
|
||||
cp ${src}/*.h . || true
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/include $out/lib
|
||||
cp *.h $out/include || true
|
||||
cp *.o $out/lib || true
|
||||
'';
|
||||
};
|
||||
|
||||
mkProgram = { pkgs, gcc, cflags, pname, psrc, pbuildInputs ? [], avr ? false }:
|
||||
let
|
||||
AVR = if avr == true then "1" else "";
|
||||
in pkgs.stdenv.mkDerivation rec {
|
||||
name = pname;
|
||||
src = psrc;
|
||||
|
||||
buildInputs = pbuildInputs;
|
||||
|
||||
include_dirs = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}/include") buildInputs);
|
||||
object_files = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/lib/*.o") buildInputs);
|
||||
|
||||
dontUnpack = true;
|
||||
dontConfigure = true;
|
||||
|
||||
buildPhase = ''
|
||||
for source in ${src}/*.c; do
|
||||
if [ -e $source ]; then
|
||||
${gcc} ${cflags} ${include_dirs} -c $source
|
||||
fi
|
||||
done
|
||||
|
||||
${gcc} -o ${name}.elf ${cflags} ${object_files} *.o
|
||||
if $AVR; then
|
||||
$OBJCOPY -O ihex ${name}.elf ${name}.hex
|
||||
fi
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp ${name}.elf ${name}.hex $out/bin
|
||||
'';
|
||||
};
|
||||
|
||||
in rec
|
||||
{
|
||||
/*
|
||||
packages.base."x86_64-linux" =
|
||||
let pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
in pkgs.stdenv.mkDerivation rec {
|
||||
name = "wearables-base";
|
||||
src = "./base";
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/include
|
||||
cp include/base.h $out/include
|
||||
'';
|
||||
};
|
||||
*/
|
||||
|
||||
defaultPackage."x86_64-linux" =
|
||||
defaultPackage."x86_64-linux" =
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
avr = pkgs.pkgsCross.avr.buildPackages;
|
||||
in pkgs.stdenv.mkDerivation rec {
|
||||
name = "hello";
|
||||
src = ./.;
|
||||
in pkgs.symlinkJoin {
|
||||
name = "avr-monorepo";
|
||||
paths = [
|
||||
(packages."x86_64-linux"."prime-tx" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags atmega32u4; })
|
||||
(packages."x86_64-linux"."radio-rx" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags atmega32u4; })
|
||||
(packages."x86_64-linux"."lantern" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags atmega32u4; avr = true; })
|
||||
(packages."x86_64-linux"."lantern-controller" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags atmega32u4; avr = true; })
|
||||
];
|
||||
};
|
||||
|
||||
MCU = "attiny85";
|
||||
CHIP_SELECT = "AVR_ATtiny85";
|
||||
F_CPU = "8000000";
|
||||
CFLAGS = ''-O -finline-functions -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -DF_CPU=${F_CPU} -std=gnu99 -D__${CHIP_SELECT}__=1 -mmcu=${MCU}'';
|
||||
packages."x86_64-linux"."dio" =
|
||||
{ gcc, cflags }:
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
in mkLibrary {
|
||||
pkgs = pkgs;
|
||||
gcc = gcc;
|
||||
cflags = cflags;
|
||||
pname = "dio";
|
||||
psrc = ./dio;
|
||||
};
|
||||
|
||||
buildPhase = ''
|
||||
set -x
|
||||
${avr.gcc}/bin/avr-gcc ${CFLAGS} -I${src}/base/include/ -o main.elf ${src}/prototype/src/main.c
|
||||
$OBJCOPY -O ihex main.elf main.hex
|
||||
'';
|
||||
installPhase = ''
|
||||
mkdir $out
|
||||
cp main.elf main.hex $out
|
||||
'';
|
||||
packages."x86_64-linux"."animation" =
|
||||
{ gcc, cflags }:
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
in mkLibrary {
|
||||
pkgs = pkgs;
|
||||
gcc = gcc;
|
||||
cflags = cflags;
|
||||
pname = "animation";
|
||||
psrc = ./animation;
|
||||
};
|
||||
|
||||
packages."x86_64-linux"."sk9822" =
|
||||
{ gcc, cflags }:
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
in mkLibrary {
|
||||
pkgs = pkgs;
|
||||
gcc = gcc;
|
||||
cflags = cflags;
|
||||
pname = "sk9822";
|
||||
psrc = ./sk9822;
|
||||
pbuildInputs = [
|
||||
(packages."x86_64-linux"."dio" { inherit gcc cflags; })
|
||||
];
|
||||
};
|
||||
|
||||
packages."x86_64-linux"."shift-register" =
|
||||
{ gcc, cflags }:
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
in mkLibrary {
|
||||
pkgs = pkgs;
|
||||
gcc = gcc;
|
||||
cflags = cflags;
|
||||
pname = "shift-register";
|
||||
psrc = ./shift-register;
|
||||
pbuildInputs = [
|
||||
(packages."x86_64-linux"."dio" { inherit gcc cflags; })
|
||||
];
|
||||
};
|
||||
|
||||
packages."x86_64-linux"."spi" =
|
||||
{ gcc, cflags }:
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
in mkLibrary {
|
||||
pkgs = pkgs;
|
||||
gcc = gcc;
|
||||
cflags = cflags;
|
||||
pname = "spi";
|
||||
psrc = ./spi;
|
||||
pbuildInputs = [
|
||||
(packages."x86_64-linux"."dio" { inherit gcc cflags; })
|
||||
];
|
||||
};
|
||||
|
||||
packages."x86_64-linux"."rfm" =
|
||||
{ gcc, cflags }:
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
in mkLibrary {
|
||||
pkgs = pkgs;
|
||||
gcc = gcc;
|
||||
cflags = cflags;
|
||||
pname = "rfm";
|
||||
psrc = ./rfm69hcw;
|
||||
pbuildInputs = [
|
||||
(packages."x86_64-linux"."dio" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."spi" { inherit gcc cflags; })
|
||||
];
|
||||
};
|
||||
|
||||
packages."x86_64-linux"."display" =
|
||||
{ gcc, cflags }:
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
in mkLibrary {
|
||||
pkgs = pkgs;
|
||||
gcc = gcc;
|
||||
cflags = cflags;
|
||||
pname = "display";
|
||||
psrc = ./display;
|
||||
pbuildInputs = [
|
||||
(packages."x86_64-linux"."dio" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."shift-register" { inherit gcc cflags; })
|
||||
];
|
||||
};
|
||||
|
||||
packages."x86_64-linux"."prime-tx" =
|
||||
{ gcc, cflags }:
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
in mkProgram {
|
||||
pkgs = pkgs;
|
||||
gcc = gcc;
|
||||
cflags = cflags;
|
||||
pname = "prime-tx";
|
||||
psrc = ./prime-tx;
|
||||
pbuildInputs = [
|
||||
(packages."x86_64-linux"."dio" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."spi" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."shift-register" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."rfm" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."display" { inherit gcc cflags; })
|
||||
];
|
||||
};
|
||||
|
||||
packages."x86_64-linux"."radio-rx" =
|
||||
{ gcc, cflags }:
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
in mkProgram {
|
||||
pkgs = pkgs;
|
||||
gcc = gcc;
|
||||
cflags = cflags;
|
||||
pname = "radio-rx";
|
||||
psrc = ./radio-rx;
|
||||
pbuildInputs = [
|
||||
(packages."x86_64-linux"."dio" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."spi" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."shift-register" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."rfm" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."display" { inherit gcc cflags; })
|
||||
];
|
||||
};
|
||||
|
||||
packages."x86_64-linux"."lantern_" =
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
avr = pkgs.pkgsCross.avr.buildPackages;
|
||||
in packages."x86_64-linux"."lantern" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags atmega32u4; };
|
||||
packages."x86_64-linux"."lantern" =
|
||||
{ gcc, cflags, avr }:
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
in mkProgram {
|
||||
pkgs = pkgs;
|
||||
gcc = gcc;
|
||||
cflags = cflags;
|
||||
pname = "lantern";
|
||||
psrc = ./lantern;
|
||||
inherit avr;
|
||||
|
||||
pbuildInputs = [
|
||||
(packages."x86_64-linux"."animation" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."dio" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."display" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."rfm" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."shift-register" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."sk9822" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."spi" { inherit gcc cflags; })
|
||||
];
|
||||
};
|
||||
|
||||
packages."x86_64-linux"."lantern-controller_" =
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
avr = pkgs.pkgsCross.avr.buildPackages;
|
||||
in packages."x86_64-linux"."lantern-controller" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags atmega32u4; avr = true; };
|
||||
packages."x86_64-linux"."lantern-controller" =
|
||||
{ gcc, cflags, avr }:
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
in mkProgram {
|
||||
pkgs = pkgs;
|
||||
gcc = gcc;
|
||||
cflags = cflags;
|
||||
pname = "lantern-controller";
|
||||
psrc = ./lantern-controller;
|
||||
inherit avr;
|
||||
|
||||
pbuildInputs = [
|
||||
(packages."x86_64-linux"."dio" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."spi" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."rfm" { inherit gcc cflags; })
|
||||
];
|
||||
};
|
||||
|
||||
packages."x86_64-linux"."ws2812_" =
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
avr = pkgs.pkgsCross.avr.buildPackages;
|
||||
in packages."x86_64-linux"."ws2812" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags attiny85; avr = true; };
|
||||
packages."x86_64-linux"."ws2812" =
|
||||
{ gcc, cflags, avr }:
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
in mkProgram {
|
||||
pkgs = pkgs;
|
||||
gcc = gcc;
|
||||
cflags = cflags;
|
||||
pname = "ws2812";
|
||||
psrc = ./ws2812;
|
||||
inherit avr;
|
||||
|
||||
pbuildInputs = [
|
||||
(packages."x86_64-linux"."dio" { inherit gcc cflags; })
|
||||
];
|
||||
};
|
||||
|
||||
devShell."x86_64-linux" =
|
||||
|
@ -55,12 +312,17 @@
|
|||
avr = with pkgs.pkgsCross.avr.buildPackages; [
|
||||
binutils
|
||||
gcc
|
||||
gdb
|
||||
avrdude
|
||||
simavr
|
||||
gtkwave
|
||||
];
|
||||
in
|
||||
pkgs.mkShell {
|
||||
name = "Wearables-shell";
|
||||
buildInputs = avr;
|
||||
buildInputs = avr ++ [ pkgs.gnumake ];
|
||||
GCC = pkgs.pkgsCross.avr.buildPackages.gcc;
|
||||
SIMAVR = pkgs.pkgsCross.avr.buildPackages.simavr;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
#include <dio.h>
|
||||
#include <sk9822.h>
|
||||
#include <rng.h>
|
||||
#include <animation.h>
|
||||
|
||||
#define FPS 60
|
||||
#define FRAME_DELAY_MS 1000 / FPS
|
||||
|
||||
uint8_t random_step(uint8_t value, uint8_t min, uint8_t max, rng_t *rng) {
|
||||
int8_t step = (rng_sample(rng) % 20) - 10;
|
||||
int new_value = value + step;
|
||||
if (new_value > max) {
|
||||
return max;
|
||||
} else if (new_value < min) {
|
||||
return min;
|
||||
} else {
|
||||
return new_value;
|
||||
}
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
normal,
|
||||
creepy,
|
||||
} color_scheme_e;
|
||||
|
||||
typedef struct {
|
||||
rgb_t lamp;
|
||||
color_scheme_e color_scheme;
|
||||
|
||||
time_line_t red_line;
|
||||
time_line_t green_line;
|
||||
time_line_t blue_line;
|
||||
|
||||
uint8_t frame;
|
||||
uint8_t duration;
|
||||
} animation_t;
|
||||
|
||||
animation_t animation_new(void) {
|
||||
return (animation_t){
|
||||
.lamp = (rgb_t){ .brightness = 1, .r = 200, .g = 30, .b = 0 },
|
||||
.color_scheme = normal,
|
||||
.red_line = time_line_new(0, 0, 0, 0),
|
||||
.green_line = time_line_new(0, 0, 0, 0),
|
||||
.blue_line = time_line_new(0, 0, 0, 0),
|
||||
|
||||
.frame = 0,
|
||||
.duration = 0,
|
||||
};
|
||||
}
|
||||
|
||||
void animation_flicker(animation_t *animation, rng_t *rng) {
|
||||
uint8_t rdest;
|
||||
uint8_t gdest;
|
||||
switch (animation->color_scheme) {
|
||||
case normal:
|
||||
rdest = random_step(animation->lamp.r, 180, 255, rng);
|
||||
gdest = random_step(animation->lamp.g, 20, 50, rng);
|
||||
animation->red_line = time_line_new(0, animation->lamp.r, 30, rdest);
|
||||
animation->green_line = time_line_new(0, animation->lamp.g, 30, gdest);
|
||||
animation->duration = 30;
|
||||
break;
|
||||
case creepy:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void animation_step(animation_t *animation, rng_t *rng) {
|
||||
if (animation->duration == 0) {
|
||||
animation_flicker(animation, rng);
|
||||
} else {
|
||||
if (animation->frame == animation->duration) {
|
||||
animation->frame = 0;
|
||||
animation->duration = 0;
|
||||
} else {
|
||||
animation->frame++;
|
||||
animation->lamp.r = time_line_next(&animation->red_line);
|
||||
animation->lamp.g = time_line_next(&animation->green_line);
|
||||
animation->lamp.b = time_line_next(&animation->blue_line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main (void) {
|
||||
DDRB = _BV(2) | _BV(1) | _BV(0);
|
||||
PORTB = 0;
|
||||
_delay_ms(50);
|
||||
|
||||
sk9822_t lights = {
|
||||
.data_pin = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 0 },
|
||||
.clock_pin = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 2 }
|
||||
};
|
||||
|
||||
rng_t rng = rng_new(0);
|
||||
animation_t animation = animation_new();
|
||||
while (1) {
|
||||
animation_step(&animation, &rng);
|
||||
sk9822_send(&lights, &animation.lamp, 1);
|
||||
_delay_ms(FRAME_DELAY_MS);
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
avrdude -c avr109 -P /dev/ttyACM0 -p m32u4 -D -U flash:w:$1:i
|
|
@ -1 +1,2 @@
|
|||
avrdude -c usbtiny -p attiny85 -U flash:w:$1:i; sleep 5; avrdude -c usbtiny -p attiny85 -D -U flash:w:$1:i
|
||||
avrdude -c usbtiny -p attiny85 -U flash:w:$1:i; sleep 5; avrdude -c usbtiny -p attiny85 -D -U flash:w:$1:i
|
||||
# avrdude -c usbtiny -p attiny85 -D -U flash:w:$1:i
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
#include <dio.h>
|
||||
#include <display.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <avr/sleep.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
dio_t light = { .ddr = &DDRC, .port = &PORTC, .pin = &PINC, .addr = 7 };
|
||||
dio_t interrupt_line = { .ddr = &DDRD, .port = &PORTD, .pin = &PIND, .addr = 2 };
|
||||
|
||||
bool button_values[4] = { false, false, false, false };
|
||||
dio_t buttons[4] = {
|
||||
{ .ddr = &DDRD, .port = &PORTD, .pin = &PIND, .addr = 6 },
|
||||
{ .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 7 },
|
||||
{ .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 6 },
|
||||
{ .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 5 },
|
||||
};
|
||||
|
||||
|
||||
ISR(INT2_vect) {
|
||||
dio_set(&light, 1);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
button_values[i] = dio_read(&buttons[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void display_buttons(display_t *display) {
|
||||
char msg[16];
|
||||
|
||||
snprintf(msg, 16, ": %d %d %d %d", button_values[0], button_values[1], button_values[2], button_values[3]);
|
||||
display_clear(display);
|
||||
display_write_message(display, msg);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
EIMSK = 1 << INT2;
|
||||
EICRA |= 1 << ISC21 | 1 << ISC20;
|
||||
|
||||
display_t display = {
|
||||
.reg = {
|
||||
.output = { .ddr = &DDRF, .port = &PORTF, .pin = &PINF, .addr = 7 },
|
||||
.shift_clock = { .ddr = &DDRF, .port = &PORTF, .pin = &PINF, .addr = 6 },
|
||||
.latch_clock = { .ddr = &DDRF, .port = &PORTF, .pin = &PINF, .addr = 5 },
|
||||
}
|
||||
};
|
||||
display_init(&display);
|
||||
|
||||
dio_set_direction(&light, LINE_OUT);
|
||||
dio_set_direction(&interrupt_line, LINE_IN);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
dio_set_direction(&buttons[i], LINE_IN);
|
||||
}
|
||||
|
||||
set_sleep_mode(SLEEP_MODE_IDLE);
|
||||
while (1) {
|
||||
display_buttons(&display);
|
||||
dio_set(&light, 0);
|
||||
|
||||
sei();
|
||||
sleep_mode();
|
||||
cli();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
#include <avr/interrupt.h>
|
||||
#include <avr/sleep.h>
|
||||
#include <dio.h>
|
||||
#include <rfm.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef enum {
|
||||
lme_off,
|
||||
lme_normal,
|
||||
lme_spooky,
|
||||
lme_eerie,
|
||||
} lantern_msg_e;
|
||||
|
||||
dio_t buttons[4] = {
|
||||
{ .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 5 },
|
||||
{ .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 6 },
|
||||
{ .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 7 },
|
||||
{ .ddr = &DDRD, .port = &PORTD, .pin = &PIND, .addr = 6 },
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
bool button_press[4];
|
||||
} status_flags_t;
|
||||
|
||||
status_flags_t status_flags = {
|
||||
.button_press = { false, false, false, false }
|
||||
};
|
||||
|
||||
ISR(INT2_vect) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
status_flags.button_press[i] = dio_read(&buttons[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
EIMSK = 1 << INT2;
|
||||
EICRA |= 1 << ISC21 | 1 << ISC20;
|
||||
|
||||
dio_t int2 = { .ddr = &DDRD, .port = &PORTD, .pin = &PIND, .addr = 2 };
|
||||
dio_set_direction(&int2, LINE_IN);
|
||||
dio_set(&int2, false);
|
||||
|
||||
rfm_t radio = (rfm_t){
|
||||
.spi = {
|
||||
.clock = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 1 },
|
||||
.data_out = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 2 },
|
||||
.data_in = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 3 },
|
||||
.chip_select = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 4 },
|
||||
},
|
||||
.irq = { .ddr = &DDRE, .port = &PORTE, .pin = &PINE, .addr = 6 },
|
||||
.reset = { .ddr = &DDRD, .port = &PORTD, .pin = &PIND, .addr = 4 },
|
||||
};
|
||||
|
||||
rfm_error_e error;
|
||||
rfm_init(&radio, (uint8_t [4]){ 0xde, 0xca, 0xfb, 0xad }, 4, &error);
|
||||
|
||||
set_sleep_mode(SLEEP_MODE_IDLE);
|
||||
while(1) {
|
||||
sei();
|
||||
sleep_mode();
|
||||
cli();
|
||||
|
||||
uint8_t msg;
|
||||
if (status_flags.button_press[0]) {
|
||||
status_flags.button_press[0] = false;
|
||||
msg = lme_normal;
|
||||
} else if (status_flags.button_press[1]) {
|
||||
status_flags.button_press[1] = false;
|
||||
msg = lme_spooky;
|
||||
} else if (status_flags.button_press[2]) {
|
||||
status_flags.button_press[2] = false;
|
||||
msg = lme_eerie;
|
||||
} else if (status_flags.button_press[3]) {
|
||||
status_flags.button_press[3] = false;
|
||||
msg = lme_off;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
rfm_transmit(&radio, &msg, 1);
|
||||
|
||||
interrupt_flags_t flags = rfm_interrupts(&radio);
|
||||
while(!flags.packet_sent) {
|
||||
_delay_ms(1);
|
||||
flags = rfm_interrupts(&radio);
|
||||
}
|
||||
rfm_standby(&radio);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,349 @@
|
|||
/*
|
||||
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of Savanni's AVR library.
|
||||
|
||||
This AVR library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
This AVR library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with this AVR library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "lantern.h"
|
||||
|
||||
uint8_t bound_uint8(int value, uint8_t min, uint8_t max) {
|
||||
if (value > max) {
|
||||
return max;
|
||||
} else if (value < min) {
|
||||
return min;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t random_step(uint8_t value, uint8_t min, uint8_t max) {
|
||||
int8_t step = (rand() % 40) - 20;
|
||||
int new_value = value + step;
|
||||
|
||||
return bound_uint8(new_value, min, max);
|
||||
}
|
||||
|
||||
animation_t animation_new(void) {
|
||||
return (animation_t) {
|
||||
.color = { .brightness = 16, .r = 0, .g = 0, .b = 0 },
|
||||
.red_line = time_line_new(0, 0, 0, 0),
|
||||
.green_line = time_line_new(0, 0, 0, 0),
|
||||
.blue_line = time_line_new(0, 0, 0, 0),
|
||||
|
||||
.frame = 0,
|
||||
.duration = 0,
|
||||
};
|
||||
}
|
||||
|
||||
void animation_begin(animation_t *self, uint8_t rdest, uint8_t gdest, uint8_t bdest, uint8_t duration) {
|
||||
self->red_line = time_line_new(0, self->color.r, duration, rdest);
|
||||
self->green_line = time_line_new(0, self->color.g, duration, gdest);
|
||||
self->blue_line = time_line_new(0, self->color.b, duration, bdest);
|
||||
self->frame = 0;
|
||||
self->duration = duration;
|
||||
}
|
||||
|
||||
void animation_step(animation_t *self) {
|
||||
if (self->frame == self->duration) {
|
||||
self->frame = 0;
|
||||
self->duration = 0;
|
||||
} else {
|
||||
self->frame++;
|
||||
self->color.r = bound_uint8(time_line_next(&self->red_line), 0, 255);
|
||||
self->color.g = bound_uint8(time_line_next(&self->green_line), 0, 255);
|
||||
self->color.b = bound_uint8(time_line_next(&self->blue_line), 0, 255);
|
||||
}
|
||||
}
|
||||
|
||||
bool animation_running(animation_t *self) {
|
||||
return self->frame != self->duration;
|
||||
}
|
||||
|
||||
lantern_t lantern_new(sk9822_t lights) {
|
||||
sk9822_init(&lights);
|
||||
return (lantern_t){
|
||||
.lights = lights,
|
||||
.color_scheme = cse_off,
|
||||
.animations = {
|
||||
animation_new(),
|
||||
animation_new(),
|
||||
animation_new(),
|
||||
animation_new(),
|
||||
animation_new(),
|
||||
animation_new(),
|
||||
animation_new(),
|
||||
animation_new(),
|
||||
animation_new(),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void lantern_start_off(lantern_t *self, int light_idx) {
|
||||
animation_begin(
|
||||
&self->animations[light_idx],
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1);
|
||||
}
|
||||
|
||||
void lantern_start_normal(lantern_t *self, int light_idx) {
|
||||
switch (light_idx) {
|
||||
case 0:
|
||||
animation_begin(
|
||||
&self->animations[0],
|
||||
random_step(self->animations[0].color.r, 180, 255),
|
||||
random_step(self->animations[0].color.g, 20, 50),
|
||||
0,
|
||||
5);
|
||||
animation_begin(
|
||||
&self->animations[3],
|
||||
random_step(self->animations[3].color.r, 180, 255),
|
||||
random_step(self->animations[3].color.g, 20, 50),
|
||||
0,
|
||||
5);
|
||||
animation_begin(
|
||||
&self->animations[6],
|
||||
random_step(self->animations[3].color.r, 180, 255),
|
||||
random_step(self->animations[3].color.g, 20, 50),
|
||||
0,
|
||||
5);
|
||||
break;
|
||||
case 1:
|
||||
animation_begin(
|
||||
&self->animations[1],
|
||||
random_step(self->animations[1].color.r, 160, 230),
|
||||
random_step(self->animations[1].color.g, 10, 30),
|
||||
0,
|
||||
5);
|
||||
animation_begin(
|
||||
&self->animations[4],
|
||||
random_step(self->animations[4].color.r, 160, 230),
|
||||
random_step(self->animations[4].color.g, 10, 30),
|
||||
0,
|
||||
5);
|
||||
animation_begin(
|
||||
&self->animations[7],
|
||||
random_step(self->animations[7].color.r, 160, 230),
|
||||
random_step(self->animations[7].color.g, 10, 30),
|
||||
0,
|
||||
5);
|
||||
break;
|
||||
case 2:
|
||||
animation_begin(
|
||||
&self->animations[2],
|
||||
random_step(self->animations[2].color.r, 140, 170),
|
||||
random_step(self->animations[2].color.g, 0, 10),
|
||||
0,
|
||||
5);
|
||||
animation_begin(
|
||||
&self->animations[5],
|
||||
random_step(self->animations[5].color.r, 140, 170),
|
||||
random_step(self->animations[5].color.g, 0, 10),
|
||||
0,
|
||||
5);
|
||||
animation_begin(
|
||||
&self->animations[8],
|
||||
random_step(self->animations[8].color.r, 140, 170),
|
||||
random_step(self->animations[8].color.g, 0, 10),
|
||||
0,
|
||||
5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void lantern_start_spooky(lantern_t *self, int light_idx) {
|
||||
switch (light_idx) {
|
||||
case 0:
|
||||
animation_begin(
|
||||
&self->animations[0],
|
||||
0,
|
||||
random_step(self->animations[0].color.g, 40, 140),
|
||||
0,
|
||||
5);
|
||||
animation_begin(
|
||||
&self->animations[3],
|
||||
0,
|
||||
random_step(self->animations[3].color.g, 40, 140),
|
||||
0,
|
||||
5);
|
||||
animation_begin(
|
||||
&self->animations[6],
|
||||
0,
|
||||
random_step(self->animations[6].color.g, 40, 140),
|
||||
0,
|
||||
5);
|
||||
break;
|
||||
case 1:
|
||||
animation_begin(
|
||||
&self->animations[1],
|
||||
0,
|
||||
random_step(self->animations[1].color.g, 20, 80),
|
||||
0,
|
||||
5);
|
||||
animation_begin(
|
||||
&self->animations[4],
|
||||
0,
|
||||
random_step(self->animations[4].color.g, 20, 80),
|
||||
0,
|
||||
5);
|
||||
animation_begin(
|
||||
&self->animations[7],
|
||||
0,
|
||||
random_step(self->animations[7].color.g, 20, 80),
|
||||
0,
|
||||
5);
|
||||
break;
|
||||
case 2:
|
||||
animation_begin(
|
||||
&self->animations[2],
|
||||
0,
|
||||
random_step(self->animations[2].color.g, 10, 40),
|
||||
0,
|
||||
5);
|
||||
animation_begin(
|
||||
&self->animations[5],
|
||||
0,
|
||||
random_step(self->animations[5].color.g, 10, 40),
|
||||
0,
|
||||
5);
|
||||
animation_begin(
|
||||
&self->animations[8],
|
||||
0,
|
||||
random_step(self->animations[8].color.g, 10, 40),
|
||||
0,
|
||||
5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void lantern_start_eerie(lantern_t *self, int light_idx) {
|
||||
switch (light_idx) {
|
||||
case 0:
|
||||
animation_begin(
|
||||
&self->animations[0],
|
||||
random_step(self->animations[0].color.r, 20, 40),
|
||||
random_step(self->animations[0].color.g, 20, 40),
|
||||
random_step(self->animations[0].color.b, 80, 120),
|
||||
5);
|
||||
animation_begin(
|
||||
&self->animations[3],
|
||||
random_step(self->animations[3].color.r, 20, 40),
|
||||
random_step(self->animations[3].color.g, 20, 40),
|
||||
random_step(self->animations[3].color.b, 80, 120),
|
||||
5);
|
||||
animation_begin(
|
||||
&self->animations[6],
|
||||
random_step(self->animations[6].color.r, 20, 40),
|
||||
random_step(self->animations[6].color.g, 20, 40),
|
||||
random_step(self->animations[6].color.b, 80, 120),
|
||||
5);
|
||||
break;
|
||||
case 1:
|
||||
animation_begin(
|
||||
&self->animations[1],
|
||||
random_step(self->animations[1].color.r, 0, 30),
|
||||
random_step(self->animations[1].color.g, 0, 30),
|
||||
random_step(self->animations[1].color.b, 60, 100),
|
||||
5);
|
||||
animation_begin(
|
||||
&self->animations[4],
|
||||
random_step(self->animations[4].color.r, 0, 30),
|
||||
random_step(self->animations[4].color.g, 0, 30),
|
||||
random_step(self->animations[4].color.b, 60, 100),
|
||||
5);
|
||||
animation_begin(
|
||||
&self->animations[7],
|
||||
random_step(self->animations[7].color.r, 0, 30),
|
||||
random_step(self->animations[7].color.g, 0, 30),
|
||||
random_step(self->animations[7].color.b, 60, 100),
|
||||
5);
|
||||
break;
|
||||
case 2:
|
||||
animation_begin(
|
||||
&self->animations[2],
|
||||
random_step(self->animations[2].color.r, 0, 10),
|
||||
random_step(self->animations[2].color.g, 0, 10),
|
||||
random_step(self->animations[2].color.b, 20, 40),
|
||||
5);
|
||||
animation_begin(
|
||||
&self->animations[5],
|
||||
random_step(self->animations[5].color.r, 0, 10),
|
||||
random_step(self->animations[5].color.g, 0, 10),
|
||||
random_step(self->animations[5].color.b, 20, 40),
|
||||
5);
|
||||
animation_begin(
|
||||
&self->animations[8],
|
||||
random_step(self->animations[8].color.r, 0, 10),
|
||||
random_step(self->animations[8].color.g, 0, 10),
|
||||
random_step(self->animations[8].color.b, 20, 40),
|
||||
5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void lantern_set_mode(lantern_t *self, color_scheme_e scheme) {
|
||||
self->color_scheme = scheme;
|
||||
}
|
||||
|
||||
void lantern_step(lantern_t *self, rgb_t colors[LIGHT_COUNT]) {
|
||||
for (int i = 0; i < LIGHT_COUNT; i++) {
|
||||
if (!animation_running(&self->animations[i])) {
|
||||
switch (self->color_scheme) {
|
||||
case cse_off:
|
||||
lantern_start_off(self, i);
|
||||
break;
|
||||
case cse_normal:
|
||||
lantern_start_normal(self, i);
|
||||
break;
|
||||
case cse_spooky:
|
||||
lantern_start_spooky(self, i);
|
||||
break;
|
||||
case cse_eerie:
|
||||
lantern_start_eerie(self, i);
|
||||
break;
|
||||
case cse_flash:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
animation_step(&self->animations[i]);
|
||||
colors[i] = self->animations[i].color;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void lantern_show(lantern_t *lantern, display_t *display) {
|
||||
char msg1[20];
|
||||
char msg2[20];
|
||||
|
||||
snprintf(msg1, 20, "[%d,%d] %x,%x,%x",
|
||||
lantern->animations[0].frame,
|
||||
lantern->animations[0].duration,
|
||||
lantern->animations[0].color.r,
|
||||
lantern->animations[0].color.g,
|
||||
lantern->animations[0].color.b
|
||||
);
|
||||
snprintf(msg2, 20, "%x,%x,%x %x,%x,%x",
|
||||
lantern->animations[1].color.r,
|
||||
lantern->animations[1].color.g,
|
||||
lantern->animations[1].color.b,
|
||||
lantern->animations[2].color.r,
|
||||
lantern->animations[2].color.g,
|
||||
lantern->animations[2].color.b
|
||||
);
|
||||
display_clear(display);
|
||||
display_write_message(display, msg1);
|
||||
display_set_location(display, 1, 0);
|
||||
display_write_message(display, msg2);
|
||||
}
|
||||
*/
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of Savanni's AVR library.
|
||||
|
||||
This AVR library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
This AVR library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with this AVR library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <animation.h>
|
||||
#include <display.h>
|
||||
#include <sk9822.h>
|
||||
|
||||
#ifndef __LANTERN_H__
|
||||
#define __LANTERN_H__
|
||||
|
||||
#define LIGHT_COUNT 9
|
||||
|
||||
typedef struct {
|
||||
rgb_t color;
|
||||
|
||||
time_line_t red_line;
|
||||
time_line_t green_line;
|
||||
time_line_t blue_line;
|
||||
|
||||
uint8_t frame;
|
||||
uint8_t duration;
|
||||
} animation_t;
|
||||
|
||||
typedef enum {
|
||||
cse_off,
|
||||
cse_normal,
|
||||
cse_spooky,
|
||||
cse_eerie,
|
||||
cse_flash
|
||||
} color_scheme_e;
|
||||
|
||||
typedef struct {
|
||||
sk9822_t lights;
|
||||
|
||||
color_scheme_e color_scheme;
|
||||
animation_t animations[LIGHT_COUNT];
|
||||
} lantern_t;
|
||||
|
||||
lantern_t lantern_new(sk9822_t);
|
||||
void lantern_set_mode(lantern_t *, color_scheme_e);
|
||||
void lantern_step(lantern_t *, rgb_t *);
|
||||
|
||||
void lantern_show(lantern_t *, display_t *);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,212 @@
|
|||
/*
|
||||
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of Savanni's AVR library.
|
||||
|
||||
This AVR library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
This AVR library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with this AVR library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/sleep.h>
|
||||
#include <dio.h>
|
||||
#include <display.h>
|
||||
#include "lantern.h"
|
||||
#include <rfm.h>
|
||||
#include <sk9822.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define FPS 15
|
||||
#define TICKS_PER_SECOND 7812
|
||||
#define FPS_TIMEOUT TICKS_PER_SECOND / FPS
|
||||
#define FPS_MS 1000 / FPS
|
||||
#define PULSE_OFF_COUNT FPS * 5
|
||||
#define PULSE_ON_COUNT 5
|
||||
|
||||
typedef enum {
|
||||
lme_off,
|
||||
lme_normal,
|
||||
lme_spooky,
|
||||
lme_eerie,
|
||||
} lantern_msg_e;
|
||||
|
||||
typedef struct {
|
||||
bool frame_timeout;
|
||||
} status_flags_t;
|
||||
|
||||
status_flags_t status_flags;
|
||||
|
||||
/*
|
||||
ISR(TIMER1_COMPA_vect) {
|
||||
status_flags.frame_timeout = true;
|
||||
}
|
||||
*/
|
||||
|
||||
ISR(INT6_vect) {
|
||||
}
|
||||
|
||||
/*
|
||||
void setup_fps_timer(void) {
|
||||
// WGM = 0100: CTC with OCR1nA top
|
||||
// CS = 101: clock / 1024
|
||||
TCCR1A = 0;
|
||||
TCCR1B = _BV(3) | _BV(2) | _BV(0);
|
||||
|
||||
// Set the top for the counter
|
||||
OCR1AH = FPS_TIMEOUT >> 8;
|
||||
OCR1AL = FPS_TIMEOUT & 0xff;
|
||||
|
||||
// Enable compare on A match interrupt
|
||||
TIMSK1 |= _BV(1);
|
||||
}
|
||||
*/
|
||||
|
||||
void startup_animation(sk9822_t *lights, rgb_t *colors) {
|
||||
for (int i = 0; i < LIGHT_COUNT; i++) {
|
||||
colors[i].brightness = 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < LIGHT_COUNT; i++) {
|
||||
colors[i].b = 0;
|
||||
colors[i].r = 128;
|
||||
sk9822_send(lights, colors, LIGHT_COUNT);
|
||||
_delay_ms(50);
|
||||
}
|
||||
|
||||
for (int i = 0; i < LIGHT_COUNT; i++) {
|
||||
colors[i].r = 0;
|
||||
colors[i].g = 128;
|
||||
sk9822_send(lights, colors, LIGHT_COUNT);
|
||||
_delay_ms(100);
|
||||
}
|
||||
|
||||
for (int i = 0; i < LIGHT_COUNT; i++) {
|
||||
colors[i].g = 0;
|
||||
colors[i].b = 128;
|
||||
sk9822_send(lights, colors, LIGHT_COUNT);
|
||||
_delay_ms(100);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
EIMSK = 1 << INT6 | 1 << INT2;
|
||||
EICRA |= 1 << ISC21 | 1 << ISC20;
|
||||
EICRB |= 1 << ISC61 | 1 << ISC60;
|
||||
|
||||
status_flags.frame_timeout = false;
|
||||
|
||||
// Disable unneeded modules
|
||||
PRR0 = _BV(7) | _BV(5) | _BV(2);
|
||||
PRR1 = _BV(7) | _BV(4) | _BV(3) | _BV(0);
|
||||
|
||||
rfm_t radio = (rfm_t){
|
||||
.spi = {
|
||||
.clock = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 1 },
|
||||
.data_out = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 2 },
|
||||
.data_in = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 3 },
|
||||
.chip_select = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 4 },
|
||||
},
|
||||
.irq = { .ddr = &DDRE, .port = &PORTE, .pin = &PINE, .addr = 6 },
|
||||
.reset = { .ddr = &DDRD, .port = &PORTD, .pin = &PIND, .addr = 4 },
|
||||
};
|
||||
|
||||
rfm_error_e error;
|
||||
rfm_init(&radio, (uint8_t [4]){ 0xde, 0xca, 0xfb, 0xad }, 4, &error);
|
||||
rfm_listen(&radio);
|
||||
|
||||
sk9822_t lights = {
|
||||
.clock_pin = { .ddr = &DDRC, .port = &PORTC, .pin = &PINC, .addr = 7 },
|
||||
.data_pin = { .ddr = &DDRD, .port = &PORTD, .pin = &PIND, .addr = 6 }
|
||||
};
|
||||
|
||||
rgb_t error_indicator[LIGHT_COUNT] = {
|
||||
{ .brightness = 1, .r = 255, .g = 0, .b = 0 },
|
||||
{ .brightness = 0, .r = 0, .g = 0, .b = 0 },
|
||||
{ .brightness = 0, .r = 0, .g = 0, .b = 0 },
|
||||
{ .brightness = 1, .r = 255, .g = 0, .b = 0 },
|
||||
{ .brightness = 0, .r = 0, .g = 0, .b = 0 },
|
||||
{ .brightness = 0, .r = 0, .g = 0, .b = 0 },
|
||||
{ .brightness = 1, .r = 255, .g = 0, .b = 0 },
|
||||
{ .brightness = 0, .r = 0, .g = 0, .b = 0 },
|
||||
{ .brightness = 0, .r = 0, .g = 0, .b = 0 },
|
||||
};
|
||||
|
||||
lantern_t lantern = lantern_new(lights);
|
||||
lantern_set_mode(&lantern, cse_off);
|
||||
|
||||
// setup_fps_timer();
|
||||
|
||||
// set_sleep_mode(SLEEP_MODE_IDLE);
|
||||
|
||||
rgb_t colors[LIGHT_COUNT] = {
|
||||
{ .brightness = 0, .r = 0, .g = 0, .b = 0 },
|
||||
{ .brightness = 0, .r = 0, .g = 0, .b = 0 },
|
||||
{ .brightness = 0, .r = 0, .g = 0, .b = 0 },
|
||||
{ .brightness = 0, .r = 0, .g = 0, .b = 0 },
|
||||
{ .brightness = 0, .r = 0, .g = 0, .b = 0 },
|
||||
{ .brightness = 0, .r = 0, .g = 0, .b = 0 },
|
||||
{ .brightness = 0, .r = 0, .g = 0, .b = 0 },
|
||||
{ .brightness = 0, .r = 0, .g = 0, .b = 0 },
|
||||
{ .brightness = 0, .r = 0, .g = 0, .b = 0 },
|
||||
};
|
||||
_delay_ms(1000);
|
||||
startup_animation(&lights, (rgb_t *)&colors);
|
||||
|
||||
while(1) {
|
||||
/*
|
||||
if (status_flags.frame_timeout) {
|
||||
status_flags.frame_timeout = false;
|
||||
lantern_step(&lantern, colors);
|
||||
sk9822_send(&lights, colors, LIGHT_COUNT);
|
||||
}
|
||||
*/
|
||||
|
||||
lantern_step(&lantern, colors);
|
||||
sk9822_send(&lights, colors, LIGHT_COUNT);
|
||||
|
||||
interrupt_flags_t flags = rfm_interrupts(&radio);
|
||||
while (flags.fifo_not_empty) {
|
||||
uint8_t msg[60];
|
||||
uint8_t length;
|
||||
|
||||
rfm_receive(&radio, (uint8_t *)msg, &length);
|
||||
if (length == 1) {
|
||||
switch (msg[0]) {
|
||||
case lme_off:
|
||||
lantern_set_mode(&lantern, cse_off);
|
||||
break;
|
||||
case lme_normal:
|
||||
lantern_set_mode(&lantern, cse_normal);
|
||||
break;
|
||||
case lme_spooky:
|
||||
lantern_set_mode(&lantern, cse_spooky);
|
||||
break;
|
||||
case lme_eerie:
|
||||
lantern_set_mode(&lantern, cse_eerie);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
flags = rfm_interrupts(&radio);
|
||||
}
|
||||
|
||||
_delay_ms(FPS_MS);
|
||||
/*
|
||||
sei();
|
||||
sleep_mode();
|
||||
cli();
|
||||
*/
|
||||
}
|
||||
|
||||
sk9822_send(&lights, error_indicator, LIGHT_COUNT);
|
||||
_delay_ms(1000);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of Savanni's AVR library.
|
||||
|
||||
Lumeto is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Lumeto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <util/delay.h>
|
||||
#include <string.h>
|
||||
#include "morse.h"
|
||||
|
||||
/* TODO: all of this is a candidate for living in an EEPROM */
|
||||
typedef struct morse_codepoint {
|
||||
size_t length;
|
||||
uint8_t values[5];
|
||||
} morse_codepoint_t;
|
||||
|
||||
const struct morse_codepoint MORSE[] = {
|
||||
/* 0 */ { .length = 5, .values = { DASH, DASH, DASH, DASH, DASH } },
|
||||
/* 1 */ { .length = 5, .values = { DOT, DASH, DASH, DASH, DASH } },
|
||||
/* 2 */ { .length = 5, .values = { DOT, DOT, DASH, DASH, DASH } },
|
||||
/* 3 */ { .length = 5, .values = { DOT, DOT, DOT, DASH, DASH } },
|
||||
/* 4 */ { .length = 5, .values = { DOT, DOT, DOT, DOT, DASH } },
|
||||
/* 5 */ { .length = 5, .values = { DOT, DOT, DOT, DOT, DOT } },
|
||||
/* 6 */ { .length = 5, .values = { DASH, DOT, DOT, DOT, DOT } },
|
||||
/* 7 */ { .length = 5, .values = { DASH, DASH, DOT, DOT, DOT } },
|
||||
/* 8 */ { .length = 5, .values = { DASH, DASH, DASH, DOT, DOT } },
|
||||
/* 9 */ { .length = 5, .values = { DASH, DASH, DASH, DASH, DOT } },
|
||||
/* a */ { .length = 2, .values = { DOT, DASH } },
|
||||
/* b */ { .length = 4, .values = { DASH, DOT, DOT, DOT } },
|
||||
/* c */ { .length = 4, .values = { DASH, DOT, DASH, DOT } },
|
||||
/* d */ { .length = 3, .values = { DASH, DOT, DOT } },
|
||||
/* e */ { .length = 1, .values = { DOT } },
|
||||
/* f */ { .length = 4, .values = { DOT, DOT, DASH, DOT } },
|
||||
/* g */ { .length = 3, .values = { DASH, DASH, DOT } },
|
||||
/* h */ { .length = 4, .values = { DOT, DOT, DOT, DOT } },
|
||||
/* i */ { .length = 2, .values = { DOT, DOT } },
|
||||
/* j */ { .length = 4, .values = { DOT, DASH, DASH, DASH } },
|
||||
/* k */ { .length = 3, .values = { DASH, DOT, DASH } },
|
||||
/* l */ { .length = 4, .values = { DOT, DASH, DOT, DOT } },
|
||||
/* m */ { .length = 2, .values = { DASH, DASH } },
|
||||
/* n */ { .length = 2, .values = { DASH, DOT } },
|
||||
/* o */ { .length = 3, .values = { DASH, DASH, DASH } },
|
||||
/* p */ { .length = 4, .values = { DOT, DASH, DASH, DOT } },
|
||||
/* q */ { .length = 4, .values = { DASH, DASH, DOT, DASH } },
|
||||
/* r */ { .length = 3, .values = { DOT, DASH, DOT } },
|
||||
/* s */ { .length = 3, .values = { DOT, DOT, DOT } },
|
||||
/* t */ { .length = 1, .values = { DASH } },
|
||||
/* u */ { .length = 3, .values = { DOT, DOT, DASH } },
|
||||
/* v */ { .length = 4, .values = { DOT, DOT, DOT, DASH } },
|
||||
/* w */ { .length = 3, .values = { DOT, DASH, DASH } },
|
||||
/* x */ { .length = 4, .values = { DASH, DOT, DOT, DASH } },
|
||||
/* y */ { .length = 4, .values = { DASH, DOT, DASH, DASH } },
|
||||
/* z */ { .length = 4, .values = { DASH, DASH, DOT, DOT } },
|
||||
};
|
||||
|
||||
const struct morse_codepoint * morse_lookup(char val) {
|
||||
size_t idx = -1;
|
||||
if (val >= '0' && val <= '9') {
|
||||
idx = val - '0';
|
||||
} else if (val >= 'a' && val <= 'z') {
|
||||
idx = (val - 'a') + 10;
|
||||
} else if (val >= 'A' && val <= 'Z') {
|
||||
idx = (val - 'A') + 10;
|
||||
}
|
||||
if (idx < 0) return NULL;
|
||||
return &MORSE[idx];
|
||||
}
|
||||
|
||||
void send_codepoint(dio_t *dio, const struct morse_codepoint *codepoint) {
|
||||
const uint8_t one = 1 << dio->addr;
|
||||
for (size_t i = 0; i < codepoint->length; i++) {
|
||||
*dio->port = *(dio->port) | one;
|
||||
if (codepoint->values[i] == DOT) {
|
||||
_delay_ms(DOT * SCALE);
|
||||
} else {
|
||||
_delay_ms(DASH * SCALE);
|
||||
}
|
||||
*dio->port = *(dio->port) & ~one;
|
||||
_delay_ms(DIVIDER * SCALE);
|
||||
}
|
||||
_delay_ms(INTERCHAR * SCALE);
|
||||
}
|
||||
|
||||
void send_morse(dio_t *dio, char *message) {
|
||||
for (size_t i = 0; i < strlen(message); i++) {
|
||||
if (message[i] == ' ') {
|
||||
_delay_ms(INTERWORD * SCALE);
|
||||
}
|
||||
const struct morse_codepoint *codepoint = morse_lookup(message[i]);
|
||||
if (codepoint != NULL) {
|
||||
send_codepoint(dio, codepoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of Savanni's AVR library.
|
||||
|
||||
Lumeto is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Lumeto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __MORSE_H__
|
||||
#define __MORSE_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <dio.h>
|
||||
|
||||
/* TODO: make this parameterizable */
|
||||
#define DOT 1
|
||||
#define DASH 3
|
||||
#define DIVIDER 1
|
||||
#define INTERCHAR 3
|
||||
#define INTERWORD 4
|
||||
#define SCALE 100
|
||||
|
||||
void send_morse(dio_t *dio, char *message);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,20 @@
|
|||
#include <dio.h>
|
||||
|
||||
#define TIMEOUT 1
|
||||
|
||||
int main(void) {
|
||||
dio_t power = { .ddr = &DDRB, .pin = &PINB, .port = &PORTB, .addr = 3 };
|
||||
dio_set_direction(&power, LINE_OUT);
|
||||
|
||||
int timeout_seconds = TIMEOUT;
|
||||
while (1) {
|
||||
if (timeout_seconds <= 0) {
|
||||
dio_set(&power, 1);
|
||||
_delay_ms(50);
|
||||
dio_set(&power, 0);
|
||||
timeout_seconds = TIMEOUT;
|
||||
}
|
||||
timeout_seconds--;
|
||||
_delay_ms(1000);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
#include <avr/io.h>
|
||||
#include <dio.h>
|
||||
#include <display.h>
|
||||
#include <rfm.h>
|
||||
#include <spi.h>
|
||||
#include <stdio.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
void status(display_t *display, rfm_t *radio, int clock) {
|
||||
op_mode_t mode = rfm_mode(radio);
|
||||
interrupt_flags_t flags = rfm_interrupts(radio);
|
||||
|
||||
display_clear(display);
|
||||
|
||||
char clock_str[16];
|
||||
sprintf(clock_str, "%4d ", clock);
|
||||
display_write_message(display, clock_str);
|
||||
|
||||
if (mode.listen_on) display_write_message(display, "Listen ");
|
||||
if (mode.mode == sleep) display_write_message(display, "Sleep");
|
||||
if (mode.mode == standby) display_write_message(display, "Standby");
|
||||
if (mode.mode == fs) display_write_message(display, "FS");
|
||||
if (mode.mode == tx) display_write_message(display, "TX");
|
||||
if (mode.mode == rx) display_write_message(display, "RX");
|
||||
|
||||
display_set_location(display, 1, 0);
|
||||
if (flags.mode_ready) display_write_message(display, "R ");
|
||||
if (flags.rx_ready) display_write_message(display, "RX ");
|
||||
if (flags.tx_ready) display_write_message(display, "TX ");
|
||||
if (flags.timeout) display_write_message(display, "TO ");
|
||||
if (flags.auto_mode) display_write_message(display, "AM ");
|
||||
if (flags.sync_addr_match) display_write_message(display, "SM ");
|
||||
if (flags.fifo_full) display_write_message(display, "F ");
|
||||
if (flags.fifo_not_empty) display_write_message(display, "NE ");
|
||||
if (flags.fifo_level) display_write_message(display, "LE ");
|
||||
if (flags.fifo_overrun) display_write_message(display, "OR ");
|
||||
if (flags.packet_sent) display_write_message(display, "PS ");
|
||||
if (flags.payload_ready) display_write_message(display, "PR");
|
||||
if (flags.crc_ok) display_write_message(display, "CRC");
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int clock = 0;
|
||||
uint8_t primes[] = { 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 0 };
|
||||
|
||||
display_t display = {
|
||||
.reg = {
|
||||
.output = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 7 },
|
||||
.shift_clock = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 6 },
|
||||
.latch_clock = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 5 },
|
||||
},
|
||||
};
|
||||
|
||||
rfm_t radio = (rfm_t){
|
||||
.spi = {
|
||||
.clock = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 1 },
|
||||
.data_out = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 2 },
|
||||
.data_in = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 3 },
|
||||
.chip_select = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 4 },
|
||||
},
|
||||
.irq = { .ddr = &DDRE, .port = &PORTE, .pin = &PINE, .addr = 6 },
|
||||
.reset = { .ddr = &DDRD, .port = &PORTD, .pin = &PIND, .addr = 4 },
|
||||
};
|
||||
|
||||
_delay_ms(15);
|
||||
display_init(&display);
|
||||
|
||||
rfm_error_e error;
|
||||
|
||||
rfm_init(&radio, (uint8_t [4]){ 0xde, 0xca, 0xfb, 0xad }, 4, &error);
|
||||
|
||||
status(&display, &radio, clock);
|
||||
|
||||
int prime = 0;
|
||||
while (1) {
|
||||
status(&display, &radio, clock);
|
||||
|
||||
op_mode_t mode = rfm_mode(&radio);
|
||||
interrupt_flags_t flags = rfm_interrupts(&radio);
|
||||
if (mode.mode == standby) {
|
||||
rfm_transmit(&radio, &primes[prime], 1);
|
||||
if (primes[prime] == 0) {
|
||||
prime = 0;
|
||||
} else {
|
||||
prime++;
|
||||
}
|
||||
} else if (mode.mode == tx && flags.packet_sent) {
|
||||
rfm_standby(&radio);
|
||||
}
|
||||
|
||||
clock++;
|
||||
_delay_ms(1000);
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
#include <base.h>
|
||||
|
||||
int main (void) {
|
||||
DDRB = 0x18;
|
||||
PORTB = 0x00;
|
||||
|
||||
_delay_ms(500);
|
||||
|
||||
io_pin_t enable_pin = { .port = &PORTB, .pin = 3 };
|
||||
io_pin_t data_pin = { .port = &PORTB, .pin = 4 };
|
||||
|
||||
set_pin(&enable_pin);
|
||||
for (uint8_t i = 0; i < 10; i++) {
|
||||
set_pin(&data_pin);
|
||||
_delay_ms(500);
|
||||
clear_pin(&data_pin);
|
||||
_delay_ms(500);
|
||||
}
|
||||
clear_pin(&enable_pin);
|
||||
|
||||
while(1) {};
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#include <base.h>
|
||||
|
||||
#define FIVE_SECOND_TICK (8000000 * 10) / 256
|
||||
|
||||
volatile uint32_t iteration = 0;
|
||||
|
||||
void set_up_pwm(void);
|
||||
void start_pwm(void);
|
||||
|
||||
ISR(TIMER0_OVF_vect) {
|
||||
if (iteration >= FIVE_SECOND_TICK) {
|
||||
GTCCR |= _BV(TSM);
|
||||
/*
|
||||
PORTB &= ~(_BV(2));
|
||||
PORTB |= _BV(1);
|
||||
*/
|
||||
PORTB = _BV(1);
|
||||
} else {
|
||||
iteration += 1;
|
||||
}
|
||||
}
|
||||
|
||||
void set_up_pwm(void) {
|
||||
// Stop the clock
|
||||
GTCCR = _BV(TSM) | _BV(PSR0);
|
||||
|
||||
TCCR0B = _BV(CS00);
|
||||
|
||||
// Set normal mode
|
||||
TCCR0A = _BV(COM0A1) | _BV(WGM01) | _BV(WGM00);
|
||||
|
||||
// Enable the overflow interrupt
|
||||
TIMSK = _BV(TOIE0);
|
||||
}
|
||||
|
||||
void start_pwm(void) {
|
||||
GTCCR &= ~(_BV(TSM));
|
||||
}
|
||||
|
||||
int main (void) {
|
||||
int8_t step = 1;
|
||||
uint8_t target = 0;
|
||||
|
||||
set_up_pwm();
|
||||
OCR0A = 0;
|
||||
|
||||
PORTB = 0;
|
||||
DDRB = _BV(2) | _BV(1) | _BV(0);
|
||||
_delay_ms(50);
|
||||
PORTB |= _BV(2);
|
||||
|
||||
sei();
|
||||
start_pwm();
|
||||
|
||||
while (iteration != FIVE_SECOND_TICK) {
|
||||
OCR0A = target;
|
||||
target += step;
|
||||
|
||||
if (target == 255) {
|
||||
step = -1;
|
||||
} else if (target == 0) {
|
||||
step = 1;
|
||||
}
|
||||
|
||||
_delay_ms(10);
|
||||
}
|
||||
|
||||
while (1) {}
|
||||
}
|
||||
|
|
@ -0,0 +1,149 @@
|
|||
#include <avr/io.h>
|
||||
#include <dio.h>
|
||||
#include <display.h>
|
||||
#include <rfm.h>
|
||||
#include <spi.h>
|
||||
#include <stdio.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
void status(display_t *display, rfm_t *radio, int clock) {
|
||||
op_mode_t mode = rfm_mode(radio);
|
||||
interrupt_flags_t flags = rfm_interrupts(radio);
|
||||
// uint8_t rssi = rfm_rssi(radio);
|
||||
|
||||
display_clear(display);
|
||||
|
||||
char clock_str[16];
|
||||
sprintf(clock_str, "%4d ", clock);
|
||||
display_write_message(display, clock_str);
|
||||
|
||||
if (mode.listen_on) display_write_message(display, "Listen ");
|
||||
if (mode.mode == sleep) display_write_message(display, "Sleep");
|
||||
if (mode.mode == standby) display_write_message(display, "Standby");
|
||||
if (mode.mode == fs) display_write_message(display, "FS");
|
||||
if (mode.mode == tx) display_write_message(display, "TX");
|
||||
if (mode.mode == rx) display_write_message(display, "RX");
|
||||
|
||||
display_set_location(display, 1, 0);
|
||||
|
||||
/*
|
||||
char msg[16];
|
||||
snprintf(msg, 15, "[-%d] ", rssi / 2);
|
||||
display_write_message(display, msg);
|
||||
*/
|
||||
|
||||
if (flags.mode_ready) display_write_message(display, "R ");
|
||||
if (flags.rx_ready) display_write_message(display, "RX ");
|
||||
if (flags.tx_ready) display_write_message(display, "TX ");
|
||||
if (flags.timeout) display_write_message(display, "TO ");
|
||||
if (flags.auto_mode) display_write_message(display, "AM ");
|
||||
if (flags.sync_addr_match) display_write_message(display, "SM ");
|
||||
if (flags.fifo_full) display_write_message(display, "F ");
|
||||
if (flags.fifo_not_empty) display_write_message(display, "NE ");
|
||||
if (flags.fifo_level) display_write_message(display, "LE ");
|
||||
if (flags.fifo_overrun) display_write_message(display, "OR ");
|
||||
if (flags.packet_sent) display_write_message(display, "PS ");
|
||||
if (flags.payload_ready) display_write_message(display, "PR");
|
||||
if (flags.crc_ok) display_write_message(display, "CRC");
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
display_t display = {
|
||||
.reg = {
|
||||
.output = { .ddr = &DDRF, .port = &PORTF, .pin = &PINF, .addr = 7 },
|
||||
.shift_clock = { .ddr = &DDRF, .port = &PORTF, .pin = &PINF, .addr = 6 },
|
||||
.latch_clock = { .ddr = &DDRF, .port = &PORTF, .pin = &PINF, .addr = 5 },
|
||||
},
|
||||
};
|
||||
|
||||
rfm_t radio = (rfm_t){
|
||||
.spi = {
|
||||
.clock = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 1 },
|
||||
.data_out = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 2 },
|
||||
.data_in = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 3 },
|
||||
.chip_select = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 4 },
|
||||
},
|
||||
.irq = { .ddr = &DDRE, .port = &PORTE, .pin = &PINE, .addr = 6 },
|
||||
.reset = { .ddr = &DDRD, .port = &PORTD, .pin = &PIND, .addr = 4 },
|
||||
};
|
||||
|
||||
_delay_ms(15);
|
||||
display_init(&display);
|
||||
display_clear(&display);
|
||||
display_write_message(&display, "waking up");
|
||||
|
||||
rfm_error_e error;
|
||||
|
||||
rfm_init(&radio, (uint8_t [4]){ 0xde, 0xca, 0xfb, 0xad }, 4, &error);
|
||||
rfm_listen(&radio);
|
||||
|
||||
/*
|
||||
if (!error) {
|
||||
display_write_message(&display, "error detected");
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
uint8_t word[8];
|
||||
uint8_t sync_length = sync_word(&radio, word);
|
||||
char msg[16];
|
||||
snprintf(msg, 15, "sync: %d", sync_length);
|
||||
display_write_message(&display, msg);
|
||||
display_set_location(&display, 1, 0);
|
||||
|
||||
if (sync_length == 4) {
|
||||
snprintf(msg, 15, ": %x %x %x %x", word[0], word[1], word[2], word[3]);
|
||||
} else {
|
||||
snprintf(msg, 15, "word err");
|
||||
}
|
||||
|
||||
display_write_message(&display, msg);
|
||||
_delay_ms(5000);
|
||||
*/
|
||||
|
||||
/*
|
||||
char msg[16];
|
||||
uint32_t frequency = rfm_frequency(&radio);
|
||||
snprintf(msg, 15, "F: %ld", frequency);
|
||||
display_write_message(&display, msg);
|
||||
_delay_ms(5000);
|
||||
*/
|
||||
|
||||
int clock = 0;
|
||||
while(1) {
|
||||
// char msg[16];
|
||||
// uint8_t packet[66];
|
||||
// uint8_t length;
|
||||
// display_clear(&display);
|
||||
|
||||
// if (length > 0) {
|
||||
// snprintf(msg, 15, "%d ", packet[0]);
|
||||
// display_write_message(&display, msg);
|
||||
// _delay_ms(1000);
|
||||
// }
|
||||
interrupt_flags_t flags = rfm_interrupts(&radio);
|
||||
if (flags.fifo_not_empty) {
|
||||
uint8_t packet[66];
|
||||
uint8_t length;
|
||||
|
||||
rfm_receive(&radio, packet, &length);
|
||||
|
||||
char msg[16];
|
||||
snprintf(msg, 15, "[%d]: %d", length, packet[0]);
|
||||
|
||||
char msg_2[16];
|
||||
snprintf(msg_2, 15, "RSSI: %d", rfm_rssi(&radio));
|
||||
|
||||
display_clear(&display);
|
||||
display_write_message(&display, msg);
|
||||
display_set_location(&display, 1, 0);
|
||||
display_write_message(&display, msg_2);
|
||||
_delay_ms(1000);
|
||||
}
|
||||
|
||||
status(&display, &radio, clock);
|
||||
_delay_ms(1000);
|
||||
clock++;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,346 @@
|
|||
/*
|
||||
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of Savanni's AVR library.
|
||||
|
||||
Lumeto is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Lumeto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include "rfm.h"
|
||||
|
||||
#define REG_FIFO 0x00
|
||||
#define REG_OP_MODE 0x01
|
||||
#define REG_DATA_MODUL 0x02
|
||||
#define REG_BITRATE_MSB 0x03
|
||||
#define REG_BITRATE_LSB 0x04
|
||||
#define REG_FDEV_MSB 0x05
|
||||
#define REG_FDEV_LSB 0x06
|
||||
#define REG_VERSION 0x10
|
||||
#define REG_PA_LEVEL 0x11
|
||||
#define REG_RXBW 0x19
|
||||
#define REG_AFCBW 0x1a
|
||||
#define REG_RSSI_CONFIG 0x23
|
||||
#define REG_RSSI_VALUE 0x24
|
||||
#define REG_DIO_MAPPING1 0x25
|
||||
#define REG_IRQ_FLAGS1 0x27
|
||||
#define REG_IRQ_FLAGS2 0x28
|
||||
#define REG_RSSI_THRESH 0x29
|
||||
#define REG_PREAMBLE_MSB 0x2c
|
||||
#define REG_PREAMBLE_LSB 0x2d
|
||||
#define REG_SYNC_CONFIG 0x2e
|
||||
#define REG_SYNC_VALUE1 0x2f
|
||||
#define REG_PACKET_CONFIG1 0x37
|
||||
#define REG_FIFO_THRESH 0x3c
|
||||
#define REG_TEST_PA1 0x5a
|
||||
#define REG_TEST_PA2 0x5c
|
||||
#define REG_TEST_DAGC 0x6f
|
||||
|
||||
#define PA1_LOW_POWER 0x55
|
||||
#define PA1_HIGH_POWER 0x5D
|
||||
#define PA2_LOW_POWER 0x70
|
||||
#define PA2_HIGH_POWER 0x7C
|
||||
|
||||
void _rfm_write(rfm_t *rfm, uint8_t reg, uint8_t *data, size_t length) {
|
||||
spi_acquire(&rfm->spi);
|
||||
spi_transceive(&rfm->spi, _BV(7) | reg);
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
spi_transceive(&rfm->spi, data[i]);
|
||||
}
|
||||
spi_release(&rfm->spi);
|
||||
}
|
||||
|
||||
void _rfm_read(rfm_t *rfm, uint8_t reg, uint8_t *data, size_t length) {
|
||||
spi_acquire(&rfm->spi);
|
||||
spi_transceive(&rfm->spi, reg);
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
data[i] = spi_transceive(&rfm->spi, 0);
|
||||
}
|
||||
spi_release(&rfm->spi);
|
||||
}
|
||||
|
||||
void _rfm_set_low_power(rfm_t *rfm) {
|
||||
_rfm_write(rfm, REG_TEST_PA1, (uint8_t [1]){ PA1_LOW_POWER }, 1);
|
||||
_rfm_write(rfm, REG_TEST_PA2, (uint8_t [1]){ PA2_LOW_POWER }, 1);
|
||||
}
|
||||
|
||||
void _rfm_set_high_power(rfm_t *rfm) {
|
||||
_rfm_write(rfm, REG_TEST_PA1, (uint8_t [1]){ PA1_HIGH_POWER }, 1);
|
||||
_rfm_write(rfm, REG_TEST_PA2, (uint8_t [1]){ PA2_HIGH_POWER }, 1);
|
||||
}
|
||||
|
||||
void rfm_init(rfm_t *rfm, uint8_t *sync_word, size_t length, rfm_error_e *error) {
|
||||
if (!error) return;
|
||||
|
||||
spi_initialize(&rfm->spi);
|
||||
dio_set_direction(&rfm->irq, LINE_IN);
|
||||
dio_set_direction(&rfm->reset, LINE_OUT);
|
||||
|
||||
rfm_reset(rfm);
|
||||
rfm_sleep(rfm);
|
||||
|
||||
uint8_t version;
|
||||
_rfm_read(rfm, REG_VERSION, &version, 1);
|
||||
if (version != 0x24) {
|
||||
*error = radio_not_found;
|
||||
return;
|
||||
}
|
||||
|
||||
// RadioHead packet format
|
||||
// 4 bytes preamble (done automatically)
|
||||
// 2 Sync words 2d, d4 (configured here, but done automatically)
|
||||
// 2 CRC CCITT octets computed on the header, length, and data (wat?)
|
||||
// 0 to 60 bytes of data
|
||||
// RSSI Threshhold -114dbm
|
||||
// No RFM69HCW adress filtering. Payload has custom headers.
|
||||
|
||||
_rfm_write(rfm, REG_FIFO_THRESH, (uint8_t [1]){ 0x8f }, 1);
|
||||
_rfm_write(rfm, REG_RSSI_THRESH, (uint8_t [1]){ 0xe4 }, 1);
|
||||
|
||||
// Fading margin improvement (3.4.4). Improved Margin, LowBeta off
|
||||
_rfm_write(rfm, REG_TEST_DAGC, (uint8_t [1]){ 0x30 }, 1);
|
||||
|
||||
_rfm_set_low_power(rfm);
|
||||
|
||||
uint8_t syncconfig;
|
||||
_rfm_read(rfm, REG_SYNC_CONFIG, &syncconfig, 1);
|
||||
uint8_t word_base = REG_SYNC_VALUE1;
|
||||
for (int i = 0; i < length; i++) {
|
||||
_rfm_write(rfm, word_base + i, &sync_word[i], 1);
|
||||
}
|
||||
syncconfig &= ~0b00111000;
|
||||
syncconfig |= (length - 1) << 3;
|
||||
_rfm_write(rfm, REG_SYNC_CONFIG, &syncconfig, 1);
|
||||
|
||||
_rfm_write(rfm, REG_PREAMBLE_MSB, (uint8_t [1]){ 0 }, 1);
|
||||
_rfm_write(rfm, REG_PREAMBLE_LSB, (uint8_t [1]){ 4 }, 1);
|
||||
|
||||
// Datamodul: CONFIG_FSK (Packet mode, FSK, no shaping: 0b00000000
|
||||
// BitRateMSB: 0x00
|
||||
// BitRateLSB: 0x80 (oscillator 32,000,000 / bitrate 250kbps = 128 (0x80))
|
||||
// FDEVMSB: 0x10
|
||||
// FDEVLSB: 0x00
|
||||
// RXBW: 0xe0
|
||||
// AFCBW: 0xe0
|
||||
// PacketConfig1: CONFIG_WHITE (variable packet format, whitening on, crc on, no address filtering)
|
||||
|
||||
_rfm_write(rfm, REG_DATA_MODUL, (uint8_t [1]){ 0 }, 1);
|
||||
_rfm_write(rfm, REG_BITRATE_MSB, (uint8_t [1]){ 0 }, 1);
|
||||
_rfm_write(rfm, REG_BITRATE_LSB, (uint8_t [1]){ 0x80 }, 1);
|
||||
_rfm_write(rfm, REG_FDEV_MSB, (uint8_t [1]){ 0x10 }, 1);
|
||||
_rfm_write(rfm, REG_FDEV_LSB, (uint8_t [1]){ 0x00 }, 1);
|
||||
_rfm_write(rfm, REG_RXBW, (uint8_t [1]){ 0xe0 }, 1);
|
||||
_rfm_write(rfm, REG_AFCBW, (uint8_t [1]){ 0xe0 }, 1);
|
||||
_rfm_write(rfm, REG_PACKET_CONFIG1, (uint8_t [1]){ 0b10110000 }, 1);
|
||||
|
||||
// set power level 13dbm
|
||||
// This is super complicated. Dig through the RadioHead library and the documentation and make things better.
|
||||
_rfm_write(rfm, REG_PA_LEVEL, (uint8_t [1]){ 0b11000000 | 31 }, 1);
|
||||
}
|
||||
|
||||
uint8_t sync_word(rfm_t *rfm, uint8_t sync_word[8]) {
|
||||
uint8_t length;
|
||||
|
||||
_rfm_read(rfm, REG_SYNC_CONFIG, &length, 1);
|
||||
length = (length >> 2) & 0b00000111;
|
||||
uint8_t word_base = REG_SYNC_VALUE1;
|
||||
for (int i = 0; i < length; i++) {
|
||||
_rfm_read(rfm, word_base + i, &sync_word[i], 1);
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
void rfm_reset(rfm_t *rfm) {
|
||||
dio_set(&rfm->reset, 1);
|
||||
_delay_us(100);
|
||||
dio_set(&rfm->reset, 0);
|
||||
_delay_us(5);
|
||||
}
|
||||
|
||||
void rfm_packet_format(rfm_t *rfm, packet_format_e format, size_t length) {
|
||||
switch (format) {
|
||||
case unlimited:
|
||||
_rfm_write(rfm, 0x37, (uint8_t [1]){ 0 }, 1);
|
||||
_rfm_write(rfm, 0x38, (uint8_t [1]){ 0 }, 1);
|
||||
break;
|
||||
case fixed:
|
||||
_rfm_write(rfm, 0x37, (uint8_t [1]){ 0 }, 1);
|
||||
_rfm_write(rfm, 0x38, (uint8_t [1]){ length }, 1);
|
||||
break;
|
||||
case variable:
|
||||
_rfm_write(rfm, 0x37, (uint8_t [1]){ _BV(7) }, 1);
|
||||
_rfm_write(rfm, 0x38, (uint8_t [1]){ 0 }, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void rfm_sleep(rfm_t *rfm) {
|
||||
rfm_set_mode(rfm, (op_mode_t){ .listen_on = false, .mode = sleep });
|
||||
}
|
||||
|
||||
void rfm_standby(rfm_t *rfm) {
|
||||
rfm_set_mode(rfm, (op_mode_t){ .listen_on = false, .mode = standby });
|
||||
}
|
||||
|
||||
void rfm_listen(rfm_t *rfm) {
|
||||
rfm_set_mode(rfm, (op_mode_t){ .listen_on = true, .mode = standby });
|
||||
}
|
||||
|
||||
void rfm_transmit(rfm_t *rfm, uint8_t *data, uint8_t length) {
|
||||
rfm_set_mode(rfm, (op_mode_t){ .listen_on = false, .mode = standby });
|
||||
_rfm_set_low_power(rfm);
|
||||
_rfm_write(rfm, REG_FIFO, &length, 1);
|
||||
_rfm_write(rfm, REG_FIFO, (uint8_t *)data, length);
|
||||
_rfm_write(rfm, REG_DIO_MAPPING1, (uint8_t [1]){ 0x00 }, 1);
|
||||
rfm_set_mode(rfm, (op_mode_t){ .listen_on = false, .mode = tx });
|
||||
}
|
||||
|
||||
void rfm_receive_mode(rfm_t *rfm) {
|
||||
_rfm_write(rfm, REG_DIO_MAPPING1, (uint8_t [1]){ _BV(6) }, 1);
|
||||
rfm_set_mode(rfm, (op_mode_t){ .listen_on = false, .mode = rx });
|
||||
}
|
||||
|
||||
void rfm_receive(rfm_t *rfm, uint8_t *data, uint8_t *length) {
|
||||
_rfm_write(rfm, REG_DIO_MAPPING1, (uint8_t [1]){ _BV(6) }, 1);
|
||||
rfm_set_mode(rfm, (op_mode_t){ .listen_on = false, .mode = rx });
|
||||
_rfm_read(rfm, REG_FIFO, length, 1);
|
||||
|
||||
if (*length > 0) {
|
||||
_rfm_read(rfm, 0x00, (uint8_t *)data, *length);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t rfm_temperature(rfm_t *rfm) {
|
||||
uint8_t ready = 0;
|
||||
uint8_t temp;
|
||||
_rfm_write(rfm, 0x4e, (uint8_t [1]){ _BV(3) }, 1);
|
||||
_delay_ms(1);
|
||||
|
||||
uint8_t i = 0;
|
||||
while (!(ready & _BV(2)) && i < 10) {
|
||||
_rfm_read(rfm, 0x4e, &ready, 1);
|
||||
i++;
|
||||
_delay_us(100);
|
||||
}
|
||||
|
||||
_rfm_read(rfm, 0x4f, &temp, 1);
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
op_mode_t rfm_mode(rfm_t *rfm) {
|
||||
op_mode_t op_mode = {
|
||||
.listen_on = false,
|
||||
.mode = sleep,
|
||||
};
|
||||
uint8_t flags;
|
||||
|
||||
_rfm_read(rfm, 0x01, &flags, 1);
|
||||
if (flags & _BV(6)) op_mode.listen_on = 1;
|
||||
op_mode.mode = (flags & 0b00011100) >> 2;
|
||||
|
||||
return op_mode;
|
||||
}
|
||||
|
||||
void rfm_set_mode(rfm_t *rfm, op_mode_t mode) {
|
||||
op_mode_t current = rfm_mode(rfm);
|
||||
uint8_t flags = mode.mode << 2;
|
||||
|
||||
if (mode.listen_on) {
|
||||
flags |= _BV(6);
|
||||
} else if (current.listen_on) {
|
||||
flags |= _BV(5);
|
||||
_rfm_write(rfm, REG_OP_MODE, (uint8_t [1]){ flags }, 1);
|
||||
|
||||
flags = flags & ~_BV(5);
|
||||
}
|
||||
|
||||
_rfm_write(rfm, REG_OP_MODE, (uint8_t [1]){ flags }, 1);
|
||||
}
|
||||
|
||||
uint8_t rfm_status(rfm_t *rfm) {
|
||||
uint8_t status_flag;
|
||||
_rfm_read(rfm, 0x28, &status_flag, 1);
|
||||
return status_flag;
|
||||
}
|
||||
|
||||
uint32_t rfm_frequency(rfm_t *rfm) {
|
||||
uint8_t frequency_bytes[3];
|
||||
uint32_t frequency;
|
||||
_rfm_read(rfm, 0x07, &frequency_bytes[2], 1);
|
||||
_rfm_read(rfm, 0x08, &frequency_bytes[1], 1);
|
||||
_rfm_read(rfm, 0x09, &frequency_bytes[0], 1);
|
||||
|
||||
frequency = frequency_bytes[2];
|
||||
frequency = frequency << 8;
|
||||
frequency += frequency_bytes[1];
|
||||
frequency = frequency << 8;
|
||||
frequency += frequency_bytes[0];
|
||||
return frequency * 61;
|
||||
}
|
||||
|
||||
interrupt_flags_t rfm_interrupts(rfm_t *rfm) {
|
||||
uint8_t irq_1;
|
||||
uint8_t irq_2;
|
||||
interrupt_flags_t flags = {
|
||||
.mode_ready = false,
|
||||
.rx_ready = false,
|
||||
.tx_ready = false,
|
||||
.timeout = false,
|
||||
.auto_mode = false,
|
||||
.sync_addr_match = false,
|
||||
|
||||
.fifo_full = false,
|
||||
.fifo_not_empty = false,
|
||||
.fifo_level = false,
|
||||
.fifo_overrun = false,
|
||||
.packet_sent = false,
|
||||
.payload_ready = false,
|
||||
.crc_ok = false,
|
||||
};
|
||||
|
||||
_rfm_read(rfm, REG_IRQ_FLAGS1, &irq_1, 1);
|
||||
_rfm_read(rfm, REG_IRQ_FLAGS2, &irq_2, 1);
|
||||
|
||||
if (irq_1 & _BV(7)) flags.mode_ready = true;
|
||||
if (irq_1 & _BV(6)) flags.rx_ready = true;
|
||||
if (irq_1 & _BV(5)) flags.tx_ready = true;
|
||||
if (irq_1 & _BV(2)) flags.timeout = true;
|
||||
if (irq_1 & _BV(1)) flags.auto_mode = true;
|
||||
if (irq_1 & _BV(0)) flags.sync_addr_match = true;
|
||||
|
||||
if (irq_2 & _BV(7)) flags.fifo_full = true;
|
||||
if (irq_2 & _BV(6)) flags.fifo_not_empty = true;
|
||||
if (irq_2 & _BV(5)) flags.fifo_level = true;
|
||||
if (irq_2 & _BV(4)) flags.fifo_overrun = true;
|
||||
if (irq_2 & _BV(3)) flags.packet_sent = true;
|
||||
if (irq_2 & _BV(2)) flags.payload_ready = true;
|
||||
if (irq_2 & _BV(1)) flags.crc_ok = true;
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
uint8_t rfm_rssi(rfm_t *rfm) {
|
||||
// uint8_t rssi_reg;
|
||||
uint8_t rssi_value;
|
||||
|
||||
/*
|
||||
_rfm_write(rfm, REG_RSSI_CONFIG, (uint8_t [1]){ _BV(0) }, 1);
|
||||
|
||||
while(!(rssi_reg & _BV(1))) {
|
||||
_rfm_read(rfm, REG_RSSI_CONFIG, &rssi_reg, 1);
|
||||
}
|
||||
*/
|
||||
|
||||
_rfm_read(rfm, REG_RSSI_VALUE, &rssi_value, 1);
|
||||
|
||||
return rssi_value;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of Savanni's AVR library.
|
||||
|
||||
Lumeto is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Lumeto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __RFM_H__
|
||||
#define __RFM_H__
|
||||
|
||||
#include <dio.h>
|
||||
#include <spi.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef enum RFM_ERROR_TYPES {
|
||||
Ok,
|
||||
radio_not_found,
|
||||
} rfm_error_e;
|
||||
|
||||
typedef struct RFM {
|
||||
spi_t spi;
|
||||
dio_t irq;
|
||||
dio_t reset;
|
||||
} rfm_t;
|
||||
|
||||
typedef enum packet_format {
|
||||
unlimited,
|
||||
fixed,
|
||||
variable,
|
||||
} packet_format_e;
|
||||
|
||||
typedef enum MODE {
|
||||
sleep,
|
||||
standby,
|
||||
fs,
|
||||
tx,
|
||||
rx,
|
||||
listen
|
||||
} mode_e;
|
||||
|
||||
/* make mode more of a state machine. define the transitions between those machines. */
|
||||
typedef struct MODE_FLAGS {
|
||||
bool listen_on;
|
||||
mode_e mode;
|
||||
} op_mode_t;
|
||||
|
||||
typedef struct INTERRUPT_FLAGS {
|
||||
bool mode_ready;
|
||||
bool rx_ready;
|
||||
bool tx_ready;
|
||||
bool timeout;
|
||||
bool auto_mode;
|
||||
bool sync_addr_match;
|
||||
|
||||
bool fifo_full;
|
||||
bool fifo_not_empty;
|
||||
bool fifo_level;
|
||||
bool fifo_overrun;
|
||||
bool packet_sent;
|
||||
bool payload_ready;
|
||||
bool crc_ok;
|
||||
} interrupt_flags_t;
|
||||
|
||||
void rfm_init(rfm_t *, uint8_t *, size_t, rfm_error_e *);
|
||||
uint8_t sync_word(rfm_t *rfm, uint8_t sync_word[8]);
|
||||
void rfm_reset(rfm_t *);
|
||||
|
||||
void rfm_packet_format(rfm_t *rfm, packet_format_e format, size_t length);
|
||||
|
||||
void rfm_sleep(rfm_t *);
|
||||
void rfm_standby(rfm_t *);
|
||||
void rfm_receive_mode(rfm_t *);
|
||||
void rfm_transmit(rfm_t *rfm, uint8_t *data, uint8_t length);
|
||||
void rfm_receive(rfm_t *rfm, uint8_t *data, uint8_t *length);
|
||||
|
||||
op_mode_t rfm_mode(rfm_t *rfm);
|
||||
void rfm_set_mode(rfm_t *rfm, op_mode_t mode);
|
||||
|
||||
uint8_t rfm_status(rfm_t *rfm);
|
||||
uint8_t rfm_temperature(rfm_t *rfm);
|
||||
uint32_t rfm_frequency(rfm_t *rfm);
|
||||
|
||||
void rfm_listen(rfm_t *rfm);
|
||||
interrupt_flags_t rfm_interrupts(rfm_t *rfm);
|
||||
|
||||
uint8_t rfm_rssi(rfm_t *rfm);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of Savanni's AVR library.
|
||||
|
||||
Lumeto is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Lumeto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <util/delay.h>
|
||||
#include <dio.h>
|
||||
#include "shift_register.h"
|
||||
|
||||
void sr_strobe_line(dio_t *line) {
|
||||
dio_set(line, 1);
|
||||
_delay_us(1);
|
||||
dio_set(line, 0);
|
||||
}
|
||||
|
||||
void sr_initialize(shift_register_t *reg) {
|
||||
dio_set_direction(®->output, LINE_OUT);
|
||||
dio_set_direction(®->shift_clock, LINE_OUT);
|
||||
dio_set_direction(®->latch_clock, LINE_OUT);
|
||||
|
||||
dio_set(®->output, 0);
|
||||
dio_set(®->shift_clock, 0);
|
||||
dio_set(®->latch_clock, 0);
|
||||
}
|
||||
|
||||
void sr_send_lsb(shift_register_t *reg, uint8_t byte) {
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
byte & _BV(i) ? dio_set(®->output, 1) : dio_set(®->output, 0);
|
||||
sr_strobe_line(®->shift_clock);
|
||||
}
|
||||
dio_set(®->output, 0);
|
||||
sr_strobe_line(®->latch_clock);
|
||||
}
|
||||
|
||||
void sr_send_msb(shift_register_t *reg, uint8_t byte) {
|
||||
for (int8_t i = 7; i >= 0; i--) {
|
||||
byte & _BV(i) ? dio_set(®->output, 1) : dio_set(®->output, 0);
|
||||
sr_strobe_line(®->shift_clock);
|
||||
}
|
||||
dio_set(®->output, 0);
|
||||
sr_strobe_line(®->latch_clock);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of Savanni's AVR library.
|
||||
|
||||
Lumeto is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Lumeto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __REG_H__
|
||||
#define __REG_H__
|
||||
|
||||
#include <dio.h>
|
||||
|
||||
typedef struct SHIFT_REGISTER {
|
||||
dio_t output;
|
||||
dio_t shift_clock;
|
||||
dio_t latch_clock;
|
||||
} shift_register_t;
|
||||
|
||||
|
||||
void sr_initialize(shift_register_t *reg);
|
||||
void sr_send_lsb(shift_register_t *reg, uint8_t byte);
|
||||
void sr_send_msb(shift_register_t *reg, uint8_t byte);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of Savanni's AVR library.
|
||||
|
||||
Lumeto is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Lumeto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "sk9822.h"
|
||||
|
||||
void send_byte(dio_t data_pin, dio_t clock_pin, uint8_t byte) {
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
dio_set(&data_pin, byte & _BV(i));
|
||||
|
||||
dio_set(&clock_pin, 1);
|
||||
dio_set(&clock_pin, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void send_start(dio_t data_pin, dio_t clock_pin) {
|
||||
dio_set(&clock_pin, 0);
|
||||
send_byte(data_pin, clock_pin, 0);
|
||||
send_byte(data_pin, clock_pin, 0);
|
||||
send_byte(data_pin, clock_pin, 0);
|
||||
send_byte(data_pin, clock_pin, 0);
|
||||
}
|
||||
|
||||
void send_term(dio_t data_pin, dio_t clock_pin) {
|
||||
send_byte(data_pin, clock_pin, 0xff);
|
||||
send_byte(data_pin, clock_pin, 0xff);
|
||||
send_byte(data_pin, clock_pin, 0xff);
|
||||
send_byte(data_pin, clock_pin, 0xff);
|
||||
dio_set(&clock_pin, 1);
|
||||
}
|
||||
|
||||
void sk9822_init(sk9822_t *lights) {
|
||||
dio_set_direction(&lights->data_pin, LINE_OUT);
|
||||
dio_set_direction(&lights->clock_pin, LINE_OUT);
|
||||
}
|
||||
|
||||
void sk9822_send(sk9822_t *lights, rgb_t * pixels, uint8_t count) {
|
||||
send_start(lights->data_pin, lights->clock_pin);
|
||||
for (uint8_t i = 0; i < count; i++) {
|
||||
send_byte(lights->data_pin, lights->clock_pin, 0xe0 + pixels[i].brightness);
|
||||
send_byte(lights->data_pin, lights->clock_pin, pixels[i].r);
|
||||
send_byte(lights->data_pin, lights->clock_pin, pixels[i].b);
|
||||
send_byte(lights->data_pin, lights->clock_pin, pixels[i].g);
|
||||
}
|
||||
send_term(lights->data_pin, lights->clock_pin);
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of Savanni's AVR library.
|
||||
|
||||
This AVR library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
This AVR library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with this AVR library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <dio.h>
|
||||
|
||||
#ifndef __SK9822_H__
|
||||
#define __SK9822_H__
|
||||
|
||||
typedef struct RGB_s {
|
||||
uint8_t brightness;
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
} rgb_t;
|
||||
|
||||
typedef struct SK9822 {
|
||||
dio_t data_pin;
|
||||
dio_t clock_pin;
|
||||
} sk9822_t;
|
||||
|
||||
void sk9822_init(sk9822_t *lights);
|
||||
|
||||
void sk9822_send(sk9822_t *lights, rgb_t *pixels, uint8_t count);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of Savanni's AVR library.
|
||||
|
||||
Lumeto is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Lumeto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <util/delay.h>
|
||||
#include "spi.h"
|
||||
|
||||
void spi_initialize(spi_t *spi) {
|
||||
dio_set_direction(&spi->clock, LINE_OUT);
|
||||
dio_set_direction(&spi->data_out, LINE_OUT);
|
||||
dio_set_direction(&spi->data_in, LINE_IN);
|
||||
dio_set_direction(&spi->chip_select, LINE_OUT);
|
||||
|
||||
dio_set(&spi->chip_select, 1);
|
||||
}
|
||||
|
||||
void spi_acquire(spi_t *spi) {
|
||||
dio_set(&spi->chip_select, 0);
|
||||
}
|
||||
|
||||
void spi_release(spi_t *spi) {
|
||||
dio_set(&spi->chip_select, 1);
|
||||
}
|
||||
|
||||
uint8_t spi_transceive(spi_t *spi, uint8_t output) {
|
||||
uint8_t input = 0;
|
||||
int input_bit;
|
||||
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
dio_set(&spi->clock, 0);
|
||||
if (output & _BV(i)) {
|
||||
dio_set(&spi->data_out, 1);
|
||||
} else {
|
||||
dio_set(&spi->data_out, 0);
|
||||
}
|
||||
_delay_us(10);
|
||||
dio_set(&spi->clock, 1);
|
||||
input_bit = dio_read(&spi->data_in);
|
||||
input = (input << 1) | input_bit;
|
||||
_delay_us(10);
|
||||
}
|
||||
dio_set(&spi->clock, 0);
|
||||
_delay_us(10);
|
||||
return input;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of Savanni's AVR library.
|
||||
|
||||
Lumeto is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Lumeto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __MORSE_H__
|
||||
#define __MORSE_H__
|
||||
|
||||
#include <dio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct SPI {
|
||||
dio_t clock;
|
||||
dio_t data_out;
|
||||
dio_t data_in;
|
||||
dio_t chip_select;
|
||||
} spi_t;
|
||||
|
||||
void spi_initialize(spi_t *spi);
|
||||
void spi_acquire(spi_t *spi);
|
||||
void spi_release(spi_t *spi);
|
||||
uint8_t spi_transceive(spi_t *spi, uint8_t output);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of Savanni's AVR library.
|
||||
|
||||
This AVR library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
This AVR library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __TIMER_H__
|
||||
#define __TIMER_H__
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
// ATmega16U4/32U4 Datasheet, table 14.4, page 133
|
||||
typedef enum {
|
||||
normal,
|
||||
pwm_phasecorrect_8bit,
|
||||
pwm_phasecorrect_9bit,
|
||||
pwm_phasecorrect_10bit,
|
||||
ctc,
|
||||
fast_pwm_8bit,
|
||||
fast_pwm_9bit,
|
||||
fast_pwm_10bit,
|
||||
pwm_phase_and_frequency_correct_icrtop,
|
||||
pwm_phase_and_frequency_correct_ocrtop,
|
||||
pwm_phase_correct_icrtop,
|
||||
pwm_phase_correct_ocrtop,
|
||||
ctc_icr,
|
||||
fast_pwm_icrtop,
|
||||
fast_pwm_ocrtop,
|
||||
} timer_mode_t;
|
||||
|
||||
// Clock prescaler selector, ATmega16U4/32U4 Datasheet, table 14.5, page 1354p
|
||||
typedef enum {
|
||||
none,
|
||||
clk_1,
|
||||
clk_8,
|
||||
clk_64,
|
||||
clk_256,
|
||||
clk_1024,
|
||||
external_falling_edge,
|
||||
external_rising_edge,
|
||||
} clock_select_t;
|
||||
|
||||
typedef struct {
|
||||
volatile uint8_t count_msb;
|
||||
volatile uint8_t count_lsb;
|
||||
volatile uint8_t top_msb;
|
||||
volatile uint8_t top_lsb;
|
||||
} timer_16bit_t;
|
||||
|
||||
#endif
|
|
@ -0,0 +1,52 @@
|
|||
// I have reduced noops at the end of each of these to take into account that there are several additional clock ticks of setup, after. However, I'm not totally sure that I get things right, seeing that there are four possible sequences, and I'm not really accounting for the timing of all four of them.
|
||||
#define write_zero(port, bit) \
|
||||
__asm__ __volatile__ ( \
|
||||
"sbi %0, %1" "\n\t" \
|
||||
"nop" "\n\t" \
|
||||
"cbi %0, %1" "\n\t" \
|
||||
"nop" "\n\t" \
|
||||
: /* no outputs */ \
|
||||
: "I" (_SFR_IO_ADDR(port)), \
|
||||
"I" (bit) \
|
||||
)
|
||||
|
||||
#define write_one(port, bit) \
|
||||
__asm__ __volatile__ ( \
|
||||
"sbi %0, %1" "\n\t" \
|
||||
"nop" "\n\t" \
|
||||
"nop" "\n\t" \
|
||||
"nop" "\n\t" \
|
||||
"nop" "\n\t" \
|
||||
"nop" "\n\t" \
|
||||
"cbi %0, %1" "\n\t" \
|
||||
: /* no outputs */ \
|
||||
: "I" (_SFR_IO_ADDR(port)), \
|
||||
"I" (bit) \
|
||||
)
|
||||
|
||||
#define write_byte(port, bit, byte) \
|
||||
__asm__ __volatile__ ( \
|
||||
; count out eight bits \
|
||||
"ldi %z, 8" "\n\t" \
|
||||
; load the current byte into a temporary register \
|
||||
"ld __tmp_reg__, %[byte]" "\n\t" \
|
||||
; shift the temporary register left, saving the msb in SREG (1 cycle) \
|
||||
"L_%=: " "lsl __tmp_reg__" "\n\t" \
|
||||
; if SREG is set, branch to I_%= (2 cycles if true, 1 cycle if false) \
|
||||
"brbs I_%=" "\n\t" \
|
||||
; SREG was zero, so write a zero to the port \
|
||||
write_zero(port, bit) \
|
||||
; Jump to J_%=, the loop cleanup (2 cycles) \
|
||||
"rjmp J_%=" "\n\t" \
|
||||
; SREG was one, so write a one to the port \
|
||||
"I_%=: " write_one(port, bit) \
|
||||
; Decrement the bits counter (1 cycle) \
|
||||
"J_%=: " "dec %z" "\n\t" \
|
||||
; are there any bits left to send? (1 cycle) \
|
||||
"cpi %z, 0" "\n\t" \
|
||||
; there are, so go back to L_%= (2 cycles) \
|
||||
"brne L_%=" "\n\t" \
|
||||
: /* no outputs */ \
|
||||
: [byte] "I" (byte) \
|
||||
)
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
#include <dio.h>
|
||||
#include "ws2812.h"
|
||||
|
||||
/*
|
||||
#include <simavr/avr/avr_mcu_section.h>
|
||||
AVR_MCU(F_CPU, "attiny85");
|
||||
|
||||
const struct avr_mmcu_vcd_trace_t _mytrace[] _MMCU_ = {
|
||||
{ AVR_MCU_VCD_SYMBOL("DDRB"), .what = (void*)&DDRB, },
|
||||
{ AVR_MCU_VCD_SYMBOL("PORTB"), .what = (void*)&PORTB, },
|
||||
};
|
||||
*/
|
||||
|
||||
#define PIXEL_COUNT 1
|
||||
const rgb_t pixels[PIXEL_COUNT] = {
|
||||
(rgb_t){ .r = 255, .g = 0, .b = 255, },
|
||||
};
|
||||
|
||||
int main (void) {
|
||||
dio_t pin = (dio_t){ .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 2 };
|
||||
dio_set_direction(&pin, LINE_OUT);
|
||||
|
||||
np_write_rgb(&pin, pixels, PIXEL_COUNT);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
#include <avr/interrupt.h>
|
||||
# include "ws2812.h"
|
||||
|
||||
// inline void write_zero(dio_t *pin, uint8_t hi, uint8_t low) {
|
||||
// uint8_t *val;
|
||||
// uint8_t *hi_reg;
|
||||
// uint8_t *low_reg;
|
||||
// __asm__ __volatile__ (
|
||||
// "ldd %[hi_reg], %[hi]\n"
|
||||
// "ldd %[low_reg], %[low]\n"
|
||||
// "ldd %[val], %[pin]\n"
|
||||
// "or %[val], %[hi_reg]\n"
|
||||
// "std %[pin], %[val]\n"
|
||||
// "nop\n"
|
||||
// "nop\n"
|
||||
// "and %[val], %[hi_reg]\n"
|
||||
// "std %[pin], %[val]\n"
|
||||
// "nop\n"
|
||||
// "nop\n"
|
||||
// "nop\n"
|
||||
// /* Need another 5 cycles */
|
||||
// : [val] "=r" (val), [hi_reg] "=r" (hi_reg), [low_reg] "=r" (low_reg)
|
||||
// : [pin] "m" (pin->port), [hi] "m" (hi), [low] "m" (low)
|
||||
// );
|
||||
// }
|
||||
|
||||
|
||||
// inline void write_one(dio_t *port, uint8_t hi, uint8_t low) {
|
||||
// __asm__ __volatile__ (
|
||||
// "or %0, %1\n"
|
||||
// "nop\n"
|
||||
// "nop\n"
|
||||
// "nop\n"
|
||||
// "nop\n"
|
||||
// "nop\n"
|
||||
// "nop\n"
|
||||
// "and %0, %1\n"
|
||||
// /* Need another 5 cycles */
|
||||
// : /* no outputs */
|
||||
// : "m" (port->port),
|
||||
// "m" (hi),
|
||||
// "m" (low)
|
||||
// );
|
||||
// }
|
||||
|
||||
inline void write_byte(dio_t *pin, uint8_t hi, uint8_t low, const uint8_t value) {
|
||||
uint8_t *state_r;
|
||||
uint8_t *hi_r;
|
||||
uint8_t *low_r;
|
||||
uint8_t *counter;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"ldi r16, 8\n"
|
||||
"ldi r17, %[value]\n"
|
||||
"ldd %[hi_r], %[hi]\n"
|
||||
"ldd %[low_r], %[low]\n"
|
||||
"ldd %[state_r], %[pin]\n"
|
||||
|
||||
"L_%=: " "lsl __tmp_reg__\n"
|
||||
"brbs I_%=\n"
|
||||
"or %[state_r], %[hi_r]\n"
|
||||
"nop\n"
|
||||
"nop\n"
|
||||
"and %[state_r], %[low_r]\n"
|
||||
"nop\n"
|
||||
"nop\n"
|
||||
"nop\n"
|
||||
"rjmp J_%=\n"
|
||||
|
||||
"I_%=: "
|
||||
"brbs I_%=\n"
|
||||
"or %[state_r], %[hi_r]\n"
|
||||
"nop\n"
|
||||
"nop\n"
|
||||
"nop\n"
|
||||
"nop\n"
|
||||
"nop\n"
|
||||
"and %[state_r], %[low_r]\n"
|
||||
|
||||
"J_%=: " "dec %[counter]\n"
|
||||
"cpi %[counter], 0\n"
|
||||
"brne L_%="
|
||||
|
||||
: [state_r] "=r" (state_r),
|
||||
[hi_r] "=r" (hi_r),
|
||||
[low_r] "=r" (low_r),
|
||||
[counter] "=r" (counter)
|
||||
|
||||
: [pin] "m" (pin->port),
|
||||
[hi] "m" (hi),
|
||||
[low] "m" (low),
|
||||
[value] "m" (value)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void np_write_rgb(dio_t *pin, const rgb_t *pixels, uint8_t length) {
|
||||
cli();
|
||||
uint8_t hi = 1 << pin->addr;
|
||||
uint8_t low = ~hi;
|
||||
for (int idx = 0; idx < length; idx++) {
|
||||
write_byte(pin, hi, low, pixels[idx].r);
|
||||
write_byte(pin, hi, low, pixels[idx].g);
|
||||
write_byte(pin, hi, low, pixels[idx].b);
|
||||
}
|
||||
sei();
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef __neopixels_h__
|
||||
#define __neopixels_h__
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <dio.h>
|
||||
|
||||
typedef struct RGB_s {
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
} rgb_t;
|
||||
|
||||
typedef struct RGBW_s {
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
uint8_t w;
|
||||
} rgbw_t;
|
||||
|
||||
// void np_initialize();
|
||||
void np_write_rgb(dio_t *, const rgb_t *, uint8_t);
|
||||
// void np_write_grb(io_pin_t *addr, rgb_t *values, uint8_t length);
|
||||
// void np_write_rgbw(io_pin_t *addr, rgbw_t *values, uint8_t length);
|
||||
// void np_write_grbw(io_pin_t *addr, rgbw_t *values, uint8_t length);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue