WIP 2
This commit is contained in:
@@ -12,5 +12,4 @@ build-std = ["std", "panic_abort"]
|
||||
[env]
|
||||
MCU="esp32"
|
||||
# Note: this variable is not used by the pio builder (`cargo build --features pio`)
|
||||
ESP_IDF_VERSION = "v5.2.3"
|
||||
|
||||
ESP_IDF_VERSION = "v5.3.3"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "esp-idf-no-std"
|
||||
name = "esp-idf-rust-no-std"
|
||||
version = "0.1.0"
|
||||
authors = ["Shaun Reed <shaunrd0@gmail.com>"]
|
||||
edition = "2021"
|
||||
@@ -7,7 +7,7 @@ resolver = "2"
|
||||
rust-version = "1.77"
|
||||
|
||||
[[bin]]
|
||||
name = "esp-idf-no-std"
|
||||
name = "esp-idf-rust-no-std"
|
||||
harness = false # do not use the built in cargo test harness -> resolve rust-analyzer errors
|
||||
|
||||
[profile.release]
|
||||
@@ -25,8 +25,6 @@ experimental = ["esp-idf-svc/experimental"]
|
||||
[dependencies]
|
||||
log = "0.4"
|
||||
esp-idf-svc = "0.51"
|
||||
esp-idf-hal = "0.45.2"
|
||||
anyhow = "1.0.98"
|
||||
|
||||
# --- Optional Embassy Integration ---
|
||||
# esp-idf-svc = { version = "0.51", features = ["critical-section", "embassy-time-driver", "embassy-sync"] }
|
||||
|
||||
27
esp/rust/02_esp-idf-no-std/README.md
Normal file
27
esp/rust/02_esp-idf-no-std/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# 02_esp-idf-no-std
|
||||
|
||||
This is an example of using ESP-IDF using no std using templates provided by https://github.com/esp-rs/esp-idf-template.
|
||||
When flashed to a device, the application just adjusts the intensity of the on-board LED for visual verification that flashing works correctly.
|
||||
|
||||
Steps used to generate this project
|
||||
|
||||
```bash
|
||||
cargo install cargo-generate
|
||||
cargo generate --git https://github.com/esp-rs/esp-idf-template.git --name esp-idf-rust-no-std -d mcu=esp32 -d std=false
|
||||
```
|
||||
|
||||
Steps to build and flash this project
|
||||
|
||||
```bash
|
||||
# Install espflash if you don't have it already
|
||||
cargo install espflash
|
||||
|
||||
# Export esp-idf build environment
|
||||
. ~/export-esp.sh
|
||||
|
||||
# Build and flash to the device
|
||||
cargo build
|
||||
cargo run
|
||||
```
|
||||
|
||||
For more detailed information on setting up a development environment, see [the esp/rust README](/esp/rust/README.md)
|
||||
@@ -1,62 +1,22 @@
|
||||
use esp_idf_hal::delay::{FreeRtos, BLOCK};
|
||||
use esp_idf_hal::i2c::*;
|
||||
use esp_idf_hal::peripherals::Peripherals;
|
||||
use esp_idf_hal::prelude::*;
|
||||
use esp_idf_svc::hal::{};
|
||||
|
||||
const SSD1306_ADDRESS: u8 = 0x3c;
|
||||
fn main() {
|
||||
// It is necessary to call this function once. Otherwise some patches to the runtime
|
||||
// implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
|
||||
esp_idf_svc::sys::link_patches();
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
esp_idf_hal::sys::link_patches();
|
||||
// Bind the log crate to the ESP Logging facilities
|
||||
esp_idf_svc::log::EspLogger::initialize_default();
|
||||
let peripherals = Peripherals::take()?;
|
||||
|
||||
let peripherals = Peripherals::take()?;
|
||||
let i2c = peripherals.i2c0;
|
||||
let sda = peripherals.pins.gpio21;
|
||||
let scl = peripherals.pins.gpio22;
|
||||
|
||||
println!("Starting I2C SSD1306 test");
|
||||
loop {
|
||||
led.toggle();
|
||||
blocking_delay(Duration::from_millis(500));
|
||||
}
|
||||
}
|
||||
|
||||
let config = I2cConfig::new().baudrate(100.kHz().into());
|
||||
let mut i2c = I2cDriver::new(i2c, sda, scl, &config)?;
|
||||
|
||||
// initialze the display - don't worry about the meaning of these bytes - it's specific to SSD1306
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0xae], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0xd4], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0x80], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0xa8], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0x3f], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0xd3], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0x00], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0x40], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0x8d], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0x14], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0xa1], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0xc8], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0xda], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0x12], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0x81], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0xcf], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0xf1], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0xdb], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0x40], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0xa4], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0xa6], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0xaf], BLOCK)?;
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0x20, 0x00], BLOCK)?;
|
||||
|
||||
// fill the display
|
||||
for _ in 0..64 {
|
||||
let data: [u8; 17] = [
|
||||
0x40, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff,
|
||||
];
|
||||
i2c.write(SSD1306_ADDRESS, &data, BLOCK)?;
|
||||
}
|
||||
|
||||
loop {
|
||||
// we are sleeping here to make sure the watchdog isn't triggered
|
||||
FreeRtos::delay_ms(500);
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0xa6], BLOCK)?;
|
||||
FreeRtos::delay_ms(500);
|
||||
i2c.write(SSD1306_ADDRESS, &[0, 0xa7], BLOCK)?;
|
||||
}
|
||||
}
|
||||
fn blocking_delay(duration: Duration) {
|
||||
let delay_start = Instant::now();
|
||||
while delay_start.elapsed() < duration {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user