Skip to content

Commit

Permalink
DMA optimization and refactoring (#67)
Browse files Browse the repository at this point in the history
* optimized DMA
* refactor code and remove duplicated code in many targets
* esp32-devkit-rust - decrease freq for reading IMU, because of interference on clock pin
  • Loading branch information
georgik committed Nov 23, 2023
1 parent bce0bc0 commit 743616f
Show file tree
Hide file tree
Showing 49 changed files with 569 additions and 1,530 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The ghost can find artifact "Walker" which allows him to pass throght the wall f
The ghost can use dynamite to clear wall in the vicinity. The ghost can use also Teleport spell to move to random place in the maze.
The Teleport spell requires some time to recharge. There are some not friendly spirits running around the maze, when collision occurs the ghost is teleported and loses five coins which are then send randomly back to the maze.

![Spooky on ESP32-S3-BOX](assets/screenshot/esp32-spooky-s3-box.jpg)
![Spooky on ESP32-S2-Kaluga](assets/screenshot/esp32-spooky-s2-kaluga.jpg)

### Creating similar custom ESP32 app from a template

Expand Down
Binary file added assets/screenshot/esp32-spooky-s2-kaluga.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 2 additions & 19 deletions esp-wrover-kit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spooky-wrover-kit"
version = "0.8.0"
version = "0.9.0"
authors = ["Juraj Michálek <juraj.michalek@gmail.com>"]
edition = "2021"
license = "MIT"
Expand All @@ -18,29 +18,12 @@ esp-println = { version = "0.7.0", features = ["esp32"] }
[dependencies]
esp-alloc = "0.3.0"
embedded-graphics = "0.8.0"
embedded-graphics-framebuf = { version = "0.3.0", git = "https://github.com/georgik/embedded-graphics-framebuf.git", branch = "feature/embedded-graphics-0.8" }
embedded-hal = "0.2"
display-interface = "0.4"
display-interface-spi = "0.4"
mipidsi = "0.7.1"
panic-halt = "0.2"
shared-bus = { version = "0.3.0" }
spooky-core = { path = "../spooky-core", default-features = false, features = [ "static_maze" ] }
spooky-embedded = { path = "../spooky-embedded", default-features = false, features = [ "static_maze" ] }
spooky-embedded = { path = "../spooky-embedded", default-features = false, features = [ "esp32", "static_maze", "resolution_320x240" ] }
spi-dma-displayinterface = { path = "../spi-dma-displayinterface", features = [ "esp32" ] }

[features]
default = [ "esp_wrover_kit" ]

system_timer = []

button_controls = []
imu_controls = []

esp32 = []
esp32s2 = ["system_timer"]
esp32s3 = []
esp32c3 = ["system_timer"]

# Enable this feature in case you have an ESP32 Wrover Kit with ILI9341
esp_wrover_kit = [ "esp32" ]
47 changes: 0 additions & 47 deletions esp-wrover-kit/src/app.rs

This file was deleted.

24 changes: 14 additions & 10 deletions esp-wrover-kit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#[global_allocator]
static ALLOCATOR: esp_alloc::EspHeap = esp_alloc::EspHeap::empty();

// use display_interface_spi::SPIInterfaceNoCS;
use spi_dma_displayinterface::spi_dma_displayinterface::SPIInterfaceNoCS;
use spi_dma_displayinterface::spi_dma_displayinterface;

use esp_backtrace as _;
use hal::{psram, prelude::*,
Expand All @@ -28,9 +27,13 @@ use embedded_graphics::{
};

mod setup;
use setup::{setup_button_keyboard, setup_movement_controller};
mod types;
mod app;
use app::app_loop;

use spooky_embedded::{
app::app_loop,
embedded_display::{LCD_H_RES, LCD_V_RES, LCD_MEMORY_SIZE},
};

use crate::types::ConfiguredPins;

Expand All @@ -56,9 +59,6 @@ fn main() -> ! {

let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);

let lcd_h_res = 240;
let lcd_v_res = 320;

let lcd_sclk = io.pins.gpio19;
let lcd_mosi = io.pins.gpio23;
let lcd_miso = io.pins.gpio25;
Expand Down Expand Up @@ -99,10 +99,10 @@ fn main() -> ! {
DmaPriority::Priority0,
));

let di = SPIInterfaceNoCS::new(spi, lcd_dc);
let di = spi_dma_displayinterface::new_no_cs(LCD_MEMORY_SIZE, spi, lcd_dc);

let mut display = match mipidsi::Builder::ili9341_rgb565(di)
.with_display_size(lcd_h_res as u16, lcd_v_res as u16)
.with_display_size(LCD_H_RES, LCD_V_RES)
.with_orientation(mipidsi::Orientation::Landscape(false))
.with_color_order(mipidsi::ColorOrder::Bgr)
.init(&mut delay, Some(lcd_reset)) {
Expand All @@ -122,6 +122,10 @@ fn main() -> ! {
let mut seed_buffer = [1u8; 32];
rng.read(&mut seed_buffer).unwrap();

app_loop(&mut display, lcd_h_res, lcd_v_res, configured_pins, seed_buffer);
let button_keyboard = setup_button_keyboard(configured_pins);

let movement_controller = setup_movement_controller(seed_buffer, button_keyboard);

app_loop(&mut display, seed_buffer, movement_controller);
loop {}
}
2 changes: 1 addition & 1 deletion esp-wrover-kit/src/setup.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::types::ConfiguredPins;
use embedded_hal::digital::v2::InputPin;
use spooky_embedded::{ button_keyboard::ButtonKeyboard, embedded_movement_controller::EmbeddedMovementController };
use spooky_embedded::{ button_keyboard::ButtonKeyboard, controllers::embedded::EmbeddedMovementController };
use spooky_core;

pub fn setup_button_keyboard<Up: InputPin, Down: InputPin, Left: InputPin, Right: InputPin, Dyn: InputPin, Tel: InputPin>(
Expand Down
4 changes: 4 additions & 0 deletions esp32-c3-devkit-rust/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ rustflags = [
"--cfg", 'target_has_atomic="ptr"',
]

[env]
# Use clean build after changing ESP_LOGLEVEL
ESP_LOGLEVEL="DEBUG"

[build]
target = "riscv32imac-unknown-none-elf"

Expand Down
25 changes: 4 additions & 21 deletions esp32-c3-devkit-rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spooky-esp32-c3"
version = "0.8.0"
version = "0.9.0"
authors = ["Juraj Michálek <juraj.michalek@gmail.com>"]
edition = "2021"
license = "MIT"
Expand All @@ -10,35 +10,18 @@ hal = { package = "esp32c3-hal", version = "0.13.0" }
esp-backtrace = { version = "0.9.0", features = [
"esp32c3",
"panic-handler",
"print-rtt",
"print-uart",
] }
esp-println = { version = "0.7.0", default-features = false, features = [ "esp32c3", "rtt" ] }
esp-println = { version = "0.7.0", default-features = false, features = [ "esp32c3", "log" ] }

[dependencies]
esp-alloc = "0.3.0"
embedded-graphics = "0.8.0"
embedded-graphics-framebuf = { version = "0.3.0", git = "https://github.com/georgik/embedded-graphics-framebuf.git", branch = "feature/embedded-graphics-0.8" }
embedded-hal = "0.2"
display-interface = "0.4"
display-interface-spi = "0.4"
icm42670 = { git = "https://github.com/jessebraham/icm42670/" }
mipidsi = "0.7.1"
panic-halt = "0.2"
shared-bus = { version = "0.3.0" }
spooky-core = { path = "../spooky-core", default-features = false, features = ["static_maze"]}
spooky-embedded = { path = "../spooky-embedded", default-features = false, features = [ "static_maze" ] }
spooky-embedded = { path = "../spooky-embedded", default-features = false, features = [ "esp32c3", "static_maze", "resolution_320x240" ] }
spi-dma-displayinterface = { path = "../spi-dma-displayinterface", features = ["esp32c3"] }

[features]
default = [ "esp32c3_ili9341" ]
system_timer = []

button_controls = []
imu_controls = []

esp32 = []
esp32s2 = ["system_timer"]
esp32s3 = []
esp32c3 = ["system_timer"]

esp32c3_ili9341 = [ "esp32c3", "imu_controls" ]
53 changes: 0 additions & 53 deletions esp32-c3-devkit-rust/src/accel_movement_controller.rs

This file was deleted.

42 changes: 0 additions & 42 deletions esp32-c3-devkit-rust/src/app.rs

This file was deleted.

Loading

0 comments on commit 743616f

Please sign in to comment.