Skip to content

Commit 007908e

Browse files
committed
update to esp-hal 1.0.0 beta
1 parent 156bea0 commit 007908e

File tree

3 files changed

+97
-29
lines changed

3 files changed

+97
-29
lines changed

.cargo/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ runner = "espflash flash --monitor"
33

44
[env]
55
ESP_LOG="INFO"
6+
ESP_HAL_CONFIG_PSRAM_MODE = "octal"
67

78
[build]
89
rustflags = [

Cargo.toml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,27 @@ license = "MIT OR Apache-2.0"
77

88

99
[dependencies]
10-
esp-hal = "0.23.1"
11-
esp-backtrace = { version = "0.15.0", features = [
10+
esp-hal = { version = "1.0.0-beta.0", features = ["esp32s3", "unstable"] }
11+
esp-backtrace = { version = "0.15.1", features = [
1212
"panic-handler",
1313
"println"
1414
] }
15-
esp-println = { version = "0.13.0", features = [ "log" ] }
16-
log = { version = "0.4.21" }
15+
esp-println = { version = "0.13", features = [ "log" ] }
16+
log = { version = "0.4.26" }
1717

18-
esp-alloc = "0.6.0"
19-
embedded-graphics = "0.8.0"
18+
esp-alloc = "0.7.0"
19+
embedded-graphics = "0.8.1"
2020
embedded-hal = "1.0.0"
2121
mipidsi = "0.9.0"
2222
#esp-display-interface-spi-dma = "0.3.0"
23-
esp-display-interface-spi-dma = { path = "../esp-display-interface-spi-dma"}
23+
# esp-display-interface-spi-dma = { path = "../esp-display-interface-spi-dma"}
2424
esp-bsp = "0.4.1"
2525
embedded-graphics-framebuf = { version = "0.3.0", git = "https://github.com/georgik/embedded-graphics-framebuf.git", branch = "feature/embedded-graphics-0.8" }
2626
heapless = "0.8.0"
27+
embedded-hal-bus = "0.3.0"
2728

2829

2930
[features]
3031
default = [ "esp-hal/esp32s3", "esp-backtrace/esp32s3", "esp-println/esp32s3", "esp32-s3-box-3" ]
3132

32-
esp32-s3-box-3 = [ "esp-bsp/esp32-s3-box-3", "esp-hal/octal-psram" ]
33+
esp32-s3-box-3 = [ "esp-bsp/esp32-s3-box-3", "esp-hal/psram" ]

src/main.rs

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

4-
use esp_bsp::prelude::*;
5-
use esp_display_interface_spi_dma::display_interface_spi_dma;
6-
4+
// use esp_bsp::prelude::*;
5+
// use esp_display_interface_spi_dma::display_interface_spi_dma;
6+
use embedded_hal_bus::spi::ExclusiveDevice;
77
use embedded_graphics::{
88
mono_font::{ascii::FONT_8X13, MonoTextStyle},
99
pixelcolor::Rgb565,
@@ -15,18 +15,17 @@ use embedded_graphics::{
1515
};
1616
#[allow(unused_imports)]
1717
use esp_backtrace as _;
18-
use esp_hal::gpio::OutputOpenDrain;
19-
use esp_hal::gpio::Pull;
18+
// use esp_hal::gpio::OutputOpenDrain;
2019
use esp_hal::rng::Rng;
2120
use esp_hal::{
2221
delay::Delay,
23-
dma::DmaPriority,
24-
gpio::{Level, Output},
22+
gpio::{Level, Output, OutputConfig, DriveMode},
2523
spi::master::Spi,
26-
main
24+
main,
25+
time::Rate,
2726
};
28-
29-
use embedded_graphics_framebuf::FrameBuf;
27+
use mipidsi::interface::SpiInterface;
28+
// use embedded_graphics_framebuf::FrameBuf;
3029
use embedded_hal::delay::DelayNs;
3130
use log::info;
3231

@@ -37,8 +36,10 @@ const HEIGHT: usize = 48;
3736
const RESET_AFTER_GENERATIONS: usize = 500;
3837

3938
use core::fmt::Write;
40-
39+
// use esp_hal::dma::Owner::Dma;
40+
use esp_hal::spi::Mode;
4141
use heapless::String;
42+
use mipidsi::{models::ILI9486Rgb565, Builder};
4243

4344
fn write_generation<D: DrawTarget<Color = Rgb565>>(
4445
display: &mut D,
@@ -160,15 +161,70 @@ fn main() -> ! {
160161
let peripherals = esp_hal::init(esp_hal::Config::default());
161162
esp_println::logger::init_logger_from_env();
162163

163-
let spi = lcd_spi!(peripherals);
164-
let di = lcd_display_interface!(peripherals, spi);
164+
// let spi = lcd_spi!(peripherals);
165+
let spi = Spi::new(
166+
peripherals.SPI2,
167+
esp_hal::spi::master::Config::default()
168+
.with_frequency(Rate::from_mhz(40))
169+
.with_mode(Mode::_0),
170+
)
171+
.unwrap()
172+
.with_sck(peripherals.GPIO7)
173+
.with_mosi(peripherals.GPIO6)
174+
// .with_cs((peripherals.GPIO5))
175+
;
176+
// .with_dma((peripherals.DMA_CH0));
177+
// let mut spi = Spi::new(
178+
// peripherals.SPI2,
179+
// esp_hal::spi::master::Config::default()
180+
// .with_frequency(100.kHz())
181+
// .with_mode(Mode::_0),
182+
// )
183+
// .unwrap()
184+
// .with_sck(sclk)
185+
// .with_miso(miso)
186+
// .with_mosi(mosi)
187+
// .with_cs(cs)
188+
// .with_dma(peripherals.DMA_CH0);
189+
190+
// let di = lcd_display_interface!(peripherals, spi);
191+
// let lcd_dc = Output::new($dc_pin, Level::Low);
192+
let mut buffer = [0_u8; 512];
193+
194+
let lcd_dc = Output::new(peripherals.GPIO4, Level::Low, OutputConfig::default());
195+
// Define the display interface with no chip select
196+
let cs_output = Output::new(peripherals.GPIO5, Level::High, OutputConfig::default());
197+
let spi_device = ExclusiveDevice::new_no_delay(spi, cs_output).unwrap();
198+
let di = SpiInterface::new(spi_device, lcd_dc, &mut buffer);
199+
200+
// let di = display_interface_spi_dma::new_no_cs(crate::LCD_MEMORY_SIZE, spi, lcd_dc);
201+
// let di = SpiInterface::new(spi_device, dc, &mut buffer);
202+
// }
165203
let mut delay = Delay::new();
166204
delay.delay_ns(500_000u32);
167205

168-
let mut display = lcd_display!(peripherals, di).init(&mut delay).unwrap();
206+
// let mut display = lcd_display!(peripherals, di).init(&mut delay).unwrap();
207+
// let mut display = mipidsi::Builder::new(mipidsi::models::ILI9342CRgb565, di)
208+
// .display_size((320 as u16), (240 as u16))
209+
// .orientation((mipidsi::options::Orientation::new()
210+
// .flip_vertical()
211+
// .flip_horizontal()
212+
// ))
213+
// .color_order(mipidsi::options::ColorOrder::Bgr)
214+
// .reset_pin(OutputOpenDrain::new(peripherals.GPIO48, Level::High, Pull::Up)
215+
// );
216+
217+
let reset = Output::new(peripherals.GPIO48, Level::High, OutputConfig::default().with_drive_mode(DriveMode::OpenDrain));
218+
219+
let mut display = Builder::new(ILI9486Rgb565, di)
220+
.reset_pin(reset)
221+
.init(&mut delay)
222+
.unwrap();
169223

170224
// Use the `lcd_backlight_init` macro to turn on the backlight
171-
lcd_backlight_init!(peripherals);
225+
let mut backlight = Output::new(peripherals.GPIO47, Level::High, OutputConfig::default());
226+
backlight.set_high();
227+
// lcd_backlight_init!(peripherals);
172228

173229
info!("Hello Conway!");
174230

@@ -181,15 +237,17 @@ fn main() -> ! {
181237
}
182238
let mut generation_count = 0;
183239

184-
let mut data = [Rgb565::BLACK; 320 * 240];
185-
let mut fbuf = FrameBuf::new(&mut data, 320, 240);
240+
// let mut data = [Rgb565::BLACK; 320 * 240];
241+
// let mut fbuf = FrameBuf::new(&mut data, 320, 240);
242+
display.clear(Rgb565::BLACK).unwrap();
186243

187244
loop {
188245
// Update the game state
189246
update_game_of_life(&mut grid);
190247

191248
// Draw the updated grid on the display
192-
draw_grid(&mut fbuf, &grid).unwrap();
249+
// draw_grid(&mut fbuf, &grid).unwrap();
250+
draw_grid(&mut display, &grid).unwrap();
193251

194252
generation_count += 1;
195253

@@ -198,10 +256,18 @@ fn main() -> ! {
198256
generation_count = 0; // Reset the generation counter
199257
}
200258

201-
write_generation(&mut fbuf, generation_count).unwrap();
259+
// write_generation(&mut fbuf, generation_count).unwrap();
260+
write_generation(&mut display, generation_count).unwrap();
261+
262+
// let pixel_iterator = fbuf.into_iter().map(|p| p.1);
263+
// // let _ = display.set_pixels(0, 0, 319, 240, pixel_iterator);
264+
// use mipidsi::interface::InterfacePixelFormat;
265+
266+
// let pixel_iterator = fbuf.into_iter().map(|p| p.1);
267+
268+
// // Send the pixels to the display
269+
// Rgb565::send_pixels(&mut display, pixel_iterator).unwrap();
202270

203-
let pixel_iterator = fbuf.into_iter().map(|p| p.1);
204-
let _ = display.set_pixels(0, 0, 319, 240, pixel_iterator);
205271

206272
// Add a delay to control the simulation speed
207273
delay.delay_ms(100u32);

0 commit comments

Comments
 (0)