Skip to content

Commit

Permalink
Merge pull request #10 from esp-rs/use-current-dependencies
Browse files Browse the repository at this point in the history
Use current dependencies
  • Loading branch information
bjoernQ authored Oct 11, 2024
2 parents e49091c + 300fe3b commit e52cd03
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 63 deletions.
155 changes: 154 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ fn process_file(
} else if trimmed.starts_with("#ENDIF") || trimmed.starts_with("//ENDIF") {
include.pop();
// Trim #+ and //+
} else if *include.last().unwrap() {
} else if include.iter().all(|v| *v) {
let mut line = line.to_string();

if trimmed.starts_with("#+") {
Expand Down Expand Up @@ -431,3 +431,156 @@ fn process_options(args: &Args) {
}
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_nested_if_else1() {
let res = process_file(
"/foo",
r#"
#IF option("opt1")
opt1
#IF option("opt2")
opt2
#ELSE
!opt2
#ENDIF
#ELSE
!opt1
#ENDIF
"#,
&["opt1".to_string(), "opt2".to_string()],
&[],
)
.unwrap();

assert_eq!(
r#"
opt1
opt2
"#
.trim(),
res.trim()
);
}

#[test]
fn test_nested_if_else2() {
let res = process_file(
"/foo",
r#"
#IF option("opt1")
opt1
#IF option("opt2")
opt2
#ELSE
!opt2
#ENDIF
#ELSE
!opt1
#ENDIF
"#,
&[],
&[],
)
.unwrap();

assert_eq!(
r#"
!opt1
"#
.trim(),
res.trim()
);
}

#[test]
fn test_nested_if_else3() {
let res = process_file(
"/foo",
r#"
#IF option("opt1")
opt1
#IF option("opt2")
opt2
#ELSE
!opt2
#ENDIF
#ELSE
!opt1
#ENDIF
"#,
&["opt1".to_string()],
&[],
)
.unwrap();

assert_eq!(
r#"
opt1
!opt2
"#
.trim(),
res.trim()
);
}

#[test]
fn test_nested_if_else4() {
let res = process_file(
"/foo",
r#"
#IF option("opt1")
#IF option("opt2")
opt2
#ELSE
!opt2
#ENDIF
opt1
#ENDIF
"#,
&["opt1".to_string()],
&[],
)
.unwrap();

assert_eq!(
r#"
!opt2
opt1
"#
.trim(),
res.trim()
);
}

#[test]
fn test_nested_if_else5() {
let res = process_file(
"/foo",
r#"
#IF option("opt1")
#IF option("opt2")
opt2
#ELSE
!opt2
#ENDIF
opt1
#ENDIF
"#,
&["opt2".to_string()],
&[],
)
.unwrap();

assert_eq!(
r#"
"#
.trim(),
res.trim()
);
}
}
2 changes: 1 addition & 1 deletion template/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ runner = "probe-rs run --chip=esp32c6"
#IF option("probe-rs")
DEFMT_LOG="info"
#ELSE
ESP_LOGLEVEL="INFO"
ESP_LOG="INFO"
#ENDIF

[build]
Expand Down
5 changes: 5 additions & 0 deletions template/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rust-analyzer.cargo.allTargets": false,
//REPLACE riscv32imac-unknown-none-elf rust_target
"rust-analyzer.cargo.target": "riscv32imac-unknown-none-elf",
}
38 changes: 11 additions & 27 deletions template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ esp-backtrace = { version = "0.14.1", features = [
#ENDIF
]}

