Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Training update #152

Merged
merged 122 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from 120 commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
f9b1918
build: ⬆️ Pin latests release
SergioGasquez Mar 3, 2023
3728543
build: ⬆️ Update nightly version
SergioGasquez Mar 3, 2023
793cb37
Merge remote-tracking branch 'upstream/main' into feature/crates-update
SergioGasquez Mar 3, 2023
ff8f125
feat: ✨ Update wifi module
SergioGasquez Mar 3, 2023
e6f87f4
feat: ✨ Update led module
SergioGasquez Mar 3, 2023
6c1394c
feat: ✨ Add examples
SergioGasquez Mar 3, 2023
987879a
feat: ✨ Initial update of temp_sensors module
SergioGasquez Mar 3, 2023
7d1f282
chore: 🚧 Comment temp_sensor module
SergioGasquez Mar 3, 2023
48af622
feat: ✨ Update hardware-check example
SergioGasquez Mar 3, 2023
9ef957d
build: 🔥 Remove unnecesary dependencies
SergioGasquez Mar 3, 2023
2bc69d4
build: 🔥 Remove unnecesary dependencies
SergioGasquez Mar 3, 2023
20b9d20
docs: 📝 Add todos
SergioGasquez Mar 3, 2023
4a8ccb7
fix: ⚡️ Updarte clock_divider
SergioGasquez Mar 3, 2023
4bfa825
build: 🔧 Update nightly toolchain
SergioGasquez Mar 6, 2023
63d59a4
build: 🔧 Update custom runner
SergioGasquez Mar 6, 2023
cfa86b9
build: 🔧 Update nightly toolchain
SergioGasquez Mar 6, 2023
c42454a
feat: ✨ Update http client example
SergioGasquez Mar 6, 2023
1108839
chore: 🏗️ Update cargo.lock
SergioGasquez Mar 6, 2023
bee12ea
feat: ✨ Initial update of http client examples
SergioGasquez Mar 6, 2023
25b2eed
feat: ✨ Update hhtp client example
SergioGasquez Mar 6, 2023
6eb6757
feat: ✨ Update hhtp client example
SergioGasquez Mar 6, 2023
95e3b54
feat: ✨ Update hhtps client example
SergioGasquez Mar 6, 2023
29b790a
feat: ✨ Update hhtp client exercise
SergioGasquez Mar 6, 2023
e140f3f
feat: ✨ Update hhtp client exercise
SergioGasquez Mar 6, 2023
28510f5
feat: ⚡️ Clippy check
SergioGasquez Mar 6, 2023
3e8b5ae
style: 🎨 Update imports
SergioGasquez Mar 6, 2023
54cd7b9
feat: 🎨 Format includes
SergioGasquez Mar 6, 2023
3ae9f7d
build: ⬆️ Update rust edition
SergioGasquez Mar 6, 2023
0fe8f3f
feat: 🎨 Format includes
SergioGasquez Mar 6, 2023
dd24b4d
feat: ✨ Initial update of http server
SergioGasquez Mar 7, 2023
d76969a
feat: ✨ Initial update of button interrupt
SergioGasquez Mar 7, 2023
a556945
feat: ✨ Update http server
SergioGasquez Mar 7, 2023
fe8da6e
build: ⬆️ Update dependencies
SergioGasquez Mar 7, 2023
5d6e9f7
build: ⬆️ Update dependencies
SergioGasquez Mar 7, 2023
d9c1563
build: ⬆️ Update dependencies
SergioGasquez Mar 7, 2023
a1c0e2e
build: ⬆️ Update dependencies
SergioGasquez Mar 7, 2023
fb09f58
build: 🏗️ Update authors
SergioGasquez Mar 7, 2023
fca68c8
build: ⬆️ Update dependencies
SergioGasquez Mar 7, 2023
f0a8476
build: ⬆️ Upgrade dependencies
SergioGasquez Mar 8, 2023
a0011bf
fix: 🐛 Fix led pin
SergioGasquez Mar 8, 2023
52dbebd
feat: ✨ Update mqtt exercise
SergioGasquez Mar 8, 2023
f7be26f
feat: ✨ Update i2c-sensor-reading exercise
SergioGasquez Mar 8, 2023
6d90df4
style: 🎨 Improve format
SergioGasquez Mar 8, 2023
ae4abfa
style: 🎨 Improve format
SergioGasquez Mar 8, 2023
cf35894
style: 🎨 Improve format
SergioGasquez Mar 8, 2023
77bb1a5
style: 🎨 Improve format
SergioGasquez Mar 8, 2023
5b84c11
fix: 🐛 Fix typo
SergioGasquez Mar 8, 2023
4a2942e
feat: ✨ Update button interrupt example
SergioGasquez Mar 10, 2023
582b985
docs: 🎨 Update format
SergioGasquez Mar 10, 2023
7f53655
docs: 🎨 Update format and links
SergioGasquez Mar 10, 2023
c982f55
docs: 🎨 Update format
SergioGasquez Mar 10, 2023
209187f
docs: ✨ Update book.toml
SergioGasquez Mar 10, 2023
915fb6a
docs: 📝 Update software chapter
SergioGasquez Mar 10, 2023
96b80e0
docs: 📝 Update repository chapter
SergioGasquez Mar 10, 2023
7a3a3db
ci: ⚡️ Update ci conditions
SergioGasquez Mar 10, 2023
ec2ae14
docs: 🐛 Remove installing target
SergioGasquez Mar 10, 2023
2acc023
docs: 📝 Update Hello, board section
SergioGasquez Mar 10, 2023
b3b7f78
docs: 🔥 Remove readme
SergioGasquez Mar 10, 2023
1a0dbcf
docs: 📝 Add intro chapter
SergioGasquez Mar 10, 2023
48d1c57
build: ➖ Remove esp32c3 crate
SergioGasquez Mar 10, 2023
d4f440c
style: ⚡️ Remove unnecesary mut
SergioGasquez Mar 10, 2023
546ce65
build: ➖ Remove unneded crates
SergioGasquez Mar 10, 2023
d67bfb4
docs: 📝 Update project organization
SergioGasquez Mar 10, 2023
7c4f5e1
docs: 📝 Update cargo-generate chapter
SergioGasquez Mar 10, 2023
dad4659
docs: 📝 Update instructions
SergioGasquez Mar 10, 2023
3db867b
style: 🎨 Format logs
SergioGasquez Mar 10, 2023
6a5851c
style: 🎨 Format logs
SergioGasquez Mar 10, 2023
379b7fd
docs: 📝 Update execise content
SergioGasquez Mar 10, 2023
943abc6
docs: 📝 Update https client instructions
SergioGasquez Mar 10, 2023
d92c798
docs: 🎨 Format code snipets md lang
SergioGasquez Mar 10, 2023
9f7ef54
docs: 📝 Remove todo
SergioGasquez Mar 10, 2023
caa3952
docs: 🎨 Remove $ from console logs where its not needed
SergioGasquez Mar 10, 2023
c9c53ec
docs: 🎨 Format summary
SergioGasquez Mar 10, 2023
907852e
docs: 🐛 Fix links
SergioGasquez Mar 10, 2023
947b1a6
chore: 🔥 Remove unused md file
SergioGasquez Mar 10, 2023
07e8918
feat: ✨ Update http server instructions
SergioGasquez Mar 10, 2023
37a88ff
docs: 📝 Update initial mqtt chapters
SergioGasquez Mar 10, 2023
d93bd33
docs: 📝 Add todo
SergioGasquez Mar 10, 2023
a0363cc
docs: 🎨 Update mqtt instructions
SergioGasquez Mar 10, 2023
41bea6a
docs: 🎨 Remove unused mark
SergioGasquez Mar 10, 2023
d08b879
docs: ✨ Introduce hint mark
SergioGasquez Mar 10, 2023
93fa8c5
docs: ✨ Update warning mark
SergioGasquez Mar 10, 2023
bc24856
docs: 📝 Add rust on esp reference
SergioGasquez Mar 10, 2023
80948fd
docs: 📝 Update mqtt part 2 instructions
SergioGasquez Mar 10, 2023
b82a6ba
chore: 🎨 Format log prints
SergioGasquez Mar 10, 2023
18df2b7
docs: 🎨 LanguageTool suggestions
SergioGasquez Mar 10, 2023
6855416
docs: 🎨 Standarize titles
SergioGasquez Mar 13, 2023
fed8911
docs: 📝 Add marks
SergioGasquez Mar 13, 2023
050ef75
docs: 📝 Update format and LT suggestions
SergioGasquez Mar 13, 2023
0f2f218
docs: 🎨 Format ESP-IDF naming
SergioGasquez Mar 13, 2023
86d53e2
docs: 📝 Update LowLevel chapter
SergioGasquez Mar 13, 2023
124ce50
docs: 📝 Update i2c chapter
SergioGasquez Mar 13, 2023
2a7c6ad
docs: 📝 Update part 1 instructions
SergioGasquez Mar 13, 2023
92f3c57
docs: 📝 Update part 2 instructions
SergioGasquez Mar 13, 2023
5cd672e
Remove local imc42670 crate
SergioGasquez Mar 13, 2023
18699a1
build: ⬆️ Update crates versions
SergioGasquez Mar 13, 2023
8fe4c2b
docs: 📝 Update datasheet links
SergioGasquez Mar 13, 2023
cd38232
docs: 📝 Update easy version instructions
SergioGasquez Mar 13, 2023
a31e5ca
docs: 📝 Update docstrings
SergioGasquez Mar 13, 2023
1f94ee7
docs: 📝 Update i2c-driver hard version
SergioGasquez Mar 13, 2023
7b4861f
style: 🎨 Rename i2c exercises in cargo.toml
SergioGasquez Mar 13, 2023
9c05ddf
docs: 📝 LanguageTool suggestions
SergioGasquez Mar 13, 2023
decfa5a
docs: 📝 LanguageTool suggestions
SergioGasquez Mar 13, 2023
0aea237
docs: 📝 Fix tyoi
SergioGasquez Mar 13, 2023
9840dee
docs: 📝 Update interrup instructions
SergioGasquez Mar 13, 2023
4a999d6
docs: 📝 Update interrup instructions
SergioGasquez Mar 13, 2023
6d5ed00
docs: 📝 Update reference chapter
SergioGasquez Mar 13, 2023
1db50f8
docs: 📝 LanguageTool warnings
SergioGasquez Mar 13, 2023
68a62e7
feat: ✨ Add rgb-led crate
SergioGasquez Mar 13, 2023
d61198f
feat: ✨ Add wifi crate
SergioGasquez Mar 13, 2023
e28ede8
feat: 🔥 Remove bsc
SergioGasquez Mar 13, 2023
3ec3448
feat: ✨ Remove bsc crate
SergioGasquez Mar 13, 2023
cf41dc9
feat: ✨ Update examples to use rgb_led and wifi crates
SergioGasquez Mar 13, 2023
8c6e071
fix: 🐛 Update crates path
SergioGasquez Mar 13, 2023
a15ac27
docs: 📝 Update advanced readme
SergioGasquez Mar 13, 2023
30d9e9d
docs: 📝 Update docstring
SergioGasquez Mar 13, 2023
7a1e3e3
docs: 📝 Remove Windows note
SergioGasquez Mar 13, 2023
213455d
docs: ⚡️ Remove TODOs
SergioGasquez Mar 13, 2023
e8fd6b2
Merge remote-tracking branch 'upstream/main' into feature/crates-update
SergioGasquez Mar 13, 2023
18767b0
build: 🐛 Fix dependencies
SergioGasquez Mar 13, 2023
cec1278
chore: 📝 Update authors
SergioGasquez Mar 14, 2023
27f42c1
docs: 🎨 Format comments
SergioGasquez Mar 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FROM debian:bullseye-slim
ENV DEBIAN_FRONTEND=noninteractive
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
ARG NIGHTLY_VERSION=nightly-2022-03-10
ARG NIGHTLY_VERSION=nightly-2023-02-28
ARG ESP_IDF_VERSION=v4.4.1
ARG ESP_BOARD=esp32c3

Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"build": {
"dockerfile": "Dockerfile",
"args": {
"NIGHTLY_VERSION": "nightly-2022-03-10"
"NIGHTLY_VERSION": "nightly-2023-02-28"
}
},
"settings": {
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
name: CI

on:
push: {}
push:
paths-ignore:
- "book/"
- "book/**"
pull_request:
branches: [main]
paths-ignore:
Expand Down
2 changes: 1 addition & 1 deletion .gitpod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
ARG CONTAINER_USER=gitpod
ARG CONTAINER_GROUP=gitpod
ARG NIGHTLY_VERSION=nightly-2022-03-10
ARG NIGHTLY_VERSION=nightly-2023-02-28
ARG ESP_IDF_VERSION=v4.4.1
ARG ESP_BOARD=esp32c3
RUN sudo install-packages git curl gcc clang ninja-build libudev-dev \
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ There is:
* GPIO/Button Interrupts ([Source](./advanced/button-interrupt))
* Driving an RGB LED
* Some useful common crates:
* [`esp32-c3-dkc02-bsc`](./common/lib/esp32-c3-dkc02-bsc) - Board-Support for the ESP32-C3-DKC02
* [`get-uuid`](./common/lib/get-uuid) - provides a compile-time generated UUID
* [`get-uuid`](./common/lib/get-uuid) - Provides a compile-time generated UUID
* [`mqtt-messages`](./common/lib/mqtt-messages) - MQTT helper functions
* [`icm42670p`](./common/lib/icm42670p) - basic sensor driver
* [`rgb-led`](./common/lib/rgb-led) - Provides support for the RGB LED (WS2812)
* [`wifi`](./common/lib/wifi) - Wifi helper functions
* Some extra bits:
* [`mqtt-python-client`](./extra/mqtt-python-client) A Python MQTT client, for testing

Expand Down
17 changes: 9 additions & 8 deletions advanced/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ Folders are listed in alphabetical order, not in the order they are taught in th

## Button Interrupt

`button-interrupt/exercise/src/main.rs` contains the project code skeleton
`button-interrupt/solution/src/main.rs` contains the solution for the first step of the exercise.
`button-interrupt/solution/src/main_led.rs` contains the solution for the second step of the exercise.
[`button-interrupt/exercise/src/main.rs`](button-interrupt/src/main.rs) contains the project code skeleton
[`button-interrupt/examples/solution.rs`](button-interrupt/examples/solution.rs) contains the solution for the first step of the exercise.
[`button-interrupt/examples/solution_led.rs`]((button-interrupt/examples/solution_led.rs) ) contains the solution for the second step of the exercise.
## I2C Driver exercise (WIP)

`i2c-driver/exercise/src/icm42670p.rs` will be gap text of a very basic i2c IMU sensor driver. The task is to complete the file, so that running `main.rs` will log the device ID of the driver. The this gap text driver is based on the version of the same name that lives in common, but provides a little bit more functionality.
[`i2c-driver/exercise/src/icm42670p.rs`](i2c-driver/src/icm42670p.rs) will be gap text of a very basic i2c IMU sensor driver. The task is to complete the file, so that running `main.rs` will log the device ID of the driver. The this gap text driver is based on the version of the same name that lives in common, but provides a little bit more functionality.

`i2c-driver/exercise/src/main.rs` will contain working code. Running it without modifying the driver file will yield errors.
[`i2c-driver/exercise/src/main.rs`](i2c-driver/src/main.rs) will contain working code. Running it without modifying the driver file will yield errors.

`i2c-driver/solution/src/icm42670p.rs` provides a solution to the task.
[`i2c-driver/exercise/src/icm42670p_solution.rs`](i2c-driver/src/icm42670p_solution.rs) provides a solution to the task.

## I2C Sensor Reading Exercise (WIP)

`i2c-sensor-reading/exercise/src/main.rs` will be an exercise skeleton that will build. The task is to use an existing driver from crates.io to read out the temperature and humidity sensor over i2c. After that, a second sensor will be read out over the same i2c bus using `shared-bus`. The driver for the second sensor is available locally in `common/`.
[`i2c-sensor-reading/src/main.rs`](i2c-sensor-reading/src/main.rs) will be an exercise skeleton that will build. The task is to use an existing driver from crates.io to read out the temperature and humidity sensor over i2c. After that, a second sensor will be read out over the same i2c bus using `shared-bus`.

`i2c-sensor-reading/solution/src/main.rs` contains a working solution.
`i2c-sensor-reading/examples/part_1.rs` contains a working solution for Part 1.
`i2c-sensor-reading/examples/part_2.rs` contains a working solution for Part 2.

19 changes: 12 additions & 7 deletions advanced/button-interrupt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
[package]
name = "button-interrupt"
version = "0.1.0"
authors = ["Anatol Ulrich <anatol.ulrich@ferrous-systems.com>", "Tanks Transfeld <tanks.transfeld@ferrous-systems.com>"]
authors = [
"Anatol Ulrich <anatol.ulrich@ferrous-systems.com>",
"Tanks Transfeld <tanks.transfeld@ferrous-systems.com>",
"Sergio Gasquez <sergio.gasquez@gmail.com>",
]
edition = "2021"
resolver = "2"

[profile.release]
opt-level = "s"

[profile.dev]
debug = true # Symbols are nice and they don't increase the size on Flash
debug = true # Symbols are nice and they don't increase the size on Flash
opt-level = "z"

[features]
default = ["native"]
native = ["esp-idf-sys/native"]

[dependencies]
esp-idf-sys = { version = "=0.31.5", features = ["binstart"] }
anyhow = "1"
esp32-c3-dkc02-bsc = { path = "../../common/lib/esp32-c3-dkc02-bsc" }
esp-idf-sys = { version = "=0.32.1", features = ["binstart"] }
anyhow = "=1.0.69"
rgb-led = { path = "../../common/lib/rgb-led" }
esp-idf-hal = "=0.40.1"

[build-dependencies]
embuild = "0.28"
anyhow = "1"
embuild = "=0.31.0"
anyhow = "=1.0.69"
1 change: 0 additions & 1 deletion advanced/button-interrupt/README.md

This file was deleted.

31 changes: 15 additions & 16 deletions advanced/button-interrupt/examples/solution.rs
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
// reference:
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/freertos.html

use std::ptr;

use anyhow::Result;
use esp_idf_sys::{
c_types::c_void, esp, gpio_config, gpio_config_t, gpio_install_isr_service,
gpio_int_type_t_GPIO_INTR_POSEDGE, gpio_isr_handler_add, gpio_mode_t_GPIO_MODE_INPUT,
xQueueGenericCreate, xQueueGiveFromISR, xQueueReceive, QueueHandle_t,ESP_INTR_FLAG_IRAM,
esp, gpio_config, gpio_config_t, gpio_install_isr_service, gpio_int_type_t_GPIO_INTR_POSEDGE,
gpio_isr_handler_add, gpio_mode_t_GPIO_MODE_INPUT, xQueueGenericCreate, xQueueGiveFromISR,
xQueueReceive, QueueHandle_t, ESP_INTR_FLAG_IRAM,
};
use std::ptr;

// This `static mut` holds the queue handle we are going to get from `xQueueGenericCreate`.
// This is unsafe, but we are careful not to enable our GPIO interrupt handler until after this value has been initialised, and then never modify it again
static mut EVENT_QUEUE: Option<QueueHandle_t> = None;

#[link_section = ".iram0.text"]
unsafe extern "C" fn button_interrupt(_: *mut c_void) {
unsafe extern "C" fn button_interrupt(_: *mut core::ffi::c_void) {
xQueueGiveFromISR(EVENT_QUEUE.unwrap(), std::ptr::null_mut());
}

fn main() -> anyhow::Result<()> {
fn main() -> Result<()> {
const GPIO_NUM: i32 = 9;

// Configures the button
let io_conf = gpio_config_t {
pin_bit_mask: 1 << GPIO_NUM,
mode: gpio_mode_t_GPIO_MODE_INPUT,
pull_up_en: true.into(),
pull_down_en: false.into(),
intr_type: gpio_int_type_t_GPIO_INTR_POSEDGE, // positive edge trigger = button down
intr_type: gpio_int_type_t_GPIO_INTR_POSEDGE, // Positive edge trigger = button down
};

// Queue configurations
const QUEUE_TYPE_BASE: u8 = 0;
const ITEM_SIZE: u32 = 0; // we're not posting any actual data, just notifying
const ITEM_SIZE: u32 = 0; // We're not posting any actual data, just notifying
const QUEUE_SIZE: u32 = 1;

unsafe {
// Writes the button configuration to the registers
esp!(gpio_config(&io_conf))?;


// Installs the generic GPIO interrupt handler
esp!(gpio_install_isr_service(ESP_INTR_FLAG_IRAM as i32))?;

Expand All @@ -57,16 +56,16 @@ fn main() -> anyhow::Result<()> {
// Reads the queue in a loop.
loop {
unsafe {
// maximum delay
// Maximum delay
const QUEUE_WAIT_TICKS: u32 = 1000;

// Reads the event item out of the queue
let res = xQueueReceive(EVENT_QUEUE.unwrap(), ptr::null_mut(), QUEUE_WAIT_TICKS);
// If the event has the value 0, nothing happens. if it has a different value, the button was pressed.

// If the event has the value 0, nothing happens. if it has a different value, the button was pressed.
match res {
1 => println!("button pressed!"),
_ => {},
1 => println!("Button pressed!"),
_ => {}
};
}
}
Expand Down
44 changes: 21 additions & 23 deletions advanced/button-interrupt/examples/solution_led.rs
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
// reference:
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/freertos.html

use std::ptr;
use esp32_c3_dkc02_bsc as bsc;
use bsc::led::{RGB8, WS2812RMT};

use anyhow::Result;
use esp_idf_hal::prelude::Peripherals;
use esp_idf_sys::{
c_types::c_void, esp, gpio_config, gpio_config_t, gpio_install_isr_service,
esp, esp_random, gpio_config, gpio_config_t, gpio_install_isr_service,
gpio_int_type_t_GPIO_INTR_POSEDGE, gpio_isr_handler_add, gpio_mode_t_GPIO_MODE_INPUT,
xQueueGenericCreate, xQueueGiveFromISR, xQueueReceive, QueueHandle_t,ESP_INTR_FLAG_IRAM, esp_random,
xQueueGenericCreate, xQueueGiveFromISR, xQueueReceive, QueueHandle_t, ESP_INTR_FLAG_IRAM,
};
use rgb_led::{RGB8, WS2812RMT};
use std::ptr;

// This `static mut` holds the queue handle we are going to get from `xQueueGenericCreate`.
// This is unsafe, but we are careful not to enable our GPIO interrupt handler until after this value has been initialised, and then never modify it again
static mut EVENT_QUEUE: Option<QueueHandle_t> = None;

#[link_section = ".iram0.text"]
unsafe extern "C" fn button_interrupt(_: *mut c_void) {
unsafe extern "C" fn button_interrupt(_: *mut core::ffi::c_void) {
xQueueGiveFromISR(EVENT_QUEUE.unwrap(), std::ptr::null_mut());
}

fn main() -> anyhow::Result<()> {
fn main() -> Result<()> {
let peripherals = Peripherals::take().unwrap();

let mut led = WS2812RMT::new()?;
let mut led = WS2812RMT::new(peripherals.pins.gpio2, peripherals.rmt.channel0)?;
const GPIO_NUM: i32 = 9;

// Configures the button
let io_conf = gpio_config_t {
pin_bit_mask: 1 << GPIO_NUM,
mode: gpio_mode_t_GPIO_MODE_INPUT,
pull_up_en: true.into(),
pull_down_en: false.into(),
intr_type: gpio_int_type_t_GPIO_INTR_POSEDGE, // positive edge trigger = button down
intr_type: gpio_int_type_t_GPIO_INTR_POSEDGE, // Positive edge trigger = button down
};

// Queue configurations
const QUEUE_TYPE_BASE: u8 = 0;
const ITEM_SIZE: u32 = 0; // we're not posting any actual data, just notifying
const ITEM_SIZE: u32 = 0; // We're not posting any actual data, just notifying
const QUEUE_SIZE: u32 = 1;

unsafe {
// Writes the button configuration to the registers
esp!(gpio_config(&io_conf))?;


// Installs the generic GPIO interrupt handler
esp!(gpio_install_isr_service(ESP_INTR_FLAG_IRAM as i32))?;

Expand All @@ -60,24 +60,22 @@ fn main() -> anyhow::Result<()> {

// Reads the queue in a loop.
loop {


unsafe {
// maximum delay
// Maximum delay
const QUEUE_WAIT_TICKS: u32 = 1000;

// Reads the event item out of the queue
let res = xQueueReceive(EVENT_QUEUE.unwrap(), ptr::null_mut(), QUEUE_WAIT_TICKS);
// If the event has the value 0, nothing happens. if it has a different value, the button was pressed.
// If the button was pressed, a function that changes the state of the LED is called.

// If the event has the value 0, nothing happens. if it has a different value, the button was pressed.
// If the button was pressed, a function that changes the state of the LED is called.

match res {
1 => {
// Generates random rgb values and sets them in the led.
random_light(&mut led);
},
_ => {},
}
_ => {}
};
}
}
Expand All @@ -93,6 +91,6 @@ fn random_light(led: &mut WS2812RMT) {

color = RGB8::new(r, g, b);
}

led.set_pixel(color).unwrap();
}
5 changes: 1 addition & 4 deletions advanced/button-interrupt/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
[toolchain]


channel = "nightly-2022-03-10"

channel = "nightly-2023-02-28"
34 changes: 15 additions & 19 deletions advanced/button-interrupt/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,65 +1,61 @@
// reference:
// Reference:
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/freertos.html
use std::ptr;

use anyhow::Result;
use esp_idf_sys::{
c_types::c_void, esp, gpio_config, gpio_config_t, gpio_install_isr_service,
esp, esp_random, gpio_config, gpio_config_t, gpio_install_isr_service,
gpio_int_type_t_GPIO_INTR_POSEDGE, gpio_isr_handler_add, gpio_mode_t_GPIO_MODE_INPUT,
xQueueGenericCreate, xQueueGiveFromISR, xQueueReceive, QueueHandle_t,ESP_INTR_FLAG_IRAM, esp_random,
xQueueGenericCreate, xQueueGiveFromISR, xQueueReceive, QueueHandle_t, ESP_INTR_FLAG_IRAM,
};
use std::ptr;

// These imports are needed for part 2.
use esp32_c3_dkc02_bsc as bsc;
use bsc::led::{RGB8, WS2812RMT};
use rgb_led::{RGB8, WS2812RMT};

// 4. Create a `static mut` that holds the queue handle.
static mut EVENT_QUEUE: Option<QueueHandle_t> = None;

// 6. Define what the interrupt handler does, once the button is pushed. Button_interrupt sends a message into the queue.
// 6. Define what the interrupt handler does, once the button is pushed. Button_interrupt sends a message into the queue.
#[link_section = ".iram0.text"]
unsafe extern "C" fn button_interrupt(_: *mut c_void) {
unsafe extern "C" fn button_interrupt(_: *mut core::ffi::c_void) {
xQueueGiveFromISR(EVENT_QUEUE.unwrap(), std::ptr::null_mut());
}

fn main() -> anyhow::Result<()> {
fn main() -> Result<()> {
const GPIO_NUM: i32 = 9;

// 1. Add GPIO configuration c struct
// 1. Add GPIO configuration C struct
// let io_conf = gpio_config_t {
// ...
// };

unsafe {

// 2. write the GPIO configuration into the register
// 2. Write the GPIO configuration into the register
// esp!(...)?;


// 3. Install the global GPIO interrupt handler
// esp!(...)?;

// Queue configurations
const QUEUE_TYPE_BASE: u8 = 0;
const ITEM_SIZE: u32 = 0;
const ITEM_SIZE: u32 = 0;
const QUEUE_SIZE: u32 = 1;

// 5. Create an event queue
// EVENT_QUEUE = Some(...);



// 7. Add the button GPIO and the function to the interrupt handler
// esp!(...)?;
}

// The loop in main waits until it gets a message through the rx ("receiver") part of the channel
loop {
unsafe {
// maximum delay
// Maximum delay
const QUEUE_WAIT_TICKS: u32 = 1000;;

// 8. Receive the event from the queue.
// let res = ...;

// 9. Handle the value of res.
// ...
}
Expand Down
Loading