Files
jerryboard-two/src/main.rs
T

114 lines
3.1 KiB
Rust
Raw Normal View History

2026-09-07 18:35:36 -05:00
#![no_std]
#![no_main]
mod backlight;
2026-09-07 22:13:21 -05:00
mod display;
mod framebuffer;
2026-09-07 18:35:36 -05:00
mod led;
2026-09-07 22:13:21 -05:00
use embedded_graphics::draw_target::DrawTarget;
use embedded_graphics::pixelcolor::Rgb565;
use embedded_graphics::prelude::*;
use embedded_graphics::primitives::{PrimitiveStyle, Rectangle, Triangle};
2026-09-07 18:35:36 -05:00
use esp_backtrace as _;
use esp_bootloader_esp_idf::esp_app_desc;
use esp_hal::{init, rmt::Rmt, time::Rate, Config};
use esp_println::println;
use smart_leds::hsv::{hsv2rgb, Hsv};
2026-09-07 22:13:21 -05:00
use smart_leds::RGB8;
const SAT: u8 = 200;
const VAL: u8 = 200;
2026-09-07 18:35:36 -05:00
esp_app_desc!();
#[esp_hal::main]
fn main() -> ! {
let peripherals = init(Config::default());
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")
};
2026-09-07 18:46:42 -05:00
let (_ledc, timer) =
backlight::setup_timer(peripherals.LEDC).expect("Failed to init backlight timer");
2026-09-07 18:35:36 -05:00
let mut backlight =
backlight::LcdBacklight::new(&timer, peripherals.GPIO22).expect("Failed to init backlight");
2026-09-07 22:13:21 -05:00
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,
);
2026-09-07 18:35:36 -05:00
let delay = esp_hal::delay::Delay::new();
2026-09-07 22:13:21 -05:00
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));
let mut pts = [
Point::new(86, 20),
Point::new(61, 50),
Point::new(111, 50),
];
let mut vx: i32 = 3;
let mut vy: i32 = 2;
let mut frame = 0u32;
2026-09-07 18:35:36 -05:00
loop {
2026-09-07 22:13:21 -05:00
let hue = (frame % 256) as u8;
let lit = hsv2rgb(Hsv {
hue,
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);
for p in &mut pts {
p.x += vx;
p.y += vy;
}
let min_x = pts.iter().map(|p| p.x).min().unwrap();
let max_x = pts.iter().map(|p| p.x).max().unwrap();
let min_y = pts.iter().map(|p| p.y).min().unwrap();
let max_y = pts.iter().map(|p| p.y).max().unwrap();
if min_x <= 0 || max_x >= display::WIDTH as i32 {
vx = -vx;
}
if min_y <= 0 || max_y >= display::HEIGHT as i32 {
vy = -vy;
}
fb.clear();
Triangle::new(pts[0], pts[1], pts[2])
.into_styled(PrimitiveStyle::with_fill(accent))
.draw(&mut fb)
.unwrap();
lcd.fill_contiguous(&screen, fb.pixels().iter().cloned())
.unwrap();
if frame % 32 == 0 {
println!(
"frame {frame}: apex=({}, {}), v=({}, {}), hue={hue}",
pts[0].x, pts[0].y, vx, vy
);
2026-09-07 18:35:36 -05:00
}
2026-09-07 22:13:21 -05:00
frame = frame.wrapping_add(1);
//delay.delay_millis(30);
2026-09-07 18:35:36 -05:00
}
}