esp-hal = { version = "0.20.1", features = [
esp-hal = { version = "0.21.0", features = [
#REPLACE esp32c6 mcu
"esp32c6",
#IF option("probe-rs")
Expand All @@ -26,20 +26,25 @@ esp-hal = { version = "0.20.1", features = [
] }
#IF !option("probe-rs")
#REPLACE esp32c6 mcu
esp-println = { version = "0.11.0", features = ["esp32c6", "log"] }
esp-println = { version = "0.12.0", features = ["esp32c6", "log"] }
log = { version = "0.4.21" }
#ENDIF
#IF option("alloc")
esp-alloc = { version = "0.4.0" }
esp-alloc = { version = "0.5.0" }
#ENDIF
#IF option("wifi")
#IF option("wifi") || option("ble")
embedded-io = "0.6.1"
esp-wifi = { version = "0.9.1", default-features=false, features = [
esp-wifi = { version = "0.10.1", default-features=false, features = [
#REPLACE esp32c6 mcu
"esp32c6",
"phy-enable-usb",
"utils",
#IF option("wifi")
"wifi",
#ENDIF
#IF option("ble")
"ble",
#ENDIF
"esp-alloc",
#IF option("probe-rs")
#+"defmt",
Expand All @@ -62,21 +67,6 @@ smoltcp = { version = "0.11.0", default-features = false, features = [
] }
#ENDIF
#IF option("ble")
#+ embedded-io = "0.6.1"
#+ esp-wifi = { version = "0.9.1", default-features=false, features = [
#REPLACE esp32c6 mcu
#+ "esp32c6",
#+ "phy-enable-usb",
#+ "ble",
#+ "esp-alloc",
#IF option("probe-rs")
#+ #+"defmt",
#ENDIF
#IF !option("probe-rs")
#+ "log",
#ENDIF
#+ ] }
#+ heapless = { version = "0.8.0", default-features = false }
#+ bleps = { git = "https://github.com/bjoernQ/bleps", package = "bleps", rev = "a5148d8ae679e021b78f53fd33afb8bb35d0b62e", features = [ "macros", "async"] }
#ENDIF
#IF option("probe-rs")
Expand All @@ -91,7 +81,7 @@ embassy-executor = { version = "0.6.0", features = [
] }
embassy-time = { version = "0.3.1", features = ["generic-queue-8"] }
#REPLACE esp32c6 mcu
esp-hal-embassy = { version = "0.3.0", features = ["esp32c6"] }
esp-hal-embassy = { version = "0.4.0", features = ["esp32c6"] }
static_cell = { version = "2.1.0", features = ["nightly"] }
#ENDIF

Expand All @@ -108,9 +98,3 @@ incremental = false
lto = 'fat'
opt-level = 's'
overflow-checks = false

[patch.crates-io]
esp-hal = { git = "https://github.com/esp-rs/esp-hal.git", rev = "be82a6521a5859129ca4f98e54e4d4d6cedffe76"}
esp-wifi = { git = "https://github.com/esp-rs/esp-hal.git", rev = "be82a6521a5859129ca4f98e54e4d4d6cedffe76"}
esp-hal-embassy = { git = "https://github.com/esp-rs/esp-hal.git", rev = "be82a6521a5859129ca4f98e54e4d4d6cedffe76"}
esp-alloc = { git = "https://github.com/esp-rs/esp-hal.git", rev = "be82a6521a5859129ca4f98e54e4d4d6cedffe76"}
7 changes: 3 additions & 4 deletions template/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
[toolchain]
#IF option("riscv")
#IF !option("stack-protector")
channel = "stable"
#ENDIF
#IF option("stack-protector")
#+channel = "nightly"
channel = "nightly"
#ELSE
#+channel = "stable"
#ENDIF
components = ["rust-src"]
#REPLACE riscv32imac-unknown-none-elf rust_target
Expand Down
24 changes: 9 additions & 15 deletions template/src/bin/async_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,24 @@ async fn main(spawner: Spawner) {
esp_hal_embassy::init(timg0.timer0);
info!("Embassy initialized!");

//IF option("wifi")
//IF option("wifi") || option("ble")
let peripherals = esp_hal::init(esp_hal::Config::default());

let timg1 = esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG1);
let _init = esp_wifi::initialize(
let _init = esp_wifi::init(
//IF option("wifi")
esp_wifi::EspWifiInitFor::Wifi,
//ENDIF
//IF option("ble")
//+esp_wifi::EspWifiInitFor::Ble,
//ENDIF
timg1.timer0,
esp_hal::rng::Rng::new(peripherals.RNG),
peripherals.RADIO_CLK,
)
.unwrap();
//ENDIF

//IF option("ble")
//+ let peripherals = esp_hal::init(esp_hal::Config::default());
//+
//+ let timg1 = esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG1);
//+ let _init = esp_wifi::initialize(
//+ esp_wifi::EspWifiInitFor::Ble,
//+ timg1.timer0,
//+ esp_hal::rng::Rng::new(peripherals.RNG),
//+ peripherals.RADIO_CLK,
//+ )
//+ .unwrap();
//ENDIF

// TODO: Spawn some tasks
let _ = spawner;

Expand Down
22 changes: 7 additions & 15 deletions template/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,24 @@ fn main() -> ! {
esp_alloc::heap_allocator!(72 * 1024);
//ENDIF

//IF option("wifi")
//IF option("wifi") || option("ble")
let peripherals = esp_hal::init(esp_hal::Config::default());

let timg0 = TimerGroup::new(peripherals.TIMG0);
let _init = esp_wifi::initialize(
let _init = esp_wifi::init(
//IF option("wifi")
esp_wifi::EspWifiInitFor::Wifi,
//ENDIF
//IF option("ble")
//+esp_wifi::EspWifiInitFor::Ble,
//ENDIF
timg0.timer0,
esp_hal::rng::Rng::new(peripherals.RNG),
peripherals.RADIO_CLK,
)
.unwrap();
//ENDIF

//IF option("ble")
//+ let peripherals = esp_hal::init(esp_hal::Config::default());
//+
//+ let timg0 = TimerGroup::new(peripherals.TIMG0);
//+ let _init = esp_wifi::initialize(
//+ esp_wifi::EspWifiInitFor::Ble,
//+ timg0.timer0,
//+ esp_hal::rng::Rng::new(peripherals.RNG),
//+ peripherals.RADIO_CLK,
//+ )
//+ .unwrap();
//ENDIF

let delay = Delay::new();
loop {
info!("Hello world!");
Expand Down

0 comments on commit e52cd03

Please sign in to comment.