Skip to content

Commit dbec2fb

Browse files
committed
update to esp-hal 0.22 and esp-bsp-rs
1 parent 6a2e1ea commit dbec2fb

File tree

5 files changed

+59
-92
lines changed

5 files changed

+59
-92
lines changed

.cargo/config.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
[target.xtensa-esp32s3-none-elf]
22
runner = "espflash flash --monitor"
33

4-
54
[env]
6-
ESP_LOGLEVEL="INFO"
5+
ESP_LOG="INFO"
6+
77
[build]
88
rustflags = [
9-
"-C", "link-arg=-Tlinkall.x",
10-
119
"-C", "link-arg=-nostartfiles",
1210
]
1311

1412
target = "xtensa-esp32s3-none-elf"
1513

1614
[unstable]
17-
build-std = ["core"]
15+
build-std = ["alloc", "core"]

Cargo.toml

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
[package]
22
name = "esp32-conways-game-of-life-rs"
3-
version = "0.4.0"
3+
version = "0.5.0"
44
authors = ["Juraj Michálek <[email protected]>"]
55
edition = "2021"
66
license = "MIT OR Apache-2.0"
77

8+
89
[dependencies]
9-
hal = { package = "esp32s3-hal", version = "0.15.0" }
10-
esp-backtrace = { version = "0.10.0", features = ["esp32s3", "panic-handler", "exception-handler", "print-uart"] }
11-
esp-println = { version = "0.8.0", features = ["esp32s3","log"] }
12-
log = { version = "0.4.18" }
13-
mipidsi = "0.7.1"
14-
embedded-graphics = "0.8.1"
10+
esp-hal = "0.22.0"
11+
esp-backtrace = { version = "0.14.2", features = [
12+
"panic-handler",
13+
"println"
14+
] }
15+
esp-println = { version = "0.12.0", features = [ "log" ] }
16+
log = { version = "0.4.21" }
17+
18+
esp-alloc = "0.5.0"
19+
embedded-graphics = "0.8.0"
20+
embedded-hal = "1.0.0"
21+
mipidsi = "0.8.0"
22+
esp-display-interface-spi-dma = "0.2.0"
23+
esp-bsp = "0.4.0"
1524
embedded-graphics-framebuf = { version = "0.3.0", git = "https://github.com/georgik/embedded-graphics-framebuf.git", branch = "feature/embedded-graphics-0.8" }
16-
display-interface = "0.4.1"
17-
display-interface-spi = "0.4.1"
1825
heapless = "0.8.0"
19-
embedded-dma = "0.2.0"
20-
esp-bsp = { version = "0.1.0" }
21-
esp-display-interface-spi-dma = { git = "https://github.com/georgik/esp-display-interface-spi-dma.git", features = ["esp32s3"] }
26+
27+
28+
[features]
29+
default = [ "esp-hal/esp32s3", "esp-backtrace/esp32s3", "esp-println/esp32s3", "esp32-s3-box-3" ]
30+
31+
esp32-s3-box-3 = [ "esp-bsp/esp32-s3-box-3", "esp-hal/octal-psram" ]

build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("cargo:rustc-link-arg=-Tlinkall.x");
3+
}

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ESP32 Conways Game of Life in Rust
22

3-
Implementation for ESP32-S3-BOX Rust Bare Metal.
3+
Implementation for ESP32-S3-BOX-3 Rust Bare Metal.
44

