Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/taunusflieger/global-state-experiment
This project shows how to share a GPIO pin across different threads.
https://github.com/taunusflieger/global-state-experiment
embedded-rust esp32 esp32c3
Last synced: 12 days ago
JSON representation
This project shows how to share a GPIO pin across different threads.
- Host: GitHub
- URL: https://github.com/taunusflieger/global-state-experiment
- Owner: taunusflieger
- Created: 2022-11-16T12:41:30.000Z (about 2 years ago)
- Default Branch: FreeRTOS-Threads
- Last Pushed: 2022-11-18T21:55:04.000Z (about 2 years ago)
- Last Synced: 2024-11-11T11:31:58.446Z (about 2 months ago)
- Topics: embedded-rust, esp32, esp32c3
- Language: Rust
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# global-state-experiment
This project helped me to answer the question how to share a GPIO pin across different threads. There are two branches:
* **FreeRTOS-Threads** here the threads are created using EP-IDF FreeRTOS
* **master** here the threads are created using embassy-sync. This version doesn't work as expected as the Timer function doesn't behave like expected. It looks like that after a while the timer doesn't create the specified delay.## How does the sharing work?
In the main thread the shared GPIO pin is stored in
```rust
type LedPin = esp_idf_hal::gpio::PinDriver<'static, Gpio7, Output>;static LED_PIN: static_cell::StaticCell>>> =
static_cell::StaticCell::new();
```
which provides a thread safe way to handle access to the shared GPIO pin## How to build?
The project is targeting the [`esp-rust-board`](https://github.com/esp-rs/esp-rust-board) which uses a esp32c3 SoC. The led pin used is GPIO7.```sh
cargo espflash flash --monitor --port /dev/ttyACM0
```The project creates two threads. One thread sets the led pin to high, the other thread sets the pin to low. Both threads have different delay/sleep values. The result is a blinking led.