Skip to content

Commit b92ff0a

Browse files
committed
Update some doctests
1 parent 87ce212 commit b92ff0a

File tree

34 files changed

+429
-293
lines changed

34 files changed

+429
-293
lines changed

documentation/API-GUIDELINES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Modules should have the following documentation format:
7777
//! ```
7878
//!
7979
//! ## Implementation State
80-
//! List unsuported features
80+
//! List unsupported features
8181
```
8282
- If any of the headers is empty, remove it
8383
- When possible, use ESP-IDF docs and TRM as references and include links if possible.

esp-hal/doc-helper/before

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# #![no_std]
2-
# use esp_hal::peripherals::Peripherals;
3-
# use esp_hal::clock::ClockControl;
4-
# use esp_hal::system::SystemControl;
2+
# use esp_hal::prelude::*;
3+
# use procmacros::handler;
4+
# use esp_hal::interrupt;
55
# #[panic_handler]
66
# fn panic(_ : &core::panic::PanicInfo) -> ! {
77
# loop {}
88
# }
9+
# #[allow(unused_variables)]
910
# fn main() {
10-
# let peripherals = Peripherals::take();
11-
# let system = SystemControl::new(peripherals.SYSTEM);
12-
# let mut clocks = ClockControl::boot_defaults(system.clock_control).freeze();

esp-hal/src/delay.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
//! # Delay
22
//!
33
//! ## Overview
4+
//!
45
//! The Delay driver provides blocking delay functionalities using the
5-
//! `SYSTIMER` peripheral for RISC-V devices and the built-in Xtensa timer for
6-
//! Xtensa devices.
6+
//! [current_time] function.
77
//!
88
//! ## Configuration
9+
//!
910
//! The delays are implemented in a "best-effort" way, meaning that the CPU will
1011
//! block for at least the amount of time specified, but accuracy can be
1112
//! affected by many factors, including interrupt usage.
1213
//!
1314
//! ## Usage
15+
//!
1416
//! This module implements the blocking [DelayMs] and [DelayUs] traits from
1517
//! [embedded-hal], both 0.2.x and 1.x.x.
1618
//!
@@ -20,7 +22,9 @@
2022
#![doc = crate::before_snippet!()]
2123
//! # use esp_hal::delay::Delay;
2224
//! # use embedded_hal::delay::DelayNs;
23-
//! let mut delay = Delay::new(&clocks);
25+
//! let system = esp_hal::init(CpuClock::boot_default());
26+
//!
27+
//! let mut delay = Delay::new(&system.clocks);
2428
//!
2529
//! delay.delay_ms(1000 as u32);
2630
//! # }

esp-hal/src/dma/mod.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! # Direct Memory Access (DMA)
22
//!
33
//! ## Overview
4+
//!
45
//! The DMA driver provides an interface to efficiently transfer data between
56
//! different memory regions and peripherals within the ESP microcontroller
67
//! without involving the CPU. The DMA controller is responsible for managing
@@ -10,25 +11,32 @@
1011
//! `ESP32-S2` are using older `PDMA` controller, whenever other chips are using
1112
//! newer `GDMA` controller.
1213
//!
13-
//! ## Examples
14-
//! ### Initialize and Utilize DMA Controller in `SPI`
14+
//! ## Example
15+
//!
16+
//! ### Initialize and utilize DMA controller in `SPI`
17+
//!
1518
//! ```rust, no_run
1619
#![doc = crate::before_snippet!()]
1720
//! # use esp_hal::dma_buffers;
1821
//! # use esp_hal::gpio::Io;
1922
//! # use esp_hal::spi::{master::{Spi, prelude::*}, SpiMode};
2023
//! # use esp_hal::dma::{Dma, DmaPriority};
21-
//! # use crate::esp_hal::prelude::_fugit_RateExtU32;
22-
//! let dma = Dma::new(peripherals.DMA);
24+
//! let system = esp_hal::init(CpuClock::boot_default());
25+
//! let dma = Dma::new(system.peripherals.DMA);
2326
#![cfg_attr(any(esp32, esp32s2), doc = "let dma_channel = dma.spi2channel;")]
2427
#![cfg_attr(not(any(esp32, esp32s2)), doc = "let dma_channel = dma.channel0;")]
25-
//! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
28+
//! let io = Io::new(system.peripherals.GPIO, system.peripherals.IO_MUX);
2629
//! let sclk = io.pins.gpio0;
2730
//! let miso = io.pins.gpio2;
2831
//! let mosi = io.pins.gpio4;
2932
//! let cs = io.pins.gpio5;
3033
//!
31-
//! let mut spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0, &clocks)
34+
//! let mut spi = Spi::new(
35+
//! system.peripherals.SPI2,
36+
//! 100.kHz(),
37+
//! SpiMode::Mode0,
38+
//! &system.clocks
39+
//! )
3240
//! .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs))
3341
//! .with_dma(dma_channel.configure(
3442
//! false,
@@ -40,10 +48,10 @@
4048
//! ⚠️ Note: Descriptors should be sized as `(max_transfer_size + CHUNK_SIZE - 1) / CHUNK_SIZE`.
4149
//! I.e., to transfer buffers of size `1..=CHUNK_SIZE`, you need 1 descriptor.
4250
//!
43-
//! ⚠️ Note: For chips that support DMA to/from PSRAM (esp32s3) DMA transfers to/from PSRAM
51+
//! ⚠️ Note: For chips that support DMA to/from PSRAM (ESP32-S3) DMA transfers to/from PSRAM
4452
//! have extra alignment requirements. The address and size of the buffer pointed to by
4553
//! each descriptor must be a multiple of the cache line (block) size. This is 32 bytes
46-
//! on esp32s3.
54+
//! on ESP32-S3.
4755
//!
4856
//! For convenience you can use the [crate::dma_buffers] macro.
4957

