Skip to content

Commit 0923d53

Browse files
committed
example of an unsafe call into ESP IDF
1 parent 632323f commit 0923d53

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

.github/configs/sdkconfig.defaults

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# The examples require a larger than the default stack size for the main thread and the posix threads.
22
CONFIG_ESP_MAIN_TASK_STACK_SIZE=20000
33
CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=8192
4+
5+
# Go figure...
6+
CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=4096

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [?.??.?] - ????-??-??
9+
* First `esp-idf-sys` examples:
10+
* `std_basics`: "Hello world" with `println!` and other types available in the Rust Standard Library like threads, atomics, local storage, collections, etc.
11+
* `unsafe_call`: Calling an ESP IDF custom API using the unsafe bindings generated by `esp-idf-sys`
912
* All FreeRTOS headers are now included, so user should get unsafe bindings for all FreeRTOS APIs which are not macros
1013
* Changes to how native vs PlatformIO build is selected, that are supposed to increase the ergonomics of using the crate:
1114
* Perform PlatformIO build **only** when the `pio` feature IS specified, and the `native` feature is NOT specified

examples/std_basics.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! This example does not use anything from the `esp-idf-sys` unsafe API
2+
//! but demonstrates, that *linking* with the `esp-idf-sys` library artefacts (and with the Rust Standard Library)
3+
//! does provide the Rust STD layer on top of ESP IDF!
4+
15
use core::cell::RefCell;
26
use core::ptr;
37
use core::sync::atomic::{AtomicUsize, Ordering};

examples/unsafe_call.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//! A super-simple example of calling an unsafe API provided by `esp-idf-sys` / ESP IDF
2+
//! and not otherwise available via the Rust Standard Library
3+
4+
use esp_idf_sys::esp_get_free_heap_size;
5+
6+
fn main() {
7+
esp_idf_sys::link_patches();
8+
9+
let free_memory = unsafe { esp_get_free_heap_size() } / 1024;
10+
11+
println!("Free memory: {free_memory}KB");
12+
}

0 commit comments

Comments
 (0)