diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cdba5321d3..b9955663c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -123,6 +123,11 @@ jobs: - name: Test-compile HAL crate for an MCU if: "${{ matrix.m.type == 'mcu' }}" run: cd "mcu/${{ matrix.m.crate }}" && cargo build --features "${{ matrix.m.name }}" -Z build-std=core --target "../../avr-specs/avr-${{ matrix.m.spec }}.json" + - name: Compile doctests for an ATmega MCU + if: "${{ matrix.m.crate == 'atmega-hal' }}" + run: >- + cd "mcu/${{ matrix.m.crate }}" && + cargo test --doc --features "${{ matrix.m.name }},enable-extra-adc" -Z build-std=core --target "../../avr-specs/avr-${{ matrix.m.spec }}.json" ravedude: name: "ravedude" diff --git a/mcu/atmega-hal/Cargo.toml b/mcu/atmega-hal/Cargo.toml index 4c2ce80145..0161284782 100644 --- a/mcu/atmega-hal/Cargo.toml +++ b/mcu/atmega-hal/Cargo.toml @@ -105,6 +105,11 @@ _peripheral-spi = [] _peripheral-usart = [] no-globals = [] +[dev-dependencies] +embedded-hal = "1.0" +ufmt = "0.2.0" +nb = "1.1.0" + [dependencies] avr-hal-generic = { path = "../../avr-hal-generic/" } diff --git a/mcu/atmega-hal/src/atmega164pa.rs b/mcu/atmega-hal/src/atmega164pa.rs index d6d15605b9..54b480611a 100644 --- a/mcu/atmega-hal/src/atmega164pa.rs +++ b/mcu/atmega-hal/src/atmega164pa.rs @@ -127,17 +127,25 @@ macro_rules! atmega164pa_timer_8bit_impl { ) => { paste! { avr_hal_generic::impl_simple_pwm! { - /// Use `$peripheral` for PWM (pins `$pin`,) + #[doc = concat!("Use `", stringify!($peripheral), "` for PWM.")] /// /// # Example - /// ``` - /// let mut timer0 = Timer0Pwm::new(dp.$peripheral, Prescaler::Prescale64); + /// ```no_run + #[doc = concat!("use atmega_hal::", stringify!($hal), " as hal;")] + #[doc = concat!("use hal::simple_pwm::{IntoPwmPin,", stringify!($timer), ",Prescaler};")] /// - /// let mut d0 = pins.d0.into_output().into_pwm(&mut timer0); - /// let mut d1 = pins.d1.into_output().into_pwm(&mut timer0); + /// let dp = hal::Peripherals::take().unwrap(); + /// let pins = hal::pins!(dp); + #[doc = concat!("let mut timer = ", stringify!($timer), "::new(dp.", stringify!($peripheral), ", Prescaler::Prescale64);")] /// - /// d0.set_duty(128); - /// d0.enable(); + $( + #[doc = paste!{ concat!( + "let mut ", stringify!([< $pin:lower >]), " = pins.", stringify!([< $pin:lower >]), ".into_output().into_pwm(&mut timer);\n", + stringify!([< $pin:lower >]), ".set_duty(128);\n", + stringify!([< $pin:lower >]), ".enable();\n", + "\n", + ) }] + )+ /// ``` pub struct $timer { timer: crate::$hal::pac::$peripheral, @@ -189,17 +197,25 @@ macro_rules! atmega164pa_timer_16bit_impl { ) => { paste! { avr_hal_generic::impl_simple_pwm! { - /// Use `$peripheral` for PWM (pins `$pin`,) + #[doc = concat!("Use `", stringify!($peripheral), "` for PWM.")] /// /// # Example - /// ``` - /// let mut timer0 = Timer0Pwm::new(dp.$peripheral, Prescaler::Prescale64); + /// ```no_run + #[doc = concat!("use atmega_hal::", stringify!($hal), " as hal;")] + #[doc = concat!("use hal::simple_pwm::{IntoPwmPin,", stringify!($timer), ",Prescaler};")] /// - /// let mut d0 = pins.d0.into_output().into_pwm(&mut timer0); - /// let mut d1 = pins.d1.into_output().into_pwm(&mut timer0); + /// let dp = hal::Peripherals::take().unwrap(); + /// let pins = hal::pins!(dp); + #[doc = concat!("let mut timer = ", stringify!($timer), "::new(dp.", stringify!($peripheral), ", Prescaler::Prescale64);")] /// - /// d0.set_duty(128); - /// d0.enable(); + $( + #[doc = paste!{ concat!( + "let mut ", stringify!([< $pin:lower >]), " = pins.", stringify!([< $pin:lower >]), ".into_output().into_pwm(&mut timer);\n", + stringify!([< $pin:lower >]), ".set_duty(128);\n", + stringify!([< $pin:lower >]), ".enable();\n", + "\n", + ) }] + )+ /// ``` pub struct $timer { timer: crate::$hal::pac::$peripheral, diff --git a/mcu/atmega-hal/src/impl/adc.rs b/mcu/atmega-hal/src/impl/adc.rs index 5376ac1fb9..97d28c7515 100644 --- a/mcu/atmega-hal/src/impl/adc.rs +++ b/mcu/atmega-hal/src/impl/adc.rs @@ -19,28 +19,49 @@ macro_rules! impl_mod_adc { pub mod adc { //! Analog-to-Digital Converter //! - //! # Example - //! - //! Complete example source code can be found in the repository: + //! For full source code, please refer to the ATmega ADC example: //! [`atmega2560-adc.rs`](https://github.com/Rahix/avr-hal/blob/main/examples/atmega2560/src/bin/atmega2560-adc.rs) //! + //! # Example: Read pins using `analog_read()` + //! + //! ```no_run + #![doc = concat!("use atmega_hal::", stringify!($hal), " as hal;")] + //! + //! let dp = hal::Peripherals::take().unwrap(); + //! let pins = hal::pins!(dp); + //! + //! let mut adc = hal::Adc::::new(dp.ADC, Default::default()); + //! + $( + #![doc = paste!{ concat!( + "let ", stringify!([< input_ $pin_name:lower >]), " = pins.", stringify!([< $pin_name:lower >]), ".into_analog_input(&mut adc);\n", + "let ", stringify!([< value_ $pin_name:lower >]), " = ", stringify!([< input_ $pin_name:lower >]), ".analog_read(&mut adc);\n\n" + )}] + )* //! ``` - //! let dp = atmega_hal::Peripherals::take().unwrap(); - //! let pins = atmega_hal::pins!(dp); //! - //! let mut adc = Adc::new(dp.ADC, Default::default()); + //! # Example: Read channels (including pins) using `read_blocking()` + //! + //! ```no_run + #![doc = concat!("use atmega_hal::", stringify!($hal), " as hal;")] //! - //! let channels: [atmega_hal::adc::Channel; 4] = [ - //! pins.pf0.into_analog_input(&mut adc).into_channel(), - //! pins.pf1.into_analog_input(&mut adc).into_channel(), - //! pins.pf2.into_analog_input(&mut adc).into_channel(), - //! pins.pf3.into_analog_input(&mut adc).into_channel(), - //! ]; + //! let dp = hal::Peripherals::take().unwrap(); + //! let pins = hal::pins!(dp); //! - //! for (index, channel) in channels.iter().enumerate() { - //! let value = adc.read_blocking(channel); - //! ufmt::uwrite!(&mut serial, "CH{}: {} ", index, value).unwrap(); - //! } + //! let mut adc = hal::Adc::::new(dp.ADC, Default::default()); + //! + //! // + $( + #![doc = paste!{ concat!( + "let ", stringify!([< channel_ $pin_name:lower >]), " = pins.", stringify!([< $pin_name:lower >]), ".into_analog_input(&mut adc).into_channel();\n", + "let ", stringify!([< value_ $pin_name:lower >]), " = adc.read_blocking(&", stringify!([< channel_ $pin_name:lower >]), ");\n\n" + ) }] + )* + $( + #![doc = paste!{ concat!( + "let ", stringify!([< value_ $channel_name:lower >]), " = adc.read_blocking(&hal::adc::channel::", stringify!([< $channel_name >]), ");\n\n" + ) }] + )* //! ``` use avr_hal_generic::paste::paste; @@ -53,14 +74,6 @@ macro_rules! impl_mod_adc { /// /// Some channels are not directly connected to pins. This module provides types which can be used /// to access them. - /// - /// # Example - /// ``` - /// let dp = atmega_hal::Peripherals::take().unwrap(); - /// let mut adc = atmega_hal::Adc::new(dp.ADC, Default::default()); - /// - /// let value = adc.read_blocking(&channel::Vbg); - /// ``` #[allow(non_camel_case_types)] pub mod channel { $( diff --git a/mcu/atmega-hal/src/impl/eeprom.rs b/mcu/atmega-hal/src/impl/eeprom.rs index 234af3eadc..4f8327874a 100644 --- a/mcu/atmega-hal/src/impl/eeprom.rs +++ b/mcu/atmega-hal/src/impl/eeprom.rs @@ -16,17 +16,18 @@ macro_rules! impl_mod_eeprom { //! Complete example source code can be found in the repository: //! [`atmega2560-eeprom.rs`](https://github.com/Rahix/avr-hal/blob/main/examples/atmega2560/src/bin/atmega2560-eeprom.rs) //! - //! ``` + //! ```no_run + #![doc = concat!("use atmega_hal::", stringify!($hal), " as hal;")] //! const BOOT_COUNT_OFFSET: u16 = 0; //! - //! let dp = atmega_hal::Peripherals::take().unwrap(); - //! let mut eeprom = Eeprom::new(dp.EEPROM); + //! let dp = hal::Peripherals::take().unwrap(); + //! let mut eeprom = hal::Eeprom::new(dp.EEPROM); //! //! let mut boot_count = eeprom.read_byte(BOOT_COUNT_OFFSET); //! boot_count = boot_count.wrapping_add(1); //! eeprom.write_byte(BOOT_COUNT_OFFSET, boot_count); //! - //! ufmt::uwriteln!(&mut serial, "Boot count: {}", boot_count).unwrap(); + //! // ufmt::uwriteln!(&mut serial, "Boot count: {}", boot_count).unwrap(); //! ``` pub use avr_hal_generic::eeprom::{EepromOps, OutOfBoundsError}; diff --git a/mcu/atmega-hal/src/impl/i2c.rs b/mcu/atmega-hal/src/impl/i2c.rs index 258e3d238f..e02146a031 100644 --- a/mcu/atmega-hal/src/impl/i2c.rs +++ b/mcu/atmega-hal/src/impl/i2c.rs @@ -17,21 +17,29 @@ macro_rules! impl_mod_i2c { //! Complete example source code can be found in the repository: //! [`atmega2560-i2cdetect.rs`](https://github.com/Rahix/avr-hal/blob/main/examples/atmega2560/src/bin/atmega2560-i2cdetect.rs) //! - //! ``` - //! let dp = atmega_hal::Peripherals::take().unwrap(); - //! let pins = atmega_hal::pins!(dp); + //! ```no_run + #![doc = concat!("use atmega_hal::", stringify!($hal), " as hal;")] + //! + //! let dp = hal::Peripherals::take().unwrap(); + //! let pins = hal::pins!(dp); //! - //! let mut i2c = I2c::new( - //! dp.TWI, - //! pins.pd1.into_pull_up_input(), - //! pins.pd0.into_pull_up_input(), - //! 50_000, - //! ); + //! type Clock = avr_hal_generic::clock::MHz16; + $( + #![doc = paste!{ concat!( + "let mut i2c = hal::i2c::", stringify!($interface), "::::new(\n", + " dp.", stringify!($peripheral), ",\n", + " pins.", stringify!([< $sda:lower >]), ".into_pull_up_input(),\n", + " pins.", stringify!([< $scl:lower >]), ".into_pull_up_input(),\n", + " 50_000,\n", + ");\n", + ) }] + )+ //! - //! i2c.i2cdetect(&mut serial, atmega_hal::i2c::Direction::Read).unwrap(); + //! // i2c.i2cdetect(&mut serial, hal::i2c::Direction::Read).unwrap(); //! ``` pub use avr_hal_generic::i2c::*; + use avr_hal_generic::paste::paste; use crate::$hal as hal; $( diff --git a/mcu/atmega-hal/src/impl/port.rs b/mcu/atmega-hal/src/impl/port.rs index a210bd7996..9d86524ac2 100644 --- a/mcu/atmega-hal/src/impl/port.rs +++ b/mcu/atmega-hal/src/impl/port.rs @@ -15,18 +15,24 @@ macro_rules! impl_mod_port { //! //! # Example //! - //! Complete example source code can be found in the repository: + //! For full source code, please refer to the ATmega port example: //! [`atmega2560-blink.rs`](https://github.com/Rahix/avr-hal/blob/main/examples/atmega2560/src/bin/atmega2560-blink.rs) //! - //! ``` - //! let dp = atmega_hal::Peripherals::take().unwrap(); - //! let pins = atmega_hal::pins!(dp); + //! ```no_run + //! use atmega_hal::prelude::*; + #![doc = concat!("use atmega_hal::", stringify!($hal), " as hal;")] + //! + //! type Clock = atmega_hal::clock::MHz8; + //! let mut delay = atmega_hal::delay::Delay::::new(); + //! + //! let dp = hal::Peripherals::take().unwrap(); + //! let pins = hal::pins!(dp); //! - //! let mut led = pins.pb7.into_output(); + //! let mut led = pins.pb2.into_output(); //! //! loop { //! led.toggle(); - //! delay_ms(1000); + //! delay.delay_ms(1000u16); //! } //! ``` use avr_hal_generic::paste::paste; diff --git a/mcu/atmega-hal/src/impl/simple_pwm.rs b/mcu/atmega-hal/src/impl/simple_pwm.rs index a00b84e492..d267da0715 100644 --- a/mcu/atmega-hal/src/impl/simple_pwm.rs +++ b/mcu/atmega-hal/src/impl/simple_pwm.rs @@ -58,17 +58,25 @@ macro_rules! timer0_8bit_impl { ) => { paste! { avr_hal_generic::impl_simple_pwm! { - /// Use `$peripheral` for PWM (pins `$pin`,) + #[doc = concat!("Use `", stringify!($peripheral), "` for PWM.")] /// /// # Example - /// ``` - /// let mut timer0 = Timer0Pwm::new(dp.$peripheral, Prescaler::Prescale64); + /// ```no_run + #[doc = concat!("use atmega_hal::", stringify!($hal), " as hal;")] + #[doc = concat!("use hal::simple_pwm::{IntoPwmPin,", stringify!($timer), ",Prescaler};")] /// - /// let mut d0 = pins.d0.into_output().into_pwm(&mut timer0); - /// let mut d1 = pins.d1.into_output().into_pwm(&mut timer0); + /// let dp = hal::Peripherals::take().unwrap(); + /// let pins = hal::pins!(dp); + #[doc = concat!("let mut timer = ", stringify!($timer), "::new(dp.", stringify!($peripheral), ", Prescaler::Prescale64);")] /// - /// d0.set_duty(128); - /// d0.enable(); + $( + #[doc = paste!{ concat!( + "let mut ", stringify!([< $pin:lower >]), " = pins.", stringify!([< $pin:lower >]), ".into_output().into_pwm(&mut timer);\n", + stringify!([< $pin:lower >]), ".set_duty(128);\n", + stringify!([< $pin:lower >]), ".enable();\n", + "\n", + ) }] + )+ /// ``` pub struct $timer { timer: crate::$hal::pac::$peripheral, @@ -120,17 +128,25 @@ macro_rules! timer1_8bit_separate_prescale { ) => { paste! { avr_hal_generic::impl_simple_pwm! { - /// Use `$peripheral` for PWM (pins `$pin`,) + #[doc = concat!("Use `", stringify!($peripheral), "` for PWM.")] /// /// # Example - /// ``` - /// let mut timer1 = Timer1Pwm::new(dp.TC1, Prescaler::Prescale64); + /// ```no_run + #[doc = concat!("use atmega_hal::", stringify!($hal), " as hal;")] + #[doc = concat!("use hal::simple_pwm::{IntoPwmPin,", stringify!($timer), ",Prescaler};")] /// - /// let mut d4 = pins.d4.into_output().into_pwm(&mut timer1); + /// let dp = hal::Peripherals::take().unwrap(); + /// let pins = hal::pins!(dp); + #[doc = concat!("let mut timer1 = ", stringify!($timer), "::new(dp.", stringify!($peripheral), ", Prescaler::Prescale64);")] /// - /// d4.set_duty(128); - /// d4.enable(); - /// ``` + $( + #[doc = paste!{ concat!( + "let mut ", stringify!([< $pin:lower >]), " = pins.", stringify!([< $pin:lower >]), ".into_output().into_pwm(&mut timer1);\n", + stringify!([< $pin:lower >]), ".set_duty(128);\n", + stringify!([< $pin:lower >]), ".enable();\n", + "\n", + ) }] + )+ pub struct $timer { timer: crate::$hal::pac::$peripheral, init: |tim, prescaler| { @@ -185,17 +201,25 @@ macro_rules! timer_10bit_impl { ) => { paste! { avr_hal_generic::impl_simple_pwm! { - /// Use `$peripheral` for PWM (pins `$pin`,) + #[doc = concat!("Use `", stringify!($peripheral), "` for PWM.")] /// /// # Example - /// ``` - /// let mut timer0 = Timer0Pwm::new(dp.$peripheral, Prescaler::Prescale64); + /// ```no_run + #[doc = concat!("use atmega_hal::", stringify!($hal), " as hal;")] + #[doc = concat!("use hal::simple_pwm::{IntoPwmPin,", stringify!($timer), ",Prescaler};")] /// - /// let mut d0 = pins.d0.into_output().into_pwm(&mut timer0); - /// let mut d1 = pins.d1.into_output().into_pwm(&mut timer0); + /// let dp = hal::Peripherals::take().unwrap(); + /// let pins = hal::pins!(dp); + #[doc = concat!("let mut timer = ", stringify!($timer), "::new(dp.", stringify!($peripheral), ", Prescaler::Prescale64);")] /// - /// d0.set_duty(128); - /// d0.enable(); + $( + #[doc = paste!{ concat!( + "let mut ", stringify!([< $pin:lower >]), " = pins.", stringify!([< $pin:lower >]), ".into_output().into_pwm(&mut timer);\n", + stringify!([< $pin:lower >]), ".set_duty(128);\n", + stringify!([< $pin:lower >]), ".enable();\n", + "\n", + ) }] + )+ /// ``` pub struct $timer { timer: crate::$hal::pac::$peripheral, @@ -252,16 +276,25 @@ macro_rules! timer_16bit_impl { ) => { paste! { avr_hal_generic::impl_simple_pwm! { - /// Use `$peripheral` for PWM (pins `$pin`,) + #[doc = concat!("Use `", stringify!($peripheral), "` for PWM.")] /// /// # Example - /// ``` - /// let mut timer1 = Timer1Pwm::new(dp.TC1, Prescaler::Prescale64); + /// ```no_run + #[doc = concat!("use atmega_hal::", stringify!($hal), " as hal;")] + #[doc = concat!("use hal::simple_pwm::{IntoPwmPin,", stringify!($timer), ",Prescaler};")] /// - /// let mut d4 = pins.d4.into_output().into_pwm(&mut timer1); + /// let dp = hal::Peripherals::take().unwrap(); + /// let pins = hal::pins!(dp); + #[doc = concat!("let mut timer = ", stringify!($timer), "::new(dp.", stringify!($peripheral), ", Prescaler::Prescale64);")] /// - /// d4.set_duty(128); - /// d4.enable(); + $( + #[doc = paste!{ concat!( + "let mut ", stringify!([< $pin:lower >]), " = pins.", stringify!([< $pin:lower >]), ".into_output().into_pwm(&mut timer);\n", + stringify!([< $pin:lower >]), ".set_duty(128);\n", + stringify!([< $pin:lower >]), ".enable();\n", + "\n", + ) }] + )+ /// ``` pub struct $timer { timer: crate::$hal::pac::$peripheral, @@ -315,16 +348,25 @@ macro_rules! timer_8bit_1wf_with_async { ) => { paste! { avr_hal_generic::impl_simple_pwm! { - /// Use `$peripheral` for PWM (pins `$pin`,) + #[doc = concat!("Use `", stringify!($peripheral), "` for PWM.")] /// /// # Example - /// ``` - /// let mut timer2 = Timer2Pwm::new(dp.TC2, Prescaler::Prescale64); + /// ```no_run + #[doc = concat!("use atmega_hal::", stringify!($hal), " as hal;")] + #[doc = concat!("use hal::simple_pwm::{IntoPwmPin,", stringify!($timer), ",Prescaler};")] /// - /// let mut d4 = pins.d4.into_output().into_pwm(&mut timer1); + /// let dp = hal::Peripherals::take().unwrap(); + /// let pins = hal::pins!(dp); + #[doc = concat!("let mut timer = ", stringify!($timer), "::new(dp.", stringify!($peripheral), ", Prescaler::Prescale64);")] /// - /// d4.set_duty(128); - /// d4.enable(); + $( + #[doc = paste!{ concat!( + "let mut ", stringify!([< $pin:lower >]), " = pins.", stringify!([< $pin:lower >]), ".into_output().into_pwm(&mut timer);\n", + stringify!([< $pin:lower >]), ".set_duty(128);\n", + stringify!([< $pin:lower >]), ".enable();\n", + "\n", + ) }] + )+ /// ``` pub struct $timer { timer: crate::$hal::pac::$peripheral, @@ -376,16 +418,25 @@ macro_rules! timer_8bit_2wf_with_async { ) => { paste! { avr_hal_generic::impl_simple_pwm! { - /// Use `$peripheral` for PWM (pins `$pin`,) + #[doc = concat!("Use `", stringify!($peripheral), "` for PWM.")] /// /// # Example - /// ``` - /// let mut timer2 = Timer2Pwm::new(dp.TC2, Prescaler::Prescale64); + /// ```no_run + #[doc = concat!("use atmega_hal::", stringify!($hal), " as hal;")] + #[doc = concat!("use hal::simple_pwm::{IntoPwmPin,", stringify!($timer), ",Prescaler};")] /// - /// let mut d4 = pins.d4.into_output().into_pwm(&mut timer1); + /// let dp = hal::Peripherals::take().unwrap(); + /// let pins = hal::pins!(dp); + #[doc = concat!("let mut timer = ", stringify!($timer), "::new(dp.", stringify!($peripheral), ", Prescaler::Prescale64);")] /// - /// d4.set_duty(128); - /// d4.enable(); + $( + #[doc = paste!{ concat!( + "let mut ", stringify!([< $pin:lower >]), " = pins.", stringify!([< $pin:lower >]), ".into_output().into_pwm(&mut timer);\n", + stringify!([< $pin:lower >]), ".set_duty(128);\n", + stringify!([< $pin:lower >]), ".enable();\n", + "\n", + ) }] + )+ /// ``` pub struct $timer { timer: crate::$hal::pac::$peripheral, diff --git a/mcu/atmega-hal/src/impl/spi.rs b/mcu/atmega-hal/src/impl/spi.rs index 42e3d4718d..b3ddc8712e 100644 --- a/mcu/atmega-hal/src/impl/spi.rs +++ b/mcu/atmega-hal/src/impl/spi.rs @@ -21,18 +21,27 @@ macro_rules! impl_mod_spi { //! Complete example source code can be found in the repository //! [`atmega2560-spi-feedback.rs`](https://github.com/Rahix/avr-hal/blob/main/examples/atmega2560/src/bin/atmega2560-spi-feedback.rs) //! - //! ``` - //! let dp = atmega_hal::Peripherals::take().unwrap(); - //! let pins = atmega_hal::pins!(dp); + //! ```no_run + #![doc = concat!("use atmega_hal::", stringify!($hal), " as hal;")] + //! + //! use embedded_hal::digital::OutputPin; + //! use embedded_hal::spi::SpiBus; + //! + //! let dp = hal::Peripherals::take().unwrap(); + //! let pins = hal::pins!(dp); //! - //! let (mut spi, mut cs) = spi::Spi::new( - //! dp.SPI, - //! pins.pb1.into_output(), - //! pins.pb2.into_output(), - //! pins.pb3.into_pull_up_input(), - //! pins.pb0.into_output(), - //! spi::Settings::default(), - //! ); + $( + #![doc = paste!{ concat!( + "let (mut spi, mut cs) = hal::spi::", stringify!($interface), "::new(\n", + " dp.", stringify!($peripheral), ",\n", + " pins.", stringify!([< $sclk:lower >]), ".into_output(),\n", + " pins.", stringify!([< $mosi:lower >]), ".into_output(),\n", + " pins.", stringify!([< $miso:lower >]), ".into_pull_up_input(),\n", + " pins.", stringify!([< $cs:lower >]), ".into_output(),\n", + " hal::spi::Settings::default(),\n", + ");\n", + ) }] + )+ //! //! let data_out = b"Hello World!"; //! let mut data_in = [0u8; 12]; @@ -41,10 +50,11 @@ macro_rules! impl_mod_spi { //! spi.transfer(&mut data_in, data_out).unwrap(); //! cs.set_high().unwrap(); //! - //! ufmt::uwriteln!(&mut serial, "data: {:?}", data_in).unwrap(); + //! // ufmt::uwriteln!(&mut serial, "data: {:?}", data_in).unwrap(); //! ``` pub use avr_hal_generic::spi::*; + use avr_hal_generic::paste::paste; use crate::$hal as hal; $( diff --git a/mcu/atmega-hal/src/impl/usart.rs b/mcu/atmega-hal/src/impl/usart.rs index 03adf7be51..c18801c394 100644 --- a/mcu/atmega-hal/src/impl/usart.rs +++ b/mcu/atmega-hal/src/impl/usart.rs @@ -25,16 +25,25 @@ macro_rules! impl_mod_usart { //! *Note: [ufmt](https://crates.io/crates/ufmt/) is used instead of `core::fmt` because //! `core::fmt` code quickly grows too large for AVR platforms.* //! - //! ``` - //! let dp = atmega_hal::Peripherals::take().unwrap(); - //! let pins = atmega_hal::pins!(dp); + //! ```no_run + //! use atmega_hal::prelude::*; + #![doc = concat!("use atmega_hal::", stringify!($hal), " as hal;")] + //! + //! let dp = hal::Peripherals::take().unwrap(); + //! let pins = hal::pins!(dp); + //! //! - //! let mut serial = Usart::new( - //! dp.USART0, - //! pins.pe0, - //! pins.pe1.into_output(), - //! Baudrate::::new(57600), - //! ); + //! type Clock = avr_hal_generic::clock::MHz16; + $( + #![doc = paste!{ concat!( + "let mut serial = hal::usart::", stringify!($interface), "::new(\n", + " dp.", stringify!($peripheral), ",\n", + " pins.", stringify!([< $rx:lower >]), ",\n", + " pins.", stringify!([< $tx:lower >]), ".into_output(),\n", + " hal::usart::Baudrate::::new(57600),\n", + ");\n", + ) }] + )+ //! //! ufmt::uwriteln!(&mut serial, "Hello from ATmega!").unwrap(); //!