esp-hal/src/i2s.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
//! # Inter-IC Sound (I2S)
22
//!
33
//! ## Overview
4+
//!
45
//! I2S (Inter-IC Sound) is a synchronous serial communication protocol usually
56
//! used for transmitting audio data between two digital audio devices.
67
//! Espressif devices may contain more than one I2S peripheral(s). These
78
//! peripherals can be configured to input and output sample data via the I2S
89
//! driver.
910
//!
10-
//!
1111
//! ## Configuration
12+
//!
1213
//! I2S supports different data formats, including varying data and channel
1314
//! widths, different standards, such as the Philips standard and configurable
1415
//! pin mappings for I2S clock (BCLK), word select (WS), and data input/output
@@ -18,33 +19,33 @@
1819
//! supports various configurations, such as different data formats, standards
1920
//! (e.g., Philips) and pin configurations. It relies on other peripheral
2021
//! modules, such as
21-
//! - `GPIO`
22-
//! - `DMA`
23-
//! - `system` (to configure and enable the I2S peripheral)
22+
//! - `GPIO`
23+
//! - `DMA`
24+
//! - `system` (to configure and enable the I2S peripheral)
25+
//!
26+
//! ## Example
2427
//!
25-
//! ## Examples
2628
//! ### Initialization
29+
//!
2730
//! ```rust, no_run
2831
#![doc = crate::before_snippet!()]
2932
//! # use esp_hal::i2s::I2s;
3033
//! # use esp_hal::i2s::Standard;
3134
//! # use esp_hal::i2s::DataFormat;
35+
//! # use esp_hal::i2s::I2sReadDma;
3236
//! # use esp_hal::gpio::Io;
3337
//! # use esp_hal::dma_buffers;
3438
//! # use esp_hal::dma::{Dma, DmaPriority};
35-
//! # use crate::esp_hal::prelude::_fugit_RateExtU32;
36-
//! # use crate::esp_hal::peripherals::Peripherals;
37-
//! # use crate::esp_hal::i2s::I2sReadDma;
38-
//! # use core::ptr::addr_of_mut;
39-
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
40-
//! let dma = Dma::new(peripherals.DMA);
39+
//! let system = esp_hal::init(CpuClock::boot_default());
40+
//! # let io = Io::new(system.peripherals.GPIO, system.peripherals.IO_MUX);
41+
//! let dma = Dma::new(system.peripherals.DMA);
4142
#![cfg_attr(any(esp32, esp32s2), doc = "let dma_channel = dma.i2s0channel;")]
4243
#![cfg_attr(not(any(esp32, esp32s2)), doc = "let dma_channel = dma.channel0;")]
4344
//! let (_, tx_descriptors, mut rx_buffer, rx_descriptors) =
4445
//! dma_buffers!(0, 4 * 4092);
4546
//!
4647
//! let i2s = I2s::new(
47-
//! peripherals.I2S0,
48+
//! system.peripherals.I2S0,
4849
//! Standard::Philips,
4950
//! DataFormat::Data16Channel16,
5051
//! 44100.Hz(),
@@ -54,7 +55,7 @@
5455
//! ),
5556
//! tx_descriptors,
5657
//! rx_descriptors,
57-
//! &clocks,
58+
//! &system.clocks,
5859
//! );
5960
#![cfg_attr(not(esp32), doc = "let i2s = i2s.with_mclk(io.pins.gpio0);")]
6061
//! let mut i2s_rx = i2s.i2s_rx

