Skip to content

Commit

Permalink
Return a tuple instead of a named struct
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Aug 23, 2024
1 parent 4540938 commit 5f282f4
Show file tree
Hide file tree
Showing 171 changed files with 355 additions and 877 deletions.
2 changes: 1 addition & 1 deletion esp-hal/doc-helper/before
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
# fn panic(_ : &core::panic::PanicInfo) -> ! {
# loop {}
# }
# #[allow(unused_variables)]
# fn main() {
# let (peripherals, clocks) = esp_hal::init(CpuClock::boot_default());
4 changes: 1 addition & 3 deletions esp-hal/src/aes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@
//! # let mut keybuf = [0_u8; 16];
//! # keybuf[..keytext.len()].copy_from_slice(keytext);
//! #
//! let system = esp_hal::init(CpuClock::boot_default());
//!
//! let mut block = [0_u8; 16];
//! block[..plaintext.len()].copy_from_slice(plaintext);
//!
//! let mut aes = Aes::new(system.peripherals.AES);
//! let mut aes = Aes::new(peripherals.AES);
//! aes.process(&mut block, Mode::Encryption128, keybuf);
//!
//! // The encryption happens in-place, so the ciphertext is in `block`
Expand Down
7 changes: 3 additions & 4 deletions esp-hal/src/analog/adc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
//! # use esp_hal::analog::adc::Adc;
//! # use esp_hal::delay::Delay;
//! # use esp_hal::gpio::Io;
//! let system = esp_hal::init(CpuClock::boot_default());
//! # let io = Io::new(system.peripherals.GPIO, system.peripherals.IO_MUX);
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
#![cfg_attr(esp32, doc = "let analog_pin = io.pins.gpio32;")]
#![cfg_attr(any(esp32s2, esp32s3), doc = "let analog_pin = io.pins.gpio3;")]
#![cfg_attr(
Expand All @@ -45,9 +44,9 @@
//! analog_pin,
//! Attenuation::Attenuation11dB,
//! );
//! let mut adc1 = Adc::new(system.peripherals.ADC1, adc1_config);
//! let mut adc1 = Adc::new(peripherals.ADC1, adc1_config);
//!
//! let mut delay = Delay::new(&system.clocks);
//! let mut delay = Delay::new(&clocks);
//!
//! loop {
//! let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut pin)).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/clock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#![cfg_attr(esp32h2, doc = "// let system = esp_hal::init(CpuClock::Clock96MHz);")]
//! //
//! // Initialize with default clock frequency for this chip
//! // let system = esp_hal::init(CpuClock::boot_default());
//! // let (peripherals, clocks) = esp_hal::init(CpuClock::boot_default());
//! # }
//! ```

