-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
223 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//! Blinks an LED | ||
//! | ||
//! This assumes that a LED is connected to GPIO4. | ||
//! Depending on your target and the board you are using you should change the pin. | ||
//! If your board doesn't have on-board LEDs don't forget to add an appropriate resistor. | ||
//! | ||
use esp_idf_hal::gpio::*; | ||
use esp_idf_hal::peripherals::Peripherals; | ||
use esp_idf_hal::task::*; | ||
use esp_idf_hal::timer::*; | ||
|
||
fn main() -> anyhow::Result<()> { | ||
esp_idf_hal::sys::link_patches(); | ||
|
||
let peripherals = Peripherals::take()?; | ||
|
||
let mut led = PinDriver::output(peripherals.pins.gpio4)?; | ||
let mut timer = TimerDriver::new(peripherals.timer00, &TimerConfig::new())?; | ||
|
||
block_on(async { | ||
loop { | ||
led.set_high()?; | ||
|
||
timer.delay(timer.tick_hz()).await?; | ||
|
||
led.set_low()?; | ||
|
||
timer.delay(timer.tick_hz()).await?; | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//! Turn an LED on/off depending on the state of a button | ||
//! | ||
//! This assumes that a LED is connected to GPIO4. | ||
//! Additionally this assumes a button connected to GPIO9. | ||
//! On an ESP32C3 development board this is the BOOT button. | ||
//! | ||
//! Depending on your target and the board you are using you should change the pins. | ||
//! If your board doesn't have on-board LEDs don't forget to add an appropriate resistor. | ||
use esp_idf_hal::gpio::*; | ||
use esp_idf_hal::peripherals::Peripherals; | ||
use esp_idf_hal::task::*; | ||
|
||
fn main() -> anyhow::Result<()> { | ||
esp_idf_hal::sys::link_patches(); | ||
|
||
let peripherals = Peripherals::take()?; | ||
|
||
let mut led = PinDriver::output(peripherals.pins.gpio4)?; | ||
let mut button = PinDriver::input(peripherals.pins.gpio9)?; | ||
|
||
button.set_pull(Pull::Down)?; | ||
|
||
block_on(async { | ||
loop { | ||
button.wait_for_high().await?; | ||
|
||
led.set_high()?; | ||
|
||
button.wait_for_low().await?; | ||
|
||
led.set_low()?; | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//! SPI loopback test | ||
//! | ||
//! Folowing pins are used: | ||
//! SCLK GPIO6 | ||
//! SDI GPIO2 | ||
//! SDO GPIO7 | ||
//! CS_1 GPIO10 | ||
//! CS_2 GPIO3 | ||
//! | ||
//! Depending on your target and the board you are using you have to change the pins. | ||
//! | ||
//! This example transfers data via SPI. | ||
//! Connect SDI and SDO pins to see the outgoing data is read as incoming data. | ||
use embedded_hal::spi::Operation; | ||
use esp_idf_hal::peripherals::Peripherals; | ||
use esp_idf_hal::prelude::*; | ||
use esp_idf_hal::spi::*; | ||
use esp_idf_hal::task::*; | ||
|
||
fn main() -> anyhow::Result<()> { | ||
esp_idf_hal::sys::link_patches(); | ||
|
||
let peripherals = Peripherals::take()?; | ||
let spi = peripherals.spi2; | ||
|
||
let sclk = peripherals.pins.gpio6; | ||
let serial_in = peripherals.pins.gpio2; // SDI | ||
let serial_out = peripherals.pins.gpio7; // SDO | ||
let cs_1 = peripherals.pins.gpio10; | ||
let cs_2 = peripherals.pins.gpio3; | ||
|
||
println!("Starting SPI loopback test"); | ||
|
||
let driver = SpiDriver::new::<SPI2>( | ||
spi, | ||
sclk, | ||
serial_out, | ||
Some(serial_in), | ||
&SpiDriverConfig::new(), | ||
)?; | ||
|
||
let config_1 = config::Config::new().baudrate(26.MHz().into()); | ||
let mut device_1 = SpiDeviceDriver::new(&driver, Some(cs_1), &config_1)?; | ||
|
||
let config_2 = config::Config::new().baudrate(13.MHz().into()); | ||
let mut device_2 = SpiDeviceDriver::new(&driver, Some(cs_2), &config_2)?; | ||
|
||
let mut read = [0u8; 4]; | ||
let write = [0xde, 0xad, 0xbe, 0xef]; | ||
|
||
block_on(async { | ||
loop { | ||
device_1.transfer_async(&mut read, &write).await?; | ||
println!("Device 1: Wrote {write:x?}, read {read:x?}"); | ||
|
||
let write_buf = [0xde, 0xad, 0xbe, 0xef]; | ||
let mut write_in_place_buf = [0xde, 0xad, 0xbe, 0xef]; | ||
let mut read_buf = [0; 8]; | ||
|
||
println!("Device 2: To write {write_in_place_buf:x?} ... "); | ||
// cascade multiple operations with different buffer length into one transaction | ||
device_2 | ||
.transaction_async(&mut [ | ||
Operation::Write(&write_buf), | ||
Operation::TransferInPlace(&mut write_in_place_buf), | ||
Operation::Read(&mut read_buf), | ||
]) | ||
.await?; | ||
println!("... read {write_in_place_buf:x?}"); | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.