Remove some examples which are adequately covered by documentation (#2538)

This commit is contained in:
Jesse Braham 2024-11-14 01:32:18 -08:00 committed by GitHub
parent 38dde2ebbd
commit 64f4fea403
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 0 additions and 284 deletions

View File

@ -1,53 +0,0 @@
//! Connect a potentiometer to an IO pin and see the read values change when
//! rotating the shaft.
//!
//! Alternatively, you could also connect the IO pin to GND or 3V3 to see the
//! maximum and minimum raw values read.
//!
//! The following wiring is assumed for ESP32:
//! - Analog pin => GPIO32
//! The following wiring is assumed for ESP32S2/S3:
//! - Analog pin => GPIO3
//! The following wiring is assumed for others:
//! - Analog pin => GPIO2
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
#![no_std]
#![no_main]
use esp_backtrace as _;
use esp_hal::{
analog::adc::{Adc, AdcConfig, Attenuation},
delay::Delay,
prelude::*,
};
use esp_println::println;
#[entry]
fn main() -> ! {
let peripherals = esp_hal::init(esp_hal::Config::default());
cfg_if::cfg_if! {
if #[cfg(feature = "esp32")] {
let analog_pin = peripherals.GPIO32;
} else if #[cfg(any(feature = "esp32s2", feature = "esp32s3"))] {
let analog_pin = peripherals.GPIO3;
} else {
let analog_pin = peripherals.GPIO2;
}
}
// Create ADC instances
let mut adc1_config = AdcConfig::new();
let mut adc1_pin = adc1_config.enable_pin(analog_pin, Attenuation::Attenuation11dB);
let mut adc1 = Adc::new(peripherals.ADC1, adc1_config);
let delay = Delay::new();
loop {
let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap();
println!("ADC reading = {}", pin_value);
delay.delay_millis(1500);
}
}

View File

@ -1,57 +0,0 @@
//! Connect a potentiometer to GPIO and see the read values change when
//! rotating the shaft. Alternatively you could also connect the PIN to GND or
//! 3V3 to see the maximum and minimum raw values read.
//!
//! The following wiring is assumed for ESP32S3:
//! - Analog pin => GPIO3
//! The following wiring is assumed for others:
//! - Analog pin => GPIO2
//% CHIPS: esp32c2 esp32c3 esp32c6 esp32s3
#![no_std]
#![no_main]
use esp_backtrace as _;
use esp_hal::{
analog::adc::{Adc, AdcConfig, Attenuation},
delay::Delay,
prelude::*,
};
use esp_println::println;
#[entry]
fn main() -> ! {
let peripherals = esp_hal::init(esp_hal::Config::default());
cfg_if::cfg_if! {
if #[cfg(feature = "esp32s3")] {
let analog_pin = peripherals.GPIO3;
} else {
let analog_pin = peripherals.GPIO2;
}
}
// Create ADC instances
// You can try any of the following calibration methods by uncommenting
// them. Note that only AdcCalLine returns readings in mV; the other two
// return raw readings in some unspecified scale.
//
// type AdcCal = ();
type AdcCal = esp_hal::analog::adc::AdcCalBasic<esp_hal::peripherals::ADC1>;
// type AdcCal = esp_hal::analog::adc::AdcCalLine<esp_hal::peripherals::ADC1>;
// type AdcCal = esp_hal::analog::adc::AdcCalCurve<esp_hal::peripherals::ADC1>;
let mut adc1_config = AdcConfig::new();
let mut adc1_pin =
adc1_config.enable_pin_with_cal::<_, AdcCal>(analog_pin, Attenuation::Attenuation11dB);
let mut adc1 = Adc::new(peripherals.ADC1, adc1_config);
let delay = Delay::new();
loop {
let pin_mv = nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap();
println!("PIN2 ADC reading = {pin_mv} mV");
delay.delay_millis(1500);
}
}

View File

@ -1,35 +0,0 @@
//! Blinks an LED
//!
//! The following wiring is assumed:
//! - LED => GPIO0
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
#![no_std]
#![no_main]
use esp_backtrace as _;
use esp_hal::{
delay::Delay,
gpio::{Level, Output},
prelude::*,
};
#[entry]
fn main() -> ! {
let peripherals = esp_hal::init(esp_hal::Config::default());
// Set GPIO0 as an output, and set its state high initially.
let mut led = Output::new(peripherals.GPIO0, Level::High);
let delay = Delay::new();
loop {
led.toggle();
delay.delay_millis(500);
led.toggle();
// or using `fugit` duration
delay.delay(2.secs());
}
}

View File