esp-hal/src/interrupt/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@
2424
//! We reserve a number of CPU interrupts, which cannot be used; see
2525
//! [`RESERVED_INTERRUPTS`].
2626
//!
27-
//! ## Examples
28-
//! ### Using the Peripheral Driver to Register an Interrupt Handler
27+
//! ## Example
28+
//!
29+
//! ### Using the peripheral driver to register an interrupt handler
30+
//!
2931
//! ```rust, no_run
3032
#![doc = crate::before_snippet!()]
3133
//! # use core::cell::RefCell;
32-
//!
34+
//! #
3335
//! # use critical_section::Mutex;
3436
//! # use esp_hal::{
3537
//! # prelude::*,
3638
//! # system::{SoftwareInterrupt, SystemControl},
3739
//! # };
3840
//! # use esp_hal::interrupt::Priority;
3941
//! # use esp_hal::interrupt::InterruptHandler;
40-
//!
41-
//! static SWINT0: Mutex<RefCell<Option<SoftwareInterrupt<0>>>> =
42-
//! Mutex::new(RefCell::new(None));
43-
//!
42+
//! #
43+
//! let system = esp_hal::init(CpuClock::boot_default());
4444
//! let mut sw_int = system.software_interrupt_control;
4545
//! critical_section::with(|cs| {
4646
//! sw_int
@@ -56,15 +56,15 @@
5656
//! });
5757
//!
5858
//! loop {}
59-
//! }
59+
//! # }
6060
//!
61-
//! # use procmacros::handler;
62-
//! # use esp_hal::interrupt;
6361
//! # use critical_section::Mutex;
6462
//! # use core::cell::RefCell;
6563
//! # use esp_hal::system::SoftwareInterrupt;
66-
//! # static SWINT0: Mutex<RefCell<Option<SoftwareInterrupt<0>>>> = Mutex::new(RefCell::new(None));
67-
//! #[handler(priority = esp_hal::interrupt::Priority::Priority1)]
64+
//! static SWINT0: Mutex<RefCell<Option<SoftwareInterrupt<0>>>> =
65+
//! Mutex::new(RefCell::new(None));
66+
//!
67+
//! #[handler(priority = Priority::Priority1)]
6868
//! fn swint0_handler() {
6969
//! // esp_println::println!("SW interrupt0");
7070
//! critical_section::with(|cs| {

esp-hal/src/lcd_cam/cam.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
//! # use fugit::RateExtU32;
2222
//! # use esp_hal::dma_buffers;
2323
//! # use esp_hal::dma::{Dma, DmaPriority};
24-
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
24+
//! let system = esp_hal::init(CpuClock::boot_default());
25+
//! # let io = Io::new(system.peripherals.GPIO, system.peripherals.IO_MUX);
2526
//!
26-
//! # let dma = Dma::new(peripherals.DMA);
27+
//! # let dma = Dma::new(system.peripherals.DMA);
2728
//! # let channel = dma.channel0;
2829
//!
2930
//! # let (tx_buffer, tx_descriptors, _, rx_descriptors) = dma_buffers!(32678, 0);
@@ -48,14 +49,14 @@
4849
//! io.pins.gpio16,
4950
//! );
5051
//!
51-
//! let lcd_cam = LcdCam::new(peripherals.LCD_CAM);
52+
//! let lcd_cam = LcdCam::new(system.peripherals.LCD_CAM);
5253
//! let mut camera = Camera::new(
5354
//! lcd_cam.cam,
5455
//! channel.rx,
5556
//! rx_descriptors,
5657
//! data_pins,
5758
//! 20u32.MHz(),
58-
//! &clocks
59+
//! &system.clocks
5960
//! )
6061
//! // Remove this for slave mode.
6162
//! .with_master_clock(mclk_pin)

