| Crates.io | avr-device |
| lib.rs | avr-device |
| version | 0.8.1 |
| created_at | 2020-07-26 09:19:36.907261+00 |
| updated_at | 2026-01-06 23:49:02.413233+00 |
| description | Register access crate for AVR microcontrollers |
| homepage | |
| repository | https://github.com/Rahix/avr-device |
| max_upload_size | |
| id | 269692 |
| size | 9,769,194 |
Auto-generated wrappers around registers for AVR microcontrollers.
Add the following to Cargo.toml:
[dependencies.avr-device]
version = "0.8.1"
features = ["atmega32u4"]
With the feature you can select which chip you want the register definitions
for. For a full list of supported AVR chips, please check
Cargo.toml.
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. 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.
To add a new chip:
vendor/. Be sure to name it like the Rust module that should be generated.Cargo.toml (it should enable
device-selected);patch
directory, ideally by including some of the snippets present in
patch/common and patch/timer; The format is decribed
here,
but it should not include the top-level _svd key, as that's handled by the
build system; If patching is unneeded (it's almost always needed!), the file
can be omitted.Cargo.toml, enabling device-selected.devices.rs,
following the format used by other modules in that file;lib.rs to conditionally use the new MCU module,
and add it to the lists of selected and available MCUs in the doc comment.cargo build --features <mcu>,rt.cargo doc --features <mcu>,rt --open (it will pop up in your browser).Since the vendor does not provide SVDs we can pass to svd2rust, we
generate one via atdf2svd. The sequence is as follows:
Check which MCUs are known to the crate (build.rs:get_available_mcus);
Select which to build for by checking enabled features (build.rs:select_mcu);
Generate the Rust module (build.rs:build_mcu_module);
Substeps are:
atdf2svd;svdtools and read the new content
/ else, read the content of the unpatched file to continue;svd2rust;prettyplease on the module to make it readable in docs.rs;It will be included from $OUT_DIR/pac/<mcu>.rs into the path
avr_device::devices::<mcu> (private), and re-exported as
avr_device::<mcu> (public).
avr-device is licensed under either of
at your option.
The vendored atdf files are licensed under the Apache License, Version 2.0 (LICENSE-VENDOR).