attiny_hal/
lib.rs

1#![no_std]
2
3//! `attiny-hal`
4//! =============
5//! Common HAL (hardware abstraction layer) for ATtiny* microcontrollers.
6//!
7//! **Note**: This version of the documentation was built for
8#![cfg_attr(feature = "attiny85", doc = "**ATtiny85**.")]
9#![cfg_attr(feature = "attiny88", doc = "**ATtiny88**.")]
10#![cfg_attr(feature = "attiny167", doc = "**ATtiny167**.")]
11#![cfg_attr(feature = "attiny2313", doc = "**ATtiny2313**.")]
12//! This means that only items which are available for this MCU are visible.  If you are using
13//! a different chip, try building the documentation locally with:
14//!
15//! ```text
16//! cargo doc --features <your-mcu> --open
17//! ```
18
19#[cfg(all(
20    not(feature = "device-selected"),
21    not(feature = "disable-device-selection-error")
22))]
23compile_error!(
24    "This crate requires you to specify your target chip as a feature.
25
26    Please select one of the following
27
28    * attiny85
29    * attiny88
30    * attiny167
31    * attiny2313
32    "
33);
34
35/// Reexport of `attiny167` from `avr-device`
36///
37#[cfg(feature = "attiny167")]
38pub use avr_device::attiny167 as pac;
39/// Reexport of `attiny2313` from `avr-device`
40///
41#[cfg(feature = "attiny2313")]
42pub use avr_device::attiny2313 as pac;
43/// Reexport of `attiny84` from `avr-device`
44///
45#[cfg(feature = "attiny84")]
46pub use avr_device::attiny84 as pac;
47/// Reexport of `attiny85` from `avr-device`
48///
49#[cfg(feature = "attiny85")]
50pub use avr_device::attiny85 as pac;
51/// Reexport of `attiny88` from `avr-device`
52///
53#[cfg(feature = "attiny88")]
54pub use avr_device::attiny88 as pac;
55
56/// See [`avr_device::entry`](https://docs.rs/avr-device/latest/avr_device/attr.entry.html).
57#[cfg(feature = "rt")]
58pub use avr_device::entry;
59
60/// Reexport of the [`avr_device`](https://docs.rs/avr-device) crate.
61///
62/// This makes items such as `avr_device::interrupt` available without depending
63/// on `avr-device` directly and keeping its version in sync manually.
64pub use avr_device;
65
66#[cfg(feature = "device-selected")]
67pub use pac::Peripherals;
68
69pub use avr_hal_generic::clock;
70pub use avr_hal_generic::delay;
71pub use avr_hal_generic::prelude;
72
73// ATtiny2313 does not have ADC and will not compile with this module
74#[cfg(all(feature = "device-selected", not(feature = "attiny2313")))]
75pub mod adc;
76#[cfg(all(feature = "device-selected", not(feature = "attiny2313")))]
77pub use adc::Adc;
78
79#[cfg(feature = "device-selected")]
80pub mod port;
81#[cfg(feature = "device-selected")]
82pub use port::Pins;
83
84#[cfg(feature = "device-selected")]
85pub mod simple_pwm;
86
87#[cfg(feature = "device-selected")]
88pub mod wdt;
89#[cfg(feature = "device-selected")]
90pub use wdt::Wdt;
91
92#[cfg(feature = "device-selected")]
93pub mod eeprom;
94#[cfg(feature = "device-selected")]
95pub use eeprom::Eeprom;
96
97#[cfg(feature = "device-selected")]
98pub mod spi;
99#[cfg(feature = "device-selected")]
100pub use spi::Spi;
101
102pub struct Attiny;
103
104#[cfg(feature = "attiny84")]
105#[macro_export]
106macro_rules! pins {
107    ($p:expr) => {
108        $crate::Pins::new($p.PORTA, $p.PORTB)
109    };
110}
111#[cfg(feature = "attiny85")]
112#[macro_export]
113macro_rules! pins {
114    ($p:expr) => {
115        $crate::Pins::new($p.PORTB)
116    };
117}
118#[cfg(feature = "attiny88")]
119#[macro_export]
120macro_rules! pins {
121    ($p:expr) => {
122        $crate::Pins::new($p.PORTA, $p.PORTB, $p.PORTC, $p.PORTD)
123    };
124}
125#[cfg(feature = "attiny167")]
126#[macro_export]
127macro_rules! pins {
128    ($p:expr) => {
129        $crate::Pins::new($p.PORTA, $p.PORTB)
130    };
131}
132#[cfg(feature = "attiny2313")]
133#[macro_export]
134macro_rules! pins {
135    ($p:expr) => {
136        $crate::Pins::new($p.PORTA, $p.PORTB, $p.PORTD)
137    };
138}