Skip to content

Commit

Permalink
prepare M5Stack CoreS3 for BSP
Browse files Browse the repository at this point in the history
  • Loading branch information
georgik committed Dec 16, 2024
1 parent ae7bdc2 commit c6958d8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 56 deletions.
1 change: 1 addition & 0 deletions m5stack-cores3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ spooky-embedded = { path = "../spooky-embedded", default-features = false, featu
esp-display-interface-spi-dma = "0.2.0"
shared-bus = { version = "0.3.0" }
log = "0.4.22"
esp-bsp = { path = "../../esp-bsp-rs", features = ["m5stackcores3"] }

[profile.dev]
# Rust debug is too slow.
Expand Down
79 changes: 23 additions & 56 deletions m5stack-cores3/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#![no_std]
#![no_main]

use esp_display_interface_spi_dma::display_interface_spi_dma;
use aw9523::I2CGpioExpanderInterface;
use axp2101::{Axp2101, I2CPowerManagementInterface};
use esp_display_interface_spi_dma::display_interface_spi_dma;
use esp_bsp::boards::m5stackcores3::{lcd_dma_spi, lcd_display, lcd_display_interface, i2c_init, lcd_reset_pin};

#[allow(unused_imports)]
use esp_backtrace as _;
Expand Down Expand Up @@ -34,9 +35,6 @@ use mipidsi::options::ColorInversion;
use shared_bus::BusManagerSimple;
use spooky_embedded::{
app::app_loop,
/*controllers::{
accel::AccelMovementController, composites::accel_composite::AccelCompositeController,
},*/
embedded_display::LCD_MEMORY_SIZE,
};

Expand All @@ -47,90 +45,59 @@ fn main() -> ! {

let mut delay = Delay::new();

info!("About to initialize the SPI LED driver");
println!("Initializing M5Stack CoreS3");

let lcd_sclk = peripherals.GPIO36;
let lcd_mosi = peripherals.GPIO37;
let lcd_cs = peripherals.GPIO3;
let lcd_dc = Output::new(peripherals.GPIO35, Level::Low);
let lcd_reset = Output::new(peripherals.GPIO15, Level::Low);

let i2c_sda = peripherals.GPIO12;
let i2c_scl = peripherals.GPIO11;
let i2c_bus = I2c::new(peripherals.I2C0, esp_hal::i2c::master::Config::default())
.with_sda(i2c_sda)
.with_scl(i2c_scl);
let bus = BusManagerSimple::new(i2c_bus);
// Initialize I2C shared bus
let bus = BusManagerSimple::new(i2c_init!(peripherals));

// Initialize AXP2101 power management
info!("Initializing AXP2101");
let axp_interface = I2CPowerManagementInterface::new(bus.acquire_i2c());
let mut axp = Axp2101::new(axp_interface);
axp.init().unwrap();

info!("Initializing GPIO Expander");
// Initialize AW9523 GPIO expander
info!("Initializing AW9523");
let aw_interface = I2CGpioExpanderInterface::new(bus.acquire_i2c());
let mut aw = aw9523::Aw9523::new(aw_interface);
aw.init().unwrap();

let dma = Dma::new(peripherals.DMA);
let dma_channel = dma.channel0;

let spi = Spi::new_with_config(
peripherals.SPI2,
esp_hal::spi::master::Config {
frequency: 40u32.MHz(),
..esp_hal::spi::master::Config::default()
},
)
.with_sck(lcd_sclk)
.with_mosi(lcd_mosi)
.with_cs(lcd_cs)
.with_dma(dma_channel.configure(false, DmaPriority::Priority0));
// Initialize DMA and SPI for LCD
let spi = lcd_dma_spi!(peripherals);

info!("SPI ready");
println!("SPI ready");

let di = display_interface_spi_dma::new_no_cs(LCD_MEMORY_SIZE, spi, lcd_dc);
// Initialize the display interface
let di = lcd_display_interface!(peripherals, spi);

// ESP32-S3-BOX display initialization workaround: Wait for the display to power up.
// If delay is 250ms, picture will be fuzzy.
// If there is no delay, display is blank
// Delay to let the display power up
delay.delay_ns(500_000u32);

let mut display = mipidsi::Builder::new(mipidsi::models::ILI9341Rgb565, di)
.display_size(240, 320)
.orientation(
mipidsi::options::Orientation::new()
.flip_vertical()
.flip_horizontal(),
)
.color_order(mipidsi::options::ColorOrder::Bgr)

// Initialize the display using the builder pattern macro
let mut display = lcd_display!(peripherals, di)
.invert_colors(ColorInversion::Inverted)
.reset_pin(lcd_reset)
.init(&mut delay)
.unwrap();

info!("Initializing...");
println!("Initializing display...");
Text::new(
"Initializing...",
Point::new(80, 110),
MonoTextStyle::new(&FONT_8X13, RgbColor::WHITE),
)
.draw(&mut display)
.unwrap();

// let icm = Icm42670::new(i2c, Address::Primary).unwrap();
.draw(&mut display)
.unwrap();

// Initialize RNG
let mut rng = Rng::new(peripherals.RNG);
let mut seed_buffer = [0u8; 32];
rng.read(&mut seed_buffer);

// let accel_movement_controller = AccelMovementController::new(icm, 0.2);
// Create the movement controller
let demo_movement_controller =
spooky_core::demo_movement_controller::DemoMovementController::new(seed_buffer);
let movement_controller = demo_movement_controller;
// let movement_controller =
// AccelCompositeController::new(demo_movement_controller, accel_movement_controller);

println!("Entering main loop");
app_loop(&mut display, seed_buffer, movement_controller);
app_loop(&mut display, seed_buffer, demo_movement_controller);
}

0 comments on commit c6958d8

Please sign in to comment.