Expand Down
4 changes: 1 addition & 3 deletions esp-hal/src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
#![doc = crate::before_snippet!()]
//! # use esp_hal::delay::Delay;
//! # use embedded_hal::delay::DelayNs;
//! let system = esp_hal::init(CpuClock::boot_default());
//!
//! let mut delay = Delay::new(&system.clocks);
//! let mut delay = Delay::new(&clocks);
//!
//! delay.delay_ms(1000 as u32);
//! # }
Expand Down
9 changes: 4 additions & 5 deletions esp-hal/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,20 @@
//! # use esp_hal::gpio::Io;
//! # use esp_hal::spi::{master::{Spi, prelude::*}, SpiMode};
//! # use esp_hal::dma::{Dma, DmaPriority};
//! let system = esp_hal::init(CpuClock::boot_default());
//! let dma = Dma::new(system.peripherals.DMA);
//! let dma = Dma::new(peripherals.DMA);
#![cfg_attr(any(esp32, esp32s2), doc = "let dma_channel = dma.spi2channel;")]
#![cfg_attr(not(any(esp32, esp32s2)), doc = "let dma_channel = dma.channel0;")]
//! let io = Io::new(system.peripherals.GPIO, system.peripherals.IO_MUX);
//! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! let sclk = io.pins.gpio0;
//! let miso = io.pins.gpio2;
//! let mosi = io.pins.gpio4;
//! let cs = io.pins.gpio5;
//!
//! let mut spi = Spi::new(
//! system.peripherals.SPI2,
//! peripherals.SPI2,
//! 100.kHz(),
//! SpiMode::Mode0,
//! &system.clocks
//! &clocks
//! )
//! .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs))
//! .with_dma(dma_channel.configure(
Expand Down
3 changes: 1 addition & 2 deletions esp-hal/src/gpio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! # use esp_hal::gpio::{Io, Level, Output};
//! let system = esp_hal::init(CpuClock::boot_default());
//! let io = Io::new(system.peripherals.GPIO, system.peripherals.IO_MUX);
//! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! let mut led = Output::new(io.pins.gpio5, Level::High);
//! # }
//! ```
Expand Down
3 changes: 1 addition & 2 deletions esp-hal/src/gpio/rtc_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
#![doc = crate::before_snippet!()]
//! # use esp_hal::gpio::rtc_io::LowPowerOutput;
//! # use esp_hal::gpio::Io;
//! let system = esp_hal::init(CpuClock::boot_default());
//! let io = Io::new(system.peripherals.GPIO, system.peripherals.IO_MUX);
//! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! // configure GPIO 1 as ULP output pin
//! let lp_pin = LowPowerOutput::<'static, 1>::new(io.pins.gpio1);
//! # }
Expand Down
7 changes: 3 additions & 4 deletions esp-hal/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@
#![doc = crate::before_snippet!()]
//! # use esp_hal::i2c::I2C;
//! # use esp_hal::gpio::Io;
//! let system = esp_hal::init(CpuClock::boot_default());
//! let io = Io::new(system.peripherals.GPIO, system.peripherals.IO_MUX);
//! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//!
//! // Create a new peripheral object with the described wiring
//! // and standard I2C clock speed.
//! let mut i2c = I2C::new(
//! system.peripherals.I2C0,
//! peripherals.I2C0,
//! io.pins.gpio1,
//! io.pins.gpio2,
//! 100.kHz(),
//! &system.clocks,
//! &clocks,
//! );
//!
//! loop {
Expand Down
9 changes: 4 additions & 5 deletions esp-hal/src/i2s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,15 @@
//! # use esp_hal::gpio::Io;
//! # use esp_hal::dma_buffers;
//! # use esp_hal::dma::{Dma, DmaPriority};
//! let system = esp_hal::init(CpuClock::boot_default());
//! # let io = Io::new(system.peripherals.GPIO, system.peripherals.IO_MUX);
//! let dma = Dma::new(system.peripherals.DMA);
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! let dma = Dma::new(peripherals.DMA);
#![cfg_attr(any(esp32, esp32s2), doc = "let dma_channel = dma.i2s0channel;")]
#![cfg_attr(not(any(esp32, esp32s2)), doc = "let dma_channel = dma.channel0;")]
//! let (_, tx_descriptors, mut rx_buffer, rx_descriptors) =
//! dma_buffers!(0, 4 * 4092);
//!
//! let i2s = I2s::new(
//! system.peripherals.I2S0,
//! peripherals.I2S0,
//! Standard::Philips,
//! DataFormat::Data16Channel16,
//! 44100.Hz(),
Expand All @@ -55,7 +54,7 @@
//! ),
//! tx_descriptors,
//! rx_descriptors,
//! &system.clocks,
//! &clocks,
//! );
#![cfg_attr(not(esp32), doc = "let i2s = i2s.with_mclk(io.pins.gpio0);")]
//! let mut i2s_rx = i2s.i2s_rx
Expand Down
4 changes: 1 addition & 3 deletions esp-hal/src/interrupt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@
//!
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! let system = esp_hal::init(CpuClock::boot_default());
//!
//! let mut sw_int =
//! SoftwareInterruptControl::new(system.peripherals.SW_INTERRUPT);
//! SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
//! critical_section::with(|cs| {
//! sw_int
//! .software_interrupt0
Expand Down
9 changes: 4 additions & 5 deletions esp-hal/src/lcd_cam/cam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
//! # use fugit::RateExtU32;
//! # use esp_hal::dma_buffers;
//! # use esp_hal::dma::{Dma, DmaPriority};
//! let system = esp_hal::init(CpuClock::boot_default());
//! # let io = Io::new(system.peripherals.GPIO, system.peripherals.IO_MUX);
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//!
//! # let dma = Dma::new(system.peripherals.DMA);
//! # let dma = Dma::new(peripherals.DMA);
//! # let channel = dma.channel0;
//!
//! # let (tx_buffer, tx_descriptors, _, rx_descriptors) = dma_buffers!(32678, 0);
Expand All @@ -49,14 +48,14 @@
//! io.pins.gpio16,
//! );
//!
//! let lcd_cam = LcdCam::new(system.peripherals.LCD_CAM);
//! let lcd_cam = LcdCam::new(peripherals.LCD_CAM);
//! let mut camera = Camera::new(
//! lcd_cam.cam,
//! channel.rx,
//! rx_descriptors,
//! data_pins,
//! 20u32.MHz(),
//! &system.clocks
//! &clocks
//! )
//! // Remove this for slave mode.
//! .with_master_clock(mclk_pin)
Expand Down
10 changes: 4 additions & 6 deletions esp-hal/src/lcd_cam/lcd/i8080.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
//! # use esp_hal::lcd_cam::{LcdCam, lcd::i8080::{Config, I8080, TxEightBits}};
//! # use esp_hal::dma_buffers;
//! # use esp_hal::dma::{Dma, DmaPriority};
//! #
//! let system = esp_hal::init(CpuClock::boot_default());
//! # let io = Io::new(system.peripherals.GPIO, system.peripherals.IO_MUX);
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//!
//! # let dma = Dma::new(system.peripherals.DMA);
//! # let dma = Dma::new(peripherals.DMA);
//! # let channel = dma.channel0;
//!
//! # let (tx_buffer, tx_descriptors, _, rx_descriptors) = dma_buffers!(32678, 0);
Expand All @@ -43,7 +41,7 @@
//! io.pins.gpio16,
//! io.pins.gpio15,
//! );
//! let lcd_cam = LcdCam::new(system.peripherals.LCD_CAM);
//! let lcd_cam = LcdCam::new(peripherals.LCD_CAM);
//!
//! let mut i8080 = I8080::new(
//! lcd_cam.lcd,
Expand All @@ -52,7 +50,7 @@
//! tx_pins,
//! 20.MHz(),
//! Config::default(),
//! &system.clocks,
//! &clocks,
//! )
//! .with_ctrl_pins(io.pins.gpio0, io.pins.gpio47);
//!
Expand Down
6 changes: 2 additions & 4 deletions esp-hal/src/ledc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@
//! # use esp_hal::ledc::LowSpeed;
//! # use esp_hal::ledc::channel;
//! # use esp_hal::gpio::Io;
//!
//! let system = esp_hal::init(CpuClock::boot_default());
//! # let io = Io::new(system.peripherals.GPIO, system.peripherals.IO_MUX);
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! # let led = io.pins.gpio0;
//!
//! let mut ledc = Ledc::new(system.peripherals.LEDC, &system.clocks);
//! let mut ledc = Ledc::new(peripherals.LEDC, &clocks);
//! ledc.set_global_slow_clock(LSGlobalClkSource::APBClk);
//!
//! let mut lstimer0 = ledc.get_timer::<LowSpeed>(timer::Number::Timer0);
Expand Down
23 changes: 6 additions & 17 deletions esp-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@
//!
//! #[entry]
//! fn main() -> ! {
//! let system = esp_hal::init(CpuClock::boot_default());
//! let (peripherals, clocks) = esp_hal::init(CpuClock::boot_default());
//!
//! // Set GPIO0 as an output, and set its state high initially.
//! let io = Io::new(system.peripherals.GPIO, system.peripherals.IO_MUX);
//! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! let mut led = Output::new(io.pins.gpio0, Level::High);
//!
//! let delay = Delay::new(&system.clocks);
//! let delay = Delay::new(&clocks);
//!
//! loop {
//! led.toggle();
Expand Down Expand Up @@ -645,21 +645,10 @@ use crate::{
peripherals::Peripherals,
};

