#![no_std] #![no_main] #![deny( clippy::mem_forget, reason = "mem::forget is generally not safe to do with esp_hal types, especially those \ holding buffers for the duration of a data transfer." )] #![deny(clippy::large_stack_frames)] // use embedded_graphics::{pixelcolor::Rgb565, prelude::DrawTarget}; // use embedded_hal_bus::spi::ExclusiveDevice; use esp_hal::{ clock::CpuClock, delay::Delay, gpio::{Level, Output, OutputConfig}, main, spi::master::{Config, Spi}, time::Rate, }; use esp_backtrace as _; // use mipidsi::{Builder, interface::SpiInterface, models::ST7789}; use crate::display::{Color, Display, Position, Rgb565, SetAddressMode}; // use crate::display::{Color, Display, Position, Rgb565, Rotation}; extern crate alloc; mod display; // This creates a default app-descriptor required by the esp-idf bootloader. // For more information see: esp_bootloader_esp_idf::esp_app_desc!(); #[allow( clippy::large_stack_frames, reason = "it's not unusual to allocate larger buffers etc. in main" )] #[main] fn main() -> ! { // generator version: 1.3.0 // generator parameters: --chip esp32 -o esp32-wroom-32e -o alloc -o esp-backtrace -o log -o vscode esp_println::logger::init_logger_from_env(); let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max()); let peripherals = esp_hal::init(config); // The following pins are used to bootstrap the chip. They are available // for use, but check the datasheet of the module for more information on them. // - GPIO0 // - GPIO2 // - GPIO5 // - GPIO12 // - GPIO15 // These GPIO pins are in use by some feature of the module and should not be used. let _ = peripherals.GPIO6; let _ = peripherals.GPIO7; let _ = peripherals.GPIO8; let _ = peripherals.GPIO9; let _ = peripherals.GPIO10; let _ = peripherals.GPIO11; let _ = peripherals.GPIO16; let _ = peripherals.GPIO20; esp_alloc::heap_allocator!(#[esp_hal::ram(reclaimed)] size: 98768); let spi = Spi::new( peripherals.SPI2, Config::default() .with_frequency(Rate::from_mhz(40)) .with_mode(esp_hal::spi::Mode::_2) .with_read_bit_order(esp_hal::spi::BitOrder::MsbFirst) .with_write_bit_order(esp_hal::spi::BitOrder::MsbFirst), ) .unwrap() .with_sck(peripherals.GPIO5) .with_mosi(peripherals.GPIO18) .with_miso(peripherals.GPIO19) .with_cs(peripherals.GPIO21); let rst = Output::new(peripherals.GPIO14, Level::Low, OutputConfig::default()); let dc = Output::new(peripherals.GPIO32, Level::Low, OutputConfig::default()); let mut display = Display { spi, dc, rst, delay: Delay::new(), }; display.init(SetAddressMode { color_order: display::ColorOrder::Bgr, ..Default::default() }); display.set_tearing(display::TearingMode::Horizontal); display.draw_rect( Position::new(0, 0), Position::new(32, 32), Rgb565::yellow().as_color(), ); let test_delay = Delay::new(); let mut color = 0; loop { log::info!("Hello world: {}", color); color = (color + 50) % 200; display.draw_rect( Position::new(0, 0), Position::new(240, 240), Color { bytes: [color, color], }, ); // let delay_start = Instant::now(); // while delay_start.elapsed() < Duration::from_millis(500) {} test_delay.delay_millis(1000); } // for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.1.0/examples }