Skip to content

Commit 3b05fb8

Browse files
committed
m5stack-atom-s3: add IMU version
1 parent f19ca9a commit 3b05fb8

File tree

5 files changed

+86
-20
lines changed

5 files changed

+86
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CI for ESP32-S3
2+
3+
on:
4+
push:
5+
paths:
6+
- "spooky-maze-m5stack-atom-s3/**"
7+
- "spooky-core/**"
8+
workflow_dispatch:
9+
10+
env:
11+
CARGO_TERM_COLOR: always
12+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13+
14+
jobs:
15+
rust-checks:
16+
name: Rust Checks
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Rust (Xtensa)
24+
uses: esp-rs/[email protected]
25+
with:
26+
default: true
27+
version: '1.85.0'
28+
buildtargets: esp32s3
29+
ldproxy: false
30+
31+
- name: Enable caching
32+
uses: Swatinem/rust-cache@v2
33+
34+
- name: Run checks
35+
working-directory: spooky-maze-m5stack-atom-s3
36+
run: |
37+
38+
# Perform common checks
39+
echo "Running common checks"
40+
cargo fmt --all -- --check --color always
41+
#cargo clippy --release --workspace -- -D warnings
42+
#cargo build --release

README.md

+26-11
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,27 @@ are dispatched to decouple hardware-specific logic from game rules.
1313
View the video [here](https://github.com/user-attachments/assets/28ef7c2b-42cc-4c79-bbdb-fcb0740bf533).
1414
</video>
1515

16-
## Screenshots
17-
18-
### Embedded Version - ESP32-S3-BOX-3
19-
![Spooky Maze Game ESP32-S3-BOX-3](assets/screenshot/spooky-maze-esp32-s3-box-3.webp)
20-
21-
### Desktop Version - macOS
22-
![Spooky Maze Game Desktop](assets/screenshot/spooky-maze-desktop.webp)
2316

2417
## Targets
2518

2619
For now, the project supports two primary targets:
2720

2821
- Desktop Rust Standard Version
2922
Use keyboard controls to move the ghost and trigger actions.
30-
- ESP32-S3-BOX-3 Embedded Version
23+
24+
![Spooky Maze Game Desktop](assets/screenshot/spooky-maze-desktop.webp)
25+
26+
- [ESP32-S3-BOX-3](https://github.com/espressif/esp-box) Embedded Version
3127
Uses an ICM42670 accelerometer for input (tilt the board to move the ghost).
3228

29+
![Spooky Maze Game ESP32-S3-BOX-3](assets/screenshot/spooky-maze-esp32-s3-box-3.webp)
30+
31+
- [M5Stack-Atom-S3](https://docs.m5stack.com/en/core/AtomS3) Embedded Version
32+
Uses an MPU6886 accelerometer for input (tilt the board to move the ghost).
33+
34+
![Spooky Maze Game M5Stack-Atom-S3](assets/screenshot/spooky-maze-m5stack-atom-s3.webp)
35+
36+
3337
Note: For older targets (e.g., ESP32-C3, ESP32-S2, etc.), please refer to the [v0.10.0 tag](https://github.com/georgik/esp32-spooky-maze-game/tree/v0.10.0).
3438

3539
## Key Technical Decisions
@@ -71,7 +75,11 @@ Movement: Arrow keys
7175

7276
### Embedded Version
7377

74-
#### ESP32-S3-BOX-3
78+
#### ESP32-S3
79+
80+
These instructions are valid for boards based on ESP32-S3:
81+
- ESP32-S3-BOX-3
82+
- M5Stack-Atom-S3
7583

7684
Prerequisites:
7785

@@ -95,15 +103,22 @@ source esp-idf/export.sh
95103

96104
Properly configured ESP32-S3-BOX-3 hardware
97105

98-
Build:
106+
Build and run:
99107

108+
- ESP32-S3-BOX-3
100109
```shell
101110
cd spooky-maze-esp32-s3-box-3
102111
cargo run --release
103112
```
113+
- M5Stack-Atom-S3
114+
```shell
115+
cd spooky-maze-m5stack-atom-s3
116+
cargo run --release
117+
```
118+
104119
Controls:
105120

106-
Movement: Tilt the board (using the ICM42670 accelerometer)
121+
Movement: Tilt the board accelerometer
107122

108123
## Differences of Embedded Bevy no_std from Classical Bevy std
109124

spooky-maze-m5stack-atom-s3/src/embedded_systems/player_input.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn dispatch_accelerometer_input<I2C, E>(
3030
dx = if accel.x > 0.0 { step } else { -step };
3131
}
3232
if accel.y.abs() > threshold {
33-
dy = if accel.y > 0.0 { step } else { -step };
33+
dy = if accel.y > 0.0 { -step } else { step };
3434
}
3535
if dx.abs() > f32::EPSILON || dy.abs() > f32::EPSILON {
3636
event_writer.send(PlayerInputEvent { dx, dy });

spooky-maze-m5stack-atom-s3/src/main.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ struct DisplayResource {
115115

116116
use crate::embedded_systems::player_input;
117117
// use crate::embedded_systems::player_input::AccelerometerResource;
118+
use crate::embedded_systems::player_input::AccelerometerResource;
118119
use bevy::platform_support::sync::atomic::AtomicU64;
119120
use bevy::platform_support::time::Instant;
120121
use core::sync::atomic::Ordering;
@@ -123,7 +124,6 @@ use spooky_core::events::npc::NpcCollisionEvent;
123124
use spooky_core::events::walker::WalkerCollisionEvent;
124125
use spooky_core::systems::collisions;
125126
use spooky_core::systems::setup::NoStdTransform;
126-
use crate::embedded_systems::player_input::AccelerometerResource;
127127

128128
static ELAPSED: AtomicU64 = AtomicU64::new(0);
129129
fn elapsed_time() -> core::time::Duration {
@@ -152,11 +152,11 @@ fn main() -> ! {
152152
.with_frequency(Rate::from_mhz(40))
153153
.with_mode(esp_hal::spi::Mode::_0),
154154
)
155-
.unwrap()
156-
.with_sck(peripherals.GPIO17)
157-
.with_mosi(peripherals.GPIO21)
158-
.with_dma(peripherals.DMA_CH0)
159-
.with_buffers(dma_rx_buf, dma_tx_buf);
155+
.unwrap()
156+
.with_sck(peripherals.GPIO17)
157+
.with_mosi(peripherals.GPIO21)
158+
.with_dma(peripherals.DMA_CH0)
159+
.with_buffers(dma_rx_buf, dma_tx_buf);
160160
let cs_output = Output::new(peripherals.GPIO15, Level::High, OutputConfig::default());
161161
let spi_delay = Delay::new();
162162
let spi_device = ExclusiveDevice::new(spi, cs_output, spi_delay).unwrap();
@@ -195,7 +195,16 @@ fn main() -> ! {
195195
.with_sda(peripherals.GPIO38)
196196
.with_scl(peripherals.GPIO39);
197197
// let icm_sensor = Icm42670::new(i2c, icm42670::Address::Primary).unwrap();
198-
let icm_sensor = Mpu6886::new(i2c);
198+
let mut icm_sensor = Mpu6886::new(i2c);
199+
let mut delay = Delay::new();
200+
match icm_sensor.init(&mut delay) {
201+
Ok(_) => {
202+
info!("MPU6886 initialized");
203+
}
204+
Err(_) => {
205+
info!("Failed to initialize MPU6886");
206+
}
207+
}
199208

200209
let mut hardware_rng = Rng::new(peripherals.RNG);
201210
let mut seed = [0u8; 32];
@@ -239,6 +248,6 @@ fn main() -> ! {
239248
loop {
240249
app.update();
241250
info!("tick");
242-
loop_delay.delay_ms(50u32);
251+
loop_delay.delay_ms(300u32);
243252
}
244253
}

0 commit comments

Comments
 (0)