Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions esp32-hal/examples/i2c_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#![no_std]
#![no_main]

use core::fmt::Write;

use embedded_graphics::{
mono_font::{
ascii::{FONT_6X10, FONT_9X18_BOLD},
Expand All @@ -29,7 +27,6 @@ use esp32_hal::{
prelude::*,
timer::TimerGroup,
Rtc,
Serial,
};
use esp_backtrace as _;
use nb::block;
Expand All @@ -45,7 +42,6 @@ fn main() -> ! {
let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let mut timer0 = timer_group0.timer0;
let mut wdt = timer_group0.wdt;
let mut serial0 = Serial::new(peripherals.UART0);
let mut rtc = Rtc::new(peripherals.RTC_CNTL);

// Disable watchdog timer
Expand All @@ -54,8 +50,6 @@ fn main() -> ! {

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

writeln!(serial0, "Enabling peripheral!").unwrap();

// Create a new peripheral object with the described wiring
// and standard I2C clock speed
let i2c = I2C::new(
Expand All @@ -71,8 +65,6 @@ fn main() -> ! {
// Start timer (5 second interval)
timer0.start(5u64.secs());

writeln!(serial0, "Starting timer!").unwrap();

// Initialize display
let interface = I2CDisplayInterface::new(i2c);
let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0)
Expand All @@ -90,8 +82,6 @@ fn main() -> ! {
.build();

loop {
writeln!(serial0, "In Loop!").unwrap();

// Fill display bufffer with a centered text with two lines (and two text
// styles)
Text::with_alignment(
Expand Down
13 changes: 5 additions & 8 deletions esp32-hal/examples/ledc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#![no_std]
#![no_main]

use core::fmt::Write;

use esp32_hal::{
clock::ClockControl,
gpio::IO,
Expand All @@ -21,7 +19,6 @@ use esp32_hal::{
prelude::*,
timer::TimerGroup,
Rtc,
Serial,
};
use esp_backtrace as _;
use xtensa_lx_rt::entry;
Expand All @@ -34,7 +31,6 @@ fn main() -> ! {

let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let mut wdt = timer_group0.wdt;
let mut serial0 = Serial::new(peripherals.UART0);
let mut rtc = Rtc::new(peripherals.RTC_CNTL);

// Disable watchdog timer
Expand All @@ -44,10 +40,11 @@ fn main() -> ! {
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
let led = io.pins.gpio4.into_push_pull_output();

writeln!(serial0, "\nESP32 Started\n\n").unwrap();

let ledc = LEDC::new(peripherals.LEDC, &clocks, &mut system.peripheral_clock_control);

let ledc = LEDC::new(
peripherals.LEDC,
&clocks,
&mut system.peripheral_clock_control,
);
let mut hstimer0 = ledc.get_timer::<HighSpeed>(timer::Number::Timer0);

hstimer0
Expand Down
4 changes: 1 addition & 3 deletions esp32-hal/examples/pulse_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,10 @@ fn main() -> ! {
};
}

esp_println::println!("Start");

loop {
// Send sequence
rmt_channel0
.send_pulse_sequence(RepeatMode::SingleShot, &seq)
.unwrap();
}
}
}
41 changes: 17 additions & 24 deletions esp32-hal/examples/ram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@
#![no_std]
#![no_main]

use core::fmt::Write;

use esp32_hal::{
clock::ClockControl,
macros::ram,
pac::{Peripherals, UART0},
pac::Peripherals,
prelude::*,
timer::TimerGroup,
Serial,
};
use esp_backtrace as _;
use esp_println::println;
use nb::block;
use xtensa_lx_rt::entry;

Expand All @@ -40,7 +38,6 @@ fn main() -> ! {
let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let mut timer0 = timer_group0.timer0;
let mut wdt = timer_group0.wdt;
let mut serial0 = Serial::new(peripherals.UART0);

// Disable MWDT flash boot protection
wdt.disable();
Expand All @@ -49,23 +46,21 @@ fn main() -> ! {

timer0.start(1u64.secs());

writeln!(
serial0,
println!(
"IRAM function located at {:p}",
function_in_ram as *const ()
)
.unwrap();
);
unsafe {
writeln!(serial0, "SOME_INITED_DATA {:x?}", SOME_INITED_DATA).unwrap();
writeln!(serial0, "SOME_UNINITED_DATA {:x?}", SOME_UNINITED_DATA).unwrap();
writeln!(serial0, "SOME_ZEROED_DATA {:x?}", SOME_ZEROED_DATA).unwrap();
println!("SOME_INITED_DATA {:x?}", SOME_INITED_DATA);
println!("SOME_UNINITED_DATA {:x?}", SOME_UNINITED_DATA);
println!("SOME_ZEROED_DATA {:x?}", SOME_ZEROED_DATA);

SOME_INITED_DATA[0] = 0xff;
SOME_ZEROED_DATA[0] = 0xff;

writeln!(serial0, "SOME_INITED_DATA {:x?}", SOME_INITED_DATA).unwrap();
writeln!(serial0, "SOME_UNINITED_DATA {:x?}", SOME_UNINITED_DATA).unwrap();
writeln!(serial0, "SOME_ZEROED_DATA {:x?}", SOME_ZEROED_DATA).unwrap();
println!("SOME_INITED_DATA {:x?}", SOME_INITED_DATA);
println!("SOME_UNINITED_DATA {:x?}", SOME_UNINITED_DATA);
println!("SOME_ZEROED_DATA {:x?}", SOME_ZEROED_DATA);

if SOME_UNINITED_DATA[0] != 0 {
SOME_UNINITED_DATA[0] = 0;
Expand All @@ -76,27 +71,25 @@ fn main() -> ! {
SOME_UNINITED_DATA[1] = 0;
}

writeln!(serial0, "Counter {}", SOME_UNINITED_DATA[1]).unwrap();
println!("Counter {}", SOME_UNINITED_DATA[1]);
SOME_UNINITED_DATA[1] += 1;
}

writeln!(
serial0,
println!(
"RTC_FAST function located at {:p}",
function_in_rtc_ram as *const ()
)
.unwrap();
writeln!(serial0, "Result {}", function_in_rtc_ram()).unwrap();
);
println!("Result {}", function_in_rtc_ram());

loop {
function_in_ram(&mut serial0);
function_in_ram();
block!(timer0.wait()).unwrap();
}
}

#[ram]
fn function_in_ram(serial0: &mut Serial<UART0>) {
writeln!(serial0, "Hello world!").unwrap();
fn function_in_ram() {
println!("Hello world!");
}

#[ram(rtc_fast)]
Expand Down
32 changes: 7 additions & 25 deletions esp32-hal/examples/read_efuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
#![no_std]
#![no_main]

use core::fmt::Write;

use esp32_hal::{
clock::ClockControl,
efuse::Efuse,
pac::Peripherals,
prelude::*,
timer::TimerGroup,
Rtc,
Serial,
};
use esp_backtrace as _;
use esp_println::println;
use xtensa_lx_rt::entry;

#[entry]
Expand All @@ -26,34 +24,18 @@ fn main() -> ! {

let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let mut wdt = timer_group0.wdt;
let mut serial0 = Serial::new(peripherals.UART0);
let mut rtc = Rtc::new(peripherals.RTC_CNTL);

// Disable MWDT and RWDT (Watchdog) flash boot protection
wdt.disable();
rtc.rwdt.disable();

writeln!(serial0, "MAC address {:02x?}", Efuse::get_mac_address()).unwrap();
writeln!(serial0, "Core Count {}", Efuse::get_core_count()).unwrap();
writeln!(
serial0,
"Bluetooth enabled {}",
Efuse::is_bluetooth_enabled()
)
.unwrap();
writeln!(serial0, "Chip type {:?}", Efuse::get_chip_type()).unwrap();
writeln!(
serial0,
"Max CPU clock {:?}",
Efuse::get_max_cpu_frequency()
)
.unwrap();
writeln!(
serial0,
"Flash Encryption {:?}",
Efuse::get_flash_encryption()
)
.unwrap();
println!("MAC address {:02x?}", Efuse::get_mac_address());
println!("Core Count {}", Efuse::get_core_count());
println!("Bluetooth enabled {}", Efuse::is_bluetooth_enabled());
println!("Chip type {:?}", Efuse::get_chip_type());
println!("Max CPU clock {:?}", Efuse::get_max_cpu_frequency());
println!("Flash Encryption {:?}", Efuse::get_flash_encryption());

loop {}
}
26 changes: 11 additions & 15 deletions esp32-hal/examples/spi_eh1_device_loopback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
#![no_std]
#![no_main]

use core::fmt::Write;

use embedded_hal_1::spi::blocking::SpiDevice;
use esp32_hal::{
clock::ClockControl,
gpio::IO,
Expand All @@ -29,13 +28,11 @@ use esp32_hal::{
timer::TimerGroup,
Delay,
Rtc,
Serial,
};
use esp_backtrace as _;
use esp_println::{print, println};
use xtensa_lx_rt::entry;

use embedded_hal_1::spi::blocking::SpiDevice;

#[entry]
fn main() -> ! {
let peripherals = Peripherals::take().unwrap();
Expand All @@ -47,7 +44,6 @@ fn main() -> ! {
let mut rtc = Rtc::new(peripherals.RTC_CNTL);
let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let mut wdt = timer_group0.wdt;
let mut serial0 = Serial::new(peripherals.UART0);

wdt.disable();
rtc.rwdt.disable();
Expand All @@ -72,23 +68,23 @@ fn main() -> ! {
let mut spi_device_3 = spi_controller.add_device(io.pins.gpio14);

let mut delay = Delay::new(&clocks);
writeln!(serial0, "=== SPI example with embedded-hal-1 traits ===").unwrap();
println!("=== SPI example with embedded-hal-1 traits ===");

loop {
// --- Symmetric transfer (Read as much as we write) ---
write!(serial0, "Starting symmetric transfer...").unwrap();
print!("Starting symmetric transfer...");
let write = [0xde, 0xad, 0xbe, 0xef];
let mut read: [u8; 4] = [0x00u8; 4];

spi_device_1.transfer(&mut read[..], &write[..]).unwrap();
assert_eq!(write, read);
spi_device_2.transfer(&mut read[..], &write[..]).unwrap();
spi_device_3.transfer(&mut read[..], &write[..]).unwrap();
writeln!(serial0, " SUCCESS").unwrap();
println!(" SUCCESS");
delay.delay_ms(250u32);

// --- Asymmetric transfer (Read more than we write) ---
write!(serial0, "Starting asymetric transfer (read > write)...").unwrap();
print!("Starting asymetric transfer (read > write)...");
let mut read: [u8; 4] = [0x00; 4];

spi_device_1
Expand All @@ -102,12 +98,12 @@ fn main() -> ! {
spi_device_3
.transfer(&mut read[0..2], &write[..])
.expect("Asymmetric transfer failed");
writeln!(serial0, " SUCCESS").unwrap();
println!(" SUCCESS");
delay.delay_ms(250u32);

// --- Symmetric transfer with huge buffer ---
// Only your RAM is the limit!
write!(serial0, "Starting huge transfer...").unwrap();
print!("Starting huge transfer...");
let mut write = [0x55u8; 4096];
for byte in 0..write.len() {
write[byte] = byte as u8;
Expand All @@ -124,12 +120,12 @@ fn main() -> ! {
spi_device_3
.transfer(&mut read[..], &write[..])
.expect("Huge transfer failed");
writeln!(serial0, " SUCCESS").unwrap();
println!(" SUCCESS");
delay.delay_ms(250u32);

// --- Symmetric transfer with huge buffer in-place (No additional allocation
// needed) ---
write!(serial0, "Starting huge transfer (in-place)...").unwrap();
print!("Starting huge transfer (in-place)...");
let mut write = [0x55u8; 4096];
for byte in 0..write.len() {
write[byte] = byte as u8;
Expand All @@ -147,7 +143,7 @@ fn main() -> ! {
spi_device_3
.transfer_in_place(&mut write[..])
.expect("Huge transfer failed");
writeln!(serial0, " SUCCESS").unwrap();
println!(" SUCCESS");
delay.delay_ms(250u32);
}
}
Loading