Compare commits
No commits in common. "c5788c5b2e1f930fa5de87cf7d14cb3de0d251c8" and "c0ff27a40e707cc4a80a47b3890177e7128a98dc" have entirely different histories.
c5788c5b2e
...
c0ff27a40e
|
@ -0,0 +1,8 @@
|
|||
[build]
|
||||
target = "avr-specs/avr-atmega32u4.json"
|
||||
|
||||
[target.'cfg(target_arch = "avr")']
|
||||
runner = "ravedude promicro"
|
||||
|
||||
[unstable]
|
||||
build-std = ["core"]
|
|
@ -0,0 +1,327 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "arduino-hal"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/rahix/avr-hal?rev=3e362624547462928a219c40f9ea8e3a64f21e5f#3e362624547462928a219c40f9ea8e3a64f21e5f"
|
||||
dependencies = [
|
||||
"atmega-hal",
|
||||
"avr-device",
|
||||
"avr-hal-generic",
|
||||
"cfg-if 1.0.0",
|
||||
"embedded-hal 0.2.7",
|
||||
"embedded-hal 1.0.0",
|
||||
"ufmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atmega-hal"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/rahix/avr-hal?rev=3e362624547462928a219c40f9ea8e3a64f21e5f#3e362624547462928a219c40f9ea8e3a64f21e5f"
|
||||
dependencies = [
|
||||
"avr-device",
|
||||
"avr-hal-generic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "avr-device"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "546b09da5e933d18b790ccb5aae351371c6c4f8094a7b011dcd7c7e7fb69cc94"
|
||||
dependencies = [
|
||||
"avr-device-macros",
|
||||
"bare-metal",
|
||||
"cfg-if 1.0.0",
|
||||
"vcell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "avr-device-macros"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b108541dc1ea060dfa9b824acbded94f658f8daecca549144d05a4d01e65b6f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "avr-hal-generic"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/rahix/avr-hal?rev=3e362624547462928a219c40f9ea8e3a64f21e5f#3e362624547462928a219c40f9ea8e3a64f21e5f"
|
||||
dependencies = [
|
||||
"avr-device",
|
||||
"cfg-if 0.1.10",
|
||||
"embedded-hal 0.2.7",
|
||||
"embedded-hal 1.0.0",
|
||||
"embedded-hal-bus",
|
||||
"embedded-storage",
|
||||
"nb 1.1.0",
|
||||
"paste",
|
||||
"rustversion",
|
||||
"ufmt",
|
||||
"unwrap-infallible",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bare-metal"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8fe8f5a8a398345e52358e18ff07cc17a568fbca5c6f73873d3a62056309603"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "crc8-rs"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89060ba4e10f285118d597b628878335d4fd67dd042f182aeec32a1f15215f69"
|
||||
|
||||
[[package]]
|
||||
name = "critical-section"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
|
||||
|
||||
[[package]]
|
||||
name = "embedded-hal"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "35949884794ad573cf46071e41c9b60efb0cb311e3ca01f7af807af1debc66ff"
|
||||
dependencies = [
|
||||
"nb 0.1.3",
|
||||
"void",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embedded-hal"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89"
|
||||
|
||||
[[package]]
|
||||
name = "embedded-hal-bus"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57b4e6ede84339ebdb418cd986e6320a34b017cdf99b5cc3efceec6450b06886"
|
||||
dependencies = [
|
||||
"critical-section",
|
||||
"embedded-hal 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embedded-storage"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "723dce4e9f25b6e6c5f35628e144794e5b459216ed7da97b7c4b66cdb3fa82ca"
|
||||
|
||||
[[package]]
|
||||
name = "hash32"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heapless"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad"
|
||||
dependencies = [
|
||||
"hash32",
|
||||
"stable_deref_trait",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "muon"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"arduino-hal",
|
||||
"avr-device",
|
||||
"crc8-rs",
|
||||
"embedded-hal 1.0.0",
|
||||
"heapless",
|
||||
"nb 1.1.0",
|
||||
"one-wire-bus",
|
||||
"panic-halt",
|
||||
"static_pins",
|
||||
"ufmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nb"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f"
|
||||
dependencies = [
|
||||
"nb 1.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nb"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
|
||||
|
||||
[[package]]
|
||||
name = "one-wire-bus"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a9761e13074f8f916702c1a1dbe0eda3fb8478704db00493f5a5c27ed5847710"
|
||||
dependencies = [
|
||||
"embedded-hal 0.2.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "panic-halt"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "de96540e0ebde571dc55c73d60ef407c653844e6f9a1e2fdbd40c07b9252d812"
|
||||
|
||||
[[package]]
|
||||
name = "paste"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.94"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2"
|
||||
|
||||
[[package]]
|
||||
name = "stable_deref_trait"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
|
||||
|
||||
[[package]]
|
||||
name = "static_pins"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"arduino-hal",
|
||||
"static_pins_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "static_pins_macros"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"arduino-hal",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ufmt"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a64846ec02b57e9108d6469d98d1648782ad6bb150a95a9baac26900bbeab9d"
|
||||
dependencies = [
|
||||
"ufmt-macros",
|
||||
"ufmt-write",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ufmt-macros"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d337d3be617449165cb4633c8dece429afd83f84051024079f97ad32a9663716"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ufmt-write"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e87a2ed6b42ec5e28cc3b94c09982969e9227600b2e3dcbc1db927a84c06bd69"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
||||
|
||||
[[package]]
|
||||
name = "unwrap-infallible"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb"
|
||||
|
||||
[[package]]
|
||||
name = "vcell"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002"
|
||||
|
||||
[[package]]
|
||||
name = "void"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
|
38
Cargo.toml
38
Cargo.toml
|
@ -1,22 +1,50 @@
|
|||
[package]
|
||||
name = "usb_avr"
|
||||
name = "muon"
|
||||
version = "0.1.0"
|
||||
authors = ["doryan <sagiev2015@yandex.ru>"]
|
||||
edition = "2021"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[[bin]]
|
||||
name = "muon"
|
||||
test = false
|
||||
bench = false
|
||||
|
||||
[dependencies]
|
||||
panic-halt = "0.2.0"
|
||||
ufmt = "0.2.0"
|
||||
nb = "1.1.0"
|
||||
embedded-hal = "1.0"
|
||||
usb-device = "0.3.2"
|
||||
heapless = "0.8.0"
|
||||
crc8-rs = "1.1.1"
|
||||
one-wire-bus = "0.1.1"
|
||||
|
||||
[dependencies.arduino-hal]
|
||||
git = "https://github.com/rahix/avr-hal"
|
||||
rev = "3e362624547462928a219c40f9ea8e3a64f21e5f"
|
||||
features = ["sparkfun-promicro"]
|
||||
|
||||
[dependencies.static_pins]
|
||||
path = "static_pins"
|
||||
|
||||
[dependencies.avr-device]
|
||||
version = "0.5.4"
|
||||
features = ["atmega32u4"]
|
||||
|
||||
# The latest releases of `proc-macro2` do not support the rust toolchain that
|
||||
# we use. Thus, we must fix this dependency to an older version where our
|
||||
# toolchain is still supported. See https://github.com/Rahix/avr-hal/issues/537
|
||||
[build-dependencies.proc-macro2]
|
||||
version = "=1.0.79"
|
||||
# [build-dependencies.proc-macro2]
|
||||
# version = "=1.0.79"
|
||||
|
||||
# Configure the build for minimal size - AVRs have very little program memory
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
codegen-units = 1
|
||||
debug = true
|
||||
lto = true
|
||||
opt-level = "s"
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
lto = true
|
||||
opt-level = "s"
|
||||
|
|
|
@ -0,0 +1,201 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) [year] [fullname]
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,34 @@
|
|||
one-wire
|
||||
========
|
||||
|
||||
Rust project for the _SparkFun ProMicro_.
|
||||
|
||||
## Build Instructions
|
||||
1. Install prerequisites as described in the [`avr-hal` README] (`avr-gcc`, `avr-libc`, `avrdude`, [`ravedude`]).
|
||||
|
||||
2. Run `cargo build` to build the firmware.
|
||||
|
||||
3. Run `cargo run` to flash the firmware to a connected board. If `ravedude`
|
||||
fails to detect your board, check its documentation at
|
||||
<https://crates.io/crates/ravedude>.
|
||||
|
||||
4. `ravedude` will open a console session after flashing where you can interact
|
||||
with the UART console of your board.
|
||||
|
||||
[`avr-hal` README]: https://github.com/Rahix/avr-hal#readme
|
||||
[`ravedude`]: https://crates.io/crates/ravedude
|
||||
|
||||
## License
|
||||
Licensed under either of
|
||||
|
||||
- Apache License, Version 2.0
|
||||
([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
|
||||
- MIT license
|
||||
([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
|
||||
|
||||
at your option.
|
||||
|
||||
## Contribution
|
||||
Unless you explicitly state otherwise, any contribution intentionally submitted
|
||||
for inclusion in the work by you, as defined in the Apache-2.0 license, shall
|
||||
be dual licensed as above, without any additional terms or conditions.
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"arch": "avr",
|
||||
"atomic-cas": false,
|
||||
"cpu": "atmega1280",
|
||||
"crt-objects-fallback": "false",
|
||||
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||
"eh-frame-header": false,
|
||||
"exe-suffix": ".elf",
|
||||
"late-link-args": {
|
||||
"gnu-cc": [
|
||||
"-lgcc"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-lgcc"
|
||||
]
|
||||
},
|
||||
"linker": "avr-gcc",
|
||||
"linker-flavor": "gnu-cc",
|
||||
"llvm-target": "avr-unknown-unknown",
|
||||
"max-atomic-width": 8,
|
||||
"metadata": {
|
||||
"description": null,
|
||||
"host_tools": null,
|
||||
"std": null,
|
||||
"tier": null
|
||||
},
|
||||
"no-default-libraries": false,
|
||||
"pre-link-args": {
|
||||
"gnu-cc": [
|
||||
"-mmcu=atmega1280",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-mmcu=atmega1280",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
]
|
||||
},
|
||||
"relocation-model": "static",
|
||||
"target-c-int-width": "16",
|
||||
"target-pointer-width": "16"
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"arch": "avr",
|
||||
"atomic-cas": false,
|
||||
"cpu": "atmega1284p",
|
||||
"crt-objects-fallback": "false",
|
||||
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||
"eh-frame-header": false,
|
||||
"exe-suffix": ".elf",
|
||||
"late-link-args": {
|
||||
"gnu-cc": [
|
||||
"-lgcc"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-lgcc"
|
||||
]
|
||||
},
|
||||
"linker": "avr-gcc",
|
||||
"linker-flavor": "gnu-cc",
|
||||
"llvm-target": "avr-unknown-unknown",
|
||||
"max-atomic-width": 8,
|
||||
"metadata": {
|
||||
"description": null,
|
||||
"host_tools": null,
|
||||
"std": null,
|
||||
"tier": null
|
||||
},
|
||||
"no-default-libraries": false,
|
||||
"pre-link-args": {
|
||||
"gnu-cc": [
|
||||
"-mmcu=atmega1284p",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-mmcu=atmega1284p",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
]
|
||||
},
|
||||
"relocation-model": "static",
|
||||
"target-c-int-width": "16",
|
||||
"target-pointer-width": "16"
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"arch": "avr",
|
||||
"atomic-cas": false,
|
||||
"cpu": "atmega128a",
|
||||
"crt-objects-fallback": "false",
|
||||
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||
"eh-frame-header": false,
|
||||
"exe-suffix": ".elf",
|
||||
"late-link-args": {
|
||||
"gnu-cc": [
|
||||
"-lgcc"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-lgcc"
|
||||
]
|
||||
},
|
||||
"linker": "avr-gcc",
|
||||
"linker-flavor": "gnu-cc",
|
||||
"llvm-target": "avr-unknown-unknown",
|
||||
"max-atomic-width": 8,
|
||||
"metadata": {
|
||||
"description": null,
|
||||
"host_tools": null,
|
||||
"std": null,
|
||||
"tier": null
|
||||
},
|
||||
"no-default-libraries": false,
|
||||
"pre-link-args": {
|
||||
"gnu-cc": [
|
||||
"-mmcu=atmega128a",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-mmcu=atmega128a",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
]
|
||||
},
|
||||
"relocation-model": "static",
|
||||
"target-c-int-width": "16",
|
||||
"target-pointer-width": "16"
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"arch": "avr",
|
||||
"atomic-cas": false,
|
||||
"cpu": "atmega164pa",
|
||||
"crt-objects-fallback": "false",
|
||||
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||
"eh-frame-header": false,
|
||||
"exe-suffix": ".elf",
|
||||
"late-link-args": {
|
||||
"gnu-cc": [
|
||||
"-lgcc"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-lgcc"
|
||||
]
|
||||
},
|
||||
"linker": "avr-gcc",
|
||||
"linker-flavor": "gnu-cc",
|
||||
"llvm-target": "avr-unknown-unknown",
|
||||
"max-atomic-width": 8,
|
||||
"metadata": {
|
||||
"description": null,
|
||||
"host_tools": null,
|
||||
"std": null,
|
||||
"tier": null
|
||||
},
|
||||
"no-default-libraries": false,
|
||||
"pre-link-args": {
|
||||
"gnu-cc": [
|
||||
"-mmcu=atmega164pa",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-mmcu=atmega164pa",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
]
|
||||
},
|
||||
"relocation-model": "static",
|
||||
"target-c-int-width": "16",
|
||||
"target-pointer-width": "16"
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"arch": "avr",
|
||||
"atomic-cas": false,
|
||||
"cpu": "atmega168",
|
||||
"crt-objects-fallback": "false",
|
||||
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||
"eh-frame-header": false,
|
||||
"exe-suffix": ".elf",
|
||||
"late-link-args": {
|
||||
"gnu-cc": [
|
||||
"-lgcc"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-lgcc"
|
||||
]
|
||||
},
|
||||
"linker": "avr-gcc",
|
||||
"linker-flavor": "gnu-cc",
|
||||
"llvm-target": "avr-unknown-unknown",
|
||||
"max-atomic-width": 8,
|
||||
"metadata": {
|
||||
"description": null,
|
||||
"host_tools": null,
|
||||
"std": null,
|
||||
"tier": null
|
||||
},
|
||||
"no-default-libraries": false,
|
||||
"pre-link-args": {
|
||||
"gnu-cc": [
|
||||
"-mmcu=atmega168",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-mmcu=atmega168",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
]
|
||||
},
|
||||
"relocation-model": "static",
|
||||
"target-c-int-width": "16",
|
||||
"target-pointer-width": "16"
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"arch": "avr",
|
||||
"atomic-cas": false,
|
||||
"cpu": "atmega2560",
|
||||
"crt-objects-fallback": "false",
|
||||
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||
"eh-frame-header": false,
|
||||
"exe-suffix": ".elf",
|
||||
"late-link-args": {
|
||||
"gnu-cc": [
|
||||
"-lgcc"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-lgcc"
|
||||
]
|
||||
},
|
||||
"linker": "avr-gcc",
|
||||
"linker-flavor": "gnu-cc",
|
||||
"llvm-target": "avr-unknown-unknown",
|
||||
"max-atomic-width": 8,
|
||||
"metadata": {
|
||||
"description": null,
|
||||
"host_tools": null,
|
||||
"std": null,
|
||||
"tier": null
|
||||
},
|
||||
"no-default-libraries": false,
|
||||
"pre-link-args": {
|
||||
"gnu-cc": [
|
||||
"-mmcu=atmega2560",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-mmcu=atmega2560",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
]
|
||||
},
|
||||
"relocation-model": "static",
|
||||
"target-c-int-width": "16",
|
||||
"target-pointer-width": "16"
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"arch": "avr",
|
||||
"atomic-cas": false,
|
||||
"cpu": "atmega328",
|
||||
"crt-objects-fallback": "false",
|
||||
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||
"eh-frame-header": false,
|
||||
"exe-suffix": ".elf",
|
||||
"late-link-args": {
|
||||
"gnu-cc": [
|
||||
"-lgcc"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-lgcc"
|
||||
]
|
||||
},
|
||||
"linker": "avr-gcc",
|
||||
"linker-flavor": "gnu-cc",
|
||||
"llvm-target": "avr-unknown-unknown",
|
||||
"max-atomic-width": 8,
|
||||
"metadata": {
|
||||
"description": null,
|
||||
"host_tools": null,
|
||||
"std": null,
|
||||
"tier": null
|
||||
},
|
||||
"no-default-libraries": false,
|
||||
"pre-link-args": {
|
||||
"gnu-cc": [
|
||||
"-mmcu=atmega328",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-mmcu=atmega328",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
]
|
||||
},
|
||||
"relocation-model": "static",
|
||||
"target-c-int-width": "16",
|
||||
"target-pointer-width": "16"
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"arch": "avr",
|
||||
"atomic-cas": false,
|
||||
"cpu": "atmega328p",
|
||||
"crt-objects-fallback": "false",
|
||||
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||
"eh-frame-header": false,
|
||||
"exe-suffix": ".elf",
|
||||
"late-link-args": {
|
||||
"gnu-cc": [
|
||||
"-lgcc"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-lgcc"
|
||||
]
|
||||
},
|
||||
"linker": "avr-gcc",
|
||||
"linker-flavor": "gnu-cc",
|
||||
"llvm-target": "avr-unknown-unknown",
|
||||
"max-atomic-width": 8,
|
||||
"metadata": {
|
||||
"description": null,
|
||||
"host_tools": null,
|
||||
"std": null,
|
||||
"tier": null
|
||||
},
|
||||
"no-default-libraries": false,
|
||||
"pre-link-args": {
|
||||
"gnu-cc": [
|
||||
"-mmcu=atmega328p",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-mmcu=atmega328p",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
]
|
||||
},
|
||||
"relocation-model": "static",
|
||||
"target-c-int-width": "16",
|
||||
"target-pointer-width": "16"
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"arch": "avr",
|
||||
"atomic-cas": false,
|
||||
"cpu": "atmega32a",
|
||||
"crt-objects-fallback": "false",
|
||||
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||
"eh-frame-header": false,
|
||||
"exe-suffix": ".elf",
|
||||
"late-link-args": {
|
||||
"gnu-cc": [
|
||||
"-lgcc"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-lgcc"
|
||||
]
|
||||
},
|
||||
"linker": "avr-gcc",
|
||||
"linker-flavor": "gnu-cc",
|
||||
"llvm-target": "avr-unknown-unknown",
|
||||
"max-atomic-width": 8,
|
||||
"metadata": {
|
||||
"description": null,
|
||||
"host_tools": null,
|
||||
"std": null,
|
||||
"tier": null
|
||||
},
|
||||
"no-default-libraries": false,
|
||||
"pre-link-args": {
|
||||
"gnu-cc": [
|
||||
"-mmcu=atmega32a",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-mmcu=atmega32a",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
]
|
||||
},
|
||||
"relocation-model": "static",
|
||||
"target-c-int-width": "16",
|
||||
"target-pointer-width": "16"
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"arch": "avr",
|
||||
"atomic-cas": false,
|
||||
"cpu": "atmega32u4",
|
||||
"crt-objects-fallback": "false",
|
||||
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||
"eh-frame-header": false,
|
||||
"exe-suffix": ".elf",
|
||||
"late-link-args": {
|
||||
"gnu-cc": [
|
||||
"-lgcc"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-lgcc"
|
||||
]
|
||||
},
|
||||
"linker": "avr-gcc",
|
||||
"linker-flavor": "gnu-cc",
|
||||
"llvm-target": "avr-unknown-unknown",
|
||||
"max-atomic-width": 8,
|
||||
"metadata": {
|
||||
"description": null,
|
||||
"host_tools": null,
|
||||
"std": null,
|
||||
"tier": null
|
||||
},
|
||||
"no-default-libraries": false,
|
||||
"pre-link-args": {
|
||||
"gnu-cc": [
|
||||
"-mmcu=atmega32u4",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-mmcu=atmega32u4",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
]
|
||||
},
|
||||
"relocation-model": "static",
|
||||
"target-c-int-width": "16",
|
||||
"target-pointer-width": "16"
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"arch": "avr",
|
||||
"atomic-cas": false,
|
||||
"cpu": "atmega48p",
|
||||
"crt-objects-fallback": "false",
|
||||
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||
"eh-frame-header": false,
|
||||
"exe-suffix": ".elf",
|
||||
"late-link-args": {
|
||||
"gnu-cc": [
|
||||
"-lgcc"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-lgcc"
|
||||
]
|
||||
},
|
||||
"linker": "avr-gcc",
|
||||
"linker-flavor": "gnu-cc",
|
||||
"llvm-target": "avr-unknown-unknown",
|
||||
"max-atomic-width": 8,
|
||||
"metadata": {
|
||||
"description": null,
|
||||
"host_tools": null,
|
||||
"std": null,
|
||||
"tier": null
|
||||
},
|
||||
"no-default-libraries": false,
|
||||
"pre-link-args": {
|
||||
"gnu-cc": [
|
||||
"-mmcu=atmega48p",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-mmcu=atmega48p",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
]
|
||||
},
|
||||
"relocation-model": "static",
|
||||
"target-c-int-width": "16",
|
||||
"target-pointer-width": "16"
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"arch": "avr",
|
||||
"atomic-cas": false,
|
||||
"cpu": "atmega8",
|
||||
"crt-objects-fallback": "false",
|
||||
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||
"eh-frame-header": false,
|
||||
"exe-suffix": ".elf",
|
||||
"late-link-args": {
|
||||
"gnu-cc": [
|
||||
"-lgcc"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-lgcc"
|
||||
]
|
||||
},
|
||||
"linker": "avr-gcc",
|
||||
"linker-flavor": "gnu-cc",
|
||||
"llvm-target": "avr-unknown-unknown",
|
||||
"max-atomic-width": 8,
|
||||
"metadata": {
|
||||
"description": null,
|
||||
"host_tools": null,
|
||||
"std": null,
|
||||
"tier": null
|
||||
},
|
||||
"no-default-libraries": false,
|
||||
"pre-link-args": {
|
||||
"gnu-cc": [
|
||||
"-mmcu=atmega8",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-mmcu=atmega8",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
]
|
||||
},
|
||||
"relocation-model": "static",
|
||||
"target-c-int-width": "16",
|
||||
"target-pointer-width": "16"
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"arch": "avr",
|
||||
"atomic-cas": false,
|
||||
"cpu": "attiny167",
|
||||
"crt-objects-fallback": "false",
|
||||
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||
"eh-frame-header": false,
|
||||
"exe-suffix": ".elf",
|
||||
"late-link-args": {
|
||||
"gnu-cc": [
|
||||
"-lgcc"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-lgcc"
|
||||
]
|
||||
},
|
||||
"linker": "avr-gcc",
|
||||
"linker-flavor": "gnu-cc",
|
||||
"llvm-target": "avr-unknown-unknown",
|
||||
"max-atomic-width": 8,
|
||||
"metadata": {
|
||||
"description": null,
|
||||
"host_tools": null,
|
||||
"std": null,
|
||||
"tier": null
|
||||
},
|
||||
"no-default-libraries": false,
|
||||
"pre-link-args": {
|
||||
"gnu-cc": [
|
||||
"-mmcu=attiny167",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-mmcu=attiny167",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
]
|
||||
},
|
||||
"relocation-model": "static",
|
||||
"target-c-int-width": "16",
|
||||
"target-pointer-width": "16"
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"arch": "avr",
|
||||
"atomic-cas": false,
|
||||
"cpu": "attiny2313",
|
||||
"crt-objects-fallback": "false",
|
||||
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||
"eh-frame-header": false,
|
||||
"exe-suffix": ".elf",
|
||||
"late-link-args": {
|
||||
"gnu-cc": [
|
||||
"-lgcc"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-lgcc"
|
||||
]
|
||||
},
|
||||
"linker": "avr-gcc",
|
||||
"linker-flavor": "gnu-cc",
|
||||
"llvm-target": "avr-unknown-unknown",
|
||||
"max-atomic-width": 8,
|
||||
"metadata": {
|
||||
"description": null,
|
||||
"host_tools": null,
|
||||
"std": null,
|
||||
"tier": null
|
||||
},
|
||||
"no-default-libraries": false,
|
||||
"pre-link-args": {
|
||||
"gnu-cc": [
|
||||
"-mmcu=attiny2313",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-mmcu=attiny2313",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
]
|
||||
},
|
||||
"relocation-model": "static",
|
||||
"target-c-int-width": "16",
|
||||
"target-pointer-width": "16"
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"arch": "avr",
|
||||
"atomic-cas": false,
|
||||
"cpu": "attiny85",
|
||||
"crt-objects-fallback": "false",
|
||||
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||
"eh-frame-header": false,
|
||||
"exe-suffix": ".elf",
|
||||
"late-link-args": {
|
||||
"gnu-cc": [
|
||||
"-lgcc"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-lgcc"
|
||||
]
|
||||
},
|
||||
"linker": "avr-gcc",
|
||||
"linker-flavor": "gnu-cc",
|
||||
"llvm-target": "avr-unknown-unknown",
|
||||
"max-atomic-width": 8,
|
||||
"metadata": {
|
||||
"description": null,
|
||||
"host_tools": null,
|
||||
"std": null,
|
||||
"tier": null
|
||||
},
|
||||
"no-default-libraries": false,
|
||||
"pre-link-args": {
|
||||
"gnu-cc": [
|
||||
"-mmcu=attiny85",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-mmcu=attiny85",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
]
|
||||
},
|
||||
"relocation-model": "static",
|
||||
"target-c-int-width": "16",
|
||||
"target-pointer-width": "16"
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"arch": "avr",
|
||||
"atomic-cas": false,
|
||||
"cpu": "attiny88",
|
||||
"crt-objects-fallback": "false",
|
||||
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||
"eh-frame-header": false,
|
||||
"exe-suffix": ".elf",
|
||||
"late-link-args": {
|
||||
"gnu-cc": [
|
||||
"-lgcc"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-lgcc"
|
||||
]
|
||||
},
|
||||
"linker": "avr-gcc",
|
||||
"linker-flavor": "gnu-cc",
|
||||
"llvm-target": "avr-unknown-unknown",
|
||||
"max-atomic-width": 8,
|
||||
"metadata": {
|
||||
"description": null,
|
||||
"host_tools": null,
|
||||
"std": null,
|
||||
"tier": null
|
||||
},
|
||||
"no-default-libraries": false,
|
||||
"pre-link-args": {
|
||||
"gnu-cc": [
|
||||
"-mmcu=attiny88",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
],
|
||||
"gnu-lld-cc": [
|
||||
"-mmcu=attiny88",
|
||||
"-Wl,--as-needed,--print-memory-usage"
|
||||
]
|
||||
},
|
||||
"relocation-model": "static",
|
||||
"target-c-int-width": "16",
|
||||
"target-pointer-width": "16"
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
[toolchain]
|
||||
channel = "nightly-2024-06-13"
|
||||
components = [ "rust-src" ]
|
||||
profile = "complete"
|
||||
profile = "minimal"
|
||||
|
|
|
@ -0,0 +1,213 @@
|
|||
#![allow(unused)]
|
||||
|
||||
use core::{cell::Cell, convert::Infallible};
|
||||
|
||||
use arduino_hal::{
|
||||
delay_us,
|
||||
pac::{EXINT, TC0},
|
||||
port::{
|
||||
mode::{Input, OpenDrain, PullUp},
|
||||
Pin, PinMode, PinOps,
|
||||
},
|
||||
};
|
||||
use avr_device::{
|
||||
asm::delay_cycles,
|
||||
interrupt::{self, disable, enable},
|
||||
};
|
||||
use embedded_hal::digital::{InputPin, OutputPin};
|
||||
|
||||
use super::static_pins_impl::StaticPinOps;
|
||||
use heapless::Vec;
|
||||
|
||||
pub struct HalfDuplexSerial<P> {
|
||||
_pin: Pin<Input<PullUp>, P>,
|
||||
}
|
||||
|
||||
#[thread_local]
|
||||
static SERIAL_BUFFER: Cell<Vec<u8, 20>> = Cell::new(Vec::new());
|
||||
|
||||
const SERIAL_TRANSMIT_DELAY_US: u32 = 4;
|
||||
const LOGIC_STATE_CHANGE_DELAY_CYCLES: u32 = 32;
|
||||
const POLL_DELAY: u32 = 12;
|
||||
|
||||
const MSB: u8 = 0x80;
|
||||
|
||||
pub type PollResult = Result<(), PollError>;
|
||||
|
||||
pub enum PollError {
|
||||
NotFound,
|
||||
NotReady,
|
||||
}
|
||||
|
||||
pub type ReadByteResult = Result<u8, ReadByteError>;
|
||||
|
||||
pub enum ReadByteError {
|
||||
CorruptedData,
|
||||
Other,
|
||||
}
|
||||
|
||||
pub trait SoftSerial<P>
|
||||
where
|
||||
P: PinOps + StaticPinOps,
|
||||
{
|
||||
fn poll(&self) -> PollResult;
|
||||
fn response(&self);
|
||||
|
||||
fn is_low(&self) -> bool;
|
||||
fn is_high(&self) -> bool;
|
||||
|
||||
fn write_byte(&self, data: u8);
|
||||
fn read_byte(&self) -> ReadByteResult;
|
||||
|
||||
fn write_bytes(&self, transmit_data: &[u8]);
|
||||
fn read_bytes(&self, recieve_buffer: &mut [u8]);
|
||||
}
|
||||
|
||||
impl<P> HalfDuplexSerial<P>
|
||||
where
|
||||
P: PinOps + StaticPinOps,
|
||||
{
|
||||
#[inline]
|
||||
pub fn new(_pin: Pin<Input<PullUp>, P>, exint: &EXINT) -> Self {
|
||||
exint.eimsk.write(|w| w.bits(1 << 3));
|
||||
exint.eicra.write(|w| unsafe { w.bits(!(1 << 6 | 1 << 7)) });
|
||||
Self { _pin }
|
||||
}
|
||||
}
|
||||
|
||||
impl<P> SoftSerial<P> for HalfDuplexSerial<P>
|
||||
where
|
||||
P: PinOps + StaticPinOps,
|
||||
{
|
||||
fn poll(&self) -> PollResult {
|
||||
P::into_output();
|
||||
P::into_input();
|
||||
|
||||
delay_us(SERIAL_TRANSMIT_DELAY_US / 2);
|
||||
|
||||
if self.is_low() {
|
||||
P::into_pull_up_input();
|
||||
|
||||
return PollResult::Err(PollError::NotFound);
|
||||
}
|
||||
|
||||
P::into_pull_up_input();
|
||||
|
||||
delay_us(SERIAL_TRANSMIT_DELAY_US / 2);
|
||||
|
||||
if self.is_high() {
|
||||
P::into_pull_up_input();
|
||||
|
||||
return PollResult::Err(PollError::NotReady);
|
||||
}
|
||||
|
||||
while self.is_low() {}
|
||||
|
||||
PollResult::Ok(())
|
||||
}
|
||||
|
||||
fn response(&self) {
|
||||
while self.is_low() {}
|
||||
|
||||
P::into_output();
|
||||
|
||||
delay_us(SERIAL_TRANSMIT_DELAY_US);
|
||||
|
||||
P::into_pull_up_input();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_low(&self) -> bool {
|
||||
(P::read() & (1 << P::PIN_NUM)) == 0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_high(&self) -> bool {
|
||||
(P::read() & (1 << P::PIN_NUM)) != 0
|
||||
}
|
||||
|
||||
fn write_byte(&self, data: u8) {
|
||||
let mut data = data;
|
||||
let mut parity_bit = 0;
|
||||
let pin_pos = 1u8 << P::PIN_NUM;
|
||||
|
||||
P::write(P::read() & !pin_pos);
|
||||
P::into_output();
|
||||
|
||||
for _ in 0..8 {
|
||||
// Since some Atmega MCUs don't have a opendrain pin mode, by switching pins mode we
|
||||
// can simulate opendrain mode
|
||||
//
|
||||
// Opendrain pin mode simulation example:
|
||||
//
|
||||
// P::into_output() -> set low;
|
||||
// P::into_input() -> set high;
|
||||
|
||||
if data & MSB == 0 {
|
||||
P::into_output();
|
||||
} else {
|
||||
P::into_input();
|
||||
parity_bit ^= 1;
|
||||
}
|
||||
|
||||
data <<= 1;
|
||||
delay_us(SERIAL_TRANSMIT_DELAY_US);
|
||||
}
|
||||
|
||||
// Hamming code and CRC are very weightful and slow, so I use simple parity check
|
||||
|
||||
if parity_bit == 1 {
|
||||
P::into_input();
|
||||
}
|
||||
|
||||
delay_us(SERIAL_TRANSMIT_DELAY_US);
|
||||
|
||||
P::into_pull_up_input();
|
||||
}
|
||||
|
||||
fn read_byte(&self) -> ReadByteResult {
|
||||
let mut data = 0u8;
|
||||
let mut parity_bit = 0u8;
|
||||
let pin_pos = 1u8 << P::PIN_NUM;
|
||||
|
||||
for _ in 0..8 {
|
||||
delay_cycles(LOGIC_STATE_CHANGE_DELAY_CYCLES);
|
||||
|
||||
if P::read() & pin_pos != 0 {
|
||||
data |= 1;
|
||||
parity_bit ^= 1;
|
||||
}
|
||||
|
||||
data <<= 1;
|
||||
|
||||
delay_cycles(LOGIC_STATE_CHANGE_DELAY_CYCLES);
|
||||
}
|
||||
|
||||
delay_cycles(LOGIC_STATE_CHANGE_DELAY_CYCLES);
|
||||
|
||||
let bit_parity_check = P::read() & pin_pos != parity_bit;
|
||||
|
||||
delay_cycles(LOGIC_STATE_CHANGE_DELAY_CYCLES);
|
||||
|
||||
if !bit_parity_check {
|
||||
return Err(ReadByteError::CorruptedData);
|
||||
}
|
||||
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
fn write_bytes(&self, transmit_data: &[u8]) {
|
||||
for byte in transmit_data {
|
||||
self.write_byte(*byte);
|
||||
}
|
||||
}
|
||||
|
||||
fn read_bytes(&self, recieve_buffer: &mut [u8]) {
|
||||
for byte in recieve_buffer {
|
||||
match self.read_byte() {
|
||||
Ok(data) => *byte = data,
|
||||
Err(_) => continue,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
// use usbd_hid::descriptor::gen_hid_descriptor;
|
||||
|
||||
// #[gen_hid_descriptor(
|
||||
// (collection = APPLICATION, usage_page = GENERIC_DESKTOP, usage = KEYBOARD) = {
|
||||
// (usage_page = KEYBOARD) = {
|
||||
// #[item_settings data,array] keycodes=input;
|
||||
// }
|
||||
// }
|
||||
// )]
|
||||
// struct KeyboardNkroReport<const K: usize> {
|
||||
// keycodes: [u8; K],
|
||||
// }
|
|
@ -0,0 +1,49 @@
|
|||
use arduino_hal::{
|
||||
delay_ms,
|
||||
hal::port::Dynamic,
|
||||
port::{
|
||||
mode::{Input, Output},
|
||||
Pin,
|
||||
},
|
||||
};
|
||||
|
||||
type Key = [Option<(usize, usize)>; 6];
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! pins_array {
|
||||
("cols", $per:expr, $($pins:tt), * ) => {
|
||||
[ $($per.$pins.into_pull_up_input().downgrade().forget_imode()), * ]
|
||||
};
|
||||
("rows", $per:expr, $($pins:tt), * ) => {
|
||||
[ $($per.$pins.into_output_high().downgrade()), * ]
|
||||
}
|
||||
}
|
||||
|
||||
pub struct KeyboardMatrix<const C: usize, const R: usize> {
|
||||
cols: [Pin<Input>; C],
|
||||
rows: [Pin<Output, Dynamic>; R],
|
||||
}
|
||||
|
||||
impl<const C: usize, const R: usize> KeyboardMatrix<C, R> {
|
||||
#[inline]
|
||||
pub fn new(cols: [Pin<Input, Dynamic>; C], rows: [Pin<Output, Dynamic>; R]) -> Self {
|
||||
Self { cols, rows }
|
||||
}
|
||||
|
||||
pub fn scan(&mut self) -> Key {
|
||||
let mut key_pos = [None; 6];
|
||||
let mut index = 0usize;
|
||||
for (i, row) in self.rows.iter_mut().enumerate() {
|
||||
row.set_low();
|
||||
delay_ms(1);
|
||||
for (j, col) in self.cols.iter().enumerate() {
|
||||
if col.is_low() && index < 6 {
|
||||
key_pos[index] = Some((i, j));
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
row.set_high();
|
||||
}
|
||||
key_pos
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
mod hid_report;
|
||||
mod matrix;
|
||||
// pub use hid_report::*;
|
||||
pub use matrix::*;
|
455
src/lib.rs
455
src/lib.rs
|
@ -1,455 +0,0 @@
|
|||
#![no_std]
|
||||
|
||||
use core::cmp::max;
|
||||
|
||||
use avr_device::{asm::delay_cycles, interrupt::free};
|
||||
use usb_device::{
|
||||
bus::{PollResult, UsbBus},
|
||||
endpoint::{EndpointAddress, EndpointType},
|
||||
Result as UsbResult, UsbDirection, UsbError,
|
||||
};
|
||||
|
||||
mod types;
|
||||
pub use types::*;
|
||||
|
||||
use types::{DPRAM_SIZE, ENDPOINTS_ALLOC_LAYOUT, ONE_MS_16_MGHZ};
|
||||
|
||||
impl<const L: usize> UsbBus for UsbDevice<L> {
|
||||
fn alloc_ep(
|
||||
&mut self,
|
||||
ep_dir: UsbDirection,
|
||||
ep_addr: Option<EndpointAddress>,
|
||||
ep_type: EndpointType,
|
||||
max_packet_size: u16,
|
||||
_interval: u8,
|
||||
) -> UsbResult<EndpointAddress> {
|
||||
// Handle first endpoint. //
|
||||
free(|_cs| {
|
||||
if ep_addr == Some(EndpointAddress::from_parts(0, UsbDirection::In)) {
|
||||
Ok(ep_addr.unwrap())
|
||||
} else {
|
||||
let address = match ep_addr {
|
||||
// If current endpoint doesn't allocated, assign ep_addr to variable. //
|
||||
Some(addr) if !self.ep_table[addr.index()].is_allocated => addr,
|
||||
|
||||
// If ep_aadr not provided, or current endpoint is allocated, try to find next free endpoint, otherwise return UsbError. //
|
||||
_ => {
|
||||
let index = self
|
||||
.ep_table
|
||||
.iter()
|
||||
.enumerate()
|
||||
.skip(1)
|
||||
.find(|(index, ep)| {
|
||||
!ep.is_allocated
|
||||
&& max_packet_size <= ENDPOINTS_ALLOC_LAYOUT[*index]
|
||||
})
|
||||
.ok_or(UsbError::EndpointOverflow)?
|
||||
.0;
|
||||
|
||||
EndpointAddress::from_parts(index, ep_dir)
|
||||
}
|
||||
};
|
||||
|
||||
// Select endpoint info by address index. //
|
||||
|
||||
let target_endpoint = &mut self.ep_table[address.index()];
|
||||
|
||||
// Get power of two number of endpoint size. //
|
||||
|
||||
let ep_size = max(8, max_packet_size.next_power_of_two());
|
||||
|
||||
// Endpoint allocation marker. //
|
||||
|
||||
if DPRAM_SIZE - self.dpram_already_used < ep_size {
|
||||
Err(UsbError::EndpointMemoryOverflow)
|
||||
} else {
|
||||
// Set endpoint parameters. //
|
||||
|
||||
target_endpoint.set_dir(ep_dir);
|
||||
target_endpoint.set_type(ep_type);
|
||||
target_endpoint.set_size(ep_size)?;
|
||||
|
||||
// Add used dpram memory. //
|
||||
|
||||
target_endpoint.is_allocated = true;
|
||||
self.dpram_already_used += ep_size;
|
||||
|
||||
Ok(address)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn enable(&mut self) {
|
||||
free(|cs| {
|
||||
let (usb, pll) = (self.usb.borrow(cs), self.pll.borrow(cs));
|
||||
|
||||
// Enable USB pads regulators. //
|
||||
|
||||
usb.uhwcon.modify(|_, w| w.uvrege().set_bit());
|
||||
|
||||
// PLL configuration //
|
||||
|
||||
pll.pllcsr.write(|w| w.pindiv().set_bit());
|
||||
|
||||
pll.pllfrq
|
||||
.write(|w| w.pdiv().mhz96().plltm().factor_15().pllusb().set_bit());
|
||||
|
||||
// Enable PLL //
|
||||
|
||||
pll.pllcsr.modify(|_, w| w.plle().set_bit());
|
||||
|
||||
// Check PLL lock //
|
||||
|
||||
while pll.pllcsr.read().plock().bit_is_clear() {}
|
||||
|
||||
// Enable USB interface. //
|
||||
|
||||
usb.usbcon
|
||||
.modify(|_, w| w.usbe().set_bit().otgpade().set_bit());
|
||||
|
||||
// Unfreeze clock. //
|
||||
|
||||
usb.usbcon
|
||||
.modify(|_, w| w.frzclk().clear_bit().vbuste().set_bit());
|
||||
|
||||
// Endpoint configuration //
|
||||
|
||||
self.allocated_endpoints().for_each(|(i, _ep)| {
|
||||
self.configure_endpoint(cs, i).unwrap();
|
||||
});
|
||||
|
||||
// Set high speed and attach the USB. //
|
||||
|
||||
usb.udcon
|
||||
.modify(|_, w| w.detach().clear_bit().lsm().clear_bit());
|
||||
|
||||
// Interrupts. //
|
||||
|
||||
usb.udien
|
||||
.modify(|_, w| w.eorste().set_bit().sofe().set_bit());
|
||||
})
|
||||
}
|
||||
|
||||
fn force_reset(&self) -> UsbResult<()> {
|
||||
free(|cs| {
|
||||
self.usb.borrow(cs).usbcon.modify(|_, w| w.usbe().set_bit());
|
||||
});
|
||||
|
||||
delay_cycles(ONE_MS_16_MGHZ);
|
||||
|
||||
free(|cs| {
|
||||
self.usb.borrow(cs).usbcon.modify(|_, w| w.usbe().set_bit());
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn is_stalled(&self, ep_addr: EndpointAddress) -> bool {
|
||||
free(|cs| {
|
||||
if self.select_endpoint(cs, ep_addr.index()).is_ok() {
|
||||
return self.usb.borrow(cs).ueconx.read().stallrq().bit_is_set();
|
||||
}
|
||||
false
|
||||
})
|
||||
}
|
||||
|
||||
fn poll(&self) -> PollResult {
|
||||
free(|cs| {
|
||||
let usb = self.usb.borrow(cs);
|
||||
|
||||
let (udint, udien, usbint) = (usb.udint.read(), usb.udien.read(), usb.usbint.read());
|
||||
|
||||
if usbint.vbusti().bit_is_set() {
|
||||
usb.usbint
|
||||
.write(|w| w.clear_interrupts().vbusti().clear_bit());
|
||||
if usb.usbsta.read().vbus().bit_is_set() {
|
||||
return PollResult::Resume;
|
||||
} else {
|
||||
return PollResult::Suspend;
|
||||
}
|
||||
}
|
||||
|
||||
if udint.suspi().bit_is_set() && udien.suspe().bit_is_set() {
|
||||
return PollResult::Suspend;
|
||||
}
|
||||
|
||||
if udint.wakeupi().bit_is_set() && udien.wakeupe().bit_is_set() {
|
||||
return PollResult::Resume;
|
||||
}
|
||||
|
||||
if udint.eorsti().bit_is_set() {
|
||||
return PollResult::Reset;
|
||||
}
|
||||
|
||||
if udint.sofi().bit_is_set() {
|
||||
usb.udint.write(|w| w.clear_interrupts().sofi().clear_bit());
|
||||
}
|
||||
|
||||
if usb.usbcon.read().frzclk().bit_is_clear() {
|
||||
let (mut ep_out, mut ep_in_complete, mut ep_setup) = (0u16, 0u16, 0u16);
|
||||
let pending_ins = self.pending_ins.borrow(cs);
|
||||
|
||||
for (ep_index, _ep) in self.allocated_endpoints() {
|
||||
if self.select_endpoint(cs, ep_index).is_err() {
|
||||
break;
|
||||
} else {
|
||||
let ueintx = usb.ueintx.read();
|
||||
|
||||
if ueintx.rxouti().bit_is_set() {
|
||||
ep_out |= 1 << ep_index;
|
||||
}
|
||||
if ueintx.rxstpi().bit_is_set() {
|
||||
ep_setup |= 1 << ep_index;
|
||||
}
|
||||
|
||||
if pending_ins.get() & (1 << ep_index) != 0 && ueintx.txini().bit_is_set() {
|
||||
ep_in_complete |= 1 << ep_index;
|
||||
pending_ins.set(pending_ins.get() & !(1 << ep_index));
|
||||
}
|
||||
}
|
||||
}
|
||||
if ep_out | ep_in_complete | ep_setup != 0 {
|
||||
return PollResult::Data {
|
||||
ep_out,
|
||||
ep_in_complete,
|
||||
ep_setup,
|
||||
};
|
||||
}
|
||||
}
|
||||
PollResult::None
|
||||
})
|
||||
}
|
||||
|
||||
fn read(&self, ep_addr: EndpointAddress, buf: &mut [u8]) -> UsbResult<usize> {
|
||||
free(|cs| {
|
||||
let usb = self.usb.borrow(cs);
|
||||
|
||||
if let Err(usb_error) = self.select_endpoint(cs, ep_addr.index()) {
|
||||
Err(usb_error)
|
||||
} else {
|
||||
let ep = &self.ep_table[ep_addr.index()];
|
||||
|
||||
if ep.ep_type == 0 {
|
||||
let ueintx = usb.ueintx.read();
|
||||
|
||||
if ueintx.rxouti().bit_is_clear() && ueintx.rxstpi().bit_is_clear() {
|
||||
return Err(UsbError::WouldBlock);
|
||||
}
|
||||
|
||||
let buf_size = self.get_size(cs);
|
||||
if buf.len() < buf_size {
|
||||
return Err(UsbError::BufferOverflow);
|
||||
}
|
||||
|
||||
for byte in &mut buf[..buf_size] {
|
||||
*byte = usb.uedatx.read().bits();
|
||||
}
|
||||
|
||||
usb.ueintx.write(|w| {
|
||||
w.clear_interrupts()
|
||||
.rxouti()
|
||||
.clear_bit()
|
||||
.rxstpi()
|
||||
.clear_bit()
|
||||
});
|
||||
|
||||
Ok(buf_size)
|
||||
} else {
|
||||
if usb.ueintx.read().rxouti().bit_is_clear() {
|
||||
return Err(UsbError::WouldBlock);
|
||||
}
|
||||
usb.ueintx
|
||||
.write(|w| w.clear_interrupts().rxouti().clear_bit());
|
||||
|
||||
let mut bytes_read = 0;
|
||||
for data in buf {
|
||||
if usb.ueintx.read().rwal().bit_is_clear() {
|
||||
break;
|
||||
}
|
||||
*data = usb.uedatx.read().bits();
|
||||
bytes_read += 1;
|
||||
}
|
||||
|
||||
if usb.ueintx.read().rwal().bit_is_set() {
|
||||
return Err(UsbError::BufferOverflow);
|
||||
}
|
||||
|
||||
usb.ueintx
|
||||
.write(|w| w.clear_interrupts().fifocon().clear_bit());
|
||||
Ok(bytes_read)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn reset(&self) {
|
||||
free(|cs| {
|
||||
let usb = self.usb.borrow(cs);
|
||||
|
||||
usb.udint.modify(|_, w| w.eorsti().clear_bit());
|
||||
|
||||
self.allocated_endpoints().for_each(|(i, _)| {
|
||||
self.configure_endpoint(cs, i).unwrap();
|
||||
});
|
||||
|
||||
// Clear resume informations. //
|
||||
|
||||
usb.udint.write(|w| {
|
||||
w.clear_interrupts()
|
||||
.wakeupi()
|
||||
.clear_bit()
|
||||
.suspi()
|
||||
.clear_bit()
|
||||
});
|
||||
|
||||
usb.udien
|
||||
.modify(|_, w| w.wakeupe().clear_bit().suspe().set_bit());
|
||||
})
|
||||
}
|
||||
|
||||
fn resume(&self) {
|
||||
free(|cs| {
|
||||
let (usb, pll) = (self.usb.borrow(cs), self.pll.borrow(cs));
|
||||
|
||||
// PLL enable //
|
||||
|
||||
pll.pllcsr
|
||||
.modify(|_, w| w.pindiv().set_bit().plle().set_bit());
|
||||
|
||||
while pll.pllcsr.read().plock().bit_is_clear() {}
|
||||
|
||||
// Resuming //
|
||||
|
||||
usb.usbcon.modify(|_, w| w.frzclk().clear_bit());
|
||||
|
||||
usb.udint.write(|w| {
|
||||
w.clear_interrupts()
|
||||
.wakeupi()
|
||||
.clear_bit()
|
||||
.suspi()
|
||||
.clear_bit()
|
||||
});
|
||||
|
||||
usb.udien
|
||||
.modify(|_, w| w.wakeupe().clear_bit().suspe().set_bit());
|
||||
})
|
||||
}
|
||||
|
||||
fn set_device_address(&self, addr: u8) {
|
||||
free(|cs| {
|
||||
let usb = self.usb.borrow(cs);
|
||||
|
||||
// Set address. //
|
||||
|
||||
usb.udaddr.modify(|_, w| w.uadd().bits(addr));
|
||||
|
||||
// Note: ADDEN and UADD shall not be written at the same time.
|
||||
// (written in atmega32u4/16u4 docs)
|
||||
|
||||
// Enable. //
|
||||
|
||||
usb.udaddr.modify(|_, w| w.adden().set_bit());
|
||||
});
|
||||
}
|
||||
|
||||
fn set_stalled(&self, ep_addr: EndpointAddress, stalled: bool) {
|
||||
free(|cs| {
|
||||
let usb = self.usb.borrow(cs);
|
||||
if self.select_endpoint(cs, ep_addr.index()).is_ok() {
|
||||
usb.ueconx
|
||||
.modify(|_, w| w.stallrq().bit(stalled).stallrqc().bit(!stalled));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn suspend(&self) {
|
||||
free(|cs| {
|
||||
let (usb, pll) = (self.usb.borrow(cs), self.pll.borrow(cs));
|
||||
|
||||
usb.udint.write(|w| {
|
||||
w.clear_interrupts()
|
||||
.wakeupi()
|
||||
.clear_bit()
|
||||
.suspi()
|
||||
.clear_bit()
|
||||
});
|
||||
|
||||
// Suspend. //
|
||||
|
||||
usb.udien
|
||||
.modify(|_, w| w.wakeupe().set_bit().suspe().clear_bit());
|
||||
|
||||
// Freeze clock. //
|
||||
|
||||
usb.usbcon.modify(|_, w| w.frzclk().set_bit());
|
||||
|
||||
// Disable PLL. //
|
||||
|
||||
pll.pllcsr.modify(|_, w| w.plle().clear_bit());
|
||||
})
|
||||
}
|
||||
|
||||
fn write(&self, ep_addr: EndpointAddress, buf: &[u8]) -> UsbResult<usize> {
|
||||
free(|cs| {
|
||||
let usb = self.usb.borrow(cs);
|
||||
|
||||
if let Err(error) = self.select_endpoint(cs, ep_addr.index()) {
|
||||
Err(error)
|
||||
} else {
|
||||
let ep = &self.ep_table[ep_addr.index()];
|
||||
|
||||
// Endpoint type confitions //
|
||||
|
||||
if ep.ep_type == 0 {
|
||||
if usb.ueintx.read().txini().bit_is_clear() {
|
||||
return Err(UsbError::WouldBlock);
|
||||
}
|
||||
|
||||
if buf.len() > ep.get_size() {
|
||||
return Err(UsbError::BufferOverflow);
|
||||
}
|
||||
|
||||
for &byte in buf {
|
||||
usb.uedatx.write(|w| w.bits(byte));
|
||||
}
|
||||
|
||||
usb.ueintx
|
||||
.write(|w| w.clear_interrupts().txini().clear_bit());
|
||||
} else {
|
||||
if usb.ueintx.read().txini().bit_is_clear() {
|
||||
return Err(UsbError::WouldBlock);
|
||||
}
|
||||
usb.ueintx.write(|w| {
|
||||
w.clear_interrupts()
|
||||
.txini()
|
||||
.clear_bit()
|
||||
.rxouti()
|
||||
.clear_bit()
|
||||
});
|
||||
|
||||
for &byte in buf {
|
||||
if usb.ueintx.read().rwal().bit_is_set() {
|
||||
usb.uedatx.write(|w| w.bits(byte));
|
||||
} else {
|
||||
return Err(UsbError::BufferOverflow);
|
||||
}
|
||||
}
|
||||
|
||||
usb.ueintx.write(|w| {
|
||||
w.clear_interrupts()
|
||||
.rxouti()
|
||||
.clear_bit()
|
||||
.fifocon()
|
||||
.clear_bit()
|
||||
});
|
||||
}
|
||||
|
||||
let pending_ins = self.pending_ins.borrow(cs);
|
||||
pending_ins.set(pending_ins.get() | 1 << ep_addr.index());
|
||||
|
||||
Ok(buf.len())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(panic_info_message)]
|
||||
#![feature(abi_avr_interrupt)]
|
||||
#![feature(asm_experimental_arch)]
|
||||
#![feature(thread_local)]
|
||||
#![allow(clippy::wrong_self_convention)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate static_pins;
|
||||
|
||||
use arduino_hal::{
|
||||
delay_ms,
|
||||
hal::{
|
||||
pins,
|
||||
port::{PD2, PD3, PD5},
|
||||
},
|
||||
port::{mode::Output, Pin},
|
||||
Peripherals,
|
||||
};
|
||||
|
||||
mod half_duplex_serial;
|
||||
mod keyboard;
|
||||
mod panic_handler;
|
||||
mod static_pins_impl;
|
||||
|
||||
use avr_device::interrupt::{enable, free};
|
||||
use half_duplex_serial::{HalfDuplexSerial, PollError, SoftSerial};
|
||||
use keyboard::*;
|
||||
|
||||
#[allow(unused)]
|
||||
use panic_handler::*;
|
||||
|
||||
pub static mut SERIAL: Option<HalfDuplexSerial<PD3>> = None;
|
||||
|
||||
static mut RX_LED: Option<Pin<Output, PD5>> = None;
|
||||
static mut POLL_INDICATOR: Option<Pin<Output, PD2>> = None;
|
||||
|
||||
fn error_poll_status_display(delay: u16) {
|
||||
unsafe {
|
||||
if let Some(poll_status) = POLL_INDICATOR.as_mut() {
|
||||
for _ in 0..=5 {
|
||||
delay_ms(delay);
|
||||
poll_status.toggle();
|
||||
}
|
||||
poll_status.set_low();
|
||||
}
|
||||
delay_ms(500)
|
||||
}
|
||||
}
|
||||
|
||||
#[arduino_hal::entry]
|
||||
fn main() -> ! {
|
||||
let dp = Peripherals::take().unwrap();
|
||||
|
||||
let pins = pins!(dp);
|
||||
|
||||
let mut matrix = KeyboardMatrix::new(
|
||||
pins_array!("cols", pins, pd0, pd4),
|
||||
pins_array!("rows", pins, pd7),
|
||||
);
|
||||
|
||||
let mut rx_led = pins.pd5.into_output();
|
||||
let poll_indicator = pins.pd2.into_output();
|
||||
// let one_wire_pin = StaticPin::new(pins.pd3.into_pull_up_input());
|
||||
pins.pb0.into_output().set_low();
|
||||
rx_led.set_low();
|
||||
|
||||
unsafe {
|
||||
SERIAL = Some(HalfDuplexSerial::new(
|
||||
pins.pd3.into_pull_up_input(),
|
||||
&dp.EXINT,
|
||||
));
|
||||
POLL_INDICATOR = Some(poll_indicator);
|
||||
RX_LED = Some(rx_led);
|
||||
enable();
|
||||
|
||||
loop {
|
||||
let pressed_keys = matrix.scan();
|
||||
if pressed_keys[0].is_some() || pressed_keys[1].is_some() {
|
||||
free(|_| {
|
||||
if let Some(serial) = SERIAL.as_ref() {
|
||||
match serial.poll() {
|
||||
Ok(_) => {
|
||||
if let Some(led) = POLL_INDICATOR.as_mut() {
|
||||
led.set_high();
|
||||
}
|
||||
}
|
||||
Err(PollError::NotFound) => error_poll_status_display(150),
|
||||
Err(PollError::NotReady) => error_poll_status_display(750),
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[avr_device::interrupt(atmega32u4)]
|
||||
unsafe fn INT3() {
|
||||
if let Some(serial) = SERIAL.as_ref() {
|
||||
serial.response();
|
||||
if let Some(led) = POLL_INDICATOR.as_mut() {
|
||||
led.toggle();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
use core::panic::PanicInfo;
|
||||
|
||||
use arduino_hal::{delay_ms, hal::pins, Peripherals};
|
||||
|
||||
#[panic_handler]
|
||||
pub unsafe fn panic(_info: &PanicInfo) -> ! {
|
||||
let dp = Peripherals::steal();
|
||||
let pins = pins!(dp);
|
||||
let mut rx_led = pins.pb0.into_output();
|
||||
|
||||
rx_led.set_low();
|
||||
|
||||
let panic_reason = _info.message().as_str();
|
||||
|
||||
match panic_reason {
|
||||
Some("1") => loop {
|
||||
rx_led.toggle();
|
||||
delay_ms(500);
|
||||
},
|
||||
Some("2") => loop {
|
||||
rx_led.toggle();
|
||||
delay_ms(100);
|
||||
rx_led.toggle();
|
||||
delay_ms(100);
|
||||
rx_led.toggle();
|
||||
delay_ms(750);
|
||||
rx_led.toggle();
|
||||
delay_ms(100);
|
||||
},
|
||||
_ => loop {
|
||||
rx_led.toggle();
|
||||
delay_ms(4000);
|
||||
},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
use arduino_hal::{hal::port::*, pac::*};
|
||||
|
||||
pub struct StaticPin<T, P>
|
||||
where
|
||||
P: StaticPinOps + PinOps,
|
||||
T: PinMode,
|
||||
{
|
||||
_p: Pin<T, P>,
|
||||
}
|
||||
|
||||
impl<T, P> StaticPin<T, P>
|
||||
where
|
||||
P: StaticPinOps + PinOps,
|
||||
T: PinMode,
|
||||
{
|
||||
#[inline]
|
||||
pub fn new(_p: Pin<T, P>) -> Self {
|
||||
Self { _p }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_high(&self) -> bool {
|
||||
!self.is_low()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_low(&self) -> bool {
|
||||
P::read() & (1 << P::PIN_NUM) == 0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_high(&self) {
|
||||
P::write(P::read() | (1 << P::PIN_NUM));
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_low(&self) {
|
||||
P::write(P::read() & !(1 << P::PIN_NUM));
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn toggle(&self) {
|
||||
P::write(P::read() ^ (1 << P::PIN_NUM));
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn into_output(&self) {
|
||||
P::into_output();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn into_pull_up_input(&self) {
|
||||
P::into_pull_up_input();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn into_input(&self) {
|
||||
P::into_input();
|
||||
}
|
||||
}
|
||||
|
||||
impl_static_pins!(
|
||||
PB0, PB1, PB2, PB3, PB4, PB5, PB6, PB7, PC6, PC7, PD0, PD1, PD2, PD3, PD4, PD5, PD6, PD7, PE2,
|
||||
PE6, PF0, PF1, PF4, PF5, PF6, PF7
|
||||
);
|
|
@ -1,3 +0,0 @@
|
|||
mod usb_device;
|
||||
|
||||
pub use usb_device::*;
|
|
@ -1,214 +0,0 @@
|
|||
use core::cell::Cell;
|
||||
|
||||
use avr_device::{
|
||||
atmega32u4::usb_device::{
|
||||
udint::W as UDINTWriter, ueintx::W as UEINTXWriter, usbint::W as USBINTWriter,
|
||||
},
|
||||
atmega32u4::{PLL, USB_DEVICE},
|
||||
interrupt::{CriticalSection, Mutex},
|
||||
};
|
||||
use usb_device::{bus::UsbBusAllocator, endpoint::EndpointType, UsbDirection, UsbError};
|
||||
|
||||
#[allow(unused)]
|
||||
#[derive(Default, Copy, Clone)]
|
||||
pub(crate) struct USBEndpoint {
|
||||
pub(crate) is_allocated: bool,
|
||||
pub(crate) size: u8,
|
||||
pub(crate) ep_type: u8,
|
||||
pub(crate) ep_dir: bool,
|
||||
}
|
||||
|
||||
impl USBEndpoint {
|
||||
#[inline]
|
||||
pub(crate) fn set_type(&mut self, ep_type: EndpointType) {
|
||||
self.ep_type = match ep_type {
|
||||
EndpointType::Control => 0, // 0b00
|
||||
EndpointType::Isochronous { .. } => 1, // 0b01
|
||||
EndpointType::Bulk => 2, // 0b10
|
||||
EndpointType::Interrupt => 3, // 0b11
|
||||
};
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn set_dir(&mut self, dir: UsbDirection) {
|
||||
self.ep_dir = match dir {
|
||||
UsbDirection::In => true,
|
||||
UsbDirection::Out => false,
|
||||
};
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn get_size(&self) -> usize {
|
||||
match self.size {
|
||||
0 /* 0b000 */ => 8,
|
||||
1 /* 0b001 */ => 16,
|
||||
2 /* 0b010 */ => 32,
|
||||
3 /* 0b011 */ => 64,
|
||||
4 /* 0b100 */ => 128,
|
||||
5 /* 0b101 */ => 256,
|
||||
6 /* 0b110 */ => 512,
|
||||
_ => unreachable!(), // unsupported, check ATMEGA32u4 docs
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn set_size(&mut self, size: u16) -> Result<(), UsbError> {
|
||||
if size > 512 {
|
||||
Err(UsbError::EndpointMemoryOverflow)
|
||||
} else {
|
||||
self.size = match size {
|
||||
8 => 0, // 0b000
|
||||
16 => 1, // 0b001
|
||||
32 => 2, // 0b010
|
||||
64 => 3, // 0b011
|
||||
128 => 4, // 0b100
|
||||
256 => 5, // 0b101
|
||||
512 => 6, // 0b110
|
||||
_ => unreachable!(), // unsupported, check ATMEGA32u4 docs
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UsbDevice<const L: usize> {
|
||||
pub(crate) pll: Mutex<PLL>,
|
||||
pub(crate) usb: Mutex<USB_DEVICE>,
|
||||
pub(crate) ep_table: [USBEndpoint; L],
|
||||
pub(crate) pending_ins: Mutex<Cell<u8>>,
|
||||
pub(crate) dpram_already_used: u16,
|
||||
}
|
||||
|
||||
pub(crate) const MAX_ENDPOINTS: usize = 7;
|
||||
pub(crate) const DPRAM_SIZE: u16 = 832;
|
||||
pub(crate) const ENDPOINTS_ALLOC_LAYOUT: [u16; MAX_ENDPOINTS] = [64, 256, 64, 64, 64, 64, 64];
|
||||
pub(crate) const ONE_MS_16_MGHZ: u32 = 16000;
|
||||
|
||||
const UDINT_BYTE: u8 = 0x7d;
|
||||
const USBINT_BYTE: u8 = 0x01;
|
||||
const UEINTX_BYTE: u8 = 0xdf;
|
||||
const UENUM_MASK: u8 = 0b111;
|
||||
|
||||
pub(crate) trait InterruptCleaner {
|
||||
fn clear_interrupts(&mut self) -> &mut Self;
|
||||
}
|
||||
|
||||
impl InterruptCleaner for UDINTWriter {
|
||||
#[inline]
|
||||
fn clear_interrupts(&mut self) -> &mut Self {
|
||||
unsafe { self.bits(UDINT_BYTE) }
|
||||
}
|
||||
}
|
||||
|
||||
impl InterruptCleaner for USBINTWriter {
|
||||
#[inline]
|
||||
fn clear_interrupts(&mut self) -> &mut Self {
|
||||
unsafe { self.bits(USBINT_BYTE) }
|
||||
}
|
||||
}
|
||||
|
||||
impl InterruptCleaner for UEINTXWriter {
|
||||
#[inline]
|
||||
fn clear_interrupts(&mut self) -> &mut Self {
|
||||
unsafe { self.bits(UEINTX_BYTE) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<const L: usize> UsbDevice<L> {
|
||||
#[inline]
|
||||
pub(crate) fn get_size(&self, cs: CriticalSection<'_>) -> usize {
|
||||
let usb = self.usb.borrow(cs);
|
||||
|
||||
(((usb.uebchx.read().bits() as u16) << 8) | (usb.uebclx.read().bits() as u16)).into()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn new(pll: PLL, usb: USB_DEVICE) -> UsbBusAllocator<Self> {
|
||||
UsbBusAllocator::new(Self {
|
||||
pll: Mutex::new(pll),
|
||||
usb: Mutex::new(usb),
|
||||
ep_table: [USBEndpoint::default(); L],
|
||||
pending_ins: Mutex::new(Cell::new(0u8)),
|
||||
dpram_already_used: 0,
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn allocated_endpoints(&self) -> impl Iterator<Item = (usize, &USBEndpoint)> {
|
||||
self.ep_table
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|&(_, ep)| ep.is_allocated)
|
||||
}
|
||||
|
||||
pub(crate) fn select_endpoint(
|
||||
&self,
|
||||
cs: CriticalSection<'_>,
|
||||
endpoint_index: usize,
|
||||
) -> Result<(), UsbError> {
|
||||
let usb = self.usb.borrow(cs);
|
||||
|
||||
if endpoint_index >= MAX_ENDPOINTS {
|
||||
return Err(UsbError::InvalidEndpoint);
|
||||
}
|
||||
|
||||
if usb.usbcon.read().frzclk().bit_is_set() {
|
||||
return Err(UsbError::InvalidState);
|
||||
}
|
||||
|
||||
usb.uenum.write(|w| w.bits(endpoint_index as u8));
|
||||
|
||||
if usb.uenum.read().bits() & UENUM_MASK != endpoint_index as u8 {
|
||||
return Err(UsbError::InvalidEndpoint);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn configure_endpoint(
|
||||
&self,
|
||||
cs: CriticalSection<'_>,
|
||||
endpoint_index: usize,
|
||||
) -> Result<(), UsbError> {
|
||||
let usb = self.usb.borrow(cs);
|
||||
let current_endpoint = self.ep_table[endpoint_index];
|
||||
|
||||
let select_endpoint_result = self.select_endpoint(cs, endpoint_index);
|
||||
|
||||
if select_endpoint_result.is_err() {
|
||||
select_endpoint_result
|
||||
} else {
|
||||
// Enable endpoint. //
|
||||
|
||||
usb.ueconx.modify(|_, w| w.epen().set_bit());
|
||||
usb.uecfg1x.modify(|_, w| w.alloc().clear_bit());
|
||||
|
||||
// Set markered endpoint parameters to uecfg0x/1x register. //
|
||||
|
||||
usb.uecfg0x.modify(|_, w| {
|
||||
w.epdir()
|
||||
.bit(current_endpoint.ep_dir)
|
||||
.eptype()
|
||||
.bits(current_endpoint.ep_type)
|
||||
});
|
||||
|
||||
usb.uecfg1x.modify(|_, w| {
|
||||
w.epbk()
|
||||
.bits(0)
|
||||
.epsize()
|
||||
.bits(current_endpoint.size)
|
||||
.alloc()
|
||||
.set_bit()
|
||||
});
|
||||
|
||||
if usb.uesta0x.read().cfgok().bit_is_clear() {
|
||||
Err(UsbError::EndpointMemoryOverflow)
|
||||
} else {
|
||||
usb.ueienx
|
||||
.modify(|_, w| w.rxoute().set_bit().rxstpe().set_bit());
|
||||
|
||||
select_endpoint_result
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
[unstable]
|
||||
build-std = ["core"]
|
|
@ -0,0 +1 @@
|
|||
/target
|
|
@ -0,0 +1,259 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "arduino-hal"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/rahix/avr-hal?rev=3e362624547462928a219c40f9ea8e3a64f21e5f#3e362624547462928a219c40f9ea8e3a64f21e5f"
|
||||
dependencies = [
|
||||
"atmega-hal",
|
||||
"avr-device",
|
||||
"avr-hal-generic",
|
||||
"cfg-if 1.0.0",
|
||||
"embedded-hal 0.2.7",
|
||||
"embedded-hal 1.0.0",
|
||||
"ufmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atmega-hal"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/rahix/avr-hal?rev=3e362624547462928a219c40f9ea8e3a64f21e5f#3e362624547462928a219c40f9ea8e3a64f21e5f"
|
||||
dependencies = [
|
||||
"avr-device",
|
||||
"avr-hal-generic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "avr-device"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "546b09da5e933d18b790ccb5aae351371c6c4f8094a7b011dcd7c7e7fb69cc94"
|
||||
dependencies = [
|
||||
"avr-device-macros",
|
||||
"bare-metal",
|
||||
"cfg-if 1.0.0",
|
||||
"vcell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "avr-device-macros"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b108541dc1ea060dfa9b824acbded94f658f8daecca549144d05a4d01e65b6f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "avr-hal-generic"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/rahix/avr-hal?rev=3e362624547462928a219c40f9ea8e3a64f21e5f#3e362624547462928a219c40f9ea8e3a64f21e5f"
|
||||
dependencies = [
|
||||
"avr-device",
|
||||
"cfg-if 0.1.10",
|
||||
"embedded-hal 0.2.7",
|
||||
"embedded-hal 1.0.0",
|
||||
"embedded-hal-bus",
|
||||
"embedded-storage",
|
||||
"nb 1.1.0",
|
||||
"paste",
|
||||
"rustversion",
|
||||
"ufmt",
|
||||
"unwrap-infallible",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bare-metal"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8fe8f5a8a398345e52358e18ff07cc17a568fbca5c6f73873d3a62056309603"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "critical-section"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
|
||||
|
||||
[[package]]
|
||||
name = "embedded-hal"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "35949884794ad573cf46071e41c9b60efb0cb311e3ca01f7af807af1debc66ff"
|
||||
dependencies = [
|
||||
"nb 0.1.3",
|
||||
"void",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embedded-hal"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89"
|
||||
|
||||
[[package]]
|
||||
name = "embedded-hal-bus"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57b4e6ede84339ebdb418cd986e6320a34b017cdf99b5cc3efceec6450b06886"
|
||||
dependencies = [
|
||||
"critical-section",
|
||||
"embedded-hal 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embedded-storage"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "723dce4e9f25b6e6c5f35628e144794e5b459216ed7da97b7c4b66cdb3fa82ca"
|
||||
|
||||
[[package]]
|
||||
name = "nb"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f"
|
||||
dependencies = [
|
||||
"nb 1.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nb"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
|
||||
|
||||
[[package]]
|
||||
name = "paste"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.94"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.39"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1f1914ce909e1658d9907913b4b91947430c7d9be598b15a1912935b8c04801"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2"
|
||||
|
||||
[[package]]
|
||||
name = "static_pins"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"arduino-hal",
|
||||
"static_pins_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "static_pins_macros"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"arduino-hal",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.99",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.99"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e02e925281e18ffd9d640e234264753c43edc62d64b2d4cf898f1bc5e75f3fc2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ufmt"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a64846ec02b57e9108d6469d98d1648782ad6bb150a95a9baac26900bbeab9d"
|
||||
dependencies = [
|
||||
"ufmt-macros",
|
||||
"ufmt-write",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ufmt-macros"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d337d3be617449165cb4633c8dece429afd83f84051024079f97ad32a9663716"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ufmt-write"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e87a2ed6b42ec5e28cc3b94c09982969e9227600b2e3dcbc1db927a84c06bd69"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
||||
|
||||
[[package]]
|
||||
name = "unwrap-infallible"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb"
|
||||
|
||||
[[package]]
|
||||
name = "vcell"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002"
|
||||
|
||||
[[package]]
|
||||
name = "void"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
|
|
@ -0,0 +1,27 @@
|
|||
[package]
|
||||
name = "static_pins"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
test = false
|
||||
|
||||
[dependencies.static_pins_macros]
|
||||
path = "static_pins_macros"
|
||||
|
||||
[dependencies.arduino-hal]
|
||||
git = "https://github.com/rahix/avr-hal"
|
||||
rev = "3e362624547462928a219c40f9ea8e3a64f21e5f"
|
||||
features = ["sparkfun-promicro"]
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
lto = true
|
||||
opt-level = "s"
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
codegen-units = 1
|
||||
debug = true
|
||||
lto = true
|
||||
opt-level = "s"
|
|
@ -0,0 +1,4 @@
|
|||
[toolchain]
|
||||
channel = "nightly-2024-06-13"
|
||||
components = [ "rust-src" ]
|
||||
profile = "minimal"
|
|
@ -0,0 +1,36 @@
|
|||
#![no_std]
|
||||
|
||||
pub use static_pins_macros::*;
|
||||
|
||||
pub trait StaticPinOps {
|
||||
type Port;
|
||||
const PIN_NUM: u8;
|
||||
|
||||
fn into_input();
|
||||
fn into_output();
|
||||
fn into_pull_up_input();
|
||||
|
||||
fn write(data: u8);
|
||||
fn read() -> u8;
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! impl_static_pins {
|
||||
($($pin:expr), +) => {
|
||||
pub trait StaticPinOps {
|
||||
type Port;
|
||||
const PIN_NUM: u8;
|
||||
|
||||
fn into_input();
|
||||
fn into_output();
|
||||
fn into_pull_up_input();
|
||||
|
||||
fn write(data: u8);
|
||||
fn read() -> u8;
|
||||
}
|
||||
|
||||
$(
|
||||
impl_static_pin!($pin);
|
||||
)+
|
||||
}
|
||||
}
|
|
@ -0,0 +1,251 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "arduino-hal"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/rahix/avr-hal?rev=3e362624547462928a219c40f9ea8e3a64f21e5f#3e362624547462928a219c40f9ea8e3a64f21e5f"
|
||||
dependencies = [
|
||||
"atmega-hal",
|
||||
"avr-device",
|
||||
"avr-hal-generic",
|
||||
"cfg-if 1.0.0",
|
||||
"embedded-hal 0.2.7",
|
||||
"embedded-hal 1.0.0",
|
||||
"ufmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atmega-hal"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/rahix/avr-hal?rev=3e362624547462928a219c40f9ea8e3a64f21e5f#3e362624547462928a219c40f9ea8e3a64f21e5f"
|
||||
dependencies = [
|
||||
"avr-device",
|
||||
"avr-hal-generic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "avr-device"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "546b09da5e933d18b790ccb5aae351371c6c4f8094a7b011dcd7c7e7fb69cc94"
|
||||
dependencies = [
|
||||
"avr-device-macros",
|
||||
"bare-metal",
|
||||
"cfg-if 1.0.0",
|
||||
"vcell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "avr-device-macros"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b108541dc1ea060dfa9b824acbded94f658f8daecca549144d05a4d01e65b6f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "avr-hal-generic"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/rahix/avr-hal?rev=3e362624547462928a219c40f9ea8e3a64f21e5f#3e362624547462928a219c40f9ea8e3a64f21e5f"
|
||||
dependencies = [
|
||||
"avr-device",
|
||||
"cfg-if 0.1.10",
|
||||
"embedded-hal 0.2.7",
|
||||
"embedded-hal 1.0.0",
|
||||
"embedded-hal-bus",
|
||||
"embedded-storage",
|
||||
"nb 1.1.0",
|
||||
"paste",
|
||||
"rustversion",
|
||||
"ufmt",
|
||||
"unwrap-infallible",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bare-metal"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8fe8f5a8a398345e52358e18ff07cc17a568fbca5c6f73873d3a62056309603"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "critical-section"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
|
||||
|
||||
[[package]]
|
||||
name = "embedded-hal"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "35949884794ad573cf46071e41c9b60efb0cb311e3ca01f7af807af1debc66ff"
|
||||
dependencies = [
|
||||
"nb 0.1.3",
|
||||
"void",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embedded-hal"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89"
|
||||
|
||||
[[package]]
|
||||
name = "embedded-hal-bus"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57b4e6ede84339ebdb418cd986e6320a34b017cdf99b5cc3efceec6450b06886"
|
||||
dependencies = [
|
||||
"critical-section",
|
||||
"embedded-hal 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embedded-storage"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "723dce4e9f25b6e6c5f35628e144794e5b459216ed7da97b7c4b66cdb3fa82ca"
|
||||
|
||||
[[package]]
|
||||
name = "nb"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f"
|
||||
dependencies = [
|
||||
"nb 1.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nb"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
|
||||
|
||||
[[package]]
|
||||
name = "paste"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.94"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.39"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1f1914ce909e1658d9907913b4b91947430c7d9be598b15a1912935b8c04801"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2"
|
||||
|
||||
[[package]]
|
||||
name = "static_pins_macros"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"arduino-hal",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.58"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ufmt"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a64846ec02b57e9108d6469d98d1648782ad6bb150a95a9baac26900bbeab9d"
|
||||
dependencies = [
|
||||
"ufmt-macros",
|
||||
"ufmt-write",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ufmt-macros"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d337d3be617449165cb4633c8dece429afd83f84051024079f97ad32a9663716"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ufmt-write"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e87a2ed6b42ec5e28cc3b94c09982969e9227600b2e3dcbc1db927a84c06bd69"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034"
|
||||
|
||||
[[package]]
|
||||
name = "unwrap-infallible"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb"
|
||||
|
||||
[[package]]
|
||||
name = "vcell"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002"
|
||||
|
||||
[[package]]
|
||||
name = "void"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
|
|
@ -0,0 +1,30 @@
|
|||
[package]
|
||||
name = "static_pins_macros"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
test = false
|
||||
proc_macro = true
|
||||
|
||||
[dependencies]
|
||||
quote = "1.0.39"
|
||||
syn = "2.0.58"
|
||||
proc-macro2 = "1.0.94"
|
||||
|
||||
[dependencies.arduino-hal]
|
||||
git = "https://github.com/rahix/avr-hal"
|
||||
rev = "3e362624547462928a219c40f9ea8e3a64f21e5f"
|
||||
features = ["sparkfun-promicro"]
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
lto = true
|
||||
opt-level = "s"
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
codegen-units = 1
|
||||
debug = true
|
||||
lto = true
|
||||
opt-level = "s"
|
|
@ -0,0 +1,4 @@
|
|||
[toolchain]
|
||||
channel = "nightly-2024-06-13"
|
||||
components = [ "rust-src" ]
|
||||
profile = "minimal"
|
|
@ -0,0 +1,104 @@
|
|||
#![feature(proc_macro_quote)]
|
||||
|
||||
use core::str::FromStr;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use quote::{format_ident, quote};
|
||||
use syn::parse;
|
||||
|
||||
const ASCII_DIGIT_OFFSET: u8 = 48;
|
||||
|
||||
#[proc_macro]
|
||||
pub fn impl_static_pin(pin: TokenStream) -> TokenStream {
|
||||
let parsing_result = parse::<syn::Ident>(pin.clone());
|
||||
|
||||
if let Ok(pin) = parsing_result {
|
||||
let mut port = pin.to_string();
|
||||
let writer_method = format_ident!("{}", port.to_ascii_lowercase());
|
||||
port.insert_str(1, "ORT");
|
||||
|
||||
let pin_num = match port.pop() {
|
||||
Some(num) if num.is_ascii_digit() => (num as u8) - ASCII_DIGIT_OFFSET,
|
||||
_ => panic!("Pin number is incorrect"),
|
||||
};
|
||||
|
||||
let port_type = proc_macro2::TokenStream::from_str(&port).unwrap();
|
||||
|
||||
let port_register_name = match port.chars().last() {
|
||||
Some(register) if register.is_ascii_alphabetic() => register,
|
||||
_ => panic!("Register name is incorrect"),
|
||||
};
|
||||
|
||||
let target_port = proc_macro2::TokenStream::from_str(&port.to_ascii_lowercase()).unwrap();
|
||||
let target_pin = format_ident!("pin{}", port_register_name.to_ascii_lowercase());
|
||||
let target_data_direction = format_ident!("ddr{}", port_register_name.to_ascii_lowercase());
|
||||
|
||||
let trait_name = proc_macro2::TokenStream::from_str("StaticPinOps").unwrap();
|
||||
|
||||
let impl_trait = quote! {
|
||||
impl #trait_name for #pin {
|
||||
type Port = #port_type;
|
||||
const PIN_NUM: u8 = #pin_num;
|
||||
|
||||
#[inline]
|
||||
fn write(data: u8) {
|
||||
unsafe {
|
||||
(*Self::Port::ptr())
|
||||
.#target_port
|
||||
.write(|w| w.bits(data));
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn read() -> u8 {
|
||||
unsafe {
|
||||
(*Self::Port::ptr())
|
||||
.#target_pin
|
||||
.read()
|
||||
.bits()
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn into_input() {
|
||||
unsafe {
|
||||
(*Self::Port::ptr())
|
||||
.#target_data_direction
|
||||
.modify(|_r, w| w.#writer_method().clear_bit());
|
||||
(*Self::Port::ptr())
|
||||
.#target_port
|
||||
.modify(|_r, w| w.#writer_method().clear_bit());
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn into_output() {
|
||||
unsafe {
|
||||
(*Self::Port::ptr())
|
||||
.#target_data_direction
|
||||
.modify(|_r, w| w.#writer_method().set_bit());
|
||||
(*Self::Port::ptr())
|
||||
.#target_port
|
||||
.modify(|_r, w| w.#writer_method().clear_bit());
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn into_pull_up_input() {
|
||||
unsafe {
|
||||
(*Self::Port::ptr())
|
||||
.#target_data_direction
|
||||
.modify(|_r, w| w.#writer_method().clear_bit());
|
||||
(*Self::Port::ptr())
|
||||
.#target_port
|
||||
.modify(|r, w| w.#writer_method().set_bit());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TokenStream::from(impl_trait)
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue