Skip to content

Commit

Permalink
Update examples and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Aug 22, 2024
1 parent fedbf30 commit 7effdb9
Show file tree
Hide file tree
Showing 124 changed files with 1,044 additions and 1,324 deletions.
11 changes: 5 additions & 6 deletions examples/src/bin/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@
use esp_backtrace as _;
use esp_hal::{
analog::adc::{Adc, AdcConfig, Attenuation},
clock::ClockControl,
delay::Delay,
gpio::Io,
peripherals::Peripherals,
prelude::*,
system::SystemControl,
};
use esp_println::println;

#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let System {
peripherals,
clocks,
..
} = esp_hal::init(CpuClock::boot_default());

let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
cfg_if::cfg_if! {
Expand Down
11 changes: 5 additions & 6 deletions examples/src/bin/adc_cal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@
use esp_backtrace as _;
use esp_hal::{
analog::adc::{Adc, AdcConfig, Attenuation},
clock::ClockControl,
delay::Delay,
gpio::Io,
peripherals::Peripherals,
prelude::*,
system::SystemControl,
};
use esp_println::println;

#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let System {
peripherals,
clocks,
..
} = esp_hal::init(CpuClock::boot_default());

let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
cfg_if::cfg_if! {
Expand Down
18 changes: 6 additions & 12 deletions examples/src/bin/advanced_serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,17 @@
#![no_main]

use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
delay::Delay,
gpio::Io,
peripherals::Peripherals,
prelude::*,
system::SystemControl,
uart::Uart,
};
use esp_hal::{delay::Delay, gpio::Io, prelude::*, uart::Uart};
use esp_println::println;
use nb::block;

#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let System {
peripherals,
clocks,
..
} = esp_hal::init(CpuClock::boot_default());

let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);

Expand Down
11 changes: 5 additions & 6 deletions examples/src/bin/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@

use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
delay::Delay,
gpio::{Io, Level, Output},
peripherals::Peripherals,
prelude::*,
system::SystemControl,
};

#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let System {
peripherals,
clocks,
..
} = esp_hal::init(CpuClock::boot_default());

// Set GPIO0 as an output, and set its state high initially.
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
Expand Down
11 changes: 5 additions & 6 deletions examples/src/bin/blinky_erased_pins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@

use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
delay::Delay,
gpio::{AnyInput, AnyOutput, Io, Level, Pull},
peripherals::Peripherals,
prelude::*,
system::SystemControl,
};

#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let System {
peripherals,
clocks,
..
} = esp_hal::init(CpuClock::boot_default());

let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);

Expand Down
18 changes: 6 additions & 12 deletions examples/src/bin/dac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,15 @@
#![no_main]

use esp_backtrace as _;
use esp_hal::{
analog::dac::Dac,
clock::ClockControl,
delay::Delay,
gpio::Io,
peripherals::Peripherals,
prelude::*,
system::SystemControl,
};
use esp_hal::{analog::dac::Dac, delay::Delay, gpio::Io, prelude::*};

#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let System {
peripherals,
clocks,
..
} = esp_hal::init(CpuClock::boot_default());

let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);

Expand Down
16 changes: 6 additions & 10 deletions examples/src/bin/debug_assist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@ use core::cell::RefCell;

use critical_section::Mutex;
use esp_backtrace as _;
use esp_hal::{
assist_debug::DebugAssist,
clock::ClockControl,
peripherals::Peripherals,
prelude::*,
system::SystemControl,
};
use esp_hal::{assist_debug::DebugAssist, prelude::*};
use esp_println::println;

static DA: Mutex<RefCell<Option<DebugAssist>>> = Mutex::new(RefCell::new(None));

#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let _clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let System {
peripherals,
clocks,
..
} = esp_hal::init(CpuClock::boot_default());

