This commit is contained in:
2026-09-07 23:33:05 -05:00
parent 3ad59eac09
commit 8d8eabc56b
5 changed files with 626 additions and 87 deletions
+85 -39
View File
@@ -6,55 +6,53 @@ mod display;
mod framebuffer;
mod led;
use embedded_graphics::draw_target::DrawTarget;
use embedded_graphics::pixelcolor::Rgb565;
use embedded_graphics::prelude::*;
use embedded_graphics::primitives::{PrimitiveStyle, Rectangle, Triangle};
use embedded_graphics::primitives::{PrimitiveStyle, Triangle};
use embassy_executor::Spawner;
use embassy_time::Timer;
use esp_backtrace as _;
use esp_bootloader_esp_idf::esp_app_desc;
use esp_hal::gpio::Output;
use esp_hal::timer::timg::TimerGroup;
use esp_hal::{init, rmt::Rmt, time::Rate, Config};
use esp_println::println;
use smart_leds::hsv::{hsv2rgb, Hsv};
use smart_leds::RGB8;
const SAT: u8 = 200;
const VAL: u8 = 200;
const SAT: u8 = 255;
const VAL: u8 = 255;
esp_app_desc!();
#[esp_hal::main]
fn main() -> ! {
let peripherals = init(Config::default());
#[embassy_executor::task]
async fn led_task(mut led: led::RgbLed) {
let mut frame = 0u32;
loop {
let hue = (frame % 256) as u8;
let lit = hsv2rgb(Hsv {
hue,
sat: SAT,
val: VAL,
});
led.set_rgb(lit).unwrap();
Timer::after_millis(30).await;
frame = frame.wrapping_add(1);
}
}
let mut led = {
let rmt = Rmt::new(peripherals.RMT, Rate::from_mhz(80)).expect("Failed to init RMT");
led::RgbLed::new(rmt.channel0, peripherals.GPIO8).expect("Failed to init RGB LED")
};
let (_ledc, timer) =
backlight::setup_timer(peripherals.LEDC).expect("Failed to init backlight timer");
#[embassy_executor::task]
async fn display_task(
mut spi: display::SpiDmaBus,
mut dc: Output<'static>,
mut cs: Output<'static>,
mut fb: framebuffer::Framebuffer,
timer: esp_hal::ledc::timer::Timer<'static, esp_hal::ledc::LowSpeed>,
bl_pin: esp_hal::peripherals::GPIO22<'static>,
) {
let mut backlight =
backlight::LcdBacklight::new(&timer, peripherals.GPIO22).expect("Failed to init backlight");
backlight::LcdBacklight::new(&timer, bl_pin).expect("Failed to init backlight");
backlight.set_level(0.5).unwrap();
let mut buffer = [0u8; 4096];
let mut lcd = display::init(
peripherals.SPI2,
peripherals.GPIO7,
peripherals.GPIO6,
peripherals.GPIO15,
peripherals.GPIO14,
peripherals.GPIO21,
&mut buffer,
);
let delay = esp_hal::delay::Delay::new();
println!("LCD {}x{} initialized", display::WIDTH, display::HEIGHT);
lcd.clear(Rgb565::BLACK).unwrap();
let mut fb = framebuffer::Framebuffer;
let screen = Rectangle::new(Point::zero(), Size::new(display::WIDTH, display::HEIGHT));
println!("backlight set to 0.5");
let mut pts = [
Point::new(86, 20),
@@ -72,8 +70,7 @@ fn main() -> ! {
sat: SAT,
val: VAL,
});
led.set_rgb(RGB8::new(0,0,0)).unwrap();
let accent = Rgb565::new(lit.r / 8, lit.g / 4, lit.b / 8);
let accent = Rgb565::new(lit.r/8, lit.g/4, lit.b/8);
for p in &mut pts {
p.x += vx;
@@ -98,7 +95,8 @@ fn main() -> ! {
.draw(&mut fb)
.unwrap();
lcd.fill_contiguous(&screen, fb.pixels().iter().cloned())
display::send_framebuffer(&mut spi, &mut dc, &mut cs, fb.as_bytes())
.await
.unwrap();
if frame % 32 == 0 {
@@ -109,6 +107,54 @@ fn main() -> ! {
}
frame = frame.wrapping_add(1);
//delay.delay_millis(30);
}
}
#[esp_rtos::main]
async fn main(spawner: Spawner) -> ! {
let peripherals = init(Config::default());
let timg0 = TimerGroup::new(peripherals.TIMG0);
esp_rtos::start(timg0.timer0, peripherals.FROM_CPU_INTR0);
let led = {
let rmt = Rmt::new(peripherals.RMT, Rate::from_mhz(80)).expect("Failed to init RMT");
led::RgbLed::new(rmt.channel0, peripherals.GPIO8).expect("Failed to init RGB LED")
};
let (_ledc, timer) =
backlight::setup_timer(peripherals.LEDC).expect("Failed to init backlight timer");
let mut buffer = [0u8; 4096];
let lcd = display::init(
display::LcdPins {
spi2: peripherals.SPI2,
sck: peripherals.GPIO7,
mosi: peripherals.GPIO6,
dc: peripherals.GPIO15,
cs: peripherals.GPIO14,
rst: peripherals.GPIO21,
dma_ch: peripherals.DMA_CH0,
},
&mut buffer,
);
let (interface, _model, _rst) = lcd.release();
let (device, dc) = interface.release();
let (spi, cs) = device.into_inner();
println!("LCD {}x{} initialized", display::WIDTH, display::HEIGHT);
spawner.spawn(led_task(led).unwrap());
spawner.spawn(display_task(
spi,
dc,
cs,
framebuffer::Framebuffer,
timer,
peripherals.GPIO22,
).unwrap());
loop {
Timer::after_millis(1000).await;
}
}