55
[![Wokwi](https://img.shields.io/endpoint?url=https%3A%2F%2Fwokwi.com%2Fbadge%2Fclick-to-simulate.json)](https://wokwi.com/projects/380370193649185793)
66

src/main.rs

Lines changed: 30 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
11
#![no_std]
22
#![no_main]
33

4+
use esp_bsp::prelude::*;
45
use esp_display_interface_spi_dma::display_interface_spi_dma;
56

6-
use esp_backtrace as _;
7-
use esp_println::println;
8-
use hal::{
9-
clock::{ClockControl, CpuClock},
10-
dma::DmaPriority,
11-
gdma::Gdma,
12-
peripherals::Peripherals,
13-
prelude::*,
14-
spi::{
15-
master::{prelude::*, Spi},
16-
SpiMode,
17-
},
18-
Delay, Rng, IO,
19-
};
20-
217
use embedded_graphics::{
228
mono_font::{ascii::FONT_8X13, MonoTextStyle},
239
pixelcolor::Rgb565,
@@ -27,10 +13,23 @@ use embedded_graphics::{
2713
text::Text,
2814
Drawable,
2915
};
16+
#[allow(unused_imports)]
17+
use esp_backtrace as _;
18+
use esp_hal::gpio::OutputOpenDrain;
19+
use esp_hal::gpio::Pull;
20+
use esp_hal::rng::Rng;
21+
use esp_hal::{
22+
delay::Delay,
23+
dma::Dma,
24+
dma::DmaPriority,
25+
gpio::{Level, Output},
26+
prelude::*,
27+
spi::master::Spi,
28+
};
3029

3130
use embedded_graphics_framebuf::FrameBuf;
32-
33-
use esp_bsp::lcd_gpios;
31+
use embedded_hal::delay::DelayNs;
32+
use log::info;
3433

3534
// Define grid size
3635
const WIDTH: usize = 64;
@@ -68,7 +67,7 @@ fn randomize_grid(rng: &mut Rng, grid: &mut [[bool; WIDTH]; HEIGHT]) {
6867
for cell in row.iter_mut() {
6968
// Read a single byte from the RNG
7069
let mut buf = [0u8; 1];
71-
rng.read(&mut buf).unwrap();
70+
rng.read(&mut buf);
7271

7372
// Set the cell to be alive or dead based on the random byte
7473
*cell = buf[0] & 1 != 0;
@@ -159,64 +158,21 @@ fn draw_grid<D: DrawTarget<Color = Rgb565>>(
159158

160159
#[entry]
161160
fn main() -> ! {
162-
let peripherals = Peripherals::take();
163-
let system = peripherals.SYSTEM.split();
164-
165-
// let clocks = ClockControl::max(system.clock_control).freeze();
166-
let clocks = ClockControl::configure(system.clock_control, CpuClock::Clock240MHz).freeze();
167-
let mut delay = Delay::new(&clocks);
168-
169-
println!("About to initialize the SPI LED driver");
170-
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
171-
let (lcd_sclk, lcd_mosi, lcd_cs, lcd_miso, lcd_dc, mut lcd_backlight, lcd_reset) =
172-
lcd_gpios!(BoardType::ESP32S3Box, io);
173-
174-
let dma = Gdma::new(peripherals.DMA);
175-
let dma_channel = dma.channel0;
176-
177-
let mut descriptors = [0u32; 8 * 3];
178-
let mut rx_descriptors = [0u32; 8 * 3];
179-
180-
let spi = Spi::new(peripherals.SPI2, 40u32.MHz(), SpiMode::Mode0, &clocks)
181-
.with_pins(Some(lcd_sclk), Some(lcd_mosi), Some(lcd_miso), Some(lcd_cs))
182-
.with_dma(dma_channel.configure(
183-
false,
184-
&mut descriptors,
185-
&mut rx_descriptors,
186-
DmaPriority::Priority0,
187-
));
188-
189-
println!("SPI ready");
190-
191-
let di = display_interface_spi_dma::new_no_cs(320 * 240 * 2, spi, lcd_dc);
192-
193-
// ESP32-S3-BOX display initialization workaround: Wait for the display to power up.
194-
// If delay is 250ms, picture will be fuzzy.
195-
// If there is no delay, display is blank
196-
delay.delay_ms(500u32);
197-
198-
let mut display = match mipidsi::Builder::ili9342c_rgb565(di)
199-
.with_display_size(320, 240)
200-
.with_orientation(mipidsi::Orientation::PortraitInverted(false))
201-
.with_color_order(mipidsi::ColorOrder::Bgr)
202-
.init(&mut delay, Some(lcd_reset))
203-
{
204-
Ok(display) => display,
205-
Err(_e) => {
206-
// Handle the error and possibly exit the application
207-
panic!("Display initialization failed");
208-
}
209-
};
161+
const LCD_MEMORY_SIZE: usize = 320 * 240 * 2;
162+
let peripherals = esp_hal::init(esp_hal::Config::default());
163+
esp_println::logger::init_logger_from_env();
210164

211-
let _ = lcd_backlight.set_high();
165+
let spi = lcd_spi!(peripherals);
166+
let di = lcd_display_interface!(peripherals, spi);
167+
let mut delay = Delay::new();
168+
delay.delay_ns(500_000u32);
212169

213-
// setup logger
214-
// To change the log_level change the env section in .cargo/config.toml
215-
// or remove it and set ESP_LOGLEVEL manually before running cargo run
216-
// this requires a clean rebuild because of https://github.com/rust-lang/cargo/issues/10358
217-
esp_println::logger::init_logger_from_env();
218-
log::info!("Logger is setup");
219-
println!("Hello Conway!");
170+
let mut display = lcd_display!(peripherals, di).init(&mut delay).unwrap();
171+
172+
// Use the `lcd_backlight_init` macro to turn on the backlight
173+
lcd_backlight_init!(peripherals);
174+
175+
info!("Hello Conway!");
220176

221177
let mut grid: [[bool; WIDTH]; HEIGHT] = [[false; WIDTH]; HEIGHT];
222178
let mut rng = Rng::new(peripherals.RNG);

0 commit comments

Comments
 (0)