let mut da = DebugAssist::new(peripherals.ASSIST_DEBUG);
da.set_interrupt_handler(interrupt_handler);
Expand Down
12 changes: 6 additions & 6 deletions examples/src/bin/dma_extmem2mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@
use aligned::{Aligned, A64};
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
delay::Delay,
dma::{Dma, DmaPriority, Mem2Mem},
dma_descriptors_chunk_size,
peripherals::Peripherals,
prelude::*,
system::SystemControl,
};
use log::{error, info};
extern crate alloc;
Expand Down Expand Up @@ -65,10 +62,13 @@ fn init_heap(psram: impl esp_hal::peripheral::Peripheral<P = esp_hal::peripheral
fn main() -> ! {
esp_println::logger::init_logger(log::LevelFilter::Info);

let peripherals = Peripherals::take();
let System {
peripherals,
clocks,
..
} = esp_hal::init(CpuClock::boot_default());

init_heap(peripherals.PSRAM);
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let delay = Delay::new(&clocks);

let mut extram_buffer: &mut [u8] = dma_alloc_buffer!(DATA_SIZE, 64);
Expand Down
12 changes: 6 additions & 6 deletions examples/src/bin/dma_mem2mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@

use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
delay::Delay,
dma::{Dma, DmaPriority, Mem2Mem},
dma_buffers,
peripherals::Peripherals,
prelude::*,
system::SystemControl,
};
use log::{error, info};

Expand All @@ -24,9 +21,12 @@ const DATA_SIZE: usize = 1024 * 10;
fn main() -> ! {
esp_println::logger::init_logger(log::LevelFilter::Info);

let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let System {
peripherals,
clocks,
..
} = esp_hal::init(CpuClock::boot_default());

let delay = Delay::new(&clocks);

let (tx_buffer, tx_descriptors, mut rx_buffer, rx_descriptors) = dma_buffers!(DATA_SIZE);
Expand Down
15 changes: 6 additions & 9 deletions examples/src/bin/embassy_hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@
use embassy_executor::Spawner;
use embassy_time::{Duration, Timer};
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
peripherals::Peripherals,
system::SystemControl,
timer::timg::TimerGroup,
};
use esp_hal::{prelude::*, timer::timg::TimerGroup};

#[embassy_executor::task]
async fn run() {
Expand All @@ -30,11 +25,13 @@ async fn run() {
#[esp_hal_embassy::main]
async fn main(spawner: Spawner) {
esp_println::logger::init_logger_from_env();
let System {
peripherals,
clocks,
..
} = esp_hal::init(CpuClock::boot_default());

esp_println::println!("Init!");
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
esp_hal_embassy::init(&clocks, timg0.timer0);
Expand Down
18 changes: 6 additions & 12 deletions examples/src/bin/embassy_i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,16 @@
use embassy_executor::Spawner;
use embassy_time::{Duration, Timer};
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
gpio::Io,
i2c::I2C,
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::timg::TimerGroup,
};
use esp_hal::{gpio::Io, i2c::I2C, prelude::*, timer::timg::TimerGroup};
use lis3dh_async::{Lis3dh, Range, SlaveAddr};

#[esp_hal_embassy::main]
async fn main(_spawner: Spawner) {
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let System {
peripherals,
clocks,
..
} = esp_hal::init(CpuClock::boot_default());

let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
esp_hal_embassy::init(&clocks, timg0.timer0);
Expand Down
18 changes: 6 additions & 12 deletions examples/src/bin/embassy_i2c_bmp180_calibration_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,15 @@
use embassy_executor::Spawner;
use embassy_time::{Duration, Timer};
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
gpio::Io,
i2c::I2C,
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::timg::TimerGroup,
};
use esp_hal::{gpio::Io, i2c::I2C, prelude::*, timer::timg::TimerGroup};

#[esp_hal_embassy::main]
async fn main(_spawner: Spawner) {
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let System {
peripherals,
clocks,
..
} = esp_hal::init(CpuClock::boot_default());

let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
esp_hal_embassy::init(&clocks, timg0.timer0);
Expand Down
11 changes: 5 additions & 6 deletions examples/src/bin/embassy_i2s_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,23 @@
use embassy_executor::Spawner;
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
dma::{Dma, DmaPriority},
dma_buffers,
gpio::Io,
i2s::{asynch::*, DataFormat, I2s, Standard},
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::timg::TimerGroup,
};
use esp_println::println;

#[esp_hal_embassy::main]
async fn main(_spawner: Spawner) {
println!("Init!");
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let System {
peripherals,
clocks,
..
} = esp_hal::init(CpuClock::boot_default());

let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
esp_hal_embassy::init(&clocks, timg0.timer0);
Expand Down
11 changes: 5 additions & 6 deletions examples/src/bin/embassy_i2s_sound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@
use embassy_executor::Spawner;
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
dma::{Dma, DmaPriority},
dma_buffers,
gpio::Io,
i2s::{asynch::*, DataFormat, I2s, Standard},
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::timg::TimerGroup,
};
use esp_println::println;
Expand All @@ -57,9 +54,11 @@ const SINE: [i16; 64] = [
#[esp_hal_embassy::main]
async fn main(_spawner: Spawner) {
println!("Init!");
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let System {
peripherals,
clocks,
..
} = esp_hal::init(CpuClock::boot_default());

let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
esp_hal_embassy::init(&clocks, timg0.timer0);
Expand Down
Loading

0 comments on commit 7effdb9

Please sign in to comment.