esp-hal/src/lcd_cam/lcd/i8080.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
//! # LCD - I8080/MOTO6800 Mode.
22
//!
33
//! ## Overview
4+
//!
45
//! The LCD_CAM peripheral I8080 driver provides support for the I8080
5-
//! format/timing. The driver mandates DMA for DMA (Direct Memory Access) for
6+
//! format/timing. The driver mandates DMA (Direct Memory Access) for
67
//! efficient data transfer.
78
//!
8-
//! ## Examples
9+
//! ## Example
10+
//!
911
//! ### MIPI-DSI Display
10-
//! Following code show how to send a command to a MIPI-DSI display over I8080
12+
//!
13+
//! The following example shows how to send a command to a MIPI-DSI display over the I8080
1114
//! protocol.
1215
//!
1316
//! ```rust, no_run
@@ -16,11 +19,11 @@
1619
//! # use esp_hal::lcd_cam::{LcdCam, lcd::i8080::{Config, I8080, TxEightBits}};
1720
//! # use esp_hal::dma_buffers;
1821
//! # use esp_hal::dma::{Dma, DmaPriority};
19-
//! # use fugit::RateExtU32;
2022
//!
21-
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
23+
//! let system = esp_hal::init(CpuClock::boot_default());
24+
//! # let io = Io::new(system.peripherals.GPIO, system.peripherals.IO_MUX);
2225
//!
23-
//! # let dma = Dma::new(peripherals.DMA);
26+
//! # let dma = Dma::new(system.peripherals.DMA);
2427
//! # let channel = dma.channel0;
2528
//!
2629
//! # let (tx_buffer, tx_descriptors, _, rx_descriptors) = dma_buffers!(32678, 0);
@@ -40,7 +43,7 @@
4043
//! io.pins.gpio16,
4144
//! io.pins.gpio15,
4245
//! );
43-
//! let lcd_cam = LcdCam::new(peripherals.LCD_CAM);
46+
//! let lcd_cam = LcdCam::new(system.peripherals.LCD_CAM);
4447
//!
4548
//! let mut i8080 = I8080::new(
4649
//! lcd_cam.lcd,
@@ -49,7 +52,7 @@
4952
//! tx_pins,
5053
//! 20.MHz(),
5154
//! Config::default(),
52-
//! &clocks,
55+
//! &system.clocks,
5356
//! )
5457
//! .with_ctrl_pins(io.pins.gpio0, io.pins.gpio47);
5558
//!

esp-hal/src/ledc/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! # LED Controller (LEDC)
22
//!
33
//! ## Overview
4+
//!
45
//! The LEDC peripheral is primarily designed to control the intensity of LEDs,
56
//! although it can also be used to generate PWM signals for other purposes. It
67
//! has multiple channels which can generate independent waveforms that can be
@@ -15,9 +16,12 @@
1516
//! supported chips.
1617
//!
1718
//! ## Examples
19+
//!
1820
//! ### Low Speed Channel
19-
//! The following will configure the Low Speed Channel0 to 24kHz output with
20-
//! 10% duty using the ABPClock
21+
//!
22+
//! The following example will configure the Low Speed Channel0 to 24kHz output
23+
//! with 10% duty using the ABPClock.
24+
//!
2125
//! ```rust, no_run
2226
#![doc = crate::before_snippet!()]
2327
//! # use esp_hal::ledc::Ledc;
@@ -26,14 +30,12 @@
2630
//! # use esp_hal::ledc::LowSpeed;
2731
//! # use esp_hal::ledc::channel;
2832
//! # use esp_hal::gpio::Io;
29-
//! # use crate::esp_hal::prelude::_esp_hal_ledc_timer_TimerIFace;
30-
//! # use crate::esp_hal::prelude::_fugit_RateExtU32;
31-
//! # use crate::esp_hal::prelude::_esp_hal_ledc_channel_ChannelIFace;
3233
//!
33-
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
34+
//! let system = esp_hal::init(CpuClock::boot_default());
35+
//! # let io = Io::new(system.peripherals.GPIO, system.peripherals.IO_MUX);
3436
//! # let led = io.pins.gpio0;
3537
//!
36-
//! let mut ledc = Ledc::new(peripherals.LEDC, &clocks);
38+
//! let mut ledc = Ledc::new(system.peripherals.LEDC, &system.clocks);
3739
//! ledc.set_global_slow_clock(LSGlobalClkSource::APBClk);
3840
//!
3941
//! let mut lstimer0 = ledc.get_timer::<LowSpeed>(timer::Number::Timer0);

0 commit comments

Comments
 (0)