/// System components.
pub struct System {
/// The available peripheral instances.
pub peripherals: Peripherals,

/// The configured clocks.
pub clocks: Clocks<'static>,
}

/// Initialize the system.
pub fn init(clock_config: CpuClock) -> System {
pub fn init(clock_config: CpuClock) -> (Peripherals, Clocks<'static>) {
let peripherals = Peripherals::take();
let clocks = ClockControl::new(clock_config).freeze();

System {
peripherals,
clocks: ClockControl::new(clock_config).freeze(),
}
(peripherals, clocks)
}
10 changes: 5 additions & 5 deletions esp-hal/src/mcpwm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@
//! # use esp_hal::mcpwm::{operator::{DeadTimeCfg, PWMStream, PwmPinConfig}, timer::PwmWorkingMode, McPwm, PeripheralClockConfig};
//! # use esp_hal::gpio::Io;
//!
//! # let system = esp_hal::init(CpuClock::boot_default());
//! # let io = Io::new(system.peripherals.GPIO, system.peripherals.IO_MUX);
//! # let (peripherals, clocks) = esp_hal::init(CpuClock::boot_default());
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! # let pin = io.pins.gpio0;
//!
//! // initialize peripheral
#![cfg_attr(
esp32h2,
doc = "let clock_cfg = PeripheralClockConfig::with_frequency(&system.clocks, 40.MHz()).unwrap();"
doc = "let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 40.MHz()).unwrap();"
)]
#![cfg_attr(
not(esp32h2),
doc = "let clock_cfg = PeripheralClockConfig::with_frequency(&system.clocks, 32.MHz()).unwrap();"
doc = "let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 32.MHz()).unwrap();"
)]
//! let mut mcpwm = McPwm::new(system.peripherals.MCPWM0, clock_cfg);
//! let mut mcpwm = McPwm::new(peripherals.MCPWM0, clock_cfg);
//!
//! // connect operator0 to timer0
//! mcpwm.operator0.set_timer(&mcpwm.timer0);
Expand Down
10 changes: 5 additions & 5 deletions esp-hal/src/mcpwm/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,22 +486,22 @@ impl<'d, Pin: OutputPin, PWM: PwmPeripheral, const OP: u8, const IS_A: bool>
/// # use esp_hal::mcpwm::{McPwm, PeripheralClockConfig};
/// # use esp_hal::mcpwm::operator::{DeadTimeCfg, PwmPinConfig, PWMStream};
/// # use esp_hal::gpio::Io;
/// let system = esp_hal::init(CpuClock::boot_default());
/// # let io = Io::new(system.peripherals.GPIO, system.peripherals.IO_MUX);
/// let (peripherals, clocks) = esp_hal::init(CpuClock::boot_default());
/// # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
/// // active high complementary using PWMA input
/// let bridge_active = DeadTimeCfg::new_ahc();
/// // use PWMB as input for both outputs
/// let bridge_off = DeadTimeCfg::new_bypass().set_output_swap(PWMStream::PWMA,
/// true);
#[cfg_attr(
esp32h2,
doc = "let clock_cfg = PeripheralClockConfig::with_frequency(&system.clocks, 40.MHz()).unwrap();"
doc = "let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 40.MHz()).unwrap();"
)]
#[cfg_attr(
not(esp32h2),
doc = "let clock_cfg = PeripheralClockConfig::with_frequency(&system.clocks, 32.MHz()).unwrap();"
doc = "let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 32.MHz()).unwrap();"
)]
/// let mut mcpwm = McPwm::new(system.peripherals.MCPWM0, clock_cfg);
/// let mut mcpwm = McPwm::new(peripherals.MCPWM0, clock_cfg);
///
/// let mut pins = mcpwm.operator0.with_linked_pins(
/// io.pins.gpio0,
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ pub use crate::timer::timg::{
pub use crate::timer::Timer as _esp_hal_timer_Timer;
#[cfg(any(uart0, uart1, uart2))]
pub use crate::uart::Instance as _esp_hal_uart_Instance;
pub use crate::{clock::CpuClock, entry, macros::*, InterruptConfigurable, System};
pub use crate::{clock::CpuClock, entry, macros::*, InterruptConfigurable};
6 changes: 2 additions & 4 deletions esp-hal/src/rmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@
//! # use esp_hal::gpio::Io;
//! # use esp_hal::clock::ClockControl;
//! # use crate::esp_hal::rmt::TxChannelCreator;
//! # use crate::esp_hal::prelude::_fugit_RateExtU32;
//! let system = esp_hal::init(CpuClock::boot_default());
//! # let io = Io::new(system.peripherals.GPIO, system.peripherals.IO_MUX);
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
#![cfg_attr(esp32h2, doc = "let freq = 32.MHz();")]
#![cfg_attr(not(esp32h2), doc = "let freq = 80.MHz();")]
//! let rmt = Rmt::new(system.peripherals.RMT, freq, &system.clocks).unwrap();
//! let rmt = Rmt::new(peripherals.RMT, freq, &clocks).unwrap();
//! let mut channel = rmt
//! .channel0
//! .configure(
Expand Down
12 changes: 6 additions & 6 deletions esp-hal/src/rom/md5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
//! # use esp_hal::gpio::Io;
//! # use core::writeln;
//! # use core::fmt::Write;
//! # let system = esp_hal::init(CpuClock::boot_default());
//! # let io = Io::new(system.peripherals.GPIO, system.peripherals.IO_MUX);
//! # let mut uart0 = Uart::new(system.peripherals.UART0, &system.clocks, io.pins.gpio1, io.pins.gpio2).unwrap();
//! # let (peripherals, clocks) = esp_hal::init(CpuClock::boot_default());
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! # let mut uart0 = Uart::new(peripherals.UART0, &clocks, io.pins.gpio1, io.pins.gpio2).unwrap();
//! # let data = "Dummy";
//! let d: md5::Digest = md5::compute(&data);
//! writeln!(uart0, "{}", d);
Expand All @@ -52,9 +52,9 @@
//! # use esp_hal::gpio::Io;
//! # use core::writeln;
//! # use core::fmt::Write;
//! # let system = esp_hal::init(CpuClock::boot_default());
//! # let io = Io::new(system.peripherals.GPIO, system.peripherals.IO_MUX);
//! # let mut uart0 = Uart::new(system.peripherals.UART0, &system.clocks, io.pins.gpio1, io.pins.gpio2).unwrap();
//! # let (peripherals, clocks) = esp_hal::init(CpuClock::boot_default());
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! # let mut uart0 = Uart::new(peripherals.UART0, &clocks, io.pins.gpio1, io.pins.gpio2).unwrap();
//! # let data0 = "Dummy";
//! # let data1 = "Dummy";
//! #
Expand Down
Loading

0 comments on commit 5f282f4

Please sign in to comment.