@ -1,55 +0,0 @@
//! This example shows how to use the DAC
//!
//! You can connect an LED (with a suitable resistor) or check the changing
//! voltage using a voltmeter on those pins.
//!
//! When targeting the ESP32, the pins for `DAC1` and `DAC2` are GPIO25 and
//! GPIO26 respectively; for the ESP32-S2, they are GPIO17 and GPIO18.
//!
//! The following wiring is assumed for ESP32:
//! - DAC1 => GPIO25
//! - DAC2 => GPIO26
//! The following wiring is assumed for ESP32S2:
//! - DAC1 => GPIO17
//! - DAC2 => GPIO18
//% CHIPS: esp32 esp32s2
#![no_std]
#![no_main]
use esp_backtrace as _;
use esp_hal::{analog::dac::Dac, delay::Delay, prelude::*};
#[entry]
fn main() -> ! {
let peripherals = esp_hal::init(esp_hal::Config::default());
cfg_if::cfg_if! {
if #[cfg(feature = "esp32")] {
let dac1_pin = peripherals.GPIO25;
let dac2_pin = peripherals.GPIO26;
} else if #[cfg(feature = "esp32s2")] {
let dac1_pin = peripherals.GPIO17;
let dac2_pin = peripherals.GPIO18;
}
}
// Create DAC instances
let mut dac1 = Dac::new(peripherals.DAC1, dac1_pin);
let mut dac2 = Dac::new(peripherals.DAC2, dac2_pin);
let delay = Delay::new();
let mut voltage_dac1: u8 = 200;
let mut voltage_dac2: u8 = 255;
loop {
// Change voltage on the pins using write function
voltage_dac1 = voltage_dac1.wrapping_add(1);
dac1.write(voltage_dac1);
voltage_dac2 = voltage_dac2.wrapping_sub(1);
dac2.write(voltage_dac2);
delay.delay_millis(50);
}
}

View File

@ -1,49 +0,0 @@
//! This shows how to write text to UART0.
//!
//! You can see the output with `espflash` if you provide the `--monitor`
//! option.
//!
//! Depending on the chip, you will need to ensure that you are connected to
//! the UART USB port, and not the USB-SERIAL-JTAG port. If you want to test
//! printing over USB-SERIAL-JTAG, try the usb_serial_jtag example instead.
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
#![no_std]
#![no_main]
use core::fmt::Write;
use esp_backtrace as _;
use esp_hal::{delay::Delay, prelude::*, uart::Uart};
#[entry]
fn main() -> ! {
let peripherals = esp_hal::init(esp_hal::Config::default());
let delay = Delay::new();
// Default pins for Uart/Serial communication
cfg_if::cfg_if! {
if #[cfg(feature = "esp32")] {
let (mut tx_pin, mut rx_pin) = (peripherals.GPIO1, peripherals.GPIO3);
} else if #[cfg(feature = "esp32c2")] {
let (mut tx_pin, mut rx_pin) = (peripherals.GPIO20, peripherals.GPIO19);
} else if #[cfg(feature = "esp32c3")] {
let (mut tx_pin, mut rx_pin) = (peripherals.GPIO21, peripherals.GPIO20);
} else if #[cfg(feature = "esp32c6")] {
let (mut tx_pin, mut rx_pin) = (peripherals.GPIO16, peripherals.GPIO17);
} else if #[cfg(feature = "esp32h2")] {
let (mut tx_pin, mut rx_pin) = (peripherals.GPIO24, peripherals.GPIO23);
} else if #[cfg(any(feature = "esp32s2", feature = "esp32s3"))] {
let (mut tx_pin, mut rx_pin) = (peripherals.GPIO43, peripherals.GPIO44);
}
}
let mut uart0 = Uart::new(peripherals.UART0, &mut rx_pin, &mut tx_pin).unwrap();
loop {
writeln!(uart0, "Hello world!").unwrap();
delay.delay(1.secs());
}
}

View File

@ -1,35 +0,0 @@
//! This demos the watchdog timer.
//!
//! Basically the same as `hello_world` but if you remove the call to
//! `wdt.feed()` the watchdog will reset the system.
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
#![no_std]
#![no_main]
use esp_backtrace as _;
use esp_hal::{
delay::Delay,
prelude::*,
timer::timg::{MwdtStage, TimerGroup},
};
use esp_println::println;
#[entry]
fn main() -> ! {
let peripherals = esp_hal::init(esp_hal::Config::default());
let delay = Delay::new();
let timg0 = TimerGroup::new_async(peripherals.TIMG0);
let mut wdt0 = timg0.wdt;
wdt0.enable();
wdt0.set_timeout(MwdtStage::Stage0, 2u64.secs());
loop {
wdt0.feed();
println!("Hello world!");
delay.delay(1.secs());
}
}