Skip to content

Commit

Permalink
esp-wrover - update hal (#63)
Browse files Browse the repository at this point in the history
* update version of project to 0.7.0
* m5stack-core - add missing IMU initialization
* esp32-c3-lcdkit clean up
* esp32-c3-devkit-rust - fix implementation and update hal
  • Loading branch information
georgik authored Nov 1, 2023
1 parent 2209028 commit 4fb44ba
Show file tree
Hide file tree
Showing 31 changed files with 166 additions and 344 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Overview:
| Name | Chip | Display | Controls | PMU |
|----------------------|----------|----------|---------------------------------------|---------|
| esp-wrover-kit | esp32 | ili9341 | 6 push-button controls, separate PINs | |
| esp32-c3-devkit-rust | esp32-c3 | ili9342c | icm42670 accelerometer | |
| esp32-c3-devkit-rust | esp32-c3 | st7789 | icm42670 accelerometer | |
| esp32-c3-lcdkit | esp32-c3 | gc9a01 | rotary encoder | |
| esp32-c6-devkit | esp32-c6 | ili9341 | resistor ladder with push buttons | |
| esp32-s2-kaluga | esp32-s2 | ili9341 | resistor ladder with push buttons | |
Expand Down
8 changes: 4 additions & 4 deletions esp-wrover-kit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[package]
name = "spooky-wrover-kit"
version = "0.6.0"
version = "0.7.0"
authors = ["Juraj Michálek <[email protected]>"]
edition = "2021"
license = "MIT"

[target.xtensa-esp32-none-elf.dependencies]
xtensa-atomic-emulation-trap = "0.4.0"
hal = { package = "esp32-hal", version = "0.15.0", features = ["psram_8m"] }
esp-backtrace = { version = "0.8.0", features = [
hal = { package = "esp32-hal", version = "0.16.0", features = ["psram-8m"] }
esp-backtrace = { version = "0.9.0", features = [
"esp32",
"panic-handler",
"print-uart",
] }
esp-println = { version = "0.6.0", features = ["esp32"] }
esp-println = { version = "0.7.0", features = ["esp32"] }

[dependencies]
esp-alloc = "0.3.0"
Expand Down
16 changes: 10 additions & 6 deletions esp-wrover-kit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
static ALLOCATOR: esp_alloc::EspHeap = esp_alloc::EspHeap::empty();

use esp_backtrace as _;
use hal::{psram, prelude::*, peripherals::Peripherals, spi, clock::{ClockControl, CpuClock}, Delay, Rng, IO};
use hal::{psram, prelude::*, peripherals::Peripherals,
spi::{
master::Spi,
SpiMode,
},
clock::{ClockControl, CpuClock}, Delay, Rng, IO};
use display_interface_spi::SPIInterfaceNoCS;
use embedded_graphics::{
mono_font::{ascii::FONT_8X13, MonoTextStyle},
Expand Down Expand Up @@ -35,21 +40,20 @@ fn main() -> ! {
psram::init_psram(peripherals.PSRAM);
init_psram_heap();

let mut system = peripherals.DPORT.split();
let system = peripherals.SYSTEM.split();
let clocks = ClockControl::configure(system.clock_control, CpuClock::Clock240MHz).freeze();

let mut delay = Delay::new(&clocks);

let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
let (unconfigured_pins, configured_pins, configured_system_pins) = setup_pins(io.pins);

let spi = spi::Spi::new_no_cs_no_miso(
peripherals.SPI3,
let spi = Spi::new_no_cs_no_miso(
peripherals.SPI2,
unconfigured_pins.sclk,
unconfigured_pins.mosi,
60u32.MHz(),
spi::SpiMode::Mode0,
&mut system.peripheral_clock_control,
SpiMode::Mode0,
&clocks,
);

Expand Down
8 changes: 4 additions & 4 deletions esp32-c3-devkit-rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[package]
name = "spooky-esp32-c3"
version = "0.6.0"
version = "0.7.0"
authors = ["Juraj Michálek <[email protected]>"]
edition = "2021"
license = "MIT"

[target.riscv32imac-unknown-none-elf.dependencies]
hal = { package = "esp32c3-hal", version = "0.12.0" }
esp-backtrace = { version = "0.8.0", features = [
hal = { package = "esp32c3-hal", version = "0.13.0" }
esp-backtrace = { version = "0.9.0", features = [
"esp32c3",
"panic-handler",
"print-uart",
] }
esp-println = { version = "0.6.0", features = [ "esp32c3" ] }
esp-println = { version = "0.7.0", features = [ "esp32c3" ] }

[dependencies]
esp-alloc = "0.3.0"
Expand Down
18 changes: 11 additions & 7 deletions esp32-c3-devkit-rust/diagram.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,21 @@
}
],
"connections": [
[ "esp:TX0", "$serialMonitor:RX", "", [] ],
[ "esp:RX0", "$serialMonitor:TX", "", [] ],
[ "esp:21", "$serialMonitor:RX", "", [] ],
[ "esp:20", "$serialMonitor:TX", "", [] ],
[ "esp:3V3", "lcd1:VCC", "green", [] ],
[ "esp:GND.1", "lcd1:GND", "black", [] ],
[ "esp:6", "lcd1:SCK", "blue", [] ],
[ "esp:7", "lcd1:MOSI", "orange", [] ],
[ "esp:GND.1", "lcd1:CS", "red", [] ],
[ "esp:21", "lcd1:D/C", "magenta", [] ],
[ "esp:0", "lcd1:SCK", "blue", [] ],
[ "esp:6", "lcd1:MOSI", "orange", [] ],
[ "esp:5", "lcd1:CS", "red", [] ],
[ "esp:4", "lcd1:D/C", "magenta", [] ],
[ "esp:3", "lcd1:RST", "yellow", [] ],
[ "lcd1:LED", "esp:3V3", "white", [] ]
],
"serialMonitor": { "display": "terminal" },
"serialMonitor": {
"display": "terminal",
"newline": "lf",
"convertEol": true
},
"dependencies": {}
}
4 changes: 2 additions & 2 deletions esp32-c3-devkit-rust/src/accel_movement_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ where
fn tick(&mut self) {
if let Ok(accel_norm) = self.icm.accel_norm() {
if accel_norm.y > self.accel_threshold {
self.last_action = Action::Left;
} else if accel_norm.y < -self.accel_threshold {
self.last_action = Action::Right;
} else if accel_norm.y < -self.accel_threshold {
self.last_action = Action::Left;
} else if accel_norm.x > self.accel_threshold {
self.last_action = Action::Down;
} else if accel_norm.x < -self.accel_threshold {
Expand Down
34 changes: 17 additions & 17 deletions esp32-c3-devkit-rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use hal::{
i2c,
peripherals::Peripherals,
prelude::*,
spi,
spi::{master::Spi, SpiMode},
Delay,
Rng,
IO
Expand All @@ -46,22 +46,24 @@ use shared_bus::BusManagerSimple;
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let mut system = peripherals.SYSTEM.split();
let system = peripherals.SYSTEM.split();
let clocks = ClockControl::configure(system.clock_control, CpuClock::Clock160MHz).freeze();

let mut delay = Delay::new(&clocks);

println!("About to initialize the SPI LED driver");
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
let (unconfigured_pins, /*configured_pins, */mut configured_system_pins) = setup_pins(io.pins);
let (uninitialized_pins, /*configured_pins, */configured_system_pins) = setup_pins(io.pins);
println!("SPI LED driver initialized");
let spi = spi::Spi::new_no_cs_no_miso(

let spi = Spi::new(
peripherals.SPI2,
unconfigured_pins.sclk,
unconfigured_pins.mosi,
uninitialized_pins.sclk,
uninitialized_pins.mosi,
uninitialized_pins.miso,
uninitialized_pins.cs,
60u32.MHz(),
spi::SpiMode::Mode0,
&mut system.peripheral_clock_control,
SpiMode::Mode0,
&clocks,
);

Expand All @@ -74,13 +76,13 @@ fn main() -> ! {
// If there is no delay, display is blank
delay.delay_ms(500u32);

let mut display = match mipidsi::Builder::ili9342c_rgb565(di)
let mut display = match mipidsi::Builder::st7789(di)
.with_display_size(240 as u16, 320 as u16)
.with_orientation(mipidsi::Orientation::Landscape(true))
.with_color_order(mipidsi::ColorOrder::Rgb)
.init(&mut delay, Some(configured_system_pins.reset)) {
Ok(display) => display,
Err(e) => {
Err(_e) => {
// Handle the error and possibly exit the application
panic!("Display initialization failed");
}
Expand All @@ -92,22 +94,20 @@ fn main() -> ! {
Text::new(
"Initializing...",
Point::new(80, 110),
MonoTextStyle::new(&FONT_8X13, RgbColor::WHITE),
MonoTextStyle::new(&FONT_8X13, RgbColor::GREEN),
)
.draw(&mut display)
.unwrap();



// #[cfg(any(feature = "imu_controls"))]
println!("Initialized");
let i2c = i2c::I2C::new(
peripherals.I2C0,
unconfigured_pins.sda,
unconfigured_pins.scl,
uninitialized_pins.sda,
uninitialized_pins.scl,
100u32.kHz(),
&mut system.peripheral_clock_control,
&clocks,
);
println!("I2C ready");

// #[cfg(any(feature = "imu_controls"))]
let bus = BusManagerSimple::new(i2c);
Expand Down
49 changes: 10 additions & 39 deletions esp32-c3-devkit-rust/src/setup.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use crate::types::{UnconfiguredPins, ConfiguredPins, ConfiguredSystemPins};
use embedded_hal::digital::v2::{OutputPin, InputPin};
use crate::types::{UnconfiguredPins, ConfiguredSystemPins};
use embedded_hal::digital::v2::OutputPin;
use hal::gpio::{self, Pins};
use spooky_embedded::{ button_keyboard::ButtonKeyboard, embedded_movement_controller::EmbeddedMovementController };
use spooky_core;

pub fn setup_pins(pins: Pins) -> (UnconfiguredPins<gpio::Unknown>, /*ConfiguredPins<impl InputPin, impl InputPin, impl InputPin, impl InputPin, impl InputPin,
impl InputPin>, */ConfiguredSystemPins<impl OutputPin, impl OutputPin, impl OutputPin>) {
let unconfigured_pins = UnconfiguredPins {
sclk: pins.gpio6,
mosi: pins.gpio7,
sda: pins.gpio8,
scl: pins.gpio18,
sclk: pins.gpio0,
mosi: pins.gpio6,
miso: pins.gpio11,
cs: pins.gpio5,
sda: pins.gpio10,
scl: pins.gpio8,
};

// let configured_pins = ConfiguredPins {
Expand All @@ -23,39 +23,10 @@ pub fn setup_pins(pins: Pins) -> (UnconfiguredPins<gpio::Unknown>, /*ConfiguredP
// };

let configured_system_pins = ConfiguredSystemPins {
dc: pins.gpio21.into_push_pull_output(),
backlight: pins.gpio5.into_push_pull_output(),
dc: pins.gpio4.into_push_pull_output(),
backlight: pins.gpio1.into_push_pull_output(),
reset: pins.gpio3.into_push_pull_output(),
};

(unconfigured_pins, /*configured_pins, */configured_system_pins)
}

pub fn setup_button_keyboard<Up: InputPin, Down: InputPin, Left: InputPin, Right: InputPin, Dyn: InputPin, Tel: InputPin>(
configured_pins: ConfiguredPins<Up, Down, Left, Right, Dyn, Tel>
) -> ButtonKeyboard<Up, Down, Left, Right, Dyn, Tel> {
ButtonKeyboard::new(
configured_pins.up_button,
configured_pins.down_button,
configured_pins.left_button,
configured_pins.right_button,
configured_pins.dynamite_button,
configured_pins.teleport_button,
)
}

pub fn setup_movement_controller<Up, Down, Left, Right, Dyn, Tel>(
seed_buffer: [u8; 32],
button_keyboard: ButtonKeyboard<Up, Down, Left, Right, Dyn, Tel>
) -> EmbeddedMovementController<Up, Down, Left, Right, Dyn, Tel>
where
Up: InputPin,
Down: InputPin,
Left: InputPin,
Right: InputPin,
Dyn: InputPin,
Tel: InputPin,
{
let demo_movement_controller = spooky_core::demo_movement_controller::DemoMovementController::new(seed_buffer);
EmbeddedMovementController::new(demo_movement_controller, button_keyboard)
}
21 changes: 7 additions & 14 deletions esp32-c3-devkit-rust/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
use hal::gpio;
use embedded_hal::digital::v2::{ InputPin, OutputPin };
use embedded_hal::digital::v2::OutputPin;

// Generic type for unconfigured pins
pub struct UnconfiguredPins<MODE> {
pub sclk: gpio::Gpio6<MODE>,
pub mosi: gpio::Gpio7<MODE>,
pub sda: gpio::Gpio8<MODE>,
pub scl: gpio::Gpio18<MODE>,
}

pub struct ConfiguredPins<Up: InputPin, Down: InputPin, Left: InputPin, Right: InputPin, Dyn: InputPin, Tel: InputPin> {
pub up_button: Up,
pub down_button: Down,
pub left_button: Left,
pub right_button: Right,
pub dynamite_button: Dyn,
pub teleport_button: Tel,
pub sclk: gpio::Gpio0<MODE>,
pub mosi: gpio::Gpio6<MODE>,
pub miso: gpio::Gpio11<MODE>,
pub cs: gpio::Gpio5<MODE>,
pub sda: gpio::Gpio10<MODE>,
pub scl: gpio::Gpio8<MODE>,
}

pub struct ConfiguredSystemPins<Dc: OutputPin, Bckl: OutputPin, Reset: OutputPin> {
Expand Down
12 changes: 4 additions & 8 deletions esp32-c3-lcdkit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
[package]
name = "spooky-esp32-c3-lcdkit"
version = "0.6.0"
version = "0.7.0"
authors = ["Juraj Michálek <[email protected]>"]
edition = "2021"
license = "MIT"

[target.riscv32imac-unknown-none-elf.dependencies]
# hal = { package = "esp32c3-hal", version = "0.12.0" }
hal = { git = "https://github.com/esp-rs/esp-hal.git", package = "esp32c3-hal", rev = "44e968f7a83f80be43d60cdc01c10eccab4b39cf" }
esp-backtrace = { version = "0.8.0", features = [
hal = { package = "esp32c3-hal", version = "0.13.0" }
esp-backtrace = { version = "0.9.0", features = [
"esp32c3",
"panic-handler",
"print-uart",
] }
esp-println = { version = "0.6.0", features = [ "esp32c3" ] }
esp-println = { version = "0.7.0", features = [ "esp32c3" ] }

[dependencies]
esp-alloc = "0.3.0"
Expand Down Expand Up @@ -42,9 +41,6 @@ system_timer = []
button_controls = []
imu_controls = []

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

esp32c3_ili9341 = [ "esp32c3", "imu_controls" ]
Loading

0 comments on commit 4fb44ba

Please sign in to comment.