diff --git a/.gitignore b/.gitignore index fede716..6aa1064 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,3 @@ /target/ -/macros/target/ **/*.rs.bk Cargo.lock - -svd/ -.deps/ -src/devices/*/* -src/generic.rs -__pycache__/ diff --git a/Cargo.toml b/Cargo.toml index 45c9e4d..a985f5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,10 +12,13 @@ keywords = ["avr", "arduino"] categories = ["no-std", "embedded", "hardware-support"] include = [ - "/src/**/*.rs", "/LICENSE-*", "/README.md", "/build.rs", + "/patch/**/*.yaml", + "/src/**/*.rs", + "/vendor/*.atdf", + "/vendor/LICENSE", ] [package.metadata.docs.rs] @@ -64,8 +67,9 @@ attiny88 = ["device-selected"] attiny1614 = ["device-selected"] avr64du32 = ["device-selected"] avr64du28 = ["device-selected"] -rt = ["avr-device-macros"] +rt = ["avr-device-macros", "critical-section"] +critical-section = ["critical-section-impl"] critical-section-impl = ["critical-section/restore-state-u8"] # Unfortunately, we can only build documentation for a single MCU. @@ -83,10 +87,19 @@ path = "macros/" version = "=0.5.4" optional = true +[build-dependencies] +svd2rust = "0.33.2" +svdtools = "0.3.14" +atdf2svd = "0.4.0" + [dev-dependencies] nb = "0.1.2" embedded-hal = "0.2.3" +[lib] +test = false +bench = false + [[example]] name = "atmega328p" path = "examples/atmega328p/src/main.rs" diff --git a/Makefile b/Makefile deleted file mode 100644 index 54751c6..0000000 --- a/Makefile +++ /dev/null @@ -1,73 +0,0 @@ -all: deps chips - -CHIPS := at90usb1286 atmega1280 atmega1284p atmega128a atmega128rfa1 atmega16 atmega164pa atmega168 atmega2560 atmega8 atmega8u2 atmega324pa atmega328p atmega328pb atmega32a atmega32u4 atmega4808 atmega4809 atmega48p atmega64 atmega644 atmega88p attiny13a attiny202 attiny2313 attiny2313a attiny402 attiny404 attiny44a attiny84 attiny85 attiny88 attiny816 attiny828 attiny841 attiny84a attiny861 attiny167 attiny1614 avr64du32 avr64du28 - -RUSTUP_TOOLCHAIN ?= nightly - -PATCHES := $(foreach chip, $(CHIPS), $(wildcard patch/$(chip).yaml)) -DEPS := $(foreach patch, $(PATCHES), $(patsubst patch/%.yaml, .deps/%.d, $(patch))) - -.PHONY: chips deps $(CHIPS) all clean -chips: $(CHIPS) -deps: $(DEPS) - -$(foreach chip, $(CHIPS), $(eval $(chip): src/devices/$(chip)/mod.rs)) - -.SECONDARY: -svd/%.svd: vendor/%.atdf - @mkdir -p svd - @echo -e "\tATDF2SVD\t$*" - @atdf2svd $< $@ 2>/dev/null - -$(foreach patch, $(PATCHES), $(eval $(patsubst patch/%.yaml, svd/%.svd.patched, $(patch)): $(patch))) - -svd/%.svd.patched: svd/%.svd .deps/%.d - @if [ -f patch/$*.yaml ] ; then \ - echo -e "\tPATCH\t\t$*"; \ - svdtools patch patch/$*.yaml; \ - test -e $@; \ - else \ - echo -e "\t - No patches found for $*"; \ - cp $< $@; \ - fi - -src/devices/%/mod.full.rs: svd/%.svd.patched - @mkdir -p $(@D) - @echo -e "\tSVD2RUST\t$*" - @cd $(@D); svd2rust --generic_mod --make_mod --target none -i $(realpath $<) - @mv $(@D)/mod.rs $@ - @mv $(@D)/generic.rs $(@D)/../../generic.rs - -src/devices/%/mod.rs: src/devices/%/mod.full.rs - @echo -e "\tFORM\t\t$*" - @RUST_LOG=WARN form -i $< -o $(@D) >/dev/null - @rm $< - @mv $(@D)/lib.rs $@ - @RUSTUP_TOOLCHAIN=$(RUSTUP_TOOLCHAIN) rustfmt $@ - @# Remove the `extern crate` lines - @sed -i'' -e "/^extern crate/d" $@ - @# Remove DEVICE_PERIPHERALS declaration and replace it with a reference - @# to the global version - @patch --no-backup-if-mismatch --quiet $@ patch/modrs.patch - @# Fixup the take() implementation - @sed -i'' -e '/#\[cfg(feature = "critical-section")]/d' $@ - @sed -i'' -e 's/critical_section::with/crate::interrupt::free/' $@ - -clean: - @echo -e "\tCLEAN\t\t./svd/" - @rm -rf svd/ - @echo -e "\tCLEAN\t\t./src/devices" - @rm -rf src/devices/at* - @echo -e "\tCLEAN\t\t./src/generic.rs" - @rm -f src/generic.rs - @echo -e "\tCLEAN\t\t./.deps/" - @rm -rf .deps/ - -# Patch dependencies -patch/%.yaml: .deps/%.d -.deps/%.d: patch/%.yaml - @mkdir -p .deps - @echo -e "\tMAKEDEPS\t$*" - @svdtools makedeps $< $@ - --include $(DEPS) diff --git a/README.md b/README.md index 23f0272..70f0b94 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,11 @@ Add the following to `Cargo.toml`: ```toml [dependencies.avr-device] version = "0.5.4" -features = ["atmega32u4"] +features = ["atmega32u4", "rt"] ``` -Via the feature you can select which chip you want the register specifications for. The following list is what is currently supported: +Via the features you can select which chip you want the register specifications +for. The following list is what is currently supported: | ATmega | ATmega USB | ATmega 0,1 Series | AT90 | ATtiny | | :-------------: | :----------: | :---------------: | :-----------: | :-----------: | @@ -32,63 +33,80 @@ Via the feature you can select which chip you want the register specifications f | `atmega2560` | | | | `attiny2313` | | `atmega164pa` | | | | `attiny2313a` | -## Build Instructions -The version on `crates.io` is pre-built. The following is only necessary when trying to build this crate from source. - -You need to have [atdf2svd][] (= 0.4.0), [svd2rust][] (= 0.28), [form][] (>= 0.8), [rustfmt][](for the *nightly* toolchain) and [svdtools][] (>= 0.1.9) installed: -```bash -cargo install atdf2svd --version 0.4.0 -cargo install svd2rust --version 0.28.0 -cargo install form -rustup component add --toolchain nightly rustfmt -pip3 install --user svdtools - -# check svdtools -svd --version -# if a "command not found" error is printed instead of a version, -# either svdtools is installed incorrectly, or its installation path is missing from the PATH variable. -# Temporary solution to PATH variable issue is to manually add the path. Like so: -export PATH=$PATH:~/.local/bin -``` - -[atdf2svd]: https://github.com/Rahix/atdf2svd -[svd2rust]: https://github.com/rust-embedded/svd2rust -[form]: https://github.com/djmcgill/form -[rustfmt]: https://github.com/rust-lang/rustfmt -[svdtools]: https://github.com/rust-embedded/svdtools - -Next, clone this repo and build the device definitions: -```bash -git clone https://github.com/Rahix/avr-device -cd avr-device -make -# You can build for just one specific chip using -# make atmega32u4 -# I suggest building documentation as well -cargo +nightly doc --features --open -``` +The `rt` feature, while optional, provides some minimal +startup/interrupt-handling code most projects will benefit from. It also enables +the `critical-section` feature, without which all peripheral access is +considered `unsafe` and the API becomes more limited. -## Internals -*avr-device* is generated using [`atdf2svd`](https://github.com/Rahix/atdf2svd) and [`svd2rust`](https://github.com/rust-embedded/svd2rust). The vendor-provided *atdf* files can be found in `vendor/`. The intermediate svd files are patched by `svdpatch.py` (Adapted from [`svdpatch.py`](https://github.com/stm32-rs/stm32-rs/blob/master/scripts/svdpatch.py) in [stm32-rs](https://github.com/stm32-rs/stm32-rs)) with device-dependent patches in `patch/`, mainly to improve undescriptive names and missing descriptions. +## Build Instructions +The PACs (Peripheral Access Crates, or really modules, in our case) **are not** +checked into git. Rather, we generate them at build time, via an automated +process implemented in [`build.rs`](./build.rs). It takes the ATDF files +Microchip (former Atmel) provides plus some patches of our own making as inputs, +and outputs a module generated from those device descriptions. These inputs +**are** checked-in. The process is similar to what the `*bindgen` crates +provide, just has more steps. So, in short, building should be a matter of +selecting the features and running cargo. ### Adding a new Chip -To add a new chip, download the *atdf* from (or [avr-mcu/packs/](https://github.com/avr-rust/avr-mcu/tree/master/packs)) and place it in `vendor/`. Be sure to name it like the Rust module that should be generated. Next, you need to integrate it into the base crate and build system. Follow what was done in commit [290613454fbd ("Add basic support for ATmega64")](https://github.com/Rahix/avr-device/commit/290613454fbdc5e4ac98e53deccaf74dafc88963). Please adhere to the alphabetical sorting that is present so far. - -Next, you **must** create a `.yaml` in `patch/` which has at least the following content: -```yaml -_svd: ../svd/.svd -``` - -If more patches need to be applied (most likely!), they should be added into this file as well. The patching format is documented in the [`svdtools` README](https://github.com/stm32-rs/svdtools#device-and-peripheral-yaml-format). Ideally, try to reuse the exisiting patches in `patch/common/` or `patch/timer/`. - -Finally, try building the crate for your MCU with `make `. +To add a new chip: + +1. Download the ATDF from and place it in + `vendor/`. Be sure to name it like the Rust module that should be generated. +2. Add a feature of the same name to `Cargo.toml` (it should enable + `device-selected`); +3. Add any needed patches to a yaml file with the same name under the `patch` + directory, ideally by including some of the snippets present in + `patch/common` and `patch/timer`; The format is decribed + [here](https://github.com/rust-embedded/svdtools#device-and-peripheral-yaml-format), + but it should not include the top-level `_svd` key, as that's handled by the + build system; If patching is unneeded (most likely it is!), the file can be + ommited. +4. Include the module into the tree, in [`devices.rs`](./src/devices.rs), + following the format used by other modules in that file; +5. Finally, try building the crate for your MCU with + `cargo build --features ,rt`. +6. Also check the built documentation for inconsistencies, via + `cargo doc --features ,rt --open` (it will pop up in your browser). + +## Internals +Since the vendor does not provide SVDs we can pass to [`svd2rust`][], we +generate one via [`atdf2svd`][]. The sequence is as follows: + +1. Check which MCUs are known to the crate + ([build.rs:get_available_mcus](./build.rs#L21-L40)); +2. Select which to build for by checking enabled features + ([build.rs:select_mcu](./build.rs#L42-L62)); +3. Generate the Rust module ([build.rs:build_mcu_module](./build.rs#L64-L148)); + + Substeps are: + 1. Register inputs with cargo; + 2. Get a temporary directory; + 3. Apply `atdf2svd`; + 4. If a yaml patch exists, use it via [`svdtools`][] and read the new content + / else, read the content of the unpatched file to continue; + 5. Get the output directory; + 6. Apply `svd2rust`; + 7. Run [`rustfmt`][] on the module to make it readable in [`docs.rs`][]; +4. It will be included from `$OUT_DIR/pac/.rs` into the path + `avr_device::devices::` (private), and re-exported as + `avr_device::` (public). + +[`atdf2svd`]: https://github.com/Rahix/atdf2svd +[`svd2rust`]: https://github.com/rust-embedded/svd2rust +[`svdtools`]: https://github.com/rust-embedded/svdtools +[`rustfmt`]: https://github.com/rust-lang/rustfmt +[`docs.rs`]: https://docs.rs/avr-device/latest/avr_device ## License *avr-device* is 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) + * 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. -The vendored *atdf* files are licensed under the Apache License, Version 2.0 ([LICENSE-VENDOR](vendor/LICENSE)). +The vendored *atdf* files are licensed under the Apache License, Version 2.0 +([LICENSE-VENDOR](vendor/LICENSE)). diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..c219c1e --- /dev/null +++ b/build.rs @@ -0,0 +1,162 @@ +#![feature(io_error_more)] +#![feature(exit_status_error)] + +use atdf2svd::{atdf, svd}; +use std::{ + collections::HashSet, + env, + fs::{self, File}, + io, + path::{Path, PathBuf}, process::{Command, Stdio}, +}; +use svd2rust::config; +use svdtools::patch; + +fn main() { + let mcus = get_available_mcus(); + let mcu = select_mcu(&mcus); + build_mcu_module(&mcu); +} + +fn get_available_mcus() -> Vec { + let crate_root = env::var_os("CARGO_MANIFEST_DIR").unwrap(); + let packs_dir = Path::new(&crate_root).join("vendor"); + // Reserve a number greater than there are atdf files in ./vendor, so we + // don't have to extend between iterations. A bit of overshoot is used so + // people won't have to remember changing this when adding a chip. + let mut available_mcus = Vec::with_capacity(50); + for pack_file in fs::read_dir(&packs_dir).unwrap() { + if let Some(mcu) = pack_file + .unwrap() + .file_name() + .to_str() + .unwrap() + .strip_suffix(".atdf") + { + available_mcus.push(mcu.to_owned()); + } + } + available_mcus +} + +fn select_mcu(mcus: &[String]) -> String { + let mut pack_name = None; + for mcu in mcus { + if let Ok(_) = env::var(format!("CARGO_FEATURE_{}", mcu.to_uppercase())) { + if pack_name.is_none() { + pack_name = Some(mcu.to_owned()); + } else { + panic!("More than one MCU feature selected!"); + } + } + } + pack_name + .expect(&format!( + "No MCU feature selected! \ + The avr-device crate requires exactly one to be enabled in order to \ + know your target's peripherals. Currently available are:\n\ + {}", + mcus.join("\n"), + )) + .to_owned() +} + +fn build_mcu_module(mcu: &str) { + // Register our inputs with Cargo. + let crate_root = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()); + let atdf_file = crate_root.join("vendor").join(format!("{}.atdf", mcu)); + println!("cargo::rerun-if-changed={}", atdf_file.display()); + let patch_dir = crate_root.join("patch"); + let patch_file = patch_dir.join(format!("{}.yaml", mcu)); + println!("cargo::rerun-if-changed={}", patch_file.display()); + + // Get a temporary directory to work inside. + let temp_dir = env::temp_dir().join(format!("avr-device-build-{}", mcu)); + ensure_directory(&temp_dir); + + // Apply atdf2svd. + let atdf_reader = File::open(&atdf_file).unwrap(); + let atdf_parsed = match atdf::parse(atdf_reader, &HashSet::::new()) { + Ok(chip) => chip, + Err(what) => { + let _ = what.format(&mut io::stdout()); + panic!("Failed to parse \"{}\"!", atdf_file.display()); + } + }; + let svd_file = temp_dir.join("unpatched.svd"); + let svd_writer = File::create(&svd_file).unwrap(); + if let Err(what) = svd::generate(&atdf_parsed, svd_writer) { + let _ = what.format(&mut io::stdout()); + panic!("Failed to generate \"{}\"!", svd_file.display()); + } + + let svd_content; + if let Ok(true) = patch_file.try_exists() { + // Point the patch file to our generated svd and apply the patch. + let includer_content = format!( + r#"_svd: {} + +_include: +- {} +"#, + svd_file.display(), + patch_file.display() + ); + let includer_file = temp_dir.join("patch.yaml"); + fs::write(&includer_file, &includer_content).unwrap(); + let svd_patched_file = temp_dir.join("patched.svd"); + patch::process_file( + &includer_file, + Some(&svd_patched_file), + None, + &Default::default(), + ) + .unwrap(); + + // Read the contents after patching. + svd_content = fs::read_to_string(&svd_patched_file).unwrap(); + } else { + // No patching needed, just read the svd. + svd_content = fs::read_to_string(&svd_file).unwrap(); + } + + // Apply svd2rust. + let out_dir = env::var("OUT_DIR").unwrap(); + let pac_dir = Path::new(&out_dir).join("pac"); + ensure_directory(&pac_dir); + let mut svd2rust_config = config::Config::default(); + svd2rust_config.target = config::Target::None; + svd2rust_config.generic_mod = true; + svd2rust_config.make_mod = true; + svd2rust_config.skip_crate_attributes = true; + svd2rust_config.strict = true; + svd2rust_config.output_dir = Some(pac_dir.to_owned()); + svd2rust_config.interrupt_link_section = Some(".text.vector".to_owned()); + let generated = svd2rust::generate(&svd_content, &svd2rust_config).unwrap(); + let module_file = pac_dir.join(mcu).with_extension("rs"); + fs::write(&module_file, generated.lib_rs).unwrap(); + + let status = Command::new("rustfmt") + .arg(module_file.to_str().unwrap()) + .stdin(Stdio::null()) + .stdout(Stdio::null()) + .status() + .unwrap(); + if let Err(what) = status.exit_ok() { + panic!("rustfmt failed to format generated source with: {}", what); + } +} + +fn ensure_directory(dir: &Path) { + if dir.is_dir() { + return; + } else if dir.try_exists().unwrap() { + println!( + "cargo::warning=A non-directory exists in \"{0}\", it will be moved to \"{0}.before\" and a directory created in its place.", + dir.display() + ); + fs::rename(&dir, dir.with_extension("before")).unwrap(); + } + + fs::create_dir(dir).unwrap(); +} diff --git a/examples/atmega328p/src/main.rs b/examples/atmega328p/src/main.rs index fc2b5dd..791bef3 100644 --- a/examples/atmega328p/src/main.rs +++ b/examples/atmega328p/src/main.rs @@ -25,7 +25,7 @@ fn panic(_info: &core::panic::PanicInfo) -> ! { // SAFETY: Because main() already has references to the peripherals this is an unsafe // operation - but because no other code can run after the panic handler was called, // we know it is okay. - let dp = unsafe { atmega328p::Peripherals::steal() }; + let dp = unsafe { Peripherals::steal() }; loop { avr_device::asm::delay_cycles(1_000_000); diff --git a/patch/at90usb1286.yaml b/patch/at90usb1286.yaml index 7ca8b0f..8a0a923 100644 --- a/patch/at90usb1286.yaml +++ b/patch/at90usb1286.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/at90usb1286.svd - _include: - "common/ac.yaml" - "common/adc.yaml" diff --git a/patch/atmega1280.yaml b/patch/atmega1280.yaml index d66b208..9c6cafa 100644 --- a/patch/atmega1280.yaml +++ b/patch/atmega1280.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/atmega1280.svd - _include: - "common/ac.yaml" - "common/adc.yaml" diff --git a/patch/atmega1284p.yaml b/patch/atmega1284p.yaml index fea3f1f..5f44c5b 100644 --- a/patch/atmega1284p.yaml +++ b/patch/atmega1284p.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/atmega1284p.svd - _include: - "common/ac.yaml" - "common/adc.yaml" diff --git a/patch/atmega128a.yaml b/patch/atmega128a.yaml index 405af3d..ae779a5 100644 --- a/patch/atmega128a.yaml +++ b/patch/atmega128a.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/atmega128a.svd - _include: - "common/ac.yaml" - "common/adc.yaml" diff --git a/patch/atmega128rfa1.yaml b/patch/atmega128rfa1.yaml index c82be77..900c537 100644 --- a/patch/atmega128rfa1.yaml +++ b/patch/atmega128rfa1.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/atmega128rfa1.svd - # this isn't complete, but the MAN_ID_0 field is broken into bits, and has an # associated 8-bit wide enum which is associated with bit 0 rather than the # entire register. many other registers within the TRX24 are incorrectly split diff --git a/patch/atmega16.yaml b/patch/atmega16.yaml index b7cefcd..33dc54b 100644 --- a/patch/atmega16.yaml +++ b/patch/atmega16.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/atmega16.svd - _include: - "common/ac.yaml" - "common/adc.yaml" diff --git a/patch/atmega164pa.yaml b/patch/atmega164pa.yaml index 8f144db..e056269 100644 --- a/patch/atmega164pa.yaml +++ b/patch/atmega164pa.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/atmega164pa.svd - _include: - "common/adc.yaml" - "common/twi.yaml" diff --git a/patch/atmega168.yaml b/patch/atmega168.yaml index ef8f6a6..5dca314 100644 --- a/patch/atmega168.yaml +++ b/patch/atmega168.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/atmega168.svd - _include: - "common/ac.yaml" - "common/adc.yaml" diff --git a/patch/atmega2560.yaml b/patch/atmega2560.yaml index d10b31d..9c6cafa 100644 --- a/patch/atmega2560.yaml +++ b/patch/atmega2560.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/atmega2560.svd - _include: - "common/ac.yaml" - "common/adc.yaml" diff --git a/patch/atmega324pa.yaml b/patch/atmega324pa.yaml index 7e14d14..e86b941 100644 --- a/patch/atmega324pa.yaml +++ b/patch/atmega324pa.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/atmega324pa.svd - _include: - "common/ac.yaml" - "common/adc.yaml" diff --git a/patch/atmega328p.yaml b/patch/atmega328p.yaml index 9ae1eff..1f9930e 100644 --- a/patch/atmega328p.yaml +++ b/patch/atmega328p.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/atmega328p.svd - _include: - "common/ac.yaml" - "common/adc.yaml" diff --git a/patch/atmega328pb.yaml b/patch/atmega328pb.yaml index db9c1d2..dfddec3 100644 --- a/patch/atmega328pb.yaml +++ b/patch/atmega328pb.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/atmega328pb.svd - # Remove index suffix from all registers and fields SPI0: _strip_end: diff --git a/patch/atmega32a.yaml b/patch/atmega32a.yaml index e5e5eb6..12c60bc 100644 --- a/patch/atmega32a.yaml +++ b/patch/atmega32a.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/atmega32a.svd - _include: - "common/ac.yaml" - "common/adc.yaml" diff --git a/patch/atmega32u4.yaml b/patch/atmega32u4.yaml index a2cb857..4dff06a 100644 --- a/patch/atmega32u4.yaml +++ b/patch/atmega32u4.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/atmega32u4.svd - _include: - "common/ac.yaml" - "common/adc.yaml" diff --git a/patch/atmega4808.yaml b/patch/atmega4808.yaml deleted file mode 100644 index f5d159a..0000000 --- a/patch/atmega4808.yaml +++ /dev/null @@ -1 +0,0 @@ -_svd: ../svd/atmega4808.svd diff --git a/patch/atmega4809.yaml b/patch/atmega4809.yaml deleted file mode 100644 index e874590..0000000 --- a/patch/atmega4809.yaml +++ /dev/null @@ -1 +0,0 @@ -_svd: ../svd/atmega4809.svd diff --git a/patch/atmega48p.yaml b/patch/atmega48p.yaml index 3159302..5dca314 100644 --- a/patch/atmega48p.yaml +++ b/patch/atmega48p.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/atmega48p.svd - _include: - "common/ac.yaml" - "common/adc.yaml" diff --git a/patch/atmega64.yaml b/patch/atmega64.yaml index f7e33ad..08350b0 100644 --- a/patch/atmega64.yaml +++ b/patch/atmega64.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/atmega64.svd - _include: - "common/ac.yaml" - "common/adc.yaml" diff --git a/patch/atmega644.yaml b/patch/atmega644.yaml index 84843bc..5dca314 100644 --- a/patch/atmega644.yaml +++ b/patch/atmega644.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/atmega644.svd - _include: - "common/ac.yaml" - "common/adc.yaml" diff --git a/patch/atmega8.yaml b/patch/atmega8.yaml index b34bd26..adc6dfa 100644 --- a/patch/atmega8.yaml +++ b/patch/atmega8.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/atmega8.svd - _include: - "common/ac.yaml" - "common/adc.yaml" diff --git a/patch/atmega88p.yaml b/patch/atmega88p.yaml index b0ed252..5dca314 100644 --- a/patch/atmega88p.yaml +++ b/patch/atmega88p.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/atmega88p.svd - _include: - "common/ac.yaml" - "common/adc.yaml" diff --git a/patch/atmega8u2.yaml b/patch/atmega8u2.yaml index 7209b7f..ea8cdad 100644 --- a/patch/atmega8u2.yaml +++ b/patch/atmega8u2.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/atmega8u2.svd - _include: - "common/ac.yaml" - "common/eeprom.yaml" diff --git a/patch/attiny13a.yaml b/patch/attiny13a.yaml index 053568a..e6b7df0 100644 --- a/patch/attiny13a.yaml +++ b/patch/attiny13a.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/attiny13a.svd - _include: - "common/ac.yaml" - "common/eeprom.yaml" diff --git a/patch/attiny1614.yaml b/patch/attiny1614.yaml deleted file mode 100644 index 6a5f01f..0000000 --- a/patch/attiny1614.yaml +++ /dev/null @@ -1 +0,0 @@ -_svd: ../svd/attiny1614.svd diff --git a/patch/attiny167.yaml b/patch/attiny167.yaml index 77d2421..2905320 100644 --- a/patch/attiny167.yaml +++ b/patch/attiny167.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/attiny167.svd - _include: - "common/ac.yaml" - "common/eeprom.yaml" diff --git a/patch/attiny202.yaml b/patch/attiny202.yaml index b11e37c..20446d2 100644 --- a/patch/attiny202.yaml +++ b/patch/attiny202.yaml @@ -1,4 +1,2 @@ -_svd: ../svd/attiny202.svd - _include: - common/attiny-0-series.yaml diff --git a/patch/attiny2313.yaml b/patch/attiny2313.yaml index 4fa3c69..6845164 100644 --- a/patch/attiny2313.yaml +++ b/patch/attiny2313.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/attiny2313.svd - _include: - "attiny2313-common.yaml" - "common/usart-single-attiny2313.yaml" diff --git a/patch/attiny2313a.yaml b/patch/attiny2313a.yaml index e5f545f..3c13fe6 100644 --- a/patch/attiny2313a.yaml +++ b/patch/attiny2313a.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/attiny2313a.svd - _include: - "attiny2313-common.yaml" - "common/usart-single-attiny2313a.yaml" diff --git a/patch/attiny402.yaml b/patch/attiny402.yaml index 7ac2fe2..20446d2 100644 --- a/patch/attiny402.yaml +++ b/patch/attiny402.yaml @@ -1,4 +1,2 @@ -_svd: ../svd/attiny402.svd - _include: - common/attiny-0-series.yaml diff --git a/patch/attiny404.yaml b/patch/attiny404.yaml index 5080ecd..20446d2 100644 --- a/patch/attiny404.yaml +++ b/patch/attiny404.yaml @@ -1,4 +1,2 @@ -_svd: ../svd/attiny404.svd - _include: - common/attiny-0-series.yaml diff --git a/patch/attiny44a.yaml b/patch/attiny44a.yaml deleted file mode 100644 index 67d92ba..0000000 --- a/patch/attiny44a.yaml +++ /dev/null @@ -1 +0,0 @@ -_svd: ../svd/attiny44a.svd diff --git a/patch/attiny816.yaml b/patch/attiny816.yaml index f1c3e2f..7658a24 100644 --- a/patch/attiny816.yaml +++ b/patch/attiny816.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/attiny816.svd - CRCSCAN: CTRLB: SRC: diff --git a/patch/attiny828.yaml b/patch/attiny828.yaml index c814854..479155f 100644 --- a/patch/attiny828.yaml +++ b/patch/attiny828.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/attiny828.svd - _include: - "common/ac.yaml" - "common/eeprom.yaml" diff --git a/patch/attiny84.yaml b/patch/attiny84.yaml index 6e24547..6528f32 100644 --- a/patch/attiny84.yaml +++ b/patch/attiny84.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/attiny84.svd - _include: - "common/ac.yaml" - "common/eeprom.yaml" diff --git a/patch/attiny841.yaml b/patch/attiny841.yaml index 7029367..0be7d70 100644 --- a/patch/attiny841.yaml +++ b/patch/attiny841.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/attiny841.svd - _include: - "common/ac.yaml" - "common/spi.yaml" diff --git a/patch/attiny84a.yaml b/patch/attiny84a.yaml index d9caea2..7116a92 100644 --- a/patch/attiny84a.yaml +++ b/patch/attiny84a.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/attiny84a.svd - _include: - "common/eeprom.yaml" diff --git a/patch/attiny85.yaml b/patch/attiny85.yaml index cd1d0c5..5951fbc 100644 --- a/patch/attiny85.yaml +++ b/patch/attiny85.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/attiny85.svd - _include: - "common/ac.yaml" - "common/eeprom.yaml" diff --git a/patch/attiny861.yaml b/patch/attiny861.yaml index f44ad52..cba99e3 100644 --- a/patch/attiny861.yaml +++ b/patch/attiny861.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/attiny861.svd - _include: - "common/ac.yaml" - "common/adc.yaml" diff --git a/patch/attiny88.yaml b/patch/attiny88.yaml index 46c777b..5faf28e 100644 --- a/patch/attiny88.yaml +++ b/patch/attiny88.yaml @@ -1,5 +1,3 @@ -_svd: ../svd/attiny88.svd - _include: - "common/ac.yaml" - "common/eeprom.yaml" diff --git a/patch/avr64du28.yaml b/patch/avr64du28.yaml deleted file mode 100644 index 83f7573..0000000 --- a/patch/avr64du28.yaml +++ /dev/null @@ -1 +0,0 @@ -_svd: ../svd/avr64du28.svd diff --git a/patch/avr64du32.yaml b/patch/avr64du32.yaml deleted file mode 100644 index 65d70cb..0000000 --- a/patch/avr64du32.yaml +++ /dev/null @@ -1 +0,0 @@ -_svd: ../svd/avr64du32.svd diff --git a/patch/modrs.patch b/patch/modrs.patch deleted file mode 100644 index e165b70..0000000 --- a/patch/modrs.patch +++ /dev/null @@ -1,5 +0,0 @@ -1337,1338c1337 -< #[no_mangle] -< static mut DEVICE_PERIPHERALS: bool = false; ---- -> use crate::devices::DEVICE_PERIPHERALS; diff --git a/src/devices/mod.rs b/src/devices.rs similarity index 54% rename from src/devices/mod.rs rename to src/devices.rs index 7575027..1707534 100644 --- a/src/devices/mod.rs +++ b/src/devices.rs @@ -1,164 +1,239 @@ -#[allow(renamed_and_removed_lints)] -#[allow(private_no_mangle_statics)] -#[no_mangle] -pub(crate) static mut DEVICE_PERIPHERALS: bool = false; - /// [AT90USB1286](https://www.microchip.com/wwwproducts/en/AT90USB1286) #[cfg(feature = "at90usb1286")] -pub mod at90usb1286; +pub mod at90usb1286 { + include!(concat!(env!("OUT_DIR"), "/pac/at90usb1286.rs")); +} /// [ATmega1280](https://www.microchip.com/wwwproducts/en/ATmega1280) #[cfg(feature = "atmega1280")] -pub mod atmega1280; +pub mod atmega1280 { + include!(concat!(env!("OUT_DIR"), "/pac/atmega1280.rs")); +} /// [ATmega1284P](https://www.microchip.com/en-us/product/ATmega1284P) #[cfg(feature = "atmega1284p")] -pub mod atmega1284p; +pub mod atmega1284p { + include!(concat!(env!("OUT_DIR"), "/pac/atmega1284p.rs")); +} /// [ATmega128A](https://www.microchip.com/wwwproducts/en/ATmega128A) #[cfg(feature = "atmega128a")] -pub mod atmega128a; +pub mod atmega128a { + include!(concat!(env!("OUT_DIR"), "/pac/atmega128a.rs")); +} /// [ATmega128RFA1](https://www.microchip.com/en-us/product/ATmega128RFA1) #[cfg(feature = "atmega128rfa1")] -pub mod atmega128rfa1; +pub mod atmega128rfa1 { + include!(concat!(env!("OUT_DIR"), "/pac/atmega128rfa1.rs")); +} /// [ATmega16](https://www.microchip.com/wwwproducts/en/ATmega16) #[cfg(feature = "atmega16")] -pub mod atmega16; +pub mod atmega16 { + include!(concat!(env!("OUT_DIR"), "/pac/atmega16.rs")); +} /// [ATmega164PA](https://www.microchip.com/en-us/product/ATmega164PA) #[cfg(feature = "atmega164pa")] -pub mod atmega164pa; +pub mod atmega164pa { + include!(concat!(env!("OUT_DIR"), "/pac/atmega164pa.rs")); +} /// [ATmega168](https://www.microchip.com/wwwproducts/en/ATmega168) #[cfg(feature = "atmega168")] -pub mod atmega168; +pub mod atmega168 { + include!(concat!(env!("OUT_DIR"), "/pac/atmega168.rs")); +} /// [ATmega2560](https://www.microchip.com/wwwproducts/en/ATmega2560) #[cfg(feature = "atmega2560")] -pub mod atmega2560; +pub mod atmega2560 { + include!(concat!(env!("OUT_DIR"), "/pac/atmega2560.rs")); +} /// [ATmega324PA](https://www.microchip.com/wwwproducts/en/ATmega324PA) #[cfg(feature = "atmega324pa")] -pub mod atmega324pa; +pub mod atmega324pa { + include!(concat!(env!("OUT_DIR"), "/pac/atmega324pa.rs")); +} /// [ATmega328P](https://www.microchip.com/wwwproducts/en/ATmega328P) #[cfg(feature = "atmega328p")] -pub mod atmega328p; +pub mod atmega328p { + include!(concat!(env!("OUT_DIR"), "/pac/atmega328p.rs")); +} /// [ATmega328PB](https://www.microchip.com/wwwproducts/en/ATmega328PB) #[cfg(feature = "atmega328pb")] -pub mod atmega328pb; +pub mod atmega328pb { + include!(concat!(env!("OUT_DIR"), "/pac/atmega328pb.rs")); +} /// [ATmega32A](https://www.microchip.com/wwwproducts/en/ATmega32A) #[cfg(feature = "atmega32a")] -pub mod atmega32a; +pub mod atmega32a { + include!(concat!(env!("OUT_DIR"), "/pac/atmega32a.rs")); +} /// [ATmega32U4](https://www.microchip.com/wwwproducts/en/ATmega32U4) #[cfg(feature = "atmega32u4")] -pub mod atmega32u4; +pub mod atmega32u4 { + include!(concat!(env!("OUT_DIR"), "/pac/atmega32u4.rs")); +} /// [ATmega4808](https://www.microchip.com/wwwproducts/en/ATmega4808) #[cfg(feature = "atmega4808")] -pub mod atmega4808; +pub mod atmega4808 { + include!(concat!(env!("OUT_DIR"), "/pac/atmega4808.rs")); +} /// [ATmega4809](https://www.microchip.com/wwwproducts/en/ATmega4809) #[cfg(feature = "atmega4809")] -pub mod atmega4809; +pub mod atmega4809 { + include!(concat!(env!("OUT_DIR"), "/pac/atmega4809.rs")); +} /// [ATmega48P](https://www.microchip.com/wwwproducts/en/ATmega48P) #[cfg(feature = "atmega48p")] -pub mod atmega48p; +pub mod atmega48p { + include!(concat!(env!("OUT_DIR"), "/pac/atmega48p.rs")); +} /// [ATmega8](https://www.microchip.com/wwwproducts/en/ATmega8) #[cfg(feature = "atmega8")] -pub mod atmega8; +pub mod atmega8 { + include!(concat!(env!("OUT_DIR"), "/pac/atmega8.rs")); +} /// [ATmega8u2](https://www.microchip.com/wwwproducts/en/ATmega8u2) #[cfg(feature = "atmega8u2")] -pub mod atmega8u2; +pub mod atmega8u2 { + include!(concat!(env!("OUT_DIR"), "/pac/atmega8u2.rs")); +} /// [ATmega64](https://www.microchip.com/wwwproducts/en/ATmega64) #[cfg(feature = "atmega64")] -pub mod atmega64; +pub mod atmega64 { + include!(concat!(env!("OUT_DIR"), "/pac/atmega64.rs")); +} /// [ATmega644](https://www.microchip.com/wwwproducts/en/ATmega644) #[cfg(feature = "atmega644")] -pub mod atmega644; +pub mod atmega644 { + include!(concat!(env!("OUT_DIR"), "/pac/atmega644.rs")); +} /// [ATtiny13A](https://www.microchip.com/wwwproducts/en/ATtiny13A) #[cfg(feature = "attiny13a")] -pub mod attiny13a; +pub mod attiny13a { + include!(concat!(env!("OUT_DIR"), "/pac/attiny13a.rs")); +} /// [ATtiny167](https://www.microchip.com/wwwproducts/en/ATtiny167) #[cfg(feature = "attiny167")] -pub mod attiny167; +pub mod attiny167 { + include!(concat!(env!("OUT_DIR"), "/pac/attiny167.rs")); +} /// [ATtiny1614](https://www.microchip.com/wwwproducts/en/ATtiny1614) #[cfg(feature = "attiny1614")] -pub mod attiny1614; +pub mod attiny1614 { + include!(concat!(env!("OUT_DIR"), "/pac/attiny1614.rs")); +} /// [ATtiny202](https://www.microchip.com/wwwproducts/en/ATtiny202) #[cfg(feature = "attiny202")] -pub mod attiny202; +pub mod attiny202 { + include!(concat!(env!("OUT_DIR"), "/pac/attiny202.rs")); +} /// [ATtiny2313](https://www.microchip.com/wwwproducts/en/ATtiny2313) #[cfg(feature = "attiny2313")] -pub mod attiny2313; +pub mod attiny2313 { + include!(concat!(env!("OUT_DIR"), "/pac/attiny2313.rs")); +} /// [ATtiny2313A](https://www.microchip.com/wwwproducts/en/ATtiny2313A) #[cfg(feature = "attiny2313a")] -pub mod attiny2313a; +pub mod attiny2313a { + include!(concat!(env!("OUT_DIR"), "/pac/attiny2313a.rs")); +} /// [ATtiny402](https://www.microchip.com/en-us/product/ATTINY402) #[cfg(feature = "attiny402")] -pub mod attiny402; +pub mod attiny402 { + include!(concat!(env!("OUT_DIR"), "/pac/attiny402.rs")); +} /// [ATtiny404](https://www.microchip.com/en-us/product/ATTINY404) #[cfg(feature = "attiny404")] -pub mod attiny404; +pub mod attiny404 { + include!(concat!(env!("OUT_DIR"), "/pac/attiny404.rs")); +} /// [ATtiny44a](https://www.microchip.com/en-us/product/ATtiny44a) #[cfg(feature = "attiny44a")] -pub mod attiny44a; +pub mod attiny44a { + include!(concat!(env!("OUT_DIR"), "/pac/attiny44a.rs")); +} /// [ATtiny816](https://www.microchip.com/wwwproducts/en/ATtiny816) #[cfg(feature = "attiny816")] -pub mod attiny816; +pub mod attiny816 { + include!(concat!(env!("OUT_DIR"), "/pac/attiny816.rs")); +} /// [ATtiny828](https://www.microchip.com/wwwproducts/en/ATtiny828) #[cfg(feature = "attiny828")] -pub mod attiny828; +pub mod attiny828 { + include!(concat!(env!("OUT_DIR"), "/pac/attiny828.rs")); +} /// [ATtiny84](https://www.microchip.com/wwwproducts/en/ATtiny84) #[cfg(feature = "attiny84")] -pub mod attiny84; +pub mod attiny84 { + include!(concat!(env!("OUT_DIR"), "/pac/attiny84.rs")); +} /// [ATtiny841](https://www.microchip.com/wwwproducts/en/ATtiny841) #[cfg(feature = "attiny841")] -pub mod attiny841; +pub mod attiny841 { + include!(concat!(env!("OUT_DIR"), "/pac/attiny841.rs")); +} /// [ATtiny84a](https://www.microchip.com/en-us/product/ATtiny84a) #[cfg(feature = "attiny84a")] -pub mod attiny84a; +pub mod attiny84a { + include!(concat!(env!("OUT_DIR"), "/pac/attiny84a.rs")); +} /// [ATtiny85](https://www.microchip.com/wwwproducts/en/ATtiny85) #[cfg(feature = "attiny85")] -pub mod attiny85; +pub mod attiny85 { + include!(concat!(env!("OUT_DIR"), "/pac/attiny85.rs")); +} /// [ATtiny861](https://www.microchip.com/wwwproducts/en/ATtiny861) #[cfg(feature = "attiny861")] -pub mod attiny861; +pub mod attiny861 { + include!(concat!(env!("OUT_DIR"), "/pac/attiny861.rs")); +} /// [ATtiny88](https://www.microchip.com/wwwproducts/en/ATtiny88) #[cfg(feature = "attiny88")] -pub mod attiny88; +pub mod attiny88 { + include!(concat!(env!("OUT_DIR"), "/pac/attiny88.rs")); +} /// [AVR64DU32](https://www.microchip.com/wwwproducts/en/AVR64DU32) #[cfg(feature = "avr64du32")] -pub mod avr64du32; +pub mod avr64du32 { + include!(concat!(env!("OUT_DIR"), "/pac/avr64du32.rs")); +} /// [AVR64DU28](https://www.microchip.com/wwwproducts/en/AVR64DU28) #[cfg(feature = "avr64du28")] -pub mod avr64du28; +pub mod avr64du28 { + include!(concat!(env!("OUT_DIR"), "/pac/avr64du28.rs")); +} diff --git a/src/lib.rs b/src/lib.rs index 2038df8..d096a43 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -162,10 +162,11 @@ pub mod asm; pub mod interrupt; -#[allow(unused_imports)] -use generic::*; +pub(crate) use generic::*; #[doc = r"Common register and bit access and modify traits"] -pub mod generic; +pub mod generic { + include!(concat!(env!("OUT_DIR"), "/pac/generic.rs")); +} /// Attribute to declare an interrupt service routine ///